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