css-calipers 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/README.md +100 -0
  2. package/dist/cjs/comparisons/index.js +25 -0
  3. package/dist/cjs/containerQueries/containerQueries.js +115 -0
  4. package/dist/cjs/containerQueries/factory.js +123 -0
  5. package/dist/cjs/containerQueries/helpers.js +95 -0
  6. package/dist/cjs/containerQueries/index.js +16 -0
  7. package/dist/cjs/containerQueries/linting/aspectRatio.js +24 -0
  8. package/dist/cjs/containerQueries/linting/block.js +23 -0
  9. package/dist/cjs/containerQueries/linting/core.js +25 -0
  10. package/dist/cjs/containerQueries/linting/custom.js +11 -0
  11. package/dist/cjs/containerQueries/linting/inline.js +23 -0
  12. package/dist/cjs/containerQueries/linting/resolution.js +12 -0
  13. package/dist/cjs/containerQueries/linting/style.js +28 -0
  14. package/dist/cjs/containerQueries/linting.js +24 -0
  15. package/dist/cjs/containerQueries/moduleRegistry.js +5 -0
  16. package/dist/cjs/containerQueries/modules/aspectRatio.js +51 -0
  17. package/dist/cjs/containerQueries/modules/block.js +53 -0
  18. package/dist/cjs/containerQueries/modules/custom.js +43 -0
  19. package/dist/cjs/containerQueries/modules/index.js +21 -0
  20. package/dist/cjs/containerQueries/modules/inline.js +53 -0
  21. package/dist/cjs/containerQueries/modules/size.js +2 -0
  22. package/dist/cjs/containerQueries/modules/style.js +36 -0
  23. package/dist/cjs/containerQueries/types.js +2 -0
  24. package/dist/cjs/containerQueries/validation.js +191 -0
  25. package/dist/cjs/core.js +5 -278
  26. package/dist/cjs/factory.js +21 -0
  27. package/dist/cjs/fraction.js +139 -0
  28. package/dist/cjs/internal/buildMeasurementCreationError.js +16 -0
  29. package/dist/cjs/internal/buildMeasurementCreationError.tests.js +5 -0
  30. package/dist/cjs/internal/createComponentQueriesApi.js +56 -0
  31. package/dist/cjs/internal/createCoreApi.js +336 -0
  32. package/dist/cjs/internal/createMediaQueriesApi.js +74 -0
  33. package/dist/cjs/internal/createUnitsApi.js +18 -0
  34. package/dist/cjs/internal/errors.js +118 -5
  35. package/dist/cjs/internal/normalizeToArray.js +9 -0
  36. package/dist/cjs/libraryHelpers/vanilla-extract.js +6 -2
  37. package/dist/cjs/logicalOperators/index.js +18 -0
  38. package/dist/cjs/mediaQueries/factory.js +5 -4
  39. package/dist/cjs/mediaQueries/mediaQueries.js +7 -5
  40. package/dist/cjs/mediaQueries/modules/dimensions.js +10 -8
  41. package/dist/cjs/mediaQueries/modules/resolution.js +6 -4
  42. package/dist/cjs/mediaQueries/validation.js +128 -116
  43. package/dist/cjs/ratio.js +141 -0
  44. package/dist/cjs/types.js +2 -0
  45. package/dist/cjs/validation.js +20 -0
  46. package/dist/esm/comparisons/index.d.ts +23 -0
  47. package/dist/esm/comparisons/index.d.ts.map +1 -0
  48. package/dist/esm/comparisons/index.js +22 -0
  49. package/dist/esm/containerQueries/containerQueries.d.ts +36 -0
  50. package/dist/esm/containerQueries/containerQueries.d.ts.map +1 -0
  51. package/dist/esm/containerQueries/containerQueries.js +109 -0
  52. package/dist/esm/containerQueries/factory.d.ts +20 -0
  53. package/dist/esm/containerQueries/factory.d.ts.map +1 -0
  54. package/dist/esm/containerQueries/factory.js +119 -0
  55. package/dist/esm/containerQueries/helpers.d.ts +53 -0
  56. package/dist/esm/containerQueries/helpers.d.ts.map +1 -0
  57. package/dist/esm/containerQueries/helpers.js +82 -0
  58. package/dist/esm/containerQueries/index.d.ts +10 -0
  59. package/dist/esm/containerQueries/index.d.ts.map +1 -0
  60. package/dist/esm/containerQueries/index.js +4 -0
  61. package/dist/esm/containerQueries/linting/aspectRatio.d.ts +4 -0
  62. package/dist/esm/containerQueries/linting/aspectRatio.d.ts.map +1 -0
  63. package/dist/esm/containerQueries/linting/aspectRatio.js +19 -0
  64. package/dist/esm/containerQueries/linting/block.d.ts +4 -0
  65. package/dist/esm/containerQueries/linting/block.d.ts.map +1 -0
  66. package/dist/esm/containerQueries/linting/block.js +18 -0
  67. package/dist/esm/containerQueries/linting/core.d.ts +4 -0
  68. package/dist/esm/containerQueries/linting/core.d.ts.map +1 -0
  69. package/dist/esm/containerQueries/linting/core.js +20 -0
  70. package/dist/esm/containerQueries/linting/custom.d.ts +3 -0
  71. package/dist/esm/containerQueries/linting/custom.d.ts.map +1 -0
  72. package/dist/esm/containerQueries/linting/custom.js +7 -0
  73. package/dist/esm/containerQueries/linting/inline.d.ts +4 -0
  74. package/dist/esm/containerQueries/linting/inline.d.ts.map +1 -0
  75. package/dist/esm/containerQueries/linting/inline.js +18 -0
  76. package/dist/esm/containerQueries/linting/resolution.d.ts +1 -0
  77. package/dist/esm/containerQueries/linting/resolution.d.ts.map +1 -0
  78. package/dist/esm/containerQueries/linting/resolution.js +12 -0
  79. package/dist/esm/containerQueries/linting/style.d.ts +3 -0
  80. package/dist/esm/containerQueries/linting/style.d.ts.map +1 -0
  81. package/dist/esm/containerQueries/linting/style.js +24 -0
  82. package/dist/esm/containerQueries/linting.d.ts +4 -0
  83. package/dist/esm/containerQueries/linting.d.ts.map +1 -0
  84. package/dist/esm/containerQueries/linting.js +20 -0
  85. package/dist/esm/containerQueries/moduleRegistry.d.ts +25 -0
  86. package/dist/esm/containerQueries/moduleRegistry.d.ts.map +1 -0
  87. package/dist/esm/containerQueries/moduleRegistry.js +1 -0
  88. package/dist/esm/containerQueries/modules/aspectRatio.d.ts +17 -0
  89. package/dist/esm/containerQueries/modules/aspectRatio.d.ts.map +1 -0
  90. package/dist/esm/containerQueries/modules/aspectRatio.js +47 -0
  91. package/dist/esm/containerQueries/modules/block.d.ts +20 -0
  92. package/dist/esm/containerQueries/modules/block.d.ts.map +1 -0
  93. package/dist/esm/containerQueries/modules/block.js +49 -0
  94. package/dist/esm/containerQueries/modules/custom.d.ts +13 -0
  95. package/dist/esm/containerQueries/modules/custom.d.ts.map +1 -0
  96. package/dist/esm/containerQueries/modules/custom.js +39 -0
  97. package/dist/esm/containerQueries/modules/index.d.ts +6 -0
  98. package/dist/esm/containerQueries/modules/index.d.ts.map +1 -0
  99. package/dist/esm/containerQueries/modules/index.js +5 -0
  100. package/dist/esm/containerQueries/modules/inline.d.ts +20 -0
  101. package/dist/esm/containerQueries/modules/inline.d.ts.map +1 -0
  102. package/dist/esm/containerQueries/modules/inline.js +49 -0
  103. package/dist/esm/containerQueries/modules/size.d.ts +41 -0
  104. package/dist/esm/containerQueries/modules/size.d.ts.map +1 -0
  105. package/dist/esm/containerQueries/modules/size.js +1 -0
  106. package/dist/esm/containerQueries/modules/style.d.ts +11 -0
  107. package/dist/esm/containerQueries/modules/style.d.ts.map +1 -0
  108. package/dist/esm/containerQueries/modules/style.js +32 -0
  109. package/dist/esm/containerQueries/types.d.ts +81 -0
  110. package/dist/esm/containerQueries/types.d.ts.map +1 -0
  111. package/dist/esm/containerQueries/types.js +1 -0
  112. package/dist/esm/containerQueries/validation.d.ts +41 -0
  113. package/dist/esm/containerQueries/validation.d.ts.map +1 -0
  114. package/dist/esm/containerQueries/validation.js +187 -0
  115. package/dist/esm/core.d.ts +27 -26
  116. package/dist/esm/core.d.ts.map +1 -1
  117. package/dist/esm/core.js +5 -266
  118. package/dist/esm/factory.d.ts +13 -0
  119. package/dist/esm/factory.d.ts.map +1 -0
  120. package/dist/esm/factory.js +17 -0
  121. package/dist/esm/fraction.d.ts +23 -0
  122. package/dist/esm/fraction.d.ts.map +1 -0
  123. package/dist/esm/fraction.js +129 -0
  124. package/dist/esm/internal/buildMeasurementCreationError.d.ts +12 -0
  125. package/dist/esm/internal/buildMeasurementCreationError.d.ts.map +1 -0
  126. package/dist/esm/internal/buildMeasurementCreationError.js +12 -0
  127. package/dist/esm/internal/buildMeasurementCreationError.tests.d.ts +3 -0
  128. package/dist/esm/internal/buildMeasurementCreationError.tests.d.ts.map +1 -0
  129. package/dist/esm/internal/buildMeasurementCreationError.tests.js +1 -0
  130. package/dist/esm/internal/createComponentQueriesApi.d.ts +34 -0
  131. package/dist/esm/internal/createComponentQueriesApi.d.ts.map +1 -0
  132. package/dist/esm/internal/createComponentQueriesApi.js +52 -0
  133. package/dist/esm/internal/createCoreApi.d.ts +289 -0
  134. package/dist/esm/internal/createCoreApi.d.ts.map +1 -0
  135. package/dist/esm/internal/createCoreApi.js +332 -0
  136. package/dist/esm/internal/createMediaQueriesApi.d.ts +35 -0
  137. package/dist/esm/internal/createMediaQueriesApi.d.ts.map +1 -0
  138. package/dist/esm/internal/createMediaQueriesApi.js +70 -0
  139. package/dist/esm/internal/createUnitsApi.d.ts +13 -0
  140. package/dist/esm/internal/createUnitsApi.d.ts.map +1 -0
  141. package/dist/esm/internal/createUnitsApi.js +14 -0
  142. package/dist/esm/internal/errors.d.ts +30 -0
  143. package/dist/esm/internal/errors.d.ts.map +1 -1
  144. package/dist/esm/internal/errors.js +113 -4
  145. package/dist/esm/internal/normalizeToArray.d.ts +2 -0
  146. package/dist/esm/internal/normalizeToArray.d.ts.map +1 -0
  147. package/dist/esm/internal/normalizeToArray.js +5 -0
  148. package/dist/esm/libraryHelpers/vanilla-extract.d.ts +2 -1
  149. package/dist/esm/libraryHelpers/vanilla-extract.d.ts.map +1 -1
  150. package/dist/esm/libraryHelpers/vanilla-extract.js +4 -1
  151. package/dist/esm/logicalOperators/index.d.ts +2 -0
  152. package/dist/esm/logicalOperators/index.d.ts.map +1 -0
  153. package/dist/esm/logicalOperators/index.js +17 -0
  154. package/dist/esm/mediaQueries/factory.d.ts +16 -1
  155. package/dist/esm/mediaQueries/factory.d.ts.map +1 -1
  156. package/dist/esm/mediaQueries/factory.js +3 -2
  157. package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts +2 -2
  158. package/dist/esm/mediaQueries/libraryHelpers/vanilla-extract.d.ts.map +1 -1
  159. package/dist/esm/mediaQueries/mediaQueries.d.ts +2 -0
  160. package/dist/esm/mediaQueries/mediaQueries.d.ts.map +1 -1
  161. package/dist/esm/mediaQueries/mediaQueries.js +4 -2
  162. package/dist/esm/mediaQueries/modules/dimensions.d.ts +2 -0
  163. package/dist/esm/mediaQueries/modules/dimensions.d.ts.map +1 -1
  164. package/dist/esm/mediaQueries/modules/dimensions.js +4 -2
  165. package/dist/esm/mediaQueries/modules/resolution.d.ts +2 -0
  166. package/dist/esm/mediaQueries/modules/resolution.d.ts.map +1 -1
  167. package/dist/esm/mediaQueries/modules/resolution.js +4 -2
  168. package/dist/esm/mediaQueries/validation.d.ts +28 -8
  169. package/dist/esm/mediaQueries/validation.d.ts.map +1 -1
  170. package/dist/esm/mediaQueries/validation.js +126 -107
  171. package/dist/esm/package.json +3 -0
  172. package/dist/esm/ratio.d.ts +22 -0
  173. package/dist/esm/ratio.d.ts.map +1 -0
  174. package/dist/esm/ratio.js +131 -0
  175. package/dist/esm/types.d.ts +35 -0
  176. package/dist/esm/types.d.ts.map +1 -0
  177. package/dist/esm/types.js +1 -0
  178. package/dist/esm/validation.d.ts +10 -0
  179. package/dist/esm/validation.d.ts.map +1 -0
  180. package/dist/esm/validation.js +15 -0
  181. package/dist/examples/containerQueries.example.js +54 -0
  182. package/dist/examples/examples/containerQueries.example.js +54 -0
  183. package/dist/examples/examples/factory-wrapper.example.js +33 -0
  184. package/dist/examples/examples/lineHeight-normalizer.example.js +81 -0
  185. package/dist/examples/examples/mediaQueries-multipleInstances.example.js +127 -0
  186. package/dist/examples/examples/mixedQueries.example.js +55 -0
  187. package/dist/examples/examples/validation-and-runtime-checks.example.js +85 -0
  188. package/dist/examples/examples/validation-unit-tests.example.js +35 -0
  189. package/dist/examples/factory-wrapper.example.js +33 -0
  190. package/dist/examples/lineHeight-normalizer.example.js +81 -0
  191. package/dist/examples/mediaQueries-multipleInstances.example.js +127 -0
  192. package/dist/examples/mixedQueries.example.js +60 -0
  193. package/dist/examples/src/comparisons/index.js +25 -0
  194. package/dist/examples/src/containerQueries/containerQueries.js +96 -0
  195. package/dist/examples/src/containerQueries/factory.js +123 -0
  196. package/dist/examples/src/containerQueries/helpers.js +94 -0
  197. package/dist/examples/src/containerQueries/index.js +16 -0
  198. package/dist/examples/src/containerQueries/linting/aspectRatio.js +20 -0
  199. package/dist/examples/src/containerQueries/linting/block.js +20 -0
  200. package/dist/examples/src/containerQueries/linting/core.js +19 -0
  201. package/dist/examples/src/containerQueries/linting/custom.js +11 -0
  202. package/dist/examples/src/containerQueries/linting/inline.js +20 -0
  203. package/dist/examples/src/containerQueries/linting/style.js +28 -0
  204. package/dist/examples/src/containerQueries/linting.js +24 -0
  205. package/dist/examples/src/containerQueries/moduleRegistry.js +5 -0
  206. package/dist/examples/src/containerQueries/modules/aspectRatio.js +33 -0
  207. package/dist/examples/src/containerQueries/modules/block.js +44 -0
  208. package/dist/examples/src/containerQueries/modules/custom.js +31 -0
  209. package/dist/examples/src/containerQueries/modules/index.js +21 -0
  210. package/dist/examples/src/containerQueries/modules/inline.js +44 -0
  211. package/dist/examples/src/containerQueries/modules/style.js +36 -0
  212. package/dist/examples/src/containerQueries/types.js +2 -0
  213. package/dist/examples/src/containerQueries/validation.js +177 -0
  214. package/dist/examples/src/core.js +16 -0
  215. package/dist/examples/src/factory.js +21 -0
  216. package/dist/examples/src/index.js +30 -0
  217. package/dist/examples/src/internal/buildMeasurementCreationError.js +16 -0
  218. package/dist/examples/src/internal/createCoreApi.js +336 -0
  219. package/dist/examples/src/internal/createMediaQueriesApi.js +74 -0
  220. package/dist/examples/src/internal/createUnitsApi.js +18 -0
  221. package/dist/examples/src/internal/errors.js +130 -0
  222. package/dist/examples/src/libraryHelpers/vanilla-extract.js +11 -0
  223. package/dist/examples/src/mediaQueries/factory.js +163 -0
  224. package/dist/examples/src/mediaQueries/helpers.js +88 -0
  225. package/dist/examples/src/mediaQueries/index.js +23 -0
  226. package/dist/examples/src/mediaQueries/linting/core.js +19 -0
  227. package/dist/examples/src/mediaQueries/linting/resolution.js +11 -0
  228. package/dist/examples/src/mediaQueries/linting.js +24 -0
  229. package/dist/examples/src/mediaQueries/mediaQueries.js +53 -0
  230. package/dist/examples/src/mediaQueries/moduleRegistry.js +5 -0
  231. package/dist/examples/src/mediaQueries/modules/custom.js +26 -0
  232. package/dist/examples/src/mediaQueries/modules/dimensions.js +61 -0
  233. package/dist/examples/src/mediaQueries/modules/display.js +20 -0
  234. package/dist/examples/src/mediaQueries/modules/environment.js +20 -0
  235. package/dist/examples/src/mediaQueries/modules/index.js +23 -0
  236. package/dist/examples/src/mediaQueries/modules/interaction.js +26 -0
  237. package/dist/examples/src/mediaQueries/modules/preferences.js +26 -0
  238. package/dist/examples/src/mediaQueries/modules/resolution.js +31 -0
  239. package/dist/examples/src/mediaQueries/types.js +2 -0
  240. package/dist/examples/src/mediaQueries/validation.js +128 -0
  241. package/dist/examples/src/ratio.js +141 -0
  242. package/dist/examples/src/types.js +2 -0
  243. package/dist/examples/src/unitDefinitions.js +67 -0
  244. package/dist/examples/src/units/absolute.js +11 -0
  245. package/dist/examples/src/units/angle.js +8 -0
  246. package/dist/examples/src/units/container.js +10 -0
  247. package/dist/examples/src/units/font-relative.js +16 -0
  248. package/dist/examples/src/units/frequency.js +6 -0
  249. package/dist/examples/src/units/grid.js +5 -0
  250. package/dist/examples/src/units/percent.js +7 -0
  251. package/dist/examples/src/units/resolution.js +7 -0
  252. package/dist/examples/src/units/time.js +6 -0
  253. package/dist/examples/src/units/viewport-dynamic.js +10 -0
  254. package/dist/examples/src/units/viewport-large.js +10 -0
  255. package/dist/examples/src/units/viewport-small.js +10 -0
  256. package/dist/examples/src/units/viewport.js +10 -0
  257. package/dist/examples/src/validation.js +20 -0
  258. package/dist/examples/validation-and-runtime-checks.example.js +85 -0
  259. package/dist/examples/validation-unit-tests.example.js +35 -0
  260. package/package.json +17 -6
