@navita/engine 0.0.9 → 0.0.11
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 +226 -0
- package/index.mjs +27 -673
- package/package.json +2 -2
- package/printers/printFontFaces.cjs +16 -0
- package/printers/printFontFaces.mjs +14 -0
- package/printers/printKeyFrames.cjs +22 -0
- package/printers/printKeyFrames.mjs +20 -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 -872
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navita/engine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Navitas CSS-in-JS engine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css-in-js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"import": "./index.mjs",
|
|
15
|
-
"require": "./index.
|
|
15
|
+
"require": "./index.cjs",
|
|
16
16
|
"types": "./index.d.ts"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var helpers_declarationsToBlock = require('../helpers/declarationsToBlock.cjs');
|
|
4
|
+
require('../helpers/hypenateProperty.cjs');
|
|
5
|
+
|
|
6
|
+
function printFontFaces(blocks) {
|
|
7
|
+
let fontFaces = '';
|
|
8
|
+
for (const block of blocks){
|
|
9
|
+
for (const rule of block.rule){
|
|
10
|
+
fontFaces += `@font-face{font-family:${block.id};${helpers_declarationsToBlock.declarationsToBlock(rule)}}`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return fontFaces;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.printFontFaces = printFontFaces;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { declarationsToBlock } from '../helpers/declarationsToBlock.mjs';
|
|
2
|
+
import '../helpers/hypenateProperty.mjs';
|
|
3
|
+
|
|
4
|
+
function printFontFaces(blocks) {
|
|
5
|
+
let fontFaces = '';
|
|
6
|
+
for (const block of blocks){
|
|
7
|
+
for (const rule of block.rule){
|
|
8
|
+
fontFaces += `@font-face{font-family:${block.id};${declarationsToBlock(rule)}}`;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return fontFaces;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { printFontFaces };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var helpers_declarationsToBlock = require('../helpers/declarationsToBlock.cjs');
|
|
4
|
+
require('../helpers/hypenateProperty.cjs');
|
|
5
|
+
|
|
6
|
+
// https://github.com/styletron/styletron/blob/master/packages/styletron-engine-atomic/src/css.ts#L48
|
|
7
|
+
function keyframesToBlock(keyframes) {
|
|
8
|
+
let result = "";
|
|
9
|
+
for(const animationState in keyframes){
|
|
10
|
+
result += `${animationState}{${helpers_declarationsToBlock.declarationsToBlock(keyframes[animationState])}}`;
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
function printKeyFrames(blocks) {
|
|
15
|
+
let keyframes = '';
|
|
16
|
+
for (const block of blocks){
|
|
17
|
+
keyframes += `@keyframes ${block.id}{${keyframesToBlock(block.rule)}}`;
|
|
18
|
+
}
|
|
19
|
+
return keyframes;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.printKeyFrames = printKeyFrames;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { declarationsToBlock } from '../helpers/declarationsToBlock.mjs';
|
|
2
|
+
import '../helpers/hypenateProperty.mjs';
|
|
3
|
+
|
|
4
|
+
// https://github.com/styletron/styletron/blob/master/packages/styletron-engine-atomic/src/css.ts#L48
|
|
5
|
+
function keyframesToBlock(keyframes) {
|
|
6
|
+
let result = "";
|
|
7
|
+
for(const animationState in keyframes){
|
|
8
|
+
result += `${animationState}{${declarationsToBlock(keyframes[animationState])}}`;
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
function printKeyFrames(blocks) {
|
|
13
|
+
let keyframes = '';
|
|
14
|
+
for (const block of blocks){
|
|
15
|
+
keyframes += `@keyframes ${block.id}{${keyframesToBlock(block.rule)}}`;
|
|
16
|
+
}
|
|
17
|
+
return keyframes;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { printKeyFrames };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var sourceMap = require('source-map');
|
|
4
|
+
|
|
5
|
+
function printSourceMap(sourceMapReferences, content) {
|
|
6
|
+
if (content.length === 0) {
|
|
7
|
+
return content;
|
|
8
|
+
}
|
|
9
|
+
const entries = Object.entries(sourceMapReferences);
|
|
10
|
+
if (entries.length === 0) {
|
|
11
|
+
return content;
|
|
12
|
+
}
|
|
13
|
+
const sourceMap$1 = new sourceMap.SourceMapGenerator({
|
|
14
|
+
file: "navita.css",
|
|
15
|
+
skipValidation: true
|
|
16
|
+
});
|
|
17
|
+
const references = entries.flatMap(([filePath, references])=>references.map((reference)=>({
|
|
18
|
+
filePath,
|
|
19
|
+
...reference
|
|
20
|
+
})));
|
|
21
|
+
for (const reference of references){
|
|
22
|
+
const { filePath , selector , line , column } = reference;
|
|
23
|
+
const generatedColumn = content.length - 1;
|
|
24
|
+
content += `${selector}{/* Only used for sourceMap */}`;
|
|
25
|
+
sourceMap$1.addMapping({
|
|
26
|
+
source: filePath,
|
|
27
|
+
original: {
|
|
28
|
+
line,
|
|
29
|
+
column
|
|
30
|
+
},
|
|
31
|
+
generated: {
|
|
32
|
+
line: 1,
|
|
33
|
+
column: generatedColumn
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const sourceMapContent = Buffer.from(sourceMap$1.toString()).toString('base64');
|
|
38
|
+
content += `\n/*# sourceMappingURL=data:application/json;base64,${sourceMapContent} */`;
|
|
39
|
+
return content;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.printSourceMap = printSourceMap;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { SourceMapGenerator } from 'source-map';
|
|
2
|
+
|
|
3
|
+
function printSourceMap(sourceMapReferences, content) {
|
|
4
|
+
if (content.length === 0) {
|
|
5
|
+
return content;
|
|
6
|
+
}
|
|
7
|
+
const entries = Object.entries(sourceMapReferences);
|
|
8
|
+
if (entries.length === 0) {
|
|
9
|
+
return content;
|
|
10
|
+
}
|
|
11
|
+
const sourceMap = new SourceMapGenerator({
|
|
12
|
+
file: "navita.css",
|
|
13
|
+
skipValidation: true
|
|
14
|
+
});
|
|
15
|
+
const references = entries.flatMap(([filePath, references])=>references.map((reference)=>({
|
|
16
|
+
filePath,
|
|
17
|
+
...reference
|
|
18
|
+
})));
|
|
19
|
+
for (const reference of references){
|
|
20
|
+
const { filePath , selector , line , column } = reference;
|
|
21
|
+
const generatedColumn = content.length - 1;
|
|
22
|
+
content += `${selector}{/* Only used for sourceMap */}`;
|
|
23
|
+
sourceMap.addMapping({
|
|
24
|
+
source: filePath,
|
|
25
|
+
original: {
|
|
26
|
+
line,
|
|
27
|
+
column
|
|
28
|
+
},
|
|
29
|
+
generated: {
|
|
30
|
+
line: 1,
|
|
31
|
+
column: generatedColumn
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const sourceMapContent = Buffer.from(sourceMap.toString()).toString('base64');
|
|
36
|
+
content += `\n/*# sourceMappingURL=data:application/json;base64,${sourceMapContent} */`;
|
|
37
|
+
return content;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { printSourceMap };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var helpers_getPropertyPriority = require('../helpers/getPropertyPriority.cjs');
|
|
4
|
+
|
|
5
|
+
function printStyleBlocks(blocks) {
|
|
6
|
+
let stylesheet = '';
|
|
7
|
+
let previousStyle;
|
|
8
|
+
for (const style of blocks){
|
|
9
|
+
if (style.type === 'static' && previousStyle && (previousStyle.selector !== style.selector || previousStyle.pseudo !== style.pseudo || previousStyle.media !== style.media || previousStyle.support !== style.support)) {
|
|
10
|
+
stylesheet += '}';
|
|
11
|
+
}
|
|
12
|
+
// Close support queries:
|
|
13
|
+
// 1. When the current style is not a support query, and the previous style was support query
|
|
14
|
+
// 2. When the current style is a support query and the previous style was a support query with a different support query
|
|
15
|
+
if (previousStyle && previousStyle.support && (!style.support || style.support !== previousStyle.support)) {
|
|
16
|
+
stylesheet += '}';
|
|
17
|
+
}
|
|
18
|
+
// Close media queries:
|
|
19
|
+
// 1. When the current style is not a media query, and the previous style was media query
|
|
20
|
+
// 2. When the current style is a media query and the previous style was a media query with a different media query
|
|
21
|
+
if (previousStyle && previousStyle.media && (!style.media || style.media !== previousStyle.media)) {
|
|
22
|
+
stylesheet += '}';
|
|
23
|
+
}
|
|
24
|
+
// Only add media queries if the previous style was not the same media query
|
|
25
|
+
if (style.media && previousStyle?.media !== style.media) {
|
|
26
|
+
stylesheet += `@media ${style.media}{`;
|
|
27
|
+
}
|
|
28
|
+
// Only add support queries if the previous style was not the same support query
|
|
29
|
+
if (style.support && previousStyle?.support !== style.support) {
|
|
30
|
+
stylesheet += `@supports ${style.support}{`;
|
|
31
|
+
}
|
|
32
|
+
if (style.type === 'rule') {
|
|
33
|
+
const className = `.${style.id}`.repeat(helpers_getPropertyPriority.getPropertyPriority(style.property));
|
|
34
|
+
stylesheet += `${className}${style.pseudo}{`;
|
|
35
|
+
} else if (style.type === 'static' && (previousStyle?.selector !== style.selector || previousStyle?.pseudo !== style.pseudo || previousStyle?.media !== style.media || previousStyle?.support !== style.support)) {
|
|
36
|
+
// If static, we don't add pseudo selectors currently
|
|
37
|
+
stylesheet += `${style.selector}${style.pseudo}{`;
|
|
38
|
+
}
|
|
39
|
+
stylesheet += `${style.property}:${style.value}`;
|
|
40
|
+
if (style.type === 'static') {
|
|
41
|
+
stylesheet += ';';
|
|
42
|
+
}
|
|
43
|
+
if (style.type === 'rule') {
|
|
44
|
+
stylesheet += '}';
|
|
45
|
+
}
|
|
46
|
+
previousStyle = style;
|
|
47
|
+
}
|
|
48
|
+
if (previousStyle?.support) {
|
|
49
|
+
stylesheet += '}';
|
|
50
|
+
}
|
|
51
|
+
if (previousStyle?.media) {
|
|
52
|
+
stylesheet += '}';
|
|
53
|
+
}
|
|
54
|
+
if (previousStyle?.type === 'static') {
|
|
55
|
+
stylesheet += '}';
|
|
56
|
+
}
|
|
57
|
+
return stylesheet;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.printStyleBlocks = printStyleBlocks;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getPropertyPriority } from '../helpers/getPropertyPriority.mjs';
|
|
2
|
+
|
|
3
|
+
function printStyleBlocks(blocks) {
|
|
4
|
+
let stylesheet = '';
|
|
5
|
+
let previousStyle;
|
|
6
|
+
for (const style of blocks){
|
|
7
|
+
if (style.type === 'static' && previousStyle && (previousStyle.selector !== style.selector || previousStyle.pseudo !== style.pseudo || previousStyle.media !== style.media || previousStyle.support !== style.support)) {
|
|
8
|
+
stylesheet += '}';
|
|
9
|
+
}
|
|
10
|
+
// Close support queries:
|
|
11
|
+
// 1. When the current style is not a support query, and the previous style was support query
|
|
12
|
+
// 2. When the current style is a support query and the previous style was a support query with a different support query
|
|
13
|
+
if (previousStyle && previousStyle.support && (!style.support || style.support !== previousStyle.support)) {
|
|
14
|
+
stylesheet += '}';
|
|
15
|
+
}
|
|
16
|
+
// Close media queries:
|
|
17
|
+
// 1. When the current style is not a media query, and the previous style was media query
|
|
18
|
+
// 2. When the current style is a media query and the previous style was a media query with a different media query
|
|
19
|
+
if (previousStyle && previousStyle.media && (!style.media || style.media !== previousStyle.media)) {
|
|
20
|
+
stylesheet += '}';
|
|
21
|
+
}
|
|
22
|
+
// Only add media queries if the previous style was not the same media query
|
|
23
|
+
if (style.media && previousStyle?.media !== style.media) {
|
|
24
|
+
stylesheet += `@media ${style.media}{`;
|
|
25
|
+
}
|
|
26
|
+
// Only add support queries if the previous style was not the same support query
|
|
27
|
+
if (style.support && previousStyle?.support !== style.support) {
|
|
28
|
+
stylesheet += `@supports ${style.support}{`;
|
|
29
|
+
}
|
|
30
|
+
if (style.type === 'rule') {
|
|
31
|
+
const className = `.${style.id}`.repeat(getPropertyPriority(style.property));
|
|
32
|
+
stylesheet += `${className}${style.pseudo}{`;
|
|
33
|
+
} else if (style.type === 'static' && (previousStyle?.selector !== style.selector || previousStyle?.pseudo !== style.pseudo || previousStyle?.media !== style.media || previousStyle?.support !== style.support)) {
|
|
34
|
+
// If static, we don't add pseudo selectors currently
|
|
35
|
+
stylesheet += `${style.selector}${style.pseudo}{`;
|
|
36
|
+
}
|
|
37
|
+
stylesheet += `${style.property}:${style.value}`;
|
|
38
|
+
if (style.type === 'static') {
|
|
39
|
+
stylesheet += ';';
|
|
40
|
+
}
|
|
41
|
+
if (style.type === 'rule') {
|
|
42
|
+
stylesheet += '}';
|
|
43
|
+
}
|
|
44
|
+
previousStyle = style;
|
|
45
|
+
}
|
|
46
|
+
if (previousStyle?.support) {
|
|
47
|
+
stylesheet += '}';
|
|
48
|
+
}
|
|
49
|
+
if (previousStyle?.media) {
|
|
50
|
+
stylesheet += '}';
|
|
51
|
+
}
|
|
52
|
+
if (previousStyle?.type === 'static') {
|
|
53
|
+
stylesheet += '}';
|
|
54
|
+
}
|
|
55
|
+
return stylesheet;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { printStyleBlocks };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var createSort = require('sort-css-media-queries/lib/create-sort.js');
|
|
4
|
+
|
|
5
|
+
const sortCSSMediaQueries = createSort();
|
|
6
|
+
function sortAtRules(blocks) {
|
|
7
|
+
return blocks.sort((a, b)=>sortCSSMediaQueries(a.media, b.media) || a.support.localeCompare(b.support));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.sortAtRules = sortAtRules;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import createSort from 'sort-css-media-queries/lib/create-sort.js';
|
|
2
|
+
|
|
3
|
+
const sortCSSMediaQueries = createSort();
|
|
4
|
+
function sortAtRules(blocks) {
|
|
5
|
+
return blocks.sort((a, b)=>sortCSSMediaQueries(a.media, b.media) || a.support.localeCompare(b.support));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { sortAtRules };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var helpers_generateCombinedAtRules = require('./helpers/generateCombinedAtRules.cjs');
|
|
4
|
+
var helpers_hypenateProperty = require('./helpers/hypenateProperty.cjs');
|
|
5
|
+
var helpers_isMediaQuery = require('./helpers/isMediaQuery.cjs');
|
|
6
|
+
var helpers_isNestedSelector = require('./helpers/isNestedSelector.cjs');
|
|
7
|
+
var helpers_isObject = require('./helpers/isObject.cjs');
|
|
8
|
+
var helpers_isSupportsQuery = require('./helpers/isSupportsQuery.cjs');
|
|
9
|
+
var helpers_normalizeCSSVarsProperty = require('./helpers/normalizeCSSVarsProperty.cjs');
|
|
10
|
+
var helpers_normalizeNestedProperty = require('./helpers/normalizeNestedProperty.cjs');
|
|
11
|
+
var helpers_pixelifyProperties = require('./helpers/pixelifyProperties.cjs');
|
|
12
|
+
var helpers_transformContentProperty = require('./helpers/transformContentProperty.cjs');
|
|
13
|
+
|
|
14
|
+
const transformValuePropertyMap = {
|
|
15
|
+
content: helpers_transformContentProperty.transformContentProperty
|
|
16
|
+
};
|
|
17
|
+
function processStyles({ cache , type }) {
|
|
18
|
+
return function process({ styles , pseudo ="" , media ="" , support ="" , selector ="" }) {
|
|
19
|
+
const result = [];
|
|
20
|
+
for (const [property, value] of Object.entries(styles)){
|
|
21
|
+
if (helpers_isObject.isObject(value)) {
|
|
22
|
+
if (helpers_isMediaQuery.isMediaQuery(property)) {
|
|
23
|
+
const combinedMedia = helpers_generateCombinedAtRules.generateCombinedAtRules(media, property.slice(6).trim());
|
|
24
|
+
result.push(...process({
|
|
25
|
+
styles: value,
|
|
26
|
+
pseudo,
|
|
27
|
+
media: combinedMedia,
|
|
28
|
+
support,
|
|
29
|
+
selector
|
|
30
|
+
}));
|
|
31
|
+
} else if (helpers_isSupportsQuery.isSupportsQuery(property)) {
|
|
32
|
+
const combinedSupport = helpers_generateCombinedAtRules.generateCombinedAtRules(support, property.slice(9).trim());
|
|
33
|
+
result.push(...process({
|
|
34
|
+
styles: value,
|
|
35
|
+
pseudo,
|
|
36
|
+
media,
|
|
37
|
+
support: combinedSupport,
|
|
38
|
+
selector
|
|
39
|
+
}));
|
|
40
|
+
} else if (helpers_isNestedSelector.isNestedSelector(property)) {
|
|
41
|
+
// This is only allowed in simple pseudos currently.
|
|
42
|
+
const copies = property.split(',').map((p)=>p.trim());
|
|
43
|
+
for (const copy of copies){
|
|
44
|
+
result.push(...process({
|
|
45
|
+
styles: value,
|
|
46
|
+
pseudo: pseudo + helpers_normalizeNestedProperty.normalizeNestedProperty(copy),
|
|
47
|
+
media,
|
|
48
|
+
support,
|
|
49
|
+
selector
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
console.warn("Unknown property", property);
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
let newProperty = helpers_normalizeCSSVarsProperty.normalizeCSSVarsProperty(property);
|
|
57
|
+
let newValue = value;
|
|
58
|
+
if (typeof value === "string") {
|
|
59
|
+
newValue = value.trim().replace(/;[\n\s]*$/, "");
|
|
60
|
+
}
|
|
61
|
+
// Check if value starts with --, if so, wrap in var()
|
|
62
|
+
if (typeof newValue === "string" && newValue.startsWith("--")) {
|
|
63
|
+
newValue = `var(${value})`;
|
|
64
|
+
}
|
|
65
|
+
if (typeof value === "number") {
|
|
66
|
+
newValue = helpers_pixelifyProperties.pixelifyProperties(newProperty, value);
|
|
67
|
+
}
|
|
68
|
+
if (transformValuePropertyMap[newProperty]) {
|
|
69
|
+
newValue = transformValuePropertyMap[newProperty](value);
|
|
70
|
+
}
|
|
71
|
+
newProperty = helpers_hypenateProperty.hyphenateProperty(newProperty);
|
|
72
|
+
// Remove trailing semicolon and new lines with regex
|
|
73
|
+
result.push(cache.getOrStore({
|
|
74
|
+
type,
|
|
75
|
+
selector,
|
|
76
|
+
property: newProperty,
|
|
77
|
+
value: newValue,
|
|
78
|
+
pseudo,
|
|
79
|
+
media,
|
|
80
|
+
support
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exports.processStyles = processStyles;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { generateCombinedAtRules } from './helpers/generateCombinedAtRules.mjs';
|
|
2
|
+
import { hyphenateProperty } from './helpers/hypenateProperty.mjs';
|
|
3
|
+
import { isMediaQuery } from './helpers/isMediaQuery.mjs';
|
|
4
|
+
import { isNestedSelector } from './helpers/isNestedSelector.mjs';
|
|
5
|
+
import { isObject } from './helpers/isObject.mjs';
|
|
6
|
+
import { isSupportsQuery } from './helpers/isSupportsQuery.mjs';
|
|
7
|
+
import { normalizeCSSVarsProperty } from './helpers/normalizeCSSVarsProperty.mjs';
|
|
8
|
+
import { normalizeNestedProperty } from './helpers/normalizeNestedProperty.mjs';
|
|
9
|
+
import { pixelifyProperties } from './helpers/pixelifyProperties.mjs';
|
|
10
|
+
import { transformContentProperty } from './helpers/transformContentProperty.mjs';
|
|
11
|
+
|
|
12
|
+
const transformValuePropertyMap = {
|
|
13
|
+
content: transformContentProperty
|
|
14
|
+
};
|
|
15
|
+
function processStyles({ cache , type }) {
|
|
16
|
+
return function process({ styles , pseudo ="" , media ="" , support ="" , selector ="" }) {
|
|
17
|
+
const result = [];
|
|
18
|
+
for (const [property, value] of Object.entries(styles)){
|
|
19
|
+
if (isObject(value)) {
|
|
20
|
+
if (isMediaQuery(property)) {
|
|
21
|
+
const combinedMedia = generateCombinedAtRules(media, property.slice(6).trim());
|
|
22
|
+
result.push(...process({
|
|
23
|
+
styles: value,
|
|
24
|
+
pseudo,
|
|
25
|
+
media: combinedMedia,
|
|
26
|
+
support,
|
|
27
|
+
selector
|
|
28
|
+
}));
|
|
29
|
+
} else if (isSupportsQuery(property)) {
|
|
30
|
+
const combinedSupport = generateCombinedAtRules(support, property.slice(9).trim());
|
|
31
|
+
result.push(...process({
|
|
32
|
+
styles: value,
|
|
33
|
+
pseudo,
|
|
34
|
+
media,
|
|
35
|
+
support: combinedSupport,
|
|
36
|
+
selector
|
|
37
|
+
}));
|
|
38
|
+
} else if (isNestedSelector(property)) {
|
|
39
|
+
// This is only allowed in simple pseudos currently.
|
|
40
|
+
const copies = property.split(',').map((p)=>p.trim());
|
|
41
|
+
for (const copy of copies){
|
|
42
|
+
result.push(...process({
|
|
43
|
+
styles: value,
|
|
44
|
+
pseudo: pseudo + normalizeNestedProperty(copy),
|
|
45
|
+
media,
|
|
46
|
+
support,
|
|
47
|
+
selector
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
console.warn("Unknown property", property);
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
let newProperty = normalizeCSSVarsProperty(property);
|
|
55
|
+
let newValue = value;
|
|
56
|
+
if (typeof value === "string") {
|
|
57
|
+
newValue = value.trim().replace(/;[\n\s]*$/, "");
|
|
58
|
+
}
|
|
59
|
+
// Check if value starts with --, if so, wrap in var()
|
|
60
|
+
if (typeof newValue === "string" && newValue.startsWith("--")) {
|
|
61
|
+
newValue = `var(${value})`;
|
|
62
|
+
}
|
|
63
|
+
if (typeof value === "number") {
|
|
64
|
+
newValue = pixelifyProperties(newProperty, value);
|
|
65
|
+
}
|
|
66
|
+
if (transformValuePropertyMap[newProperty]) {
|
|
67
|
+
newValue = transformValuePropertyMap[newProperty](value);
|
|
68
|
+
}
|
|
69
|
+
newProperty = hyphenateProperty(newProperty);
|
|
70
|
+
// Remove trailing semicolon and new lines with regex
|
|
71
|
+
result.push(cache.getOrStore({
|
|
72
|
+
type,
|
|
73
|
+
selector,
|
|
74
|
+
property: newProperty,
|
|
75
|
+
value: newValue,
|
|
76
|
+
pseudo,
|
|
77
|
+
media,
|
|
78
|
+
support
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { processStyles };
|
package/types.cjs
ADDED
package/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|