bernova 1.7.4 → 1.7.6

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 (33) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +69 -1
  3. package/dist/bin/buildstyle.js +1 -1
  4. package/dist/bin/copyCss.js +2 -0
  5. package/dist/bin/copyProvider.js +2 -0
  6. package/dist/bin/copyTools.js +2 -0
  7. package/dist/bin/functions/getFx.js +1 -0
  8. package/dist/bin/functions/scriptFx.js +1 -0
  9. package/dist/bin/functions/utils.js +1 -0
  10. package/dist/bin/functions/writeFx.js +1 -0
  11. package/dist/bin/preBuildStyles.js +2 -0
  12. package/dist/interfaces/componentsType.ts +633 -173
  13. package/dist/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +1 -1
  14. package/dist/src/lib/generateCss/helpers/generateCssStyles.utils.js +1 -1
  15. package/dist/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +1 -1
  16. package/dist/src/lib/generateProvider/generateProvider.utils.js +1 -1
  17. package/dist/src/lib/generateProvider/template/{providerTemplate.js → providerTemplate-link.js} +11 -5
  18. package/dist/src/lib/generateProvider/template/providerTemplate-style.js +155 -0
  19. package/dist/src/lib/generateProvider/template/providerTemplate.d.ts +1 -1
  20. package/dist/src/lib/typingStyles/typingStyles.utils.js +1 -1
  21. package/dist/types/lib/generateCss/helpers/rulename/formatRuleName.utils.d.ts +2 -1
  22. package/dist/types/lib/generateProvider/template/providerTemplate-style.d.ts +18 -0
  23. package/package.json +6 -2
  24. package/src/app.js +4 -2
  25. package/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +48 -8
  26. package/src/lib/generateCss/helpers/generateCssStyles.utils.js +5 -2
  27. package/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +25 -0
  28. package/src/lib/generateProvider/generateProvider.utils.js +9 -8
  29. package/src/lib/generateProvider/template/{providerTemplate.js → providerTemplate-link.js} +11 -5
  30. package/src/lib/generateProvider/template/providerTemplate-style.js +155 -0
  31. package/src/lib/generateProvider/template/providerTemplate.d.ts +1 -1
  32. package/src/lib/typingStyles/typingStyles.utils.js +12 -6
  33. /package/dist/types/lib/generateProvider/template/{providerTemplate.d.ts → providerTemplate-link.d.ts} +0 -0
