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,109 @@
|
|
|
1
|
+
import { emitAspectRatioFeatures, emitBlockSizeFeatures, emitCustomFeatures, emitInlineSizeFeatures, emitStyleFeatures, } from "./modules";
|
|
2
|
+
import { runContainerQueryLint } from "./linting";
|
|
3
|
+
import { lintHeightExactRedundancy, lintWidthExactRedundancy, } from "./linting/core";
|
|
4
|
+
import { defaultContainerQueryValidation } from "./validation";
|
|
5
|
+
import { createContainerQueryBuilder } from "./helpers";
|
|
6
|
+
export const createEmitCoreFeatures = (validation) => (props, helpers) => {
|
|
7
|
+
const allowQueryArrays = helpers.config.allowQueryArrays !== false;
|
|
8
|
+
const assertNoArray = (value, label) => {
|
|
9
|
+
if (Array.isArray(value) && !allowQueryArrays) {
|
|
10
|
+
throw new Error(`${label} does not allow arrays.`);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const emitFeature = (name, value) => {
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
value.forEach((entry) => {
|
|
16
|
+
var _a;
|
|
17
|
+
((_a = helpers.addFeatureUnsafe) !== null && _a !== void 0 ? _a : helpers.addFeature)(name, entry);
|
|
18
|
+
});
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
helpers.addFeature(name, value);
|
|
22
|
+
};
|
|
23
|
+
const { runContainerQueryValidation, validateMinMaxWidth, validateWidthValuesPositive, validateMinMaxHeight, validateHeightValuesPositive, } = validation;
|
|
24
|
+
if (!runContainerQueryValidation(props, helpers, validateMinMaxWidth, "core", "minWidth must be less than or equal to maxWidth")) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!runContainerQueryValidation(props, helpers, validateMinMaxHeight, "core", "minHeight must be less than or equal to maxHeight")) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!runContainerQueryValidation(props, helpers, validateWidthValuesPositive, "core", "width values must be greater than 0")) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!runContainerQueryValidation(props, helpers, validateHeightValuesPositive, "core", "height values must be greater than 0")) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!runContainerQueryLint(props, helpers, lintWidthExactRedundancy, "minWidth should not be combined with maxWidth when both are equal")) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!runContainerQueryLint(props, helpers, lintHeightExactRedundancy, "minHeight should not be combined with maxHeight when both are equal")) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (props.minWidth !== undefined) {
|
|
43
|
+
assertNoArray(props.minWidth, "minWidth");
|
|
44
|
+
emitFeature("min-width", props.minWidth);
|
|
45
|
+
}
|
|
46
|
+
if (props.maxWidth !== undefined) {
|
|
47
|
+
assertNoArray(props.maxWidth, "maxWidth");
|
|
48
|
+
emitFeature("max-width", props.maxWidth);
|
|
49
|
+
}
|
|
50
|
+
if (props.minHeight !== undefined) {
|
|
51
|
+
assertNoArray(props.minHeight, "minHeight");
|
|
52
|
+
emitFeature("min-height", props.minHeight);
|
|
53
|
+
}
|
|
54
|
+
if (props.maxHeight !== undefined) {
|
|
55
|
+
assertNoArray(props.maxHeight, "maxHeight");
|
|
56
|
+
emitFeature("max-height", props.maxHeight);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
export const emitCoreFeatures = createEmitCoreFeatures(defaultContainerQueryValidation);
|
|
60
|
+
const emitBaseFeatures = (props, helpers) => {
|
|
61
|
+
emitCoreFeatures(props, helpers);
|
|
62
|
+
emitAspectRatioFeatures(props, helpers);
|
|
63
|
+
emitInlineSizeFeatures(props, helpers);
|
|
64
|
+
emitBlockSizeFeatures(props, helpers);
|
|
65
|
+
emitStyleFeatures(props, helpers);
|
|
66
|
+
emitCustomFeatures(props, helpers);
|
|
67
|
+
};
|
|
68
|
+
export const buildContainerQueryString = createContainerQueryBuilder({
|
|
69
|
+
emitBase: emitBaseFeatures,
|
|
70
|
+
});
|
|
71
|
+
const wrapContainerCondition = (value) => {
|
|
72
|
+
const trimmed = value.trim();
|
|
73
|
+
if (trimmed.includes(" and ") ||
|
|
74
|
+
trimmed.includes(" or ") ||
|
|
75
|
+
trimmed.startsWith("not ")) {
|
|
76
|
+
return `(${trimmed})`;
|
|
77
|
+
}
|
|
78
|
+
return trimmed;
|
|
79
|
+
};
|
|
80
|
+
export const buildContainerConditionString = (condition) => {
|
|
81
|
+
if ("and" in condition) {
|
|
82
|
+
return condition.and
|
|
83
|
+
.map((entry) => wrapContainerCondition(buildContainerConditionString(entry)))
|
|
84
|
+
.join(" and ");
|
|
85
|
+
}
|
|
86
|
+
if ("or" in condition) {
|
|
87
|
+
return condition.or
|
|
88
|
+
.map((entry) => wrapContainerCondition(buildContainerConditionString(entry)))
|
|
89
|
+
.join(" or ");
|
|
90
|
+
}
|
|
91
|
+
if ("not" in condition) {
|
|
92
|
+
return `not ${wrapContainerCondition(buildContainerConditionString(condition.not))}`;
|
|
93
|
+
}
|
|
94
|
+
return buildContainerQueryString(condition);
|
|
95
|
+
};
|
|
96
|
+
export const makeContainerQueryStyle = (queries) => (stylesByQuery) => {
|
|
97
|
+
const result = {};
|
|
98
|
+
Object.keys(stylesByQuery).forEach((key) => {
|
|
99
|
+
const styles = stylesByQuery[key];
|
|
100
|
+
const props = queries[key];
|
|
101
|
+
if (!styles || !props)
|
|
102
|
+
return;
|
|
103
|
+
result[buildContainerQueryString(props)] = styles;
|
|
104
|
+
});
|
|
105
|
+
const containerQuery = {
|
|
106
|
+
"@container": result,
|
|
107
|
+
};
|
|
108
|
+
return containerQuery;
|
|
109
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ComplexStyleRule, StyleRule } from "../mediaQueries/types";
|
|
2
|
+
import type { CSSContainerQueries } from "./types";
|
|
3
|
+
import type { ContainerQueryBuilderConfig } from "./helpers";
|
|
4
|
+
import type { ContainerQueryModulesList } from "./moduleRegistry";
|
|
5
|
+
type ContainerQueryStyleMap<TQueries> = Partial<Record<keyof TQueries, StyleRule>>;
|
|
6
|
+
export type ContainerQueryFactoryConfig<TModules extends ContainerQueryModulesList | undefined = undefined, TOutput = ComplexStyleRule> = ContainerQueryBuilderConfig & {
|
|
7
|
+
label: string;
|
|
8
|
+
modules?: TModules;
|
|
9
|
+
output?: (container: ComplexStyleRule) => TOutput;
|
|
10
|
+
};
|
|
11
|
+
export declare const createContainerQueryFactory: () => <TModules extends ContainerQueryModulesList | undefined, TQueries extends CSSContainerQueries, TOutput = ComplexStyleRule>(options: {
|
|
12
|
+
queries: TQueries;
|
|
13
|
+
config: ContainerQueryFactoryConfig<TModules, TOutput>;
|
|
14
|
+
}) => (stylesByQuery: ContainerQueryStyleMap<TQueries>) => TOutput;
|
|
15
|
+
export declare const containerQueryFactory: <TModules extends ContainerQueryModulesList | undefined, TQueries extends CSSContainerQueries, TOutput = ComplexStyleRule>(options: {
|
|
16
|
+
queries: TQueries;
|
|
17
|
+
config: ContainerQueryFactoryConfig<TModules, TOutput>;
|
|
18
|
+
}) => (stylesByQuery: ContainerQueryStyleMap<TQueries>) => TOutput;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/containerQueries/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACzE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
|
+
"core",
|
|
4
|
+
"inline",
|
|
5
|
+
"block",
|
|
6
|
+
"aspectRatio",
|
|
7
|
+
"style",
|
|
8
|
+
"custom",
|
|
9
|
+
];
|
|
10
|
+
const MODULE_KEYS = {
|
|
11
|
+
core: ["minWidth", "maxWidth", "minHeight", "maxHeight"],
|
|
12
|
+
inline: ["inlineSize", "inlineSizeRange"],
|
|
13
|
+
block: ["blockSize", "blockSizeRange"],
|
|
14
|
+
aspectRatio: ["aspectRatio", "minAspectRatio", "maxAspectRatio"],
|
|
15
|
+
style: ["style"],
|
|
16
|
+
custom: ["customFeatures"],
|
|
17
|
+
};
|
|
18
|
+
const KEY_TO_MODULE = Object.fromEntries(Object.keys(MODULE_KEYS).flatMap((moduleId) => MODULE_KEYS[moduleId].map((key) => [key, moduleId])));
|
|
19
|
+
const collectConditionKeys = (condition, keys) => {
|
|
20
|
+
if ("and" in condition) {
|
|
21
|
+
condition.and.forEach((entry) => collectConditionKeys(entry, keys));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if ("or" in condition) {
|
|
25
|
+
condition.or.forEach((entry) => collectConditionKeys(entry, keys));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if ("not" in condition) {
|
|
29
|
+
collectConditionKeys(condition.not, keys);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
Object.keys(condition).forEach((key) => keys.add(key));
|
|
33
|
+
};
|
|
34
|
+
const collectAndConditionKeys = (condition, keys) => {
|
|
35
|
+
if ("and" in condition) {
|
|
36
|
+
condition.and.forEach((entry) => collectAndConditionKeys(entry, keys));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if ("or" in condition || "not" in condition) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
Object.keys(condition).forEach((key) => keys.push(key));
|
|
43
|
+
};
|
|
44
|
+
const guardUnsupportedCondition = (condition, modules, config, label) => {
|
|
45
|
+
const allowed = new Set();
|
|
46
|
+
modules.forEach((moduleId) => {
|
|
47
|
+
MODULE_KEYS[moduleId].forEach((key) => {
|
|
48
|
+
allowed.add(key);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
const conditionKeys = new Set();
|
|
52
|
+
collectConditionKeys(condition, conditionKeys);
|
|
53
|
+
conditionKeys.forEach((key) => {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
if (allowed.has(key))
|
|
56
|
+
return;
|
|
57
|
+
const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : "throw";
|
|
58
|
+
const moduleHint = KEY_TO_MODULE[key];
|
|
59
|
+
const moduleSuffix = moduleHint
|
|
60
|
+
? ` Add "${moduleHint}" to modules.`
|
|
61
|
+
: "";
|
|
62
|
+
const message = `Container query factory "${label}" received unsupported feature "${key}".${moduleSuffix}`;
|
|
63
|
+
if (mode === "log") {
|
|
64
|
+
console.warn(message);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (mode === "allow")
|
|
68
|
+
return;
|
|
69
|
+
throw new Error(message);
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
const guardDuplicateConditions = (condition, config, label) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
const keys = [];
|
|
75
|
+
collectAndConditionKeys(condition, keys);
|
|
76
|
+
const seen = new Set();
|
|
77
|
+
const duplicates = new Set();
|
|
78
|
+
keys.forEach((key) => {
|
|
79
|
+
if (seen.has(key)) {
|
|
80
|
+
duplicates.add(key);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
seen.add(key);
|
|
84
|
+
});
|
|
85
|
+
if (!duplicates.size)
|
|
86
|
+
return;
|
|
87
|
+
const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : "throw";
|
|
88
|
+
const message = `Container query factory "${label}" received duplicate condition "${Array.from(duplicates).join('", "')}".`;
|
|
89
|
+
if (mode === "log") {
|
|
90
|
+
console.warn(message);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (mode === "allow")
|
|
94
|
+
return;
|
|
95
|
+
throw new Error(message);
|
|
96
|
+
};
|
|
97
|
+
export const createContainerQueryFactory = () => (options) => {
|
|
98
|
+
var _a;
|
|
99
|
+
const modules = (_a = options.config.modules) !== null && _a !== void 0 ? _a : ALL_CONTAINER_QUERY_MODULES;
|
|
100
|
+
return (stylesByQuery) => {
|
|
101
|
+
const result = {};
|
|
102
|
+
Object.keys(stylesByQuery).forEach((key) => {
|
|
103
|
+
const styles = stylesByQuery[key];
|
|
104
|
+
const rule = options.queries[key];
|
|
105
|
+
if (!styles || !(rule === null || rule === void 0 ? void 0 : rule.query))
|
|
106
|
+
return;
|
|
107
|
+
guardUnsupportedCondition(rule.query.condition, modules, options.config, options.config.label);
|
|
108
|
+
guardDuplicateConditions(rule.query.condition, options.config, options.config.label);
|
|
109
|
+
result[buildContainerConditionString(rule.query.condition)] = styles;
|
|
110
|
+
});
|
|
111
|
+
const containerQuery = {
|
|
112
|
+
"@container": result,
|
|
113
|
+
};
|
|
114
|
+
return options.config.output
|
|
115
|
+
? options.config.output(containerQuery)
|
|
116
|
+
: containerQuery;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
export const containerQueryFactory = createContainerQueryFactory();
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { IRatio } from "../ratio";
|
|
2
|
+
import type { IMeasurement } from "../core";
|
|
3
|
+
import type { ComparisonValue } from "../comparisons";
|
|
4
|
+
import type { CSSComparison, CSSRange } from "./types";
|
|
5
|
+
import type { ValidationResult } from "../validation";
|
|
6
|
+
export type ContainerQueryValidationResult = ValidationResult;
|
|
7
|
+
export type ContainerQueryValidator<TConfig> = (config: TConfig) => ContainerQueryValidationResult;
|
|
8
|
+
type ContainerQueryFeatureValue = string | number | IMeasurement | IRatio;
|
|
9
|
+
type ContainerQueryFeatureEmitter = (name: string, value: ContainerQueryFeatureValue) => void;
|
|
10
|
+
type ContainerQueryConditionEmitter = (condition: string) => void;
|
|
11
|
+
export type ContainerQueryInvalidValueMode = "allow" | "log" | "throw";
|
|
12
|
+
export type ContainerQueryLintingMode = "allow" | "log" | "throw";
|
|
13
|
+
export type ContainerQueryBuilderConfig = {
|
|
14
|
+
errorHandling?: {
|
|
15
|
+
invalidValueMode?: ContainerQueryInvalidValueMode;
|
|
16
|
+
lintingMode?: ContainerQueryLintingMode;
|
|
17
|
+
};
|
|
18
|
+
allowQueryArrays?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export interface ContainerQueryBuilderHelpers {
|
|
21
|
+
addFeature: ContainerQueryFeatureEmitter;
|
|
22
|
+
addFeatureUnsafe: ContainerQueryFeatureEmitter;
|
|
23
|
+
addCondition: ContainerQueryConditionEmitter;
|
|
24
|
+
config: ContainerQueryBuilderConfig;
|
|
25
|
+
}
|
|
26
|
+
export type ContainerQueryExtensionHandler<TConfig> = (config: TConfig, helpers: ContainerQueryBuilderHelpers) => void;
|
|
27
|
+
type ContainerQueryBuilderOptions<TConfig> = {
|
|
28
|
+
emitBase: ContainerQueryExtensionHandler<TConfig>;
|
|
29
|
+
emitExtensions?: ContainerQueryExtensionHandler<TConfig>;
|
|
30
|
+
resolveType?: (config: TConfig) => "all" | "print" | "screen" | undefined;
|
|
31
|
+
config?: ContainerQueryBuilderConfig;
|
|
32
|
+
};
|
|
33
|
+
export declare const formatContainerQueryValue: (value: ContainerQueryFeatureValue) => string;
|
|
34
|
+
type ContainerQueryRangeMode = "min" | "max";
|
|
35
|
+
type ContainerQueryRangeOptions = {
|
|
36
|
+
mode?: ContainerQueryRangeMode;
|
|
37
|
+
inclusive?: boolean;
|
|
38
|
+
};
|
|
39
|
+
export declare const buildContainerComparison: <TValue>(comparison: ComparisonValue<TValue>) => CSSComparison<TValue>;
|
|
40
|
+
export declare const buildContainerRange: <TValue>(min: TValue, max: TValue, options?: ContainerQueryRangeOptions) => CSSRange<TValue>;
|
|
41
|
+
export declare const buildContainerQueryStringFromParts: (parts: string[]) => string;
|
|
42
|
+
export declare const formatContainerQueryComparison: (name: string, operator: string, value: ContainerQueryFeatureValue) => string;
|
|
43
|
+
export declare const createContainerQueryFeatureEmitter: (parts: string[]) => ContainerQueryFeatureEmitter;
|
|
44
|
+
export declare const createContainerQueryConditionEmitter: (parts: string[]) => ContainerQueryConditionEmitter;
|
|
45
|
+
type ContainerQueryFeatureEmitterOptions = {
|
|
46
|
+
emitted?: Set<string>;
|
|
47
|
+
lintingMode?: ContainerQueryLintingMode;
|
|
48
|
+
};
|
|
49
|
+
export declare const createContainerQueryFeatureEmitterWithTracking: (parts: string[], options?: ContainerQueryFeatureEmitterOptions) => ContainerQueryFeatureEmitter;
|
|
50
|
+
export declare const createContainerQueryBuilder: <TConfig>(options: ContainerQueryBuilderOptions<TConfig>) => (config: TConfig) => string;
|
|
51
|
+
export declare const applyContainerQueryValidation: <TConfig>(config: TConfig, helpers: ContainerQueryBuilderHelpers, validator?: ContainerQueryValidator<TConfig>, context?: string) => boolean;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/containerQueries/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,MAAM,MAAM,8BAA8B,GAAG,gBAAgB,CAAC;AAE9D,MAAM,MAAM,uBAAuB,CAAC,OAAO,IAAI,CAC7C,MAAM,EAAE,OAAO,KACZ,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
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { hasCssMethod } from "../core";
|
|
2
|
+
import { normalizeValidationResult } from "../validation";
|
|
3
|
+
export const formatContainerQueryValue = (value) => (hasCssMethod(value) ? value.css() : String(value));
|
|
4
|
+
export const buildContainerComparison = (comparison) => comparison;
|
|
5
|
+
export const buildContainerRange = (min, max, options = {}) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const mode = (_a = options.mode) !== null && _a !== void 0 ? _a : "min";
|
|
8
|
+
const operator = options.inclusive === false ? "<" : "<=";
|
|
9
|
+
if (mode === "max") {
|
|
10
|
+
return { min, max, maxOperator: operator };
|
|
11
|
+
}
|
|
12
|
+
return { min, max, minOperator: operator };
|
|
13
|
+
};
|
|
14
|
+
export const buildContainerQueryStringFromParts = (parts) => parts.join(" and ");
|
|
15
|
+
export const formatContainerQueryComparison = (name, operator, value) => {
|
|
16
|
+
return `(${name} ${operator} ${formatContainerQueryValue(value)})`;
|
|
17
|
+
};
|
|
18
|
+
export const createContainerQueryFeatureEmitter = (parts) => (name, value) => {
|
|
19
|
+
parts.push(`(${name}: ${formatContainerQueryValue(value)})`);
|
|
20
|
+
};
|
|
21
|
+
export const createContainerQueryConditionEmitter = (parts) => (condition) => {
|
|
22
|
+
parts.push(condition);
|
|
23
|
+
};
|
|
24
|
+
export const createContainerQueryFeatureEmitterWithTracking = (parts, options = {}) => {
|
|
25
|
+
const { emitted, lintingMode = "throw" } = options;
|
|
26
|
+
return (name, value) => {
|
|
27
|
+
if (emitted === null || emitted === void 0 ? void 0 : emitted.has(name)) {
|
|
28
|
+
if (lintingMode === "throw") {
|
|
29
|
+
throw new Error(`Container query feature "${name}" was emitted more than once.`);
|
|
30
|
+
}
|
|
31
|
+
if (lintingMode === "log") {
|
|
32
|
+
console.warn(`Container query feature "${name}" was emitted more than once; using the latest value.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
emitted === null || emitted === void 0 ? void 0 : emitted.add(name);
|
|
36
|
+
parts.push(`(${name}: ${formatContainerQueryValue(value)})`);
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export const createContainerQueryBuilder = (options) => {
|
|
40
|
+
return (config) => {
|
|
41
|
+
var _a, _b, _c, _d, _e;
|
|
42
|
+
const parts = [];
|
|
43
|
+
const emittedFeatures = new Set();
|
|
44
|
+
const helpers = {
|
|
45
|
+
addFeature: createContainerQueryFeatureEmitterWithTracking(parts, {
|
|
46
|
+
emitted: emittedFeatures,
|
|
47
|
+
lintingMode: (_c = (_b = (_a = options.config) === null || _a === void 0 ? void 0 : _a.errorHandling) === null || _b === void 0 ? void 0 : _b.lintingMode) !== null && _c !== void 0 ? _c : "throw",
|
|
48
|
+
}),
|
|
49
|
+
addFeatureUnsafe: createContainerQueryFeatureEmitter(parts),
|
|
50
|
+
addCondition: createContainerQueryConditionEmitter(parts),
|
|
51
|
+
config: (_d = options.config) !== null && _d !== void 0 ? _d : {},
|
|
52
|
+
};
|
|
53
|
+
options.emitBase(config, helpers);
|
|
54
|
+
(_e = options.emitExtensions) === null || _e === void 0 ? void 0 : _e.call(options, config, helpers);
|
|
55
|
+
return buildContainerQueryStringFromParts(parts);
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export const applyContainerQueryValidation = (config, helpers, validator, context) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
if (!validator)
|
|
61
|
+
return true;
|
|
62
|
+
const normalized = normalizeValidationResult(validator(config));
|
|
63
|
+
if (normalized.valid)
|
|
64
|
+
return true;
|
|
65
|
+
const mode = (_b = (_a = helpers.config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : "throw";
|
|
66
|
+
if (mode === "log") {
|
|
67
|
+
const suffix = normalized.message ? `: ${normalized.message}` : "";
|
|
68
|
+
const prefix = context
|
|
69
|
+
? `Container query ${context} validation failed`
|
|
70
|
+
: "Container query validation failed";
|
|
71
|
+
console.warn(`${prefix}${suffix}`);
|
|
72
|
+
}
|
|
73
|
+
if (mode === "allow")
|
|
74
|
+
return true;
|
|
75
|
+
if (mode === "log")
|
|
76
|
+
return true;
|
|
77
|
+
const suffix = normalized.message ? `: ${normalized.message}` : "";
|
|
78
|
+
const prefix = context
|
|
79
|
+
? `Container query ${context} validation failed`
|
|
80
|
+
: "Container query validation failed";
|
|
81
|
+
throw new Error(`${prefix}${suffix}`);
|
|
82
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { buildContainerConditionString, buildContainerQueryString, makeContainerQueryStyle, } from "./containerQueries";
|
|
2
|
+
export { buildContainerComparison, buildContainerRange, formatContainerQueryValue, } from "./helpers";
|
|
3
|
+
export { containerQueryFactory, createContainerQueryFactory } from "./factory";
|
|
4
|
+
export { defineContainerQueryModules } from "./moduleRegistry";
|
|
5
|
+
export type * from "./types";
|
|
6
|
+
export type * from "./containerQueries";
|
|
7
|
+
export type * from "./factory";
|
|
8
|
+
export type * from "./modules";
|
|
9
|
+
export type * from "./moduleRegistry";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/containerQueries/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC/D,mBAAmB,SAAS,CAAC;AAC7B,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,WAAW,CAAC;AAC/B,mBAAmB,WAAW,CAAC;AAC/B,mBAAmB,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { buildContainerConditionString, buildContainerQueryString, makeContainerQueryStyle, } from "./containerQueries";
|
|
2
|
+
export { buildContainerComparison, buildContainerRange, formatContainerQueryValue, } from "./helpers";
|
|
3
|
+
export { containerQueryFactory, createContainerQueryFactory } from "./factory";
|
|
4
|
+
export { defineContainerQueryModules } from "./moduleRegistry";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IContainerQueryAspectRatio } from "../modules/aspectRatio";
|
|
2
|
+
export declare const lintAspectRatioRedundancy: (props: IContainerQueryAspectRatio) => void;
|
|
3
|
+
export declare const lintAspectRatioRangeCollapse: (props: IContainerQueryAspectRatio) => void;
|
|
4
|
+
//# sourceMappingURL=aspectRatio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aspectRatio.d.ts","sourceRoot":"","sources":["../../../../src/containerQueries/linting/aspectRatio.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAGzE,eAAO,MAAM,yBAAyB,GACpC,OAAO,0BAA0B,KAChC,IAOF,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,OAAO,0BAA0B,KAChC,IAeF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ratioToFloat } from "../../ratio";
|
|
2
|
+
export const lintAspectRatioRedundancy = (props) => {
|
|
3
|
+
if (!props.aspectRatio)
|
|
4
|
+
return;
|
|
5
|
+
if (props.minAspectRatio || props.maxAspectRatio) {
|
|
6
|
+
throw new Error("aspectRatio should not be combined with minAspectRatio or maxAspectRatio");
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export const lintAspectRatioRangeCollapse = (props) => {
|
|
10
|
+
if (!props.minAspectRatio || !props.maxAspectRatio)
|
|
11
|
+
return;
|
|
12
|
+
if (Array.isArray(props.minAspectRatio) ||
|
|
13
|
+
Array.isArray(props.maxAspectRatio)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (ratioToFloat(props.minAspectRatio) === ratioToFloat(props.maxAspectRatio)) {
|
|
17
|
+
throw new Error("minAspectRatio and maxAspectRatio are equal; use aspectRatio instead");
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../../src/containerQueries/linting/block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,eAAO,MAAM,mBAAmB,GAC9B,OAAO,oBAAoB,KAC1B,IAOF,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,OAAO,oBAAoB,KAC1B,IAUF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { normalizeToArray } from "../../internal/normalizeToArray";
|
|
2
|
+
export const lintBlockRedundancy = (props) => {
|
|
3
|
+
if (!props.blockSize)
|
|
4
|
+
return;
|
|
5
|
+
if (props.blockSizeRange) {
|
|
6
|
+
throw new Error("blockSize should not be combined with blockSizeRange");
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export const lintBlockRangeCollapse = (props) => {
|
|
10
|
+
if (!props.blockSizeRange)
|
|
11
|
+
return;
|
|
12
|
+
normalizeToArray(props.blockSizeRange).forEach((range) => {
|
|
13
|
+
const { min, max } = range;
|
|
14
|
+
if (min.equals(max)) {
|
|
15
|
+
throw new Error("blockSizeRange min and max are equal; use blockSize instead");
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IContainerQueryCore } from "../containerQueries";
|
|
2
|
+
export declare const lintWidthExactRedundancy: (props: IContainerQueryCore) => void;
|
|
3
|
+
export declare const lintHeightExactRedundancy: (props: IContainerQueryCore) => void;
|
|
4
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../src/containerQueries/linting/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,eAAO,MAAM,wBAAwB,GACnC,OAAO,mBAAmB,KACzB,IAUF,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,OAAO,mBAAmB,KACzB,IAUF,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const lintWidthExactRedundancy = (props) => {
|
|
2
|
+
if (!props.minWidth || !props.maxWidth)
|
|
3
|
+
return;
|
|
4
|
+
if (Array.isArray(props.minWidth) || Array.isArray(props.maxWidth)) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (props.minWidth.equals(props.maxWidth)) {
|
|
8
|
+
throw new Error("minWidth should not be combined with maxWidth when both are equal");
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export const lintHeightExactRedundancy = (props) => {
|
|
12
|
+
if (!props.minHeight || !props.maxHeight)
|
|
13
|
+
return;
|
|
14
|
+
if (Array.isArray(props.minHeight) || Array.isArray(props.maxHeight)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (props.minHeight.equals(props.maxHeight)) {
|
|
18
|
+
throw new Error("minHeight should not be combined with maxHeight when both are equal");
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../../../src/containerQueries/linting/custom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAEvE,eAAO,MAAM,kBAAkB,GAC7B,OAAO,6BAA6B,KACnC,IAKF,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IContainerQueryInline } from "../modules/inline";
|
|
2
|
+
export declare const lintInlineRedundancy: (props: IContainerQueryInline) => void;
|
|
3
|
+
export declare const lintInlineRangeCollapse: (props: IContainerQueryInline) => void;
|
|
4
|
+
//# sourceMappingURL=inline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../../../../src/containerQueries/linting/inline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAG/D,eAAO,MAAM,oBAAoB,GAC/B,OAAO,qBAAqB,KAC3B,IAOF,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,OAAO,qBAAqB,KAC3B,IAUF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { normalizeToArray } from "../../internal/normalizeToArray";
|
|
2
|
+
export const lintInlineRedundancy = (props) => {
|
|
3
|
+
if (!props.inlineSize)
|
|
4
|
+
return;
|
|
5
|
+
if (props.inlineSizeRange) {
|
|
6
|
+
throw new Error("inlineSize should not be combined with inlineSizeRange");
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export const lintInlineRangeCollapse = (props) => {
|
|
10
|
+
if (!props.inlineSizeRange)
|
|
11
|
+
return;
|
|
12
|
+
normalizeToArray(props.inlineSizeRange).forEach((range) => {
|
|
13
|
+
const { min, max } = range;
|
|
14
|
+
if (min.equals(max)) {
|
|
15
|
+
throw new Error("inlineSizeRange min and max are equal; use inlineSize instead");
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=resolution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolution.d.ts","sourceRoot":"","sources":["../../../../src/containerQueries/linting/resolution.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import type { IMediaQueryResolutionRange } from '../modules/resolution';
|
|
3
|
+
// export const lintResolutionRedundancy = (
|
|
4
|
+
// props: IMediaQueryResolutionRange,
|
|
5
|
+
// ): void => {
|
|
6
|
+
// if (!props.resolutionValue) return;
|
|
7
|
+
// if (props.minResolution || props.maxResolution) {
|
|
8
|
+
// throw new Error(
|
|
9
|
+
// 'resolution should not be combined with minResolution or maxResolution',
|
|
10
|
+
// );
|
|
11
|
+
// }
|
|
12
|
+
// };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../../src/containerQueries/linting/style.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAO7D,eAAO,MAAM,kBAAkB,GAC7B,OAAO,oBAAoB,KAC1B,IAiBF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { hasCssMethod } from "../../core";
|
|
2
|
+
const isComparisonShape = (value) => {
|
|
3
|
+
if (typeof value !== "object" || value === null)
|
|
4
|
+
return false;
|
|
5
|
+
return "operator" in value && "value" in value;
|
|
6
|
+
};
|
|
7
|
+
export const lintStyleCondition = (props) => {
|
|
8
|
+
if (!props.style)
|
|
9
|
+
return;
|
|
10
|
+
if (!Object.keys(props.style).length) {
|
|
11
|
+
throw new Error("style conditions must not be empty.");
|
|
12
|
+
}
|
|
13
|
+
Object.values(props.style).forEach((value) => {
|
|
14
|
+
if (value === undefined || value === null)
|
|
15
|
+
return;
|
|
16
|
+
if (Array.isArray(value))
|
|
17
|
+
return;
|
|
18
|
+
if (hasCssMethod(value))
|
|
19
|
+
return;
|
|
20
|
+
if (isComparisonShape(value)) {
|
|
21
|
+
throw new Error("style conditions must not contain comparisons.");
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ContainerQueryBuilderHelpers } from "./helpers";
|
|
2
|
+
export type ContainerQueryLintCheck<TConfig> = (config: TConfig) => void;
|
|
3
|
+
export declare const runContainerQueryLint: <TConfig>(config: TConfig, helpers: ContainerQueryBuilderHelpers, check?: ContainerQueryLintCheck<TConfig>, message?: string) => boolean;
|
|
4
|
+
//# sourceMappingURL=linting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linting.d.ts","sourceRoot":"","sources":["../../../src/containerQueries/linting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAE7B,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,uBAAuB,CAAC,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;AAEzE,eAAO,MAAM,qBAAqB,GAAI,OAAO,EAC3C,QAAQ,OAAO,EACf,SAAS,4BAA4B,EACrC,QAAQ,uBAAuB,CAAC,OAAO,CAAC,EACxC,gBAAuC,KACtC,OAiBF,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const runContainerQueryLint = (config, helpers, check, message = "Container query lint failed") => {
|
|
2
|
+
var _a, _b;
|
|
3
|
+
if (!check)
|
|
4
|
+
return true;
|
|
5
|
+
const mode = (_b = (_a = helpers.config.errorHandling) === null || _a === void 0 ? void 0 : _a.lintingMode) !== null && _b !== void 0 ? _b : "throw";
|
|
6
|
+
if (mode === "allow")
|
|
7
|
+
return true;
|
|
8
|
+
if (mode === "log") {
|
|
9
|
+
try {
|
|
10
|
+
check(config);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
console.warn(message);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
check(config);
|
|
19
|
+
return true;
|
|
20
|
+
};
|