@@ -0,0 +1,332 @@
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
+ import { UNIT_DEFINITIONS, } from '../unitDefinitions';
13
+ import { buildMeasurementCreationError } from './buildMeasurementCreationError';
14
+ import { createErrorHelpers, } from './errors';
15
+ export const createCoreApi = (errorStore) => {
16
+ var _Measurement_instances, _a, _Measurement_value, _Measurement_unit, _Measurement_clone;
17
+ const { throwHelperError, throwMeasurementMethodError } = createErrorHelpers(errorStore);
18
+ const assertMatchingUnits = (left, right, context) => {
19
+ const leftUnit = left.getUnit();
20
+ const rightUnit = right.getUnit();
21
+ if (leftUnit !== rightUnit) {
22
+ throwHelperError({
23
+ operation: 'css-calipers.assertMatchingUnits',
24
+ params: [left, right],
25
+ message: `measurement unit mismatch: ${leftUnit} vs ${rightUnit}`,
26
+ context,
27
+ details: { code: 'CALIPERS_E_UNIT_MISMATCH' },
28
+ });
29
+ }
30
+ };
31
+ const deltaToNumber = (base, delta) => {
32
+ if (typeof delta === 'number')
33
+ return delta;
34
+ assertMatchingUnits(base, delta, 'deltaToNumber');
35
+ return delta.getValue();
36
+ };
37
+ class Measurement {
38
+ constructor(value, unit) {
39
+ _Measurement_instances.add(this);
40
+ _Measurement_value.set(this, void 0);
41
+ _Measurement_unit.set(this, void 0);
42
+ if (!Number.isFinite(value)) {
43
+ throwHelperError({
44
+ operation: 'css-calipers.Measurement.constructor',
45
+ params: [],
46
+ message: `Non-finite measurement value: ${value}`,
47
+ details: { code: 'CALIPERS_E_NONFINITE' },
48
+ });
49
+ }
50
+ const normalizedUnit = unit.toLowerCase();
51
+ __classPrivateFieldSet(this, _Measurement_value, value, "f");
52
+ __classPrivateFieldSet(this, _Measurement_unit, normalizedUnit, "f");
53
+ Object.defineProperty(this, '__unitBrand', {
54
+ value: normalizedUnit,
55
+ enumerable: false,
56
+ configurable: false,
57
+ writable: false,
58
+ });
59
+ }
60
+ css() {
61
+ return `${__classPrivateFieldGet(this, _Measurement_value, "f")}${__classPrivateFieldGet(this, _Measurement_unit, "f")}`;
62
+ }
63
+ toString() {
64
+ return this.css();
65
+ }
66
+ getUnit() {
67
+ return __classPrivateFieldGet(this, _Measurement_unit, "f");
68
+ }
69
+ getValue() {
70
+ return __classPrivateFieldGet(this, _Measurement_value, "f");
71
+ }
72
+ valueOf() {
73
+ return __classPrivateFieldGet(this, _Measurement_value, "f");
74
+ }
75
+ [(_Measurement_value = new WeakMap(), _Measurement_unit = new WeakMap(), _Measurement_instances = new WeakSet(), Symbol.toPrimitive)](hint) {
76
+ if (hint === 'number')
77
+ return __classPrivateFieldGet(this, _Measurement_value, "f");
78
+ return this.css();
79
+ }
80
+ isUnit(expected) {
81
+ return __classPrivateFieldGet(this, _Measurement_unit, "f") === expected.toLowerCase();
82
+ }
83
+ assertUnit(expected, context) {
84
+ if (!this.isUnit(expected)) {
85
+ throwMeasurementMethodError({
86
+ operation: 'css-calipers.Measurement.assertUnit',
87
+ caller: this,
88
+ params: [],
89
+ message: `Expected unit "${expected}", received "${__classPrivateFieldGet(this, _Measurement_unit, "f")}".`,
90
+ context,
91
+ details: { code: 'CALIPERS_E_ASSERT_UNIT' },
92
+ });
93
+ }
94
+ }
95
+ assert(predicate, message) {
96
+ if (!predicate(this)) {
97
+ throwMeasurementMethodError({
98
+ operation: 'css-calipers.Measurement.assert',
99
+ caller: this,
100
+ params: [],
101
+ message,
102
+ details: { code: 'CALIPERS_E_ASSERT_PREDICATE' },
103
+ });
104
+ }
105
+ }
106
+ equals(other, strict = true) {
107
+ const otherUnit = other.getUnit();
108
+ if (__classPrivateFieldGet(this, _Measurement_unit, "f") !== otherUnit) {
109
+ if (strict) {
110
+ assertMatchingUnits(this, other, 'equals(strict)');
111
+ }
112
+ return false;
113
+ }
114
+ return __classPrivateFieldGet(this, _Measurement_value, "f") === other.getValue();
115
+ }
116
+ compare(other, strict = true) {
117
+ if (strict) {
118
+ assertMatchingUnits(this, other, 'compare(strict)');
119
+ }
120
+ else if (__classPrivateFieldGet(this, _Measurement_unit, "f") !== other.getUnit()) {
121
+ return __classPrivateFieldGet(this, _Measurement_unit, "f") < other.getUnit() ? -1 : 1;
122
+ }
123
+ const diff = __classPrivateFieldGet(this, _Measurement_value, "f") - other.getValue();
124
+ if (diff === 0)
125
+ return 0;
126
+ return diff < 0 ? -1 : 1;
127
+ }
128
+ add(delta) {
129
+ const next = __classPrivateFieldGet(this, _Measurement_value, "f") + deltaToNumber(this, delta);
130
+ return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, next);
131
+ }
132
+ subtract(delta) {
133
+ const next = __classPrivateFieldGet(this, _Measurement_value, "f") - deltaToNumber(this, delta);
134
+ return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, next);
135
+ }
136
+ multiply(factor) {
137
+ if (factor === 1)
138
+ return this;
139
+ if (factor === 0)
140
+ return new _a(0, __classPrivateFieldGet(this, _Measurement_unit, "f"));
141
+ if (factor === -1)
142
+ return new _a(-__classPrivateFieldGet(this, _Measurement_value, "f"), __classPrivateFieldGet(this, _Measurement_unit, "f"));
143
+ return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, __classPrivateFieldGet(this, _Measurement_value, "f") * factor);
144
+ }
145
+ divide(divisor) {
146
+ if (divisor === 1)
147
+ return this;
148
+ if (divisor === 0) {
149
+ throwMeasurementMethodError({
150
+ operation: 'css-calipers.Measurement.divide',
151
+ caller: this,
152
+ params: [],
153
+ message: `Cannot divide ${this.css()} by zero`,
154
+ details: { code: 'CALIPERS_E_DIVIDE_BY_ZERO' },
155
+ });
156
+ }
157
+ const result = __classPrivateFieldGet(this, _Measurement_value, "f") / divisor;
158
+ if (!Number.isFinite(result)) {
159
+ throwMeasurementMethodError({
160
+ operation: 'css-calipers.Measurement.divide',
161
+ caller: this,
162
+ params: [],
163
+ message: 'Non-finite result',
164
+ details: { code: 'CALIPERS_E_NONFINITE_RESULT' },
165
+ });
166
+ }
167
+ return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, result);
168
+ }
169
+ double() {
170
+ return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, __classPrivateFieldGet(this, _Measurement_value, "f") * 2);
171
+ }
172
+ half() {
173
+ return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, __classPrivateFieldGet(this, _Measurement_value, "f") / 2);
174
+ }
175
+ negation(shouldNegate = true) {
176
+ return shouldNegate ? __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, -__classPrivateFieldGet(this, _Measurement_value, "f")) : this;
177
+ }
178
+ absolute() {
179
+ return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, Math.abs(__classPrivateFieldGet(this, _Measurement_value, "f")));
180
+ }
181
+ round(precision = 0) {
182
+ const next = precision === 0
183
+ ? Math.round(__classPrivateFieldGet(this, _Measurement_value, "f"))
184
+ : Number(__classPrivateFieldGet(this, _Measurement_value, "f").toFixed(precision));
185
+ return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, next);
186
+ }
187
+ floor() {
188
+ return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, Math.floor(__classPrivateFieldGet(this, _Measurement_value, "f")));
189
+ }
190
+ ceil() {
191
+ return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, Math.ceil(__classPrivateFieldGet(this, _Measurement_value, "f")));
192
+ }
193
+ clamp(min, max) {
194
+ assertMatchingUnits(this, min, 'clamp(min)');
195
+ assertMatchingUnits(this, max, 'clamp(max)');
196
+ const minValue = min.getValue();
197
+ const maxValue = max.getValue();
198
+ if (!Number.isFinite(minValue) || !Number.isFinite(maxValue)) {
199
+ throwMeasurementMethodError({
200
+ operation: 'css-calipers.Measurement.clamp',
201
+ caller: this,
202
+ params: [min, max],
203
+ message: 'clamp: expected finite bounds',
204
+ details: { code: 'CALIPERS_E_CLAMP_NONFINITE_BOUNDS' },
205
+ });
206
+ }
207
+ if (minValue > maxValue) {
208
+ throwMeasurementMethodError({
209
+ operation: 'css-calipers.Measurement.clamp',
210
+ caller: this,
211
+ params: [min, max],
212
+ message: `clamp: min (${min.css()}) must be <= max (${max.css()})`,
213
+ details: { code: 'CALIPERS_E_CLAMP_INVALID_RANGE' },
214
+ });
215
+ }
216
+ const clamped = Math.min(maxValue, Math.max(minValue, __classPrivateFieldGet(this, _Measurement_value, "f")));
217
+ return __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_clone).call(this, clamped);
218
+ }
219
+ }
220
+ _a = Measurement, _Measurement_clone = function _Measurement_clone(value) {
221
+ return new _a(value, __classPrivateFieldGet(this, _Measurement_unit, "f"));
222
+ };
223
+ const createMeasurement = (value, unit) => new Measurement(value, unit);
224
+ const isMeasurement = (x) => x instanceof Measurement;
225
+ function m(value, unitOrOptions = 'px', context) {
226
+ var _b;
227
+ const options = unitOrOptions && typeof unitOrOptions === 'object'
228
+ ? unitOrOptions
229
+ : { unit: unitOrOptions, context };
230
+ const unit = ((_b = options.unit) !== null && _b !== void 0 ? _b : 'px');
231
+ const contextLabel = options.context;
232
+ const normalizedUnit = unit.toLowerCase();
233
+ if (!Number.isFinite(value)) {
234
+ const errorPayload = buildMeasurementCreationError(value, normalizedUnit, 'm', contextLabel);
235
+ throwHelperError({
236
+ operation: 'css-calipers.m',
237
+ params: [],
238
+ message: errorPayload.message,
239
+ context: errorPayload.context,
240
+ details: errorPayload.details,
241
+ includeStackHint: true,
242
+ });
243
+ }
244
+ return createMeasurement(value, normalizedUnit);
245
+ }
246
+ const createUnitHelper = (unit, helperName) => {
247
+ const normalizedUnit = unit.toLowerCase();
248
+ const helperLabel = helperName !== null && helperName !== void 0 ? helperName : `makeUnitHelper(${normalizedUnit})`;
249
+ const factory = (value, context) => {
250
+ if (!Number.isFinite(value)) {
251
+ const errorPayload = buildMeasurementCreationError(value, normalizedUnit, helperLabel, context);
252
+ throwHelperError({
253
+ operation: `css-calipers.${helperLabel}`,
254
+ params: [],
255
+ message: errorPayload.message,
256
+ context: errorPayload.context,
257
+ details: errorPayload.details,
258
+ includeStackHint: true,
259
+ });
260
+ }
261
+ return createMeasurement(value, normalizedUnit);
262
+ };
263
+ return Object.assign(factory, {
264
+ unit: normalizedUnit,
265
+ });
266
+ };
267
+ const makeUnitHelper = (unit) => {
268
+ return createUnitHelper(unit);
269
+ };
270
+ const makeUnitHelperFromDefinition = (name) => createUnitHelper(UNIT_DEFINITIONS[name].unit, name);
271
+ const measurementUnitMetadata = UNIT_DEFINITIONS;
272
+ const makeUnitGuard = (helper) => {
273
+ return (value) => isMeasurement(value) && value.isUnit(helper.unit);
274
+ };
275
+ const makeUnitAssert = (helper) => {
276
+ const guard = makeUnitGuard(helper);
277
+ return (value, context) => {
278
+ if (!guard(value)) {
279
+ throwHelperError({
280
+ operation: 'css-calipers.makeUnitAssert',
281
+ params: isMeasurement(value) ? [value] : [],
282
+ message: `Expected unit "${helper.unit}".`,
283
+ context,
284
+ details: { code: 'CALIPERS_E_ASSERT_UNIT' },
285
+ });
286
+ }
287
+ };
288
+ };
289
+ const hasCssMethod = (x) => {
290
+ return (typeof x === 'object' &&
291
+ x !== null &&
292
+ 'css' in x &&
293
+ typeof x.css === 'function');
294
+ };
295
+ const measurementMin = (a, b) => {
296
+ assertMatchingUnits(a, b, 'measurementMin');
297
+ return a.getValue() <= b.getValue() ? a : b;
298
+ };
299
+ const measurementMax = (a, b) => {
300
+ assertMatchingUnits(a, b, 'measurementMax');
301
+ return a.getValue() >= b.getValue() ? a : b;
302
+ };
303
+ const assertUnit = (measurement, expectedUnit, context) => measurement.assertUnit(expectedUnit, context);
304
+ const assertCondition = (condition, message) => {
305
+ const passed = typeof condition === 'function' ? condition() : condition;
306
+ if (!passed) {
307
+ throwHelperError({
308
+ operation: 'css-calipers.assertCondition',
309
+ params: [],
310
+ message,
311
+ details: { code: 'CALIPERS_E_ASSERT_CONDITION' },
312
+ });
313
+ }
314
+ };
315
+ return {
316
+ m,
317
+ isMeasurement,
318
+ assertMatchingUnits,
319
+ measurementMin,
320
+ measurementMax,
321
+ measurementUnitMetadata,
322
+ makeUnitHelper,
323
+ makeUnitHelperFromDefinition,
324
+ makeUnitGuard,
325
+ makeUnitAssert,
326
+ hasCssMethod,
327
+ assertUnit,
328
+ assertCondition,
329
+ getErrorConfig: errorStore.getErrorConfig,
330
+ setErrorConfig: errorStore.setErrorConfig,
331
+ };
332
+ };
@@ -0,0 +1,35 @@
1
+ import type { CoreApi } from './createCoreApi';
2
+ import type { ComplexStyleRule, StyleRule } from '../mediaQueries/types';
3
+ import { type IMediaQueries, type IMediaQueryProps, type IMediaQueryStyles } from '../mediaQueries/mediaQueries';
4
+ import { type IMediaQueryCustomFeatures, type IMediaQueryDimensions, type IMediaQueryDisplay, type IMediaQueryEnvironment, type IMediaQueryInteraction, type IMediaQueryPreferences } from '../mediaQueries/modules';
5
+ import { type IMediaQueryResolutionRange } from '../mediaQueries/modules/resolution';
6
+ import { type MediaQueryFactoryConfig } from '../mediaQueries/factory';
7
+ import type { MediaQueryBuilderHelpers } from '../mediaQueries/helpers';
8
+ import type { MediaQueryModulesList } from '../mediaQueries/moduleRegistry';
9
+ type MediaQueriesCore = Pick<CoreApi, 'assertCondition' | 'assertMatchingUnits'>;
10
+ export declare const createMediaQueriesApi: (core: MediaQueriesCore) => {
11
+ readonly buildMediaQueryString: (config: IMediaQueryProps) => string;
12
+ readonly makeMediaQueryStyle: <T extends IMediaQueries>(queries: T) => (stylesByQuery: IMediaQueryStyles<T>) => ComplexStyleRule;
13
+ readonly mediaQueryFactory: <TModules extends MediaQueryModulesList | undefined, TQueries extends Record<string, TModules extends MediaQueryModulesList ? (import("../mediaQueries/moduleRegistry").MediaQueryModulePropsMap[TModules[number]] extends infer T ? T extends import("../mediaQueries/moduleRegistry").MediaQueryModulePropsMap[TModules[number]] ? T extends unknown ? (value: T) => void : never : never : never) extends (value: infer R) => void ? R : never : IMediaQueryProps>, TOutput = ComplexStyleRule>(options: {
14
+ queries: TQueries;
15
+ config: MediaQueryFactoryConfig<TModules, TOutput>;
16
+ }) => (stylesByQuery: Partial<Record<keyof TQueries, StyleRule>>) => TOutput;
17
+ readonly emitCoreFeatures: (props: import("../mediaQueries/mediaQueries").IMediaQueryCore, helpers: MediaQueryBuilderHelpers) => void;
18
+ readonly emitDimensionsFeatures: (props: IMediaQueryDimensions, helpers: MediaQueryBuilderHelpers, validate?: import("../mediaQueries/modules").MediaQueryDimensionsValidator) => void;
19
+ readonly emitResolutionFeatures: (props: IMediaQueryResolutionRange, helpers: MediaQueryBuilderHelpers, validate?: import("../mediaQueries/modules").MediaQueryResolutionValidator) => void;
20
+ readonly emitInteractionFeatures: (props: IMediaQueryInteraction, helpers: MediaQueryBuilderHelpers, validate?: import("../mediaQueries/modules").MediaQueryInteractionValidator) => void;
21
+ readonly emitPreferencesFeatures: (props: IMediaQueryPreferences, helpers: MediaQueryBuilderHelpers, validate?: import("../mediaQueries/modules").MediaQueryPreferencesValidator) => void;
22
+ readonly emitDisplayFeatures: (props: IMediaQueryDisplay, helpers: MediaQueryBuilderHelpers, validate?: import("../mediaQueries/modules").MediaQueryDisplayValidator) => void;
23
+ readonly emitEnvironmentFeatures: (props: IMediaQueryEnvironment, helpers: MediaQueryBuilderHelpers, validate?: import("../mediaQueries/modules").MediaQueryEnvironmentValidator) => void;
24
+ readonly emitCustomFeatures: (props: IMediaQueryCustomFeatures, helpers: MediaQueryBuilderHelpers, validate?: import("../mediaQueries/modules").MediaQueryCustomFeaturesValidator) => void;
25
+ readonly mediaQueryOutputVanillaExtract: (media: StyleRule) => import("../mediaQueries/types").SelectorMap;
26
+ readonly createMediaQueryBuilder: <TConfig>(options: {
27
+ emitBase: import("../mediaQueries/helpers").MediaQueryExtensionHandler<TConfig>;
28
+ emitExtensions?: import("../mediaQueries/helpers").MediaQueryExtensionHandler<TConfig> | undefined;
29
+ resolveType?: ((config: TConfig) => "all" | "print" | "screen" | undefined) | undefined;
30
+ config?: import("../mediaQueries/helpers").MediaQueryBuilderConfig;
31
+ }) => (config: TConfig) => string;
32
+ };
33
+ export type MediaQueriesApi = ReturnType<typeof createMediaQueriesApi>;
34
+ export type { IMediaQueries, IMediaQueryProps, IMediaQueryStyles, IMediaQueryCustomFeatures, IMediaQueryDimensions, IMediaQueryResolutionRange, IMediaQueryInteraction, IMediaQueryPreferences, IMediaQueryDisplay, IMediaQueryEnvironment, MediaQueryFactoryConfig, MediaQueryModulesList, };
35
+ //# sourceMappingURL=createMediaQueriesApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMediaQueriesApi.d.ts","sourceRoot":"","sources":["../../../src/internal/createMediaQueriesApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAIzE,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAOL,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAEL,KAAK,uBAAuB,EAE7B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAE5E,KAAK,gBAAgB,GAAG,IAAI,CAC1B,OAAO,EACP,iBAAiB,GAAG,qBAAqB,CAC1C,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,MAAM,gBAAgB;;mCAkCvD,CAAC,SAAS,aAAa,WAAW,CAAC,MACnC,eAAe,iBAAiB,CAAC,CAAC,CAAC,KAAG,gBAAgB;;;;WA+DiuF,yDAA2C;;;;;;;;;;;;;;;WA1D7zF,eAAO;CAyChB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACvE,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,yBAAyB,EACzB,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,GACtB,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { createMediaQueryBuilder } from '../mediaQueries/helpers';
2
+ import { createMediaQueryValidation, } from '../mediaQueries/validation';
3
+ import { createEmitCoreFeatures, } from '../mediaQueries/mediaQueries';
4
+ import { createEmitDimensionsFeatures, emitDisplayFeatures, emitEnvironmentFeatures, emitInteractionFeatures, emitPreferencesFeatures, emitCustomFeatures, } from '../mediaQueries/modules';
5
+ import { createEmitResolutionFeatures, } from '../mediaQueries/modules/resolution';
6
+ import { createMediaQueryFactory, } from '../mediaQueries/factory';
7
+ import { mediaQueryOutputVanillaExtract } from '../mediaQueries/libraryHelpers/vanilla-extract';
8
+ export const createMediaQueriesApi = (core) => {
9
+ const validation = createMediaQueryValidation({
10
+ assertCondition: core.assertCondition,
11
+ assertMatchingUnits: core.assertMatchingUnits,
12
+ });
13
+ const emitCoreFeatures = createEmitCoreFeatures(validation);
14
+ const emitDimensionsFeatures = createEmitDimensionsFeatures(validation);
15
+ const emitResolutionFeatures = createEmitResolutionFeatures(validation);
16
+ const emitBaseFeatures = (props, helpers) => {
17
+ emitCoreFeatures(props, helpers);
18
+ emitDimensionsFeatures(props, helpers);
19
+ emitResolutionFeatures(props, helpers);
20
+ emitInteractionFeatures(props, helpers);
21
+ emitPreferencesFeatures(props, helpers);
22
+ emitDisplayFeatures(props, helpers);
23
+ emitEnvironmentFeatures(props, helpers);
24
+ emitCustomFeatures(props, helpers);
25
+ };
26
+ const buildMediaQueryString = createMediaQueryBuilder({
27
+ emitBase: emitBaseFeatures,
28
+ resolveType: (props) => props.type,
29
+ });
30
+ const makeMediaQueryStyle = (queries) => (stylesByQuery) => {
31
+ const result = {};
32
+ Object.keys(stylesByQuery).forEach((key) => {
33
+ const styles = stylesByQuery[key];
34
+ const props = queries[key];
35
+ if (!styles || !props)
36
+ return;
37
+ result[buildMediaQueryString(props)] = styles;
38
+ });
39
+ const mediaQuery = {
40
+ '@media': result,
41
+ };
42
+ return mediaQuery;
43
+ };
44
+ const moduleEmitters = {
45
+ core: emitCoreFeatures,
46
+ dimensions: emitDimensionsFeatures,
47
+ resolution: emitResolutionFeatures,
48
+ interaction: emitInteractionFeatures,
49
+ preferences: emitPreferencesFeatures,
50
+ display: emitDisplayFeatures,
51
+ environment: emitEnvironmentFeatures,
52
+ custom: emitCustomFeatures,
53
+ };
54
+ const mediaQueryFactory = createMediaQueryFactory(moduleEmitters);
55
+ return {
56
+ buildMediaQueryString,
57
+ makeMediaQueryStyle,
58
+ mediaQueryFactory,
59
+ emitCoreFeatures,
60
+ emitDimensionsFeatures,
61
+ emitResolutionFeatures,
62
+ emitInteractionFeatures,
63
+ emitPreferencesFeatures,
64
+ emitDisplayFeatures,
65
+ emitEnvironmentFeatures,
66
+ emitCustomFeatures,
67
+ mediaQueryOutputVanillaExtract,
68
+ createMediaQueryBuilder,
69
+ };
70
+ };
@@ -0,0 +1,13 @@
1
+ import type { UnitHelper, UnitGuard, UnitAssertion } from '../core';
2
+ import type { UnitDefinitionRecord, UnitHelperName } from '../unitDefinitions';
3
+ import type { CoreApi } from './createCoreApi';
4
+ type UnitHelpersMap = {
5
+ [K in UnitHelperName]: UnitHelper<UnitDefinitionRecord[K]['unit']>;
6
+ };
7
+ export type UnitsApi = UnitHelpersMap & {
8
+ isPercentMeasurement: UnitGuard<UnitHelpersMap['mPercent']>;
9
+ assertPercentMeasurement: UnitAssertion<UnitHelpersMap['mPercent']>;
10
+ };
11
+ export declare const createUnitsApi: (core: CoreApi) => UnitsApi;
12
+ export {};
13
+ //# sourceMappingURL=createUnitsApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createUnitsApi.d.ts","sourceRoot":"","sources":["../../../src/internal/createUnitsApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,KAAK,cAAc,GAAG;KACnB,CAAC,IAAI,cAAc,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;CACnE,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG;IACtC,oBAAoB,EAAE,SAAS,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5D,wBAAwB,EAAE,aAAa,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;CACrE,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,MAAM,OAAO,KAAG,QAmB9C,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { UNIT_DEFINITIONS } from '../unitDefinitions';
2
+ export const createUnitsApi = (core) => {
3
+ const helpers = Object.keys(UNIT_DEFINITIONS).reduce((acc, name) => {
4
+ const helperName = name;
5
+ acc[helperName] = core.makeUnitHelperFromDefinition(helperName);
6
+ return acc;
7
+ }, {});
8
+ const mPercent = helpers.mPercent;
9
+ return {
10
+ ...helpers,
11
+ isPercentMeasurement: core.makeUnitGuard(mPercent),
12
+ assertPercentMeasurement: core.makeUnitAssert(mPercent),
13
+ };
14
+ };
@@ -1,4 +1,19 @@
1
1
  import type { IMeasurement } from "../core";
