@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 ADDED
@@ -0,0 +1,122 @@
1
+ import type plugin from "tailwindcss/plugin"
2
+
3
+ declare const daisyui: ReturnType<typeof plugin>
4
+
5
+ export default daisyui
6
+
7
+ // todo - the keys of a theme could be typed here? see: https://daisyui.com/docs/themes/#-5
8
+ /**
9
+ * @link https://daisyui.com/docs/themes/#-4
10
+ */
11
+ type CustomTheme = Record<string, Record<string, string>>
12
+
13
+ /**
14
+ * https://daisyui.com/docs/themes/#
15
+ */
16
+ type Theme =
17
+ | "light"
18
+ | "dark"
19
+ | "cupcake"
20
+ | "bumblebee"
21
+ | "emerald"
22
+ | "corporate"
23
+ | "synthwave"
24
+ | "retro"
25
+ | "cyberpunk"
26
+ | "valentine"
27
+ | "halloween"
28
+ | "garden"
29
+ | "forest"
30
+ | "aqua"
31
+ | "lofi"
32
+ | "pastel"
33
+ | "fantasy"
34
+ | "wireframe"
35
+ | "black"
36
+ | "luxury"
37
+ | "dracula"
38
+ | "cmyk"
39
+ | "autumn"
40
+ | "business"
41
+ | "acid"
42
+ | "lemonade"
43
+ | "night"
44
+ | "coffee"
45
+ | "winter"
46
+ | "dim"
47
+ | "nord"
48
+ | "sunset"
49
+
50
+ interface DaisyUIConfig {
51
+ /**
52
+ * If it's true, all themes will be included. If it's false, only light and dark themes will be available.
53
+ * If it's an array, only themes in the array will be included and the first theme will be the default theme.
54
+ * Read more about [themes](https://daisyui.com/docs/themes/).
55
+ *
56
+ * @default false
57
+ */
58
+ themes?: boolean | (Theme | CustomTheme)[]
59
+ /**
60
+ * Allows us to pick another theme for the system's auto dark mode. By default, dark theme
61
+ * (or a custom theme named dark) will be the default theme if no theme is specified and
62
+ * the user is using dark mode on their system.
63
+ * With this config, you can set another theme to be the default dark mode theme.
64
+ *
65
+ * @default 'dark'
66
+ */
67
+ darkTheme?: string
68
+ /**
69
+ * If it's true, a [few base styles](https://github.com/saadeghi/daisyui/blob/master/src/base) will be added.
70
+ *
71
+ * @default true
72
+ */
73
+ base?: boolean
74
+ /**
75
+ * If it's true, components will have colors and style, so you won't need to design anything.
76
+ * If it's false, components will have no color and no visual style, so you can design your own style
77
+ * on a basic skeleton.
78
+ *
79
+ * @default true
80
+ */
81
+ styled?: boolean
82
+ /**
83
+ * If it's true, [responsive and utility classes](https://github.com/saadeghi/daisyui/tree/master/src/utilities) will be added.
84
+ *
85
+ * @default true
86
+ */
87
+ utils?: boolean
88
+ /**
89
+ * If it's true, your theme will be right-to-left. You need to add `dir='rtl'` to your body tag.
90
+ * If you're using daisyUI with RTL option, I suggest using [tailwindcss-flip](https://github.com/cvrajeesh/tailwindcss-flip)
91
+ * plugin to flip all your Tailwind utilities automatically.
92
+ *
93
+ * @default false
94
+ */
95
+ rtl?: boolean
96
+ /**
97
+ * Adds a prefix to class name for all daisyUI classes (including component classes, modifier classes and responsive
98
+ * classes). For example, `btn` will become `prefix-btn`. If you're using a second CSS library that has similar
99
+ * class names, you can use this config to avoid conflicts. Utility classes like color names (e.g. `bg-primary`)
100
+ * or border-radius (e.g. `rounded-box`) will not be affected by this config because they're being added
101
+ * as extensions to Tailwind CSS classes. If you use daisyUI `prefix` option (like `daisy-`) and
102
+ * Tailwind CSS `prefix` option (like `tw-`) together, classnames will be prefixed like
103
+ * this: `tw-daisy-btn`.
104
+ *
105
+ * @default ''
106
+ */
107
+ prefix?: string
108
+ /**
109
+ * If it's true, daisyUI shows logs in the terminal while CSS is building.
110
+ *
111
+ * @default true
112
+ */
113
+ logs?: boolean
114
+ /**
115
+ * The element that receives theme color CSS variables
116
+ *
117
+ * @default ':root'
118
+ */
119
+ themeRoot?: string
120
+ }
121
+
122
+ export type { DaisyUIConfig as Config, Theme, CustomTheme }
package/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,7 @@
1
+ module.exports = {
2
+ borderRadius: {
3
+ badge: "var(--rounded-badge, 1.9rem)",
4
+ btn: "var(--rounded-btn, 0.5rem)",
5
+ box: "var(--rounded-box, 1rem)",
6
+ },
7
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@macroui/macroui",
4
- "version": "4.0.2",
4
+ "version": "4.0.3",
5
5
  "description": "Macroui - Tailwind CSS Component Library",
6
6
  "author": "Macroui <peng.deyou@gmail.com>",
7
7
  "license": "MIT",
@@ -30,17 +30,22 @@
30
30
  "module": "./dist/index.js",
31
31
  "types": "./dist/index.d.ts",
32
32
  "exports": {
33
- "./dist/*": "./dist/*",
34
- "./full.css": "./dist/full.css",
35
33
  ".": {
36
34
  "import": "./dist/index.js",
37
35
  "require": "./dist/index.js",
38
36
  "types": "./dist/index.d.ts"
39
- }
37
+ },
38
+ "./dist/*": "./dist/*",
39
+ "./full.css": "./dist/full.css",
40
+ "./styled.css": "./dist/styled.css"
40
41
  },
