@macroui/macroui 4.0.2 â 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +122 -0
- package/index.js +149 -0
- package/lib/addPrefix.js +104 -0
- package/lib/createPlugin.js +19 -0
- package/lib/responsiveRegex.js +45 -0
- package/lib/utility-classes.js +7 -0
- package/package.json +10 -5
- package/src/src/index.d.ts +122 -0
- package/src/src/index.js +149 -0
- package/src/src/lib/addPrefix.js +104 -0
- package/src/src/lib/createPlugin.js +19 -0
- package/src/src/lib/responsiveRegex.js +45 -0
- package/src/src/lib/utility-classes.js +7 -0
- package/src/src/theming/colorNames.js +30 -0
- package/src/src/theming/functions.js +262 -0
- package/src/src/theming/index.js +35 -0
- package/src/src/theming/themeDefaults.js +47 -0
- package/src/src/theming/themes.d.ts +5 -0
- package/src/src/theming/themes.js +485 -0
- package/theming/colorNames.js +30 -0
- package/theming/functions.js +262 -0
- package/theming/index.js +35 -0
- package/theming/themeDefaults.js +47 -0
- package/theming/themes.d.ts +5 -0
- package/theming/themes.js +485 -0
package/src/src/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// const tailwindColors = require("tailwindcss/colors")
|
|
2
|
+
// const tailwindPlugin = require("tailwindcss/plugin")
|
|
3
|
+
const tailwindPlugin = require("./lib/createPlugin")
|
|
4
|
+
|
|
5
|
+
const postcssJs = require("postcss-js")
|
|
6
|
+
const pc = require("picocolors")
|
|
7
|
+
const postcssPrefix = require("./lib/addPrefix")
|
|
8
|
+
|
|
9
|
+
const daisyuiInfo = require("../package.json")
|
|
10
|
+
const utilities = require("../dist/utilities")
|
|
11
|
+
const base = require("../dist/base")
|
|
12
|
+
const unstyled = require("../dist/unstyled")
|
|
13
|
+
const styled = require("../dist/styled")
|
|
14
|
+
const utilitiesUnstyled = require("../dist/utilities-unstyled")
|
|
15
|
+
const utilitiesStyled = require("../dist/utilities-styled")
|
|
16
|
+
const themes = require("./theming/themes")
|
|
17
|
+
const colorFunctions = require("./theming/functions")
|
|
18
|
+
const utilityClasses = require("./lib/utility-classes")
|
|
19
|
+
const colorObject = require("./theming/index")
|
|
20
|
+
|
|
21
|
+
const mainFunction = ({ addBase, addComponents, config }) => {
|
|
22
|
+
let logs = false
|
|
23
|
+
if (config("daisyui.logs") !== false) {
|
|
24
|
+
logs = true
|
|
25
|
+
}
|
|
26
|
+
if (logs) {
|
|
27
|
+
console.log()
|
|
28
|
+
console.log(`đŧ ${pc.magenta("daisyUI")} ${pc.dim(daisyuiInfo.version)}`)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// inject @base style
|
|
32
|
+
if (config("daisyui.base") !== false) {
|
|
33
|
+
addBase(base)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// inject components
|
|
37
|
+
let file = styled
|
|
38
|
+
if (config("daisyui.styled") === false) {
|
|
39
|
+
file = unstyled
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// add prefix to class names if specified
|
|
43
|
+
const prefix = config("daisyui.prefix")
|
|
44
|
+
let postcssJsProcess
|
|
45
|
+
if (prefix) {
|
|
46
|
+
try {
|
|
47
|
+
postcssJsProcess = postcssJs.sync(postcssPrefix({ prefix, ignore: [] }))
|
|
48
|
+
} catch (error) {
|
|
49
|
+
logs && console.error(`Error occurred and prevent applying the "prefix" option:`, error)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const shouldApplyPrefix = prefix && postcssJsProcess
|
|
53
|
+
if (shouldApplyPrefix) {
|
|
54
|
+
file = postcssJsProcess(file)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
addComponents(file)
|
|
58
|
+
|
|
59
|
+
const themeInjector = colorFunctions.injectThemes(addBase, config, themes)
|
|
60
|
+
themeInjector
|
|
61
|
+
|
|
62
|
+
// inject @utilities style needed by components
|
|
63
|
+
if (config("daisyui.utils") !== false) {
|
|
64
|
+
addComponents(utilities, { variants: ["responsive"] })
|
|
65
|
+
|
|
66
|
+
let toAdd = utilitiesUnstyled // shadow clone here to avoid mutate the original
|
|
67
|
+
if (shouldApplyPrefix) {
|
|
68
|
+
toAdd = postcssJsProcess(toAdd)
|
|
69
|
+
}
|
|
70
|
+
addComponents(toAdd, { variants: ["responsive"] })
|
|
71
|
+
|
|
72
|
+
toAdd = utilitiesStyled
|
|
73
|
+
if (shouldApplyPrefix) {
|
|
74
|
+
toAdd = postcssJsProcess(toAdd)
|
|
75
|
+
}
|
|
76
|
+
addComponents(toAdd, { variants: ["responsive"] })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (logs) {
|
|
80
|
+
if (config("daisyui.styled") === false) {
|
|
81
|
+
console.log(
|
|
82
|
+
`ââ ${pc.yellow("âšī¸")} ${pc.blue("styled")} ${pc.reset("config is")} ${pc.blue(
|
|
83
|
+
"false"
|
|
84
|
+
)} ${pc.dim("\tcomponents won't have design decisions")}`
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
if (config("daisyui.utils") === false) {
|
|
88
|
+
console.log(
|
|
89
|
+
`ââ ${pc.yellow("âšī¸")} ${pc.blue("utils")} ${pc.reset("config is")} ${pc.blue(
|
|
90
|
+
"false"
|
|
91
|
+
)} ${pc.dim("\tdaisyUI utility classes are disabled")}`
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
if (config("daisyui.prefix") && config("daisyui.prefix") !== "") {
|
|
95
|
+
console.log(
|
|
96
|
+
`ââ ${pc.green("âī¸")} ${pc.blue("prefix")} is enabled${pc.dim(
|
|
97
|
+
"\t\tdaisyUI classnames must use"
|
|
98
|
+
)} ${pc.blue(config("daisyui.prefix"))} ${pc.dim("prefix")}`
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
if (themeInjector.themeOrder.length > 0) {
|
|
102
|
+
console.log(
|
|
103
|
+
`ââ ${pc.green("âī¸")} ${themeInjector.themeOrder.length} ${
|
|
104
|
+
themeInjector.themeOrder.length > 1 ? "themes" : "theme"
|
|
105
|
+
} added${pc.dim("\t\thttps://daisyui.com/docs/themes")}`
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
if (themeInjector.themeOrder.length === 0) {
|
|
109
|
+
console.log(
|
|
110
|
+
`ââ ${pc.yellow("âšī¸")} All themes are disabled in config${pc.dim(
|
|
111
|
+
"\t\thttps://daisyui.com/docs/themes"
|
|
112
|
+
)}`
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
const messages = [
|
|
116
|
+
`${pc.green("â¤ī¸")} ${pc.reset("Support daisyUI project:")}\t${pc.dim(
|
|
117
|
+
daisyuiInfo.funding.url
|
|
118
|
+
)}`,
|
|
119
|
+
`${pc.green("â
")} ${pc.reset("Star daisyUI on GitHub")}\t${pc.dim(
|
|
120
|
+
"https://github.com/saadeghi/daisyui"
|
|
121
|
+
)}`,
|
|
122
|
+
]
|
|
123
|
+
console.log(`â°â ${messages[Math.floor(Math.random() * messages.length)]}`)
|
|
124
|
+
console.log()
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = tailwindPlugin(mainFunction, {
|
|
129
|
+
theme: {
|
|
130
|
+
extend: {
|
|
131
|
+
colors: {
|
|
132
|
+
...colorObject,
|
|
133
|
+
// adding all Tailwind `neutral` shades here so they don't get overridden by daisyUI `neutral` color
|
|
134
|
+
"neutral-50": "#fafafa",
|
|
135
|
+
"neutral-100": "#f5f5f5",
|
|
136
|
+
"neutral-200": "#e5e5e5",
|
|
137
|
+
"neutral-300": "#d4d4d4",
|
|
138
|
+
"neutral-400": "#a3a3a3",
|
|
139
|
+
"neutral-500": "#737373",
|
|
140
|
+
"neutral-600": "#525252",
|
|
141
|
+
"neutral-700": "#404040",
|
|
142
|
+
"neutral-800": "#262626",
|
|
143
|
+
"neutral-900": "#171717",
|
|
144
|
+
"neutral-950": "#0a0a0a",
|
|
145
|
+
},
|
|
146
|
+
...utilityClasses,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const Tokenizer = require("css-selector-tokenizer")
|
|
2
|
+
|
|
3
|
+
function itMatchesOne(arr, term) {
|
|
4
|
+
return arr.some((i) => term.search(i) >= 0)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function parseAttrSelector(node) {
|
|
8
|
+
const { content } = node
|
|
9
|
+
const regex =
|
|
10
|
+
/(^class|^id)([*^?~|$=]*)+(?:("\s*)([^"\\]*?(?:\\.[^"\\]*)*?)(\s*")|('\s*)([^'\\]*?(?:\\.[^'\\]*)*?)(\s*'))/i
|
|
11
|
+
|
|
12
|
+
const [type, operator, head, classes, foot] = content.split(regex).filter((part) => part)
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
type,
|
|
16
|
+
operator,
|
|
17
|
+
head,
|
|
18
|
+
classes: classes ? classes.split(" ").map((c) => c.replace(/"|'/g, "")) : [],
|
|
19
|
+
foot,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function attrStringify({ type, operator, head, classes, foot }) {
|
|
24
|
+
return `${type}${operator || ""}${head || ""}${classes.join(" ")}${foot || ""}`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function prefixNode(node, prefix) {
|
|
28
|
+
if (["class", "id"].includes(node.type)) {
|
|
29
|
+
return {
|
|
30
|
+
...node,
|
|
31
|
+
name: `${prefix}${node.name}`,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (["attribute"].includes(node.type) && node.content) {
|
|
36
|
+
const { type, operator, head, classes, foot } = parseAttrSelector(node)
|
|
37
|
+
|
|
38
|
+
if (!["class", "id"].includes(type)) return node
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
...node,
|
|
42
|
+
content: attrStringify({
|
|
43
|
+
type,
|
|
44
|
+
operator,
|
|
45
|
+
head,
|
|
46
|
+
classes: classes.map((cls) => `${prefix}${cls}`),
|
|
47
|
+
foot,
|
|
48
|
+
}),
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return node
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function iterateSelectorNodes(selector, options) {
|
|
56
|
+
const { prefix, ignore } = options
|
|
57
|
+
return {
|
|
58
|
+
...selector,
|
|
59
|
+
nodes: selector.nodes.map((node) => {
|
|
60
|
+
if (["selector", "nested-pseudo-class"].includes(node.type)) {
|
|
61
|
+
return iterateSelectorNodes(node, options)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (itMatchesOne(ignore, Tokenizer.stringify(node))) return node
|
|
65
|
+
|
|
66
|
+
return prefixNode(node, prefix)
|
|
67
|
+
}),
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @type {import('postcss').PluginCreator}
|
|
73
|
+
*/
|
|
74
|
+
module.exports = (opts = {}) => {
|
|
75
|
+
const { prefix, ignore } = {
|
|
76
|
+
prefix: "",
|
|
77
|
+
ignore: [],
|
|
78
|
+
...opts,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (typeof prefix !== "string") {
|
|
82
|
+
throw new Error("prefix option should be of type string.")
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!Array.isArray(ignore)) {
|
|
86
|
+
throw new Error("ignore options should be an Array.")
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!prefix.length) return
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
postcssPlugin: "addprefix",
|
|
93
|
+
Root(root, postcss) {
|
|
94
|
+
root.walkRules((rule) => {
|
|
95
|
+
const parsed = Tokenizer.parse(rule.selector)
|
|
96
|
+
const selector = iterateSelectorNodes(parsed, { prefix, ignore })
|
|
97
|
+
|
|
98
|
+
rule.selector = Tokenizer.stringify(selector)
|
|
99
|
+
})
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports.postcss = true
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function createPlugin(plugin, config) {
|
|
2
|
+
return {
|
|
3
|
+
handler: plugin,
|
|
4
|
+
config,
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
createPlugin.withOptions = (pluginFunction, configFunction = () => ({})) => {
|
|
8
|
+
const optionsFunction = (options) => ({
|
|
9
|
+
__options: options,
|
|
10
|
+
handler: pluginFunction(options),
|
|
11
|
+
config: configFunction(options),
|
|
12
|
+
})
|
|
13
|
+
optionsFunction.__isOptionsFunction = true
|
|
14
|
+
optionsFunction.__pluginFunction = pluginFunction
|
|
15
|
+
optionsFunction.__configFunction = configFunction
|
|
16
|
+
return optionsFunction
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = createPlugin
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// regext for all daisyUI colors
|
|
2
|
+
// ((primary|secondary|accent|neutral)(-content|))|((info|success|warning|error)(-content|))|(base)(-100|-200|-300|-content)
|
|
3
|
+
|
|
4
|
+
// regex for all Tailwind CSS color utilities
|
|
5
|
+
// (bg|to|via|from|text|ring|fill|caret|stroke|border|divide|accent|shadow|outline|decoration|placeholder|ring-offset)
|
|
6
|
+
|
|
7
|
+
module.exports = [
|
|
8
|
+
{
|
|
9
|
+
pattern: /.*/,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
// responsive utilities for daisyUI responsive modifiers
|
|
13
|
+
pattern: /.(sm|md|lg|xl)/,
|
|
14
|
+
variants: ["sm", "md", "lg", "xl"],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
// responsive utilities for daisyUI components
|
|
18
|
+
pattern:
|
|
19
|
+
/(drawer-open|modal-(middle|top|bottom)|card-(side|compact|normal)|(stats|divider)-(horizontal|vertical)|dropdown-(end|top|bottom|left|right))/,
|
|
20
|
+
variants: ["sm", "md", "lg", "xl"],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
// color utilities for daisyUI colors
|
|
24
|
+
pattern:
|
|
25
|
+
/(bg|to|via|from|text|fill|stroke|border|outline)-((primary|secondary|accent|neutral)(-content|))|((info|success|warning|error)(-content|))|(base)(-100|-200|-300|-content)/,
|
|
26
|
+
variants: [
|
|
27
|
+
// "first",
|
|
28
|
+
// "last",
|
|
29
|
+
// "odd",
|
|
30
|
+
// "even",
|
|
31
|
+
// "visited",
|
|
32
|
+
// "checked",
|
|
33
|
+
// "empty",
|
|
34
|
+
// "read-only",
|
|
35
|
+
// "group-hover",
|
|
36
|
+
// "group-focus",
|
|
37
|
+
// "focus-within",
|
|
38
|
+
"hover",
|
|
39
|
+
"focus",
|
|
40
|
+
// "focus-visible",
|
|
41
|
+
// "active",
|
|
42
|
+
// "disabled",
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
"primary": "--p",
|
|
3
|
+
"primary-content": "--pc",
|
|
4
|
+
|
|
5
|
+
"secondary": "--s",
|
|
6
|
+
"secondary-content": "--sc",
|
|
7
|
+
|
|
8
|
+
"accent": "--a",
|
|
9
|
+
"accent-content": "--ac",
|
|
10
|
+
|
|
11
|
+
"neutral": "--n",
|
|
12
|
+
"neutral-content": "--nc",
|
|
13
|
+
|
|
14
|
+
"base-100": "--b1",
|
|
15
|
+
"base-200": "--b2",
|
|
16
|
+
"base-300": "--b3",
|
|
17
|
+
"base-content": "--bc",
|
|
18
|
+
|
|
19
|
+
"info": "--in",
|
|
20
|
+
"info-content": "--inc",
|
|
21
|
+
|
|
22
|
+
"success": "--su",
|
|
23
|
+
"success-content": "--suc",
|
|
24
|
+
|
|
25
|
+
"warning": "--wa",
|
|
26
|
+
"warning-content": "--wac",
|
|
27
|
+
|
|
28
|
+
"error": "--er",
|
|
29
|
+
"error-content": "--erc",
|
|
30
|
+
}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
const pc = require("picocolors")
|
|
2
|
+
const colorNames = require("./colorNames")
|
|
3
|
+
const themeDefaults = require("./themeDefaults")
|
|
4
|
+
|
|
5
|
+
const { oklch, interpolate, wcagContrast } = require("culori/require")
|
|
6
|
+
|
|
7
|
+
const colorIsInvalid = (input) => {
|
|
8
|
+
console.error(
|
|
9
|
+
`ââ ${pc.red("â ī¸")} ${pc.bgRed(" Error ")} Invalid color ${pc.red(input)} in ${pc.green(
|
|
10
|
+
"tailwind.config.js"
|
|
11
|
+
)}`
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
const cutNumber = (number) => {
|
|
15
|
+
try {
|
|
16
|
+
if (number) {
|
|
17
|
+
return +number.toFixed(6)
|
|
18
|
+
}
|
|
19
|
+
return 0
|
|
20
|
+
} catch (e) {
|
|
21
|
+
// colorIsInvalid(number)
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
module.exports = {
|
|
26
|
+
isDark: (color) => {
|
|
27
|
+
try {
|
|
28
|
+
if (wcagContrast(color, "black") < wcagContrast(color, "white")) {
|
|
29
|
+
return true
|
|
30
|
+
}
|
|
31
|
+
return false
|
|
32
|
+
} catch (e) {
|
|
33
|
+
// colorIsInvalid(color)
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
colorObjToString: (input) => {
|
|
39
|
+
const { l, c, h } = input
|
|
40
|
+
return `${Number.parseFloat((cutNumber(l) * 100).toFixed(6))}% ${cutNumber(c)} ${cutNumber(h)}`
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
generateForegroundColorFrom: function (input, percentage = 0.8) {
|
|
44
|
+
try {
|
|
45
|
+
const result = interpolate(
|
|
46
|
+
[input, this.isDark(input) ? "white" : "black"],
|
|
47
|
+
"oklch"
|
|
48
|
+
)(percentage)
|
|
49
|
+
return this.colorObjToString(result)
|
|
50
|
+
} catch (e) {
|
|
51
|
+
// colorIsInvalid(input)
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
generateDarkenColorFrom: function (input, percentage = 0.07) {
|
|
57
|
+
try {
|
|
58
|
+
const result = interpolate([input, "black"], "oklch")(percentage)
|
|
59
|
+
return this.colorObjToString(result)
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// colorIsInvalid(input)
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
convertColorFormat: function (input) {
|
|
67
|
+
if (typeof input !== "object" || input === null) {
|
|
68
|
+
return input
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const resultObj = {}
|
|
72
|
+
|
|
73
|
+
for (const [rule, value] of Object.entries(input)) {
|
|
74
|
+
if (Object.hasOwn(colorNames, rule)) {
|
|
75
|
+
try {
|
|
76
|
+
const colorObj = oklch(value)
|
|
77
|
+
resultObj[colorNames[rule]] = this.colorObjToString(colorObj)
|
|
78
|
+
} catch (e) {
|
|
79
|
+
colorIsInvalid(value)
|
|
80
|
+
return false
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
resultObj[rule] = value
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// auto generate base colors
|
|
87
|
+
if (!Object.hasOwn(input, "base-100")) {
|
|
88
|
+
resultObj["--b1"] = "100% 0 0"
|
|
89
|
+
}
|
|
90
|
+
if (!Object.hasOwn(input, "base-200")) {
|
|
91
|
+
resultObj["--b2"] = this.generateDarkenColorFrom(input["base-100"], 0.07)
|
|
92
|
+
}
|
|
93
|
+
if (!Object.hasOwn(input, "base-300")) {
|
|
94
|
+
if (Object.hasOwn(input, "base-200")) {
|
|
95
|
+
resultObj["--b3"] = this.generateDarkenColorFrom(input["base-200"], 0.07)
|
|
96
|
+
} else {
|
|
97
|
+
resultObj["--b3"] = this.generateDarkenColorFrom(input["base-100"], 0.14)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// auto generate state colors
|
|
102
|
+
|
|
103
|
+
if (!Object.hasOwn(input, "info")) {
|
|
104
|
+
resultObj["--in"] = "72.06% 0.191 231.6"
|
|
105
|
+
}
|
|
106
|
+
if (!Object.hasOwn(input, "success")) {
|
|
107
|
+
resultObj["--su"] = "64.8% 0.150 160"
|
|
108
|
+
}
|
|
109
|
+
if (!Object.hasOwn(input, "warning")) {
|
|
110
|
+
resultObj["--wa"] = "84.71% 0.199 83.87"
|
|
111
|
+
}
|
|
112
|
+
if (!Object.hasOwn(input, "error")) {
|
|
113
|
+
resultObj["--er"] = "71.76% 0.221 22.18"
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// auto generate content colors
|
|
117
|
+
if (!Object.hasOwn(input, "base-content")) {
|
|
118
|
+
resultObj["--bc"] = this.generateForegroundColorFrom(input["base-100"], 0.8)
|
|
119
|
+
}
|
|
120
|
+
if (!Object.hasOwn(input, "primary-content")) {
|
|
121
|
+
resultObj["--pc"] = this.generateForegroundColorFrom(input.primary, 0.8)
|
|
122
|
+
}
|
|
123
|
+
if (!Object.hasOwn(input, "secondary-content")) {
|
|
124
|
+
resultObj["--sc"] = this.generateForegroundColorFrom(input.secondary, 0.8)
|
|
125
|
+
}
|
|
126
|
+
if (!Object.hasOwn(input, "accent-content")) {
|
|
127
|
+
resultObj["--ac"] = this.generateForegroundColorFrom(input.accent, 0.8)
|
|
128
|
+
}
|
|
129
|
+
if (!Object.hasOwn(input, "neutral-content")) {
|
|
130
|
+
resultObj["--nc"] = this.generateForegroundColorFrom(input.neutral, 0.8)
|
|
131
|
+
}
|
|
132
|
+
if (!Object.hasOwn(input, "info-content")) {
|
|
133
|
+
if (Object.hasOwn(input, "info")) {
|
|
134
|
+
resultObj["--inc"] = this.generateForegroundColorFrom(input.info, 0.8)
|
|
135
|
+
} else {
|
|
136
|
+
resultObj["--inc"] = "0% 0 0"
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (!Object.hasOwn(input, "success-content")) {
|
|
140
|
+
if (Object.hasOwn(input, "success")) {
|
|
141
|
+
resultObj["--suc"] = this.generateForegroundColorFrom(input.success, 0.8)
|
|
142
|
+
} else {
|
|
143
|
+
resultObj["--suc"] = "0% 0 0"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (!Object.hasOwn(input, "warning-content")) {
|
|
147
|
+
if (Object.hasOwn(input, "warning")) {
|
|
148
|
+
resultObj["--wac"] = this.generateForegroundColorFrom(input.warning, 0.8)
|
|
149
|
+
} else {
|
|
150
|
+
resultObj["--wac"] = "0% 0 0"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (!Object.hasOwn(input, "error-content")) {
|
|
154
|
+
if (Object.hasOwn(input, "error")) {
|
|
155
|
+
resultObj["--erc"] = this.generateForegroundColorFrom(input.error, 0.8)
|
|
156
|
+
} else {
|
|
157
|
+
resultObj["--erc"] = "0% 0 0"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// add css variables if not exist
|
|
162
|
+
for (const item of Object.entries(themeDefaults.variables)) {
|
|
163
|
+
const [variable, value] = item
|
|
164
|
+
if (!Object.hasOwn(input, variable)) {
|
|
165
|
+
resultObj[variable] = value
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// add other custom styles
|
|
170
|
+
if (!Object.hasOwn(colorNames, rule)) {
|
|
171
|
+
resultObj[rule] = value
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return resultObj
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
injectThemes: function (addBase, config, themes) {
|
|
179
|
+
const includedThemesObj = {}
|
|
180
|
+
// add default themes
|
|
181
|
+
const themeRoot = config("daisyui.themeRoot") ?? ":root"
|
|
182
|
+
for (const [theme, value] of Object.entries(themes)) {
|
|
183
|
+
includedThemesObj[theme] = this.convertColorFormat(value)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// add custom themes
|
|
187
|
+
if (Array.isArray(config("daisyui.themes"))) {
|
|
188
|
+
for (const item of config("daisyui.themes")) {
|
|
189
|
+
if (typeof item === "object" && item !== null) {
|
|
190
|
+
for (const [customThemeName, customThemevalue] of Object.entries(item)) {
|
|
191
|
+
includedThemesObj[customThemeName] = this.convertColorFormat(customThemevalue)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let themeOrder = []
|
|
198
|
+
if (Array.isArray(config("daisyui.themes"))) {
|
|
199
|
+
for (const theme of config("daisyui.themes")) {
|
|
200
|
+
if (typeof theme === "object" && theme !== null) {
|
|
201
|
+
for (const customThemeName of Object.keys(theme)) {
|
|
202
|
+
themeOrder.push(customThemeName)
|
|
203
|
+
}
|
|
204
|
+
} else if (Object.hasOwn(includedThemesObj, theme)) {
|
|
205
|
+
themeOrder.push(theme)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
} else if (config("daisyui.themes") === true) {
|
|
209
|
+
themeOrder = themeDefaults.themeOrder
|
|
210
|
+
} else {
|
|
211
|
+
themeOrder = ["light", "dark"]
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// inject themes in order
|
|
215
|
+
const themesToInject = {}
|
|
216
|
+
themeOrder.forEach((themeName, index) => {
|
|
217
|
+
if (index === 0) {
|
|
218
|
+
// first theme as root
|
|
219
|
+
themesToInject[themeRoot] = includedThemesObj[themeName]
|
|
220
|
+
} else if (index === 1) {
|
|
221
|
+
// auto dark
|
|
222
|
+
if (config("daisyui.darkTheme")) {
|
|
223
|
+
if (
|
|
224
|
+
themeOrder[0] !== config("daisyui.darkTheme") &&
|
|
225
|
+
themeOrder.includes(config("daisyui.darkTheme"))
|
|
226
|
+
) {
|
|
227
|
+
themesToInject["@media (prefers-color-scheme: dark)"] = {
|
|
228
|
+
[themeRoot]: includedThemesObj[`${config("daisyui.darkTheme")}`],
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
} else if (config("daisyui.darkTheme") === false) {
|
|
232
|
+
// disables prefers-color-scheme: dark
|
|
233
|
+
} else {
|
|
234
|
+
if (themeOrder[0] !== "dark" && themeOrder.includes("dark")) {
|
|
235
|
+
themesToInject["@media (prefers-color-scheme: dark)"] = {
|
|
236
|
+
[themeRoot]: includedThemesObj.dark,
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// theme 0 with name
|
|
241
|
+
themesToInject[`[data-theme=${themeOrder[0]}]`] = includedThemesObj[themeOrder[0]]
|
|
242
|
+
themesToInject[`${themeRoot}:has(input.theme-controller[value=${themeOrder[0]}]:checked)`] =
|
|
243
|
+
includedThemesObj[themeOrder[0]]
|
|
244
|
+
// theme 1 with name
|
|
245
|
+
themesToInject[`[data-theme=${themeOrder[1]}]`] = includedThemesObj[themeOrder[1]]
|
|
246
|
+
themesToInject[`${themeRoot}:has(input.theme-controller[value=${themeOrder[1]}]:checked)`] =
|
|
247
|
+
includedThemesObj[themeOrder[1]]
|
|
248
|
+
} else {
|
|
249
|
+
themesToInject[`[data-theme=${themeName}]`] = includedThemesObj[themeName]
|
|
250
|
+
themesToInject[`${themeRoot}:has(input.theme-controller[value=${themeName}]:checked)`] =
|
|
251
|
+
includedThemesObj[themeName]
|
|
252
|
+
}
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
addBase(themesToInject)
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
includedThemesObj,
|
|
259
|
+
themeOrder,
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const colorObject = {
|
|
2
|
+
"transparent": "transparent",
|
|
3
|
+
"current": "currentColor",
|
|
4
|
+
|
|
5
|
+
"primary": "var(--fallback-p,oklch(var(--p)/<alpha-value>))",
|
|
6
|
+
"primary-content": "var(--fallback-pc,oklch(var(--pc)/<alpha-value>))",
|
|
7
|
+
|
|
8
|
+
"secondary": "var(--fallback-s,oklch(var(--s)/<alpha-value>))",
|
|
9
|
+
"secondary-content": "var(--fallback-sc,oklch(var(--sc)/<alpha-value>))",
|
|
10
|
+
|
|
11
|
+
"accent": "var(--fallback-a,oklch(var(--a)/<alpha-value>))",
|
|
12
|
+
"accent-content": "var(--fallback-ac,oklch(var(--ac)/<alpha-value>))",
|
|
13
|
+
|
|
14
|
+
"neutral": "var(--fallback-n,oklch(var(--n)/<alpha-value>))",
|
|
15
|
+
"neutral-content": "var(--fallback-nc,oklch(var(--nc)/<alpha-value>))",
|
|
16
|
+
|
|
17
|
+
"base-100": "var(--fallback-b1,oklch(var(--b1)/<alpha-value>))",
|
|
18
|
+
"base-200": "var(--fallback-b2,oklch(var(--b2)/<alpha-value>))",
|
|
19
|
+
"base-300": "var(--fallback-b3,oklch(var(--b3)/<alpha-value>))",
|
|
20
|
+
"base-content": "var(--fallback-bc,oklch(var(--bc)/<alpha-value>))",
|
|
21
|
+
|
|
22
|
+
"info": "var(--fallback-in,oklch(var(--in)/<alpha-value>))",
|
|
23
|
+
"info-content": "var(--fallback-inc,oklch(var(--inc)/<alpha-value>))",
|
|
24
|
+
|
|
25
|
+
"success": "var(--fallback-su,oklch(var(--su)/<alpha-value>))",
|
|
26
|
+
"success-content": "var(--fallback-suc,oklch(var(--suc)/<alpha-value>))",
|
|
27
|
+
|
|
28
|
+
"warning": "var(--fallback-wa,oklch(var(--wa)/<alpha-value>))",
|
|
29
|
+
"warning-content": "var(--fallback-wac,oklch(var(--wac)/<alpha-value>))",
|
|
30
|
+
|
|
31
|
+
"error": "var(--fallback-er,oklch(var(--er)/<alpha-value>))",
|
|
32
|
+
"error-content": "var(--fallback-erc,oklch(var(--erc)/<alpha-value>))",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = colorObject
|