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