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.umd.js CHANGED
@@ -1,4 +1,1254 @@
1
- (function(u,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(u=typeof globalThis<"u"?globalThis:u||self,L(u.PQWebComponents={}))})(this,function(u){"use strict";const o=.45359237,r=9.80665,H=5280,a=25.4/1e3,n=12*a,W=1852,Q=66*660,p=4.54609,g=231,I=268.8025,f=1/8,F=1/20,j=1/16,B=8,_=8,Y=1/16,X=240,Z=250,tt=10,N=14.59390294,b=1055.05585262,y=4.1868,M=4.184,R=550*o*r*n,C=101325,$=1/760,U=133.322387415,et=624150974e10,k={Length:["m","nano[nm]","µm","micron","mm","cm","dm","km","in","ft-in","thou[mil, or thousandth of an inch]","ft","yd","mile","NM[M, nmi, or nautical mile]"],Mass:["kg","g","mg","µg","oz","lbm","slug","ton(US/short)","ton(UK-Imperial/long)","tonne"],Time:["s[second]","s","minute","h","h[hour]","day","week"],ElectricalCurrent:["A","Ampere[amp]","mA","µA","kA","MA","esu/s"],Temperature:["°K","°C","°F","°Ra"],"Amount of Substance":["mol","mmol","kmol"],"Luminous Intensity":["cd[candela]","lm/sr","cp[candlepower]","cp[candlepower(before 1948)]"],Acceleration:["m/s²","m/min²","mm/s²","ft/s²","ft/min²","in/s²"],"Gravitational Constant":["m³/kg/s²","N⋅m²/kg²","dyn⋅cm²/g²"],"Velocity (Angular)":["rad/s","rad/min","rad/h","deg°/s","deg°/min","deg°/h","rpm[rev/min]","rev/s"],"Acceleration (Angular)":["rad/s²","rad/min²","deg°/s²","deg°/min²"],Illuminance:["lux","lumen/m²","lm/m²","meter-candle","phot","foot-candle","fc","lumen/ft²","lm/ft²"],Frequency:["Hz","1/s","1/min","rpm","1/hour","mHz","kHz","MHz","GHz"],Area:["m²","µm²","mm²","cm²","km²","hectare","in²","ft²","yd²","acre","mile²"],"Volume / Section Modulus":["m³","µm³","mm³","cm³","L","ml","km³","in³","ft³","yd³","gal(UK-imperial)","gal(US-liquid)","gal(US-dry)","pint(UK-imperial)","pint(US-liquid)","pint(US-dry)","fluid ounce(UK-imperial)","fluid ounce(US-liquid)","bushel(UK-imperial)","bushel(US-dry)","cup(US-liquid)","cup(Legal)","cup(Metric)","cup(Imperial)"],"Polar Moment of Inertia":["m⁴","mm⁴","cm⁴","in⁴","ft⁴"],"Moment of Inertia":["kg⋅m²","g⋅cm²","g⋅mm²","lbm⋅ft²","lbm⋅in²","oz⋅in²"],Force:["N","kN","MN","kgf","lb","lbf","kip[kilo pound]"],Angle:["radian","rad","deg°","revolution"],"Solid Angle":["sr[steradian]","m²/m²"],"BMI-Body Mass Index/Ballistic Coefficient":["kg/m²","g/cm²","g/mm²","tonne/m²","lbm/yd²","lbm/ft²","lbm/in²","oz/yd²","oz/ft²","oz/in²"],Density:["kg/m³","kg/L","g/cm³","g/mm³","lbm/ft³","lbm/in³"],Energy:["J[Joule]","kJ","MJ","GJ","TNT Equivalent[kiloton]","Btu","MM Btu","calorie(IT)","kilo-calorie(IT)","calorie(TH)","kilo-calorie(TH)","HP Hour","Wh","kWh","eV[electron-volt]"],Power:["W","kW","MW","GW[Gigawatt]","Btu/h","Btu/minute","MM Btu/h","Btu(AC)","calorie(IT)/second","calorie(IT)/minute","kilo-calorie(IT)/hour","calorie(TH)/second","calorie(TH)/minute","kilo-calorie(TH)/hour","lb-ft/second","lb-ft/minute","HP","J/second","J/minute","J/h","MJ/h","kJ/minute"],"Torque, Moment of Force":["Nm","kNm","lb-in","kip-in","lb-ft","oz-in","oz-ft"],"Pressure/Stress":["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²]"],"Pressure Drop per Unit Length":["Pa/m","Pascal/m","kPa/m","MPa/km","bar/m","mbar/mm","atm/m","mm HG/m","in HG/ft","mm W.C./m","m W.C./m","in W.C./ft","in W.C./100 ft","psf/in","psi/ft","ksi/ft","Torr/ft","mTorr/m"],"Uniformly Distributed (Uniform Line) Load | Stiffness of Linear Spring":["N/m","N/mm","kN/m","lb/ft","kips/ft","lb/in"],"Stiffness of Rotary Spring":["N⋅m/rad","N⋅m/deg°","N⋅mm/rad","N⋅mm/deg°","lb-ft/rad","lb-ft/deg°","lb-in/rad","lb-in/deg°"],"Flow Rate (Volume)":["m³/s","m³/min","m³/h","L/s","L/min","L/h","cm³/s","cm³/min","in³/s","in³/min","ft³/s","CFM","CFM[ft³/min]","CFH","CFH[ft³/h]","yd³/min","yd³/h","gpm(US)","gph(US)","bushel(UK-imperial)/h","bushel(US)/h"],"Flow Rate (Mass)":["kg/s","kg/min","kg/h","g/s","g/min","g/h","slug/s","slug/min","slug/h","lbm/s","lbm/min","lbm/h","oz/s","oz/min","oz/h","tonne/h","short ton/h","long ton/h"],"Speed / Velocity (Linear)":["m/s","mm/s","km/s","mm/min","m/min","km/min","mm/h","m/h","km/h","in/s","fps","fps[ft/second]","fpm","fpm[ft/minute]","mph[mile/h]","knot[kn, kt, or nautical mile/h]"],"Fuel Heat Value (Volume)":["J/m³","J/L","kJ/L","kJ/m³","MJ/m³","GJ/m³","cal(IT)/L","kcal(IT)/m³","cal(TH)/L","kcal(TH)/m³","Wh/L","Wh/m³","kWh/m³","HP Hour/ft³","Btu/gal(US)","Btu/ft³","MM Btu/ft³"],"Fuel Heat Value (Mass)":["J/kg","J/g","kJ/kg","MJ/kg","GJ/kg","cal(IT)/g","kcal(IT)/kg","cal(TH)/g","kcal(TH)/kg","Wh/g","Wh/kg","kWh/kg","HP Hour/lbm","Btu/lbm","MM Btu/lbm","Btu/ton(short)"],"Mass Heat Capacity":["J/(kg·°K)","J/(kg·°C)","J/(g·°K)","J/(g·°C)","Btu/(lbm·°F)"],"Viscosity - Absolute/Dynamic(μ)":["PI[Pa·s]","N·s/m²","kg/m/s","P[Poise]","cP","lb·s/ft²","lbm/ft/s"],"Viscosity - Kinematic":["m²/s","m²/min","m²/hr","St[cm²/s]","Stoke","cm²/min","cm²/hr","cSt[mm²/s]","mm²/min","mm²/hr","ft²/s","ft²/min","ft²/hr","in²/s","in²/min","in²/hr"],"Linear Thermal Expansion Coefficient":["1/°K","1/°C","1/°F","1/°Ra"],"Thermal Conductivity":["W/(m⋅°K)","W/(cm⋅°K)","BTU/(h⋅ft⋅°F)","BTU/(h⋅in⋅°F)"],"Electrical Charge":["C[coulomb]","Ah","ampere-hour","mAh","e[electron]","faraday"],"Electrical Potential Difference (Voltage)":["V","Volt","joule/coulomb","J/C","µV","mV","kV","MV"],"Electrical Resistance(Impedance)":["Ω[Ohm]","µΩ","mΩ","kΩ","MΩ"],"Electrical Capacitance":["F[farad]","pF","nF","µF","mF"],"Electrical Inductance":["H[henry]","µH","mH"],"Electrical Conductance":["S[siemens]","℧","µS","mS","kS"],"Magnetic Flux":["Wb[weber]","nWb","µWb","mWb","cWb","dWb"],"Luminous Flux":["lm[lumen]","cd⋅sr"],"Magnetic Flux Density":["T[tesla]","Wb/m²","µT","G","mT"],"Katalytic Activity":["kat[katal]","mol/s","µkat","mkat","kkat","Mkat"],Radioactivity:["Bq[becquerel]","1/s","µBq","mBq","kBq","MBq","Rd[rutherford]","Ci[curie]"],"Absorbed Dose of Ionizing Radiation":["Gy[gray]","J/kg","µGy","mGy","kGy","MGy"],"Equivalent Dose of Ionizing Radiation":["Sv[sievert]","J/kg","µSv","mSv","kSv","MSv"],"Volumetric Displacement":["m³/rad","m³/rev","L/rev","cc/rev","ft³/rev","in³/rev","gal(US-liquid)/rev"],"Fuel Economy":["km/L","mpg(US)","mile/gal(US-liquid)","mpg(UK)","mile/gal(UK-imperial)","mile/L"],"Fuel Consumption":["m³/m","L/km","L/100km","L/mile","L/100mile","gal(US-liquid)/mile","gal(US-liquid)/100mile","gal(UK-imperial)/mile","gal(UK-imperial)/100mile"],"New Energy Economy (MPGe)":["m/J","km/kWh","km/MJ","MPGe","mile/MJ","mile/kWh","mile/MM Btu"],"New Energy Consumption":["J/m","Wh/km","Wh/mile","kWh/km","kWh/100km","kWh/mile","kWh/100mile","MJ/km","MJ/100km","MJ/mile","MJ/100mile","MM Btu/km","MM Btu/100km","MM Btu/mile","MM Btu/100mile"],"Baud Rate":["bit/s","Bd","kBd","MBd","GBd"],Currency:["$","¢","$1K","$1M","$1B","$1T"],"Impulse / Momentum":["N·s","Newton-second","lb·s","kg·m/s","lbm·fps","lbm·fpm"],"Digital Storage":["bit","kilobit","kibibit","megabit","mebibit","gigabit","gibibit","terabit","tebibit","petabit","pebibit","byte","kilobyte","kibibyte","megabyte","mebibyte","gigabyte","gibibyte","terabyte","tebibyte","petabyte","pebibyte"],"Data Transfer Rate":["bit/s","kilobit/s","kibibit/s","megabit/s","mebibit/s","gigabit/s","gibibit/s","terabit/s","tebibit/s","petabit/s","pebibit/s"]},w={Length:{m:1,"nano[nm]":1/1e9,µm:1/1e6,micron:1/1e6,mm:1/1e3,cm:.01,dm:.1,km:1e3,in:a,"thou[mil, or thousandth of an inch]":a/1e3,"ft-in":a,ft:n,yd:3*n,mile:H*n,"NM[M, nmi, or nautical mile]":W},Mass:{kg:1,g:.001,mg:1/1e6,µg:1/1e9,oz:1/16*o,lbm:o,slug:N,"ton(US/short)":2e3*o,"ton(UK-Imperial/long)":2240*o,tonne:1e3},Time:{"s[second]":1,s:1,minute:60,h:3600,"h[hour]":3600,day:3600*24,week:3600*24*7},ElectricalCurrent:{A:1,"Ampere[amp]":1,mA:.001,µA:1e-6,kA:1e3,MA:1e6,"esu/s":1/3e9},Temperature:{"°K":{c0:1,c1:0},"°C":{c0:1,c1:273.15},"°F":{c0:5/9,c1:255.3722222},"°Ra":{c0:5/9,c1:0}},"Amount of Substance":{mol:1,mmol:.001,kmol:1e3},"Luminous Intensity":{"cd[candela]":1,"lm/sr":1,"cp[candlepower]":1,"cp[candlepower(before 1948)]":.981},Acceleration:{"m/s²":1,"m/min²":1/3600,"mm/s²":.001,"ft/s²":n,"ft/min²":n/3600,"in/s²":a},"Gravitational Constant":{"m³/kg/s²":1,"N⋅m²/kg²":1,"dyn⋅cm²/g²":1e3},"Velocity (Angular)":{"rad/s":1,"rad/min":1/60,"rad/h":1/3600,"deg°/s":Math.PI/180,"deg°/min":Math.PI/180/60,"deg°/h":Math.PI/180/3600,"rpm[rev/min]":2*Math.PI/60,"rev/s":2*Math.PI},"Acceleration (Angular)":{"rad/s²":1,"rad/min²":1/3600,"deg°/s²":Math.PI/180,"deg°/min²":Math.PI/180/3600},Illuminance:{lux:1,"lumen/m²":1,"lm/m²":1,"meter-candle":1,phot:1e4,"foot-candle":1/Math.pow(n,2),fc:1/Math.pow(n,2),"lumen/ft²":1/Math.pow(n,2),"lm/ft²":1/Math.pow(n,2)},Frequency:{Hz:1,"1/s":1,"1/min":1/60,rpm:1/60,"1/hour":1/3600,mHz:1/1e3,kHz:1e3,MHz:1e6,GHz:1e9},Area:{"m²":1,"µm²":Math.pow(1/1e6,2),"mm²":Math.pow(1/1e3,2),"cm²":Math.pow(1/100,2),"km²":1e6,hectare:Math.pow(100,2),"in²":Math.pow(a,2),"ft²":Math.pow(n,2),"yd²":Math.pow(n*3,2),acre:Q*Math.pow(n,2),"mile²":Math.pow(H*n,2)},"Volume / Section Modulus":{"m³":1,"µm³":Math.pow(1/1e6,3),"mm³":Math.pow(1/1e3,3),"cm³":Math.pow(1/100,3),L:1/1e3,ml:1/1e6,"km³":Math.pow(1e3,3),"in³":Math.pow(a,3),"ft³":Math.pow(n,3),"yd³":Math.pow(n*3,3),"gal(UK-imperial)":p*1/1e3,"gal(US-liquid)":g*Math.pow(a,3),"gal(US-dry)":I*Math.pow(a,3),"pint(UK-imperial)":f*p*1/1e3,"pint(US-liquid)":f*g*Math.pow(a,3),"pint(US-dry)":f*I*Math.pow(a,3),"fluid ounce(UK-imperial)":F*f*p/1e3,"fluid ounce(US-liquid)":j*f*g*Math.pow(a,3),"bushel(UK-imperial)":B*p/1e3,"bushel(US-dry)":_*I*Math.pow(a,3),"cup(US-liquid)":Y*g*Math.pow(a,3),"cup(Legal)":X*Math.pow(.01,3),"cup(Metric)":Z*Math.pow(.01,3),"cup(Imperial)":tt*F*f*p/1e3},"Polar Moment of Inertia":{"m⁴":1,"mm⁴":1e-12,"cm⁴":1e-8,"in⁴":Math.pow(a,4),"ft⁴":Math.pow(n,4)},"Moment of Inertia":{"kg⋅m²":1,"g⋅cm²":1/(1e3*1e4),"g⋅mm²":1/(1e3*1e6),"lbm⋅ft²":o*Math.pow(n,2),"lbm⋅in²":o*Math.pow(a,2),"oz⋅in²":o/16*Math.pow(a,2)},Force:{N:1,kN:1e3,MN:1e6,kgf:r,lb:o*r,lbf:o*r,"kip[kilo pound]":1e3*o*r},Angle:{radian:1,rad:1,"deg°":Math.PI/180,revolution:Math.PI*2},"Solid Angle":{"sr[steradian]":1,"m²/m²":1},"BMI-Body Mass Index/Ballistic Coefficient":{"kg/m²":1,"g/cm²":1/1e3/Math.pow(.01,2),"g/mm²":1/1e3/Math.pow(.001,2),"tonne/m²":1e3,"lbm/yd²":o/Math.pow(n*3,2),"lbm/ft²":o/Math.pow(n,2),"lbm/in²":o/Math.pow(a,2),"oz/yd²":o/16/Math.pow(3*n,2),"oz/ft²":o/16/Math.pow(n,2),"oz/in²":o/16/Math.pow(a,2)},Density:{"kg/m³":1,"kg/L":1e3,"g/cm³":1/1e3/Math.pow(.01,3),"g/mm³":1/1e3/Math.pow(.001,3),"lbm/ft³":o/Math.pow(n,3),"lbm/in³":o/Math.pow(a,3)},Energy:{"J[Joule]":1,kJ:1e3,MJ:1e6,GJ:1e9,"TNT Equivalent[kiloton]":1e9*M,Btu:b,"MM Btu":b*1e6,"calorie(IT)":y,"kilo-calorie(IT)":y*1e3,"calorie(TH)":M,"kilo-calorie(TH)":M*1e3,"HP Hour":R*3600,Wh:3600,kWh:3600*1e3,"eV{electron-volt]":1/et},Power:{W:1,kW:1e3,MW:1e6,"GW[Gigawatt]":1e9,"Btu/h":b/3600,"Btu/minute":b/60,"MM Btu/h":b*1e6/3600,"Btu(AC)":b/3600,"calorie(IT)/second":y,"calorie(IT)/minute":y/60,"kilo-calorie(IT)/hour":y*1e3/3600,"calorie(TH)/second":M,"calorie(TH)/minute":M/60,"kilo-calorie(TH)/hour":M*1e3/3600,"lb-ft/second":o*r*n,"lb-ft/minute":o*r*n/60,HP:R,"J/second":1,"J/minute":1/60,"J/h":1/3600,"MJ/h":1e6/3600,"kJ/minute":1e3/60},"Torque, Moment of Force":{Nm:1,kNm:1e3,"lb-in":o*r*a,"kip-in":1e3*o*r*a,"lb-ft":o*r*n,"oz-in":o/16*r*a,"oz-ft":o/16*r*n},"Pressure/Stress":{Pa:1,kPa:1e3,MPa:1e6,GPa:1e9,bar:100*1e3,mbar:100,atm:C,"mm HG":U,"cm HG":U*10,"in HG":U*25.4,"mm W.C.":1/1e3*1e3*r,"m W.C.":1*1e3*r,"in W.C.":a*1e3*r,psf:o*r/Math.pow(n,2),psi:o*r/Math.pow(a,2),ksi:o*r/Math.pow(a,2)*1e3,"ksi{kip/in²]":o*r/Math.pow(a,2)*1e3},"Pressure Drop per Unit Length":{"Pa/m":1,"Pascal/m":1,"kPa/m":1e3,"MPa/km":1e6/1e3,"bar/m":1e5,"mbar/mm":100*1e3,"atm/m":C,"mm HG/m":U,"in HG/ft":U*25.4/n,"mm W.C./m":1/1e3*1e3*r,"m W.C./m":1e3*r,"in W.C./ft":a*1e3*r/n,"in W.C./100 ft":a*1e3*r/n/100,"psf/in":o*r/Math.pow(n,2)/a,"psi/ft":o*r/Math.pow(n,2)/n,"ksi/ft":o*r/Math.pow(n,2)/n*1e3,"Torr/ft":$*C/n,"mTorr/m":$*C/1e3},"Uniformly Distributed (Uniform Line) Load | Stiffness of Linear Spring":{"N/m":1,"N/mm":1e3,"kN/m":1e3,"lb/ft":o*r/n,"kips/ft":1e3*o*r/n,"lb/in":o*r/a},"Stiffness of Rotary Spring":{"N⋅m/rad":1,"N⋅m/deg°":1/Math.PI*180,"N⋅mm/rad":1/1e3,"N⋅mm/deg°":1/1e3/Math.PI*180,"lb-ft/rad":o*r*n,"lb-ft/deg°":o*r*n/(Math.PI/180),"lb-in/rad":o*r*a,"lb-in/deg°":o*r*a/(Math.PI/180)},"Flow Rate (Volume)":{"m³/s":1,"m³/min":1/60,"m³/h":1/3600,"L/s":1/1e3,"L/min":1/1e3/60,"L/h":1/1e3/3600,"cm³/s":1e-6,"cm³/min":1e-6/60,"in³/s":Math.pow(a,3),"in³/min":Math.pow(a,3)/60,"ft³/s":Math.pow(n,3),CFM:Math.pow(n,3)/60,"CFM[ft³/min]":Math.pow(n,3)/60,CFH:Math.pow(n,3)/3600,"CFH[ft³/h]":Math.pow(n,3)/3600,"yd³/min":Math.pow(n*3,3)/60,"yd³/h":Math.pow(n*3,3)/3600,"gpm(US)":g*Math.pow(a,3)/60,"gph(US)":g*Math.pow(a,3)/3600,"bushel(UK-imperial)/h":B*p/1e3/3600,"bushel(US)/h":_*I*Math.pow(a,3)/3600},"Flow Rate (Mass)":{"kg/s":1,"kg/min":1/60,"kg/h":1/3600,"g/s":1/1e3,"g/min":1/1e3/60,"g/h":1/1e3/3600,"slug/s":N,"slug/min":N/60,"slug/h":N/3600,"lbm/s":o,"lbm/min":o/60,"lbm/h":o/3600,"oz/s":o/16,"oz/min":o/16/60,"oz/h":o/16/3600,"tonne/h":1e3/3600,"short ton/h":2e3*o/3600,"long ton/h":2240*o/3600},"Speed / Velocity (Linear)":{"m/s":1,"mm/s":1/1e3,"km/s":1,"mm/min":1/1e3/60,"m/min":1/60,"km/min":1e3/60,"mm/h":1/1e3/3600,"m/h":1/3600,"km/h":1e3/3600,"in/s":a,fps:n,"fps[ft/second]":n,fpm:n/60,"fpm[ft/minute]":n/60,"mph[mile/h]":H*n/3600,"knot[kn, kt, or nautical mile/h]":W/3600},"Electrical Potential Difference (Voltage)":{V:1,Volt:1,"joule/coulomb":1,"J/C":1,µV:1/1e6,mV:1/1e3,kV:1e3,MV:1e6}},T=l=>{if(console.log("getUnitCategory called with unit:",l),!l)return console.warn("Unit is undefined or null"),"Custom";for(const t in k)if(k[t].includes(l))return console.log(`Category found for unit ${l}:`,t),t;return console.warn(`No category found for unit: ${l}`),"Custom"},d=(l,t,e,i)=>{if(t==="ft-in"&&e!=="ft-in")return it(l,e);if(t!=="ft-in"&&e==="ft-in")return nt(l,t);if(i!=="Temperature"){const s=w[i][t]/w[i][e];return l*s}else{const s=w[i][t].c0,m=w[i][t].c1,c=w[i][e].c0,h=w[i][e].c1;return(l*s+m-h)/c}},O=(l,t)=>{let e;if(Number.isInteger(l)?e=l.toString():e=l.toFixed(t).replace(/\.?0+$/,""),Math.abs(parseFloat(e))>=1e3){const i=e.split(".");i[0]=i[0].replace(/\B(?=(\d{3})+(?!\d))/g,","),e=i.join(".")}return e},P=l=>{const t=/(\d+)\'(\s*-\s*)?(\d+)?(\s+)?(\d+)?\/?(\d+)?/,e=/(\d+)\'/,i=/(\d+)/;let s=l.match(t);if(s){const m=parseInt(s[1])||0,c=parseInt(s[3])||0,h=parseInt(s[5])||0,v=parseInt(s[6])||1;return D(m,c,h,v)}if(s=l.match(e),s){const m=parseInt(s[1])||0;return D(m,0,0,1)}if(s=l.match(i),s){const m=parseInt(s[1])||0;return D(0,m,0,1)}return parseFloat(l)},D=(l,t,e,i)=>l*12+t+e/i,S=(l,t='1/16"')=>{if(l<0)return`-${S(-l,t)}`;const e=parseInt(t.split("/")[1].replace('"',""));let i=Math.floor(l/12),s=Math.floor(l%12);const m=l-Math.floor(l);let c="";if(m>0&&t!==0){let v=Math.round(m*e);const q=(K,x)=>x?q(x,K%x):K,z=q(v,e);c=` ${v/z}/${e/z}`,c.trim()==="1/1"&&(s++,s>=12&&(i++,s-=12),c="")}let h="";return i>0&&(h+=`${i}'`),i>0&&(s>0||c!=="")&&(h+="-"),s>0&&(h+=`${s}`),c!==""&&(h+=c),(s>0||c!=="")&&(h+='"'),h.trim()},it=(l,t)=>{const e=l*.0254;return d(e,"m",t,"Length")},nt=(l,t)=>d(l,t,"m","Length")/.0254;class E extends HTMLElement{constructor(){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")}connectedCallback(){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()}disconnectedCallback(){this.removeEventListeners()}static get observedAttributes(){return["value","unit","decimal-places","show-unit-arrow"]}attributeChangedCallback(t,e,i){if(console.log(`attributeChangedCallback called: ${t}`,{oldValue:e,newValue:i}),t==="value")this.inputValue=i||"0",this.value=this.parseValue(this.inputValue,this.unit),console.log("New value parsed:",this.value);else if(t==="unit"){const s=this.unit,m=this.unitCategory;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=d({value:this.value,fromUnit:s,toUnit:this.unit,unitCategory:this.unitCategory})):console.log("Unit category changed, keeping original value"),console.log("New value:",this.value))}else 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));this.render()}updateUnitCategory(){console.log("updateUnitCategory called with unit:",this.unit),this.unitCategory=T(this.unit),console.log("Updated unit category:",this.unitCategory)}parseValue(t,e){if(console.log("parseValue called with:",{value:t,unit:e}),typeof t=="string"&&t.trim()==="")return console.log("Empty string value, returning 0"),0;const i=e==="ft-in"?P(t):parseFloat(t)||0;return console.log("Parsed value:",i),i}formatDisplayValue(){return this.unit==="ft-in"?S(this.value):O(this.value,this.decimalPlaces)}handleUnitChange(t){if(t.target.tagName==="SELECT"){const e=t.target.value;console.log("handleUnitChange:",{from:this.unit,to:e,value:this.value,unitCategory:this.unitCategory}),this.value=d(this.value,this.unit,e,this.unitCategory),console.log("Converted value:",this.value),this.unit=e,this.updateUnitCategory(),this.render()}this.updateDropdownWidth()}render(){const t=this.formatDisplayValue();this.shadowRoot.innerHTML=`
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.PQWebComponents = {}));
3
+ })(this, function(exports2) {
4
+ "use strict";/**
5
+ * physical-quantity v1.2.0
6
+ * A web component bundle to represent physical quantities with automated unit conversion.
7
+ * @license MIT
8
+ * @author E3d - Don Wen <don.wen@calcslive.com>
9
+ */
10
+
11
+ const THOUSAND = 1e3;
12
+ const MILLION = 1e6;
13
+ const BILLION = 1e9;
14
+ const POUNDMASS_KG = 0.45359237;
15
+ const GRAVITY_SI = 9.80665;
16
+ const MILE_FOOT = 5280;
17
+ const INCH_METER = 25.4 / 1e3;
18
+ const FOOT_METER = 12 * INCH_METER;
19
+ const NM_METER = 1852;
20
+ const ACRE_FOOT2 = 66 * 660;
21
+ const GALLON_UK_IMPERIAL_LITRE = 4.54609;
22
+ const GALLON_US_LIQUID_IN3 = 231;
23
+ const GALLON_US_DRY_IN3 = 268.8025;
24
+ const PINT_GALLON = 1 / 8;
25
+ const OUNCE_FLUID_PINT_UK_IMPERIAL = 1 / 20;
26
+ const OUNCE_FLUID_PINT_US_LIQUID = 1 / 16;
27
+ const BUSHEL_GALLON_UK_IMPERIAL = 8;
28
+ const BUSHEL_GALLON_US_DRY = 8;
29
+ const CUP_US_GALLON_LIQUID = 1 / 16;
30
+ const CUP_LEGAL_ML_LIQUID = 240;
31
+ const CUP_METRIC_ML_LIQUID = 250;
32
+ const CUP_IMPERIAL_OUNCE_LIQUID = 10;
33
+ const SLUG_KG = 14.59390294;
34
+ const BTU_J = 1055.05585262;
35
+ const CALORIE_IT_J = 4.1868;
36
+ const CALORIE_TH_J = 4.184;
37
+ const HP_W = 550 * POUNDMASS_KG * GRAVITY_SI * FOOT_METER;
38
+ const ATM_PA = 101325;
39
+ const TORR_ATM = 1 / 760;
40
+ const MMHG_PA = 133.322387415;
41
+ const J_EV = 624150974e10;
42
+ const UNITS = {
43
+ /* 901 */
44
+ Length: [
45
+ "m",
46
+ "nano[nm]",
47
+ "µm",
48
+ "micron",
49
+ "mm",
50
+ "cm",
51
+ "dm",
52
+ "km",
53
+ "in",
54
+ "ft-in",
55
+ "thou[mil, or thousandth of an inch]",
56
+ // a thousandth is called a thou per wiki
57
+ "ft",
58
+ "yd",
59
+ "mile",
60
+ "NM[M, nmi, or nautical mile]"
61
+ ],
62
+ /* 902 */
63
+ Mass: [
64
+ "kg",
65
+ "g",
66
+ "mg",
67
+ "µg",
68
+ "oz",
69
+ "lbm",
70
+ "slug",
71
+ "ton(US/short)",
72
+ "ton(UK-Imperial/long)",
73
+ "tonne"
74
+ ],
75
+ /* 903 */
76
+ Time: ["s[second]", "s", "minute", "h", "h[hour]", "day", "week"],
77
+ /* 904 */
78
+ ElectricalCurrent: ["A", "Ampere[amp]", "mA", "µA", "kA", "MA", "esu/s"],
79
+ /* 905 */
80
+ Temperature: ["°K", "°C", "°F", "°Ra"],
81
+ /* 906 */
82
+ "Amount of Substance": ["mol", "mmol", "kmol"],
83
+ /* 907 */
84
+ "Luminous Intensity": [
85
+ "cd[candela]",
86
+ "lm/sr",
87
+ "cp[candlepower]",
88
+ "cp[candlepower(before 1948)]"
89
+ ],
90
+ /* 100 */
91
+ Acceleration: ["m/s²", "m/min²", "mm/s²", "ft/s²", "ft/min²", "in/s²"],
92
+ /* 1001 */
93
+ "Gravitational Constant": ["m³/kg/s²", "N⋅m²/kg²", "dyn⋅cm²/g²"],
94
+ /* 1010 */
95
+ "Velocity (Angular)": [
96
+ "rad/s",
97
+ "rad/min",
98
+ "rad/h",
99
+ "deg°/s",
100
+ "deg°/min",
101
+ "deg°/h",
102
+ "rpm[rev/min]",
103
+ "rev/s"
104
+ ],
105
+ /* 1011 */
106
+ "Acceleration (Angular)": ["rad/s²", "rad/min²", "deg°/s²", "deg°/min²"],
107
+ /* 102 */
108
+ Illuminance: [
109
+ "lux",
110
+ "lumen/m²",
111
+ "lm/m²",
112
+ "meter-candle",
113
+ "phot",
114
+ "foot-candle",
115
+ "fc",
116
+ "lumen/ft²",
117
+ "lm/ft²"
118
+ ],
119
+ /* 103 */
120
+ Frequency: ["Hz", "1/s", "1/min", "rpm", "1/hour", "mHz", "kHz", "MHz", "GHz"],
121
+ /* 104 */
122
+ Area: [
123
+ "m²",
124
+ "µm²",
125
+ "mm²",
126
+ "cm²",
127
+ "km²",
128
+ "hectare",
129
+ "in²",
130
+ "ft²",
131
+ "yd²",
132
+ "acre",
133
+ "mile²"
134
+ ],
135
+ /* 105 */
136
+ "Volume / Section Modulus": [
137
+ "m³",
138
+ "µm³",
139
+ "mm³",
140
+ "cm³",
141
+ "L",
142
+ "ml",
143
+ "km³",
144
+ "in³",
145
+ "ft³",
146
+ "yd³",
147
+ "gal(UK-imperial)",
148
+ "gal(US-liquid)",
149
+ "gal(US-dry)",
150
+ "pint(UK-imperial)",
151
+ "pint(US-liquid)",
152
+ "pint(US-dry)",
153
+ "fluid ounce(UK-imperial)",
154
+ "fluid ounce(US-liquid)",
155
+ "bushel(UK-imperial)",
156
+ "bushel(US-dry)",
157
+ "cup(US-liquid)",
158
+ "cup(Legal)",
159
+ "cup(Metric)",
160
+ "cup(Imperial)"
161
+ ],
162
+ /* 106 */
163
+ "Polar Moment of Inertia": ["m⁴", "mm⁴", "cm⁴", "in⁴", "ft⁴"],
164
+ /* 1060 */
165
+ "Moment of Inertia": ["kg⋅m²", "g⋅cm²", "g⋅mm²", "lbm⋅ft²", "lbm⋅in²", "oz⋅in²"],
166
+ /* 107 */
167
+ Force: ["N", "kN", "MN", "kgf", "lb", "lbf", "kip[kilo pound]"],
168
+ /* 108 */
169
+ Angle: ["radian", "rad", "deg°", "revolution"],
170
+ /* 1081 */
171
+ "Solid Angle": ["sr[steradian]", "m²/m²"],
172
+ /* 1090 */
173
+ "BMI-Body Mass Index/Ballistic Coefficient": [
174
+ "kg/m²",
175
+ "g/cm²",
176
+ "g/mm²",
177
+ "tonne/m²",
178
+ "lbm/yd²",
179
+ "lbm/ft²",
180
+ "lbm/in²",
181
+ "oz/yd²",
182
+ "oz/ft²",
183
+ "oz/in²"
184
+ ],
185
+ /* 1091 */
186
+ Density: ["kg/m³", "kg/L", "g/cm³", "g/mm³", "lbm/ft³", "lbm/in³"],
187
+ /* 110 */
188
+ Energy: [
189
+ "J[Joule]",
190
+ "kJ",
191
+ "MJ",
192
+ "GJ",
193
+ "TNT Equivalent[kiloton]",
194
+ "Btu",
195
+ "MM Btu",
196
+ "calorie(IT)",
197
+ // 4.1868J
198
+ "kilo-calorie(IT)",
199
+ "calorie(TH)",
200
+ // 4.184J
201
+ "kilo-calorie(TH)",
202
+ "HP Hour",
203
+ "Wh",
204
+ "kWh",
205
+ "eV[electron-volt]"
206
+ ],
207
+ /* 111 */
208
+ Power: [
209
+ "W",
210
+ "kW",
211
+ "MW",
212
+ "GW[Gigawatt]",
213
+ "Btu/h",
214
+ "Btu/minute",
215
+ "MM Btu/h",
216
+ "Btu(AC)",
217
+ "calorie(IT)/second",
218
+ "calorie(IT)/minute",
219
+ "kilo-calorie(IT)/hour",
220
+ "calorie(TH)/second",
221
+ "calorie(TH)/minute",
222
+ "kilo-calorie(TH)/hour",
223
+ "lb-ft/second",
224
+ "lb-ft/minute",
225
+ "HP",
226
+ "J/second",
227
+ "J/minute",
228
+ "J/h",
229
+ "MJ/h",
230
+ "kJ/minute"
231
+ ],
232
+ /* 112 */
233
+ "Torque, Moment of Force": ["Nm", "kNm", "lb-in", "kip-in", "lb-ft", "oz-in", "oz-ft"],
234
+ /* 1130 */
235
+ "Pressure/Stress": [
236
+ "Pa",
237
+ "kPa",
238
+ "MPa",
239
+ "GPa",
240
+ "bar",
241
+ "mbar",
242
+ "atm",
243
+ "mm HG",
244
+ "cm HG",
245
+ "in HG",
246
+ "mm W.C.",
247
+ "m W.C.",
248
+ "in W.C.",
249
+ "psf",
250
+ "psi",
251
+ "ksi",
252
+ "ksi[kip/in²]"
253
+ ],
254
+ /* 1131 */
255
+ "Pressure Drop per Unit Length": [
256
+ "Pa/m",
257
+ "Pascal/m",
258
+ "kPa/m",
259
+ "MPa/km",
260
+ "bar/m",
261
+ "mbar/mm",
262
+ "atm/m",
263
+ "mm HG/m",
264
+ "in HG/ft",
265
+ "mm W.C./m",
266
+ "m W.C./m",
267
+ "in W.C./ft",
268
+ "in W.C./100 ft",
269
+ "psf/in",
270
+ "psi/ft",
271
+ "ksi/ft",
272
+ "Torr/ft",
273
+ "mTorr/m"
274
+ ],
275
+ /* 1132 */
276
+ "Uniformly Distributed (Uniform Line) Load | Stiffness of Linear Spring": ["N/m", "N/mm", "kN/m", "lb/ft", "kips/ft", "lb/in"],
277
+ // 1132
278
+ /* 1133 */
279
+ "Stiffness of Rotary Spring": [
280
+ "N⋅m/rad",
281
+ "N⋅m/deg°",
282
+ "N⋅mm/rad",
283
+ "N⋅mm/deg°",
284
+ "lb-ft/rad",
285
+ "lb-ft/deg°",
286
+ "lb-in/rad",
287
+ "lb-in/deg°"
288
+ ],
289
+ /* 114 */
290
+ "Flow Rate (Volume)": [
291
+ "m³/s",
292
+ "m³/min",
293
+ "m³/h",
294
+ "L/s",
295
+ "L/min",
296
+ "L/h",
297
+ "cm³/s",
298
+ "cm³/min",
299
+ "in³/s",
300
+ "in³/min",
301
+ "ft³/s",
302
+ "CFM",
303
+ "CFM[ft³/min]",
304
+ "CFH",
305
+ "CFH[ft³/h]",
306
+ "yd³/min",
307
+ "yd³/h",
308
+ "gpm(US)",
309
+ "gph(US)",
310
+ "bushel(UK-imperial)/h",
311
+ "bushel(US)/h"
312
+ ],
313
+ /* 115 */
314
+ "Flow Rate (Mass)": [
315
+ "kg/s",
316
+ "kg/min",
317
+ "kg/h",
318
+ "g/s",
319
+ "g/min",
320
+ "g/h",
321
+ "slug/s",
322
+ "slug/min",
323
+ "slug/h",
324
+ "lbm/s",
325
+ "lbm/min",
326
+ "lbm/h",
327
+ "oz/s",
328
+ "oz/min",
329
+ "oz/h",
330
+ "tonne/h",
331
+ "short ton/h",
332
+ "long ton/h"
333
+ ],
334
+ /* 117 */
335
+ "Speed / Velocity (Linear)": [
336
+ "m/s",
337
+ "mm/s",
338
+ "km/s",
339
+ "mm/min",
340
+ "m/min",
341
+ "km/min",
342
+ "mm/h",
343
+ "m/h",
344
+ "km/h",
345
+ "in/s",
346
+ "fps",
347
+ "fps[ft/second]",
348
+ "fpm",
349
+ // clear version
350
+ "fpm[ft/minute]",
351
+ // redundant version
352
+ "mph[mile/h]",
353
+ "knot[kn, kt, or nautical mile/h]"
354
+ ],
355
+ /* 118 */
356
+ /* 119 */
357
+ "Fuel Heat Value (Volume)": [
358
+ "J/m³",
359
+ "J/L",
360
+ "kJ/L",
361
+ "kJ/m³",
362
+ "MJ/m³",
363
+ "GJ/m³",
364
+ "cal(IT)/L",
365
+ // 4.1868J
366
+ "kcal(IT)/m³",
367
+ "cal(TH)/L",
368
+ // 4.184J
369
+ "kcal(TH)/m³",
370
+ "Wh/L",
371
+ "Wh/m³",
372
+ "kWh/m³",
373
+ "HP Hour/ft³",
374
+ "Btu/gal(US)",
375
+ "Btu/ft³",
376
+ "MM Btu/ft³"
377
+ ],
378
+ /* 120 */
379
+ "Fuel Heat Value (Mass)": [
380
+ "J/kg",
381
+ "J/g",
382
+ "kJ/kg",
383
+ "MJ/kg",
384
+ "GJ/kg",
385
+ "cal(IT)/g",
386
+ "kcal(IT)/kg",
387
+ "cal(TH)/g",
388
+ "kcal(TH)/kg",
389
+ "Wh/g",
390
+ "Wh/kg",
391
+ "kWh/kg",
392
+ "HP Hour/lbm",
393
+ "Btu/lbm",
394
+ "MM Btu/lbm",
395
+ "Btu/ton(short)"
396
+ ],
397
+ /* 121 */
398
+ "Mass Heat Capacity": ["J/(kg·°K)", "J/(kg·°C)", "J/(g·°K)", "J/(g·°C)", "Btu/(lbm·°F)"],
399
+ /* 122 */
400
+ "Viscosity - Absolute/Dynamic(μ)": [
401
+ "PI[Pa·s]",
402
+ "N·s/m²",
403
+ "kg/m/s",
404
+ "P[Poise]",
405
+ "cP",
406
+ "lb·s/ft²",
407
+ "lbm/ft/s"
408
+ ],
409
+ /* 123 */
410
+ "Viscosity - Kinematic": [
411
+ "m²/s",
412
+ "m²/min",
413
+ "m²/hr",
414
+ "St[cm²/s]",
415
+ "Stoke",
416
+ "cm²/min",
417
+ "cm²/hr",
418
+ "cSt[mm²/s]",
419
+ "mm²/min",
420
+ "mm²/hr",
421
+ "ft²/s",
422
+ "ft²/min",
423
+ "ft²/hr",
424
+ "in²/s",
425
+ "in²/min",
426
+ "in²/hr"
427
+ ],
428
+ /* 1240 */
429
+ "Linear Thermal Expansion Coefficient": ["1/°K", "1/°C", "1/°F", "1/°Ra"],
430
+ /* 1241 */
431
+ "Thermal Conductivity": ["W/(m⋅°K)", "W/(cm⋅°K)", "BTU/(h⋅ft⋅°F)", "BTU/(h⋅in⋅°F)"],
432
+ // TODO:
433
+ /* 125 */
434
+ "Electrical Charge": [
435
+ "C[coulomb]",
436
+ "Ah",
437
+ "ampere-hour",
438
+ "mAh",
439
+ "e[electron]",
440
+ "faraday"
441
+ ],
442
+ /* 126 */
443
+ "Electrical Potential Difference (Voltage)": [
444
+ "V",
445
+ "Volt",
446
+ "joule/coulomb",
447
+ "J/C",
448
+ "µV",
449
+ "mV",
450
+ "kV",
451
+ "MV"
452
+ ],
453
+ /* 127 */
454
+ "Electrical Resistance(Impedance)": ["Ω[Ohm]", "µΩ", "mΩ", "kΩ", "MΩ"],
455
+ /* 128 */
456
+ "Electrical Capacitance": ["F[farad]", "pF", "nF", "µF", "mF"],
457
+ /* 129 */
458
+ "Electrical Inductance": ["H[henry]", "µH", "mH"],
459
+ /* 130 */
460
+ "Electrical Conductance": ["S[siemens]", "℧", "µS", "mS", "kS"],
461
+ /* 131 */
462
+ "Magnetic Flux": ["Wb[weber]", "nWb", "µWb", "mWb", "cWb", "dWb"],
463
+ /* 132 */
464
+ "Luminous Flux": ["lm[lumen]", "cd⋅sr"],
465
+ /* 133 */
466
+ "Magnetic Flux Density": ["T[tesla]", "Wb/m²", "µT", "G", "mT"],
467
+ /* 134 */
468
+ "Katalytic Activity": ["kat[katal]", "mol/s", "µkat", "mkat", "kkat", "Mkat"],
469
+ /* 135 */
470
+ Radioactivity: [
471
+ "Bq[becquerel]",
472
+ "1/s",
473
+ "µBq",
474
+ "mBq",
475
+ "kBq",
476
+ "MBq",
477
+ "Rd[rutherford]",
478
+ "Ci[curie]"
479
+ ],
480
+ /* 136 */
481
+ "Absorbed Dose of Ionizing Radiation": ["Gy[gray]", "J/kg", "µGy", "mGy", "kGy", "MGy"],
482
+ /* 137 */
483
+ "Equivalent Dose of Ionizing Radiation": ["Sv[sievert]", "J/kg", "µSv", "mSv", "kSv", "MSv"],
484
+ /* 138 */
485
+ "Volumetric Displacement": [
486
+ /** baseUnit does not need to be included here.
487
+ * => Update: show baseUnit so user can tell it is based on volume/angle, instead of volume/cycle. 20221016
488
+ */
489
+ "m³/rad",
490
+ "m³/rev",
491
+ "L/rev",
492
+ "cc/rev",
493
+ "ft³/rev",
494
+ "in³/rev",
495
+ "gal(US-liquid)/rev"
496
+ ],
497
+ /* 139 */
498
+ "Fuel Economy": [
499
+ // 'm/m³',
500
+ "km/L",
501
+ "mpg(US)",
502
+ "mile/gal(US-liquid)",
503
+ "mpg(UK)",
504
+ "mile/gal(UK-imperial)",
505
+ "mile/L"
506
+ ],
507
+ /* 140 */
508
+ "Fuel Consumption": [
509
+ "m³/m",
510
+ "L/km",
511
+ "L/100km",
512
+ "L/mile",
513
+ "L/100mile",
514
+ "gal(US-liquid)/mile",
515
+ "gal(US-liquid)/100mile",
516
+ "gal(UK-imperial)/mile",
517
+ "gal(UK-imperial)/100mile"
518
+ ],
519
+ /* 141 */
520
+ "New Energy Economy (MPGe)": [
521
+ "m/J",
522
+ "km/kWh",
523
+ "km/MJ",
524
+ "MPGe",
525
+ "mile/MJ",
526
+ "mile/kWh",
527
+ "mile/MM Btu"
528
+ ],
529
+ /* 142 */
530
+ "New Energy Consumption": [
531
+ "J/m",
532
+ "Wh/km",
533
+ "Wh/mile",
534
+ "kWh/km",
535
+ "kWh/100km",
536
+ "kWh/mile",
537
+ "kWh/100mile",
538
+ "MJ/km",
539
+ "MJ/100km",
540
+ "MJ/mile",
541
+ "MJ/100mile",
542
+ "MM Btu/km",
543
+ "MM Btu/100km",
544
+ "MM Btu/mile",
545
+ "MM Btu/100mile"
546
+ ],
547
+ /* 143 */
548
+ "Baud Rate": ["bit/s", "Bd", "kBd", "MBd", "GBd"],
549
+ /* 144 */
550
+ /* 145 */
551
+ /* 146 */
552
+ /* 147 */
553
+ /* 148 */
554
+ /* 149 */
555
+ /* 150 */
556
+ Currency: ["$", "¢", "$1K", "$1M", "$1B", "$1T"],
557
+ /* 151 */
558
+ "Impulse / Momentum": ["N·s", "Newton-second", "lb·s", "kg·m/s", "lbm·fps", "lbm·fpm"],
559
+ /* 152 */
560
+ "Digital Storage": [
561
+ "bit",
562
+ "kilobit",
563
+ "kibibit",
564
+ "megabit",
565
+ "mebibit",
566
+ "gigabit",
567
+ "gibibit",
568
+ "terabit",
569
+ "tebibit",
570
+ "petabit",
571
+ "pebibit",
572
+ "byte",
573
+ "kilobyte",
574
+ "kibibyte",
575
+ "megabyte",
576
+ "mebibyte",
577
+ "gigabyte",
578
+ "gibibyte",
579
+ "terabyte",
580
+ "tebibyte",
581
+ "petabyte",
582
+ "pebibyte"
583
+ ],
584
+ /* 153 */
585
+ "Data Transfer Rate": [
586
+ "bit/s",
587
+ "kilobit/s",
588
+ "kibibit/s",
589
+ "megabit/s",
590
+ "mebibit/s",
591
+ "gigabit/s",
592
+ "gibibit/s",
593
+ "terabit/s",
594
+ "tebibit/s",
595
+ "petabit/s",
596
+ "pebibit/s"
597
+ ]
598
+ /* 154 */
599
+ /* */
600
+ };
601
+ const CONVERSION_FACTORS = {
602
+ /* 901 */
603
+ Length: {
604
+ "m": 1,
605
+ "nano[nm]": 1 / BILLION,
606
+ "µm": 1 / MILLION,
607
+ "micron": 1 / MILLION,
608
+ "mm": 1 / THOUSAND,
609
+ "cm": 0.01,
610
+ "dm": 0.1,
611
+ "km": THOUSAND,
612
+ "in": INCH_METER,
613
+ "thou[mil, or thousandth of an inch]": INCH_METER / THOUSAND,
614
+ // a thousandth is called a thou per wiki
615
+ "ft-in": INCH_METER,
616
+ "ft": FOOT_METER,
617
+ "yd": 3 * FOOT_METER,
618
+ "mile": MILE_FOOT * FOOT_METER,
619
+ "NM[M, nmi, or nautical mile]": NM_METER
620
+ },
621
+ /* 902 */
622
+ Mass: {
623
+ "kg": 1,
624
+ "g": 1e-3,
625
+ "mg": 1 / MILLION,
626
+ "µg": 1 / BILLION,
627
+ "oz": 1 / 16 * POUNDMASS_KG,
628
+ "lbm": POUNDMASS_KG,
629
+ "slug": SLUG_KG,
630
+ "ton(US/short)": 2e3 * POUNDMASS_KG,
631
+ "ton(UK-Imperial/long)": 2240 * POUNDMASS_KG,
632
+ "tonne": THOUSAND
633
+ },
634
+ /* 903 */
635
+ Time: {
636
+ /* ["s[second]", "s", "minute", "h", "h[hour]", "day", "week"], */
637
+ "s[second]": 1,
638
+ "s": 1,
639
+ "minute": 60,
640
+ "h": 3600,
641
+ "h[hour]": 3600,
642
+ "day": 3600 * 24,
643
+ "week": 3600 * 24 * 7
644
+ },
645
+ /* 904 */
646
+ ElectricalCurrent: {
647
+ /* ["A", "Ampere[amp]", "mA", "µA", "kA", "MA", "esu/s"], */
648
+ "A": 1,
649
+ "Ampere[amp]": 1,
650
+ "mA": 1e-3,
651
+ "µA": 1e-6,
652
+ "kA": THOUSAND,
653
+ "MA": MILLION,
654
+ "esu/s": 1 / 3e9
655
+ },
656
+ /* 905 */
657
+ Temperature: {
658
+ "°K": { c0: 1, c1: 0 },
659
+ "°C": { c0: 1, c1: 273.15 },
660
+ "°F": { c0: 5 / 9, c1: 255.3722222 },
661
+ "°Ra": { c0: 5 / 9, c1: 0 }
662
+ },
663
+ /* 906 */
664
+ "Amount of Substance": {
665
+ "mol": 1,
666
+ "mmol": 1e-3,
667
+ "kmol": THOUSAND
668
+ },
669
+ /* 907 */
670
+ "Luminous Intensity": {
671
+ "cd[candela]": 1,
672
+ "lm/sr": 1,
673
+ "cp[candlepower]": 1,
674
+ "cp[candlepower(before 1948)]": 0.981
675
+ },
676
+ /* 100 */
677
+ Acceleration: {
678
+ "m/s²": 1,
679
+ "m/min²": 1 / 3600,
680
+ "mm/s²": 1e-3,
681
+ "ft/s²": FOOT_METER,
682
+ "ft/min²": FOOT_METER / 3600,
683
+ "in/s²": INCH_METER
684
+ },
685
+ /* 1001 */
686
+ "Gravitational Constant": {
687
+ "m³/kg/s²": 1,
688
+ "N⋅m²/kg²": 1,
689
+ "dyn⋅cm²/g²": THOUSAND
690
+ },
691
+ /* 1010 */
692
+ "Velocity (Angular)": {
693
+ "rad/s": 1,
694
+ "rad/min": 1 / 60,
695
+ "rad/h": 1 / 3600,
696
+ "deg°/s": Math.PI / 180,
697
+ "deg°/min": Math.PI / 180 / 60,
698
+ "deg°/h": Math.PI / 180 / 3600,
699
+ "rpm[rev/min]": 2 * Math.PI / 60,
700
+ "rev/s": 2 * Math.PI
701
+ },
702
+ /* 1011 */
703
+ "Acceleration (Angular)": {
704
+ "rad/s²": 1,
705
+ "rad/min²": 1 / 3600,
706
+ "deg°/s²": Math.PI / 180,
707
+ "deg°/min²": Math.PI / 180 / 3600
708
+ },
709
+ /* 102 */
710
+ Illuminance: {
711
+ "lux": 1,
712
+ "lumen/m²": 1,
713
+ "lm/m²": 1,
714
+ "meter-candle": 1,
715
+ "phot": 1e4,
716
+ "foot-candle": 1 / Math.pow(FOOT_METER, 2),
717
+ "fc": 1 / Math.pow(FOOT_METER, 2),
718
+ "lumen/ft²": 1 / Math.pow(FOOT_METER, 2),
719
+ "lm/ft²": 1 / Math.pow(FOOT_METER, 2)
720
+ },
721
+ /* 103 */
722
+ Frequency: {
723
+ "Hz": 1,
724
+ "1/s": 1,
725
+ "1/min": 1 / 60,
726
+ "rpm": 1 / 60,
727
+ "1/hour": 1 / 3600,
728
+ "mHz": 1 / THOUSAND,
729
+ "kHz": THOUSAND,
730
+ "MHz": MILLION,
731
+ "GHz": BILLION
732
+ },
733
+ /* 104 */
734
+ Area: {
735
+ "m²": 1,
736
+ "µm²": Math.pow(1 / MILLION, 2),
737
+ "mm²": Math.pow(1 / THOUSAND, 2),
738
+ "cm²": Math.pow(1 / 100, 2),
739
+ "km²": MILLION,
740
+ "hectare": Math.pow(100, 2),
741
+ "in²": Math.pow(INCH_METER, 2),
742
+ "ft²": Math.pow(FOOT_METER, 2),
743
+ "yd²": Math.pow(FOOT_METER * 3, 2),
744
+ "acre": ACRE_FOOT2 * Math.pow(FOOT_METER, 2),
745
+ "mile²": Math.pow(MILE_FOOT * FOOT_METER, 2)
746
+ },
747
+ /* 105 */
748
+ "Volume / Section Modulus": {
749
+ "m³": 1,
750
+ "µm³": Math.pow(1 / MILLION, 3),
751
+ "mm³": Math.pow(1 / THOUSAND, 3),
752
+ "cm³": Math.pow(1 / 100, 3),
753
+ "L": 1 / THOUSAND,
754
+ "ml": 1 / MILLION,
755
+ "km³": Math.pow(THOUSAND, 3),
756
+ "in³": Math.pow(INCH_METER, 3),
757
+ "ft³": Math.pow(FOOT_METER, 3),
758
+ "yd³": Math.pow(FOOT_METER * 3, 3),
759
+ "gal(UK-imperial)": GALLON_UK_IMPERIAL_LITRE * 1 / 1e3,
760
+ "gal(US-liquid)": GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3),
761
+ "gal(US-dry)": GALLON_US_DRY_IN3 * Math.pow(INCH_METER, 3),
762
+ "pint(UK-imperial)": PINT_GALLON * GALLON_UK_IMPERIAL_LITRE * 1 / 1e3,
763
+ "pint(US-liquid)": PINT_GALLON * GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3),
764
+ "pint(US-dry)": PINT_GALLON * GALLON_US_DRY_IN3 * Math.pow(INCH_METER, 3),
765
+ "fluid ounce(UK-imperial)": OUNCE_FLUID_PINT_UK_IMPERIAL * PINT_GALLON * GALLON_UK_IMPERIAL_LITRE / 1e3,
766
+ "fluid ounce(US-liquid)": OUNCE_FLUID_PINT_US_LIQUID * PINT_GALLON * GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3),
767
+ "bushel(UK-imperial)": BUSHEL_GALLON_UK_IMPERIAL * GALLON_UK_IMPERIAL_LITRE / 1e3,
768
+ "bushel(US-dry)": BUSHEL_GALLON_US_DRY * GALLON_US_DRY_IN3 * Math.pow(INCH_METER, 3),
769
+ "cup(US-liquid)": CUP_US_GALLON_LIQUID * GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3),
770
+ "cup(Legal)": CUP_LEGAL_ML_LIQUID * Math.pow(0.01, 3),
771
+ "cup(Metric)": CUP_METRIC_ML_LIQUID * Math.pow(0.01, 3),
772
+ "cup(Imperial)": CUP_IMPERIAL_OUNCE_LIQUID * OUNCE_FLUID_PINT_UK_IMPERIAL * PINT_GALLON * GALLON_UK_IMPERIAL_LITRE / 1e3
773
+ },
774
+ /* 106 */
775
+ "Polar Moment of Inertia": {
776
+ "m⁴": 1,
777
+ "mm⁴": 1e-12,
778
+ "cm⁴": 1e-8,
779
+ "in⁴": Math.pow(INCH_METER, 4),
780
+ "ft⁴": Math.pow(FOOT_METER, 4)
781
+ },
782
+ /* 1060 */
783
+ "Moment of Inertia": {
784
+ "kg⋅m²": 1,
785
+ "g⋅cm²": 1 / (THOUSAND * 1e4),
786
+ "g⋅mm²": 1 / (THOUSAND * MILLION),
787
+ "lbm⋅ft²": POUNDMASS_KG * Math.pow(FOOT_METER, 2),
788
+ "lbm⋅in²": POUNDMASS_KG * Math.pow(INCH_METER, 2),
789
+ "oz⋅in²": POUNDMASS_KG / 16 * Math.pow(INCH_METER, 2)
790
+ },
791
+ /* 107 */
792
+ Force: {
793
+ "N": 1,
794
+ "kN": THOUSAND,
795
+ "MN": MILLION,
796
+ "kgf": GRAVITY_SI,
797
+ "lb": POUNDMASS_KG * GRAVITY_SI,
798
+ "lbf": POUNDMASS_KG * GRAVITY_SI,
799
+ "kip[kilo pound]": THOUSAND * POUNDMASS_KG * GRAVITY_SI
800
+ },
801
+ /* 108 */
802
+ Angle: {
803
+ "radian": 1,
804
+ "rad": 1,
805
+ "deg°": Math.PI / 180,
806
+ "revolution": Math.PI * 2
807
+ },
808
+ /* 1081 */
809
+ "Solid Angle": {
810
+ "sr[steradian]": 1,
811
+ "m²/m²": 1
812
+ },
813
+ /* 1090 */
814
+ "BMI-Body Mass Index/Ballistic Coefficient": {
815
+ "kg/m²": 1,
816
+ "g/cm²": 1 / THOUSAND / Math.pow(0.01, 2),
817
+ "g/mm²": 1 / THOUSAND / Math.pow(1e-3, 2),
818
+ "tonne/m²": THOUSAND,
819
+ "lbm/yd²": POUNDMASS_KG / Math.pow(FOOT_METER * 3, 2),
820
+ "lbm/ft²": POUNDMASS_KG / Math.pow(FOOT_METER, 2),
821
+ "lbm/in²": POUNDMASS_KG / Math.pow(INCH_METER, 2),
822
+ "oz/yd²": POUNDMASS_KG / 16 / Math.pow(3 * FOOT_METER, 2),
823
+ "oz/ft²": POUNDMASS_KG / 16 / Math.pow(FOOT_METER, 2),
824
+ "oz/in²": POUNDMASS_KG / 16 / Math.pow(INCH_METER, 2)
825
+ },
826
+ /* 1091 */
827
+ Density: {
828
+ "kg/m³": 1,
829
+ "kg/L": 1e3,
830
+ "g/cm³": 1 / 1e3 / Math.pow(0.01, 3),
831
+ "g/mm³": 1 / 1e3 / Math.pow(1e-3, 3),
832
+ "lbm/ft³": POUNDMASS_KG / Math.pow(FOOT_METER, 3),
833
+ "lbm/in³": POUNDMASS_KG / Math.pow(INCH_METER, 3)
834
+ },
835
+ /* 110 */
836
+ Energy: {
837
+ "J[Joule]": 1,
838
+ "kJ": THOUSAND,
839
+ "MJ": MILLION,
840
+ "GJ": BILLION,
841
+ "TNT Equivalent[kiloton]": 1e9 * CALORIE_TH_J,
842
+ // 1e9 = 1000000000.0,
843
+ "Btu": BTU_J,
844
+ "MM Btu": BTU_J * MILLION,
845
+ "calorie(IT)": CALORIE_IT_J,
846
+ // 4.1868J
847
+ "kilo-calorie(IT)": CALORIE_IT_J * THOUSAND,
848
+ "calorie(TH)": CALORIE_TH_J,
849
+ // 4.184J
850
+ "kilo-calorie(TH)": CALORIE_TH_J * 1e3,
851
+ "HP Hour": HP_W * 3600,
852
+ "Wh": 3600,
853
+ "kWh": 3600 * THOUSAND,
854
+ "eV{electron-volt]": 1 / J_EV
855
+ },
856
+ /* 111 */
857
+ Power: {
858
+ "W": 1,
859
+ "kW": THOUSAND,
860
+ "MW": MILLION,
861
+ "GW[Gigawatt]": BILLION,
862
+ "Btu/h": BTU_J / 3600,
863
+ "Btu/minute": BTU_J / 60,
864
+ "MM Btu/h": BTU_J * MILLION / 3600,
865
+ "Btu(AC)": BTU_J / 3600,
866
+ "calorie(IT)/second": CALORIE_IT_J,
867
+ "calorie(IT)/minute": CALORIE_IT_J / 60,
868
+ "kilo-calorie(IT)/hour": CALORIE_IT_J * THOUSAND / 3600,
869
+ "calorie(TH)/second": CALORIE_TH_J,
870
+ "calorie(TH)/minute": CALORIE_TH_J / 60,
871
+ "kilo-calorie(TH)/hour": CALORIE_TH_J * THOUSAND / 3600,
872
+ "lb-ft/second": POUNDMASS_KG * GRAVITY_SI * FOOT_METER,
873
+ "lb-ft/minute": POUNDMASS_KG * GRAVITY_SI * FOOT_METER / 60,
874
+ "HP": HP_W,
875
+ "J/second": 1,
876
+ "J/minute": 1 / 60,
877
+ "J/h": 1 / 3600,
878
+ "MJ/h": MILLION / 3600,
879
+ "kJ/minute": THOUSAND / 60
880
+ },
881
+ /* 112 */
882
+ "Torque, Moment of Force": {
883
+ "Nm": 1,
884
+ "kNm": THOUSAND,
885
+ "lb-in": POUNDMASS_KG * GRAVITY_SI * INCH_METER,
886
+ "kip-in": THOUSAND * POUNDMASS_KG * GRAVITY_SI * INCH_METER,
887
+ "lb-ft": POUNDMASS_KG * GRAVITY_SI * FOOT_METER,
888
+ "oz-in": POUNDMASS_KG / 16 * GRAVITY_SI * INCH_METER,
889
+ "oz-ft": POUNDMASS_KG / 16 * GRAVITY_SI * FOOT_METER
890
+ },
891
+ /* 1130 */
892
+ "Pressure/Stress": {
893
+ "Pa": 1,
894
+ "kPa": THOUSAND,
895
+ "MPa": MILLION,
896
+ "GPa": BILLION,
897
+ "bar": 100 * THOUSAND,
898
+ "mbar": 100,
899
+ "atm": ATM_PA,
900
+ "mm HG": MMHG_PA,
901
+ "cm HG": MMHG_PA * 10,
902
+ "in HG": MMHG_PA * 25.4,
903
+ "mm W.C.": 1 / 1e3 * 1e3 * GRAVITY_SI,
904
+ "m W.C.": 1 * 1e3 * GRAVITY_SI,
905
+ "in W.C.": INCH_METER * 1e3 * GRAVITY_SI,
906
+ "psf": POUNDMASS_KG * GRAVITY_SI / Math.pow(FOOT_METER, 2),
907
+ "psi": POUNDMASS_KG * GRAVITY_SI / Math.pow(INCH_METER, 2),
908
+ "ksi": POUNDMASS_KG * GRAVITY_SI / Math.pow(INCH_METER, 2) * THOUSAND,
909
+ "ksi{kip/in²]": POUNDMASS_KG * GRAVITY_SI / Math.pow(INCH_METER, 2) * THOUSAND
910
+ },
911
+ /* 1131 */
912
+ "Pressure Drop per Unit Length": {
913
+ "Pa/m": 1,
914
+ "Pascal/m": 1,
915
+ "kPa/m": THOUSAND,
916
+ "MPa/km": MILLION / THOUSAND,
917
+ "bar/m": 1e5,
918
+ "mbar/mm": 100 * THOUSAND,
919
+ "atm/m": ATM_PA,
920
+ "mm HG/m": MMHG_PA,
921
+ "in HG/ft": MMHG_PA * 25.4 / FOOT_METER,
922
+ "mm W.C./m": 1 / THOUSAND * THOUSAND * GRAVITY_SI,
923
+ "m W.C./m": THOUSAND * GRAVITY_SI,
924
+ "in W.C./ft": INCH_METER * THOUSAND * GRAVITY_SI / FOOT_METER,
925
+ "in W.C./100 ft": INCH_METER * THOUSAND * GRAVITY_SI / FOOT_METER / 100,
926
+ "psf/in": POUNDMASS_KG * GRAVITY_SI / Math.pow(FOOT_METER, 2) / INCH_METER,
927
+ "psi/ft": POUNDMASS_KG * GRAVITY_SI / Math.pow(FOOT_METER, 2) / FOOT_METER,
928
+ "ksi/ft": POUNDMASS_KG * GRAVITY_SI / Math.pow(FOOT_METER, 2) / FOOT_METER * THOUSAND,
929
+ "Torr/ft": TORR_ATM * ATM_PA / FOOT_METER,
930
+ "mTorr/m": TORR_ATM * ATM_PA / THOUSAND
931
+ },
932
+ /* 1132 */
933
+ "Uniformly Distributed (Uniform Line) Load | Stiffness of Linear Spring": {
934
+ "N/m": 1,
935
+ "N/mm": THOUSAND,
936
+ "kN/m": THOUSAND,
937
+ "lb/ft": POUNDMASS_KG * GRAVITY_SI / FOOT_METER,
938
+ "kips/ft": THOUSAND * POUNDMASS_KG * GRAVITY_SI / FOOT_METER,
939
+ "lb/in": POUNDMASS_KG * GRAVITY_SI / INCH_METER
940
+ },
941
+ /* 1133 */
942
+ "Stiffness of Rotary Spring": {
943
+ "N⋅m/rad": 1,
944
+ "N⋅m/deg°": 1 / Math.PI * 180,
945
+ "N⋅mm/rad": 1 / THOUSAND,
946
+ "N⋅mm/deg°": 1 / THOUSAND / Math.PI * 180,
947
+ "lb-ft/rad": POUNDMASS_KG * GRAVITY_SI * FOOT_METER,
948
+ "lb-ft/deg°": POUNDMASS_KG * GRAVITY_SI * FOOT_METER / (Math.PI / 180),
949
+ "lb-in/rad": POUNDMASS_KG * GRAVITY_SI * INCH_METER,
950
+ "lb-in/deg°": POUNDMASS_KG * GRAVITY_SI * INCH_METER / (Math.PI / 180)
951
+ },
952
+ /* 114 */
953
+ "Flow Rate (Volume)": {
954
+ "m³/s": 1,
955
+ "m³/min": 1 / 60,
956
+ "m³/h": 1 / 3600,
957
+ "L/s": 1 / THOUSAND,
958
+ "L/min": 1 / THOUSAND / 60,
959
+ "L/h": 1 / THOUSAND / 3600,
960
+ "cm³/s": 1e-6,
961
+ "cm³/min": 1e-6 / 60,
962
+ "in³/s": Math.pow(INCH_METER, 3),
963
+ "in³/min": Math.pow(INCH_METER, 3) / 60,
964
+ "ft³/s": Math.pow(FOOT_METER, 3),
965
+ "CFM": Math.pow(FOOT_METER, 3) / 60,
966
+ "CFM[ft³/min]": Math.pow(FOOT_METER, 3) / 60,
967
+ "CFH": Math.pow(FOOT_METER, 3) / 3600,
968
+ "CFH[ft³/h]": Math.pow(FOOT_METER, 3) / 3600,
969
+ "yd³/min": Math.pow(FOOT_METER * 3, 3) / 60,
970
+ "yd³/h": Math.pow(FOOT_METER * 3, 3) / 3600,
971
+ "gpm(US)": GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3) / 60,
972
+ "gph(US)": GALLON_US_LIQUID_IN3 * Math.pow(INCH_METER, 3) / 3600,
973
+ "bushel(UK-imperial)/h": BUSHEL_GALLON_UK_IMPERIAL * GALLON_UK_IMPERIAL_LITRE / 1e3 / 3600,
974
+ "bushel(US)/h": BUSHEL_GALLON_US_DRY * GALLON_US_DRY_IN3 * Math.pow(INCH_METER, 3) / 3600
975
+ },
976
+ /* 115 */
977
+ "Flow Rate (Mass)": {
978
+ "kg/s": 1,
979
+ "kg/min": 1 / 60,
980
+ "kg/h": 1 / 3600,
981
+ "g/s": 1 / THOUSAND,
982
+ "g/min": 1 / THOUSAND / 60,
983
+ "g/h": 1 / THOUSAND / 3600,
984
+ "slug/s": SLUG_KG,
985
+ "slug/min": SLUG_KG / 60,
986
+ "slug/h": SLUG_KG / 3600,
987
+ "lbm/s": POUNDMASS_KG,
988
+ "lbm/min": POUNDMASS_KG / 60,
989
+ "lbm/h": POUNDMASS_KG / 3600,
990
+ "oz/s": POUNDMASS_KG / 16,
991
+ "oz/min": POUNDMASS_KG / 16 / 60,
992
+ "oz/h": POUNDMASS_KG / 16 / 3600,
993
+ "tonne/h": THOUSAND / 3600,
994
+ "short ton/h": 2e3 * POUNDMASS_KG / 3600,
995
+ "long ton/h": 2240 * POUNDMASS_KG / 3600
996
+ },
997
+ /* 117 */
998
+ "Speed / Velocity (Linear)": {
999
+ "m/s": 1,
1000
+ "mm/s": 1 / THOUSAND,
1001
+ "km/s": 1,
1002
+ "mm/min": 1 / THOUSAND / 60,
1003
+ "m/min": 1 / 60,
1004
+ "km/min": THOUSAND / 60,
1005
+ "mm/h": 1 / THOUSAND / 3600,
1006
+ "m/h": 1 / 3600,
1007
+ "km/h": THOUSAND / 3600,
1008
+ "in/s": INCH_METER,
1009
+ "fps": FOOT_METER,
1010
+ "fps[ft/second]": FOOT_METER,
1011
+ "fpm": FOOT_METER / 60,
1012
+ // clear version
1013
+ "fpm[ft/minute]": FOOT_METER / 60,
1014
+ // redundant version
1015
+ "mph[mile/h]": MILE_FOOT * FOOT_METER / 3600,
1016
+ "knot[kn, kt, or nautical mile/h]": NM_METER / 3600
1017
+ },
1018
+ /* 126 */
1019
+ "Electrical Potential Difference (Voltage)": {
1020
+ "V": 1,
1021
+ "Volt": 1,
1022
+ "joule/coulomb": 1,
1023
+ "J/C": 1,
1024
+ "µV": 1 / MILLION,
1025
+ "mV": 1 / THOUSAND,
1026
+ "kV": THOUSAND,
1027
+ "MV": MILLION
1028
+ }
1029
+ };
1030
+ const getUnitCategory = (unit) => {
1031
+ console.log("getUnitCategory called with unit:", unit);
1032
+ if (!unit) {
1033
+ console.warn("Unit is undefined or null");
1034
+ return "Custom";
1035
+ }
1036
+ for (const category in UNITS) {
1037
+ if (UNITS[category].includes(unit)) {
1038
+ console.log(`Category found for unit ${unit}:`, category);
1039
+ return category;
1040
+ }
1041
+ }
1042
+ console.warn(`No category found for unit: ${unit}`);
1043
+ return "Custom";
1044
+ };
1045
+ const convertValue = (value, fromUnit, toUnit, unitCategory) => {
1046
+ if (fromUnit === "ft-in" && toUnit !== "ft-in") {
1047
+ return convertFromFeetInches(value, toUnit);
1048
+ } else if (fromUnit !== "ft-in" && toUnit === "ft-in") {
1049
+ return convertToFeetInches(value, fromUnit);
1050
+ } else if (unitCategory !== "Temperature") {
1051
+ const c = CONVERSION_FACTORS[unitCategory][fromUnit] / CONVERSION_FACTORS[unitCategory][toUnit];
1052
+ return value * c;
1053
+ } else {
1054
+ const Cf0 = CONVERSION_FACTORS[unitCategory][fromUnit].c0;
1055
+ const Cf1 = CONVERSION_FACTORS[unitCategory][fromUnit].c1;
1056
+ const Ct0 = CONVERSION_FACTORS[unitCategory][toUnit].c0;
1057
+ const Ct1 = CONVERSION_FACTORS[unitCategory][toUnit].c1;
1058
+ return (value * Cf0 + Cf1 - Ct1) / Ct0;
1059
+ }
1060
+ };
1061
+ const formatValue = (value, decimalPlaces) => {
1062
+ let formattedValue;
1063
+ if (Number.isInteger(value)) {
1064
+ formattedValue = value.toString();
1065
+ } else {
1066
+ formattedValue = value.toFixed(decimalPlaces).replace(/\.?0+$/, "");
1067
+ }
1068
+ if (Math.abs(parseFloat(formattedValue)) >= 1e3) {
1069
+ const parts = formattedValue.split(".");
1070
+ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
1071
+ formattedValue = parts.join(".");
1072
+ }
1073
+ return formattedValue;
1074
+ };
1075
+ const parseFeetInchesValue = (valueString) => {
1076
+ const regexFeetInches = /(\d+)\'(\s*-\s*)?(\d+)?(\s+)?(\d+)?\/?(\d+)?/;
1077
+ const regexFeet = /(\d+)\'/;
1078
+ const regexInches = /(\d+)/;
1079
+ let match = valueString.match(regexFeetInches);
1080
+ if (match) {
1081
+ const feet = parseInt(match[1]) || 0;
1082
+ const inches = parseInt(match[3]) || 0;
1083
+ const numerator = parseInt(match[5]) || 0;
1084
+ const denominator = parseInt(match[6]) || 1;
1085
+ return calculateTotalInches(feet, inches, numerator, denominator);
1086
+ }
1087
+ match = valueString.match(regexFeet);
1088
+ if (match) {
1089
+ const feet = parseInt(match[1]) || 0;
1090
+ return calculateTotalInches(feet, 0, 0, 1);
1091
+ }
1092
+ match = valueString.match(regexInches);
1093
+ if (match) {
1094
+ const inches = parseInt(match[1]) || 0;
1095
+ return calculateTotalInches(0, inches, 0, 1);
1096
+ }
1097
+ return parseFloat(valueString);
1098
+ };
1099
+ const calculateTotalInches = (feet, inches, numerator, denominator) => {
1100
+ return feet * 12 + inches + numerator / denominator;
1101
+ };
1102
+ const formatFeetInchesValue = (totalInches, inchPrecision = '1/16"') => {
1103
+ if (totalInches < 0) {
1104
+ return `-${formatFeetInchesValue(-totalInches, inchPrecision)}`;
1105
+ }
1106
+ const precisionDenominator = parseInt(inchPrecision.split("/")[1].replace('"', ""));
1107
+ let feet = Math.floor(totalInches / 12);
1108
+ let inches = Math.floor(totalInches % 12);
1109
+ const fractionalInches = totalInches - Math.floor(totalInches);
1110
+ let fractionStr = "";
1111
+ if (fractionalInches > 0) {
1112
+ if (inchPrecision !== 0) {
1113
+ let numerator = Math.round(fractionalInches * precisionDenominator);
1114
+ const gcd = (a, b) => b ? gcd(b, a % b) : a;
1115
+ const commonDivisor = gcd(numerator, precisionDenominator);
1116
+ fractionStr = ` ${numerator / commonDivisor}/${precisionDenominator / commonDivisor}`;
1117
+ if (fractionStr.trim() === "1/1") {
1118
+ inches++;
1119
+ if (inches >= 12) {
1120
+ feet++;
1121
+ inches -= 12;
1122
+ }
1123
+ fractionStr = "";
1124
+ }
1125
+ }
1126
+ }
1127
+ let output = "";
1128
+ if (feet > 0) {
1129
+ output += `${feet}'`;
1130
+ }
1131
+ if (feet > 0 && (inches > 0 || fractionStr !== "")) {
1132
+ output += `-`;
1133
+ }
1134
+ if (inches > 0) {
1135
+ output += `${inches}`;
1136
+ }
1137
+ if (fractionStr !== "") {
1138
+ output += fractionStr;
1139
+ }
1140
+ if (inches > 0 || fractionStr !== "") {
1141
+ output += '"';
1142
+ }
1143
+ return output.trim();
1144
+ };
1145
+ const convertFromFeetInches = (totalInches, toUnit) => {
1146
+ const inchesInMeters = totalInches * 0.0254;
1147
+ return convertValue(inchesInMeters, "m", toUnit, "Length");
1148
+ };
1149
+ const convertToFeetInches = (value, fromUnit) => {
1150
+ const valueInMeters = convertValue(value, fromUnit, "m", "Length");
1151
+ return valueInMeters / 0.0254;
1152
+ };
1153
+ class PhysicalQuantity extends HTMLElement {
1154
+ constructor() {
1155
+ super();
1156
+ this.attachShadow({ mode: "open" });
1157
+ this.unitCategory = "";
1158
+ console.log("PhysicalQuantity constructor called");
1159
+ }
1160
+ connectedCallback() {
1161
+ console.log("connectedCallback called");
1162
+ this.unit = this.getAttribute("unit");
1163
+ console.log("Initial unit:", this.unit);
1164
+ this.updateUnitCategory();
1165
+ this.inputValue = this.getAttribute("value");
1166
+ console.log("Initial inputValue:", this.inputValue);
1167
+ this.value = this.parseValue(this.inputValue, this.unit);
1168
+ console.log("Parsed value:", this.value);
1169
+ this.decimalPlaces = parseInt(this.getAttribute("decimal-places")) || 2;
1170
+ this.showUnitArrow = !this.hasAttribute("show-unit-arrow") || this.getAttribute("show-unit-arrow") === "true";
1171
+ console.log("Initial state:", { unit: this.unit, value: this.value, unitCategory: this.unitCategory, decimalPlaces: this.decimalPlaces, showUnitArrow: this.showUnitArrow });
1172
+ this.render();
1173
+ this.attachEventListeners();
1174
+ }
1175
+ disconnectedCallback() {
1176
+ this.removeEventListeners();
1177
+ }
1178
+ static get observedAttributes() {
1179
+ return ["value", "unit", "decimal-places", "show-unit-arrow"];
1180
+ }
1181
+ attributeChangedCallback(name, oldValue, newValue) {
1182
+ console.log(`attributeChangedCallback called: ${name}`, { oldValue, newValue });
1183
+ if (name === "value") {
1184
+ this.inputValue = newValue || "0";
1185
+ this.value = this.parseValue(this.inputValue, this.unit);
1186
+ console.log("New value parsed:", this.value);
1187
+ } else if (name === "unit") {
1188
+ const oldUnit = this.unit;
1189
+ const oldCategory = this.unitCategory;
1190
+ this.unit = newValue || "mm";
1191
+ this.updateUnitCategory();
1192
+ if (oldUnit !== this.unit) {
1193
+ if (oldCategory === this.unitCategory) {
1194
+ console.log("Converting value:", { from: oldUnit, to: this.unit, value: this.value, unitCategory: this.unitCategory });
1195
+ this.value = convertValue({
1196
+ value: this.value,
1197
+ fromUnit: oldUnit,
1198
+ toUnit: this.unit,
1199
+ unitCategory: this.unitCategory
1200
+ });
1201
+ } else {
1202
+ console.log("Unit category changed, keeping original value");
1203
+ }
1204
+ console.log("New value:", this.value);
1205
+ }
1206
+ } else if (name === "decimal-places") {
1207
+ this.decimalPlaces = parseInt(newValue) || 2;
1208
+ console.log("New decimal places:", this.decimalPlaces);
1209
+ } else if (name === "show-unit-arrow") {
1210
+ this.showUnitArrow = newValue === null || newValue === "true";
1211
+ console.log("Show unit arrow:", this.showUnitArrow);
1212
+ }
1213
+ this.render();
1214
+ }
1215
+ updateUnitCategory() {
1216
+ console.log("updateUnitCategory called with unit:", this.unit);
1217
+ this.unitCategory = getUnitCategory(this.unit);
1218
+ console.log("Updated unit category:", this.unitCategory);
1219
+ }
1220
+ parseValue(value, unit) {
1221
+ console.log("parseValue called with:", { value, unit });
1222
+ if (typeof value === "string" && value.trim() === "") {
1223
+ console.log("Empty string value, returning 0");
1224
+ return 0;
1225
+ }
1226
+ const parsedValue = unit === "ft-in" ? parseFeetInchesValue(value) : parseFloat(value) || 0;
1227
+ console.log("Parsed value:", parsedValue);
1228
+ return parsedValue;
1229
+ }
1230
+ formatDisplayValue() {
1231
+ if (this.unit === "ft-in") {
1232
+ return formatFeetInchesValue(this.value);
1233
+ } else {
1234
+ return formatValue(this.value, this.decimalPlaces);
1235
+ }
1236
+ }
1237
+ handleUnitChange(event) {
1238
+ if (event.target.tagName === "SELECT") {
1239
+ const newUnit = event.target.value;
1240
+ console.log("handleUnitChange:", { from: this.unit, to: newUnit, value: this.value, unitCategory: this.unitCategory });
1241
+ this.value = convertValue(this.value, this.unit, newUnit, this.unitCategory);
1242
+ console.log("Converted value:", this.value);
1243
+ this.unit = newUnit;
1244
+ this.updateUnitCategory();
1245
+ this.render();
1246
+ }
1247
+ this.updateDropdownWidth();
1248
+ }
1249
+ render() {
1250
+ const formattedValue = this.formatDisplayValue();
1251
+ this.shadowRoot.innerHTML = `
2
1252
  <style>
3
1253
  :host {
4
1254
  display: inline-flex;
@@ -21,9 +1271,9 @@
21
1271
  align-items: baseline;
22
1272
  }
23
1273
  .unit-container select {
24
- appearance: ${this.showUnitArrow?"auto":"none"};
25
- -webkit-appearance: ${this.showUnitArrow?"auto":"none"};
26
- -moz-appearance: ${this.showUnitArrow?"auto":"none"};
1274
+ appearance: ${this.showUnitArrow ? "auto" : "none"};
1275
+ -webkit-appearance: ${this.showUnitArrow ? "auto" : "none"};
1276
+ -moz-appearance: ${this.showUnitArrow ? "auto" : "none"};
27
1277
  border-radius: 0.15em;
28
1278
  border: none;
29
1279
  margin: 0;
@@ -41,61 +1291,98 @@
41
1291
  min-width: 2.5em;
42
1292
  }
43
1293
  .unit-container select::-ms-expand {
44
- display: ${this.showUnitArrow?"block":"none"};
45
- }
46
- /* Custom arrow styles */
47
- /*
48
- .unit-container::after {
49
- content: '▼';
50
- font-size: 0.7em;
51
- color: red;
52
- position: absolute;
53
- right: 0.3em;
54
- top: 50%;
55
- transform: translateY(-50%);
56
- pointer-events: none;
57
- }
58
- */
59
- .tooltip {
60
- position: absolute;
61
- bottom: 100%;
62
- left: 50%;
63
- transform: translateX(-50%);
64
- padding: 0;
65
- display: none;
66
- font-size: 12px;
67
- pointer-events: none;
68
- }
69
- .unit-container:hover .tooltip {
70
- display: block;
71
- }
72
- .tooltip a {
73
- text-decoration: none;
74
- color: blue;
75
- }
76
- .tooltip a:hover {
77
- text-decoration: underline;
1294
+ display: ${this.showUnitArrow ? "block" : "none"};
78
1295
  }
79
1296
  </style>
80
1297
 
81
1298
  <div class="quantity">
82
- <span class="value">${t}</span>
1299
+ <span class="value">${formattedValue}</span>
83
1300
  <div class="unit-container">
84
1301
  <select>
85
- ${(k[this.unitCategory]||[this.unit]).map(e=>`<option value="${e}" ${e===this.unit?"selected":""}>
86
- ${e}</option>`).join("")}
1302
+ ${(UNITS[this.unitCategory] || [this.unit]).map((unit) => `<option value="${unit}" ${unit === this.unit ? "selected" : ""}>
1303
+ ${unit}</option>`).join("")}
87
1304
  </select>
88
-
89
- ${this.showUnitArrow&&this.unitCategory!=="Custom"?`
90
- <a class="tooltip" href="https://v2-docs.donwen.com/daily-calculations/unit-converter.html"
91
- title="Unit Converter for All Categories" target="_blank">
92
- <img src="${this.e3dLogoUrl}" width="12" />
93
- </a>
94
- `:""}
95
-
96
1305
  </div>
97
1306
  </div>
98
- `,this.updateDropdownWidth()}updateDropdownWidth(){const t=this.shadowRoot.querySelector("select");if(!t)return;const e=document.createElement("span");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;const i=e.offsetWidth;document.body.removeChild(e);const s=this.showUnitArrow?16:6,m=this.showUnitArrow?8:0;let h=i+s+m+2;h=Math.max(h,30),t.style.width=`${h}px`}attachEventListeners(){this.shadowRoot.addEventListener("change",this.handleUnitChange.bind(this));const t=this.shadowRoot.querySelector(".unit-container");t&&(t.addEventListener("mouseover",this.handleUnitContainerMouseOver.bind(this)),t.addEventListener("mouseout",this.handleUnitContainerMouseOut.bind(this)))}removeEventListeners(){this.shadowRoot.removeEventListener("change",this.handleUnitChange.bind(this));const t=this.shadowRoot.querySelector(".unit-container");t&&(t.removeEventListener("mouseover",this.handleUnitContainerMouseOver.bind(this)),t.removeEventListener("mouseout",this.handleUnitContainerMouseOut.bind(this)))}handleUnitContainerMouseOver(){const t=this.shadowRoot.querySelector(".tooltip");t&&(this.tooltipTimeout=setTimeout(()=>{t.style.display="block"},1e3))}handleUnitContainerMouseOut(){const t=this.shadowRoot.querySelector(".tooltip");t&&(setTimeout(()=>{t.style.display="none"},2e3),clearTimeout(this.tooltipTimeout))}}class J extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.values=[],this.unit="",this.unitCategory="",this.decimalPlaces=2,this.showUnitArrow=!0}connectedCallback(){this.unit=this.getAttribute("unit")||"cm",this.values=this.getAttribute("values").split(",").map(Number).map(t=>this.parseValue(t,this.unit)),this.unitCategory=T(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()}static get observedAttributes(){return["values","unit","decimal-places","show-unit-arrow"]}attributeChangedCallback(t,e,i){if(t==="values")this.values=i.split(",").map(Number).map(s=>this.parseValue(s,this.unit));else if(t==="unit"){const s=this.unit;this.unit=i,this.unitCategory=T(i),s!==i&&(this.values=this.values.map(m=>d(m,s,i,this.unitCategory)))}else t==="decimal-places"?this.decimalPlaces=parseInt(i)||2:t==="show-unit-arrow"&&(this.showUnitArrow=i===null||i==="true");this.render()}render(){const t=this.values.map(e=>this.formatPairValue(e));this.shadowRoot.innerHTML=`
1307
+ `;
1308
+ this.updateDropdownWidth();
1309
+ }
1310
+ updateDropdownWidth() {
1311
+ const selectElement = this.shadowRoot.querySelector("select");
1312
+ if (!selectElement)
1313
+ return;
1314
+ const tempSpan = document.createElement("span");
1315
+ tempSpan.style.visibility = "hidden";
1316
+ tempSpan.style.position = "absolute";
1317
+ tempSpan.style.whiteSpace = "nowrap";
1318
+ tempSpan.style.font = window.getComputedStyle(selectElement).font;
1319
+ document.body.appendChild(tempSpan);
1320
+ tempSpan.textContent = this.unit;
1321
+ const textWidth = tempSpan.offsetWidth;
1322
+ document.body.removeChild(tempSpan);
1323
+ const selectPadding = this.showUnitArrow ? 16 : 6;
1324
+ const arrowWidth = this.showUnitArrow ? 8 : 0;
1325
+ const extraPadding = 2;
1326
+ let finalWidth = textWidth + selectPadding + arrowWidth + extraPadding;
1327
+ finalWidth = Math.max(finalWidth, 30);
1328
+ selectElement.style.width = `${finalWidth}px`;
1329
+ }
1330
+ attachEventListeners() {
1331
+ this.shadowRoot.addEventListener("change", this.handleUnitChange.bind(this));
1332
+ }
1333
+ removeEventListeners() {
1334
+ this.shadowRoot.removeEventListener("change", this.handleUnitChange.bind(this));
1335
+ }
1336
+ }
1337
+ class UcQtyPair extends HTMLElement {
1338
+ constructor() {
1339
+ super();
1340
+ this.attachShadow({ mode: "open" });
1341
+ this.values = [];
1342
+ this.unit = "";
1343
+ this.unitCategory = "";
1344
+ this.decimalPlaces = 2;
1345
+ this.showUnitArrow = true;
1346
+ this.format = "";
1347
+ }
1348
+ connectedCallback() {
1349
+ this.unit = this.getAttribute("unit") || "cm";
1350
+ this.parsePairValues(this.getAttribute("values"));
1351
+ this.unitCategory = getUnitCategory(this.unit);
1352
+ this.decimalPlaces = parseInt(this.getAttribute("decimal-places")) || 2;
1353
+ this.showUnitArrow = !this.hasAttribute("show-unit-arrow") || this.getAttribute("show-unit-arrow") === "true";
1354
+ this.render();
1355
+ this.attachEventListeners();
1356
+ }
1357
+ static get observedAttributes() {
1358
+ return ["values", "unit", "decimal-places", "show-unit-arrow"];
1359
+ }
1360
+ attributeChangedCallback(name, oldValue, newValue) {
1361
+ if (name === "values") {
1362
+ this.parsePairValues(newValue);
1363
+ } else if (name === "unit") {
1364
+ const oldUnit = this.unit;
1365
+ this.unit = newValue;
1366
+ this.unitCategory = getUnitCategory(newValue);
1367
+ if (oldUnit !== newValue) {
1368
+ this.values = this.values.map((value) => convertValue(value, oldUnit, newValue, this.unitCategory));
1369
+ }
1370
+ } else if (name === "decimal-places") {
1371
+ this.decimalPlaces = parseInt(newValue) || 2;
1372
+ } else if (name === "show-unit-arrow") {
1373
+ this.showUnitArrow = newValue === null || newValue === "true";
1374
+ }
1375
+ this.render();
1376
+ }
1377
+ render() {
1378
+ const formattedValues = this.values.map((value) => this.formatPairValue(value));
1379
+ let valuesHtml;
1380
+ if (this.format === "x") {
1381
+ valuesHtml = `${formattedValues[0]} <span class="unit-text">${this.unit}</span> x ${formattedValues[1]}`;
1382
+ } else {
1383
+ valuesHtml = `(${formattedValues.join(", ")})`;
1384
+ }
1385
+ this.shadowRoot.innerHTML = `
99
1386
  <style>
100
1387
  :host {
101
1388
  display: inline-flex;
@@ -112,15 +1399,24 @@
112
1399
  margin-left: 2px;
113
1400
  position: relative;
114
1401
  }
1402
+ .unit-text {
1403
+ color: blue;
1404
+ background-color: lightgray;
1405
+ font-family: inherit;
1406
+ font-size: 0.9em;
1407
+ line-height: normal;
1408
+ border-radius: 0.15em;
1409
+ padding: 0 0.2em;
1410
+ }
115
1411
  .unit-container {
116
1412
  position: relative;
117
1413
  display: inline-flex;
118
1414
  align-items: baseline;
119
1415
  }
120
1416
  .unit-container select {
121
- appearance: ${this.showUnitArrow?"auto":"none"};
122
- -webkit-appearance: ${this.showUnitArrow?"auto":"none"};
123
- -moz-appearance: ${this.showUnitArrow?"auto":"none"};
1417
+ appearance: ${this.showUnitArrow ? "auto" : "none"};
1418
+ -webkit-appearance: ${this.showUnitArrow ? "auto" : "none"};
1419
+ -moz-appearance: ${this.showUnitArrow ? "auto" : "none"};
124
1420
  border-radius: 0.15em;
125
1421
  border: none;
126
1422
  margin: 0;
@@ -137,17 +1433,154 @@
137
1433
  min-width: 2.5em;
138
1434
  }
139
1435
  </style>
140
-
1436
+
141
1437
  <div class="quantity-pair">
142
- <span class="values">(${t.join(", ")})</span>
1438
+ <span class="values">${valuesHtml}</span>
143
1439
  <div class="unit-container">
144
1440
  <select>
145
- ${(k[this.unitCategory]||[this.unit]).map(e=>`<option value="${e}" ${e===this.unit?"selected":""}>
146
- ${e}</option>`).join("")}
1441
+ ${(UNITS[this.unitCategory] || [this.unit]).map((unit) => `<option value="${unit}" ${unit === this.unit ? "selected" : ""}>${unit}</option>`).join("")}
147
1442
  </select>
148
- </div>
149
- </div>
150
- `,this.updateDropdownWidth()}updateDropdownWidth(){const t=this.shadowRoot.querySelector("select");if(!t)return;const e=document.createElement("span");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;const i=e.offsetWidth;document.body.removeChild(e);const s=this.showUnitArrow?16:6,m=this.showUnitArrow?8:0;let h=i+s+m+2;h=Math.max(h,30),t.style.width=`${h}px`}attachEventListeners(){this.shadowRoot.addEventListener("change",this.handleUnitChange.bind(this))}parseValue(t,e){return e==="ft-in"?P(t):parseFloat(t)}formatPairValue(t){return this.unit==="ft-in"?S(t):O(t,this.decimalPlaces)}handleUnitChange(t){if(t.target.tagName==="SELECT"){const e=t.target.value;this.values=this.values.map(i=>d(i,this.unit,e,this.unitCategory)),this.unit=e,this.render()}this.updateDropdownWidth()}}class V extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.values=[],this.unit="",this.unitCategory="",this.decimalPlaces=2,this.showUnitArrow=!0,this.format="",this.hasParentheses=!1}connectedCallback(){this.unit=this.getAttribute("unit")||"cm",this.parseTripletValues(this.getAttribute("values")),this.unitCategory=T(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()}static get observedAttributes(){return["values","unit","decimal-places","show-unit-arrow"]}attributeChangedCallback(t,e,i){if(t==="values")this.parseTripletValues(i);else if(t==="unit"){const s=this.unit;this.unit=i,this.unitCategory=T(i),s!==i&&(this.values=this.values.map(m=>d(m,s,i,this.unitCategory)))}else t==="decimal-places"?this.decimalPlaces=parseInt(i)||2:t==="show-unit-arrow"&&(this.showUnitArrow=i===null||i==="true");this.render()}parseValue(t,e){return e==="ft-in"?P(t):parseFloat(t)}parseTripletValues(t){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")}formatTripletValue(t){return this.unit==="ft-in"?S(t):O(t,this.decimalPlaces)}formatTriplet(t){let e="";const i=t.map(s=>this.formatTripletValue(s));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}render(){const t=this.formatTriplet(this.values);this.shadowRoot.innerHTML=`
1443
+ </div>
1444
+ </div>
1445
+ `;
1446
+ this.updateDropdownWidth();
1447
+ }
1448
+ updateDropdownWidth() {
1449
+ const selectElement = this.shadowRoot.querySelector("select");
1450
+ if (!selectElement)
1451
+ return;
1452
+ const tempSpan = document.createElement("span");
1453
+ tempSpan.style.visibility = "hidden";
1454
+ tempSpan.style.position = "absolute";
1455
+ tempSpan.style.whiteSpace = "nowrap";
1456
+ tempSpan.style.font = window.getComputedStyle(selectElement).font;
1457
+ document.body.appendChild(tempSpan);
1458
+ tempSpan.textContent = this.unit;
1459
+ const textWidth = tempSpan.offsetWidth;
1460
+ document.body.removeChild(tempSpan);
1461
+ const selectPadding = this.showUnitArrow ? 16 : 6;
1462
+ const arrowWidth = this.showUnitArrow ? 8 : 0;
1463
+ const extraPadding = 2;
1464
+ let finalWidth = textWidth + selectPadding + arrowWidth + extraPadding;
1465
+ finalWidth = Math.max(finalWidth, 30);
1466
+ selectElement.style.width = `${finalWidth}px`;
1467
+ }
1468
+ attachEventListeners() {
1469
+ this.shadowRoot.addEventListener("change", this.handleUnitChange.bind(this));
1470
+ }
1471
+ parsePairValues(valuesString) {
1472
+ this.format = "";
1473
+ if (!valuesString)
1474
+ return;
1475
+ if (valuesString.startsWith("(") && valuesString.endsWith(")")) {
1476
+ valuesString = valuesString.slice(1, -1);
1477
+ }
1478
+ if (valuesString.includes("x")) {
1479
+ this.values = valuesString.split("x").map((v) => this.parseValue(v, this.unit));
1480
+ this.format = "x";
1481
+ } else if (valuesString.includes(",")) {
1482
+ this.values = valuesString.split(",").map((s) => s.trim()).map((v) => this.parseValue(v, this.unit));
1483
+ this.format = "tuple";
1484
+ }
1485
+ }
1486
+ parseValue(value, unit) {
1487
+ return unit === "ft-in" ? parseFeetInchesValue(value) : parseFloat(value);
1488
+ }
1489
+ formatPairValue(value) {
1490
+ if (this.unit === "ft-in") {
1491
+ return formatFeetInchesValue(value);
1492
+ } else {
1493
+ return formatValue(value, this.decimalPlaces);
1494
+ }
1495
+ }
1496
+ handleUnitChange(event) {
1497
+ if (event.target.tagName === "SELECT") {
1498
+ const newUnit = event.target.value;
1499
+ this.values = this.values.map((value) => convertValue(value, this.unit, newUnit, this.unitCategory));
1500
+ this.unit = newUnit;
1501
+ this.render();
1502
+ }
1503
+ this.updateDropdownWidth();
1504
+ }
1505
+ }
1506
+ class UcQtyTriplet extends HTMLElement {
1507
+ constructor() {
1508
+ super();
1509
+ this.attachShadow({ mode: "open" });
1510
+ this.values = [];
1511
+ this.unit = "";
1512
+ this.unitCategory = "";
1513
+ this.decimalPlaces = 2;
1514
+ this.showUnitArrow = true;
1515
+ this.format = "";
1516
+ }
1517
+ connectedCallback() {
1518
+ this.unit = this.getAttribute("unit") || "cm";
1519
+ this.parseTripletValues(this.getAttribute("values"));
1520
+ this.unitCategory = getUnitCategory(this.unit);
1521
+ this.decimalPlaces = parseInt(this.getAttribute("decimal-places")) || 2;
1522
+ this.showUnitArrow = !this.hasAttribute("show-unit-arrow") || this.getAttribute("show-unit-arrow") === "true";
1523
+ this.render();
1524
+ this.attachEventListeners();
1525
+ }
1526
+ static get observedAttributes() {
1527
+ return ["values", "unit", "decimal-places", "show-unit-arrow"];
1528
+ }
1529
+ attributeChangedCallback(name, oldValue, newValue) {
1530
+ if (name === "values") {
1531
+ this.parseTripletValues(newValue);
1532
+ } else if (name === "unit") {
1533
+ const oldUnit = this.unit;
1534
+ this.unit = newValue;
1535
+ this.unitCategory = getUnitCategory(newValue);
1536
+ if (oldUnit !== newValue) {
1537
+ this.values = this.values.map((value) => convertValue(value, oldUnit, newValue, this.unitCategory));
1538
+ }
1539
+ } else if (name === "decimal-places") {
1540
+ this.decimalPlaces = parseInt(newValue) || 2;
1541
+ } else if (name === "show-unit-arrow") {
1542
+ this.showUnitArrow = newValue === null || newValue === "true";
1543
+ }
1544
+ this.render();
1545
+ }
1546
+ parseValue(value, unit) {
1547
+ return unit === "ft-in" ? parseFeetInchesValue(value) : parseFloat(value);
1548
+ }
1549
+ parseTripletValues(valuesString) {
1550
+ this.format = "";
1551
+ if (!valuesString)
1552
+ return;
1553
+ if (valuesString.startsWith("(") && valuesString.endsWith(")")) {
1554
+ valuesString = valuesString.slice(1, -1);
1555
+ }
1556
+ if (valuesString.includes("x")) {
1557
+ this.values = valuesString.split("x").map((v) => this.parseValue(v, this.unit));
1558
+ this.format = "x";
1559
+ } else if (valuesString.includes(",")) {
1560
+ this.values = valuesString.split(",").map((s) => s.trim()).map((v) => this.parseValue(v, this.unit));
1561
+ this.format = "tuple";
1562
+ }
1563
+ }
1564
+ formatTripletValue(value) {
1565
+ if (this.unit === "ft-in") {
1566
+ return formatFeetInchesValue(value);
1567
+ } else {
1568
+ return formatValue(value, this.decimalPlaces);
1569
+ }
1570
+ }
1571
+ formatTriplet(values) {
1572
+ let result = "";
1573
+ const formattedValues = values.map((value) => this.formatTripletValue(value));
1574
+ if (this.format === "x") {
1575
+ result = `${formattedValues[0]} <span class="unit-text">${this.unit}</span> x ${formattedValues[1]} <span class="unit-text">${this.unit}</span> x ${formattedValues[2]}`;
1576
+ } else if (this.format === "tuple") {
1577
+ result = "(" + formattedValues.join(", ") + ")";
1578
+ }
1579
+ return result;
1580
+ }
1581
+ render() {
1582
+ const formattedTriplet = this.formatTriplet(this.values);
1583
+ this.shadowRoot.innerHTML = `
151
1584
  <style>
152
1585
  :host {
153
1586
  display: inline-flex;
@@ -180,9 +1613,9 @@
180
1613
  align-items: baseline;
181
1614
  }
182
1615
  .unit-container select {
183
- appearance: ${this.showUnitArrow?"auto":"none"};
184
- -webkit-appearance: ${this.showUnitArrow?"auto":"none"};
185
- -moz-appearance: ${this.showUnitArrow?"auto":"none"};
1616
+ appearance: ${this.showUnitArrow ? "auto" : "none"};
1617
+ -webkit-appearance: ${this.showUnitArrow ? "auto" : "none"};
1618
+ -moz-appearance: ${this.showUnitArrow ? "auto" : "none"};
186
1619
  border: none;
187
1620
  margin: 0;
188
1621
  cursor: pointer;
@@ -193,18 +1626,62 @@
193
1626
  </style>
194
1627
 
195
1628
  <span class="quantity-triplet">
196
- ${this.hasParentheses?"(":""}
197
- <span class="values">${t}</span>
198
- ${this.hasParentheses&&this.format!=="x"?")":""}
1629
+ <span class="values">${formattedTriplet}</span>
199
1630
  <div class="unit-container">
200
1631
  <select>
201
- ${(k[this.unitCategory]||[this.unit]).map(e=>`<option value="${e}" ${e===this.unit?"selected":""}>
202
- ${e}</option>`).join("")}
1632
+ ${(UNITS[this.unitCategory] || [this.unit]).map((unit) => `<option value="${unit}" ${unit === this.unit ? "selected" : ""}>
1633
+ ${unit}</option>`).join("")}
203
1634
  </select>
204
1635
  </div>
205
- ${this.hasParentheses&&this.format==="x"?")":""}
206
1636
  </span>
207
- `,this.updateDropdownWidth()}updateDropdownWidth(){const t=this.shadowRoot.querySelector("select");if(!t)return;const e=document.createElement("span");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;const i=e.offsetWidth;document.body.removeChild(e);const s=this.showUnitArrow?16:6,m=this.showUnitArrow?8:0;let h=i+s+m+2;h=Math.max(h,30),t.style.width=`${h}px`}attachEventListeners(){this.shadowRoot.addEventListener("change",this.handleUnitChange.bind(this))}handleUnitChange(t){if(t.target.tagName==="SELECT"){const e=t.target.value;this.values=this.values.map(i=>d(i,this.unit,e,this.unitCategory)),this.unit=e,this.render()}this.updateDropdownWidth()}}class G extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.count=0}connectedCallback(){this.render(),this.attachEventListeners()}render(){this.shadowRoot.innerHTML=`
1637
+ `;
1638
+ this.updateDropdownWidth();
1639
+ }
1640
+ updateDropdownWidth() {
1641
+ const selectElement = this.shadowRoot.querySelector("select");
1642
+ if (!selectElement)
1643
+ return;
1644
+ const tempSpan = document.createElement("span");
1645
+ tempSpan.style.visibility = "hidden";
1646
+ tempSpan.style.position = "absolute";
1647
+ tempSpan.style.whiteSpace = "nowrap";
1648
+ tempSpan.style.font = window.getComputedStyle(selectElement).font;
1649
+ document.body.appendChild(tempSpan);
1650
+ tempSpan.textContent = this.unit;
1651
+ const textWidth = tempSpan.offsetWidth;
1652
+ document.body.removeChild(tempSpan);
1653
+ const selectPadding = this.showUnitArrow ? 16 : 6;
1654
+ const arrowWidth = this.showUnitArrow ? 8 : 0;
1655
+ const extraPadding = 2;
1656
+ let finalWidth = textWidth + selectPadding + arrowWidth + extraPadding;
1657
+ finalWidth = Math.max(finalWidth, 30);
1658
+ selectElement.style.width = `${finalWidth}px`;
1659
+ }
1660
+ attachEventListeners() {
1661
+ this.shadowRoot.addEventListener("change", this.handleUnitChange.bind(this));
1662
+ }
1663
+ handleUnitChange(event) {
1664
+ if (event.target.tagName === "SELECT") {
1665
+ const newUnit = event.target.value;
1666
+ this.values = this.values.map((value) => convertValue(value, this.unit, newUnit, this.unitCategory));
1667
+ this.unit = newUnit;
1668
+ this.render();
1669
+ }
1670
+ this.updateDropdownWidth();
1671
+ }
1672
+ }
1673
+ class NewComponent1 extends HTMLElement {
1674
+ constructor() {
1675
+ super();
1676
+ this.attachShadow({ mode: "open" });
1677
+ this.count = 0;
1678
+ }
1679
+ connectedCallback() {
1680
+ this.render();
1681
+ this.attachEventListeners();
1682
+ }
1683
+ render() {
1684
+ this.shadowRoot.innerHTML = `
208
1685
  <style>
209
1686
  :host {
210
1687
  display: inline-block;
@@ -235,4 +1712,41 @@
235
1712
  <span class="count">${this.count}</span>
236
1713
  <button class="increment">+</button>
237
1714
  </div>
238
- `}attachEventListeners(){const t=this.shadowRoot.querySelector(".increment"),e=this.shadowRoot.querySelector(".decrement");t.addEventListener("click",()=>this.increment()),e.addEventListener("click",()=>this.decrement())}increment(){this.count++,this.updateCount()}decrement(){this.count--,this.updateCount()}updateCount(){const t=this.shadowRoot.querySelector(".count");t.textContent=this.count}}const A=(l,t)=>{typeof window<"u"&&!customElements.get(l)&&customElements.define(l,t)};A("physical-quantity",E),A("uc-qty",class extends E{}),A("uc-qty-pair",J),A("uc-qty-triplet",V),A("new-component-1",G),u.NewComponent1=G,u.PhysicalQuantity=E,u.UcQtyPair=J,u.UcQtyTriplet=V,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
1715
+ `;
1716
+ }
1717
+ attachEventListeners() {
1718
+ const incrementBtn = this.shadowRoot.querySelector(".increment");
1719
+ const decrementBtn = this.shadowRoot.querySelector(".decrement");
1720
+ incrementBtn.addEventListener("click", () => this.increment());
1721
+ decrementBtn.addEventListener("click", () => this.decrement());
1722
+ }
1723
+ increment() {
1724
+ this.count++;
1725
+ this.updateCount();
1726
+ }
1727
+ decrement() {
1728
+ this.count--;
1729
+ this.updateCount();
1730
+ }
1731
+ updateCount() {
1732
+ const countElement = this.shadowRoot.querySelector(".count");
1733
+ countElement.textContent = this.count;
1734
+ }
1735
+ }
1736
+ const defineCustomElement = (name, component) => {
1737
+ if (typeof window !== "undefined" && !customElements.get(name)) {
1738
+ customElements.define(name, component);
1739
+ }
1740
+ };
1741
+ defineCustomElement("physical-quantity", PhysicalQuantity);
1742
+ defineCustomElement("uc-qty", class extends PhysicalQuantity {
1743
+ });
1744
+ defineCustomElement("uc-qty-pair", UcQtyPair);
1745
+ defineCustomElement("uc-qty-triplet", UcQtyTriplet);
1746
+ defineCustomElement("new-component-1", NewComponent1);
1747
+ exports2.NewComponent1 = NewComponent1;
1748
+ exports2.PhysicalQuantity = PhysicalQuantity;
1749
+ exports2.UcQtyPair = UcQtyPair;
1750
+ exports2.UcQtyTriplet = UcQtyTriplet;
1751
+ Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
1752
+ });