@trackunit/css-tailwind-custom-properties-plugin 0.0.21 → 0.0.23
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.cjs +101 -51
- package/index.js +103 -49
- package/package.json +4 -1
- package/src/index.d.ts +2 -2
- package/src/plugin.d.ts +4 -4
- package/src/variablesToCSSRules.d.ts +29 -29
package/index.cjs
CHANGED
|
@@ -2,62 +2,112 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var createPlugin$2 = {};
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
var createPlugin$1 = {};
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
(function (exports) {
|
|
10
|
+
Object.defineProperty(exports, "__esModule", {
|
|
11
|
+
value: true
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "default", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: ()=>_default
|
|
16
|
+
});
|
|
17
|
+
function createPlugin(plugin, config) {
|
|
18
|
+
return {
|
|
19
|
+
handler: plugin,
|
|
20
|
+
config
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
createPlugin.withOptions = function(pluginFunction, configFunction = ()=>({})) {
|
|
24
|
+
const optionsFunction = function(options) {
|
|
25
|
+
return {
|
|
26
|
+
__options: options,
|
|
27
|
+
handler: pluginFunction(options),
|
|
28
|
+
config: configFunction(options)
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
optionsFunction.__isOptionsFunction = true;
|
|
32
|
+
// Expose plugin dependencies so that `object-hash` returns a different
|
|
33
|
+
// value if anything here changes, to ensure a rebuild is triggered.
|
|
34
|
+
optionsFunction.__pluginFunction = pluginFunction;
|
|
35
|
+
optionsFunction.__configFunction = configFunction;
|
|
36
|
+
return optionsFunction;
|
|
37
|
+
};
|
|
38
|
+
const _default = createPlugin;
|
|
39
|
+
}(createPlugin$1));
|
|
40
|
+
|
|
41
|
+
(function (exports) {
|
|
42
|
+
Object.defineProperty(exports, "__esModule", {
|
|
43
|
+
value: true
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "default", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: ()=>_default
|
|
48
|
+
});
|
|
49
|
+
const _createPlugin = /*#__PURE__*/ _interopRequireDefault(createPlugin$1);
|
|
50
|
+
function _interopRequireDefault(obj) {
|
|
51
|
+
return obj && obj.__esModule ? obj : {
|
|
52
|
+
default: obj
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const _default = _createPlugin.default;
|
|
56
|
+
}(createPlugin$2));
|
|
10
57
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
flattend
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
[
|
|
53
|
-
}
|
|
54
|
-
|
|
58
|
+
let createPlugin = createPlugin$2;
|
|
59
|
+
var plugin = (createPlugin.__esModule ? createPlugin : { default: createPlugin }).default;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Converts an array of keys to a valid CSS custom property name.
|
|
63
|
+
*
|
|
64
|
+
* @param keys An array of strings representing the keys to be converted to a CSS custom property name.
|
|
65
|
+
* @returns { string } A string representing the CSS custom property name.
|
|
66
|
+
*/
|
|
67
|
+
const keysToCssVariableName = (keys) => `--${keys.join("-")}`.replace(/[^a-zA-Z0-9]/g, "-");
|
|
68
|
+
/**
|
|
69
|
+
* Flattens a nested object containing variables declarations and their values
|
|
70
|
+
* into a flat object where the keys are the CSS variable names and the values are
|
|
71
|
+
* the corresponding CSS variable values.
|
|
72
|
+
*
|
|
73
|
+
* @param {object} values - The object containing the nested variables declarations and their values
|
|
74
|
+
* @param {object} [output] - The flat object to store the generated CSS variable names and values
|
|
75
|
+
* @param {string[]} [keys] - An array of keys representing the current path of the object being processed
|
|
76
|
+
* @returns {VariablesDeclerationObject} - The generated flat object containing the CSS variable names and values
|
|
77
|
+
*/
|
|
78
|
+
const flattenVariablesDeclerationValues = (values, output = {}, keys = []) => {
|
|
79
|
+
for (const [key, value] of Object.entries(values)) {
|
|
80
|
+
let flattend = {};
|
|
81
|
+
if (typeof value === "object") {
|
|
82
|
+
flattend = flattenVariablesDeclerationValues(value, output, [...keys, key]);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
flattend[keysToCssVariableName([...keys, key])] = value;
|
|
86
|
+
}
|
|
87
|
+
output = Object.assign(Object.assign({}, flattend), output);
|
|
88
|
+
}
|
|
89
|
+
return output;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Converts a object containing CSS variables to an array of CSS rules.
|
|
93
|
+
*
|
|
94
|
+
* @param variablesDecleration An object containing the CSS variables and their corresponding values.
|
|
95
|
+
* @returns {CSSRuleObject[]} An array of CSS rules.
|
|
96
|
+
*/
|
|
97
|
+
const variablesToCSSRules = (variablesDecleration) => {
|
|
98
|
+
if (!variablesDecleration) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
const cssRules = Object.entries(variablesDecleration).map(([key, value]) => ({
|
|
102
|
+
[key === "DEFAULT" ? ":root" : `.${key}`]: flattenVariablesDeclerationValues(value),
|
|
103
|
+
}));
|
|
104
|
+
return cssRules;
|
|
55
105
|
};
|
|
56
106
|
|
|
57
|
-
const CssTailwindCustomPropertiesPlugin =
|
|
58
|
-
const variablesDeclerationFromThemeConfig = theme("variables", {});
|
|
59
|
-
const cssRules = variablesToCSSRules(variablesDeclerationFromThemeConfig);
|
|
60
|
-
addBase(cssRules);
|
|
107
|
+
const CssTailwindCustomPropertiesPlugin = plugin(({ addBase, theme }) => {
|
|
108
|
+
const variablesDeclerationFromThemeConfig = theme("variables", {});
|
|
109
|
+
const cssRules = variablesToCSSRules(variablesDeclerationFromThemeConfig);
|
|
110
|
+
addBase(cssRules);
|
|
61
111
|
});
|
|
62
112
|
|
|
63
113
|
exports.CssTailwindCustomPropertiesPlugin = CssTailwindCustomPropertiesPlugin;
|
package/index.js
CHANGED
|
@@ -1,55 +1,109 @@
|
|
|
1
|
-
|
|
1
|
+
var createPlugin$2 = {};
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
3
|
+
var createPlugin$1 = {};
|
|
4
|
+
|
|
5
|
+
(function (exports) {
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(exports, "default", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: ()=>_default
|
|
12
|
+
});
|
|
13
|
+
function createPlugin(plugin, config) {
|
|
14
|
+
return {
|
|
15
|
+
handler: plugin,
|
|
16
|
+
config
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
createPlugin.withOptions = function(pluginFunction, configFunction = ()=>({})) {
|
|
20
|
+
const optionsFunction = function(options) {
|
|
21
|
+
return {
|
|
22
|
+
__options: options,
|
|
23
|
+
handler: pluginFunction(options),
|
|
24
|
+
config: configFunction(options)
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
optionsFunction.__isOptionsFunction = true;
|
|
28
|
+
// Expose plugin dependencies so that `object-hash` returns a different
|
|
29
|
+
// value if anything here changes, to ensure a rebuild is triggered.
|
|
30
|
+
optionsFunction.__pluginFunction = pluginFunction;
|
|
31
|
+
optionsFunction.__configFunction = configFunction;
|
|
32
|
+
return optionsFunction;
|
|
33
|
+
};
|
|
34
|
+
const _default = createPlugin;
|
|
35
|
+
}(createPlugin$1));
|
|
36
|
+
|
|
37
|
+
(function (exports) {
|
|
38
|
+
Object.defineProperty(exports, "__esModule", {
|
|
39
|
+
value: true
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports, "default", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: ()=>_default
|
|
44
|
+
});
|
|
45
|
+
const _createPlugin = /*#__PURE__*/ _interopRequireDefault(createPlugin$1);
|
|
46
|
+
function _interopRequireDefault(obj) {
|
|
47
|
+
return obj && obj.__esModule ? obj : {
|
|
48
|
+
default: obj
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const _default = _createPlugin.default;
|
|
52
|
+
}(createPlugin$2));
|
|
53
|
+
|
|
54
|
+
let createPlugin = createPlugin$2;
|
|
55
|
+
var plugin = (createPlugin.__esModule ? createPlugin : { default: createPlugin }).default;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Converts an array of keys to a valid CSS custom property name.
|
|
59
|
+
*
|
|
60
|
+
* @param keys An array of strings representing the keys to be converted to a CSS custom property name.
|
|
61
|
+
* @returns { string } A string representing the CSS custom property name.
|
|
62
|
+
*/
|
|
63
|
+
const keysToCssVariableName = (keys) => `--${keys.join("-")}`.replace(/[^a-zA-Z0-9]/g, "-");
|
|
64
|
+
/**
|
|
65
|
+
* Flattens a nested object containing variables declarations and their values
|
|
66
|
+
* into a flat object where the keys are the CSS variable names and the values are
|
|
67
|
+
* the corresponding CSS variable values.
|
|
68
|
+
*
|
|
69
|
+
* @param {object} values - The object containing the nested variables declarations and their values
|
|
70
|
+
* @param {object} [output] - The flat object to store the generated CSS variable names and values
|
|
71
|
+
* @param {string[]} [keys] - An array of keys representing the current path of the object being processed
|
|
72
|
+
* @returns {VariablesDeclerationObject} - The generated flat object containing the CSS variable names and values
|
|
73
|
+
*/
|
|
74
|
+
const flattenVariablesDeclerationValues = (values, output = {}, keys = []) => {
|
|
75
|
+
for (const [key, value] of Object.entries(values)) {
|
|
76
|
+
let flattend = {};
|
|
77
|
+
if (typeof value === "object") {
|
|
78
|
+
flattend = flattenVariablesDeclerationValues(value, output, [...keys, key]);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
flattend[keysToCssVariableName([...keys, key])] = value;
|
|
82
|
+
}
|
|
83
|
+
output = Object.assign(Object.assign({}, flattend), output);
|
|
84
|
+
}
|
|
85
|
+
return output;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Converts a object containing CSS variables to an array of CSS rules.
|
|
89
|
+
*
|
|
90
|
+
* @param variablesDecleration An object containing the CSS variables and their corresponding values.
|
|
91
|
+
* @returns {CSSRuleObject[]} An array of CSS rules.
|
|
92
|
+
*/
|
|
93
|
+
const variablesToCSSRules = (variablesDecleration) => {
|
|
94
|
+
if (!variablesDecleration) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
const cssRules = Object.entries(variablesDecleration).map(([key, value]) => ({
|
|
98
|
+
[key === "DEFAULT" ? ":root" : `.${key}`]: flattenVariablesDeclerationValues(value),
|
|
99
|
+
}));
|
|
100
|
+
return cssRules;
|
|
47
101
|
};
|
|
48
102
|
|
|
49
|
-
const CssTailwindCustomPropertiesPlugin = plugin(({ addBase, theme }) => {
|
|
50
|
-
const variablesDeclerationFromThemeConfig = theme("variables", {});
|
|
51
|
-
const cssRules = variablesToCSSRules(variablesDeclerationFromThemeConfig);
|
|
52
|
-
addBase(cssRules);
|
|
103
|
+
const CssTailwindCustomPropertiesPlugin = plugin(({ addBase, theme }) => {
|
|
104
|
+
const variablesDeclerationFromThemeConfig = theme("variables", {});
|
|
105
|
+
const cssRules = variablesToCSSRules(variablesDeclerationFromThemeConfig);
|
|
106
|
+
addBase(cssRules);
|
|
53
107
|
});
|
|
54
108
|
|
|
55
109
|
export { CssTailwindCustomPropertiesPlugin, flattenVariablesDeclerationValues, keysToCssVariableName, variablesToCSSRules };
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/css-tailwind-custom-properties-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"main": "./index.cjs",
|
|
5
5
|
"repository": "https://github.com/Trackunit/manager",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=16.x"
|
|
9
|
+
},
|
|
7
10
|
"module": "./index.js",
|
|
8
11
|
"type": "module",
|
|
9
12
|
"types": "./src/index.d.ts"
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./plugin";
|
|
2
|
-
export * from "./variablesToCSSRules";
|
|
1
|
+
export * from "./plugin";
|
|
2
|
+
export * from "./variablesToCSSRules";
|
package/src/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const CssTailwindCustomPropertiesPlugin: {
|
|
2
|
-
handler: import("tailwindcss/types/config").PluginCreator;
|
|
3
|
-
config?: Partial<import("tailwindcss/types/config").Config> | undefined;
|
|
4
|
-
};
|
|
1
|
+
export declare const CssTailwindCustomPropertiesPlugin: {
|
|
2
|
+
handler: import("tailwindcss/types/config").PluginCreator;
|
|
3
|
+
config?: Partial<import("tailwindcss/types/config").Config> | undefined;
|
|
4
|
+
};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { CSSRuleObject } from "tailwindcss/types/config";
|
|
2
|
-
export type VariablesDeclerationObject = {
|
|
3
|
-
[variableName: string]: string;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Converts an array of keys to a valid CSS custom property name.
|
|
7
|
-
*
|
|
8
|
-
* @param keys An array of strings representing the keys to be converted to a CSS custom property name.
|
|
9
|
-
* @returns { string } A string representing the CSS custom property name.
|
|
10
|
-
*/
|
|
11
|
-
export declare const keysToCssVariableName: (keys: string[]) => string;
|
|
12
|
-
/**
|
|
13
|
-
* Flattens a nested object containing variables declarations and their values
|
|
14
|
-
* into a flat object where the keys are the CSS variable names and the values are
|
|
15
|
-
* the corresponding CSS variable values.
|
|
16
|
-
*
|
|
17
|
-
* @param {object} values - The object containing the nested variables declarations and their values
|
|
18
|
-
* @param {object} [output] - The flat object to store the generated CSS variable names and values
|
|
19
|
-
* @param {string[]} [keys] - An array of keys representing the current path of the object being processed
|
|
20
|
-
* @returns {VariablesDeclerationObject} - The generated flat object containing the CSS variable names and values
|
|
21
|
-
*/
|
|
22
|
-
export declare const flattenVariablesDeclerationValues: (values: object, output?: VariablesDeclerationObject, keys?: string[]) => VariablesDeclerationObject;
|
|
23
|
-
/**
|
|
24
|
-
* Converts a object containing CSS variables to an array of CSS rules.
|
|
25
|
-
*
|
|
26
|
-
* @param variablesDecleration An object containing the CSS variables and their corresponding values.
|
|
27
|
-
* @returns {CSSRuleObject[]} An array of CSS rules.
|
|
28
|
-
*/
|
|
29
|
-
export declare const variablesToCSSRules: (variablesDecleration: object) => CSSRuleObject[];
|
|
1
|
+
import { CSSRuleObject } from "tailwindcss/types/config";
|
|
2
|
+
export type VariablesDeclerationObject = {
|
|
3
|
+
[variableName: string]: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Converts an array of keys to a valid CSS custom property name.
|
|
7
|
+
*
|
|
8
|
+
* @param keys An array of strings representing the keys to be converted to a CSS custom property name.
|
|
9
|
+
* @returns { string } A string representing the CSS custom property name.
|
|
10
|
+
*/
|
|
11
|
+
export declare const keysToCssVariableName: (keys: string[]) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Flattens a nested object containing variables declarations and their values
|
|
14
|
+
* into a flat object where the keys are the CSS variable names and the values are
|
|
15
|
+
* the corresponding CSS variable values.
|
|
16
|
+
*
|
|
17
|
+
* @param {object} values - The object containing the nested variables declarations and their values
|
|
18
|
+
* @param {object} [output] - The flat object to store the generated CSS variable names and values
|
|
19
|
+
* @param {string[]} [keys] - An array of keys representing the current path of the object being processed
|
|
20
|
+
* @returns {VariablesDeclerationObject} - The generated flat object containing the CSS variable names and values
|
|
21
|
+
*/
|
|
22
|
+
export declare const flattenVariablesDeclerationValues: (values: object, output?: VariablesDeclerationObject, keys?: string[]) => VariablesDeclerationObject;
|
|
23
|
+
/**
|
|
24
|
+
* Converts a object containing CSS variables to an array of CSS rules.
|
|
25
|
+
*
|
|
26
|
+
* @param variablesDecleration An object containing the CSS variables and their corresponding values.
|
|
27
|
+
* @returns {CSSRuleObject[]} An array of CSS rules.
|
|
28
|
+
*/
|
|
29
|
+
export declare const variablesToCSSRules: (variablesDecleration: object) => CSSRuleObject[];
|