daisyui 2.3.7-alpha.3 → 2.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "daisyui",
3
- "version": "2.3.7-alpha.3",
3
+ "version": "2.4.0",
4
4
  "description": "daisyUI - Tailwind CSS Components",
5
5
  "author": "Pouya Saadeghi",
6
6
  "license": "MIT",
@@ -29,6 +29,7 @@
29
29
  "main": "src/index.js",
30
30
  "typings": "src/index.js",
31
31
  "files": [
32
+ "src/lib/**/*.js",
32
33
  "dist/*.js",
33
34
  "dist/{themes,styled,unstyled,full}.css",
34
35
  "!dist/*.rtl.css",
@@ -0,0 +1,87 @@
1
+ const Tokenizer = require('css-selector-tokenizer');
2
+ const {
3
+ parseAttrSelector,
4
+ attrStringify,
5
+ itMatchesOne,
6
+ } = require('./utils');
7
+
8
+ function prefixNode(node, prefix) {
9
+ if (['class', 'id'].includes(node.type)) {
10
+ return {
11
+ ...node,
12
+ name: `${prefix}${node.name}`,
13
+ };
14
+ }
15
+
16
+ if (['attribute'].includes(node.type) && node.content) {
17
+ const {
18
+ type, operator, head, classes, foot,
19
+ } = parseAttrSelector(node);
20
+
21
+ if (!['class', 'id'].includes(type)) return node;
22
+
23
+ return {
24
+ ...node,
25
+ content: attrStringify({
26
+ type,
27
+ operator,
28
+ head,
29
+ classes: classes.map((cls) => `${prefix}${cls}`),
30
+ foot,
31
+ }),
32
+ }
33
+ }
34
+
35
+ return node;
36
+ }
37
+
38
+ function iterateSelectorNodes(selector, options) {
39
+ const { prefix, ignore } = options;
40
+ return {
41
+ ...selector,
42
+ nodes: selector.nodes.map((node) => {
43
+ if (['selector', 'nested-pseudo-class'].includes(node.type)) {
44
+ return iterateSelectorNodes(node, options);
45
+ }
46
+
47
+ if (itMatchesOne(ignore, Tokenizer.stringify(node))) return node;
48
+
49
+ return prefixNode(node, prefix);
50
+ }),
51
+ };
52
+ }
53
+
54
+ /**
55
+ * @type {import('postcss').PluginCreator}
56
+ */
57
+ module.exports = (opts = {}) => {
58
+ const { prefix, ignore } = {
59
+ prefix: '',
60
+ ignore: [],
61
+ ...opts,
62
+ };
63
+
64
+ if (typeof prefix !== 'string') {
65
+ throw new Error('@postcss-prefix: prefix option should be of type string.');
66
+ }
67
+
68
+ if (!Array.isArray(ignore)) {
69
+ throw new Error('@postcss-prefix: ignore options should be an Array.');
70
+ }
71
+
72
+ if (!prefix.length) return;
73
+
74
+ return {
75
+ postcssPlugin: 'postcss-prefixer',
76
+ Root(root, postcss) {
77
+ root.walkRules((rule) => {
78
+ const parsed = Tokenizer.parse(rule.selector);
79
+ const selector = iterateSelectorNodes(parsed, { prefix, ignore });
80
+
81
+ rule.selector = Tokenizer.stringify(selector);
82
+ });
83
+ },
84
+ };
85
+ }
86
+
87
+ module.exports.postcss = true
@@ -0,0 +1,29 @@
1
+ module.exports = {
2
+
3
+ itMatchesOne(arr, term) {
4
+ return arr.some((i) => term.search(i) >= 0);
5
+ },
6
+
7
+ parseAttrSelector(node) {
8
+ const { content } = node;
9
+ const regex = /(^class|^id)([*^?~|$=]*)+(?:("\s*)([^"\\]*?(?:\\.[^"\\]*)*?)(\s*")|('\s*)([^'\\]*?(?:\\.[^'\\]*)*?)(\s*'))/i;
10
+
11
+ const [type, operator, head, classes, foot] = content
12
+ .split(regex)
13
+ .filter((part) => part);
14
+
15
+ return {
16
+ type,
17
+ operator,
18
+ head,
19
+ classes: classes ? classes.split(' ').map((c) => c.replace(/"|'/g, '')) : [],
20
+ foot,
21
+ };
22
+ },
23
+
24
+ attrStringify({
25
+ type, operator, head, classes, foot,
26
+ }) {
27
+ return `${type}${operator || ''}${head || ''}${classes.join(' ')}${foot || ''}`;
28
+ },
29
+ };
@@ -0,0 +1 @@
1
+ module.exports = { pattern: /.(sm|md|lg|xl)/, variants: ["sm", "md", "lg", "xl"] };