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.
Files changed (125) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1778 -0
  3. package/dist/bin/bernova.js +2 -0
  4. package/dist/bin/buildstyle.js +2 -0
  5. package/dist/bin/createConfigFile.js +2 -0
  6. package/dist/bin/declareCssType.js +1 -0
  7. package/dist/index.js +1 -0
  8. package/dist/src/app.js +1 -0
  9. package/dist/src/constants/compilerType.js +1 -0
  10. package/dist/src/constants/cssAdvancedSelectors.js +1 -0
  11. package/dist/src/constants/cssProps.js +1 -0
  12. package/dist/src/constants/cssPseudoClasses.js +1 -0
  13. package/dist/src/constants/cssPseudoElements.js +1 -0
  14. package/dist/src/constants/index.js +1 -0
  15. package/dist/src/constants/resetCss.js +1 -0
  16. package/dist/src/index.d.ts +31 -0
  17. package/dist/src/index.js +1 -0
  18. package/dist/src/lib/compileConfig.js +1 -0
  19. package/dist/src/lib/compileThemes.js +1 -0
  20. package/dist/src/lib/copyLocalFonts/copyLocalFonts.utils.js +1 -0
  21. package/dist/src/lib/copyLocalFonts/generateCssFonts.utils.js +1 -0
  22. package/dist/src/lib/extractDocFragment/extractDocFragment.utils.js +1 -0
  23. package/dist/src/lib/fileExists/fileExists.utils.js +1 -0
  24. package/dist/src/lib/generateBaseCss/generateBaseCss.utils.js +1 -0
  25. package/dist/src/lib/generateCss/generateCSS.utils.js +1 -0
  26. package/dist/src/lib/generateCss/helpers/advanceselector/advancedSelectorHandler.utils.js +1 -0
  27. package/dist/src/lib/generateCss/helpers/attribute/attributeHandler.utils.js +1 -0
  28. package/dist/src/lib/generateCss/helpers/classnames/formatClassName.utils.js +1 -0
  29. package/dist/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +1 -0
  30. package/dist/src/lib/generateCss/helpers/cssVars/generateVars.utils.js +1 -0
  31. package/dist/src/lib/generateCss/helpers/dynamicValues/dynamicValues.utils.js +1 -0
  32. package/dist/src/lib/generateCss/helpers/dynamicValues/processDynamic.utils.js +1 -0
  33. package/dist/src/lib/generateCss/helpers/filterGenerateCss.utils.js +1 -0
  34. package/dist/src/lib/generateCss/helpers/foreign/foreignHandler.utils.js +1 -0
  35. package/dist/src/lib/generateCss/helpers/generateCssStyles.utils.js +1 -0
  36. package/dist/src/lib/generateCss/helpers/index.js +1 -0
  37. package/dist/src/lib/generateCss/helpers/mediaqueries/generateMediaQueries.utils.js +1 -0
  38. package/dist/src/lib/generateCss/helpers/mediaqueries/mediaQueriesHandler.utils.js +1 -0
  39. package/dist/src/lib/generateCss/helpers/other/declareCssType.utils.js +1 -0
  40. package/dist/src/lib/generateCss/helpers/other/generateGlobalStyles.utils.js +1 -0
  41. package/dist/src/lib/generateCss/helpers/pseudo/pseudoHandler.utils.js +1 -0
  42. package/dist/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +1 -0
  43. package/dist/src/lib/generateCss/helpers/utils/extractValues.utils.js +1 -0
  44. package/dist/src/lib/generateCss/helpers/utils/formattedStatKey.utils.js +1 -0
  45. package/dist/src/lib/generateCss/helpers/utils/index.js +1 -0
  46. package/dist/src/lib/generateCss/helpers/utils/processCss.utils.js +1 -0
  47. package/dist/src/lib/generateCss/helpers/utils/separateStyles.utils.js +1 -0
  48. package/dist/src/lib/generateCss/helpers/utils/validatePreviouslyExists.utils.js +1 -0
  49. package/dist/src/lib/generateCssDoc/generateCssDoc.util.js +1 -0
  50. package/dist/src/lib/generateProvider/generateProvider.utils.js +1 -0
  51. package/dist/src/lib/generateProvider/template/providerTemplate.d.ts +60 -0
  52. package/dist/src/lib/generateProvider/template/providerTemplate.js +1 -0
  53. package/dist/src/lib/generateThemeRegister/generateThemeRegister.utils.js +1 -0
  54. package/dist/src/lib/generateTools/generateTools.utils.js +1 -0
  55. package/dist/src/lib/generateTypesTools/generateTypesTools.utils.js +1 -0
  56. package/dist/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +1 -0
  57. package/dist/src/lib/index.js +1 -0
  58. package/dist/src/lib/processMediaConfig/processMediaConfig.util.js +1 -0
  59. package/dist/src/lib/readFile/readFile.utils.js +1 -0
  60. package/dist/src/lib/simplifyName/simplifyName.utils.js +1 -0
  61. package/dist/src/lib/typingStyles/index.js +1 -0
  62. package/dist/src/lib/typingStyles/typingStyles.utils.js +1 -0
  63. package/dist/src/lib/writeDoc/writeDoc.utils.js +1 -0
  64. package/package.json +80 -0
  65. package/src/app.js +176 -0
  66. package/src/constants/__tests__/compilerType.test.js +20 -0
  67. package/src/constants/__tests__/cssAdvancedSelectors.test.js +38 -0
  68. package/src/constants/__tests__/cssProps.test.js +331 -0
  69. package/src/constants/__tests__/cssPseudoClasses.test.js +48 -0
  70. package/src/constants/compilerType.js +14 -0
  71. package/src/constants/cssAdvancedSelectors.js +32 -0
  72. package/src/constants/cssProps.js +325 -0
  73. package/src/constants/cssPseudoClasses.js +138 -0
  74. package/src/constants/cssPseudoElements.js +83 -0
  75. package/src/constants/index.js +15 -0
  76. package/src/constants/resetCss.js +171 -0
  77. package/src/index.d.ts +31 -0
  78. package/src/index.js +20 -0
  79. package/src/lib/compileConfig.js +59 -0
  80. package/src/lib/compileThemes.js +118 -0
  81. package/src/lib/copyLocalFonts/copyLocalFonts.utils.js +42 -0
  82. package/src/lib/copyLocalFonts/generateCssFonts.utils.js +56 -0
  83. package/src/lib/extractDocFragment/extractDocFragment.utils.js +25 -0
  84. package/src/lib/fileExists/fileExists.utils.js +31 -0
  85. package/src/lib/generateBaseCss/generateBaseCss.utils.js +51 -0
  86. package/src/lib/generateCss/generateCSS.utils.js +42 -0
  87. package/src/lib/generateCss/helpers/advanceselector/advancedSelectorHandler.utils.js +22 -0
  88. package/src/lib/generateCss/helpers/attribute/attributeHandler.utils.js +47 -0
  89. package/src/lib/generateCss/helpers/classnames/formatClassName.utils.js +28 -0
  90. package/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +124 -0
  91. package/src/lib/generateCss/helpers/cssVars/generateVars.utils.js +73 -0
  92. package/src/lib/generateCss/helpers/dynamicValues/dynamicValues.utils.js +72 -0
  93. package/src/lib/generateCss/helpers/dynamicValues/processDynamic.utils.js +10 -0
  94. package/src/lib/generateCss/helpers/filterGenerateCss.utils.js +73 -0
  95. package/src/lib/generateCss/helpers/foreign/foreignHandler.utils.js +85 -0
  96. package/src/lib/generateCss/helpers/generateCssStyles.utils.js +249 -0
  97. package/src/lib/generateCss/helpers/index.js +53 -0
  98. package/src/lib/generateCss/helpers/mediaqueries/generateMediaQueries.utils.js +9 -0
  99. package/src/lib/generateCss/helpers/mediaqueries/mediaQueriesHandler.utils.js +181 -0
  100. package/src/lib/generateCss/helpers/other/declareCssType.utils.js +120 -0
  101. package/src/lib/generateCss/helpers/other/generateGlobalStyles.utils.js +30 -0
  102. package/src/lib/generateCss/helpers/pseudo/pseudoHandler.utils.js +56 -0
  103. package/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +163 -0
  104. package/src/lib/generateCss/helpers/utils/extractValues.utils.js +44 -0
  105. package/src/lib/generateCss/helpers/utils/formattedStatKey.utils.js +43 -0
  106. package/src/lib/generateCss/helpers/utils/index.js +15 -0
  107. package/src/lib/generateCss/helpers/utils/processCss.utils.js +93 -0
  108. package/src/lib/generateCss/helpers/utils/separateStyles.utils.js +43 -0
  109. package/src/lib/generateCss/helpers/utils/validatePreviouslyExists.utils.js +61 -0
  110. package/src/lib/generateCssDoc/generateCssDoc.util.js +47 -0
  111. package/src/lib/generateProvider/generateProvider.utils.js +283 -0
  112. package/src/lib/generateProvider/template/providerTemplate.d.ts +60 -0
  113. package/src/lib/generateProvider/template/providerTemplate.js +160 -0
  114. package/src/lib/generateThemeRegister/generateThemeRegister.utils.js +136 -0
  115. package/src/lib/generateTools/generateTools.utils.js +181 -0
  116. package/src/lib/generateTypesTools/generateTypesTools.utils.js +59 -0
  117. package/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +96 -0
  118. package/src/lib/index.js +61 -0
  119. package/src/lib/processMediaConfig/processMediaConfig.util.js +32 -0
  120. package/src/lib/readFile/readFile.utils.js +110 -0
  121. package/src/lib/simplifyName/__tests__/simplifyName.utils.test.js +87 -0
  122. package/src/lib/simplifyName/simplifyName.utils.js +28 -0
  123. package/src/lib/typingStyles/index.js +3 -0
  124. package/src/lib/typingStyles/typingStyles.utils.js +144 -0
  125. package/src/lib/writeDoc/writeDoc.utils.js +30 -0
