@attrx/role-morphic 0.1.0 → 0.2.1

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.
@@ -0,0 +1,2148 @@
1
+ // src/roles/area/constants.ts
2
+ var AREA_UNITS = {
3
+ // SI Units (todos exatos)
4
+ square_kilometer: {
5
+ factor: 1e6,
6
+ symbol: "km\xB2",
7
+ singular: "square kilometer",
8
+ plural: "square kilometers"
9
+ },
10
+ hectare: {
11
+ factor: 1e4,
12
+ symbol: "ha",
13
+ singular: "hectare",
14
+ plural: "hectares"
15
+ },
16
+ are: {
17
+ factor: 100,
18
+ symbol: "a",
19
+ singular: "are",
20
+ plural: "ares"
21
+ },
22
+ square_meter: {
23
+ factor: 1,
24
+ symbol: "m\xB2",
25
+ singular: "square meter",
26
+ plural: "square meters"
27
+ },
28
+ square_decimeter: {
29
+ factor: 0.01,
30
+ symbol: "dm\xB2",
31
+ singular: "square decimeter",
32
+ plural: "square decimeters"
33
+ },
34
+ square_centimeter: {
35
+ factor: 1e-4,
36
+ symbol: "cm\xB2",
37
+ singular: "square centimeter",
38
+ plural: "square centimeters"
39
+ },
40
+ square_millimeter: {
41
+ factor: 1e-6,
42
+ symbol: "mm\xB2",
43
+ singular: "square millimeter",
44
+ plural: "square millimeters"
45
+ },
46
+ // Imperial/US (todos exatos, derivados de comprimento² desde 1959)
47
+ square_mile: {
48
+ factor: 2589988110336e-6,
49
+ symbol: "mi\xB2",
50
+ singular: "square mile",
51
+ plural: "square miles"
52
+ },
53
+ acre: {
54
+ factor: 4046.8564224,
55
+ symbol: "ac",
56
+ singular: "acre",
57
+ plural: "acres"
58
+ },
59
+ square_yard: {
60
+ factor: 0.83612736,
61
+ symbol: "yd\xB2",
62
+ singular: "square yard",
63
+ plural: "square yards"
64
+ },
65
+ square_foot: {
66
+ factor: 0.09290304,
67
+ symbol: "ft\xB2",
68
+ singular: "square foot",
69
+ plural: "square feet"
70
+ },
71
+ square_inch: {
72
+ factor: 64516e-8,
73
+ symbol: "in\xB2",
74
+ singular: "square inch",
75
+ plural: "square inches"
76
+ }
77
+ };
78
+ Object.fromEntries(
79
+ Object.entries(AREA_UNITS).map(([unit, config]) => [
80
+ unit,
81
+ config.factor ?? 1
82
+ ])
83
+ );
84
+
85
+ // src/roles/area/convert.ts
86
+ var AREA_BASE = "square_meter";
87
+ function toBaseArea(variant, value) {
88
+ const unit = AREA_UNITS[variant];
89
+ if (!unit) {
90
+ throw new Error(`Unknown area variant: ${variant}`);
91
+ }
92
+ return value * (unit.factor ?? 1);
93
+ }
94
+ function fromBaseArea(variant, baseValue) {
95
+ const unit = AREA_UNITS[variant];
96
+ if (!unit) {
97
+ throw new Error(`Unknown area variant: ${variant}`);
98
+ }
99
+ return baseValue / (unit.factor ?? 1);
100
+ }
101
+ function convertArea(from, to, value) {
102
+ if (from === to) {
103
+ return value;
104
+ }
105
+ const baseValue = toBaseArea(from, value);
106
+ return fromBaseArea(to, baseValue);
107
+ }
108
+ function tryConvertArea(from, to, value) {
109
+ try {
110
+ const result = convertArea(from, to, value);
111
+ return { ok: true, value: result };
112
+ } catch (err) {
113
+ return { ok: false, error: String(err) };
114
+ }
115
+ }
116
+ function hasAreaVariant(variant) {
117
+ return variant in AREA_UNITS;
118
+ }
119
+ function getAreaVariants() {
120
+ return Object.keys(AREA_UNITS);
121
+ }
122
+
123
+ // src/roles/length/constants.ts
124
+ var LENGTH_UNITS = {
125
+ // SI Units (todos exatos)
126
+ kilometer: {
127
+ factor: 1e3,
128
+ symbol: "km",
129
+ singular: "kilometer",
130
+ plural: "kilometers"
131
+ },
132
+ hectometer: {
133
+ factor: 100,
134
+ symbol: "hm",
135
+ singular: "hectometer",
136
+ plural: "hectometers"
137
+ },
138
+ decameter: {
139
+ factor: 10,
140
+ symbol: "dam",
141
+ singular: "decameter",
142
+ plural: "decameters"
143
+ },
144
+ meter: {
145
+ factor: 1,
146
+ symbol: "m",
147
+ singular: "meter",
148
+ plural: "meters"
149
+ },
150
+ decimeter: {
151
+ factor: 0.1,
152
+ symbol: "dm",
153
+ singular: "decimeter",
154
+ plural: "decimeters"
155
+ },
156
+ centimeter: {
157
+ factor: 0.01,
158
+ symbol: "cm",
159
+ singular: "centimeter",
160
+ plural: "centimeters"
161
+ },
162
+ millimeter: {
163
+ factor: 1e-3,
164
+ symbol: "mm",
165
+ singular: "millimeter",
166
+ plural: "millimeters"
167
+ },
168
+ micrometer: {
169
+ factor: 1e-6,
170
+ symbol: "\u03BCm",
171
+ singular: "micrometer",
172
+ plural: "micrometers"
173
+ },
174
+ nanometer: {
175
+ factor: 1e-9,
176
+ symbol: "nm",
177
+ singular: "nanometer",
178
+ plural: "nanometers"
179
+ },
180
+ // Imperial/US (exatos desde 1959)
181
+ inch: {
182
+ factor: 0.0254,
183
+ symbol: "in",
184
+ singular: "inch",
185
+ plural: "inches"
186
+ },
187
+ foot: {
188
+ factor: 0.3048,
189
+ symbol: "ft",
190
+ singular: "foot",
191
+ plural: "feet"
192
+ },
193
+ yard: {
194
+ factor: 0.9144,
195
+ symbol: "yd",
196
+ singular: "yard",
197
+ plural: "yards"
198
+ },
199
+ mile: {
200
+ factor: 1609.344,
201
+ symbol: "mi",
202
+ singular: "mile",
203
+ plural: "miles"
204
+ },
205
+ // Nautical (exato por definição internacional)
206
+ nautical_mile: {
207
+ factor: 1852,
208
+ symbol: "nmi",
209
+ singular: "nautical mile",
210
+ plural: "nautical miles"
211
+ },
212
+ // Other (derivados, portanto exatos)
213
+ fathom: {
214
+ factor: 1.8288,
215
+ // 6 feet
216
+ symbol: "ftm",
217
+ singular: "fathom",
218
+ plural: "fathoms"
219
+ },
220
+ furlong: {
221
+ factor: 201.168,
222
+ // 660 feet = 1/8 mile
223
+ symbol: "fur",
224
+ singular: "furlong",
225
+ plural: "furlongs"
226
+ },
227
+ league: {
228
+ factor: 4828.032,
229
+ // 3 miles
230
+ symbol: "lea",
231
+ singular: "league",
232
+ plural: "leagues"
233
+ }
234
+ };
235
+ Object.fromEntries(
236
+ Object.entries(LENGTH_UNITS).map(([unit, config]) => [
237
+ unit,
238
+ config.factor ?? 1
239
+ ])
240
+ );
241
+
242
+ // src/roles/length/convert.ts
243
+ var LENGTH_BASE = "meter";
244
+ function toBaseLength(variant, value) {
245
+ const unit = LENGTH_UNITS[variant];
246
+ if (!unit) {
247
+ throw new Error(`Unknown length variant: ${variant}`);
248
+ }
249
+ return value * (unit.factor ?? 1);
250
+ }
251
+ function fromBaseLength(variant, baseValue) {
252
+ const unit = LENGTH_UNITS[variant];
253
+ if (!unit) {
254
+ throw new Error(`Unknown length variant: ${variant}`);
255
+ }
256
+ return baseValue / (unit.factor ?? 1);
257
+ }
258
+ function convertLength(from, to, value) {
259
+ if (from === to) {
260
+ return value;
261
+ }
262
+ const baseValue = toBaseLength(from, value);
263
+ return fromBaseLength(to, baseValue);
264
+ }
265
+ function tryConvertLength(from, to, value) {
266
+ try {
267
+ const result = convertLength(from, to, value);
268
+ return { ok: true, value: result };
269
+ } catch (err) {
270
+ return { ok: false, error: String(err) };
271
+ }
272
+ }
273
+ function hasLengthVariant(variant) {
274
+ return variant in LENGTH_UNITS;
275
+ }
276
+ function getLengthVariants() {
277
+ return Object.keys(LENGTH_UNITS);
278
+ }
279
+
280
+ // src/roles/mass/constants.ts
281
+ var MASS_UNITS = {
282
+ // ===========================================================================
283
+ // SI / Metric
284
+ // ===========================================================================
285
+ metric_ton: {
286
+ factor: 1e3,
287
+ symbol: "t",
288
+ singular: "metric ton",
289
+ plural: "metric tons"
290
+ },
291
+ kilogram: {
292
+ factor: 1,
293
+ symbol: "kg",
294
+ singular: "kilogram",
295
+ plural: "kilograms"
296
+ },
297
+ hectogram: {
298
+ factor: 0.1,
299
+ symbol: "hg",
300
+ singular: "hectogram",
301
+ plural: "hectograms"
302
+ },
303
+ decagram: {
304
+ factor: 0.01,
305
+ symbol: "dag",
306
+ singular: "decagram",
307
+ plural: "decagrams"
308
+ },
309
+ gram: {
310
+ factor: 1e-3,
311
+ symbol: "g",
312
+ singular: "gram",
313
+ plural: "grams"
314
+ },
315
+ decigram: {
316
+ factor: 1e-4,
317
+ symbol: "dg",
318
+ singular: "decigram",
319
+ plural: "decigrams"
320
+ },
321
+ centigram: {
322
+ factor: 1e-5,
323
+ symbol: "cg",
324
+ singular: "centigram",
325
+ plural: "centigrams"
326
+ },
327
+ milligram: {
328
+ factor: 1e-6,
329
+ symbol: "mg",
330
+ singular: "milligram",
331
+ plural: "milligrams"
332
+ },
333
+ microgram: {
334
+ factor: 1e-9,
335
+ symbol: "\u03BCg",
336
+ singular: "microgram",
337
+ plural: "micrograms"
338
+ },
339
+ // ===========================================================================
340
+ // Avoirdupois (US/UK) - Sistema padrão para peso comum
341
+ // ===========================================================================
342
+ long_ton: {
343
+ factor: 1016.0469088,
344
+ // 2240 lb (exato)
345
+ symbol: "long tn",
346
+ singular: "long ton",
347
+ plural: "long tons"
348
+ },
349
+ short_ton: {
350
+ factor: 907.18474,
351
+ // 2000 lb (exato)
352
+ symbol: "sh tn",
353
+ singular: "short ton",
354
+ plural: "short tons"
355
+ },
356
+ stone: {
357
+ factor: 6.35029318,
358
+ // 14 lb (exato)
359
+ symbol: "st",
360
+ singular: "stone",
361
+ plural: "stone"
362
+ // stone não muda no plural em inglês
363
+ },
364
+ pound: {
365
+ factor: 0.45359237,
366
+ // Exato desde 1959
367
+ symbol: "lb",
368
+ singular: "pound",
369
+ plural: "pounds"
370
+ },
371
+ ounce: {
372
+ factor: 0.028349523125,
373
+ // 1/16 lb (exato)
374
+ symbol: "oz",
375
+ singular: "ounce",
376
+ plural: "ounces"
377
+ },
378
+ dram: {
379
+ factor: 0.0017718451953125,
380
+ // 1/16 oz (exato)
381
+ symbol: "dr",
382
+ singular: "dram",
383
+ plural: "drams"
384
+ },
385
+ grain: {
386
+ factor: 6479891e-11,
387
+ // 1/7000 lb (exato)
388
+ symbol: "gr",
389
+ singular: "grain",
390
+ plural: "grains"
391
+ },
392
+ // ===========================================================================
393
+ // Troy (metais preciosos)
394
+ // ===========================================================================
395
+ troy_pound: {
396
+ factor: 0.3732417216,
397
+ // 12 troy oz (exato)
398
+ symbol: "lb t",
399
+ singular: "troy pound",
400
+ plural: "troy pounds"
401
+ },
402
+ troy_ounce: {
403
+ factor: 0.0311034768,
404
+ // 480 grains (exato)
405
+ symbol: "oz t",
406
+ singular: "troy ounce",
407
+ plural: "troy ounces"
408
+ },
409
+ pennyweight: {
410
+ factor: 0.00155517384,
411
+ // 1/20 troy oz (exato)
412
+ symbol: "dwt",
413
+ singular: "pennyweight",
414
+ plural: "pennyweights"
415
+ }
416
+ };
417
+ Object.fromEntries(
418
+ Object.entries(MASS_UNITS).map(([unit, config]) => [
419
+ unit,
420
+ config.factor ?? 1
421
+ ])
422
+ );
423
+
424
+ // src/roles/mass/convert.ts
425
+ var MASS_BASE = "kilogram";
426
+ function toBaseMass(variant, value) {
427
+ const unit = MASS_UNITS[variant];
428
+ if (!unit) {
429
+ throw new Error(`Unknown mass variant: ${variant}`);
430
+ }
431
+ return value * (unit.factor ?? 1);
432
+ }
433
+ function fromBaseMass(variant, baseValue) {
434
+ const unit = MASS_UNITS[variant];
435
+ if (!unit) {
436
+ throw new Error(`Unknown mass variant: ${variant}`);
437
+ }
438
+ return baseValue / (unit.factor ?? 1);
439
+ }
440
+ function convertMass(from, to, value) {
441
+ if (from === to) {
442
+ return value;
443
+ }
444
+ const baseValue = toBaseMass(from, value);
445
+ return fromBaseMass(to, baseValue);
446
+ }
447
+ function tryConvertMass(from, to, value) {
448
+ try {
449
+ const result = convertMass(from, to, value);
450
+ return { ok: true, value: result };
451
+ } catch (err) {
452
+ return { ok: false, error: String(err) };
453
+ }
454
+ }
455
+ function hasMassVariant(variant) {
456
+ return variant in MASS_UNITS;
457
+ }
458
+ function getMassVariants() {
459
+ return Object.keys(MASS_UNITS);
460
+ }
461
+
462
+ // src/roles/temperature/constants.ts
463
+ var TEMPERATURE_UNITS = {
464
+ celsius: {
465
+ symbol: "\xB0C",
466
+ singular: "degree Celsius",
467
+ plural: "degrees Celsius",
468
+ toBase: (c) => c,
469
+ fromBase: (c) => c,
470
+ noSpace: true
471
+ // 25°C não 25 °C
472
+ },
473
+ fahrenheit: {
474
+ symbol: "\xB0F",
475
+ singular: "degree Fahrenheit",
476
+ plural: "degrees Fahrenheit",
477
+ toBase: (f) => (f - 32) * (5 / 9),
478
+ fromBase: (c) => c * (9 / 5) + 32,
479
+ noSpace: true
480
+ // 77°F não 77 °F
481
+ },
482
+ kelvin: {
483
+ symbol: "K",
484
+ singular: "kelvin",
485
+ plural: "kelvins",
486
+ toBase: (k) => k - 273.15,
487
+ fromBase: (c) => c + 273.15
488
+ // Kelvin usa espaço: "273 K" (convenção SI)
489
+ },
490
+ rankine: {
491
+ symbol: "\xB0R",
492
+ singular: "degree Rankine",
493
+ plural: "degrees Rankine",
494
+ toBase: (r) => (r - 491.67) * (5 / 9),
495
+ fromBase: (c) => (c + 273.15) * (9 / 5),
496
+ noSpace: true
497
+ // 500°R não 500 °R
498
+ }
499
+ };
500
+
501
+ // src/roles/temperature/convert.ts
502
+ var TEMPERATURE_BASE = "celsius";
503
+ function toBaseTemperature(variant, value) {
504
+ const unit = TEMPERATURE_UNITS[variant];
505
+ if (!unit) {
506
+ throw new Error(`Unknown temperature variant: ${variant}`);
507
+ }
508
+ if (unit.toBase) {
509
+ return unit.toBase(value);
510
+ }
511
+ return value * (unit.factor ?? 1);
512
+ }
513
+ function fromBaseTemperature(variant, baseValue) {
514
+ const unit = TEMPERATURE_UNITS[variant];
515
+ if (!unit) {
516
+ throw new Error(`Unknown temperature variant: ${variant}`);
517
+ }
518
+ if (unit.fromBase) {
519
+ return unit.fromBase(baseValue);
520
+ }
521
+ return baseValue / (unit.factor ?? 1);
522
+ }
523
+ function convertTemperature(from, to, value) {
524
+ if (from === to) {
525
+ return value;
526
+ }
527
+ const baseValue = toBaseTemperature(from, value);
528
+ return fromBaseTemperature(to, baseValue);
529
+ }
530
+ function tryConvertTemperature(from, to, value) {
531
+ try {
532
+ const result = convertTemperature(from, to, value);
533
+ return { ok: true, value: result };
534
+ } catch (err) {
535
+ return { ok: false, error: String(err) };
536
+ }
537
+ }
538
+ function hasTemperatureVariant(variant) {
539
+ return variant in TEMPERATURE_UNITS;
540
+ }
541
+ function getTemperatureVariants() {
542
+ return Object.keys(TEMPERATURE_UNITS);
543
+ }
544
+
545
+ // src/roles/volume/constants.ts
546
+ var VOLUME_UNITS = {
547
+ // SI / Métrico
548
+ cubic_meter: {
549
+ factor: 1e3,
550
+ symbol: "m\xB3",
551
+ singular: "cubic meter",
552
+ plural: "cubic meters"
553
+ },
554
+ cubic_decimeter: {
555
+ factor: 1,
556
+ symbol: "dm\xB3",
557
+ singular: "cubic decimeter",
558
+ plural: "cubic decimeters"
559
+ },
560
+ cubic_centimeter: {
561
+ factor: 1e-3,
562
+ symbol: "cm\xB3",
563
+ singular: "cubic centimeter",
564
+ plural: "cubic centimeters"
565
+ },
566
+ cubic_millimeter: {
567
+ factor: 1e-6,
568
+ symbol: "mm\xB3",
569
+ singular: "cubic millimeter",
570
+ plural: "cubic millimeters"
571
+ },
572
+ hectoliter: {
573
+ factor: 100,
574
+ symbol: "hL",
575
+ singular: "hectoliter",
576
+ plural: "hectoliters"
577
+ },
578
+ decaliter: {
579
+ factor: 10,
580
+ symbol: "daL",
581
+ singular: "decaliter",
582
+ plural: "decaliters"
583
+ },
584
+ liter: {
585
+ factor: 1,
586
+ symbol: "L",
587
+ singular: "liter",
588
+ plural: "liters"
589
+ },
590
+ deciliter: {
591
+ factor: 0.1,
592
+ symbol: "dL",
593
+ singular: "deciliter",
594
+ plural: "deciliters"
595
+ },
596
+ centiliter: {
597
+ factor: 0.01,
598
+ symbol: "cL",
599
+ singular: "centiliter",
600
+ plural: "centiliters"
601
+ },
602
+ milliliter: {
603
+ factor: 1e-3,
604
+ symbol: "mL",
605
+ singular: "milliliter",
606
+ plural: "milliliters"
607
+ },
608
+ microliter: {
609
+ factor: 1e-6,
610
+ symbol: "\u03BCL",
611
+ singular: "microliter",
612
+ plural: "microliters"
613
+ },
614
+ // US Customary (baseado em 1 gallon = 231 in³ = 3.785411784 L)
615
+ gallon_us: {
616
+ factor: 3.785411784,
617
+ symbol: "gal",
618
+ singular: "gallon",
619
+ plural: "gallons"
620
+ },
621
+ quart_us: {
622
+ factor: 0.946352946,
623
+ // gallon/4
624
+ symbol: "qt",
625
+ singular: "quart",
626
+ plural: "quarts"
627
+ },
628
+ pint_us: {
629
+ factor: 0.473176473,
630
+ // gallon/8
631
+ symbol: "pt",
632
+ singular: "pint",
633
+ plural: "pints"
634
+ },
635
+ cup_us: {
636
+ factor: 0.2365882365,
637
+ // gallon/16
638
+ symbol: "cup",
639
+ singular: "cup",
640
+ plural: "cups"
641
+ },
642
+ fluid_ounce_us: {
643
+ factor: 0.0295735295625,
644
+ // gallon/128
645
+ symbol: "fl oz",
646
+ singular: "fluid ounce",
647
+ plural: "fluid ounces"
648
+ },
649
+ tablespoon_us: {
650
+ factor: 0.01478676478125,
651
+ // fl oz/2
652
+ symbol: "tbsp",
653
+ singular: "tablespoon",
654
+ plural: "tablespoons"
655
+ },
656
+ teaspoon_us: {
657
+ factor: 0.00492892159375,
658
+ // tbsp/3
659
+ symbol: "tsp",
660
+ singular: "teaspoon",
661
+ plural: "teaspoons"
662
+ },
663
+ // Imperial UK (1 gallon UK = 4.54609 L exato)
664
+ gallon_uk: {
665
+ factor: 4.54609,
666
+ symbol: "gal (UK)",
667
+ singular: "gallon (UK)",
668
+ plural: "gallons (UK)"
669
+ },
670
+ quart_uk: {
671
+ factor: 1.1365225,
672
+ // gallon/4
673
+ symbol: "qt (UK)",
674
+ singular: "quart (UK)",
675
+ plural: "quarts (UK)"
676
+ },
677
+ pint_uk: {
678
+ factor: 0.56826125,
679
+ // gallon/8
680
+ symbol: "pt (UK)",
681
+ singular: "pint (UK)",
682
+ plural: "pints (UK)"
683
+ },
684
+ fluid_ounce_uk: {
685
+ factor: 0.0284130625,
686
+ // gallon/160
687
+ symbol: "fl oz (UK)",
688
+ singular: "fluid ounce (UK)",
689
+ plural: "fluid ounces (UK)"
690
+ },
691
+ // Other
692
+ barrel_oil: {
693
+ factor: 158.987294928,
694
+ // 42 US gallons (petroleum)
695
+ symbol: "bbl",
696
+ singular: "barrel",
697
+ plural: "barrels"
698
+ },
699
+ cubic_inch: {
700
+ factor: 0.016387064,
701
+ // (0.0254)³ × 1000
702
+ symbol: "in\xB3",
703
+ singular: "cubic inch",
704
+ plural: "cubic inches"
705
+ },
706
+ cubic_foot: {
707
+ factor: 28.316846592,
708
+ // (0.3048)³ × 1000
709
+ symbol: "ft\xB3",
710
+ singular: "cubic foot",
711
+ plural: "cubic feet"
712
+ },
713
+ cubic_yard: {
714
+ factor: 764.554857984,
715
+ // (0.9144)³ × 1000
716
+ symbol: "yd\xB3",
717
+ singular: "cubic yard",
718
+ plural: "cubic yards"
719
+ }
720
+ };
721
+ Object.fromEntries(
722
+ Object.entries(VOLUME_UNITS).map(([unit, config]) => [
723
+ unit,
724
+ config.factor ?? 1
725
+ ])
726
+ );
727
+
728
+ // src/roles/volume/convert.ts
729
+ var VOLUME_BASE = "liter";
730
+ function toBaseVolume(variant, value) {
731
+ const unit = VOLUME_UNITS[variant];
732
+ if (!unit) {
733
+ throw new Error(`Unknown volume variant: ${variant}`);
734
+ }
735
+ return value * (unit.factor ?? 1);
736
+ }
737
+ function fromBaseVolume(variant, baseValue) {
738
+ const unit = VOLUME_UNITS[variant];
739
+ if (!unit) {
740
+ throw new Error(`Unknown volume variant: ${variant}`);
741
+ }
742
+ return baseValue / (unit.factor ?? 1);
743
+ }
744
+ function convertVolume(from, to, value) {
745
+ if (from === to) {
746
+ return value;
747
+ }
748
+ const baseValue = toBaseVolume(from, value);
749
+ return fromBaseVolume(to, baseValue);
750
+ }
751
+ function tryConvertVolume(from, to, value) {
752
+ try {
753
+ const result = convertVolume(from, to, value);
754
+ return { ok: true, value: result };
755
+ } catch (err) {
756
+ return { ok: false, error: String(err) };
757
+ }
758
+ }
759
+ function hasVolumeVariant(variant) {
760
+ return variant in VOLUME_UNITS;
761
+ }
762
+ function getVolumeVariants() {
763
+ return Object.keys(VOLUME_UNITS);
764
+ }
765
+
766
+ // src/roles/speed/constants.ts
767
+ var SPEED_UNITS = {
768
+ // SI Units
769
+ meter_per_second: {
770
+ factor: 1,
771
+ symbol: "m/s",
772
+ singular: "meter per second",
773
+ plural: "meters per second"
774
+ },
775
+ kilometer_per_hour: {
776
+ factor: 1e3 / 3600,
777
+ // 0.277777...
778
+ symbol: "km/h",
779
+ singular: "kilometer per hour",
780
+ plural: "kilometers per hour"
781
+ },
782
+ // Imperial/US (exatos desde 1959)
783
+ mile_per_hour: {
784
+ factor: 0.44704,
785
+ // 1609.344 / 3600 (exato)
786
+ symbol: "mph",
787
+ singular: "mile per hour",
788
+ plural: "miles per hour"
789
+ },
790
+ foot_per_second: {
791
+ factor: 0.3048,
792
+ // exato
793
+ symbol: "ft/s",
794
+ singular: "foot per second",
795
+ plural: "feet per second"
796
+ },
797
+ // Nautical (exato)
798
+ knot: {
799
+ factor: 1852 / 3600,
800
+ // 0.514444...
801
+ symbol: "kn",
802
+ singular: "knot",
803
+ plural: "knots"
804
+ },
805
+ // Scientific
806
+ mach: {
807
+ factor: 340.29,
808
+ // velocidade do som ao nível do mar, 15°C (aproximado)
809
+ symbol: "Ma",
810
+ singular: "mach",
811
+ plural: "mach"
812
+ },
813
+ speed_of_light: {
814
+ factor: 299792458,
815
+ // exato por definição SI
816
+ symbol: "c",
817
+ singular: "speed of light",
818
+ plural: "speed of light"
819
+ }
820
+ };
821
+ Object.fromEntries(
822
+ Object.entries(SPEED_UNITS).map(([unit, config]) => [
823
+ unit,
824
+ config.factor ?? 1
825
+ ])
826
+ );
827
+
828
+ // src/roles/speed/convert.ts
829
+ var SPEED_BASE = "meter_per_second";
830
+ function toBaseSpeed(variant, value) {
831
+ const unit = SPEED_UNITS[variant];
832
+ if (!unit) {
833
+ throw new Error(`Unknown speed variant: ${variant}`);
834
+ }
835
+ return value * (unit.factor ?? 1);
836
+ }
837
+ function fromBaseSpeed(variant, baseValue) {
838
+ const unit = SPEED_UNITS[variant];
839
+ if (!unit) {
840
+ throw new Error(`Unknown speed variant: ${variant}`);
841
+ }
842
+ return baseValue / (unit.factor ?? 1);
843
+ }
844
+ function convertSpeed(from, to, value) {
845
+ if (from === to) {
846
+ return value;
847
+ }
848
+ const baseValue = toBaseSpeed(from, value);
849
+ return fromBaseSpeed(to, baseValue);
850
+ }
851
+ function tryConvertSpeed(from, to, value) {
852
+ try {
853
+ const result = convertSpeed(from, to, value);
854
+ return { ok: true, value: result };
855
+ } catch (err) {
856
+ return { ok: false, error: String(err) };
857
+ }
858
+ }
859
+ function hasSpeedVariant(variant) {
860
+ return variant in SPEED_UNITS;
861
+ }
862
+ function getSpeedVariants() {
863
+ return Object.keys(SPEED_UNITS);
864
+ }
865
+
866
+ // src/roles/energy/constants.ts
867
+ var ENERGY_UNITS = {
868
+ // SI Units (todos exatos)
869
+ gigajoule: {
870
+ factor: 1e9,
871
+ symbol: "GJ",
872
+ singular: "gigajoule",
873
+ plural: "gigajoules"
874
+ },
875
+ megajoule: {
876
+ factor: 1e6,
877
+ symbol: "MJ",
878
+ singular: "megajoule",
879
+ plural: "megajoules"
880
+ },
881
+ kilojoule: {
882
+ factor: 1e3,
883
+ symbol: "kJ",
884
+ singular: "kilojoule",
885
+ plural: "kilojoules"
886
+ },
887
+ joule: {
888
+ factor: 1,
889
+ symbol: "J",
890
+ singular: "joule",
891
+ plural: "joules"
892
+ },
893
+ millijoule: {
894
+ factor: 1e-3,
895
+ symbol: "mJ",
896
+ singular: "millijoule",
897
+ plural: "millijoules"
898
+ },
899
+ // Calories (International Table - IT)
900
+ // 1 cal (IT) = 4.1868 J (exato por definição)
901
+ calorie: {
902
+ factor: 4.1868,
903
+ symbol: "cal",
904
+ singular: "calorie",
905
+ plural: "calories"
906
+ },
907
+ // 1 kcal = 1000 cal = 4186.8 J (= 1 "food Calorie")
908
+ kilocalorie: {
909
+ factor: 4186.8,
910
+ symbol: "kcal",
911
+ singular: "kilocalorie",
912
+ plural: "kilocalories"
913
+ },
914
+ // Watt-hour (exatos)
915
+ // 1 Wh = 1 W × 3600 s = 3600 J
916
+ watt_hour: {
917
+ factor: 3600,
918
+ symbol: "Wh",
919
+ singular: "watt-hour",
920
+ plural: "watt-hours"
921
+ },
922
+ kilowatt_hour: {
923
+ factor: 36e5,
924
+ symbol: "kWh",
925
+ singular: "kilowatt-hour",
926
+ plural: "kilowatt-hours"
927
+ },
928
+ megawatt_hour: {
929
+ factor: 36e8,
930
+ symbol: "MWh",
931
+ singular: "megawatt-hour",
932
+ plural: "megawatt-hours"
933
+ },
934
+ gigawatt_hour: {
935
+ factor: 36e11,
936
+ symbol: "GWh",
937
+ singular: "gigawatt-hour",
938
+ plural: "gigawatt-hours"
939
+ },
940
+ // BTU (International Table)
941
+ // 1 BTU (IT) = 1055.05585262 J (definição)
942
+ btu: {
943
+ factor: 1055.05585262,
944
+ symbol: "BTU",
945
+ singular: "BTU",
946
+ plural: "BTUs"
947
+ },
948
+ // 1 therm = 100,000 BTU (IT)
949
+ therm: {
950
+ factor: 105505585262e-3,
951
+ symbol: "thm",
952
+ singular: "therm",
953
+ plural: "therms"
954
+ },
955
+ // Scientific
956
+ // 1 eV = 1.602176634e-19 J (SI 2019, exato por definição)
957
+ electronvolt: {
958
+ factor: 1602176634e-28,
959
+ symbol: "eV",
960
+ singular: "electronvolt",
961
+ plural: "electronvolts"
962
+ },
963
+ kiloelectronvolt: {
964
+ factor: 1602176634e-25,
965
+ symbol: "keV",
966
+ singular: "kiloelectronvolt",
967
+ plural: "kiloelectronvolts"
968
+ },
969
+ megaelectronvolt: {
970
+ factor: 1602176634e-22,
971
+ symbol: "MeV",
972
+ singular: "megaelectronvolt",
973
+ plural: "megaelectronvolts"
974
+ },
975
+ // 1 erg = 1e-7 J (CGS, exato)
976
+ erg: {
977
+ factor: 1e-7,
978
+ symbol: "erg",
979
+ singular: "erg",
980
+ plural: "ergs"
981
+ },
982
+ // Mechanical
983
+ // 1 ft⋅lbf = 1.3558179483314004 J (derivado de foot e pound-force)
984
+ foot_pound: {
985
+ factor: 1.3558179483314003,
986
+ symbol: "ft\u22C5lbf",
987
+ singular: "foot-pound",
988
+ plural: "foot-pounds"
989
+ }
990
+ };
991
+ Object.fromEntries(
992
+ Object.entries(ENERGY_UNITS).map(([unit, config]) => [
993
+ unit,
994
+ config.factor ?? 1
995
+ ])
996
+ );
997
+
998
+ // src/roles/energy/convert.ts
999
+ var ENERGY_BASE = "joule";
1000
+ function toBaseEnergy(variant, value) {
1001
+ const unit = ENERGY_UNITS[variant];
1002
+ if (!unit) {
1003
+ throw new Error(`Unknown energy variant: ${variant}`);
1004
+ }
1005
+ return value * (unit.factor ?? 1);
1006
+ }
1007
+ function fromBaseEnergy(variant, baseValue) {
1008
+ const unit = ENERGY_UNITS[variant];
1009
+ if (!unit) {
1010
+ throw new Error(`Unknown energy variant: ${variant}`);
1011
+ }
1012
+ return baseValue / (unit.factor ?? 1);
1013
+ }
1014
+ function convertEnergy(from, to, value) {
1015
+ if (from === to) {
1016
+ return value;
1017
+ }
1018
+ const baseValue = toBaseEnergy(from, value);
1019
+ return fromBaseEnergy(to, baseValue);
1020
+ }
1021
+ function tryConvertEnergy(from, to, value) {
1022
+ try {
1023
+ const result = convertEnergy(from, to, value);
1024
+ return { ok: true, value: result };
1025
+ } catch (err) {
1026
+ return { ok: false, error: String(err) };
1027
+ }
1028
+ }
1029
+ function hasEnergyVariant(variant) {
1030
+ return variant in ENERGY_UNITS;
1031
+ }
1032
+ function getEnergyVariants() {
1033
+ return Object.keys(ENERGY_UNITS);
1034
+ }
1035
+
1036
+ // src/roles/power/constants.ts
1037
+ var POWER_UNITS = {
1038
+ // SI Units (todos exatos)
1039
+ gigawatt: {
1040
+ factor: 1e9,
1041
+ symbol: "GW",
1042
+ singular: "gigawatt",
1043
+ plural: "gigawatts"
1044
+ },
1045
+ megawatt: {
1046
+ factor: 1e6,
1047
+ symbol: "MW",
1048
+ singular: "megawatt",
1049
+ plural: "megawatts"
1050
+ },
1051
+ kilowatt: {
1052
+ factor: 1e3,
1053
+ symbol: "kW",
1054
+ singular: "kilowatt",
1055
+ plural: "kilowatts"
1056
+ },
1057
+ watt: {
1058
+ factor: 1,
1059
+ symbol: "W",
1060
+ singular: "watt",
1061
+ plural: "watts"
1062
+ },
1063
+ milliwatt: {
1064
+ factor: 1e-3,
1065
+ symbol: "mW",
1066
+ singular: "milliwatt",
1067
+ plural: "milliwatts"
1068
+ },
1069
+ microwatt: {
1070
+ factor: 1e-6,
1071
+ symbol: "\u03BCW",
1072
+ singular: "microwatt",
1073
+ plural: "microwatts"
1074
+ },
1075
+ // Horsepower variants
1076
+ // Mechanical (imperial): 550 ft⋅lbf/s
1077
+ // = 550 × 0.3048 m × 4.4482216152605 N / s = 745.69987158227 W
1078
+ horsepower_mechanical: {
1079
+ factor: 745.69987158227,
1080
+ symbol: "hp",
1081
+ singular: "horsepower",
1082
+ plural: "horsepower"
1083
+ },
1084
+ // Metric (PS, CV, pk): 75 kgf⋅m/s = 75 × 9.80665 W = 735.49875 W (exato)
1085
+ horsepower_metric: {
1086
+ factor: 735.49875,
1087
+ symbol: "PS",
1088
+ singular: "metric horsepower",
1089
+ plural: "metric horsepower"
1090
+ },
1091
+ // Electrical: 746 W (exato por definição)
1092
+ horsepower_electric: {
1093
+ factor: 746,
1094
+ symbol: "hp(E)",
1095
+ singular: "electric horsepower",
1096
+ plural: "electric horsepower"
1097
+ },
1098
+ // Boiler: 33,475 BTU/h = 9809.5 W
1099
+ horsepower_boiler: {
1100
+ factor: 9809.5,
1101
+ symbol: "hp(S)",
1102
+ singular: "boiler horsepower",
1103
+ plural: "boiler horsepower"
1104
+ },
1105
+ // BTU-based
1106
+ // 1 BTU/h = 1055.05585262 J / 3600 s = 0.29307107017222 W
1107
+ btu_per_hour: {
1108
+ factor: 0.29307107017222,
1109
+ symbol: "BTU/h",
1110
+ singular: "BTU per hour",
1111
+ plural: "BTUs per hour"
1112
+ },
1113
+ // 1 BTU/s = 1055.05585262 W
1114
+ btu_per_second: {
1115
+ factor: 1055.05585262,
1116
+ symbol: "BTU/s",
1117
+ singular: "BTU per second",
1118
+ plural: "BTUs per second"
1119
+ },
1120
+ // Other
1121
+ // 1 ton of refrigeration = 12000 BTU/h = 3516.8528420667 W
1122
+ ton_of_refrigeration: {
1123
+ factor: 3516.8528420667,
1124
+ symbol: "TR",
1125
+ singular: "ton of refrigeration",
1126
+ plural: "tons of refrigeration"
1127
+ },
1128
+ // 1 ft⋅lbf/s = 1.3558179483314004 W
1129
+ foot_pound_per_second: {
1130
+ factor: 1.3558179483314003,
1131
+ symbol: "ft\u22C5lbf/s",
1132
+ singular: "foot-pound per second",
1133
+ plural: "foot-pounds per second"
1134
+ },
1135
+ // 1 cal/s = 4.1868 W
1136
+ calorie_per_second: {
1137
+ factor: 4.1868,
1138
+ symbol: "cal/s",
1139
+ singular: "calorie per second",
1140
+ plural: "calories per second"
1141
+ },
1142
+ // 1 kcal/h = 4186.8 / 3600 = 1.163 W
1143
+ kilocalorie_per_hour: {
1144
+ factor: 1.163,
1145
+ symbol: "kcal/h",
1146
+ singular: "kilocalorie per hour",
1147
+ plural: "kilocalories per hour"
1148
+ }
1149
+ };
1150
+ Object.fromEntries(
1151
+ Object.entries(POWER_UNITS).map(([unit, config]) => [
1152
+ unit,
1153
+ config.factor ?? 1
1154
+ ])
1155
+ );
1156
+
1157
+ // src/roles/power/convert.ts
1158
+ var POWER_BASE = "watt";
1159
+ function toBasePower(variant, value) {
1160
+ const config = POWER_UNITS[variant];
1161
+ if (!config) {
1162
+ throw new Error(`Unknown power unit: ${variant}`);
1163
+ }
1164
+ return value * (config.factor ?? 1);
1165
+ }
1166
+ function fromBasePower(variant, baseValue) {
1167
+ const config = POWER_UNITS[variant];
1168
+ if (!config) {
1169
+ throw new Error(`Unknown power unit: ${variant}`);
1170
+ }
1171
+ return baseValue / (config.factor ?? 1);
1172
+ }
1173
+ function convertPower(from, to, value) {
1174
+ if (from === to) {
1175
+ return value;
1176
+ }
1177
+ const baseValue = toBasePower(from, value);
1178
+ return fromBasePower(to, baseValue);
1179
+ }
1180
+ function tryConvertPower(from, to, value) {
1181
+ try {
1182
+ return { ok: true, value: convertPower(from, to, value) };
1183
+ } catch (e) {
1184
+ return { ok: false, error: e.message };
1185
+ }
1186
+ }
1187
+ function hasPowerVariant(variant) {
1188
+ return variant in POWER_UNITS;
1189
+ }
1190
+ function getPowerVariants() {
1191
+ return Object.keys(POWER_UNITS);
1192
+ }
1193
+
1194
+ // src/roles/pressure/constants.ts
1195
+ var PRESSURE_UNITS = {
1196
+ // SI Units (todos exatos)
1197
+ megapascal: {
1198
+ factor: 1e6,
1199
+ symbol: "MPa",
1200
+ singular: "megapascal",
1201
+ plural: "megapascals"
1202
+ },
1203
+ kilopascal: {
1204
+ factor: 1e3,
1205
+ symbol: "kPa",
1206
+ singular: "kilopascal",
1207
+ plural: "kilopascals"
1208
+ },
1209
+ hectopascal: {
1210
+ factor: 100,
1211
+ symbol: "hPa",
1212
+ singular: "hectopascal",
1213
+ plural: "hectopascals"
1214
+ },
1215
+ pascal: {
1216
+ factor: 1,
1217
+ symbol: "Pa",
1218
+ singular: "pascal",
1219
+ plural: "pascals"
1220
+ },
1221
+ // Bar (exatos por definição)
1222
+ bar: {
1223
+ factor: 1e5,
1224
+ symbol: "bar",
1225
+ singular: "bar",
1226
+ plural: "bar"
1227
+ },
1228
+ millibar: {
1229
+ factor: 100,
1230
+ // = 1 hPa
1231
+ symbol: "mbar",
1232
+ singular: "millibar",
1233
+ plural: "millibar"
1234
+ },
1235
+ // Atmosphere (exato, CGPM 1954)
1236
+ atmosphere: {
1237
+ factor: 101325,
1238
+ symbol: "atm",
1239
+ singular: "atmosphere",
1240
+ plural: "atmospheres"
1241
+ },
1242
+ // Mercury column
1243
+ torr: {
1244
+ factor: 101325 / 760,
1245
+ // ≈ 133.322368421
1246
+ symbol: "Torr",
1247
+ singular: "torr",
1248
+ plural: "torr"
1249
+ },
1250
+ mmhg: {
1251
+ factor: 133.322387415,
1252
+ // Convenção NIST
1253
+ symbol: "mmHg",
1254
+ singular: "millimeter of mercury",
1255
+ plural: "millimeters of mercury"
1256
+ },
1257
+ inhg: {
1258
+ factor: 3386.389,
1259
+ // Polegadas de mercúrio
1260
+ symbol: "inHg",
1261
+ singular: "inch of mercury",
1262
+ plural: "inches of mercury"
1263
+ },
1264
+ // Imperial (derivados de lb/in²)
1265
+ psi: {
1266
+ factor: 6894.757293168,
1267
+ // 1 lbf/in²
1268
+ symbol: "psi",
1269
+ singular: "pound per square inch",
1270
+ plural: "pounds per square inch"
1271
+ },
1272
+ ksi: {
1273
+ factor: 6894757293168e-6,
1274
+ // 1000 psi
1275
+ symbol: "ksi",
1276
+ singular: "kilopound per square inch",
1277
+ plural: "kilopounds per square inch"
1278
+ },
1279
+ // Water column
1280
+ cmh2o: {
1281
+ factor: 98.0665,
1282
+ // cm de água a 4°C
1283
+ symbol: "cmH\u2082O",
1284
+ singular: "centimeter of water",
1285
+ plural: "centimeters of water"
1286
+ },
1287
+ inh2o: {
1288
+ factor: 249.08891,
1289
+ // polegadas de água
1290
+ symbol: "inH\u2082O",
1291
+ singular: "inch of water",
1292
+ plural: "inches of water"
1293
+ }
1294
+ };
1295
+ Object.fromEntries(
1296
+ Object.entries(PRESSURE_UNITS).map(([unit, config]) => [
1297
+ unit,
1298
+ config.factor ?? 1
1299
+ ])
1300
+ );
1301
+
1302
+ // src/roles/pressure/convert.ts
1303
+ var PRESSURE_BASE = "pascal";
1304
+ function toBasePressure(variant, value) {
1305
+ const config = PRESSURE_UNITS[variant];
1306
+ if (!config) {
1307
+ throw new Error(`Unknown pressure unit: ${variant}`);
1308
+ }
1309
+ return value * (config.factor ?? 1);
1310
+ }
1311
+ function fromBasePressure(variant, baseValue) {
1312
+ const config = PRESSURE_UNITS[variant];
1313
+ if (!config) {
1314
+ throw new Error(`Unknown pressure unit: ${variant}`);
1315
+ }
1316
+ return baseValue / (config.factor ?? 1);
1317
+ }
1318
+ function convertPressure(from, to, value) {
1319
+ if (from === to) {
1320
+ return value;
1321
+ }
1322
+ const baseValue = toBasePressure(from, value);
1323
+ return fromBasePressure(to, baseValue);
1324
+ }
1325
+ function tryConvertPressure(from, to, value) {
1326
+ try {
1327
+ return { ok: true, value: convertPressure(from, to, value) };
1328
+ } catch (e) {
1329
+ return { ok: false, error: e.message };
1330
+ }
1331
+ }
1332
+ function hasPressureVariant(variant) {
1333
+ return variant in PRESSURE_UNITS;
1334
+ }
1335
+ function getPressureVariants() {
1336
+ return Object.keys(PRESSURE_UNITS);
1337
+ }
1338
+
1339
+ // src/roles/frequency/constants.ts
1340
+ var FREQUENCY_UNITS = {
1341
+ // SI Units (todos exatos)
1342
+ terahertz: {
1343
+ factor: 1e12,
1344
+ symbol: "THz",
1345
+ singular: "terahertz",
1346
+ plural: "terahertz"
1347
+ },
1348
+ gigahertz: {
1349
+ factor: 1e9,
1350
+ symbol: "GHz",
1351
+ singular: "gigahertz",
1352
+ plural: "gigahertz"
1353
+ },
1354
+ megahertz: {
1355
+ factor: 1e6,
1356
+ symbol: "MHz",
1357
+ singular: "megahertz",
1358
+ plural: "megahertz"
1359
+ },
1360
+ kilohertz: {
1361
+ factor: 1e3,
1362
+ symbol: "kHz",
1363
+ singular: "kilohertz",
1364
+ plural: "kilohertz"
1365
+ },
1366
+ hertz: {
1367
+ factor: 1,
1368
+ symbol: "Hz",
1369
+ singular: "hertz",
1370
+ plural: "hertz"
1371
+ },
1372
+ millihertz: {
1373
+ factor: 1e-3,
1374
+ symbol: "mHz",
1375
+ singular: "millihertz",
1376
+ plural: "millihertz"
1377
+ },
1378
+ microhertz: {
1379
+ factor: 1e-6,
1380
+ symbol: "\u03BCHz",
1381
+ singular: "microhertz",
1382
+ plural: "microhertz"
1383
+ },
1384
+ // Other units
1385
+ rpm: {
1386
+ factor: 1 / 60,
1387
+ // 1 RPM = 1/60 Hz
1388
+ symbol: "rpm",
1389
+ singular: "revolution per minute",
1390
+ plural: "revolutions per minute"
1391
+ },
1392
+ bpm: {
1393
+ factor: 1 / 60,
1394
+ // 1 BPM = 1/60 Hz
1395
+ symbol: "bpm",
1396
+ singular: "beat per minute",
1397
+ plural: "beats per minute"
1398
+ },
1399
+ radians_per_second: {
1400
+ factor: 1 / (2 * Math.PI),
1401
+ // 1 rad/s = 1/(2π) Hz ≈ 0.159154943
1402
+ symbol: "rad/s",
1403
+ singular: "radian per second",
1404
+ plural: "radians per second"
1405
+ },
1406
+ cycles_per_minute: {
1407
+ factor: 1 / 60,
1408
+ // same as RPM
1409
+ symbol: "cpm",
1410
+ singular: "cycle per minute",
1411
+ plural: "cycles per minute"
1412
+ }
1413
+ };
1414
+ Object.fromEntries(
1415
+ Object.entries(FREQUENCY_UNITS).map(([unit, config]) => [
1416
+ unit,
1417
+ config.factor ?? 1
1418
+ ])
1419
+ );
1420
+
1421
+ // src/roles/frequency/convert.ts
1422
+ var FREQUENCY_BASE = "hertz";
1423
+ function toBaseFrequency(variant, value) {
1424
+ const config = FREQUENCY_UNITS[variant];
1425
+ if (!config) {
1426
+ throw new Error(`Unknown frequency unit: ${variant}`);
1427
+ }
1428
+ return value * (config.factor ?? 1);
1429
+ }
1430
+ function fromBaseFrequency(variant, baseValue) {
1431
+ const config = FREQUENCY_UNITS[variant];
1432
+ if (!config) {
1433
+ throw new Error(`Unknown frequency unit: ${variant}`);
1434
+ }
1435
+ return baseValue / (config.factor ?? 1);
1436
+ }
1437
+ function convertFrequency(from, to, value) {
1438
+ if (from === to) {
1439
+ return value;
1440
+ }
1441
+ const baseValue = toBaseFrequency(from, value);
1442
+ return fromBaseFrequency(to, baseValue);
1443
+ }
1444
+ function tryConvertFrequency(from, to, value) {
1445
+ try {
1446
+ return { ok: true, value: convertFrequency(from, to, value) };
1447
+ } catch (e) {
1448
+ return { ok: false, error: e.message };
1449
+ }
1450
+ }
1451
+ function hasFrequencyVariant(variant) {
1452
+ return variant in FREQUENCY_UNITS;
1453
+ }
1454
+ function getFrequencyVariants() {
1455
+ return Object.keys(FREQUENCY_UNITS);
1456
+ }
1457
+
1458
+ // src/roles/angle/constants.ts
1459
+ var DEGREES_PER_RADIAN = 180 / Math.PI;
1460
+ var DEGREES_PER_MILLIRADIAN = 180 / (1e3 * Math.PI);
1461
+ var ANGLE_UNITS = {
1462
+ // Volta completa
1463
+ turn: {
1464
+ factor: 360,
1465
+ symbol: "tr",
1466
+ singular: "turn",
1467
+ plural: "turns"
1468
+ },
1469
+ // Base
1470
+ degree: {
1471
+ factor: 1,
1472
+ symbol: "\xB0",
1473
+ singular: "degree",
1474
+ plural: "degrees",
1475
+ noSpace: true
1476
+ // 45° não 45 °
1477
+ },
1478
+ // Subdivisões do grau
1479
+ arcminute: {
1480
+ factor: 1 / 60,
1481
+ // 0.016666...
1482
+ symbol: "\u2032",
1483
+ singular: "arcminute",
1484
+ plural: "arcminutes",
1485
+ noSpace: true
1486
+ // 30′ não 30 ′
1487
+ },
1488
+ arcsecond: {
1489
+ factor: 1 / 3600,
1490
+ // 0.000277...
1491
+ symbol: "\u2033",
1492
+ singular: "arcsecond",
1493
+ plural: "arcseconds",
1494
+ noSpace: true
1495
+ // 45″ não 45 ″
1496
+ },
1497
+ milliarcsecond: {
1498
+ factor: 1 / 36e5,
1499
+ // 2.777...e-7
1500
+ symbol: "mas",
1501
+ singular: "milliarcsecond",
1502
+ plural: "milliarcseconds"
1503
+ },
1504
+ // Radianos (unidade SI)
1505
+ radian: {
1506
+ factor: DEGREES_PER_RADIAN,
1507
+ // 180/π ≈ 57.2958
1508
+ symbol: "rad",
1509
+ singular: "radian",
1510
+ plural: "radians"
1511
+ },
1512
+ milliradian: {
1513
+ factor: DEGREES_PER_MILLIRADIAN,
1514
+ // 180/(1000π) ≈ 0.0573
1515
+ symbol: "mrad",
1516
+ singular: "milliradian",
1517
+ plural: "milliradians"
1518
+ },
1519
+ // Gradiano (gon)
1520
+ gradian: {
1521
+ factor: 0.9,
1522
+ // 360/400
1523
+ symbol: "gon",
1524
+ singular: "gradian",
1525
+ plural: "gradians"
1526
+ }
1527
+ };
1528
+ Object.fromEntries(
1529
+ Object.entries(ANGLE_UNITS).map(([unit, config]) => [
1530
+ unit,
1531
+ config.factor ?? 1
1532
+ ])
1533
+ );
1534
+
1535
+ // src/roles/angle/convert.ts
1536
+ var ANGLE_BASE = "degree";
1537
+ function toBaseAngle(variant, value) {
1538
+ const config = ANGLE_UNITS[variant];
1539
+ if (!config) {
1540
+ throw new Error(`Unknown angle unit: ${variant}`);
1541
+ }
1542
+ return value * (config.factor ?? 1);
1543
+ }
1544
+ function fromBaseAngle(variant, baseValue) {
1545
+ const config = ANGLE_UNITS[variant];
1546
+ if (!config) {
1547
+ throw new Error(`Unknown angle unit: ${variant}`);
1548
+ }
1549
+ return baseValue / (config.factor ?? 1);
1550
+ }
1551
+ function convertAngle(from, to, value) {
1552
+ if (from === to) {
1553
+ return value;
1554
+ }
1555
+ const baseValue = toBaseAngle(from, value);
1556
+ return fromBaseAngle(to, baseValue);
1557
+ }
1558
+ function tryConvertAngle(from, to, value) {
1559
+ try {
1560
+ return { ok: true, value: convertAngle(from, to, value) };
1561
+ } catch (e) {
1562
+ return { ok: false, error: e.message };
1563
+ }
1564
+ }
1565
+ function hasAngleVariant(variant) {
1566
+ return variant in ANGLE_UNITS;
1567
+ }
1568
+ function getAngleVariants() {
1569
+ return Object.keys(ANGLE_UNITS);
1570
+ }
1571
+
1572
+ // src/roles/time/constants.ts
1573
+ var TIME_UNITS = {
1574
+ // SI prefixes (exatos)
1575
+ nanosecond: {
1576
+ factor: 1e-9,
1577
+ symbol: "ns",
1578
+ singular: "nanosecond",
1579
+ plural: "nanoseconds"
1580
+ },
1581
+ microsecond: {
1582
+ factor: 1e-6,
1583
+ symbol: "\u03BCs",
1584
+ singular: "microsecond",
1585
+ plural: "microseconds"
1586
+ },
1587
+ millisecond: {
1588
+ factor: 1e-3,
1589
+ symbol: "ms",
1590
+ singular: "millisecond",
1591
+ plural: "milliseconds"
1592
+ },
1593
+ second: {
1594
+ factor: 1,
1595
+ symbol: "s",
1596
+ singular: "second",
1597
+ plural: "seconds"
1598
+ },
1599
+ // Common (exatos)
1600
+ minute: {
1601
+ factor: 60,
1602
+ symbol: "min",
1603
+ singular: "minute",
1604
+ plural: "minutes"
1605
+ },
1606
+ hour: {
1607
+ factor: 3600,
1608
+ symbol: "h",
1609
+ singular: "hour",
1610
+ plural: "hours"
1611
+ },
1612
+ day: {
1613
+ factor: 86400,
1614
+ symbol: "d",
1615
+ singular: "day",
1616
+ plural: "days"
1617
+ },
1618
+ week: {
1619
+ factor: 604800,
1620
+ symbol: "wk",
1621
+ singular: "week",
1622
+ plural: "weeks"
1623
+ },
1624
+ // Calendar (aproximados - baseados no ano Gregoriano)
1625
+ month: {
1626
+ factor: 2629746,
1627
+ // 31556952 / 12
1628
+ symbol: "mo",
1629
+ singular: "month",
1630
+ plural: "months"
1631
+ },
1632
+ year: {
1633
+ factor: 31556952,
1634
+ // 365.2425 * 86400
1635
+ symbol: "yr",
1636
+ singular: "year",
1637
+ plural: "years"
1638
+ },
1639
+ decade: {
1640
+ factor: 315569520,
1641
+ // 10 * year
1642
+ symbol: "dec",
1643
+ singular: "decade",
1644
+ plural: "decades"
1645
+ },
1646
+ century: {
1647
+ factor: 3155695200,
1648
+ // 100 * year
1649
+ symbol: "c",
1650
+ singular: "century",
1651
+ plural: "centuries"
1652
+ },
1653
+ millennium: {
1654
+ factor: 31556952e3,
1655
+ // 1000 * year
1656
+ symbol: "ky",
1657
+ singular: "millennium",
1658
+ plural: "millennia"
1659
+ }
1660
+ };
1661
+ Object.fromEntries(
1662
+ Object.entries(TIME_UNITS).map(([unit, config]) => [
1663
+ unit,
1664
+ config.factor ?? 1
1665
+ ])
1666
+ );
1667
+
1668
+ // src/roles/time/convert.ts
1669
+ var TIME_BASE = "second";
1670
+ function toBaseTime(variant, value) {
1671
+ const config = TIME_UNITS[variant];
1672
+ if (!config) {
1673
+ throw new Error(`Unknown time unit: ${variant}`);
1674
+ }
1675
+ return value * (config.factor ?? 1);
1676
+ }
1677
+ function fromBaseTime(variant, baseValue) {
1678
+ const config = TIME_UNITS[variant];
1679
+ if (!config) {
1680
+ throw new Error(`Unknown time unit: ${variant}`);
1681
+ }
1682
+ return baseValue / (config.factor ?? 1);
1683
+ }
1684
+ function convertTime(from, to, value) {
1685
+ if (from === to) {
1686
+ return value;
1687
+ }
1688
+ const baseValue = toBaseTime(from, value);
1689
+ return fromBaseTime(to, baseValue);
1690
+ }
1691
+ function tryConvertTime(from, to, value) {
1692
+ try {
1693
+ return { ok: true, value: convertTime(from, to, value) };
1694
+ } catch (e) {
1695
+ return { ok: false, error: e.message };
1696
+ }
1697
+ }
1698
+ function hasTimeVariant(variant) {
1699
+ return variant in TIME_UNITS;
1700
+ }
1701
+ function getTimeVariants() {
1702
+ return Object.keys(TIME_UNITS);
1703
+ }
1704
+
1705
+ // src/roles/digital/constants.ts
1706
+ var DIGITAL_UNITS = {
1707
+ // Fundamental
1708
+ bit: {
1709
+ factor: 0.125,
1710
+ // 1/8 byte
1711
+ symbol: "b",
1712
+ singular: "bit",
1713
+ plural: "bits"
1714
+ },
1715
+ byte: {
1716
+ factor: 1,
1717
+ symbol: "B",
1718
+ singular: "byte",
1719
+ plural: "bytes"
1720
+ },
1721
+ // IEC Binary (base 1024) - RAM, cache, file systems
1722
+ kibibyte: {
1723
+ factor: 1024,
1724
+ // 2^10
1725
+ symbol: "KiB",
1726
+ singular: "kibibyte",
1727
+ plural: "kibibytes"
1728
+ },
1729
+ mebibyte: {
1730
+ factor: 1048576,
1731
+ // 2^20
1732
+ symbol: "MiB",
1733
+ singular: "mebibyte",
1734
+ plural: "mebibytes"
1735
+ },
1736
+ gibibyte: {
1737
+ factor: 1073741824,
1738
+ // 2^30
1739
+ symbol: "GiB",
1740
+ singular: "gibibyte",
1741
+ plural: "gibibytes"
1742
+ },
1743
+ tebibyte: {
1744
+ factor: 1099511627776,
1745
+ // 2^40
1746
+ symbol: "TiB",
1747
+ singular: "tebibyte",
1748
+ plural: "tebibytes"
1749
+ },
1750
+ pebibyte: {
1751
+ factor: 1125899906842624,
1752
+ // 2^50
1753
+ symbol: "PiB",
1754
+ singular: "pebibyte",
1755
+ plural: "pebibytes"
1756
+ },
1757
+ exbibyte: {
1758
+ factor: 1152921504606847e3,
1759
+ // 2^60
1760
+ symbol: "EiB",
1761
+ singular: "exbibyte",
1762
+ plural: "exbibytes"
1763
+ },
1764
+ // SI Decimal (base 1000) - HD marketing, network speeds
1765
+ kilobyte: {
1766
+ factor: 1e3,
1767
+ // 10^3
1768
+ symbol: "kB",
1769
+ singular: "kilobyte",
1770
+ plural: "kilobytes"
1771
+ },
1772
+ megabyte: {
1773
+ factor: 1e6,
1774
+ // 10^6
1775
+ symbol: "MB",
1776
+ singular: "megabyte",
1777
+ plural: "megabytes"
1778
+ },
1779
+ gigabyte: {
1780
+ factor: 1e9,
1781
+ // 10^9
1782
+ symbol: "GB",
1783
+ singular: "gigabyte",
1784
+ plural: "gigabytes"
1785
+ },
1786
+ terabyte: {
1787
+ factor: 1e12,
1788
+ // 10^12
1789
+ symbol: "TB",
1790
+ singular: "terabyte",
1791
+ plural: "terabytes"
1792
+ },
1793
+ petabyte: {
1794
+ factor: 1e15,
1795
+ // 10^15
1796
+ symbol: "PB",
1797
+ singular: "petabyte",
1798
+ plural: "petabytes"
1799
+ },
1800
+ exabyte: {
1801
+ factor: 1e18,
1802
+ // 10^18
1803
+ symbol: "EB",
1804
+ singular: "exabyte",
1805
+ plural: "exabytes"
1806
+ }
1807
+ };
1808
+ Object.fromEntries(
1809
+ Object.entries(DIGITAL_UNITS).map(([unit, config]) => [
1810
+ unit,
1811
+ config.factor ?? 1
1812
+ ])
1813
+ );
1814
+
1815
+ // src/roles/digital/convert.ts
1816
+ var DIGITAL_BASE = "byte";
1817
+ function toBaseDigital(variant, value) {
1818
+ const config = DIGITAL_UNITS[variant];
1819
+ if (!config) {
1820
+ throw new Error(`Unknown digital unit: ${variant}`);
1821
+ }
1822
+ return value * (config.factor ?? 1);
1823
+ }
1824
+ function fromBaseDigital(variant, baseValue) {
1825
+ const config = DIGITAL_UNITS[variant];
1826
+ if (!config) {
1827
+ throw new Error(`Unknown digital unit: ${variant}`);
1828
+ }
1829
+ return baseValue / (config.factor ?? 1);
1830
+ }
1831
+ function convertDigital(from, to, value) {
1832
+ if (from === to) {
1833
+ return value;
1834
+ }
1835
+ const baseValue = toBaseDigital(from, value);
1836
+ return fromBaseDigital(to, baseValue);
1837
+ }
1838
+ function tryConvertDigital(from, to, value) {
1839
+ try {
1840
+ return { ok: true, value: convertDigital(from, to, value) };
1841
+ } catch (e) {
1842
+ return { ok: false, error: e.message };
1843
+ }
1844
+ }
1845
+ function hasDigitalVariant(variant) {
1846
+ return variant in DIGITAL_UNITS;
1847
+ }
1848
+ function getDigitalVariants() {
1849
+ return Object.keys(DIGITAL_UNITS);
1850
+ }
1851
+
1852
+ // src/roles/color/types.ts
1853
+ function clamp(value, min, max) {
1854
+ return Math.min(Math.max(value, min), max);
1855
+ }
1856
+ function normalizeRgbChannel(value) {
1857
+ return clamp(Math.round(value), 0, 255);
1858
+ }
1859
+ function normalizeAlpha(value) {
1860
+ if (value === void 0) return 1;
1861
+ return clamp(value, 0, 1);
1862
+ }
1863
+ function rgbToHsl(r, g, b) {
1864
+ r /= 255;
1865
+ g /= 255;
1866
+ b /= 255;
1867
+ const max = Math.max(r, g, b);
1868
+ const min = Math.min(r, g, b);
1869
+ const l = (max + min) / 2;
1870
+ if (max === min) {
1871
+ return { h: 0, s: 0, l: l * 100 };
1872
+ }
1873
+ const d = max - min;
1874
+ const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
1875
+ let h;
1876
+ switch (max) {
1877
+ case r:
1878
+ h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
1879
+ break;
1880
+ case g:
1881
+ h = ((b - r) / d + 2) / 6;
1882
+ break;
1883
+ default:
1884
+ h = ((r - g) / d + 4) / 6;
1885
+ break;
1886
+ }
1887
+ return {
1888
+ h: Math.round(h * 360),
1889
+ s: Math.round(s * 100),
1890
+ l: Math.round(l * 100)
1891
+ };
1892
+ }
1893
+ function hslToRgb(h, s, l) {
1894
+ h /= 360;
1895
+ s /= 100;
1896
+ l /= 100;
1897
+ if (s === 0) {
1898
+ const gray = Math.round(l * 255);
1899
+ return { r: gray, g: gray, b: gray };
1900
+ }
1901
+ const hue2rgb = (p2, q2, t) => {
1902
+ if (t < 0) t += 1;
1903
+ if (t > 1) t -= 1;
1904
+ if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
1905
+ if (t < 1 / 2) return q2;
1906
+ if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
1907
+ return p2;
1908
+ };
1909
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
1910
+ const p = 2 * l - q;
1911
+ return {
1912
+ r: Math.round(hue2rgb(p, q, h + 1 / 3) * 255),
1913
+ g: Math.round(hue2rgb(p, q, h) * 255),
1914
+ b: Math.round(hue2rgb(p, q, h - 1 / 3) * 255)
1915
+ };
1916
+ }
1917
+
1918
+ // src/roles/color/convert.ts
1919
+ function hexToRgba(hex) {
1920
+ let h = hex.trim();
1921
+ if (h.startsWith("#")) h = h.slice(1);
1922
+ let r, g, b, a;
1923
+ if (h.length === 3) {
1924
+ r = parseInt(h[0] + h[0], 16);
1925
+ g = parseInt(h[1] + h[1], 16);
1926
+ b = parseInt(h[2] + h[2], 16);
1927
+ a = 1;
1928
+ } else if (h.length === 4) {
1929
+ r = parseInt(h[0] + h[0], 16);
1930
+ g = parseInt(h[1] + h[1], 16);
1931
+ b = parseInt(h[2] + h[2], 16);
1932
+ a = parseInt(h[3] + h[3], 16) / 255;
1933
+ } else if (h.length === 6) {
1934
+ r = parseInt(h.slice(0, 2), 16);
1935
+ g = parseInt(h.slice(2, 4), 16);
1936
+ b = parseInt(h.slice(4, 6), 16);
1937
+ a = 1;
1938
+ } else if (h.length === 8) {
1939
+ r = parseInt(h.slice(0, 2), 16);
1940
+ g = parseInt(h.slice(2, 4), 16);
1941
+ b = parseInt(h.slice(4, 6), 16);
1942
+ a = parseInt(h.slice(6, 8), 16) / 255;
1943
+ } else {
1944
+ throw new Error(`Invalid hex color: ${hex}`);
1945
+ }
1946
+ return { r, g, b, a };
1947
+ }
1948
+ function rgbObjectToRgba(rgb) {
1949
+ return {
1950
+ r: normalizeRgbChannel(rgb.r),
1951
+ g: normalizeRgbChannel(rgb.g),
1952
+ b: normalizeRgbChannel(rgb.b),
1953
+ a: normalizeAlpha(rgb.a)
1954
+ };
1955
+ }
1956
+ function rgbStringToRgba(rgb) {
1957
+ const match = rgb.match(/rgba?\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)/i);
1958
+ if (!match) {
1959
+ throw new Error(`Invalid RGB string: ${rgb}`);
1960
+ }
1961
+ return {
1962
+ r: normalizeRgbChannel(parseFloat(match[1])),
1963
+ g: normalizeRgbChannel(parseFloat(match[2])),
1964
+ b: normalizeRgbChannel(parseFloat(match[3])),
1965
+ a: match[4] !== void 0 ? normalizeAlpha(parseFloat(match[4])) : 1
1966
+ };
1967
+ }
1968
+ function hslObjectToRgba(hsl) {
1969
+ const { r, g, b } = hslToRgb(hsl.h, hsl.s, hsl.l);
1970
+ return {
1971
+ r,
1972
+ g,
1973
+ b,
1974
+ a: normalizeAlpha(hsl.a)
1975
+ };
1976
+ }
1977
+ function hslStringToRgba(hsl) {
1978
+ const match = hsl.match(/hsla?\s*\(\s*([\d.]+)\s*,\s*([\d.]+)%?\s*,\s*([\d.]+)%?\s*(?:,\s*([\d.]+)\s*)?\)/i);
1979
+ if (!match) {
1980
+ throw new Error(`Invalid HSL string: ${hsl}`);
1981
+ }
1982
+ const h = parseFloat(match[1]);
1983
+ const s = parseFloat(match[2]);
1984
+ const l = parseFloat(match[3]);
1985
+ const a = match[4] !== void 0 ? parseFloat(match[4]) : 1;
1986
+ const { r, g, b } = hslToRgb(h, s, l);
1987
+ return { r, g, b, a: normalizeAlpha(a) };
1988
+ }
1989
+ function toBaseColor(variant, value) {
1990
+ switch (variant) {
1991
+ case "hex":
1992
+ return hexToRgba(value);
1993
+ case "rgb_object":
1994
+ return rgbObjectToRgba(value);
1995
+ case "rgb_string":
1996
+ return rgbStringToRgba(value);
1997
+ case "hsl_object":
1998
+ return hslObjectToRgba(value);
1999
+ case "hsl_string":
2000
+ return hslStringToRgba(value);
2001
+ default:
2002
+ throw new Error(`Unknown color variant: ${variant}`);
2003
+ }
2004
+ }
2005
+ function rgbaToHex(rgba, includeAlpha = false) {
2006
+ const r = rgba.r.toString(16).padStart(2, "0");
2007
+ const g = rgba.g.toString(16).padStart(2, "0");
2008
+ const b = rgba.b.toString(16).padStart(2, "0");
2009
+ if (includeAlpha || rgba.a < 1) {
2010
+ const a = Math.round(rgba.a * 255).toString(16).padStart(2, "0");
2011
+ return `#${r}${g}${b}${a}`;
2012
+ }
2013
+ return `#${r}${g}${b}`;
2014
+ }
2015
+ function rgbaToRgbObject(rgba) {
2016
+ if (rgba.a < 1) {
2017
+ return { r: rgba.r, g: rgba.g, b: rgba.b, a: rgba.a };
2018
+ }
2019
+ return { r: rgba.r, g: rgba.g, b: rgba.b };
2020
+ }
2021
+ function rgbaToRgbString(rgba) {
2022
+ if (rgba.a < 1) {
2023
+ return `rgba(${rgba.r}, ${rgba.g}, ${rgba.b}, ${rgba.a})`;
2024
+ }
2025
+ return `rgb(${rgba.r}, ${rgba.g}, ${rgba.b})`;
2026
+ }
2027
+ function rgbaToHslObject(rgba) {
2028
+ const { h, s, l } = rgbToHsl(rgba.r, rgba.g, rgba.b);
2029
+ if (rgba.a < 1) {
2030
+ return { h, s, l, a: rgba.a };
2031
+ }
2032
+ return { h, s, l };
2033
+ }
2034
+ function rgbaToHslString(rgba) {
2035
+ const { h, s, l } = rgbToHsl(rgba.r, rgba.g, rgba.b);
2036
+ if (rgba.a < 1) {
2037
+ return `hsla(${h}, ${s}%, ${l}%, ${rgba.a})`;
2038
+ }
2039
+ return `hsl(${h}, ${s}%, ${l}%)`;
2040
+ }
2041
+ function fromBaseColor(variant, rgba) {
2042
+ switch (variant) {
2043
+ case "hex":
2044
+ return rgbaToHex(rgba);
2045
+ case "rgb_object":
2046
+ return rgbaToRgbObject(rgba);
2047
+ case "rgb_string":
2048
+ return rgbaToRgbString(rgba);
2049
+ case "hsl_object":
2050
+ return rgbaToHslObject(rgba);
2051
+ case "hsl_string":
2052
+ return rgbaToHslString(rgba);
2053
+ default:
2054
+ throw new Error(`Unknown color variant: ${variant}`);
2055
+ }
2056
+ }
2057
+ function convertColor(from, to, value) {
2058
+ if (from === to) {
2059
+ return value;
2060
+ }
2061
+ const rgba = toBaseColor(from, value);
2062
+ return fromBaseColor(to, rgba);
2063
+ }
2064
+ function tryConvertColor(from, to, value) {
2065
+ try {
2066
+ const result = convertColor(from, to, value);
2067
+ return { ok: true, value: result };
2068
+ } catch (error) {
2069
+ return {
2070
+ ok: false,
2071
+ error: error instanceof Error ? error.message : String(error)
2072
+ };
2073
+ }
2074
+ }
2075
+
2076
+ // src/roles/date/convert.ts
2077
+ function isoToBase(value) {
2078
+ const date = new Date(value);
2079
+ if (isNaN(date.getTime())) {
2080
+ throw new Error(`Invalid ISO date: ${value}`);
2081
+ }
2082
+ return date.getTime();
2083
+ }
2084
+ function timestampToBase(value) {
2085
+ return value;
2086
+ }
2087
+ function epochToBase(value) {
2088
+ return value * 1e3;
2089
+ }
2090
+ function toBaseDate(variant, value) {
2091
+ switch (variant) {
2092
+ case "iso":
2093
+ return isoToBase(value);
2094
+ case "timestamp":
2095
+ return timestampToBase(value);
2096
+ case "epoch":
2097
+ return epochToBase(value);
2098
+ default:
2099
+ throw new Error(`Unknown date variant: ${variant}`);
2100
+ }
2101
+ }
2102
+ function baseToIso(base) {
2103
+ const date = new Date(base);
2104
+ if (isNaN(date.getTime())) {
2105
+ throw new Error(`Invalid timestamp: ${base}`);
2106
+ }
2107
+ return date.toISOString();
2108
+ }
2109
+ function baseToTimestamp(base) {
2110
+ return base;
2111
+ }
2112
+ function baseToEpoch(base) {
2113
+ return Math.floor(base / 1e3);
2114
+ }
2115
+ function fromBaseDate(variant, base) {
2116
+ switch (variant) {
2117
+ case "iso":
2118
+ return baseToIso(base);
2119
+ case "timestamp":
2120
+ return baseToTimestamp(base);
2121
+ case "epoch":
2122
+ return baseToEpoch(base);
2123
+ default:
2124
+ throw new Error(`Unknown date variant: ${variant}`);
2125
+ }
2126
+ }
2127
+ function convertDate(from, to, value) {
2128
+ if (from === to) {
2129
+ return value;
2130
+ }
2131
+ const base = toBaseDate(from, value);
2132
+ return fromBaseDate(to, base);
2133
+ }
2134
+ function tryConvertDate(from, to, value) {
2135
+ try {
2136
+ const result = convertDate(from, to, value);
2137
+ return { ok: true, value: result };
2138
+ } catch (error) {
2139
+ return {
2140
+ ok: false,
2141
+ error: error instanceof Error ? error.message : String(error)
2142
+ };
2143
+ }
2144
+ }
2145
+
2146
+ export { ANGLE_BASE, AREA_BASE, DIGITAL_BASE, ENERGY_BASE, FREQUENCY_BASE, LENGTH_BASE, MASS_BASE, POWER_BASE, PRESSURE_BASE, SPEED_BASE, TEMPERATURE_BASE, TIME_BASE, VOLUME_BASE, convertAngle, convertArea, convertColor, convertDate, convertDigital, convertEnergy, convertFrequency, convertLength, convertMass, convertPower, convertPressure, convertSpeed, convertTemperature, convertTime, convertVolume, fromBaseAngle, fromBaseArea, fromBaseDigital, fromBaseEnergy, fromBaseFrequency, fromBaseLength, fromBaseMass, fromBasePower, fromBasePressure, fromBaseSpeed, fromBaseTemperature, fromBaseTime, fromBaseVolume, getAngleVariants, getAreaVariants, getDigitalVariants, getEnergyVariants, getFrequencyVariants, getLengthVariants, getMassVariants, getPowerVariants, getPressureVariants, getSpeedVariants, getTemperatureVariants, getTimeVariants, getVolumeVariants, hasAngleVariant, hasAreaVariant, hasDigitalVariant, hasEnergyVariant, hasFrequencyVariant, hasLengthVariant, hasMassVariant, hasPowerVariant, hasPressureVariant, hasSpeedVariant, hasTemperatureVariant, hasTimeVariant, hasVolumeVariant, toBaseAngle, toBaseArea, toBaseDigital, toBaseEnergy, toBaseFrequency, toBaseLength, toBaseMass, toBasePower, toBasePressure, toBaseSpeed, toBaseTemperature, toBaseTime, toBaseVolume, tryConvertAngle, tryConvertArea, tryConvertColor, tryConvertDate, tryConvertDigital, tryConvertEnergy, tryConvertFrequency, tryConvertLength, tryConvertMass, tryConvertPower, tryConvertPressure, tryConvertSpeed, tryConvertTemperature, tryConvertTime, tryConvertVolume };
2147
+ //# sourceMappingURL=convert.mjs.map
2148
+ //# sourceMappingURL=convert.mjs.map