effcss 1.0.0

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 (57) hide show
  1. package/LICENSE +251 -0
  2. package/README.md +152 -0
  3. package/dist/build/define-provider-with-configs.min.js +1 -0
  4. package/dist/build/define-provider.min.js +1 -0
  5. package/dist/configs/basic.js +1 -0
  6. package/dist/configs/ext.js +1 -0
  7. package/dist/css/dict.js +1 -0
  8. package/dist/css/functions.js +1 -0
  9. package/dist/index.js +1 -0
  10. package/dist/types/allConfigs.d.ts +1 -0
  11. package/dist/types/build/defineProvider.d.ts +1 -0
  12. package/dist/types/build/defineProviderWithConfigs.d.ts +1 -0
  13. package/dist/types/defineProvider.d.ts +1 -0
  14. package/dist/types/defineProviderWithConfigs.d.ts +1 -0
  15. package/dist/types/src/_provider/constants.d.ts +5 -0
  16. package/dist/types/src/_provider/manage.d.ts +35 -0
  17. package/dist/types/src/_provider/process.d.ts +102 -0
  18. package/dist/types/src/configs/basic/Agent.d.ts +3 -0
  19. package/dist/types/src/configs/basic/AgentColor.d.ts +3 -0
  20. package/dist/types/src/configs/basic/Animation.d.ts +3 -0
  21. package/dist/types/src/configs/basic/Background.d.ts +3 -0
  22. package/dist/types/src/configs/basic/Border.d.ts +3 -0
  23. package/dist/types/src/configs/basic/BorderExt.d.ts +3 -0
  24. package/dist/types/src/configs/basic/Box.d.ts +3 -0
  25. package/dist/types/src/configs/basic/Color.d.ts +3 -0
  26. package/dist/types/src/configs/basic/Column.d.ts +3 -0
  27. package/dist/types/src/configs/basic/FlexContainer.d.ts +3 -0
  28. package/dist/types/src/configs/basic/FlexItem.d.ts +3 -0
  29. package/dist/types/src/configs/basic/Font.d.ts +3 -0
  30. package/dist/types/src/configs/basic/GridContainer.d.ts +3 -0
  31. package/dist/types/src/configs/basic/GridItem.d.ts +3 -0
  32. package/dist/types/src/configs/basic/Indent.d.ts +3 -0
  33. package/dist/types/src/configs/basic/Inset.d.ts +3 -0
  34. package/dist/types/src/configs/basic/Mask.d.ts +3 -0
  35. package/dist/types/src/configs/basic/Object.d.ts +3 -0
  36. package/dist/types/src/configs/basic/Outline.d.ts +3 -0
  37. package/dist/types/src/configs/basic/Scroll.d.ts +3 -0
  38. package/dist/types/src/configs/basic/ScrollExt.d.ts +3 -0
  39. package/dist/types/src/configs/basic/Size.d.ts +3 -0
  40. package/dist/types/src/configs/basic/SizeExt.d.ts +3 -0
  41. package/dist/types/src/configs/basic/Text.d.ts +3 -0
  42. package/dist/types/src/configs/basic/Transform.d.ts +3 -0
  43. package/dist/types/src/configs/basic/Transition.d.ts +3 -0
  44. package/dist/types/src/configs/basic/User.d.ts +3 -0
  45. package/dist/types/src/configs/basic/View.d.ts +3 -0
  46. package/dist/types/src/configs/basic.d.ts +112 -0
  47. package/dist/types/src/configs/ext/Keyframes.d.ts +6 -0
  48. package/dist/types/src/configs/ext/Reset.d.ts +3 -0
  49. package/dist/types/src/configs/ext.d.ts +8 -0
  50. package/dist/types/src/css/dict.d.ts +4 -0
  51. package/dist/types/src/css/functions.d.ts +443 -0
  52. package/dist/types/src/index.d.ts +11 -0
  53. package/dist/types/src/types.d.ts +358 -0
  54. package/dist/types/src/utils.d.ts +88 -0
  55. package/dist/types/tests/Processor.test.d.ts +1 -0
  56. package/dist/utils.js +1 -0
  57. package/package.json +67 -0
