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/CHANGELOG.md +29 -0
- package/README.md +22 -38
- package/dist/pq.es.js +721 -496
- package/dist/pq.umd.js +1585 -71
- package/index.html +70 -0
- package/package.json +37 -11
package/dist/pq.es.js
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
596
|
+
};
|
|
597
|
+
const CONVERSION_FACTORS = {
|
|
560
598
|
/* 901 */
|
|
561
599
|
Length: {
|
|
562
|
-
m: 1,
|
|
563
|
-
"nano[nm]": 1 /
|
|
564
|
-
µm: 1 /
|
|
565
|
-
micron: 1 /
|
|
566
|
-
mm: 1 /
|
|
567
|
-
cm: 0.01,
|
|
568
|
-
dm: 0.1,
|
|
569
|
-
km:
|
|
570
|
-
in:
|
|
571
|
-
"thou[mil, or thousandth of an inch]":
|
|
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":
|
|
574
|
-
ft:
|
|
575
|
-
yd: 3 *
|
|
576
|
-
mile:
|
|
577
|
-
"NM[M, nmi, or nautical mile]":
|
|
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 /
|
|
584
|
-
µg: 1 /
|
|
585
|
-
oz: 1 / 16 *
|
|
586
|
-
lbm:
|
|
587
|
-
slug:
|
|
588
|
-
"ton(US/short)": 2e3 *
|
|
589
|
-
"ton(UK-Imperial/long)": 2240 *
|
|
590
|
-
tonne:
|
|
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:
|
|
611
|
-
MA:
|
|
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:
|
|
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²":
|
|
640
|
-
"ft/min²":
|
|
641
|
-
"in/s²":
|
|
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²":
|
|
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(
|
|
675
|
-
fc: 1 / Math.pow(
|
|
676
|
-
"lumen/ft²": 1 / Math.pow(
|
|
677
|
-
"lm/ft²": 1 / Math.pow(
|
|
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 /
|
|
687
|
-
kHz:
|
|
688
|
-
MHz:
|
|
689
|
-
GHz:
|
|
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 /
|
|
695
|
-
"mm²": Math.pow(1 /
|
|
732
|
+
"µm²": Math.pow(1 / MILLION, 2),
|
|
733
|
+
"mm²": Math.pow(1 / THOUSAND, 2),
|
|
696
734
|
"cm²": Math.pow(1 / 100, 2),
|
|
697
|
-
"km²":
|
|
698
|
-
hectare: Math.pow(100, 2),
|
|
699
|
-
"in²": Math.pow(
|
|
700
|
-
"ft²": Math.pow(
|
|
701
|
-
"yd²": Math.pow(
|
|
702
|
-
acre:
|
|
703
|
-
"mile²": Math.pow(
|
|
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 /
|
|
709
|
-
"mm³": Math.pow(1 /
|
|
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 /
|
|
712
|
-
ml: 1 /
|
|
713
|
-
"km³": Math.pow(
|
|
714
|
-
"in³": Math.pow(
|
|
715
|
-
"ft³": Math.pow(
|
|
716
|
-
"yd³": Math.pow(
|
|
717
|
-
"gal(UK-imperial)":
|
|
718
|
-
"gal(US-liquid)":
|
|
719
|
-
"gal(US-dry)":
|
|
720
|
-
"pint(UK-imperial)":
|
|
721
|
-
"pint(US-liquid)":
|
|
722
|
-
"pint(US-dry)":
|
|
723
|
-
"fluid ounce(UK-imperial)":
|
|
724
|
-
"fluid ounce(US-liquid)":
|
|
725
|
-
"bushel(UK-imperial)":
|
|
726
|
-
"bushel(US-dry)":
|
|
727
|
-
"cup(US-liquid)":
|
|
728
|
-
"cup(Legal)":
|
|
729
|
-
"cup(Metric)":
|
|
730
|
-
"cup(Imperial)":
|
|
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(
|
|
738
|
-
"ft⁴": Math.pow(
|
|
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 / (
|
|
744
|
-
"g⋅mm²": 1 / (
|
|
745
|
-
"lbm⋅ft²":
|
|
746
|
-
"lbm⋅in²":
|
|
747
|
-
"oz⋅in²":
|
|
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:
|
|
753
|
-
MN:
|
|
754
|
-
kgf:
|
|
755
|
-
lb:
|
|
756
|
-
lbf:
|
|
757
|
-
"kip[kilo pound]":
|
|
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 /
|
|
775
|
-
"g/mm²": 1 /
|
|
776
|
-
"tonne/m²":
|
|
777
|
-
"lbm/yd²":
|
|
778
|
-
"lbm/ft²":
|
|
779
|
-
"lbm/in²":
|
|
780
|
-
"oz/yd²":
|
|
781
|
-
"oz/ft²":
|
|
782
|
-
"oz/in²":
|
|
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³":
|
|
791
|
-
"lbm/in³":
|
|
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:
|
|
797
|
-
MJ:
|
|
798
|
-
GJ:
|
|
799
|
-
"TNT Equivalent[kiloton]": 1e9 *
|
|
834
|
+
"kJ": THOUSAND,
|
|
835
|
+
"MJ": MILLION,
|
|
836
|
+
"GJ": BILLION,
|
|
837
|
+
"TNT Equivalent[kiloton]": 1e9 * CALORIE_TH_J,
|
|
800
838
|
// 1e9 = 1000000000.0,
|
|
801
|
-
Btu:
|
|
802
|
-
"MM Btu":
|
|
803
|
-
"calorie(IT)":
|
|
839
|
+
"Btu": BTU_J,
|
|
840
|
+
"MM Btu": BTU_J * MILLION,
|
|
841
|
+
"calorie(IT)": CALORIE_IT_J,
|
|
804
842
|
// 4.1868J
|
|
805
|
-
"kilo-calorie(IT)":
|
|
806
|
-
"calorie(TH)":
|
|
843
|
+
"kilo-calorie(IT)": CALORIE_IT_J * THOUSAND,
|
|
844
|
+
"calorie(TH)": CALORIE_TH_J,
|
|
807
845
|
// 4.184J
|
|
808
|
-
"kilo-calorie(TH)":
|
|
809
|
-
"HP Hour":
|
|
810
|
-
Wh: 3600,
|
|
811
|
-
kWh: 3600 *
|
|
812
|
-
"eV{electron-volt]": 1 /
|
|
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:
|
|
818
|
-
MW:
|
|
819
|
-
"GW[Gigawatt]":
|
|
820
|
-
"Btu/h":
|
|
821
|
-
"Btu/minute":
|
|
822
|
-
"MM Btu/h":
|
|
823
|
-
"Btu(AC)":
|
|
824
|
-
"calorie(IT)/second":
|
|
825
|
-
"calorie(IT)/minute":
|
|
826
|
-
"kilo-calorie(IT)/hour":
|
|
827
|
-
"calorie(TH)/second":
|
|
828
|
-
"calorie(TH)/minute":
|
|
829
|
-
"kilo-calorie(TH)/hour":
|
|
830
|
-
"lb-ft/second":
|
|
831
|
-
"lb-ft/minute":
|
|
832
|
-
HP:
|
|
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":
|
|
837
|
-
"kJ/minute":
|
|
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:
|
|
843
|
-
"lb-in":
|
|
844
|
-
"kip-in":
|
|
845
|
-
"lb-ft":
|
|
846
|
-
"oz-in":
|
|
847
|
-
"oz-ft":
|
|
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:
|
|
853
|
-
MPa:
|
|
854
|
-
GPa:
|
|
855
|
-
bar: 100 *
|
|
856
|
-
mbar: 100,
|
|
857
|
-
atm:
|
|
858
|
-
"mm HG":
|
|
859
|
-
"cm HG":
|
|
860
|
-
"in HG":
|
|
861
|
-
"mm W.C.": 1 / 1e3 * 1e3 *
|
|
862
|
-
"m W.C.": 1 * 1e3 *
|
|
863
|
-
"in W.C.":
|
|
864
|
-
psf:
|
|
865
|
-
psi:
|
|
866
|
-
ksi:
|
|
867
|
-
"ksi{kip/in²]":
|
|
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":
|
|
874
|
-
"MPa/km":
|
|
911
|
+
"kPa/m": THOUSAND,
|
|
912
|
+
"MPa/km": MILLION / THOUSAND,
|
|
875
913
|
"bar/m": 1e5,
|
|
876
|
-
"mbar/mm": 100 *
|
|
877
|
-
"atm/m":
|
|
878
|
-
"mm HG/m":
|
|
879
|
-
"in HG/ft":
|
|
880
|
-
"mm W.C./m": 1 /
|
|
881
|
-
"m W.C./m":
|
|
882
|
-
"in W.C./ft":
|
|
883
|
-
"in W.C./100 ft":
|
|
884
|
-
"psf/in":
|
|
885
|
-
"psi/ft":
|
|
886
|
-
"ksi/ft":
|
|
887
|
-
"Torr/ft":
|
|
888
|
-
"mTorr/m":
|
|
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":
|
|
894
|
-
"kN/m":
|
|
895
|
-
"lb/ft":
|
|
896
|
-
"kips/ft":
|
|
897
|
-
"lb/in":
|
|
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 /
|
|
904
|
-
"N⋅mm/deg°": 1 /
|
|
905
|
-
"lb-ft/rad":
|
|
906
|
-
"lb-ft/deg°":
|
|
907
|
-
"lb-in/rad":
|
|
908
|
-
"lb-in/deg°":
|
|
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 /
|
|
916
|
-
"L/min": 1 /
|
|
917
|
-
"L/h": 1 /
|
|
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(
|
|
921
|
-
"in³/min": Math.pow(
|
|
922
|
-
"ft³/s": Math.pow(
|
|
923
|
-
CFM: Math.pow(
|
|
924
|
-
"CFM[ft³/min]": Math.pow(
|
|
925
|
-
CFH: Math.pow(
|
|
926
|
-
"CFH[ft³/h]": Math.pow(
|
|
927
|
-
"yd³/min": Math.pow(
|
|
928
|
-
"yd³/h": Math.pow(
|
|
929
|
-
"gpm(US)":
|
|
930
|
-
"gph(US)":
|
|
931
|
-
"bushel(UK-imperial)/h":
|
|
932
|
-
"bushel(US)/h":
|
|
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 /
|
|
940
|
-
"g/min": 1 /
|
|
941
|
-
"g/h": 1 /
|
|
942
|
-
"slug/s":
|
|
943
|
-
"slug/min":
|
|
944
|
-
"slug/h":
|
|
945
|
-
"lbm/s":
|
|
946
|
-
"lbm/min":
|
|
947
|
-
"lbm/h":
|
|
948
|
-
"oz/s":
|
|
949
|
-
"oz/min":
|
|
950
|
-
"oz/h":
|
|
951
|
-
"tonne/h":
|
|
952
|
-
"short ton/h": 2e3 *
|
|
953
|
-
"long ton/h": 2240 *
|
|
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 /
|
|
996
|
+
"mm/s": 1 / THOUSAND,
|
|
959
997
|
"km/s": 1,
|
|
960
|
-
"mm/min": 1 /
|
|
998
|
+
"mm/min": 1 / THOUSAND / 60,
|
|
961
999
|
"m/min": 1 / 60,
|
|
962
|
-
"km/min":
|
|
963
|
-
"mm/h": 1 /
|
|
1000
|
+
"km/min": THOUSAND / 60,
|
|
1001
|
+
"mm/h": 1 / THOUSAND / 3600,
|
|
964
1002
|
"m/h": 1 / 3600,
|
|
965
|
-
"km/h":
|
|
966
|
-
"in/s":
|
|
967
|
-
fps:
|
|
968
|
-
"fps[ft/second]":
|
|
969
|
-
fpm:
|
|
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]":
|
|
1009
|
+
"fpm[ft/minute]": FOOT_METER / 60,
|
|
972
1010
|
// redundant version
|
|
973
|
-
"mph[mile/h]":
|
|
974
|
-
"knot[kn, kt, or nautical mile/h]":
|
|
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 /
|
|
983
|
-
mV: 1 /
|
|
984
|
-
kV:
|
|
985
|
-
MV:
|
|
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
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
if (
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
const
|
|
1001
|
-
|
|
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
|
-
|
|
1004
|
-
|
|
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
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
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
|
-
|
|
1013
|
-
|
|
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 (
|
|
1021
|
-
|
|
1022
|
-
return H(m, 0, 0, 1);
|
|
1130
|
+
if (inches > 0) {
|
|
1131
|
+
output += `${inches}`;
|
|
1023
1132
|
}
|
|
1024
|
-
if (
|
|
1025
|
-
|
|
1026
|
-
return H(0, m, 0, 1);
|
|
1133
|
+
if (fractionStr !== "") {
|
|
1134
|
+
output += fractionStr;
|
|
1027
1135
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
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
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
const
|
|
1045
|
-
return
|
|
1046
|
-
}
|
|
1047
|
-
|
|
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()
|
|
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")
|
|
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(
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
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)
|
|
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(
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
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
|
-
|
|
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(
|
|
1088
|
-
if (
|
|
1089
|
-
const
|
|
1090
|
-
console.log("handleUnitChange:", { from: this.unit, to:
|
|
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
|
|
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">${
|
|
1295
|
+
<span class="value">${formattedValue}</span>
|
|
1178
1296
|
<div class="unit-container">
|
|
1179
1297
|
<select>
|
|
1180
|
-
${(
|
|
1181
|
-
${
|
|
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
|
-
|
|
1303
|
+
`;
|
|
1304
|
+
this.updateDropdownWidth();
|
|
1194
1305
|
}
|
|
1195
1306
|
updateDropdownWidth() {
|
|
1196
|
-
const
|
|
1197
|
-
if (!
|
|
1307
|
+
const selectElement = this.shadowRoot.querySelector("select");
|
|
1308
|
+
if (!selectElement)
|
|
1198
1309
|
return;
|
|
1199
|
-
const
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
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
|
|
1333
|
+
class UcQtyPair extends HTMLElement {
|
|
1231
1334
|
constructor() {
|
|
1232
|
-
super()
|
|
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"
|
|
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(
|
|
1241
|
-
if (
|
|
1242
|
-
this.
|
|
1243
|
-
else if (
|
|
1244
|
-
const
|
|
1245
|
-
this.unit =
|
|
1246
|
-
|
|
1247
|
-
|
|
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
|
|
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"
|
|
1434
|
+
<span class="values">${valuesHtml}</span>
|
|
1297
1435
|
<div class="unit-container">
|
|
1298
1436
|
<select>
|
|
1299
|
-
${(
|
|
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
|
-
|
|
1439
|
+
</div>
|
|
1440
|
+
</div>
|
|
1441
|
+
`;
|
|
1442
|
+
this.updateDropdownWidth();
|
|
1305
1443
|
}
|
|
1306
1444
|
updateDropdownWidth() {
|
|
1307
|
-
const
|
|
1308
|
-
if (!
|
|
1445
|
+
const selectElement = this.shadowRoot.querySelector("select");
|
|
1446
|
+
if (!selectElement)
|
|
1309
1447
|
return;
|
|
1310
|
-
const
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
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
|
-
|
|
1322
|
-
|
|
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
|
-
|
|
1325
|
-
return
|
|
1482
|
+
parseValue(value, unit) {
|
|
1483
|
+
return unit === "ft-in" ? parseFeetInchesValue(value) : parseFloat(value);
|
|
1326
1484
|
}
|
|
1327
|
-
|
|
1328
|
-
if (
|
|
1329
|
-
|
|
1330
|
-
|
|
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
|
|
1502
|
+
class UcQtyTriplet extends HTMLElement {
|
|
1336
1503
|
constructor() {
|
|
1337
|
-
super()
|
|
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"
|
|
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(
|
|
1346
|
-
if (
|
|
1347
|
-
this.parseTripletValues(
|
|
1348
|
-
else if (
|
|
1349
|
-
const
|
|
1350
|
-
this.unit =
|
|
1351
|
-
|
|
1352
|
-
|
|
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(
|
|
1356
|
-
return
|
|
1542
|
+
parseValue(value, unit) {
|
|
1543
|
+
return unit === "ft-in" ? parseFeetInchesValue(value) : parseFloat(value);
|
|
1357
1544
|
}
|
|
1358
|
-
parseTripletValues(
|
|
1359
|
-
this.format = ""
|
|
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(
|
|
1362
|
-
|
|
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(
|
|
1365
|
-
let
|
|
1366
|
-
const
|
|
1367
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
${(
|
|
1423
|
-
${
|
|
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
|
-
|
|
1633
|
+
`;
|
|
1634
|
+
this.updateDropdownWidth();
|
|
1429
1635
|
}
|
|
1430
1636
|
updateDropdownWidth() {
|
|
1431
|
-
const
|
|
1432
|
-
if (!
|
|
1637
|
+
const selectElement = this.shadowRoot.querySelector("select");
|
|
1638
|
+
if (!selectElement)
|
|
1433
1639
|
return;
|
|
1434
|
-
const
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
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(
|
|
1446
|
-
if (
|
|
1447
|
-
const
|
|
1448
|
-
this.values = this.values.map((
|
|
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
|
|
1669
|
+
class NewComponent1 extends HTMLElement {
|
|
1454
1670
|
constructor() {
|
|
1455
|
-
super()
|
|
1671
|
+
super();
|
|
1672
|
+
this.attachShadow({ mode: "open" });
|
|
1673
|
+
this.count = 0;
|
|
1456
1674
|
}
|
|
1457
1675
|
connectedCallback() {
|
|
1458
|
-
this.render()
|
|
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
|
|
1496
|
-
|
|
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
|
|
1720
|
+
this.count++;
|
|
1721
|
+
this.updateCount();
|
|
1500
1722
|
}
|
|
1501
1723
|
decrement() {
|
|
1502
|
-
this.count
|
|
1724
|
+
this.count--;
|
|
1725
|
+
this.updateCount();
|
|
1503
1726
|
}
|
|
1504
1727
|
updateCount() {
|
|
1505
|
-
const
|
|
1506
|
-
|
|
1728
|
+
const countElement = this.shadowRoot.querySelector(".count");
|
|
1729
|
+
countElement.textContent = this.count;
|
|
1507
1730
|
}
|
|
1508
1731
|
}
|
|
1509
|
-
const
|
|
1510
|
-
typeof window
|
|
1732
|
+
const defineCustomElement = (name, component) => {
|
|
1733
|
+
if (typeof window !== "undefined" && !customElements.get(name)) {
|
|
1734
|
+
customElements.define(name, component);
|
|
1735
|
+
}
|
|
1511
1736
|
};
|
|
1512
|
-
|
|
1513
|
-
|
|
1737
|
+
defineCustomElement("physical-quantity", PhysicalQuantity);
|
|
1738
|
+
defineCustomElement("uc-qty", class extends PhysicalQuantity {
|
|
1514
1739
|
});
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1740
|
+
defineCustomElement("uc-qty-pair", UcQtyPair);
|
|
1741
|
+
defineCustomElement("uc-qty-triplet", UcQtyTriplet);
|
|
1742
|
+
defineCustomElement("new-component-1", NewComponent1);
|
|
1518
1743
|
export {
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1744
|
+
NewComponent1,
|
|
1745
|
+
PhysicalQuantity,
|
|
1746
|
+
UcQtyPair,
|
|
1747
|
+
UcQtyTriplet
|
|
1523
1748
|
};
|