Files
waybar-online/assets/battery-EWyHazIA.js
2025-08-02 08:13:49 +00:00

3 lines
9.2 KiB
JavaScript

function _(e){Object.defineProperty(e,"__esModule",{value:!0,configurable:!0})}function A(e,c,a,o){Object.defineProperty(e,c,{get:a,set:o,enumerable:!0,configurable:!0})}var R={};_(R);A(R,"default",()=>U);class U extends Error{constructor(c,a,o,m,s){super(c+":"+o+":"+m+": "+a),this.reason=a,this.filename=c,this.line=o,this.column=m,this.source=s}}var z={};_(z);A(z,"default",()=>H);class H{constructor(c,a,o){this.start=c,this.end=a,this.source=o}}var oe={};A(oe,"CssTypes",()=>$);var $=function(e){return e.stylesheet="stylesheet",e.rule="rule",e.declaration="declaration",e.comment="comment",e.container="container",e.charset="charset",e.document="document",e.customMedia="custom-media",e.fontFace="font-face",e.host="host",e.import="import",e.keyframes="keyframes",e.keyframe="keyframe",e.layer="layer",e.media="media",e.namespace="namespace",e.page="page",e.startingStyle="starting-style",e.supports="supports",e}({});const Q=1e4,N=(e,c,a)=>{let o=a,m=Q;do{const s=c.map(g=>e.indexOf(g,o));s.push(e.indexOf("\\",o));const h=s.filter(g=>g!==-1);if(h.length===0)return-1;const r=Math.min(...h);if(e[r]==="\\")o=r+2,m--;else return r}while(m>0);throw new Error("Too many escaping")},E=(e,c,a)=>{let o=a,m=Q;do{const s=c.map(i=>e.indexOf(i,o));s.push(e.indexOf("(",o)),s.push(e.indexOf('"',o)),s.push(e.indexOf("'",o)),s.push(e.indexOf("\\",o));const h=s.filter(i=>i!==-1);if(h.length===0)return-1;const r=Math.min(...h);switch(e[r]){case"\\":o=r+2;break;case"(":{const i=E(e,[")"],r+1);if(i===-1)return-1;o=i+1}break;case'"':{const i=N(e,['"'],r+1);if(i===-1)return-1;o=i+1}break;case"'":{const i=N(e,["'"],r+1);if(i===-1)return-1;o=i+1}break;default:return r}m--}while(m>0);throw new Error("Too many escaping")},ce=(e,c)=>{const a=[];let o=0;for(;o<e.length;){const m=E(e,c,o);if(m===-1)return a.push(e.substring(o)),a;a.push(e.substring(o,m)),o=m+1}return a},L=/\/\*[^]*?(?:\*\/|$)/g,se=(e,c)=>{c=c||{};let a=1,o=1;function m(n){const t=n.match(/\n/g);t&&(a+=t.length);const u=n.lastIndexOf(`
`);o=~u?n.length-u:o+n.length}function s(){const n={line:a,column:o};return function(t){return t.position=new H(n,{line:a,column:o},c?.source||""),w(),t}}const h=[];function r(n){const t=new U(c?.source||"",n,a,o,e);if(c?.silent)h.push(t);else throw t}function g(){const n=y();return{type:$.stylesheet,stylesheet:{source:c?.source,rules:n,parsingErrors:h}}}function i(){const n=/^{\s*/.exec(e);return n?(l(n),!0):!1}function d(){const n=/^}/.exec(e);return n?(l(n),!0):!1}function y(){let n;const t=[];for(w(),p(t);e.length&&e.charAt(0)!=="}"&&(n=ne()||re());)n&&(t.push(n),p(t));return t}function l(n){const t=n[0];return m(t),e=e.slice(t.length),n}function w(){const n=/^\s*/.exec(e);n&&l(n)}function p(n){let t;for(n=n||[];t=V();)t&&n.push(t);return n}function V(){const n=s();if(e.charAt(0)!=="/"||e.charAt(1)!=="*")return;const t=/^\/\*[^]*?\*\//.exec(e);return t?(l(t),n({type:$.comment,comment:t[0].slice(2,-2)})):r("End of comment missing")}function S(){const n=/^([^{]+)/.exec(e);if(!n)return;l(n);const t=b(n[0]).replace(L,"");return ce(t,[","]).map(u=>b(u))}function k(){const n=s(),t=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/.exec(e);if(!t)return;l(t);const u=b(t[0]),f=/^:\s*/.exec(e);if(!f)return r("property missing ':'");l(f);let x="";const v=E(e,[";","}"]);v!==-1&&(x=e.substring(0,v),l([x]),x=b(x).replace(L,""));const M=n({type:$.declaration,property:u.replace(L,""),value:x}),F=/^[;\s]*/.exec(e);return F&&l(F),M}function I(){const n=[];if(!i())return r("missing '{'");p(n);let t;for(;t=k();)t&&(n.push(t),p(n));return d()?n:r("missing '}'")}function j(){let n;const t=[],u=s();for(;n=/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/.exec(e);){const f=l(n);t.push(f[1]);const x=/^,\s*/.exec(e);x&&l(x)}if(t.length)return u({type:$.keyframe,values:t,declarations:I()||[]})}function B(){const n=s(),t=/^@([-\w]+)?keyframes\s*/.exec(e);if(!t)return;const u=l(t)[1],f=/^([-\w]+)\s*/.exec(e);if(!f)return r("@keyframes missing name");const x=l(f)[1];if(!i())return r("@keyframes missing '{'");let v,M=p();for(;v=j();)M.push(v),M=M.concat(p());return d()?n({type:$.keyframes,name:x,vendor:u,keyframes:M}):r("@keyframes missing '}'")}function D(){const n=s(),t=/^@supports *([^{]+)/.exec(e);if(!t)return;const u=b(l(t)[1]);if(!i())return r("@supports missing '{'");const f=p().concat(y());return d()?n({type:$.supports,supports:u,rules:f}):r("@supports missing '}'")}function W(){const n=s(),t=/^@host\s*/.exec(e);if(!t)return;if(l(t),!i())return r("@host missing '{'");const u=p().concat(y());return d()?n({type:$.host,rules:u}):r("@host missing '}'")}function q(){const n=s(),t=/^@container *([^{]+)/.exec(e);if(!t)return;const u=b(l(t)[1]);if(!i())return r("@container missing '{'");const f=p().concat(y());return d()?n({type:$.container,container:u,rules:f}):r("@container missing '}'")}function G(){const n=s(),t=/^@layer *([^{;@]+)/.exec(e);if(!t)return;const u=b(l(t)[1]);if(!i()){const x=/^[;\s]*/.exec(e);return x&&l(x),n({type:$.layer,layer:u})}const f=p().concat(y());return d()?n({type:$.layer,layer:u,rules:f}):r("@layer missing '}'")}function J(){const n=s(),t=/^@media *([^{]+)/.exec(e);if(!t)return;const u=b(l(t)[1]);if(!i())return r("@media missing '{'");const f=p().concat(y());return d()?n({type:$.media,media:u,rules:f}):r("@media missing '}'")}function K(){const n=s(),t=/^@custom-media\s+(--\S+)\s+([^{;\s][^{;]*);/.exec(e);if(!t)return;const u=l(t);return n({type:$.customMedia,name:b(u[1]),media:b(u[2])})}function X(){const n=s(),t=/^@page */.exec(e);if(!t)return;l(t);const u=S()||[];if(!i())return r("@page missing '{'");let f=p(),x;for(;x=k();)f.push(x),f=f.concat(p());return d()?n({type:$.page,selectors:u,declarations:f}):r("@page missing '}'")}function Y(){const n=s(),t=/^@([-\w]+)?document *([^{]+)/.exec(e);if(!t)return;const u=l(t),f=b(u[1]),x=b(u[2]);if(!i())return r("@document missing '{'");const v=p().concat(y());return d()?n({type:$.document,document:x,vendor:f,rules:v}):r("@document missing '}'")}function Z(){const n=s(),t=/^@font-face\s*/.exec(e);if(!t)return;if(l(t),!i())return r("@font-face missing '{'");let u=p(),f;for(;f=k();)u.push(f),u=u.concat(p());return d()?n({type:$.fontFace,declarations:u}):r("@font-face missing '}'")}function C(){const n=s(),t=/^@starting-style\s*/.exec(e);if(!t)return;if(l(t),!i())return r("@starting-style missing '{'");const u=p().concat(y());return d()?n({type:$.startingStyle,rules:u}):r("@starting-style missing '}'")}const T=P("import"),ee=P("charset"),te=P("namespace");function P(n){const t=new RegExp("^@"+n+`\\s*((?::?[^;'"]|"(?:\\\\"|[^"])*?"|'(?:\\\\'|[^'])*?')+)(?:;|$)`);return function(){const u=s(),f=t.exec(e);if(!f)return;const x=l(f),v={type:n};return v[n]=x[1].trim(),u(v)}}function ne(){if(e[0]==="@")return B()||J()||K()||D()||T()||ee()||te()||Y()||X()||W()||Z()||q()||C()||G()}function re(){const n=s(),t=S();return t?(p(),n({type:$.rule,selectors:t,declarations:I()||[]})):r("selector missing")}return O(g())};function b(e){return e?e.trim():""}function O(e,c){const a=e&&typeof e.type=="string",o=a?e:c;for(const m in e){const s=e[m];Array.isArray(s)?s.forEach(h=>{O(h,o)}):s&&typeof s=="object"&&O(s,o)}return a&&Object.defineProperty(e,"parent",{configurable:!0,writable:!0,enumerable:!1,value:c||null}),e}var ae=se;const ie=ae,ue=(e,c,a)=>Math.min(Math.max(e,c),a),le=async()=>await fetch("/waybar-online/fontawesome/css/fontawesome.min.css").then(c=>c.text()),fe=await le();function me(){const e=new Map;return ie(fe).stylesheet.rules.forEach(a=>{if(a.type===$.rule){const o=a.declarations[0];if(o.type===$.declaration){if(o.property!=="--fa")return;a.selectors[0];const m=o.value.slice(1,-1);try{const s=String.fromCodePoint(parseInt(m.slice(1),16));if(!Number.isNaN(parseInt(s)))return;e.set(s,m)}catch{}}}}),e}const de=[...me().keys()],pe=new RegExp(de.map(e=>`\\${e}`).join("|"),"g"),he=e=>e.replace(pe,a=>`<span class="fa">${a}</span>`),ge=e=>{let c="";const a=()=>{if(e.config)return c||e.config?.format||void 0},o=g=>c=g||"",m=document.createElement("span");return e.update&&setInterval(e.update,e.interval),{element:m,set:g=>{const i=a();if(!i)return console.error("No format found"),"N/A";const d=i.replace(/\{(\w+)\}/g,(y,l)=>g[l]!==void 0?g[l]:y);m.innerHTML=he(d)},getIcon:(g,i,d=0)=>{const y=e.config?.["format-icons"],l=y?.length||0,w=ue(g/((d==0?100:d)/l),0,l-1),p=y?.[Math.round(w)];return p||""},getState:(g,i)=>{const d=e.config?.states;if(typeof d!="object")return"";const y=Object.entries(d);y.sort((w,p)=>i?w[1]-p[1]:p[1]-w[1]);let l="";return y.forEach(w=>{(i?g<=w[1]:g>=w[1])&&!l?(e.module.element.classList.add(w[0]),l=w[0]):e.module.element.classList.remove(w[0])}),l},setFormat:o}},xe=(e,c)=>{const a=ge({interval:1e3,update:()=>s(),config:c,module:e});e.element.appendChild(a.element);const o=h=>{let r="Unknown";return h.charging&&h.level<1&&(r="Charging"),!h.charging&&h.level===1&&(r="Full"),h.charging&&h.level===1&&(r="Plugged"),!h.charging&&h.level<1&&(r="Discharging"),r};let m="Unknown";const s=async()=>{const h={level:Math.random(),charging:Math.random()>.5},r=Math.round(h.level*100),g=o(h);e.element.classList.remove(m.toLowerCase()),e.element.classList.add(g.toLowerCase()),m=g,e.element.title=g;const i=a.getState(r,!0);if(c){const d=g.toLowerCase();let y="";i&&c["format-"+d+"-"+i]?y=c["format-"+d+"-"+i]:c["format-"+d]?y=c["format-"+d]:i&&c["format-"+i]&&(y=c["format-"+i]),a.setFormat(y)}a.set({capacity:r,icon:a.getIcon(r)})};s()};export{xe as createBatteryModule};