physical-quantity 1.1.92 → 1.2.2

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/pq.es.js CHANGED
@@ -1,4 +1,41 @@
1
- const o = 0.45359237, r = 9.80665, v = 5280, l = 25.4 / 1e3, n = 12 * l, W = 1852, V = 66 * 660, d = 4.54609, p = 231, I = 268.8025, g = 1 / 8, F = 1 / 20, G = 1 / 16, B = 8, _ = 8, q = 1 / 16, z = 240, K = 250, Q = 10, T = 14.59390294, f = 1055.05585262, w = 4.1868, b = 4.184, R = 550 * o * r * n, N = 101325, $ = 1 / 760, y = 133.322387415, j = 624150974e10, U = {
1
+ /**
2
+ * physical-quantity v1.2.0
3
+ * A web component bundle to represent physical quantities with automated unit conversion.
4
+ * @license MIT
5
+ * @author E3d - Don Wen <don.wen@calcslive.com>
6
+ */
7
+ const THOUSAND = 1e3;
8
+ const MILLION = 1e6;
9
+ const BILLION = 1e9;
10
+ const POUNDMASS_KG = 0.45359237;
11
+ const GRAVITY_SI = 9.80665;
12
+ const MILE_FOOT = 5280;
13
+ const INCH_METER = 25.4 / 1e3;
14
+ const FOOT_METER = 12 * INCH_METER;
15
+ const NM_METER = 1852;
16
+ const ACRE_FOOT2 = 66 * 660;
17
+ const GALLON_UK_IMPERIAL_LITRE = 4.54609;
18
+ const GALLON_US_LIQUID_IN3 = 231;
19
+ const GALLON_US_DRY_IN3 = 268.8025;
20
+ const PINT_GALLON = 1 / 8;
21
+ const OUNCE_FLUID_PINT_UK_IMPERIAL = 1 / 20;
22
+ const OUNCE_FLUID_PINT_US_LIQUID = 1 / 16;
23
+ const BUSHEL_GALLON_UK_IMPERIAL = 8;
24
+ const BUSHEL_GALLON_US_DRY = 8;
25
+ const CUP_US_GALLON_LIQUID = 1 / 16;
26
+ const CUP_LEGAL_ML_LIQUID = 240;
27
+ const CUP_METRIC_ML_LIQUID = 250;
28
+ const CUP_IMPERIAL_OUNCE_LIQUID = 10;
29
+ const SLUG_KG = 14.59390294;
30
+ const BTU_J = 1055.05585262;
31
+ const CALORIE_IT_J = 4.1868;
32
+ const CALORIE_TH_J = 4.184;
33
+ const HP_W = 550 * POUNDMASS_KG * GRAVITY_SI * FOOT_METER;
34
+ const ATM_PA = 101325;
35
+ const TORR_ATM = 1 / 760;
36
+ const MMHG_PA = 133.322387415;
37
+ const J_EV = 624150974e10;
38
+ const UNITS = {
2
39
  /* 901 */
3
40
  Length: [
4
41
  "m",
@@ -556,59 +593,60 @@ const o = 0.45359237, r = 9.80665, v = 5280, l = 25.4 / 1e3, n = 12 * l, W = 185
556
593
  ]
557
594
  /* 154 */
558
595
  /* */
559
- }, M = {
596
+ };
597
+ const CONVERSION_FACTORS = {
560
598
  /* 901 */
561
599
  Length: {
562
- m: 1,
563
- "nano[nm]": 1 / 1e9,
564
- µm: 1 / 1e6,
565
- micron: 1 / 1e6,
566
- mm: 1 / 1e3,
567
- cm: 0.01,
568
- dm: 0.1,
569
- km: 1e3,
570
- in: l,
571
- "thou[mil, or thousandth of an inch]": l / 1e3,
600
+ "m": 1,
601
+ "nano[nm]": 1 / BILLION,
602
+ "µm": 1 / MILLION,
603
+ "micron": 1 / MILLION,
604
+ "mm": 1 / THOUSAND,
605
+ "cm": 0.01,
606
+ "dm": 0.1,
607
+ "km": THOUSAND,
608
+ "in": INCH_METER,
609
+ "thou[mil, or thousandth of an inch]": INCH_METER / THOUSAND,
572
610
  // a thousandth is called a thou per wiki
573
- "ft-in": l,
574
- ft: n,
575
- yd: 3 * n,
576
- mile: v * n,
577
- "NM[M, nmi, or nautical mile]": W
611
+ "ft-in": INCH_METER,
612
+ "ft": FOOT_METER,
613
+ "yd": 3 * FOOT_METER,
614
+ "mile": MILE_FOOT * FOOT_METER,
615
+ "NM[M, nmi, or nautical mile]": NM_METER
578
616
  },
579
617
  /* 902 */
580
618
  Mass: {
581
- kg: 1,
582
- g: 1e-3,
583
- mg: 1 / 1e6,
584
- µg: 1 / 1e9,
585
- oz: 1 / 16 * o,
586
- lbm: o,
587
- slug: T,
588
- "ton(US/short)": 2e3 * o,
589
- "ton(UK-Imperial/long)": 2240 * o,
590
- tonne: 1e3
619
+ "kg": 1,
620
+ "g": 1e-3,
621
+ "mg": 1 / MILLION,
622
+ "µg": 1 / BILLION,
623
+ "oz": 1 / 16 * POUNDMASS_KG,
624
+ "lbm": POUNDMASS_KG,
625
+ "slug": SLUG_KG,
626
+ "ton(US/short)": 2e3 * POUNDMASS_KG,
627
+ "ton(UK-Imperial/long)": 2240 * POUNDMASS_KG,
628
+ "tonne": THOUSAND
591
629
  },
592
630
  /* 903 */
593
631
  Time: {
594
632
  /* ["s[second]", "s", "minute", "h", "h[hour]", "day", "week"], */
595
633
  "s[second]": 1,
596
- s: 1,
597
- minute: 60,
598
- h: 3600,
634
+ "s": 1,
635
+ "minute": 60,
636
+ "h": 3600,
599
637
  "h[hour]": 3600,
600
- day: 3600 * 24,
601
- week: 3600 * 24 * 7
638
+ "day": 3600 * 24,
639
+ "week": 3600 * 24 * 7
602
640
  },
603
641
  /* 904 */
604
642
  ElectricalCurrent: {
605
643
  /* ["A", "Ampere[amp]", "mA", "µA", "kA", "MA", "esu/s"], */
606
- A: 1,
644
+ "A": 1,
607
645
  "Ampere[amp]": 1,
608
- mA: 1e-3,
609
- µA: 1e-6,
610
- kA: 1e3,
611
- MA: 1e6,
646
+ "mA": 1e-3,
647
+ "µA": 1e-6,
648
+ "kA": THOUSAND,
649
+ "MA": MILLION,
612
650
  "esu/s": 1 / 3e9
613
651
  },
614
652
  /* 905 */
@@ -620,9 +658,9 @@ const o = 0.45359237, r = 9.80665, v = 5280, l = 25.4 / 1e3, n = 12 * l, W = 185
620
658
  },
621
659
  /* 906 */
622
660
  "Amount of Substance": {
623
- mol: 1,
624
- mmol: 1e-3,
625
- kmol: 1e3
661
+ "mol": 1,
662
+ "mmol": 1e-3,
663
+ "kmol": THOUSAND
626
664
  },
627
665
  /* 907 */
628
666
  "Luminous Intensity": {
@@ -636,15 +674,15 @@ const o = 0.45359237, r = 9.80665, v = 5280, l = 25.4 / 1e3, n = 12 * l, W = 185
636
674
  "m/s²": 1,
637
675
  "m/min²": 1 / 3600,
638
676
  "mm/s²": 1e-3,
639
- "ft/s²": n,
640
- "ft/min²": n / 3600,
641
- "in/s²": l
677
+ "ft/s²": FOOT_METER,
678
+ "ft/min²": FOOT_METER / 3600,
679
+ "in/s²": INCH_METER
642
680
  },
643
681
  /* 1001 */
644
682
  "Gravitational Constant": {
645
683
  "m³/kg/s²": 1,
646
684
  "N⋅m²/kg²": 1,
647
- "dyn⋅cm²/g²": 1e3
685
+ "dyn⋅cm²/g²": THOUSAND
648
686
  },
649
687
  /* 1010 */
650
688
  "Velocity (Angular)": {
@@ -666,102 +704,102 @@ const o = 0.45359237, r = 9.80665, v = 5280, l = 25.4 / 1e3, n = 12 * l, W = 185
666
704
  },
667
705
  /* 102 */
668
706
  Illuminance: {
669
- lux: 1,
707
+ "lux": 1,
670
708
  "lumen/m²": 1,
671
709
  "lm/m²": 1,
672
710
  "meter-candle": 1,
673
- phot: 1e4,
674
- "foot-candle": 1 / Math.pow(n, 2),
675
- fc: 1 / Math.pow(n, 2),
676
- "lumen/ft²": 1 / Math.pow(n, 2),
677
- "lm/ft²": 1 / Math.pow(n, 2)
711
+ "phot": 1e4,
712
+ "foot-candle": 1 / Math.pow(FOOT_METER, 2),
713
+ "fc": 1 / Math.pow(FOOT_METER, 2),
714
+ "lumen/ft²": 1 / Math.pow(FOOT_METER, 2),
715
+ "lm/ft²": 1 / Math.pow(FOOT_METER, 2)
678
716
  },
679
717
  /* 103 */
680
718
  Frequency: {
681
- Hz: 1,
719
+ "Hz": 1,
682
720
  "1/s": 1,
683
721
  "1/min": 1 / 60,
684
- rpm: 1 / 60,
722
+ "rpm": 1 / 60,
685
723
  "1/hour": 1 / 3600,
686
- mHz: 1 / 1e3,
687
- kHz: 1e3,
688
- MHz: 1e6,
689
- GHz: 1e9
724
+ "mHz": 1 / THOUSAND,
725
+ "kHz": THOUSAND,
726
+ "MHz": MILLION,
727
+ "GHz": BILLION
690
728
  },
691
729
  /* 104 */
692
730
  Area: {
693
731
  "m²": 1,
694
- "µm²": Math.pow(1 / 1e6, 2),
695
- "mm²": Math.pow(1 / 1e3, 2),
732
+ "µm²": Math.pow(1 / MILLION, 2),
733
+ "mm²": Math.pow(1 / THOUSAND, 2),
696
734
  "cm²": Math.pow(1 / 100, 2),
697
- "km²": 1e6,
698
- hectare: Math.pow(100, 2),
699
- "in²": Math.pow(l, 2),
700
- "ft²": Math.pow(n, 2),
701
- "yd²": Math.pow(n * 3, 2),
702
- acre: V * Math.pow(n, 2),
703
- "mile²": Math.pow(v * n, 2)
735
+ "km²": MILLION,
736
+ "hectare": Math.pow(100, 2),
737
+ "in²": Math.pow(INCH_METER, 2),
738
+ "ft²": Math.pow(FOOT_METER, 2),
739
+ "yd²": Math.pow(FOOT_METER * 3, 2),
740
+ "acre": ACRE_FOOT2 * Math.pow(FOOT_METER, 2),
741
+ "mile²": Math.pow(MILE_FOOT * FOOT_METER, 2)
704
742
  },
705
743
  /* 105 */
706
744
  "Volume / Section Modulus": {
707
745
  "m³": 1,
708
- "µm³": Math.pow(1 / 1e6, 3),
709
- "mm³": Math.pow(1 / 1e3, 3),
746
+ "µm³": Math.pow(1 / MILLION, 3),
747
+ "mm³": Math.pow(1 / THOUSAND, 3),
710
748
  "cm³": Math.pow(1 / 100, 3),
711
- L: 1 / 1e3,
712
- ml: 1 / 1e6,
713
- "km³": Math.pow(1e3, 3),
714
- "in³": Math.pow(l, 3),
715
- "ft³": Math.pow(n, 3),
716
- "yd³": Math.pow(n * 3, 3),
717
- "gal(UK-imperial)": d * 1 / 1e3,
718
- "gal(US-liquid)": p * Math.pow(l, 3),
719
- "gal(US-dry)": I * Math.pow(l, 3),
720
- "pint(UK-imperial)": g * d * 1 / 1e3,
721
- "pint(US-liquid)": g * p * Math.pow(l, 3),
722
- "pint(US-dry)": g * I * Math.pow(l, 3),
723
- "fluid ounce(UK-imperial)": F * g * d / 1e3,
724
- "fluid ounce(US-liquid)": G * g * p * Math.pow(l, 3),
725
- "bushel(UK-imperial)": B * d / 1e3,
726
- "bushel(US-dry)": _ * I * Math.pow(l, 3),
727
- "cup(US-liquid)": q * p * Math.pow(l, 3),
728
- "cup(Legal)": z * Math.pow(0.01, 3),
729
- "cup(Metric)": K * Math.pow(0.01, 3),
730
- "cup(Imperial)": Q * F * g * d / 1e3
749
+ "L": 1 / THOUSAND,
750
+ "ml": 1 / MILLION,
751
+ "km³": Math.pow(THOUSAND, 3),
752
+ "in³": Math.pow(INCH_METER, 3),
753
+ "ft³": Math.pow(FOOT_METER, 3),
754
+ "yd³": Math.pow(FOOT_METER * 3, 3),
755
+ "gal(UK-imperial)": GALLON_UK_IMPERIAL_LITRE * 1 / 1e3,
756
+ "gal(US-liquid)": GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3),
757
+ "gal(US-dry)": GALLON_US_DRY_IN3 * Math.pow(INCH_METER, 3),
758
+ "pint(UK-imperial)": PINT_GALLON * GALLON_UK_IMPERIAL_LITRE * 1 / 1e3,
759
+ "pint(US-liquid)": PINT_GALLON * GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3),
760
+ "pint(US-dry)": PINT_GALLON * GALLON_US_DRY_IN3 * Math.pow(INCH_METER, 3),
761
+ "fluid ounce(UK-imperial)": OUNCE_FLUID_PINT_UK_IMPERIAL * PINT_GALLON * GALLON_UK_IMPERIAL_LITRE / 1e3,
762
+ "fluid ounce(US-liquid)": OUNCE_FLUID_PINT_US_LIQUID * PINT_GALLON * GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3),
763
+ "bushel(UK-imperial)": BUSHEL_GALLON_UK_IMPERIAL * GALLON_UK_IMPERIAL_LITRE / 1e3,
764
+ "bushel(US-dry)": BUSHEL_GALLON_US_DRY * GALLON_US_DRY_IN3 * Math.pow(INCH_METER, 3),
765
+ "cup(US-liquid)": CUP_US_GALLON_LIQUID * GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3),
766
+ "cup(Legal)": CUP_LEGAL_ML_LIQUID * Math.pow(0.01, 3),
767
+ "cup(Metric)": CUP_METRIC_ML_LIQUID * Math.pow(0.01, 3),
768
+ "cup(Imperial)": CUP_IMPERIAL_OUNCE_LIQUID * OUNCE_FLUID_PINT_UK_IMPERIAL * PINT_GALLON * GALLON_UK_IMPERIAL_LITRE / 1e3
731
769
  },
