@thejaredwilcurt/csslop 0.0.24 → 0.0.25
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/README.md +4 -0
- package/package.json +5 -3
- package/src/declarations/background.js +26 -1
- package/src/declarations/config.js +60 -0
- package/src/declarations/css-wide-keywords.js +47 -25
- package/src/declarations/lookup.js +44 -0
- package/src/declarations/merge.js +27 -30
- package/src/declarations/order.js +32 -6
- package/src/declarations/process.js +146 -55
- package/src/index.js +29 -5
- package/src/rules/optimize.js +198 -78
- package/src/rules/stringify.js +11 -4
- package/src/value/gradients.js +87 -46
- package/src/value/math.js +17 -2
- package/src/value/minify.js +110 -14
package/src/value/minify.js
CHANGED
|
@@ -755,6 +755,51 @@ function convertAbsoluteLengthsToPx (value) {
|
|
|
755
755
|
});
|
|
756
756
|
}
|
|
757
757
|
|
|
758
|
+
/**
|
|
759
|
+
* Properties whose `initial` value is a number the browser resolves, so the
|
|
760
|
+
* keyword only ever shortens for the two that have a shorter written form.
|
|
761
|
+
*
|
|
762
|
+
* @type {Set<string>}
|
|
763
|
+
*/
|
|
764
|
+
const NUMERIC_INITIAL_PROPERTIES = new Set([
|
|
765
|
+
'opacity',
|
|
766
|
+
'z-index',
|
|
767
|
+
'flex-grow',
|
|
768
|
+
'flex-shrink',
|
|
769
|
+
'order',
|
|
770
|
+
'line-height',
|
|
771
|
+
'zoom'
|
|
772
|
+
]);
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* Properties whose `initial` value is zero.
|
|
776
|
+
*
|
|
777
|
+
* @type {Set<string>}
|
|
778
|
+
*/
|
|
779
|
+
const ZERO_INITIAL_PROPERTIES = new Set(['margin', 'padding']);
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Properties whose `initial` value is `auto`.
|
|
783
|
+
*
|
|
784
|
+
* @type {Set<string>}
|
|
785
|
+
*/
|
|
786
|
+
const AUTO_INITIAL_PROPERTIES = new Set(['min-width', 'min-height']);
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Properties whose value is a time, where a millisecond amount may be worth
|
|
790
|
+
* rewriting in seconds.
|
|
791
|
+
*
|
|
792
|
+
* @type {Set<string>}
|
|
793
|
+
*/
|
|
794
|
+
const TIME_PROPERTIES = new Set([
|
|
795
|
+
'transition',
|
|
796
|
+
'transition-duration',
|
|
797
|
+
'transition-delay',
|
|
798
|
+
'animation',
|
|
799
|
+
'animation-duration',
|
|
800
|
+
'animation-delay'
|
|
801
|
+
]);
|
|
802
|
+
|
|
758
803
|
/**
|
|
759
804
|
* Applies property-specific optimizations to a CSS value (transition, flex, font,
|
|
760
805
|
* background, display, scale, border-radius, shorthand collapsing, etc.).
|
|
@@ -773,15 +818,7 @@ function applyPropertyOptimizations (val, property, allowsHexSpaceElision) {
|
|
|
773
818
|
}
|
|
774
819
|
|
|
775
820
|
// Convert ms to s for time-related properties when the seconds form is shorter
|
|
776
|
-
|
|
777
|
-
property === 'transition' ||
|
|
778
|
-
property === 'transition-duration' ||
|
|
779
|
-
property === 'transition-delay' ||
|
|
780
|
-
property === 'animation' ||
|
|
781
|
-
property === 'animation-duration' ||
|
|
782
|
-
property === 'animation-delay'
|
|
783
|
-
);
|
|
784
|
-
if (isTimeProperty) {
|
|
821
|
+
if (TIME_PROPERTIES.has(property)) {
|
|
785
822
|
val = convertMillisecondsToSeconds(val);
|
|
786
823
|
}
|
|
787
824
|
|
|
@@ -823,7 +860,7 @@ function applyPropertyOptimizations (val, property, allowsHexSpaceElision) {
|
|
|
823
860
|
|
|
824
861
|
// Initial values
|
|
825
862
|
if (val === 'initial') {
|
|
826
|
-
if (
|
|
863
|
+
if (NUMERIC_INITIAL_PROPERTIES.has(property)) {
|
|
827
864
|
// Just leaving them or mapping some: opacity: initial -> opacity: 1
|
|
828
865
|
if (property === 'opacity') {
|
|
829
866
|
val = '1';
|
|
@@ -832,10 +869,10 @@ function applyPropertyOptimizations (val, property, allowsHexSpaceElision) {
|
|
|
832
869
|
val = 'auto';
|
|
833
870
|
}
|
|
834
871
|
}
|
|
835
|
-
if (
|
|
872
|
+
if (ZERO_INITIAL_PROPERTIES.has(property)) {
|
|
836
873
|
val = '0';
|
|
837
874
|
}
|
|
838
|
-
if (
|
|
875
|
+
if (AUTO_INITIAL_PROPERTIES.has(property)) {
|
|
839
876
|
val = 'auto';
|
|
840
877
|
}
|
|
841
878
|
// background-color: initial should become #0000 (transparent)
|
|
@@ -1043,7 +1080,7 @@ function applyPropertyOptimizations (val, property, allowsHexSpaceElision) {
|
|
|
1043
1080
|
* @param {object} declaration The CSS declaration object with property and value fields.
|
|
1044
1081
|
* @return {string} The minified value string.
|
|
1045
1082
|
*/
|
|
1046
|
-
function
|
|
1083
|
+
function computeMinifiedValue (declaration) {
|
|
1047
1084
|
if (declaration.property === 'position-area') {
|
|
1048
1085
|
const shorthand = POSITION_AREA_SHORTHANDS[declaration.value];
|
|
1049
1086
|
if (shorthand) {
|
|
@@ -1135,4 +1172,63 @@ function minifyValue (declaration) {
|
|
|
1135
1172
|
return val;
|
|
1136
1173
|
}
|
|
1137
1174
|
|
|
1138
|
-
|
|
1175
|
+
/**
|
|
1176
|
+
* Memoizes minified values for the current stylesheet. Minification runs many
|
|
1177
|
+
* passes over the same declarations (deduplication, shorthand assembly,
|
|
1178
|
+
* CSS-wide keyword hoisting, stringification), and the result only depends on
|
|
1179
|
+
* the declaration fields that make up the cache key, so each distinct
|
|
1180
|
+
* property/value pair is minified once per stylesheet.
|
|
1181
|
+
*
|
|
1182
|
+
* @type {Map<string, string>}
|
|
1183
|
+
*/
|
|
1184
|
+
const minifiedValueCache = new Map();
|
|
1185
|
+
|
|
1186
|
+
/**
|
|
1187
|
+
* Discards every memoized value. The minifier calls this at the start of each
|
|
1188
|
+
* stylesheet, since the active `@charset` can change how a value minifies and
|
|
1189
|
+
* the cache should not outlive the pass that filled it.
|
|
1190
|
+
*/
|
|
1191
|
+
function clearMinifiedValueCache () {
|
|
1192
|
+
minifiedValueCache.clear();
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* Builds the cache key for a declaration from every field the value minifier
|
|
1197
|
+
* reads. A null character cannot appear in a property name or in a parsed CSS
|
|
1198
|
+
* value, so it safely delimits the parts.
|
|
1199
|
+
*
|
|
1200
|
+
* @param {object} declaration The CSS declaration object.
|
|
1201
|
+
* @return {string} The cache key.
|
|
1202
|
+
*/
|
|
1203
|
+
function createMinifiedValueCacheKey (declaration) {
|
|
1204
|
+
const assembledFlag = declaration.isAssembledShorthand ? '1' : '0';
|
|
1205
|
+
return declaration.property + '\u0000' + assembledFlag + '\u0000' + declaration.value;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* Minifies a CSS declaration's value, reusing the memoized result when the same
|
|
1210
|
+
* property and value has already been minified during this pass.
|
|
1211
|
+
*
|
|
1212
|
+
* @param {object} declaration The CSS declaration object with property and value fields.
|
|
1213
|
+
* @return {string} The minified value string.
|
|
1214
|
+
*/
|
|
1215
|
+
function minifyValue (declaration) {
|
|
1216
|
+
// Only string values have a stable, collision-free key; anything else is rare
|
|
1217
|
+
// enough that minifying it again costs less than encoding its type.
|
|
1218
|
+
if (typeof declaration.value !== 'string') {
|
|
1219
|
+
return computeMinifiedValue(declaration);
|
|
1220
|
+
}
|
|
1221
|
+
const cacheKey = createMinifiedValueCacheKey(declaration);
|
|
1222
|
+
const cachedValue = minifiedValueCache.get(cacheKey);
|
|
1223
|
+
if (cachedValue !== undefined) {
|
|
1224
|
+
return cachedValue;
|
|
1225
|
+
}
|
|
1226
|
+
const minifiedValue = computeMinifiedValue(declaration);
|
|
1227
|
+
minifiedValueCache.set(cacheKey, minifiedValue);
|
|
1228
|
+
return minifiedValue;
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
export {
|
|
1232
|
+
clearMinifiedValueCache,
|
|
1233
|
+
minifyValue
|
|
1234
|
+
};
|