bernova 0.0.2
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/LICENSE +201 -0
- package/README.md +1778 -0
- package/dist/bin/bernova.js +2 -0
- package/dist/bin/buildstyle.js +2 -0
- package/dist/bin/createConfigFile.js +2 -0
- package/dist/bin/declareCssType.js +1 -0
- package/dist/index.js +1 -0
- package/dist/src/app.js +1 -0
- package/dist/src/constants/compilerType.js +1 -0
- package/dist/src/constants/cssAdvancedSelectors.js +1 -0
- package/dist/src/constants/cssProps.js +1 -0
- package/dist/src/constants/cssPseudoClasses.js +1 -0
- package/dist/src/constants/cssPseudoElements.js +1 -0
- package/dist/src/constants/index.js +1 -0
- package/dist/src/constants/resetCss.js +1 -0
- package/dist/src/index.d.ts +31 -0
- package/dist/src/index.js +1 -0
- package/dist/src/lib/compileConfig.js +1 -0
- package/dist/src/lib/compileThemes.js +1 -0
- package/dist/src/lib/copyLocalFonts/copyLocalFonts.utils.js +1 -0
- package/dist/src/lib/copyLocalFonts/generateCssFonts.utils.js +1 -0
- package/dist/src/lib/extractDocFragment/extractDocFragment.utils.js +1 -0
- package/dist/src/lib/fileExists/fileExists.utils.js +1 -0
- package/dist/src/lib/generateBaseCss/generateBaseCss.utils.js +1 -0
- package/dist/src/lib/generateCss/generateCSS.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/advanceselector/advancedSelectorHandler.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/attribute/attributeHandler.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/classnames/formatClassName.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/cssVars/generateVars.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/dynamicValues/dynamicValues.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/dynamicValues/processDynamic.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/filterGenerateCss.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/foreign/foreignHandler.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/generateCssStyles.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/index.js +1 -0
- package/dist/src/lib/generateCss/helpers/mediaqueries/generateMediaQueries.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/mediaqueries/mediaQueriesHandler.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/other/declareCssType.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/other/generateGlobalStyles.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/pseudo/pseudoHandler.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/utils/extractValues.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/utils/formattedStatKey.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/utils/index.js +1 -0
- package/dist/src/lib/generateCss/helpers/utils/processCss.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/utils/separateStyles.utils.js +1 -0
- package/dist/src/lib/generateCss/helpers/utils/validatePreviouslyExists.utils.js +1 -0
- package/dist/src/lib/generateCssDoc/generateCssDoc.util.js +1 -0
- package/dist/src/lib/generateProvider/generateProvider.utils.js +1 -0
- package/dist/src/lib/generateProvider/template/providerTemplate.d.ts +60 -0
- package/dist/src/lib/generateProvider/template/providerTemplate.js +1 -0
- package/dist/src/lib/generateThemeRegister/generateThemeRegister.utils.js +1 -0
- package/dist/src/lib/generateTools/generateTools.utils.js +1 -0
- package/dist/src/lib/generateTypesTools/generateTypesTools.utils.js +1 -0
- package/dist/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +1 -0
- package/dist/src/lib/index.js +1 -0
- package/dist/src/lib/processMediaConfig/processMediaConfig.util.js +1 -0
- package/dist/src/lib/readFile/readFile.utils.js +1 -0
- package/dist/src/lib/simplifyName/simplifyName.utils.js +1 -0
- package/dist/src/lib/typingStyles/index.js +1 -0
- package/dist/src/lib/typingStyles/typingStyles.utils.js +1 -0
- package/dist/src/lib/writeDoc/writeDoc.utils.js +1 -0
- package/package.json +80 -0
- package/src/app.js +176 -0
- package/src/constants/__tests__/compilerType.test.js +20 -0
- package/src/constants/__tests__/cssAdvancedSelectors.test.js +38 -0
- package/src/constants/__tests__/cssProps.test.js +331 -0
- package/src/constants/__tests__/cssPseudoClasses.test.js +48 -0
- package/src/constants/compilerType.js +14 -0
- package/src/constants/cssAdvancedSelectors.js +32 -0
- package/src/constants/cssProps.js +325 -0
- package/src/constants/cssPseudoClasses.js +138 -0
- package/src/constants/cssPseudoElements.js +83 -0
- package/src/constants/index.js +15 -0
- package/src/constants/resetCss.js +171 -0
- package/src/index.d.ts +31 -0
- package/src/index.js +20 -0
- package/src/lib/compileConfig.js +59 -0
- package/src/lib/compileThemes.js +118 -0
- package/src/lib/copyLocalFonts/copyLocalFonts.utils.js +42 -0
- package/src/lib/copyLocalFonts/generateCssFonts.utils.js +56 -0
- package/src/lib/extractDocFragment/extractDocFragment.utils.js +25 -0
- package/src/lib/fileExists/fileExists.utils.js +31 -0
- package/src/lib/generateBaseCss/generateBaseCss.utils.js +51 -0
- package/src/lib/generateCss/generateCSS.utils.js +42 -0
- package/src/lib/generateCss/helpers/advanceselector/advancedSelectorHandler.utils.js +22 -0
- package/src/lib/generateCss/helpers/attribute/attributeHandler.utils.js +47 -0
- package/src/lib/generateCss/helpers/classnames/formatClassName.utils.js +28 -0
- package/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +124 -0
- package/src/lib/generateCss/helpers/cssVars/generateVars.utils.js +73 -0
- package/src/lib/generateCss/helpers/dynamicValues/dynamicValues.utils.js +72 -0
- package/src/lib/generateCss/helpers/dynamicValues/processDynamic.utils.js +10 -0
- package/src/lib/generateCss/helpers/filterGenerateCss.utils.js +73 -0
- package/src/lib/generateCss/helpers/foreign/foreignHandler.utils.js +85 -0
- package/src/lib/generateCss/helpers/generateCssStyles.utils.js +249 -0
- package/src/lib/generateCss/helpers/index.js +53 -0
- package/src/lib/generateCss/helpers/mediaqueries/generateMediaQueries.utils.js +9 -0
- package/src/lib/generateCss/helpers/mediaqueries/mediaQueriesHandler.utils.js +181 -0
- package/src/lib/generateCss/helpers/other/declareCssType.utils.js +120 -0
- package/src/lib/generateCss/helpers/other/generateGlobalStyles.utils.js +30 -0
- package/src/lib/generateCss/helpers/pseudo/pseudoHandler.utils.js +56 -0
- package/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +163 -0
- package/src/lib/generateCss/helpers/utils/extractValues.utils.js +44 -0
- package/src/lib/generateCss/helpers/utils/formattedStatKey.utils.js +43 -0
- package/src/lib/generateCss/helpers/utils/index.js +15 -0
- package/src/lib/generateCss/helpers/utils/processCss.utils.js +93 -0
- package/src/lib/generateCss/helpers/utils/separateStyles.utils.js +43 -0
- package/src/lib/generateCss/helpers/utils/validatePreviouslyExists.utils.js +61 -0
- package/src/lib/generateCssDoc/generateCssDoc.util.js +47 -0
- package/src/lib/generateProvider/generateProvider.utils.js +283 -0
- package/src/lib/generateProvider/template/providerTemplate.d.ts +60 -0
- package/src/lib/generateProvider/template/providerTemplate.js +160 -0
- package/src/lib/generateThemeRegister/generateThemeRegister.utils.js +136 -0
- package/src/lib/generateTools/generateTools.utils.js +181 -0
- package/src/lib/generateTypesTools/generateTypesTools.utils.js +59 -0
- package/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +96 -0
- package/src/lib/index.js +61 -0
- package/src/lib/processMediaConfig/processMediaConfig.util.js +32 -0
- package/src/lib/readFile/readFile.utils.js +110 -0
- package/src/lib/simplifyName/__tests__/simplifyName.utils.test.js +87 -0
- package/src/lib/simplifyName/simplifyName.utils.js +28 -0
- package/src/lib/typingStyles/index.js +3 -0
- package/src/lib/typingStyles/typingStyles.utils.js +144 -0
- package/src/lib/writeDoc/writeDoc.utils.js +30 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const { separateStyles } = require('../utils/separateStyles.utils.js');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles custom attributes and processes nested objects.
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} attributes - The custom attributes to process.
|
|
7
|
+
* @param {string} ruleName - The base rule name to be used.
|
|
8
|
+
* @param {Function} processSource - A function to process nested objects.
|
|
9
|
+
* @param {string} [carry] - An optional carry attribute for nested processing.
|
|
10
|
+
*/
|
|
11
|
+
const attributeHandler = ({
|
|
12
|
+
attributes,
|
|
13
|
+
ruleName,
|
|
14
|
+
processSource,
|
|
15
|
+
carry = undefined,
|
|
16
|
+
}) => {
|
|
17
|
+
for (const [attr, properties] of Object.entries(attributes)) {
|
|
18
|
+
//* lower case the attribute name for consistency
|
|
19
|
+
const attrLower = attr.toLowerCase();
|
|
20
|
+
//* build the complete attribute selector
|
|
21
|
+
const attrName = carry
|
|
22
|
+
? `${ruleName}[${carry}="${attrLower}"]`
|
|
23
|
+
: `${ruleName}[${attrLower}="true"]`;
|
|
24
|
+
//* separate properties into special and regular
|
|
25
|
+
const { styles, lib, other } = separateStyles(properties);
|
|
26
|
+
//* check if existe styles
|
|
27
|
+
const hasStyles = Object.entries(styles).length > 0;
|
|
28
|
+
const hasLib = Object.entries(lib).length > 0;
|
|
29
|
+
const hasOther = Object.entries(other).length > 0;
|
|
30
|
+
//* Process styles and lib if they exist
|
|
31
|
+
if (hasStyles || hasLib) {
|
|
32
|
+
const mergeStyles = { ...styles, ...lib };
|
|
33
|
+
processSource({ source: mergeStyles, theRule: attrName });
|
|
34
|
+
}
|
|
35
|
+
//* Process nested attributes if they exist
|
|
36
|
+
if (hasOther) {
|
|
37
|
+
attributeHandler({
|
|
38
|
+
attributes: other,
|
|
39
|
+
ruleName,
|
|
40
|
+
processSource,
|
|
41
|
+
carry: attrLower,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = { attributeHandler };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS Class Name Formatter for Bernova
|
|
3
|
+
*
|
|
4
|
+
* Ensures consistent CSS class naming by converting JavaScript naming conventions
|
|
5
|
+
* to CSS-friendly format. Follows CSS naming best practices.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Formats JavaScript property names into valid CSS class names
|
|
10
|
+
* Converts to lowercase and replaces underscores with hyphens for CSS compatibility
|
|
11
|
+
*
|
|
12
|
+
* @param {string} className - The class name to format (JavaScript property name)
|
|
13
|
+
* @returns {string} CSS-formatted class name (lowercase with hyphens)
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* formatClassName('primaryButton') // returns 'primarybutton'
|
|
17
|
+
* formatClassName('nav_item_active') // returns 'nav-item-active'
|
|
18
|
+
* formatClassName('HEADER_TITLE') // returns 'header-title'
|
|
19
|
+
*/
|
|
20
|
+
const formatClassName = (className) => {
|
|
21
|
+
if (!className || typeof className !== 'string') {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return className.toLowerCase().replace(/_/g, '-');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
module.exports = { formatClassName };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS Register Handler for Bernova
|
|
3
|
+
*
|
|
4
|
+
* Processes the CSS class register to generate provider utilities and tools.
|
|
5
|
+
* Creates structured exports for components, class mappings, and TypeScript types.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { simplifyName } = require('../../../simplifyName/simplifyName.utils');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Handles the CSS register to generate provider documentation and tools
|
|
12
|
+
* Recursively processes nested component structures and creates exports
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} params - Handler parameters
|
|
15
|
+
* @param {Object} params.register - CSS class register with component mappings
|
|
16
|
+
* @param {string} params.prefix - CSS class prefix to remove from names
|
|
17
|
+
* @returns {Object} Processed documentation for providers and tools
|
|
18
|
+
*/
|
|
19
|
+
const handlerRegister = ({ register, prefix }) => {
|
|
20
|
+
// Track registered components to avoid duplicates
|
|
21
|
+
const componentsRegistered = new Set();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Recursively processes the register object to generate structured documentation
|
|
25
|
+
* @param {Object} rg - Current register level to process
|
|
26
|
+
* @param {number} space - Indentation spacing for formatting
|
|
27
|
+
* @param {number} lv - Current nesting level (1 = top level)
|
|
28
|
+
*/
|
|
29
|
+
const processRegister = ({ rg, space = 2, lv = 1 }) => {
|
|
30
|
+
const currentSpace = ' '.repeat(space);
|
|
31
|
+
return Object.entries(rg).reduce(
|
|
32
|
+
(acc, [comp, value]) => {
|
|
33
|
+
// Clean component name by removing CSS prefix
|
|
34
|
+
const component = comp.replace(`${prefix}-`, '');
|
|
35
|
+
|
|
36
|
+
if (typeof value === 'object') {
|
|
37
|
+
// Handle nested component structures
|
|
38
|
+
const isFirstLevel = lv === 1;
|
|
39
|
+
const UC = isFirstLevel ? component.toUpperCase() : component;
|
|
40
|
+
|
|
41
|
+
// Generate provider documentation (opening braces)
|
|
42
|
+
acc.prov.doc += `${currentSpace}${UC}: {\n`;
|
|
43
|
+
acc.prov.declare += `${currentSpace}${UC}: {\n`;
|
|
44
|
+
|
|
45
|
+
// Add to components list (union types and object mapping)
|
|
46
|
+
acc.comp.simple += acc.comp.simple.length ? ` | '${UC}'` : `'${UC}'`;
|
|
47
|
+
acc.comp.object += isFirstLevel
|
|
48
|
+
? `${currentSpace}${UC}: '${UC}',\n`
|
|
49
|
+
: '';
|
|
50
|
+
// Recursively process nested structures with increased indentation
|
|
51
|
+
const nextSpace = space + 2;
|
|
52
|
+
const nextLv = lv + 1;
|
|
53
|
+
const {
|
|
54
|
+
prov: { doc, declare: declareType },
|
|
55
|
+
tools: { doc: toolsDoc, declare: toolsDeclare },
|
|
56
|
+
} = processRegister({
|
|
57
|
+
rg: value,
|
|
58
|
+
space: nextSpace,
|
|
59
|
+
lv: nextLv,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Close provider documentation (closing braces)
|
|
63
|
+
acc.prov.doc += doc;
|
|
64
|
+
acc.prov.declare += declareType;
|
|
65
|
+
acc.prov.doc += `${currentSpace}},\n`;
|
|
66
|
+
acc.prov.declare += `${currentSpace}},\n`;
|
|
67
|
+
|
|
68
|
+
// Append tools documentation from nested processing
|
|
69
|
+
acc.tools.doc += toolsDoc;
|
|
70
|
+
acc.tools.declare += toolsDeclare;
|
|
71
|
+
} else if (typeof value === 'boolean' && value) {
|
|
72
|
+
// Handle leaf nodes (actual CSS class mappings)
|
|
73
|
+
|
|
74
|
+
// Generate tools documentation (simplified component names)
|
|
75
|
+
const componentTools = simplifyName(component);
|
|
76
|
+
if (!componentsRegistered.has(componentTools)) {
|
|
77
|
+
componentsRegistered.add(componentTools);
|
|
78
|
+
acc.tools.doc += ` ${componentTools}: '${component}',\n`;
|
|
79
|
+
acc.tools.declare += ` ${component}: string,\n`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Generate provider documentation (use last part after __ as key)
|
|
83
|
+
const provKey = component.split('__').at(-1);
|
|
84
|
+
acc.prov.doc += `${currentSpace}${provKey}: '${component}',\n`;
|
|
85
|
+
acc.prov.declare += `${currentSpace}${provKey}: string,\n`;
|
|
86
|
+
} else if (typeof value === 'string') {
|
|
87
|
+
// Handle string mappings (class name aliases)
|
|
88
|
+
|
|
89
|
+
// Generate tools documentation from string value
|
|
90
|
+
const compFromValue = simplifyName(value).replace(`${prefix}_`, '');
|
|
91
|
+
if (!componentsRegistered.has(compFromValue)) {
|
|
92
|
+
componentsRegistered.add(compFromValue);
|
|
93
|
+
acc.tools.doc += ` ${compFromValue}: '${value}',\n`;
|
|
94
|
+
acc.tools.declare += ` ${compFromValue}: string,\n`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Generate provider documentation with string value
|
|
98
|
+
const provKey = component.split('__').at(-1);
|
|
99
|
+
acc.prov.doc += `${currentSpace}${provKey}: '${value}',\n`;
|
|
100
|
+
acc.prov.declare += `${currentSpace}${provKey}: string,\n`;
|
|
101
|
+
} else if (typeof value === 'function') {
|
|
102
|
+
// Handle dynamic value functions (special cases for type generation)
|
|
103
|
+
if (component === 'dynamic_values') {
|
|
104
|
+
acc.prov.doc += `${currentSpace}${component}: ${value.toString()},\n`;
|
|
105
|
+
} else if (component === 'dynamic_values_type') {
|
|
106
|
+
acc.prov.declare += `${currentSpace}dynamic_values: ${value()},\n`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return acc;
|
|
110
|
+
},
|
|
111
|
+
// Initialize accumulator with empty documentation structures
|
|
112
|
+
{
|
|
113
|
+
comp: { simple: '', object: '' }, // Component type definitions
|
|
114
|
+
prov: { doc: '', declare: '' }, // Provider documentation and types
|
|
115
|
+
tools: { doc: '', declare: '' }, // Tools utilities and types
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Start processing from the root register
|
|
121
|
+
return processRegister({ rg: register });
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
module.exports = { handlerRegister };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS Variables Generator for Bernova
|
|
3
|
+
*
|
|
4
|
+
* Converts JavaScript objects into CSS custom properties (CSS variables).
|
|
5
|
+
* Handles nested objects recursively and generates corresponding TypeScript types.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { simplifyName } = require('../../../simplifyName/simplifyName.utils');
|
|
9
|
+
const { formatClassName } = require('../classnames/formatClassName.utils');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Recursively generates CSS variables from a JavaScript object structure
|
|
13
|
+
* Creates CSS custom properties with proper naming and generates documentation
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} params - Generation parameters
|
|
16
|
+
* @param {Object} params.source - Source object with variable definitions
|
|
17
|
+
* @param {string} params.varName - CSS variable prefix (defaults to '-')
|
|
18
|
+
* @param {string} params.prefix - Theme prefix for variable naming
|
|
19
|
+
* @returns {Object} Generated CSS variables and TypeScript documentation
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const source = { colors: { primary: '#007bff', secondary: '#6c757d' } };
|
|
23
|
+
* const { root, rootDocs } = generateVars({ source, varName: '--theme', prefix: 'app' });
|
|
24
|
+
* // Generates: --theme-colors-primary: #007bff; --theme-colors-secondary: #6c757d;
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const generateVars = ({ source, varName = '-', prefix }) => {
|
|
28
|
+
const sourceEntries = Object.entries(source);
|
|
29
|
+
|
|
30
|
+
// Process each key-value pair in the source object
|
|
31
|
+
const { root, rootDocs } = sourceEntries.reduce(
|
|
32
|
+
(acc, [key, value]) => {
|
|
33
|
+
// Create CSS variable name with proper formatting
|
|
34
|
+
const varKey = `${varName}-${formatClassName(key)}`;
|
|
35
|
+
|
|
36
|
+
if (typeof value === 'object' && value !== null) {
|
|
37
|
+
// Recursively process nested objects
|
|
38
|
+
const { root: nestedRoot, rootDocs: nestedDocs } = generateVars({
|
|
39
|
+
source: value,
|
|
40
|
+
varName: varKey,
|
|
41
|
+
prefix,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Accumulate nested CSS variables and documentation
|
|
45
|
+
acc.root += nestedRoot;
|
|
46
|
+
acc.rootDocs.doc += nestedDocs.doc;
|
|
47
|
+
acc.rootDocs.declare += nestedDocs.declare;
|
|
48
|
+
} else {
|
|
49
|
+
// Generate CSS variable for primitive values
|
|
50
|
+
const rootRegisterKey = simplifyName(varKey).replace(`${prefix}_`, '');
|
|
51
|
+
|
|
52
|
+
// Add CSS custom property declaration
|
|
53
|
+
acc.root += `${varKey}: ${value};\n`;
|
|
54
|
+
|
|
55
|
+
// Add JavaScript object property for provider
|
|
56
|
+
acc.rootDocs.doc += ` ${rootRegisterKey}: 'var(${varKey})',\n`;
|
|
57
|
+
|
|
58
|
+
// Add TypeScript declaration
|
|
59
|
+
acc.rootDocs.declare += ` ${rootRegisterKey}: string;\n`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return acc;
|
|
63
|
+
},
|
|
64
|
+
{ root: '', rootDocs: { doc: '', declare: '' } }
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
root,
|
|
69
|
+
rootDocs,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
module.exports = { generateVars };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic Values Processor for Bernova CSS Framework
|
|
3
|
+
*
|
|
4
|
+
* Handles runtime CSS variable generation and type definitions.
|
|
5
|
+
* Processes dynamic values that can be updated at runtime via JavaScript.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Converts dynamic style objects to CSS custom properties
|
|
10
|
+
* Generates both string format (for CSS injection) and object format (for JS access)
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} styles - Dynamic styles object with $ prefixed keys
|
|
13
|
+
* @returns {Object} CSS variables in string and object format
|
|
14
|
+
* @example
|
|
15
|
+
* dynamic_values({ $primaryColor: '#ff0000' })
|
|
16
|
+
* // Returns: { string: '--primarycolor: #ff0000; ', object: { '--primarycolor': '#ff0000' } }
|
|
17
|
+
*/
|
|
18
|
+
const dynamic_values = (styles) => {
|
|
19
|
+
return Object.entries(styles).reduce(
|
|
20
|
+
(acc, [key, value]) => {
|
|
21
|
+
// Generate CSS custom property name (lowercase, remove $)
|
|
22
|
+
const varName = '--' + key.toLocaleLowerCase().replace('$', '');
|
|
23
|
+
acc.string += varName + ': ' + value + '; ';
|
|
24
|
+
acc.object[varName] = value;
|
|
25
|
+
return acc;
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
string: '', // CSS string format: '--var: value; '
|
|
29
|
+
object: {}, // Object format: { '--var': 'value' }
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Generates TypeScript type definitions for dynamic values function
|
|
36
|
+
* Creates type-safe interfaces for runtime CSS variable manipulation
|
|
37
|
+
*
|
|
38
|
+
* @param {Object} dynamicValues - Dynamic values object to generate types for
|
|
39
|
+
* @returns {string} TypeScript function signature
|
|
40
|
+
*/
|
|
41
|
+
const dynamic_values_type = (dynamicValues) => {
|
|
42
|
+
const types = Object.keys(dynamicValues).reduce(
|
|
43
|
+
(acc, key) => (acc += `'${key}': string; `),
|
|
44
|
+
''
|
|
45
|
+
);
|
|
46
|
+
return `(styles: { ${types}}) => { string: string; object: object } `;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Registers dynamic values in the component register system
|
|
51
|
+
* Associates dynamic values with their parent components for provider generation
|
|
52
|
+
*
|
|
53
|
+
* @param {Object} params - Registration parameters
|
|
54
|
+
* @param {Object} params.dynamicValues - Dynamic values to register
|
|
55
|
+
* @param {Object} params.register - Component register to update
|
|
56
|
+
* @param {string} params.ruleName - CSS rule name to extract component from
|
|
57
|
+
* @param {string} params.prefix - CSS prefix to remove from component name
|
|
58
|
+
*/
|
|
59
|
+
const setDynamicRegister = ({ dynamicValues, register, ruleName, prefix }) => {
|
|
60
|
+
const relatedComponent = ruleName
|
|
61
|
+
.split('--')[0]
|
|
62
|
+
.split('__')[0]
|
|
63
|
+
.replace(prefix, '');
|
|
64
|
+
if (!(relatedComponent in register)) {
|
|
65
|
+
register[relatedComponent] = {};
|
|
66
|
+
}
|
|
67
|
+
register[relatedComponent].dynamic_values = dynamic_values;
|
|
68
|
+
register[relatedComponent].dynamic_values_type = () =>
|
|
69
|
+
dynamic_values_type(dynamicValues);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
module.exports = { setDynamicRegister };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const processDynamicProps = (dynamic) => {
|
|
2
|
+
if (Array.isArray(dynamic)) {
|
|
3
|
+
return dynamic.reduce((acc, curr) => {
|
|
4
|
+
acc[curr] = `var(--${curr.toLocaleLowerCase().replace('$', '')})`;
|
|
5
|
+
return acc;
|
|
6
|
+
}, {});
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
module.exports = { processDynamicProps };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const { compilerTypeValid } = require('../../../constants');
|
|
2
|
+
const { generateVars } = require('./cssVars/generateVars.utils');
|
|
3
|
+
const { generateCssStyles } = require('./generateCssStyles.utils');
|
|
4
|
+
const { generateGlobalStyles } = require('./other/generateGlobalStyles.utils');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Filters and generates CSS content based on compiler type and source configuration
|
|
8
|
+
* This function determines what CSS should be generated based on the compilation mode
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} params - The parameters object
|
|
11
|
+
* @param {Object} params.source - Source configuration containing foundations, theme, global, and media
|
|
12
|
+
* @param {string} params.compilerType - Type of compilation: 'full', 'foundationOnly', or 'componentOnly'
|
|
13
|
+
* @param {string} params.baseCss - Base CSS content to include in foundations
|
|
14
|
+
* @param {string} params.prefix - CSS variable prefix for namespacing
|
|
15
|
+
* @returns {Object} Object containing generated CSS parts and documentation
|
|
16
|
+
*/
|
|
17
|
+
const filterGenerateCss = ({ source, compilerType, baseCss, prefix }) => {
|
|
18
|
+
const { foundations, theme, global, media } = source;
|
|
19
|
+
|
|
20
|
+
// Determine what content to generate based on compiler type
|
|
21
|
+
const hasFoundations =
|
|
22
|
+
compilerType === compilerTypeValid.full ||
|
|
23
|
+
compilerType === compilerTypeValid.foundationOnly;
|
|
24
|
+
const hasTheme =
|
|
25
|
+
compilerType === compilerTypeValid.full ||
|
|
26
|
+
compilerType === compilerTypeValid.componentOnly;
|
|
27
|
+
|
|
28
|
+
// Generate foundation CSS (CSS variables, base styles, global styles)
|
|
29
|
+
const { foundationsCss, rootDocs, globalDocs } = (() => {
|
|
30
|
+
if (!hasFoundations) {
|
|
31
|
+
return {
|
|
32
|
+
foundationsCss: '',
|
|
33
|
+
rootDocs: { doc: '', declare: '' },
|
|
34
|
+
globalDocs: { doc: '', declare: '' },
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// Generate CSS custom properties (variables) from foundations
|
|
38
|
+
const { root, rootDocs } = foundations
|
|
39
|
+
? generateVars({
|
|
40
|
+
source: foundations,
|
|
41
|
+
varName: prefix ? `--${prefix}` : '-',
|
|
42
|
+
prefix,
|
|
43
|
+
})
|
|
44
|
+
: { root: '', rootDocs: { doc: '', declare: '' } };
|
|
45
|
+
|
|
46
|
+
// Generate global styles that apply to all elements
|
|
47
|
+
const { globalStyles, globalDocs } = global
|
|
48
|
+
? generateGlobalStyles(global)
|
|
49
|
+
: { globalStyles: '', globalDocs: { doc: '', declare: '' } };
|
|
50
|
+
|
|
51
|
+
// Combine base CSS, root variables, and global styles
|
|
52
|
+
const foundationsCss = `${baseCss}:root{\n${root}}\n${globalStyles}`;
|
|
53
|
+
return { foundationsCss, rootDocs, globalDocs };
|
|
54
|
+
})();
|
|
55
|
+
|
|
56
|
+
// Generate component theme styles (classes, utilities, etc.)
|
|
57
|
+
const { stylesCss, stylesDocs } = (() => {
|
|
58
|
+
if (!hasTheme || !theme) {
|
|
59
|
+
return { stylesCss: '', stylesDocs: {} };
|
|
60
|
+
}
|
|
61
|
+
const { styles, stylesDocs } = generateCssStyles({
|
|
62
|
+
source: theme,
|
|
63
|
+
mediaConfig: media,
|
|
64
|
+
prefix,
|
|
65
|
+
});
|
|
66
|
+
return { stylesCss: styles, stylesDocs };
|
|
67
|
+
})();
|
|
68
|
+
|
|
69
|
+
// Return separated CSS parts for further processing
|
|
70
|
+
return { stylesCss, foundationsCss, stylesDocs, rootDocs, globalDocs };
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
module.exports = { filterGenerateCss };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Foreign Theme Handler for Bernova CSS Framework
|
|
3
|
+
*
|
|
4
|
+
* Processes external/foreign theme components and integrates them
|
|
5
|
+
* into the main CSS generation system. Handles variant mapping
|
|
6
|
+
* and component structure transformation.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { cssProps } = require('../../../../constants/cssProps');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Handles integration of foreign theme components into Bernova system
|
|
13
|
+
* Transforms external component structures into compatible CSS class mappings
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} foreign - Foreign theme components to integrate
|
|
16
|
+
* @param {string} prefix - CSS class prefix for generated classes
|
|
17
|
+
* @returns {Object} Transformed component structure with register data
|
|
18
|
+
*/
|
|
19
|
+
const foreignHandler = ({ foreign, prefix }) => {
|
|
20
|
+
return Object.entries(foreign).reduce(
|
|
21
|
+
(acc, [foreignName, { component, variant, name = '' }]) => {
|
|
22
|
+
if (!component) {
|
|
23
|
+
return acc;
|
|
24
|
+
}
|
|
25
|
+
let isMainSet = false;
|
|
26
|
+
let structure = {};
|
|
27
|
+
const lowerName = name.toLocaleLowerCase();
|
|
28
|
+
const componentVariant = variant && component[variant];
|
|
29
|
+
if (componentVariant) {
|
|
30
|
+
const lowerVariant = variant.toLocaleLowerCase();
|
|
31
|
+
Object.entries(componentVariant).forEach(([key, value]) => {
|
|
32
|
+
if (key in cssProps && !(key in structure)) {
|
|
33
|
+
structure[lowerName] = `${prefix}${lowerName}--${lowerVariant}`;
|
|
34
|
+
}
|
|
35
|
+
if (key.startsWith('_')) {
|
|
36
|
+
const subComponent = key.toLocaleLowerCase().substring(1);
|
|
37
|
+
structure[
|
|
38
|
+
subComponent
|
|
39
|
+
] = `${prefix}${lowerName}__${subComponent}--${lowerVariant}`;
|
|
40
|
+
}
|
|
41
|
+
if (key === '$foreign') {
|
|
42
|
+
const v = `$_${lowerVariant}`;
|
|
43
|
+
if (!(v in structure)) {
|
|
44
|
+
structure[v] = {};
|
|
45
|
+
}
|
|
46
|
+
structure[v] = {
|
|
47
|
+
...structure[v],
|
|
48
|
+
...foreignHandler({ foreign: value, prefix }),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
Object.entries(component).forEach(([key, value]) => {
|
|
54
|
+
if (key in cssProps && !isMainSet) {
|
|
55
|
+
const cssClass =
|
|
56
|
+
lowerName in structure
|
|
57
|
+
? `${prefix}${lowerName} ${structure[lowerName]}`
|
|
58
|
+
: `${prefix}${lowerName}`;
|
|
59
|
+
structure[lowerName] = cssClass;
|
|
60
|
+
isMainSet = true;
|
|
61
|
+
}
|
|
62
|
+
if (key.startsWith('_')) {
|
|
63
|
+
const subComponent = key.toLocaleLowerCase().substring(1);
|
|
64
|
+
const compoundedComponent = `${lowerName}__${subComponent}`;
|
|
65
|
+
const cssClass =
|
|
66
|
+
subComponent in structure
|
|
67
|
+
? `${prefix}${compoundedComponent} ${structure[subComponent]}`
|
|
68
|
+
: `${prefix}${compoundedComponent}`;
|
|
69
|
+
structure[subComponent] = cssClass;
|
|
70
|
+
}
|
|
71
|
+
if (key === '$foreign') {
|
|
72
|
+
structure = {
|
|
73
|
+
...structure,
|
|
74
|
+
...foreignHandler({ foreign: value, prefix }),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
acc[foreignName] = structure;
|
|
79
|
+
return acc;
|
|
80
|
+
},
|
|
81
|
+
{}
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
module.exports = { foreignHandler };
|