-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
89 lines (89 loc) · 21.5 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
(()=>{var O=class{constructor(e){this.element=e,this.sensorType=e.getAttribute("data-sensorType"),this.readingPane=e.querySelector(".reading"),this.errorPane=e.querySelector(".error"),e.querySelector("select#frequency")&&(this.frequency=+e.querySelector("select#frequency").value),this.switch=e.querySelector(".switch-inp"),this.Apple="requestPermission"in DeviceMotionEvent,this.constructSensor(),this.sensor&&this.listen()}constructSensor(){try{switch(this.sensorType){case"Accelerometer":this.sensor=new Accelerometer({frequency:this.frequency,referenceFrame:"screen"}),this.unit="m/s\xB2",this.freq_dep=!0;break;case"LinearAccelerationSensor":this.sensor=new LinearAccelerationSensor({frequency:this.frequency,referenceFrame:"screen"}),this.unit="m/s\xB2",this.freq_dep=!0;break;case"Gravity":this.sensor=new GravitySensor({frequency:this.frequency,referenceFrame:"screen"}),this.unit="m/s\xB2",this.freq_dep=!0;break;case"AmbientLightSensor":this.sensor=new AmbientLightSensor,this.unit="lux",this.freq_dep=!1;break;case"Gyroscope":this.sensor=new Gyroscope({frequency:this.frequency,referenceFrame:"screen"}),this.unit="rad/s",this.freq_dep=!0;break;case"Magnetometer":this.sensor=new Magnetometer({frequency:this.frequency,referenceFrame:"screen"}),this.unit="\u03BCT",this.freq_dep=!0;break;case"Geolocation":this.sensor=new GeolocationSensor,this.freq_dep=!1;break;case"ProximitySensor":this.sensor=new ProximitySensor,this.freq_dep=!1;break;case"AbsoluteOrientationSensor":this.sensor=new AbsoluteOrientationSensor({frequency:this.frequency}),this.freq_dep=!0;break;case"RelativeOrientationSensor":this.sensor=new RelativeOrientationSensor({frequency:this.frequency}),this.freq_dep=!0;break}}catch(e){this.handleError(e)}this.sensor&&(this.freq_dep||(this.sensor.onreading=()=>this.setReading()),this.sensor.onerror=e=>this.handleError(e.error),this.sensor.onactivate=()=>this.sensorActivated=!0,console.log(`${this.sensorType} Activated`)),this.sensorType=="Geolocation"&&navigator.geolocation.getCurrentPosition(e=>{},e=>this.handleError(e))}start(){this.freq_dep&&(this.intervalID=setInterval(()=>this.setReading(),1e3/this.frequency)),this.sensor.start(),this.sensorStarted=!0,this.readingPane.style.display="grid",this.frequency&&(this.freq_toggle.style.display="flex"),console.log(`Starting ${this.sensorType} ================================`)}stop(){this.freq_dep&&clearTimeout(this.intervalID),this.sensor.stop(),this.errorPane.style.display="none",this.readingPane.style.display="none",this.frequency&&(this.freq_toggle.style.display="none"),console.log(`Stoping ${this.sensorType} ================================`)}listen(){this.frequency&&(this.freq_toggle=this.element.querySelector(".freq-sel"),this.freq_toggle.addEventListener("change",()=>{this.stop(),this.frequency=+this.element.querySelector("select#frequency").value,this.constructSensor(),this.start()})),this.switch.addEventListener("change",()=>{if(this.switch.checked){if(this.Apple){DeviceMotionEvent.requestPermission().then(e=>{e=="granted"&&this.start()}).catch(e=>this.handleError(e));return}this.start()}else this.stop()})}setReading(){if(console.log(this.sensor.timestamp),["AbsoluteOrientationSensor","RelativeOrientationSensor"].includes(this.sensorType)){this.readingPane.innerHTML=`
<label>quaternion.x</label>
<output>: ${this.polarityPadding(this.sensor.quaternion[0].toFixed(8))}
</output>
<label>quaternion.y</label>
<output>: ${this.polarityPadding(this.sensor.quaternion[1].toFixed(8))}
</output >
<label>quaternion.z</label>
<output>: ${this.polarityPadding(this.sensor.quaternion[2].toFixed(8))}
</output >
<label>quaternion.w</label>
<output>: ${this.polarityPadding(this.sensor.quaternion[3].toFixed(8))}
</output>`;return}if(this.sensorType==="AmbientLightSensor"){this.readingPane.innerHTML=`<label>Illuminance</label><output>: ${this.sensor.illuminance} ${this.unit}</output>`;return}if(this.sensorType==="Geolocation"){let e=`<label>Latitude</label>
<output>: ${this.sensor.latitude.toFixed(8)}</output>`,i=`<label>Longitude</label>
<output>: ${this.sensor.longitude.toFixed(8)}</output>`,r="",n="",l="";this.sensor.altitude&&(r=`<label>Altitude</label>
<output>: ${this.sensor.altitude.toFixed(8)}</output>`),this.sensor.heading&&(n=`<label>Heading</label>
<output>: ${this.sensor.heading.toFixed(8)}</output>`),this.sensor.speed&&(l=`<label>Speed</label>
<output>: ${this.sensor.speed.toFixed(8)}</output>`),this.readingPane.innerHTML=e+i+r+n+l;return}if(this.sensorType==="ProximitySensor"){this.readingPane.innerHTML=`
<label>Objects Nearby</label>
<output>: ${this.sensor.near}</output>
<label>Distance</label>
<output>: ${this.sensor.distance}</output>
<label>Max</label>
<output>: ${this.sensor.max}</output>`;return}this.readingPane.innerHTML=`
<label>x</label>
<output>:
${this.polarityPadding(this.sensor.x.toFixed(5))} ${this.unit} </output>
<label>y</label>
<output>:
${this.polarityPadding(this.sensor.y.toFixed(5))} ${this.unit} </output >
<label>z</label>
<output>:
${this.polarityPadding(this.sensor.z.toFixed(5))} ${this.unit} </output >`}handleError(e){if(console.log(e.name),this.errorPane.style.display="block",this.readingPane.style.display="none",(this.sensorActivated||this.sensorStarted)&&(this.freq_dep&&clearTimeout(this.intervalID),this.sensor.stop()),e.name==="NotAllowedError"){this.errorPane.innerHTML="Permission to access sensor was denied";return}if(e.name==="NotReadableError"){this.errorPane.innerHTML="Cannot connect to the sensor";return}if(e.name==="SecurityError"){this.errorPane.innerHTML="Sensor construction was blocked by a feature policy";return}if(e.name==="ReferenceError"){this.errorPane.innerHTML="Sensor is not supported by the browser",this.switch.closest(".switch").style.display="none";return}this.errorPane.innerHTML=e.message}polarityPadding(e){let i=parseFloat(e);return i<0?i:`+${i}`}};function k(t,e){for(let i in e)Object.defineProperty(t,i,{configurable:!0,value:e[i]})}var T=new WeakMap,te=(t,...e)=>class extends t{constructor(...i){super(i);let r=document.createDocumentFragment();T.set(this,r)}addEventListener(i,...r){return T.get(this).addEventListener(i,...r)}removeEventListener(...i){return T.get(this).removeEventListener(...i)}dispatchEvent(i){k(i,{currentTarget:this}),i.target||k(i,{target:this});let n=T.get(this).dispatchEvent(i);return n&&this.parentNode&&this.parentNode.dispatchEvent(i),k(i,{currentTarget:null,target:null}),n}},D=class extends te(Object){},re=Symbol("__abort__");function _(t,e){Object.defineProperty(t,`on${e}`,{enumerable:!0,configurable:!1,writable:!0,value:null})}function M(t,e,i){let r=t[e];for(let n in i)r[n]=i[n],Object.defineProperty(t,n,{get:()=>r[n]})}var I=class extends Event{constructor(e,i){super(e,i);if(!i||!(i.error instanceof DOMException))throw TypeError("Failed to construct 'SensorErrorEvent':2nd argument much contain 'error' property");Object.defineProperty(this,"error",{configurable:!1,writable:!1,value:i.error})}},w={IDLE:1,ACTIVATING:2,ACTIVE:3},E=Symbol("__sensor__"),f=E,g=Symbol("Sensor.notifyError"),m=Symbol("Sensor.notifyActivatedState"),x=Symbol("Sensor.activateCallback"),u=Symbol("Sensor.deactivateCallback"),b=class extends D{[x](){}[u](){}[g](e,i){let r=new I("error",{error:new DOMException(e,i)});this.dispatchEvent(r),this.stop()}[m](){let e=new Event("activate");this[f].activated=!0,this.dispatchEvent(e),this[f].state=w.ACTIVE}constructor(e){super();if(this[E]={state:w.IDLE,frequency:null,activated:!1,hasReading:!1,timestamp:null},_(this,"reading"),_(this,"activate"),_(this,"error"),Object.defineProperty(this,"activated",{get:()=>this[f].activated}),Object.defineProperty(this,"hasReading",{get:()=>this[f].hasReading}),Object.defineProperty(this,"timestamp",{get:()=>this[f].timestamp}),window&&window.parent!=window.top)throw new DOMException("Only instantiable in a top-level browsing context","SecurityError");e&&typeof e.frequency=="number"&&e.frequency>60&&(this.frequency=e.frequency)}dispatchEvent(e){switch(e.type){case"reading":case"error":case"activate":{let i=`on${e.type}`;typeof this[i]=="function"&&this[i](e),super.dispatchEvent(e);break}default:super.dispatchEvent(e)}}start(){this[f].state===w.ACTIVATING||this[f].state===w.ACTIVE||(this[f].state=w.ACTIVATING,this[x]())}stop(){this[f].state!==w.IDLE&&(this[f].activated=!1,this[f].hasReading=!1,this[f].timestamp=null,this[u](),this[f].state=w.IDLE)}};var s=E,v=Symbol("handleEvent"),q;screen.orientation?q=screen.orientation:screen.msOrientation?q=screen.msOrientation:(q={},Object.defineProperty(q,"angle",{get:()=>window.orientation||0}));var R=function(){let t=navigator.userAgent.match(/.*Chrome\/([0-9]+)/),e=t?parseInt(t[1],10):null,r=e===null||e>=66?Math.PI/180:1;return function(n){return n*r}}(),A=(t,...e)=>class extends t{constructor(...i){super(i);for(let r of e)if(`on${r}`in window){this[s].eventName=r;break}}[x](){window.addEventListener(this[s].eventName,this[v].bind(this),{capture:!0})}[u](){window.removeEventListener(this[s].eventName,this[v].bind(this),{capture:!0})}};function j(t,e,i){let r=Math.PI/180,n=(e||0)*r,l=(i||0)*r,d=(t||0)*r,p=Math.cos(d*.5),o=Math.sin(d*.5),a=Math.cos(l*.5),h=Math.sin(l*.5),y=Math.cos(n*.5),S=Math.sin(n*.5),L=S*a*p-y*h*o,J=y*h*p+S*a*o,K=y*a*o+S*h*p,ee=y*a*p-S*h*o;return[L,J,K,ee]}function ie(t,e,i){let r=Math.sin(i/2),n=Math.cos(i/2),l=[e[0]*r,e[1]*r,e[2]*r,n];function d(o,a){let h=o[0]*a[3]+o[3]*a[0]+o[1]*a[2]-o[2]*a[1],y=o[1]*a[3]+o[3]*a[1]+o[2]*a[0]-o[0]*a[2],S=o[2]*a[3]+o[3]*a[2]+o[0]*a[1]-o[1]*a[0],L=o[3]*a[3]-o[0]*a[0]-o[1]*a[1]-o[2]*a[2];return[h,y,S,L]}function p(o){let a=Math.sqrt(o[0]**2+o[1]**2+o[2]**2+o[3]**2);return a===0?[0,0,0,1]:o.map(h=>h/a)}return p(d(t,l))}function V(t,e){return(t instanceof Float32Array||t instanceof Float64Array)&&t.length>=16&&(t[0]=1-2*(e[1]**2+e[2]**2),t[1]=2*(e[0]*e[1]-e[2]*e[3]),t[2]=2*(e[0]*e[2]+e[1]*e[3]),t[3]=0,t[4]=2*(e[0]*e[1]+e[2]*e[3]),t[5]=1-2*(e[0]**2+e[2]**2),t[6]=2*(e[1]*e[2]-e[0]*e[3]),t[7]=0,t[8]=2*(e[0]*e[2]-e[1]*e[3]),t[9]=2*(e[1]*e[2]+e[0]*e[3]),t[10]=1-2*(e[0]**2+e[1]**2),t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1),t}function Q(t){return t?ie(t,[0,0,1],-q.angle*Math.PI/180):null}var z=class extends A(b,"deviceorientation"){constructor(e={}){super(e);switch(e.referenceFrame||"device"){case"screen":Object.defineProperty(this,"quaternion",{get:()=>Q(this[s].quaternion)});break;default:Object.defineProperty(this,"quaternion",{get:()=>this[s].quaternion})}}[v](e){if(e.absolute||e.alpha===null){this[g]("Could not connect to a sensor","NotReadableError");return}this[s].activated||this[m](),this[s].timestamp=performance.now(),this[s].quaternion=j(e.alpha,e.beta,e.gamma),this[s].hasReading=!0,this.dispatchEvent(new Event("reading"))}[u](){super[u](),this[s].quaternion=null}populateMatrix(e){V(e,this.quaternion)}},$=class extends A(b,"deviceorientationabsolute","deviceorientation"){constructor(e={}){super(e);switch(e.referenceFrame||"device"){case"screen":Object.defineProperty(this,"quaternion",{get:()=>Q(this[s].quaternion)});break;default:Object.defineProperty(this,"quaternion",{get:()=>this[s].quaternion})}}[v](e){let i=e.absolute===!0||"webkitCompassHeading"in e,r=e.alpha!==null||e.webkitCompassHeading!==void 0;if(!i||!r){this[g]("Could not connect to a sensor","NotReadableError");return}this[s].activated||this[m](),this[s].hasReading=!0,this[s].timestamp=performance.now();let n=e.webkitCompassHeading!=null?360-e.webkitCompassHeading:e.alpha;this[s].quaternion=j(n,e.beta,e.gamma),this.dispatchEvent(new Event("reading"))}[u](){super[u](),this[s].quaternion=null}populateMatrix(e){V(e,this.quaternion)}},H=class extends A(b,"devicemotion"){constructor(e){super(e);M(this,s,{x:null,y:null,z:null})}[v](e){if(e.rotationRate.alpha===null){this[g]("Could not connect to a sensor","NotReadableError");return}this[s].activated||this[m](),this[s].timestamp=performance.now(),this[s].x=R(e.rotationRate.alpha),this[s].y=R(e.rotationRate.beta),this[s].z=R(e.rotationRate.gamma),this[s].hasReading=!0,this.dispatchEvent(new Event("reading"))}[u](){super[u](),this[s].x=null,this[s].y=null,this[s].z=null}},G=class extends A(b,"devicemotion"){constructor(e){super(e);M(this,s,{x:null,y:null,z:null})}[v](e){if(e.accelerationIncludingGravity.x===null){this[g]("Could not connect to a sensor","NotReadableError");return}this[s].activated||this[m](),this[s].timestamp=performance.now(),this[s].x=e.accelerationIncludingGravity.x,this[s].y=e.accelerationIncludingGravity.y,this[s].z=e.accelerationIncludingGravity.z,this[s].hasReading=!0,this.dispatchEvent(new Event("reading"))}[u](){super[u](),this[s].x=null,this[s].y=null,this[s].z=null}},N=class extends A(b,"devicemotion"){constructor(e){super(e);M(this,s,{x:null,y:null,z:null})}[v](e){if(e.acceleration.x===null){this[g]("Could not connect to a sensor","NotReadableError");return}this[s].activated||this[m](),this[s].timestamp=performance.now(),this[s].x=e.acceleration.x,this[s].y=e.acceleration.y,this[s].z=e.acceleration.z,this[s].hasReading=!0,this.dispatchEvent(new Event("reading"))}[u](){super[u](),this[s].x=null,this[s].y=null,this[s].z=null}},C=class extends A(b,"devicemotion"){constructor(e){super(e);M(this,s,{x:null,y:null,z:null})}[v](e){if(e.acceleration.x===null||e.accelerationIncludingGravity.x===null){this[g]("Could not connect to a sensor","NotReadableError");return}this[s].activated||this[m](),this[s].timestamp=performance.now(),this[s].x=e.accelerationIncludingGravity.x-e.acceleration.x,this[s].y=e.accelerationIncludingGravity.y-e.acceleration.y,this[s].z=e.accelerationIncludingGravity.z-e.acceleration.z,this[s].hasReading=!0,this.dispatchEvent(new Event("reading"))}[u](){super[u](),this[s].x=null,this[s].y=null,this[s].z=null}};var c=E;async function B(){let t="prompt";return navigator.permissions&&(t=(await navigator.permissions.query({name:"geolocation"})).state),new Promise(e=>{if(t==="granted")return e(t);let i=l=>{e("granted")},r=l=>{l.code===l.PERMISSION_DENIED?e("denied"):e(t)},n={maximumAge:Infinity,timeout:0};navigator.geolocation.getCurrentPosition(i,r,n)})}function U(t,e,i,r){let n=o=>{let a=o.timestamp-performance.timing.navigationStart,h=o.coords;e(a,h)},l=o=>{let a;switch(o.code){case o.TIMEOUT:a="TimeoutError";break;case o.PERMISSION_DENIED:a="NotAllowedError";break;case o.POSITION_UNAVAILABLE:a="NotReadableError";break;default:a="UnknownError"}i(o.message,a)},d={enableHighAccuracy:!1,maximumAge:0,timeout:Infinity};return navigator.geolocation.watchPosition(n,l,d)}function P(t){navigator.geolocation.clearWatch(t)}var W=class{constructor(){return this.constructor.instance||(this.constructor.instance=this),this.subscribers=new Map,this.options={},this.watchId=null,this.lastReading=null,this.constructor.instance}unsubscribe(e){this.subscribers.delete(e),!this.subscribers.size&&this.watchId&&(P(this.watchId),this.watchId=null)}subscribe(e,i,r,n){let l=(...p)=>{this.lastReading=p;for({onreading:r}of this.subscribers.values())typeof r=="function"&&r(...p)},d=(...p)=>{for({onerror:n}of this.subscribers.values())typeof n=="function"&&n(...p)};this.options=i,this.watchId&&P(this.watchId),this.lastReading&&typeof r=="function"&&r(...this.lastReading),this.subscribers.set(e,{onreading:r,onerror:n}),this.watchId=U(this.options,l,d)}},F=class extends b{static async read(e={}){return new Promise(async(i,r)=>{let n=(a,h)=>{let y=new I("error",{error:new DOMException(a,h)});P(o),r(y)},l=(a,h)=>{let y={timestamp:a,accuracy:h.accuracy,altitude:h.altitude,altitudeAccuracy:h.altitudeAccuracy,heading:h.heading,latitude:h.latitude,longitude:h.longitude,speed:h.speed};P(o),i(y)},d=e.signal;if(d&&d.aborted)return r(new DOMException("Read was cancelled","AbortError"));if(await B()!=="granted"){n("Permission denied.","NowAllowedError");return}let o=U(e,l,n);d&&d.addEventListener("abort",()=>{P(o),r(new DOMException("Read was cancelled","AbortError"))})})}constructor(e={}){super(e);this[c].options=e,this[c].fifo=new W;let i={latitude:null,longitude:null,altitude:null,accuracy:null,altitudeAccuracy:null,heading:null,speed:null},r=this[c];for(let n in i)r[n]=i[n],Object.defineProperty(this,n,{get:()=>r[n]})}async[x](){let e=(n,l)=>{this[c].timestamp=n,this[c].accuracy=l.accuracy,this[c].altitude=l.altitude,this[c].altitudeAccuracy=l.altitudeAccuracy,this[c].heading=l.heading,this[c].latitude=l.latitude,this[c].longitude=l.longitude,this[c].speed=l.speed,this[c].hasReading=!0,this.dispatchEvent(new Event("reading"))},i=(n,l)=>{this[g](n,l)};if(await B()!=="granted"){i("Permission denied.","NowAllowedError");return}this[c].fifo.subscribe(this,this[c].options,e,i),this[c].activated||this[m]()}[u](){this[c].fifo.unsubscribe(this),this[c].timestamp=null,this[c].accuracy=null,this[c].altitude=null,this[c].altitudeAccuracy=null,this[c].heading=null,this[c].latitude=null,this[c].longitude=null,this[c].speed=null,this[c].hasReading=!1}};function X(t,e=document){return e.querySelector(t)}function se(t,e=document){return[...e.querySelectorAll(t)]}var Y=[{name:"Accelerometer",label:"Accelerometer",type:"low-level"},{name:"LinearAccelerationSensor",label:"Linear Acceleration Sensor",type:"low-level"},{name:"Gravity",label:"Gravity Sensor",type:"low-level"},{name:"AmbientLightSensor",label:"Ambient Light Sensor",type:"low-level"},{name:"Gyroscope",label:"Gyroscope",type:"low-level"},{name:"Magnetometer",label:"Magnetometer",type:"low-level"},{name:"Geolocation",label:"Geolocation",type:"low-level"},{name:"ProximitySensor",label:"Proximity Sensor",type:"low-level"},{name:"AbsoluteOrientationSensor",label:"Absolute Orientation Sensor",type:"high-level"},{name:"RelativeOrientationSensor",label:"Relative Orientation Sensor",type:"high-level"}];(function(){let t=Y.filter(n=>n.type==="low-level"),e=Y.filter(n=>n.type==="high-level"),i='<header span="row"><h4>Low-Level Sensors</h4></header>',r='<header span="row"><h4>High-Level (fusion) Sensors</h4></header>';t.forEach(n=>i+=`<section class="sensor-cnt" data-sensorType="${n.name}">
<header>
<span>${n.label}</span>
<div class="rhs">
${n.name!=="AmbientLightSensor"&&n.name!=="Geolocation"&&n.name!=="ProximitySensor"?`<div class="freq-sel">
<label class="opacity5" for="frequency">freq:</label>
<div class="select-cnt">
<select id="frequency">
<option value="1">1Hz</option>
<option value="2">2Hz</option>
<option selected="selected" value="5">5Hz</option>
<option value="10">10Hz</option>
<option value="20">20Hz</option>
<option value="30">30Hz</option>
<option value="60">60Hz</option>
</select>
</div>
</div>`:""}
<div class="switch">
<input class="switch-inp" type="checkbox" />
<div class="switch-cnt">
<div class="thumb"></div>
</div>
</div>
</div>
</header>
<div class="error"></div>
<div class="reading"></div>
</section>`),e.forEach(n=>r+=`<section class="sensor-cnt" data-sensorType="${n.name}">
<header>
<span>${n.label}</span>
<div class="rhs">
<div class="freq-sel">
<label class="opacity5" for="frequency">freq:</label>
<div class="select-cnt">
<select id="frequency">
<option value="1">1Hz</option>
<option value="2">2Hz</option>
<option selected="selected" value="5">5Hz</option>
<option value="10">10Hz</option>
<option value="20">20Hz</option>
<option value="30">30Hz</option>
<option value="60">60Hz</option>
</select>
</div>
</div>
<div class="switch">
<input class="switch-inp" type="checkbox" />
<div class="switch-cnt">
<div class="thumb"></div>
</div>
</div>
</div>
</header>
<div class="error"></div>
<div class="reading"></div>
</section>`),X(".sensor-wrapper").insertAdjacentHTML("beforeend",`${i}<div span="row" aria-hidden="true" class="h-1"> </div>${r}`)})();window.Accelerometer||(window.Accelerometer=G);window.Gyroscope||(window.Gyroscope=H);window.GravitySensor||(window.GravitySensor=C);window.LinearAccelerationSensor||(window.LinearAccelerationSensor=N);window.RelativeOrientationSensor||(window.RelativeOrientationSensor=z);window.AbsoluteOrientationSensor||(window.AbsoluteOrientationSensor=$);window.GeolocationSensor||(window.GeolocationSensor=F);se(".sensor-cnt").forEach(t=>{new O(t)});var Z=class{constructor(e,i,r){this.root=document.querySelector("html"),i&&(this.namespace=i),r&&(this.setMetaTheme=r),this.label="darkMode",this.InitializeTheme(),e.addEventListener("click",()=>this.toggleTheme())}InitializeTheme(){this.namespace&&(this.label=`${this.namespace}-darkMode`);let e=localStorage.getItem(this.label);e==="false"||e==null?(this.setLightMode(),this.setMetaTheme&&this.setMeta("light")):(this.setDarkMode(),this.setMetaTheme&&this.setMeta("dark"))}setMeta(e){let i=document.querySelector('html meta[name="theme-color"]');if(!i){document.createElement("meta").setAttribute("name","theme-color"),document.querySelector("head").insertAdjacentHTML("beforeend",`<meta name="theme-color" content="${e==="dark"?"#191919":"#ffffff"}" />`);return}i.insertAdjacentHTML("afterend",`<meta name="theme-color" content="${e==="dark"?"#191919":"#ffffff"}" />`),i.remove()}toggleTheme(){localStorage.getItem(this.label)==="false"?(this.setDarkMode(),this.setMetaTheme&&this.setMeta("dark")):(this.setLightMode(),this.setMetaTheme&&this.setMeta("light"))}setDarkMode(){this.root.classList.add("dark"),localStorage.setItem(this.label,!0),this.setMetaTheme&&this.setMeta("dark")}setLightMode(){this.root.classList.remove("dark"),localStorage.setItem(this.label,!1),this.setMetaTheme&&this.setMeta("light")}};new Z(X("#darkMode-toggle"),"sensor",!0);})();