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