css-calipers 0.9.3 → 0.9.4
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 +100 -0
- package/dist/cjs/comparisons/index.js +25 -0
- package/dist/cjs/containerQueries/containerQueries.js +115 -0
- package/dist/cjs/containerQueries/factory.js +123 -0
- package/dist/cjs/containerQueries/helpers.js +95 -0
- package/dist/cjs/containerQueries/index.js +16 -0
- package/dist/cjs/containerQueries/linting/aspectRatio.js +24 -0
- package/dist/cjs/containerQueries/linting/block.js +23 -0
- package/dist/cjs/containerQueries/linting/core.js +25 -0
- package/dist/cjs/containerQueries/linting/custom.js +11 -0
- package/dist/cjs/containerQueries/linting/inline.js +23 -0
- package/dist/cjs/containerQueries/linting/resolution.js +12 -0
- package/dist/cjs/containerQueries/linting/style.js +28 -0
- package/dist/cjs/containerQueries/linting.js +24 -0
- package/dist/cjs/containerQueries/moduleRegistry.js +5 -0
- package/dist/cjs/containerQueries/modules/aspectRatio.js +51 -0
- package/dist/cjs/containerQueries/modules/block.js +53 -0
- package/dist/cjs/containerQueries/modules/custom.js +43 -0
- package/dist/cjs/containerQueries/modules/index.js +21 -0
- package/dist/cjs/containerQueries/modules/inline.js +53 -0
- package/dist/cjs/containerQueries/modules/size.js +2 -0
- package/dist/cjs/containerQueries/modules/style.js +36 -0
- package/dist/cjs/containerQueries/types.js +2 -0
- package/dist/cjs/containerQueries/validation.js +191 -0
- package/dist/cjs/core.js +5 -278
- package/dist/cjs/factory.js +21 -0
- package/dist/cjs/fraction.js +139 -0
- package/dist/cjs/internal/buildMeasurementCreationError.js +16 -0
- package/dist/cjs/internal/buildMeasurementCreationError.tests.js +5 -0
- package/dist/cjs/internal/createComponentQueriesApi.js +56 -0
- package/dist/cjs/internal/createCoreApi.js +336 -0
- package/dist/cjs/internal/createMediaQueriesApi.js +74 -0
- package/dist/cjs/internal/createUnitsApi.js +18 -0
- package/dist/cjs/internal/errors.js +118 -5
- package/dist/cjs/internal/normalizeToArray.js +9 -0
- package/dist/cjs/libraryHelpers/vanilla-extract.js +6 -2
- package/dist/cjs/logicalOperators/index.js +18 -0
- package/dist/cjs/mediaQueries/factory.js +5 -4
- package/dist/cjs/mediaQueries/mediaQueries.js +7 -5
- package/dist/cjs/mediaQueries/modules/dimensions.js +10 -8
- package/dist/cjs/mediaQueries/modules/resolution.js +6 -4
- package/dist/cjs/mediaQueries/validation.js +128 -116
- package/dist/cjs/ratio.js +141 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/validation.js +20 -0
- package/dist/esm/comparisons/index.d.ts +23 -0
- package/dist/esm/comparisons/index.d.ts.map +1 -0
- package/dist/esm/comparisons/index.js +22 -0
- package/dist/esm/containerQueries/containerQueries.d.ts +36 -0
- package/dist/esm/containerQueries/containerQueries.d.ts.map +1 -0
- package/dist/esm/containerQueries/containerQueries.js +109 -0
- package/dist/esm/containerQueries/factory.d.ts +20 -0
- package/dist/esm/containerQueries/factory.d.ts.map +1 -0
- package/dist/esm/containerQueries/factory.js +119 -0
- package/dist/esm/containerQueries/helpers.d.ts +53 -0
- package/dist/esm/containerQueries/helpers.d.ts.map +1 -0
- package/dist/esm/containerQueries/helpers.js +82 -0
- package/dist/esm/containerQueries/index.d.ts +10 -0
- package/dist/esm/containerQueries/index.d.ts.map +1 -0
- package/dist/esm/containerQueries/index.js +4 -0
- package/dist/esm/containerQueries/linting/aspectRatio.d.ts +4 -0
- package/dist/esm/containerQueries/linting/aspectRatio.d.ts.map +1 -0
- package/dist/esm/containerQueries/linting/aspectRatio.js +19 -0
- package/dist/esm/containerQueries/linting/block.d.ts +4 -0
- package/dist/esm/containerQueries/linting/block.d.ts.map +1 -0
- package/dist/esm/containerQueries/linting/block.js +18 -0
- package/dist/esm/containerQueries/linting/core.d.ts +4 -0
- package/dist/esm/containerQueries/linting/core.d.ts.map +1 -0
- package/dist/esm/containerQueries/linting/core.js +20 -0
- package/dist/esm/containerQueries/linting/custom.d.ts +3 -0
- package/dist/esm/containerQueries/linting/custom.d.ts.map +1 -0
- package/dist/esm/containerQueries/linting/custom.js +7 -0
- package/dist/esm/containerQueries/linting/inline.d.ts +4 -0
- package/dist/esm/containerQueries/linting/inline.d.ts.map +1 -0
- package/dist/esm/containerQueries/linting/inline.js +18 -0
- package/dist/esm/containerQueries/linting/resolution.d.ts +1 -0
- package/dist/esm/containerQueries/linting/resolution.d.ts.map +1 -0
- package/dist/esm/containerQueries/linting/resolution.js +12 -0
- package/dist/esm/containerQueries/linting/style.d.ts +3 -0
- package/dist/esm/containerQueries/linting/style.d.ts.map +1 -0
- package/dist/esm/containerQueries/linting/style.js +24 -0
- package/dist/esm/containerQueries/linting.d.ts +4 -0
- package/dist/esm/containerQueries/linting.d.ts.map +1 -0
- package/dist/esm/containerQueries/linting.js +20 -0
- package/dist/esm/containerQueries/moduleRegistry.d.ts +25 -0
- package/dist/esm/containerQueries/moduleRegistry.d.ts.map +1 -0
- package/dist/esm/containerQueries/moduleRegistry.js +1 -0
- package/dist/esm/containerQueries/modules/aspectRatio.d.ts +17 -0
- package/dist/esm/containerQueries/modules/aspectRatio.d.ts.map +1 -0
- package/dist/esm/containerQueries/modules/aspectRatio.js +47 -0
- package/dist/esm/containerQueries/modules/block.d.ts +20 -0
- package/dist/esm/containerQueries/modules/block.d.ts.map +1 -0
- package/dist/esm/containerQueries/modules/block.js +49 -0
- package/dist/esm/containerQueries/modules/custom.d.ts +13 -0
- package/dist/esm/containerQueries/modules/custom.d.ts.map +1 -0
- package/dist/esm/containerQueries/modules/custom.js +39 -0
- package/dist/esm/containerQueries/modules/index.d.ts +6 -0
- package/dist/esm/containerQueries/modules/index.d.ts.map +1 -0
- package/dist/esm/containerQueries/modules/index.js +5 -0
- package/dist/esm/containerQueries/modules/inline.d.ts +20 -0
- package/dist/esm/containerQueries/modules/inline.d.ts.map +1 -0
- package/dist/esm/containerQueries/modules/inline.js +49 -0
- package/dist/esm/containerQueries/modules/size.d.ts +41 -0
- package/dist/esm/containerQueries/modules/size.d.ts.map +1 -0
- package/dist/esm/containerQueries/modules/size.js +1 -0
- package/dist/esm/containerQueries/modules/style.d.ts +11 -0
- package/dist/esm/containerQueries/modules/style.d.ts.map +1 -0
- package/dist/esm/containerQueries/modules/style.js +32 -0
- package/dist/esm/containerQueries/types.d.ts +81 -0
- package/dist/esm/containerQueries/types.d.ts.map +1 -0
- package/dist/esm/containerQueries/types.js +1 -0
- package/dist/esm/containerQueries/validation.d.ts +41 -0
- package/dist/esm/containerQueries/validation.d.ts.map +1 -0
- package/dist/esm/containerQueries/validation.js +187 -0
- package/dist/esm/core.d.ts +27 -26
- package/dist/esm/core.d.ts.map +1 -1
- package/dist/esm/core.js +5 -266
- package/dist/esm/factory.d.ts +13 -0
- package/dist/esm/factory.d.ts.map +1 -0
- package/dist/esm/factory.js +17 -0
- package/dist/esm/fraction.d.ts +23 -0
- package/dist/esm/fraction.d.ts.map +1 -0
- package/dist/esm/fraction.js +129 -0
- package/dist/esm/internal/buildMeasurementCreationError.d.ts +12 -0
- package/dist/esm/internal/buildMeasurementCreationError.d.ts.map +1 -0
- package/dist/esm/internal/buildMeasurementCreationError.js +12 -0
- package/dist/esm/internal/buildMeasurementCreationError.tests.d.ts +3 -0
- package/dist/esm/internal/buildMeasurementCreationError.tests.d.ts.map +1 -0
- package/dist/esm/internal/buildMeasurementCreationError.tests.js +1 -0
- package/dist/esm/internal/createComponentQueriesApi.d.ts +34 -0
- package/dist/esm/internal/createComponentQueriesApi.d.ts.map +1 -0
- package/dist/esm/internal/createComponentQueriesApi.js +52 -0
- package/dist/esm/internal/createCoreApi.d.ts +289 -0
- package/dist/esm/internal/createCoreApi.d.ts.map +1 -0
- package/dist/esm/internal/createCoreApi.js +332 -0
- package/dist/esm/internal/createMediaQueriesApi.d.ts +35 -0
- package/dist/esm/internal/createMediaQueriesApi.d.ts.map +1 -0
- package/dist/esm/internal/createMediaQueriesApi.js +70 -0
- package/dist/esm/internal/createUnitsApi.d.ts +13 -0
- package/dist/esm/internal/createUnitsApi.d.ts.map +1 -0
- package/dist/esm/internal/createUnitsApi.js +14 -0
- package/dist/esm/internal/errors.d.ts +30 -0
- package/dist/esm/internal/errors.d.ts.map +1 -1
- package/dist/esm/internal/errors.js +113 -4
- package/dist/esm/internal/normalizeToArray.d.ts +2 -0
- package/dist/esm/internal/normalizeToArray.d.ts.map +1 -0
- package/dist/esm/internal/normalizeToArray.js +5 -0
- package/dist/esm/libraryHelpers/vanilla-extract.d.ts +2 -1
- package/dist/esm/libraryHelpers/vanilla-extract.d.ts.map +1 -1
- package/dist/esm/libraryHelpers/vanilla-extract.js +4 -1
- package/dist/esm/logicalOperators/index.d.ts +2 -0
- package/dist/esm/logicalOperators/index.d.ts.map +1 -0
- package/dist/esm/logicalOperators/index.js +17 -0
- package/dist/esm/mediaQueries/factory.d.ts +16 -1
- package/dist/esm/mediaQueries/factory.d.ts.map +1 -1
- package/dist/esm/mediaQueries/factory.js +3 -2
- package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts +2 -2
- package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts.map +1 -1
- package/dist/esm/mediaQueries/mediaQueries.d.ts +2 -0
- package/dist/esm/mediaQueries/mediaQueries.d.ts.map +1 -1
- package/dist/esm/mediaQueries/mediaQueries.js +4 -2
- package/dist/esm/mediaQueries/modules/dimensions.d.ts +2 -0
- package/dist/esm/mediaQueries/modules/dimensions.d.ts.map +1 -1
- package/dist/esm/mediaQueries/modules/dimensions.js +4 -2
- package/dist/esm/mediaQueries/modules/resolution.d.ts +2 -0
- package/dist/esm/mediaQueries/modules/resolution.d.ts.map +1 -1
- package/dist/esm/mediaQueries/modules/resolution.js +4 -2
- package/dist/esm/mediaQueries/validation.d.ts +28 -8
- package/dist/esm/mediaQueries/validation.d.ts.map +1 -1
- package/dist/esm/mediaQueries/validation.js +126 -107
- package/dist/esm/ratio.d.ts +22 -0
- package/dist/esm/ratio.d.ts.map +1 -0
- package/dist/esm/ratio.js +131 -0
- package/dist/esm/types.d.ts +35 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/validation.d.ts +10 -0
- package/dist/esm/validation.d.ts.map +1 -0
- package/dist/esm/validation.js +15 -0
- package/dist/examples/containerQueries.example.js +54 -0
- package/dist/examples/examples/containerQueries.example.js +54 -0
- package/dist/examples/examples/factory-wrapper.example.js +33 -0
- package/dist/examples/examples/lineHeight-normalizer.example.js +81 -0
- package/dist/examples/examples/mediaQueries-multipleInstances.example.js +127 -0
- package/dist/examples/examples/mixedQueries.example.js +55 -0
- package/dist/examples/examples/validation-and-runtime-checks.example.js +85 -0
- package/dist/examples/examples/validation-unit-tests.example.js +35 -0
- package/dist/examples/factory-wrapper.example.js +33 -0
- package/dist/examples/lineHeight-normalizer.example.js +81 -0
- package/dist/examples/mediaQueries-multipleInstances.example.js +127 -0
- package/dist/examples/mixedQueries.example.js +60 -0
- package/dist/examples/src/comparisons/index.js +25 -0
- package/dist/examples/src/containerQueries/containerQueries.js +96 -0
- package/dist/examples/src/containerQueries/factory.js +123 -0
- package/dist/examples/src/containerQueries/helpers.js +94 -0
- package/dist/examples/src/containerQueries/index.js +16 -0
- package/dist/examples/src/containerQueries/linting/aspectRatio.js +20 -0
- package/dist/examples/src/containerQueries/linting/block.js +20 -0
- package/dist/examples/src/containerQueries/linting/core.js +19 -0
- package/dist/examples/src/containerQueries/linting/custom.js +11 -0
- package/dist/examples/src/containerQueries/linting/inline.js +20 -0
- package/dist/examples/src/containerQueries/linting/style.js +28 -0
- package/dist/examples/src/containerQueries/linting.js +24 -0
- package/dist/examples/src/containerQueries/moduleRegistry.js +5 -0
- package/dist/examples/src/containerQueries/modules/aspectRatio.js +33 -0
- package/dist/examples/src/containerQueries/modules/block.js +44 -0
- package/dist/examples/src/containerQueries/modules/custom.js +31 -0
- package/dist/examples/src/containerQueries/modules/index.js +21 -0
- package/dist/examples/src/containerQueries/modules/inline.js +44 -0
- package/dist/examples/src/containerQueries/modules/style.js +36 -0
- package/dist/examples/src/containerQueries/types.js +2 -0
- package/dist/examples/src/containerQueries/validation.js +177 -0
- package/dist/examples/src/core.js +16 -0
- package/dist/examples/src/factory.js +21 -0
- package/dist/examples/src/index.js +30 -0
- package/dist/examples/src/internal/buildMeasurementCreationError.js +16 -0
- package/dist/examples/src/internal/createCoreApi.js +336 -0
- package/dist/examples/src/internal/createMediaQueriesApi.js +74 -0
- package/dist/examples/src/internal/createUnitsApi.js +18 -0
- package/dist/examples/src/internal/errors.js +130 -0
- package/dist/examples/src/libraryHelpers/vanilla-extract.js +11 -0
- package/dist/examples/src/mediaQueries/factory.js +163 -0
- package/dist/examples/src/mediaQueries/helpers.js +88 -0
- package/dist/examples/src/mediaQueries/index.js +23 -0
- package/dist/examples/src/mediaQueries/linting/core.js +19 -0
- package/dist/examples/src/mediaQueries/linting/resolution.js +11 -0
- package/dist/examples/src/mediaQueries/linting.js +24 -0
- package/dist/examples/src/mediaQueries/mediaQueries.js +53 -0
- package/dist/examples/src/mediaQueries/moduleRegistry.js +5 -0
- package/dist/examples/src/mediaQueries/modules/custom.js +26 -0
- package/dist/examples/src/mediaQueries/modules/dimensions.js +61 -0
- package/dist/examples/src/mediaQueries/modules/display.js +20 -0
- package/dist/examples/src/mediaQueries/modules/environment.js +20 -0
- package/dist/examples/src/mediaQueries/modules/index.js +23 -0
- package/dist/examples/src/mediaQueries/modules/interaction.js +26 -0
- package/dist/examples/src/mediaQueries/modules/preferences.js +26 -0
- package/dist/examples/src/mediaQueries/modules/resolution.js +31 -0
- package/dist/examples/src/mediaQueries/types.js +2 -0
- package/dist/examples/src/mediaQueries/validation.js +128 -0
- package/dist/examples/src/ratio.js +141 -0
- package/dist/examples/src/types.js +2 -0
- package/dist/examples/src/unitDefinitions.js +67 -0
- package/dist/examples/src/units/absolute.js +11 -0
- package/dist/examples/src/units/angle.js +8 -0
- package/dist/examples/src/units/container.js +10 -0
- package/dist/examples/src/units/font-relative.js +16 -0
- package/dist/examples/src/units/frequency.js +6 -0
- package/dist/examples/src/units/grid.js +5 -0
- package/dist/examples/src/units/percent.js +7 -0
- package/dist/examples/src/units/resolution.js +7 -0
- package/dist/examples/src/units/time.js +6 -0
- package/dist/examples/src/units/viewport-dynamic.js +10 -0
- package/dist/examples/src/units/viewport-large.js +10 -0
- package/dist/examples/src/units/viewport-small.js +10 -0
- package/dist/examples/src/units/viewport.js +10 -0
- package/dist/examples/src/validation.js +20 -0
- package/dist/examples/validation-and-runtime-checks.example.js +85 -0
- package/dist/examples/validation-unit-tests.example.js +35 -0
- package/package.json +16 -5
|
@@ -0,0 +1,177 @@
|
|
|
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;
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
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);
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
@@ -0,0 +1,336 @@
|
|
|
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;
|