732
770
  /* 106 */
733
771
  "Polar Moment of Inertia": {
734
772
  "m⁴": 1,
735
773
  "mm⁴": 1e-12,
736
774
  "cm⁴": 1e-8,
737
- "in⁴": Math.pow(l, 4),
738
- "ft⁴": Math.pow(n, 4)
775
+ "in⁴": Math.pow(INCH_METER, 4),
776
+ "ft⁴": Math.pow(FOOT_METER, 4)
739
777
  },
740
778
  /* 1060 */
741
779
  "Moment of Inertia": {
742
780
  "kg⋅m²": 1,
743
- "g⋅cm²": 1 / (1e3 * 1e4),
744
- "g⋅mm²": 1 / (1e3 * 1e6),
745
- "lbm⋅ft²": o * Math.pow(n, 2),
746
- "lbm⋅in²": o * Math.pow(l, 2),
747
- "oz⋅in²": o / 16 * Math.pow(l, 2)
781
+ "g⋅cm²": 1 / (THOUSAND * 1e4),
782
+ "g⋅mm²": 1 / (THOUSAND * MILLION),
783
+ "lbm⋅ft²": POUNDMASS_KG * Math.pow(FOOT_METER, 2),
784
+ "lbm⋅in²": POUNDMASS_KG * Math.pow(INCH_METER, 2),
785
+ "oz⋅in²": POUNDMASS_KG / 16 * Math.pow(INCH_METER, 2)
748
786
  },
749
787
  /* 107 */
750
788
  Force: {
751
- N: 1,
752
- kN: 1e3,
753
- MN: 1e6,
754
- kgf: r,
755
- lb: o * r,
756
- lbf: o * r,
757
- "kip[kilo pound]": 1e3 * o * r
789
+ "N": 1,
790
+ "kN": THOUSAND,
791
+ "MN": MILLION,
792
+ "kgf": GRAVITY_SI,
793
+ "lb": POUNDMASS_KG * GRAVITY_SI,
794
+ "lbf": POUNDMASS_KG * GRAVITY_SI,
795
+ "kip[kilo pound]": THOUSAND * POUNDMASS_KG * GRAVITY_SI
758
796
  },
759
797
  /* 108 */
760
798
  Angle: {
761
- radian: 1,
762
- rad: 1,
799
+ "radian": 1,
800
+ "rad": 1,
763
801
  "deg°": Math.PI / 180,
764
- revolution: Math.PI * 2
802
+ "revolution": Math.PI * 2
765
803
  },
766
804
  /* 1081 */
