css-calipers 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -25
- package/dist/cjs/factory.js +0 -3
- package/dist/esm/factory.d.ts +0 -2
- package/dist/esm/factory.d.ts.map +1 -1
- package/dist/esm/factory.js +0 -3
- package/package.json +5 -18
- package/RELEASING.md +0 -62
- package/dist/cjs/comparisons/index.js +0 -25
- package/dist/cjs/containerQueries/containerQueries.js +0 -115
- package/dist/cjs/containerQueries/factory.js +0 -123
- package/dist/cjs/containerQueries/helpers.js +0 -95
- package/dist/cjs/containerQueries/index.js +0 -16
- package/dist/cjs/containerQueries/linting/aspectRatio.js +0 -24
- package/dist/cjs/containerQueries/linting/block.js +0 -23
- package/dist/cjs/containerQueries/linting/core.js +0 -25
- package/dist/cjs/containerQueries/linting/custom.js +0 -11
- package/dist/cjs/containerQueries/linting/inline.js +0 -23
- package/dist/cjs/containerQueries/linting/resolution.js +0 -12
- package/dist/cjs/containerQueries/linting/style.js +0 -28
- package/dist/cjs/containerQueries/linting.js +0 -24
- package/dist/cjs/containerQueries/moduleRegistry.js +0 -5
- package/dist/cjs/containerQueries/modules/aspectRatio.js +0 -51
- package/dist/cjs/containerQueries/modules/block.js +0 -53
- package/dist/cjs/containerQueries/modules/custom.js +0 -43
- package/dist/cjs/containerQueries/modules/index.js +0 -21
- package/dist/cjs/containerQueries/modules/inline.js +0 -53
- package/dist/cjs/containerQueries/modules/size.js +0 -2
- package/dist/cjs/containerQueries/modules/style.js +0 -36
- package/dist/cjs/containerQueries/types.js +0 -2
- package/dist/cjs/containerQueries/validation.js +0 -191
- package/dist/cjs/fraction.js +0 -139
- package/dist/cjs/internal/createComponentQueriesApi.js +0 -56
- package/dist/cjs/internal/createMediaQueriesApi.js +0 -73
- package/dist/cjs/internal/normalizeToArray.js +0 -9
- package/dist/cjs/libraryHelpers/vanilla-extract.js +0 -11
- package/dist/cjs/logicalOperators/index.js +0 -18
- package/dist/cjs/mediaQueries/factory.js +0 -187
- package/dist/cjs/mediaQueries/helpers.js +0 -97
- package/dist/cjs/mediaQueries/index.js +0 -23
- package/dist/cjs/mediaQueries/libraryHelpers/vanilla-extract.js +0 -77
- package/dist/cjs/mediaQueries/linting/core.js +0 -19
- package/dist/cjs/mediaQueries/linting/resolution.js +0 -11
- package/dist/cjs/mediaQueries/linting.js +0 -24
- package/dist/cjs/mediaQueries/mediaQueries.js +0 -53
- package/dist/cjs/mediaQueries/mediaQueryFactory.js +0 -120
- package/dist/cjs/mediaQueries/moduleRegistry.js +0 -5
- package/dist/cjs/mediaQueries/modules/custom.js +0 -26
- package/dist/cjs/mediaQueries/modules/dimensions.js +0 -61
- package/dist/cjs/mediaQueries/modules/display.js +0 -20
- package/dist/cjs/mediaQueries/modules/environment.js +0 -20
- package/dist/cjs/mediaQueries/modules/index.js +0 -23
- package/dist/cjs/mediaQueries/modules/interaction.js +0 -26
- package/dist/cjs/mediaQueries/modules/preferences.js +0 -26
- package/dist/cjs/mediaQueries/modules/resolution.js +0 -31
- package/dist/cjs/mediaQueries/types.js +0 -2
- package/dist/cjs/mediaQueries/validation.js +0 -134
- package/dist/cjs/sciNotation.js +0 -74
- package/dist/cjs/types.js +0 -2
- package/dist/cjs/validation.js +0 -20
- package/dist/esm/comparisons/index.d.ts +0 -23
- package/dist/esm/comparisons/index.d.ts.map +0 -1
- package/dist/esm/comparisons/index.js +0 -22
- package/dist/esm/containerQueries/containerQueries.d.ts +0 -36
- package/dist/esm/containerQueries/containerQueries.d.ts.map +0 -1
- package/dist/esm/containerQueries/containerQueries.js +0 -109
- package/dist/esm/containerQueries/factory.d.ts +0 -20
- package/dist/esm/containerQueries/factory.d.ts.map +0 -1
- package/dist/esm/containerQueries/factory.js +0 -119
- package/dist/esm/containerQueries/helpers.d.ts +0 -53
- package/dist/esm/containerQueries/helpers.d.ts.map +0 -1
- package/dist/esm/containerQueries/helpers.js +0 -82
- package/dist/esm/containerQueries/index.d.ts +0 -10
- package/dist/esm/containerQueries/index.d.ts.map +0 -1
- package/dist/esm/containerQueries/index.js +0 -4
- package/dist/esm/containerQueries/linting/aspectRatio.d.ts +0 -4
- package/dist/esm/containerQueries/linting/aspectRatio.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/aspectRatio.js +0 -19
- package/dist/esm/containerQueries/linting/block.d.ts +0 -4
- package/dist/esm/containerQueries/linting/block.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/block.js +0 -18
- package/dist/esm/containerQueries/linting/core.d.ts +0 -4
- package/dist/esm/containerQueries/linting/core.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/core.js +0 -20
- package/dist/esm/containerQueries/linting/custom.d.ts +0 -3
- package/dist/esm/containerQueries/linting/custom.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/custom.js +0 -7
- package/dist/esm/containerQueries/linting/inline.d.ts +0 -4
- package/dist/esm/containerQueries/linting/inline.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/inline.js +0 -18
- package/dist/esm/containerQueries/linting/resolution.d.ts +0 -1
- package/dist/esm/containerQueries/linting/resolution.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/resolution.js +0 -12
- package/dist/esm/containerQueries/linting/style.d.ts +0 -3
- package/dist/esm/containerQueries/linting/style.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting/style.js +0 -24
- package/dist/esm/containerQueries/linting.d.ts +0 -4
- package/dist/esm/containerQueries/linting.d.ts.map +0 -1
- package/dist/esm/containerQueries/linting.js +0 -20
- package/dist/esm/containerQueries/moduleRegistry.d.ts +0 -25
- package/dist/esm/containerQueries/moduleRegistry.d.ts.map +0 -1
- package/dist/esm/containerQueries/moduleRegistry.js +0 -1
- package/dist/esm/containerQueries/modules/aspectRatio.d.ts +0 -17
- package/dist/esm/containerQueries/modules/aspectRatio.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/aspectRatio.js +0 -47
- package/dist/esm/containerQueries/modules/block.d.ts +0 -20
- package/dist/esm/containerQueries/modules/block.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/block.js +0 -49
- package/dist/esm/containerQueries/modules/custom.d.ts +0 -13
- package/dist/esm/containerQueries/modules/custom.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/custom.js +0 -39
- package/dist/esm/containerQueries/modules/index.d.ts +0 -6
- package/dist/esm/containerQueries/modules/index.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/index.js +0 -5
- package/dist/esm/containerQueries/modules/inline.d.ts +0 -20
- package/dist/esm/containerQueries/modules/inline.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/inline.js +0 -49
- package/dist/esm/containerQueries/modules/size.d.ts +0 -41
- package/dist/esm/containerQueries/modules/size.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/size.js +0 -1
- package/dist/esm/containerQueries/modules/style.d.ts +0 -11
- package/dist/esm/containerQueries/modules/style.d.ts.map +0 -1
- package/dist/esm/containerQueries/modules/style.js +0 -32
- package/dist/esm/containerQueries/types.d.ts +0 -81
- package/dist/esm/containerQueries/types.d.ts.map +0 -1
- package/dist/esm/containerQueries/types.js +0 -1
- package/dist/esm/containerQueries/validation.d.ts +0 -41
- package/dist/esm/containerQueries/validation.d.ts.map +0 -1
- package/dist/esm/containerQueries/validation.js +0 -187
- package/dist/esm/fraction.d.ts +0 -23
- package/dist/esm/fraction.d.ts.map +0 -1
- package/dist/esm/fraction.js +0 -129
- package/dist/esm/internal/createComponentQueriesApi.d.ts +0 -34
- package/dist/esm/internal/createComponentQueriesApi.d.ts.map +0 -1
- package/dist/esm/internal/createComponentQueriesApi.js +0 -52
- package/dist/esm/internal/createMediaQueriesApi.d.ts +0 -35
- package/dist/esm/internal/createMediaQueriesApi.d.ts.map +0 -1
- package/dist/esm/internal/createMediaQueriesApi.js +0 -69
- package/dist/esm/internal/normalizeToArray.d.ts +0 -2
- package/dist/esm/internal/normalizeToArray.d.ts.map +0 -1
- package/dist/esm/internal/normalizeToArray.js +0 -5
- package/dist/esm/libraryHelpers/vanilla-extract.d.ts +0 -4
- package/dist/esm/libraryHelpers/vanilla-extract.d.ts.map +0 -1
- package/dist/esm/libraryHelpers/vanilla-extract.js +0 -6
- package/dist/esm/logicalOperators/index.d.ts +0 -2
- package/dist/esm/logicalOperators/index.d.ts.map +0 -1
- package/dist/esm/logicalOperators/index.js +0 -17
- package/dist/esm/mediaQueries/factory.d.ts +0 -45
- package/dist/esm/mediaQueries/factory.d.ts.map +0 -1
- package/dist/esm/mediaQueries/factory.js +0 -183
- package/dist/esm/mediaQueries/helpers.d.ts +0 -40
- package/dist/esm/mediaQueries/helpers.d.ts.map +0 -1
- package/dist/esm/mediaQueries/helpers.js +0 -87
- package/dist/esm/mediaQueries/index.d.ts +0 -8
- package/dist/esm/mediaQueries/index.d.ts.map +0 -1
- package/dist/esm/mediaQueries/index.js +0 -7
- package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts +0 -5
- package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts.map +0 -1
- package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.js +0 -71
- package/dist/esm/mediaQueries/linting/core.d.ts +0 -5
- package/dist/esm/mediaQueries/linting/core.d.ts.map +0 -1
- package/dist/esm/mediaQueries/linting/core.js +0 -14
- package/dist/esm/mediaQueries/linting/resolution.d.ts +0 -3
- package/dist/esm/mediaQueries/linting/resolution.d.ts.map +0 -1
- package/dist/esm/mediaQueries/linting/resolution.js +0 -7
- package/dist/esm/mediaQueries/linting.d.ts +0 -4
- package/dist/esm/mediaQueries/linting.d.ts.map +0 -1
- package/dist/esm/mediaQueries/linting.js +0 -20
- package/dist/esm/mediaQueries/mediaQueries.d.ts +0 -23
- package/dist/esm/mediaQueries/mediaQueries.d.ts.map +0 -1
- package/dist/esm/mediaQueries/mediaQueries.js +0 -48
- package/dist/esm/mediaQueries/moduleRegistry.d.ts +0 -27
- package/dist/esm/mediaQueries/moduleRegistry.d.ts.map +0 -1
- package/dist/esm/mediaQueries/moduleRegistry.js +0 -1
- package/dist/esm/mediaQueries/modules/custom.d.ts +0 -10
- package/dist/esm/mediaQueries/modules/custom.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/custom.js +0 -22
- package/dist/esm/mediaQueries/modules/dimensions.d.ts +0 -19
- package/dist/esm/mediaQueries/modules/dimensions.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/dimensions.js +0 -57
- package/dist/esm/mediaQueries/modules/display.d.ts +0 -9
- package/dist/esm/mediaQueries/modules/display.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/display.js +0 -16
- package/dist/esm/mediaQueries/modules/environment.d.ts +0 -9
- package/dist/esm/mediaQueries/modules/environment.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/environment.js +0 -16
- package/dist/esm/mediaQueries/modules/index.d.ts +0 -8
- package/dist/esm/mediaQueries/modules/index.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/index.js +0 -7
- package/dist/esm/mediaQueries/modules/interaction.d.ts +0 -11
- package/dist/esm/mediaQueries/modules/interaction.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/interaction.js +0 -22
- package/dist/esm/mediaQueries/modules/preferences.d.ts +0 -11
- package/dist/esm/mediaQueries/modules/preferences.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/preferences.js +0 -22
- package/dist/esm/mediaQueries/modules/resolution.d.ts +0 -12
- package/dist/esm/mediaQueries/modules/resolution.d.ts.map +0 -1
- package/dist/esm/mediaQueries/modules/resolution.js +0 -27
- package/dist/esm/mediaQueries/types.d.ts +0 -117
- package/dist/esm/mediaQueries/types.d.ts.map +0 -1
- package/dist/esm/mediaQueries/types.js +0 -1
- package/dist/esm/mediaQueries/validation.d.ts +0 -33
- package/dist/esm/mediaQueries/validation.d.ts.map +0 -1
- package/dist/esm/mediaQueries/validation.js +0 -130
- package/dist/esm/sciNotation.d.ts +0 -14
- package/dist/esm/sciNotation.d.ts.map +0 -1
- package/dist/esm/sciNotation.js +0 -69
- package/dist/esm/types.d.ts +0 -35
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -1
- package/dist/esm/validation.d.ts +0 -10
- package/dist/esm/validation.d.ts.map +0 -1
- package/dist/esm/validation.js +0 -15
- package/dist/examples/containerQueries.example.js +0 -54
- package/dist/examples/examples/containerQueries.example.js +0 -54
- package/dist/examples/examples/factory-wrapper.example.js +0 -33
- package/dist/examples/examples/lineHeight-normalizer.example.js +0 -81
- package/dist/examples/examples/mediaQueries-multipleInstances.example.js +0 -127
- package/dist/examples/examples/mixedQueries.example.js +0 -55
- package/dist/examples/examples/validation-and-runtime-checks.example.js +0 -85
- package/dist/examples/examples/validation-unit-tests.example.js +0 -35
- package/dist/examples/factory-wrapper.example.js +0 -33
- package/dist/examples/lineHeight-normalizer.example.js +0 -81
- package/dist/examples/mediaQueries-multipleInstances.example.js +0 -127
- package/dist/examples/mixedQueries.example.js +0 -60
- package/dist/examples/src/comparisons/index.js +0 -25
- package/dist/examples/src/containerQueries/containerQueries.js +0 -96
- package/dist/examples/src/containerQueries/factory.js +0 -123
- package/dist/examples/src/containerQueries/helpers.js +0 -94
- package/dist/examples/src/containerQueries/index.js +0 -16
- package/dist/examples/src/containerQueries/linting/aspectRatio.js +0 -20
- package/dist/examples/src/containerQueries/linting/block.js +0 -20
- package/dist/examples/src/containerQueries/linting/core.js +0 -19
- package/dist/examples/src/containerQueries/linting/custom.js +0 -11
- package/dist/examples/src/containerQueries/linting/inline.js +0 -20
- package/dist/examples/src/containerQueries/linting/style.js +0 -28
- package/dist/examples/src/containerQueries/linting.js +0 -24
- package/dist/examples/src/containerQueries/moduleRegistry.js +0 -5
- package/dist/examples/src/containerQueries/modules/aspectRatio.js +0 -33
- package/dist/examples/src/containerQueries/modules/block.js +0 -44
- package/dist/examples/src/containerQueries/modules/custom.js +0 -31
- package/dist/examples/src/containerQueries/modules/index.js +0 -21
- package/dist/examples/src/containerQueries/modules/inline.js +0 -44
- package/dist/examples/src/containerQueries/modules/style.js +0 -36
- package/dist/examples/src/containerQueries/types.js +0 -2
- package/dist/examples/src/containerQueries/validation.js +0 -177
- package/dist/examples/src/core.js +0 -16
- package/dist/examples/src/factory.js +0 -21
- package/dist/examples/src/index.js +0 -30
- package/dist/examples/src/internal/buildMeasurementCreationError.js +0 -16
- package/dist/examples/src/internal/createCoreApi.js +0 -336
- package/dist/examples/src/internal/createMediaQueriesApi.js +0 -74
- package/dist/examples/src/internal/createUnitsApi.js +0 -18
- package/dist/examples/src/internal/errors.js +0 -130
- package/dist/examples/src/libraryHelpers/vanilla-extract.js +0 -11
- package/dist/examples/src/mediaQueries/factory.js +0 -163
- package/dist/examples/src/mediaQueries/helpers.js +0 -88
- package/dist/examples/src/mediaQueries/index.js +0 -23
- package/dist/examples/src/mediaQueries/linting/core.js +0 -19
- package/dist/examples/src/mediaQueries/linting/resolution.js +0 -11
- package/dist/examples/src/mediaQueries/linting.js +0 -24
- package/dist/examples/src/mediaQueries/mediaQueries.js +0 -53
- package/dist/examples/src/mediaQueries/moduleRegistry.js +0 -5
- package/dist/examples/src/mediaQueries/modules/custom.js +0 -26
- package/dist/examples/src/mediaQueries/modules/dimensions.js +0 -61
- package/dist/examples/src/mediaQueries/modules/display.js +0 -20
- package/dist/examples/src/mediaQueries/modules/environment.js +0 -20
- package/dist/examples/src/mediaQueries/modules/index.js +0 -23
- package/dist/examples/src/mediaQueries/modules/interaction.js +0 -26
- package/dist/examples/src/mediaQueries/modules/preferences.js +0 -26
- package/dist/examples/src/mediaQueries/modules/resolution.js +0 -31
- package/dist/examples/src/mediaQueries/types.js +0 -2
- package/dist/examples/src/mediaQueries/validation.js +0 -128
- package/dist/examples/src/ratio.js +0 -141
- package/dist/examples/src/types.js +0 -2
- package/dist/examples/src/unitDefinitions.js +0 -67
- package/dist/examples/src/units/absolute.js +0 -11
- package/dist/examples/src/units/angle.js +0 -8
- package/dist/examples/src/units/container.js +0 -10
- package/dist/examples/src/units/font-relative.js +0 -16
- package/dist/examples/src/units/frequency.js +0 -6
- package/dist/examples/src/units/grid.js +0 -5
- package/dist/examples/src/units/percent.js +0 -7
- package/dist/examples/src/units/resolution.js +0 -7
- package/dist/examples/src/units/time.js +0 -6
- package/dist/examples/src/units/viewport-dynamic.js +0 -10
- package/dist/examples/src/units/viewport-large.js +0 -10
- package/dist/examples/src/units/viewport-small.js +0 -10
- package/dist/examples/src/units/viewport.js +0 -10
- package/dist/examples/src/validation.js +0 -20
- package/dist/examples/validation-and-runtime-checks.example.js +0 -85
- package/dist/examples/validation-unit-tests.example.js +0 -35
package/README.md
CHANGED
|
@@ -67,34 +67,31 @@ If you prefer, you can also import unit helpers from dedicated subpaths. For exa
|
|
|
67
67
|
- Status: early `0.x` release. Backwards compatibility is not guaranteed until `1.0.0`.
|
|
68
68
|
- Questions or bugs: open an issue on GitHub (see the repository link at the top of this page or in `package.json`).
|
|
69
69
|
- Tooling: tested primarily with TypeScript 5.6+ on Node 18+.
|
|
70
|
+
- Support: this is a solo, early-stage project. If it saves you time, you can [buy me a coffee](https://buymeacoffee.com/slafleche) to support continued work.
|
|
70
71
|
|
|
71
72
|
---
|
|
72
73
|
|
|
73
74
|
## Media queries
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
import { mediaQueryFactory } from "css-calipers/mediaQueries";
|
|
78
|
-
|
|
79
|
-
const media = mediaQueryFactory({
|
|
80
|
-
queries: {
|
|
81
|
-
mobile: { maxWidth: m(639) },
|
|
82
|
-
desktop: { minWidth: m(640) },
|
|
83
|
-
},
|
|
84
|
-
config: {
|
|
85
|
-
label: "layout",
|
|
86
|
-
},
|
|
87
|
-
});
|
|
76
|
+
Media queries have moved out of CSS-Calipers. From `0.15` on, CSS-Calipers is
|
|
77
|
+
purely the measurement layer.
|
|
88
78
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
79
|
+
CSS-Calipers itself is part of
|
|
80
|
+
[CSS-Bookends](https://github.com/slafleche/css-bookends): it is the measurement
|
|
81
|
+
lexicon at the centre of the umbrella. The first CSS-Bookends beta gives you
|
|
82
|
+
exactly what `css-calipers@0.14` does today, the same measurement layer and the
|
|
83
|
+
same media query helper, just split into two installable pieces (`css-calipers`
|
|
84
|
+
plus `@css-bookends/media-queries`). Nothing is lost.
|
|
85
|
+
|
|
86
|
+
If you use the media query helper:
|
|
87
|
+
|
|
88
|
+
- **Switch to CSS-Bookends** and add `@css-bookends/media-queries` alongside
|
|
89
|
+
`css-calipers`. Same helper, now maintained in the umbrella.
|
|
90
|
+
- **Or stay on `css-calipers@0.14`**, which still bundles the media query helper
|
|
91
|
+
and remains the `latest` release for now.
|
|
96
92
|
|
|
97
|
-
|
|
93
|
+
CSS-Bookends is the long-term home for everything beyond measurement (spacing,
|
|
94
|
+
colours, borders, and more), so moving over is the recommended path.
|
|
98
95
|
|
|
99
96
|
---
|
|
100
97
|
|
|
@@ -354,8 +351,7 @@ setErrorConfig({ stackHints: "on" });
|
|
|
354
351
|
## Factory entrypoint (optional)
|
|
355
352
|
|
|
356
353
|
If you want instance-scoped configuration and a single re-export surface, use
|
|
357
|
-
the factory entrypoint. The instance includes core helpers
|
|
358
|
-
mediaQueries.
|
|
354
|
+
the factory entrypoint. The instance includes core helpers and unit helpers.
|
|
359
355
|
|
|
360
356
|
```
|
|
361
357
|
import { createCalipers } from "css-calipers/factory";
|
|
@@ -364,7 +360,7 @@ const calipers = createCalipers({
|
|
|
364
360
|
errorConfig: { stackHints: "on" },
|
|
365
361
|
});
|
|
366
362
|
|
|
367
|
-
export const { m, mPx,
|
|
363
|
+
export const { m, mPx, units } = calipers;
|
|
368
364
|
```
|
|
369
365
|
|
|
370
366
|
See [examples/factory-wrapper.example.ts](examples/factory-wrapper.example.ts)
|
|
@@ -478,7 +474,7 @@ parts inside a broader styling solution.
|
|
|
478
474
|
Deeper guides live alongside this README:
|
|
479
475
|
|
|
480
476
|
- Measurements core: [README_MEASUREMENT.md](README_MEASUREMENT.md)
|
|
481
|
-
- Media queries: [
|
|
477
|
+
- Media queries: now in [`@css-bookends/media-queries`](https://github.com/slafleche/css-bookends)
|
|
482
478
|
|
|
483
479
|
### Further examples in this repo
|
|
484
480
|
|
package/dist/cjs/factory.js
CHANGED
|
@@ -4,17 +4,14 @@ exports.createCalipers = void 0;
|
|
|
4
4
|
const errors_1 = require("./internal/errors");
|
|
5
5
|
const createCoreApi_1 = require("./internal/createCoreApi");
|
|
6
6
|
const createUnitsApi_1 = require("./internal/createUnitsApi");
|
|
7
|
-
const createMediaQueriesApi_1 = require("./internal/createMediaQueriesApi");
|
|
8
7
|
const createCalipers = (config = {}) => {
|
|
9
8
|
var _a;
|
|
10
9
|
const errorStore = (0, errors_1.createErrorConfigStore)((_a = config.errorConfig) !== null && _a !== void 0 ? _a : {});
|
|
11
10
|
const core = (0, createCoreApi_1.createCoreApi)(errorStore);
|
|
12
11
|
const units = (0, createUnitsApi_1.createUnitsApi)(core);
|
|
13
|
-
const mediaQueries = (0, createMediaQueriesApi_1.createMediaQueriesApi)(core);
|
|
14
12
|
return {
|
|
15
13
|
...core,
|
|
16
14
|
...units,
|
|
17
|
-
mediaQueries,
|
|
18
15
|
units,
|
|
19
16
|
};
|
|
20
17
|
};
|
package/dist/esm/factory.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { type ErrorConfig } from './internal/errors';
|
|
2
2
|
import { type CoreApi } from './internal/createCoreApi';
|
|
3
3
|
import { type UnitsApi } from './internal/createUnitsApi';
|
|
4
|
-
import { type MediaQueriesApi } from './internal/createMediaQueriesApi';
|
|
5
4
|
export type CalipersFactoryConfig = {
|
|
6
5
|
errorConfig?: ErrorConfig;
|
|
7
6
|
};
|
|
8
7
|
export type CalipersInstance = CoreApi & UnitsApi & {
|
|
9
|
-
mediaQueries: MediaQueriesApi;
|
|
10
8
|
units: UnitsApi;
|
|
11
9
|
};
|
|
12
10
|
export declare const createCalipers: (config?: CalipersFactoryConfig) => CalipersInstance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE1E,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,OAAO,GACpC,QAAQ,GAAG;IACT,KAAK,EAAE,QAAQ,CAAC;CACjB,CAAC;AAEJ,eAAO,MAAM,cAAc,GACzB,SAAQ,qBAA0B,KACjC,gBAYF,CAAC"}
|
package/dist/esm/factory.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { createErrorConfigStore } from './internal/errors';
|
|
2
2
|
import { createCoreApi } from './internal/createCoreApi';
|
|
3
3
|
import { createUnitsApi } from './internal/createUnitsApi';
|
|
4
|
-
import { createMediaQueriesApi, } from './internal/createMediaQueriesApi';
|
|
5
4
|
export const createCalipers = (config = {}) => {
|
|
6
5
|
var _a;
|
|
7
6
|
const errorStore = createErrorConfigStore((_a = config.errorConfig) !== null && _a !== void 0 ? _a : {});
|
|
8
7
|
const core = createCoreApi(errorStore);
|
|
9
8
|
const units = createUnitsApi(core);
|
|
10
|
-
const mediaQueries = createMediaQueriesApi(core);
|
|
11
9
|
return {
|
|
12
10
|
...core,
|
|
13
11
|
...units,
|
|
14
|
-
mediaQueries,
|
|
15
12
|
units,
|
|
16
13
|
};
|
|
17
14
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-calipers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Compile-time unit safety for numeric, unit-bearing CSS values via typed measurements.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
"files": [
|
|
29
29
|
"dist",
|
|
30
30
|
"README.md",
|
|
31
|
-
"LICENSE.txt"
|
|
32
|
-
"RELEASING.md"
|
|
31
|
+
"LICENSE.txt"
|
|
33
32
|
],
|
|
34
33
|
"sideEffects": false,
|
|
35
34
|
"type": "commonjs",
|
|
@@ -42,11 +41,6 @@
|
|
|
42
41
|
"import": "./dist/esm/index.js",
|
|
43
42
|
"require": "./dist/cjs/index.js"
|
|
44
43
|
},
|
|
45
|
-
"./mediaQueries": {
|
|
46
|
-
"types": "./dist/esm/mediaQueries/index.d.ts",
|
|
47
|
-
"import": "./dist/esm/mediaQueries/index.js",
|
|
48
|
-
"require": "./dist/cjs/mediaQueries/index.js"
|
|
49
|
-
},
|
|
50
44
|
"./factory": {
|
|
51
45
|
"types": "./dist/esm/factory.d.ts",
|
|
52
46
|
"import": "./dist/esm/factory.js",
|
|
@@ -86,14 +80,7 @@
|
|
|
86
80
|
"build:examples": "tsc -p tsconfig.examples.json --noEmit",
|
|
87
81
|
"build:test": "npm run build && npm run test",
|
|
88
82
|
"build:delete": "node -e \"const { existsSync, rmSync } = require('fs'); const paths = ['dist/cjs', 'dist/esm']; for (const p of paths) { console.log('Scanning', p + '...'); if (existsSync(p)) { console.log('Found', p + ', deleting...'); rmSync(p, { recursive: true, force: true }); console.log('Deleted', p); } else { console.log(p + ' not found, skipping.'); } }\"",
|
|
89
|
-
"
|
|
90
|
-
"release": "node scripts/release.mjs",
|
|
91
|
-
"release:dry": "node scripts/release.mjs --dry-run",
|
|
92
|
-
"test": "npm run build && npm run test:core && npm run test:ratio && npm run test:mediaQueries && npm run test:factory && npm run test:dist && npm run test:types && npm run test:tsc && npm run lint && npm run test:internal",
|
|
93
|
-
"test:mediaQueries": "vitest run tests/runtime/mediaQueries/mediaQueries.src.test.ts",
|
|
94
|
-
"test:mediaQueries:cjs": "vitest run tests/runtime/mediaQueries/mediaQueries.cjs.test.ts tests/runtime/api-surface/mediaQueries.api-surface.cjs.test.ts",
|
|
95
|
-
"test:mediaQueries:esm": "vitest run tests/runtime/mediaQueries/mediaQueries.esm.test.ts tests/runtime/api-surface/mediaQueries.api-surface.esm.test.ts",
|
|
96
|
-
"test:mediaQueries:dist": "npm run test:mediaQueries:cjs && npm run test:mediaQueries:esm",
|
|
83
|
+
"test": "npm run build && npm run test:core && npm run test:ratio && npm run test:factory && npm run test:dist && npm run test:types && npm run test:tsc && npm run lint && npm run test:internal",
|
|
97
84
|
"test:core": "vitest run tests/runtime/core/core.src.test.ts",
|
|
98
85
|
"test:ratio": "vitest run tests/runtime/ratio/ratio.src.test.ts",
|
|
99
86
|
"test:core:cjs": "vitest run tests/runtime/core/core.cjs.test.ts tests/runtime/api-surface/api-surface.cjs.test.ts",
|
|
@@ -103,11 +90,11 @@
|
|
|
103
90
|
"test:lint": "npm run lint",
|
|
104
91
|
"test:types": "echo \"\n 🧪 Starting tsd type checks...\n\" && tsd --files tests/types/**/*.test-d.ts && echo \"✅ tsd type checks passed!\n\"",
|
|
105
92
|
"test:tsc": "tsc -p tsconfig.json --noEmit",
|
|
106
|
-
"test:dist": "npm run test:core:dist && npm run test:
|
|
93
|
+
"test:dist": "npm run test:core:dist && npm run test:factory:dist",
|
|
107
94
|
"test:factory": "vitest run tests/runtime/factory/factory.src.test.ts",
|
|
108
95
|
"test:factory:cjs": "vitest run tests/runtime/factory/factory.cjs.test.ts tests/runtime/api-surface/factory.api-surface.cjs.test.ts",
|
|
109
96
|
"test:factory:esm": "vitest run tests/runtime/factory/factory.esm.test.ts tests/runtime/api-surface/factory.api-surface.esm.test.ts",
|
|
110
97
|
"test:factory:dist": "npm run test:factory:cjs && npm run test:factory:esm",
|
|
111
98
|
"test:internal": "tsc -p tsconfig.internal.json --noEmit"
|
|
112
99
|
}
|
|
113
|
-
}
|
|
100
|
+
}
|
package/RELEASING.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# Releasing CSS-Calipers
|
|
2
|
-
|
|
3
|
-
This document describes how to publish a new version of `css-calipers` to npm
|
|
4
|
-
using the local release script.
|
|
5
|
-
|
|
6
|
-
## Prerequisites
|
|
7
|
-
|
|
8
|
-
- You have push access to the `main` branch of the repository.
|
|
9
|
-
- You are logged in to npm with an account that can publish the
|
|
10
|
-
`css-calipers` package (`npm whoami` should work).
|
|
11
|
-
- If your npm account uses 2FA, be ready to enter your OTP during
|
|
12
|
-
`npm publish`.
|
|
13
|
-
- The supported runtime target for published builds is Node 18 or newer.
|
|
14
|
-
|
|
15
|
-
## Release flow (local, scripted)
|
|
16
|
-
|
|
17
|
-
Releases should be performed via the `release` script rather than calling
|
|
18
|
-
`npm publish` directly.
|
|
19
|
-
|
|
20
|
-
1. Ensure your local `main` branch is up to date.
|
|
21
|
-
2. From the project root, run `npm run release`.
|
|
22
|
-
|
|
23
|
-
3. The script will:
|
|
24
|
-
- Verify that the current branch is `main` (abort otherwise).
|
|
25
|
-
- Warn if there are uncommitted changes and ask whether to continue.
|
|
26
|
-
- Run the core tests (`npm run test:core`).
|
|
27
|
-
- Run the build (`npm run build`) to produce `dist/cjs` and `dist/esm`.
|
|
28
|
-
- Check that the expected build outputs exist.
|
|
29
|
-
- Run the dist tests (`npm run test:dist`) against both CJS and ESM outputs.
|
|
30
|
-
- Run the type tests (`npm run test:types`).
|
|
31
|
-
- Prompt you to choose the version bump (`patch`, `minor`, or `major`).
|
|
32
|
-
- Run `npm version <type>` to bump the version and create a tag.
|
|
33
|
-
- Show the new version and ask for final confirmation before publishing.
|
|
34
|
-
- On confirmation, run `npm publish` (with a special environment variable
|
|
35
|
-
set), which also triggers the `prepublishOnly` hook and publishes under
|
|
36
|
-
the default `latest` dist-tag.
|
|
37
|
-
|
|
38
|
-
If any step fails (tests, build, or publish), the script will exit with a
|
|
39
|
-
non-zero status and print an error message.
|
|
40
|
-
|
|
41
|
-
## prepublishOnly safety net
|
|
42
|
-
|
|
43
|
-
The `prepublishOnly` npm script is configured to refuse direct `npm publish`
|
|
44
|
-
unless the `CSS_CALIPERS_RELEASE` environment variable is set. It does not
|
|
45
|
-
re-run tests or builds; those are handled by the release script.
|
|
46
|
-
|
|
47
|
-
The `prepublishOnly` hook runs automatically on every `npm publish` and will
|
|
48
|
-
block publishing if the environment guard fails.
|
|
49
|
-
|
|
50
|
-
## Dist-tag strategy
|
|
51
|
-
|
|
52
|
-
- All releases are currently published with npm’s default `latest` dist-tag.
|
|
53
|
-
- There is no separate `next`/`beta` channel yet; if that changes, both this
|
|
54
|
-
document and the release script should be updated to reflect the new
|
|
55
|
-
tagging behavior.
|
|
56
|
-
|
|
57
|
-
## Notes and future improvements
|
|
58
|
-
|
|
59
|
-
- Direct `npm publish` is discouraged; prefer `npm run release` so all checks
|
|
60
|
-
run consistently.
|
|
61
|
-
- In the future, publishing can be moved to CI (for example, from tags on
|
|
62
|
-
`main`) without changing the core expectations described here.
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compare = void 0;
|
|
4
|
-
exports.compare = {
|
|
5
|
-
eq: (value) => ({
|
|
6
|
-
operator: "=",
|
|
7
|
-
value,
|
|
8
|
-
}),
|
|
9
|
-
lt: (value) => ({
|
|
10
|
-
operator: "<",
|
|
11
|
-
value,
|
|
12
|
-
}),
|
|
13
|
-
lte: (value) => ({
|
|
14
|
-
operator: "<=",
|
|
15
|
-
value,
|
|
16
|
-
}),
|
|
17
|
-
gt: (value) => ({
|
|
18
|
-
operator: ">",
|
|
19
|
-
value,
|
|
20
|
-
}),
|
|
21
|
-
gte: (value) => ({
|
|
22
|
-
operator: ">=",
|
|
23
|
-
value,
|
|
24
|
-
}),
|
|
25
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeContainerQueryStyle = exports.buildContainerConditionString = exports.buildContainerQueryString = exports.emitCoreFeatures = exports.createEmitCoreFeatures = void 0;
|
|
4
|
-
const modules_1 = require("./modules");
|
|
5
|
-
const linting_1 = require("./linting");
|
|
6
|
-
const core_1 = require("./linting/core");
|
|
7
|
-
const validation_1 = require("./validation");
|
|
8
|
-
const helpers_1 = require("./helpers");
|
|
9
|
-
const createEmitCoreFeatures = (validation) => (props, helpers) => {
|
|
10
|
-
const allowQueryArrays = helpers.config.allowQueryArrays !== false;
|
|
11
|
-
const assertNoArray = (value, label) => {
|
|
12
|
-
if (Array.isArray(value) && !allowQueryArrays) {
|
|
13
|
-
throw new Error(`${label} does not allow arrays.`);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const emitFeature = (name, value) => {
|
|
17
|
-
if (Array.isArray(value)) {
|
|
18
|
-
value.forEach((entry) => {
|
|
19
|
-
var _a;
|
|
20
|
-
((_a = helpers.addFeatureUnsafe) !== null && _a !== void 0 ? _a : helpers.addFeature)(name, entry);
|
|
21
|
-
});
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
helpers.addFeature(name, value);
|
|
25
|
-
};
|
|
26
|
-
const { runContainerQueryValidation, validateMinMaxWidth, validateWidthValuesPositive, validateMinMaxHeight, validateHeightValuesPositive, } = validation;
|
|
27
|
-
if (!runContainerQueryValidation(props, helpers, validateMinMaxWidth, "core", "minWidth must be less than or equal to maxWidth")) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (!runContainerQueryValidation(props, helpers, validateMinMaxHeight, "core", "minHeight must be less than or equal to maxHeight")) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (!runContainerQueryValidation(props, helpers, validateWidthValuesPositive, "core", "width values must be greater than 0")) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (!runContainerQueryValidation(props, helpers, validateHeightValuesPositive, "core", "height values must be greater than 0")) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (!(0, linting_1.runContainerQueryLint)(props, helpers, core_1.lintWidthExactRedundancy, "minWidth should not be combined with maxWidth when both are equal")) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (!(0, linting_1.runContainerQueryLint)(props, helpers, core_1.lintHeightExactRedundancy, "minHeight should not be combined with maxHeight when both are equal")) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (props.minWidth !== undefined) {
|
|
46
|
-
assertNoArray(props.minWidth, "minWidth");
|
|
47
|
-
emitFeature("min-width", props.minWidth);
|
|
48
|
-
}
|
|
49
|
-
if (props.maxWidth !== undefined) {
|
|
50
|
-
assertNoArray(props.maxWidth, "maxWidth");
|
|
51
|
-
emitFeature("max-width", props.maxWidth);
|
|
52
|
-
}
|
|
53
|
-
if (props.minHeight !== undefined) {
|
|
54
|
-
assertNoArray(props.minHeight, "minHeight");
|
|
55
|
-
emitFeature("min-height", props.minHeight);
|
|
56
|
-
}
|
|
57
|
-
if (props.maxHeight !== undefined) {
|
|
58
|
-
assertNoArray(props.maxHeight, "maxHeight");
|
|
59
|
-
emitFeature("max-height", props.maxHeight);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
exports.createEmitCoreFeatures = createEmitCoreFeatures;
|
|
63
|
-
exports.emitCoreFeatures = (0, exports.createEmitCoreFeatures)(validation_1.defaultContainerQueryValidation);
|
|
64
|
-
const emitBaseFeatures = (props, helpers) => {
|
|
65
|
-
(0, exports.emitCoreFeatures)(props, helpers);
|
|
66
|
-
(0, modules_1.emitAspectRatioFeatures)(props, helpers);
|
|
67
|
-
(0, modules_1.emitInlineSizeFeatures)(props, helpers);
|
|
68
|
-
(0, modules_1.emitBlockSizeFeatures)(props, helpers);
|
|
69
|
-
(0, modules_1.emitStyleFeatures)(props, helpers);
|
|
70
|
-
(0, modules_1.emitCustomFeatures)(props, helpers);
|
|
71
|
-
};
|
|
72
|
-
exports.buildContainerQueryString = (0, helpers_1.createContainerQueryBuilder)({
|
|
73
|
-
emitBase: emitBaseFeatures,
|
|
74
|
-
});
|
|
75
|
-
const wrapContainerCondition = (value) => {
|
|
76
|
-
const trimmed = value.trim();
|
|
77
|
-
if (trimmed.includes(" and ") ||
|
|
78
|
-
trimmed.includes(" or ") ||
|
|
79
|
-
trimmed.startsWith("not ")) {
|
|
80
|
-
return `(${trimmed})`;
|
|
81
|
-
}
|
|
82
|
-
return trimmed;
|
|
83
|
-
};
|
|
84
|
-
const buildContainerConditionString = (condition) => {
|
|
85
|
-
if ("and" in condition) {
|
|
86
|
-
return condition.and
|
|
87
|
-
.map((entry) => wrapContainerCondition((0, exports.buildContainerConditionString)(entry)))
|
|
88
|
-
.join(" and ");
|
|
89
|
-
}
|
|
90
|
-
if ("or" in condition) {
|
|
91
|
-
return condition.or
|
|
92
|
-
.map((entry) => wrapContainerCondition((0, exports.buildContainerConditionString)(entry)))
|
|
93
|
-
.join(" or ");
|
|
94
|
-
}
|
|
95
|
-
if ("not" in condition) {
|
|
96
|
-
return `not ${wrapContainerCondition((0, exports.buildContainerConditionString)(condition.not))}`;
|
|
97
|
-
}
|
|
98
|
-
return (0, exports.buildContainerQueryString)(condition);
|
|
99
|
-
};
|
|
100
|
-
exports.buildContainerConditionString = buildContainerConditionString;
|
|
101
|
-
const makeContainerQueryStyle = (queries) => (stylesByQuery) => {
|
|
102
|
-
const result = {};
|
|
103
|
-
Object.keys(stylesByQuery).forEach((key) => {
|
|
104
|
-
const styles = stylesByQuery[key];
|
|
105
|
-
const props = queries[key];
|
|
106
|
-
if (!styles || !props)
|
|
107
|
-
return;
|
|
108
|
-
result[(0, exports.buildContainerQueryString)(props)] = styles;
|
|
109
|
-
});
|
|
110
|
-
const containerQuery = {
|
|
111
|
-
"@container": result,
|
|
112
|
-
};
|
|
113
|
-
return containerQuery;
|
|
114
|
-
};
|
|
115
|
-
exports.makeContainerQueryStyle = makeContainerQueryStyle;
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.containerQueryFactory = exports.createContainerQueryFactory = void 0;
|
|
4
|
-
const containerQueries_1 = require("./containerQueries");
|
|
5
|
-
const ALL_CONTAINER_QUERY_MODULES = [
|
|
6
|
-
"core",
|
|
7
|
-
"inline",
|
|
8
|
-
"block",
|
|
9
|
-
"aspectRatio",
|
|
10
|
-
"style",
|
|
11
|
-
"custom",
|
|
12
|
-
];
|
|
13
|
-
const MODULE_KEYS = {
|
|
14
|
-
core: ["minWidth", "maxWidth", "minHeight", "maxHeight"],
|
|
15
|
-
inline: ["inlineSize", "inlineSizeRange"],
|
|
16
|
-
block: ["blockSize", "blockSizeRange"],
|
|
17
|
-
aspectRatio: ["aspectRatio", "minAspectRatio", "maxAspectRatio"],
|
|
18
|
-
style: ["style"],
|
|
19
|
-
custom: ["customFeatures"],
|
|
20
|
-
};
|
|
21
|
-
const KEY_TO_MODULE = Object.fromEntries(Object.keys(MODULE_KEYS).flatMap((moduleId) => MODULE_KEYS[moduleId].map((key) => [key, moduleId])));
|
|
22
|
-
const collectConditionKeys = (condition, keys) => {
|
|
23
|
-
if ("and" in condition) {
|
|
24
|
-
condition.and.forEach((entry) => collectConditionKeys(entry, keys));
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if ("or" in condition) {
|
|
28
|
-
condition.or.forEach((entry) => collectConditionKeys(entry, keys));
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if ("not" in condition) {
|
|
32
|
-
collectConditionKeys(condition.not, keys);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
Object.keys(condition).forEach((key) => keys.add(key));
|
|
36
|
-
};
|
|
37
|
-
const collectAndConditionKeys = (condition, keys) => {
|
|
38
|
-
if ("and" in condition) {
|
|
39
|
-
condition.and.forEach((entry) => collectAndConditionKeys(entry, keys));
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if ("or" in condition || "not" in condition) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
Object.keys(condition).forEach((key) => keys.push(key));
|
|
46
|
-
};
|
|
47
|
-
const guardUnsupportedCondition = (condition, modules, config, label) => {
|
|
48
|
-
const allowed = new Set();
|
|
49
|
-
modules.forEach((moduleId) => {
|
|
50
|
-
MODULE_KEYS[moduleId].forEach((key) => {
|
|
51
|
-
allowed.add(key);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
const conditionKeys = new Set();
|
|
55
|
-
collectConditionKeys(condition, conditionKeys);
|
|
56
|
-
conditionKeys.forEach((key) => {
|
|
57
|
-
var _a, _b;
|
|
58
|
-
if (allowed.has(key))
|
|
59
|
-
return;
|
|
60
|
-
const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : "throw";
|
|
61
|
-
const moduleHint = KEY_TO_MODULE[key];
|
|
62
|
-
const moduleSuffix = moduleHint
|
|
63
|
-
? ` Add "${moduleHint}" to modules.`
|
|
64
|
-
: "";
|
|
65
|
-
const message = `Container query factory "${label}" received unsupported feature "${key}".${moduleSuffix}`;
|
|
66
|
-
if (mode === "log") {
|
|
67
|
-
console.warn(message);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (mode === "allow")
|
|
71
|
-
return;
|
|
72
|
-
throw new Error(message);
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
const guardDuplicateConditions = (condition, config, label) => {
|
|
76
|
-
var _a, _b;
|
|
77
|
-
const keys = [];
|
|
78
|
-
collectAndConditionKeys(condition, keys);
|
|
79
|
-
const seen = new Set();
|
|
80
|
-
const duplicates = new Set();
|
|
81
|
-
keys.forEach((key) => {
|
|
82
|
-
if (seen.has(key)) {
|
|
83
|
-
duplicates.add(key);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
seen.add(key);
|
|
87
|
-
});
|
|
88
|
-
if (!duplicates.size)
|
|
89
|
-
return;
|
|
90
|
-
const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : "throw";
|
|
91
|
-
const message = `Container query factory "${label}" received duplicate condition "${Array.from(duplicates).join('", "')}".`;
|
|
92
|
-
if (mode === "log") {
|
|
93
|
-
console.warn(message);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (mode === "allow")
|
|
97
|
-
return;
|
|
98
|
-
throw new Error(message);
|
|
99
|
-
};
|
|
100
|
-
const createContainerQueryFactory = () => (options) => {
|
|
101
|
-
var _a;
|
|
102
|
-
const modules = (_a = options.config.modules) !== null && _a !== void 0 ? _a : ALL_CONTAINER_QUERY_MODULES;
|
|
103
|
-
return (stylesByQuery) => {
|
|
104
|
-
const result = {};
|
|
105
|
-
Object.keys(stylesByQuery).forEach((key) => {
|
|
106
|
-
const styles = stylesByQuery[key];
|
|
107
|
-
const rule = options.queries[key];
|
|
108
|
-
if (!styles || !(rule === null || rule === void 0 ? void 0 : rule.query))
|
|
109
|
-
return;
|
|
110
|
-
guardUnsupportedCondition(rule.query.condition, modules, options.config, options.config.label);
|
|
111
|
-
guardDuplicateConditions(rule.query.condition, options.config, options.config.label);
|
|
112
|
-
result[(0, containerQueries_1.buildContainerConditionString)(rule.query.condition)] = styles;
|
|
113
|
-
});
|
|
114
|
-
const containerQuery = {
|
|
115
|
-
"@container": result,
|
|
116
|
-
};
|
|
117
|
-
return options.config.output
|
|
118
|
-
? options.config.output(containerQuery)
|
|
119
|
-
: containerQuery;
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
exports.createContainerQueryFactory = createContainerQueryFactory;
|
|
123
|
-
exports.containerQueryFactory = (0, exports.createContainerQueryFactory)();
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applyContainerQueryValidation = exports.createContainerQueryBuilder = exports.createContainerQueryFeatureEmitterWithTracking = exports.createContainerQueryConditionEmitter = exports.createContainerQueryFeatureEmitter = exports.formatContainerQueryComparison = exports.buildContainerQueryStringFromParts = exports.buildContainerRange = exports.buildContainerComparison = exports.formatContainerQueryValue = void 0;
|
|
4
|
-
const core_1 = require("../core");
|
|
5
|
-
const validation_1 = require("../validation");
|
|
6
|
-
const formatContainerQueryValue = (value) => ((0, core_1.hasCssMethod)(value) ? value.css() : String(value));
|
|
7
|
-
exports.formatContainerQueryValue = formatContainerQueryValue;
|
|
8
|
-
const buildContainerComparison = (comparison) => comparison;
|
|
9
|
-
exports.buildContainerComparison = buildContainerComparison;
|
|
10
|
-
const buildContainerRange = (min, max, options = {}) => {
|
|
11
|
-
var _a;
|
|
12
|
-
const mode = (_a = options.mode) !== null && _a !== void 0 ? _a : "min";
|
|
13
|
-
const operator = options.inclusive === false ? "<" : "<=";
|
|
14
|
-
if (mode === "max") {
|
|
15
|
-
return { min, max, maxOperator: operator };
|
|
16
|
-
}
|
|
17
|
-
return { min, max, minOperator: operator };
|
|
18
|
-
};
|
|
19
|
-
exports.buildContainerRange = buildContainerRange;
|
|
20
|
-
const buildContainerQueryStringFromParts = (parts) => parts.join(" and ");
|
|
21
|
-
exports.buildContainerQueryStringFromParts = buildContainerQueryStringFromParts;
|
|
22
|
-
const formatContainerQueryComparison = (name, operator, value) => {
|
|
23
|
-
return `(${name} ${operator} ${(0, exports.formatContainerQueryValue)(value)})`;
|
|
24
|
-
};
|
|
25
|
-
exports.formatContainerQueryComparison = formatContainerQueryComparison;
|
|
26
|
-
const createContainerQueryFeatureEmitter = (parts) => (name, value) => {
|
|
27
|
-
parts.push(`(${name}: ${(0, exports.formatContainerQueryValue)(value)})`);
|
|
28
|
-
};
|
|
29
|
-
exports.createContainerQueryFeatureEmitter = createContainerQueryFeatureEmitter;
|
|
30
|
-
const createContainerQueryConditionEmitter = (parts) => (condition) => {
|
|
31
|
-
parts.push(condition);
|
|
32
|
-
};
|
|
33
|
-
exports.createContainerQueryConditionEmitter = createContainerQueryConditionEmitter;
|
|
34
|
-
const createContainerQueryFeatureEmitterWithTracking = (parts, options = {}) => {
|
|
35
|
-
const { emitted, lintingMode = "throw" } = options;
|
|
36
|
-
return (name, value) => {
|
|
37
|
-
if (emitted === null || emitted === void 0 ? void 0 : emitted.has(name)) {
|
|
38
|
-
if (lintingMode === "throw") {
|
|
39
|
-
throw new Error(`Container query feature "${name}" was emitted more than once.`);
|
|
40
|
-
}
|
|
41
|
-
if (lintingMode === "log") {
|
|
42
|
-
console.warn(`Container query feature "${name}" was emitted more than once; using the latest value.`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
emitted === null || emitted === void 0 ? void 0 : emitted.add(name);
|
|
46
|
-
parts.push(`(${name}: ${(0, exports.formatContainerQueryValue)(value)})`);
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
exports.createContainerQueryFeatureEmitterWithTracking = createContainerQueryFeatureEmitterWithTracking;
|
|
50
|
-
const createContainerQueryBuilder = (options) => {
|
|
51
|
-
return (config) => {
|
|
52
|
-
var _a, _b, _c, _d, _e;
|
|
53
|
-
const parts = [];
|
|
54
|
-
const emittedFeatures = new Set();
|
|
55
|
-
const helpers = {
|
|
56
|
-
addFeature: (0, exports.createContainerQueryFeatureEmitterWithTracking)(parts, {
|
|
57
|
-
emitted: emittedFeatures,
|
|
58
|
-
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",
|
|
59
|
-
}),
|
|
60
|
-
addFeatureUnsafe: (0, exports.createContainerQueryFeatureEmitter)(parts),
|
|
61
|
-
addCondition: (0, exports.createContainerQueryConditionEmitter)(parts),
|
|
62
|
-
config: (_d = options.config) !== null && _d !== void 0 ? _d : {},
|
|
63
|
-
};
|
|
64
|
-
options.emitBase(config, helpers);
|
|
65
|
-
(_e = options.emitExtensions) === null || _e === void 0 ? void 0 : _e.call(options, config, helpers);
|
|
66
|
-
return (0, exports.buildContainerQueryStringFromParts)(parts);
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
exports.createContainerQueryBuilder = createContainerQueryBuilder;
|
|
70
|
-
const applyContainerQueryValidation = (config, helpers, validator, context) => {
|
|
71
|
-
var _a, _b;
|
|
72
|
-
if (!validator)
|
|
73
|
-
return true;
|
|
74
|
-
const normalized = (0, validation_1.normalizeValidationResult)(validator(config));
|
|
75
|
-
if (normalized.valid)
|
|
76
|
-
return true;
|
|
77
|
-
const mode = (_b = (_a = helpers.config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : "throw";
|
|
78
|
-
if (mode === "log") {
|
|
79
|
-
const suffix = normalized.message ? `: ${normalized.message}` : "";
|
|
80
|
-
const prefix = context
|
|
81
|
-
? `Container query ${context} validation failed`
|
|
82
|
-
: "Container query validation failed";
|
|
83
|
-
console.warn(`${prefix}${suffix}`);
|
|
84
|
-
}
|
|
85
|
-
if (mode === "allow")
|
|
86
|
-
return true;
|
|
87
|
-
if (mode === "log")
|
|
88
|
-
return true;
|
|
89
|
-
const suffix = normalized.message ? `: ${normalized.message}` : "";
|
|
90
|
-
const prefix = context
|
|
91
|
-
? `Container query ${context} validation failed`
|
|
92
|
-
: "Container query validation failed";
|
|
93
|
-
throw new Error(`${prefix}${suffix}`);
|
|
94
|
-
};
|
|
95
|
-
exports.applyContainerQueryValidation = applyContainerQueryValidation;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineContainerQueryModules = exports.createContainerQueryFactory = exports.containerQueryFactory = exports.formatContainerQueryValue = exports.buildContainerRange = exports.buildContainerComparison = exports.makeContainerQueryStyle = exports.buildContainerQueryString = exports.buildContainerConditionString = void 0;
|
|
4
|
-
var containerQueries_1 = require("./containerQueries");
|
|
5
|
-
Object.defineProperty(exports, "buildContainerConditionString", { enumerable: true, get: function () { return containerQueries_1.buildContainerConditionString; } });
|
|
6
|
-
Object.defineProperty(exports, "buildContainerQueryString", { enumerable: true, get: function () { return containerQueries_1.buildContainerQueryString; } });
|
|
7
|
-
Object.defineProperty(exports, "makeContainerQueryStyle", { enumerable: true, get: function () { return containerQueries_1.makeContainerQueryStyle; } });
|
|
8
|
-
var helpers_1 = require("./helpers");
|
|
9
|
-
Object.defineProperty(exports, "buildContainerComparison", { enumerable: true, get: function () { return helpers_1.buildContainerComparison; } });
|
|
10
|
-
Object.defineProperty(exports, "buildContainerRange", { enumerable: true, get: function () { return helpers_1.buildContainerRange; } });
|
|
11
|
-
Object.defineProperty(exports, "formatContainerQueryValue", { enumerable: true, get: function () { return helpers_1.formatContainerQueryValue; } });
|
|
12
|
-
var factory_1 = require("./factory");
|
|
13
|
-
Object.defineProperty(exports, "containerQueryFactory", { enumerable: true, get: function () { return factory_1.containerQueryFactory; } });
|
|
14
|
-
Object.defineProperty(exports, "createContainerQueryFactory", { enumerable: true, get: function () { return factory_1.createContainerQueryFactory; } });
|
|
15
|
-
var moduleRegistry_1 = require("./moduleRegistry");
|
|
16
|
-
Object.defineProperty(exports, "defineContainerQueryModules", { enumerable: true, get: function () { return moduleRegistry_1.defineContainerQueryModules; } });
|