css-calipers 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) 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/ratio.d.ts +22 -0
  172. package/dist/esm/ratio.d.ts.map +1 -0
  173. package/dist/esm/ratio.js +131 -0
  174. package/dist/esm/types.d.ts +35 -0
  175. package/dist/esm/types.d.ts.map +1 -0
  176. package/dist/esm/types.js +1 -0
  177. package/dist/esm/validation.d.ts +10 -0
  178. package/dist/esm/validation.d.ts.map +1 -0
  179. package/dist/esm/validation.js +15 -0
  180. package/dist/examples/containerQueries.example.js +54 -0
  181. package/dist/examples/examples/containerQueries.example.js +54 -0
  182. package/dist/examples/examples/factory-wrapper.example.js +33 -0
  183. package/dist/examples/examples/lineHeight-normalizer.example.js +81 -0
  184. package/dist/examples/examples/mediaQueries-multipleInstances.example.js +127 -0
  185. package/dist/examples/examples/mixedQueries.example.js +55 -0
  186. package/dist/examples/examples/validation-and-runtime-checks.example.js +85 -0
  187. package/dist/examples/examples/validation-unit-tests.example.js +35 -0
  188. package/dist/examples/factory-wrapper.example.js +33 -0
  189. package/dist/examples/lineHeight-normalizer.example.js +81 -0
  190. package/dist/examples/mediaQueries-multipleInstances.example.js +127 -0
  191. package/dist/examples/mixedQueries.example.js +60 -0
  192. package/dist/examples/src/comparisons/index.js +25 -0
  193. package/dist/examples/src/containerQueries/containerQueries.js +96 -0
  194. package/dist/examples/src/containerQueries/factory.js +123 -0
  195. package/dist/examples/src/containerQueries/helpers.js +94 -0
  196. package/dist/examples/src/containerQueries/index.js +16 -0
  197. package/dist/examples/src/containerQueries/linting/aspectRatio.js +20 -0
  198. package/dist/examples/src/containerQueries/linting/block.js +20 -0
  199. package/dist/examples/src/containerQueries/linting/core.js +19 -0
  200. package/dist/examples/src/containerQueries/linting/custom.js +11 -0
  201. package/dist/examples/src/containerQueries/linting/inline.js +20 -0
  202. package/dist/examples/src/containerQueries/linting/style.js +28 -0
  203. package/dist/examples/src/containerQueries/linting.js +24 -0
  204. package/dist/examples/src/containerQueries/moduleRegistry.js +5 -0
  205. package/dist/examples/src/containerQueries/modules/aspectRatio.js +33 -0
  206. package/dist/examples/src/containerQueries/modules/block.js +44 -0
  207. package/dist/examples/src/containerQueries/modules/custom.js +31 -0
  208. package/dist/examples/src/containerQueries/modules/index.js +21 -0
  209. package/dist/examples/src/containerQueries/modules/inline.js +44 -0
  210. package/dist/examples/src/containerQueries/modules/style.js +36 -0
  211. package/dist/examples/src/containerQueries/types.js +2 -0
  212. package/dist/examples/src/containerQueries/validation.js +177 -0
  213. package/dist/examples/src/core.js +16 -0
  214. package/dist/examples/src/factory.js +21 -0
  215. package/dist/examples/src/index.js +30 -0
  216. package/dist/examples/src/internal/buildMeasurementCreationError.js +16 -0
  217. package/dist/examples/src/internal/createCoreApi.js +336 -0
  218. package/dist/examples/src/internal/createMediaQueriesApi.js +74 -0
  219. package/dist/examples/src/internal/createUnitsApi.js +18 -0
  220. package/dist/examples/src/internal/errors.js +130 -0
  221. package/dist/examples/src/libraryHelpers/vanilla-extract.js +11 -0
  222. package/dist/examples/src/mediaQueries/factory.js +163 -0
  223. package/dist/examples/src/mediaQueries/helpers.js +88 -0
  224. package/dist/examples/src/mediaQueries/index.js +23 -0
  225. package/dist/examples/src/mediaQueries/linting/core.js +19 -0
  226. package/dist/examples/src/mediaQueries/linting/resolution.js +11 -0
  227. package/dist/examples/src/mediaQueries/linting.js +24 -0
  228. package/dist/examples/src/mediaQueries/mediaQueries.js +53 -0
  229. package/dist/examples/src/mediaQueries/moduleRegistry.js +5 -0
  230. package/dist/examples/src/mediaQueries/modules/custom.js +26 -0
  231. package/dist/examples/src/mediaQueries/modules/dimensions.js +61 -0
  232. package/dist/examples/src/mediaQueries/modules/display.js +20 -0
  233. package/dist/examples/src/mediaQueries/modules/environment.js +20 -0
  234. package/dist/examples/src/mediaQueries/modules/index.js +23 -0
  235. package/dist/examples/src/mediaQueries/modules/interaction.js +26 -0
  236. package/dist/examples/src/mediaQueries/modules/preferences.js +26 -0
  237. package/dist/examples/src/mediaQueries/modules/resolution.js +31 -0
  238. package/dist/examples/src/mediaQueries/types.js +2 -0
  239. package/dist/examples/src/mediaQueries/validation.js +128 -0
  240. package/dist/examples/src/ratio.js +141 -0
  241. package/dist/examples/src/types.js +2 -0
  242. package/dist/examples/src/unitDefinitions.js +67 -0
  243. package/dist/examples/src/units/absolute.js +11 -0
  244. package/dist/examples/src/units/angle.js +8 -0
  245. package/dist/examples/src/units/container.js +10 -0
  246. package/dist/examples/src/units/font-relative.js +16 -0
  247. package/dist/examples/src/units/frequency.js +6 -0
  248. package/dist/examples/src/units/grid.js +5 -0
  249. package/dist/examples/src/units/percent.js +7 -0
  250. package/dist/examples/src/units/resolution.js +7 -0
  251. package/dist/examples/src/units/time.js +6 -0
  252. package/dist/examples/src/units/viewport-dynamic.js +10 -0
  253. package/dist/examples/src/units/viewport-large.js +10 -0
  254. package/dist/examples/src/units/viewport-small.js +10 -0
  255. package/dist/examples/src/units/viewport.js +10 -0
  256. package/dist/examples/src/validation.js +20 -0
  257. package/dist/examples/validation-and-runtime-checks.example.js +85 -0
  258. package/dist/examples/validation-unit-tests.example.js +35 -0
  259. package/package.json +16 -5