767
805
  "Solid Angle": {
@@ -771,15 +809,15 @@ const o = 0.45359237, r = 9.80665, v = 5280, l = 25.4 / 1e3, n = 12 * l, W = 185
771
809
  /* 1090 */
772
810
  "BMI-Body Mass Index/Ballistic Coefficient": {
773
811
  "kg/m²": 1,
774
- "g/cm²": 1 / 1e3 / Math.pow(0.01, 2),
775
- "g/mm²": 1 / 1e3 / Math.pow(1e-3, 2),
776
- "tonne/m²": 1e3,
777
- "lbm/yd²": o / Math.pow(n * 3, 2),
778
- "lbm/ft²": o / Math.pow(n, 2),
779
- "lbm/in²": o / Math.pow(l, 2),
780
- "oz/yd²": o / 16 / Math.pow(3 * n, 2),
781
- "oz/ft²": o / 16 / Math.pow(n, 2),
782
- "oz/in²": o / 16 / Math.pow(l, 2)
812
+ "g/cm²": 1 / THOUSAND / Math.pow(0.01, 2),
813
+ "g/mm²": 1 / THOUSAND / Math.pow(1e-3, 2),
814
+ "tonne/m²": THOUSAND,
815
+ "lbm/yd²": POUNDMASS_KG / Math.pow(FOOT_METER * 3, 2),
816
+ "lbm/ft²": POUNDMASS_KG / Math.pow(FOOT_METER, 2),
817
+ "lbm/in²": POUNDMASS_KG / Math.pow(INCH_METER, 2),
818
+ "oz/yd²": POUNDMASS_KG / 16 / Math.pow(3 * FOOT_METER, 2),
819
+ "oz/ft²": POUNDMASS_KG / 16 / Math.pow(FOOT_METER, 2),
820
+ "oz/in²": POUNDMASS_KG / 16 / Math.pow(INCH_METER, 2)
783
821
  },
784
822
  /* 1091 */
785
823
  Density: {
@@ -787,269 +825,348 @@ const o = 0.45359237, r = 9.80665, v = 5280, l = 25.4 / 1e3, n = 12 * l, W = 185
787
825
  "kg/L": 1e3,
788
826
  "g/cm³": 1 / 1e3 / Math.pow(0.01, 3),
789
827
  "g/mm³": 1 / 1e3 / Math.pow(1e-3, 3),
790
- "lbm/ft³": o / Math.pow(n, 3),
791
- "lbm/in³": o / Math.pow(l, 3)
828
+ "lbm/ft³": POUNDMASS_KG / Math.pow(FOOT_METER, 3),
829
+ "lbm/in³": POUNDMASS_KG / Math.pow(INCH_METER, 3)
792
830
  },
793
831
  /* 110 */
794
832
  Energy: {
795
833
  "J[Joule]": 1,
796
- kJ: 1e3,
797
- MJ: 1e6,
798
- GJ: 1e9,
799
- "TNT Equivalent[kiloton]": 1e9 * b,
834
+ "kJ": THOUSAND,
835
+ "MJ": MILLION,
836
+ "GJ": BILLION,
837
+ "TNT Equivalent[kiloton]": 1e9 * CALORIE_TH_J,
800
838
  // 1e9 = 1000000000.0,
801
- Btu: f,
802
- "MM Btu": f * 1e6,
803
- "calorie(IT)": w,
839
+ "Btu": BTU_J,
840
+ "MM Btu": BTU_J * MILLION,
841
+ "calorie(IT)": CALORIE_IT_J,
804
842
  // 4.1868J
805
- "kilo-calorie(IT)": w * 1e3,
806
- "calorie(TH)": b,
843
+ "kilo-calorie(IT)": CALORIE_IT_J * THOUSAND,
844
+ "calorie(TH)": CALORIE_TH_J,
807
845
  // 4.184J
808
- "kilo-calorie(TH)": b * 1e3,
809
- "HP Hour": R * 3600,
810
- Wh: 3600,
811
- kWh: 3600 * 1e3,
812
- "eV{electron-volt]": 1 / j
846
+ "kilo-calorie(TH)": CALORIE_TH_J * 1e3,
847
+ "HP Hour": HP_W * 3600,
848
+ "Wh": 3600,
849
+ "kWh": 3600 * THOUSAND,
850
+ "eV{electron-volt]": 1 / J_EV
813
851
  },
814
852
  /* 111 */
815
853
  Power: {
816
- W: 1,
817
- kW: 1e3,
818
- MW: 1e6,
819
- "GW[Gigawatt]": 1e9,
820
- "Btu/h": f / 3600,
821
- "Btu/minute": f / 60,
822
- "MM Btu/h": f * 1e6 / 3600,
823
- "Btu(AC)": f / 3600,
824
- "calorie(IT)/second": w,
825
- "calorie(IT)/minute": w / 60,
826
- "kilo-calorie(IT)/hour": w * 1e3 / 3600,
827
- "calorie(TH)/second": b,
828
- "calorie(TH)/minute": b / 60,
829
- "kilo-calorie(TH)/hour": b * 1e3 / 3600,
830
- "lb-ft/second": o * r * n,
831
- "lb-ft/minute": o * r * n / 60,
832
- HP: R,
854
+ "W": 1,
855
+ "kW": THOUSAND,
856
+ "MW": MILLION,
857
+ "GW[Gigawatt]": BILLION,
858
+ "Btu/h": BTU_J / 3600,
859
+ "Btu/minute": BTU_J / 60,
860
+ "MM Btu/h": BTU_J * MILLION / 3600,
861
+ "Btu(AC)": BTU_J / 3600,
862
+ "calorie(IT)/second": CALORIE_IT_J,
863
+ "calorie(IT)/minute": CALORIE_IT_J / 60,
864
+ "kilo-calorie(IT)/hour": CALORIE_IT_J * THOUSAND / 3600,
865
+ "calorie(TH)/second": CALORIE_TH_J,
866
+ "calorie(TH)/minute": CALORIE_TH_J / 60,
867
+ "kilo-calorie(TH)/hour": CALORIE_TH_J * THOUSAND / 3600,
868
+ "lb-ft/second": POUNDMASS_KG * GRAVITY_SI * FOOT_METER,
869
+ "lb-ft/minute": POUNDMASS_KG * GRAVITY_SI * FOOT_METER / 60,
870
+ "HP": HP_W,
833
871
  "J/second": 1,
834
872
  "J/minute": 1 / 60,
835
873
  "J/h": 1 / 3600,
836
- "MJ/h": 1e6 / 3600,
837
- "kJ/minute": 1e3 / 60
874
+ "MJ/h": MILLION / 3600,
875
+ "kJ/minute": THOUSAND / 60
838
876
  },
839
877
  /* 112 */
840
878
  "Torque, Moment of Force": {
841
- Nm: 1,
842
- kNm: 1e3,
843
- "lb-in": o * r * l,
844
- "kip-in": 1e3 * o * r * l,
845
- "lb-ft": o * r * n,
846
- "oz-in": o / 16 * r * l,
847
- "oz-ft": o / 16 * r * n
879
+ "Nm": 1,
880
+ "kNm": THOUSAND,
881
+ "lb-in": POUNDMASS_KG * GRAVITY_SI * INCH_METER,
882
+ "kip-in": THOUSAND * POUNDMASS_KG * GRAVITY_SI * INCH_METER,
883
+ "lb-ft": POUNDMASS_KG * GRAVITY_SI * FOOT_METER,
884
+ "oz-in": POUNDMASS_KG / 16 * GRAVITY_SI * INCH_METER,
885
+ "oz-ft": POUNDMASS_KG / 16 * GRAVITY_SI * FOOT_METER
848
886
  },
849
887
  /* 1130 */
850
888
  "Pressure/Stress": {
851
- Pa: 1,
852
- kPa: 1e3,
853
- MPa: 1e6,
854
- GPa: 1e9,
855
- bar: 100 * 1e3,
856
- mbar: 100,
857
- atm: N,
858
- "mm HG": y,
859
- "cm HG": y * 10,
860
- "in HG": y * 25.4,
861
- "mm W.C.": 1 / 1e3 * 1e3 * r,
862
- "m W.C.": 1 * 1e3 * r,
863
- "in W.C.": l * 1e3 * r,
864
- psf: o * r / Math.pow(n, 2),
865
- psi: o * r / Math.pow(l, 2),
866
- ksi: o * r / Math.pow(l, 2) * 1e3,
867
- "ksi{kip/in²]": o * r / Math.pow(l, 2) * 1e3
889
+ "Pa": 1,
890
+ "kPa": THOUSAND,
891
+ "MPa": MILLION,
892
+ "GPa": BILLION,
893
+ "bar": 100 * THOUSAND,
894
+ "mbar": 100,
895
+ "atm": ATM_PA,
896
+ "mm HG": MMHG_PA,
897
+ "cm HG": MMHG_PA * 10,
898
+ "in HG": MMHG_PA * 25.4,
899
+ "mm W.C.": 1 / 1e3 * 1e3 * GRAVITY_SI,
900
+ "m W.C.": 1 * 1e3 * GRAVITY_SI,
901
+ "in W.C.": INCH_METER * 1e3 * GRAVITY_SI,
902
+ "psf": POUNDMASS_KG * GRAVITY_SI / Math.pow(FOOT_METER, 2),
903
+ "psi": POUNDMASS_KG * GRAVITY_SI / Math.pow(INCH_METER, 2),
904
+ "ksi": POUNDMASS_KG * GRAVITY_SI / Math.pow(INCH_METER, 2) * THOUSAND,
905
+ "ksi{kip/in²]": POUNDMASS_KG * GRAVITY_SI / Math.pow(INCH_METER, 2) * THOUSAND
868
906
  },
869
907
  /* 1131 */
870
908
  "Pressure Drop per Unit Length": {
871
909
  "Pa/m": 1,
872
910
  "Pascal/m": 1,
873
- "kPa/m": 1e3,
874
- "MPa/km": 1e6 / 1e3,
911
+ "kPa/m": THOUSAND,
912
+ "MPa/km": MILLION / THOUSAND,
875
913
  "bar/m": 1e5,
876
- "mbar/mm": 100 * 1e3,
877
- "atm/m": N,
878
- "mm HG/m": y,
879
- "in HG/ft": y * 25.4 / n,
880
- "mm W.C./m": 1 / 1e3 * 1e3 * r,
881
- "m W.C./m": 1e3 * r,
882
- "in W.C./ft": l * 1e3 * r / n,
883
- "in W.C./100 ft": l * 1e3 * r / n / 100,
884
- "psf/in": o * r / Math.pow(n, 2) / l,
885
- "psi/ft": o * r / Math.pow(n, 2) / n,
886
- "ksi/ft": o * r / Math.pow(n, 2) / n * 1e3,
887
- "Torr/ft": $ * N / n,
888
- "mTorr/m": $ * N / 1e3
914
+ "mbar/mm": 100 * THOUSAND,
915
+ "atm/m": ATM_PA,
916
+ "mm HG/m": MMHG_PA,
917
+ "in HG/ft": MMHG_PA * 25.4 / FOOT_METER,
918
+ "mm W.C./m": 1 / THOUSAND * THOUSAND * GRAVITY_SI,
919
+ "m W.C./m": THOUSAND * GRAVITY_SI,
920
+ "in W.C./ft": INCH_METER * THOUSAND * GRAVITY_SI / FOOT_METER,
921
+ "in W.C./100 ft": INCH_METER * THOUSAND * GRAVITY_SI / FOOT_METER / 100,
922
+ "psf/in": POUNDMASS_KG * GRAVITY_SI / Math.pow(FOOT_METER, 2) / INCH_METER,
923
+ "psi/ft": POUNDMASS_KG * GRAVITY_SI / Math.pow(FOOT_METER, 2) / FOOT_METER,
924
+ "ksi/ft": POUNDMASS_KG * GRAVITY_SI / Math.pow(FOOT_METER, 2) / FOOT_METER * THOUSAND,
925
+ "Torr/ft": TORR_ATM * ATM_PA / FOOT_METER,
926
+ "mTorr/m": TORR_ATM * ATM_PA / THOUSAND
889
927
  },
890
928
  /* 1132 */
891
929
  "Uniformly Distributed (Uniform Line) Load | Stiffness of Linear Spring": {
892
930
  "N/m": 1,
893
- "N/mm": 1e3,
894
- "kN/m": 1e3,
895
- "lb/ft": o * r / n,
896
- "kips/ft": 1e3 * o * r / n,
897
- "lb/in": o * r / l
931
+ "N/mm": THOUSAND,
932
+ "kN/m": THOUSAND,
933
+ "lb/ft": POUNDMASS_KG * GRAVITY_SI / FOOT_METER,
934
+ "kips/ft": THOUSAND * POUNDMASS_KG * GRAVITY_SI / FOOT_METER,
935
+ "lb/in": POUNDMASS_KG * GRAVITY_SI / INCH_METER
898
936
  },
899
937
  /* 1133 */
900
938
  "Stiffness of Rotary Spring": {
901
939
  "N⋅m/rad": 1,
902
940
  "N⋅m/deg°": 1 / Math.PI * 180,
903
- "N⋅mm/rad": 1 / 1e3,
904
- "N⋅mm/deg°": 1 / 1e3 / Math.PI * 180,
905
- "lb-ft/rad": o * r * n,
906
- "lb-ft/deg°": o * r * n / (Math.PI / 180),
907
- "lb-in/rad": o * r * l,
908
- "lb-in/deg°": o * r * l / (Math.PI / 180)
941
+ "N⋅mm/rad": 1 / THOUSAND,
942
+ "N⋅mm/deg°": 1 / THOUSAND / Math.PI * 180,
943
+ "lb-ft/rad": POUNDMASS_KG * GRAVITY_SI * FOOT_METER,
944
+ "lb-ft/deg°": POUNDMASS_KG * GRAVITY_SI * FOOT_METER / (Math.PI / 180),
945
+ "lb-in/rad": POUNDMASS_KG * GRAVITY_SI * INCH_METER,
946
+ "lb-in/deg°": POUNDMASS_KG * GRAVITY_SI * INCH_METER / (Math.PI / 180)
909
947
  },
910
948
  /* 114 */
911
949
  "Flow Rate (Volume)": {
912
950
  "m³/s": 1,
913
951
  "m³/min": 1 / 60,
914
952
  "m³/h": 1 / 3600,
915
- "L/s": 1 / 1e3,
916
- "L/min": 1 / 1e3 / 60,
917
- "L/h": 1 / 1e3 / 3600,
953
+ "L/s": 1 / THOUSAND,
954
+ "L/min": 1 / THOUSAND / 60,
955
+ "L/h": 1 / THOUSAND / 3600,
918
956
  "cm³/s": 1e-6,
919
957
  "cm³/min": 1e-6 / 60,
920
- "in³/s": Math.pow(l, 3),
921
- "in³/min": Math.pow(l, 3) / 60,
922
- "ft³/s": Math.pow(n, 3),
923
- CFM: Math.pow(n, 3) / 60,
924
- "CFM[ft³/min]": Math.pow(n, 3) / 60,
925
- CFH: Math.pow(n, 3) / 3600,
926
- "CFH[ft³/h]": Math.pow(n, 3) / 3600,
927
- "yd³/min": Math.pow(n * 3, 3) / 60,
928
- "yd³/h": Math.pow(n * 3, 3) / 3600,
929
- "gpm(US)": p * Math.pow(l, 3) / 60,
930
- "gph(US)": p * Math.pow(l, 3) / 3600,
931
- "bushel(UK-imperial)/h": B * d / 1e3 / 3600,
932
- "bushel(US)/h": _ * I * Math.pow(l, 3) / 3600
958
+ "in³/s": Math.pow(INCH_METER, 3),
959
+ "in³/min": Math.pow(INCH_METER, 3) / 60,
960
+ "ft³/s": Math.pow(FOOT_METER, 3),
961
+ "CFM": Math.pow(FOOT_METER, 3) / 60,
962
+ "CFM[ft³/min]": Math.pow(FOOT_METER, 3) / 60,
963
+ "CFH": Math.pow(FOOT_METER, 3) / 3600,
964
+ "CFH[ft³/h]": Math.pow(FOOT_METER, 3) / 3600,
965
+ "yd³/min": Math.pow(FOOT_METER * 3, 3) / 60,
966
+ "yd³/h": Math.pow(FOOT_METER * 3, 3) / 3600,
967
+ "gpm(US)": GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3) / 60,
968
+ "gph(US)": GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3) / 3600,
969
+ "bushel(UK-imperial)/h": BUSHEL_GALLON_UK_IMPERIAL * GALLON_UK_IMPERIAL_LITRE / 1e3 / 3600,
970
+ "bushel(US)/h": BUSHEL_GALLON_US_DRY * GALLON_US_DRY_IN3 * Math.pow(INCH_METER, 3) / 3600
933
971
  },
