bernova 1.7.5 → 1.7.7
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 +45 -0
- package/dist/interfaces/componentsType.ts +633 -173
- package/dist/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +1 -1
- package/dist/src/lib/generateCss/helpers/generateCssStyles.utils.js +1 -1
- package/dist/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +1 -1
- package/dist/src/lib/generateProvider/template/providerTemplate-link.js +170 -1
- package/dist/src/lib/generateProvider/template/providerTemplate-style.js +155 -1
- package/dist/src/lib/typingStyles/typingStyles.utils.js +1 -1
- package/dist/types/lib/generateCss/helpers/rulename/formatRuleName.utils.d.ts +2 -1
- package/package.json +1 -1
- package/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +48 -8
- package/src/lib/generateCss/helpers/generateCssStyles.utils.js +5 -2
- package/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +25 -0
- package/src/lib/generateProvider/template/providerTemplate-link.js +9 -3
- package/src/lib/generateProvider/template/providerTemplate-style.js +9 -3
- package/src/lib/typingStyles/typingStyles.utils.js +12 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
const{simplifyName:e}=require("../../../simplifyName/simplifyName.utils"),o=({register:o,prefix:
|
|
1
|
+
const{simplifyName:e}=require("../../../simplifyName/simplifyName.utils"),o=["$boolean$","$number$","$string$","$bigint$","$symbol$","$undefined$","$null$"],l=e=>{if(/^Symbol\.for\(['"](.+)['"]\)$/.test(e)){const o=e.match(/^Symbol\.for\(['"](.+)['"]\)$/);return{vl:Symbol.for(o[1]),tp:"symbol"}}return/^-?\d+n$/.test(e)?{vl:BigInt(e.slice(0,-1)),tp:"bigint"}:isNaN(e)||isNaN(parseFloat(e))?"true"===e?{vl:!0,tp:"boolean"}:"false"===e?{vl:!1,tp:"boolean"}:"null"===e?{vl:null,tp:"null"}:"undefined"===e?{vl:void 0,tp:"undefined"}:o.includes(e)?{vl:"''",tp:e.replaceAll("$","")}:{vl:`'${e}'`,tp:"string"}:{vl:Number(e),tp:"number"}},t=({register:o,prefix:t})=>{const r=new Set,n=({rg:o,space:c=2,lv:s=1})=>{const $=" ".repeat(c);return Object.entries(o).reduce((o,[p,a])=>{const d=p.replace(`${t}-`,"");if("object"==typeof a){const e=1===s,l=e?d.toUpperCase():d;o.prov.doc+=`${$}${l}: {\n`,o.prov.declare+=`${$}${l}: {\n`,o.comp.simple+=o.comp.simple.length?` | '${l}'`:`'${l}'`,o.comp.object+=e?`${$}${l}: '${l}',\n`:"";const t=c+2,r=s+1,{prov:{doc:p,declare:i},tools:{doc:v,declare:m}}=n({rg:a,space:t,lv:r});o.prov.doc+=p,o.prov.declare+=i,o.prov.doc+=`${$}},\n`,o.prov.declare+=`${$}},\n`,o.tools.doc+=v,o.tools.declare+=m}else if("boolean"==typeof a&&a){const l=e(d);r.has(l)||(r.add(l),o.tools.doc+=` ${l}: '${d}',\n`,o.tools.declare+=` ${d}: string,\n`);const t=d.split("__").at(-1);o.prov.doc+=`${$}${t}: '${d}',\n`,o.prov.declare+=`${$}${t}: string,\n`}else if("string"==typeof a){const{vl:n,tp:c}=l(a),s=e(a).replace(`${t}_`,"");r.has(s)||(r.add(s),o.tools.doc+=` ${s}: ${n},\n`,o.tools.declare+=` ${s}: ${c},\n`);const p=d.split("__").at(-1);o.prov.doc+=`${$}${p}: ${n},\n`,o.prov.declare+=`${$}${p}: ${c},\n`}else"function"==typeof a&&("dynamic_values"===d?o.prov.doc+=`${$}${d}: ${a.toString()},\n`:"dynamic_values_type"===d&&(o.prov.declare+=`${$}dynamic_values: ${a()},\n`));return o},{comp:{simple:"",object:""},prov:{doc:"",declare:""},tools:{doc:"",declare:""}})};return n({rg:o})};module.exports={handlerRegister:t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const{formatRuleName:e,setForeignRegister:r,pseudoHandler:s,foreignHandler:t,attributeHandler:a,advancedSelectorHandler:i,separateStyles:
|
|
1
|
+
const{formatRuleName:e,setForeignRegister:r,pseudoHandler:s,foreignHandler:t,attributeHandler:a,advancedSelectorHandler:i,separateStyles:l,extractValues:n,mediaQueriesHandler:o,generateMediaQueries:u,handlerRegister:c,setDynamicRegister:d,processDynamicProps:p}=require("./index.js"),g=({source:g,mediaConfig:m,prefix:f})=>{let $="",y={};const R={},h=f?`${f}-`:"",b=({source:u,parentRule:c,theRule:g})=>{const{styles:f,lib:{$dynamicValues:S,$literals:x,...N},other:j}=l(u),D=Object.entries(f).length>0,O=Object.entries(j).length>0,V=Object.entries(N).length>0,Q=S?p(S):void 0,v=e({theRule:g,parentRule:c,register:y,hasStyles:D,prefix:h,literals:x});if(D&&($+=`.${v} { ${n({styles:f,dynamicValues:Q})} }\n`),V){const{$pseudoClasses:e,$pseudoElements:l,$mediaQueries:n,$attributes:u,$advancedSelectors:c,$foreign:p}=N;if(Object.entries(j).length&&b({source:j,parentRule:v}),e&&s({pseudoData:e,ruleName:v,processSource:b}),l&&s({pseudoData:l,ruleName:v,processSource:b}),n&&m&&o({config:m,mediaQueries:n,parentRule:v,theRule:g,mediaRegister:R}),u&&a({attributes:u,ruleName:v,processSource:b}),c&&i(c,v,b),p){const e=t({foreign:p,prefix:h}),s=v.replace(h,"");r({ruleName:s,foreignRegister:e,register:y})}Q&&d({dynamicValues:Q,register:y,ruleName:v,prefix:h})}if(O)for(const[u,f]of Object.entries(j))if("object"==typeof f){const{$pseudoClasses:S,$pseudoElements:x,$mediaQueries:N,$attributes:j,$advancedSelectors:D,$foreign:O,$dynamicValues:V,$literals:Q,...v}=f,{styles:H,other:C}=l(v),E=Object.entries(H).length>0,k=V?p(V):void 0,q=e({key:u,theRule:g,parentRule:c,register:y,hasStyles:E,prefix:h,literals:Q});if(E&&($+=`.${q} { ${n({styles:H,dynamicValues:k})} }\n`),Object.entries(C).length&&b({source:C,parentRule:q}),S&&s({pseudoData:S,ruleName:q,processSource:b}),x&&s({pseudoData:x,ruleName:q,processSource:b}),N&&m&&o({config:m,mediaQueries:N,parentRule:q,theRule:g,mediaRegister:R}),j&&a({attributes:j,ruleName:q,processSource:b}),D&&i(D,q,b),O){const e=t({foreign:O,prefix:h}),s=q.replace(h,"");r({ruleName:s,foreignRegister:e,register:y})}k&&d({dynamicValues:k,register:y,ruleName:q,prefix:h})}};b({source:g});const S=c({register:y,prefix:f}),x=u(R);return{styles:$.concat(x),stylesDocs:S}};module.exports={generateCssStyles:g};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const{formattedStatKey:e}=require("../utils"),t=({register:t,component:n,variant:r,mainComponent:i,hasStyles:o,prefix:a})=>{if(i in t||(t[i]={}),n in t[i]||(t[i][n]=!!o&&`${a}${n}`),r){const o=`$_${e(r)}`;if(o in t[i]||(t[i][o]={}),!(n in t[i][o])){const e=!!t[i][n];t[i][o][n]=e?`${a}${n} ${a}${n}--${r}`:`${a}${n}--${r}`}}},n=({parentRule:e,key:t,prefix:n})=>{const[r,i]=e.split("--");return{mainComponent:r,variant:i&&i.length&&i.replace(/\[.*?\]/g,""),lowerKey:!!t&&t.length&&t.toLocaleLowerCase()}},r=({ruleName:t,foreignRegister:r,register:i})=>{const{mainComponent:o,variant:a}=n({parentRule:t});if(o in i||(i[o]={}),a){const t=`$_${e(a)}`;t in i[o]||(i[o][t]={}),i[o][t]={...i[o][t],...r}}else i[o]={...i[o],...r}},i=({key:e="",parentRule:r,theRule:i,hasStyles:o,prefix:a,register:s={}})=>{let
|
|
1
|
+
const{formattedStatKey:e}=require("../utils"),t=({register:t,component:n,variant:r,mainComponent:i,hasStyles:o,prefix:a,literals:s})=>{if(i in t||(t[i]={}),n in t[i]||(t[i][n]=!!o&&`${a}${n}`),r){const o=`$_${e(r)}`;if(o in t[i]||(t[i][o]={}),!(n in t[i][o])){const e=!!t[i][n];t[i][o][n]=e?`${a}${n} ${a}${n}--${r}`:`${a}${n}--${r}`}}s&&Object.entries(s).forEach(([n,o])=>{const a=String(o);if(r){const s=`$_${e(r)}`;if(t[i][s][n]=a,!(n in t[i])){const e=null===o?"$null$":`$${String(typeof o)}$`;t[i][n]=e}}else t[i][n]=a})},n=({parentRule:e,key:t,prefix:n})=>{const[r,i]=e.split("--");return{mainComponent:r,variant:i&&i.length&&i.replace(/\[.*?\]/g,""),lowerKey:!!t&&t.length&&t.toLocaleLowerCase()}},r=({ruleName:t,foreignRegister:r,register:i})=>{const{mainComponent:o,variant:a}=n({parentRule:t});if(o in i||(i[o]={}),a){const t=`$_${e(a)}`;t in i[o]||(i[o][t]={}),i[o][t]={...i[o][t],...r}}else i[o]={...i[o],...r}},i=({key:e="",parentRule:r,theRule:i,hasStyles:o,prefix:a,register:s={},literals:l})=>{let $="";if(i)$=i;else if(r){const{mainComponent:i,variant:p,lowerKey:m}=n({parentRule:r,key:e}),c=i.replace(a,"");e.startsWith("_")?($=p?`${i}_${m}--${p}`:`${i}_${m}`,t({register:s,mainComponent:c,component:`${c}_${m}`,variant:p,hasStyles:o,prefix:a,literals:l})):m&&($=`${i}--${m}`,t({register:s,mainComponent:c,component:c,variant:m,hasStyles:o,prefix:a,literals:l}))}else{const n=e.toLocaleLowerCase().replace(/\[.*?\]/g,"");$=`${a}${n}`,e.length&&t({register:s,component:n,mainComponent:n,hasStyles:o,prefix:a,literals:l})}return $};module.exports={formatRuleName:i,setForeignRegister:r};
|
|
@@ -1 +1,170 @@
|
|
|
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 = (css, 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 baseUrl = document.location.origin;
|
|
31
|
+
const href = new URL(css, baseUrl).href;
|
|
32
|
+
linkElement.href = href;
|
|
33
|
+
};
|
|
34
|
+
#handlerThemes = (data) => {
|
|
35
|
+
const { css, foreign } = data;
|
|
36
|
+
const beforeFiles = foreign?.before || [];
|
|
37
|
+
const afterFiles = foreign?.after || [];
|
|
38
|
+
//* set the lower priority foreign themes
|
|
39
|
+
beforeFiles.forEach((url, idx) => {
|
|
40
|
+
const id = `${this.#linkId}-foreign-before-${idx + 1}`;
|
|
41
|
+
this.#linkBuilder(url, id);
|
|
42
|
+
});
|
|
43
|
+
//* set main theme
|
|
44
|
+
this.#linkBuilder(css, this.#linkId);
|
|
45
|
+
//* set the higher priority foreign themes
|
|
46
|
+
afterFiles.forEach((url, idx) => {
|
|
47
|
+
const id = `${this.#linkId}-foreign-after-${idx + 1}`;
|
|
48
|
+
this.#linkBuilder(url, id);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
#cleanUpLinks = () => {
|
|
52
|
+
if (typeof document === 'undefined') return;
|
|
53
|
+
const links = document.querySelectorAll(`link[id^="${this.#linkId}"]`);
|
|
54
|
+
links.forEach((link) => link.remove());
|
|
55
|
+
};
|
|
56
|
+
/* Bernova provider methods */
|
|
57
|
+
|
|
58
|
+
constructor({ linkId, jsInCss } = {}) {
|
|
59
|
+
this.#themes = cssThemes;
|
|
60
|
+
this.#themesVariables = cssVars;
|
|
61
|
+
this.#themesClassNames = cssClasses;
|
|
62
|
+
this.#themesComponents = cssAvailableComponents;
|
|
63
|
+
this.#themesGlobalStyles = cssGlobalStyles;
|
|
64
|
+
this.#themesMediaQueries = cssMediaQueries;
|
|
65
|
+
this.#linkId = linkId || 'kb-styled-link';
|
|
66
|
+
this.#currentTheme = Object.keys(cssThemes)[0];
|
|
67
|
+
this.#jsInCss = !!jsInCss;
|
|
68
|
+
this.getComponentStyles = this.getComponentStyles.bind(this);
|
|
69
|
+
|
|
70
|
+
if (
|
|
71
|
+
typeof window !== 'undefined' &&
|
|
72
|
+
typeof document !== 'undefined' &&
|
|
73
|
+
this.#jsInCss
|
|
74
|
+
) {
|
|
75
|
+
this.#cleanUpLinks();
|
|
76
|
+
this.#handlerThemes(this.#themes[this.#currentTheme]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// ? getters and setters
|
|
80
|
+
//* theme selected
|
|
81
|
+
get themeSelected() {
|
|
82
|
+
return this.#currentTheme;
|
|
83
|
+
}
|
|
84
|
+
set themeSelected(themeName) {
|
|
85
|
+
if (themeName in this.#themes) {
|
|
86
|
+
if (this.#jsInCss) {
|
|
87
|
+
this.#cleanUpLinks();
|
|
88
|
+
this.#handlerThemes(this.#themes[themeName]);
|
|
89
|
+
}
|
|
90
|
+
this.#currentTheme = themeName;
|
|
91
|
+
} else {
|
|
92
|
+
throw new Error(`${themeName} is not exists`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//* themes
|
|
96
|
+
get allThemesNames() {
|
|
97
|
+
return Object.keys(this.#themes);
|
|
98
|
+
}
|
|
99
|
+
get allThemes() {
|
|
100
|
+
return this.#themes;
|
|
101
|
+
}
|
|
102
|
+
//* variables
|
|
103
|
+
get variables() {
|
|
104
|
+
return this.#themesVariables[this.#currentTheme];
|
|
105
|
+
}
|
|
106
|
+
//* classNames
|
|
107
|
+
get classNames() {
|
|
108
|
+
return this.#themesClassNames[this.#currentTheme];
|
|
109
|
+
}
|
|
110
|
+
//* components
|
|
111
|
+
get components() {
|
|
112
|
+
return this.#themesComponents[this.#currentTheme];
|
|
113
|
+
}
|
|
114
|
+
//* global styles
|
|
115
|
+
get globalStyles() {
|
|
116
|
+
return this.#themesGlobalStyles[this.#currentTheme];
|
|
117
|
+
}
|
|
118
|
+
//* media queries
|
|
119
|
+
get mediaQueries() {
|
|
120
|
+
return this.#themesMediaQueries[this.#currentTheme];
|
|
121
|
+
}
|
|
122
|
+
//? methods
|
|
123
|
+
getComponentStyles({ variant, component, additionalClassNames }) {
|
|
124
|
+
const THEME = this.#themesClassNames[this.#currentTheme];
|
|
125
|
+
const upperComponent = component.toLocaleUpperCase();
|
|
126
|
+
const COMPONENT = THEME[upperComponent];
|
|
127
|
+
|
|
128
|
+
if (!COMPONENT) return {};
|
|
129
|
+
|
|
130
|
+
const structure = {};
|
|
131
|
+
const startV = '$_';
|
|
132
|
+
const componentVariant = (() => {
|
|
133
|
+
if (!!variant) {
|
|
134
|
+
const lowerVariant = variant.toLocaleLowerCase().replace(/-/g, '_');
|
|
135
|
+
return `${startV}${lowerVariant}`;
|
|
136
|
+
} else {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
if (componentVariant && componentVariant in COMPONENT) {
|
|
141
|
+
const variantFragment = COMPONENT[componentVariant];
|
|
142
|
+
Object.entries(variantFragment).forEach(([key, value]) => {
|
|
143
|
+
if (!(key in structure)) {
|
|
144
|
+
structure[key] = value;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
Object.entries(COMPONENT).forEach(([key, value]) => {
|
|
149
|
+
if (key.startsWith(startV)) return;
|
|
150
|
+
if (!(key in structure) && value) {
|
|
151
|
+
structure[key] = value;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
if (!!additionalClassNames && Object.keys(additionalClassNames).length) {
|
|
155
|
+
Object.entries(additionalClassNames).forEach(([key, value]) => {
|
|
156
|
+
if (!(key in structure)) {
|
|
157
|
+
structure[key] = value;
|
|
158
|
+
} else if (value) {
|
|
159
|
+
const existingValue = structure[key].split(' ');
|
|
160
|
+
const newValue = value.split(' ');
|
|
161
|
+
const combinedValues = Array.from(
|
|
162
|
+
new Set([...existingValue, ...newValue]),
|
|
163
|
+
);
|
|
164
|
+
structure[key] = combinedValues.join(' ');
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return structure;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -1 +1,155 @@
|
|
|
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 = (css, id) => {
|
|
22
|
+
if (typeof document === 'undefined') return;
|
|
23
|
+
let styleElement = document.getElementById(id);
|
|
24
|
+
if (!styleElement) {
|
|
25
|
+
styleElement = document.createElement('style');
|
|
26
|
+
styleElement.id = id;
|
|
27
|
+
styleElement.type = 'text/css';
|
|
28
|
+
document.head.appendChild(styleElement);
|
|
29
|
+
}
|
|
30
|
+
styleElement.innerHTML = css;
|
|
31
|
+
};
|
|
32
|
+
#handlerThemes = (data) => {
|
|
33
|
+
const { css } = data;
|
|
34
|
+
this.#linkBuilder(css, this.#linkId);
|
|
35
|
+
};
|
|
36
|
+
#cleanUpLinks = () => {
|
|
37
|
+
if (typeof document === 'undefined') return;
|
|
38
|
+
const style = document.getElementById(this.#linkId);
|
|
39
|
+
if (style) style.remove();
|
|
40
|
+
};
|
|
41
|
+
/* Bernova provider methods */
|
|
42
|
+
|
|
43
|
+
constructor({ linkId, jsInCss } = {}) {
|
|
44
|
+
this.#themes = cssThemes;
|
|
45
|
+
this.#themesVariables = cssVars;
|
|
46
|
+
this.#themesClassNames = cssClasses;
|
|
47
|
+
this.#themesComponents = cssAvailableComponents;
|
|
48
|
+
this.#themesGlobalStyles = cssGlobalStyles;
|
|
49
|
+
this.#themesMediaQueries = cssMediaQueries;
|
|
50
|
+
this.#linkId = linkId || 'kb-styled-link';
|
|
51
|
+
this.#currentTheme = Object.keys(cssThemes)[0];
|
|
52
|
+
this.#jsInCss = !!jsInCss;
|
|
53
|
+
this.getComponentStyles = this.getComponentStyles.bind(this);
|
|
54
|
+
|
|
55
|
+
if (
|
|
56
|
+
typeof window !== 'undefined' &&
|
|
57
|
+
typeof document !== 'undefined' &&
|
|
58
|
+
this.#jsInCss
|
|
59
|
+
) {
|
|
60
|
+
this.#cleanUpLinks();
|
|
61
|
+
this.#handlerThemes(this.#themes[this.#currentTheme]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// ? getters and setters
|
|
65
|
+
//* theme selected
|
|
66
|
+
get themeSelected() {
|
|
67
|
+
return this.#currentTheme;
|
|
68
|
+
}
|
|
69
|
+
set themeSelected(themeName) {
|
|
70
|
+
if (themeName in this.#themes) {
|
|
71
|
+
if (this.#jsInCss) {
|
|
72
|
+
this.#cleanUpLinks();
|
|
73
|
+
this.#handlerThemes(this.#themes[themeName]);
|
|
74
|
+
}
|
|
75
|
+
this.#currentTheme = themeName;
|
|
76
|
+
} else {
|
|
77
|
+
throw new Error(`${themeName} is not exists`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//* themes
|
|
81
|
+
get allThemesNames() {
|
|
82
|
+
return Object.keys(this.#themes);
|
|
83
|
+
}
|
|
84
|
+
get allThemes() {
|
|
85
|
+
return this.#themes;
|
|
86
|
+
}
|
|
87
|
+
//* variables
|
|
88
|
+
get variables() {
|
|
89
|
+
return this.#themesVariables[this.#currentTheme];
|
|
90
|
+
}
|
|
91
|
+
//* classNames
|
|
92
|
+
get classNames() {
|
|
93
|
+
return this.#themesClassNames[this.#currentTheme];
|
|
94
|
+
}
|
|
95
|
+
//* components
|
|
96
|
+
get components() {
|
|
97
|
+
return this.#themesComponents[this.#currentTheme];
|
|
98
|
+
}
|
|
99
|
+
//* global styles
|
|
100
|
+
get globalStyles() {
|
|
101
|
+
return this.#themesGlobalStyles[this.#currentTheme];
|
|
102
|
+
}
|
|
103
|
+
//* media queries
|
|
104
|
+
get mediaQueries() {
|
|
105
|
+
return this.#themesMediaQueries[this.#currentTheme];
|
|
106
|
+
}
|
|
107
|
+
//? methods
|
|
108
|
+
getComponentStyles({ variant, component, additionalClassNames }) {
|
|
109
|
+
const THEME = this.#themesClassNames[this.#currentTheme];
|
|
110
|
+
const upperComponent = component.toLocaleUpperCase();
|
|
111
|
+
const COMPONENT = THEME[upperComponent];
|
|
112
|
+
|
|
113
|
+
if (!COMPONENT) return {};
|
|
114
|
+
|
|
115
|
+
const structure = {};
|
|
116
|
+
const startV = '$_';
|
|
117
|
+
const componentVariant = (() => {
|
|
118
|
+
if (!!variant) {
|
|
119
|
+
const lowerVariant = variant.toLocaleLowerCase().replace(/-/g, '_');
|
|
120
|
+
return `${startV}${lowerVariant}`;
|
|
121
|
+
} else {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
})();
|
|
125
|
+
if (componentVariant && componentVariant in COMPONENT) {
|
|
126
|
+
const variantFragment = COMPONENT[componentVariant];
|
|
127
|
+
Object.entries(variantFragment).forEach(([key, value]) => {
|
|
128
|
+
if (!(key in structure)) {
|
|
129
|
+
structure[key] = value;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
Object.entries(COMPONENT).forEach(([key, value]) => {
|
|
134
|
+
if (key.startsWith(startV)) return;
|
|
135
|
+
if (!(key in structure) && value) {
|
|
136
|
+
structure[key] = value;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
if (!!additionalClassNames && Object.keys(additionalClassNames).length) {
|
|
140
|
+
Object.entries(additionalClassNames).forEach(([key, value]) => {
|
|
141
|
+
if (!(key in structure)) {
|
|
142
|
+
structure[key] = value;
|
|
143
|
+
} else if (value) {
|
|
144
|
+
const existingValue = structure[key].split(' ');
|
|
145
|
+
const newValue = value.split(' ');
|
|
146
|
+
const combinedValues = Array.from(
|
|
147
|
+
new Set([...existingValue, ...newValue]),
|
|
148
|
+
);
|
|
149
|
+
structure[key] = combinedValues.join(' ');
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return structure;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const{cssProps:e,cssPseudoClasses:
|
|
1
|
+
const{cssProps:e,cssPseudoClasses:n,cssPseudoElements:s,cssAdvancedSelectors:t}=require("../../constants"),r=({object:e,type:n})=>Object.keys(e).reduce((e,s)=>e+` ${s}?: ${n};\n`,""),$=({advancedSelectors:e,type:n})=>Object.keys(e).reduce((e,s,t)=>e+`${t>0?" |":""} { ${s}?: ${n}; }\n`,""),p=({mediaConfig:e,type:n})=>e&&Array.isArray(e)?e.reduce((e,s)=>e+` '${s.name}'?: ${n};\n`,""):"",y=({mediaConfig:y})=>{const o="CssLibPropsType",i=Array.isArray(y)&&y.length>0,a="CssPropsType",d="CssPseudoClassesType",c="CssPseudoElementsType",l="CssAdvancedSelectorsType",u="CssMediaQueriesType",g="CssForeignType",C="CssLiteralsType",b=`${o} & { $target?: string; }`,x="CssLibPseudoClassesType",m="CssLibPseudoElementsType",T="CssLibAdvancedSelectorsType",k="CssLibAttributesType",L="CssLibMediaQueriesType",P="CssForeignLibType",v="CssDynamicValuesType",A="CssLibLiteralsType",j=`export type ${o} = ${a} & ${x} & ${m} & ${T} & ${v} & ${k}${i?` & ${L}`:""} & ${P} & ${A};\n`;return`\nexport type ${a} = {\n${r({object:e,type:"string"})}}\n\nexport type ${d} = {\n${r({object:n,type:`${d} | ${c} | ${b}`})}}\n\nexport type ${c} = {\n${r({object:s,type:`${c} | ${d} | ${o}`})}}\n\nexport type ${l} = \n${$({advancedSelectors:t,type:b})}\n\nexport type ${u} = ${a} & { $type?: string; $values?: { [key: string]: string; }; }\n\nexport type ${g} = { [key:string]: { component: object; variant?: string | unknown; name: string; } }\n\nexport type ${C} = { [key: string]: string | number | boolean | null | undefined | bigint | symbol; }\n\nexport type ${x} = {\n $pseudoClasses?: ${d} \n}\n\nexport type ${m} = {\n $pseudoElements?: ${c} \n}\n\nexport type ${v} = {\n $dynamicValues?: string[]; \n}\n\nexport type ${T} = {\n $advancedSelectors?: ${l}[] \n}\n\nexport type ${k} = { $attributes?: { [key: string]: ${o} } | { [key: string]: { [key: string]: ${o} } } }\n\n${i?`export type ${L} = {\n $mediaQueries?: {\n [key: string]: ${u}\n } | {\n${p({mediaConfig:y,type:o})} }\n}\n`:""}\nexport type ${P} = {\n $foreign?: ${g} \n}\n\nexport type ${A} = {\n $literals?: ${C}; \n}\n\n${j}\n `};module.exports={typingStyles:y};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export function formatRuleName({ key, parentRule, theRule, hasStyles, prefix, register, }: {
|
|
1
|
+
export function formatRuleName({ key, parentRule, theRule, hasStyles, prefix, register, literals, }: {
|
|
2
2
|
key?: string;
|
|
3
3
|
parentRule: any;
|
|
4
4
|
theRule: any;
|
|
5
5
|
hasStyles: any;
|
|
6
6
|
prefix: any;
|
|
7
7
|
register?: {};
|
|
8
|
+
literals: any;
|
|
8
9
|
}): string;
|
|
9
10
|
export function setForeignRegister({ ruleName, foreignRegister, register }: {
|
|
10
11
|
ruleName: any;
|
package/package.json
CHANGED
|
@@ -7,6 +7,45 @@
|
|
|
7
7
|
|
|
8
8
|
const { simplifyName } = require('../../../simplifyName/simplifyName.utils');
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* List of primitive value indicators for special string processing
|
|
12
|
+
*/
|
|
13
|
+
const primitiveValues = [
|
|
14
|
+
'$boolean$',
|
|
15
|
+
'$number$',
|
|
16
|
+
'$string$',
|
|
17
|
+
'$bigint$',
|
|
18
|
+
'$symbol$',
|
|
19
|
+
'$undefined$',
|
|
20
|
+
'$null$',
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Processes a string value and determines its type
|
|
24
|
+
* @param {string} str - The input string to process
|
|
25
|
+
* @returns {Object} - An object containing the processed value and its type
|
|
26
|
+
*/
|
|
27
|
+
const processStringValue = (str) => {
|
|
28
|
+
if (/^Symbol\.for\(['"](.+)['"]\)$/.test(str)) {
|
|
29
|
+
const match = str.match(/^Symbol\.for\(['"](.+)['"]\)$/);
|
|
30
|
+
return { vl: Symbol.for(match[1]), tp: 'symbol' };
|
|
31
|
+
} else if (/^-?\d+n$/.test(str)) {
|
|
32
|
+
return { vl: BigInt(str.slice(0, -1)), tp: 'bigint' }; // remove the 'n' and convert to BigInt
|
|
33
|
+
} else if (!isNaN(str) && !isNaN(parseFloat(str))) {
|
|
34
|
+
return { vl: Number(str), tp: 'number' };
|
|
35
|
+
} else if (str === 'true') {
|
|
36
|
+
return { vl: true, tp: 'boolean' };
|
|
37
|
+
} else if (str === 'false') {
|
|
38
|
+
return { vl: false, tp: 'boolean' };
|
|
39
|
+
} else if (str === 'null') {
|
|
40
|
+
return { vl: null, tp: 'null' };
|
|
41
|
+
} else if (str === 'undefined') {
|
|
42
|
+
return { vl: undefined, tp: 'undefined' };
|
|
43
|
+
} else if (primitiveValues.includes(str)) {
|
|
44
|
+
return { vl: `''`, tp: str.replaceAll('$', '') };
|
|
45
|
+
}
|
|
46
|
+
return { vl: `'${str}'`, tp: 'string' };
|
|
47
|
+
};
|
|
48
|
+
|
|
10
49
|
/**
|
|
11
50
|
* Handles the CSS register to generate provider documentation and tools
|
|
12
51
|
* Recursively processes nested component structures and creates exports
|
|
@@ -84,20 +123,21 @@ const handlerRegister = ({ register, prefix }) => {
|
|
|
84
123
|
acc.prov.doc += `${currentSpace}${provKey}: '${component}',\n`;
|
|
85
124
|
acc.prov.declare += `${currentSpace}${provKey}: string,\n`;
|
|
86
125
|
} else if (typeof value === 'string') {
|
|
87
|
-
|
|
126
|
+
//? Handle string mappings (class name aliases)
|
|
88
127
|
|
|
89
|
-
|
|
128
|
+
const { vl, tp } = processStringValue(value);
|
|
129
|
+
//* Generate tools documentation from string value
|
|
90
130
|
const compFromValue = simplifyName(value).replace(`${prefix}_`, '');
|
|
91
131
|
if (!componentsRegistered.has(compFromValue)) {
|
|
92
132
|
componentsRegistered.add(compFromValue);
|
|
93
|
-
acc.tools.doc += ` ${compFromValue}:
|
|
94
|
-
acc.tools.declare += ` ${compFromValue}:
|
|
133
|
+
acc.tools.doc += ` ${compFromValue}: ${vl},\n`;
|
|
134
|
+
acc.tools.declare += ` ${compFromValue}: ${tp},\n`;
|
|
95
135
|
}
|
|
96
136
|
|
|
97
|
-
|
|
137
|
+
//* Generate provider documentation with string value
|
|
98
138
|
const provKey = component.split('__').at(-1);
|
|
99
|
-
acc.prov.doc += `${currentSpace}${provKey}:
|
|
100
|
-
acc.prov.declare += `${currentSpace}${provKey}:
|
|
139
|
+
acc.prov.doc += `${currentSpace}${provKey}: ${vl},\n`;
|
|
140
|
+
acc.prov.declare += `${currentSpace}${provKey}: ${tp},\n`;
|
|
101
141
|
} else if (typeof value === 'function') {
|
|
102
142
|
// Handle dynamic value functions (special cases for type generation)
|
|
103
143
|
if (component === 'dynamic_values') {
|
|
@@ -113,7 +153,7 @@ const handlerRegister = ({ register, prefix }) => {
|
|
|
113
153
|
comp: { simple: '', object: '' }, // Component type definitions
|
|
114
154
|
prov: { doc: '', declare: '' }, // Provider documentation and types
|
|
115
155
|
tools: { doc: '', declare: '' }, // Tools utilities and types
|
|
116
|
-
}
|
|
156
|
+
},
|
|
117
157
|
);
|
|
118
158
|
};
|
|
119
159
|
|
|
@@ -59,7 +59,7 @@ const generateCssStyles = ({ source, mediaConfig, prefix }) => {
|
|
|
59
59
|
}) => {
|
|
60
60
|
const {
|
|
61
61
|
styles,
|
|
62
|
-
lib: { $dynamicValues, ...lib },
|
|
62
|
+
lib: { $dynamicValues, $literals, ...lib },
|
|
63
63
|
other,
|
|
64
64
|
} = separateStyles(source);
|
|
65
65
|
const hasStyles = Object.entries(styles).length > 0;
|
|
@@ -76,6 +76,7 @@ const generateCssStyles = ({ source, mediaConfig, prefix }) => {
|
|
|
76
76
|
register,
|
|
77
77
|
hasStyles,
|
|
78
78
|
prefix: prefixed,
|
|
79
|
+
literals: $literals,
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
if (hasStyles) {
|
|
@@ -150,6 +151,7 @@ const generateCssStyles = ({ source, mediaConfig, prefix }) => {
|
|
|
150
151
|
$advancedSelectors,
|
|
151
152
|
$foreign,
|
|
152
153
|
$dynamicValues,
|
|
154
|
+
$literals,
|
|
153
155
|
...css
|
|
154
156
|
} = value;
|
|
155
157
|
|
|
@@ -167,6 +169,7 @@ const generateCssStyles = ({ source, mediaConfig, prefix }) => {
|
|
|
167
169
|
register,
|
|
168
170
|
hasStyles,
|
|
169
171
|
prefix: prefixed,
|
|
172
|
+
literals: $literals,
|
|
170
173
|
});
|
|
171
174
|
|
|
172
175
|
if (hasStyles) {
|
|
@@ -212,7 +215,7 @@ const generateCssStyles = ({ source, mediaConfig, prefix }) => {
|
|
|
212
215
|
advancedSelectorHandler(
|
|
213
216
|
$advancedSelectors,
|
|
214
217
|
ruleName,
|
|
215
|
-
processSource
|
|
218
|
+
processSource,
|
|
216
219
|
);
|
|
217
220
|
}
|
|
218
221
|
if ($foreign) {
|
|
@@ -25,6 +25,7 @@ const setRegister = ({
|
|
|
25
25
|
mainComponent,
|
|
26
26
|
hasStyles,
|
|
27
27
|
prefix,
|
|
28
|
+
literals,
|
|
28
29
|
}) => {
|
|
29
30
|
// Initialize main component in register if not exists
|
|
30
31
|
if (!(mainComponent in register)) {
|
|
@@ -53,6 +54,26 @@ const setRegister = ({
|
|
|
53
54
|
: `${prefix}${component}--${variant}`; // Variant only
|
|
54
55
|
}
|
|
55
56
|
}
|
|
57
|
+
|
|
58
|
+
// Handle literals registration if provided
|
|
59
|
+
if (literals) {
|
|
60
|
+
Object.entries(literals).forEach(([literalKey, literalValue]) => {
|
|
61
|
+
const lValue = String(literalValue);
|
|
62
|
+
if (!!variant) {
|
|
63
|
+
const v = `$_${formattedStatKey(variant)}`;
|
|
64
|
+
register[mainComponent][v][literalKey] = lValue;
|
|
65
|
+
if (!(literalKey in register[mainComponent])) {
|
|
66
|
+
const lValueType =
|
|
67
|
+
literalValue === null
|
|
68
|
+
? '$null$'
|
|
69
|
+
: `$${String(typeof literalValue)}$`;
|
|
70
|
+
register[mainComponent][literalKey] = lValueType;
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
register[mainComponent][literalKey] = lValue;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
56
77
|
};
|
|
57
78
|
|
|
58
79
|
const getRuleNameSlices = ({ parentRule, key, prefix }) => {
|
|
@@ -101,6 +122,7 @@ const formatRuleName = ({
|
|
|
101
122
|
hasStyles,
|
|
102
123
|
prefix,
|
|
103
124
|
register = {},
|
|
125
|
+
literals,
|
|
104
126
|
}) => {
|
|
105
127
|
let className = '';
|
|
106
128
|
// Use theRule directly if provided (for pseudo-classes, selectors, etc.)
|
|
@@ -119,6 +141,7 @@ const formatRuleName = ({
|
|
|
119
141
|
mainComponent: cleanKey,
|
|
120
142
|
hasStyles,
|
|
121
143
|
prefix,
|
|
144
|
+
literals,
|
|
122
145
|
});
|
|
123
146
|
}
|
|
124
147
|
} else {
|
|
@@ -142,6 +165,7 @@ const formatRuleName = ({
|
|
|
142
165
|
variant,
|
|
143
166
|
hasStyles,
|
|
144
167
|
prefix,
|
|
168
|
+
literals,
|
|
145
169
|
});
|
|
146
170
|
} else if (lowerKey) {
|
|
147
171
|
className = `${mainComponent}--${lowerKey}`;
|
|
@@ -153,6 +177,7 @@ const formatRuleName = ({
|
|
|
153
177
|
variant: lowerKey,
|
|
154
178
|
hasStyles,
|
|
155
179
|
prefix,
|
|
180
|
+
literals,
|
|
156
181
|
});
|
|
157
182
|
}
|
|
158
183
|
}
|
|
@@ -147,16 +147,22 @@ export class $_Provider_$ {
|
|
|
147
147
|
}
|
|
148
148
|
Object.entries(COMPONENT).forEach(([key, value]) => {
|
|
149
149
|
if (key.startsWith(startV)) return;
|
|
150
|
-
if (!(key in structure)) {
|
|
150
|
+
if (!(key in structure) && value) {
|
|
151
151
|
structure[key] = value;
|
|
152
152
|
}
|
|
153
153
|
});
|
|
154
154
|
if (!!additionalClassNames && Object.keys(additionalClassNames).length) {
|
|
155
155
|
Object.entries(additionalClassNames).forEach(([key, value]) => {
|
|
156
156
|
if (!(key in structure)) {
|
|
157
|
-
structure[key] =
|
|
157
|
+
structure[key] = value;
|
|
158
|
+
} else if (value) {
|
|
159
|
+
const existingValue = structure[key].split(' ');
|
|
160
|
+
const newValue = value.split(' ');
|
|
161
|
+
const combinedValues = Array.from(
|
|
162
|
+
new Set([...existingValue, ...newValue]),
|
|
163
|
+
);
|
|
164
|
+
structure[key] = combinedValues.join(' ');
|
|
158
165
|
}
|
|
159
|
-
structure[key] += ` ${value}`;
|
|
160
166
|
});
|
|
161
167
|
}
|
|
162
168
|
return structure;
|
|
@@ -132,16 +132,22 @@ export class $_Provider_$ {
|
|
|
132
132
|
}
|
|
133
133
|
Object.entries(COMPONENT).forEach(([key, value]) => {
|
|
134
134
|
if (key.startsWith(startV)) return;
|
|
135
|
-
if (!(key in structure)) {
|
|
135
|
+
if (!(key in structure) && value) {
|
|
136
136
|
structure[key] = value;
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
if (!!additionalClassNames && Object.keys(additionalClassNames).length) {
|
|
140
140
|
Object.entries(additionalClassNames).forEach(([key, value]) => {
|
|
141
141
|
if (!(key in structure)) {
|
|
142
|
-
structure[key] =
|
|
142
|
+
structure[key] = value;
|
|
143
|
+
} else if (value) {
|
|
144
|
+
const existingValue = structure[key].split(' ');
|
|
145
|
+
const newValue = value.split(' ');
|
|
146
|
+
const combinedValues = Array.from(
|
|
147
|
+
new Set([...existingValue, ...newValue]),
|
|
148
|
+
);
|
|
149
|
+
structure[key] = combinedValues.join(' ');
|
|
143
150
|
}
|
|
144
|
-
structure[key] += ` ${value}`;
|
|
145
151
|
});
|
|
146
152
|
}
|
|
147
153
|
return structure;
|