css-calipers 0.9.3 → 0.9.5
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,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;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMediaQueriesApi = void 0;
|
|
4
|
+
const helpers_1 = require("../mediaQueries/helpers");
|
|
5
|
+
const validation_1 = require("../mediaQueries/validation");
|
|
6
|
+
const mediaQueries_1 = require("../mediaQueries/mediaQueries");
|
|
7
|
+
const modules_1 = require("../mediaQueries/modules");
|
|
8
|
+
const resolution_1 = require("../mediaQueries/modules/resolution");
|
|
9
|
+
const factory_1 = require("../mediaQueries/factory");
|
|
10
|
+
const vanilla_extract_1 = require("../mediaQueries/libraryHelpers/vanilla-extract");
|
|
11
|
+
const createMediaQueriesApi = (core) => {
|
|
12
|
+
const validation = (0, validation_1.createMediaQueryValidation)({
|
|
13
|
+
assertCondition: core.assertCondition,
|
|
14
|
+
assertMatchingUnits: core.assertMatchingUnits,
|
|
15
|
+
});
|
|
16
|
+
const emitCoreFeatures = (0, mediaQueries_1.createEmitCoreFeatures)(validation);
|
|
17
|
+
const emitDimensionsFeatures = (0, modules_1.createEmitDimensionsFeatures)(validation);
|
|
18
|
+
const emitResolutionFeatures = (0, resolution_1.createEmitResolutionFeatures)(validation);
|
|
19
|
+
const emitBaseFeatures = (props, helpers) => {
|
|
20
|
+
emitCoreFeatures(props, helpers);
|
|
21
|
+
emitDimensionsFeatures(props, helpers);
|
|
22
|
+
emitResolutionFeatures(props, helpers);
|
|
23
|
+
(0, modules_1.emitInteractionFeatures)(props, helpers);
|
|
24
|
+
(0, modules_1.emitPreferencesFeatures)(props, helpers);
|
|
25
|
+
(0, modules_1.emitDisplayFeatures)(props, helpers);
|
|
26
|
+
(0, modules_1.emitEnvironmentFeatures)(props, helpers);
|
|
27
|
+
(0, modules_1.emitCustomFeatures)(props, helpers);
|
|
28
|
+
};
|
|
29
|
+
const buildMediaQueryString = (0, helpers_1.createMediaQueryBuilder)({
|
|
30
|
+
emitBase: emitBaseFeatures,
|
|
31
|
+
resolveType: (props) => props.type,
|
|
32
|
+
});
|
|
33
|
+
const makeMediaQueryStyle = (queries) => (stylesByQuery) => {
|
|
34
|
+
const result = {};
|
|
35
|
+
Object.keys(stylesByQuery).forEach((key) => {
|
|
36
|
+
const styles = stylesByQuery[key];
|
|
37
|
+
const props = queries[key];
|
|
38
|
+
if (!styles || !props)
|
|
39
|
+
return;
|
|
40
|
+
result[buildMediaQueryString(props)] = styles;
|
|
41
|
+
});
|
|
42
|
+
const mediaQuery = {
|
|
43
|
+
'@media': result,
|
|
44
|
+
};
|
|
45
|
+
return mediaQuery;
|
|
46
|
+
};
|
|
47
|
+
const moduleEmitters = {
|
|
48
|
+
core: emitCoreFeatures,
|
|
49
|
+
dimensions: emitDimensionsFeatures,
|
|
50
|
+
resolution: emitResolutionFeatures,
|
|
51
|
+
interaction: modules_1.emitInteractionFeatures,
|
|
52
|
+
preferences: modules_1.emitPreferencesFeatures,
|
|
53
|
+
display: modules_1.emitDisplayFeatures,
|
|
54
|
+
environment: modules_1.emitEnvironmentFeatures,
|
|
55
|
+
custom: modules_1.emitCustomFeatures,
|
|
56
|
+
};
|
|
57
|
+
const mediaQueryFactory = (0, factory_1.createMediaQueryFactory)(moduleEmitters);
|
|
58
|
+
return {
|
|
59
|
+
buildMediaQueryString,
|
|
60
|
+
makeMediaQueryStyle,
|
|
61
|
+
mediaQueryFactory,
|
|
62
|
+
emitCoreFeatures,
|
|
63
|
+
emitDimensionsFeatures,
|
|
64
|
+
emitResolutionFeatures,
|
|
65
|
+
emitInteractionFeatures: modules_1.emitInteractionFeatures,
|
|
66
|
+
emitPreferencesFeatures: modules_1.emitPreferencesFeatures,
|
|
67
|
+
emitDisplayFeatures: modules_1.emitDisplayFeatures,
|
|
68
|
+
emitEnvironmentFeatures: modules_1.emitEnvironmentFeatures,
|
|
69
|
+
emitCustomFeatures: modules_1.emitCustomFeatures,
|
|
70
|
+
mediaQueryOutputVanillaExtract: vanilla_extract_1.mediaQueryOutputVanillaExtract,
|
|
71
|
+
createMediaQueryBuilder: helpers_1.createMediaQueryBuilder,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
exports.createMediaQueriesApi = createMediaQueriesApi;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createUnitsApi = void 0;
|
|
4
|
+
const unitDefinitions_1 = require("../unitDefinitions");
|
|
5
|
+
const createUnitsApi = (core) => {
|
|
6
|
+
const helpers = Object.keys(unitDefinitions_1.UNIT_DEFINITIONS).reduce((acc, name) => {
|
|
7
|
+
const helperName = name;
|
|
8
|
+
acc[helperName] = core.makeUnitHelperFromDefinition(helperName);
|
|
9
|
+
return acc;
|
|
10
|
+
}, {});
|
|
11
|
+
const mPercent = helpers.mPercent;
|
|
12
|
+
return {
|
|
13
|
+
...helpers,
|
|
14
|
+
isPercentMeasurement: core.makeUnitGuard(mPercent),
|
|
15
|
+
assertPercentMeasurement: core.makeUnitAssert(mPercent),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.createUnitsApi = createUnitsApi;
|
|
@@ -1,17 +1,130 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwHelperError = exports.throwMeasurementMethodError = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.throwHelperError = exports.throwMeasurementMethodError = exports.createErrorHelpers = exports.getErrorConfig = exports.setErrorConfig = exports.createErrorConfigStore = void 0;
|
|
4
|
+
const DEFAULT_ERROR_CONFIG = {
|
|
5
|
+
stackHints: "auto",
|
|
6
|
+
};
|
|
7
|
+
let errorConfig = { ...DEFAULT_ERROR_CONFIG };
|
|
8
|
+
const createErrorConfigStore = (initial = {}) => {
|
|
9
|
+
let config = {
|
|
10
|
+
...DEFAULT_ERROR_CONFIG,
|
|
11
|
+
...initial,
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
getErrorConfig: () => config,
|
|
15
|
+
setErrorConfig: (next) => {
|
|
16
|
+
config = { ...config, ...next };
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.createErrorConfigStore = createErrorConfigStore;
|
|
21
|
+
const setErrorConfig = (next) => {
|
|
22
|
+
errorConfig = { ...errorConfig, ...next };
|
|
23
|
+
};
|
|
24
|
+
exports.setErrorConfig = setErrorConfig;
|
|
25
|
+
const getErrorConfig = () => errorConfig;
|
|
26
|
+
exports.getErrorConfig = getErrorConfig;
|
|
27
|
+
const createErrorHelpers = (store) => {
|
|
28
|
+
const getConfig = () => store.getErrorConfig();
|
|
29
|
+
const throwMeasurementMethodError = (ctx) => {
|
|
30
|
+
const includeStack = shouldIncludeStackHint(ctx.includeStackHint, getConfig());
|
|
31
|
+
const stackHint = includeStack
|
|
32
|
+
? extractStackHint(new Error().stack)
|
|
33
|
+
: undefined;
|
|
34
|
+
throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context, {
|
|
35
|
+
...ctx.details,
|
|
36
|
+
stackHint,
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
39
|
+
const throwHelperError = (ctx) => {
|
|
40
|
+
const includeStack = shouldIncludeStackHint(ctx.includeStackHint, getConfig());
|
|
41
|
+
const stackHint = includeStack
|
|
42
|
+
? extractStackHint(new Error().stack)
|
|
43
|
+
: undefined;
|
|
44
|
+
throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context, {
|
|
45
|
+
...ctx.details,
|
|
46
|
+
stackHint,
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
49
|
+
return { throwMeasurementMethodError, throwHelperError };
|
|
50
|
+
};
|
|
51
|
+
exports.createErrorHelpers = createErrorHelpers;
|
|
52
|
+
const isProductionEnv = () => {
|
|
53
|
+
var _a;
|
|
54
|
+
if (typeof globalThis === "undefined")
|
|
55
|
+
return false;
|
|
56
|
+
const maybeProcess = globalThis
|
|
57
|
+
.process;
|
|
58
|
+
return ((_a = maybeProcess === null || maybeProcess === void 0 ? void 0 : maybeProcess.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === "production";
|
|
59
|
+
};
|
|
60
|
+
const shouldIncludeStackHint = (override, config = errorConfig) => {
|
|
61
|
+
if (override === false)
|
|
62
|
+
return false;
|
|
63
|
+
if (config.stackHints === "off")
|
|
64
|
+
return false;
|
|
65
|
+
if (config.stackHints === "on")
|
|
66
|
+
return true;
|
|
67
|
+
if (override === true)
|
|
68
|
+
return !isProductionEnv();
|
|
69
|
+
return false;
|
|
70
|
+
};
|
|
71
|
+
const formatDetailBlock = (details) => {
|
|
72
|
+
if (!details)
|
|
73
|
+
return "";
|
|
74
|
+
const parts = [];
|
|
75
|
+
if (details.code)
|
|
76
|
+
parts.push(`code=${details.code}`);
|
|
77
|
+
if (details.helper)
|
|
78
|
+
parts.push(`helper=${details.helper}`);
|
|
79
|
+
if (details.inputSummary)
|
|
80
|
+
parts.push(`inputs=${details.inputSummary}`);
|
|
81
|
+
if (details.stackHint)
|
|
82
|
+
parts.push(`stack=${details.stackHint}`);
|
|
83
|
+
return parts.length > 0 ? ` [${parts.join(" | ")}]` : "";
|
|
84
|
+
};
|
|
85
|
+
const formatErrorMessage = (operation, message, context, details) => {
|
|
5
86
|
const core = `${operation}: ${message}`;
|
|
6
|
-
|
|
87
|
+
const base = context ? `${context}: ${core}` : core;
|
|
88
|
+
return `${base}${formatDetailBlock(details)}`;
|
|
89
|
+
};
|
|
90
|
+
const extractStackHint = (stack) => {
|
|
91
|
+
var _a;
|
|
92
|
+
if (!stack)
|
|
93
|
+
return undefined;
|
|
94
|
+
const lines = stack
|
|
95
|
+
.split("\n")
|
|
96
|
+
.map((line) => line.trim())
|
|
97
|
+
.filter(Boolean)
|
|
98
|
+
.slice(1);
|
|
99
|
+
if (lines.length === 0)
|
|
100
|
+
return undefined;
|
|
101
|
+
const filtered = lines.filter((line) => !line.includes("/src/internal/errors") &&
|
|
102
|
+
!line.includes("throwHelperError") &&
|
|
103
|
+
!line.includes("throwMeasurementMethodError"));
|
|
104
|
+
const hint = (_a = filtered[0]) !== null && _a !== void 0 ? _a : lines[0];
|
|
105
|
+
return hint.replace(/^at\s+/, "");
|
|
7
106
|
};
|
|
8
107
|
/** Throw an Error for a Measurement instance method using a structured context. */
|
|
9
108
|
const throwMeasurementMethodError = (ctx) => {
|
|
10
|
-
|
|
109
|
+
const includeStack = shouldIncludeStackHint(ctx.includeStackHint);
|
|
110
|
+
const stackHint = includeStack
|
|
111
|
+
? extractStackHint(new Error().stack)
|
|
112
|
+
: undefined;
|
|
113
|
+
throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context, {
|
|
114
|
+
...ctx.details,
|
|
115
|
+
stackHint,
|
|
116
|
+
}));
|
|
11
117
|
};
|
|
12
118
|
exports.throwMeasurementMethodError = throwMeasurementMethodError;
|
|
13
119
|
/** Throw an Error for a helper/free function using a structured context. */
|
|
14
120
|
const throwHelperError = (ctx) => {
|
|
15
|
-
|
|
121
|
+
const includeStack = shouldIncludeStackHint(ctx.includeStackHint);
|
|
122
|
+
const stackHint = includeStack
|
|
123
|
+
? extractStackHint(new Error().stack)
|
|
124
|
+
: undefined;
|
|
125
|
+
throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context, {
|
|
126
|
+
...ctx.details,
|
|
127
|
+
stackHint,
|
|
128
|
+
}));
|
|
16
129
|
};
|
|
17
130
|
exports.throwHelperError = throwHelperError;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeToArray = void 0;
|
|
4
|
+
const normalizeToArray = (value) => {
|
|
5
|
+
if (value === undefined || value === null)
|
|
6
|
+
return [];
|
|
7
|
+
return Array.isArray(value) ? value : [value];
|
|
8
|
+
};
|
|
9
|
+
exports.normalizeToArray = normalizeToArray;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mediaQueryOutputVanillaExtract = void 0;
|
|
3
|
+
exports.containerQueryOutputVanillaExtract = exports.mediaQueryOutputVanillaExtract = void 0;
|
|
4
4
|
const mediaQueryOutputVanillaExtract = (media) => ({
|
|
5
|
-
|
|
5
|
+
"&": media,
|
|
6
6
|
});
|
|
7
7
|
exports.mediaQueryOutputVanillaExtract = mediaQueryOutputVanillaExtract;
|
|
8
|
+
const containerQueryOutputVanillaExtract = (container) => ({
|
|
9
|
+
"&": container,
|
|
10
|
+
});
|
|
11
|
+
exports.containerQueryOutputVanillaExtract = containerQueryOutputVanillaExtract;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// export type ContentQueryVariable =
|
|
4
|
+
// ContainerQueryModuleKeysMap[keyof ContainerQueryModuleKeysMap];
|
|
5
|
+
// export type ContentQueryComparisonValue = IMeasurement | number | string;
|
|
6
|
+
// export type Comparison<
|
|
7
|
+
// Variable = ContentQueryVariable,
|
|
8
|
+
// Value = ContentQueryComparisonValue
|
|
9
|
+
// > = {
|
|
10
|
+
// variable: Variable;
|
|
11
|
+
// operator: IComparisonOperator;
|
|
12
|
+
// value: Value;
|
|
13
|
+
// };
|
|
14
|
+
// export type ComparisonValue<Value = ContentQueryComparisonValue> = {
|
|
15
|
+
// operator: IComparisonOperator;
|
|
16
|
+
// value: Value;
|
|
17
|
+
// readonly __comparisonBrand: unique symbol;
|
|
18
|
+
// };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mediaQueryFactory = void 0;
|
|
3
|
+
exports.mediaQueryFactory = exports.createMediaQueryFactory = void 0;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
5
|
const mediaQueries_1 = require("./mediaQueries");
|
|
6
6
|
const modules_1 = require("./modules");
|
|
@@ -127,7 +127,7 @@ const runCustomLinter = (props, config) => {
|
|
|
127
127
|
return;
|
|
128
128
|
throw new Error(message);
|
|
129
129
|
};
|
|
130
|
-
const
|
|
130
|
+
const createMediaQueryFactory = (emitters) => (options) => {
|
|
131
131
|
var _a;
|
|
132
132
|
const modules = (_a = options.config.modules) !== null && _a !== void 0 ? _a : ALL_MEDIA_QUERY_MODULES;
|
|
133
133
|
const buildMediaQuery = (0, helpers_1.createMediaQueryBuilder)({
|
|
@@ -136,7 +136,7 @@ const mediaQueryFactory = (options) => {
|
|
|
136
136
|
runCustomValidator(props, options.config);
|
|
137
137
|
runCustomLinter(props, options.config);
|
|
138
138
|
modules.forEach((moduleId) => {
|
|
139
|
-
|
|
139
|
+
emitters[moduleId](props, helpers);
|
|
140
140
|
});
|
|
141
141
|
},
|
|
142
142
|
resolveType: (props) => props.type,
|
|
@@ -159,4 +159,5 @@ const mediaQueryFactory = (options) => {
|
|
|
159
159
|
: mediaQuery;
|
|
160
160
|
};
|
|
161
161
|
};
|
|
162
|
-
exports.
|
|
162
|
+
exports.createMediaQueryFactory = createMediaQueryFactory;
|
|
163
|
+
exports.mediaQueryFactory = (0, exports.createMediaQueryFactory)(MODULE_EMITTERS);
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeMediaQueryStyle = exports.buildMediaQueryString = exports.emitCoreFeatures = void 0;
|
|
3
|
+
exports.makeMediaQueryStyle = exports.buildMediaQueryString = exports.emitCoreFeatures = exports.createEmitCoreFeatures = void 0;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
5
|
const validation_1 = require("./validation");
|
|
6
6
|
const modules_1 = require("./modules");
|
|
7
|
-
const
|
|
8
|
-
|
|
7
|
+
const createEmitCoreFeatures = (validation) => (props, helpers) => {
|
|
8
|
+
const { runMediaQueryValidation, validateMinMaxWidth, validateWidthValuesPositive, } = validation;
|
|
9
|
+
if (!runMediaQueryValidation(props, helpers, validateMinMaxWidth, "core", "minWidth must be less than or equal to maxWidth")) {
|
|
9
10
|
return;
|
|
10
11
|
}
|
|
11
|
-
if (!
|
|
12
|
+
if (!runMediaQueryValidation(props, helpers, validateWidthValuesPositive, "core", "width values must be greater than 0")) {
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
const { addFeature } = helpers;
|
|
@@ -19,7 +20,8 @@ const emitCoreFeatures = (props, helpers) => {
|
|
|
19
20
|
addFeature("max-width", props.maxWidth);
|
|
20
21
|
}
|
|
21
22
|
};
|
|
22
|
-
exports.
|
|
23
|
+
exports.createEmitCoreFeatures = createEmitCoreFeatures;
|
|
24
|
+
exports.emitCoreFeatures = (0, exports.createEmitCoreFeatures)(validation_1.defaultMediaQueryValidation);
|
|
23
25
|
const emitBaseFeatures = (props, helpers) => {
|
|
24
26
|
(0, exports.emitCoreFeatures)(props, helpers);
|
|
25
27
|
(0, modules_1.emitDimensionsFeatures)(props, helpers);
|