@@ -0,0 +1,187 @@
1
+ import { applyContainerQueryValidation } from "./helpers";
2
+ import { assertCondition, assertMatchingUnits, hasCssMethod, isMeasurement, isRatio, } from "../core";
3
+ import { toValidationResult } from "../validation";
4
+ import { normalizeToArray } from "../internal/normalizeToArray";
5
+ import { ratioToFloat } from "../ratio";
6
+ const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
7
+ const assertMeasurement = (value, label) => {
8
+ assertCondition(isMeasurement(value), `${label} must be a measurement`);
9
+ };
10
+ const assertMeasurementPositive = (value, label) => {
11
+ assertCondition(value.getValue() > 0, `${label} must be greater than 0`);
12
+ };
13
+ const assertRatio = (value, label) => {
14
+ assertCondition(isRatio(value), `${label} must be a ratio created with r()`);
15
+ };
16
+ const assertRatioPositive = (value, label) => {
17
+ assertCondition(value.numerator() > 0, `${label} numerator must be greater than 0`);
18
+ assertCondition(value.denominator() > 0, `${label} denominator must be greater than 0`);
19
+ };
20
+ const isStyleValue = (value) => {
21
+ if (typeof value === "string")
22
+ return true;
23
+ if (isFiniteNumber(value))
24
+ return true;
25
+ if (hasCssMethod(value))
26
+ return true;
27
+ return false;
28
+ };
29
+ export const createContainerQueryValidation = (core) => {
30
+ const assertCondition = core.assertCondition;
31
+ const assertMatchingUnits = core.assertMatchingUnits;
32
+ const runContainerQueryValidation = (config, helpers, check, context, fallbackMessage = "Invalid container query configuration") => {
33
+ if (!check)
34
+ return true;
35
+ try {
36
+ check(config);
37
+ return true;
38
+ }
39
+ catch (error) {
40
+ const result = toValidationResult(error, fallbackMessage);
41
+ return applyContainerQueryValidation(config, helpers, () => result, context);
42
+ }
43
+ };
44
+ const validateMinMaxWidth = (props) => {
45
+ if (!props.minWidth || !props.maxWidth)
46
+ return;
47
+ if (Array.isArray(props.minWidth) || Array.isArray(props.maxWidth)) {
48
+ return;
49
+ }
50
+ assertMatchingUnits(props.minWidth, props.maxWidth, "containerQueries.minMaxWidth");
51
+ assertCondition(props.minWidth.getValue() <= props.maxWidth.getValue(), "minWidth must be less than or equal to maxWidth");
52
+ };
53
+ const validateWidthValuesPositive = (props) => {
54
+ normalizeToArray(props.minWidth).forEach((value) => {
55
+ assertMeasurement(value, "minWidth");
56
+ assertMeasurementPositive(value, "minWidth");
57
+ });
58
+ normalizeToArray(props.maxWidth).forEach((value) => {
59
+ assertMeasurement(value, "maxWidth");
60
+ assertMeasurementPositive(value, "maxWidth");
61
+ });
62
+ };
63
+ const validateMinMaxHeight = (props) => {
64
+ if (!props.minHeight || !props.maxHeight)
65
+ return;
66
+ if (Array.isArray(props.minHeight) || Array.isArray(props.maxHeight)) {
67
+ return;
68
+ }
69
+ assertMatchingUnits(props.minHeight, props.maxHeight, "containerQueries.minMaxHeight");
70
+ assertCondition(props.minHeight.getValue() <= props.maxHeight.getValue(), "minHeight must be less than or equal to maxHeight");
71
+ };
72
+ const validateHeightValuesPositive = (props) => {
73
+ normalizeToArray(props.minHeight).forEach((value) => {
74
+ assertMeasurement(value, "minHeight");
75
+ assertMeasurementPositive(value, "minHeight");
76
+ });
77
+ normalizeToArray(props.maxHeight).forEach((value) => {
78
+ assertMeasurement(value, "maxHeight");
79
+ assertMeasurementPositive(value, "maxHeight");
80
+ });
81
+ };
82
+ const validateInlineSizeValues = (props) => {
83
+ normalizeToArray(props.inlineSize).forEach((value) => {
84
+ assertMeasurement(value.value, "inlineSize");
85
+ assertMeasurementPositive(value.value, "inlineSize");
86
+ });
87
+ normalizeToArray(props.inlineSizeRange).forEach((value) => {
88
+ assertMeasurement(value.min, "inlineSizeRange.min");
89
+ assertMeasurement(value.max, "inlineSizeRange.max");
90
+ assertMeasurementPositive(value.min, "inlineSizeRange.min");
91
+ assertMeasurementPositive(value.max, "inlineSizeRange.max");
92
+ assertMatchingUnits(value.min, value.max, "containerQueries.inlineSizeRangeUnits");
93
+ assertCondition(value.min.getValue() <= value.max.getValue(), "inlineSizeRange min must be less than or equal to max");
94
+ });
95
+ };
96
+ const validateBlockSizeValues = (props) => {
97
+ normalizeToArray(props.blockSize).forEach((value) => {
98
+ assertMeasurement(value.value, "blockSize");
99
+ assertMeasurementPositive(value.value, "blockSize");
100
+ });
101
+ normalizeToArray(props.blockSizeRange).forEach((value) => {
102
+ assertMeasurement(value.min, "blockSizeRange.min");
103
+ assertMeasurement(value.max, "blockSizeRange.max");
104
+ assertMeasurementPositive(value.min, "blockSizeRange.min");
105
+ assertMeasurementPositive(value.max, "blockSizeRange.max");
106
+ assertMatchingUnits(value.min, value.max, "containerQueries.blockSizeRangeUnits");
107
+ assertCondition(value.min.getValue() <= value.max.getValue(), "blockSizeRange min must be less than or equal to max");
108
+ });
109
+ };
110
+ const validateAspectRatioValues = (props) => {
111
+ normalizeToArray(props.aspectRatio).forEach((value) => {
112
+ assertRatio(value, "aspectRatio");
113
+ assertRatioPositive(value, "aspectRatio");
114
+ });
115
+ normalizeToArray(props.minAspectRatio).forEach((value) => {
116
+ assertRatio(value, "minAspectRatio");
117
+ assertRatioPositive(value, "minAspectRatio");
118
+ });
119
+ normalizeToArray(props.maxAspectRatio).forEach((value) => {
120
+ assertRatio(value, "maxAspectRatio");
121
+ assertRatioPositive(value, "maxAspectRatio");
122
+ });
123
+ if (props.minAspectRatio &&
124
+ props.maxAspectRatio &&
125
+ !Array.isArray(props.minAspectRatio) &&
126
+ !Array.isArray(props.maxAspectRatio)) {
127
+ const minValue = ratioToFloat(props.minAspectRatio);
128
+ const maxValue = ratioToFloat(props.maxAspectRatio);
129
+ assertCondition(minValue <= maxValue, "minAspectRatio must be less than or equal to maxAspectRatio");
130
+ }
131
+ };
132
+ const validateStyleValues = (props) => {
133
+ if (!props.style)
134
+ return;
135
+ const entries = Object.entries(props.style);
136
+ assertCondition(entries.length > 0, "style conditions must not be empty.");
137
+ entries.forEach(([name, value]) => {
138
+ if (value === undefined || value === null)
139
+ return;
140
+ if (Array.isArray(value)) {
141
+ assertCondition(value.length > 0, `style.${name} must not be empty`);
142
+ value.forEach((entry, index) => {
143
+ assertCondition(isStyleValue(entry), `style.${name}[${index}] must be a primitive or measurement`);
144
+ });
145
+ return;
146
+ }
147
+ assertCondition(isStyleValue(value), `style.${name} must be a primitive or measurement`);
148
+ });
149
+ };
150
+ const validateCustomFeatures = (props) => {
151
+ if (!props.customFeatures)
152
+ return;
153
+ const entries = Object.entries(props.customFeatures);
154
+ assertCondition(entries.length > 0, "customFeatures should not be empty.");
155
+ entries.forEach(([name, value]) => {
156
+ const trimmedName = name.trim();
157
+ assertCondition(trimmedName.length > 0, "Custom feature name must be non-empty.");
158
+ if (value === undefined || value === null)
159
+ return;
160
+ if (Array.isArray(value)) {
161
+ value.forEach((entry, index) => {
162
+ assertCondition(isStyleValue(entry), `Custom feature "${trimmedName}[${index}]" must be a primitive or a measurement.`);
163
+ });
164
+ return;
165
+ }
166
+ assertCondition(isStyleValue(value), `Custom feature "${trimmedName}" must be a primitive or a measurement.`);
167
+ });
168
+ };
169
+ return {
170
+ runContainerQueryValidation,
171
+ validateMinMaxWidth,
172
+ validateWidthValuesPositive,
173
+ validateMinMaxHeight,
174
+ validateHeightValuesPositive,
175
+ validateInlineSizeValues,
176
+ validateBlockSizeValues,
177
+ validateAspectRatioValues,
178
+ validateStyleValues,
179
+ validateCustomFeatures,
180
+ };
181
+ };
182
+ const defaultContainerQueryValidation = createContainerQueryValidation({
183
+ assertCondition,
184
+ assertMatchingUnits,
185
+ });
186
+ export const { runContainerQueryValidation, validateMinMaxWidth, validateWidthValuesPositive, validateMinMaxHeight, validateHeightValuesPositive, validateInlineSizeValues, validateBlockSizeValues, validateAspectRatioValues, validateStyleValues, validateCustomFeatures, } = defaultContainerQueryValidation;
187
+ export { defaultContainerQueryValidation };
@@ -1,4 +1,5 @@
1
- import { type UnitCategory, type UnitDefinition, type UnitDefinitionRecord, type UnitHelperName } from './unitDefinitions';
1
+ import { type UnitCategory, type UnitDefinition, type UnitDefinitionRecord } from './unitDefinitions';
2
+ import { type ErrorConfig, type ErrorCode } from './internal/errors';
2
3
  type UnitSymbol = UnitDefinitionRecord[keyof UnitDefinitionRecord]['unit'];
