css-calipers 0.14.0 → 1.0.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.
Files changed (291) hide show
  1. package/README.md +15 -29
  2. package/dist/cjs/factory.js +0 -3
  3. package/dist/esm/factory.d.ts +0 -2
  4. package/dist/esm/factory.d.ts.map +1 -1
  5. package/dist/esm/factory.js +0 -3
  6. package/package.json +4 -17
  7. package/RELEASING.md +0 -62
  8. package/dist/cjs/comparisons/index.js +0 -25
  9. package/dist/cjs/containerQueries/containerQueries.js +0 -115
  10. package/dist/cjs/containerQueries/factory.js +0 -123
  11. package/dist/cjs/containerQueries/helpers.js +0 -95
  12. package/dist/cjs/containerQueries/index.js +0 -16
  13. package/dist/cjs/containerQueries/linting/aspectRatio.js +0 -24
  14. package/dist/cjs/containerQueries/linting/block.js +0 -23
  15. package/dist/cjs/containerQueries/linting/core.js +0 -25
  16. package/dist/cjs/containerQueries/linting/custom.js +0 -11
  17. package/dist/cjs/containerQueries/linting/inline.js +0 -23
  18. package/dist/cjs/containerQueries/linting/resolution.js +0 -12
  19. package/dist/cjs/containerQueries/linting/style.js +0 -28
  20. package/dist/cjs/containerQueries/linting.js +0 -24
  21. package/dist/cjs/containerQueries/moduleRegistry.js +0 -5
  22. package/dist/cjs/containerQueries/modules/aspectRatio.js +0 -51
  23. package/dist/cjs/containerQueries/modules/block.js +0 -53
  24. package/dist/cjs/containerQueries/modules/custom.js +0 -43
  25. package/dist/cjs/containerQueries/modules/index.js +0 -21
  26. package/dist/cjs/containerQueries/modules/inline.js +0 -53
  27. package/dist/cjs/containerQueries/modules/size.js +0 -2
  28. package/dist/cjs/containerQueries/modules/style.js +0 -36
  29. package/dist/cjs/containerQueries/types.js +0 -2
  30. package/dist/cjs/containerQueries/validation.js +0 -191
  31. package/dist/cjs/fraction.js +0 -139
  32. package/dist/cjs/internal/createComponentQueriesApi.js +0 -56
  33. package/dist/cjs/internal/createMediaQueriesApi.js +0 -73
  34. package/dist/cjs/internal/normalizeToArray.js +0 -9
  35. package/dist/cjs/libraryHelpers/vanilla-extract.js +0 -11
  36. package/dist/cjs/logicalOperators/index.js +0 -18
  37. package/dist/cjs/mediaQueries/factory.js +0 -187
  38. package/dist/cjs/mediaQueries/helpers.js +0 -97
  39. package/dist/cjs/mediaQueries/index.js +0 -23
  40. package/dist/cjs/mediaQueries/libraryHelpers/vanilla-extract.js +0 -77
  41. package/dist/cjs/mediaQueries/linting/core.js +0 -19
  42. package/dist/cjs/mediaQueries/linting/resolution.js +0 -11
  43. package/dist/cjs/mediaQueries/linting.js +0 -24
  44. package/dist/cjs/mediaQueries/mediaQueries.js +0 -53
  45. package/dist/cjs/mediaQueries/mediaQueryFactory.js +0 -120
  46. package/dist/cjs/mediaQueries/moduleRegistry.js +0 -5
  47. package/dist/cjs/mediaQueries/modules/custom.js +0 -26
  48. package/dist/cjs/mediaQueries/modules/dimensions.js +0 -61
  49. package/dist/cjs/mediaQueries/modules/display.js +0 -20
  50. package/dist/cjs/mediaQueries/modules/environment.js +0 -20
  51. package/dist/cjs/mediaQueries/modules/index.js +0 -23
  52. package/dist/cjs/mediaQueries/modules/interaction.js +0 -26
  53. package/dist/cjs/mediaQueries/modules/preferences.js +0 -26
  54. package/dist/cjs/mediaQueries/modules/resolution.js +0 -31
  55. package/dist/cjs/mediaQueries/types.js +0 -2
  56. package/dist/cjs/mediaQueries/validation.js +0 -134
  57. package/dist/cjs/sciNotation.js +0 -74
  58. package/dist/cjs/types.js +0 -2
  59. package/dist/cjs/validation.js +0 -20
  60. package/dist/esm/comparisons/index.d.ts +0 -23
  61. package/dist/esm/comparisons/index.d.ts.map +0 -1
  62. package/dist/esm/comparisons/index.js +0 -22
  63. package/dist/esm/containerQueries/containerQueries.d.ts +0 -36
  64. package/dist/esm/containerQueries/containerQueries.d.ts.map +0 -1
  65. package/dist/esm/containerQueries/containerQueries.js +0 -109
  66. package/dist/esm/containerQueries/factory.d.ts +0 -20
  67. package/dist/esm/containerQueries/factory.d.ts.map +0 -1
  68. package/dist/esm/containerQueries/factory.js +0 -119
  69. package/dist/esm/containerQueries/helpers.d.ts +0 -53
  70. package/dist/esm/containerQueries/helpers.d.ts.map +0 -1
  71. package/dist/esm/containerQueries/helpers.js +0 -82
  72. package/dist/esm/containerQueries/index.d.ts +0 -10
  73. package/dist/esm/containerQueries/index.d.ts.map +0 -1
  74. package/dist/esm/containerQueries/index.js +0 -4
  75. package/dist/esm/containerQueries/linting/aspectRatio.d.ts +0 -4
  76. package/dist/esm/containerQueries/linting/aspectRatio.d.ts.map +0 -1
  77. package/dist/esm/containerQueries/linting/aspectRatio.js +0 -19
  78. package/dist/esm/containerQueries/linting/block.d.ts +0 -4
  79. package/dist/esm/containerQueries/linting/block.d.ts.map +0 -1
  80. package/dist/esm/containerQueries/linting/block.js +0 -18
  81. package/dist/esm/containerQueries/linting/core.d.ts +0 -4
  82. package/dist/esm/containerQueries/linting/core.d.ts.map +0 -1
  83. package/dist/esm/containerQueries/linting/core.js +0 -20
  84. package/dist/esm/containerQueries/linting/custom.d.ts +0 -3
  85. package/dist/esm/containerQueries/linting/custom.d.ts.map +0 -1
  86. package/dist/esm/containerQueries/linting/custom.js +0 -7
  87. package/dist/esm/containerQueries/linting/inline.d.ts +0 -4
  88. package/dist/esm/containerQueries/linting/inline.d.ts.map +0 -1
  89. package/dist/esm/containerQueries/linting/inline.js +0 -18
  90. package/dist/esm/containerQueries/linting/resolution.d.ts +0 -1
  91. package/dist/esm/containerQueries/linting/resolution.d.ts.map +0 -1
  92. package/dist/esm/containerQueries/linting/resolution.js +0 -12
  93. package/dist/esm/containerQueries/linting/style.d.ts +0 -3
  94. package/dist/esm/containerQueries/linting/style.d.ts.map +0 -1
  95. package/dist/esm/containerQueries/linting/style.js +0 -24
  96. package/dist/esm/containerQueries/linting.d.ts +0 -4
  97. package/dist/esm/containerQueries/linting.d.ts.map +0 -1
  98. package/dist/esm/containerQueries/linting.js +0 -20
  99. package/dist/esm/containerQueries/moduleRegistry.d.ts +0 -25
  100. package/dist/esm/containerQueries/moduleRegistry.d.ts.map +0 -1
  101. package/dist/esm/containerQueries/moduleRegistry.js +0 -1
  102. package/dist/esm/containerQueries/modules/aspectRatio.d.ts +0 -17
  103. package/dist/esm/containerQueries/modules/aspectRatio.d.ts.map +0 -1
  104. package/dist/esm/containerQueries/modules/aspectRatio.js +0 -47
  105. package/dist/esm/containerQueries/modules/block.d.ts +0 -20
  106. package/dist/esm/containerQueries/modules/block.d.ts.map +0 -1
  107. package/dist/esm/containerQueries/modules/block.js +0 -49
  108. package/dist/esm/containerQueries/modules/custom.d.ts +0 -13
  109. package/dist/esm/containerQueries/modules/custom.d.ts.map +0 -1
  110. package/dist/esm/containerQueries/modules/custom.js +0 -39
  111. package/dist/esm/containerQueries/modules/index.d.ts +0 -6
  112. package/dist/esm/containerQueries/modules/index.d.ts.map +0 -1
  113. package/dist/esm/containerQueries/modules/index.js +0 -5
  114. package/dist/esm/containerQueries/modules/inline.d.ts +0 -20
  115. package/dist/esm/containerQueries/modules/inline.d.ts.map +0 -1
  116. package/dist/esm/containerQueries/modules/inline.js +0 -49
  117. package/dist/esm/containerQueries/modules/size.d.ts +0 -41
  118. package/dist/esm/containerQueries/modules/size.d.ts.map +0 -1
  119. package/dist/esm/containerQueries/modules/size.js +0 -1
  120. package/dist/esm/containerQueries/modules/style.d.ts +0 -11
  121. package/dist/esm/containerQueries/modules/style.d.ts.map +0 -1
  122. package/dist/esm/containerQueries/modules/style.js +0 -32
  123. package/dist/esm/containerQueries/types.d.ts +0 -81
  124. package/dist/esm/containerQueries/types.d.ts.map +0 -1
  125. package/dist/esm/containerQueries/types.js +0 -1
  126. package/dist/esm/containerQueries/validation.d.ts +0 -41
  127. package/dist/esm/containerQueries/validation.d.ts.map +0 -1
  128. package/dist/esm/containerQueries/validation.js +0 -187
  129. package/dist/esm/fraction.d.ts +0 -23
  130. package/dist/esm/fraction.d.ts.map +0 -1
  131. package/dist/esm/fraction.js +0 -129
  132. package/dist/esm/internal/createComponentQueriesApi.d.ts +0 -34
  133. package/dist/esm/internal/createComponentQueriesApi.d.ts.map +0 -1
  134. package/dist/esm/internal/createComponentQueriesApi.js +0 -52
  135. package/dist/esm/internal/createMediaQueriesApi.d.ts +0 -35
  136. package/dist/esm/internal/createMediaQueriesApi.d.ts.map +0 -1
  137. package/dist/esm/internal/createMediaQueriesApi.js +0 -69
  138. package/dist/esm/internal/normalizeToArray.d.ts +0 -2
  139. package/dist/esm/internal/normalizeToArray.d.ts.map +0 -1
  140. package/dist/esm/internal/normalizeToArray.js +0 -5
  141. package/dist/esm/libraryHelpers/vanilla-extract.d.ts +0 -4
  142. package/dist/esm/libraryHelpers/vanilla-extract.d.ts.map +0 -1
  143. package/dist/esm/libraryHelpers/vanilla-extract.js +0 -6
  144. package/dist/esm/logicalOperators/index.d.ts +0 -2
  145. package/dist/esm/logicalOperators/index.d.ts.map +0 -1
  146. package/dist/esm/logicalOperators/index.js +0 -17
  147. package/dist/esm/mediaQueries/factory.d.ts +0 -45
  148. package/dist/esm/mediaQueries/factory.d.ts.map +0 -1
  149. package/dist/esm/mediaQueries/factory.js +0 -183
  150. package/dist/esm/mediaQueries/helpers.d.ts +0 -40
  151. package/dist/esm/mediaQueries/helpers.d.ts.map +0 -1
  152. package/dist/esm/mediaQueries/helpers.js +0 -87
  153. package/dist/esm/mediaQueries/index.d.ts +0 -8
  154. package/dist/esm/mediaQueries/index.d.ts.map +0 -1
  155. package/dist/esm/mediaQueries/index.js +0 -7
  156. package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts +0 -5
  157. package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts.map +0 -1
  158. package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.js +0 -71
  159. package/dist/esm/mediaQueries/linting/core.d.ts +0 -5
  160. package/dist/esm/mediaQueries/linting/core.d.ts.map +0 -1
  161. package/dist/esm/mediaQueries/linting/core.js +0 -14
  162. package/dist/esm/mediaQueries/linting/resolution.d.ts +0 -3
  163. package/dist/esm/mediaQueries/linting/resolution.d.ts.map +0 -1
  164. package/dist/esm/mediaQueries/linting/resolution.js +0 -7
  165. package/dist/esm/mediaQueries/linting.d.ts +0 -4
  166. package/dist/esm/mediaQueries/linting.d.ts.map +0 -1
  167. package/dist/esm/mediaQueries/linting.js +0 -20
  168. package/dist/esm/mediaQueries/mediaQueries.d.ts +0 -23
  169. package/dist/esm/mediaQueries/mediaQueries.d.ts.map +0 -1
  170. package/dist/esm/mediaQueries/mediaQueries.js +0 -48
  171. package/dist/esm/mediaQueries/moduleRegistry.d.ts +0 -27
  172. package/dist/esm/mediaQueries/moduleRegistry.d.ts.map +0 -1
  173. package/dist/esm/mediaQueries/moduleRegistry.js +0 -1
  174. package/dist/esm/mediaQueries/modules/custom.d.ts +0 -10
  175. package/dist/esm/mediaQueries/modules/custom.d.ts.map +0 -1
  176. package/dist/esm/mediaQueries/modules/custom.js +0 -22
  177. package/dist/esm/mediaQueries/modules/dimensions.d.ts +0 -19
  178. package/dist/esm/mediaQueries/modules/dimensions.d.ts.map +0 -1
  179. package/dist/esm/mediaQueries/modules/dimensions.js +0 -57
  180. package/dist/esm/mediaQueries/modules/display.d.ts +0 -9
  181. package/dist/esm/mediaQueries/modules/display.d.ts.map +0 -1
  182. package/dist/esm/mediaQueries/modules/display.js +0 -16
  183. package/dist/esm/mediaQueries/modules/environment.d.ts +0 -9
  184. package/dist/esm/mediaQueries/modules/environment.d.ts.map +0 -1
  185. package/dist/esm/mediaQueries/modules/environment.js +0 -16
  186. package/dist/esm/mediaQueries/modules/index.d.ts +0 -8
  187. package/dist/esm/mediaQueries/modules/index.d.ts.map +0 -1
  188. package/dist/esm/mediaQueries/modules/index.js +0 -7
  189. package/dist/esm/mediaQueries/modules/interaction.d.ts +0 -11
  190. package/dist/esm/mediaQueries/modules/interaction.d.ts.map +0 -1
  191. package/dist/esm/mediaQueries/modules/interaction.js +0 -22
  192. package/dist/esm/mediaQueries/modules/preferences.d.ts +0 -11
  193. package/dist/esm/mediaQueries/modules/preferences.d.ts.map +0 -1
  194. package/dist/esm/mediaQueries/modules/preferences.js +0 -22
  195. package/dist/esm/mediaQueries/modules/resolution.d.ts +0 -12
  196. package/dist/esm/mediaQueries/modules/resolution.d.ts.map +0 -1
  197. package/dist/esm/mediaQueries/modules/resolution.js +0 -27
  198. package/dist/esm/mediaQueries/types.d.ts +0 -117
  199. package/dist/esm/mediaQueries/types.d.ts.map +0 -1
  200. package/dist/esm/mediaQueries/types.js +0 -1
  201. package/dist/esm/mediaQueries/validation.d.ts +0 -33
  202. package/dist/esm/mediaQueries/validation.d.ts.map +0 -1
  203. package/dist/esm/mediaQueries/validation.js +0 -130
  204. package/dist/esm/sciNotation.d.ts +0 -14
  205. package/dist/esm/sciNotation.d.ts.map +0 -1
  206. package/dist/esm/sciNotation.js +0 -69
  207. package/dist/esm/types.d.ts +0 -35
  208. package/dist/esm/types.d.ts.map +0 -1
  209. package/dist/esm/types.js +0 -1
  210. package/dist/esm/validation.d.ts +0 -10
  211. package/dist/esm/validation.d.ts.map +0 -1
  212. package/dist/esm/validation.js +0 -15
  213. package/dist/examples/containerQueries.example.js +0 -54
  214. package/dist/examples/examples/containerQueries.example.js +0 -54
  215. package/dist/examples/examples/factory-wrapper.example.js +0 -33
  216. package/dist/examples/examples/lineHeight-normalizer.example.js +0 -81
  217. package/dist/examples/examples/mediaQueries-multipleInstances.example.js +0 -127
  218. package/dist/examples/examples/mixedQueries.example.js +0 -55
  219. package/dist/examples/examples/validation-and-runtime-checks.example.js +0 -85
  220. package/dist/examples/examples/validation-unit-tests.example.js +0 -35
  221. package/dist/examples/factory-wrapper.example.js +0 -33
  222. package/dist/examples/lineHeight-normalizer.example.js +0 -81
  223. package/dist/examples/mediaQueries-multipleInstances.example.js +0 -127
  224. package/dist/examples/mixedQueries.example.js +0 -60
  225. package/dist/examples/src/comparisons/index.js +0 -25
  226. package/dist/examples/src/containerQueries/containerQueries.js +0 -96
  227. package/dist/examples/src/containerQueries/factory.js +0 -123
  228. package/dist/examples/src/containerQueries/helpers.js +0 -94
  229. package/dist/examples/src/containerQueries/index.js +0 -16
  230. package/dist/examples/src/containerQueries/linting/aspectRatio.js +0 -20
  231. package/dist/examples/src/containerQueries/linting/block.js +0 -20
  232. package/dist/examples/src/containerQueries/linting/core.js +0 -19
  233. package/dist/examples/src/containerQueries/linting/custom.js +0 -11
  234. package/dist/examples/src/containerQueries/linting/inline.js +0 -20
  235. package/dist/examples/src/containerQueries/linting/style.js +0 -28
  236. package/dist/examples/src/containerQueries/linting.js +0 -24
  237. package/dist/examples/src/containerQueries/moduleRegistry.js +0 -5
  238. package/dist/examples/src/containerQueries/modules/aspectRatio.js +0 -33
  239. package/dist/examples/src/containerQueries/modules/block.js +0 -44
  240. package/dist/examples/src/containerQueries/modules/custom.js +0 -31
  241. package/dist/examples/src/containerQueries/modules/index.js +0 -21
  242. package/dist/examples/src/containerQueries/modules/inline.js +0 -44
  243. package/dist/examples/src/containerQueries/modules/style.js +0 -36
  244. package/dist/examples/src/containerQueries/types.js +0 -2
  245. package/dist/examples/src/containerQueries/validation.js +0 -177
  246. package/dist/examples/src/core.js +0 -16
  247. package/dist/examples/src/factory.js +0 -21
  248. package/dist/examples/src/index.js +0 -30
  249. package/dist/examples/src/internal/buildMeasurementCreationError.js +0 -16
  250. package/dist/examples/src/internal/createCoreApi.js +0 -336
  251. package/dist/examples/src/internal/createMediaQueriesApi.js +0 -74
  252. package/dist/examples/src/internal/createUnitsApi.js +0 -18
  253. package/dist/examples/src/internal/errors.js +0 -130
  254. package/dist/examples/src/libraryHelpers/vanilla-extract.js +0 -11
  255. package/dist/examples/src/mediaQueries/factory.js +0 -163
  256. package/dist/examples/src/mediaQueries/helpers.js +0 -88
  257. package/dist/examples/src/mediaQueries/index.js +0 -23
  258. package/dist/examples/src/mediaQueries/linting/core.js +0 -19
  259. package/dist/examples/src/mediaQueries/linting/resolution.js +0 -11
  260. package/dist/examples/src/mediaQueries/linting.js +0 -24
  261. package/dist/examples/src/mediaQueries/mediaQueries.js +0 -53
  262. package/dist/examples/src/mediaQueries/moduleRegistry.js +0 -5
  263. package/dist/examples/src/mediaQueries/modules/custom.js +0 -26
  264. package/dist/examples/src/mediaQueries/modules/dimensions.js +0 -61
  265. package/dist/examples/src/mediaQueries/modules/display.js +0 -20
  266. package/dist/examples/src/mediaQueries/modules/environment.js +0 -20
  267. package/dist/examples/src/mediaQueries/modules/index.js +0 -23
  268. package/dist/examples/src/mediaQueries/modules/interaction.js +0 -26
  269. package/dist/examples/src/mediaQueries/modules/preferences.js +0 -26
  270. package/dist/examples/src/mediaQueries/modules/resolution.js +0 -31
  271. package/dist/examples/src/mediaQueries/types.js +0 -2
  272. package/dist/examples/src/mediaQueries/validation.js +0 -128
  273. package/dist/examples/src/ratio.js +0 -141
  274. package/dist/examples/src/types.js +0 -2
  275. package/dist/examples/src/unitDefinitions.js +0 -67
  276. package/dist/examples/src/units/absolute.js +0 -11
  277. package/dist/examples/src/units/angle.js +0 -8
  278. package/dist/examples/src/units/container.js +0 -10
  279. package/dist/examples/src/units/font-relative.js +0 -16
  280. package/dist/examples/src/units/frequency.js +0 -6
  281. package/dist/examples/src/units/grid.js +0 -5
  282. package/dist/examples/src/units/percent.js +0 -7
  283. package/dist/examples/src/units/resolution.js +0 -7
  284. package/dist/examples/src/units/time.js +0 -6
  285. package/dist/examples/src/units/viewport-dynamic.js +0 -10
  286. package/dist/examples/src/units/viewport-large.js +0 -10
  287. package/dist/examples/src/units/viewport-small.js +0 -10
  288. package/dist/examples/src/units/viewport.js +0 -10
  289. package/dist/examples/src/validation.js +0 -20
  290. package/dist/examples/validation-and-runtime-checks.example.js +0 -85
  291. package/dist/examples/validation-unit-tests.example.js +0 -35
