@navita/engine 0.0.10 → 0.0.12
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/cache.cjs +27 -0
- package/cache.mjs +25 -0
- package/helpers/declarationsToBlock.cjs +17 -0
- package/helpers/declarationsToBlock.mjs +15 -0
- package/helpers/generateCombinedAtRules.cjs +10 -0
- package/helpers/generateCombinedAtRules.mjs +8 -0
- package/helpers/getPropertyPriority.cjs +262 -0
- package/helpers/getPropertyPriority.mjs +260 -0
- package/helpers/hypenateProperty.cjs +11 -0
- package/helpers/hypenateProperty.mjs +9 -0
- package/helpers/isMediaQuery.cjs +7 -0
- package/helpers/isMediaQuery.mjs +5 -0
- package/helpers/isNestedSelector.cjs +8 -0
- package/helpers/isNestedSelector.mjs +6 -0
- package/helpers/isObject.cjs +7 -0
- package/helpers/isObject.mjs +5 -0
- package/helpers/isSupportsQuery.cjs +7 -0
- package/helpers/isSupportsQuery.mjs +5 -0
- package/helpers/normalizeCSSVarsProperty.cjs +15 -0
- package/helpers/normalizeCSSVarsProperty.mjs +13 -0
- package/helpers/normalizeNestedProperty.cjs +10 -0
- package/helpers/normalizeNestedProperty.mjs +8 -0
- package/helpers/pixelifyProperties.cjs +58 -0
- package/helpers/pixelifyProperties.mjs +56 -0
- package/helpers/splitStyleBlocks.cjs +19 -0
- package/helpers/splitStyleBlocks.mjs +17 -0
- package/helpers/transformContentProperty.cjs +8 -0
- package/helpers/transformContentProperty.mjs +6 -0
- package/identifiers/IDGenerator.cjs +10 -0
- package/identifiers/IDGenerator.mjs +8 -0
- package/identifiers/alphaIDGenerator.cjs +27 -0
- package/identifiers/alphaIDGenerator.mjs +25 -0
- package/identifiers/propertyValueIDGenerator.cjs +24 -0
- package/identifiers/propertyValueIDGenerator.mjs +22 -0
- package/index.cjs +213 -0
- package/index.mjs +14 -677
- package/package.json +2 -2
- package/printers/printFontFaces.cjs +15 -0
- package/printers/printFontFaces.mjs +13 -0
- package/printers/printKeyFrames.cjs +21 -0
- package/printers/printKeyFrames.mjs +19 -0
- package/printers/printSourceMap.cjs +42 -0
- package/printers/printSourceMap.mjs +40 -0
- package/printers/printStyleBlocks.cjs +60 -0
- package/printers/printStyleBlocks.mjs +58 -0
- package/printers/sortAtRules.cjs +10 -0
- package/printers/sortAtRules.mjs +8 -0
- package/printers/sortStatic.cjs +7 -0
- package/printers/sortStatic.mjs +5 -0
- package/processStyles.cjs +88 -0
- package/processStyles.mjs +86 -0
- package/types.cjs +2 -0
- package/types.mjs +1 -0
- package/wrappers/classList.cjs +6 -0
- package/wrappers/classList.mjs +4 -0
- package/wrappers/static.cjs +6 -0
- package/wrappers/static.mjs +4 -0
- package/index.js +0 -876
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const regex = /var\(([^,]+).*\)/;
|
|
4
|
+
function normalizeCSSVarsProperty(property) {
|
|
5
|
+
if (!property.startsWith('var(')) {
|
|
6
|
+
return property;
|
|
7
|
+
}
|
|
8
|
+
const matches = property.match(regex);
|
|
9
|
+
if (!matches) {
|
|
10
|
+
return property;
|
|
11
|
+
}
|
|
12
|
+
return matches[1];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.normalizeCSSVarsProperty = normalizeCSSVarsProperty;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const regex = /var\(([^,]+).*\)/;
|
|
2
|
+
function normalizeCSSVarsProperty(property) {
|
|
3
|
+
if (!property.startsWith('var(')) {
|
|
4
|
+
return property;
|
|
5
|
+
}
|
|
6
|
+
const matches = property.match(regex);
|
|
7
|
+
if (!matches) {
|
|
8
|
+
return property;
|
|
9
|
+
}
|
|
10
|
+
return matches[1];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { normalizeCSSVarsProperty };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const UNITLESS = {
|
|
4
|
+
animationIterationCount: true,
|
|
5
|
+
borderImage: true,
|
|
6
|
+
borderImageOutset: true,
|
|
7
|
+
borderImageSlice: true,
|
|
8
|
+
borderImageWidth: true,
|
|
9
|
+
boxFlex: true,
|
|
10
|
+
boxFlexGroup: true,
|
|
11
|
+
columnCount: true,
|
|
12
|
+
columns: true,
|
|
13
|
+
flex: true,
|
|
14
|
+
flexGrow: true,
|
|
15
|
+
flexShrink: true,
|
|
16
|
+
fontWeight: true,
|
|
17
|
+
gridArea: true,
|
|
18
|
+
gridColumn: true,
|
|
19
|
+
gridColumnEnd: true,
|
|
20
|
+
gridColumnStart: true,
|
|
21
|
+
gridRow: true,
|
|
22
|
+
gridRowEnd: true,
|
|
23
|
+
gridRowStart: true,
|
|
24
|
+
initialLetter: true,
|
|
25
|
+
lineClamp: true,
|
|
26
|
+
lineHeight: true,
|
|
27
|
+
maxLines: true,
|
|
28
|
+
opacity: true,
|
|
29
|
+
order: true,
|
|
30
|
+
orphans: true,
|
|
31
|
+
scale: true,
|
|
32
|
+
tabSize: true,
|
|
33
|
+
WebkitLineClamp: true,
|
|
34
|
+
widows: true,
|
|
35
|
+
zIndex: true,
|
|
36
|
+
zoom: true,
|
|
37
|
+
// svg properties
|
|
38
|
+
fillOpacity: true,
|
|
39
|
+
floodOpacity: true,
|
|
40
|
+
maskBorder: true,
|
|
41
|
+
maskBorderOutset: true,
|
|
42
|
+
maskBorderSlice: true,
|
|
43
|
+
maskBorderWidth: true,
|
|
44
|
+
shapeImageThreshold: true,
|
|
45
|
+
stopOpacity: true,
|
|
46
|
+
strokeDashoffset: true,
|
|
47
|
+
strokeMiterlimit: true,
|
|
48
|
+
strokeOpacity: true,
|
|
49
|
+
strokeWidth: true
|
|
50
|
+
};
|
|
51
|
+
function pixelifyProperties(property, value) {
|
|
52
|
+
if (value !== 0 && !UNITLESS[property]) {
|
|
53
|
+
return `${value}px`;
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.pixelifyProperties = pixelifyProperties;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const UNITLESS = {
|
|
2
|
+
animationIterationCount: true,
|
|
3
|
+
borderImage: true,
|
|
4
|
+
borderImageOutset: true,
|
|
5
|
+
borderImageSlice: true,
|
|
6
|
+
borderImageWidth: true,
|
|
7
|
+
boxFlex: true,
|
|
8
|
+
boxFlexGroup: true,
|
|
9
|
+
columnCount: true,
|
|
10
|
+
columns: true,
|
|
11
|
+
flex: true,
|
|
12
|
+
flexGrow: true,
|
|
13
|
+
flexShrink: true,
|
|
14
|
+
fontWeight: true,
|
|
15
|
+
gridArea: true,
|
|
16
|
+
gridColumn: true,
|
|
17
|
+
gridColumnEnd: true,
|
|
18
|
+
gridColumnStart: true,
|
|
19
|
+
gridRow: true,
|
|
20
|
+
gridRowEnd: true,
|
|
21
|
+
gridRowStart: true,
|
|
22
|
+
initialLetter: true,
|
|
23
|
+
lineClamp: true,
|
|
24
|
+
lineHeight: true,
|
|
25
|
+
maxLines: true,
|
|
26
|
+
opacity: true,
|
|
27
|
+
order: true,
|
|
28
|
+
orphans: true,
|
|
29
|
+
scale: true,
|
|
30
|
+
tabSize: true,
|
|
31
|
+
WebkitLineClamp: true,
|
|
32
|
+
widows: true,
|
|
33
|
+
zIndex: true,
|
|
34
|
+
zoom: true,
|
|
35
|
+
// svg properties
|
|
36
|
+
fillOpacity: true,
|
|
37
|
+
floodOpacity: true,
|
|
38
|
+
maskBorder: true,
|
|
39
|
+
maskBorderOutset: true,
|
|
40
|
+
maskBorderSlice: true,
|
|
41
|
+
maskBorderWidth: true,
|
|
42
|
+
shapeImageThreshold: true,
|
|
43
|
+
stopOpacity: true,
|
|
44
|
+
strokeDashoffset: true,
|
|
45
|
+
strokeMiterlimit: true,
|
|
46
|
+
strokeOpacity: true,
|
|
47
|
+
strokeWidth: true
|
|
48
|
+
};
|
|
49
|
+
function pixelifyProperties(property, value) {
|
|
50
|
+
if (value !== 0 && !UNITLESS[property]) {
|
|
51
|
+
return `${value}px`;
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { pixelifyProperties };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function splitStyleBlocks(blocks) {
|
|
4
|
+
const atRules = [];
|
|
5
|
+
const rules = [];
|
|
6
|
+
for (const block of blocks){
|
|
7
|
+
if (block.media || block.support) {
|
|
8
|
+
atRules.push(block);
|
|
9
|
+
} else {
|
|
10
|
+
rules.push(block);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
atRules,
|
|
15
|
+
rules
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.splitStyleBlocks = splitStyleBlocks;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function splitStyleBlocks(blocks) {
|
|
2
|
+
const atRules = [];
|
|
3
|
+
const rules = [];
|
|
4
|
+
for (const block of blocks){
|
|
5
|
+
if (block.media || block.support) {
|
|
6
|
+
atRules.push(block);
|
|
7
|
+
} else {
|
|
8
|
+
rules.push(block);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
atRules,
|
|
13
|
+
rules
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { splitStyleBlocks };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// https://github.com/vanilla-extract-css/vanilla-extract/blob/40d7e72c041989a4dc847dc66b94a4c680b5536e/packages/css/src/transformCss.ts#L277
|
|
4
|
+
function transformContentProperty(value) {
|
|
5
|
+
return value && (value.includes('"') || value.includes("'") || /^([A-Za-z\-]+\([^]*|[^]*-quote|inherit|initial|none|normal|revert|unset)(\s|$)/.test(value)) ? value : `"${value}"`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
exports.transformContentProperty = transformContentProperty;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// https://github.com/vanilla-extract-css/vanilla-extract/blob/40d7e72c041989a4dc847dc66b94a4c680b5536e/packages/css/src/transformCss.ts#L277
|
|
2
|
+
function transformContentProperty(value) {
|
|
3
|
+
return value && (value.includes('"') || value.includes("'") || /^([A-Za-z\-]+\([^]*|[^]*-quote|inherit|initial|none|normal|revert|unset)(\s|$)/.test(value)) ? value : `"${value}"`;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export { transformContentProperty };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
4
|
+
const charLength = chars.length;
|
|
5
|
+
class AlphaIDGenerator {
|
|
6
|
+
constructor(blacklist = [
|
|
7
|
+
'ad'
|
|
8
|
+
]){
|
|
9
|
+
this.blacklist = blacklist;
|
|
10
|
+
this.counter = 1;
|
|
11
|
+
}
|
|
12
|
+
next() {
|
|
13
|
+
const nextString = (id, className = '')=>{
|
|
14
|
+
if (id <= charLength) {
|
|
15
|
+
return chars[id - 1] + className;
|
|
16
|
+
}
|
|
17
|
+
return nextString(id / charLength | 0, chars[(id - 1) % charLength] + className);
|
|
18
|
+
};
|
|
19
|
+
let className;
|
|
20
|
+
do {
|
|
21
|
+
className = nextString(this.counter++);
|
|
22
|
+
}while (this.blacklist.includes(className.toLowerCase()))
|
|
23
|
+
return className;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.AlphaIDGenerator = AlphaIDGenerator;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
2
|
+
const charLength = chars.length;
|
|
3
|
+
class AlphaIDGenerator {
|
|
4
|
+
constructor(blacklist = [
|
|
5
|
+
'ad'
|
|
6
|
+
]){
|
|
7
|
+
this.blacklist = blacklist;
|
|
8
|
+
this.counter = 1;
|
|
9
|
+
}
|
|
10
|
+
next() {
|
|
11
|
+
const nextString = (id, className = '')=>{
|
|
12
|
+
if (id <= charLength) {
|
|
13
|
+
return chars[id - 1] + className;
|
|
14
|
+
}
|
|
15
|
+
return nextString(id / charLength | 0, chars[(id - 1) % charLength] + className);
|
|
16
|
+
};
|
|
17
|
+
let className;
|
|
18
|
+
do {
|
|
19
|
+
className = nextString(this.counter++);
|
|
20
|
+
}while (this.blacklist.includes(className.toLowerCase()))
|
|
21
|
+
return className;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { AlphaIDGenerator };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var identifiers_alphaIDGenerator = require('./alphaIDGenerator.cjs');
|
|
4
|
+
|
|
5
|
+
class PropertyValueIDGenerator {
|
|
6
|
+
property = new identifiers_alphaIDGenerator.AlphaIDGenerator();
|
|
7
|
+
cache = {};
|
|
8
|
+
next({ property , media ='' , support ='' , pseudo ='' , value }) {
|
|
9
|
+
const propertyKey = `${media}${support}${pseudo}${property}`;
|
|
10
|
+
if (this.cache[propertyKey] === undefined) {
|
|
11
|
+
this.cache[propertyKey] = {
|
|
12
|
+
key: this.property.next(),
|
|
13
|
+
cache: {}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const entry = this.cache[propertyKey];
|
|
17
|
+
if (entry.cache[value] === undefined) {
|
|
18
|
+
entry.cache[value] = Object.keys(entry.cache).length + 1;
|
|
19
|
+
}
|
|
20
|
+
return `${entry.key}${entry.cache[value]}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.PropertyValueIDGenerator = PropertyValueIDGenerator;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AlphaIDGenerator } from './alphaIDGenerator.mjs';
|
|
2
|
+
|
|
3
|
+
class PropertyValueIDGenerator {
|
|
4
|
+
property = new AlphaIDGenerator();
|
|
5
|
+
cache = {};
|
|
6
|
+
next({ property , media ='' , support ='' , pseudo ='' , value }) {
|
|
7
|
+
const propertyKey = `${media}${support}${pseudo}${property}`;
|
|
8
|
+
if (this.cache[propertyKey] === undefined) {
|
|
9
|
+
this.cache[propertyKey] = {
|
|
10
|
+
key: this.property.next(),
|
|
11
|
+
cache: {}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const entry = this.cache[propertyKey];
|
|
15
|
+
if (entry.cache[value] === undefined) {
|
|
16
|
+
entry.cache[value] = Object.keys(entry.cache).length + 1;
|
|
17
|
+
}
|
|
18
|
+
return `${entry.key}${entry.cache[value]}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { PropertyValueIDGenerator };
|
package/index.cjs
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var hash = require('@emotion/hash');
|
|
5
|
+
var cache = require('./cache.cjs');
|
|
6
|
+
var helpers_isObject = require('./helpers/isObject.cjs');
|
|
7
|
+
var helpers_splitStyleBlocks = require('./helpers/splitStyleBlocks.cjs');
|
|
8
|
+
var identifiers_IDGenerator = require('./identifiers/IDGenerator.cjs');
|
|
9
|
+
var identifiers_alphaIDGenerator = require('./identifiers/alphaIDGenerator.cjs');
|
|
10
|
+
var identifiers_propertyValueIDGenerator = require('./identifiers/propertyValueIDGenerator.cjs');
|
|
11
|
+
var printers_printFontFaces = require('./printers/printFontFaces.cjs');
|
|
12
|
+
var printers_printKeyFrames = require('./printers/printKeyFrames.cjs');
|
|
13
|
+
var printers_printSourceMap = require('./printers/printSourceMap.cjs');
|
|
14
|
+
var printers_printStyleBlocks = require('./printers/printStyleBlocks.cjs');
|
|
15
|
+
var printers_sortAtRules = require('./printers/sortAtRules.cjs');
|
|
16
|
+
var processStyles = require('./processStyles.cjs');
|
|
17
|
+
var wrappers_classList = require('./wrappers/classList.cjs');
|
|
18
|
+
var wrappers_static = require('./wrappers/static.cjs');
|
|
19
|
+
|
|
20
|
+
const defaultOptions = {
|
|
21
|
+
enableSourceMaps: false,
|
|
22
|
+
enableDebugIdentifiers: false
|
|
23
|
+
};
|
|
24
|
+
class Engine {
|
|
25
|
+
caches = {
|
|
26
|
+
rule: new cache.Cache(new identifiers_propertyValueIDGenerator.PropertyValueIDGenerator()),
|
|
27
|
+
static: new cache.Cache(new identifiers_IDGenerator.IDGenerator()),
|
|
28
|
+
keyframes: new cache.Cache(new identifiers_alphaIDGenerator.AlphaIDGenerator()),
|
|
29
|
+
fontFace: new cache.Cache(new identifiers_alphaIDGenerator.AlphaIDGenerator()),
|
|
30
|
+
identifiers: new cache.Cache(new identifiers_alphaIDGenerator.AlphaIDGenerator())
|
|
31
|
+
};
|
|
32
|
+
usedIds = {};
|
|
33
|
+
identifierCount = 0;
|
|
34
|
+
options = {};
|
|
35
|
+
sourceMapReferences = {};
|
|
36
|
+
constructor(options = {}){
|
|
37
|
+
this.options = {
|
|
38
|
+
...defaultOptions,
|
|
39
|
+
...Object.keys(options).reduce((acc, key)=>{
|
|
40
|
+
if (options[key] !== undefined) {
|
|
41
|
+
acc[key] = options[key];
|
|
42
|
+
}
|
|
43
|
+
return acc;
|
|
44
|
+
}, {})
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
addStatic(selector, styles) {
|
|
48
|
+
this.addUsedIds("static", processStyles.processStyles({
|
|
49
|
+
type: "static",
|
|
50
|
+
cache: this.caches.static
|
|
51
|
+
})({
|
|
52
|
+
styles,
|
|
53
|
+
selector
|
|
54
|
+
}).map((style)=>style.id));
|
|
55
|
+
return new wrappers_static.Static();
|
|
56
|
+
}
|
|
57
|
+
addStyle(styles) {
|
|
58
|
+
const rules = processStyles.processStyles({
|
|
59
|
+
type: "rule",
|
|
60
|
+
cache: this.caches.rule
|
|
61
|
+
})({
|
|
62
|
+
styles
|
|
63
|
+
});
|
|
64
|
+
const ids = rules.map((rule)=>rule.id);
|
|
65
|
+
this.addUsedIds("rule", ids);
|
|
66
|
+
return new wrappers_classList.ClassList(ids.join(" "));
|
|
67
|
+
}
|
|
68
|
+
addFontFace(fontFace) {
|
|
69
|
+
const { id } = this.caches.fontFace.getOrStore({
|
|
70
|
+
type: "fontFace",
|
|
71
|
+
rule: Array.isArray(fontFace) ? fontFace : [
|
|
72
|
+
fontFace
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
this.addUsedIds("fontFace", [
|
|
76
|
+
id
|
|
77
|
+
]);
|
|
78
|
+
return id;
|
|
79
|
+
}
|
|
80
|
+
addKeyframes(keyframes) {
|
|
81
|
+
const { id } = this.caches.keyframes.getOrStore({
|
|
82
|
+
type: "keyframes",
|
|
83
|
+
rule: keyframes
|
|
84
|
+
});
|
|
85
|
+
this.addUsedIds("keyframes", [
|
|
86
|
+
id
|
|
87
|
+
]);
|
|
88
|
+
return id;
|
|
89
|
+
}
|
|
90
|
+
addSourceMapReference({ filePath , identifier , classList , line , column , index }) {
|
|
91
|
+
if (!this.options.enableSourceMaps) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const { name } = path.parse(filePath);
|
|
95
|
+
const extraClass = this.options.enableDebugIdentifiers ? `${name}_${identifier}` : '';
|
|
96
|
+
const selector = '.' + classList.toString().split(' ').concat(extraClass).filter(Boolean).join('.');
|
|
97
|
+
const newFilePath = path.relative(this.options.context || process.cwd(), filePath);
|
|
98
|
+
if (index === 0 || !this.sourceMapReferences[newFilePath]) {
|
|
99
|
+
this.sourceMapReferences[newFilePath] = [];
|
|
100
|
+
}
|
|
101
|
+
this.sourceMapReferences[newFilePath][index] = {
|
|
102
|
+
selector,
|
|
103
|
+
line,
|
|
104
|
+
column
|
|
105
|
+
};
|
|
106
|
+
return extraClass;
|
|
107
|
+
}
|
|
108
|
+
generateIdentifier(value) {
|
|
109
|
+
if (typeof value === 'undefined') {
|
|
110
|
+
let identifier = hash((this.identifierCount++).toString(36));
|
|
111
|
+
if (identifier.match(/^\d/)) {
|
|
112
|
+
identifier = `_${identifier}`;
|
|
113
|
+
}
|
|
114
|
+
return identifier;
|
|
115
|
+
}
|
|
116
|
+
const newValue = JSON.stringify(value);
|
|
117
|
+
const { id } = this.caches.identifiers.getOrStore({
|
|
118
|
+
value: newValue
|
|
119
|
+
});
|
|
120
|
+
this.addUsedIds("identifiers", [
|
|
121
|
+
id
|
|
122
|
+
]);
|
|
123
|
+
return `_${id}`;
|
|
124
|
+
}
|
|
125
|
+
renderCssToString(options) {
|
|
126
|
+
const { filePaths , usedIds , opinionatedLayers =false } = options || {};
|
|
127
|
+
// We prioritize ids over filePaths. If neither are provided, we use all the used filePaths.
|
|
128
|
+
const { keyframes: keyframesCache , fontFace: fontFaceCache , static: staticCache , rule: ruleCache } = usedIds ?? this.getUsedCacheIds(filePaths ?? Object.keys(this.usedIds));
|
|
129
|
+
const { atRules , rules } = helpers_splitStyleBlocks.splitStyleBlocks(this.caches.rule.items(ruleCache));
|
|
130
|
+
const keyFrameCss = printers_printKeyFrames.printKeyFrames(this.caches.keyframes.items(keyframesCache));
|
|
131
|
+
const fontFaceCss = printers_printFontFaces.printFontFaces(this.caches.fontFace.items(fontFaceCache));
|
|
132
|
+
const staticCss = printers_printStyleBlocks.printStyleBlocks(this.caches.static.items(staticCache));
|
|
133
|
+
const atRulesCss = printers_printStyleBlocks.printStyleBlocks(printers_sortAtRules.sortAtRules(atRules));
|
|
134
|
+
const rulesCss = printers_printStyleBlocks.printStyleBlocks(rules);
|
|
135
|
+
if (opinionatedLayers) {
|
|
136
|
+
const result = `${keyFrameCss}${fontFaceCss}` + (staticCss.length > 0 ? `@layer static{${staticCss}}` : '') + (rulesCss.length > 0 ? `@layer rules{${rulesCss}}` : '') + (atRulesCss.length > 0 ? `@layer at{${atRulesCss}}` : '');
|
|
137
|
+
if (result.length > 0) {
|
|
138
|
+
return `@layer static,rules,at;${result}`;
|
|
139
|
+
}
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
return printers_printSourceMap.printSourceMap(this.sourceMapReferences, keyFrameCss + fontFaceCss + staticCss + rulesCss + atRulesCss);
|
|
143
|
+
}
|
|
144
|
+
serialize() {
|
|
145
|
+
const { caches , usedIds , identifierCount , sourceMapReferences } = this;
|
|
146
|
+
return JSON.stringify({
|
|
147
|
+
caches,
|
|
148
|
+
usedIds,
|
|
149
|
+
identifierCount,
|
|
150
|
+
sourceMapReferences
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async deserialize(buffer) {
|
|
154
|
+
const data = JSON.parse(buffer.toString());
|
|
155
|
+
function assign(target, source) {
|
|
156
|
+
for(const key in source){
|
|
157
|
+
if (helpers_isObject.isObject(target[key]) && helpers_isObject.isObject(source[key])) {
|
|
158
|
+
assign(target[key], source[key]);
|
|
159
|
+
} else {
|
|
160
|
+
target[key] = source[key];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return target;
|
|
164
|
+
}
|
|
165
|
+
assign(this, data);
|
|
166
|
+
}
|
|
167
|
+
setFilePath(filePath) {
|
|
168
|
+
this.filePath = filePath;
|
|
169
|
+
}
|
|
170
|
+
clearUsedIds(filePath) {
|
|
171
|
+
if (filePath === undefined) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.usedIds[filePath] = {};
|
|
175
|
+
}
|
|
176
|
+
addUsedIds(cacheType, identifiers) {
|
|
177
|
+
const { filePath } = this;
|
|
178
|
+
if (filePath === undefined) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (this.usedIds[filePath] === undefined) {
|
|
182
|
+
this.usedIds[filePath] = {};
|
|
183
|
+
}
|
|
184
|
+
if (this.usedIds[filePath][cacheType] === undefined) {
|
|
185
|
+
this.usedIds[filePath][cacheType] = [];
|
|
186
|
+
}
|
|
187
|
+
this.usedIds[filePath][cacheType] = [
|
|
188
|
+
...new Set([
|
|
189
|
+
...this.usedIds[filePath][cacheType],
|
|
190
|
+
...identifiers
|
|
191
|
+
])
|
|
192
|
+
];
|
|
193
|
+
}
|
|
194
|
+
getUsedCacheIds(filePaths = []) {
|
|
195
|
+
return filePaths.reduce((acc, filePath)=>({
|
|
196
|
+
...acc,
|
|
197
|
+
...Object.keys(this.usedIds[filePath] || []).reduce((cache, key)=>({
|
|
198
|
+
...cache,
|
|
199
|
+
[key]: [
|
|
200
|
+
...acc[key] || [],
|
|
201
|
+
...this.usedIds[filePath][key] || []
|
|
202
|
+
]
|
|
203
|
+
}), {})
|
|
204
|
+
}), Object.keys(this.caches).reduce((acc, key)=>({
|
|
205
|
+
...acc,
|
|
206
|
+
[key]: []
|
|
207
|
+
}), {}));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
exports.ClassList = wrappers_classList.ClassList;
|
|
212
|
+
exports.Static = wrappers_static.Static;
|
|
213
|
+
exports.Engine = Engine;
|