@@ -0,0 +1,358 @@
1
+ /**
2
+ * Style manager
3
+ * @description
4
+ * Class that manage CSSStylesheets
5
+ */
6
+ export interface IStyleManager {
7
+ /**
8
+ * Get stylesheet
9
+ * @param key - stylesheet key
10
+ */
11
+ get(key: string): CSSStyleSheet | undefined;
12
+ /**
13
+ * Get all stylesheets
14
+ */
15
+ getAll(): Record<string, CSSStyleSheet>;
16
+ /**
17
+ * Add stylesheet
18
+ * @param key - stylesheet key
19
+ * @param stylesheet - CSSStylesheet instance
20
+ */
21
+ add(key: string, stylesheet: CSSStyleSheet): true | void;
22
+ /**
23
+ * Remove sheet
24
+ * @param key - stylesheet key
25
+ */
26
+ remove(key: string): true | void;
27
+ /**
28
+ * Remove all stylesheets
29
+ */
30
+ removeAll(): void;
31
+ /**
32
+ * Pack styles into CSSStyleSheet
33
+ * @param key - stylesheet key
34
+ * @param styles - stylesheet content
35
+ */
36
+ pack(key: string, styles: string): CSSStyleSheet | void;
37
+ /**
38
+ * Cache computed CSS rules
39
+ * @param key
40
+ * @param styleSheet
41
+ */
42
+ cacheRules: (key: string, stylesheet: CSSStyleSheet) => void;
43
+ /**
44
+ * Get expanded selectors
45
+ * @param key
46
+ */
47
+ getExpandedSelectors: (key: string) => Set<string>;
48
+ /**
49
+ * Expand existing CSS rule
50
+ * @param key - stylesheet key
51
+ * @param init - initial selector
52
+ * @param exp - expanded selector
53
+ */
54
+ expandRule: (key: string, init: string, exp: string) => true | void;
55
+ /**
56
+ * Apply stylesheets to node
57
+ * @param root
58
+ */
59
+ apply(root: {
60
+ adoptedStyleSheets: CSSStyleSheet[];
61
+ }): void;
62
+ }
63
+ /**
64
+ * Style processor
65
+ * @description
66
+ * Class that compiles style object to CSSStylesheet string content
67
+ */
68
+ export interface IStyleProcessor {
69
+ /**
70
+ * Basic styles
71
+ */
72
+ baseStyles: string;
73
+ /**
74
+ * Create expanded selector with state
75
+ * @param b
76
+ * @param selector
77
+ */
78
+ expandSelector(b: string, selector: string): [string, string];
79
+ /**
80
+ * Compile style config to CSS stylesheet text content
81
+ * @param b - block key
82
+ * @param styleConfig - style config
83
+ */
84
+ compile(b: string, styleConfig: TStyleConfig): string;
85
+ }
86
+ export interface IStyleProvider extends HTMLElement {
87
+ manager?: IStyleManager;
88
+ processor?: IStyleProcessor;
89
+ /**
90
+ * Compile sheet
91
+ */
92
+ compileStyleSheet(key: string, config: TStyleConfig): CSSStyleSheet | void;
93
+ /**
94
+ * Expand stylesheet
95
+ * @param key
96
+ * @param selectors
97
+ */
98
+ expandStyleSheet(key: string, selectors: string[]): number | undefined;
99
+ /**
100
+ * Process configs
101
+ * @param styles
102
+ * @param ext
103
+ */
104
+ processStyles(styles: Record<string, TStyleConfig>, ext: Record<string, string[]>): void;
105
+ }
106
+ /**
107
+ * Variable type
108
+ */
109
+ export type TVariable = {
110
+ syn?: string;
111
+ ini?: number | string;
112
+ inh?: boolean;
113
+ typ?: unknown;
114
+ } | {
115
+ syn?: string;
116
+ ini?: number | string;
117
+ inh?: boolean;
118
+ typ: 'c';
119
+ all?: boolean;
120
+ };
121
+ /**
122
+ * Style config
123
+ */
124
+ export type TStyleConfig = {
125
+ /**
126
+ * CSS variables config
127
+ */
128
+ _?: Record<string, TVariable>;
129
+ /**
130
+ * Keys dictionary
131
+ * @description
132
+ */
133
+ k?: Record<string, string>;
134
+ /**
135
+ * Values dictionary
136
+ * @description
137
+ */
138
+ v?: Record<string, Record<string, string | number>>;
139
+ /**
140
+ * Style config object
141
+ * @description
142
+ * Config to be compiled to CSSStylesheet string content
143
+ */
144
+ c: Record<string, Record<string, string | number> | string>;
145
+ };
146
+ type TVariants = Record<string | number, string | number>;
147
+ export interface IValues {
148
+ /**
149
+ * lightness
150
+ */
151
+ lig: TVariants;
152
+ /**
153
+ * hue
154
+ */
155
+ hue: TVariants;
156
+ /**
157
+ * chroma
158
+ */
159
+ chr: TVariants;
160
+ /**
161
+ * alpha
162
+ */
163
+ alp: TVariants;
164
+ /**
165
+ * Time
166
+ */
167
+ time: TVariants;
168
+ /**
169
+ * Iteration-count coefficients
170
+ */
171
+ ic: TVariants;
172
+ /**
173
+ * font-family
174
+ */
175
+ ff: TVariants;
176
+ /**
177
+ * Font-weight
178
+ */
179
+ fwg: TVariants;
180
+ /**
181
+ * Font-size coefficients
182
+ */
183
+ fsz: TVariants;
184
+ /**
185
+ * Root font-size
186
+ */
187
+ rem: TVariants;
188
+ /**
189
+ * Breakpoints
190
+ */
191
+ bp: TVariants;
192
+ /**
193
+ * Spacing
194
+ */
195
+ sp: TVariants;
196
+ /**
197
+ * Size
198
+ */
199
+ sz: TVariants;
200
+ /**
201
+ * Universal size units
202
+ */
203
+ szu: TVariants;
204
+ /**
205
+ * Thickness
206
+ */
207
+ th: TVariants;
208
+ /**
209
+ * Radius
210
+ */
211
+ rad: TVariants;
212
+ /**
213
+ * relative values
214
+ */
215
+ coef: TVariants;
216
+ /**
217
+ * Ratio coefficients
218
+ */
219
+ rat: TVariants;
220
+ /**
221
+ * Fractions (between 0 and 1)
222
+ */
223
+ fr: TVariants;
224
+ /**
225
+ * Opacity
226
+ */
227
+ o: TVariants;
228
+ /**
229
+ * Z-index coefficients
230
+ */
231
+ zi: TVariants;
232
+ /**
233
+ * Letter-spacing coefficients
234
+ */
235
+ lsp: TVariants;
236
+ /**
237
+ * Line-height coefficients
238
+ */
239
+ lh: TVariants;
240
+ /**
241
+ * Viewport units
242
+ */
243
+ vu: TVariants;
244
+ /**
245
+ * Viewport width
246
+ */
247
+ vw: TVariants;
248
+ /**
249
+ * Viewport height
250
+ */
251
+ vh: TVariants;
252
+ /**
253
+ * Viewport min size
254
+ */
255
+ vmin: TVariants;
256
+ /**
257
+ * Viewport max size
258
+ */
259
+ vmax: TVariants;
260
+ /**
261
+ * Container query units
262
+ */
263
+ cqu: TVariants;
264
+ /**
265
+ * Container query block size
266
+ */
267
+ cqb: TVariants;
268
+ /**
269
+ * Container query inline size
270
+ */
271
+ cqi: TVariants;
272
+ /**
273
+ * Container query min size
274
+ */
275
+ cqmin: TVariants;
276
+ /**
277
+ * Container query max size
278
+ */
279
+ cqmax: TVariants;
280
+ /**
281
+ * Perspective coefficients
282
+ */
283
+ pers: TVariants;
284
+ /**
285
+ * Zoom coefficients
286
+ */
287
+ zm: TVariants;
288
+ /**
289
+ * Rotate coefficients
290
+ */
291
+ rot: TVariants;
292
+ /**
293
+ * Skew coefficients
294
+ */
295
+ sk: TVariants;
296
+ /**
297
+ * Translate coefficients
298
+ */
299
+ tr: TVariants;
300
+ /**
301
+ * Scale coefficients
302
+ */
303
+ sc: TVariants;
304
+ /**
305
+ * Inset
306
+ */
307
+ ins: TVariants;
308
+ /**
309
+ * Flex-grow
310
+ */
311
+ fg: TVariants;
312
+ /**
313
+ * Flex-shrink
314
+ */
315
+ fs: TVariants;
316
+ /**
317
+ * Flex-basis
318
+ */
319
+ fb: TVariants;
320
+ /**
321
+ * Flex-order
322
+ */
323
+ fo: TVariants;
324
+ /**
325
+ * Grid row amount
326
+ */
327
+ ra: TVariants;
328
+ /**
329
+ * Grid column amount
330
+ */
331
+ co: TVariants;
332
+ /**
333
+ * Grid row offset
334
+ */
335
+ ro: TVariants;
336
+ /**
337
+ * Grid column offset
338
+ */
339
+ ca: TVariants;
340
+ }
341
+ export type TModeValues = Record<string, Record<string, Record<string, string | number>>>;
342
+ export interface IStyleProvider {
343
+ /**
344
+ * Settings script element id
345
+ */
346
+ settingsid?: string;
347
+ /**
348
+ * CSS var prefix
349
+ */
350
+ prefix?: string | null;
351
+ /**
352
+ * Style generation mode
353
+ * @description
354
+ * `a` - data-attributes, `c` - classes
355
+ */
356
+ mode?: 'a' | 'c' | null;
357
+ }
358
+ export {};
@@ -0,0 +1,88 @@
1
+ import { IStyleProvider, TStyleConfig } from "types";
2
+ export declare const SETTINGS_ID = "effcss";
3
+ export declare const COMPONENT_NAME = "style-provider";
4
+ /**
5
+ * Get provider styles
6
+ */
7
+ export declare const getProviderStyles: () => string;
8
+ /**
9
+ * Create settings script element
10
+ * @param settings
11
+ * @param params
12
+ */
13
+ export declare const createSettingsElement: (settings: object, params?: {
14
+ id: string;
15
+ }) => Node;
16
+ /**
17
+ * Create settings HTML string
18
+ * @param settings
19
+ * @param params
20
+ */
21
+ export declare const createSettingsHTML: (settings: object, params?: {
22
+ id: string;
23
+ }) => string;
24
+ /**
25
+ * Get provider component
26
+ */
27
+ export declare const getProvider: (root?: Document) => IStyleProvider;
28
+ /**
29
+ * Compile stylesheet
30
+ * @param key - stylesheet key
31
+ * @param config - style config
32
+ * @param provider - style provider
33
+ */
34
+ export declare const compileStyleSheet: (key: string, config: TStyleConfig, provider?: IStyleProvider) => void | CSSStyleSheet;
35
+ /**
36
+ * Expand stylesheet
37
+ * @param key - stylesheet key
38
+ * @param config - style config
39
+ * @param provider - style provider
40
+ */
41
+ export declare const expandStyleSheet: (key: string, config: string[], provider?: IStyleProvider) => number | undefined;
42
+ /**
43
+ * Get stylesheet from provider
44
+ * @param key
45
+ */
46
+ export declare const getStyleSheet: (key: string, provider?: IStyleProvider) => CSSStyleSheet | undefined;
47
+ /**
48
+ * Add stylesheet to provider
49
+ * @param key
50
+ */
51
+ export declare const addStyleSheet: (key: string, stylesheet: CSSStyleSheet, provider?: IStyleProvider) => true | void | undefined;
52
+ /**
53
+ * Remove stylesheet from provider
54
+ * @param key
55
+ */
56
+ export declare const removeStyleSheet: (key: string, provider?: IStyleProvider) => true | void | undefined;
57
+ /**
58
+ * Stringify stylesheet
59
+ * @param key
60
+ * @param provider
61
+ */
62
+ export declare const stringifyStyleSheet: (key: string, provider?: IStyleProvider) => string;
63
+ /**
64
+ * Get all stylesheets
65
+ * @param key
66
+ */
67
+ export declare const stringifyAllStyles: (provider?: IStyleProvider) => string;
68
+ /**
69
+ * Get rules count for stylesheet
70
+ * @param key
71
+ * @param provider
72
+ */
73
+ export declare const getRulesCount: (key: string, provider?: IStyleProvider) => number;
74
+ /**
75
+ * Get total rules count
76
+ * @param provider
77
+ */
78
+ export declare const getTotalRulesCount: (provider?: IStyleProvider) => number;
79
+ export declare class StylesCollector {
80
+ getElementsByTagName(key: string): {}[] | undefined;
81
+ }
82
+ export declare class StyleDispatcher {
83
+ root: Document;
84
+ provider?: IStyleProvider;
85
+ construstor(root?: Document): void;
86
+ compile: (key: string, config: TStyleConfig) => void | CSSStyleSheet;
87
+ expand: (key: string, config: string[]) => number | undefined;
88
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/utils.js ADDED
@@ -0,0 +1 @@
1
+ const e="effcss",r="style-provider",t=()=>`${r} {display: contents;}`,i=(r,t)=>{const i=JSON.stringify(r),n=(null==t?void 0:t.id)||e,o=document.createElement("script");return o.id=n,o.type="application/json",o.innerHTML=i,o},n=(r,t)=>{const i=JSON.stringify(r);return`<script id="${(null==t?void 0:t.id)||e}" type="application/json">${i}<\/script>`},o=(e=document)=>{var r;return null===(r=e.getElementsByTagName("style-provider"))||void 0===r?void 0:r[0]},l=(e,r,t=o())=>t.compileStyleSheet(e,r),d=(e,r,t=o())=>t.expandStyleSheet(e,r),s=(e,r=o())=>{var t;return null===(t=null==r?void 0:r.manager)||void 0===t?void 0:t.get(e)},v=(e,r,t=o())=>{var i;return null===(i=null==t?void 0:t.manager)||void 0===i?void 0:i.add(e,r)},a=(e,r=o())=>{var t;return null===(t=null==r?void 0:r.manager)||void 0===t?void 0:t.remove(e)},u=(e,r=o())=>{var t;return[...(null===(t=s(e,r))||void 0===t?void 0:t.cssRules)||[]].map((e=>e.cssText)).join("")},c=(e=o())=>{var r;return Object.keys((null===(r=null==e?void 0:e.manager)||void 0===r?void 0:r.getAll())||{}).map((r=>u(r,e))).join("")},p=(e,r=o())=>{var t,i;return(null===(i=null===(t=s(e,r))||void 0===t?void 0:t.cssRules)||void 0===i?void 0:i.length)||0},m=(e=o())=>{var r;return Object.keys((null===(r=null==e?void 0:e.manager)||void 0===r?void 0:r.getAll())||{}).reduce(((r,t)=>r+p(t,e)),0)};class g{getElementsByTagName(e){if("style-provider"===e)return[{}]}}class y{constructor(){this.root=document,this.compile=(e,r)=>l(e,r,this.provider),this.expand=(e,r)=>d(e,r,this.provider)}construstor(e){e&&(this.root=e),this.provider=o(this.root)}}export{r as COMPONENT_NAME,e as SETTINGS_ID,y as StyleDispatcher,g as StylesCollector,v as addStyleSheet,l as compileStyleSheet,i as createSettingsElement,n as createSettingsHTML,d as expandStyleSheet,o as getProvider,t as getProviderStyles,p as getRulesCount,s as getStyleSheet,m as getTotalRulesCount,a as removeStyleSheet,c as stringifyAllStyles,u as stringifyStyleSheet};
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "effcss",
3
+ "version": "1.0.0",
4
+ "description": "Next generation CSS-in-JS library",
5
+ "scripts": {
6
+ "build": "rollup -c",
7
+ "test": "vitest"
8
+ },
9
+ "keywords": [
10
+ "web components",
11
+ "ui",
12
+ "typescript",
13
+ "css",
14
+ "css-in-js"
15
+ ],
16
+ "author": "Marat Sabitov",
17
+ "license": "Apache 2.0",
18
+ "main": "dist/index.js",
19
+ "types": "dist/types/src/types.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/types/src/index.d.ts",
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.js"
25
+ },
26
+ "./configs/basic": {
27
+ "types": "./dist/types/src/configs/basic.d.ts",
28
+ "import": "./dist/configs/basic.js"
29
+ },
30
+ "./configs/ext": {
31
+ "types": "./dist/types/src/configs/ext.d.ts",
32
+ "import": "./dist/configs/ext.js"
33
+ },
34
+ "./css/dict": {
35
+ "types": "./dist/types/src/css/dict.d.ts",
36
+ "import": "./dist/css/dict.js"
37
+ },
38
+ "./css/functions": {
39
+ "types": "./dist/types/src/css/functions.d.ts",
40
+ "import": "./dist/css/functions.js"
41
+ },
42
+ "./utils": {
43
+ "types": "./dist/types/src/utils.d.ts",
44
+ "import": "./dist/utils.js"
45
+ },
46
+ "./types": {
47
+ "types": "./dist/types/src/types.d.ts",
48
+ "import": "./dist/types/src/types.d.ts"
49
+ }
50
+ },
51
+ "devDependencies": {
52
+ "@rollup/plugin-terser": "^0.4.4",
53
+ "@rollup/plugin-typescript": "^11.1.6",
54
+ "vitest": "^2.1.8"
55
+ },
56
+ "files": [
57
+ "LICENSE",
58
+ "README.md",
59
+ "package.json",
60
+ "dist"
61
+ ],
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "https://gitverse.ru/msabitov/effcss.git"
65
+ },
66
+ "homepage": "https://gitverse.ru/msabitov/effcss/content/master/README.md"
67
+ }