@master/css 2.0.0-rc.68 → 2.0.0-rc.69
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/common.cjs +0 -2
- package/dist/common.d.ts +0 -1
- package/dist/common.mjs +1 -2
- package/dist/config/functions.cjs +9 -243
- package/dist/config/functions.d.ts +137 -2
- package/dist/config/functions.mjs +9 -243
- package/dist/config/index.cjs +2 -2
- package/dist/config/index.mjs +2 -2
- package/dist/config/modes.cjs +307 -3
- package/dist/config/modes.d.ts +306 -2
- package/dist/config/modes.mjs +307 -3
- package/dist/config/rules.cjs +740 -782
- package/dist/config/rules.d.ts +692 -683
- package/dist/config/rules.mjs +741 -783
- package/dist/config/utilities.cjs +328 -97
- package/dist/config/utilities.d.ts +247 -16
- package/dist/config/utilities.mjs +328 -97
- package/dist/config/variables.cjs +88 -460
- package/dist/config/variables.d.ts +358 -369
- package/dist/config/variables.mjs +88 -460
- package/dist/core.cjs +234 -234
- package/dist/core.d.ts +5 -3
- package/dist/core.mjs +234 -234
- package/dist/create.cjs +10 -0
- package/dist/create.d.ts +3 -0
- package/dist/create.mjs +8 -0
- package/dist/declarers/core.group.cjs +99 -0
- package/dist/declarers/core.group.d.ts +2 -0
- package/dist/declarers/core.group.mjs +97 -0
- package/dist/declarers/core.variable.cjs +9 -0
- package/dist/declarers/core.variable.d.ts +4 -0
- package/dist/declarers/core.variable.mjs +7 -0
- package/dist/declarers/index.cjs +13 -0
- package/dist/declarers/index.d.ts +10 -0
- package/dist/declarers/index.mjs +11 -0
- package/dist/declarers/pair.cjs +12 -0
- package/dist/declarers/pair.d.ts +4 -0
- package/dist/declarers/pair.mjs +10 -0
- package/dist/factories/with-syntax-layer.cjs +0 -2
- package/dist/factories/with-syntax-layer.mjs +0 -2
- package/dist/function-transformers/core.calc.cjs +225 -0
- package/dist/function-transformers/core.calc.d.ts +2 -0
- package/dist/function-transformers/core.calc.mjs +223 -0
- package/dist/function-transformers/core.variable.cjs +23 -0
- package/dist/function-transformers/core.variable.d.ts +7 -0
- package/dist/function-transformers/core.variable.mjs +21 -0
- package/dist/function-transformers/index.cjs +11 -0
- package/dist/function-transformers/index.d.ts +8 -0
- package/dist/function-transformers/index.mjs +9 -0
- package/dist/index.cjs +10 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.mjs +6 -1
- package/dist/layer.cjs +2 -4
- package/dist/layer.mjs +2 -4
- package/dist/non-layer.cjs +2 -4
- package/dist/non-layer.mjs +2 -4
- package/dist/syntax-rule-type.cjs +8 -7
- package/dist/syntax-rule-type.d.ts +7 -7
- package/dist/syntax-rule-type.mjs +8 -7
- package/dist/syntax-rule.cjs +305 -258
- package/dist/syntax-rule.d.ts +2 -2
- package/dist/syntax-rule.mjs +306 -259
- package/dist/{utils/autofill-solid-style.cjs → transformers/auto-fill-solid.cjs} +3 -3
- package/dist/transformers/auto-fill-solid.d.ts +2 -0
- package/dist/{utils/autofill-solid-style.mjs → transformers/auto-fill-solid.mjs} +3 -3
- package/dist/transformers/index.cjs +9 -0
- package/dist/transformers/index.d.ts +6 -0
- package/dist/transformers/index.mjs +7 -0
- package/dist/types/common.d.ts +0 -2
- package/dist/types/config.d.ts +24 -20
- package/dist/types/syntax.d.ts +10 -8
- package/dist/utils/equal-selectors.cjs +1 -2
- package/dist/utils/equal-selectors.mjs +1 -2
- package/dist/utils/extend-config.cjs +83 -44
- package/dist/utils/extend-config.d.ts +10 -1
- package/dist/utils/extend-config.mjs +83 -44
- package/dist/utils/flatten-meta-object.cjs +38 -0
- package/dist/utils/flatten-meta-object.d.ts +13 -0
- package/dist/utils/flatten-meta-object.mjs +36 -0
- package/dist/utils/flatten-object.cjs +13 -9
- package/dist/utils/flatten-object.d.ts +1 -1
- package/dist/utils/flatten-object.mjs +13 -9
- package/dist/utils/generate-css.cjs +2 -2
- package/dist/utils/generate-css.d.ts +1 -2
- package/dist/utils/generate-css.mjs +2 -2
- package/dist/utils/minify-extended-config.cjs +64 -0
- package/dist/utils/minify-extended-config.d.ts +9 -0
- package/dist/utils/minify-extended-config.mjs +62 -0
- package/dist/utils/nest-meta-object.cjs +25 -0
- package/dist/utils/nest-meta-object.d.ts +7 -0
- package/dist/utils/nest-meta-object.mjs +23 -0
- package/dist/utils/parse-at.cjs +1 -2
- package/dist/utils/parse-at.d.ts +2 -2
- package/dist/utils/parse-at.mjs +1 -2
- package/dist/utils/parse-pair.cjs +3 -6
- package/dist/utils/parse-pair.mjs +3 -6
- package/dist/utils/parse-selector.cjs +2 -4
- package/dist/utils/parse-selector.d.ts +2 -2
- package/dist/utils/parse-selector.mjs +2 -4
- package/dist/utils/sort-readable-classes.cjs +2 -2
- package/dist/utils/sort-readable-classes.d.ts +1 -2
- package/dist/utils/sort-readable-classes.mjs +2 -2
- package/dist/variable-rule.cjs +35 -29
- package/dist/variable-rule.d.ts +16 -6
- package/dist/variable-rule.mjs +35 -29
- package/package.json +1 -1
- package/dist/utils/autofill-solid-style.d.ts +0 -3
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cssEscape = require('../shared/utils/css-escape.cjs');
|
|
4
|
+
var common = require('../common.cjs');
|
|
5
|
+
|
|
6
|
+
function coreGroup(value) {
|
|
7
|
+
const declarations = {};
|
|
8
|
+
const addProp = (propertyName)=>{
|
|
9
|
+
const indexOfColon = propertyName.indexOf(':');
|
|
10
|
+
if (indexOfColon !== -1) {
|
|
11
|
+
const propName = propertyName.slice(0, indexOfColon);
|
|
12
|
+
declarations[propName] = propertyName.slice(indexOfColon + 1);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const handleRule = (rule)=>{
|
|
16
|
+
const addProps = (cssText)=>{
|
|
17
|
+
const cssProperties = cssText.slice(cssEscape(rule.name).length).match(/\{(.*)\}/)?.[1].split(';');
|
|
18
|
+
if (cssProperties) for (const eachCssProperty of cssProperties){
|
|
19
|
+
addProp(eachCssProperty);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
addProps(rule.text);
|
|
23
|
+
// animation
|
|
24
|
+
if (rule.animationNames) {
|
|
25
|
+
if (!this.animationNames) {
|
|
26
|
+
this.animationNames = new Set();
|
|
27
|
+
}
|
|
28
|
+
for (const eachKeyframeName of rule.animationNames){
|
|
29
|
+
this.animationNames.add(eachKeyframeName);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// variable
|
|
33
|
+
if (rule.variableNames) {
|
|
34
|
+
if (this.variableNames) {
|
|
35
|
+
for (const eachVariableName of rule.variableNames){
|
|
36
|
+
this.variableNames.add(eachVariableName);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
this.variableNames = new Set(rule.variableNames);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const names = [];
|
|
44
|
+
let currentName = '';
|
|
45
|
+
const addName = ()=>{
|
|
46
|
+
if (currentName) {
|
|
47
|
+
names.push(currentName.replace(/ /g, '|'));
|
|
48
|
+
currentName = '';
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
let i = 1;
|
|
52
|
+
(function analyze(end) {
|
|
53
|
+
for(; i < value.length; i++){
|
|
54
|
+
const char = value[i];
|
|
55
|
+
if (!end) {
|
|
56
|
+
if (char === ';') {
|
|
57
|
+
addName();
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (char === '}') {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
currentName += char;
|
|
65
|
+
if (end === char) {
|
|
66
|
+
if (end === '\'' || end === '"') {
|
|
67
|
+
let count = 0;
|
|
68
|
+
for(let j = currentName.length - 2;; j--){
|
|
69
|
+
if (currentName[j] !== '\\') {
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
count++;
|
|
73
|
+
}
|
|
74
|
+
if (count % 2) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
} else if (char in common.VALUE_DELIMITERS && end !== '\'' && end !== '"') {
|
|
80
|
+
i++;
|
|
81
|
+
analyze(common.VALUE_DELIMITERS[char]);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
})('');
|
|
85
|
+
addName();
|
|
86
|
+
for (const eachName of names){
|
|
87
|
+
const rules = this.css.generate(eachName, this.mode);
|
|
88
|
+
if (rules.length) {
|
|
89
|
+
for (const eachRule of rules){
|
|
90
|
+
handleRule(eachRule);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
addProp(eachName);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return declarations;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = coreGroup;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import cssEscape from '../shared/utils/css-escape.mjs';
|
|
2
|
+
import { VALUE_DELIMITERS } from '../common.mjs';
|
|
3
|
+
|
|
4
|
+
function coreGroup(value) {
|
|
5
|
+
const declarations = {};
|
|
6
|
+
const addProp = (propertyName)=>{
|
|
7
|
+
const indexOfColon = propertyName.indexOf(':');
|
|
8
|
+
if (indexOfColon !== -1) {
|
|
9
|
+
const propName = propertyName.slice(0, indexOfColon);
|
|
10
|
+
declarations[propName] = propertyName.slice(indexOfColon + 1);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const handleRule = (rule)=>{
|
|
14
|
+
const addProps = (cssText)=>{
|
|
15
|
+
const cssProperties = cssText.slice(cssEscape(rule.name).length).match(/\{(.*)\}/)?.[1].split(';');
|
|
16
|
+
if (cssProperties) for (const eachCssProperty of cssProperties){
|
|
17
|
+
addProp(eachCssProperty);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
addProps(rule.text);
|
|
21
|
+
// animation
|
|
22
|
+
if (rule.animationNames) {
|
|
23
|
+
if (!this.animationNames) {
|
|
24
|
+
this.animationNames = new Set();
|
|
25
|
+
}
|
|
26
|
+
for (const eachKeyframeName of rule.animationNames){
|
|
27
|
+
this.animationNames.add(eachKeyframeName);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// variable
|
|
31
|
+
if (rule.variableNames) {
|
|
32
|
+
if (this.variableNames) {
|
|
33
|
+
for (const eachVariableName of rule.variableNames){
|
|
34
|
+
this.variableNames.add(eachVariableName);
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
this.variableNames = new Set(rule.variableNames);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const names = [];
|
|
42
|
+
let currentName = '';
|
|
43
|
+
const addName = ()=>{
|
|
44
|
+
if (currentName) {
|
|
45
|
+
names.push(currentName.replace(/ /g, '|'));
|
|
46
|
+
currentName = '';
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
let i = 1;
|
|
50
|
+
(function analyze(end) {
|
|
51
|
+
for(; i < value.length; i++){
|
|
52
|
+
const char = value[i];
|
|
53
|
+
if (!end) {
|
|
54
|
+
if (char === ';') {
|
|
55
|
+
addName();
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (char === '}') {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
currentName += char;
|
|
63
|
+
if (end === char) {
|
|
64
|
+
if (end === '\'' || end === '"') {
|
|
65
|
+
let count = 0;
|
|
66
|
+
for(let j = currentName.length - 2;; j--){
|
|
67
|
+
if (currentName[j] !== '\\') {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
count++;
|
|
71
|
+
}
|
|
72
|
+
if (count % 2) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
} else if (char in VALUE_DELIMITERS && end !== '\'' && end !== '"') {
|
|
78
|
+
i++;
|
|
79
|
+
analyze(VALUE_DELIMITERS[char]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})('');
|
|
83
|
+
addName();
|
|
84
|
+
for (const eachName of names){
|
|
85
|
+
const rules = this.css.generate(eachName, this.mode);
|
|
86
|
+
if (rules.length) {
|
|
87
|
+
for (const eachRule of rules){
|
|
88
|
+
handleRule(eachRule);
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
addProp(eachName);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return declarations;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { coreGroup as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core_group = require('./core.group.cjs');
|
|
4
|
+
var core_variable = require('./core.variable.cjs');
|
|
5
|
+
var pair = require('./pair.cjs');
|
|
6
|
+
|
|
7
|
+
const declarers = {
|
|
8
|
+
pair,
|
|
9
|
+
'core.group': core_group,
|
|
10
|
+
'core.variable': core_variable
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
module.exports = declarers;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import coreGroup from './core.group';
|
|
2
|
+
import coreVariable from './core.variable';
|
|
3
|
+
import pair from './pair';
|
|
4
|
+
declare const declarers: {
|
|
5
|
+
pair: typeof pair;
|
|
6
|
+
'core.group': typeof coreGroup;
|
|
7
|
+
'core.variable': typeof coreVariable;
|
|
8
|
+
};
|
|
9
|
+
export default declarers;
|
|
10
|
+
export type DeclarerNames = keyof typeof declarers;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import coreGroup from './core.group.mjs';
|
|
2
|
+
import coreVariable from './core.variable.mjs';
|
|
3
|
+
import pair from './pair.mjs';
|
|
4
|
+
|
|
5
|
+
const declarers = {
|
|
6
|
+
pair,
|
|
7
|
+
'core.group': coreGroup,
|
|
8
|
+
'core.variable': coreVariable
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { declarers as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function pair(_, valueComponents, data) {
|
|
4
|
+
const [x, y] = data;
|
|
5
|
+
const length = valueComponents.length;
|
|
6
|
+
return {
|
|
7
|
+
[x]: length === 1 ? valueComponents[0].text : valueComponents[0].text,
|
|
8
|
+
[y]: length === 1 ? valueComponents[0].text : valueComponents[2].text
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = pair;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function pair(_, valueComponents, data) {
|
|
2
|
+
const [x, y] = data;
|
|
3
|
+
const length = valueComponents.length;
|
|
4
|
+
return {
|
|
5
|
+
[x]: length === 1 ? valueComponents[0].text : valueComponents[0].text,
|
|
6
|
+
[y]: length === 1 ? valueComponents[0].text : valueComponents[2].text
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { pair as default };
|
|
@@ -27,7 +27,6 @@ function withSyntaxLayer(Base) {
|
|
|
27
27
|
super.insert(syntaxRule, index);
|
|
28
28
|
this.insertVariables(syntaxRule);
|
|
29
29
|
this.insertAnimations(syntaxRule);
|
|
30
|
-
syntaxRule.definition.insert?.call(syntaxRule);
|
|
31
30
|
return index;
|
|
32
31
|
}
|
|
33
32
|
delete(key) {
|
|
@@ -48,7 +47,6 @@ function withSyntaxLayer(Base) {
|
|
|
48
47
|
syntaxRule.animationNames?.forEach((eachAnimationName)=>{
|
|
49
48
|
deleteLayerToken(eachAnimationName, this.css.animationsNonLayer);
|
|
50
49
|
});
|
|
51
|
-
syntaxRule.definition.delete?.call(syntaxRule, syntaxRule.name);
|
|
52
50
|
return syntaxRule;
|
|
53
51
|
}
|
|
54
52
|
insertVariables(syntaxRule) {
|
|
@@ -25,7 +25,6 @@ function withSyntaxLayer(Base) {
|
|
|
25
25
|
super.insert(syntaxRule, index);
|
|
26
26
|
this.insertVariables(syntaxRule);
|
|
27
27
|
this.insertAnimations(syntaxRule);
|
|
28
|
-
syntaxRule.definition.insert?.call(syntaxRule);
|
|
29
28
|
return index;
|
|
30
29
|
}
|
|
31
30
|
delete(key) {
|
|
@@ -46,7 +45,6 @@ function withSyntaxLayer(Base) {
|
|
|
46
45
|
syntaxRule.animationNames?.forEach((eachAnimationName)=>{
|
|
47
46
|
deleteLayerToken(eachAnimationName, this.css.animationsNonLayer);
|
|
48
47
|
});
|
|
49
|
-
syntaxRule.definition.delete?.call(syntaxRule, syntaxRule.name);
|
|
50
48
|
return syntaxRule;
|
|
51
49
|
}
|
|
52
50
|
insertVariables(syntaxRule) {
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var functions = require('../config/functions.cjs');
|
|
4
|
+
var common = require('../common.cjs');
|
|
5
|
+
|
|
6
|
+
function coreCalc(value, bypassVariableNames) {
|
|
7
|
+
const valueComponents = [];
|
|
8
|
+
let i = 0;
|
|
9
|
+
const anaylzeDeeply = (currentValueComponents, bypassHandlingSeparator, parentBypassParsing, parentUnitChecking, isVarFunction)=>{
|
|
10
|
+
const isChildHandler = valueComponents !== currentValueComponents;
|
|
11
|
+
const unparsedValueComponents = [];
|
|
12
|
+
let bypassParsing = false;
|
|
13
|
+
let hasUnit = false;
|
|
14
|
+
let currentHasUnit = false;
|
|
15
|
+
let unitChecking = false;
|
|
16
|
+
let childHasUnit = undefined;
|
|
17
|
+
let current = '';
|
|
18
|
+
const clear = (separator, prefix = '', suffix = '')=>{
|
|
19
|
+
if (childHasUnit === false && separator !== ' ' && this.definition.unit) {
|
|
20
|
+
childHasUnit = undefined;
|
|
21
|
+
if (!unitChecking) {
|
|
22
|
+
pushUnitValueComponents();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (current) {
|
|
26
|
+
if (!isVarFunction) {
|
|
27
|
+
const result = common.BASE_UNIT_REGEX.exec(current);
|
|
28
|
+
if (result) {
|
|
29
|
+
current = (+result[1] * (this.css.config.baseUnit ?? 1)).toString();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (!bypassParsing && !parentBypassParsing) {
|
|
33
|
+
const valueComponent = {
|
|
34
|
+
...this.parseValue(current),
|
|
35
|
+
token: current
|
|
36
|
+
};
|
|
37
|
+
if (!hasUnit && isNaN(+current) && valueComponent.type === 'number') {
|
|
38
|
+
hasUnit = true;
|
|
39
|
+
}
|
|
40
|
+
if (unitChecking) {
|
|
41
|
+
if (isNaN(+current)) {
|
|
42
|
+
if (valueComponent.type === 'number') {
|
|
43
|
+
currentValueComponents.push(valueComponent);
|
|
44
|
+
currentHasUnit = true;
|
|
45
|
+
} else {
|
|
46
|
+
currentValueComponents.push(valueComponent);
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
currentValueComponents.push({
|
|
50
|
+
type: 'number',
|
|
51
|
+
value: +current,
|
|
52
|
+
token: current
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
if (isChildHandler) {
|
|
57
|
+
const newValueComponent = {
|
|
58
|
+
type: 'string',
|
|
59
|
+
value: current,
|
|
60
|
+
token: current
|
|
61
|
+
};
|
|
62
|
+
unparsedValueComponents.push(newValueComponent);
|
|
63
|
+
currentValueComponents.push(newValueComponent);
|
|
64
|
+
} else {
|
|
65
|
+
currentValueComponents.push(valueComponent);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
currentValueComponents.push({
|
|
70
|
+
type: 'string',
|
|
71
|
+
value: current,
|
|
72
|
+
token: current
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
current = '';
|
|
76
|
+
}
|
|
77
|
+
if (separator) {
|
|
78
|
+
if (separator === '+' || separator === '-') {
|
|
79
|
+
handleUnitChecking();
|
|
80
|
+
}
|
|
81
|
+
if (prefix && value[i - 1] === ' ') {
|
|
82
|
+
prefix = '';
|
|
83
|
+
}
|
|
84
|
+
if (suffix && value[i + 1] === ' ') {
|
|
85
|
+
suffix = '';
|
|
86
|
+
}
|
|
87
|
+
if (bypassHandlingSeparator) {
|
|
88
|
+
currentValueComponents.push({
|
|
89
|
+
type: 'separator',
|
|
90
|
+
value: separator,
|
|
91
|
+
text: separator,
|
|
92
|
+
token: separator
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
currentValueComponents.push({
|
|
96
|
+
type: 'separator',
|
|
97
|
+
value: separator,
|
|
98
|
+
text: prefix + separator + suffix,
|
|
99
|
+
token: separator
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
bypassParsing = false;
|
|
104
|
+
};
|
|
105
|
+
const pushUnitValueComponents = ()=>{
|
|
106
|
+
if (this.definition.unit === 'rem' || this.definition.unit === 'em') {
|
|
107
|
+
currentValueComponents.push({
|
|
108
|
+
type: 'separator',
|
|
109
|
+
value: '/',
|
|
110
|
+
text: ' / ',
|
|
111
|
+
token: '/'
|
|
112
|
+
}, {
|
|
113
|
+
type: 'number',
|
|
114
|
+
value: this.css.config.rootSize,
|
|
115
|
+
token: String(this.css.config.rootSize)
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
currentValueComponents.push({
|
|
119
|
+
type: 'separator',
|
|
120
|
+
value: '*',
|
|
121
|
+
text: ' * ',
|
|
122
|
+
token: '*'
|
|
123
|
+
}, {
|
|
124
|
+
type: 'number',
|
|
125
|
+
value: 1,
|
|
126
|
+
unit: this.definition.unit,
|
|
127
|
+
token: this.definition.unit
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
const handleUnitChecking = ()=>{
|
|
131
|
+
if (unitChecking && !currentHasUnit && !parentUnitChecking && (!isChildHandler || hasUnit)) {
|
|
132
|
+
pushUnitValueComponents();
|
|
133
|
+
}
|
|
134
|
+
unitChecking = false;
|
|
135
|
+
currentHasUnit = false;
|
|
136
|
+
};
|
|
137
|
+
for(; i < value.length; i++){
|
|
138
|
+
const char = value[i];
|
|
139
|
+
if (char === '(') {
|
|
140
|
+
const symbolResult = /^([+-])/.exec(current);
|
|
141
|
+
if (symbolResult) {
|
|
142
|
+
currentValueComponents.push({
|
|
143
|
+
type: 'string',
|
|
144
|
+
value: symbolResult[1],
|
|
145
|
+
token: symbolResult[1]
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const functionName = symbolResult ? current.slice(1) : current;
|
|
149
|
+
const newValueComponent = {
|
|
150
|
+
type: 'function',
|
|
151
|
+
name: functionName,
|
|
152
|
+
symbol: char,
|
|
153
|
+
children: [],
|
|
154
|
+
bypassTransform: functionName === 'calc',
|
|
155
|
+
token: current
|
|
156
|
+
};
|
|
157
|
+
currentValueComponents.push(newValueComponent);
|
|
158
|
+
current = '';
|
|
159
|
+
i++;
|
|
160
|
+
const isVarFunction = functionName === '$' || functionName === 'var';
|
|
161
|
+
childHasUnit = anaylzeDeeply(newValueComponent.children, functionName !== '' && functionName !== 'calc' && (isVarFunction || Object.prototype.hasOwnProperty.call(functions, functionName)), bypassParsing || isVarFunction || unitChecking && currentHasUnit, unitChecking, isVarFunction) || functionName === 'var';
|
|
162
|
+
if (!childHasUnit && functionName === '$') {
|
|
163
|
+
const variableType = this.css.variables.get(newValueComponent.children[0].value)?.type;
|
|
164
|
+
childHasUnit = !variableType || variableType === 'string';
|
|
165
|
+
}
|
|
166
|
+
if (childHasUnit) {
|
|
167
|
+
hasUnit = true;
|
|
168
|
+
currentHasUnit = true;
|
|
169
|
+
}
|
|
170
|
+
} else if (char === ')') {
|
|
171
|
+
clear('');
|
|
172
|
+
if (hasUnit) {
|
|
173
|
+
for (const eachUnparsedValueComponent of unparsedValueComponents){
|
|
174
|
+
Object.assign(eachUnparsedValueComponent, this.parseValue(eachUnparsedValueComponent.value));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return hasUnit;
|
|
178
|
+
} else if (char === ',') {
|
|
179
|
+
clear(char, '', ' ');
|
|
180
|
+
} else if (char === ' ') {
|
|
181
|
+
clear(char);
|
|
182
|
+
} else {
|
|
183
|
+
const previousChar = value[i - 1];
|
|
184
|
+
switch(char){
|
|
185
|
+
case '+':
|
|
186
|
+
if (!current && previousChar !== ')') {
|
|
187
|
+
current += char;
|
|
188
|
+
} else {
|
|
189
|
+
clear(char, ' ', ' ');
|
|
190
|
+
}
|
|
191
|
+
break;
|
|
192
|
+
case '-':
|
|
193
|
+
if (!current && previousChar !== ')') {
|
|
194
|
+
current += char;
|
|
195
|
+
} else {
|
|
196
|
+
clear(char, ' ', ' ');
|
|
197
|
+
}
|
|
198
|
+
break;
|
|
199
|
+
case '*':
|
|
200
|
+
if (this.definition.unit) {
|
|
201
|
+
unitChecking = true;
|
|
202
|
+
}
|
|
203
|
+
clear(char, ' ', ' ');
|
|
204
|
+
break;
|
|
205
|
+
case '/':
|
|
206
|
+
if (this.definition.unit) {
|
|
207
|
+
unitChecking = true;
|
|
208
|
+
}
|
|
209
|
+
clear(char, ' ', ' ');
|
|
210
|
+
bypassParsing = true;
|
|
211
|
+
break;
|
|
212
|
+
default:
|
|
213
|
+
current += char;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
clear('');
|
|
219
|
+
handleUnitChecking();
|
|
220
|
+
};
|
|
221
|
+
anaylzeDeeply(valueComponents, false, false, false, false);
|
|
222
|
+
return 'calc(' + this.resolveValue(valueComponents, this.definition.unit, bypassVariableNames, true) + ')';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
module.exports = coreCalc;
|