3
4
  export type MeasurementString<Unit extends string = UnitSymbol> = `${number}${Unit}`;
4
5
  type UnitBrand<Unit extends string> = {
@@ -16,8 +17,8 @@ export interface IMeasurement<Unit extends string = string> {
16
17
  assert: (predicate: (measurement: IMeasurement<Unit>) => boolean, message: string) => void;
17
18
  equals: (other: IMeasurement<string>) => boolean;
18
19
  compare: (other: IMeasurement<string>) => number;
19
- add: (delta: DeltaInput) => IMeasurement<Unit>;
20
- subtract: (delta: DeltaInput) => IMeasurement<Unit>;
20
+ add: (delta: number | IMeasurement<string>) => IMeasurement<Unit>;
21
+ subtract: (delta: number | IMeasurement<string>) => IMeasurement<Unit>;
21
22
  multiply: (factor: number) => IMeasurement<Unit>;
22
23
  divide: (divisor: number) => IMeasurement<Unit>;
23
24
  double: () => IMeasurement<Unit>;
@@ -29,18 +30,28 @@ export interface IMeasurement<Unit extends string = string> {
29
30
  ceil: () => IMeasurement<Unit>;
30
31
  clamp: (min: IMeasurement<string>, max: IMeasurement<string>) => IMeasurement<Unit>;
31
32
  }
32
- type DeltaInput = number | IMeasurement<string>;
33
- export declare function assertMatchingUnits<Unit extends string>(left: IMeasurement<Unit>, right: IMeasurement<Unit>, context: string): void;
34
- export declare const isMeasurement: (x: unknown) => x is IMeasurement<string>;
35
- export declare function m(value: number): BrandedMeasurement<'px'>;
36
- export declare function m<Unit extends string>(value: number, unit: Unit): IMeasurement<Lowercase<Unit>> & UnitBrand<Lowercase<Unit>>;
37
33
  export type BrandedMeasurement<Unit extends string> = IMeasurement<Unit> & UnitBrand<Unit>;
38
- export type UnitHelper<Unit extends string = string> = ((value: number) => BrandedMeasurement<Unit>) & {
34
+ export type UnitHelper<Unit extends string = string> = ((value: number, context?: string) => BrandedMeasurement<Unit>) & {
39
35
  unit: Unit;
40
36
  };
41
- export declare const makeUnitHelper: <Unit extends string>(unit: Unit) => UnitHelper<Unit>;
42
- export declare const makeUnitHelperFromDefinition: <Name extends UnitHelperName>(name: Name) => UnitHelper<UnitDefinitionRecord[Name]["unit"]>;
43
- export declare const measurementUnitMetadata: {
37
+ export type MeasurementOf<T extends UnitHelper> = ReturnType<T>;
38
+ export type UnitGuard<T extends UnitHelper> = (value: unknown) => value is MeasurementOf<T>;
39
+ export type UnitAssertion<T extends UnitHelper> = (value: unknown, context?: string) => asserts value is MeasurementOf<T>;
40
+ export declare const m: {
41
+ (value: number): BrandedMeasurement<"px">;
42
+ (value: number, options: {
43
+ context?: string;
44
+ }): BrandedMeasurement<"px">;
45
+ <Unit extends string>(value: number, unit: Unit, context?: string): IMeasurement<Lowercase<Unit>> & {
46
+ readonly __unitBrand: Lowercase<Unit>;
47
+ };
48
+ <Unit extends string>(value: number, options: {
49
+ unit?: Unit | undefined;
50
+ context?: string;
51
+ }): IMeasurement<Lowercase<Unit>> & {
52
+ readonly __unitBrand: Lowercase<Unit>;
53
+ };
54
+ }, isMeasurement: (x: unknown) => x is IMeasurement<string>, assertMatchingUnits: <Unit extends string>(left: IMeasurement<Unit>, right: IMeasurement<Unit>, context: string) => void, measurementMin: <Unit extends string>(a: IMeasurement<Unit>, b: IMeasurement<Unit>) => IMeasurement<Unit>, measurementMax: <Unit extends string>(a: IMeasurement<Unit>, b: IMeasurement<Unit>) => IMeasurement<Unit>, measurementUnitMetadata: {
44
55
  readonly mPercent: {
45
56
  readonly unit: "%";
46
57
  readonly category: "percent";
@@ -289,20 +300,10 @@ export declare const measurementUnitMetadata: {
289
300
  readonly unit: "fr";
290
301
  readonly category: "flex";
291
302
  };
292
- };
303
+ }, makeUnitHelper: <Unit extends string>(unit: Unit) => UnitHelper<Unit>, makeUnitHelperFromDefinition: <Name extends import("./unitDefinitions").UnitHelperName>(name: Name) => UnitHelper<UnitDefinitionRecord[Name]["unit"]>, makeUnitGuard: <T extends UnitHelper>(helper: T) => UnitGuard<T>, makeUnitAssert: <T extends UnitHelper>(helper: T) => UnitAssertion<T>, hasCssMethod: (x: unknown) => x is {
304
+ css: () => string;
305
+ }, assertUnit: <Unit extends string>(measurement: IMeasurement<Unit>, expectedUnit: string, context?: string) => void, assertCondition: (condition: boolean | (() => boolean), message: string) => void, getErrorConfig: () => Required<ErrorConfig>, setErrorConfig: (next: ErrorConfig) => void;
293
306
  export type MeasurementUnitDefinition = UnitDefinition;
294
307
  export type MeasurementUnitCategory = UnitCategory;
295
- export type MeasurementOf<T extends UnitHelper> = ReturnType<T>;
296
- export type UnitGuard<T extends UnitHelper> = (value: unknown) => value is MeasurementOf<T>;
297
- export type UnitAssertion<T extends UnitHelper> = (value: unknown, context?: string) => asserts value is MeasurementOf<T>;
298
- export declare const makeUnitGuard: <T extends UnitHelper>(helper: T) => UnitGuard<T>;
299
- export declare const makeUnitAssert: <T extends UnitHelper>(helper: T) => UnitAssertion<T>;
300
- export declare const hasCssMethod: (x: unknown) => x is {
301
- css: () => string;
302
- };
303
- export declare const measurementMin: <Unit extends string>(a: IMeasurement<Unit>, b: IMeasurement<Unit>) => IMeasurement<Unit>;
304
- export declare const measurementMax: <Unit extends string>(a: IMeasurement<Unit>, b: IMeasurement<Unit>) => IMeasurement<Unit>;
305
- export declare const assertUnit: <Unit extends string>(measurement: IMeasurement<Unit>, expectedUnit: string, context?: string) => void;
306
- export declare const assertCondition: (condition: boolean | (() => boolean), message: string) => void;
307
- export {};
308
+ export { type ErrorConfig, type ErrorCode };
308
309
  //# sourceMappingURL=core.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAM3B,KAAK,UAAU,GAAG,oBAAoB,CAAC,MAAM,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3E,MAAM,MAAM,iBAAiB,CAAC,IAAI,SAAS,MAAM,GAAG,UAAU,IAC5D,GAAG,MAAM,GAAG,IAAI,EAAE,CAAC;AAErB,KAAK,SAAS,CAAC,IAAI,SAAS,MAAM,IAAI;IAAE,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAA;CAAE,CAAC;AAErE,MAAM,WAAW,YAAY,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IACxD,GAAG,EAAE,MAAM,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,MAAM,CAAC;IACvB,O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;;;;;;;;;;;GAnBt1K,aAAa,6CACb,mBAAmB,uGACnB,cAAc,6FACd,cAAc,6FACd,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GACvB,cAAc,yDACd,4BAA4B,sFAaiiQ,0BAA0B,WAZvlQ,aAAa,qDACb,cAAc,yDACd,YAAY;;GACZ,UAAU,0GACV,eAAe,mEACf,cAAc,+BACd,cAAc,6BACL,CAAC;AAEZ,MAAM,MAAM,yBAAyB,GAAG,cAAc,CAAC;AACvD,MAAM,MAAM,uBAAuB,GAAG,YAAY,CAAC;AACnD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,CAAC"}
package/dist/esm/core.js CHANGED
@@ -1,266 +1,5 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _Measurement_instances, _a, _Measurement_value, _Measurement_unit, _Measurement_clone;
13
- import { UNIT_DEFINITIONS, } from './unitDefinitions';
14
- import { throwHelperError, throwMeasurementMethodError, } from './internal/errors';
15
- export function assertMatchingUnits(left, right, context) {
16
- const leftUnit = left.getUnit();
17
- const rightUnit = right.getUnit();
18
- if (leftUnit !== rightUnit) {
19
- throwHelperError({
20
- operation: 'css-calipers.assertMatchingUnits',
21
- params: [left, right],
22
- message: `measurement unit mismatch: ${leftUnit} vs ${rightUnit}`,
23
- context,
24
- });
25
- }
26
- }
27
- const deltaToNumber = (base, delta) => {
28
- if (typeof delta === 'number')
29
- return delta;
30
- assertMatchingUnits(base, delta, 'deltaToNumber');
31
- return delta.getValue();
32
- };
33
- class Measurement {
34
- constructor(value, unit) {
35
- _Measurement_instances.add(this);
36
- _Measurement_value.set(this, void 0);
37
- _Measurement_unit.set(this, void 0);
38
- if (!Number.isFinite(value)) {
39
- throwHelperError({
40
- operation: 'css-calipers.Measurement.constructor',
41
- params: [],
42
- message: `Non-finite measurement value: ${value}`,
43
- });
44
- }
45
- const normalizedUnit = unit.toLowerCase();
46
- __classPrivateFieldSet(this, _Measurement_value, value, "f");
47
- __classPrivateFieldSet(this, _Measurement_unit, normalizedUnit, "f");
48
- Object.defineProperty(this, '__unitBrand', {
49
- value: normalizedUnit,
50
- enumerable: false,
51
- configurable: false,
52
- writable: false,
53
- });
54
- }
55
- css() {
56
- return `${__classPrivateFieldGet(this, _Measurement_value, "f")}${__classPrivateFieldGet(this, _Measurement_unit, "f")}`;
57
- }
58
- toString() {
59
- return this.css();
60
- }
61
- getUnit() {
62
- return __classPrivateFieldGet(this, _Measurement_unit, "f");
63
- }
64
- getValue() {
65
- return __classPrivateFieldGet(this, _Measurement_value, "f");
66
- }
67
- valueOf() {
68
- return __classPrivateFieldGet(this, _Measurement_value, "f");
69
- }
70
- [(_Measurement_value = new WeakMap(), _Measurement_unit = new WeakMap(), _Measurement_instances = new WeakSet(), Symbol.toPrimitive)](hint) {
71
- if (hint === 'number')
72
- return __classPrivateFieldGet(this, _Measurement_value, "f");
73
- return this.css();
74
- }
75
- isUnit(expected) {
76
- return __classPrivateFieldGet(this, _Measurement_unit, "f") === expected.toLowerCase();
77
- }
78
- assertUnit(expected, context) {
79
- if (!this.isUnit(expected)) {
80
- throwMeasurementMethodError({
81
- operation: 'css-calipers.Measurement.assertUnit',
82
- caller: this,
83
- params: [],
84
- message: `Expected unit "${expected}", received "${__classPrivateFieldGet(this, _Measurement_unit, "f")}".`,
85
- context,
86
- });
87
- }
88
- }
89
- assert(predicate, message) {
90
- if (!predicate(this)) {
91
- throwMeasurementMethodError({
92
- operation: 'css-calipers.Measurement.assert',
93
- caller: this,
94
- params: [],
95
- message,
96
- });
97
- }
98
- }
99
- equals(other, strict = true) {
100
- const otherUnit = other.getUnit();
101
- if (__classPrivateFieldGet(this, _Measurement_unit, "f") !== otherUnit) {
102
- if (strict) {
103
- assertMatchingUnits(this, other, 'equals(strict)');
104
- }
105
- return false;
106
- }
107
- return __classPrivateFieldGet(this, _Measurement_value, "f") === other.getValue();
108
- }
109
- compare(other, strict = true) {
110
- if (strict) {
111
- assertMatchingUnits(this, other, 'compare(strict)');
112
- }
113
- else if (__classPrivateFieldGet(this, _Measurement_unit, "f") !== other.getUnit()) {
114
- return __classPrivateFieldGet(this, _Measurement_unit, "f") < other.getUnit() ? -1 : 1;
115
- }
116
- const diff = __classPrivateFieldGet(this, _Measurement_value, "f") - other.getValue();
117
- if (diff === 0)
118
- return 0;
119
- return diff < 0 ? -1 : 1;
120
- }
121
- add(delta) {
122
- const next = __classPrivateFieldGet(this, _Measurement_value, "f") + deltaToNumber(this, delta);
123
- return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, next);
124
- }
125
- subtract(delta) {
126
- const next = __classPrivateFieldGet(this, _Measurement_value, "f") - deltaToNumber(this, delta);
127
- return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, next);
128
- }
129
- multiply(factor) {
130
- if (factor === 1)
131
- return this;
132
- if (factor === 0)
133
- return new _a(0, __classPrivateFieldGet(this, _Measurement_unit, "f"));
134
- if (factor === -1)
135
- return new _a(-__classPrivateFieldGet(this, _Measurement_value, "f"), __classPrivateFieldGet(this, _Measurement_unit, "f"));
136
- return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, __classPrivateFieldGet(this, _Measurement_value, "f") * factor);
137
- }
138
- divide(divisor) {
139
- if (divisor === 1)
140
- return this;
141
- if (divisor === 0) {
142
- throwMeasurementMethodError({
143
- operation: 'css-calipers.Measurement.divide',
144
- caller: this,
145
- params: [],
146
- message: `Cannot divide ${this.css()} by zero`,
147
- });
148
- }
149
- const result = __classPrivateFieldGet(this, _Measurement_value, "f") / divisor;
150
- if (!Number.isFinite(result)) {
151
- throwMeasurementMethodError({
152
- operation: 'css-calipers.Measurement.divide',
153
- caller: this,
154
- params: [],
155
- message: 'Non-finite result',
156
- });
157
- }
158
- return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, result);
159
- }
160
- double() {
161
- return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, __classPrivateFieldGet(this, _Measurement_value, "f") * 2);
162
- }
163
- half() {
164
- return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, __classPrivateFieldGet(this, _Measurement_value, "f") / 2);
165
- }
166
- negation(shouldNegate = true) {
167
- return shouldNegate ? __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, -__classPrivateFieldGet(this, _Measurement_value, "f")) : this;
168
- }
169
- absolute() {
170
- return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, Math.abs(__classPrivateFieldGet(this, _Measurement_value, "f")));
171
- }
172
- round(precision = 0) {
173
- const next = precision === 0
174
- ? Math.round(__classPrivateFieldGet(this, _Measurement_value, "f"))
175
- : Number(__classPrivateFieldGet(this, _Measurement_value, "f").toFixed(precision));
176
- return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, next);
177
- }
178
- floor() {
179
- return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, Math.floor(__classPrivateFieldGet(this, _Measurement_value, "f")));
180
- }
181
- ceil() {
182
- return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, Math.ceil(__classPrivateFieldGet(this, _Measurement_value, "f")));
183
- }
184
- clamp(min, max) {
185
- assertMatchingUnits(this, min, 'clamp(min)');
186
- assertMatchingUnits(this, max, 'clamp(max)');
187
- const minValue = min.getValue();
188
- const maxValue = max.getValue();
189
- if (!Number.isFinite(minValue) || !Number.isFinite(maxValue)) {
190
- throwMeasurementMethodError({
191
- operation: 'css-calipers.Measurement.clamp',
192
- caller: this,
193
- params: [min, max],
194
- message: 'clamp: expected finite bounds',
195
- });
196
- }
197
- if (minValue > maxValue) {
198
- throwMeasurementMethodError({
199
- operation: 'css-calipers.Measurement.clamp',
200
- caller: this,
201
- params: [min, max],
202
- message: `clamp: min (${min.css()}) must be <= max (${max.css()})`,
203
- });
204
- }
205
- const clamped = Math.min(maxValue, Math.max(minValue, __classPrivateFieldGet(this, _Measurement_value, "f")));
206
- return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, clamped);
207
- }
208
- }
209
- _a = Measurement, _Measurement_clone = function _Measurement_clone(value) {
210
- return new _a(value, __classPrivateFieldGet(this, _Measurement_unit, "f"));
211
- };
212
- const createMeasurement = (value, unit) => new Measurement(value, unit);
213
- export const isMeasurement = (x) => x instanceof Measurement;
214
- export function m(value, unit = 'px') {
215
- return createMeasurement(value, unit.toLowerCase());
216
- }
217
- export const makeUnitHelper = (unit) => {
218
- const normalizedUnit = unit.toLowerCase();
219
- const factory = (value) => createMeasurement(value, normalizedUnit);
220
- return Object.assign(factory, {
221
- unit: normalizedUnit,
222
- });
223
- };
224
- export const makeUnitHelperFromDefinition = (name) => makeUnitHelper(UNIT_DEFINITIONS[name].unit);
225
- export const measurementUnitMetadata = UNIT_DEFINITIONS;
226
- export const makeUnitGuard = (helper) => {
227
- return (value) => isMeasurement(value) && value.isUnit(helper.unit);
228
- };
229
- export const makeUnitAssert = (helper) => {
230
- const guard = makeUnitGuard(helper);
231
- return (value, context) => {
232
- if (!guard(value)) {
233
- throwHelperError({
234
- operation: 'css-calipers.makeUnitAssert',
235
- params: isMeasurement(value) ? [value] : [],
236
- message: `Expected unit "${helper.unit}".`,
237
- context,
238
- });
239
- }
240
- };
241
- };
242
- export const hasCssMethod = (x) => {
243
- return (typeof x === 'object' &&
244
- x !== null &&
245
- 'css' in x &&
246
- typeof x.css === 'function');
247
- };
248
- export const measurementMin = (a, b) => {
249
- assertMatchingUnits(a, b, 'measurementMin');
250
- return a.getValue() <= b.getValue() ? a : b;
251
- };
252
- export const measurementMax = (a, b) => {
253
- assertMatchingUnits(a, b, 'measurementMax');
254
- return a.getValue() >= b.getValue() ? a : b;
255
- };
256
- export const assertUnit = (measurement, expectedUnit, context) => measurement.assertUnit(expectedUnit, context);
257
- export const assertCondition = (condition, message) => {
258
- const passed = typeof condition === 'function' ? condition() : condition;
259
- if (!passed) {
260
- throwHelperError({
261
- operation: 'css-calipers.assertCondition',
262
- params: [],
263
- message,
264
- });
265
- }
266
- };
1
+ import { createCoreApi } from './internal/createCoreApi';
2
+ import { createErrorConfigStore, } from './internal/errors';
3
+ const defaultErrorStore = createErrorConfigStore();
4
+ const coreApi = createCoreApi(defaultErrorStore);
5
+ export const { m, isMeasurement, assertMatchingUnits, measurementMin, measurementMax, measurementUnitMetadata, makeUnitHelper, makeUnitHelperFromDefinition, makeUnitGuard, makeUnitAssert, hasCssMethod, assertUnit, assertCondition, getErrorConfig, setErrorConfig, } = coreApi;
@@ -0,0 +1,13 @@
1
+ import { type ErrorConfig } from './internal/errors';
2
+ import { type CoreApi } from './internal/createCoreApi';
3
+ import { type UnitsApi } from './internal/createUnitsApi';
4
+ import { type MediaQueriesApi } from './internal/createMediaQueriesApi';
5
+ export type CalipersFactoryConfig = {
6
+ errorConfig?: ErrorConfig;
7
+ };
8
+ export type CalipersInstance = CoreApi & UnitsApi & {
9
+ mediaQueries: MediaQueriesApi;
10
+ units: UnitsApi;
11
+ };
12
+ export declare const createCalipers: (config?: CalipersFactoryConfig) => CalipersInstance;
13
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,kCAAkC,CAAC;AAE1C,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,OAAO,GACpC,QAAQ,GAAG;IACT,YAAY,EAAE,eAAe,CAAC;IAC9B,KAAK,EAAE,QAAQ,CAAC;CACjB,CAAC;AAEJ,eAAO,MAAM,cAAc,GACzB,SAAQ,qBAA0B,KACjC,gBAcF,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { createErrorConfigStore } from './internal/errors';
2
+ import { createCoreApi } from './internal/createCoreApi';
3
+ import { createUnitsApi } from './internal/createUnitsApi';
4
+ import { createMediaQueriesApi, } from './internal/createMediaQueriesApi';
5
+ export const createCalipers = (config = {}) => {
6
+ var _a;
7
+ const errorStore = createErrorConfigStore((_a = config.errorConfig) !== null && _a !== void 0 ? _a : {});
8
+ const core = createCoreApi(errorStore);
9
+ const units = createUnitsApi(core);
10
+ const mediaQueries = createMediaQueriesApi(core);
11
+ return {
12
+ ...core,
13
+ ...units,
14
+ mediaQueries,
15
+ units,
16
+ };
17
+ };
@@ -0,0 +1,23 @@
1
+ export interface IFraction {
2
+ css: () => string;
3
+ toString: () => string;
4
+ valueOf: () => number;
5
+ numerator: () => number;
6
+ denominator: () => number;
7
+ withNumerator: (numerator: number) => IFraction;
8
+ withDenominator: (denominator: number) => IFraction;
9
+ }
10
+ export type Fraction = IFraction;
11
+ export type RatioParts = {
12
+ numerator: number;
13
+ denominator: number;
14
+ };
15
+ export declare function r(denominator: number): Fraction;
16
+ export declare function r(numerator: number, denominator: number): Fraction;
17
+ export declare const isFraction: (value: unknown) => value is IFraction;
18
+ export declare const parseRatio: (value: number | string | IFraction) => RatioParts | null;
19
+ export declare const normalizeFraction: (fraction: IFraction) => IFraction;
20
+ export declare const reduceFraction: (fraction: IFraction) => IFraction;
21
+ export declare const simplifyFraction: (fraction: IFraction) => IFraction;
22
+ export declare const fractionToFloat: (fraction: IFraction) => number;
23
+ //# sourceMappingURL=fraction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fraction.d.ts","sourceRoot":"","sources":["../../src/fraction.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,SAAS,CAAC;IAChD,eAAe,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,SAAS,CAAC;CACrD;AAED,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC;AAEjC,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAwDF,wBAAgB,CAAC,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC;AACjD,wBAAgB,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC;AAUpE,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAWpD,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,SAAS,KAAG,UAAU,GAAG,IAoB5E,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,UAAU,SAAS,KAAG,SAiCvD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,UAAU,SAAS,KAAG,SACxB,CAAC;AAE9B,eAAO,MAAM,gBAAgB,GAAI,UAAU,SAAS,KAAG,SAOtD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,UAAU,SAAS,KAAG,MACP,CAAC"}