41
42
  "files": [
42
43
  "dist",
43
- "src"
44
+ "src",
45
+ "lib",
46
+ "theming",
47
+ "index.js",
48
+ "index.d.ts"
44
49
  ],
45
50
  "peerDependencies": {
46
51
  "tailwindcss": ">=3.3.0"
@@ -0,0 +1,122 @@
1
+ import type plugin from "tailwindcss/plugin"
2
+
3
+ declare const daisyui: ReturnType<typeof plugin>
4
+
5
+ export default daisyui
6
+
7
+ // todo - the keys of a theme could be typed here? see: https://daisyui.com/docs/themes/#-5
8
+ /**
9
+ * @link https://daisyui.com/docs/themes/#-4
10
+ */
11
+ type CustomTheme = Record<string, Record<string, string>>
12
+
13
+ /**
14
+ * https://daisyui.com/docs/themes/#
15
+ */
16
+ type Theme =
17
+ | "light"
18
+ | "dark"
19
+ | "cupcake"
20
+ | "bumblebee"
21
+ | "emerald"
22
+ | "corporate"
23
+ | "synthwave"
24
+ | "retro"
25
+ | "cyberpunk"
26
+ | "valentine"
27
+ | "halloween"
28
+ | "garden"
29
+ | "forest"
30
+ | "aqua"
31
+ | "lofi"
32
+ | "pastel"
33
+ | "fantasy"
34
+ | "wireframe"
35
+ | "black"
36
+ | "luxury"
37
+ | "dracula"
38
+ | "cmyk"
39
+ | "autumn"
40
+ | "business"
41
+ | "acid"
42
+ | "lemonade"
43
+ | "night"
44
+ | "coffee"
45
+ | "winter"
46
+ | "dim"
47
+ | "nord"
48
+ | "sunset"
49
+
50
+ interface DaisyUIConfig {
51
+ /**
52
+ * If it's true, all themes will be included. If it's false, only light and dark themes will be available.
53
+ * If it's an array, only themes in the array will be included and the first theme will be the default theme.
54
+ * Read more about [themes](https://daisyui.com/docs/themes/).
55
+ *
56
+ * @default false
57
+ */
58
+ themes?: boolean | (Theme | CustomTheme)[]
59
+ /**
60
+ * Allows us to pick another theme for the system's auto dark mode. By default, dark theme
61
+ * (or a custom theme named dark) will be the default theme if no theme is specified and
62
+ * the user is using dark mode on their system.
63
+ * With this config, you can set another theme to be the default dark mode theme.
64
+ *
65
+ * @default 'dark'
66
+ */
67
+ darkTheme?: string
68
+ /**
69
+ * If it's true, a [few base styles](https://github.com/saadeghi/daisyui/blob/master/src/base) will be added.
70
+ *
71
+ * @default true
72
+ */
73
+ base?: boolean
74
+ /**
75
+ * If it's true, components will have colors and style, so you won't need to design anything.
76
+ * If it's false, components will have no color and no visual style, so you can design your own style
77
+ * on a basic skeleton.
78
+ *
79
+ * @default true
80
+ */
81
+ styled?: boolean
82
+ /**
83
+ * If it's true, [responsive and utility classes](https://github.com/saadeghi/daisyui/tree/master/src/utilities) will be added.
84
+ *
85
+ * @default true
86
+ */
87
+ utils?: boolean
88
+ /**
89
+ * If it's true, your theme will be right-to-left. You need to add `dir='rtl'` to your body tag.
90
+ * If you're using daisyUI with RTL option, I suggest using [tailwindcss-flip](https://github.com/cvrajeesh/tailwindcss-flip)
91
+ * plugin to flip all your Tailwind utilities automatically.
92
+ *
93
+ * @default false
94
+ */
95
+ rtl?: boolean
96
+ /**
97
+ * Adds a prefix to class name for all daisyUI classes (including component classes, modifier classes and responsive
98
+ * classes). For example, `btn` will become `prefix-btn`. If you're using a second CSS library that has similar
99
+ * class names, you can use this config to avoid conflicts. Utility classes like color names (e.g. `bg-primary`)
100
+ * or border-radius (e.g. `rounded-box`) will not be affected by this config because they're being added
101
+ * as extensions to Tailwind CSS classes. If you use daisyUI `prefix` option (like `daisy-`) and
102
+ * Tailwind CSS `prefix` option (like `tw-`) together, classnames will be prefixed like
103
+ * this: `tw-daisy-btn`.
104
+ *
105
+ * @default ''
106
+ */
107
+ prefix?: string
108
+ /**
109
+ * If it's true, daisyUI shows logs in the terminal while CSS is building.
110
+ *
111
+ * @default true
112
+ */
113
+ logs?: boolean
114
+ /**
115
+ * The element that receives theme color CSS variables
116
+ *
117
+ * @default ':root'
118
+ */
119
+ themeRoot?: string
120
+ }
121
+
122
+ export type { DaisyUIConfig as Config, Theme, CustomTheme }