css-calipers 0.9.2 → 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.
Files changed (260) hide show
  1. package/README.md +100 -0
  2. package/dist/cjs/comparisons/index.js +25 -0
  3. package/dist/cjs/containerQueries/containerQueries.js +115 -0
  4. package/dist/cjs/containerQueries/factory.js +123 -0
  5. package/dist/cjs/containerQueries/helpers.js +95 -0
  6. package/dist/cjs/containerQueries/index.js +16 -0
  7. package/dist/cjs/containerQueries/linting/aspectRatio.js +24 -0
  8. package/dist/cjs/containerQueries/linting/block.js +23 -0
  9. package/dist/cjs/containerQueries/linting/core.js +25 -0
  10. package/dist/cjs/containerQueries/linting/custom.js +11 -0
  11. package/dist/cjs/containerQueries/linting/inline.js +23 -0
  12. package/dist/cjs/containerQueries/linting/resolution.js +12 -0
  13. package/dist/cjs/containerQueries/linting/style.js +28 -0
  14. package/dist/cjs/containerQueries/linting.js +24 -0
  15. package/dist/cjs/containerQueries/moduleRegistry.js +5 -0
  16. package/dist/cjs/containerQueries/modules/aspectRatio.js +51 -0
  17. package/dist/cjs/containerQueries/modules/block.js +53 -0
  18. package/dist/cjs/containerQueries/modules/custom.js +43 -0
  19. package/dist/cjs/containerQueries/modules/index.js +21 -0
  20. package/dist/cjs/containerQueries/modules/inline.js +53 -0
  21. package/dist/cjs/containerQueries/modules/size.js +2 -0
  22. package/dist/cjs/containerQueries/modules/style.js +36 -0
  23. package/dist/cjs/containerQueries/types.js +2 -0
  24. package/dist/cjs/containerQueries/validation.js +191 -0
  25. package/dist/cjs/core.js +5 -278
  26. package/dist/cjs/factory.js +21 -0
  27. package/dist/cjs/fraction.js +139 -0
  28. package/dist/cjs/internal/buildMeasurementCreationError.js +16 -0
  29. package/dist/cjs/internal/buildMeasurementCreationError.tests.js +5 -0
  30. package/dist/cjs/internal/createComponentQueriesApi.js +56 -0
  31. package/dist/cjs/internal/createCoreApi.js +336 -0
  32. package/dist/cjs/internal/createMediaQueriesApi.js +74 -0
  33. package/dist/cjs/internal/createUnitsApi.js +18 -0
  34. package/dist/cjs/internal/errors.js +118 -5
  35. package/dist/cjs/internal/normalizeToArray.js +9 -0
  36. package/dist/cjs/libraryHelpers/vanilla-extract.js +6 -2
  37. package/dist/cjs/logicalOperators/index.js +18 -0
  38. package/dist/cjs/mediaQueries/factory.js +5 -4
  39. package/dist/cjs/mediaQueries/mediaQueries.js +7 -5
  40. package/dist/cjs/mediaQueries/modules/dimensions.js +10 -8
  41. package/dist/cjs/mediaQueries/modules/resolution.js +6 -4
  42. package/dist/cjs/mediaQueries/validation.js +128 -116
  43. package/dist/cjs/ratio.js +141 -0
  44. package/dist/cjs/types.js +2 -0
  45. package/dist/cjs/validation.js +20 -0
  46. package/dist/esm/comparisons/index.d.ts +23 -0
  47. package/dist/esm/comparisons/index.d.ts.map +1 -0
  48. package/dist/esm/comparisons/index.js +22 -0
  49. package/dist/esm/containerQueries/containerQueries.d.ts +36 -0
  50. package/dist/esm/containerQueries/containerQueries.d.ts.map +1 -0
  51. package/dist/esm/containerQueries/containerQueries.js +109 -0
  52. package/dist/esm/containerQueries/factory.d.ts +20 -0
  53. package/dist/esm/containerQueries/factory.d.ts.map +1 -0
  54. package/dist/esm/containerQueries/factory.js +119 -0
  55. package/dist/esm/containerQueries/helpers.d.ts +53 -0
  56. package/dist/esm/containerQueries/helpers.d.ts.map +1 -0
  57. package/dist/esm/containerQueries/helpers.js +82 -0
  58. package/dist/esm/containerQueries/index.d.ts +10 -0
  59. package/dist/esm/containerQueries/index.d.ts.map +1 -0
  60. package/dist/esm/containerQueries/index.js +4 -0
  61. package/dist/esm/containerQueries/linting/aspectRatio.d.ts +4 -0
  62. package/dist/esm/containerQueries/linting/aspectRatio.d.ts.map +1 -0
  63. package/dist/esm/containerQueries/linting/aspectRatio.js +19 -0
  64. package/dist/esm/containerQueries/linting/block.d.ts +4 -0
  65. package/dist/esm/containerQueries/linting/block.d.ts.map +1 -0
  66. package/dist/esm/containerQueries/linting/block.js +18 -0
  67. package/dist/esm/containerQueries/linting/core.d.ts +4 -0
  68. package/dist/esm/containerQueries/linting/core.d.ts.map +1 -0
  69. package/dist/esm/containerQueries/linting/core.js +20 -0
  70. package/dist/esm/containerQueries/linting/custom.d.ts +3 -0
  71. package/dist/esm/containerQueries/linting/custom.d.ts.map +1 -0
  72. package/dist/esm/containerQueries/linting/custom.js +7 -0
  73. package/dist/esm/containerQueries/linting/inline.d.ts +4 -0
  74. package/dist/esm/containerQueries/linting/inline.d.ts.map +1 -0
  75. package/dist/esm/containerQueries/linting/inline.js +18 -0
  76. package/dist/esm/containerQueries/linting/resolution.d.ts +1 -0
  77. package/dist/esm/containerQueries/linting/resolution.d.ts.map +1 -0
  78. package/dist/esm/containerQueries/linting/resolution.js +12 -0
  79. package/dist/esm/containerQueries/linting/style.d.ts +3 -0
  80. package/dist/esm/containerQueries/linting/style.d.ts.map +1 -0
  81. package/dist/esm/containerQueries/linting/style.js +24 -0
  82. package/dist/esm/containerQueries/linting.d.ts +4 -0
  83. package/dist/esm/containerQueries/linting.d.ts.map +1 -0
  84. package/dist/esm/containerQueries/linting.js +20 -0
  85. package/dist/esm/containerQueries/moduleRegistry.d.ts +25 -0
  86. package/dist/esm/containerQueries/moduleRegistry.d.ts.map +1 -0
  87. package/dist/esm/containerQueries/moduleRegistry.js +1 -0
  88. package/dist/esm/containerQueries/modules/aspectRatio.d.ts +17 -0
  89. package/dist/esm/containerQueries/modules/aspectRatio.d.ts.map +1 -0
  90. package/dist/esm/containerQueries/modules/aspectRatio.js +47 -0
  91. package/dist/esm/containerQueries/modules/block.d.ts +20 -0
  92. package/dist/esm/containerQueries/modules/block.d.ts.map +1 -0
  93. package/dist/esm/containerQueries/modules/block.js +49 -0
  94. package/dist/esm/containerQueries/modules/custom.d.ts +13 -0
  95. package/dist/esm/containerQueries/modules/custom.d.ts.map +1 -0
  96. package/dist/esm/containerQueries/modules/custom.js +39 -0
  97. package/dist/esm/containerQueries/modules/index.d.ts +6 -0
  98. package/dist/esm/containerQueries/modules/index.d.ts.map +1 -0
  99. package/dist/esm/containerQueries/modules/index.js +5 -0
  100. package/dist/esm/containerQueries/modules/inline.d.ts +20 -0
  101. package/dist/esm/containerQueries/modules/inline.d.ts.map +1 -0
  102. package/dist/esm/containerQueries/modules/inline.js +49 -0
  103. package/dist/esm/containerQueries/modules/size.d.ts +41 -0
  104. package/dist/esm/containerQueries/modules/size.d.ts.map +1 -0
  105. package/dist/esm/containerQueries/modules/size.js +1 -0
  106. package/dist/esm/containerQueries/modules/style.d.ts +11 -0
  107. package/dist/esm/containerQueries/modules/style.d.ts.map +1 -0
  108. package/dist/esm/containerQueries/modules/style.js +32 -0
  109. package/dist/esm/containerQueries/types.d.ts +81 -0
  110. package/dist/esm/containerQueries/types.d.ts.map +1 -0
  111. package/dist/esm/containerQueries/types.js +1 -0
  112. package/dist/esm/containerQueries/validation.d.ts +41 -0
  113. package/dist/esm/containerQueries/validation.d.ts.map +1 -0
  114. package/dist/esm/containerQueries/validation.js +187 -0
  115. package/dist/esm/core.d.ts +27 -26
  116. package/dist/esm/core.d.ts.map +1 -1
  117. package/dist/esm/core.js +5 -266
  118. package/dist/esm/factory.d.ts +13 -0
  119. package/dist/esm/factory.d.ts.map +1 -0
  120. package/dist/esm/factory.js +17 -0
  121. package/dist/esm/fraction.d.ts +23 -0
  122. package/dist/esm/fraction.d.ts.map +1 -0
  123. package/dist/esm/fraction.js +129 -0
  124. package/dist/esm/internal/buildMeasurementCreationError.d.ts +12 -0
  125. package/dist/esm/internal/buildMeasurementCreationError.d.ts.map +1 -0
  126. package/dist/esm/internal/buildMeasurementCreationError.js +12 -0
  127. package/dist/esm/internal/buildMeasurementCreationError.tests.d.ts +3 -0
  128. package/dist/esm/internal/buildMeasurementCreationError.tests.d.ts.map +1 -0
  129. package/dist/esm/internal/buildMeasurementCreationError.tests.js +1 -0
  130. package/dist/esm/internal/createComponentQueriesApi.d.ts +34 -0
  131. package/dist/esm/internal/createComponentQueriesApi.d.ts.map +1 -0
  132. package/dist/esm/internal/createComponentQueriesApi.js +52 -0
  133. package/dist/esm/internal/createCoreApi.d.ts +289 -0
  134. package/dist/esm/internal/createCoreApi.d.ts.map +1 -0
  135. package/dist/esm/internal/createCoreApi.js +332 -0
  136. package/dist/esm/internal/createMediaQueriesApi.d.ts +35 -0
  137. package/dist/esm/internal/createMediaQueriesApi.d.ts.map +1 -0
  138. package/dist/esm/internal/createMediaQueriesApi.js +70 -0
  139. package/dist/esm/internal/createUnitsApi.d.ts +13 -0
  140. package/dist/esm/internal/createUnitsApi.d.ts.map +1 -0
  141. package/dist/esm/internal/createUnitsApi.js +14 -0
  142. package/dist/esm/internal/errors.d.ts +30 -0
  143. package/dist/esm/internal/errors.d.ts.map +1 -1
  144. package/dist/esm/internal/errors.js +113 -4
  145. package/dist/esm/internal/normalizeToArray.d.ts +2 -0
  146. package/dist/esm/internal/normalizeToArray.d.ts.map +1 -0
  147. package/dist/esm/internal/normalizeToArray.js +5 -0
  148. package/dist/esm/libraryHelpers/vanilla-extract.d.ts +2 -1
  149. package/dist/esm/libraryHelpers/vanilla-extract.d.ts.map +1 -1
  150. package/dist/esm/libraryHelpers/vanilla-extract.js +4 -1
  151. package/dist/esm/logicalOperators/index.d.ts +2 -0
  152. package/dist/esm/logicalOperators/index.d.ts.map +1 -0
  153. package/dist/esm/logicalOperators/index.js +17 -0
  154. package/dist/esm/mediaQueries/factory.d.ts +16 -1
  155. package/dist/esm/mediaQueries/factory.d.ts.map +1 -1
  156. package/dist/esm/mediaQueries/factory.js +3 -2
  157. package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts +2 -2
  158. package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts.map +1 -1
  159. package/dist/esm/mediaQueries/mediaQueries.d.ts +2 -0
  160. package/dist/esm/mediaQueries/mediaQueries.d.ts.map +1 -1
  161. package/dist/esm/mediaQueries/mediaQueries.js +4 -2
  162. package/dist/esm/mediaQueries/modules/dimensions.d.ts +2 -0
  163. package/dist/esm/mediaQueries/modules/dimensions.d.ts.map +1 -1
  164. package/dist/esm/mediaQueries/modules/dimensions.js +4 -2
  165. package/dist/esm/mediaQueries/modules/resolution.d.ts +2 -0
  166. package/dist/esm/mediaQueries/modules/resolution.d.ts.map +1 -1
  167. package/dist/esm/mediaQueries/modules/resolution.js +4 -2
  168. package/dist/esm/mediaQueries/validation.d.ts +28 -8
  169. package/dist/esm/mediaQueries/validation.d.ts.map +1 -1
  170. package/dist/esm/mediaQueries/validation.js +126 -107
  171. package/dist/esm/package.json +3 -0
  172. package/dist/esm/ratio.d.ts +22 -0
  173. package/dist/esm/ratio.d.ts.map +1 -0
  174. package/dist/esm/ratio.js +131 -0
  175. package/dist/esm/types.d.ts +35 -0
  176. package/dist/esm/types.d.ts.map +1 -0
  177. package/dist/esm/types.js +1 -0
  178. package/dist/esm/validation.d.ts +10 -0
  179. package/dist/esm/validation.d.ts.map +1 -0
  180. package/dist/esm/validation.js +15 -0
  181. package/dist/examples/containerQueries.example.js +54 -0
  182. package/dist/examples/examples/containerQueries.example.js +54 -0
  183. package/dist/examples/examples/factory-wrapper.example.js +33 -0
  184. package/dist/examples/examples/lineHeight-normalizer.example.js +81 -0
  185. package/dist/examples/examples/mediaQueries-multipleInstances.example.js +127 -0
  186. package/dist/examples/examples/mixedQueries.example.js +55 -0
  187. package/dist/examples/examples/validation-and-runtime-checks.example.js +85 -0
  188. package/dist/examples/examples/validation-unit-tests.example.js +35 -0
  189. package/dist/examples/factory-wrapper.example.js +33 -0
  190. package/dist/examples/lineHeight-normalizer.example.js +81 -0
  191. package/dist/examples/mediaQueries-multipleInstances.example.js +127 -0
  192. package/dist/examples/mixedQueries.example.js +60 -0
  193. package/dist/examples/src/comparisons/index.js +25 -0
  194. package/dist/examples/src/containerQueries/containerQueries.js +96 -0
  195. package/dist/examples/src/containerQueries/factory.js +123 -0
  196. package/dist/examples/src/containerQueries/helpers.js +94 -0
  197. package/dist/examples/src/containerQueries/index.js +16 -0
  198. package/dist/examples/src/containerQueries/linting/aspectRatio.js +20 -0
  199. package/dist/examples/src/containerQueries/linting/block.js +20 -0
  200. package/dist/examples/src/containerQueries/linting/core.js +19 -0
  201. package/dist/examples/src/containerQueries/linting/custom.js +11 -0
  202. package/dist/examples/src/containerQueries/linting/inline.js +20 -0
  203. package/dist/examples/src/containerQueries/linting/style.js +28 -0
  204. package/dist/examples/src/containerQueries/linting.js +24 -0
  205. package/dist/examples/src/containerQueries/moduleRegistry.js +5 -0
  206. package/dist/examples/src/containerQueries/modules/aspectRatio.js +33 -0
  207. package/dist/examples/src/containerQueries/modules/block.js +44 -0
  208. package/dist/examples/src/containerQueries/modules/custom.js +31 -0
  209. package/dist/examples/src/containerQueries/modules/index.js +21 -0
  210. package/dist/examples/src/containerQueries/modules/inline.js +44 -0
  211. package/dist/examples/src/containerQueries/modules/style.js +36 -0
  212. package/dist/examples/src/containerQueries/types.js +2 -0
  213. package/dist/examples/src/containerQueries/validation.js +177 -0
  214. package/dist/examples/src/core.js +16 -0
  215. package/dist/examples/src/factory.js +21 -0
  216. package/dist/examples/src/index.js +30 -0
  217. package/dist/examples/src/internal/buildMeasurementCreationError.js +16 -0
  218. package/dist/examples/src/internal/createCoreApi.js +336 -0
  219. package/dist/examples/src/internal/createMediaQueriesApi.js +74 -0
  220. package/dist/examples/src/internal/createUnitsApi.js +18 -0
  221. package/dist/examples/src/internal/errors.js +130 -0
  222. package/dist/examples/src/libraryHelpers/vanilla-extract.js +11 -0
  223. package/dist/examples/src/mediaQueries/factory.js +163 -0
  224. package/dist/examples/src/mediaQueries/helpers.js +88 -0
  225. package/dist/examples/src/mediaQueries/index.js +23 -0
  226. package/dist/examples/src/mediaQueries/linting/core.js +19 -0
  227. package/dist/examples/src/mediaQueries/linting/resolution.js +11 -0
  228. package/dist/examples/src/mediaQueries/linting.js +24 -0
  229. package/dist/examples/src/mediaQueries/mediaQueries.js +53 -0
  230. package/dist/examples/src/mediaQueries/moduleRegistry.js +5 -0
  231. package/dist/examples/src/mediaQueries/modules/custom.js +26 -0
  232. package/dist/examples/src/mediaQueries/modules/dimensions.js +61 -0
  233. package/dist/examples/src/mediaQueries/modules/display.js +20 -0
  234. package/dist/examples/src/mediaQueries/modules/environment.js +20 -0
  235. package/dist/examples/src/mediaQueries/modules/index.js +23 -0
  236. package/dist/examples/src/mediaQueries/modules/interaction.js +26 -0
  237. package/dist/examples/src/mediaQueries/modules/preferences.js +26 -0
  238. package/dist/examples/src/mediaQueries/modules/resolution.js +31 -0
  239. package/dist/examples/src/mediaQueries/types.js +2 -0
  240. package/dist/examples/src/mediaQueries/validation.js +128 -0
  241. package/dist/examples/src/ratio.js +141 -0
  242. package/dist/examples/src/types.js +2 -0
  243. package/dist/examples/src/unitDefinitions.js +67 -0
  244. package/dist/examples/src/units/absolute.js +11 -0
  245. package/dist/examples/src/units/angle.js +8 -0
  246. package/dist/examples/src/units/container.js +10 -0
  247. package/dist/examples/src/units/font-relative.js +16 -0
  248. package/dist/examples/src/units/frequency.js +6 -0
  249. package/dist/examples/src/units/grid.js +5 -0
  250. package/dist/examples/src/units/percent.js +7 -0
  251. package/dist/examples/src/units/resolution.js +7 -0
  252. package/dist/examples/src/units/time.js +6 -0
  253. package/dist/examples/src/units/viewport-dynamic.js +10 -0
  254. package/dist/examples/src/units/viewport-large.js +10 -0
  255. package/dist/examples/src/units/viewport-small.js +10 -0
  256. package/dist/examples/src/units/viewport.js +10 -0
  257. package/dist/examples/src/validation.js +20 -0
  258. package/dist/examples/validation-and-runtime-checks.example.js +85 -0
  259. package/dist/examples/validation-unit-tests.example.js +35 -0
  260. package/package.json +17 -6
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ /**
3
+ * Example-only file.
4
+ *
5
+ * Not part of the public API surface or published bundle. This sketch shows
6
+ * how css-calipers can participate in dev-only validation around design
7
+ * tokens or configuration values inside style helpers or components. The
8
+ * helpers here are framework-agnostic; imagine them being called from React,
9
+ * a template system, or a Node script.
10
+ *
11
+ * The same `bodyLineHeight` token is used in two different places:
12
+ * - an icon + label row that returns a small HTML snippet and enforces
13
+ * "icon must not exceed line-height"
14
+ * - a table-of-contents heading row that returns a style object and enforces
15
+ * row height and body line-height invariants for readability
16
+ *
17
+ * See the sibling unit test example for how to assert related invariants in a unit test.
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.buildTocHeadingStyles = exports.renderIconWithLabelHtml = void 0;
22
+ const css_calipers_1 = require("css-calipers");
23
+ // Pretend these tokens come from a design token file or configuration layer.
24
+ // Two different components will enforce different invariants against the same
25
+ // underlying line-height measurement.
26
+ const bodyLineHeight = (0, css_calipers_1.m)(1.4, "rem");
27
+ const iconTokenSize = (0, css_calipers_1.m)(1.2, "rem");
28
+ const tocHeadingRowHeightToken = (0, css_calipers_1.m)(2, "rem");
29
+ // An icon+label row where you don't want the icon to visually dominate the
30
+ // text. In development, assert that the icon's size does not exceed the
31
+ // line-height it sits next to. Here we return a small HTML snippet to
32
+ // illustrate string-based consumers.
33
+ const renderIconWithLabelHtml = (labelText) => {
34
+ const iconSize = iconTokenSize;
35
+ if (process.env.NODE_ENV !== "production") {
36
+ // Make sure both measurements use the same unit family before comparing.
37
+ (0, css_calipers_1.assertMatchingUnits)(iconSize, bodyLineHeight, "iconWithLabel: icon and line-height units must match");
38
+ if (iconSize.getValue() > bodyLineHeight.getValue()) {
39
+ throw new Error(`iconWithLabel: icon must not exceed line-height; ` +
40
+ `iconSize=${iconSize.css()}, bodyLineHeight=${bodyLineHeight.css()}`);
41
+ }
42
+ }
43
+ const iconStyle = `width:${iconSize.css()};height:${iconSize.css()};`;
44
+ const labelStyle = `line-height:${bodyLineHeight.css()};`;
45
+ return `
46
+ <span class="row">
47
+ <span class="icon" style="${iconStyle}"/>
48
+ <span class="label" style="${labelStyle}">${labelText}</span>
49
+ </span>`;
50
+ };
51
+ exports.renderIconWithLabelHtml = renderIconWithLabelHtml;
52
+ // A table-of-contents row where H2 entries should remain readable and aligned
53
+ // with the typography system. In development, enforce a minimum line-height
54
+ // and require that the H2 row height is at least the underlying line-height.
55
+ const buildTocHeadingStyles = () => {
56
+ const tocHeadingRowHeight = tocHeadingRowHeightToken;
57
+ if (process.env.NODE_ENV !== "production") {
58
+ // Require body line-height to stay within a reasonable range for body
59
+ // text, using the same measurement token.
60
+ const minBodyLineHeight = (0, css_calipers_1.m)(1.2, "rem");
61
+ const maxBodyLineHeight = (0, css_calipers_1.m)(1.8, "rem");
62
+ const bodyValue = bodyLineHeight.getValue();
63
+ if (!(bodyValue >= minBodyLineHeight.getValue() &&
64
+ bodyValue <= maxBodyLineHeight.getValue())) {
65
+ throw new Error(`tocHeading: body line-height out of range; ` +
66
+ `${bodyLineHeight.css()} (expected between ` +
67
+ `${minBodyLineHeight.css()} and ${maxBodyLineHeight.css()})`);
68
+ }
69
+ // Row height should not be smaller than the line-height it uses.
70
+ (0, css_calipers_1.assertMatchingUnits)(tocHeadingRowHeight, bodyLineHeight, "tocHeading: row height and line-height units must match");
71
+ if (tocHeadingRowHeight.getValue() < bodyLineHeight.getValue()) {
72
+ throw new Error(`tocHeading: row height must be >= line-height; ` +
73
+ `row=${tocHeadingRowHeight.css()}, bodyLineHeight=${bodyLineHeight.css()}`);
74
+ }
75
+ }
76
+ // In real code these would be component or style objects. Here we just show
77
+ // that measurement values flow through `.css()` into plain style shapes.
78
+ return {
79
+ row: {
80
+ minHeight: tocHeadingRowHeight.css(),
81
+ lineHeight: bodyLineHeight.css(),
82
+ },
83
+ };
84
+ };
85
+ exports.buildTocHeadingStyles = buildTocHeadingStyles;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /**
3
+ * Example-only file.
4
+ *
5
+ * Not part of the public API surface or published bundle. This sketch shows
6
+ * how to exercise a simple design-token invariant in unit tests using Vitest,
7
+ * which this repo already uses for its own test suite. The pattern is test-
8
+ * runner agnostic; you can adapt it to Jest, Mocha, or any other framework.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ const vitest_1 = require("vitest");
12
+ const css_calipers_1 = require("css-calipers");
13
+ // Pretend these spacing tokens come from a design token file or configuration
14
+ // layer. The intent is a simple invariant: small <= large and both share units.
15
+ const spacingTokens = {
16
+ spaceSm: (0, css_calipers_1.m)(4), // defaults to "px" if no unit is given
17
+ spaceLg: (0, css_calipers_1.m)(12),
18
+ };
19
+ (0, vitest_1.describe)("spacing tokens (example unit test)", () => {
20
+ (0, vitest_1.it)("use the same unit for related tokens", () => {
21
+ const { spaceSm, spaceLg } = spacingTokens;
22
+ // Unit consistency between related tokens.
23
+ (0, css_calipers_1.assertMatchingUnits)(spaceSm, spaceLg, "spacing tokens: spaceSm and spaceLg must share units");
24
+ });
25
+ (0, vitest_1.it)("keep small <= large", () => {
26
+ const { spaceSm, spaceLg } = spacingTokens;
27
+ // Ordering invariant: small should never exceed large.
28
+ const smValue = spaceSm.getValue();
29
+ const lgValue = spaceLg.getValue();
30
+ if (!(smValue <= lgValue)) {
31
+ throw new Error(`spacing tokens out of order: ` +
32
+ `spaceSm=${spaceSm.css()}, spaceLg=${spaceLg.css()}`);
33
+ }
34
+ });
35
+ });
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.m = exports.mVw = exports.mEm = exports.makeMediaQueryStyle = exports.buildMediaQueryString = exports.units = exports.mediaQueries = exports.assertCondition = exports.assertMatchingUnits = exports.mPercent = exports.mPx = void 0;
4
+ const factory_1 = require("css-calipers/factory");
5
+ /**
6
+ * Example wrapper module.
7
+ * Use the factory once, then re-export from here across your app.
8
+ * This keeps a single import path and makes refactors cheaper.
9
+ */
10
+ const calipers = (0, factory_1.createCalipers)({
11
+ errorConfig: { stackHints: 'on' },
12
+ });
13
+ exports.mPx = calipers.mPx, exports.mPercent = calipers.mPercent, exports.assertMatchingUnits = calipers.assertMatchingUnits, exports.assertCondition = calipers.assertCondition, exports.mediaQueries = calipers.mediaQueries, exports.units = calipers.units;
14
+ exports.buildMediaQueryString = exports.mediaQueries.buildMediaQueryString, exports.makeMediaQueryStyle = exports.mediaQueries.makeMediaQueryStyle;
15
+ exports.mEm = exports.units.mEm, exports.mVw = exports.units.mVw;
16
+ /**
17
+ * Benefit: you can make custom changes in one place without touching call sites.
18
+ * Example wrapper below is intentionally demonstrative, not a recommended m change.
19
+ */
20
+ const m = (value, unitOrOptions, context) => {
21
+ var _a;
22
+ if (!unitOrOptions) {
23
+ return calipers.m(value, '%', context);
24
+ }
25
+ if (typeof unitOrOptions === 'object') {
26
+ return calipers.m(value, {
27
+ ...unitOrOptions,
28
+ unit: (_a = unitOrOptions.unit) !== null && _a !== void 0 ? _a : '%',
29
+ });
30
+ }
31
+ return calipers.m(value, unitOrOptions, context);
32
+ };
33
+ exports.m = m;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * Example-only file.
4
+ *
5
+ * This is not part of the public API surface and is not published in the
6
+ * package. It exists to demonstrate one way to normalize mixed line-height
7
+ * inputs into a single value with a `.css()` method. See the README for a
8
+ * deeper discussion of this pattern and its trade-offs.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.normalizeLineHeight = void 0;
12
+ const css_calipers_1 = require("css-calipers");
13
+ const parseNumericWithUnit = (raw) => {
14
+ const value = raw.trim();
15
+ const match = value.match(/^(-?\d*\.?\d+)\s*(px|rem|em|%)$/i);
16
+ if (!match)
17
+ return null;
18
+ const [, numeric, unit] = match;
19
+ return {
20
+ value: Number(numeric),
21
+ unit: unit.toLowerCase(),
22
+ };
23
+ };
24
+ const normalizeLineHeight = (value) => {
25
+ // Case 1: bare number (unitless line-height)
26
+ if (typeof value === 'number') {
27
+ return {
28
+ css: () => value,
29
+ };
30
+ }
31
+ const trimmed = value.trim();
32
+ // Case 2: numeric value + unit string (for example, "1.5rem", "20px")
33
+ const numericWithUnit = parseNumericWithUnit(trimmed);
34
+ if (numericWithUnit) {
35
+ const measurement = (0, css_calipers_1.m)(numericWithUnit.value, numericWithUnit.unit);
36
+ return measurement;
37
+ }
38
+ // Case 3: unitless numeric string (for example, "1.5")
39
+ const numericValue = Number(trimmed);
40
+ if (!Number.isNaN(numericValue)) {
41
+ return {
42
+ css: () => numericValue,
43
+ };
44
+ }
45
+ // Case 4: keywords ("normal") or CSS variables ("var(--body-line-height)")
46
+ // remain opaque CSS strings and resolve at runtime.
47
+ return {
48
+ css: () => trimmed,
49
+ };
50
+ };
51
+ exports.normalizeLineHeight = normalizeLineHeight;
52
+ // Example usages (not executed here; for illustration only):
53
+ const lineHeightFromNumber = (0, exports.normalizeLineHeight)(1.5);
54
+ const lineHeightFromUnitString = (0, exports.normalizeLineHeight)('1.5rem');
55
+ const lineHeightFromNumericString = (0, exports.normalizeLineHeight)('1.5');
56
+ const lineHeightFromKeyword = (0, exports.normalizeLineHeight)('normal');
57
+ const lineHeightFromVar = (0, exports.normalizeLineHeight)('var(--body-line-height)');
58
+ // All normalized values expose a `.css()` method:
59
+ const lineHeightStyles = {
60
+ number: lineHeightFromNumber.css(),
61
+ unitString: lineHeightFromUnitString.css(),
62
+ numericString: lineHeightFromNumericString.css(),
63
+ keyword: lineHeightFromKeyword.css(),
64
+ cssVariable: lineHeightFromVar.css(),
65
+ };
66
+ // Advanced example: if the normalized value happens to be a CSS-Calipers
67
+ // measurement, you can safely do math on it before emitting CSS.
68
+ const baseLineHeight = (0, exports.normalizeLineHeight)('1.4rem');
69
+ const minLineHeight = (0, css_calipers_1.m)(1.2, 'rem');
70
+ const maxLineHeight = (0, css_calipers_1.m)(1.8, 'rem');
71
+ let clampedLineHeight;
72
+ if ((0, css_calipers_1.isMeasurement)(baseLineHeight)) {
73
+ // Here TypeScript knows `baseLineHeight` is an IMeasurement, so you can use
74
+ // unit-aware helpers before emitting.
75
+ const clamped = baseLineHeight.clamp(minLineHeight, maxLineHeight);
76
+ clampedLineHeight = clamped.css();
77
+ }
78
+ else {
79
+ // Keywords or CSS variables bypass CSS-Calipers and stay as-is.
80
+ clampedLineHeight = baseLineHeight.css();
81
+ }
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ /**
3
+ * Example-only file.
4
+ *
5
+ * This is not part of the public API surface and is not published in the
6
+ * package. It shows how a page layout and a grid component can use different
7
+ * media query configs (and different breakpoints) in the same codebase.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const css_calipers_1 = require("css-calipers");
11
+ const mediaQueries_1 = require("css-calipers/mediaQueries");
12
+ // Simple helper: grid component uses its own breakpoints and column labels.
13
+ // This helper uses the default builder, which includes all modules.
14
+ const gridBreakpoints = {
15
+ columns_four: { maxWidth: (0, css_calipers_1.m)(1200) },
16
+ columns_three: { maxWidth: (0, css_calipers_1.m)(1024) },
17
+ columns_two: { maxWidth: (0, css_calipers_1.m)(768) },
18
+ columns_one: { maxWidth: (0, css_calipers_1.m)(520) },
19
+ };
20
+ const gridMediaSimple = (0, mediaQueries_1.makeMediaQueryStyle)(gridBreakpoints);
21
+ const gridStylesSimple = {
22
+ display: "grid",
23
+ gap: "16px",
24
+ gridTemplateColumns: "repeat(4, 1fr)",
25
+ ...gridMediaSimple({
26
+ columns_four: { gridTemplateColumns: "repeat(4, 1fr)" },
27
+ columns_three: { gridTemplateColumns: "repeat(3, 1fr)" },
28
+ columns_two: { gridTemplateColumns: "repeat(2, 1fr)" },
29
+ columns_one: { gridTemplateColumns: "1fr" },
30
+ }),
31
+ };
32
+ // Multiple instances: page layout and grid component use different configs.
33
+ // Layout uses the standard mobile/tablet/desktop breakpoints and defaults.
34
+ // The default keeps all modules enabled, if you want to limit modules, you
35
+ // can specify what moduels to load explicitely
36
+ const layoutMedia = (0, mediaQueries_1.mediaQueryFactory)({
37
+ queries: {
38
+ mobile: { maxWidth: (0, css_calipers_1.m)(639) },
39
+ tablet: { minWidth: (0, css_calipers_1.m)(640), maxWidth: (0, css_calipers_1.m)(1023) },
40
+ desktop: { minWidth: (0, css_calipers_1.m)(1024) },
41
+ },
42
+ config: { label: "layout" },
43
+ });
44
+ // Grid uses a custom breakpoint map and custom error handling for iteration.
45
+ // Note "core" is explicit here and no other modules will be loaded.
46
+ const gridMedia = (0, mediaQueries_1.mediaQueryFactory)({
47
+ queries: gridBreakpoints,
48
+ config: {
49
+ label: "product-grid",
50
+ modules: ["core"],
51
+ errorHandling: {
52
+ invalidValueMode: "log",
53
+ lintingMode: "log",
54
+ },
55
+ },
56
+ });
57
+ const pageStyles = {
58
+ display: "grid",
59
+ gridTemplateColumns: "repeat(4, 1fr)",
60
+ ...layoutMedia({
61
+ mobile: { gridTemplateColumns: "1fr" },
62
+ tablet: { gridTemplateColumns: "repeat(2, 1fr)" },
63
+ desktop: { gridTemplateColumns: "repeat(4, 1fr)" },
64
+ }),
65
+ };
66
+ const gridStyles = {
67
+ display: "grid",
68
+ gap: "16px",
69
+ gridTemplateColumns: "repeat(4, 1fr)",
70
+ ...gridMedia({
71
+ columns_four: { gridTemplateColumns: "repeat(4, 1fr)" },
72
+ columns_three: { gridTemplateColumns: "repeat(3, 1fr)" },
73
+ columns_two: { gridTemplateColumns: "repeat(2, 1fr)" },
74
+ columns_one: { gridTemplateColumns: "1fr" },
75
+ }),
76
+ };
77
+ // Advanced example: any-hover with custom validation + linting.
78
+ // Note
79
+ const interactionMedia = (0, mediaQueries_1.mediaQueryFactory)({
80
+ queries: {
81
+ hoverReady: {
82
+ anyHover: "hover",
83
+ anyPointer: "fine",
84
+ reducedMotion: "no-preference",
85
+ },
86
+ hoverDisabled: {
87
+ anyHover: "none",
88
+ anyPointer: "coarse",
89
+ reducedMotion: "reduce",
90
+ },
91
+ },
92
+ config: {
93
+ label: "interaction",
94
+ modules: ["interaction", "preferences"],
95
+ errorHandling: {
96
+ invalidValueMode: "throw",
97
+ lintingMode: "log",
98
+ },
99
+ output: (media) => ({
100
+ label: "interaction",
101
+ media,
102
+ note: "Custom output for advanced example",
103
+ }),
104
+ custom: {
105
+ key: "any-hover-guard",
106
+ validator: (props) => {
107
+ if (props.anyHover && !props.anyPointer) {
108
+ return "anyHover should be paired with anyPointer for clarity";
109
+ }
110
+ return true;
111
+ },
112
+ linter: (props) => {
113
+ if (props.anyHover === "none" && props.anyPointer === "fine") {
114
+ return "anyHover none rarely pairs with anyPointer fine";
115
+ }
116
+ return true;
117
+ },
118
+ },
119
+ },
120
+ });
121
+ const interactionResult = interactionMedia({
122
+ hoverReady: { cursor: "pointer", transitionDuration: "160ms" },
123
+ hoverDisabled: { cursor: "default", transitionDuration: "0ms" },
124
+ });
125
+ const interactionStyles = {
126
+ ...interactionResult.media,
127
+ };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ /**
3
+ * Example-only file.
4
+ *
5
+ * This is not part of the public API surface and is not published in the
6
+ * package. It shows how to nest media + container query outputs, including
7
+ * optional vanilla-extract helpers.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const css_calipers_1 = require("css-calipers");
11
+ const mediaQueries_1 = require("css-calipers/mediaQueries");
12
+ const containerQueries_1 = require("css-calipers/containerQueries");
13
+ const comparisons_1 = require("../src/comparisons");
14
+ const media = (0, mediaQueries_1.makeMediaQueryStyle)({
15
+ desktop: {
16
+ minWidth: (0, css_calipers_1.m)(1024),
17
+ aspectRatio: (0, css_calipers_1.r)(16, 9),
18
+ },
19
+ });
20
+ const media2 = (0, mediaQueries_1.makeMediaQueryStyle)({
21
+ queryA: {
22
+ minWidth: (0, css_calipers_1.m)(1024),
23
+ maxWidth: (0, css_calipers_1.m)(2024),
24
+ and: {
25
+ minResolution: (0, css_calipers_1.m)(2, "dppx"),
26
+ not: {
27
+ aspectRatio: (0, css_calipers_1.r)(16, 9),
28
+ },
29
+ },
30
+ },
31
+ });
32
+ const container = (0, containerQueries_1.makeContainerQueryStyle)({
33
+ wideCard: {
34
+ inlineSize: comparisons_1.compare.gte((0, css_calipers_1.m)(28, "rem")),
35
+ and: {
36
+ aspectRatio: (0, css_calipers_1.r)(4, 3),
37
+ },
38
+ },
39
+ });
40
+ const nestedStyles = media({
41
+ desktop: container({
42
+ wideCard: {
43
+ gridTemplateColumns: "1fr 2fr",
44
+ gridTemplateRows: "none",
45
+ alignItems: "stretch",
46
+ },
47
+ }),
48
+ });
49
+ // const vanillaExtractStyles = mediaQueryOutputVanillaExtract(
50
+ // media({
51
+ // desktop: containerQueryOutputVanillaExtract(
52
+ // container({
53
+ // wideCard: {
54
+ // gridTemplateColumns: "1fr 2fr",
55
+ // gridTemplateRows: "none",
56
+ // },
57
+ // }),
58
+ // ),
59
+ // }),
60
+ // );
@@ -0,0 +1,25 @@
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
+ };
@@ -0,0 +1,96 @@
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 { runContainerQueryValidation, validateMinMaxWidth, validateWidthValuesPositive, validateMinMaxHeight, validateHeightValuesPositive, } = validation;
11
+ if (!runContainerQueryValidation(props, helpers, validateMinMaxWidth, "core", "minWidth must be less than or equal to maxWidth")) {
12
+ return;
13
+ }
14
+ if (!runContainerQueryValidation(props, helpers, validateMinMaxHeight, "core", "minHeight must be less than or equal to maxHeight")) {
15
+ return;
16
+ }
17
+ if (!runContainerQueryValidation(props, helpers, validateWidthValuesPositive, "core", "width values must be greater than 0")) {
18
+ return;
19
+ }
20
+ if (!runContainerQueryValidation(props, helpers, validateHeightValuesPositive, "core", "height values must be greater than 0")) {
21
+ return;
22
+ }
23
+ if (!(0, linting_1.runContainerQueryLint)(props, helpers, core_1.lintWidthExactRedundancy, "minWidth should not be combined with maxWidth when both are equal")) {
24
+ return;
25
+ }
26
+ if (!(0, linting_1.runContainerQueryLint)(props, helpers, core_1.lintHeightExactRedundancy, "minHeight should not be combined with maxHeight when both are equal")) {
27
+ return;
28
+ }
29
+ const { addFeature } = helpers;
30
+ if (props.minWidth) {
31
+ addFeature("min-width", props.minWidth);
32
+ }
33
+ if (props.maxWidth) {
34
+ addFeature("max-width", props.maxWidth);
35
+ }
36
+ if (props.minHeight) {
37
+ addFeature("min-height", props.minHeight);
38
+ }
39
+ if (props.maxHeight) {
40
+ addFeature("max-height", props.maxHeight);
41
+ }
42
+ };
43
+ exports.createEmitCoreFeatures = createEmitCoreFeatures;
44
+ exports.emitCoreFeatures = (0, exports.createEmitCoreFeatures)(validation_1.defaultContainerQueryValidation);
45
+ const emitBaseFeatures = (props, helpers) => {
46
+ (0, exports.emitCoreFeatures)(props, helpers);
47
+ (0, modules_1.emitAspectRatioFeatures)(props, helpers);
48
+ (0, modules_1.emitInlineSizeFeatures)(props, helpers);
49
+ (0, modules_1.emitBlockSizeFeatures)(props, helpers);
50
+ (0, modules_1.emitStyleFeatures)(props, helpers);
51
+ (0, modules_1.emitCustomFeatures)(props, helpers);
52
+ };
53
+ exports.buildContainerQueryString = (0, helpers_1.createContainerQueryBuilder)({
54
+ emitBase: emitBaseFeatures,
55
+ });
56
+ const wrapContainerCondition = (value) => {
57
+ const trimmed = value.trim();
58
+ if (trimmed.includes(" and ") ||
59
+ trimmed.includes(" or ") ||
60
+ trimmed.startsWith("not ")) {
61
+ return `(${trimmed})`;
62
+ }
63
+ return trimmed;
64
+ };
65
+ const buildContainerConditionString = (condition) => {
66
+ if ("and" in condition) {
67
+ return condition.and
68
+ .map((entry) => wrapContainerCondition((0, exports.buildContainerConditionString)(entry)))
69
+ .join(" and ");
70
+ }
71
+ if ("or" in condition) {
72
+ return condition.or
73
+ .map((entry) => wrapContainerCondition((0, exports.buildContainerConditionString)(entry)))
74
+ .join(" or ");
75
+ }
76
+ if ("not" in condition) {
77
+ return `not ${wrapContainerCondition((0, exports.buildContainerConditionString)(condition.not))}`;
78
+ }
79
+ return (0, exports.buildContainerQueryString)(condition);
80
+ };
81
+ exports.buildContainerConditionString = buildContainerConditionString;
82
+ const makeContainerQueryStyle = (queries) => (stylesByQuery) => {
83
+ const result = {};
84
+ Object.keys(stylesByQuery).forEach((key) => {
85
+ const styles = stylesByQuery[key];
86
+ const props = queries[key];
87
+ if (!styles || !props)
88
+ return;
89
+ result[(0, exports.buildContainerQueryString)(props)] = styles;
90
+ });
91
+ const containerQuery = {
92
+ "@container": result,
93
+ };
94
+ return containerQuery;
95
+ };
96
+ exports.makeContainerQueryStyle = makeContainerQueryStyle;
@@ -0,0 +1,123 @@
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)();