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,131 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
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");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
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");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _RatioImpl_numerator, _RatioImpl_denominator, _RatioImpl_omitDenominatorWhenOne;
|
|
13
|
+
class RatioImpl {
|
|
14
|
+
constructor(numerator, denominator, options = {}) {
|
|
15
|
+
var _a;
|
|
16
|
+
_RatioImpl_numerator.set(this, void 0);
|
|
17
|
+
_RatioImpl_denominator.set(this, void 0);
|
|
18
|
+
_RatioImpl_omitDenominatorWhenOne.set(this, void 0);
|
|
19
|
+
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
|
|
20
|
+
throw new Error("Ratio values must be finite numbers.");
|
|
21
|
+
}
|
|
22
|
+
if (denominator === 0) {
|
|
23
|
+
throw new Error("Ratio denominator cannot be zero.");
|
|
24
|
+
}
|
|
25
|
+
__classPrivateFieldSet(this, _RatioImpl_numerator, numerator, "f");
|
|
26
|
+
__classPrivateFieldSet(this, _RatioImpl_denominator, denominator, "f");
|
|
27
|
+
__classPrivateFieldSet(this, _RatioImpl_omitDenominatorWhenOne, (_a = options.omitDenominatorWhenOne) !== null && _a !== void 0 ? _a : false, "f");
|
|
28
|
+
}
|
|
29
|
+
numerator() {
|
|
30
|
+
return __classPrivateFieldGet(this, _RatioImpl_numerator, "f");
|
|
31
|
+
}
|
|
32
|
+
denominator() {
|
|
33
|
+
return __classPrivateFieldGet(this, _RatioImpl_denominator, "f");
|
|
34
|
+
}
|
|
35
|
+
withNumerator(numerator) {
|
|
36
|
+
return new RatioImpl(numerator, __classPrivateFieldGet(this, _RatioImpl_denominator, "f"));
|
|
37
|
+
}
|
|
38
|
+
withDenominator(denominator) {
|
|
39
|
+
return new RatioImpl(__classPrivateFieldGet(this, _RatioImpl_numerator, "f"), denominator);
|
|
40
|
+
}
|
|
41
|
+
valueOf() {
|
|
42
|
+
return __classPrivateFieldGet(this, _RatioImpl_numerator, "f") / __classPrivateFieldGet(this, _RatioImpl_denominator, "f");
|
|
43
|
+
}
|
|
44
|
+
css() {
|
|
45
|
+
if (__classPrivateFieldGet(this, _RatioImpl_omitDenominatorWhenOne, "f") && __classPrivateFieldGet(this, _RatioImpl_denominator, "f") === 1) {
|
|
46
|
+
return String(__classPrivateFieldGet(this, _RatioImpl_numerator, "f"));
|
|
47
|
+
}
|
|
48
|
+
return `${__classPrivateFieldGet(this, _RatioImpl_numerator, "f")}/${__classPrivateFieldGet(this, _RatioImpl_denominator, "f")}`;
|
|
49
|
+
}
|
|
50
|
+
toString() {
|
|
51
|
+
return this.css();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
_RatioImpl_numerator = new WeakMap(), _RatioImpl_denominator = new WeakMap(), _RatioImpl_omitDenominatorWhenOne = new WeakMap();
|
|
55
|
+
export function r(numeratorOrDenominator, denominator) {
|
|
56
|
+
const numerator = denominator === undefined ? numeratorOrDenominator : numeratorOrDenominator;
|
|
57
|
+
const resolvedDenominator = denominator === undefined ? 1 : denominator;
|
|
58
|
+
return new RatioImpl(numerator, resolvedDenominator);
|
|
59
|
+
}
|
|
60
|
+
export const isRatio = (value) => {
|
|
61
|
+
return (typeof value === "object" &&
|
|
62
|
+
value !== null &&
|
|
63
|
+
"css" in value &&
|
|
64
|
+
"numerator" in value &&
|
|
65
|
+
"denominator" in value &&
|
|
66
|
+
typeof value.css === "function" &&
|
|
67
|
+
typeof value.numerator === "function" &&
|
|
68
|
+
typeof value.denominator === "function");
|
|
69
|
+
};
|
|
70
|
+
export const parseRatio = (value) => {
|
|
71
|
+
if (typeof value === "number") {
|
|
72
|
+
return Number.isFinite(value) ? { numerator: value, denominator: 1 } : null;
|
|
73
|
+
}
|
|
74
|
+
if (isRatio(value)) {
|
|
75
|
+
return { numerator: value.numerator(), denominator: value.denominator() };
|
|
76
|
+
}
|
|
77
|
+
const trimmed = value.trim();
|
|
78
|
+
if (!trimmed)
|
|
79
|
+
return null;
|
|
80
|
+
if (trimmed.includes("/")) {
|
|
81
|
+
const [left, right] = trimmed.split("/");
|
|
82
|
+
if (left === undefined || right === undefined)
|
|
83
|
+
return null;
|
|
84
|
+
const numerator = Number(left.trim());
|
|
85
|
+
const denominator = Number(right.trim());
|
|
86
|
+
if (!Number.isFinite(numerator) || !Number.isFinite(denominator))
|
|
87
|
+
return null;
|
|
88
|
+
if (denominator === 0)
|
|
89
|
+
return null;
|
|
90
|
+
return { numerator, denominator };
|
|
91
|
+
}
|
|
92
|
+
const parsed = Number(trimmed);
|
|
93
|
+
return Number.isFinite(parsed) ? { numerator: parsed, denominator: 1 } : null;
|
|
94
|
+
};
|
|
95
|
+
export const normalizeRatio = (ratio) => {
|
|
96
|
+
let numerator = ratio.numerator();
|
|
97
|
+
let denominator = ratio.denominator();
|
|
98
|
+
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
|
|
99
|
+
throw new Error("Ratio values must be finite numbers.");
|
|
100
|
+
}
|
|
101
|
+
if (denominator === 0) {
|
|
102
|
+
throw new Error("Ratio denominator cannot be zero.");
|
|
103
|
+
}
|
|
104
|
+
if (!Number.isInteger(numerator) || !Number.isInteger(denominator)) {
|
|
105
|
+
return new RatioImpl(numerator, denominator);
|
|
106
|
+
}
|
|
107
|
+
if (denominator < 0) {
|
|
108
|
+
numerator = -numerator;
|
|
109
|
+
denominator = Math.abs(denominator);
|
|
110
|
+
}
|
|
111
|
+
const gcd = (a, b) => {
|
|
112
|
+
let x = Math.abs(a);
|
|
113
|
+
let y = Math.abs(b);
|
|
114
|
+
while (y !== 0) {
|
|
115
|
+
const next = x % y;
|
|
116
|
+
x = y;
|
|
117
|
+
y = next;
|
|
118
|
+
}
|
|
119
|
+
return x === 0 ? 1 : x;
|
|
120
|
+
};
|
|
121
|
+
const divisor = gcd(numerator, denominator);
|
|
122
|
+
return new RatioImpl(numerator / divisor, denominator / divisor);
|
|
123
|
+
};
|
|
124
|
+
export const reduceRatio = (ratio) => normalizeRatio(ratio);
|
|
125
|
+
export const simplifyRatio = (ratio) => {
|
|
126
|
+
const reduced = normalizeRatio(ratio);
|
|
127
|
+
return new RatioImpl(reduced.numerator(), reduced.denominator(), {
|
|
128
|
+
omitDenominatorWhenOne: true,
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
export const ratioToFloat = (ratio) => ratio.numerator() / ratio.denominator();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type Resolve<T> = {
|
|
2
|
+
[Key in keyof T]: T[Key];
|
|
3
|
+
} & {};
|
|
4
|
+
export type CSSVarFunction = string;
|
|
5
|
+
export type MapLeafNodes<T, Leaf> = T extends null ? null : T extends string ? Leaf : T extends object ? {
|
|
6
|
+
[Key in keyof T]: MapLeafNodes<T[Key], Leaf>;
|
|
7
|
+
} : Leaf;
|
|
8
|
+
export type NullableTokens = {
|
|
9
|
+
[key: string]: string | NullableTokens | null;
|
|
10
|
+
};
|
|
11
|
+
export type Tokens = {
|
|
12
|
+
[key: string]: string | Tokens;
|
|
13
|
+
};
|
|
14
|
+
export type ThemeVars<ThemeContract extends NullableTokens> = MapLeafNodes<ThemeContract, CSSVarFunction>;
|
|
15
|
+
export type ClassNames = string | Array<ClassNames>;
|
|
16
|
+
type _PropertySyntax = "<angle>" | "<color>" | "<custom-ident>" | "<image>" | "<integer>" | "<length-percentage>" | "<length>" | "<number>" | "<percentage>" | "<resolution>" | "<string>" | "<time>" | "<transform-function>" | "<transform-list>" | "<url>" | "*";
|
|
17
|
+
type LooseAutocomplete<Suggestions extends string> = Suggestions | Omit<string, Suggestions>;
|
|
18
|
+
export type PropertySyntax = LooseAutocomplete<_PropertySyntax>;
|
|
19
|
+
export type QueryRule<Key extends string, StyleType> = {
|
|
20
|
+
[key in Key]?: {
|
|
21
|
+
[query: string]: Omit<StyleType, Key>;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export type QueryMedia<StyleType> = QueryRule<"@media", StyleType>;
|
|
25
|
+
export type QueryFeature<StyleType> = QueryRule<"@supports", StyleType>;
|
|
26
|
+
export type QueryContainer<StyleType> = QueryRule<"@container", StyleType>;
|
|
27
|
+
export type QueryLayer<StyleType> = QueryRule<"@layer", StyleType>;
|
|
28
|
+
export type QueryStartingStyle<StyleType> = {
|
|
29
|
+
"@starting-style"?: Omit<StyleType, "@starting-style">;
|
|
30
|
+
};
|
|
31
|
+
export interface QueryAll<StyleType> extends QueryMedia<StyleType & QueryAll<StyleType>>, QueryFeature<StyleType & QueryAll<StyleType>>, QueryContainer<StyleType & QueryAll<StyleType>>, QueryLayer<StyleType & QueryAll<StyleType>>, QueryStartingStyle<StyleType> {
|
|
32
|
+
}
|
|
33
|
+
export type WithQuery<StyleType> = StyleType & QueryAll<StyleType>;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;KACtB,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;CACzB,GAAG,EAAE,CAAC;AAEP,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,SAAS,IAAI,GAC9C,IAAI,GACJ,CAAC,SAAS,MAAM,GAChB,IAAI,GACJ,CAAC,SAAS,MAAM,GAChB;KAAG,GAAG,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;CAAE,GAChD,IAAI,CAAC;AAET,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,aAAa,SAAS,cAAc,IAAI,YAAY,CACxE,aAAa,EACb,cAAc,CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;AAEpD,KAAK,eAAe,GAChB,SAAS,GACT,SAAS,GACT,gBAAgB,GAChB,SAAS,GACT,WAAW,GACX,qBAAqB,GACrB,UAAU,GACV,UAAU,GACV,cAAc,GACd,cAAc,GACd,UAAU,GACV,QAAQ,GACR,sBAAsB,GACtB,kBAAkB,GAClB,OAAO,GACP,GAAG,CAAC;AAER,KAAK,iBAAiB,CAAC,WAAW,SAAS,MAAM,IAC7C,WAAW,GACX,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAE9B,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAAC,eAAe,CAAC,CAAC;AAEhE,MAAM,MAAM,SAAS,CAAC,GAAG,SAAS,MAAM,EAAE,SAAS,IAAI;KACpD,GAAG,IAAI,GAAG,CAAC,CAAC,EAAE;QACb,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;KACvC;CACF,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,SAAS,IAAI,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AACnE,MAAM,MAAM,YAAY,CAAC,SAAS,IAAI,SAAS,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AACxE,MAAM,MAAM,cAAc,CAAC,SAAS,IAAI,SAAS,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;AAC3E,MAAM,MAAM,UAAU,CAAC,SAAS,IAAI,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AACnE,MAAM,MAAM,kBAAkB,CAAC,SAAS,IAAI;IAC1C,iBAAiB,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;CACxD,CAAC;AAEF,MAAM,WAAW,QAAQ,CAAC,SAAS,CACjC,SAAQ,UAAU,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EACjD,YAAY,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAC7C,cAAc,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAC/C,UAAU,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAC3C,kBAAkB,CAAC,SAAS,CAAC;CAAG;AAEpC,MAAM,MAAM,SAAS,CAAC,SAAS,IAAI,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ValidationResult = boolean | string | null | undefined | {
|
|
2
|
+
valid: boolean;
|
|
3
|
+
message?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const normalizeValidationResult: (result: ValidationResult) => {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
message?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const toValidationResult: (error: unknown, fallback: string) => ValidationResult;
|
|
10
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB,OAAO,GACP,MAAM,GACN,IAAI,GACJ,SAAS,GACT;IACE,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEN,eAAO,MAAM,yBAAyB,GACpC,QAAQ,gBAAgB,KACvB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAOpC,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,OAAO,OAAO,EACd,UAAU,MAAM,KACf,gBAGF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const normalizeValidationResult = (result) => {
|
|
2
|
+
if (result === undefined || result === null)
|
|
3
|
+
return { valid: true };
|
|
4
|
+
if (typeof result === "boolean")
|
|
5
|
+
return { valid: result };
|
|
6
|
+
if (typeof result === "string") {
|
|
7
|
+
return result ? { valid: false, message: result } : { valid: true };
|
|
8
|
+
}
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
export const toValidationResult = (error, fallback) => {
|
|
12
|
+
if (error instanceof Error && error.message)
|
|
13
|
+
return error.message;
|
|
14
|
+
return fallback;
|
|
15
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Example-only file.
|
|
4
|
+
*
|
|
5
|
+
* This is not part of the public API surface and is not published in the
|
|
6
|
+
* package. It shows how to nest media + container query outputs, including
|
|
7
|
+
* optional vanilla-extract helpers.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const css_1 = require("@vanilla-extract/css");
|
|
11
|
+
const factory_wrapper_example_1 = require("./factory-wrapper.example");
|
|
12
|
+
const containerQueries_1 = require("../src/containerQueries");
|
|
13
|
+
const media = (0, factory_wrapper_example_1.makeMediaQueryStyle)({
|
|
14
|
+
desktop: { minWidth: (0, factory_wrapper_example_1.m)(1024) },
|
|
15
|
+
});
|
|
16
|
+
const container = (0, containerQueries_1.makeContainerQueryStyle)({
|
|
17
|
+
wideCard: {
|
|
18
|
+
inlineSize: { operator: ">=", value: (0, factory_wrapper_example_1.m)(28, "rem") },
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
// const nestedStyles = media({
|
|
22
|
+
// desktop: container({
|
|
23
|
+
// wideCard: {
|
|
24
|
+
// gridTemplateColumns: "1fr 2fr",
|
|
25
|
+
// gridTemplateRows: "none",
|
|
26
|
+
// alignItems: "stretch",
|
|
27
|
+
// },
|
|
28
|
+
// }),
|
|
29
|
+
// });
|
|
30
|
+
const sampleClasses = {
|
|
31
|
+
container: (0, css_1.style)({
|
|
32
|
+
display: "grid",
|
|
33
|
+
}),
|
|
34
|
+
logo: (0, css_1.style)({}),
|
|
35
|
+
text: (0, css_1.style)({}),
|
|
36
|
+
};
|
|
37
|
+
const sampleComponent = `
|
|
38
|
+
<div className={container}>
|
|
39
|
+
<div className={logo}>Logo</div>
|
|
40
|
+
<div className={text}>Some text here</div>
|
|
41
|
+
</div>
|
|
42
|
+
`;
|
|
43
|
+
// const vanillaExtractStyles = mediaQueryOutputVanillaExtract(
|
|
44
|
+
// media({
|
|
45
|
+
// desktop: containerQueryOutputVanillaExtract(
|
|
46
|
+
// container({
|
|
47
|
+
// wideCard: {
|
|
48
|
+
// gridTemplateColumns: "1fr 2fr",
|
|
49
|
+
// gridTemplateRows: "none",
|
|
50
|
+
// },
|
|
51
|
+
// }),
|
|
52
|
+
// ),
|
|
53
|
+
// }),
|
|
54
|
+
// );
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Example-only file.
|
|
4
|
+
*
|
|
5
|
+
* This is not part of the public API surface and is not published in the
|
|
6
|
+
* package. It shows how to nest media + container query outputs, including
|
|
7
|
+
* optional vanilla-extract helpers.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const css_1 = require("@vanilla-extract/css");
|
|
11
|
+
const factory_wrapper_example_1 = require("./factory-wrapper.example");
|
|
12
|
+
const containerQueries_1 = require("../src/containerQueries");
|
|
13
|
+
const media = (0, factory_wrapper_example_1.makeMediaQueryStyle)({
|
|
14
|
+
desktop: { minWidth: (0, factory_wrapper_example_1.m)(1024) },
|
|
15
|
+
});
|
|
16
|
+
const container = (0, containerQueries_1.makeContainerQueryStyle)({
|
|
17
|
+
wideCard: {
|
|
18
|
+
inlineSize: { operator: ">=", value: (0, factory_wrapper_example_1.m)(28, "rem") },
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
// const nestedStyles = media({
|
|
22
|
+
// desktop: container({
|
|
23
|
+
// wideCard: {
|
|
24
|
+
// gridTemplateColumns: "1fr 2fr",
|
|
25
|
+
// gridTemplateRows: "none",
|
|
26
|
+
// alignItems: "stretch",
|
|
27
|
+
// },
|
|
28
|
+
// }),
|
|
29
|
+
// });
|
|
30
|
+
const sampleClasses = {
|
|
31
|
+
container: (0, css_1.style)({
|
|
32
|
+
display: "grid",
|
|
33
|
+
}),
|
|
34
|
+
logo: (0, css_1.style)({}),
|
|
35
|
+
text: (0, css_1.style)({}),
|
|
36
|
+
};
|
|
37
|
+
const sampleComponent = `
|
|
38
|
+
<div className={container}>
|
|
39
|
+
<div className={logo}>Logo</div>
|
|
40
|
+
<div className={text}>Some text here</div>
|
|
41
|
+
</div>
|
|
42
|
+
`;
|
|
43
|
+
// const vanillaExtractStyles = mediaQueryOutputVanillaExtract(
|
|
44
|
+
// media({
|
|
45
|
+
// desktop: containerQueryOutputVanillaExtract(
|
|
46
|
+
// container({
|
|
47
|
+
// wideCard: {
|
|
48
|
+
// gridTemplateColumns: "1fr 2fr",
|
|
49
|
+
// gridTemplateRows: "none",
|
|
50
|
+
// },
|
|
51
|
+
// }),
|
|
52
|
+
// ),
|
|
53
|
+
// }),
|
|
54
|
+
// );
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.m = exports.mVw = exports.mEm = exports.makeMediaQueryStyle = exports.buildMediaQueryString = exports.units = exports.mediaQueries = exports.assertCondition = exports.assertMatchingUnits = exports.mPercent = exports.mPx = void 0;
|
|
4
|
+
const factory_1 = require("css-calipers/factory");
|
|
5
|
+
/**
|
|
6
|
+
* Example wrapper module.
|
|
7
|
+
* Use the factory once, then re-export from here across your app.
|
|
8
|
+
* This keeps a single import path and makes refactors cheaper.
|
|
9
|
+
*/
|
|
10
|
+
const calipers = (0, factory_1.createCalipers)({
|
|
11
|
+
errorConfig: { stackHints: 'on' },
|
|
12
|
+
});
|
|
13
|
+
exports.mPx = calipers.mPx, exports.mPercent = calipers.mPercent, exports.assertMatchingUnits = calipers.assertMatchingUnits, exports.assertCondition = calipers.assertCondition, exports.mediaQueries = calipers.mediaQueries, exports.units = calipers.units;
|
|
14
|
+
exports.buildMediaQueryString = exports.mediaQueries.buildMediaQueryString, exports.makeMediaQueryStyle = exports.mediaQueries.makeMediaQueryStyle;
|
|
15
|
+
exports.mEm = exports.units.mEm, exports.mVw = exports.units.mVw;
|
|
16
|
+
/**
|
|
17
|
+
* Benefit: you can make custom changes in one place without touching call sites.
|
|
18
|
+
* Example wrapper below is intentionally demonstrative, not a recommended m change.
|
|
19
|
+
*/
|
|
20
|
+
const m = (value, unitOrOptions, context) => {
|
|
21
|
+
var _a;
|
|
22
|
+
if (!unitOrOptions) {
|
|
23
|
+
return calipers.m(value, '%', context);
|
|
24
|
+
}
|
|
25
|
+
if (typeof unitOrOptions === 'object') {
|
|
26
|
+
return calipers.m(value, {
|
|
27
|
+
...unitOrOptions,
|
|
28
|
+
unit: (_a = unitOrOptions.unit) !== null && _a !== void 0 ? _a : '%',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return calipers.m(value, unitOrOptions, context);
|
|
32
|
+
};
|
|
33
|
+
exports.m = m;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Example-only file.
|
|
4
|
+
*
|
|
5
|
+
* This is not part of the public API surface and is not published in the
|
|
6
|
+
* package. It exists to demonstrate one way to normalize mixed line-height
|
|
7
|
+
* inputs into a single value with a `.css()` method. See the README for a
|
|
8
|
+
* deeper discussion of this pattern and its trade-offs.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.normalizeLineHeight = void 0;
|
|
12
|
+
const css_calipers_1 = require("css-calipers");
|
|
13
|
+
const parseNumericWithUnit = (raw) => {
|
|
14
|
+
const value = raw.trim();
|
|
15
|
+
const match = value.match(/^(-?\d*\.?\d+)\s*(px|rem|em|%)$/i);
|
|
16
|
+
if (!match)
|
|
17
|
+
return null;
|
|
18
|
+
const [, numeric, unit] = match;
|
|
19
|
+
return {
|
|
20
|
+
value: Number(numeric),
|
|
21
|
+
unit: unit.toLowerCase(),
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const normalizeLineHeight = (value) => {
|
|
25
|
+
// Case 1: bare number (unitless line-height)
|
|
26
|
+
if (typeof value === 'number') {
|
|
27
|
+
return {
|
|
28
|
+
css: () => value,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const trimmed = value.trim();
|
|
32
|
+
// Case 2: numeric value + unit string (for example, "1.5rem", "20px")
|
|
33
|
+
const numericWithUnit = parseNumericWithUnit(trimmed);
|
|
34
|
+
if (numericWithUnit) {
|
|
35
|
+
const measurement = (0, css_calipers_1.m)(numericWithUnit.value, numericWithUnit.unit);
|
|
36
|
+
return measurement;
|
|
37
|
+
}
|
|
38
|
+
// Case 3: unitless numeric string (for example, "1.5")
|
|
39
|
+
const numericValue = Number(trimmed);
|
|
40
|
+
if (!Number.isNaN(numericValue)) {
|
|
41
|
+
return {
|
|
42
|
+
css: () => numericValue,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// Case 4: keywords ("normal") or CSS variables ("var(--body-line-height)")
|
|
46
|
+
// remain opaque CSS strings and resolve at runtime.
|
|
47
|
+
return {
|
|
48
|
+
css: () => trimmed,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.normalizeLineHeight = normalizeLineHeight;
|
|
52
|
+
// Example usages (not executed here; for illustration only):
|
|
53
|
+
const lineHeightFromNumber = (0, exports.normalizeLineHeight)(1.5);
|
|
54
|
+
const lineHeightFromUnitString = (0, exports.normalizeLineHeight)('1.5rem');
|
|
55
|
+
const lineHeightFromNumericString = (0, exports.normalizeLineHeight)('1.5');
|
|
56
|
+
const lineHeightFromKeyword = (0, exports.normalizeLineHeight)('normal');
|
|
57
|
+
const lineHeightFromVar = (0, exports.normalizeLineHeight)('var(--body-line-height)');
|
|
58
|
+
// All normalized values expose a `.css()` method:
|
|
59
|
+
const lineHeightStyles = {
|
|
60
|
+
number: lineHeightFromNumber.css(),
|
|
61
|
+
unitString: lineHeightFromUnitString.css(),
|
|
62
|
+
numericString: lineHeightFromNumericString.css(),
|
|
63
|
+
keyword: lineHeightFromKeyword.css(),
|
|
64
|
+
cssVariable: lineHeightFromVar.css(),
|
|
65
|
+
};
|
|
66
|
+
// Advanced example: if the normalized value happens to be a CSS-Calipers
|
|
67
|
+
// measurement, you can safely do math on it before emitting CSS.
|
|
68
|
+
const baseLineHeight = (0, exports.normalizeLineHeight)('1.4rem');
|
|
69
|
+
const minLineHeight = (0, css_calipers_1.m)(1.2, 'rem');
|
|
70
|
+
const maxLineHeight = (0, css_calipers_1.m)(1.8, 'rem');
|
|
71
|
+
let clampedLineHeight;
|
|
72
|
+
if ((0, css_calipers_1.isMeasurement)(baseLineHeight)) {
|
|
73
|
+
// Here TypeScript knows `baseLineHeight` is an IMeasurement, so you can use
|
|
74
|
+
// unit-aware helpers before emitting.
|
|
75
|
+
const clamped = baseLineHeight.clamp(minLineHeight, maxLineHeight);
|
|
76
|
+
clampedLineHeight = clamped.css();
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// Keywords or CSS variables bypass CSS-Calipers and stay as-is.
|
|
80
|
+
clampedLineHeight = baseLineHeight.css();
|
|
81
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Example-only file.
|
|
4
|
+
*
|
|
5
|
+
* This is not part of the public API surface and is not published in the
|
|
6
|
+
* package. It shows how a page layout and a grid component can use different
|
|
7
|
+
* media query configs (and different breakpoints) in the same codebase.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const css_calipers_1 = require("css-calipers");
|
|
11
|
+
const mediaQueries_1 = require("css-calipers/mediaQueries");
|
|
12
|
+
// Simple helper: grid component uses its own breakpoints and column labels.
|
|
13
|
+
// This helper uses the default builder, which includes all modules.
|
|
14
|
+
const gridBreakpoints = {
|
|
15
|
+
columns_four: { maxWidth: (0, css_calipers_1.m)(1200) },
|
|
16
|
+
columns_three: { maxWidth: (0, css_calipers_1.m)(1024) },
|
|
17
|
+
columns_two: { maxWidth: (0, css_calipers_1.m)(768) },
|
|
18
|
+
columns_one: { maxWidth: (0, css_calipers_1.m)(520) },
|
|
19
|
+
};
|
|
20
|
+
const gridMediaSimple = (0, mediaQueries_1.makeMediaQueryStyle)(gridBreakpoints);
|
|
21
|
+
const gridStylesSimple = {
|
|
22
|
+
display: "grid",
|
|
23
|
+
gap: "16px",
|
|
24
|
+
gridTemplateColumns: "repeat(4, 1fr)",
|
|
25
|
+
...gridMediaSimple({
|
|
26
|
+
columns_four: { gridTemplateColumns: "repeat(4, 1fr)" },
|
|
27
|
+
columns_three: { gridTemplateColumns: "repeat(3, 1fr)" },
|
|
28
|
+
columns_two: { gridTemplateColumns: "repeat(2, 1fr)" },
|
|
29
|
+
columns_one: { gridTemplateColumns: "1fr" },
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
// Multiple instances: page layout and grid component use different configs.
|
|
33
|
+
// Layout uses the standard mobile/tablet/desktop breakpoints and defaults.
|
|
34
|
+
// The default keeps all modules enabled, if you want to limit modules, you
|
|
35
|
+
// can specify what moduels to load explicitely
|
|
36
|
+
const layoutMedia = (0, mediaQueries_1.mediaQueryFactory)({
|
|
37
|
+
queries: {
|
|
38
|
+
mobile: { maxWidth: (0, css_calipers_1.m)(639) },
|
|
39
|
+
tablet: { minWidth: (0, css_calipers_1.m)(640), maxWidth: (0, css_calipers_1.m)(1023) },
|
|
40
|
+
desktop: { minWidth: (0, css_calipers_1.m)(1024) },
|
|
41
|
+
},
|
|
42
|
+
config: { label: "layout" },
|
|
43
|
+
});
|
|
44
|
+
// Grid uses a custom breakpoint map and custom error handling for iteration.
|
|
45
|
+
// Note "core" is explicit here and no other modules will be loaded.
|
|
46
|
+
const gridMedia = (0, mediaQueries_1.mediaQueryFactory)({
|
|
47
|
+
queries: gridBreakpoints,
|
|
48
|
+
config: {
|
|
49
|
+
label: "product-grid",
|
|
50
|
+
modules: ["core"],
|
|
51
|
+
errorHandling: {
|
|
52
|
+
invalidValueMode: "log",
|
|
53
|
+
lintingMode: "log",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
const pageStyles = {
|
|
58
|
+
display: "grid",
|
|
59
|
+
gridTemplateColumns: "repeat(4, 1fr)",
|
|
60
|
+
...layoutMedia({
|
|
61
|
+
mobile: { gridTemplateColumns: "1fr" },
|
|
62
|
+
tablet: { gridTemplateColumns: "repeat(2, 1fr)" },
|
|
63
|
+
desktop: { gridTemplateColumns: "repeat(4, 1fr)" },
|
|
64
|
+
}),
|
|
65
|
+
};
|
|
66
|
+
const gridStyles = {
|
|
67
|
+
display: "grid",
|
|
68
|
+
gap: "16px",
|
|
69
|
+
gridTemplateColumns: "repeat(4, 1fr)",
|
|
70
|
+
...gridMedia({
|
|
71
|
+
columns_four: { gridTemplateColumns: "repeat(4, 1fr)" },
|
|
72
|
+
columns_three: { gridTemplateColumns: "repeat(3, 1fr)" },
|
|
73
|
+
columns_two: { gridTemplateColumns: "repeat(2, 1fr)" },
|
|
74
|
+
columns_one: { gridTemplateColumns: "1fr" },
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
// Advanced example: any-hover with custom validation + linting.
|
|
78
|
+
// Note
|
|
79
|
+
const interactionMedia = (0, mediaQueries_1.mediaQueryFactory)({
|
|
80
|
+
queries: {
|
|
81
|
+
hoverReady: {
|
|
82
|
+
anyHover: "hover",
|
|
83
|
+
anyPointer: "fine",
|
|
84
|
+
reducedMotion: "no-preference",
|
|
85
|
+
},
|
|
86
|
+
hoverDisabled: {
|
|
87
|
+
anyHover: "none",
|
|
88
|
+
anyPointer: "coarse",
|
|
89
|
+
reducedMotion: "reduce",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
config: {
|
|
93
|
+
label: "interaction",
|
|
94
|
+
modules: ["interaction", "preferences"],
|
|
95
|
+
errorHandling: {
|
|
96
|
+
invalidValueMode: "throw",
|
|
97
|
+
lintingMode: "log",
|
|
98
|
+
},
|
|
99
|
+
output: (media) => ({
|
|
100
|
+
label: "interaction",
|
|
101
|
+
media,
|
|
102
|
+
note: "Custom output for advanced example",
|
|
103
|
+
}),
|
|
104
|
+
custom: {
|
|
105
|
+
key: "any-hover-guard",
|
|
106
|
+
validator: (props) => {
|
|
107
|
+
if (props.anyHover && !props.anyPointer) {
|
|
108
|
+
return "anyHover should be paired with anyPointer for clarity";
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
},
|
|
112
|
+
linter: (props) => {
|
|
113
|
+
if (props.anyHover === "none" && props.anyPointer === "fine") {
|
|
114
|
+
return "anyHover none rarely pairs with anyPointer fine";
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
const interactionResult = interactionMedia({
|
|
122
|
+
hoverReady: { cursor: "pointer", transitionDuration: "160ms" },
|
|
123
|
+
hoverDisabled: { cursor: "default", transitionDuration: "0ms" },
|
|
124
|
+
});
|
|
125
|
+
const interactionStyles = {
|
|
126
|
+
...interactionResult.media,
|
|
127
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Example-only file.
|
|
4
|
+
*
|
|
5
|
+
* This is not part of the public API surface and is not published in the
|
|
6
|
+
* package. It shows how to nest media + container query outputs, including
|
|
7
|
+
* optional vanilla-extract helpers.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const css_calipers_1 = require("css-calipers");
|
|
11
|
+
const mediaQueries_1 = require("css-calipers/mediaQueries");
|
|
12
|
+
const containerQueries_1 = require("css-calipers/containerQueries");
|
|
13
|
+
const media = (0, mediaQueries_1.makeMediaQueryStyle)({
|
|
14
|
+
desktop: { minWidth: (0, css_calipers_1.m)(1024) },
|
|
15
|
+
aspectRatio: (0, css_calipers_1.m)("16/9"),
|
|
16
|
+
});
|
|
17
|
+
// const media2 = makeMediaQueryStyle({
|
|
18
|
+
// queryA: {
|
|
19
|
+
// // implied "and"
|
|
20
|
+
// minWidth: m(1024),
|
|
21
|
+
// maxWidth: m(2024),
|
|
22
|
+
// },
|
|
23
|
+
// queryB: not({
|
|
24
|
+
// minResolution: m(2, "dppx"),
|
|
25
|
+
// }),
|
|
26
|
+
// queryC: or({
|
|
27
|
+
// aspectRatio: m("16/9"),
|
|
28
|
+
// }),
|
|
29
|
+
// });
|
|
30
|
+
const container = (0, containerQueries_1.makeContainerQueryStyle)({
|
|
31
|
+
wideCard: {
|
|
32
|
+
inlineSize: { operator: ">=", value: (0, css_calipers_1.m)(28, "rem") },
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
const nestedStyles = media({
|
|
36
|
+
desktop: container({
|
|
37
|
+
wideCard: {
|
|
38
|
+
gridTemplateColumns: "1fr 2fr",
|
|
39
|
+
gridTemplateRows: "none",
|
|
40
|
+
alignItems: "stretch",
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
// const vanillaExtractStyles = mediaQueryOutputVanillaExtract(
|
|
45
|
+
// media({
|
|
46
|
+
// desktop: containerQueryOutputVanillaExtract(
|
|
47
|
+
// container({
|
|
48
|
+
// wideCard: {
|
|
49
|
+
// gridTemplateColumns: "1fr 2fr",
|
|
50
|
+
// gridTemplateRows: "none",
|
|
51
|
+
// },
|
|
52
|
+
// }),
|
|
53
|
+
// ),
|
|
54
|
+
// }),
|
|
55
|
+
// );
|