@symbo.ls/scratch 2.33.14 → 2.33.20
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/cjs/index.js +168 -74
- package/dist/cjs/set.js +116 -26
- package/dist/cjs/system/index.js +148 -54
- package/dist/cjs/system/shadow.js +115 -17
- package/dist/cjs/system/spacing.js +147 -53
- package/dist/cjs/system/timing.js +101 -6
- package/dist/cjs/system/typography.js +101 -6
- package/dist/cjs/transforms/index.js +155 -120
- package/dist/cjs/utils/index.js +104 -6
- package/dist/cjs/utils/sequence.js +103 -6
- package/dist/cjs/utils/unit.js +53 -0
- package/package.json +4 -4
- package/src/system/spacing.js +61 -54
- package/src/transforms/index.js +21 -29
- package/src/utils/sequence.js +61 -19
- package/src/utils/unit.js +69 -2
|
@@ -316,7 +316,9 @@ __export(sequence_exports, {
|
|
|
316
316
|
generateSequence: () => generateSequence,
|
|
317
317
|
generateSequencePosition: () => generateSequencePosition,
|
|
318
318
|
generateSubSequence: () => generateSubSequence,
|
|
319
|
+
getFnPrefixAndValue: () => getFnPrefixAndValue,
|
|
319
320
|
getSequenceValue: () => getSequenceValue,
|
|
321
|
+
getSequenceValueBySymbols: () => getSequenceValueBySymbols,
|
|
320
322
|
getSequenceValuePropertyPair: () => getSequenceValuePropertyPair,
|
|
321
323
|
getSubratio: () => getSubratio,
|
|
322
324
|
getSubratioDifference: () => getSubratioDifference,
|
|
@@ -684,6 +686,58 @@ var getActiveConfig = (def) => {
|
|
|
684
686
|
var isScalingUnit = (unit) => {
|
|
685
687
|
return unit === "em" || unit === "rem" || unit === "vw" || unit === "vh" || unit === "vmax" || unit === "vmin";
|
|
686
688
|
};
|
|
689
|
+
var CSS_UNITS = [
|
|
690
|
+
// Absolute
|
|
691
|
+
"px",
|
|
692
|
+
"cm",
|
|
693
|
+
"mm",
|
|
694
|
+
"in",
|
|
695
|
+
"pt",
|
|
696
|
+
"pc",
|
|
697
|
+
// Font-relative
|
|
698
|
+
"em",
|
|
699
|
+
"rem",
|
|
700
|
+
"ex",
|
|
701
|
+
"cap",
|
|
702
|
+
"ch",
|
|
703
|
+
"ic",
|
|
704
|
+
"lh",
|
|
705
|
+
"rlh",
|
|
706
|
+
// Viewport-relative
|
|
707
|
+
"%",
|
|
708
|
+
"vw",
|
|
709
|
+
"vh",
|
|
710
|
+
"vmin",
|
|
711
|
+
"vmax",
|
|
712
|
+
"svw",
|
|
713
|
+
"svh",
|
|
714
|
+
"lvw",
|
|
715
|
+
"lvh",
|
|
716
|
+
"dvw",
|
|
717
|
+
"dvh",
|
|
718
|
+
// Container query units
|
|
719
|
+
"cqw",
|
|
720
|
+
"cqh",
|
|
721
|
+
"cqi",
|
|
722
|
+
"cqb",
|
|
723
|
+
"cqmin",
|
|
724
|
+
"cqmax",
|
|
725
|
+
// Angle
|
|
726
|
+
"deg",
|
|
727
|
+
"rad",
|
|
728
|
+
"grad",
|
|
729
|
+
"turn",
|
|
730
|
+
// Time
|
|
731
|
+
"s",
|
|
732
|
+
"ms",
|
|
733
|
+
// Resolution
|
|
734
|
+
"dpi",
|
|
735
|
+
"dpcm",
|
|
736
|
+
"dppx",
|
|
737
|
+
// Grid fractional
|
|
738
|
+
"fr",
|
|
739
|
+
"auto"
|
|
740
|
+
];
|
|
687
741
|
|
|
688
742
|
// src/utils/sequence.js
|
|
689
743
|
var numToLetterMap = {
|
|
@@ -728,6 +782,12 @@ var setSequenceValue = (props, sequenceProps) => {
|
|
|
728
782
|
sequenceProps.scales[key] = scaling;
|
|
729
783
|
sequenceProps.vars[variable] = scaling + sequenceProps.unit;
|
|
730
784
|
};
|
|
785
|
+
var getFnPrefixAndValue = (val) => {
|
|
786
|
+
if (!val.includes("(")) return val;
|
|
787
|
+
const prefix = val.split("(")[0];
|
|
788
|
+
const value = val.slice(val.indexOf("(") + 1, val.lastIndexOf(")"));
|
|
789
|
+
return [prefix, value];
|
|
790
|
+
};
|
|
731
791
|
var setScalingVar = (key, sequenceProps) => {
|
|
732
792
|
const { base, type, unit } = sequenceProps;
|
|
733
793
|
const defaultVal = (isScalingUnit(unit) ? 1 : base) + unit;
|
|
@@ -861,13 +921,26 @@ var generateSequencePosition = (sequenceProps, position = 0) => {
|
|
|
861
921
|
var getSequenceValue = (value = "A", sequenceProps) => {
|
|
862
922
|
const CONFIG2 = getActiveConfig();
|
|
863
923
|
const { UNIT: UNIT2 } = CONFIG2;
|
|
864
|
-
const { sequence, unit = UNIT2.default, useVariable } = sequenceProps;
|
|
865
924
|
if (isString(value) && value.slice(0, 2) === "--") return `var(${value})`;
|
|
866
|
-
const
|
|
925
|
+
const { sequence, unit = UNIT2.default, useVariable } = sequenceProps;
|
|
867
926
|
const startsWithDashOrLetterRegex = /^-?[a-zA-Z]/i;
|
|
868
927
|
const startsWithDashOrLetter = startsWithDashOrLetterRegex.test(value);
|
|
869
|
-
|
|
870
|
-
|
|
928
|
+
const hasUnits = CSS_UNITS.some((unit2) => value.includes(unit2));
|
|
929
|
+
if (hasUnits || !startsWithDashOrLetter) return value;
|
|
930
|
+
const skipArr = [
|
|
931
|
+
"none",
|
|
932
|
+
"auto",
|
|
933
|
+
"max-content",
|
|
934
|
+
"min-content",
|
|
935
|
+
"fit-content",
|
|
936
|
+
"inherit",
|
|
937
|
+
"initial",
|
|
938
|
+
"unset",
|
|
939
|
+
"revert",
|
|
940
|
+
"revert-layer"
|
|
941
|
+
];
|
|
942
|
+
if (skipArr.includes(value)) return value;
|
|
943
|
+
const prefix = `--${(0, import_utils3.toDashCase)(sequenceProps.type.replace(".", "-"))}-`;
|
|
871
944
|
const letterVal = value.toUpperCase();
|
|
872
945
|
const isNegative = letterVal.slice(0, 1) === "-" ? "-" : "";
|
|
873
946
|
let absValue = isNegative ? letterVal.slice(1) : letterVal;
|
|
@@ -909,14 +982,38 @@ var getSequenceValue = (value = "A", sequenceProps) => {
|
|
|
909
982
|
}
|
|
910
983
|
return isNegative + sequenceItem.scaling + unit;
|
|
911
984
|
};
|
|
912
|
-
var
|
|
985
|
+
var getSequenceValueBySymbols = (value, sequenceProps) => {
|
|
986
|
+
const mathArr = ["+", "-", "*", "/", ","].filter(
|
|
987
|
+
(v) => value.includes(v + " ")
|
|
988
|
+
);
|
|
989
|
+
if (!mathArr.length) return value;
|
|
990
|
+
return mathArr.map((symbol) => {
|
|
991
|
+
const valuesArr = value.split(symbol + " ").map((v) => v.trim());
|
|
992
|
+
const transformedValues = valuesArr.map((v) => {
|
|
993
|
+
return getSequenceValue(v, sequenceProps);
|
|
994
|
+
});
|
|
995
|
+
return transformedValues.join(symbol + " ");
|
|
996
|
+
}).join("");
|
|
997
|
+
};
|
|
998
|
+
var getSequenceValuePropertyPair = (value, propertyName, sequenceProps, fnPrefix) => {
|
|
913
999
|
if (typeof value !== "string") {
|
|
914
1000
|
const CONFIG2 = getActiveConfig();
|
|
915
1001
|
if (CONFIG2.verbose) console.warn(propertyName, value, "is not a string");
|
|
916
1002
|
return { [propertyName]: value };
|
|
917
1003
|
}
|
|
918
1004
|
if (value === "-" || value === "") return {};
|
|
919
|
-
|
|
1005
|
+
if (!fnPrefix && value.includes("(")) {
|
|
1006
|
+
const fnArr = getFnPrefixAndValue(value);
|
|
1007
|
+
fnPrefix = fnArr[0];
|
|
1008
|
+
value = fnArr[1];
|
|
1009
|
+
}
|
|
1010
|
+
const mathArr = ["+", "-", "*", "/", ","].filter(
|
|
1011
|
+
(v) => value.includes(v + " ")
|
|
1012
|
+
);
|
|
1013
|
+
if (mathArr.length) {
|
|
1014
|
+
value = getSequenceValueBySymbols(value, sequenceProps);
|
|
1015
|
+
} else value = getSequenceValue(value, sequenceProps);
|
|
1016
|
+
return { [propertyName]: fnPrefix ? `${fnPrefix}(${value})` : value };
|
|
920
1017
|
};
|
|
921
1018
|
var findHeadingLetter = (h1Matches, index) => numToLetterMap[h1Matches - index];
|
|
922
1019
|
var findHeadings = (propertyNames) => {
|
package/dist/cjs/utils/unit.js
CHANGED
|
@@ -20,9 +20,62 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/utils/unit.js
|
|
21
21
|
var unit_exports = {};
|
|
22
22
|
__export(unit_exports, {
|
|
23
|
+
CSS_UNITS: () => CSS_UNITS,
|
|
23
24
|
isScalingUnit: () => isScalingUnit
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(unit_exports);
|
|
26
27
|
var isScalingUnit = (unit) => {
|
|
27
28
|
return unit === "em" || unit === "rem" || unit === "vw" || unit === "vh" || unit === "vmax" || unit === "vmin";
|
|
28
29
|
};
|
|
30
|
+
var CSS_UNITS = [
|
|
31
|
+
// Absolute
|
|
32
|
+
"px",
|
|
33
|
+
"cm",
|
|
34
|
+
"mm",
|
|
35
|
+
"in",
|
|
36
|
+
"pt",
|
|
37
|
+
"pc",
|
|
38
|
+
// Font-relative
|
|
39
|
+
"em",
|
|
40
|
+
"rem",
|
|
41
|
+
"ex",
|
|
42
|
+
"cap",
|
|
43
|
+
"ch",
|
|
44
|
+
"ic",
|
|
45
|
+
"lh",
|
|
46
|
+
"rlh",
|
|
47
|
+
// Viewport-relative
|
|
48
|
+
"%",
|
|
49
|
+
"vw",
|
|
50
|
+
"vh",
|
|
51
|
+
"vmin",
|
|
52
|
+
"vmax",
|
|
53
|
+
"svw",
|
|
54
|
+
"svh",
|
|
55
|
+
"lvw",
|
|
56
|
+
"lvh",
|
|
57
|
+
"dvw",
|
|
58
|
+
"dvh",
|
|
59
|
+
// Container query units
|
|
60
|
+
"cqw",
|
|
61
|
+
"cqh",
|
|
62
|
+
"cqi",
|
|
63
|
+
"cqb",
|
|
64
|
+
"cqmin",
|
|
65
|
+
"cqmax",
|
|
66
|
+
// Angle
|
|
67
|
+
"deg",
|
|
68
|
+
"rad",
|
|
69
|
+
"grad",
|
|
70
|
+
"turn",
|
|
71
|
+
// Time
|
|
72
|
+
"s",
|
|
73
|
+
"ms",
|
|
74
|
+
// Resolution
|
|
75
|
+
"dpi",
|
|
76
|
+
"dpcm",
|
|
77
|
+
"dppx",
|
|
78
|
+
// Grid fractional
|
|
79
|
+
"fr",
|
|
80
|
+
"auto"
|
|
81
|
+
];
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@symbo.ls/scratch",
|
|
3
3
|
"description": "Φ / CSS framework and methodology.",
|
|
4
4
|
"author": "symbo.ls",
|
|
5
|
-
"version": "2.33.
|
|
5
|
+
"version": "2.33.20",
|
|
6
6
|
"files": [
|
|
7
7
|
"src",
|
|
8
8
|
"dist"
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@domql/utils": "^2.33.
|
|
29
|
-
"@symbo.ls/utils": "^2.33.
|
|
28
|
+
"@domql/utils": "^2.33.20",
|
|
29
|
+
"@symbo.ls/utils": "^2.33.20",
|
|
30
30
|
"color-contrast-checker": "^1.5.0"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "717ab2ed8690b295c7d6c79e31831048f20f4e86"
|
|
33
33
|
}
|
package/src/system/spacing.js
CHANGED
|
@@ -5,28 +5,22 @@ import { isArray, isString, merge } from '@domql/utils'
|
|
|
5
5
|
|
|
6
6
|
import { getActiveConfig } from '../factory.js'
|
|
7
7
|
import {
|
|
8
|
+
CSS_UNITS,
|
|
8
9
|
applyMediaSequenceVars,
|
|
9
10
|
applySequenceVars,
|
|
10
11
|
generateSequence,
|
|
12
|
+
getFnPrefixAndValue,
|
|
11
13
|
getSequenceValuePropertyPair
|
|
12
14
|
} from '../utils'
|
|
13
15
|
|
|
14
|
-
const runThroughMedia = FACTORY => {
|
|
16
|
+
const runThroughMedia = (FACTORY) => {
|
|
15
17
|
for (const prop in FACTORY) {
|
|
16
18
|
const mediaProps = FACTORY[prop]
|
|
17
19
|
|
|
18
20
|
const isMediaName = prop.slice(0, 1) === '@'
|
|
19
21
|
if (!isMediaName) continue
|
|
20
22
|
|
|
21
|
-
const {
|
|
22
|
-
type,
|
|
23
|
-
base,
|
|
24
|
-
ratio,
|
|
25
|
-
range,
|
|
26
|
-
subSequence,
|
|
27
|
-
h1Matches,
|
|
28
|
-
unit
|
|
29
|
-
} = FACTORY
|
|
23
|
+
const { type, base, ratio, range, subSequence, h1Matches, unit } = FACTORY
|
|
30
24
|
|
|
31
25
|
merge(mediaProps, {
|
|
32
26
|
type,
|
|
@@ -47,6 +41,13 @@ const runThroughMedia = FACTORY => {
|
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
43
|
|
|
44
|
+
export const checkIfBoxSize = (propertyName) => {
|
|
45
|
+
const prop = propertyName.toLowerCase()
|
|
46
|
+
const includesWidth = prop.includes('width') || prop.includes('height')
|
|
47
|
+
const includesBorder = prop.includes('border') || prop.includes('outline')
|
|
48
|
+
return includesWidth && !includesBorder
|
|
49
|
+
}
|
|
50
|
+
|
|
50
51
|
export const applySpacingSequence = () => {
|
|
51
52
|
const CONFIG = getActiveConfig()
|
|
52
53
|
const { SPACING } = CONFIG
|
|
@@ -66,15 +67,20 @@ const getSequence = (sequenceProps) => {
|
|
|
66
67
|
export const getSpacingByKey = (
|
|
67
68
|
value,
|
|
68
69
|
propertyName = 'padding',
|
|
69
|
-
sequenceProps
|
|
70
|
+
sequenceProps,
|
|
71
|
+
fnPrefix
|
|
70
72
|
) => {
|
|
71
73
|
const sequence = getSequence(sequenceProps)
|
|
72
74
|
|
|
73
|
-
if (isString(value)
|
|
74
|
-
|
|
75
|
+
if (isString(value)) {
|
|
76
|
+
if (!fnPrefix && value.includes('(')) {
|
|
77
|
+
const fnArray = getFnPrefixAndValue(value)
|
|
78
|
+
fnPrefix = fnArray[0]
|
|
79
|
+
value = fnArray[1]
|
|
80
|
+
}
|
|
75
81
|
}
|
|
76
82
|
|
|
77
|
-
const stack = arrayzeValue(value)
|
|
83
|
+
const stack = fnPrefix ? [value] : arrayzeValue(value)
|
|
78
84
|
if (!isArray(stack)) return
|
|
79
85
|
|
|
80
86
|
if (stack.length > 1) {
|
|
@@ -90,56 +96,57 @@ export const getSpacingByKey = (
|
|
|
90
96
|
4: ['BlockStart', 'InlineEnd', 'BlockEnd', 'InlineStart']
|
|
91
97
|
}
|
|
92
98
|
|
|
93
|
-
const wrapSequenceValueByDirection = (direction, i) =>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
const wrapSequenceValueByDirection = (direction, i) =>
|
|
100
|
+
getSequenceValuePropertyPair(
|
|
101
|
+
stack[i],
|
|
102
|
+
propertyName + direction + suffix,
|
|
103
|
+
sequence,
|
|
104
|
+
fnPrefix
|
|
105
|
+
)
|
|
98
106
|
|
|
99
|
-
return directions[stack.length].map((dir, key) =>
|
|
107
|
+
return directions[stack.length].map((dir, key) =>
|
|
108
|
+
wrapSequenceValueByDirection(dir, key)
|
|
109
|
+
)
|
|
100
110
|
}
|
|
101
111
|
|
|
102
|
-
return getSequenceValuePropertyPair(
|
|
103
|
-
value,
|
|
104
|
-
propertyName,
|
|
105
|
-
sequence
|
|
106
|
-
)
|
|
112
|
+
return getSequenceValuePropertyPair(value, propertyName, sequence, fnPrefix)
|
|
107
113
|
}
|
|
108
114
|
|
|
109
|
-
export const getSpacingBasedOnRatio = (props, propertyName, val) => {
|
|
115
|
+
export const getSpacingBasedOnRatio = (props, propertyName, val, fnPrefix) => {
|
|
110
116
|
const CONFIG = getActiveConfig()
|
|
111
117
|
const { SPACING } = CONFIG
|
|
112
118
|
|
|
113
|
-
|
|
114
|
-
const value = val || props[propertyName]
|
|
115
|
-
|
|
116
|
-
if (spacingRatio) {
|
|
117
|
-
let sequenceProps = SPACING[spacingRatio]
|
|
118
|
-
|
|
119
|
-
if (!sequenceProps) {
|
|
120
|
-
const { type, base, range, subSequence } = SPACING
|
|
121
|
-
|
|
122
|
-
sequenceProps = SPACING[spacingRatio] = merge({
|
|
123
|
-
ratio: spacingRatio,
|
|
124
|
-
type: type + '-' + spacingRatio,
|
|
125
|
-
unit,
|
|
126
|
-
sequence: {},
|
|
127
|
-
scales: {},
|
|
128
|
-
templates: {},
|
|
129
|
-
vars: {}
|
|
130
|
-
}, {
|
|
131
|
-
base,
|
|
132
|
-
range,
|
|
133
|
-
subSequence,
|
|
134
|
-
ratio: SPACING.ratio,
|
|
135
|
-
unit: SPACING.unit
|
|
136
|
-
})
|
|
137
|
-
}
|
|
119
|
+
let value = val || props[propertyName]
|
|
138
120
|
|
|
139
|
-
|
|
121
|
+
if (!fnPrefix && isString(value) && value.includes('(')) {
|
|
122
|
+
const fnArr = getFnPrefixAndValue(value)
|
|
123
|
+
fnPrefix = fnArr[0]
|
|
124
|
+
value = fnArr[1]
|
|
125
|
+
}
|
|
140
126
|
|
|
141
|
-
|
|
127
|
+
if (props.spacingRatio) {
|
|
128
|
+
const sequenceProps = applyCustomSequence(props)
|
|
129
|
+
return getSpacingByKey(value, propertyName, sequenceProps, fnPrefix)
|
|
142
130
|
}
|
|
143
131
|
|
|
144
|
-
return getSpacingByKey(value, propertyName)
|
|
132
|
+
return getSpacingByKey(value, propertyName, SPACING, fnPrefix)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const splitSpacedValue = (val) => {
|
|
136
|
+
const addDefault = (v) => {
|
|
137
|
+
const isSymbol = ['+', '-', '*', '/'].includes(v)
|
|
138
|
+
const hasUnits = CSS_UNITS.some((unit) => val.includes(unit))
|
|
139
|
+
if (isSymbol || hasUnits) return v
|
|
140
|
+
const isSingleLetter = v.length < 3 && /[A-Z]/.test(v)
|
|
141
|
+
if (isSingleLetter) return v + '_default'
|
|
142
|
+
return v
|
|
143
|
+
}
|
|
144
|
+
return val
|
|
145
|
+
.split(',')
|
|
146
|
+
.map((v) => v.trim())
|
|
147
|
+
.map(addDefault)
|
|
148
|
+
.join(',')
|
|
149
|
+
.split(' ')
|
|
150
|
+
.map(addDefault)
|
|
151
|
+
.join(' ')
|
|
145
152
|
}
|
package/src/transforms/index.js
CHANGED
|
@@ -9,8 +9,11 @@ import {
|
|
|
9
9
|
getMediaColor,
|
|
10
10
|
getTimingByKey,
|
|
11
11
|
getTimingFunction,
|
|
12
|
-
getSpacingBasedOnRatio
|
|
12
|
+
getSpacingBasedOnRatio,
|
|
13
|
+
checkIfBoxSize,
|
|
14
|
+
splitSpacedValue
|
|
13
15
|
} from '../system'
|
|
16
|
+
import { getFnPrefixAndValue } from '../utils'
|
|
14
17
|
|
|
15
18
|
const isBorderStyle = (str) =>
|
|
16
19
|
[
|
|
@@ -142,41 +145,30 @@ export const splitTransition = (transition) => {
|
|
|
142
145
|
return arr.map(transformTransition).join(',')
|
|
143
146
|
}
|
|
144
147
|
|
|
145
|
-
export const checkIfBoxSize = (propertyName) => {
|
|
146
|
-
const prop = propertyName.toLowerCase()
|
|
147
|
-
return (
|
|
148
|
-
(prop.includes('width') || prop.includes('height')) &&
|
|
149
|
-
!prop.includes('border')
|
|
150
|
-
)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
148
|
export const transformSize = (propertyName, val, props = {}, opts = {}) => {
|
|
154
149
|
let value = val || props[propertyName]
|
|
155
150
|
|
|
156
151
|
if (isUndefined(value) && isNull(value)) return
|
|
157
152
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
.join(' ')
|
|
153
|
+
let fnPrefix
|
|
154
|
+
if (isString(value)) {
|
|
155
|
+
// has function prefix
|
|
156
|
+
if (value.includes('(')) {
|
|
157
|
+
const fnArr = getFnPrefixAndValue(value)
|
|
158
|
+
fnPrefix = fnArr[0]
|
|
159
|
+
value = fnArr[1]
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const shouldScaleBoxSize = props.scaleBoxSize
|
|
163
|
+
const isBoxSize = checkIfBoxSize(propertyName)
|
|
164
|
+
if (!shouldScaleBoxSize && isBoxSize) {
|
|
165
|
+
value = splitSpacedValue(value)
|
|
166
|
+
}
|
|
173
167
|
}
|
|
174
168
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return getSpacingByKey(value, propertyName)
|
|
179
|
-
}
|
|
169
|
+
return opts.ratio
|
|
170
|
+
? getSpacingBasedOnRatio(props, propertyName, value, fnPrefix)
|
|
171
|
+
: getSpacingByKey(value, propertyName, undefined, fnPrefix)
|
|
180
172
|
}
|
|
181
173
|
|
|
182
174
|
export const transformSizeRatio = (propertyName, props) => {
|
package/src/utils/sequence.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { isString } from '@domql/utils'
|
|
4
4
|
import { toDashCase } from '@symbo.ls/utils'
|
|
5
5
|
import { getActiveConfig } from '../factory.js'
|
|
6
|
-
import { isScalingUnit } from './unit.js'
|
|
6
|
+
import { CSS_UNITS, isScalingUnit } from './unit.js'
|
|
7
7
|
|
|
8
8
|
export const numToLetterMap = {
|
|
9
9
|
'-6': 'U',
|
|
@@ -49,6 +49,13 @@ const setSequenceValue = (props, sequenceProps) => {
|
|
|
49
49
|
sequenceProps.vars[variable] = scaling + sequenceProps.unit
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
export const getFnPrefixAndValue = (val) => {
|
|
53
|
+
if (!val.includes('(')) return val
|
|
54
|
+
const prefix = val.split('(')[0]
|
|
55
|
+
const value = val.slice(val.indexOf('(') + 1, val.lastIndexOf(')'))
|
|
56
|
+
return [prefix, value]
|
|
57
|
+
}
|
|
58
|
+
|
|
52
59
|
export const setScalingVar = (key, sequenceProps) => {
|
|
53
60
|
const { base, type, unit } = sequenceProps
|
|
54
61
|
|
|
@@ -224,29 +231,31 @@ export const getSequenceValue = (value = 'A', sequenceProps) => {
|
|
|
224
231
|
const CONFIG = getActiveConfig()
|
|
225
232
|
const { UNIT } = CONFIG
|
|
226
233
|
|
|
227
|
-
const { sequence, unit = UNIT.default, useVariable } = sequenceProps
|
|
228
|
-
|
|
229
234
|
if (isString(value) && value.slice(0, 2) === '--') return `var(${value})`
|
|
230
235
|
|
|
231
|
-
const
|
|
236
|
+
const { sequence, unit = UNIT.default, useVariable } = sequenceProps
|
|
232
237
|
|
|
233
238
|
const startsWithDashOrLetterRegex = /^-?[a-zA-Z]/i
|
|
234
239
|
const startsWithDashOrLetter = startsWithDashOrLetterRegex.test(value)
|
|
235
240
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
241
|
+
const hasUnits = CSS_UNITS.some((unit) => value.includes(unit))
|
|
242
|
+
if (hasUnits || !startsWithDashOrLetter) return value
|
|
243
|
+
|
|
244
|
+
const skipArr = [
|
|
245
|
+
'none',
|
|
246
|
+
'auto',
|
|
247
|
+
'max-content',
|
|
248
|
+
'min-content',
|
|
249
|
+
'fit-content',
|
|
250
|
+
'inherit',
|
|
251
|
+
'initial',
|
|
252
|
+
'unset',
|
|
253
|
+
'revert',
|
|
254
|
+
'revert-layer'
|
|
255
|
+
]
|
|
256
|
+
if (skipArr.includes(value)) return value
|
|
249
257
|
|
|
258
|
+
const prefix = `--${toDashCase(sequenceProps.type.replace('.', '-'))}-`
|
|
250
259
|
const letterVal = value.toUpperCase()
|
|
251
260
|
const isNegative = letterVal.slice(0, 1) === '-' ? '-' : ''
|
|
252
261
|
let absValue = isNegative ? letterVal.slice(1) : letterVal
|
|
@@ -300,18 +309,51 @@ export const getSequenceValue = (value = 'A', sequenceProps) => {
|
|
|
300
309
|
return isNegative + sequenceItem.scaling + unit
|
|
301
310
|
}
|
|
302
311
|
|
|
312
|
+
export const getSequenceValueBySymbols = (value, sequenceProps) => {
|
|
313
|
+
const mathArr = ['+', '-', '*', '/', ','].filter((v) =>
|
|
314
|
+
value.includes(v + ' ')
|
|
315
|
+
)
|
|
316
|
+
if (!mathArr.length) return value
|
|
317
|
+
|
|
318
|
+
return mathArr
|
|
319
|
+
.map((symbol) => {
|
|
320
|
+
const valuesArr = value.split(symbol + ' ').map((v) => v.trim())
|
|
321
|
+
const transformedValues = valuesArr.map((v) => {
|
|
322
|
+
return getSequenceValue(v, sequenceProps)
|
|
323
|
+
})
|
|
324
|
+
return transformedValues.join(symbol + ' ')
|
|
325
|
+
})
|
|
326
|
+
.join('')
|
|
327
|
+
}
|
|
328
|
+
|
|
303
329
|
export const getSequenceValuePropertyPair = (
|
|
304
330
|
value,
|
|
305
331
|
propertyName,
|
|
306
|
-
sequenceProps
|
|
332
|
+
sequenceProps,
|
|
333
|
+
fnPrefix
|
|
307
334
|
) => {
|
|
308
335
|
if (typeof value !== 'string') {
|
|
309
336
|
const CONFIG = getActiveConfig()
|
|
310
337
|
if (CONFIG.verbose) console.warn(propertyName, value, 'is not a string')
|
|
311
338
|
return { [propertyName]: value }
|
|
312
339
|
}
|
|
340
|
+
|
|
313
341
|
if (value === '-' || value === '') return {}
|
|
314
|
-
|
|
342
|
+
|
|
343
|
+
if (!fnPrefix && value.includes('(')) {
|
|
344
|
+
const fnArr = getFnPrefixAndValue(value)
|
|
345
|
+
fnPrefix = fnArr[0]
|
|
346
|
+
value = fnArr[1]
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const mathArr = ['+', '-', '*', '/', ','].filter((v) =>
|
|
350
|
+
value.includes(v + ' ')
|
|
351
|
+
)
|
|
352
|
+
if (mathArr.length) {
|
|
353
|
+
value = getSequenceValueBySymbols(value, sequenceProps)
|
|
354
|
+
} else value = getSequenceValue(value, sequenceProps)
|
|
355
|
+
|
|
356
|
+
return { [propertyName]: fnPrefix ? `${fnPrefix}(${value})` : value }
|
|
315
357
|
}
|
|
316
358
|
|
|
317
359
|
export const findHeadingLetter = (h1Matches, index) =>
|
package/src/utils/unit.js
CHANGED
|
@@ -1,5 +1,72 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
export const isScalingUnit = unit => {
|
|
4
|
-
return
|
|
3
|
+
export const isScalingUnit = (unit) => {
|
|
4
|
+
return (
|
|
5
|
+
unit === 'em' ||
|
|
6
|
+
unit === 'rem' ||
|
|
7
|
+
unit === 'vw' ||
|
|
8
|
+
unit === 'vh' ||
|
|
9
|
+
unit === 'vmax' ||
|
|
10
|
+
unit === 'vmin'
|
|
11
|
+
)
|
|
5
12
|
}
|
|
13
|
+
|
|
14
|
+
export const CSS_UNITS = [
|
|
15
|
+
// Absolute
|
|
16
|
+
'px',
|
|
17
|
+
'cm',
|
|
18
|
+
'mm',
|
|
19
|
+
'in',
|
|
20
|
+
'pt',
|
|
21
|
+
'pc',
|
|
22
|
+
|
|
23
|
+
// Font-relative
|
|
24
|
+
'em',
|
|
25
|
+
'rem',
|
|
26
|
+
'ex',
|
|
27
|
+
'cap',
|
|
28
|
+
'ch',
|
|
29
|
+
'ic',
|
|
30
|
+
'lh',
|
|
31
|
+
'rlh',
|
|
32
|
+
|
|
33
|
+
// Viewport-relative
|
|
34
|
+
'%',
|
|
35
|
+
'vw',
|
|
36
|
+
'vh',
|
|
37
|
+
'vmin',
|
|
38
|
+
'vmax',
|
|
39
|
+
'svw',
|
|
40
|
+
'svh',
|
|
41
|
+
'lvw',
|
|
42
|
+
'lvh',
|
|
43
|
+
'dvw',
|
|
44
|
+
'dvh',
|
|
45
|
+
|
|
46
|
+
// Container query units
|
|
47
|
+
'cqw',
|
|
48
|
+
'cqh',
|
|
49
|
+
'cqi',
|
|
50
|
+
'cqb',
|
|
51
|
+
'cqmin',
|
|
52
|
+
'cqmax',
|
|
53
|
+
|
|
54
|
+
// Angle
|
|
55
|
+
'deg',
|
|
56
|
+
'rad',
|
|
57
|
+
'grad',
|
|
58
|
+
'turn',
|
|
59
|
+
|
|
60
|
+
// Time
|
|
61
|
+
's',
|
|
62
|
+
'ms',
|
|
63
|
+
|
|
64
|
+
// Resolution
|
|
65
|
+
'dpi',
|
|
66
|
+
'dpcm',
|
|
67
|
+
'dppx',
|
|
68
|
+
|
|
69
|
+
// Grid fractional
|
|
70
|
+
'fr',
|
|
71
|
+
'auto'
|
|
72
|
+
]
|