934
972
  /* 115 */
935
973
  "Flow Rate (Mass)": {
936
974
  "kg/s": 1,
937
975
  "kg/min": 1 / 60,
938
976
  "kg/h": 1 / 3600,
939
- "g/s": 1 / 1e3,
940
- "g/min": 1 / 1e3 / 60,
941
- "g/h": 1 / 1e3 / 3600,
942
- "slug/s": T,
943
- "slug/min": T / 60,
944
- "slug/h": T / 3600,
945
- "lbm/s": o,
946
- "lbm/min": o / 60,
947
- "lbm/h": o / 3600,
948
- "oz/s": o / 16,
949
- "oz/min": o / 16 / 60,
950
- "oz/h": o / 16 / 3600,
951
- "tonne/h": 1e3 / 3600,
952
- "short ton/h": 2e3 * o / 3600,
953
- "long ton/h": 2240 * o / 3600
977
+ "g/s": 1 / THOUSAND,
978
+ "g/min": 1 / THOUSAND / 60,
979
+ "g/h": 1 / THOUSAND / 3600,
980
+ "slug/s": SLUG_KG,
981
+ "slug/min": SLUG_KG / 60,
982
+ "slug/h": SLUG_KG / 3600,
983
+ "lbm/s": POUNDMASS_KG,
984
+ "lbm/min": POUNDMASS_KG / 60,
985
+ "lbm/h": POUNDMASS_KG / 3600,
986
+ "oz/s": POUNDMASS_KG / 16,
987
+ "oz/min": POUNDMASS_KG / 16 / 60,
988
+ "oz/h": POUNDMASS_KG / 16 / 3600,
989
+ "tonne/h": THOUSAND / 3600,
990
+ "short ton/h": 2e3 * POUNDMASS_KG / 3600,
991
+ "long ton/h": 2240 * POUNDMASS_KG / 3600
954
992
  },
955
993
  /* 117 */
956
994
  "Speed / Velocity (Linear)": {
957
995
  "m/s": 1,
958
- "mm/s": 1 / 1e3,
996
+ "mm/s": 1 / THOUSAND,
959
997
  "km/s": 1,
960
- "mm/min": 1 / 1e3 / 60,
998
+ "mm/min": 1 / THOUSAND / 60,
961
999
  "m/min": 1 / 60,
962
- "km/min": 1e3 / 60,
963
- "mm/h": 1 / 1e3 / 3600,
1000
+ "km/min": THOUSAND / 60,
1001
+ "mm/h": 1 / THOUSAND / 3600,
964
1002
  "m/h": 1 / 3600,
965
- "km/h": 1e3 / 3600,
966
- "in/s": l,
967
- fps: n,
968
- "fps[ft/second]": n,
969
- fpm: n / 60,
1003
+ "km/h": THOUSAND / 3600,
1004
+ "in/s": INCH_METER,
1005
+ "fps": FOOT_METER,
1006
+ "fps[ft/second]": FOOT_METER,
1007
+ "fpm": FOOT_METER / 60,
970
1008
  // clear version
971
- "fpm[ft/minute]": n / 60,
1009
+ "fpm[ft/minute]": FOOT_METER / 60,
972
1010
  // redundant version
973
- "mph[mile/h]": v * n / 3600,
974
- "knot[kn, kt, or nautical mile/h]": W / 3600
1011
+ "mph[mile/h]": MILE_FOOT * FOOT_METER / 3600,
1012
+ "knot[kn, kt, or nautical mile/h]": NM_METER / 3600
975
1013
  },
976
1014
  /* 126 */
