const toSolidByte=(t,e)=>{const n=parseInt(e,16);return String.fromCharCode(n)},regexNum=/%([0-9A-F]{2})/g;export function toBase64String(t){const e=encodeURIComponent(t).replace(regexNum,toSolidByte);return window.btoa(e)}export function fromBase64String(t){const e=window.atob(t).split("").map((t=>"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2))).join("");return decodeURIComponent(e)}const r={text:/^[^\u0025]+/,percent:/^\u0025{2}/,arg:/^\u0025([+0\u0020\u002d]*)([0-9]*)(\.[0-9]+)?(b|d|i|f|s)/},fun={b:t=>t?"true":"false",d(t){const e=parseInt(t,10);return`${e<0?"-":this.sign&&!isNaN(e)?"+":""}${Math.abs(e)}`},f(t){const e=parseFloat(t),n=e<0?"-":this.sign&&!isNaN(e)?"+":"";return this.precision?`${n}${Math.abs(e).toFixed(this.precision)}`:`${n}${Math.abs(e)}`},s:t=>String(t)};Object.assign(fun,{i:fun.d});const sprintf=Object.assign((function(t,...e){if(void 0===t)throw new Error("[sprintf] format must be specified");const n=sprintf.cache;return n[t]&&Object.prototype.hasOwnProperty.call(n,t)||(n[t]=sprintf.parse(t)),sprintf.format(n[t],e)}),{cache:Object.create(null),format:(t,e)=>t.map((function(t){let n,r;if("string"==typeof t)n=t;else{const s=e.shift();if(n=(t.fun||(()=>"")).call(t,s),t.width){const e=t.width-n.length;e>0&&(r=(t.pad||" ").repeat(e),t.left?n+=r:n=r+n)}}return n})).join(""),parse:function(t){const e=[];let n=t;for(;0!==n.length;){let t=r.text.exec(n);if(t)e.push(t[0]);else if(t=r.percent.exec(n),t)e.push("%");else{if(t=r.arg.exec(n),!t)throw new Error("[sprintf] could not parse: "+n);{const n=Object.create(null),r=t[1],s=t[2],i=t[3],o=t[4],a=fun[o];if(!a)throw new Error("[sprintf] invalid type: "+o);n.fun=a,r&&(-1!==r.indexOf("-")&&(n.left=!0),-1!==r.indexOf("+")&&(n.sign=!0)),s&&(n.width=parseInt(s,10),-1!==r.indexOf("0")?n.pad="0":n.pad=" "),i&&(n.precision=parseInt(i.substr(1),10)),e.push(n)}}n=n.substring(t[0].length)}return e}});export{sprintf};
