css-calipers 0.0.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +1 -1
- package/README.md +334 -0
- package/RELEASING.md +62 -0
- package/dist/cjs/core.js +279 -0
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/internal/errors.js +17 -0
- package/dist/cjs/unitDefinitions.js +67 -0
- package/dist/cjs/units/absolute.js +11 -0
- package/dist/cjs/units/angle.js +8 -0
- package/dist/cjs/units/container.js +10 -0
- package/dist/cjs/units/font-relative.js +16 -0
- package/dist/cjs/units/frequency.js +6 -0
- package/dist/cjs/units/grid.js +5 -0
- package/dist/cjs/units/percent.js +7 -0
- package/dist/cjs/units/resolution.js +7 -0
- package/dist/cjs/units/time.js +6 -0
- package/dist/cjs/units/viewport-dynamic.js +10 -0
- package/dist/cjs/units/viewport-large.js +10 -0
- package/dist/cjs/units/viewport-small.js +10 -0
- package/dist/cjs/units/viewport.js +10 -0
- package/dist/esm/core.d.ts +307 -0
- package/dist/esm/core.d.ts.map +1 -0
- package/dist/esm/core.js +264 -0
- package/dist/esm/index.d.ts +15 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/internal/errors.d.ts +28 -0
- package/dist/esm/internal/errors.d.ts.map +1 -0
- package/dist/esm/internal/errors.js +12 -0
- package/dist/esm/unitDefinitions.d.ts +259 -0
- package/dist/esm/unitDefinitions.d.ts.map +1 -0
- package/dist/esm/unitDefinitions.js +64 -0
- package/dist/esm/units/absolute.d.ts +16 -0
- package/dist/esm/units/absolute.d.ts.map +1 -0
- package/dist/esm/units/absolute.js +8 -0
- package/dist/esm/units/angle.d.ts +10 -0
- package/dist/esm/units/angle.d.ts.map +1 -0
- package/dist/esm/units/angle.js +5 -0
- package/dist/esm/units/container.d.ts +14 -0
- package/dist/esm/units/container.d.ts.map +1 -0
- package/dist/esm/units/container.js +7 -0
- package/dist/esm/units/font-relative.d.ts +26 -0
- package/dist/esm/units/font-relative.d.ts.map +1 -0
- package/dist/esm/units/font-relative.js +13 -0
- package/dist/esm/units/frequency.d.ts +6 -0
- package/dist/esm/units/frequency.d.ts.map +1 -0
- package/dist/esm/units/frequency.js +3 -0
- package/dist/esm/units/grid.d.ts +4 -0
- package/dist/esm/units/grid.d.ts.map +1 -0
- package/dist/esm/units/grid.js +2 -0
- package/dist/esm/units/percent.d.ts +6 -0
- package/dist/esm/units/percent.d.ts.map +1 -0
- package/dist/esm/units/percent.js +4 -0
- package/dist/esm/units/resolution.d.ts +8 -0
- package/dist/esm/units/resolution.d.ts.map +1 -0
- package/dist/esm/units/resolution.js +4 -0
- package/dist/esm/units/time.d.ts +6 -0
- package/dist/esm/units/time.d.ts.map +1 -0
- package/dist/esm/units/time.js +3 -0
- package/dist/esm/units/viewport-dynamic.d.ts +14 -0
- package/dist/esm/units/viewport-dynamic.d.ts.map +1 -0
- package/dist/esm/units/viewport-dynamic.js +7 -0
- package/dist/esm/units/viewport-large.d.ts +14 -0
- package/dist/esm/units/viewport-large.d.ts.map +1 -0
- package/dist/esm/units/viewport-large.js +7 -0
- package/dist/esm/units/viewport-small.d.ts +14 -0
- package/dist/esm/units/viewport-small.d.ts.map +1 -0
- package/dist/esm/units/viewport-small.js +7 -0
- package/dist/esm/units/viewport.d.ts +14 -0
- package/dist/esm/units/viewport.d.ts.map +1 -0
- package/dist/esm/units/viewport.js +7 -0
- package/package.json +49 -7
- package/README.txt +0 -21
package/dist/esm/core.js
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
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 const m = (value, unit = 'px') => createMeasurement(value, unit.toLowerCase());
|
|
215
|
+
export const makeUnitHelper = (unit) => {
|
|
216
|
+
const normalizedUnit = unit.toLowerCase();
|
|
217
|
+
const factory = (value) => createMeasurement(value, normalizedUnit);
|
|
218
|
+
return Object.assign(factory, {
|
|
219
|
+
unit: normalizedUnit,
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
export const makeUnitHelperFromDefinition = (name) => makeUnitHelper(UNIT_DEFINITIONS[name].unit);
|
|
223
|
+
export const measurementUnitMetadata = UNIT_DEFINITIONS;
|
|
224
|
+
export const makeUnitGuard = (helper) => {
|
|
225
|
+
return (value) => isMeasurement(value) && value.isUnit(helper.unit);
|
|
226
|
+
};
|
|
227
|
+
export const makeUnitAssert = (helper) => {
|
|
228
|
+
const guard = makeUnitGuard(helper);
|
|
229
|
+
return (value, context) => {
|
|
230
|
+
if (!guard(value)) {
|
|
231
|
+
throwHelperError({
|
|
232
|
+
operation: 'css-calipers.makeUnitAssert',
|
|
233
|
+
params: isMeasurement(value) ? [value] : [],
|
|
234
|
+
message: `Expected unit "${helper.unit}".`,
|
|
235
|
+
context,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
export const hasCssMethod = (x) => {
|
|
241
|
+
return (typeof x === 'object' &&
|
|
242
|
+
x !== null &&
|
|
243
|
+
'css' in x &&
|
|
244
|
+
typeof x.css === 'function');
|
|
245
|
+
};
|
|
246
|
+
export const measurementMin = (a, b) => {
|
|
247
|
+
assertMatchingUnits(a, b, 'measurementMin');
|
|
248
|
+
return a.getValue() <= b.getValue() ? a : b;
|
|
249
|
+
};
|
|
250
|
+
export const measurementMax = (a, b) => {
|
|
251
|
+
assertMatchingUnits(a, b, 'measurementMax');
|
|
252
|
+
return a.getValue() >= b.getValue() ? a : b;
|
|
253
|
+
};
|
|
254
|
+
export const assertUnit = (measurement, expectedUnit, context) => measurement.assertUnit(expectedUnit, context);
|
|
255
|
+
export const assertCondition = (condition, message) => {
|
|
256
|
+
const passed = typeof condition === 'function' ? condition() : condition;
|
|
257
|
+
if (!passed) {
|
|
258
|
+
throwHelperError({
|
|
259
|
+
operation: 'css-calipers.assertCondition',
|
|
260
|
+
params: [],
|
|
261
|
+
message,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './units/percent';
|
|
3
|
+
export * from './units/absolute';
|
|
4
|
+
export * from './units/font-relative';
|
|
5
|
+
export * from './units/viewport';
|
|
6
|
+
export * from './units/viewport-small';
|
|
7
|
+
export * from './units/viewport-large';
|
|
8
|
+
export * from './units/viewport-dynamic';
|
|
9
|
+
export * from './units/container';
|
|
10
|
+
export * from './units/angle';
|
|
11
|
+
export * from './units/time';
|
|
12
|
+
export * from './units/frequency';
|
|
13
|
+
export * from './units/resolution';
|
|
14
|
+
export * from './units/grid';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AAEvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './units/percent';
|
|
3
|
+
export * from './units/absolute';
|
|
4
|
+
export * from './units/font-relative';
|
|
5
|
+
export * from './units/viewport';
|
|
6
|
+
export * from './units/viewport-small';
|
|
7
|
+
export * from './units/viewport-large';
|
|
8
|
+
export * from './units/viewport-dynamic';
|
|
9
|
+
export * from './units/container';
|
|
10
|
+
export * from './units/angle';
|
|
11
|
+
export * from './units/time';
|
|
12
|
+
export * from './units/frequency';
|
|
13
|
+
export * from './units/resolution';
|
|
14
|
+
export * from './units/grid';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IMeasurement } from "../core";
|
|
2
|
+
export interface MeasurementMethodErrorContext {
|
|
3
|
+
/** Operation name (for example, "add", "divide", "clamp"). */
|
|
4
|
+
operation: string;
|
|
5
|
+
/** Receiver of the method call. */
|
|
6
|
+
caller: IMeasurement<string>;
|
|
7
|
+
/** Other measurements involved (for example, delta, min, max). */
|
|
8
|
+
params: IMeasurement<string>[];
|
|
9
|
+
/** Core human-readable description of what went wrong. */
|
|
10
|
+
message: string;
|
|
11
|
+
/** Optional caller-supplied context prefix. */
|
|
12
|
+
context?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface HelperErrorContext {
|
|
15
|
+
/** Operation name (for example, "assertMatchingUnits"). */
|
|
16
|
+
operation: string;
|
|
17
|
+
/** Measurements involved in the helper call (for example, left/right, min/max). */
|
|
18
|
+
params: IMeasurement<string>[];
|
|
19
|
+
/** Core human-readable description of what went wrong. */
|
|
20
|
+
message: string;
|
|
21
|
+
/** Optional caller-supplied context prefix. */
|
|
22
|
+
context?: string;
|
|
23
|
+
}
|
|
24
|
+
/** Throw an Error for a Measurement instance method using a structured context. */
|
|
25
|
+
export declare const throwMeasurementMethodError: (ctx: MeasurementMethodErrorContext) => never;
|
|
26
|
+
/** Throw an Error for a helper/free function using a structured context. */
|
|
27
|
+
export declare const throwHelperError: (ctx: HelperErrorContext) => never;
|
|
28
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const formatErrorMessage = (operation, message, context) => {
|
|
2
|
+
const core = `${operation}: ${message}`;
|
|
3
|
+
return context ? `${context}: ${core}` : core;
|
|
4
|
+
};
|
|
5
|
+
/** Throw an Error for a Measurement instance method using a structured context. */
|
|
6
|
+
export const throwMeasurementMethodError = (ctx) => {
|
|
7
|
+
throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context));
|
|
8
|
+
};
|
|
9
|
+
/** Throw an Error for a helper/free function using a structured context. */
|
|
10
|
+
export const throwHelperError = (ctx) => {
|
|
11
|
+
throw new Error(formatErrorMessage(ctx.operation, ctx.message, ctx.context));
|
|
12
|
+
};
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
export type UnitCategory = 'percent' | 'length-absolute' | 'length-font-relative' | 'length-viewport' | 'length-viewport-small' | 'length-viewport-large' | 'length-viewport-dynamic' | 'length-container' | 'angle' | 'time' | 'frequency' | 'resolution' | 'flex';
|
|
2
|
+
export type UnitDefinition = {
|
|
3
|
+
unit: string;
|
|
4
|
+
category: UnitCategory;
|
|
5
|
+
description?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const UNIT_DEFINITIONS: {
|
|
8
|
+
readonly mPercent: {
|
|
9
|
+
readonly unit: "%";
|
|
10
|
+
readonly category: "percent";
|
|
11
|
+
};
|
|
12
|
+
readonly mPx: {
|
|
13
|
+
readonly unit: "px";
|
|
14
|
+
readonly category: "length-absolute";
|
|
15
|
+
};
|
|
16
|
+
readonly mCm: {
|
|
17
|
+
readonly unit: "cm";
|
|
18
|
+
readonly category: "length-absolute";
|
|
19
|
+
};
|
|
20
|
+
readonly mMm: {
|
|
21
|
+
readonly unit: "mm";
|
|
22
|
+
readonly category: "length-absolute";
|
|
23
|
+
};
|
|
24
|
+
readonly mQ: {
|
|
25
|
+
readonly unit: "q";
|
|
26
|
+
readonly category: "length-absolute";
|
|
27
|
+
};
|
|
28
|
+
readonly mIn: {
|
|
29
|
+
readonly unit: "in";
|
|
30
|
+
readonly category: "length-absolute";
|
|
31
|
+
};
|
|
32
|
+
readonly mPc: {
|
|
33
|
+
readonly unit: "pc";
|
|
34
|
+
readonly category: "length-absolute";
|
|
35
|
+
};
|
|
36
|
+
readonly mPt: {
|
|
37
|
+
readonly unit: "pt";
|
|
38
|
+
readonly category: "length-absolute";
|
|
39
|
+
};
|
|
40
|
+
readonly mEm: {
|
|
41
|
+
readonly unit: "em";
|
|
42
|
+
readonly category: "length-font-relative";
|
|
43
|
+
};
|
|
44
|
+
readonly mRem: {
|
|
45
|
+
readonly unit: "rem";
|
|
46
|
+
readonly category: "length-font-relative";
|
|
47
|
+
};
|
|
48
|
+
readonly mEx: {
|
|
49
|
+
readonly unit: "ex";
|
|
50
|
+
readonly category: "length-font-relative";
|
|
51
|
+
};
|
|
52
|
+
readonly mRex: {
|
|
53
|
+
readonly unit: "rex";
|
|
54
|
+
readonly category: "length-font-relative";
|
|
55
|
+
};
|
|
56
|
+
readonly mCh: {
|
|
57
|
+
readonly unit: "ch";
|
|
58
|
+
readonly category: "length-font-relative";
|
|
59
|
+
};
|
|
60
|
+
readonly mRch: {
|
|
61
|
+
readonly unit: "rch";
|
|
62
|
+
readonly category: "length-font-relative";
|
|
63
|
+
};
|
|
64
|
+
readonly mCap: {
|
|
65
|
+
readonly unit: "cap";
|
|
66
|
+
readonly category: "length-font-relative";
|
|
67
|
+
};
|
|
68
|
+
readonly mRcap: {
|
|
69
|
+
readonly unit: "rcap";
|
|
70
|
+
readonly category: "length-font-relative";
|
|
71
|
+
};
|
|
72
|
+
readonly mIc: {
|
|
73
|
+
readonly unit: "ic";
|
|
74
|
+
readonly category: "length-font-relative";
|
|
75
|
+
};
|
|
76
|
+
readonly mRic: {
|
|
77
|
+
readonly unit: "ric";
|
|
78
|
+
readonly category: "length-font-relative";
|
|
79
|
+
};
|
|
80
|
+
readonly mLh: {
|
|
81
|
+
readonly unit: "lh";
|
|
82
|
+
readonly category: "length-font-relative";
|
|
83
|
+
};
|
|
84
|
+
readonly mRlh: {
|
|
85
|
+
readonly unit: "rlh";
|
|
86
|
+
readonly category: "length-font-relative";
|
|
87
|
+
};
|
|
88
|
+
readonly mVw: {
|
|
89
|
+
readonly unit: "vw";
|
|
90
|
+
readonly category: "length-viewport";
|
|
91
|
+
};
|
|
92
|
+
readonly mVh: {
|
|
93
|
+
readonly unit: "vh";
|
|
94
|
+
readonly category: "length-viewport";
|
|
95
|
+
};
|
|
96
|
+
readonly mVi: {
|
|
97
|
+
readonly unit: "vi";
|
|
98
|
+
readonly category: "length-viewport";
|
|
99
|
+
};
|
|
100
|
+
readonly mVb: {
|
|
101
|
+
readonly unit: "vb";
|
|
102
|
+
readonly category: "length-viewport";
|
|
103
|
+
};
|
|
104
|
+
readonly mVmin: {
|
|
105
|
+
readonly unit: "vmin";
|
|
106
|
+
readonly category: "length-viewport";
|
|
107
|
+
};
|
|
108
|
+
readonly mVmax: {
|
|
109
|
+
readonly unit: "vmax";
|
|
110
|
+
readonly category: "length-viewport";
|
|
111
|
+
};
|
|
112
|
+
readonly mSvw: {
|
|
113
|
+
readonly unit: "svw";
|
|
114
|
+
readonly category: "length-viewport-small";
|
|
115
|
+
};
|
|
116
|
+
readonly mSvh: {
|
|
117
|
+
readonly unit: "svh";
|
|
118
|
+
readonly category: "length-viewport-small";
|
|
119
|
+
};
|
|
120
|
+
readonly mSvi: {
|
|
121
|
+
readonly unit: "svi";
|
|
122
|
+
readonly category: "length-viewport-small";
|
|
123
|
+
};
|
|
124
|
+
readonly mSvb: {
|
|
125
|
+
readonly unit: "svb";
|
|
126
|
+
readonly category: "length-viewport-small";
|
|
127
|
+
};
|
|
128
|
+
readonly mSvmin: {
|
|
129
|
+
readonly unit: "svmin";
|
|
130
|
+
readonly category: "length-viewport-small";
|
|
131
|
+
};
|
|
132
|
+
readonly mSvmax: {
|
|
133
|
+
readonly unit: "svmax";
|
|
134
|
+
readonly category: "length-viewport-small";
|
|
135
|
+
};
|
|
136
|
+
readonly mLvw: {
|
|
137
|
+
readonly unit: "lvw";
|
|
138
|
+
readonly category: "length-viewport-large";
|
|
139
|
+
};
|
|
140
|
+
readonly mLvh: {
|
|
141
|
+
readonly unit: "lvh";
|
|
142
|
+
readonly category: "length-viewport-large";
|
|
143
|
+
};
|
|
144
|
+
readonly mLvi: {
|
|
145
|
+
readonly unit: "lvi";
|
|
146
|
+
readonly category: "length-viewport-large";
|
|
147
|
+
};
|
|
148
|
+
readonly mLvb: {
|
|
149
|
+
readonly unit: "lvb";
|
|
150
|
+
readonly category: "length-viewport-large";
|
|
151
|
+
};
|
|
152
|
+
readonly mLvmin: {
|
|
153
|
+
readonly unit: "lvmin";
|
|
154
|
+
readonly category: "length-viewport-large";
|
|
155
|
+
};
|
|
156
|
+
readonly mLvmax: {
|
|
157
|
+
readonly unit: "lvmax";
|
|
158
|
+
readonly category: "length-viewport-large";
|
|
159
|
+
};
|
|
160
|
+
readonly mDvw: {
|
|
161
|
+
readonly unit: "dvw";
|
|
162
|
+
readonly category: "length-viewport-dynamic";
|
|
163
|
+
};
|
|
164
|
+
readonly mDvh: {
|
|
165
|
+
readonly unit: "dvh";
|
|
166
|
+
readonly category: "length-viewport-dynamic";
|
|
167
|
+
};
|
|
168
|
+
readonly mDvi: {
|
|
169
|
+
readonly unit: "dvi";
|
|
170
|
+
readonly category: "length-viewport-dynamic";
|
|
171
|
+
};
|
|
172
|
+
readonly mDvb: {
|
|
173
|
+
readonly unit: "dvb";
|
|
174
|
+
readonly category: "length-viewport-dynamic";
|
|
175
|
+
};
|
|
176
|
+
readonly mDvmin: {
|
|
177
|
+
readonly unit: "dvmin";
|
|
178
|
+
readonly category: "length-viewport-dynamic";
|
|
179
|
+
};
|
|
180
|
+
readonly mDvmax: {
|
|
181
|
+
readonly unit: "dvmax";
|
|
182
|
+
readonly category: "length-viewport-dynamic";
|
|
183
|
+
};
|
|
184
|
+
readonly mCqw: {
|
|
185
|
+
readonly unit: "cqw";
|
|
186
|
+
readonly category: "length-container";
|
|
187
|
+
};
|
|
188
|
+
readonly mCqh: {
|
|
189
|
+
readonly unit: "cqh";
|
|
190
|
+
readonly category: "length-container";
|
|
191
|
+
};
|
|
192
|
+
readonly mCqi: {
|
|
193
|
+
readonly unit: "cqi";
|
|
194
|
+
readonly category: "length-container";
|
|
195
|
+
};
|
|
196
|
+
readonly mCqb: {
|
|
197
|
+
readonly unit: "cqb";
|
|
198
|
+
readonly category: "length-container";
|
|
199
|
+
};
|
|
200
|
+
readonly mCqmin: {
|
|
201
|
+
readonly unit: "cqmin";
|
|
202
|
+
readonly category: "length-container";
|
|
203
|
+
};
|
|
204
|
+
readonly mCqmax: {
|
|
205
|
+
readonly unit: "cqmax";
|
|
206
|
+
readonly category: "length-container";
|
|
207
|
+
};
|
|
208
|
+
readonly mDeg: {
|
|
209
|
+
readonly unit: "deg";
|
|
210
|
+
readonly category: "angle";
|
|
211
|
+
};
|
|
212
|
+
readonly mRad: {
|
|
213
|
+
readonly unit: "rad";
|
|
214
|
+
readonly category: "angle";
|
|
215
|
+
};
|
|
216
|
+
readonly mGrad: {
|
|
217
|
+
readonly unit: "grad";
|
|
218
|
+
readonly category: "angle";
|
|
219
|
+
};
|
|
220
|
+
readonly mTurn: {
|
|
221
|
+
readonly unit: "turn";
|
|
222
|
+
readonly category: "angle";
|
|
223
|
+
};
|
|
224
|
+
readonly mS: {
|
|
225
|
+
readonly unit: "s";
|
|
226
|
+
readonly category: "time";
|
|
227
|
+
};
|
|
228
|
+
readonly mMs: {
|
|
229
|
+
readonly unit: "ms";
|
|
230
|
+
readonly category: "time";
|
|
231
|
+
};
|
|
232
|
+
readonly mHz: {
|
|
233
|
+
readonly unit: "hz";
|
|
234
|
+
readonly category: "frequency";
|
|
235
|
+
};
|
|
236
|
+
readonly mKhz: {
|
|
237
|
+
readonly unit: "khz";
|
|
238
|
+
readonly category: "frequency";
|
|
239
|
+
};
|
|
240
|
+
readonly mDpi: {
|
|
241
|
+
readonly unit: "dpi";
|
|
242
|
+
readonly category: "resolution";
|
|
243
|
+
};
|
|
244
|
+
readonly mDpcm: {
|
|
245
|
+
readonly unit: "dpcm";
|
|
246
|
+
readonly category: "resolution";
|
|
247
|
+
};
|
|
248
|
+
readonly mDppx: {
|
|
249
|
+
readonly unit: "dppx";
|
|
250
|
+
readonly category: "resolution";
|
|
251
|
+
};
|
|
252
|
+
readonly mFr: {
|
|
253
|
+
readonly unit: "fr";
|
|
254
|
+
readonly category: "flex";
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
export type UnitDefinitionRecord = typeof UNIT_DEFINITIONS;
|
|
258
|
+
export type UnitHelperName = keyof UnitDefinitionRecord;
|
|
259
|
+
//# sourceMappingURL=unitDefinitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unitDefinitions.d.ts","sourceRoot":"","sources":["../../src/unitDefinitions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,iBAAiB,GACjB,sBAAsB,GACtB,iBAAiB,GACjB,uBAAuB,GACvB,uBAAuB,GACvB,yBAAyB,GACzB,kBAAkB,GAClB,OAAO,GACP,MAAM,GACN,WAAW,GACX,YAAY,GACZ,MAAM,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2EsB,CAAC;AAEpD,MAAM,MAAM,oBAAoB,GAAG,OAAO,gBAAgB,CAAC;AAC3D,MAAM,MAAM,cAAc,GAAG,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const UNIT_DEFINITIONS = {
|
|
2
|
+
mPercent: { unit: '%', category: 'percent' },
|
|
3
|
+
mPx: { unit: 'px', category: 'length-absolute' },
|
|
4
|
+
mCm: { unit: 'cm', category: 'length-absolute' },
|
|
5
|
+
mMm: { unit: 'mm', category: 'length-absolute' },
|
|
6
|
+
mQ: { unit: 'q', category: 'length-absolute' },
|
|
7
|
+
mIn: { unit: 'in', category: 'length-absolute' },
|
|
8
|
+
mPc: { unit: 'pc', category: 'length-absolute' },
|
|
9
|
+
mPt: { unit: 'pt', category: 'length-absolute' },
|
|
10
|
+
mEm: { unit: 'em', category: 'length-font-relative' },
|
|
11
|
+
mRem: { unit: 'rem', category: 'length-font-relative' },
|
|
12
|
+
mEx: { unit: 'ex', category: 'length-font-relative' },
|
|
13
|
+
mRex: { unit: 'rex', category: 'length-font-relative' },
|
|
14
|
+
mCh: { unit: 'ch', category: 'length-font-relative' },
|
|
15
|
+
mRch: { unit: 'rch', category: 'length-font-relative' },
|
|
16
|
+
mCap: { unit: 'cap', category: 'length-font-relative' },
|
|
17
|
+
mRcap: { unit: 'rcap', category: 'length-font-relative' },
|
|
18
|
+
mIc: { unit: 'ic', category: 'length-font-relative' },
|
|
19
|
+
mRic: { unit: 'ric', category: 'length-font-relative' },
|
|
20
|
+
mLh: { unit: 'lh', category: 'length-font-relative' },
|
|
21
|
+
mRlh: { unit: 'rlh', category: 'length-font-relative' },
|
|
22
|
+
mVw: { unit: 'vw', category: 'length-viewport' },
|
|
23
|
+
mVh: { unit: 'vh', category: 'length-viewport' },
|
|
24
|
+
mVi: { unit: 'vi', category: 'length-viewport' },
|
|
25
|
+
mVb: { unit: 'vb', category: 'length-viewport' },
|
|
26
|
+
mVmin: { unit: 'vmin', category: 'length-viewport' },
|
|
27
|
+
mVmax: { unit: 'vmax', category: 'length-viewport' },
|
|
28
|
+
mSvw: { unit: 'svw', category: 'length-viewport-small' },
|
|
29
|
+
mSvh: { unit: 'svh', category: 'length-viewport-small' },
|
|
30
|
+
mSvi: { unit: 'svi', category: 'length-viewport-small' },
|
|
31
|
+
mSvb: { unit: 'svb', category: 'length-viewport-small' },
|
|
32
|
+
mSvmin: { unit: 'svmin', category: 'length-viewport-small' },
|
|
33
|
+
mSvmax: { unit: 'svmax', category: 'length-viewport-small' },
|
|
34
|
+
mLvw: { unit: 'lvw', category: 'length-viewport-large' },
|
|
35
|
+
mLvh: { unit: 'lvh', category: 'length-viewport-large' },
|
|
36
|
+
mLvi: { unit: 'lvi', category: 'length-viewport-large' },
|
|
37
|
+
mLvb: { unit: 'lvb', category: 'length-viewport-large' },
|
|
38
|
+
mLvmin: { unit: 'lvmin', category: 'length-viewport-large' },
|
|
39
|
+
mLvmax: { unit: 'lvmax', category: 'length-viewport-large' },
|
|
40
|
+
mDvw: { unit: 'dvw', category: 'length-viewport-dynamic' },
|
|
41
|
+
mDvh: { unit: 'dvh', category: 'length-viewport-dynamic' },
|
|
42
|
+
mDvi: { unit: 'dvi', category: 'length-viewport-dynamic' },
|
|
43
|
+
mDvb: { unit: 'dvb', category: 'length-viewport-dynamic' },
|
|
44
|
+
mDvmin: { unit: 'dvmin', category: 'length-viewport-dynamic' },
|
|
45
|
+
mDvmax: { unit: 'dvmax', category: 'length-viewport-dynamic' },
|
|
46
|
+
mCqw: { unit: 'cqw', category: 'length-container' },
|
|
47
|
+
mCqh: { unit: 'cqh', category: 'length-container' },
|
|
48
|
+
mCqi: { unit: 'cqi', category: 'length-container' },
|
|
49
|
+
mCqb: { unit: 'cqb', category: 'length-container' },
|
|
50
|
+
mCqmin: { unit: 'cqmin', category: 'length-container' },
|
|
51
|
+
mCqmax: { unit: 'cqmax', category: 'length-container' },
|
|
52
|
+
mDeg: { unit: 'deg', category: 'angle' },
|
|
53
|
+
mRad: { unit: 'rad', category: 'angle' },
|
|
54
|
+
mGrad: { unit: 'grad', category: 'angle' },
|
|
55
|
+
mTurn: { unit: 'turn', category: 'angle' },
|
|
56
|
+
mS: { unit: 's', category: 'time' },
|
|
57
|
+
mMs: { unit: 'ms', category: 'time' },
|
|
58
|
+
mHz: { unit: 'hz', category: 'frequency' },
|
|
59
|
+
mKhz: { unit: 'khz', category: 'frequency' },
|
|
60
|
+
mDpi: { unit: 'dpi', category: 'resolution' },
|
|
61
|
+
mDpcm: { unit: 'dpcm', category: 'resolution' },
|
|
62
|
+
mDppx: { unit: 'dppx', category: 'resolution' },
|
|
63
|
+
mFr: { unit: 'fr', category: 'flex' },
|
|
64
|
+
};
|