css-engine-test-pb 0.1.8 → 0.2.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.
- package/dist/compiler.d.ts +2 -2
- package/dist/compiler.js +3 -1
- package/dist/engine.d.ts +1 -0
- package/dist/engine.js +5 -0
- package/dist/mergeClasses.js +18 -1
- package/package.json +1 -1
package/dist/compiler.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { StyleRule, StyleBucket } from './types';
|
|
2
|
-
interface CompiledRule {
|
|
2
|
+
export interface CompiledRule {
|
|
3
3
|
className: string;
|
|
4
4
|
cssText: string;
|
|
5
5
|
bucket: StyleBucket;
|
|
6
|
+
propertyKey?: string;
|
|
6
7
|
}
|
|
7
8
|
export type CompileMode = 'atomic' | 'monolithic';
|
|
8
9
|
export declare class StyleCompiler {
|
|
@@ -18,4 +19,3 @@ export declare class StyleCompiler {
|
|
|
18
19
|
private processCombinators;
|
|
19
20
|
private processMediaQueries;
|
|
20
21
|
}
|
|
21
|
-
export {};
|
package/dist/compiler.js
CHANGED
|
@@ -154,10 +154,12 @@ export class StyleCompiler {
|
|
|
154
154
|
if (media) {
|
|
155
155
|
cssText = `${media} { ${cssRule} }`;
|
|
156
156
|
}
|
|
157
|
+
const propertyKey = `${kebabProperty}${pseudo || ''}${media || ''}`;
|
|
157
158
|
rules.push({
|
|
158
159
|
className,
|
|
159
160
|
cssText,
|
|
160
|
-
bucket
|
|
161
|
+
bucket,
|
|
162
|
+
propertyKey
|
|
161
163
|
});
|
|
162
164
|
});
|
|
163
165
|
}
|
package/dist/engine.d.ts
CHANGED
package/dist/engine.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StyleCompiler } from './compiler';
|
|
2
2
|
import { InsertionFactory } from './insertionFactory';
|
|
3
|
+
export const atomicClassMap = new Map();
|
|
3
4
|
export class StyleEngine {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.compiler = new StyleCompiler();
|
|
@@ -14,6 +15,9 @@ export class StyleEngine {
|
|
|
14
15
|
const rules = this.compiler.compile(styleDefinition, mode);
|
|
15
16
|
rules.forEach(rule => {
|
|
16
17
|
this.insertion.insertRule(rule.cssText, rule.bucket);
|
|
18
|
+
if (rule.propertyKey) {
|
|
19
|
+
atomicClassMap.set(rule.className, rule.propertyKey);
|
|
20
|
+
}
|
|
17
21
|
});
|
|
18
22
|
const classNames = Array.from(new Set(rules.map(r => r.className))).join(' ');
|
|
19
23
|
this.cache.set(cacheKey, classNames);
|
|
@@ -35,6 +39,7 @@ export class StyleEngine {
|
|
|
35
39
|
clear() {
|
|
36
40
|
this.insertion.clear();
|
|
37
41
|
this.cache.clear();
|
|
42
|
+
atomicClassMap.clear();
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
let globalEngine = null;
|
package/dist/mergeClasses.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
import { atomicClassMap } from './engine';
|
|
1
2
|
export function mergeClasses(...classNames) {
|
|
2
|
-
|
|
3
|
+
const allClasses = classNames
|
|
4
|
+
.filter((cn) => Boolean(cn))
|
|
5
|
+
.flatMap(cn => cn.split(' '));
|
|
6
|
+
const propertyWins = new Map();
|
|
7
|
+
const nonAtomic = [];
|
|
8
|
+
const seenNonAtomic = new Set();
|
|
9
|
+
for (const cls of allClasses) {
|
|
10
|
+
const propKey = atomicClassMap.get(cls);
|
|
11
|
+
if (propKey) {
|
|
12
|
+
propertyWins.set(propKey, cls);
|
|
13
|
+
}
|
|
14
|
+
else if (!seenNonAtomic.has(cls)) {
|
|
15
|
+
seenNonAtomic.add(cls);
|
|
16
|
+
nonAtomic.push(cls);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return [...nonAtomic, ...propertyWins.values()].join(' ');
|
|
3
20
|
}
|