physical-quantity 1.1.7 → 1.1.9
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/README.md
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
|
|
12
12
|
## Demo: Physical Quantity element - No Unit Converter or Dual Units Needed
|
|
13
13
|
[Box Size & Mass @https://e3d.github.io](https://e3d.github.io)
|
|
14
|
+
<script async src="//jsfiddle.net/hithere/tz8ym4fh/54/embed/"></script>
|
|
15
|
+
<iframe width="100%" height="300" src="https://jsfiddle.net/hithere/tz8ym4fh/54/embedded/result" allowfullscreen="true" frameborder="0"></iframe>
|
|
16
|
+
|
|
17
|
+

|
|
14
18
|
|
|
15
19
|
## Installation
|
|
16
20
|
|
|
@@ -66,6 +70,7 @@ Here's an example of how to use the component in an HTML file:
|
|
|
66
70
|
</head>
|
|
67
71
|
<body>
|
|
68
72
|
<physical-quantity value="25.4" unit="mm"></physical-quantity>
|
|
73
|
+
<physical-quantity value="1500" unit="psf" decimal-places=4></physical-quantity> <br>
|
|
69
74
|
</body>
|
|
70
75
|
</html>
|
|
71
76
|
```
|
|
@@ -73,8 +78,9 @@ Here's an example of how to use the component in an HTML file:
|
|
|
73
78
|
### Attributes
|
|
74
79
|
The physical-quantity component supports the following attributes:
|
|
75
80
|
|
|
76
|
-
value: The initial value of the physical quantity. It can be any number.
|
|
77
|
-
unit: The initial unit of the physical quantity. It must be a valid unit within the supported unit category (e.g., mm, cm, m, in, ft for length).
|
|
81
|
+
- value: The initial value of the physical quantity. It can be any number.
|
|
82
|
+
- unit: The initial unit of the physical quantity. It must be a valid unit within the supported unit category (e.g., mm, cm, m, in, ft for length).
|
|
83
|
+
- decimal-places: web author can specify the decimal-places depending on the magnitude of the quantity. Default to be 3.
|
|
78
84
|
|
|
79
85
|
### Supported Units
|
|
80
86
|
Currently, the component supports the following categories and units:
|
|
@@ -88,6 +94,24 @@ Currently, the component supports the following categories and units:
|
|
|
88
94
|
- kg (kilogram)
|
|
89
95
|
- g (gram)
|
|
90
96
|
- lbm (pound mass)
|
|
97
|
+
- Pressure/Stress:
|
|
98
|
+
- Pa
|
|
99
|
+
- kPa
|
|
100
|
+
- MPa
|
|
101
|
+
- GPa
|
|
102
|
+
- bar
|
|
103
|
+
- mbar,
|
|
104
|
+
- atm,
|
|
105
|
+
- mm HG,
|
|
106
|
+
- cm HG,
|
|
107
|
+
- in HG,
|
|
108
|
+
- mm W.C.,
|
|
109
|
+
- m W.C.,
|
|
110
|
+
- in W.C.,
|
|
111
|
+
- psf,
|
|
112
|
+
- psi,
|
|
113
|
+
- ksi,
|
|
114
|
+
- ksi[kip/in²,
|
|
91
115
|
- ... (more to update.)
|
|
92
116
|
|
|
93
117
|
## License
|
package/dist/pq.min.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
const GRAVITY_SI=9.80665,POUNDMASS_KG=.45359237,INCH_METER=.0254,FOOT_METER=12*INCH_METER,ATM_PA=101325,TORR_ATM=1/760,MMHG_PA=133.322387415;// 1 mmHG = 133.322387415 Pa
|
|
1
2
|
class PhysicalQuantity extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.value=0,this.unit="mm",this.unitCategory="Length",this.decimalPlaces=3,// Default decimal places
|
|
2
|
-
this.units={Length:["m","cm","mm","in","ft"],Mass:["g","kg","lbm"]},this.unitConversion={Length:{m:1,cm:.01,mm:.001,in
|
|
3
|
+
this.units={Length:["m","cm","mm","in","ft"],Mass:["g","kg","lbm"],Pressure:["Pa","kPa","MPa","GPa","bar","mbar","atm","mm HG","cm HG","in HG","mm W.C.","m W.C.","in W.C.","psf","psi","ksi","ksi[kip/in²]"]},this.unitConversion={Length:{m:1,cm:.01,mm:.001,in:INCH_METER,ft:FOOT_METER},
|
|
3
4
|
// Add other category conversion factors as needed
|
|
4
|
-
Mass:{kg:1,g:.001,lbm
|
|
5
|
+
Mass:{kg:1,g:.001,lbm:POUNDMASS_KG},Pressure:{Pa:1,kPa:1e3,MPa:1e6,GPa:1e9,bar:1e5,mbar:100,atm:ATM_PA,"mm HG":MMHG_PA,"cm HG":10*MMHG_PA,"in HG":25.4*MMHG_PA,"mm W.C.":+GRAVITY_SI,"m W.C.":1e3*GRAVITY_SI,"in W.C.":1e3*INCH_METER*GRAVITY_SI,psf:POUNDMASS_KG*GRAVITY_SI/Math.pow(FOOT_METER,2),psi:POUNDMASS_KG*GRAVITY_SI/Math.pow(INCH_METER,2),ksi:POUNDMASS_KG*GRAVITY_SI/Math.pow(INCH_METER,2)*1e3,"ksi[kip/in²]":POUNDMASS_KG*GRAVITY_SI/Math.pow(INCH_METER,2)*1e3}},
|
|
5
6
|
// this.handleUnitChange = this.handleUnitChange; // Bind the method to the instance
|
|
6
7
|
// this.handleMouseOver = this.handleMouseOver; // Bind the method to the instance
|
|
7
8
|
// this.handleMouseOut = this.handleMouseOut;
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "physical-quantity",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "A web component to represent a physical quantity with unit conversion.",
|
|
5
5
|
"main": "./dist/pq.min.js",
|
|
6
6
|
"files": [
|
|
7
|
-
"dist/"
|
|
7
|
+
"dist/",
|
|
8
|
+
"images/"
|
|
8
9
|
],
|
|
9
10
|
"scripts": {
|
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|