@@ -1,134 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultMediaQueryValidation = exports.validateResolutionValues = exports.validateAspectRatioValuesPositive = exports.validateMinMaxAspectRatio = exports.validateHeightValuesPositive = exports.validateMinMaxHeight = exports.validateWidthValuesPositive = exports.validateMinMaxWidth = exports.runMediaQueryValidation = exports.createMediaQueryValidation = void 0;
4
- const helpers_1 = require("./helpers");
5
- const core_1 = require("../core");
6
- const toValidationResult = (error, fallback) => {
7
- if (error instanceof Error && error.message)
8
- return error.message;
9
- return fallback;
10
- };
11
- const createMediaQueryValidation = (core) => {
12
- const { assertCondition } = core;
13
- const runMediaQueryValidation = (config, helpers, check, context, fallbackMessage = 'Invalid media query configuration') => {
14
- if (!check)
15
- return true;
16
- try {
17
- check(config);
18
- return true;
19
- }
20
- catch (error) {
21
- const result = toValidationResult(error, fallbackMessage);
22
- return (0, helpers_1.applyMediaQueryValidation)(config, helpers, () => result, context);
23
- }
24
- };
25
- const validateMinMaxWidth = (props) => {
26
- if (!props.minWidth || !props.maxWidth)
27
- return;
28
- // Mixed units are valid CSS — each bound is evaluated independently — so we
29
- // only enforce ordering when the units match and the comparison is meaningful.
30
- if (props.minWidth.getUnit() !== props.maxWidth.getUnit())
31
- return;
32
- assertCondition(props.minWidth.getValue() <= props.maxWidth.getValue(), 'minWidth must be less than or equal to maxWidth');
33
- };
34
- const validateWidthValuesPositive = (props) => {
35
- const assertPositive = (value, label) => {
36
- assertCondition(value.getValue() > 0, `${label} must be greater than 0`);
37
- };
38
- if (props.width) {
39
- assertPositive(props.width, 'width');
40
- }
41
- if (props.minWidth) {
42
- assertPositive(props.minWidth, 'minWidth');
43
- }
44
- if (props.maxWidth) {
45
- assertPositive(props.maxWidth, 'maxWidth');
46
- }
47
- };
48
- const validateMinMaxHeight = (props) => {
49
- if (!props.minHeight || !props.maxHeight)
50
- return;
51
- // Mixed units are valid CSS; only enforce ordering when units match.
52
- if (props.minHeight.getUnit() !== props.maxHeight.getUnit())
53
- return;
54
- assertCondition(props.minHeight.getValue() <= props.maxHeight.getValue(), 'minHeight must be less than or equal to maxHeight');
55
- };
56
- const validateHeightValuesPositive = (props) => {
57
- const assertPositive = (value, label) => {
58
- assertCondition(value.getValue() > 0, `${label} must be greater than 0`);
59
- };
60
- if (props.height) {
61
- assertPositive(props.height, 'height');
62
- }
63
- if (props.minHeight) {
64
- assertPositive(props.minHeight, 'minHeight');
65
- }
66
- if (props.maxHeight) {
67
- assertPositive(props.maxHeight, 'maxHeight');
68
- }
69
- };
70
- const validateMinMaxAspectRatio = (props) => {
71
- if (!props.minAspectRatio || !props.maxAspectRatio)
72
- return;
73
- const assertRatio = (value, label) => {
74
- assertCondition((0, core_1.isRatio)(value), `${label} must be a ratio created with r()`);
75
- };
76
- assertRatio(props.minAspectRatio, 'minAspectRatio');
77
- assertRatio(props.maxAspectRatio, 'maxAspectRatio');
78
- const minRatio = (0, core_1.ratioToFloat)(props.minAspectRatio);
79
- const maxRatio = (0, core_1.ratioToFloat)(props.maxAspectRatio);
80
- assertCondition(minRatio <= maxRatio, 'minAspectRatio must be less than or equal to maxAspectRatio');
81
- };
82
- const validateAspectRatioValuesPositive = (props) => {
83
- const assertRatio = (value, label) => {
84
- assertCondition((0, core_1.isRatio)(value), `${label} must be a ratio created with r()`);
85
- };
86
- const assertValidPositive = (label, ratio) => {
87
- assertCondition((0, core_1.ratioToFloat)(ratio) > 0, `${label} must be a valid ratio greater than 0`);
88
- };
89
- if (props.aspectRatio !== undefined) {
90
- assertRatio(props.aspectRatio, 'aspectRatio');
91
- assertValidPositive('aspectRatio', props.aspectRatio);
92
- }
93
- if (props.minAspectRatio !== undefined) {
94
- assertRatio(props.minAspectRatio, 'minAspectRatio');
95
- assertValidPositive('minAspectRatio', props.minAspectRatio);
96
- }
97
- if (props.maxAspectRatio !== undefined) {
98
- assertRatio(props.maxAspectRatio, 'maxAspectRatio');
99
- assertValidPositive('maxAspectRatio', props.maxAspectRatio);
100
- }
101
- };
102
- const validateResolutionValues = (props) => {
103
- const assertPositive = (value, label) => {
104
- assertCondition(value.getValue() > 0, `${label} must be greater than 0`);
105
- };
106
- if (props.resolutionValue) {
107
- assertPositive(props.resolutionValue, 'resolution');
108
- }
109
- if (props.minResolution) {
110
- assertPositive(props.minResolution, 'minResolution');
111
- }
112
- if (props.maxResolution) {
113
- assertPositive(props.maxResolution, 'maxResolution');
114
- }
115
- // Resolution bounds may use different units (dpi, dpcm, dppx, x) — all
116
- // valid CSS — so we no longer require min/max to share a unit.
117
- };
118
- return {
119
- runMediaQueryValidation,
120
- validateMinMaxWidth,
121
- validateWidthValuesPositive,
122
- validateMinMaxHeight,
123
- validateHeightValuesPositive,
124
- validateMinMaxAspectRatio,
125
- validateAspectRatioValuesPositive,
126
- validateResolutionValues,
127
- };
128
- };
129
- exports.createMediaQueryValidation = createMediaQueryValidation;
130
- const defaultMediaQueryValidation = (0, exports.createMediaQueryValidation)({
131
- assertCondition: core_1.assertCondition,
132
- });
133
- exports.defaultMediaQueryValidation = defaultMediaQueryValidation;
134
- exports.runMediaQueryValidation = defaultMediaQueryValidation.runMediaQueryValidation, exports.validateMinMaxWidth = defaultMediaQueryValidation.validateMinMaxWidth, exports.validateWidthValuesPositive = defaultMediaQueryValidation.validateWidthValuesPositive, exports.validateMinMaxHeight = defaultMediaQueryValidation.validateMinMaxHeight, exports.validateHeightValuesPositive = defaultMediaQueryValidation.validateHeightValuesPositive, exports.validateMinMaxAspectRatio = defaultMediaQueryValidation.validateMinMaxAspectRatio, exports.validateAspectRatioValuesPositive = defaultMediaQueryValidation.validateAspectRatioValuesPositive, exports.validateResolutionValues = defaultMediaQueryValidation.validateResolutionValues;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _SciNotationImpl_coefficient, _SciNotationImpl_exponent, _SciNotationImpl_unit;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.isSciNotation = void 0;
16
- exports.sciNotation = sciNotation;
17
- class SciNotationImpl {
18
- constructor(coefficient, exponent, unit = 'px') {
19
- _SciNotationImpl_coefficient.set(this, void 0);
20
- _SciNotationImpl_exponent.set(this, void 0);
21
- _SciNotationImpl_unit.set(this, void 0);
22
- if (!Number.isFinite(coefficient) || !Number.isFinite(exponent)) {
23
- throw new Error('Scientific notation values must be finite numbers.');
24
- }
25
- if (!Number.isInteger(exponent)) {
26
- throw new Error('Scientific notation exponent must be an integer.');
27
- }
28
- __classPrivateFieldSet(this, _SciNotationImpl_coefficient, coefficient, "f");
29
- __classPrivateFieldSet(this, _SciNotationImpl_exponent, exponent, "f");
30
- __classPrivateFieldSet(this, _SciNotationImpl_unit, unit.toLowerCase(), "f");
31
- }
32
- coefficient() {
33
- return __classPrivateFieldGet(this, _SciNotationImpl_coefficient, "f");
34
- }
35
- exponent() {
36
- return __classPrivateFieldGet(this, _SciNotationImpl_exponent, "f");
37
- }
38
- getUnit() {
39
- return __classPrivateFieldGet(this, _SciNotationImpl_unit, "f");
40
- }
41
- valueOf() {
42
- return __classPrivateFieldGet(this, _SciNotationImpl_coefficient, "f") * 10 ** __classPrivateFieldGet(this, _SciNotationImpl_exponent, "f");
43
- }
44
- getValue() {
45
- return this.valueOf();
46
- }
47
- css() {
48
- return `${this.valueOf()}${__classPrivateFieldGet(this, _SciNotationImpl_unit, "f")}`;
49
- }
50
- toString() {
51
- return this.css();
52
- }
53
- withCoefficient(coefficient) {
54
- return new SciNotationImpl(coefficient, __classPrivateFieldGet(this, _SciNotationImpl_exponent, "f"), __classPrivateFieldGet(this, _SciNotationImpl_unit, "f"));
55
- }
56
- withExponent(exponent) {
57
- return new SciNotationImpl(__classPrivateFieldGet(this, _SciNotationImpl_coefficient, "f"), exponent, __classPrivateFieldGet(this, _SciNotationImpl_unit, "f"));
58
- }
59
- }
60
- _SciNotationImpl_coefficient = new WeakMap(), _SciNotationImpl_exponent = new WeakMap(), _SciNotationImpl_unit = new WeakMap();
61
- function sciNotation(coefficient, exponent, unit = 'px') {
62
- return new SciNotationImpl(coefficient, exponent, unit);
63
- }
64
- const isSciNotation = (value) => {
65
- return (typeof value === 'object' &&
66
- value !== null &&
67
- 'coefficient' in value &&
68
- 'exponent' in value &&
69
- 'getUnit' in value &&
70
- typeof value.coefficient === 'function' &&
71
- typeof value.exponent === 'function' &&
72
- typeof value.getUnit === 'function');
73
- };
74
- exports.isSciNotation = isSciNotation;
package/dist/cjs/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toValidationResult = exports.normalizeValidationResult = void 0;
4
- const normalizeValidationResult = (result) => {
5
- if (result === undefined || result === null)
6
- return { valid: true };
7
- if (typeof result === "boolean")
8
- return { valid: result };
9
- if (typeof result === "string") {
10
- return result ? { valid: false, message: result } : { valid: true };
11
- }
12
- return result;
13
- };
14
- exports.normalizeValidationResult = normalizeValidationResult;
15
- const toValidationResult = (error, fallback) => {
16
- if (error instanceof Error && error.message)
17
- return error.message;
18
- return fallback;
19
- };
20
- exports.toValidationResult = toValidationResult;
@@ -1,23 +0,0 @@
1
- import type { ContainerQueryModuleKeysMap } from "../containerQueries/moduleRegistry";
2
- import type { IMeasurement } from "../core";
3
- export type IComparisonOperator = "<" | "<=" | ">" | ">=" | "=";
4
- export type ContentQueryVariable = ContainerQueryModuleKeysMap[keyof ContainerQueryModuleKeysMap];
5
- export type ContentQueryComparisonValue = IMeasurement | number | string;
6
- export type Comparison<Variable = ContentQueryVariable, Value = ContentQueryComparisonValue> = {
7
- variable: Variable;
8
- operator: IComparisonOperator;
9
- value: Value;
10
- };
11
- export type ComparisonValue<Value = ContentQueryComparisonValue> = {
12
- operator: IComparisonOperator;
13
- value: Value;
14
- readonly __comparisonBrand: unique symbol;
15
- };
16
- export declare const compare: {
17
- eq: <T extends ContentQueryComparisonValue>(value: T) => ComparisonValue<T>;
18
- lt: <T extends ContentQueryComparisonValue>(value: T) => ComparisonValue<T>;
19
- lte: <T extends ContentQueryComparisonValue>(value: T) => ComparisonValue<T>;
20
- gt: <T extends ContentQueryComparisonValue>(value: T) => ComparisonValue<T>;
21
- gte: <T extends ContentQueryComparisonValue>(value: T) => ComparisonValue<T>;
22
- };
23
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/comparisons/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,MAAM,mBAAmB,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;AAEhE,MAAM,MAAM,oBAAoB,GAC9B,2BAA2B,CAAC,MAAM,2BAA2B,CAAC,CAAC;AAEjE,MAAM,MAAM,2BAA2B,GACnC,YAAY,GACZ,MAAM,GACN,MAAM,CAAC;AAEX,MAAM,MAAM,UAAU,CACpB,QAAQ,GAAG,oBAAoB,EAC/B,KAAK,GAAG,2BAA2B,IACjC;IACF,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,KAAK,GAAG,2BAA2B,IAAI;IACjE,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,CAAC,iBAAiB,EAAE,OAAO,MAAM,CAAC;CAC3C,CAAC;AAEF,eAAO,MAAM,OAAO;SACb,CAAC,SAAS,2BAA2B,SACjC,CAAC,KACP,eAAe,CAAC,CAAC,CAAC;SAIhB,CAAC,SAAS,2BAA2B,SACjC,CAAC,KACP,eAAe,CAAC,CAAC,CAAC;UAIf,CAAC,SAAS,2BAA2B,SAClC,CAAC,KACP,eAAe,CAAC,CAAC,CAAC;SAIhB,CAAC,SAAS,2BAA2B,SACjC,CAAC,KACP,eAAe,CAAC,CAAC,CAAC;UAIf,CAAC,SAAS,2BAA2B,SAClC,CAAC,KACP,eAAe,CAAC,CAAC,CAAC;CAItB,CAAC"}
@@ -1,22 +0,0 @@
1
- export const compare = {
2
- eq: (value) => ({
3
- operator: "=",
4
- value,
5
- }),
6
- lt: (value) => ({
7
- operator: "<",
8
- value,
9
- }),
10
- lte: (value) => ({
11
- operator: "<=",
12
- value,
13
- }),
14
- gt: (value) => ({
15
- operator: ">",
16
- value,
17
- }),
18
- gte: (value) => ({
19
- operator: ">=",
20
- value,
21
- }),
22
- };
@@ -1,36 +0,0 @@
1
- import { IMeasurement } from "../core";
2
- import type { Comparison, IComparisonOperator } from "../comparisons";
3
- import type { IContainerQueryAspectRatio, IContainerQueryBlock, IContainerQueryCustomFeatures, IContainerQueryInline, IContainerQueryStyle } from "./modules";
4
- import { ContainerQueryValidation } from "./validation";
5
- import { ContainerQueryBuilderHelpers } from "./helpers";
6
- import type { StyleRule } from "../mediaQueries/types";
7
- import type { CSSContainerCondition } from "./types";
8
- export interface IContainerQueryProps extends IContainerQueryCore, IContainerQueryInline, IContainerQueryBlock, IContainerQueryAspectRatio, IContainerQueryStyle, IContainerQueryCustomFeatures {
9
- }
10
- export interface IContainerQueryCore {
11
- minWidth?: IMeasurement | IMeasurement[];
12
- maxWidth?: IMeasurement | IMeasurement[];
13
- minHeight?: IMeasurement | IMeasurement[];
14
- maxHeight?: IMeasurement | IMeasurement[];
15
- }
16
- export type IContainerQueryCoreVariables = IContainerQueryCore["minWidth"] | IContainerQueryCore["maxWidth"] | IContainerQueryCore["minHeight"] | IContainerQueryCore["maxHeight"];
17
- export type SizeComparisonValue = IMeasurement | string | number;
18
- export type CoreComparisonVariable = "minWidth" | "maxWidth" | "minHeight" | "maxHeight";
19
- export type CoreComparison = Comparison<CoreComparisonVariable, IMeasurement>;
20
- export type CoreComparisonBlock<Variable = CoreComparisonVariable, Value = IMeasurement> = {
21
- variable: Variable;
22
- operator: IComparisonOperator;
23
- value: Value;
24
- };
25
- export interface IContainerQuery {
26
- props: IContainerQueryProps;
27
- styles: StyleRule;
28
- }
29
- export type IContainerQueries = Record<string, IContainerQueryProps>;
30
- export type IContainerQueryStyles<T extends IContainerQueries> = Partial<Record<keyof T, StyleRule>>;
31
- export declare const createEmitCoreFeatures: (validation: ContainerQueryValidation) => (props: IContainerQueryCore, helpers: ContainerQueryBuilderHelpers) => void;
32
- export declare const emitCoreFeatures: (props: IContainerQueryCore, helpers: ContainerQueryBuilderHelpers) => void;
33
- export declare const buildContainerQueryString: (config: IContainerQueryProps) => string;
34
- export declare const buildContainerConditionString: (condition: CSSContainerCondition) => string;
35
- export declare const makeContainerQueryStyle: <T extends IContainerQueries>(queries: T) => (stylesByQuery: IContainerQueryStyles<T>) => StyleRule;
36
- //# sourceMappingURL=containerQueries.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"containerQueries.d.ts","sourceRoot":"","sources":["../../../src/containerQueries/containerQueries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,KAAK,EACV,0BAA0B,EAC1B,oBAAoB,EACpB,6BAA6B,EAC7B,qBAAqB,EACrB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C9B,KAAK,EAAE,oBAAoB,CAAC;IAC5B,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAErE,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,iBAAiB,IAAI,OAAO,CACtE,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,CAC3B,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAChC,YAAY,wBAAwB,MACpC,OAAO,mBAAmB,EAAE,SAAS,4BAA4B,KAAG,IA6GpE,CAAC;AAEJ,eAAO,MAAM,gBAAgB,UA/GnB,mBAAmB,WAAW,4BAA4B,KAAG,IAiHtE,CAAC;AAcF,eAAO,MAAM,yBAAyB,0CAEpC,CAAC;AAcH,eAAO,MAAM,6BAA6B,GACxC,WAAW,qBAAqB,KAC/B,MAeF,CAAC;AAEF,eAAO,MAAM,uBAAuB,GACjC,CAAC,SAAS,iBAAiB,EAAE,SAAS,CAAC,MACvC,eAAe,qBAAqB,CAAC,CAAC,CAAC,KAAG,SAc1C,CAAC"}
@@ -1,109 +0,0 @@
1
- import { emitAspectRatioFeatures, emitBlockSizeFeatures, emitCustomFeatures, emitInlineSizeFeatures, emitStyleFeatures, } from "./modules";
2
- import { runContainerQueryLint } from "./linting";
3
- import { lintHeightExactRedundancy, lintWidthExactRedundancy, } from "./linting/core";
4
- import { defaultContainerQueryValidation } from "./validation";
5
- import { createContainerQueryBuilder } from "./helpers";
6
- export const createEmitCoreFeatures = (validation) => (props, helpers) => {
7
- const allowQueryArrays = helpers.config.allowQueryArrays !== false;
8
- const assertNoArray = (value, label) => {
9
- if (Array.isArray(value) && !allowQueryArrays) {
10
- throw new Error(`${label} does not allow arrays.`);
11
- }
12
- };
13
- const emitFeature = (name, value) => {
14
- if (Array.isArray(value)) {
15
- value.forEach((entry) => {
16
- var _a;
17
- ((_a = helpers.addFeatureUnsafe) !== null && _a !== void 0 ? _a : helpers.addFeature)(name, entry);
18
- });
19
- return;
20
- }
21
- helpers.addFeature(name, value);
22
- };
23
- const { runContainerQueryValidation, validateMinMaxWidth, validateWidthValuesPositive, validateMinMaxHeight, validateHeightValuesPositive, } = validation;
24
- if (!runContainerQueryValidation(props, helpers, validateMinMaxWidth, "core", "minWidth must be less than or equal to maxWidth")) {
25
- return;
26
- }
27
- if (!runContainerQueryValidation(props, helpers, validateMinMaxHeight, "core", "minHeight must be less than or equal to maxHeight")) {
28
- return;
29
- }
30
- if (!runContainerQueryValidation(props, helpers, validateWidthValuesPositive, "core", "width values must be greater than 0")) {
31
- return;
32
- }
33
- if (!runContainerQueryValidation(props, helpers, validateHeightValuesPositive, "core", "height values must be greater than 0")) {
34
- return;
35
- }
36
- if (!runContainerQueryLint(props, helpers, lintWidthExactRedundancy, "minWidth should not be combined with maxWidth when both are equal")) {
37
- return;
38
- }
39
- if (!runContainerQueryLint(props, helpers, lintHeightExactRedundancy, "minHeight should not be combined with maxHeight when both are equal")) {
40
- return;
41
- }
42
- if (props.minWidth !== undefined) {
43
- assertNoArray(props.minWidth, "minWidth");
44
- emitFeature("min-width", props.minWidth);
45
- }
46
- if (props.maxWidth !== undefined) {
47
- assertNoArray(props.maxWidth, "maxWidth");
48
- emitFeature("max-width", props.maxWidth);
49
- }
50
- if (props.minHeight !== undefined) {
51
- assertNoArray(props.minHeight, "minHeight");
52
- emitFeature("min-height", props.minHeight);
53
- }
54
- if (props.maxHeight !== undefined) {
55
- assertNoArray(props.maxHeight, "maxHeight");
56
- emitFeature("max-height", props.maxHeight);
57
- }
58
- };
59
- export const emitCoreFeatures = createEmitCoreFeatures(defaultContainerQueryValidation);
60
- const emitBaseFeatures = (props, helpers) => {
61
- emitCoreFeatures(props, helpers);
62
- emitAspectRatioFeatures(props, helpers);
63
- emitInlineSizeFeatures(props, helpers);
64
- emitBlockSizeFeatures(props, helpers);
65
- emitStyleFeatures(props, helpers);
66
- emitCustomFeatures(props, helpers);
67
- };
68
- export const buildContainerQueryString = createContainerQueryBuilder({
69
- emitBase: emitBaseFeatures,
70
- });
71
- const wrapContainerCondition = (value) => {
72
- const trimmed = value.trim();
73
- if (trimmed.includes(" and ") ||
74
- trimmed.includes(" or ") ||
75
- trimmed.startsWith("not ")) {
76
- return `(${trimmed})`;
77
- }
78
- return trimmed;
79
- };
80
- export const buildContainerConditionString = (condition) => {
81
- if ("and" in condition) {
82
- return condition.and
83
- .map((entry) => wrapContainerCondition(buildContainerConditionString(entry)))
84
- .join(" and ");
85
- }
86
- if ("or" in condition) {
87
- return condition.or
88
- .map((entry) => wrapContainerCondition(buildContainerConditionString(entry)))
89
- .join(" or ");
90
- }
91
- if ("not" in condition) {
92
- return `not ${wrapContainerCondition(buildContainerConditionString(condition.not))}`;
93
- }
94
- return buildContainerQueryString(condition);
95
- };
96
- export const makeContainerQueryStyle = (queries) => (stylesByQuery) => {
97
- const result = {};
98
- Object.keys(stylesByQuery).forEach((key) => {
99
- const styles = stylesByQuery[key];
100
- const props = queries[key];
101
- if (!styles || !props)
102
- return;
103
- result[buildContainerQueryString(props)] = styles;
104
- });
105
- const containerQuery = {
106
- "@container": result,
107
- };
108
- return containerQuery;
109
- };
@@ -1,20 +0,0 @@
1
- import type { ComplexStyleRule, StyleRule } from "../mediaQueries/types";
2
- import type { CSSContainerQueries } from "./types";
3
- import type { ContainerQueryBuilderConfig } from "./helpers";
4
- import type { ContainerQueryModulesList } from "./moduleRegistry";
5
- type ContainerQueryStyleMap<TQueries> = Partial<Record<keyof TQueries, StyleRule>>;
6
- export type ContainerQueryFactoryConfig<TModules extends ContainerQueryModulesList | undefined = undefined, TOutput = ComplexStyleRule> = ContainerQueryBuilderConfig & {
7
- label: string;
8
- modules?: TModules;
9
- output?: (container: ComplexStyleRule) => TOutput;
10
- };
11
- export declare const createContainerQueryFactory: () => <TModules extends ContainerQueryModulesList | undefined, TQueries extends CSSContainerQueries, TOutput = ComplexStyleRule>(options: {
12
- queries: TQueries;
13
- config: ContainerQueryFactoryConfig<TModules, TOutput>;
14
- }) => (stylesByQuery: ContainerQueryStyleMap<TQueries>) => TOutput;
15
- export declare const containerQueryFactory: <TModules extends ContainerQueryModulesList | undefined, TQueries extends CSSContainerQueries, TOutput = ComplexStyleRule>(options: {
16
- queries: TQueries;
17
- config: ContainerQueryFactoryConfig<TModules, TOutput>;
18
- }) => (stylesByQuery: ContainerQueryStyleMap<TQueries>) => TOutput;
19
- export {};
20
- //# sourceMappingURL=factory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/containerQueries/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,KAAK,EAEV,mBAAmB,EACpB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EACV,2BAA2B,EAC5B,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAEV,yBAAyB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B,KAAK,sBAAsB,CAAC,QAAQ,IAAI,OAAO,CAC7C,MAAM,CAAC,MAAM,QAAQ,EAAE,SAAS,CAAC,CAClC,CAAC;AAqIF,MAAM,MAAM,2BAA2B,CACrC,QAAQ,SAAS,yBAAyB,GAAG,SAAS,GAAG,SAAS,EAClE,OAAO,GAAG,gBAAgB,IACxB,2BAA2B,GAAG;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,gBAAgB,KAAK,OAAO,CAAC;CACnD,CAAC;AAEF,eAAO,MAAM,2BAA2B,SACtC,QAAQ,SAAS,yBAAyB,GAAG,SAAS,EACtD,QAAQ,SAAS,mBAAmB,EACpC,OAAO,GAAG,gBAAgB,EAC1B,SAAS;IACT,OAAO,EAAE,QAAQ,CAAC;IAClB,MAAM,EAAE,2BAA2B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;CACxD,MAGS,eAAe,sBAAsB,CAAC,QAAQ,CAAC,KAAG,OA6B3D,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAxChC,QAAQ,SAAS,yBAAyB,GAAG,SAAS,EACtD,QAAQ,SAAS,mBAAmB,EACpC,OAAO,8BACE;IACT,OAAO,EAAE,QAAQ,CAAC;IAClB,MAAM,EAAE,2BAA2B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;CACxD,MAGS,eAAe,sBAAsB,CAAC,QAAQ,CAAC,KAAG,OA+BM,CAAC"}
@@ -1,119 +0,0 @@
1
- import { buildContainerConditionString } from "./containerQueries";
2
- const ALL_CONTAINER_QUERY_MODULES = [
3
- "core",
4
- "inline",
5
- "block",
6
- "aspectRatio",
7
- "style",
8
- "custom",
9
- ];
10
- const MODULE_KEYS = {
11
- core: ["minWidth", "maxWidth", "minHeight", "maxHeight"],
12
- inline: ["inlineSize", "inlineSizeRange"],
13
- block: ["blockSize", "blockSizeRange"],
14
- aspectRatio: ["aspectRatio", "minAspectRatio", "maxAspectRatio"],
15
- style: ["style"],
16
- custom: ["customFeatures"],
17
- };
18
- const KEY_TO_MODULE = Object.fromEntries(Object.keys(MODULE_KEYS).flatMap((moduleId) => MODULE_KEYS[moduleId].map((key) => [key, moduleId])));
19
- const collectConditionKeys = (condition, keys) => {
20
- if ("and" in condition) {
21
- condition.and.forEach((entry) => collectConditionKeys(entry, keys));
22
- return;
23
- }
24
- if ("or" in condition) {
25
- condition.or.forEach((entry) => collectConditionKeys(entry, keys));
26
- return;
27
- }
28
- if ("not" in condition) {
29
- collectConditionKeys(condition.not, keys);
30
- return;
31
- }
32
- Object.keys(condition).forEach((key) => keys.add(key));
33
- };
34
- const collectAndConditionKeys = (condition, keys) => {
35
- if ("and" in condition) {
36
- condition.and.forEach((entry) => collectAndConditionKeys(entry, keys));
37
- return;
38
- }
39
- if ("or" in condition || "not" in condition) {
40
- return;
41
- }
42
- Object.keys(condition).forEach((key) => keys.push(key));
43
- };
44
- const guardUnsupportedCondition = (condition, modules, config, label) => {
45
- const allowed = new Set();
46
- modules.forEach((moduleId) => {
47
- MODULE_KEYS[moduleId].forEach((key) => {
48
- allowed.add(key);
49
- });
50
- });
51
- const conditionKeys = new Set();
52
- collectConditionKeys(condition, conditionKeys);
53
- conditionKeys.forEach((key) => {
54
- var _a, _b;
55
- if (allowed.has(key))
56
- return;
57
- const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : "throw";
58
- const moduleHint = KEY_TO_MODULE[key];
59
- const moduleSuffix = moduleHint
60
- ? ` Add "${moduleHint}" to modules.`
61
- : "";
62
- const message = `Container query factory "${label}" received unsupported feature "${key}".${moduleSuffix}`;
63
- if (mode === "log") {
64
- console.warn(message);
65
- return;
66
- }
67
- if (mode === "allow")
68
- return;
69
- throw new Error(message);
70
- });
71
- };
72
- const guardDuplicateConditions = (condition, config, label) => {
73
- var _a, _b;
74
- const keys = [];
75
- collectAndConditionKeys(condition, keys);
76
- const seen = new Set();
77
- const duplicates = new Set();
78
- keys.forEach((key) => {
79
- if (seen.has(key)) {
80
- duplicates.add(key);
81
- return;
82
- }
83
- seen.add(key);
84
- });
85
- if (!duplicates.size)
86
- return;
87
- const mode = (_b = (_a = config.errorHandling) === null || _a === void 0 ? void 0 : _a.invalidValueMode) !== null && _b !== void 0 ? _b : "throw";
88
- const message = `Container query factory "${label}" received duplicate condition "${Array.from(duplicates).join('", "')}".`;
89
- if (mode === "log") {
90
- console.warn(message);
91
- return;
92
- }
93
- if (mode === "allow")
94
- return;
95
- throw new Error(message);
96
- };
97
- export const createContainerQueryFactory = () => (options) => {
98
- var _a;
99
- const modules = (_a = options.config.modules) !== null && _a !== void 0 ? _a : ALL_CONTAINER_QUERY_MODULES;
100
- return (stylesByQuery) => {
101
- const result = {};
102
- Object.keys(stylesByQuery).forEach((key) => {
103
- const styles = stylesByQuery[key];
104
- const rule = options.queries[key];
105
- if (!styles || !(rule === null || rule === void 0 ? void 0 : rule.query))
106
- return;
107
- guardUnsupportedCondition(rule.query.condition, modules, options.config, options.config.label);
108
- guardDuplicateConditions(rule.query.condition, options.config, options.config.label);
109
- result[buildContainerConditionString(rule.query.condition)] = styles;
110
- });
111
- const containerQuery = {
112
- "@container": result,
113
- };
114
- return options.config.output
115
- ? options.config.output(containerQuery)
116
- : containerQuery;
117
- };
118
- };
119
- export const containerQueryFactory = createContainerQueryFactory();
@@ -1,53 +0,0 @@
1
- import type { IRatio } from "../ratio";
2
- import type { IMeasurement } from "../core";
3
- import type { ComparisonValue } from "../comparisons";
4
- import type { CSSComparison, CSSRange } from "./types";
5
- import type { ValidationResult } from "../validation";
6
- export type ContainerQueryValidationResult = ValidationResult;
7
- export type ContainerQueryValidator<TConfig> = (config: TConfig) => ContainerQueryValidationResult;
8
- type ContainerQueryFeatureValue = string | number | IMeasurement | IRatio;
9
- type ContainerQueryFeatureEmitter = (name: string, value: ContainerQueryFeatureValue) => void;
10
- type ContainerQueryConditionEmitter = (condition: string) => void;
11
- export type ContainerQueryInvalidValueMode = "allow" | "log" | "throw";
12
- export type ContainerQueryLintingMode = "allow" | "log" | "throw";
13
- export type ContainerQueryBuilderConfig = {
14
- errorHandling?: {
15
- invalidValueMode?: ContainerQueryInvalidValueMode;
16
- lintingMode?: ContainerQueryLintingMode;
17
- };
18
- allowQueryArrays?: boolean;
19
- };
20
- export interface ContainerQueryBuilderHelpers {
21
- addFeature: ContainerQueryFeatureEmitter;
22
- addFeatureUnsafe: ContainerQueryFeatureEmitter;
23
- addCondition: ContainerQueryConditionEmitter;
24
- config: ContainerQueryBuilderConfig;
25
- }
26
- export type ContainerQueryExtensionHandler<TConfig> = (config: TConfig, helpers: ContainerQueryBuilderHelpers) => void;
27
- type ContainerQueryBuilderOptions<TConfig> = {
28
- emitBase: ContainerQueryExtensionHandler<TConfig>;
29
- emitExtensions?: ContainerQueryExtensionHandler<TConfig>;
30
- resolveType?: (config: TConfig) => "all" | "print" | "screen" | undefined;
31
- config?: ContainerQueryBuilderConfig;
32
- };
33
- export declare const formatContainerQueryValue: (value: ContainerQueryFeatureValue) => string;
34
- type ContainerQueryRangeMode = "min" | "max";
35
- type ContainerQueryRangeOptions = {
36
- mode?: ContainerQueryRangeMode;
37
- inclusive?: boolean;
38
- };
39
- export declare const buildContainerComparison: <TValue>(comparison: ComparisonValue<TValue>) => CSSComparison<TValue>;
40
- export declare const buildContainerRange: <TValue>(min: TValue, max: TValue, options?: ContainerQueryRangeOptions) => CSSRange<TValue>;
41
- export declare const buildContainerQueryStringFromParts: (parts: string[]) => string;
42
- export declare const formatContainerQueryComparison: (name: string, operator: string, value: ContainerQueryFeatureValue) => string;
43
- export declare const createContainerQueryFeatureEmitter: (parts: string[]) => ContainerQueryFeatureEmitter;
44
- export declare const createContainerQueryConditionEmitter: (parts: string[]) => ContainerQueryConditionEmitter;
45
- type ContainerQueryFeatureEmitterOptions = {
46
- emitted?: Set<string>;
47
- lintingMode?: ContainerQueryLintingMode;
48
- };
49
- export declare const createContainerQueryFeatureEmitterWithTracking: (parts: string[], options?: ContainerQueryFeatureEmitterOptions) => ContainerQueryFeatureEmitter;
50
- export declare const createContainerQueryBuilder: <TConfig>(options: ContainerQueryBuilderOptions<TConfig>) => (config: TConfig) => string;
51
- export declare const applyContainerQueryValidation: <TConfig>(config: TConfig, helpers: ContainerQueryBuilderHelpers, validator?: ContainerQueryValidator<TConfig>, context?: string) => boolean;
52
- export {};
53
- //# sourceMappingURL=helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/containerQueries/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,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