@@ -0,0 +1,171 @@
1
+ /**
2
+ * CSS Reset for Bernova
3
+ *
4
+ * Provides a comprehensive CSS reset that normalizes default browser styles.
5
+ * Based on modern reset principles, ensures consistent cross-browser rendering.
6
+ *
7
+ * Features:
8
+ * - Removes default margins and padding
9
+ * - Sets consistent box-sizing
10
+ * - Normalizes form elements
11
+ * - Resets list styles
12
+ * - Standardizes table presentation
13
+ *
14
+ * This reset is optional and can be enabled via the `resetCss` flag in theme configuration.
15
+ */
16
+ const resetCss = `
17
+ html {
18
+ margin: 0;
19
+ padding: 0;
20
+ vertical-align: baseline;
21
+ margin-block-start: 0;
22
+ margin-block-end: 0;
23
+ margin-inline-start: 0;
24
+ margin-inline-end: 0;
25
+ box-sizing: border-box;
26
+ background-color: transparent;
27
+ border: 0;
28
+ }
29
+ body,
30
+ div,
31
+ span,
32
+ applet,
33
+ object,
34
+ iframe,
35
+ h1,
36
+ h2,
37
+ h3,
38
+ h4,
39
+ h5,
40
+ h6,
41
+ p,
42
+ blockquote,
43
+ pre,
44
+ a,
45
+ abbr,
46
+ acronym,
47
+ address,
48
+ big,
49
+ cite,
50
+ code,
51
+ del,
52
+ dfn,
53
+ em,
54
+ img,
55
+ ins,
56
+ kbd,
57
+ q,
58
+ s,
59
+ samp,
60
+ small,
61
+ strike,
62
+ strong,
63
+ sub,
64
+ sup,
65
+ tt,
66
+ var,
67
+ b,
68
+ u,
69
+ i,
70
+ center,
71
+ dl,
72
+ dt,
73
+ dd,
74
+ ol,
75
+ ul,
76
+ li,
77
+ fieldset,
78
+ form,
79
+ label,
80
+ legend,
81
+ table,
82
+ caption,
83
+ tbody,
84
+ tfoot,
85
+ thead,
86
+ tr,
87
+ th,
88
+ td,
89
+ article,
90
+ aside,
91
+ canvas,
92
+ details,
93
+ embed,
94
+ figure,
95
+ figcaption,
96
+ footer,
97
+ header,
98
+ hgroup,
99
+ menu,
100
+ nav,
101
+ output,
102
+ ruby,
103
+ section,
104
+ summary,
105
+ time,
106
+ mark,
107
+ audio,
108
+ video,
109
+ dialog,
110
+ input,
111
+ button {
112
+ margin: 0;
113
+ padding: 0;
114
+ vertical-align: baseline;
115
+ margin-block-start: 0;
116
+ margin-block-end: 0;
117
+ margin-inline-start: 0;
118
+ margin-inline-end: 0;
119
+ box-sizing: border-box;
120
+ background-color: transparent;
121
+ border: 0;
122
+ }
123
+ article,
124
+ aside,
125
+ details,
126
+ figcaption,
127
+ figure,
128
+ footer,
129
+ header,
130
+ hgroup,
131
+ menu,
132
+ nav,
133
+ section {
134
+ display: block;
135
+ }
136
+ body {
137
+ line-height: 1;
138
+ }
139
+ ol,
140
+ ul {
141
+ list-style: none;
142
+ }
143
+ blockquote,
144
+ q {
145
+ quotes: none;
146
+ }
147
+ blockquote::before,
148
+ blockquote::after,
149
+ q::before,
150
+ q::after {
151
+ content: "";
152
+ content: none;
153
+ }
154
+ table {
155
+ border-collapse: collapse;
156
+ border-spacing: 0;
157
+ }
158
+
159
+ @supports (font: -apple-system-body) {
160
+ html {
161
+ font: -apple-system-body;
162
+ }
163
+ }
164
+ @supports (font: system-ui) {
165
+ html {
166
+ font: system-ui;
167
+ }
168
+ }
169
+ `;
170
+
171
+ module.exports = { resetCss };
package/src/index.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ // Type definitions for Bernova
2
+ export interface BernovaConfig {
3
+ themes: any[];
4
+ provider?: {
5
+ path: string;
6
+ name: string;
7
+ declarationHelp?: boolean;
8
+ };
9
+ }
10
+
11
+ export interface BernovaTheme {
12
+ name: string;
13
+ stylesPath?: string;
14
+ [key: string]: any;
15
+ }
16
+
17
+ // Main Bernova function
18
+ export function bernovaStyles(compilerType?: string): Promise<void>;
19
+
20
+ // Library exports
21
+ export const lib: any;
22
+ export const constants: any;
23
+
24
+ // Default export
25
+ declare const bernova: {
26
+ bernovaStyles: typeof bernovaStyles;
27
+ lib: typeof lib;
28
+ constants: typeof constants;
29
+ };
30
+
31
+ export default bernova;
package/src/index.js ADDED
@@ -0,0 +1,20 @@
1
+ // Main entry point for Bernova package
2
+ const lib = require('./lib');
3
+ const constants = require('./constants');
4
+ const { bernovaStyles } = require('./app');
5
+
6
+ // Export the main functionality
7
+ module.exports = {
8
+ // Main function
9
+ bernovaStyles,
10
+
11
+ // Library functions
12
+ ...lib,
13
+
14
+ // Constants
15
+ ...constants,
16
+
17
+ // Direct access to modules
18
+ lib,
19
+ constants,
20
+ };
@@ -0,0 +1,59 @@
1
+ const path = require('path');
2
+ const tsConfigPaths = require('tsconfig-paths');
3
+ const { readConfigData } = require('./readFile/readFile.utils.js');
4
+
5
+ /**
6
+ * Compiles and validates the Bernova configuration from bernova.config.json
7
+ * Sets up TypeScript path mapping if configured
8
+ *
9
+ * @param {Object} params - The parameters object
10
+ * @param {string} params.dir - The project directory containing the configuration file
11
+ * @returns {Promise<Object>} Configuration object containing themes and provider settings
12
+ * @throws {Error} When configuration file is invalid or missing
13
+ */
14
+ const compileConfig = async ({ dir }) => {
15
+ try {
16
+ const configDir = path.resolve(dir, 'bernova.config.json');
17
+ const configData = await readConfigData(configDir);
18
+
19
+ if (!configData) {
20
+ throw new Error(`Configuration file not found at ${configDir}`);
21
+ }
22
+
23
+ const { themes, provider, tsconfigPath } = configData;
24
+
25
+ // Validate required configuration
26
+ if (!themes || !Array.isArray(themes) || themes.length === 0) {
27
+ throw new Error('Configuration must include at least one theme');
28
+ }
29
+
30
+ // Setup TypeScript path mapping if configured
31
+ if (tsconfigPath) {
32
+ try {
33
+ const tsConfig = path.resolve(dir, tsconfigPath);
34
+ const tsConfigData = await readConfigData(tsConfig);
35
+
36
+ if (tsConfigData?.compilerOptions) {
37
+ tsConfigPaths.register({
38
+ baseUrl: tsConfigData.compilerOptions.baseUrl || dir,
39
+ paths: tsConfigData.compilerOptions.paths || {},
40
+ });
41
+ console.log(`TypeScript paths configured from ${tsconfigPath}`);
42
+ } else {
43
+ console.warn(`Invalid or empty tsconfig at ${tsconfigPath}`);
44
+ }
45
+ } catch (error) {
46
+ console.warn(
47
+ `Failed to load TypeScript configuration: ${error.message}`
48
+ );
49
+ }
50
+ }
51
+
52
+ return { themes, provider };
53
+ } catch (error) {
54
+ console.error('Failed to compile configuration:', error.message);
55
+ throw error;
56
+ }
57
+ };
58
+
59
+ module.exports = { compileConfig };
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Theme Compilation Module for Bernova
3
+ *
4
+ * Compiles theme configurations by resolving file paths and loading theme data.
5
+ * Validates file existence and structures theme data for CSS generation.
6
+ */
7
+
8
+ const path = require('path');
9
+ const fs = require('fs');
10
+ const { readThemeData } = require('./readFile/readFile.utils');
11
+ const { fileExists } = require('./fileExists/fileExists.utils');
12
+
13
+ /**
14
+ * Compiles a theme configuration by loading and validating theme files
15
+ *
16
+ * @param {Object} params - Compilation parameters
17
+ * @param {Object} params.themeConfig - Theme configuration object
18
+ * @param {string} params.themeConfig.name - Theme name (defaults to 'bernova')
19
+ * @param {string} params.themeConfig.prefix - CSS variable prefix
20
+ * @param {Object} params.themeConfig.theme - Theme styles configuration
21
+ * @param {Object} params.themeConfig.foundations - Foundation styles configuration
22
+ * @param {Object} params.themeConfig.globalStyles - Global styles configuration
23
+ * @param {Object} params.themeConfig.mediaQueries - Media queries configuration
24
+ * @param {string} params.themeConfig.stylesPath - Output path for generated styles
25
+ * @param {Array} params.themeConfig.fonts - Font configurations
26
+ * @param {boolean} params.themeConfig.resetCss - Whether to include CSS reset
27
+ * @param {Object} params.themeConfig.bvTools - Development tools configuration
28
+ * @param {Object} params.themeConfig.typesTools - TypeScript tools configuration
29
+ * @param {Array} params.themeConfig.foreignThemes - External theme integrations
30
+ * @param {string} params.dir - Base directory for resolving relative paths
31
+ * @returns {Object} Compiled theme data and configuration
32
+ */
33
+ const compileThemes = ({
34
+ themeConfig: {
35
+ name = 'bernova',
36
+ prefix,
37
+ theme,
38
+ foundations,
39
+ globalStyles,
40
+ mediaQueries,
41
+ stylesPath,
42
+ fonts,
43
+ resetCss,
44
+ bvTools,
45
+ typesTools,
46
+ foreignThemes,
47
+ },
48
+ dir,
49
+ }) => {
50
+ // Resolve and validate theme file paths
51
+ const paths = (() => {
52
+ const resolvedPaths = {};
53
+
54
+ // Process foundations (CSS variables, base tokens)
55
+ if (
56
+ foundations?.name &&
57
+ foundations?.path &&
58
+ fileExists(dir, foundations.path)
59
+ ) {
60
+ resolvedPaths.foundations = {
61
+ path: path.resolve(dir, foundations.path),
62
+ name: foundations.name,
63
+ };
64
+ }
65
+
66
+ // Process theme styles (component styles, utilities)
67
+ if (theme?.name && theme?.path && fileExists(dir, theme.path)) {
68
+ resolvedPaths.theme = {
69
+ path: path.resolve(dir, theme.path),
70
+ name: theme.name,
71
+ };
72
+ }
73
+
74
+ // Process global styles (CSS resets, base element styles)
75
+ if (
76
+ globalStyles?.name &&
77
+ globalStyles?.path &&
78
+ fileExists(dir, globalStyles.path)
79
+ ) {
80
+ resolvedPaths.global = {
81
+ path: path.resolve(dir, globalStyles.path),
82
+ name: globalStyles.name,
83
+ };
84
+ }
85
+
86
+ // Process media queries (responsive breakpoints)
87
+ if (
88
+ mediaQueries?.name &&
89
+ mediaQueries?.path &&
90
+ fileExists(dir, mediaQueries.path)
91
+ ) {
92
+ resolvedPaths.media = {
93
+ path: path.resolve(dir, mediaQueries.path),
94
+ name: mediaQueries.name,
95
+ };
96
+ }
97
+
98
+ return resolvedPaths;
99
+ })();
100
+
101
+ // Load theme data from resolved file paths
102
+ const themeCss = readThemeData(paths);
103
+
104
+ // Return compiled theme configuration
105
+ return {
106
+ themeCss, // Loaded CSS-in-JS theme data
107
+ fonts, // Font configuration
108
+ resetCss, // CSS reset flag
109
+ bvTools, // Development tools configuration
110
+ name, // Theme name
111
+ stylesPath, // Output directory for generated CSS
112
+ typesTools, // TypeScript generation tools
113
+ prefix, // CSS variable prefix
114
+ foreignThemes, // External theme dependencies
115
+ };
116
+ };
117
+
118
+ module.exports = { compileThemes };
@@ -0,0 +1,42 @@
1
+ const path = require('path');
2
+ const fs = require('fs').promises;
3
+
4
+ /**
5
+ * Copies local font files to the output directory.
6
+ *
7
+ * @param {Array} localFonts - The local fonts configuration.
8
+ * @param {string} outputDir - The output directory.
9
+ */
10
+ const copyLocalFonts = async (localFonts, outputDir) => {
11
+ if (!localFonts || localFonts.length === 0) {
12
+ console.log('No local fonts to copy.');
13
+ return;
14
+ }
15
+ const { default: ora } = await import('ora');
16
+ const spinner = ora('Copying local fonts...').start();
17
+
18
+ try {
19
+ for (const font of localFonts) {
20
+ for (const weight in font.files) {
21
+ const srcPath = path.resolve(font.files[weight]);
22
+ const destDir = path.resolve(outputDir, 'fonts');
23
+ const destPath = path.resolve(
24
+ destDir,
25
+ path.basename(font.files[weight])
26
+ );
27
+
28
+ // Ensure the destination directory exists
29
+ await fs.mkdir(destDir, { recursive: true });
30
+
31
+ // Copy the font file
32
+ await fs.copyFile(srcPath, destPath);
33
+ spinner.succeed(`Copied ${srcPath} to ${destPath}`);
34
+ }
35
+ }
36
+ } catch (error) {
37
+ spinner.fail('Failed to copy local fonts.');
38
+ console.error(error);
39
+ }
40
+ };
41
+
42
+ module.exports = { copyLocalFonts };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * CSS Font Generator for Bernova CSS Framework
3
+ *
4
+ * Generates CSS font declarations for both Google Fonts and local font files.
5
+ * Creates @import statements for Google Fonts and @font-face rules for local fonts.
6
+ */
7
+
8
+ const path = require('path');
9
+
10
+ /**
11
+ * Generates CSS font declarations from fonts configuration
12
+ * Supports both Google Fonts (via @import) and local fonts (via @font-face)
13
+ *
14
+ * @param {Object} fonts - Fonts configuration object
15
+ * @param {Array} fonts.google - Google Fonts configuration array
16
+ * @param {Array} fonts.local - Local fonts configuration array
17
+ * @returns {string} Generated CSS font declarations
18
+ * @example
19
+ * generateCssFonts({
20
+ * google: [{ name: 'Roboto', weights: [400, 700] }],
21
+ * local: [{ name: 'CustomFont', files: { 400: './custom.ttf' } }]
22
+ * })
23
+ */
24
+ const generateCssFonts = (fonts) => {
25
+ let css = '';
26
+
27
+ // Generate Google Fonts @import statements
28
+ if (fonts?.google?.length) {
29
+ fonts.google.forEach((font) => {
30
+ const weights = font.weights.join(';');
31
+ css += `@import url('https://fonts.googleapis.com/css2?family=${font.name.replace(
32
+ / /g,
33
+ '+'
34
+ )}:wght@${weights}&display=swap');\n`;
35
+ });
36
+ }
37
+
38
+ // Generate local fonts @font-face declarations
39
+ if (fonts?.local?.length) {
40
+ fonts.local.forEach((font) => {
41
+ Object.entries(font.files).forEach(([weight, filePath]) => {
42
+ css += `
43
+ @font-face {
44
+ font-family: '${font.name}';
45
+ src: url('./fonts/${path.basename(filePath)}') format('truetype');
46
+ font-weight: ${weight};
47
+ font-style: normal;
48
+ }\n`;
49
+ });
50
+ });
51
+ }
52
+
53
+ return css;
54
+ };
55
+
56
+ module.exports = { generateCssFonts };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * CSS Documentation Fragment Extractor for Bernova
3
+ *
4
+ * Extracts specific sections from CSS documentation using comment markers.
5
+ * Used for partial compilation to preserve existing CSS sections.
6
+ */
7
+
8
+ /**
9
+ * Extracts a specific section from CSS documentation using regex matching
10
+ * Looks for content between matching comment markers
11
+ *
12
+ * @param {string} section - Name of the section to extract
13
+ * @param {string} doc - CSS document content to search in
14
+ * @returns {string} Extracted section content (trimmed) or empty string if not found
15
+ */
16
+ const extractDocFragment = ({ section, doc }) => {
17
+ // Create regex pattern to match section markers
18
+ const matcher = new RegExp(
19
+ `/\\* ${section} \\*/([\\s\\S]*?)/\\* ${section} \\*/`
20
+ );
21
+ const match = doc.match(matcher);
22
+ return match ? match[1].trim() : '';
23
+ };
24
+
25
+ module.exports = { extractDocFragment };
@@ -0,0 +1,31 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ /**
5
+ * Checks if a file exists at the specified path
6
+ * Safely handles path resolution and filesystem access errors
7
+ *
8
+ * @param {string} dir - The base directory path
9
+ * @param {string} currentPath - The relative file path to check
10
+ * @returns {boolean} True if the file exists, false otherwise
11
+ *
12
+ * @example
13
+ * fileExists('/project', 'src/index.js') // true if /project/src/index.js exists
14
+ * fileExists('.', 'package.json') // true if ./package.json exists
15
+ */
16
+ const fileExists = (dir, currentPath) => {
17
+ try {
18
+ if (!dir || !currentPath) {
19
+ return false;
20
+ }
21
+
22
+ const fullPath = path.resolve(dir, currentPath);
23
+ return fs.existsSync(fullPath);
24
+ } catch (error) {
25
+ // Handle any filesystem or path resolution errors
26
+ console.warn(`Error checking file existence: ${error.message}`);
27
+ return false;
28
+ }
29
+ };
30
+
31
+ module.exports = { fileExists };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Base CSS Generation for Bernova
3
+ *
4
+ * Generates foundational CSS including font definitions and CSS reset.
5
+ * Handles local font copying and CSS font-face generation.
6
+ */
7
+
8
+ const { resetCss: defaultResetCss } = require('../../constants/resetCss');
9
+ const { copyLocalFonts } = require('../copyLocalFonts/copyLocalFonts.utils');
10
+ const {
11
+ generateCssFonts,
12
+ } = require('../copyLocalFonts/generateCssFonts.utils');
13
+
14
+ /**
15
+ * Generates base CSS content including fonts and optional reset styles
16
+ *
17
+ * @param {Object} params - Generation parameters
18
+ * @param {Object} params.fonts - Font configuration object
19
+ * @param {Array} params.fonts.local - Local font files to copy
20
+ * @param {boolean} params.resetCss - Whether to include CSS reset
21
+ * @param {string} params.stylesPath - Output path for font files
22
+ * @returns {Promise<string>} Generated base CSS content
23
+ */
24
+ const generateBaseCss = async ({ fonts, resetCss, stylesPath }) => {
25
+ // Copy local font files to the output directory
26
+ if (fonts?.local && Array.isArray(fonts.local) && fonts.local.length > 0) {
27
+ await copyLocalFonts(fonts.local, stylesPath);
28
+ }
29
+
30
+ // Generate base CSS content
31
+ return (() => {
32
+ let baseCss = '';
33
+
34
+ // Add font-face declarations if fonts are configured
35
+ if (fonts) {
36
+ const fontCss = generateCssFonts(fonts);
37
+ if (fontCss) {
38
+ baseCss += fontCss + '\n';
39
+ }
40
+ }
41
+
42
+ // Add CSS reset if enabled
43
+ if (resetCss) {
44
+ baseCss += defaultResetCss + '\n';
45
+ }
46
+
47
+ return baseCss;
48
+ })();
49
+ };
50
+
51
+ module.exports = { generateBaseCss };
@@ -0,0 +1,42 @@
1
+ const { filterGenerateCss } = require('./helpers/filterGenerateCss.utils');
2
+
3
+ /**
4
+ * Generates CSS based on the provided source, media queries, and other parameters.
5
+ *
6
+ * @param {Object} source - The source object containing foundations and theme.
7
+ * @param {string} dir - The directory where the CSS files will be saved.
8
+ * @param {Array} mediaQueries - An array of media queries to be used.
9
+ * @param {string} name - The name to be used for the generated CSS.
10
+ * @param {boolean} [generateProvider=false] - Flag to determine if a provider should be generated.
11
+ * @param {string} [baseCss=''] - Base font CSS to be included in the generated CSS.
12
+ * @returns {Promise<Object>} - A promise that resolves to an object containing the generated CSS and minified CSS.
13
+ */
14
+ const generateCSS = async ({ source, prefix, baseCss = '', compilerType }) => {
15
+ const { default: ora } = await import('ora');
16
+ const spinner = ora('Generating CSS...').start();
17
+
18
+ try {
19
+ const { stylesCss, foundationsCss, stylesDocs, rootDocs, globalDocs } =
20
+ filterGenerateCss({
21
+ source,
22
+ compilerType,
23
+ baseCss,
24
+ prefix,
25
+ });
26
+
27
+ spinner.succeed('CSS generation completed successfully.');
28
+ return {
29
+ stylesCss,
30
+ foundationsCss,
31
+ stylesDocs,
32
+ rootDocs,
33
+ globalDocs,
34
+ };
35
+ } catch (error) {
36
+ spinner.fail('Error generating CSS.');
37
+ console.error(error);
38
+ throw error; // Re-throw the error after logging it
39
+ }
40
+ };
41
+
42
+ module.exports = { generateCSS };
@@ -0,0 +1,22 @@
1
+ const { cssAdvancedSelectors } = require('../../../../constants/index.js');
2
+
3
+ /**
4
+ * Handles advanced CSS selectors and processes nested objects.
5
+ *
6
+ * @param {Array} selectors - An array of selector objects.
7
+ * @param {string} ruleName - The base rule name to be used.
8
+ * @param {Function} processSource - A function to process nested objects.
9
+ */
10
+ const advancedSelectorHandler = (selectors, ruleName, processSource) => {
11
+ selectors.forEach((key) => {
12
+ for (const [selector, { $target, ...value }] of Object.entries(key)) {
13
+ if (cssAdvancedSelectors[selector] && $target) {
14
+ const parsedSelector = cssAdvancedSelectors[selector];
15
+ const completeRuleName = `${ruleName}${parsedSelector}${$target}`;
16
+ processSource({ source: value, theRule: completeRuleName });
17
+ }
18
+ }
19
+ });
20
+ };
21
+
22
+ module.exports = { advancedSelectorHandler };