bernova 1.2.2 → 1.3.1
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/CHANGELOG.md +12 -0
- package/README.md +5 -0
- package/dist/bin/buildstyle.js +1 -1
- package/dist/src/lib/generateProvider/template/providerTemplate.d.ts +2 -0
- package/dist/src/lib/generateProvider/template/providerTemplate.js +163 -1
- package/dist/src/styles/default/default.css +9 -0
- package/dist/src/styles/default/default.min.css +0 -0
- package/dist/styles/default/default.css +9 -0
- package/dist/styles/default/default.min.css +0 -0
- package/dist/styles/default/default.min.min.css +0 -0
- package/package.json +1 -1
- package/src/lib/generateProvider/template/providerTemplate.d.ts +2 -0
- package/src/lib/generateProvider/template/providerTemplate.js +2 -0
- package/src/styles/default/default.css +9 -0
- package/src/styles/default/default.min.css +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ All notable changes to Bernova will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.3.1] - 2026-01-21
|
|
9
|
+
|
|
10
|
+
### Patch
|
|
11
|
+
|
|
12
|
+
- **prevent minify provider**: Prevent minify providerTemplate.js file
|
|
13
|
+
|
|
14
|
+
## [1.3.0] - 2026-01-21
|
|
15
|
+
|
|
16
|
+
### New Features
|
|
17
|
+
|
|
18
|
+
- **Added --embed-css flag**: Added the function for embedded styles.
|
|
19
|
+
|
|
8
20
|
## [1.2.2] - 2026-01-16
|
|
9
21
|
|
|
10
22
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1854,6 +1854,8 @@ When publishing our projects, depending of the packager configuration, it is nec
|
|
|
1854
1854
|
- `"provider"`: Custom output path for provider file
|
|
1855
1855
|
- `"tools"`: Custom output path for tools files (cssVars, cssClasses, etc)
|
|
1856
1856
|
|
|
1857
|
+
- **embedCss**: When set to `'true'`, instead of generating a static CSS file, the styles generated by Bernova will be embedded.
|
|
1858
|
+
|
|
1857
1859
|
### Overwrite or set a single customOutDirs
|
|
1858
1860
|
|
|
1859
1861
|
You may need to run the bv-build script in multiple outputs, and the bernova.config.json file configuration only supports one path. In these cases, you can use flags to specify the output path for the specific case.
|
|
@@ -1896,4 +1898,7 @@ npx bv-build --types none
|
|
|
1896
1898
|
|
|
1897
1899
|
# Prevent process the js ad dts files
|
|
1898
1900
|
npx bv-build --prevent-process-js
|
|
1901
|
+
|
|
1902
|
+
# Embed styles
|
|
1903
|
+
npx bv-build --embed-css
|
|
1899
1904
|
```
|
package/dist/bin/buildstyle.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const e=require("fs").promises,s=require("path"),t=require("@babel/core"),{minify:
|
|
2
|
+
const e=require("fs").promises,s=require("path"),t=require("@babel/core"),{minify:n}=require("terser"),{extractDocFragment:r,writeDoc:a,fileExists:o,readConfigData:i,buildRelativePath:c}=require("../src/lib");async function l({baseOutPath:t,jsFile:n,rootDir:i,customOutDirs:l,dir:m,minifyJS:p,preventMoveJS:h,provider:f,type:y="",embedCss:b,cssFiles:g}){const D=n.name.endsWith(".d.ts"),j=s.resolve(m,n.path,n.name);if(!o(m,j))return void console.error(`File not found: ${j}`);let C=await e.readFile(j,"utf8");const O=!!l?.css||b&&g.length>0;if("stats.js"===n.name&&O){const t=r({section:"CssThemes",doc:C}),n=t.replace(/export const cssThemes\s*=\s*/,""),a=new Function(`return (${n})`)();if(l?.css){const e=s.relative(i||"",f.path),n=c({from:s.resolve(e),to:s.resolve(m,l.css)}),r=v({cssThemes:a,cssOutPath:""!==y?s.join("../",n):n});C=C.replace(t,`export const cssThemes = {\n${r}};\n`)}else if(b&&g.length>0){const n={},r=await g.reduce(async(t,{name:r,path:a,parent:i})=>{const c=s.resolve(m,a,r);if(o(m,c)){const s=await e.readFile(c,"utf8");if(i)i.forEach(e=>{const{name:t,position:r}=e;t in n||(n[t]={before:"",after:""}),n[t][r]+=s.replace(/\s+/g,"")});else{const e=r.replace(".css","").replace(".min","");e in t||(t[e]=""),t[e]+=s.replace(/\s+/g,"")}}return t},{}),a=`export const cssThemes = {\n${Object.entries(r).reduce((e,[s,t])=>{const r=n[s]||{before:"",after:""};return e+`'${s}': { css: \`${r.before+t+r.after}\` },\n`},"")}};\n`;C=C.replace(t,a)}}if(n.name===`${f.name.toLocaleLowerCase()}.js`&&O){const t="\n #linkBuilder = (css, id) => {\n if (typeof document === 'undefined') return;\n let styleElement = document.getElementById(id);\n if (!styleElement) {\n styleElement = document.createElement('style');\n styleElement.id = id;\n styleElement.type = 'text/css';\n document.head.appendChild(styleElement);\n }\n styleElement.innerHTML = css;\n };\n #handlerThemes = (data) => {\n const { css } = data;\n this.#linkBuilder(css, this.#linkId);\n };\n #cleanUpLinks = () => {\n if (typeof document === 'undefined') return;\n const style = document.getElementById(this.#linkId);\n if (style) style.remove();\n };\n ",n="../src/lib/generateProvider/template/providerTemplate.js";let a=await e.readFile(s.resolve(__dirname,n),"utf8");a=a.replace(/\$_Provider_\$/g,f.name);const o=r({section:"Bernova provider methods",doc:a});C=a.replace(o,t.trim())}if(n.name===`${f.name.toLocaleLowerCase()}.d.ts`&&O){const t="\n #linkBuilder(css: string, id: string): void;\n #handlerThemes(data: { css: string }): void;\n #cleanUpLinks(): void;\n ",n="../src/lib/generateProvider/template/providerTemplate.d.ts";let a=await e.readFile(s.resolve(__dirname,n),"utf8");a=a.replace(/\$_Provider_\$/g,f.name);const o=r({section:"Bernova provider methods",doc:a});C=a.replace(o,t.trim())}"cjs"!==y||D||(C=await d(C,j,!0)),"esm"!==y||D||(C=await d(C,j)),p&&!D&&(C=await u(C));const $=s.relative(i||"",n.path),w=h?j:s.resolve(t,$,n.name);await a(w,C,n.name)}async function m({baseOutPath:t,cssFiles:n,rootDir:r,customOutDirs:i,dir:c}){for(const l of n){const n=(()=>r&&!i?.css?s.relative(r,l.path):i?.css?i.css:l.path)(),m=s.resolve(c,l.path,l.name);if(o(c,m)){const r=await e.readFile(m,"utf8"),o=l.name.replace(".min","");await a(s.resolve(t,n,o),r,o)}}}function p({baseOutDir:e,type:t="-"}){const n=(()=>{switch(t){case"cjs":return"cjs";case"esm":return"esm";default:return""}})();return s.join(e,n)}async function d(e,s,n=!1){const r=!!n&&"commonjs";return(await t.transformAsync(e,{filename:s,presets:[["@babel/preset-env",{modules:r,targets:{node:"current"}}]]})).code}async function u(e){return(await n(e,{compress:{dead_code:!0,drop_console:!1,drop_debugger:!0,keep_classnames:!1,keep_fargs:!0,keep_fnames:!1,keep_infinity:!1},mangle:{toplevel:!1},format:{comments:!1}})).code}function h({themes:e,minifyCss:t}){return e&&Array.isArray(e)&&e.length>0?e.reduce((e,n)=>{const{name:r,stylesPath:a,foreignThemes:o}=n;return r&&a&&y(e,{name:t?`${r}.min.css`:`${r}.css`,path:a}),o&&Array.isArray(o)&&o.length>0&&o.forEach(t=>{const n=s.basename(t.path),a=t.path.replace(n,"").trim(),o=e.findIndex(e=>e.name===n&&e.path===a);o>=0?e[o].parent.push({name:r,position:t.position}):e.push({name:n,path:a,parent:[{name:r,position:t.position}]})}),e},[]):[]}function f({provider:e,themes:s,preventMoveDTS:t=!1}){const n=s&&s.bvTools?s.reduce((e,{bvTools:s})=>{const{path:n,declarationHelp:r,cssVariables:a,cssClassNames:o,cssMediaQueries:i,cssGlobalStyles:c,availableComponents:l}=s,m=r&&!t;return a&&(y(e,{name:"cssVars.js",path:n}),m&&y(e,{name:"cssVars.d.ts",path:n})),o&&(y(e,{name:"cssClasses.js",path:n}),m&&y(e,{name:"cssClasses.d.ts",path:n})),i&&(y(e,{name:"cssMediaQueries.js",path:n}),m&&y(e,{name:"cssMediaQueries.d.ts",path:n})),c&&(y(e,{name:"cssGlobalStyles.js",path:n}),m&&y(e,{name:"cssGlobalStyles.d.ts",path:n})),l&&(y(e,{name:"cssAvailableComponents.js",path:n}),m&&y(e,{name:"cssAvailableComponents.d.js",path:n})),e},[]):[];return e&&(y(n,{name:`${e.name.toLocaleLowerCase()}.js`,path:e.path}),y(n,{name:"stats.js",path:`${e.path}/stats`}),e.declarationHelp&&!t&&(y(n,{name:`${e.name.toLocaleLowerCase()}.d.ts`,path:e.path}),y(n,{name:"stats.d.ts",path:`${e.path}/stats`}))),n}function v({cssThemes:e,cssOutPath:t}){return Object.entries(e).reduce((e,[n,{foreign:r}])=>{const{before:a,after:o}=r,i=a&&Array.isArray(a)&&a.length>0?a.reduce((e,n,r)=>{const a=s.basename(n);return r>0&&(e+=", "),e+`'${t}/${a}'`},""):"",c=o&&Array.isArray(o)&&o.length>0?o.reduce((e,n,r)=>{const a=s.basename(n);return r>0&&(e+=", "),e+`'${t}/${a}'`},""):"";return e+`'${n}': { css: '${t}/${n}.css', foreign: { before: [${i}], after: [${c}] } },\n`},"")}function y(e,s){e.some(e=>e.name===s.name&&e.path===s.path)||e.push(s)}function b(){const e=["--base-out-dir","--root-dir","--prevent-process-js","--prevent-move-js","--prevent-move-dts","--types","--css","--tools","--provider","--embed-css"],s={};for(let t=0;t<process.argv.length;t++)if(e.includes(process.argv[t])){const n=process.argv[t].replace("--","").replace(/-([a-z])/g,(e,s)=>s.toUpperCase()),r=process.argv[t+1];s[n]=(()=>!(r&&!e.includes(r))||("none"===r.toLocaleLowerCase()?"":r))()}return s}function g({jsonCustomOutDirs:e,cliCustomOutDirs:s}){let t={};return e&&(t={...e}),s&&(t={...t,...s}),Object.keys(t).length>0?t:void 0}(async()=>{const e=process.cwd(),t=await i(s.resolve(e,"bernova.config.json")),{compilerOptions:n,provider:r,themes:a}=t;n&&r&&a||(console.error("Invalid configuration: Missing compilerOptions, themes or provider"),process.exit(1));const{baseOutDir:o,rootDir:c,minifyCss:d,minifyJS:u,preventMoveJS:v,preventMoveDTS:y,types:D,embedCss:j,customOutDirs:C}=n,{baseOutDir:O,rootDir:$,types:w,preventMoveJs:T,preventMoveDts:F,preventProcessJs:_=!1,embedCss:M,...P}=b(),S=O??o??"",A=$??c??void 0,E=T??v??!1,L=F??y??!1,k=w??D??void 0,J=M??j??!1,x=g({jsonCustomOutDirs:C,cliCustomOutDirs:P}),B=h({themes:a,minifyCss:d}),I=_?[]:f({provider:r,themes:a,preventMoveDTS:L}),q=p({baseOutDir:S});if(B&&B.length>0&&!J&&await m({baseOutPath:q,cssFiles:B,rootDir:A,customOutDirs:x,dir:e}),I&&I.length>0)if(k&&Array.isArray(k)&&k.length>0)for(const s of k){const t=p({baseOutDir:S,type:s});for(const n of I)await l({baseOutPath:t,jsFile:n,rootDir:A,customOutDirs:x,dir:e,minifyJS:u,preventMoveJS:E,provider:r,type:s,embedCss:J,cssFiles:B})}else for(const s of I)await l({baseOutPath:q,jsFile:s,rootDir:A,customOutDirs:x,dir:e,minifyJS:u,preventMoveJS:E,provider:r,embedCss:J,cssFiles:B})})();
|
|
@@ -32,12 +32,14 @@ export declare class $_Provider_$ {
|
|
|
32
32
|
#themesMediaQueries: typeof cssMediaQueries;
|
|
33
33
|
#linkId: string;
|
|
34
34
|
#jsInCss: boolean;
|
|
35
|
+
/* Bernova provider methods */
|
|
35
36
|
#linkBuilder: (url: string, id: string) => void;
|
|
36
37
|
#handlerThemes: (data: {
|
|
37
38
|
css: string;
|
|
38
39
|
foreign?: { high?: string[]; low?: string[] };
|
|
39
40
|
}) => void;
|
|
40
41
|
#cleanUpLinks: () => void;
|
|
42
|
+
/* Bernova provider methods */
|
|
41
43
|
|
|
42
44
|
constructor(options?: { linkId?: string; jsInCss?: boolean });
|
|
43
45
|
|
|
@@ -1 +1,163 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
cssThemes,
|
|
3
|
+
cssClasses,
|
|
4
|
+
cssVars,
|
|
5
|
+
cssAvailableComponents,
|
|
6
|
+
cssGlobalStyles,
|
|
7
|
+
cssMediaQueries,
|
|
8
|
+
} from './stats/stats';
|
|
9
|
+
|
|
10
|
+
export class $_Provider_$ {
|
|
11
|
+
#currentTheme;
|
|
12
|
+
#themes;
|
|
13
|
+
#themesVariables;
|
|
14
|
+
#themesClassNames;
|
|
15
|
+
#themesComponents;
|
|
16
|
+
#themesGlobalStyles;
|
|
17
|
+
#themesMediaQueries;
|
|
18
|
+
#linkId;
|
|
19
|
+
#jsInCss;
|
|
20
|
+
/* Bernova provider methods */
|
|
21
|
+
#linkBuilder = (url, id) => {
|
|
22
|
+
if (typeof document === 'undefined') return;
|
|
23
|
+
let linkElement = document.getElementById(id);
|
|
24
|
+
if (!linkElement) {
|
|
25
|
+
linkElement = document.createElement('link');
|
|
26
|
+
linkElement.id = id;
|
|
27
|
+
linkElement.rel = 'stylesheet';
|
|
28
|
+
document.head.appendChild(linkElement);
|
|
29
|
+
}
|
|
30
|
+
const href = new URL(url, import.meta.url).href;
|
|
31
|
+
linkElement.href = href;
|
|
32
|
+
};
|
|
33
|
+
#handlerThemes = (data) => {
|
|
34
|
+
const { css, foreign } = data;
|
|
35
|
+
const beforeFiles = foreign?.before || [];
|
|
36
|
+
const afterFiles = foreign?.after || [];
|
|
37
|
+
//* set the lower priority foreign themes
|
|
38
|
+
beforeFiles.forEach((url, idx) => {
|
|
39
|
+
const id = `${this.#linkId}-foreign-before-${idx + 1}`;
|
|
40
|
+
this.#linkBuilder(url, id);
|
|
41
|
+
});
|
|
42
|
+
//* set main theme
|
|
43
|
+
this.#linkBuilder(css, this.#linkId);
|
|
44
|
+
//* set the higher priority foreign themes
|
|
45
|
+
afterFiles.forEach((url, idx) => {
|
|
46
|
+
const id = `${this.#linkId}-foreign-after-${idx + 1}`;
|
|
47
|
+
this.#linkBuilder(url, id);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
#cleanUpLinks = () => {
|
|
51
|
+
if (typeof document === 'undefined') return;
|
|
52
|
+
const links = document.querySelectorAll(`link[id^="${this.#linkId}"]`);
|
|
53
|
+
links.forEach((link) => link.remove());
|
|
54
|
+
};
|
|
55
|
+
/* Bernova provider methods */
|
|
56
|
+
|
|
57
|
+
constructor({ linkId, jsInCss } = {}) {
|
|
58
|
+
this.#themes = cssThemes;
|
|
59
|
+
this.#themesVariables = cssVars;
|
|
60
|
+
this.#themesClassNames = cssClasses;
|
|
61
|
+
this.#themesComponents = cssAvailableComponents;
|
|
62
|
+
this.#themesGlobalStyles = cssGlobalStyles;
|
|
63
|
+
this.#themesMediaQueries = cssMediaQueries;
|
|
64
|
+
this.#linkId = linkId || 'kb-styled-link';
|
|
65
|
+
this.#currentTheme = Object.keys(cssThemes)[0];
|
|
66
|
+
this.#jsInCss = !!jsInCss;
|
|
67
|
+
this.getComponentStyles = this.getComponentStyles.bind(this);
|
|
68
|
+
|
|
69
|
+
if (
|
|
70
|
+
typeof window !== 'undefined' &&
|
|
71
|
+
typeof document !== 'undefined' &&
|
|
72
|
+
this.#jsInCss
|
|
73
|
+
) {
|
|
74
|
+
this.#cleanUpLinks();
|
|
75
|
+
this.#handlerThemes(this.#themes[this.#currentTheme]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// ? getters and setters
|
|
79
|
+
//* theme selected
|
|
80
|
+
get themeSelected() {
|
|
81
|
+
return this.#currentTheme;
|
|
82
|
+
}
|
|
83
|
+
set themeSelected(themeName) {
|
|
84
|
+
if (themeName in this.#themes) {
|
|
85
|
+
if (this.#jsInCss) {
|
|
86
|
+
this.#cleanUpLinks();
|
|
87
|
+
this.#handlerThemes(this.#themes[themeName]);
|
|
88
|
+
}
|
|
89
|
+
this.#currentTheme = themeName;
|
|
90
|
+
} else {
|
|
91
|
+
throw new Error(`${themeName} is not exists`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//* themes
|
|
95
|
+
get allThemesNames() {
|
|
96
|
+
return Object.keys(this.#themes);
|
|
97
|
+
}
|
|
98
|
+
get allThemes() {
|
|
99
|
+
return this.#themes;
|
|
100
|
+
}
|
|
101
|
+
//* variables
|
|
102
|
+
get variables() {
|
|
103
|
+
return this.#themesVariables[this.#currentTheme];
|
|
104
|
+
}
|
|
105
|
+
//* classNames
|
|
106
|
+
get classNames() {
|
|
107
|
+
return this.#themesClassNames[this.#currentTheme];
|
|
108
|
+
}
|
|
109
|
+
//* components
|
|
110
|
+
get components() {
|
|
111
|
+
return this.#themesComponents[this.#currentTheme];
|
|
112
|
+
}
|
|
113
|
+
//* global styles
|
|
114
|
+
get globalStyles() {
|
|
115
|
+
return this.#themesGlobalStyles[this.#currentTheme];
|
|
116
|
+
}
|
|
117
|
+
//* media queries
|
|
118
|
+
get mediaQueries() {
|
|
119
|
+
return this.#themesMediaQueries[this.#currentTheme];
|
|
120
|
+
}
|
|
121
|
+
//? methods
|
|
122
|
+
getComponentStyles({ variant, component, additionalClassNames }) {
|
|
123
|
+
const THEME = this.#themesClassNames[this.#currentTheme];
|
|
124
|
+
const upperComponent = component.toLocaleUpperCase();
|
|
125
|
+
const COMPONENT = THEME[upperComponent];
|
|
126
|
+
|
|
127
|
+
if (!COMPONENT) return {};
|
|
128
|
+
|
|
129
|
+
const structure = {};
|
|
130
|
+
const startV = '$_';
|
|
131
|
+
const componentVariant = (() => {
|
|
132
|
+
if (!!variant) {
|
|
133
|
+
const lowerVariant = variant.toLocaleLowerCase().replace(/-/g, '_');
|
|
134
|
+
return `${startV}${lowerVariant}`;
|
|
135
|
+
} else {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
})();
|
|
139
|
+
if (componentVariant && componentVariant in COMPONENT) {
|
|
140
|
+
const variantFragment = COMPONENT[componentVariant];
|
|
141
|
+
Object.entries(variantFragment).forEach(([key, value]) => {
|
|
142
|
+
if (!(key in structure)) {
|
|
143
|
+
structure[key] = value;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
Object.entries(COMPONENT).forEach(([key, value]) => {
|
|
148
|
+
if (key.startsWith(startV)) return;
|
|
149
|
+
if (!(key in structure)) {
|
|
150
|
+
structure[key] = value;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (!!additionalClassNames && Object.keys(additionalClassNames).length) {
|
|
154
|
+
Object.entries(additionalClassNames).forEach(([key, value]) => {
|
|
155
|
+
if (!(key in structure)) {
|
|
156
|
+
structure[key] = '';
|
|
157
|
+
}
|
|
158
|
+
structure[key] += ` ${value}`;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return structure;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -32,12 +32,14 @@ export declare class $_Provider_$ {
|
|
|
32
32
|
#themesMediaQueries: typeof cssMediaQueries;
|
|
33
33
|
#linkId: string;
|
|
34
34
|
#jsInCss: boolean;
|
|
35
|
+
/* Bernova provider methods */
|
|
35
36
|
#linkBuilder: (url: string, id: string) => void;
|
|
36
37
|
#handlerThemes: (data: {
|
|
37
38
|
css: string;
|
|
38
39
|
foreign?: { high?: string[]; low?: string[] };
|
|
39
40
|
}) => void;
|
|
40
41
|
#cleanUpLinks: () => void;
|
|
42
|
+
/* Bernova provider methods */
|
|
41
43
|
|
|
42
44
|
constructor(options?: { linkId?: string; jsInCss?: boolean });
|
|
43
45
|
|
|
@@ -17,6 +17,7 @@ export class $_Provider_$ {
|
|
|
17
17
|
#themesMediaQueries;
|
|
18
18
|
#linkId;
|
|
19
19
|
#jsInCss;
|
|
20
|
+
/* Bernova provider methods */
|
|
20
21
|
#linkBuilder = (url, id) => {
|
|
21
22
|
if (typeof document === 'undefined') return;
|
|
22
23
|
let linkElement = document.getElementById(id);
|
|
@@ -51,6 +52,7 @@ export class $_Provider_$ {
|
|
|
51
52
|
const links = document.querySelectorAll(`link[id^="${this.#linkId}"]`);
|
|
52
53
|
links.forEach((link) => link.remove());
|
|
53
54
|
};
|
|
55
|
+
/* Bernova provider methods */
|
|
54
56
|
|
|
55
57
|
constructor({ linkId, jsInCss } = {}) {
|
|
56
58
|
this.#themes = cssThemes;
|
|
File without changes
|