effcss 2.2.1 → 3.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.
@@ -1,571 +0,0 @@
1
- type TOptBool = boolean | undefined;
2
- type TOptSheet = CSSStyleSheet | undefined;
3
- type TStrDict = Record<string, string>;
4
- type TDict = Record<string, string | number>;
5
- type TMetaDict = Record<string, TDict>;
6
- /**
7
- * Stylesheet config
8
- * @description
9
- * Contains descriptions of rules, variables, keyframes, and interpolation dictionaries used within the stylesheet.
10
- */
11
- export type TStyleSheetConfig = {
12
- /**
13
- * CSS variables
14
- * @see {@link TVariable}
15
- */
16
- _?: Record<string, TVariable>;
17
- /**
18
- * Keyframes
19
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes}
20
- */
21
- kf?: Record<string, TMetaDict>;
22
- /**
23
- * Keys dictionary
24
- * @description
25
- * Dictionary with primitive type values.
26
- * In interpolation expressions, these values will have an advantage over the global ones.
27
- */
28
- k?: TStrDict;
29
- /**
30
- * Values dictionary
31
- * @description
32
- * Dictionary with object values.
33
- * In interpolation expressions, these values will have an advantage over the global ones.
34
- */
35
- v?: TMetaDict;
36
- /**
37
- * Stylesheet content
38
- * @description
39
- * This object will be compiled to CSSStylesheet string content.
40
- * The conversion rules are defined by the {@link IStyleProcessor | style processor}.
41
- */
42
- c: object;
43
- };
44
- /**
45
- * Dictionary of stylesheet configs
46
- */
47
- export type TConfigDict = Record<string, TStyleSheetConfig>;
48
- /**
49
- * Array of stylesheet configs
50
- */
51
- export type TConfigArray = TStyleSheetConfig[];
52
- /**
53
- * Style target
54
- */
55
- export type TStyleTarget = string | TStyleSheetConfig;
56
- export type TOneOrManyTargets = TStyleTarget | TStyleTarget[];
57
- /**
58
- * Provider settings
59
- */
60
- export type TProviderSettings = {
61
- /**
62
- * Style themes
63
- */
64
- themes?: TThemes;
65
- /**
66
- * Root styles
67
- */
68
- rootStyle?: object;
69
- /**
70
- * Global params units
71
- */
72
- units?: TStrDict;
73
- /**
74
- * Global keys
75
- */
76
- keys?: TStrDict;
77
- /**
78
- * Global sets of keys
79
- */
80
- sets?: TMetaDict;
81
- /**
82
- * Media queries breakpoints
83
- */
84
- mediaBP?: TStrDict;
85
- /**
86
- * Container queries breakpoints
87
- */
88
- containerBP?: TStrDict;
89
- };
90
- /**
91
- * Provider initial content
92
- */
93
- export type TProviderInitContent = TConfigDict;
94
- /**
95
- * Style manager
96
- * @description
97
- * Manages CSS stylesheets.
98
- */
99
- export interface IStyleManager {
100
- /**
101
- * Get stylesheet by key
102
- * @param key - stylesheet key
103
- */
104
- get(key?: string): TOptSheet;
105
- /**
106
- * Get index of stylesheet
107
- * @param styleSheet - CSS stylesheet
108
- */
109
- getIndex(styleSheet: CSSStyleSheet): number;
110
- /**
111
- * Get all stylesheets dictionary
112
- */
113
- getAll(): Record<string, CSSStyleSheet>;
114
- /**
115
- * Add stylesheet
116
- * @param key - stylesheet key
117
- * @param stylesheet - {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet | CSSStylesheet} instance
118
- * @returns `true` if stylesheet is added
119
- */
120
- add(key: string, stylesheet: CSSStyleSheet): TOptBool;
121
- /**
122
- * Replace stylesheet content
123
- * @param key - stylesheet key
124
- * @param styles - stylesheet content string
125
- * @returns `true` if stylesheet is replaced
126
- */
127
- replace(key: string, styles: string): TOptBool;
128
- /**
129
- * Remove stylesheet
130
- * @param key - stylesheet key
131
- * @returns `true` if stylesheet is removed
132
- */
133
- remove(key: string): TOptBool;
134
- /**
135
- * Remove all stylesheets
136
- */
137
- removeAll(): void;
138
- /**
139
- * Pack styles into CSSStyleSheet and add it into stylesheet dictionary
140
- * @param key - stylesheet key
141
- * @param styles - stylesheet content string
142
- * @returns `true` if stylesheet is packed
143
- * @example
144
- * ```ts
145
- * getProvider().manager.pack('card', '.card{width: auto;height:100%};.card__header{display:flex;height:5rem;}');
146
- * ```
147
- */
148
- pack(key: string, styles: string): TOptBool;
149
- /**
150
- * Check if stylesheet exist
151
- * @param key - stylesheet key
152
- */
153
- has(key?: string): boolean;
154
- /**
155
- * Is stylesheet on
156
- * @param key - stylesheet key
157
- */
158
- status(key?: string): boolean;
159
- /**
160
- * Switch stylesheet on
161
- * @param key - stylesheet key
162
- */
163
- on(key?: string | (string | undefined)[]): TOptBool;
164
- /**
165
- * Switch stylesheet off
166
- * @param key - stylesheet key
167
- */
168
- off(key?: string | (string | undefined)[]): TOptBool;
169
- /**
170
- * Apply stylesheets to style consumer
171
- * @param consumer - {@link TStyleConsumer | style consumer}
172
- * @description
173
- * Explicitly applies the current style sheets to the consumer.
174
- * You usually don't need to call this method, as the manager automatically updates the styles of registered consumers.
175
- */
176
- apply(consumer: TStyleConsumer): void;
177
- /**
178
- * Register style consumer
179
- * @param consumer - {@link TStyleConsumer | style consumer}
180
- * @description
181
- * A registered consumer will automatically receive up-to-date styles when they are added, modified, or deleted.
182
- * If the style provider does not contain the `isolated`, the current document will be automatically registered.
183
- */
184
- registerNode(consumer: TStyleConsumer): void;
185
- /**
186
- * Unregister style consumer
187
- * @param consumer - {@link TStyleConsumer | style consumer}
188
- */
189
- unregisterNode(consumer: TStyleConsumer): void;
190
- /**
191
- * Apply style changes to dependent nodes
192
- * @description
193
- * You usually don't need to use this method.
194
- * If you update the stylesheets through the style provider's methods,
195
- * it will automatically apply them to all consumers.
196
- * @see {@link IStyleProvider}
197
- */
198
- notify(): void;
199
- }
200
- /**
201
- * BEM selector resolver
202
- * @description
203
- * Creates a selector from the passed parts.
204
- * @returns BEM selector string
205
- */
206
- export type TResolveSelector = (params: {
207
- /**
208
- * {@link https://en.bem.info/methodology/key-concepts/#block | Block}
209
- */
210
- b: string;
211
- /**
212
- * {@link https://en.bem.info/methodology/key-concepts/#element | Element}
213
- */
214
- e?: string;
215
- /**
216
- * {@link https://en.bem.info/methodology/key-concepts/#modifier | Modifier}
217
- */
218
- m?: string;
219
- /**
220
- * {@link https://en.bem.info/methodology/key-concepts/#modifier | Modifier value}
221
- */
222
- mv?: string;
223
- }) => string;
224
- /**
225
- * BEM attribute resolver
226
- * @description
227
- * Creates an object containing target attribute with its value.
228
- * The object content depends on the value of the style provider's `mode` {@link IStyleProviderParams.mode | attribute}.
229
- * @returns object containing target attribute with its value.
230
- */
231
- export type TResolveAttr = (
232
- /**
233
- * {@link https://en.bem.info/methodology/key-concepts/#block | Block}
234
- */
235
- b?: string) => <E extends string>(
236
- /**
237
- * {@link https://en.bem.info/methodology/key-concepts/#element | Element}
238
- */
239
- e?: E) => <M extends Record<string, Record<string, string | number | TOptBool | null>>>(
240
- /**
241
- * {@link https://en.bem.info/methodology/key-concepts/#modifier | Modifiers}
242
- */
243
- m?: string | Partial<M[NoInfer<E>]>) => TStrDict;
244
- /**
245
- * Resolved attributes object
246
- */
247
- type TResolvedAttr = ReturnType<TResolveAttr>;
248
- /**
249
- * Style resolver
250
- * @description
251
- * Resolves stylesheets' selectors/attributes/identifiers
252
- */
253
- export interface IStyleResolver {
254
- /**
255
- * Selector resolver
256
- */
257
- selector: TResolveSelector;
258
- /**
259
- * Attribute resolver
260
- */
261
- attr: TResolveAttr;
262
- /**
263
- * Var name resolver
264
- */
265
- varName: (...parts: (string | number)[]) => string;
266
- /**
267
- * Keyframes name resolver
268
- */
269
- kfName: (...parts: (string | number)[]) => string;
270
- }
271
- /**
272
- * Stylesheet resolver getter
273
- */
274
- export type TCreateResolver = (params?: {
275
- mode?: TStyleMode | null;
276
- }) => IStyleResolver;
277
- /**
278
- * Style processor
279
- * @description
280
- * Converts stylesheet config to CSSStylesheet string content.
281
- */
282
- export interface IStyleProcessor {
283
- /**
284
- * Compile style config to CSS stylesheet text content
285
- * @param b - block key
286
- * @param config - stylesheet config
287
- */
288
- compile(b: string, config: TStyleSheetConfig): string;
289
- }
290
- /**
291
- * Style collector
292
- * @description
293
- * Collects stylesheet configs and maps them with keys
294
- */
295
- export interface IStyleCollector {
296
- /**
297
- * Collect config
298
- * @param config - stylesheet config
299
- * @param key - stylesheet key
300
- */
301
- use(config: TStyleSheetConfig, key?: string): string;
302
- /**
303
- * Mutates original stylesheet config with new content
304
- * @param key - stylesheet key
305
- * @param nextConfig - new stylesheet config
306
- */
307
- mutate(key: string, nextConfig: TStyleSheetConfig): TStyleSheetConfig;
308
- /**
309
- * Get key of collected config
310
- * @param config - stylesheet config
311
- */
312
- getKey(config: TStyleSheetConfig): string | undefined;
313
- /**
314
- * Get all collected keys
315
- */
316
- getKeys(): string[];
317
- /**
318
- * Get all collected configs
319
- */
320
- getConfigs(): TConfigDict;
321
- }
322
- /**
323
- * Style provider
324
- * @description
325
- * Basic interface for style provider component.
326
- */
327
- export interface IStyleProvider {
328
- /**
329
- * Provider initial content
330
- */
331
- initContent: TProviderInitContent;
332
- /**
333
- * Provider settings
334
- */
335
- settingsContent: TProviderSettings;
336
- /**
337
- * All collected stylesheet configs
338
- */
339
- configs: TConfigDict;
340
- /**
341
- * Use stylesheet
342
- * @param config - stylesheet config
343
- * @returns {@link IStyleResolver.attr | attribute resolver}
344
- * @description
345
- * The method allows to use stylesheet without having its key.
346
- * It returns {@link IStyleResolver.attr | attribute resolver}, that can create BEM selectors for config passed.
347
- */
348
- use(config: TStyleSheetConfig, key?: string): TResolvedAttr;
349
- /**
350
- * Alter stylesheet with merged config
351
- * @param target - target stylesheet config or key
352
- * @param nextConfig - next stylesheet config, that will be merged with previous
353
- */
354
- alter(target: TStyleTarget, nextConfig: TStyleSheetConfig): TResolvedAttr;
355
- /**
356
- * Use public stylesheet configs
357
- * @param configs - stylesheet configs
358
- */
359
- usePublic(configs: TConfigDict): Record<string, TResolvedAttr>;
360
- /**
361
- * Use private stylesheet configs
362
- * @param configs - stylesheet configs
363
- */
364
- usePrivate(configs: TConfigArray): TResolvedAttr[];
365
- /**
366
- * Resolve stylesheet
367
- * @param key - stylesheet key
368
- * @returns BEM attribute resolver for stylesheet
369
- */
370
- resolve(key?: string): TResolvedAttr;
371
- /**
372
- * Prepare CSS from config
373
- * @param config - stylesheet config
374
- * @param key - stylesheet key
375
- */
376
- css(config: TStyleSheetConfig, key: string): string;
377
- /**
378
- * Get CSS stylesheet
379
- * @param target - target stylesheet config or key
380
- */
381
- get(target?: TStyleTarget): TOptSheet;
382
- /**
383
- * Switch stylesheet/stylesheets on
384
- * @param target - target stylesheet config or key
385
- */
386
- on(target?: TOneOrManyTargets): TOptBool;
387
- /**
388
- * Switch stylesheet/stylesheets off
389
- * @param target - target stylesheet config or key
390
- */
391
- off(target?: TOneOrManyTargets): TOptBool;
392
- /**
393
- * Check if stylesheet is on
394
- * @param target - target stylesheet config or key
395
- */
396
- status(target?: TStyleTarget): TOptBool;
397
- /**
398
- * Get many CSS stylesheets
399
- * @param target - target stylesheet configs and/or keys
400
- */
401
- getMany(targets?: TStyleTarget[]): TOptSheet[];
402
- /**
403
- * Subscribe to style changes
404
- * @param consumer - styles consumer
405
- */
406
- subscribe(consumer: TStyleConsumer): void;
407
- /**
408
- * Unsubscribe from styles changes
409
- * @param consumer - styles consumer
410
- */
411
- unsubscribe(consumer: TStyleConsumer): void;
412
- }
413
- /**
414
- * Style dispatcher
415
- * @description
416
- * Dispatches style operations to provider
417
- */
418
- export interface IStyleDispatcher {
419
- /**
420
- * Use stylesheet
421
- * @see {@link IStyleProvider.use}
422
- */
423
- use: IStyleProvider['use'];
424
- /**
425
- * Use public stylesheet configs
426
- * @see {@link IStyleProvider.usePublic}
427
- */
428
- usePublic: IStyleProvider['usePublic'];
429
- /**
430
- * Use private stylesheet configs
431
- * @see {@link IStyleProvider.usePrivate}
432
- */
433
- usePrivate: IStyleProvider['usePrivate'];
434
- /**
435
- * Resolve stylesheet
436
- * @see {@link IStyleProvider.resolve}
437
- */
438
- resolve: IStyleProvider['resolve'];
439
- }
440
- /**
441
- * Variable type
442
- * @description
443
- * `c` - oklch color variable,
444
- * otherwise simple CSS variable.
445
- */
446
- export type TVariableType = 'c' | undefined;
447
- /**
448
- * CSS variable
449
- * @description
450
- * Specifies variable format in {@link TStyleSheetConfig | stylesheet config}.
451
- * Extends {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@property | `@property` rule}.
452
- */
453
- export type TVariable = {
454
- /**
455
- * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax | Syntax}
456
- */
457
- syn?: string;
458
- /**
459
- * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@property/initial-value | Initial value}
460
- */
461
- ini?: number | string;
462
- /**
463
- * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@property/inherits | Inherits}
464
- */
465
- inh?: boolean;
466
- /**
467
- * {@link TVariableType | Type}
468
- */
469
- typ?: unknown;
470
- /**
471
- * Create service variables
472
- * @description
473
- * If this variable type use service variables,
474
- * it will declare them.
475
- */
476
- all?: boolean;
477
- };
478
- /**
479
- * Style themes
480
- */
481
- export type TThemes = Record<string, Record<string, Record<string, string | number>>>;
482
- /**
483
- * Style generation mode for {@link IStyleResolver | BEM selectors}
484
- * @description
485
- * `a` - attributes
486
- * `c` - classes
487
- */
488
- export type TStyleMode = 'a' | 'c';
489
- /**
490
- * Style provider attributes
491
- * @description
492
- * Attributes that can be set on a provider component.
493
- */
494
- export interface IStyleProviderParams {
495
- /**
496
- * Settings script selector
497
- * @description
498
- * Allows to read the initial settings from a separate element script.
499
- * If not specified, `effcss` is used.
500
- */
501
- settingsid?: string;
502
- /**
503
- * Initial content script selector
504
- */
505
- initcls?: string;
506
- /**
507
- * Prefix
508
- * @description
509
- * Allows to prefix scoped keys with special string.
510
- * If not specified, `eff` is used.
511
- */
512
- prefix?: string | null;
513
- /**
514
- * Style generation mode for BEM-selectors
515
- * @description
516
- * It only affects the generation of BEM selectors.
517
- * @see {@link TStyleMode}
518
- */
519
- mode?: TStyleMode | null;
520
- /**
521
- * Isolated provider
522
- * @description
523
- * If specified, provider won`t register document as dependent node
524
- */
525
- isolated?: '' | null;
526
- /**
527
- * Hydrate initial stylesheets
528
- */
529
- hydrate?: '' | null;
530
- /**
531
- * Custom event name that fires when styles changes
532
- * @description
533
- * Allows you to subscribe to a style change event in the DOM.
534
- * If not specified, `effcsschanges` is used.
535
- */
536
- eventname?: string | null;
537
- }
538
- /**
539
- * Style consumer node
540
- * @description
541
- * It can be registered via {@link IStyleManager.registerNode | `StyleManager.registerNode`} method.
542
- */
543
- export type TStyleConsumer = {
544
- adoptedStyleSheets: CSSStyleSheet[];
545
- };
546
- /**
547
- * Props to define style provider
548
- */
549
- export interface IDefineProviderProps {
550
- /**
551
- * Element name
552
- * @defaultValue style-provider
553
- */
554
- name?: string;
555
- /**
556
- * Initial styles
557
- */
558
- styles?: TProviderInitContent;
559
- /**
560
- * Provider config
561
- * @description
562
- * Will be used for initial stylesheets generation
563
- */
564
- settings?: TProviderSettings;
565
- }
566
- declare global {
567
- interface Window {
568
- __EFFCSS_PARAMS__: IDefineProviderProps;
569
- }
570
- }
571
- export {};
@@ -1,131 +0,0 @@
1
- import { IStyleDispatcher, IStyleProvider, TConfigArray, TConfigDict, TStyleSheetConfig, TStyleTarget } from '../types';
2
- /**
3
- * Get style provider component
4
- * @param root - style provider scope
5
- * @description
6
- * Use this function to get the first provider element found in the document
7
- * @see {@link IStyleProvider}
8
- */
9
- export declare const getProvider: (root?: Document, tag?: string | undefined) => IStyleProvider;
10
- /**
11
- * Use stylesheet
12
- * @param config - stylesheet config
13
- * @param provider - style provider
14
- * @see {@link IStyleProvider}
15
- */
16
- export declare const useStyleSheet: (config: TStyleSheetConfig, key?: string, provider?: IStyleProvider) => <E extends string>(e?: E) => <M extends Record<string, Record<string, string | number | (boolean | undefined) | null>>>(m?: string | Partial<M[NoInfer<E>]>) => {
17
- [x: string]: string;
18
- };
19
- /**
20
- * Use public stylehseet configs
21
- * @param styles - stylesheet configs
22
- * @param provider - style provider
23
- * @see {@link IStyleProvider}
24
- */
25
- export declare const usePublicStyleSheets: (styles: TConfigDict, provider?: IStyleProvider) => Record<string, <E extends string>(e?: E) => <M extends Record<string, Record<string, string | number | (boolean | undefined) | null>>>(m?: string | Partial<M[NoInfer<E>]>) => {
26
- [x: string]: string;
27
- }>;
28
- /**
29
- * Use private stylehseet configs
30
- * @param styles - stylesheet configs
31
- * @param provider - style provider
32
- * @see {@link IStyleProvider}
33
- */
34
- export declare const usePrivateStyleSheets: (styles: TConfigArray, provider?: IStyleProvider) => (<E extends string>(e?: E) => <M extends Record<string, Record<string, string | number | (boolean | undefined) | null>>>(m?: string | Partial<M[NoInfer<E>]>) => {
35
- [x: string]: string;
36
- })[];
37
- /**
38
- * Resolve stylesheet
39
- * @param key stylesheet key
40
- * @param provider - style provider
41
- * @see {@link IStyleProvider}
42
- */
43
- export declare const resolveStyleSheet: (key?: string, provider?: IStyleProvider) => <E extends string>(e?: E) => <M extends Record<string, Record<string, string | number | (boolean | undefined) | null>>>(m?: string | Partial<M[NoInfer<E>]>) => {
44
- [x: string]: string;
45
- };
46
- /**
47
- * Get stylesheet from provider
48
- * @param key - stylesheet key
49
- * @param provider - style provider
50
- * @see {@link IStyleProvider}
51
- */
52
- export declare const getStyleSheet: (key?: TStyleTarget, provider?: IStyleProvider) => CSSStyleSheet | undefined;
53
- /**
54
- * Get stylesheet from provider
55
- * @param key - stylesheet key
56
- * @param provider - style provider
57
- * @see {@link IStyleProvider}
58
- */
59
- export declare const getManyStyleSheets: (key?: TStyleTarget[], provider?: IStyleProvider) => (CSSStyleSheet | undefined)[];
60
- /**
61
- * Stringify stylesheet
62
- * @param key - stylesheet key
63
- * @param provider - style provider
64
- * @see {@link IStyleProvider}
65
- */
66
- export declare const stringifyOne: (key?: TStyleTarget, provider?: IStyleProvider) => string;
67
- /**
68
- * Stringify stylesheet
69
- * @param key - stylesheet key
70
- * @param provider - style provider
71
- * @see {@link IStyleProvider}
72
- */
73
- export declare const stringifyMany: (key?: TStyleTarget[], provider?: IStyleProvider) => string;
74
- /**
75
- * Get rules count for stylesheet
76
- * @param key - stylesheet key
77
- * @param provider - style provider
78
- * @see {@link IStyleProvider}
79
- */
80
- export declare const measureOne: (key: string, provider?: IStyleProvider) => number;
81
- /**
82
- * Get rules count for stylesheet
83
- * @param key - stylesheet key
84
- * @param provider - style provider
85
- * @see {@link IStyleProvider}
86
- */
87
- export declare const measureMany: (keys: string[], provider?: IStyleProvider) => number;
88
- interface IStyleDispatcherParams {
89
- root?: Document;
90
- tag?: string;
91
- }
92
- /**
93
- * Basic class for manipulating stylesheets
94
- */
95
- declare class StyleDispatcher implements IStyleDispatcher {
96
- /**
97
- * Style provider
98
- */
99
- protected _p: IStyleProvider;
100
- constructor(params?: IStyleDispatcherParams);
101
- /**
102
- * Use stylesheet
103
- * @param config - stylesheet config
104
- * @see {@link IStyleProvider}
105
- */
106
- use: IStyleProvider['use'];
107
- /**
108
- * Use public stylesheet configs
109
- * @param styles - stylesheet configs
110
- * @see {@link IStyleProvider}
111
- */
112
- usePublic: IStyleProvider['usePublic'];
113
- /**
114
- * Use private stylesheet configs
115
- * @param styles - stylesheet configs
116
- * @see {@link IStyleProvider}
117
- */
118
- usePrivate: IStyleProvider['usePrivate'];
119
- /**
120
- * Resolve stylesheet
121
- * @param key - stylesheet key
122
- * @see {@link IStyleProvider}
123
- */
124
- resolve: IStyleProvider['resolve'];
125
- }
126
- /**
127
- * Create style dispatcher
128
- * @param params - dispatcher params
129
- */
130
- export declare function createDispatcher(params?: IStyleDispatcherParams): StyleDispatcher;
131
- export {};