977
1015
  "Electrical Potential Difference (Voltage)": {
978
- V: 1,
979
- Volt: 1,
1016
+ "V": 1,
1017
+ "Volt": 1,
980
1018
  "joule/coulomb": 1,
981
1019
  "J/C": 1,
982
- µV: 1 / 1e6,
983
- mV: 1 / 1e3,
984
- kV: 1e3,
985
- MV: 1e6
1020
+ "µV": 1 / MILLION,
1021
+ "mV": 1 / THOUSAND,
1022
+ "kV": THOUSAND,
1023
+ "MV": MILLION
1024
+ }
1025
+ };
1026
+ const getUnitCategory = (unit) => {
1027
+ console.log("getUnitCategory called with unit:", unit);
1028
+ if (!unit) {
1029
+ console.warn("Unit is undefined or null");
1030
+ return "Custom";
1031
+ }
1032
+ for (const category in UNITS) {
1033
+ if (UNITS[category].includes(unit)) {
1034
+ console.log(`Category found for unit ${unit}:`, category);
1035
+ return category;
1036
+ }
986
1037
  }
987
- }, k = (a) => {
988
- if (console.log("getUnitCategory called with unit:", a), !a)
989
- return console.warn("Unit is undefined or null"), "Custom";
990
- for (const t in U)
991
- if (U[t].includes(a))
992
- return console.log(`Category found for unit ${a}:`, t), t;
993
- return console.warn(`No category found for unit: ${a}`), "Custom";
994
- }, u = (a, t, e, i) => {
995
- if (t === "ft-in" && e !== "ft-in")
996
- return Y(a, e);
997
- if (t !== "ft-in" && e === "ft-in")
998
- return X(a, t);
999
- if (i !== "Temperature") {
1000
- const s = M[i][t] / M[i][e];
1001
- return a * s;
1038
+ console.warn(`No category found for unit: ${unit}`);
1039
+ return "Custom";
1040
+ };
1041
+ const convertValue = (value, fromUnit, toUnit, unitCategory) => {
1042
+ if (fromUnit === "ft-in" && toUnit !== "ft-in") {
1043
+ return convertFromFeetInches(value, toUnit);
1044
+ } else if (fromUnit !== "ft-in" && toUnit === "ft-in") {
1045
+ return convertToFeetInches(value, fromUnit);
1046
+ } else if (unitCategory !== "Temperature") {
1047
+ const c = CONVERSION_FACTORS[unitCategory][fromUnit] / CONVERSION_FACTORS[unitCategory][toUnit];
1048
+ return value * c;
1049
+ } else {
1050
+ const Cf0 = CONVERSION_FACTORS[unitCategory][fromUnit].c0;
1051
+ const Cf1 = CONVERSION_FACTORS[unitCategory][fromUnit].c1;
1052
+ const Ct0 = CONVERSION_FACTORS[unitCategory][toUnit].c0;
1053
+ const Ct1 = CONVERSION_FACTORS[unitCategory][toUnit].c1;
1054
+ return (value * Cf0 + Cf1 - Ct1) / Ct0;
1055
+ }
1056
+ };
1057
+ const formatValue = (value, decimalPlaces) => {
1058
+ let formattedValue;
1059
+ if (Number.isInteger(value)) {
1060
+ formattedValue = value.toString();
1002
1061
  } else {
1003
- const s = M[i][t].c0, m = M[i][t].c1, c = M[i][e].c0, h = M[i][e].c1;
1004
- return (a * s + m - h) / c;
1062
+ formattedValue = value.toFixed(decimalPlaces).replace(/\.?0+$/, "");
1063
+ }
1064
+ if (Math.abs(parseFloat(formattedValue)) >= 1e3) {
1065
+ const parts = formattedValue.split(".");
1066
+ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
1067
+ formattedValue = parts.join(".");
1068
+ }
1069
+ return formattedValue;
1070
+ };
1071
+ const parseFeetInchesValue = (valueString) => {
1072
+ const regexFeetInches = /(\d+)\'(\s*-\s*)?(\d+)?(\s+)?(\d+)?\/?(\d+)?/;
1073
+ const regexFeet = /(\d+)\'/;
1074
+ const regexInches = /(\d+)/;
1075
+ let match = valueString.match(regexFeetInches);
1076
+ if (match) {
1077
+ const feet = parseInt(match[1]) || 0;
1078
+ const inches = parseInt(match[3]) || 0;
1079
+ const numerator = parseInt(match[5]) || 0;
1080
+ const denominator = parseInt(match[6]) || 1;
1081
+ return calculateTotalInches(feet, inches, numerator, denominator);
1082
+ }
1083
+ match = valueString.match(regexFeet);
1084
+ if (match) {
1085
+ const feet = parseInt(match[1]) || 0;
1086
+ return calculateTotalInches(feet, 0, 0, 1);
1087
+ }
1088
+ match = valueString.match(regexInches);
1089
+ if (match) {
1090
+ const inches = parseInt(match[1]) || 0;
1091
+ return calculateTotalInches(0, inches, 0, 1);
1092
+ }
1093
+ return parseFloat(valueString);
1094
+ };
1095
+ const calculateTotalInches = (feet, inches, numerator, denominator) => {
1096
+ return feet * 12 + inches + numerator / denominator;
1097
+ };
1098
+ const formatFeetInchesValue = (totalInches, inchPrecision = '1/16"') => {
1099
+ if (totalInches < 0) {
1100
+ return `-${formatFeetInchesValue(-totalInches, inchPrecision)}`;
1101
+ }
1102
+ const precisionDenominator = parseInt(inchPrecision.split("/")[1].replace('"', ""));
1103
+ let feet = Math.floor(totalInches / 12);
1104
+ let inches = Math.floor(totalInches % 12);
1105
+ const fractionalInches = totalInches - Math.floor(totalInches);
1106
+ let fractionStr = "";
1107
+ if (fractionalInches > 0) {
1108
+ if (inchPrecision !== 0) {
1109
+ let numerator = Math.round(fractionalInches * precisionDenominator);
1110
+ const gcd = (a, b) => b ? gcd(b, a % b) : a;
1111
+ const commonDivisor = gcd(numerator, precisionDenominator);
1112
+ fractionStr = ` ${numerator / commonDivisor}/${precisionDenominator / commonDivisor}`;
1113
+ if (fractionStr.trim() === "1/1") {
1114
+ inches++;
1115
+ if (inches >= 12) {
1116
+ feet++;
1117
+ inches -= 12;
1118
+ }
1119
+ fractionStr = "";
1120
+ }
1121
+ }
1005
1122
  }
1006
- }, O = (a, t) => {
1007
- let e;
1008
- if (Number.isInteger(a) ? e = a.toString() : e = a.toFixed(t).replace(/\.?0+$/, ""), Math.abs(parseFloat(e)) >= 1e3) {
1009
- const i = e.split(".");
1010
- i[0] = i[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","), e = i.join(".");
1123
+ let output = "";
1124
+ if (feet > 0) {
1125
+ output += `${feet}'`;
1011
1126
  }
1012
- return e;
1013
- }, D = (a) => {
1014
- const t = /(\d+)\'(\s*-\s*)?(\d+)?(\s+)?(\d+)?\/?(\d+)?/, e = /(\d+)\'/, i = /(\d+)/;
1015
- let s = a.match(t);
1016
- if (s) {
1017
- const m = parseInt(s[1]) || 0, c = parseInt(s[3]) || 0, h = parseInt(s[5]) || 0, L = parseInt(s[6]) || 1;
1018
- return H(m, c, h, L);
1127
+ if (feet > 0 && (inches > 0 || fractionStr !== "")) {
1128
+ output += `-`;
1019
1129
  }
1020
- if (s = a.match(e), s) {
1021
- const m = parseInt(s[1]) || 0;
1022
- return H(m, 0, 0, 1);
1130
+ if (inches > 0) {
1131
+ output += `${inches}`;
1023
1132
  }
1024
- if (s = a.match(i), s) {
1025
- const m = parseInt(s[1]) || 0;
1026
- return H(0, m, 0, 1);
1133
+ if (fractionStr !== "") {
1134
+ output += fractionStr;
1027
1135
  }
1028
- return parseFloat(a);
1029
- }, H = (a, t, e, i) => a * 12 + t + e / i, C = (a, t = '1/16"') => {
1030
- if (a < 0)
1031
- return `-${C(-a, t)}`;
1032
- const e = parseInt(t.split("/")[1].replace('"', ""));
1033
- let i = Math.floor(a / 12), s = Math.floor(a % 12);
1034
- const m = a - Math.floor(a);
1035
- let c = "";
1036
- if (m > 0 && t !== 0) {
1037
- let L = Math.round(m * e);
1038
- const P = (x, S) => S ? P(S, x % S) : x, E = P(L, e);
1039
- c = ` ${L / E}/${e / E}`, c.trim() === "1/1" && (s++, s >= 12 && (i++, s -= 12), c = "");
1136
+ if (inches > 0 || fractionStr !== "") {
1137
+ output += '"';
1040
1138
  }
1041
- let h = "";
1042
- return i > 0 && (h += `${i}'`), i > 0 && (s > 0 || c !== "") && (h += "-"), s > 0 && (h += `${s}`), c !== "" && (h += c), (s > 0 || c !== "") && (h += '"'), h.trim();
1043
- }, Y = (a, t) => {
1044
- const e = a * 0.0254;
1045
- return u(e, "m", t, "Length");
1046
- }, X = (a, t) => u(a, t, "m", "Length") / 0.0254;
1047
- class J extends HTMLElement {
1139
+ return output.trim();
1140
+ };
1141
+ const convertFromFeetInches = (totalInches, toUnit) => {
1142
+ const inchesInMeters = totalInches * 0.0254;
1143
+ return convertValue(inchesInMeters, "m", toUnit, "Length");
1144
+ };
1145
+ const convertToFeetInches = (value, fromUnit) => {
1146
+ const valueInMeters = convertValue(value, fromUnit, "m", "Length");
1147
+ return valueInMeters / 0.0254;
1148
+ };
1149
+ class PhysicalQuantity extends HTMLElement {
1048
1150
  constructor() {
1049
- super(), this.attachShadow({ mode: "open" }), this.tooltipTimeout = null, this.unitCategory = "", this.e3dLogoUrl = "https://firebasestorage.googleapis.com/v0/b/auto-calc-80237.appspot.com/o/shared%2Fassets%2Fimages%2Fe3d-logo2.png?alt=media&token=7064f466-6168-4b8a-b921-4e86115cb492", console.log("PhysicalQuantity constructor called");
1151
+ super();
1152
+ this.attachShadow({ mode: "open" });
1153
+ this.unitCategory = "";
1154
+ console.log("PhysicalQuantity constructor called");
1050
1155
  }
1051
1156
  connectedCallback() {
1052
- console.log("connectedCallback called"), this.unit = this.getAttribute("unit"), console.log("Initial unit:", this.unit), this.updateUnitCategory(), this.inputValue = this.getAttribute("value"), console.log("Initial inputValue:", this.inputValue), this.value = this.parseValue(this.inputValue, this.unit), console.log("Parsed value:", this.value), this.decimalPlaces = parseInt(this.getAttribute("decimal-places")) || 2, this.showUnitArrow = !this.hasAttribute("show-unit-arrow") || this.getAttribute("show-unit-arrow") === "true", console.log("Initial state:", { unit: this.unit, value: this.value, unitCategory: this.unitCategory, decimalPlaces: this.decimalPlaces, showUnitArrow: this.showUnitArrow }), this.render(), this.attachEventListeners();
1157
+ console.log("connectedCallback called");
1158
+ this.unit = this.getAttribute("unit");
1159
+ console.log("Initial unit:", this.unit);
1160
+ this.updateUnitCategory();
1161
+ this.inputValue = this.getAttribute("value");
1162
+ console.log("Initial inputValue:", this.inputValue);
1163
+ this.value = this.parseValue(this.inputValue, this.unit);
1164
+ console.log("Parsed value:", this.value);
1165
+ this.decimalPlaces = parseInt(this.getAttribute("decimal-places")) || 2;
1166
+ this.showUnitArrow = !this.hasAttribute("show-unit-arrow") || this.getAttribute("show-unit-arrow") === "true";
1167
+ console.log("Initial state:", { unit: this.unit, value: this.value, unitCategory: this.unitCategory, decimalPlaces: this.decimalPlaces, showUnitArrow: this.showUnitArrow });
1168
+ this.render();
1169
+ this.attachEventListeners();
1053
1170
  }
1054
1171
  disconnectedCallback() {
1055
1172
  this.removeEventListeners();
@@ -1057,42 +1174,76 @@ class J extends HTMLElement {
1057
1174
  static get observedAttributes() {
1058
1175
  return ["value", "unit", "decimal-places", "show-unit-arrow"];
1059
1176
  }
1060
- attributeChangedCallback(t, e, i) {
1061
- if (console.log(`attributeChangedCallback called: ${t}`, { oldValue: e, newValue: i }), t === "value")
1062
- this.inputValue = i || "0", this.value = this.parseValue(this.inputValue, this.unit), console.log("New value parsed:", this.value);
1063
- else if (t === "unit") {
1064
- const s = this.unit, m = this.unitCategory;
1065
- this.unit = i || "mm", this.updateUnitCategory(), s !== this.unit && (m === this.unitCategory ? (console.log("Converting value:", { from: s, to: this.unit, value: this.value, unitCategory: this.unitCategory }), this.value = u({
1066
- value: this.value,
1067
- fromUnit: s,
1068
- toUnit: this.unit,
1069
- unitCategory: this.unitCategory
1070
- })) : console.log("Unit category changed, keeping original value"), console.log("New value:", this.value));
1071
- } else
1072
- t === "decimal-places" ? (this.decimalPlaces = parseInt(i) || 2, console.log("New decimal places:", this.decimalPlaces)) : t === "show-unit-arrow" && (this.showUnitArrow = i === null || i === "true", console.log("Show unit arrow:", this.showUnitArrow));
1177
+ attributeChangedCallback(name, oldValue, newValue) {
1178
+ console.log(`attributeChangedCallback called: ${name}`, { oldValue, newValue });
1179
+ if (name === "value") {
1180
+ this.inputValue = newValue || "0";
1181
+ this.value = this.parseValue(this.inputValue, this.unit);
1182
+ console.log("New value parsed:", this.value);
1183
+ } else if (name === "unit") {
1184
+ const oldUnit = this.unit;
1185
+ const oldCategory = this.unitCategory;
1186
+ this.unit = newValue || "mm";
1187
+ this.updateUnitCategory();
1188
+ if (oldUnit !== this.unit) {
1189
+ if (oldCategory === this.unitCategory) {
1190
+ console.log("Converting value:", { from: oldUnit, to: this.unit, value: this.value, unitCategory: this.unitCategory });
1191
+ this.value = convertValue({
1192
+ value: this.value,
1193
+ fromUnit: oldUnit,
1194
+ toUnit: this.unit,
1195
+ unitCategory: this.unitCategory
1196
+ });
1197
+ } else {
1198
+ console.log("Unit category changed, keeping original value");
1199
+ }
1200
+ console.log("New value:", this.value);
1201
+ }
1202
+ } else if (name === "decimal-places") {
1203
+ this.decimalPlaces = parseInt(newValue) || 2;
1204
+ console.log("New decimal places:", this.decimalPlaces);
1205
+ } else if (name === "show-unit-arrow") {
1206
+ this.showUnitArrow = newValue === null || newValue === "true";
1207
+ console.log("Show unit arrow:", this.showUnitArrow);
1208
+ }
1073
1209
  this.render();
1074
1210
  }
1075
1211
  updateUnitCategory() {
1076
- console.log("updateUnitCategory called with unit:", this.unit), this.unitCategory = k(this.unit), console.log("Updated unit category:", this.unitCategory);
1212
+ console.log("updateUnitCategory called with unit:", this.unit);
1213
+ this.unitCategory = getUnitCategory(this.unit);
1214
+ console.log("Updated unit category:", this.unitCategory);
1077
1215
  }
1078
- parseValue(t, e) {
1079
- if (console.log("parseValue called with:", { value: t, unit: e }), typeof t == "string" && t.trim() === "")
1080
- return console.log("Empty string value, returning 0"), 0;
1081
- const i = e === "ft-in" ? D(t) : parseFloat(t) || 0;
1082
- return console.log("Parsed value:", i), i;
1216
+ parseValue(value, unit) {
1217
+ console.log("parseValue called with:", { value, unit });
1218
+ if (typeof value === "string" && value.trim() === "") {
1219
+ console.log("Empty string value, returning 0");
1220
+ return 0;
1221
+ }
1222
+ const parsedValue = unit === "ft-in" ? parseFeetInchesValue(value) : parseFloat(value) || 0;
1223
+ console.log("Parsed value:", parsedValue);
1224
+ return parsedValue;
1083
1225
  }
1084
1226
  formatDisplayValue() {
1085
- return this.unit === "ft-in" ? C(this.value) : O(this.value, this.decimalPlaces);
1227
+ if (this.unit === "ft-in") {
1228
+ return formatFeetInchesValue(this.value);
1229
+ } else {
1230
+ return formatValue(this.value, this.decimalPlaces);
1231
+ }
1086
1232
  }
1087
- handleUnitChange(t) {
1088
- if (t.target.tagName === "SELECT") {
1089
- const e = t.target.value;
1090
- console.log("handleUnitChange:", { from: this.unit, to: e, value: this.value, unitCategory: this.unitCategory }), this.value = u(this.value, this.unit, e, this.unitCategory), console.log("Converted value:", this.value), this.unit = e, this.updateUnitCategory(), this.render();
1233
+ handleUnitChange(event) {
1234
+ if (event.target.tagName === "SELECT") {
1235
+ const newUnit = event.target.value;
1236
+ console.log("handleUnitChange:", { from: this.unit, to: newUnit, value: this.value, unitCategory: this.unitCategory });
1237
+ this.value = convertValue(this.value, this.unit, newUnit, this.unitCategory);
1238
+ console.log("Converted value:", this.value);
1239
+ this.unit = newUnit;
1240
+ this.updateUnitCategory();
1241
+ this.render();
1091
1242
  }
1092
1243
  this.updateDropdownWidth();
1093
1244
  }
1094
1245
  render() {
1095
- const t = this.formatDisplayValue();
1246
+ const formattedValue = this.formatDisplayValue();
1096
1247
  this.shadowRoot.innerHTML = `
1097
1248
  <style>
1098
1249
  :host {
@@ -1138,117 +1289,95 @@ class J extends HTMLElement {
1138
1289
  .unit-container select::-ms-expand {
1139
1290
  display: ${this.showUnitArrow ? "block" : "none"};
1140
1291
  }
1141
- /* Custom arrow styles */
1142
- /*
1143
- .unit-container::after {
1144
- content: '▼';
1145
- font-size: 0.7em;
1146
- color: red;
1147
- position: absolute;
1148
- right: 0.3em;
1149
- top: 50%;
1150
- transform: translateY(-50%);
1151
- pointer-events: none;
1152
- }
1153
- */
1154
- .tooltip {
1155
- position: absolute;
1156
- bottom: 100%;
1157
- left: 50%;
1158
- transform: translateX(-50%);
1159
- padding: 0;
1160
- display: none;
1161
- font-size: 12px;
1162
- pointer-events: none;
1163
- }
1164
- .unit-container:hover .tooltip {
1165
- display: block;
1166
- }
1167
- .tooltip a {
1168
- text-decoration: none;
1169
- color: blue;
1170
- }
1171
- .tooltip a:hover {
1172
- text-decoration: underline;
1173
- }
1174
1292
  </style>
1175
1293
 
1176
1294
  <div class="quantity">
1177
- <span class="value">${t}</span>
1295
+ <span class="value">${formattedValue}</span>
1178
1296
  <div class="unit-container">
1179
1297
  <select>
1180
- ${(U[this.unitCategory] || [this.unit]).map((e) => `<option value="${e}" ${e === this.unit ? "selected" : ""}>
1181
- ${e}</option>`).join("")}
1298
+ ${(UNITS[this.unitCategory] || [this.unit]).map((unit) => `<option value="${unit}" ${unit === this.unit ? "selected" : ""}>
1299
+ ${unit}</option>`).join("")}
1182
1300
  </select>
1183
-
1184
- ${this.showUnitArrow && this.unitCategory !== "Custom" ? `
1185
- <a class="tooltip" href="https://v2-docs.donwen.com/daily-calculations/unit-converter.html"
1186
- title="Unit Converter for All Categories" target="_blank">
1187
- <img src="${this.e3dLogoUrl}" width="12" />
1188
- </a>
1189
- ` : ""}
1190
-
1191
1301
  </div>
1192
1302
  </div>
1193
- `, this.updateDropdownWidth();
1303
+ `;
1304
+ this.updateDropdownWidth();
1194
1305
  }
1195
1306
  updateDropdownWidth() {
1196
- const t = this.shadowRoot.querySelector("select");
1197
- if (!t)
1307
+ const selectElement = this.shadowRoot.querySelector("select");
1308
+ if (!selectElement)
1198
1309
  return;
1199
- const e = document.createElement("span");
1200
- e.style.visibility = "hidden", e.style.position = "absolute", e.style.whiteSpace = "nowrap", e.style.font = window.getComputedStyle(t).font, document.body.appendChild(e), e.textContent = this.unit;
1201
- const i = e.offsetWidth;
1202
- document.body.removeChild(e);
1203
- const s = this.showUnitArrow ? 16 : 6, m = this.showUnitArrow ? 8 : 0;
1204
- let h = i + s + m + 2;
1205
- h = Math.max(h, 30), t.style.width = `${h}px`;
1310
+ const tempSpan = document.createElement("span");
1311
+ tempSpan.style.visibility = "hidden";
1312
+ tempSpan.style.position = "absolute";
1313
+ tempSpan.style.whiteSpace = "nowrap";
1314
+ tempSpan.style.font = window.getComputedStyle(selectElement).font;
1315
+ document.body.appendChild(tempSpan);
1316
+ tempSpan.textContent = this.unit;
1317
+ const textWidth = tempSpan.offsetWidth;
1318
+ document.body.removeChild(tempSpan);
1319
+ const selectPadding = this.showUnitArrow ? 16 : 6;
1320
+ const arrowWidth = this.showUnitArrow ? 8 : 0;
1321
+ const extraPadding = 2;
1322
+ let finalWidth = textWidth + selectPadding + arrowWidth + extraPadding;
1323
+ finalWidth = Math.max(finalWidth, 30);
1324
+ selectElement.style.width = `${finalWidth}px`;
1206
1325
  }
1207
1326
  attachEventListeners() {
1208
1327
  this.shadowRoot.addEventListener("change", this.handleUnitChange.bind(this));
1209
- const t = this.shadowRoot.querySelector(".unit-container");
1210
- t && (t.addEventListener("mouseover", this.handleUnitContainerMouseOver.bind(this)), t.addEventListener("mouseout", this.handleUnitContainerMouseOut.bind(this)));
1211
1328
  }
1212
1329
  removeEventListeners() {
1213
1330
  this.shadowRoot.removeEventListener("change", this.handleUnitChange.bind(this));
1214
- const t = this.shadowRoot.querySelector(".unit-container");
1215
- t && (t.removeEventListener("mouseover", this.handleUnitContainerMouseOver.bind(this)), t.removeEventListener("mouseout", this.handleUnitContainerMouseOut.bind(this)));
1216
- }
1217
- handleUnitContainerMouseOver() {
1218
- const t = this.shadowRoot.querySelector(".tooltip");
1219
- t && (this.tooltipTimeout = setTimeout(() => {
1220
- t.style.display = "block";
1221
- }, 1e3));
1222
- }
1223
- handleUnitContainerMouseOut() {
1224
- const t = this.shadowRoot.querySelector(".tooltip");
1225
- t && (setTimeout(() => {
1226
- t.style.display = "none";
1227
- }, 2e3), clearTimeout(this.tooltipTimeout));
1228
1331
  }
1229
1332
  }
1230
- class Z extends HTMLElement {
1333
+ class UcQtyPair extends HTMLElement {
1231
1334
  constructor() {
1232
- super(), this.attachShadow({ mode: "open" }), this.values = [], this.unit = "", this.unitCategory = "", this.decimalPlaces = 2, this.showUnitArrow = !0;
1335
+ super();
1336
+ this.attachShadow({ mode: "open" });
1337
+ this.values = [];
1338
+ this.unit = "";
1339
+ this.unitCategory = "";
1340
+ this.decimalPlaces = 2;
1341
+ this.showUnitArrow = true;
1342
+ this.format = "";
1233
1343
  }
1234
1344
  connectedCallback() {
1235
- this.unit = this.getAttribute("unit") || "cm", this.values = this.getAttribute("values").split(",").map(Number).map((t) => this.parseValue(t, this.unit)), this.unitCategory = k(this.unit), this.decimalPlaces = parseInt(this.getAttribute("decimal-places")) || 2, this.showUnitArrow = !this.hasAttribute("show-unit-arrow") || this.getAttribute("show-unit-arrow") === "true", this.render(), this.attachEventListeners();
1345
+ this.unit = this.getAttribute("unit") || "cm";
1346
+ this.parsePairValues(this.getAttribute("values"));
1347
+ this.unitCategory = getUnitCategory(this.unit);
1348
+ this.decimalPlaces = parseInt(this.getAttribute("decimal-places")) || 2;
1349
+ this.showUnitArrow = !this.hasAttribute("show-unit-arrow") || this.getAttribute("show-unit-arrow") === "true";
1350
+ this.render();
1351
+ this.attachEventListeners();
1236
1352
  }
1237
1353
  static get observedAttributes() {
1238
1354
  return ["values", "unit", "decimal-places", "show-unit-arrow"];
1239
1355
  }
1240
- attributeChangedCallback(t, e, i) {
1241
- if (t === "values")
1242
- this.values = i.split(",").map(Number).map((s) => this.parseValue(s, this.unit));
1243
- else if (t === "unit") {
1244
- const s = this.unit;
1245
- this.unit = i, this.unitCategory = k(i), s !== i && (this.values = this.values.map((m) => u(m, s, i, this.unitCategory)));
1246
- } else
1247
- t === "decimal-places" ? this.decimalPlaces = parseInt(i) || 2 : t === "show-unit-arrow" && (this.showUnitArrow = i === null || i === "true");
1356
+ attributeChangedCallback(name, oldValue, newValue) {
1357
+ if (name === "values") {
1358
+ this.parsePairValues(newValue);
1359
+ } else if (name === "unit") {
1360
+ const oldUnit = this.unit;
1361
+ this.unit = newValue;
1362
+ this.unitCategory = getUnitCategory(newValue);
1363
+ if (oldUnit !== newValue) {
1364
+ this.values = this.values.map((value) => convertValue(value, oldUnit, newValue, this.unitCategory));
1365
+ }
1366
+ } else if (name === "decimal-places") {
1367
+ this.decimalPlaces = parseInt(newValue) || 2;
1368
+ } else if (name === "show-unit-arrow") {
1369
+ this.showUnitArrow = newValue === null || newValue === "true";
1370
+ }
1248
1371
  this.render();
1249
1372
  }
1250
1373
  render() {
1251
- const t = this.values.map((e) => this.formatPairValue(e));
1374
+ const formattedValues = this.values.map((value) => this.formatPairValue(value));
1375
+ let valuesHtml;
1376
+ if (this.format === "x") {
1377
+ valuesHtml = `${formattedValues[0]} <span class="unit-text">${this.unit}</span> x ${formattedValues[1]}`;
1378
+ } else {
1379
+ valuesHtml = `(${formattedValues.join(", ")})`;
1380
+ }
1252
1381
  this.shadowRoot.innerHTML = `
1253
1382
  <style>
1254
1383
  :host {
@@ -1266,6 +1395,15 @@ class Z extends HTMLElement {
1266
1395
  margin-left: 2px;
1267
1396
  position: relative;
1268
1397
  }
1398
+ .unit-text {
1399
+ color: blue;
1400
+ background-color: lightgray;
1401
+ font-family: inherit;
1402
+ font-size: 0.9em;
1403
+ line-height: normal;
1404
+ border-radius: 0.15em;
1405
+ padding: 0 0.2em;
1406
+ }
1269
1407
  .unit-container {
1270
1408
  position: relative;
1271
1409
  display: inline-flex;
@@ -1291,83 +1429,153 @@ class Z extends HTMLElement {
1291
1429
  min-width: 2.5em;
1292
1430
  }
1293
1431
  </style>
1294
-
1432
+
1295
1433
  <div class="quantity-pair">
1296
- <span class="values">(${t.join(", ")})</span>
1434
+ <span class="values">${valuesHtml}</span>
1297
1435
  <div class="unit-container">
1298
1436
  <select>
1299
- ${(U[this.unitCategory] || [this.unit]).map((e) => `<option value="${e}" ${e === this.unit ? "selected" : ""}>
1300
- ${e}</option>`).join("")}
1437
+ ${(UNITS[this.unitCategory] || [this.unit]).map((unit) => `<option value="${unit}" ${unit === this.unit ? "selected" : ""}>${unit}</option>`).join("")}
1301
1438
  </select>
1302
- </div>
1303
- </div>
1304
- `, this.updateDropdownWidth();
1439
+ </div>
1440
+ </div>
1441
+ `;
1442
+ this.updateDropdownWidth();
1305
1443
  }
1306
1444
  updateDropdownWidth() {
1307
- const t = this.shadowRoot.querySelector("select");
1308
- if (!t)
1445
+ const selectElement = this.shadowRoot.querySelector("select");
1446
+ if (!selectElement)
1309
1447
  return;
1310
- const e = document.createElement("span");
1311
- e.style.visibility = "hidden", e.style.position = "absolute", e.style.whiteSpace = "nowrap", e.style.font = window.getComputedStyle(t).font, document.body.appendChild(e), e.textContent = this.unit;
1312
- const i = e.offsetWidth;
1313
- document.body.removeChild(e);
1314
- const s = this.showUnitArrow ? 16 : 6, m = this.showUnitArrow ? 8 : 0;
1315
- let h = i + s + m + 2;
1316
- h = Math.max(h, 30), t.style.width = `${h}px`;
1448
+ const tempSpan = document.createElement("span");
1449
+ tempSpan.style.visibility = "hidden";
1450
+ tempSpan.style.position = "absolute";
1451
+ tempSpan.style.whiteSpace = "nowrap";
1452
+ tempSpan.style.font = window.getComputedStyle(selectElement).font;
1453
+ document.body.appendChild(tempSpan);
1454
+ tempSpan.textContent = this.unit;
1455
+ const textWidth = tempSpan.offsetWidth;
1456
+ document.body.removeChild(tempSpan);
1457
+ const selectPadding = this.showUnitArrow ? 16 : 6;
1458
+ const arrowWidth = this.showUnitArrow ? 8 : 0;
1459
+ const extraPadding = 2;
1460
+ let finalWidth = textWidth + selectPadding + arrowWidth + extraPadding;
1461
+ finalWidth = Math.max(finalWidth, 30);
1462
+ selectElement.style.width = `${finalWidth}px`;
1317
1463
  }
1318
1464
  attachEventListeners() {
1319
1465
  this.shadowRoot.addEventListener("change", this.handleUnitChange.bind(this));
1320
1466
  }
1321
- parseValue(t, e) {
1322
- return e === "ft-in" ? D(t) : parseFloat(t);
1467
+ parsePairValues(valuesString) {
1468
+ this.format = "";
1469
+ if (!valuesString)
1470
+ return;
1471
+ if (valuesString.startsWith("(") && valuesString.endsWith(")")) {
1472
+ valuesString = valuesString.slice(1, -1);
1473
+ }
1474
+ if (valuesString.includes("x")) {
1475
+ this.values = valuesString.split("x").map((v) => this.parseValue(v, this.unit));
1476
+ this.format = "x";
1477
+ } else if (valuesString.includes(",")) {
1478
+ this.values = valuesString.split(",").map((s) => s.trim()).map((v) => this.parseValue(v, this.unit));
1479
+ this.format = "tuple";
1480
+ }
1323
1481
  }
1324
- formatPairValue(t) {
1325
- return this.unit === "ft-in" ? C(t) : O(t, this.decimalPlaces);
1482
+ parseValue(value, unit) {
1483
+ return unit === "ft-in" ? parseFeetInchesValue(value) : parseFloat(value);
1326
1484
  }
1327
- handleUnitChange(t) {
1328
- if (t.target.tagName === "SELECT") {
1329
- const e = t.target.value;
1330
- this.values = this.values.map((i) => u(i, this.unit, e, this.unitCategory)), this.unit = e, this.render();
1485
+ formatPairValue(value) {
1486
+ if (this.unit === "ft-in") {
1487
+ return formatFeetInchesValue(value);
1488
+ } else {
1489
+ return formatValue(value, this.decimalPlaces);
1490
+ }
1491
+ }
1492
+ handleUnitChange(event) {
1493
+ if (event.target.tagName === "SELECT") {
1494
+ const newUnit = event.target.value;
1495
+ this.values = this.values.map((value) => convertValue(value, this.unit, newUnit, this.unitCategory));
1496
+ this.unit = newUnit;
1497
+ this.render();
1331
1498
  }
1332
1499
  this.updateDropdownWidth();
1333
1500
  }
1334
1501
  }
1335
- class tt extends HTMLElement {
1502
+ class UcQtyTriplet extends HTMLElement {
1336
1503
  constructor() {
1337
- super(), this.attachShadow({ mode: "open" }), this.values = [], this.unit = "", this.unitCategory = "", this.decimalPlaces = 2, this.showUnitArrow = !0, this.format = "", this.hasParentheses = !1;
1504
+ super();
1505
+ this.attachShadow({ mode: "open" });
1506
+ this.values = [];
1507
+ this.unit = "";
1508
+ this.unitCategory = "";
1509
+ this.decimalPlaces = 2;
1510
+ this.showUnitArrow = true;
1511
+ this.format = "";
1338
1512
  }
1339
1513
  connectedCallback() {
1340
- this.unit = this.getAttribute("unit") || "cm", this.parseTripletValues(this.getAttribute("values")), this.unitCategory = k(this.unit), this.decimalPlaces = parseInt(this.getAttribute("decimal-places")) || 2, this.showUnitArrow = !this.hasAttribute("show-unit-arrow") || this.getAttribute("show-unit-arrow") === "true", this.render(), this.attachEventListeners();
1514
+ this.unit = this.getAttribute("unit") || "cm";
1515
+ this.parseTripletValues(this.getAttribute("values"));
1516
+ this.unitCategory = getUnitCategory(this.unit);
1517
+ this.decimalPlaces = parseInt(this.getAttribute("decimal-places")) || 2;
1518
+ this.showUnitArrow = !this.hasAttribute("show-unit-arrow") || this.getAttribute("show-unit-arrow") === "true";
1519
+ this.render();
1520
+ this.attachEventListeners();
1341
1521
  }
1342
1522
  static get observedAttributes() {
1343
1523
  return ["values", "unit", "decimal-places", "show-unit-arrow"];
1344
1524
  }
1345
- attributeChangedCallback(t, e, i) {
1346
- if (t === "values")
1347
- this.parseTripletValues(i);
1348
- else if (t === "unit") {
1349
- const s = this.unit;
1350
- this.unit = i, this.unitCategory = k(i), s !== i && (this.values = this.values.map((m) => u(m, s, i, this.unitCategory)));
1351
- } else
1352
- t === "decimal-places" ? this.decimalPlaces = parseInt(i) || 2 : t === "show-unit-arrow" && (this.showUnitArrow = i === null || i === "true");
1525
+ attributeChangedCallback(name, oldValue, newValue) {
1526
+ if (name === "values") {
1527
+ this.parseTripletValues(newValue);
1528
+ } else if (name === "unit") {
1529
+ const oldUnit = this.unit;
1530
+ this.unit = newValue;
1531
+ this.unitCategory = getUnitCategory(newValue);
1532
+ if (oldUnit !== newValue) {
1533
+ this.values = this.values.map((value) => convertValue(value, oldUnit, newValue, this.unitCategory));
1534
+ }
1535
+ } else if (name === "decimal-places") {
1536
+ this.decimalPlaces = parseInt(newValue) || 2;
1537
+ } else if (name === "show-unit-arrow") {
1538
+ this.showUnitArrow = newValue === null || newValue === "true";
1539
+ }
1353
1540
  this.render();
1354
1541
  }
1355
- parseValue(t, e) {
1356
- return e === "ft-in" ? D(t) : parseFloat(t);
1542
+ parseValue(value, unit) {
1543
+ return unit === "ft-in" ? parseFeetInchesValue(value) : parseFloat(value);
1357
1544
  }
1358
- parseTripletValues(t) {
1359
- this.format = "", this.hasParentheses = t.startsWith("(") && t.endsWith(")"), this.hasParentheses && (t = t.slice(1, -1)), t.includes("x") ? (this.values = t.split("x").map((e) => this.parseValue(e, this.unit)), this.format = "x") : t.includes(",") ? (this.values = t.split(",").map((e) => e.trim()).map((e) => this.parseValue(e, this.unit)), this.format = "comma") : (this.values = t.split(/\s+/).map((e) => this.parseValue(e, this.unit)), this.format = "space");
1545
+ parseTripletValues(valuesString) {
1546
+ this.format = "";
1547
+ if (!valuesString)
1548
+ return;
1549
+ if (valuesString.startsWith("(") && valuesString.endsWith(")")) {
1550
+ valuesString = valuesString.slice(1, -1);
1551
+ }
1552
+ if (valuesString.includes("x")) {
1553
+ this.values = valuesString.split("x").map((v) => this.parseValue(v, this.unit));
1554
+ this.format = "x";
1555
+ } else if (valuesString.includes(",")) {
1556
+ this.values = valuesString.split(",").map((s) => s.trim()).map((v) => this.parseValue(v, this.unit));
1557
+ this.format = "tuple";
1558
+ }
1360
1559
  }
1361
- formatTripletValue(t) {
1362
- return this.unit === "ft-in" ? C(t) : O(t, this.decimalPlaces);
1560
+ formatTripletValue(value) {
1561
+ if (this.unit === "ft-in") {
1562
+ return formatFeetInchesValue(value);
1563
+ } else {
1564
+ return formatValue(value, this.decimalPlaces);
1565
+ }
1363
1566
  }
1364
- formatTriplet(t) {
1365
- let e = "";
1366
- const i = t.map((s) => this.formatTripletValue(s));
1367
- return this.format === "x" ? e = `${i[0]} <span class="unit-text">${this.unit}</span> x ${i[1]} <span class="unit-text">${this.unit}</span> x ${i[2]}` : this.format === "comma" ? e = i.join(", ") : e = i.join(" "), e;
1567
+ formatTriplet(values) {
1568
+ let result = "";
1569
+ const formattedValues = values.map((value) => this.formatTripletValue(value));
1570
+ if (this.format === "x") {
1571
+ result = `${formattedValues[0]} <span class="unit-text">${this.unit}</span> x ${formattedValues[1]} <span class="unit-text">${this.unit}</span> x ${formattedValues[2]}`;
1572
+ } else if (this.format === "tuple") {
1573
+ result = "(" + formattedValues.join(", ") + ")";
1574
+ }
1575
+ return result;
1368
1576
  }
1369
1577
  render() {
1370
- const t = this.formatTriplet(this.values);
1578
+ const formattedTriplet = this.formatTriplet(this.values);
1371
1579
  this.shadowRoot.innerHTML = `
1372
1580
  <style>
1373
1581
  :host {
@@ -1414,48 +1622,59 @@ class tt extends HTMLElement {
1414
1622
  </style>
1415
1623
 
1416
1624
  <span class="quantity-triplet">
1417
- ${this.hasParentheses ? "(" : ""}
1418
- <span class="values">${t}</span>
1419
- ${this.hasParentheses && this.format !== "x" ? ")" : ""}
1625
+ <span class="values">${formattedTriplet}</span>
1420
1626
  <div class="unit-container">
1421
1627
  <select>
1422
- ${(U[this.unitCategory] || [this.unit]).map((e) => `<option value="${e}" ${e === this.unit ? "selected" : ""}>
1423
- ${e}</option>`).join("")}
1628
+ ${(UNITS[this.unitCategory] || [this.unit]).map((unit) => `<option value="${unit}" ${unit === this.unit ? "selected" : ""}>
1629
+ ${unit}</option>`).join("")}
1424
1630
  </select>
1425
1631
  </div>
1426
- ${this.hasParentheses && this.format === "x" ? ")" : ""}
1427
1632
  </span>
1428
- `, this.updateDropdownWidth();
1633
+ `;
1634
+ this.updateDropdownWidth();
1429
1635
  }
1430
1636
  updateDropdownWidth() {
1431
- const t = this.shadowRoot.querySelector("select");
1432
- if (!t)
1637
+ const selectElement = this.shadowRoot.querySelector("select");
1638
+ if (!selectElement)
1433
1639
  return;
1434
- const e = document.createElement("span");
1435
- e.style.visibility = "hidden", e.style.position = "absolute", e.style.whiteSpace = "nowrap", e.style.font = window.getComputedStyle(t).font, document.body.appendChild(e), e.textContent = this.unit;
1436
- const i = e.offsetWidth;
1437
- document.body.removeChild(e);
1438
- const s = this.showUnitArrow ? 16 : 6, m = this.showUnitArrow ? 8 : 0;
1439
- let h = i + s + m + 2;
1440
- h = Math.max(h, 30), t.style.width = `${h}px`;
1640
+ const tempSpan = document.createElement("span");
1641
+ tempSpan.style.visibility = "hidden";
1642
+ tempSpan.style.position = "absolute";
1643
+ tempSpan.style.whiteSpace = "nowrap";
1644
+ tempSpan.style.font = window.getComputedStyle(selectElement).font;
1645
+ document.body.appendChild(tempSpan);
1646
+ tempSpan.textContent = this.unit;
1647
+ const textWidth = tempSpan.offsetWidth;
1648
+ document.body.removeChild(tempSpan);
1649
+ const selectPadding = this.showUnitArrow ? 16 : 6;
1650
+ const arrowWidth = this.showUnitArrow ? 8 : 0;
1651
+ const extraPadding = 2;
1652
+ let finalWidth = textWidth + selectPadding + arrowWidth + extraPadding;
1653
+ finalWidth = Math.max(finalWidth, 30);
1654
+ selectElement.style.width = `${finalWidth}px`;
1441
1655
  }
1442
1656
  attachEventListeners() {
1443
1657
  this.shadowRoot.addEventListener("change", this.handleUnitChange.bind(this));
1444
1658
  }
1445
- handleUnitChange(t) {
1446
- if (t.target.tagName === "SELECT") {
1447
- const e = t.target.value;
1448
- this.values = this.values.map((i) => u(i, this.unit, e, this.unitCategory)), this.unit = e, this.render();
1659
+ handleUnitChange(event) {
1660
+ if (event.target.tagName === "SELECT") {
1661
+ const newUnit = event.target.value;
1662
+ this.values = this.values.map((value) => convertValue(value, this.unit, newUnit, this.unitCategory));
1663
+ this.unit = newUnit;
1664
+ this.render();
1449
1665
  }
1450
1666
  this.updateDropdownWidth();
1451
1667
  }
1452
1668
  }
1453
- class et extends HTMLElement {
1669
+ class NewComponent1 extends HTMLElement {
1454
1670
  constructor() {
1455
- super(), this.attachShadow({ mode: "open" }), this.count = 0;
1671
+ super();
1672
+ this.attachShadow({ mode: "open" });
1673
+ this.count = 0;
1456
1674
  }
1457
1675
  connectedCallback() {
1458
- this.render(), this.attachEventListeners();
1676
+ this.render();
1677
+ this.attachEventListeners();
1459
1678
  }
1460
1679
  render() {
1461
1680
  this.shadowRoot.innerHTML = `
@@ -1492,32 +1711,38 @@ class et extends HTMLElement {
1492
1711
  `;
1493
1712
  }
1494
1713
  attachEventListeners() {
1495
- const t = this.shadowRoot.querySelector(".increment"), e = this.shadowRoot.querySelector(".decrement");
1496
- t.addEventListener("click", () => this.increment()), e.addEventListener("click", () => this.decrement());
1714
+ const incrementBtn = this.shadowRoot.querySelector(".increment");
1715
+ const decrementBtn = this.shadowRoot.querySelector(".decrement");
1716
+ incrementBtn.addEventListener("click", () => this.increment());
1717
+ decrementBtn.addEventListener("click", () => this.decrement());
1497
1718
  }
1498
1719
  increment() {
1499
- this.count++, this.updateCount();
1720
+ this.count++;
1721
+ this.updateCount();
1500
1722
  }
1501
1723
  decrement() {
1502
- this.count--, this.updateCount();
1724
+ this.count--;
1725
+ this.updateCount();
1503
1726
  }
1504
1727
  updateCount() {
1505
- const t = this.shadowRoot.querySelector(".count");
1506
- t.textContent = this.count;
1728
+ const countElement = this.shadowRoot.querySelector(".count");
1729
+ countElement.textContent = this.count;
1507
1730
  }
1508
1731
  }
1509
- const A = (a, t) => {
1510
- typeof window < "u" && !customElements.get(a) && customElements.define(a, t);
1732
+ const defineCustomElement = (name, component) => {
1733
+ if (typeof window !== "undefined" && !customElements.get(name)) {
1734
+ customElements.define(name, component);
1735
+ }
1511
1736
  };
1512
- A("physical-quantity", J);
1513
- A("uc-qty", class extends J {
1737
+ defineCustomElement("physical-quantity", PhysicalQuantity);
1738
+ defineCustomElement("uc-qty", class extends PhysicalQuantity {
1514
1739
  });
1515
- A("uc-qty-pair", Z);
1516
- A("uc-qty-triplet", tt);
1517
- A("new-component-1", et);
1740
+ defineCustomElement("uc-qty-pair", UcQtyPair);
1741
+ defineCustomElement("uc-qty-triplet", UcQtyTriplet);
1742
+ defineCustomElement("new-component-1", NewComponent1);
1518
1743
  export {
1519
- et as NewComponent1,
1520
- J as PhysicalQuantity,
1521
- Z as UcQtyPair,
1522
- tt as UcQtyTriplet
1744
+ NewComponent1,
1745
+ PhysicalQuantity,
1746
+ UcQtyPair,
1747
+ UcQtyTriplet
1523
1748
  };