2
+ export type ErrorCode = "CALIPERS_E_NONFINITE" | "CALIPERS_E_UNIT_MISMATCH" | "CALIPERS_E_ASSERT_UNIT" | "CALIPERS_E_ASSERT_CONDITION" | "CALIPERS_E_ASSERT_PREDICATE" | "CALIPERS_E_DIVIDE_BY_ZERO" | "CALIPERS_E_NONFINITE_RESULT" | "CALIPERS_E_CLAMP_NONFINITE_BOUNDS" | "CALIPERS_E_CLAMP_INVALID_RANGE";
3
+ export interface ErrorDetails {
4
+ code?: ErrorCode;
5
+ helper?: string;
6
+ inputSummary?: string;
7
+ stackHint?: string;
8
+ }
9
+ export type StackHintMode = "auto" | "on" | "off";
10
+ export interface ErrorConfig {
11
+ stackHints?: StackHintMode;
12
+ }
13
+ export type ErrorConfigStore = {
14
+ getErrorConfig: () => Required<ErrorConfig>;
15
+ setErrorConfig: (next: ErrorConfig) => void;
16
+ };
2
17
  export interface MeasurementMethodErrorContext {
3
18
  /** Operation name (for example, "add", "divide", "clamp"). */
4
19
  operation: string;
@@ -10,6 +25,10 @@ export interface MeasurementMethodErrorContext {
10
25
  message: string;
11
26
  /** Optional caller-supplied context prefix. */
12
27
  context?: string;
28
+ /** Optional extra details for error formatting. */
29
+ details?: ErrorDetails;
30
+ /** Override the stack hint config for this error. */
31
+ includeStackHint?: boolean;
13
32
  }
14
33
  export interface HelperErrorContext {
15
34
  /** Operation name (for example, "assertMatchingUnits"). */
@@ -20,7 +39,18 @@ export interface HelperErrorContext {
20
39
  message: string;
21
40
  /** Optional caller-supplied context prefix. */
22
41
  context?: string;
42
+ /** Optional extra details for error formatting. */
43
+ details?: ErrorDetails;
44
+ /** Override the stack hint config for this error. */
45
+ includeStackHint?: boolean;
23
46
  }
47
+ export declare const createErrorConfigStore: (initial?: ErrorConfig) => ErrorConfigStore;
48
+ export declare const setErrorConfig: (next: ErrorConfig) => void;
49
+ export declare const getErrorConfig: () => Required<ErrorConfig>;
50
+ export declare const createErrorHelpers: (store: ErrorConfigStore) => {
51
+ throwMeasurementMethodError: (ctx: MeasurementMethodErrorContext) => never;
52
+ throwHelperError: (ctx: HelperErrorContext) => never;
53
+ };
24
54
  /** Throw an Error for a Measurement instance method using a structured context. */
25
55
  export declare const throwMeasurementMethodError: (ctx: MeasurementMethodErrorContext) => never;
26
56
  /** Throw an Error for a helper/free function using a structured context. */
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/internal/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,WAAW,6BAA6B;IAC5C,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7B,kEAAkE;IAClE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;IAC/B,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,mFAAmF;IACnF,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;IAC/B,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAWD,mFAAmF;AACnF,eAAO,MAAM,2BAA2B,GACtC,KAAK,6BAA6B,KACjC,KAIF,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,GAAI,KAAK,kBAAkB,KAAG,KAI1D,CAAC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/internal/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,MAAM,SAAS,GACjB,sBAAsB,GACtB,0BAA0B,GAC1B,wBAAwB,GACxB,6BAA6B,GAC7B,6BAA6B,GAC7B,2BAA2B,GAC3B,6BAA6B,GAC7B,mCAAmC,GACnC,gCAAgC,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;AAElD,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,aAAa,CAAC;CAC5B;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,cAAc,EAAE,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC5C,cAAc,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;CAC7C,CAAC;AAEF,MAAM,WAAW,6BAA6B;IAC5C,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7B,kEAAkE;IAClE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;IAC/B,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,qDAAqD;IACrD,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,mFAAmF;IACnF,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;IAC/B,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,qDAAqD;IACrD,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAQD,eAAO,MAAM,sBAAsB,GACjC,UAAS,WAAgB,KACxB,gBAWF,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,MAAM,WAAW,KAAG,IAElD,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,QAAQ,CAAC,WAAW,CAAgB,CAAC;AAEvE,eAAO,MAAM,kBAAkB,GAAI,OAAO,gBAAgB;uCAIjD,6BAA6B,KACjC,KAAK;4BAeuB,kBAAkB,KAAG,KAAK;CAgB1D,CAAC;AA4DF,mFAAmF;AACnF,eAAO,MAAM,2BAA2B,GACtC,KAAK,6BAA6B,KACjC,KAWF,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,GAAI,KAAK,kBAAkB,KAAG,KAW1D,CAAC"}
@@ -1,12 +1,121 @@
1
- const formatErrorMessage = (operation, message, context) => {
1
+ const DEFAULT_ERROR_CONFIG = {
2
+ stackHints: "auto",
3
+ };
4
+ let errorConfig = { ...DEFAULT_ERROR_CONFIG };
5
+ export const createErrorConfigStore = (initial = {}) => {
6
+ let config = {
7
+ ...DEFAULT_ERROR_CONFIG,
8
+ ...initial,
9
+ };
10
+ return {
11
+ getErrorConfig: () => config,
12
+ setErrorConfig: (next) => {
13
+ config = { ...config, ...next };
14
+ },
15
+ };
16
+ };
17
+ export const setErrorConfig = (next) => {
18
+ errorConfig = { ...errorConfig, ...next };
19
+ };
20
+ export const getErrorConfig = () => errorConfig;
21
+ export const createErrorHelpers = (store) => {
22
+ const getConfig = () => store.getErrorConfig();
23
+ const throwMeasurementMethodError = (ctx) => {
24
+ const includeStack = shouldIncludeStackHint(ctx.includeStackHint, getConfig());
25
+ const stackHint = includeStack
26
+ ? extractStackHint(new Error().stack)
27
+ : undefined;
28
+ throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context, {
29
+ ...ctx.details,
30
+ stackHint,
31
+ }));
32
+ };
33
+ const throwHelperError = (ctx) => {
34
+ const includeStack = shouldIncludeStackHint(ctx.includeStackHint, getConfig());
35
+ const stackHint = includeStack
36
+ ? extractStackHint(new Error().stack)
37
+ : undefined;
38
+ throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context, {
39
+ ...ctx.details,
40
+ stackHint,
41
+ }));
42
+ };
43
+ return { throwMeasurementMethodError, throwHelperError };
44
+ };
45
+ const isProductionEnv = () => {
46
+ var _a;
47
+ if (typeof globalThis === "undefined")
48
+ return false;
49
+ const maybeProcess = globalThis
50
+ .process;
51
+ return ((_a = maybeProcess === null || maybeProcess === void 0 ? void 0 : maybeProcess.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === "production";
52
+ };
53
+ const shouldIncludeStackHint = (override, config = errorConfig) => {
54
+ if (override === false)
55
+ return false;
56
+ if (config.stackHints === "off")
57
+ return false;
58
+ if (config.stackHints === "on")
59
+ return true;
60
+ if (override === true)
61
+ return !isProductionEnv();
62
+ return false;
63
+ };
64
+ const formatDetailBlock = (details) => {
65
+ if (!details)
66
+ return "";
67
+ const parts = [];
68
+ if (details.code)
69
+ parts.push(`code=${details.code}`);
70
+ if (details.helper)
71
+ parts.push(`helper=${details.helper}`);
72
+ if (details.inputSummary)
73
+ parts.push(`inputs=${details.inputSummary}`);
74
+ if (details.stackHint)
75
+ parts.push(`stack=${details.stackHint}`);
76
+ return parts.length > 0 ? ` [${parts.join(" | ")}]` : "";
77
+ };
78
+ const formatErrorMessage = (operation, message, context, details) => {
2
79
  const core = `${operation}: ${message}`;
3
- return context ? `${context}: ${core}` : core;
80
+ const base = context ? `${context}: ${core}` : core;
81
+ return `${base}${formatDetailBlock(details)}`;
82
+ };
83
+ const extractStackHint = (stack) => {
84
+ var _a;
85
+ if (!stack)
86
+ return undefined;
87
+ const lines = stack
88
+ .split("\n")
89
+ .map((line) => line.trim())
90
+ .filter(Boolean)
91
+ .slice(1);
92
+ if (lines.length === 0)
93
+ return undefined;
94
+ const filtered = lines.filter((line) => !line.includes("/src/internal/errors") &&
95
+ !line.includes("throwHelperError") &&
96
+ !line.includes("throwMeasurementMethodError"));
97
+ const hint = (_a = filtered[0]) !== null && _a !== void 0 ? _a : lines[0];
98
+ return hint.replace(/^at\s+/, "");
4
99
  };
5
100
  /** Throw an Error for a Measurement instance method using a structured context. */
6
101
  export const throwMeasurementMethodError = (ctx) => {
7
- throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context));
102
+ const includeStack = shouldIncludeStackHint(ctx.includeStackHint);
103
+ const stackHint = includeStack
104
+ ? extractStackHint(new Error().stack)
105
+ : undefined;
106
+ throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context, {
107
+ ...ctx.details,
108
+ stackHint,
109
+ }));
8
110
  };
9
111
  /** Throw an Error for a helper/free function using a structured context. */
10
112
  export const throwHelperError = (ctx) => {
11
- throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context));
113
+ const includeStack = shouldIncludeStackHint(ctx.includeStackHint);
114
+ const stackHint = includeStack
115
+ ? extractStackHint(new Error().stack)
116
+ : undefined;
117
+ throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context, {
118
+ ...ctx.details,
119
+ stackHint,
120
+ }));
12
121
  };