@@ -0,0 +1,155 @@
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 {
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
+ }
@@ -33,7 +33,7 @@ export declare class $_Provider_$ {
33
33
  #linkId: string;
34
34
  #jsInCss: boolean;
35
35
  /* Bernova provider methods */
36
- #linkBuilder: (url: string, id: string) => void;
36
+ #linkBuilder: (css: string, id: string) => void;
37
37
  #handlerThemes: (data: {
38
38
  css: string;
39
39
  foreign?: { high?: string[]; low?: string[] };
@@ -72,6 +72,7 @@ const typingStyles = ({ mediaConfig }) => {
72
72
  const cssAdvancedSelectorsName = 'CssAdvancedSelectorsType';
73
73
  const cssMediaQueriesName = 'CssMediaQueriesType';
74
74
  const cssForeignName = 'CssForeignType';
75
+ const cssLiteralsName = 'CssLiteralsType';
75
76
  //* bases types
76
77
  const cssPropsWithTarget = `${cssLibPropsName} & { $target?: string; }`;
77
78
  const cssPropsType = `export type ${cssPropsName} = {\n${generateKeysType({
@@ -82,22 +83,23 @@ const typingStyles = ({ mediaConfig }) => {
82
83
  {
83
84
  object: cssPseudoClasses,
84
85
  type: `${cssPseudoClassesName} | ${cssPseudoElementsName} | ${cssPropsWithTarget}`,
85
- }
86
+ },
86
87
  )}}\n`;
87
88
  const cssPseudoElementsType = `export type ${cssPseudoElementsName} = {\n${generateKeysType(
88
89
  {
89
90
  object: cssPseudoElements,
90
91
  type: `${cssPseudoElementsName} | ${cssPseudoClassesName} | ${cssLibPropsName}`,
91
- }
92
+ },
92
93
  )}}\n`;
93
94
  const cssAdvancedSelectorsType = `export type ${cssAdvancedSelectorsName} = \n${generateAdvancedSelectorsType(
94
95
  {
95
96
  advancedSelectors: cssAdvancedSelectors,
96
97
  type: cssPropsWithTarget,
97
- }
98
+ },
98
99
  )}\n`;
99
- const mediaQueriesType = `export type ${cssMediaQueriesName} = ${cssPropsName} & { $type?: string; $values?: { [key: string]: string }; }\n`;
100
+ const mediaQueriesType = `export type ${cssMediaQueriesName} = ${cssPropsName} & { $type?: string; $values?: { [key: string]: string; }; }\n`;
100
101
  const foreignType = `export type ${cssForeignName} = { [key:string]: { component: object; variant?: string | unknown; name: string; } }\n`;
102
+ const literalsType = `export type ${cssLiteralsName} = { [key: string]: string | number | boolean | null | undefined | bigint | symbol; }\n`;
101
103
  ///? lib
102
104
  //* lib names
103
105
  const cssLibPseudoClassesName = 'CssLibPseudoClassesType';
@@ -107,21 +109,23 @@ const typingStyles = ({ mediaConfig }) => {
107
109
  const cssLibMediaQueriesName = 'CssLibMediaQueriesType';
108
110
  const cssForeignLibName = 'CssForeignLibType';
109
111
  const cssDynamicValuesName = 'CssDynamicValuesType';
112
+ const cssLibLiteralsName = 'CssLibLiteralsType';
110
113
  //* lib types
111
114
  const libProps = `export type ${cssLibPropsName} = ${cssPropsName} & ${cssLibPseudoClassesName} & ${cssLibPseudoElementsName} & ${cssLibAdvancedSelectorsName} & ${cssDynamicValuesName} & ${cssLibAttributesName}${
112
115
  hasMediaConfig ? ` & ${cssLibMediaQueriesName}` : ''
113
- } & ${cssForeignLibName};\n`;
116
+ } & ${cssForeignLibName} & ${cssLibLiteralsName};\n`;
114
117
  const pseudoClasses = `export type ${cssLibPseudoClassesName} = {\n $pseudoClasses?: ${cssPseudoClassesName} \n}\n`;
115
118
  const pseudoElements = `export type ${cssLibPseudoElementsName} = {\n $pseudoElements?: ${cssPseudoElementsName} \n}\n`;
116
119
  const advancedSelectors = `export type ${cssLibAdvancedSelectorsName} = {\n $advancedSelectors?: ${cssAdvancedSelectorsName}[] \n}\n`;
117
120
  const attributes = `export type ${cssLibAttributesName} = { $attributes?: { [key: string]: ${cssLibPropsName} } | { [key: string]: { [key: string]: ${cssLibPropsName} } } }\n`;
118
121
  const mediaQueries = hasMediaConfig
119
122
  ? `export type ${cssLibMediaQueriesName} = {\n $mediaQueries?: {\n [key: string]: ${cssMediaQueriesName}\n } | {\n${generateMediaTypes(
120
- { mediaConfig, type: cssLibPropsName }
123
+ { mediaConfig, type: cssLibPropsName },
121
124
  )} }\n}\n`
122
125
  : '';
123
126
  const foreign = `export type ${cssForeignLibName} = {\n $foreign?: ${cssForeignName} \n}\n`;
124
127
  const dynamicValues = `export type ${cssDynamicValuesName} = {\n $dynamicValues?: string[]; \n}\n`;
128
+ const literals = `export type ${cssLibLiteralsName} = {\n $literals?: ${cssLiteralsName}; \n}\n`;
125
129
 
126
130
  return `
127
131
  ${cssPropsType}
@@ -130,6 +134,7 @@ ${cssPseudoElementsType}
130
134
  ${cssAdvancedSelectorsType}
131
135
  ${mediaQueriesType}
132
136
  ${foreignType}
137
+ ${literalsType}
133
138
  ${pseudoClasses}
134
139
  ${pseudoElements}
135
140
  ${dynamicValues}
@@ -137,6 +142,7 @@ ${advancedSelectors}
137
142
  ${attributes}
138
143
  ${mediaQueries}
139
144
  ${foreign}
145
+ ${literals}
140
146
  ${libProps}
141
147
  `;
142
148
  };