css-calipers 0.13.0 → 0.15.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/README.md +21 -25
- package/dist/cjs/factory.js +0 -3
- package/dist/cjs/internal/createCoreApi.js +30 -9
- package/dist/esm/core.d.ts +21 -17
- package/dist/esm/core.d.ts.map +1 -1
- package/dist/esm/factory.d.ts +0 -2
- package/dist/esm/factory.d.ts.map +1 -1
- package/dist/esm/factory.js +0 -3
- package/dist/esm/internal/createCoreApi.d.ts +7 -11
- package/dist/esm/internal/createCoreApi.d.ts.map +1 -1
- package/dist/esm/internal/createCoreApi.js +30 -9
- package/package.json +11 -24
- package/RELEASING.md +0 -62
- package/dist/cjs/comparisons/index.js +0 -25
- package/dist/cjs/containerQueries/containerQueries.js +0 -115
- package/dist/cjs/containerQueries/factory.js +0 -123
- package/dist/cjs/containerQueries/helpers.js +0 -95
- package/dist/cjs/containerQueries/index.js +0 -16
- package/dist/cjs/containerQueries/linting/aspectRatio.js +0 -24
- package/dist/cjs/containerQueries/linting/block.js +0 -23
- package/dist/cjs/containerQueries/linting/core.js +0 -25
- package/dist/cjs/containerQueries/linting/custom.js +0 -11
- package/dist/cjs/containerQueries/linting/inline.js +0 -23
- package/dist/cjs/containerQueries/linting/resolution.js +0 -12
- package/dist/cjs/containerQueries/linting/style.js +0 -28
- package/dist/cjs/containerQueries/linting.js +0 -24
- package/dist/cjs/containerQueries/moduleRegistry.js +0 -5
- package/dist/cjs/containerQueries/modules/aspectRatio.js +0 -51
- package/dist/cjs/containerQueries/modules/block.js +0 -53
- package/dist/cjs/containerQueries/modules/custom.js +0 -43
- package/dist/cjs/containerQueries/modules/index.js +0 -21
- package/dist/cjs/containerQueries/modules/inline.js +0 -53
- package/dist/cjs/containerQueries/modules/size.js +0 -2
- package/dist/cjs/containerQueries/modules/style.js +0 -36
- package/dist/cjs/containerQueries/types.js +0 -2
- package/dist/cjs/containerQueries/validation.js +0 -191
- package/dist/cjs/fraction.js +0 -139
- package/dist/cjs/internal/createComponentQueriesApi.js +0 -56
- package/dist/cjs/internal/createMediaQueriesApi.js +0 -74
- package/dist/cjs/internal/normalizeToArray.js +0 -9
- package/dist/cjs/libraryHelpers/vanilla-extract.js +0 -11
- package/dist/cjs/logicalOperators/index.js +0 -18
- package/dist/cjs/mediaQueries/factory.js +0 -187
- package/dist/cjs/mediaQueries/helpers.js +0 -97
- package/dist/cjs/mediaQueries/index.js +0 -23
- package/dist/cjs/mediaQueries/libraryHelpers/vanilla-extract.js +0 -77
- package/dist/cjs/mediaQueries/linting/core.js +0 -19
- package/dist/cjs/mediaQueries/linting/resolution.js +0 -11
- package/dist/cjs/mediaQueries/linting.js +0 -24
- package/dist/cjs/mediaQueries/mediaQueries.js +0 -53
- package/dist/cjs/mediaQueries/mediaQueryFactory.js +0 -120
- package/dist/cjs/mediaQueries/moduleRegistry.js +0 -5
- package/dist/cjs/mediaQueries/modules/custom.js +0 -26
- package/dist/cjs/mediaQueries/modules/dimensions.js +0 -61
- package/dist/cjs/mediaQueries/modules/display.js +0 -20
- package/dist/cjs/mediaQueries/modules/environment.js +0 -20
- package/dist/cjs/mediaQueries/modules/index.js +0 -23
- package/dist/cjs/mediaQueries/modules/interaction.js +0 -26
- package/dist/cjs/mediaQueries/modules/preferences.js +0 -26
- package/dist/cjs/mediaQueries/modules/resolution.js +0 -31
- package/dist/cjs/mediaQueries/types.js +0 -2
- package/dist/cjs/mediaQueries/validation.js +0 -131
- package/dist/cjs/types.js +0 -2
- package/dist/cjs/validation.js +0 -20
- package/dist/esm/comparisons/index.d.ts +0 -23
- package/dist/esm/comparisons/index.d.ts.map +0 -1
- package/dist/esm/comparisons/index.js +0 -22
- package/dist/esm/containerQueries/containerQueries.d.ts +0 -36
- package/dist/esm/containerQueries/containerQueries.d.ts.map +0 -1
- package/dist/esm/containerQueries/containerQueries.js +0 -109
- package/dist/esm/containerQueries/factory.d.ts +0 -20
- package/dist/esm/containerQueries/factory.d.ts.map +0 -1
- package/dist/esm/containerQueries/factory.js +0 -119
- package/dist/esm/containerQueries/helpers.d.ts +0 -53
- package/dist/esm/containerQueries/helpers.d.ts.map +0 -1
- package/dist/esm/containerQueries/helpers.js +0 -82
- package/dist/esm/containerQueries/index.d.ts +0 -10
- package/dist/esm/containerQueries/index.d.ts.map +0 -1
- package/dist/esm/containerQueries/index.js +0 -4
- package/dist/esm/containerQueries/linting/aspectRatio.d.ts +0 -4
- package/dist/esm/containerQueries/linting/aspectRatio.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/aspectRatio.js +0 -19
- package/dist/esm/containerQueries/linting/block.d.ts +0 -4
- package/dist/esm/containerQueries/linting/block.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/block.js +0 -18
- package/dist/esm/containerQueries/linting/core.d.ts +0 -4
- package/dist/esm/containerQueries/linting/core.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/core.js +0 -20
- package/dist/esm/containerQueries/linting/custom.d.ts +0 -3
- package/dist/esm/containerQueries/linting/custom.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/custom.js +0 -7
- package/dist/esm/containerQueries/linting/inline.d.ts +0 -4
- package/dist/esm/containerQueries/linting/inline.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/inline.js +0 -18
- package/dist/esm/containerQueries/linting/resolution.d.ts +0 -1
- package/dist/esm/containerQueries/linting/resolution.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/resolution.js +0 -12
- package/dist/esm/containerQueries/linting/style.d.ts +0 -3
- package/dist/esm/containerQueries/linting/style.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/style.js +0 -24
- package/dist/esm/containerQueries/linting.d.ts +0 -4
- package/dist/esm/containerQueries/linting.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting.js +0 -20
- package/dist/esm/containerQueries/moduleRegistry.d.ts +0 -25
- package/dist/esm/containerQueries/moduleRegistry.d.ts.map +0 -1
- package/dist/esm/containerQueries/moduleRegistry.js +0 -1
- package/dist/esm/containerQueries/modules/aspectRatio.d.ts +0 -17
- package/dist/esm/containerQueries/modules/aspectRatio.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/aspectRatio.js +0 -47
- package/dist/esm/containerQueries/modules/block.d.ts +0 -20
- package/dist/esm/containerQueries/modules/block.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/block.js +0 -49
- package/dist/esm/containerQueries/modules/custom.d.ts +0 -13
- package/dist/esm/containerQueries/modules/custom.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/custom.js +0 -39
- package/dist/esm/containerQueries/modules/index.d.ts +0 -6
- package/dist/esm/containerQueries/modules/index.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/index.js +0 -5
- package/dist/esm/containerQueries/modules/inline.d.ts +0 -20
- package/dist/esm/containerQueries/modules/inline.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/inline.js +0 -49
- package/dist/esm/containerQueries/modules/size.d.ts +0 -41
- package/dist/esm/containerQueries/modules/size.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/size.js +0 -1
- package/dist/esm/containerQueries/modules/style.d.ts +0 -11
- package/dist/esm/containerQueries/modules/style.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/style.js +0 -32
- package/dist/esm/containerQueries/types.d.ts +0 -81
- package/dist/esm/containerQueries/types.d.ts.map +0 -1
- package/dist/esm/containerQueries/types.js +0 -1
- package/dist/esm/containerQueries/validation.d.ts +0 -41
- package/dist/esm/containerQueries/validation.d.ts.map +0 -1
- package/dist/esm/containerQueries/validation.js +0 -187
- package/dist/esm/fraction.d.ts +0 -23
- package/dist/esm/fraction.d.ts.map +0 -1
- package/dist/esm/fraction.js +0 -129
- package/dist/esm/internal/createComponentQueriesApi.d.ts +0 -34
- package/dist/esm/internal/createComponentQueriesApi.d.ts.map +0 -1
- package/dist/esm/internal/createComponentQueriesApi.js +0 -52
- package/dist/esm/internal/createMediaQueriesApi.d.ts +0 -35
- package/dist/esm/internal/createMediaQueriesApi.d.ts.map +0 -1
- package/dist/esm/internal/createMediaQueriesApi.js +0 -70
- package/dist/esm/internal/normalizeToArray.d.ts +0 -2
- package/dist/esm/internal/normalizeToArray.d.ts.map +0 -1
- package/dist/esm/internal/normalizeToArray.js +0 -5
- package/dist/esm/libraryHelpers/vanilla-extract.d.ts +0 -4
- package/dist/esm/libraryHelpers/vanilla-extract.d.ts.map +0 -1
- package/dist/esm/libraryHelpers/vanilla-extract.js +0 -6
- package/dist/esm/logicalOperators/index.d.ts +0 -2
- package/dist/esm/logicalOperators/index.d.ts.map +0 -1
- package/dist/esm/logicalOperators/index.js +0 -17
- package/dist/esm/mediaQueries/factory.d.ts +0 -45
- package/dist/esm/mediaQueries/factory.d.ts.map +0 -1
- package/dist/esm/mediaQueries/factory.js +0 -183
- package/dist/esm/mediaQueries/helpers.d.ts +0 -40
- package/dist/esm/mediaQueries/helpers.d.ts.map +0 -1
- package/dist/esm/mediaQueries/helpers.js +0 -87
- package/dist/esm/mediaQueries/index.d.ts +0 -8
- package/dist/esm/mediaQueries/index.d.ts.map +0 -1
- package/dist/esm/mediaQueries/index.js +0 -7
- package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts +0 -5
- package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts.map +0 -1
- package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.js +0 -71
- package/dist/esm/mediaQueries/linting/core.d.ts +0 -5
- package/dist/esm/mediaQueries/linting/core.d.ts.map +0 -1
- package/dist/esm/mediaQueries/linting/core.js +0 -14
- package/dist/esm/mediaQueries/linting/resolution.d.ts +0 -3
- package/dist/esm/mediaQueries/linting/resolution.d.ts.map +0 -1
- package/dist/esm/mediaQueries/linting/resolution.js +0 -7
- package/dist/esm/mediaQueries/linting.d.ts +0 -4
- package/dist/esm/mediaQueries/linting.d.ts.map +0 -1
- package/dist/esm/mediaQueries/linting.js +0 -20
- package/dist/esm/mediaQueries/mediaQueries.d.ts +0 -23
- package/dist/esm/mediaQueries/mediaQueries.d.ts.map +0 -1
- package/dist/esm/mediaQueries/mediaQueries.js +0 -48
- package/dist/esm/mediaQueries/moduleRegistry.d.ts +0 -27
- package/dist/esm/mediaQueries/moduleRegistry.d.ts.map +0 -1
- package/dist/esm/mediaQueries/moduleRegistry.js +0 -1
- package/dist/esm/mediaQueries/modules/custom.d.ts +0 -10
- package/dist/esm/mediaQueries/modules/custom.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/custom.js +0 -22
- package/dist/esm/mediaQueries/modules/dimensions.d.ts +0 -19
- package/dist/esm/mediaQueries/modules/dimensions.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/dimensions.js +0 -57
- package/dist/esm/mediaQueries/modules/display.d.ts +0 -9
- package/dist/esm/mediaQueries/modules/display.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/display.js +0 -16
- package/dist/esm/mediaQueries/modules/environment.d.ts +0 -9
- package/dist/esm/mediaQueries/modules/environment.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/environment.js +0 -16
- package/dist/esm/mediaQueries/modules/index.d.ts +0 -8
- package/dist/esm/mediaQueries/modules/index.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/index.js +0 -7
- package/dist/esm/mediaQueries/modules/interaction.d.ts +0 -11
- package/dist/esm/mediaQueries/modules/interaction.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/interaction.js +0 -22
- package/dist/esm/mediaQueries/modules/preferences.d.ts +0 -11
- package/dist/esm/mediaQueries/modules/preferences.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/preferences.js +0 -22
- package/dist/esm/mediaQueries/modules/resolution.d.ts +0 -12
- package/dist/esm/mediaQueries/modules/resolution.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/resolution.js +0 -27
- package/dist/esm/mediaQueries/types.d.ts +0 -117
- package/dist/esm/mediaQueries/types.d.ts.map +0 -1
- package/dist/esm/mediaQueries/types.js +0 -1
- package/dist/esm/mediaQueries/validation.d.ts +0 -34
- package/dist/esm/mediaQueries/validation.d.ts.map +0 -1
- package/dist/esm/mediaQueries/validation.js +0 -127
- package/dist/esm/types.d.ts +0 -35
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -1
- package/dist/esm/validation.d.ts +0 -10
- package/dist/esm/validation.d.ts.map +0 -1
- package/dist/esm/validation.js +0 -15
- package/dist/examples/containerQueries.example.js +0 -54
- package/dist/examples/examples/containerQueries.example.js +0 -54
- package/dist/examples/examples/factory-wrapper.example.js +0 -33
- package/dist/examples/examples/lineHeight-normalizer.example.js +0 -81
- package/dist/examples/examples/mediaQueries-multipleInstances.example.js +0 -127
- package/dist/examples/examples/mixedQueries.example.js +0 -55
- package/dist/examples/examples/validation-and-runtime-checks.example.js +0 -85
- package/dist/examples/examples/validation-unit-tests.example.js +0 -35
- package/dist/examples/factory-wrapper.example.js +0 -33
- package/dist/examples/lineHeight-normalizer.example.js +0 -81
- package/dist/examples/mediaQueries-multipleInstances.example.js +0 -127
- package/dist/examples/mixedQueries.example.js +0 -60
- package/dist/examples/src/comparisons/index.js +0 -25
- package/dist/examples/src/containerQueries/containerQueries.js +0 -96
- package/dist/examples/src/containerQueries/factory.js +0 -123
- package/dist/examples/src/containerQueries/helpers.js +0 -94
- package/dist/examples/src/containerQueries/index.js +0 -16
- package/dist/examples/src/containerQueries/linting/aspectRatio.js +0 -20
- package/dist/examples/src/containerQueries/linting/block.js +0 -20
- package/dist/examples/src/containerQueries/linting/core.js +0 -19
- package/dist/examples/src/containerQueries/linting/custom.js +0 -11
- package/dist/examples/src/containerQueries/linting/inline.js +0 -20
- package/dist/examples/src/containerQueries/linting/style.js +0 -28
- package/dist/examples/src/containerQueries/linting.js +0 -24
- package/dist/examples/src/containerQueries/moduleRegistry.js +0 -5
- package/dist/examples/src/containerQueries/modules/aspectRatio.js +0 -33
- package/dist/examples/src/containerQueries/modules/block.js +0 -44
- package/dist/examples/src/containerQueries/modules/custom.js +0 -31
- package/dist/examples/src/containerQueries/modules/index.js +0 -21
- package/dist/examples/src/containerQueries/modules/inline.js +0 -44
- package/dist/examples/src/containerQueries/modules/style.js +0 -36
- package/dist/examples/src/containerQueries/types.js +0 -2
- package/dist/examples/src/containerQueries/validation.js +0 -177
- package/dist/examples/src/core.js +0 -16
- package/dist/examples/src/factory.js +0 -21
- package/dist/examples/src/index.js +0 -30
- package/dist/examples/src/internal/buildMeasurementCreationError.js +0 -16
- package/dist/examples/src/internal/createCoreApi.js +0 -336
- package/dist/examples/src/internal/createMediaQueriesApi.js +0 -74
- package/dist/examples/src/internal/createUnitsApi.js +0 -18
- package/dist/examples/src/internal/errors.js +0 -130
- package/dist/examples/src/libraryHelpers/vanilla-extract.js +0 -11
- package/dist/examples/src/mediaQueries/factory.js +0 -163
- package/dist/examples/src/mediaQueries/helpers.js +0 -88
- package/dist/examples/src/mediaQueries/index.js +0 -23
- package/dist/examples/src/mediaQueries/linting/core.js +0 -19
- package/dist/examples/src/mediaQueries/linting/resolution.js +0 -11
- package/dist/examples/src/mediaQueries/linting.js +0 -24
- package/dist/examples/src/mediaQueries/mediaQueries.js +0 -53
- package/dist/examples/src/mediaQueries/moduleRegistry.js +0 -5
- package/dist/examples/src/mediaQueries/modules/custom.js +0 -26
- package/dist/examples/src/mediaQueries/modules/dimensions.js +0 -61
- package/dist/examples/src/mediaQueries/modules/display.js +0 -20
- package/dist/examples/src/mediaQueries/modules/environment.js +0 -20
- package/dist/examples/src/mediaQueries/modules/index.js +0 -23
- package/dist/examples/src/mediaQueries/modules/interaction.js +0 -26
- package/dist/examples/src/mediaQueries/modules/preferences.js +0 -26
- package/dist/examples/src/mediaQueries/modules/resolution.js +0 -31
- package/dist/examples/src/mediaQueries/types.js +0 -2
- package/dist/examples/src/mediaQueries/validation.js +0 -128
- package/dist/examples/src/ratio.js +0 -141
- package/dist/examples/src/types.js +0 -2
- package/dist/examples/src/unitDefinitions.js +0 -67
- package/dist/examples/src/units/absolute.js +0 -11
- package/dist/examples/src/units/angle.js +0 -8
- package/dist/examples/src/units/container.js +0 -10
- package/dist/examples/src/units/font-relative.js +0 -16
- package/dist/examples/src/units/frequency.js +0 -6
- package/dist/examples/src/units/grid.js +0 -5
- package/dist/examples/src/units/percent.js +0 -7
- package/dist/examples/src/units/resolution.js +0 -7
- package/dist/examples/src/units/time.js +0 -6
- package/dist/examples/src/units/viewport-dynamic.js +0 -10
- package/dist/examples/src/units/viewport-large.js +0 -10
- package/dist/examples/src/units/viewport-small.js +0 -10
- package/dist/examples/src/units/viewport.js +0 -10
- package/dist/examples/src/validation.js +0 -20
- package/dist/examples/validation-and-runtime-checks.example.js +0 -85
- package/dist/examples/validation-unit-tests.example.js +0 -35
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultContainerQueryValidation = exports.validateCustomFeatures = exports.validateStyleValues = exports.validateAspectRatioValues = exports.validateBlockSizeValues = exports.validateInlineSizeValues = exports.validateHeightValuesPositive = exports.validateMinMaxHeight = exports.validateWidthValuesPositive = exports.validateMinMaxWidth = exports.runContainerQueryValidation = exports.createContainerQueryValidation = void 0;
|
|
4
|
-
const helpers_1 = require("./helpers");
|
|
5
|
-
const core_1 = require("../core");
|
|
6
|
-
const validation_1 = require("../validation");
|
|
7
|
-
const ratio_1 = require("../ratio");
|
|
8
|
-
const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
9
|
-
const assertMeasurement = (value, label) => {
|
|
10
|
-
(0, core_1.assertCondition)((0, core_1.isMeasurement)(value), `${label} must be a measurement`);
|
|
11
|
-
};
|
|
12
|
-
const assertMeasurementPositive = (value, label) => {
|
|
13
|
-
(0, core_1.assertCondition)(value.getValue() > 0, `${label} must be greater than 0`);
|
|
14
|
-
};
|
|
15
|
-
const assertRatio = (value, label) => {
|
|
16
|
-
(0, core_1.assertCondition)((0, core_1.isRatio)(value), `${label} must be a ratio created with r()`);
|
|
17
|
-
};
|
|
18
|
-
const assertRatioPositive = (value, label) => {
|
|
19
|
-
(0, core_1.assertCondition)(value.numerator() > 0, `${label} numerator must be greater than 0`);
|
|
20
|
-
(0, core_1.assertCondition)(value.denominator() > 0, `${label} denominator must be greater than 0`);
|
|
21
|
-
};
|
|
22
|
-
const isStyleValue = (value) => {
|
|
23
|
-
if (typeof value === "string")
|
|
24
|
-
return true;
|
|
25
|
-
if (isFiniteNumber(value))
|
|
26
|
-
return true;
|
|
27
|
-
if ((0, core_1.hasCssMethod)(value))
|
|
28
|
-
return true;
|
|
29
|
-
return false;
|
|
30
|
-
};
|
|
31
|
-
const createContainerQueryValidation = (core) => {
|
|
32
|
-
const assertCondition = core.assertCondition;
|
|
33
|
-
const assertMatchingUnits = core.assertMatchingUnits;
|
|
34
|
-
const runContainerQueryValidation = (config, helpers, check, context, fallbackMessage = "Invalid container query configuration") => {
|
|
35
|
-
if (!check)
|
|
36
|
-
return true;
|
|
37
|
-
try {
|
|
38
|
-
check(config);
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
const result = (0, validation_1.toValidationResult)(error, fallbackMessage);
|
|
43
|
-
return (0, helpers_1.applyContainerQueryValidation)(config, helpers, () => result, context);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const validateMinMaxWidth = (props) => {
|
|
47
|
-
if (!props.minWidth || !props.maxWidth)
|
|
48
|
-
return;
|
|
49
|
-
assertMatchingUnits(props.minWidth, props.maxWidth, "containerQueries.minMaxWidth");
|
|
50
|
-
assertCondition(props.minWidth.getValue() <= props.maxWidth.getValue(), "minWidth must be less than or equal to maxWidth");
|
|
51
|
-
};
|
|
52
|
-
const validateWidthValuesPositive = (props) => {
|
|
53
|
-
if (props.minWidth) {
|
|
54
|
-
assertMeasurement(props.minWidth, "minWidth");
|
|
55
|
-
assertMeasurementPositive(props.minWidth, "minWidth");
|
|
56
|
-
}
|
|
57
|
-
if (props.maxWidth) {
|
|
58
|
-
assertMeasurement(props.maxWidth, "maxWidth");
|
|
59
|
-
assertMeasurementPositive(props.maxWidth, "maxWidth");
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const validateMinMaxHeight = (props) => {
|
|
63
|
-
if (!props.minHeight || !props.maxHeight)
|
|
64
|
-
return;
|
|
65
|
-
assertMatchingUnits(props.minHeight, props.maxHeight, "containerQueries.minMaxHeight");
|
|
66
|
-
assertCondition(props.minHeight.getValue() <= props.maxHeight.getValue(), "minHeight must be less than or equal to maxHeight");
|
|
67
|
-
};
|
|
68
|
-
const validateHeightValuesPositive = (props) => {
|
|
69
|
-
if (props.minHeight) {
|
|
70
|
-
assertMeasurement(props.minHeight, "minHeight");
|
|
71
|
-
assertMeasurementPositive(props.minHeight, "minHeight");
|
|
72
|
-
}
|
|
73
|
-
if (props.maxHeight) {
|
|
74
|
-
assertMeasurement(props.maxHeight, "maxHeight");
|
|
75
|
-
assertMeasurementPositive(props.maxHeight, "maxHeight");
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const validateInlineSizeValues = (props) => {
|
|
79
|
-
if (props.inlineSize) {
|
|
80
|
-
assertMeasurement(props.inlineSize.value, "inlineSize");
|
|
81
|
-
assertMeasurementPositive(props.inlineSize.value, "inlineSize");
|
|
82
|
-
}
|
|
83
|
-
if (props.inlineSizeRange) {
|
|
84
|
-
assertMeasurement(props.inlineSizeRange.min, "inlineSizeRange.min");
|
|
85
|
-
assertMeasurement(props.inlineSizeRange.max, "inlineSizeRange.max");
|
|
86
|
-
assertMeasurementPositive(props.inlineSizeRange.min, "inlineSizeRange.min");
|
|
87
|
-
assertMeasurementPositive(props.inlineSizeRange.max, "inlineSizeRange.max");
|
|
88
|
-
assertMatchingUnits(props.inlineSizeRange.min, props.inlineSizeRange.max, "containerQueries.inlineSizeRangeUnits");
|
|
89
|
-
assertCondition(props.inlineSizeRange.min.getValue() <=
|
|
90
|
-
props.inlineSizeRange.max.getValue(), "inlineSizeRange min must be less than or equal to max");
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const validateBlockSizeValues = (props) => {
|
|
94
|
-
if (props.blockSize) {
|
|
95
|
-
assertMeasurement(props.blockSize.value, "blockSize");
|
|
96
|
-
assertMeasurementPositive(props.blockSize.value, "blockSize");
|
|
97
|
-
}
|
|
98
|
-
if (props.blockSizeRange) {
|
|
99
|
-
assertMeasurement(props.blockSizeRange.min, "blockSizeRange.min");
|
|
100
|
-
assertMeasurement(props.blockSizeRange.max, "blockSizeRange.max");
|
|
101
|
-
assertMeasurementPositive(props.blockSizeRange.min, "blockSizeRange.min");
|
|
102
|
-
assertMeasurementPositive(props.blockSizeRange.max, "blockSizeRange.max");
|
|
103
|
-
assertMatchingUnits(props.blockSizeRange.min, props.blockSizeRange.max, "containerQueries.blockSizeRangeUnits");
|
|
104
|
-
assertCondition(props.blockSizeRange.min.getValue() <=
|
|
105
|
-
props.blockSizeRange.max.getValue(), "blockSizeRange min must be less than or equal to max");
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const validateAspectRatioValues = (props) => {
|
|
109
|
-
if (props.aspectRatio) {
|
|
110
|
-
assertRatio(props.aspectRatio, "aspectRatio");
|
|
111
|
-
assertRatioPositive(props.aspectRatio, "aspectRatio");
|
|
112
|
-
}
|
|
113
|
-
if (props.minAspectRatio) {
|
|
114
|
-
assertRatio(props.minAspectRatio, "minAspectRatio");
|
|
115
|
-
assertRatioPositive(props.minAspectRatio, "minAspectRatio");
|
|
116
|
-
}
|
|
117
|
-
if (props.maxAspectRatio) {
|
|
118
|
-
assertRatio(props.maxAspectRatio, "maxAspectRatio");
|
|
119
|
-
assertRatioPositive(props.maxAspectRatio, "maxAspectRatio");
|
|
120
|
-
}
|
|
121
|
-
if (props.minAspectRatio && props.maxAspectRatio) {
|
|
122
|
-
const minValue = (0, ratio_1.ratioToFloat)(props.minAspectRatio);
|
|
123
|
-
const maxValue = (0, ratio_1.ratioToFloat)(props.maxAspectRatio);
|
|
124
|
-
assertCondition(minValue <= maxValue, "minAspectRatio must be less than or equal to maxAspectRatio");
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
const validateStyleValues = (props) => {
|
|
128
|
-
if (!props.style)
|
|
129
|
-
return;
|
|
130
|
-
const entries = Object.entries(props.style);
|
|
131
|
-
assertCondition(entries.length > 0, "style conditions must not be empty.");
|
|
132
|
-
entries.forEach(([name, value]) => {
|
|
133
|
-
if (value === undefined || value === null)
|
|
134
|
-
return;
|
|
135
|
-
if (Array.isArray(value)) {
|
|
136
|
-
assertCondition(value.length > 0, `style.${name} must not be empty`);
|
|
137
|
-
value.forEach((entry, index) => {
|
|
138
|
-
assertCondition(isStyleValue(entry), `style.${name}[${index}] must be a primitive or measurement`);
|
|
139
|
-
});
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
assertCondition(isStyleValue(value), `style.${name} must be a primitive or measurement`);
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
const validateCustomFeatures = (props) => {
|
|
146
|
-
if (!props.customFeatures)
|
|
147
|
-
return;
|
|
148
|
-
const entries = Object.entries(props.customFeatures);
|
|
149
|
-
assertCondition(entries.length > 0, "customFeatures should not be empty.");
|
|
150
|
-
entries.forEach(([name, value]) => {
|
|
151
|
-
const trimmedName = name.trim();
|
|
152
|
-
assertCondition(trimmedName.length > 0, "Custom feature name must be non-empty.");
|
|
153
|
-
if (value === undefined || value === null)
|
|
154
|
-
return;
|
|
155
|
-
assertCondition(isStyleValue(value), `Custom feature "${trimmedName}" must be a primitive or a measurement.`);
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
return {
|
|
159
|
-
runContainerQueryValidation,
|
|
160
|
-
validateMinMaxWidth,
|
|
161
|
-
validateWidthValuesPositive,
|
|
162
|
-
validateMinMaxHeight,
|
|
163
|
-
validateHeightValuesPositive,
|
|
164
|
-
validateInlineSizeValues,
|
|
165
|
-
validateBlockSizeValues,
|
|
166
|
-
validateAspectRatioValues,
|
|
167
|
-
validateStyleValues,
|
|
168
|
-
validateCustomFeatures,
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
exports.createContainerQueryValidation = createContainerQueryValidation;
|
|
172
|
-
const defaultContainerQueryValidation = (0, exports.createContainerQueryValidation)({
|
|
173
|
-
assertCondition: core_1.assertCondition,
|
|
174
|
-
assertMatchingUnits: core_1.assertMatchingUnits,
|
|
175
|
-
});
|
|
176
|
-
exports.defaultContainerQueryValidation = defaultContainerQueryValidation;
|
|
177
|
-
exports.runContainerQueryValidation = defaultContainerQueryValidation.runContainerQueryValidation, exports.validateMinMaxWidth = defaultContainerQueryValidation.validateMinMaxWidth, exports.validateWidthValuesPositive = defaultContainerQueryValidation.validateWidthValuesPositive, exports.validateMinMaxHeight = defaultContainerQueryValidation.validateMinMaxHeight, exports.validateHeightValuesPositive = defaultContainerQueryValidation.validateHeightValuesPositive, exports.validateInlineSizeValues = defaultContainerQueryValidation.validateInlineSizeValues, exports.validateBlockSizeValues = defaultContainerQueryValidation.validateBlockSizeValues, exports.validateAspectRatioValues = defaultContainerQueryValidation.validateAspectRatioValues, exports.validateStyleValues = defaultContainerQueryValidation.validateStyleValues, exports.validateCustomFeatures = defaultContainerQueryValidation.validateCustomFeatures;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.simplifyRatio = exports.reduceRatio = exports.r = exports.parseRatio = exports.normalizeRatio = exports.isRatio = exports.ratioToFloat = 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
|
-
const createCoreApi_1 = require("./internal/createCoreApi");
|
|
5
|
-
const errors_1 = require("./internal/errors");
|
|
6
|
-
const ratio_1 = require("./ratio");
|
|
7
|
-
Object.defineProperty(exports, "isRatio", { enumerable: true, get: function () { return ratio_1.isRatio; } });
|
|
8
|
-
Object.defineProperty(exports, "normalizeRatio", { enumerable: true, get: function () { return ratio_1.normalizeRatio; } });
|
|
9
|
-
Object.defineProperty(exports, "parseRatio", { enumerable: true, get: function () { return ratio_1.parseRatio; } });
|
|
10
|
-
Object.defineProperty(exports, "r", { enumerable: true, get: function () { return ratio_1.r; } });
|
|
11
|
-
Object.defineProperty(exports, "ratioToFloat", { enumerable: true, get: function () { return ratio_1.ratioToFloat; } });
|
|
12
|
-
Object.defineProperty(exports, "reduceRatio", { enumerable: true, get: function () { return ratio_1.reduceRatio; } });
|
|
13
|
-
Object.defineProperty(exports, "simplifyRatio", { enumerable: true, get: function () { return ratio_1.simplifyRatio; } });
|
|
14
|
-
const defaultErrorStore = (0, errors_1.createErrorConfigStore)();
|
|
15
|
-
const coreApi = (0, createCoreApi_1.createCoreApi)(defaultErrorStore);
|
|
16
|
-
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;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCalipers = void 0;
|
|
4
|
-
const errors_1 = require("./internal/errors");
|
|
5
|
-
const createCoreApi_1 = require("./internal/createCoreApi");
|
|
6
|
-
const createUnitsApi_1 = require("./internal/createUnitsApi");
|
|
7
|
-
const createMediaQueriesApi_1 = require("./internal/createMediaQueriesApi");
|
|
8
|
-
const createCalipers = (config = {}) => {
|
|
9
|
-
var _a;
|
|
10
|
-
const errorStore = (0, errors_1.createErrorConfigStore)((_a = config.errorConfig) !== null && _a !== void 0 ? _a : {});
|
|
11
|
-
const core = (0, createCoreApi_1.createCoreApi)(errorStore);
|
|
12
|
-
const units = (0, createUnitsApi_1.createUnitsApi)(core);
|
|
13
|
-
const mediaQueries = (0, createMediaQueriesApi_1.createMediaQueriesApi)(core);
|
|
14
|
-
return {
|
|
15
|
-
...core,
|
|
16
|
-
...units,
|
|
17
|
-
mediaQueries,
|
|
18
|
-
units,
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
exports.createCalipers = createCalipers;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./core"), exports);
|
|
18
|
-
__exportStar(require("./units/percent"), exports);
|
|
19
|
-
__exportStar(require("./units/absolute"), exports);
|
|
20
|
-
__exportStar(require("./units/font-relative"), exports);
|
|
21
|
-
__exportStar(require("./units/viewport"), exports);
|
|
22
|
-
__exportStar(require("./units/viewport-small"), exports);
|
|
23
|
-
__exportStar(require("./units/viewport-large"), exports);
|
|
24
|
-
__exportStar(require("./units/viewport-dynamic"), exports);
|
|
25
|
-
__exportStar(require("./units/container"), exports);
|
|
26
|
-
__exportStar(require("./units/angle"), exports);
|
|
27
|
-
__exportStar(require("./units/time"), exports);
|
|
28
|
-
__exportStar(require("./units/frequency"), exports);
|
|
29
|
-
__exportStar(require("./units/resolution"), exports);
|
|
30
|
-
__exportStar(require("./units/grid"), exports);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildMeasurementCreationError = void 0;
|
|
4
|
-
const buildMeasurementCreationError = (value, unit, helper, context) => {
|
|
5
|
-
const code = 'CALIPERS_E_NONFINITE';
|
|
6
|
-
return {
|
|
7
|
-
message: `Non-finite measurement value: ${value}`,
|
|
8
|
-
context,
|
|
9
|
-
details: {
|
|
10
|
-
code,
|
|
11
|
-
helper,
|
|
12
|
-
inputSummary: `value=${value}, unit=${unit}`,
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
exports.buildMeasurementCreationError = buildMeasurementCreationError;
|
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.createCoreApi = void 0;
|
|
15
|
-
const unitDefinitions_1 = require("../unitDefinitions");
|
|
16
|
-
const buildMeasurementCreationError_1 = require("./buildMeasurementCreationError");
|
|
17
|
-
const errors_1 = require("./errors");
|
|
18
|
-
const createCoreApi = (errorStore) => {
|
|
19
|
-
var _Measurement_instances, _a, _Measurement_value, _Measurement_unit, _Measurement_clone;
|
|
20
|
-
const { throwHelperError, throwMeasurementMethodError } = (0, errors_1.createErrorHelpers)(errorStore);
|
|
21
|
-
const assertMatchingUnits = (left, right, context) => {
|
|
22
|
-
const leftUnit = left.getUnit();
|
|
23
|
-
const rightUnit = right.getUnit();
|
|
24
|
-
if (leftUnit !== rightUnit) {
|
|
25
|
-
throwHelperError({
|
|
26
|
-
operation: 'css-calipers.assertMatchingUnits',
|
|
27
|
-
params: [left, right],
|
|
28
|
-
message: `measurement unit mismatch: ${leftUnit} vs ${rightUnit}`,
|
|
29
|
-
context,
|
|
30
|
-
details: { code: 'CALIPERS_E_UNIT_MISMATCH' },
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const deltaToNumber = (base, delta) => {
|
|
35
|
-
if (typeof delta === 'number')
|
|
36
|
-
return delta;
|
|
37
|
-
assertMatchingUnits(base, delta, 'deltaToNumber');
|
|
38
|
-
return delta.getValue();
|
|
39
|
-
};
|
|
40
|
-
class Measurement {
|
|
41
|
-
constructor(value, unit) {
|
|
42
|
-
_Measurement_instances.add(this);
|
|
43
|
-
_Measurement_value.set(this, void 0);
|
|
44
|
-
_Measurement_unit.set(this, void 0);
|
|
45
|
-
if (!Number.isFinite(value)) {
|
|
46
|
-
throwHelperError({
|
|
47
|
-
operation: 'css-calipers.Measurement.constructor',
|
|
48
|
-
params: [],
|
|
49
|
-
message: `Non-finite measurement value: ${value}`,
|
|
50
|
-
details: { code: 'CALIPERS_E_NONFINITE' },
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
const normalizedUnit = unit.toLowerCase();
|
|
54
|
-
__classPrivateFieldSet(this, _Measurement_value, value, "f");
|
|
55
|
-
__classPrivateFieldSet(this, _Measurement_unit, normalizedUnit, "f");
|
|
56
|
-
Object.defineProperty(this, '__unitBrand', {
|
|
57
|
-
value: normalizedUnit,
|
|
58
|
-
enumerable: false,
|
|
59
|
-
configurable: false,
|
|
60
|
-
writable: false,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
css() {
|
|
64
|
-
return `${__classPrivateFieldGet(this, _Measurement_value, "f")}${__classPrivateFieldGet(this, _Measurement_unit, "f")}`;
|
|
65
|
-
}
|
|
66
|
-
toString() {
|
|
67
|
-
return this.css();
|
|
68
|
-
}
|
|
69
|
-
getUnit() {
|
|
70
|
-
return __classPrivateFieldGet(this, _Measurement_unit, "f");
|
|
71
|
-
}
|
|
72
|
-
getValue() {
|
|
73
|
-
return __classPrivateFieldGet(this, _Measurement_value, "f");
|
|
74
|
-
}
|
|
75
|
-
valueOf() {
|
|
76
|
-
return __classPrivateFieldGet(this, _Measurement_value, "f");
|
|
77
|
-
}
|
|
78
|
-
[(_Measurement_value = new WeakMap(), _Measurement_unit = new WeakMap(), _Measurement_instances = new WeakSet(), Symbol.toPrimitive)](hint) {
|
|
79
|
-
if (hint === 'number')
|
|
80
|
-
return __classPrivateFieldGet(this, _Measurement_value, "f");
|
|
81
|
-
return this.css();
|
|
82
|
-
}
|
|
83
|
-
isUnit(expected) {
|
|
84
|
-
return __classPrivateFieldGet(this, _Measurement_unit, "f") === expected.toLowerCase();
|
|
85
|
-
}
|
|
86
|
-
assertUnit(expected, context) {
|
|
87
|
-
if (!this.isUnit(expected)) {
|
|
88
|
-
throwMeasurementMethodError({
|
|
89
|
-
operation: 'css-calipers.Measurement.assertUnit',
|
|
90
|
-
caller: this,
|
|
91
|
-
params: [],
|
|
92
|
-
message: `Expected unit "${expected}", received "${__classPrivateFieldGet(this, _Measurement_unit, "f")}".`,
|
|
93
|
-
context,
|
|
94
|
-
details: { code: 'CALIPERS_E_ASSERT_UNIT' },
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
assert(predicate, message) {
|
|
99
|
-
if (!predicate(this)) {
|
|
100
|
-
throwMeasurementMethodError({
|
|
101
|
-
operation: 'css-calipers.Measurement.assert',
|
|
102
|
-
caller: this,
|
|
103
|
-
params: [],
|
|
104
|
-
message,
|
|
105
|
-
details: { code: 'CALIPERS_E_ASSERT_PREDICATE' },
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
equals(other, strict = true) {
|
|
110
|
-
const otherUnit = other.getUnit();
|
|
111
|
-
if (__classPrivateFieldGet(this, _Measurement_unit, "f") !== otherUnit) {
|
|
112
|
-
if (strict) {
|
|
113
|
-
assertMatchingUnits(this, other, 'equals(strict)');
|
|
114
|
-
}
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
return __classPrivateFieldGet(this, _Measurement_value, "f") === other.getValue();
|
|
118
|
-
}
|
|
119
|
-
compare(other, strict = true) {
|
|
120
|
-
if (strict) {
|
|
121
|
-
assertMatchingUnits(this, other, 'compare(strict)');
|
|
122
|
-
}
|
|
123
|
-
else if (__classPrivateFieldGet(this, _Measurement_unit, "f") !== other.getUnit()) {
|
|
124
|
-
return __classPrivateFieldGet(this, _Measurement_unit, "f") < other.getUnit() ? -1 : 1;
|
|
125
|
-
}
|
|
126
|
-
const diff = __classPrivateFieldGet(this, _Measurement_value, "f") - other.getValue();
|
|
127
|
-
if (diff === 0)
|
|
128
|
-
return 0;
|
|
129
|
-
return diff < 0 ? -1 : 1;
|
|
130
|
-
}
|
|
131
|
-
add(delta) {
|
|
132
|
-
const next = __classPrivateFieldGet(this, _Measurement_value, "f") + deltaToNumber(this, delta);
|
|
133
|
-
return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, next);
|
|
134
|
-
}
|
|
135
|
-
subtract(delta) {
|
|
136
|
-
const next = __classPrivateFieldGet(this, _Measurement_value, "f") - deltaToNumber(this, delta);
|
|
137
|
-
return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, next);
|
|
138
|
-
}
|
|
139
|
-
multiply(factor) {
|
|
140
|
-
if (factor === 1)
|
|
141
|
-
return this;
|
|
142
|
-
if (factor === 0)
|
|
143
|
-
return new _a(0, __classPrivateFieldGet(this, _Measurement_unit, "f"));
|
|
144
|
-
if (factor === -1)
|
|
145
|
-
return new _a(-__classPrivateFieldGet(this, _Measurement_value, "f"), __classPrivateFieldGet(this, _Measurement_unit, "f"));
|
|
146
|
-
return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, __classPrivateFieldGet(this, _Measurement_value, "f") * factor);
|
|
147
|
-
}
|
|
148
|
-
divide(divisor) {
|
|
149
|
-
if (divisor === 1)
|
|
150
|
-
return this;
|
|
151
|
-
if (divisor === 0) {
|
|
152
|
-
throwMeasurementMethodError({
|
|
153
|
-
operation: 'css-calipers.Measurement.divide',
|
|
154
|
-
caller: this,
|
|
155
|
-
params: [],
|
|
156
|
-
message: `Cannot divide ${this.css()} by zero`,
|
|
157
|
-
details: { code: 'CALIPERS_E_DIVIDE_BY_ZERO' },
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
const result = __classPrivateFieldGet(this, _Measurement_value, "f") / divisor;
|
|
161
|
-
if (!Number.isFinite(result)) {
|
|
162
|
-
throwMeasurementMethodError({
|
|
163
|
-
operation: 'css-calipers.Measurement.divide',
|
|
164
|
-
caller: this,
|
|
165
|
-
params: [],
|
|
166
|
-
message: 'Non-finite result',
|
|
167
|
-
details: { code: 'CALIPERS_E_NONFINITE_RESULT' },
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, result);
|
|
171
|
-
}
|
|
172
|
-
double() {
|
|
173
|
-
return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, __classPrivateFieldGet(this, _Measurement_value, "f") * 2);
|
|
174
|
-
}
|
|
175
|
-
half() {
|
|
176
|
-
return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, __classPrivateFieldGet(this, _Measurement_value, "f") / 2);
|
|
177
|
-
}
|
|
178
|
-
negation(shouldNegate = true) {
|
|
179
|
-
return shouldNegate ? __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, -__classPrivateFieldGet(this, _Measurement_value, "f")) : this;
|
|
180
|
-
}
|
|
181
|
-
absolute() {
|
|
182
|
-
return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, Math.abs(__classPrivateFieldGet(this, _Measurement_value, "f")));
|
|
183
|
-
}
|
|
184
|
-
round(precision = 0) {
|
|
185
|
-
const next = precision === 0
|
|
186
|
-
? Math.round(__classPrivateFieldGet(this, _Measurement_value, "f"))
|
|
187
|
-
: Number(__classPrivateFieldGet(this, _Measurement_value, "f").toFixed(precision));
|
|
188
|
-
return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, next);
|
|
189
|
-
}
|
|
190
|
-
floor() {
|
|
191
|
-
return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, Math.floor(__classPrivateFieldGet(this, _Measurement_value, "f")));
|
|
192
|
-
}
|
|
193
|
-
ceil() {
|
|
194
|
-
return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, Math.ceil(__classPrivateFieldGet(this, _Measurement_value, "f")));
|
|
195
|
-
}
|
|
196
|
-
clamp(min, max) {
|
|
197
|
-
assertMatchingUnits(this, min, 'clamp(min)');
|
|
198
|
-
assertMatchingUnits(this, max, 'clamp(max)');
|
|
199
|
-
const minValue = min.getValue();
|
|
200
|
-
const maxValue = max.getValue();
|
|
201
|
-
if (!Number.isFinite(minValue) || !Number.isFinite(maxValue)) {
|
|
202
|
-
throwMeasurementMethodError({
|
|
203
|
-
operation: 'css-calipers.Measurement.clamp',
|
|
204
|
-
caller: this,
|
|
205
|
-
params: [min, max],
|
|
206
|
-
message: 'clamp: expected finite bounds',
|
|
207
|
-
details: { code: 'CALIPERS_E_CLAMP_NONFINITE_BOUNDS' },
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
if (minValue > maxValue) {
|
|
211
|
-
throwMeasurementMethodError({
|
|
212
|
-
operation: 'css-calipers.Measurement.clamp',
|
|
213
|
-
caller: this,
|
|
214
|
-
params: [min, max],
|
|
215
|
-
message: `clamp: min (${min.css()}) must be <= max (${max.css()})`,
|
|
216
|
-
details: { code: 'CALIPERS_E_CLAMP_INVALID_RANGE' },
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
const clamped = Math.min(maxValue, Math.max(minValue, __classPrivateFieldGet(this, _Measurement_value, "f")));
|
|
220
|
-
return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, clamped);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
_a = Measurement, _Measurement_clone = function _Measurement_clone(value) {
|
|
224
|
-
return new _a(value, __classPrivateFieldGet(this, _Measurement_unit, "f"));
|
|
225
|
-
};
|
|
226
|
-
const createMeasurement = (value, unit) => new Measurement(value, unit);
|
|
227
|
-
const isMeasurement = (x) => x instanceof Measurement;
|
|
228
|
-
function m(value, unitOrOptions = 'px', context) {
|
|
229
|
-
var _b;
|
|
230
|
-
const options = unitOrOptions && typeof unitOrOptions === 'object'
|
|
231
|
-
? unitOrOptions
|
|
232
|
-
: { unit: unitOrOptions, context };
|
|
233
|
-
const unit = ((_b = options.unit) !== null && _b !== void 0 ? _b : 'px');
|
|
234
|
-
const contextLabel = options.context;
|
|
235
|
-
const normalizedUnit = unit.toLowerCase();
|
|
236
|
-
if (!Number.isFinite(value)) {
|
|
237
|
-
const errorPayload = (0, buildMeasurementCreationError_1.buildMeasurementCreationError)(value, normalizedUnit, 'm', contextLabel);
|
|
238
|
-
throwHelperError({
|
|
239
|
-
operation: 'css-calipers.m',
|
|
240
|
-
params: [],
|
|
241
|
-
message: errorPayload.message,
|
|
242
|
-
context: errorPayload.context,
|
|
243
|
-
details: errorPayload.details,
|
|
244
|
-
includeStackHint: true,
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
return createMeasurement(value, normalizedUnit);
|
|
248
|
-
}
|
|
249
|
-
const createUnitHelper = (unit, helperName) => {
|
|
250
|
-
const normalizedUnit = unit.toLowerCase();
|
|
251
|
-
const helperLabel = helperName !== null && helperName !== void 0 ? helperName : `makeUnitHelper(${normalizedUnit})`;
|
|
252
|
-
const factory = (value, context) => {
|
|
253
|
-
if (!Number.isFinite(value)) {
|
|
254
|
-
const errorPayload = (0, buildMeasurementCreationError_1.buildMeasurementCreationError)(value, normalizedUnit, helperLabel, context);
|
|
255
|
-
throwHelperError({
|
|
256
|
-
operation: `css-calipers.${helperLabel}`,
|
|
257
|
-
params: [],
|
|
258
|
-
message: errorPayload.message,
|
|
259
|
-
context: errorPayload.context,
|
|
260
|
-
details: errorPayload.details,
|
|
261
|
-
includeStackHint: true,
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
return createMeasurement(value, normalizedUnit);
|
|
265
|
-
};
|
|
266
|
-
return Object.assign(factory, {
|
|
267
|
-
unit: normalizedUnit,
|
|
268
|
-
});
|
|
269
|
-
};
|
|
270
|
-
const makeUnitHelper = (unit) => {
|
|
271
|
-
return createUnitHelper(unit);
|
|
272
|
-
};
|
|
273
|
-
const makeUnitHelperFromDefinition = (name) => createUnitHelper(unitDefinitions_1.UNIT_DEFINITIONS[name].unit, name);
|
|
274
|
-
const measurementUnitMetadata = unitDefinitions_1.UNIT_DEFINITIONS;
|
|
275
|
-
const makeUnitGuard = (helper) => {
|
|
276
|
-
return (value) => isMeasurement(value) && value.isUnit(helper.unit);
|
|
277
|
-
};
|
|
278
|
-
const makeUnitAssert = (helper) => {
|
|
279
|
-
const guard = makeUnitGuard(helper);
|
|
280
|
-
return (value, context) => {
|
|
281
|
-
if (!guard(value)) {
|
|
282
|
-
throwHelperError({
|
|
283
|
-
operation: 'css-calipers.makeUnitAssert',
|
|
284
|
-
params: isMeasurement(value) ? [value] : [],
|
|
285
|
-
message: `Expected unit "${helper.unit}".`,
|
|
286
|
-
context,
|
|
287
|
-
details: { code: 'CALIPERS_E_ASSERT_UNIT' },
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
};
|
|
292
|
-
const hasCssMethod = (x) => {
|
|
293
|
-
return (typeof x === 'object' &&
|
|
294
|
-
x !== null &&
|
|
295
|
-
'css' in x &&
|
|
296
|
-
typeof x.css === 'function');
|
|
297
|
-
};
|
|
298
|
-
const measurementMin = (a, b) => {
|
|
299
|
-
assertMatchingUnits(a, b, 'measurementMin');
|
|
300
|
-
return a.getValue() <= b.getValue() ? a : b;
|
|
301
|
-
};
|
|
302
|
-
const measurementMax = (a, b) => {
|
|
303
|
-
assertMatchingUnits(a, b, 'measurementMax');
|
|
304
|
-
return a.getValue() >= b.getValue() ? a : b;
|
|
305
|
-
};
|
|
306
|
-
const assertUnit = (measurement, expectedUnit, context) => measurement.assertUnit(expectedUnit, context);
|
|
307
|
-
const assertCondition = (condition, message) => {
|
|
308
|
-
const passed = typeof condition === 'function' ? condition() : condition;
|
|
309
|
-
if (!passed) {
|
|
310
|
-
throwHelperError({
|
|
311
|
-
operation: 'css-calipers.assertCondition',
|
|
312
|
-
params: [],
|
|
313
|
-
message,
|
|
314
|
-
details: { code: 'CALIPERS_E_ASSERT_CONDITION' },
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
return {
|
|
319
|
-
m,
|
|
320
|
-
isMeasurement,
|
|
321
|
-
assertMatchingUnits,
|
|
322
|
-
measurementMin,
|
|
323
|
-
measurementMax,
|
|
324
|
-
measurementUnitMetadata,
|
|
325
|
-
makeUnitHelper,
|
|
326
|
-
makeUnitHelperFromDefinition,
|
|
327
|
-
makeUnitGuard,
|
|
328
|
-
makeUnitAssert,
|
|
329
|
-
hasCssMethod,
|
|
330
|
-
assertUnit,
|
|
331
|
-
assertCondition,
|
|
332
|
-
getErrorConfig: errorStore.getErrorConfig,
|
|
333
|
-
setErrorConfig: errorStore.setErrorConfig,
|
|
334
|
-
};
|
|
335
|
-
};
|
|
336
|
-
exports.createCoreApi = createCoreApi;
|