css-calipers 0.9.6 → 0.10.0
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/core.js +10 -1
- package/dist/cjs/mediaQueries/validation.js +18 -32
- package/dist/cjs/ratio.js +38 -22
- package/dist/esm/core.d.ts +3 -0
- package/dist/esm/core.d.ts.map +1 -1
- package/dist/esm/core.js +2 -0
- package/dist/esm/internal/createMediaQueriesApi.d.ts.map +1 -1
- package/dist/esm/mediaQueries/helpers.d.ts +2 -2
- package/dist/esm/mediaQueries/helpers.d.ts.map +1 -1
- package/dist/esm/mediaQueries/modules/dimensions.d.ts +2 -2
- package/dist/esm/mediaQueries/modules/dimensions.d.ts.map +1 -1
- package/dist/esm/mediaQueries/validation.d.ts.map +1 -1
- package/dist/esm/mediaQueries/validation.js +19 -33
- package/dist/esm/ratio.d.ts +7 -2
- package/dist/esm/ratio.d.ts.map +1 -1
- package/dist/esm/ratio.js +36 -21
- package/package.json +4 -3
package/dist/cjs/core.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setErrorConfig = exports.getErrorConfig = exports.assertCondition = exports.assertUnit = exports.hasCssMethod = exports.makeUnitAssert = exports.makeUnitGuard = exports.makeUnitHelperFromDefinition = exports.makeUnitHelper = exports.measurementUnitMetadata = exports.measurementMax = exports.measurementMin = exports.assertMatchingUnits = exports.isMeasurement = exports.m = void 0;
|
|
3
|
+
exports.simplifyRatio = exports.reduceRatio = exports.toFloat = exports.ratioToFloat = exports.parseRatio = exports.normalizeRatio = exports.isRatio = exports.r = exports.setErrorConfig = exports.getErrorConfig = exports.assertCondition = exports.assertUnit = exports.hasCssMethod = exports.makeUnitAssert = exports.makeUnitGuard = exports.makeUnitHelperFromDefinition = exports.makeUnitHelper = exports.measurementUnitMetadata = exports.measurementMax = exports.measurementMin = exports.assertMatchingUnits = exports.isMeasurement = exports.m = void 0;
|
|
4
4
|
const createCoreApi_1 = require("./internal/createCoreApi");
|
|
5
5
|
const errors_1 = require("./internal/errors");
|
|
6
|
+
const ratio_1 = require("./ratio");
|
|
7
|
+
Object.defineProperty(exports, "r", { enumerable: true, get: function () { return ratio_1.r; } });
|
|
8
|
+
Object.defineProperty(exports, "isRatio", { enumerable: true, get: function () { return ratio_1.isRatio; } });
|
|
9
|
+
Object.defineProperty(exports, "normalizeRatio", { enumerable: true, get: function () { return ratio_1.normalizeRatio; } });
|
|
10
|
+
Object.defineProperty(exports, "parseRatio", { enumerable: true, get: function () { return ratio_1.parseRatio; } });
|
|
11
|
+
Object.defineProperty(exports, "ratioToFloat", { enumerable: true, get: function () { return ratio_1.ratioToFloat; } });
|
|
12
|
+
Object.defineProperty(exports, "toFloat", { enumerable: true, get: function () { return ratio_1.toFloat; } });
|
|
13
|
+
Object.defineProperty(exports, "reduceRatio", { enumerable: true, get: function () { return ratio_1.reduceRatio; } });
|
|
14
|
+
Object.defineProperty(exports, "simplifyRatio", { enumerable: true, get: function () { return ratio_1.simplifyRatio; } });
|
|
6
15
|
const defaultErrorStore = (0, errors_1.createErrorConfigStore)();
|
|
7
16
|
const coreApi = (0, createCoreApi_1.createCoreApi)(defaultErrorStore);
|
|
8
17
|
exports.m = coreApi.m, exports.isMeasurement = coreApi.isMeasurement, exports.assertMatchingUnits = coreApi.assertMatchingUnits, exports.measurementMin = coreApi.measurementMin, exports.measurementMax = coreApi.measurementMax, exports.measurementUnitMetadata = coreApi.measurementUnitMetadata, exports.makeUnitHelper = coreApi.makeUnitHelper, exports.makeUnitHelperFromDefinition = coreApi.makeUnitHelperFromDefinition, exports.makeUnitGuard = coreApi.makeUnitGuard, exports.makeUnitAssert = coreApi.makeUnitAssert, exports.hasCssMethod = coreApi.hasCssMethod, exports.assertUnit = coreApi.assertUnit, exports.assertCondition = coreApi.assertCondition, exports.getErrorConfig = coreApi.getErrorConfig, exports.setErrorConfig = coreApi.setErrorConfig;
|
|
@@ -62,50 +62,36 @@ const createMediaQueryValidation = (core) => {
|
|
|
62
62
|
assertPositive(props.maxHeight, 'maxHeight');
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
-
const parseAspectRatio = (value) => {
|
|
66
|
-
if (value === undefined || value === null)
|
|
67
|
-
return null;
|
|
68
|
-
if (typeof value === 'number')
|
|
69
|
-
return Number.isFinite(value) ? value : null;
|
|
70
|
-
const trimmed = value.trim();
|
|
71
|
-
if (!trimmed)
|
|
72
|
-
return null;
|
|
73
|
-
if (trimmed.includes('/')) {
|
|
74
|
-
const [left, right] = trimmed.split('/');
|
|
75
|
-
if (left === undefined || right === undefined)
|
|
76
|
-
return null;
|
|
77
|
-
const numerator = Number(left.trim());
|
|
78
|
-
const denominator = Number(right.trim());
|
|
79
|
-
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
if (denominator === 0)
|
|
83
|
-
return null;
|
|
84
|
-
return numerator / denominator;
|
|
85
|
-
}
|
|
86
|
-
const parsed = Number(trimmed);
|
|
87
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
88
|
-
};
|
|
89
65
|
const validateMinMaxAspectRatio = (props) => {
|
|
90
66
|
if (!props.minAspectRatio || !props.maxAspectRatio)
|
|
91
67
|
return;
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
68
|
+
const assertRatio = (value, label) => {
|
|
69
|
+
assertCondition((0, core_1.isRatio)(value), `${label} must be a ratio created with r()`);
|
|
70
|
+
};
|
|
71
|
+
assertRatio(props.minAspectRatio, 'minAspectRatio');
|
|
72
|
+
assertRatio(props.maxAspectRatio, 'maxAspectRatio');
|
|
73
|
+
const minRatio = (0, core_1.ratioToFloat)(props.minAspectRatio);
|
|
74
|
+
const maxRatio = (0, core_1.ratioToFloat)(props.maxAspectRatio);
|
|
95
75
|
assertCondition(minRatio <= maxRatio, 'minAspectRatio must be less than or equal to maxAspectRatio');
|
|
96
76
|
};
|
|
97
77
|
const validateAspectRatioValuesPositive = (props) => {
|
|
98
|
-
const
|
|
99
|
-
assertCondition(
|
|
78
|
+
const assertRatio = (value, label) => {
|
|
79
|
+
assertCondition((0, core_1.isRatio)(value), `${label} must be a ratio created with r()`);
|
|
80
|
+
};
|
|
81
|
+
const assertValidPositive = (label, ratio) => {
|
|
82
|
+
assertCondition((0, core_1.ratioToFloat)(ratio) > 0, `${label} must be a valid ratio greater than 0`);
|
|
100
83
|
};
|
|
101
84
|
if (props.aspectRatio !== undefined) {
|
|
102
|
-
|
|
85
|
+
assertRatio(props.aspectRatio, 'aspectRatio');
|
|
86
|
+
assertValidPositive('aspectRatio', props.aspectRatio);
|
|
103
87
|
}
|
|
104
88
|
if (props.minAspectRatio !== undefined) {
|
|
105
|
-
|
|
89
|
+
assertRatio(props.minAspectRatio, 'minAspectRatio');
|
|
90
|
+
assertValidPositive('minAspectRatio', props.minAspectRatio);
|
|
106
91
|
}
|
|
107
92
|
if (props.maxAspectRatio !== undefined) {
|
|
108
|
-
|
|
93
|
+
assertRatio(props.maxAspectRatio, 'maxAspectRatio');
|
|
94
|
+
assertValidPositive('maxAspectRatio', props.maxAspectRatio);
|
|
109
95
|
}
|
|
110
96
|
};
|
|
111
97
|
const validateResolutionValues = (props) => {
|
package/dist/cjs/ratio.js
CHANGED
|
@@ -12,7 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
};
|
|
13
13
|
var _RatioImpl_numerator, _RatioImpl_denominator, _RatioImpl_omitDenominatorWhenOne;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ratioToFloat = exports.simplifyRatio = exports.reduceRatio = exports.normalizeRatio = exports.parseRatio = exports.isRatio = void 0;
|
|
15
|
+
exports.toFloat = exports.ratioToFloat = exports.simplifyRatio = exports.reduceRatio = exports.normalizeRatio = exports.parseRatio = exports.isRatio = void 0;
|
|
16
16
|
exports.r = r;
|
|
17
17
|
class RatioImpl {
|
|
18
18
|
constructor(numerator, denominator, options = {}) {
|
|
@@ -21,10 +21,10 @@ class RatioImpl {
|
|
|
21
21
|
_RatioImpl_denominator.set(this, void 0);
|
|
22
22
|
_RatioImpl_omitDenominatorWhenOne.set(this, void 0);
|
|
23
23
|
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
|
|
24
|
-
throw new Error(
|
|
24
|
+
throw new Error('Ratio values must be finite numbers.');
|
|
25
25
|
}
|
|
26
26
|
if (denominator === 0) {
|
|
27
|
-
throw new Error(
|
|
27
|
+
throw new Error('Ratio denominator cannot be zero.');
|
|
28
28
|
}
|
|
29
29
|
__classPrivateFieldSet(this, _RatioImpl_numerator, numerator, "f");
|
|
30
30
|
__classPrivateFieldSet(this, _RatioImpl_denominator, denominator, "f");
|
|
@@ -56,25 +56,35 @@ class RatioImpl {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
_RatioImpl_numerator = new WeakMap(), _RatioImpl_denominator = new WeakMap(), _RatioImpl_omitDenominatorWhenOne = new WeakMap();
|
|
59
|
-
function r(numeratorOrDenominator,
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
function r(numeratorOrDenominator, denominatorOrOptions, options) {
|
|
60
|
+
const hasOptionsArg = typeof denominatorOrOptions === 'object' &&
|
|
61
|
+
denominatorOrOptions !== null;
|
|
62
|
+
const resolvedOptions = hasOptionsArg
|
|
63
|
+
? denominatorOrOptions
|
|
64
|
+
: options;
|
|
65
|
+
const numerator = numeratorOrDenominator;
|
|
66
|
+
const resolvedDenominator = hasOptionsArg
|
|
67
|
+
? 1
|
|
68
|
+
: denominatorOrOptions !== null && denominatorOrOptions !== void 0 ? denominatorOrOptions : 1;
|
|
69
|
+
const ratio = new RatioImpl(numerator, resolvedDenominator);
|
|
70
|
+
return (resolvedOptions === null || resolvedOptions === void 0 ? void 0 : resolvedOptions.simplify) ? (0, exports.simplifyRatio)(ratio) : ratio;
|
|
63
71
|
}
|
|
64
72
|
const isRatio = (value) => {
|
|
65
|
-
return (typeof value ===
|
|
73
|
+
return (typeof value === 'object' &&
|
|
66
74
|
value !== null &&
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
typeof value.css ===
|
|
71
|
-
typeof value.numerator ===
|
|
72
|
-
typeof value.denominator ===
|
|
75
|
+
'css' in value &&
|
|
76
|
+
'numerator' in value &&
|
|
77
|
+
'denominator' in value &&
|
|
78
|
+
typeof value.css === 'function' &&
|
|
79
|
+
typeof value.numerator === 'function' &&
|
|
80
|
+
typeof value.denominator === 'function');
|
|
73
81
|
};
|
|
74
82
|
exports.isRatio = isRatio;
|
|
75
83
|
const parseRatio = (value) => {
|
|
76
|
-
if (typeof value ===
|
|
77
|
-
return Number.isFinite(value)
|
|
84
|
+
if (typeof value === 'number') {
|
|
85
|
+
return Number.isFinite(value)
|
|
86
|
+
? { numerator: value, denominator: 1 }
|
|
87
|
+
: null;
|
|
78
88
|
}
|
|
79
89
|
if ((0, exports.isRatio)(value)) {
|
|
80
90
|
return { numerator: value.numerator(), denominator: value.denominator() };
|
|
@@ -82,30 +92,34 @@ const parseRatio = (value) => {
|
|
|
82
92
|
const trimmed = value.trim();
|
|
83
93
|
if (!trimmed)
|
|
84
94
|
return null;
|
|
85
|
-
if (trimmed.includes(
|
|
86
|
-
const
|
|
95
|
+
if (trimmed.includes('/') || trimmed.includes(':')) {
|
|
96
|
+
const delimiter = trimmed.includes('/') ? '/' : ':';
|
|
97
|
+
const [left, right] = trimmed.split(delimiter);
|
|
87
98
|
if (left === undefined || right === undefined)
|
|
88
99
|
return null;
|
|
89
100
|
const numerator = Number(left.trim());
|
|
90
101
|
const denominator = Number(right.trim());
|
|
91
|
-
if (!Number.isFinite(numerator) || !Number.isFinite(denominator))
|
|
102
|
+
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
|
|
92
103
|
return null;
|
|
104
|
+
}
|
|
93
105
|
if (denominator === 0)
|
|
94
106
|
return null;
|
|
95
107
|
return { numerator, denominator };
|
|
96
108
|
}
|
|
97
109
|
const parsed = Number(trimmed);
|
|
98
|
-
return Number.isFinite(parsed)
|
|
110
|
+
return Number.isFinite(parsed)
|
|
111
|
+
? { numerator: parsed, denominator: 1 }
|
|
112
|
+
: null;
|
|
99
113
|
};
|
|
100
114
|
exports.parseRatio = parseRatio;
|
|
101
115
|
const normalizeRatio = (ratio) => {
|
|
102
116
|
let numerator = ratio.numerator();
|
|
103
117
|
let denominator = ratio.denominator();
|
|
104
118
|
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
|
|
105
|
-
throw new Error(
|
|
119
|
+
throw new Error('Ratio values must be finite numbers.');
|
|
106
120
|
}
|
|
107
121
|
if (denominator === 0) {
|
|
108
|
-
throw new Error(
|
|
122
|
+
throw new Error('Ratio denominator cannot be zero.');
|
|
109
123
|
}
|
|
110
124
|
if (!Number.isInteger(numerator) || !Number.isInteger(denominator)) {
|
|
111
125
|
return new RatioImpl(numerator, denominator);
|
|
@@ -139,3 +153,5 @@ const simplifyRatio = (ratio) => {
|
|
|
139
153
|
exports.simplifyRatio = simplifyRatio;
|
|
140
154
|
const ratioToFloat = (ratio) => ratio.numerator() / ratio.denominator();
|
|
141
155
|
exports.ratioToFloat = ratioToFloat;
|
|
156
|
+
const toFloat = (ratio) => (0, exports.ratioToFloat)(ratio);
|
|
157
|
+
exports.toFloat = toFloat;
|
package/dist/esm/core.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type UnitCategory, type UnitDefinition, type UnitDefinitionRecord } from './unitDefinitions';
|
|
2
2
|
import { type ErrorConfig, type ErrorCode } from './internal/errors';
|
|
3
|
+
import { r, isRatio, normalizeRatio, parseRatio, ratioToFloat, toFloat, reduceRatio, simplifyRatio, type IRatio, type RatioParts } from './ratio';
|
|
3
4
|
type UnitSymbol = UnitDefinitionRecord[keyof UnitDefinitionRecord]['unit'];
|
|
4
5
|
export type MeasurementString<Unit extends string = UnitSymbol> = `${number}${Unit}`;
|
|
5
6
|
type UnitBrand<Unit extends string> = {
|
|
@@ -306,4 +307,6 @@ export declare const m: {
|
|
|
306
307
|
export type MeasurementUnitDefinition = UnitDefinition;
|
|
307
308
|
export type MeasurementUnitCategory = UnitCategory;
|
|
308
309
|
export { type ErrorConfig, type ErrorCode };
|
|
310
|
+
export { r, isRatio, normalizeRatio, parseRatio, ratioToFloat, toFloat, reduceRatio, simplifyRatio, };
|
|
311
|
+
export type { IRatio, RatioParts };
|
|
309
312
|
//# sourceMappingURL=core.d.ts.map
|
package/dist/esm/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EAC1B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EAC1B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,CAAC,EACD,OAAO,EACP,cAAc,EACd,UAAU,EACV,YAAY,EACZ,OAAO,EACP,WAAW,EACX,aAAa,EACb,KAAK,MAAM,EACX,KAAK,UAAU,EAChB,MAAM,SAAS,CAAC;AAEjB,KAAK,UAAU,GAAG,oBAAoB,CAAC,MAAM,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3E,MAAM,MAAM,iBAAiB,CAAC,IAAI,SAAS,MAAM,GAAG,UAAU,IAC5D,GAAG,MAAM,GAAG,IAAI,E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,OAAO,EACd,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,KAAK,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC;AAKvC,eAAO,MACL,CAAC;;;eA+BihK,CAAC;;;;;;;;;;;GA9BnhK,aAAa,6CACb,mBAAmB,uGACnB,cAAc,6FACd,cAAc,6FACd,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GACvB,cAAc,yDACd,4BAA4B,sFAwB8tP,0BAA0B,WAvBpxP,aAAa,qDACb,cAAc,yDACd,YAAY;;GACZ,UAAU,0GACV,eAAe,mEACf,cAAc,+BACd,cAAc,6BACL,CAAC;AAEZ,MAAM,MAAM,yBAAyB,GAAG,cAAc,CAAC;AACvD,MAAM,MAAM,uBAAuB,GAAG,YAAY,CAAC;AACnD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,CAAC;AAC5C,OAAO,EACL,CAAC,EACD,OAAO,EACP,cAAc,EACd,UAAU,EACV,YAAY,EACZ,OAAO,EACP,WAAW,EACX,aAAa,GACd,CAAC;AACF,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/esm/core.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createCoreApi } from './internal/createCoreApi';
|
|
2
2
|
import { createErrorConfigStore, } from './internal/errors';
|
|
3
|
+
import { r, isRatio, normalizeRatio, parseRatio, ratioToFloat, toFloat, reduceRatio, simplifyRatio, } from './ratio';
|
|
3
4
|
const defaultErrorStore = createErrorConfigStore();
|
|
4
5
|
const coreApi = createCoreApi(defaultErrorStore);
|
|
5
6
|
export const { m, isMeasurement, assertMatchingUnits, measurementMin, measurementMax, measurementUnitMetadata, makeUnitHelper, makeUnitHelperFromDefinition, makeUnitGuard, makeUnitAssert, hasCssMethod, assertUnit, assertCondition, getErrorConfig, setErrorConfig, } = coreApi;
|
|
7
|
+
export { r, isRatio, normalizeRatio, parseRatio, ratioToFloat, toFloat, reduceRatio, simplifyRatio, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMediaQueriesApi.d.ts","sourceRoot":"","sources":["../../../src/internal/createMediaQueriesApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAIzE,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAOL,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAEL,KAAK,uBAAuB,EAE7B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAE5E,KAAK,gBAAgB,GAAG,IAAI,CAC1B,OAAO,EACP,iBAAiB,GAAG,qBAAqB,CAC1C,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,MAAM,gBAAgB;;mCAkCvD,CAAC,SAAS,aAAa,WAAW,CAAC,MACnC,eAAe,iBAAiB,CAAC,C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,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,GACtB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IMeasurement } from '../core';
|
|
2
|
-
type MediaQueryFeatureValue = string | number | IMeasurement;
|
|
1
|
+
import type { IMeasurement, IRatio } from '../core';
|
|
2
|
+
type MediaQueryFeatureValue = string | number | IMeasurement | IRatio;
|
|
3
3
|
type MediaQueryFeatureEmitter = (name: string, value: MediaQueryFeatureValue) => void;
|
|
4
4
|
export type MediaQueryInvalidValueMode = 'allow' | 'log' | 'throw';
|
|
5
5
|
export type MediaQueryLintingMode = 'allow' | 'log' | 'throw';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGpD,KAAK,sBAAsB,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,MAAM,CAAC;AAEtE,KAAK,wBAAwB,GAAG,CAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,sBAAsB,KAC1B,IAAI,CAAC;AAEV,MAAM,MAAM,0BAA0B,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;AACnE,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;AAE9D,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,CAAC,EAAE;QACd,gBAAgB,CAAC,EAAE,0BAA0B,CAAC;QAC9C,WAAW,CAAC,EAAE,qB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S,+BAAoC,KAC5C,wBAkBF,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,OAAO,EAC7C,SAAS,wBAAwB,CAAC,OAAO,CAAC,MAElC,QAAQ,OAAO,KAAG,MAiB3B,CAAC;AAaF,eAAO,MAAM,yBAAyB,GAAI,OAAO,EAC/C,QAAQ,OAAO,EACf,SAAS,wBAAwB,EACjC,YAAY,mBAAmB,CAAC,OAAO,CAAC,EACxC,UAAU,MAAM,KACf,OAqBF,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,UAAU,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,EAChD,YAAW,KAAK,GAAG,OAAO,GAAG,QAAmB,KAC/C,MAaF,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IMeasurement } from '../../core';
|
|
1
|
+
import type { IMeasurement, IRatio } from '../../core';
|
|
2
2
|
import type { MediaQueryBuilderHelpers, MediaQueryValidator } from '../helpers';
|
|
3
3
|
import { type MediaQueryValidation } from '../validation';
|
|
4
|
-
type MediaQueryRatio =
|
|
4
|
+
type MediaQueryRatio = IRatio;
|
|
5
5
|
export interface IMediaQueryDimensions {
|
|
6
6
|
width?: IMeasurement;
|
|
7
7
|
minHeight?: IMeasurement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dimensions.d.ts","sourceRoot":"","sources":["../../../../src/mediaQueries/modules/dimensions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"dimensions.d.ts","sourceRoot":"","sources":["../../../../src/mediaQueries/modules/dimensions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EACV,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,eAAe,CAAC;AAOvB,KAAK,eAAe,GAAG,MAAM,CAAC;AAE9B,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC,WAAW,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;CACxC;AAED,MAAM,MAAM,6BAA6B,GACvC,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;AAE7C,eAAO,MAAM,4BAA4B,GACvC,YAAY,oBAAoB,MAEhC,OAAO,qBAAqB,EAC5B,SAAS,wBAAwB,EACjC,WAAW,6BAA6B,KACvC,IAmHF,CAAC;AAEF,eAAO,MAAM,sBAAsB,UAxH1B,qBAAqB,WACnB,wBAAwB,aACtB,6BAA6B,KACvC,IAuHF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,MAAM,WAAW,CAAC;AAEnB,OAAO,
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/mediaQueries/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,eAAe,EACf,mBAAmB,EAIpB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AA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I,EA4KP,oBAAoB,UArJX,qBAAqB,KAC3B,IAAI,EAqJP,4BAA4B,UAvInB,qBAAqB,KAC3B,IAAI,EAuIP,yBAAyB,UAhHhB,qBAAqB,KAC3B,IAAI,EAgHP,iCAAiC,UA1FxB,qBAAqB,KAC3B,IAAI,EA0FP,wBAAwB,UAvDf,0BAA0B,KAChC,IAuD0B,CAAC;AAEhC,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { applyMediaQueryValidation } from './helpers';
|
|
2
|
-
import { assertCondition, assertMatchingUnits } from '../core';
|
|
2
|
+
import { assertCondition, assertMatchingUnits, isRatio, ratioToFloat, } from '../core';
|
|
3
3
|
const toValidationResult = (error, fallback) => {
|
|
4
4
|
if (error instanceof Error && error.message)
|
|
5
5
|
return error.message;
|
|
@@ -59,50 +59,36 @@ export const createMediaQueryValidation = (core) => {
|
|
|
59
59
|
assertPositive(props.maxHeight, 'maxHeight');
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
const parseAspectRatio = (value) => {
|
|
63
|
-
if (value === undefined || value === null)
|
|
64
|
-
return null;
|
|
65
|
-
if (typeof value === 'number')
|
|
66
|
-
return Number.isFinite(value) ? value : null;
|
|
67
|
-
const trimmed = value.trim();
|
|
68
|
-
if (!trimmed)
|
|
69
|
-
return null;
|
|
70
|
-
if (trimmed.includes('/')) {
|
|
71
|
-
const [left, right] = trimmed.split('/');
|
|
72
|
-
if (left === undefined || right === undefined)
|
|
73
|
-
return null;
|
|
74
|
-
const numerator = Number(left.trim());
|
|
75
|
-
const denominator = Number(right.trim());
|
|
76
|
-
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
if (denominator === 0)
|
|
80
|
-
return null;
|
|
81
|
-
return numerator / denominator;
|
|
82
|
-
}
|
|
83
|
-
const parsed = Number(trimmed);
|
|
84
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
85
|
-
};
|
|
86
62
|
const validateMinMaxAspectRatio = (props) => {
|
|
87
63
|
if (!props.minAspectRatio || !props.maxAspectRatio)
|
|
88
64
|
return;
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
65
|
+
const assertRatio = (value, label) => {
|
|
66
|
+
assertCondition(isRatio(value), `${label} must be a ratio created with r()`);
|
|
67
|
+
};
|
|
68
|
+
assertRatio(props.minAspectRatio, 'minAspectRatio');
|
|
69
|
+
assertRatio(props.maxAspectRatio, 'maxAspectRatio');
|
|
70
|
+
const minRatio = ratioToFloat(props.minAspectRatio);
|
|
71
|
+
const maxRatio = ratioToFloat(props.maxAspectRatio);
|
|
92
72
|
assertCondition(minRatio <= maxRatio, 'minAspectRatio must be less than or equal to maxAspectRatio');
|
|
93
73
|
};
|
|
94
74
|
const validateAspectRatioValuesPositive = (props) => {
|
|
95
|
-
const
|
|
96
|
-
assertCondition(value
|
|
75
|
+
const assertRatio = (value, label) => {
|
|
76
|
+
assertCondition(isRatio(value), `${label} must be a ratio created with r()`);
|
|
77
|
+
};
|
|
78
|
+
const assertValidPositive = (label, ratio) => {
|
|
79
|
+
assertCondition(ratioToFloat(ratio) > 0, `${label} must be a valid ratio greater than 0`);
|
|
97
80
|
};
|
|
98
81
|
if (props.aspectRatio !== undefined) {
|
|
99
|
-
|
|
82
|
+
assertRatio(props.aspectRatio, 'aspectRatio');
|
|
83
|
+
assertValidPositive('aspectRatio', props.aspectRatio);
|
|
100
84
|
}
|
|
101
85
|
if (props.minAspectRatio !== undefined) {
|
|
102
|
-
|
|
86
|
+
assertRatio(props.minAspectRatio, 'minAspectRatio');
|
|
87
|
+
assertValidPositive('minAspectRatio', props.minAspectRatio);
|
|
103
88
|
}
|
|
104
89
|
if (props.maxAspectRatio !== undefined) {
|
|
105
|
-
|
|
90
|
+
assertRatio(props.maxAspectRatio, 'maxAspectRatio');
|
|
91
|
+
assertValidPositive('maxAspectRatio', props.maxAspectRatio);
|
|
106
92
|
}
|
|
107
93
|
};
|
|
108
94
|
const validateResolutionValues = (props) => {
|
package/dist/esm/ratio.d.ts
CHANGED
|
@@ -11,12 +11,17 @@ export type RatioParts = {
|
|
|
11
11
|
numerator: number;
|
|
12
12
|
denominator: number;
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
type RatioCreateOptions = {
|
|
15
|
+
simplify?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare function r(denominator: number, options?: RatioCreateOptions): IRatio;
|
|
18
|
+
export declare function r(numerator: number, denominator: number, options?: RatioCreateOptions): IRatio;
|
|
16
19
|
export declare const isRatio: (value: unknown) => value is IRatio;
|
|
17
20
|
export declare const parseRatio: (value: number | string | IRatio) => RatioParts | null;
|
|
18
21
|
export declare const normalizeRatio: (ratio: IRatio) => IRatio;
|
|
19
22
|
export declare const reduceRatio: (ratio: IRatio) => IRatio;
|
|
20
23
|
export declare const simplifyRatio: (ratio: IRatio) => IRatio;
|
|
21
24
|
export declare const ratioToFloat: (ratio: IRatio) => number;
|
|
25
|
+
export declare const toFloat: (ratio: IRatio) => number;
|
|
26
|
+
export {};
|
|
22
27
|
//# sourceMappingURL=ratio.d.ts.map
|
package/dist/esm/ratio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ratio.d.ts","sourceRoot":"","sources":["../../src/ratio.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,MAAM,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7C,eAAe,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,CAAC;CAClD;AAED,MAAM,MAAM,UAAU,GAAG;I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B,CAAC;AAC5E,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,MAK7C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,MACJ,CAAC;AAE1C,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,KAAG,MAA6B,CAAC"}
|
package/dist/esm/ratio.js
CHANGED
|
@@ -17,10 +17,10 @@ class RatioImpl {
|
|
|
17
17
|
_RatioImpl_denominator.set(this, void 0);
|
|
18
18
|
_RatioImpl_omitDenominatorWhenOne.set(this, void 0);
|
|
19
19
|
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
|
|
20
|
-
throw new Error(
|
|
20
|
+
throw new Error('Ratio values must be finite numbers.');
|
|
21
21
|
}
|
|
22
22
|
if (denominator === 0) {
|
|
23
|
-
throw new Error(
|
|
23
|
+
throw new Error('Ratio denominator cannot be zero.');
|
|
24
24
|
}
|
|
25
25
|
__classPrivateFieldSet(this, _RatioImpl_numerator, numerator, "f");
|
|
26
26
|
__classPrivateFieldSet(this, _RatioImpl_denominator, denominator, "f");
|
|
@@ -52,24 +52,34 @@ class RatioImpl {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
_RatioImpl_numerator = new WeakMap(), _RatioImpl_denominator = new WeakMap(), _RatioImpl_omitDenominatorWhenOne = new WeakMap();
|
|
55
|
-
export function r(numeratorOrDenominator,
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
export function r(numeratorOrDenominator, denominatorOrOptions, options) {
|
|
56
|
+
const hasOptionsArg = typeof denominatorOrOptions === 'object' &&
|
|
57
|
+
denominatorOrOptions !== null;
|
|
58
|
+
const resolvedOptions = hasOptionsArg
|
|
59
|
+
? denominatorOrOptions
|
|
60
|
+
: options;
|
|
61
|
+
const numerator = numeratorOrDenominator;
|
|
62
|
+
const resolvedDenominator = hasOptionsArg
|
|
63
|
+
? 1
|
|
64
|
+
: denominatorOrOptions !== null && denominatorOrOptions !== void 0 ? denominatorOrOptions : 1;
|
|
65
|
+
const ratio = new RatioImpl(numerator, resolvedDenominator);
|
|
66
|
+
return (resolvedOptions === null || resolvedOptions === void 0 ? void 0 : resolvedOptions.simplify) ? simplifyRatio(ratio) : ratio;
|
|
59
67
|
}
|
|
60
68
|
export const isRatio = (value) => {
|
|
61
|
-
return (typeof value ===
|
|
69
|
+
return (typeof value === 'object' &&
|
|
62
70
|
value !== null &&
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
typeof value.css ===
|
|
67
|
-
typeof value.numerator ===
|
|
68
|
-
typeof value.denominator ===
|
|
71
|
+
'css' in value &&
|
|
72
|
+
'numerator' in value &&
|
|
73
|
+
'denominator' in value &&
|
|
74
|
+
typeof value.css === 'function' &&
|
|
75
|
+
typeof value.numerator === 'function' &&
|
|
76
|
+
typeof value.denominator === 'function');
|
|
69
77
|
};
|
|
70
78
|
export const parseRatio = (value) => {
|
|
71
|
-
if (typeof value ===
|
|
72
|
-
return Number.isFinite(value)
|
|
79
|
+
if (typeof value === 'number') {
|
|
80
|
+
return Number.isFinite(value)
|
|
81
|
+
? { numerator: value, denominator: 1 }
|
|
82
|
+
: null;
|
|
73
83
|
}
|
|
74
84
|
if (isRatio(value)) {
|
|
75
85
|
return { numerator: value.numerator(), denominator: value.denominator() };
|
|
@@ -77,29 +87,33 @@ export const parseRatio = (value) => {
|
|
|
77
87
|
const trimmed = value.trim();
|
|
78
88
|
if (!trimmed)
|
|
79
89
|
return null;
|
|
80
|
-
if (trimmed.includes(
|
|
81
|
-
const
|
|
90
|
+
if (trimmed.includes('/') || trimmed.includes(':')) {
|
|
91
|
+
const delimiter = trimmed.includes('/') ? '/' : ':';
|
|
92
|
+
const [left, right] = trimmed.split(delimiter);
|
|
82
93
|
if (left === undefined || right === undefined)
|
|
83
94
|
return null;
|
|
84
95
|
const numerator = Number(left.trim());
|
|
85
96
|
const denominator = Number(right.trim());
|
|
86
|
-
if (!Number.isFinite(numerator) || !Number.isFinite(denominator))
|
|
97
|
+
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
|
|
87
98
|
return null;
|
|
99
|
+
}
|
|
88
100
|
if (denominator === 0)
|
|
89
101
|
return null;
|
|
90
102
|
return { numerator, denominator };
|
|
91
103
|
}
|
|
92
104
|
const parsed = Number(trimmed);
|
|
93
|
-
return Number.isFinite(parsed)
|
|
105
|
+
return Number.isFinite(parsed)
|
|
106
|
+
? { numerator: parsed, denominator: 1 }
|
|
107
|
+
: null;
|
|
94
108
|
};
|
|
95
109
|
export const normalizeRatio = (ratio) => {
|
|
96
110
|
let numerator = ratio.numerator();
|
|
97
111
|
let denominator = ratio.denominator();
|
|
98
112
|
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
|
|
99
|
-
throw new Error(
|
|
113
|
+
throw new Error('Ratio values must be finite numbers.');
|
|
100
114
|
}
|
|
101
115
|
if (denominator === 0) {
|
|
102
|
-
throw new Error(
|
|
116
|
+
throw new Error('Ratio denominator cannot be zero.');
|
|
103
117
|
}
|
|
104
118
|
if (!Number.isInteger(numerator) || !Number.isInteger(denominator)) {
|
|
105
119
|
return new RatioImpl(numerator, denominator);
|
|
@@ -129,3 +143,4 @@ export const simplifyRatio = (ratio) => {
|
|
|
129
143
|
});
|
|
130
144
|
};
|
|
131
145
|
export const ratioToFloat = (ratio) => ratio.numerator() / ratio.denominator();
|
|
146
|
+
export const toFloat = (ratio) => ratioToFloat(ratio);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-calipers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Compile-time unit safety for numeric, unit-bearing CSS values via typed measurements.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"@types/node": "^24.10.1",
|
|
73
73
|
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
74
74
|
"@typescript-eslint/parser": "^8.50.1",
|
|
75
|
-
"@vitest/coverage-v8": "^4.0.14",
|
|
76
75
|
"@vanilla-extract/css": "^1.18.0",
|
|
76
|
+
"@vitest/coverage-v8": "^4.0.14",
|
|
77
77
|
"eslint": "^9.39.2",
|
|
78
78
|
"tsd": "^0.31.0",
|
|
79
79
|
"typescript": "^5.6.3",
|
|
@@ -89,12 +89,13 @@
|
|
|
89
89
|
"prepublishOnly": "node -e \"if (!process.env.CSS_CALIPERS_RELEASE) { console.error('Direct npm publish is disabled; use \\\"npm run release\\\" instead.'); process.exit(1); }\" && npm run test:internal",
|
|
90
90
|
"release": "node scripts/release.mjs",
|
|
91
91
|
"release:dry": "node scripts/release.mjs --dry-run",
|
|
92
|
-
"test": "npm run build && npm run test:core && npm run test:mediaQueries && npm run test:factory && npm run test:dist && npm run test:types && npm run test:tsc && npm run lint && npm run test:internal",
|
|
92
|
+
"test": "npm run build && npm run test:core && npm run test:ratio && npm run test:mediaQueries && npm run test:factory && npm run test:dist && npm run test:types && npm run test:tsc && npm run lint && npm run test:internal",
|
|
93
93
|
"test:mediaQueries": "vitest run tests/runtime/mediaQueries/mediaQueries.src.test.ts",
|
|
94
94
|
"test:mediaQueries:cjs": "vitest run tests/runtime/mediaQueries/mediaQueries.cjs.test.ts tests/runtime/api-surface/mediaQueries.api-surface.cjs.test.ts",
|
|
95
95
|
"test:mediaQueries:esm": "vitest run tests/runtime/mediaQueries/mediaQueries.esm.test.ts tests/runtime/api-surface/mediaQueries.api-surface.esm.test.ts",
|
|
96
96
|
"test:mediaQueries:dist": "npm run test:mediaQueries:cjs && npm run test:mediaQueries:esm",
|
|
97
97
|
"test:core": "vitest run tests/runtime/core/core.src.test.ts",
|
|
98
|
+
"test:ratio": "vitest run tests/runtime/ratio/ratio.src.test.ts",
|
|
98
99
|
"test:core:cjs": "vitest run tests/runtime/core/core.cjs.test.ts tests/runtime/api-surface/api-surface.cjs.test.ts",
|
|
99
100
|
"test:core:esm": "vitest run tests/runtime/core/core.esm.test.ts tests/runtime/api-surface/api-surface.esm.test.ts",
|
|
100
101
|
"test:core:dist": "npm run test:core:cjs && npm run test:core:esm",
|