diff --git a/components/floating-button/floating-button.css b/components/floating-button/floating-button.css index cfdca41..4138af8 100644 --- a/components/floating-button/floating-button.css +++ b/components/floating-button/floating-button.css @@ -42,7 +42,7 @@ /* Default opacity for inactive button */ #floating-button.inactive { - opacity: 0.4; + opacity: 0.3; } /* Style changes when dragging */ diff --git a/dist/main.js b/dist/main.js index 93c2a88..e56156e 100644 --- a/dist/main.js +++ b/dist/main.js @@ -1 +1 @@ -let $;function We(e){if($==null)return $=e.classList.contains("enable-para"),$}let w="";function $e(e){return w!=""||(w=e.getAttribute("data-bani-name")||""),w}let r=1,l=r,X,L="d-block",b;function je(e){b=$e(e),r=parseInt(localStorage.getItem("currentShabadStart_"+b))||1,l=r,X=e,We(e)&&(L="d-inline"),de(e)}function Ge(e){if(r<=1)return;Xe(),l=r-1;const t=500;let n=0;for(;e.getBoundingClientRect().heightwindow.innerHeight){o.classList.remove(L),r++;break}if(n>t)break;n++}localStorage.setItem("currentShabadStart_"+b,r)}function Xe(){let t=r,n=Math.max(l,r);for(;t<=n;){const o=document.getElementById("shabad_"+t);if(o&&o.classList.remove(L),t-r>500)break;t++}}function Ue(){let t=r;for(r=l+1;t<=l;){const n=document.getElementById("shabad_"+t);if(n&&n.classList.remove(L),t-r>500)break;t++}}function Ve(e){if(!document.getElementById("shabad_"+(l+1)))return;Ue(),l=r;const n=500;let o=0;for(;e.getBoundingClientRect().heightwindow.innerHeight){c.classList.remove(L),l--;break}if(l++,o>n)break;o++}localStorage.setItem("currentShabadStart_"+b,r)}function de(e){let n=0;for(;e.getBoundingClientRect().heightwindow.innerHeight){o.classList.remove(L),l--;break}if(l++,n>500)break;n++}localStorage.setItem("currentShabadStart_"+b,r)}function k(e){X&&(Ye(),e&&(r=e),l=r,de(X))}function Ye(){let e=r;const t=500;let n=0;for(;e<=l;){const o=document.getElementById("shabad_"+e);if(o&&o.classList.remove(L),e++,n>t)break;n++}}function fe(){document.fullscreenElement?document.exitFullscreen&&document.exitFullscreen().then(()=>{k(),ee()}):document.documentElement.requestFullscreen().then(()=>{k(),ee()})}const ge="floatingButtonX",he="floatingButtonY";function f(e,t){localStorage.setItem(e,t)}function R(e){localStorage.removeItem(e)}function a(e){return localStorage.getItem(e)}const me="fontSize",_="lineHeight",T="wordSpacing",Le="align",U="english",V="punjabi",N="darkMode",z="fontColor",x="backgroundColor";function Ke(){localStorage.clear()}function Ee(e){Ge(e)}function Ie(e){Ve(e)}function Ze(){window.addEventListener("resize",()=>{ee()})}function h(e){return e!=null&&!isNaN(e)&&e!=="undefined"&&e!==""}function pe(...e){for(const t of e)if(t==null||isNaN(t)||t==="undefined")return!1;return!0}function p(e,t,n){return n>=e&&n<=t}function m(e){return e&&typeof e=="string"&&e.length>0}function qe(){const e=document.getElementById("leftAlign"),t=document.getElementById("middleAlign"),n=document.getElementById("rightAlign"),o=document.getElementById("justifyAlign"),c=document.getElementById("bani");tt(e,t,n,o,c),Je(e,t,n,o,c)}function Je(e,t,n,o,c){e.addEventListener("change",i=>{F("start",i.target.checked,c)}),t.addEventListener("change",i=>{F("center",i.target.checked,c)}),n.addEventListener("change",i=>{F("end",i.target.checked,c)}),o.addEventListener("change",i=>{F("justify",i.target.checked,c)})}function F(e,t,n){!t&&!m(e)||(n.style.textAlign=e,Qe(e))}function Qe(e){m(e)&&f(Le,e)}function et(e,t,n,o,c,i){switch(c){case"start":i.style.textAlign=c,e.checked=!0;break;case"end":i.style.textAlign=c,n.checked=!0;break;case"center":i.style.textAlign=c,t.checked=!0;break;case"justify":i.style.textAlign=c,o.checked=!0;break}}function tt(e,t,n,o,c){const i=a(Le);m(i)&&et(e,t,n,o,i,c)}function nt(){const e=document.getElementById("background-color");it(e),ot(e),ct(e)}function ot(e){e.addEventListener("change",t=>{ye(t.target.value),f(x,t.target.value)})}function ye(e){document.documentElement.style.setProperty("--background-color",e)}function Se(e,t){e.value=t}function it(e){let t=a(x);m(t)&&Se(e,t)}const ae="#ffffff";function ct(e){document.getElementById("background-reset-icon").addEventListener("click",()=>{document.documentElement.style.setProperty("--background-color",ae),R(x),Se(e,ae)})}function rt(){let e=a(x);m(e)&&ye(e)}function st(){const e=document.getElementById("dark-mode");lt(e),at(e)}function at(e){e.addEventListener("change",t=>{t.target.checked?(Y("true"),f(N,"true")):(Y("false"),f(N,"false"))})}function Y(e){e==="true"?H(!0):e==="false"&&H(!1)}function K(e,t){t==="true"?e.checked=!0:t==="false"&&(e.checked=!1)}function lt(e){let t=a(N);m(t)||(t="false"),K(e,t)}function ut(){let e=a(N);m(e)||(e="false"),Y(e)}const dt="#121212",ft="#E0E0E0",gt="#ffffff",ht="#000000";function H(e){if(e){document.documentElement.style.setProperty("--font-color",ft),document.documentElement.style.setProperty("--background-color",dt);return}document.documentElement.style.setProperty("--font-color",ht),document.documentElement.style.setProperty("--background-color",gt)}const mt=window.matchMedia("(prefers-color-scheme: dark)");mt.addEventListener("change",e=>{const t=document.getElementById("dark-mode");e.matches?(H(!0),K(t,"true")):(H(!1),K(t,"false"))});function Lt(e){const t=document.getElementById("english");pt(e,t),Et(e,t)}function Et(e,t){t.addEventListener("change",n=>{n.target.checked?(Z(e,"true"),f(V,"true")):(Z(e,"false"),f(V,"false")),k()})}function Z(e,t){t==="true"?e.classList.remove("hide-shabad-en"):t==="false"&&e.classList.add("hide-shabad-en")}function It(e,t){t==="true"?e.checked=!0:t==="false"&&(e.checked=!1)}function pt(e,t){let n=a(V);m(n)||(n="false"),Z(e,n),It(t,n)}function yt(){const e=document.getElementById("font-color");Bt(e),St(e),bt(e)}function St(e){e.addEventListener("change",t=>{Be(t.target.value),f(z,t.target.value)})}function Be(e){document.documentElement.style.setProperty("--font-color",e)}function be(e,t){e.value=t}function Bt(e){let t=a(z);m(t)&&be(e,t)}const le="#000000";function bt(e){document.getElementById("font-reset-icon").addEventListener("click",()=>{document.documentElement.style.setProperty("--font-color",le),R(z),be(e,le)})}function kt(){let e=a(z);m(e)&&Be(e)}function y(e,t){e.value=Number.parseFloat(t).toFixed(2)}let ke;function Ct(e,t){ke=setInterval(()=>{e()},t)}function ue(e){clearInterval(ke),e()}function S(e,t,n,o){e.addEventListener("pointerdown",c=>{Ct(()=>{t()},o)}),e.addEventListener("pointerup",c=>{ue(()=>{n()})}),e.addEventListener("pointerleave",c=>{ue(()=>{n()})})}const Ce=1,ve=200,we=1,Fe=.04;function vt(){const e=document.getElementById("font-input"),t=document.getElementById("bani");Ft(e,t),At(e,t),wt(e,t)}function wt(e,t){e.addEventListener("change",n=>{h(n.target.value)&&p(Ce,ve,n.target.value)&&(t.style.fontSize=n.target.value+"px",te(t))})}function Ft(e,t){const n=document.getElementById("font-increase");S(n,()=>{Ae(Fe,t,e)},()=>{te(t)},we)}function At(e,t){const n=document.getElementById("font-decrease");S(n,()=>{Ae(-Fe,t,e)},()=>{te(t)},we)}function Nt(){const e=document.getElementById("bani"),t=window.getComputedStyle(e).getPropertyValue("font-size"),n=Number.parseFloat(t.substring(0,t.length-2)),o=document.getElementById("font-input");y(o,n)}function Ae(e,t,n){const o=window.getComputedStyle(t).getPropertyValue("font-size");let i=Number.parseFloat(o.substring(0,o.length-2))+e;p(Ce,ve,i)&&(y(n,i),t.style.fontSize=i+"px")}function Ht(e){const t=a(me);if(h(t)){e.style.fontSize=t+"px";return}}function te(e){const t=window.getComputedStyle(e).getPropertyValue("font-size"),n=Number.parseFloat(t.substring(0,t.length-2));if(h(n)){f(me,n);return}}const q=1,Ne=10,He=10,Re=.01;let u=null;function Rt(){const e=document.getElementById("line-height-input"),t=document.getElementById("bani");Tt(e,t),zt(e,t),_t(e,t)}function _t(e,t){e.addEventListener("change",n=>{const o=n.target.value;h(o)&&p(q,Ne,o)?(t.style.lineHeight=o,u=Number.parseFloat(o),ne(u)):(u=null,t.style.lineHeight="normal",R(_))})}function Tt(e,t){const n=document.getElementById("line-height-increase");S(n,()=>{_e(Re,t,e)},()=>{ne(u)},He)}function zt(e,t){const n=document.getElementById("line-height-decrease");S(n,()=>{_e(-Re,t,e)},()=>{ne(u)},He)}function _e(e,t,n){let o;u?o=u+e:o=q+e,p(q,Ne,o)&&(u=o,y(n,u),t.style.lineHeight=u)}function xt(){const e=a(_);if(!h(e)){u=null;return}const t=document.getElementById("line-height-input");u=Number.parseFloat(e),y(t,e)}function Pt(e){const t=a(_);if(h(t)){u=Number.parseFloat(t),e.style.lineHeight=u;return}u=null}function ne(e){if(h(e)){f(_,e);return}}function Dt(e){const t=document.getElementById("punjabi");Wt(e,t),Mt(e,t)}function Mt(e,t){t.addEventListener("change",n=>{n.target.checked?(J(e,"true"),f(U,"true")):(J(e,"false"),f(U,"false")),k()})}function J(e,t){t==="true"?e.classList.remove("hide-shabad-pu"):t==="false"&&e.classList.add("hide-shabad-pu")}function Ot(e,t){t==="true"?e.checked=!0:t==="false"&&(e.checked=!1)}function Wt(e,t){let n=a(U);m(n)||(n="false"),J(e,n),Ot(t,n)}const Q=1,Te=20,ze=10,xe=.01;let d=null;function $t(){const e=document.getElementById("word-spacing-input"),t=document.getElementById("bani");Gt(e,t),Xt(e,t),jt(e,t)}function jt(e,t){e.addEventListener("change",n=>{let o=n.target.value;o&&(o=Number.parseFloat(o)),h(o)&&p(Q,Te,o)?(t.style.wordSpacing=o+"px",d=Number.parseFloat(o),oe(d)):(d=null,t.style.wordSpacing="normal",R(T))})}function Gt(e,t){const n=document.getElementById("word-spacing-increase");S(n,()=>{Pe(xe,t,e)},()=>{oe(d)},ze)}function Xt(e,t){const n=document.getElementById("word-spacing-decrease");S(n,()=>{Pe(-xe,t,e)},()=>{oe(d)},ze)}function Pe(e,t,n){let o;d?o=d+e:o=Q+e,p(Q,Te,o)&&(d=o,y(n,d),t.style.wordSpacing=d+"px")}function Ut(){const e=a(T);if(!h(e)){d=null;return}const t=document.getElementById("word-spacing-input");d=Number.parseFloat(e),y(t,e)}function Vt(e){const t=a(T);if(h(t)){d=Number.parseFloat(t),e.style.wordSpacing=d+"px";return}d=null}function oe(e){if(h(e)){f(T,e);return}}let A=!1;function Yt(e,t){fetch("components/menu/menu.html").then(n=>{n.text().then(o=>{e.innerHTML=o,Kt(t)})}).catch(n=>{console.log(n)})}let I;function Kt(e){I||(I=document.getElementById("menu")),tn(e)}function Zt(){I||(I=document.getElementById("menu")),A?I.classList.add("menuClose"):I.classList.remove("menuClose"),A=!A}function qt(){document.getElementById("reset-icon").addEventListener("click",()=>{Ke(),location.reload()})}function Jt(){document.getElementById("restart-icon").addEventListener("click",()=>{k(1)})}function Qt(e){vt(),Rt(),$t(),qe(),Dt(e),Lt(e),st(),yt(),nt()}function en(e){Nt(),xt(),Ut(),je(e)}function tn(e){qt(),Jt(),Qt(e),en(e)}let j=window.innerWidth,G=window.innerHeight;function nn(e,t){fetch("components/floating-button/floating-button.html").then(n=>n.text()).then(n=>{e.innerHTML=n;const o=document.getElementById("menu-container");o&&Yt(o,t),rn(t)}).catch(console.error)}function on(e){let t=a(ge),n=a(he);if(pe(t,n)){t=Number.parseFloat(t),n=Number.parseFloat(n);const o=e.offsetWidth;e.offsetHeight,ie(e,t,n,o)}}let De=0,Me=0;function cn(e,t){pe(e,t)&&(f(ge,e),f(he,t))}function rn(e){const t=document.getElementById("floating-button");on(t);let n=!1,o=!1,c=!1,i=!1,g=!1,P=!1,D,M,ce,re;function C(s,E){return s.closest(`#${E}`)!==null}t.addEventListener("pointerdown",s=>{i=C(s.target,"left-icon"),g=C(s.target,"right-icon"),c=C(s.target,"menu-icon"),P=C(s.target,"fullscreen-icon"),o=!0,n=!0,t.classList.remove("inactive"),D=s.clientX,M=s.clientY,ce=t.offsetLeft,re=t.offsetTop,t.setPointerCapture(s.pointerId)}),t.addEventListener("pointermove",s=>{if(n){const E=s.clientX-D,B=s.clientY-M;if(Math.abs(E)>v||Math.abs(B)>v){const O=t.offsetWidth;t.offsetHeight;let W=ce+E,Oe=re+B;ie(t,W,Oe,O),c=!1,i=!1,g=!1,P=!1,o=!1}}});const v=15;t.addEventListener("pointerup",s=>{const E=s.clientX,B=s.clientY,se=Math.abs(E-D),O=Math.abs(B-M),W=se<=v&&O<=v;o&&W?(c&&Zt(),i&&Ee(e),g&&Ie(e),P&&fe()):n&&cn(De,Me),n=!1,A||t.classList.add("inactive"),t.releasePointerCapture(s.pointerId)}),Ze()}function ie(e,t,n,o,c){j=window.innerWidth,G=window.innerHeight;const i=o/2,g=10;t-i-g<0&&(t=i+g),t+i+g>j&&(t=j-i-g),n-i-g<0&&(n=i+g),n+i+g>G&&(n=G-i-g),De=t,Me=n,e.style.left=`${t}px`,e.style.top=`${n}px`,e.style.bottom="auto",e.style.right="auto"}function ee(){const e=document.getElementById("floating-button");if(!e)return;const t=e.offsetLeft,n=e.offsetTop,o=e.offsetWidth;e.offsetHeight,ie(e,t,n,o)}function sn(e){an(e)}function an(e){document.addEventListener("keydown",t=>{t.key==="ArrowLeft"||t.key==="A"||t.key==="a"?Ee(e):t.key==="ArrowRight"||t.key==="D"||t.key==="d"?Ie(e):(t.key==="F"||t.key==="f")&&fe()})}function ln(e){document.readyState==="complete"||document.readyState==="interactive"?e():document.addEventListener?document.addEventListener("DOMContentLoaded",e):document.attachEvent&&document.attachEvent("onreadystatechange",function(){document.readyState==="complete"&&e()})}function un(){const e=document.getElementById("bani");if(!e)return;const t=document.getElementById("floating-button-container");t!=null&&nn(t,e);function n(){Ht(e),Pt(e),Vt(e)}n(),sn(e)}ln(un);ut();kt();rt(); +let $;function We(e){if($==null)return $=e.classList.contains("enable-para"),$}let w="";function $e(e){return w!=""||(w=e.getAttribute("data-bani-name")||""),w}let r=1,l=r,X,L="d-block",b;function je(e){b=$e(e),r=parseInt(localStorage.getItem("currentShabadStart_"+b))||1,l=r,X=e,We(e)&&(L="d-inline"),de(e)}function Ge(e){if(r<=1)return;Xe(),l=r-1;const t=500;let n=0;for(;e.getBoundingClientRect().heightwindow.innerHeight){o.classList.remove(L),r++;break}if(n>t)break;n++}localStorage.setItem("currentShabadStart_"+b,r)}function Xe(){let t=r,n=Math.max(l,r);for(;t<=n;){const o=document.getElementById("shabad_"+t);if(o&&o.classList.remove(L),t-r>500)break;t++}}function Ue(){let t=r;for(r=l+1;t<=l;){const n=document.getElementById("shabad_"+t);if(n&&n.classList.remove(L),t-r>500)break;t++}}function Ve(e){if(!document.getElementById("shabad_"+(l+1)))return;Ue(),l=r;const n=500;let o=0;for(;e.getBoundingClientRect().heightwindow.innerHeight){c.classList.remove(L),l--;break}if(l++,o>n)break;o++}localStorage.setItem("currentShabadStart_"+b,r)}function de(e){let n=0;for(;e.getBoundingClientRect().heightwindow.innerHeight){o.classList.remove(L),l--;break}if(l++,n>500)break;n++}localStorage.setItem("currentShabadStart_"+b,r)}function k(e){X&&(Ye(),e&&(r=e),l=r,de(X))}function Ye(){let e=r;const t=500;let n=0;for(;e<=l;){const o=document.getElementById("shabad_"+e);if(o&&o.classList.remove(L),e++,n>t)break;n++}}function fe(){document.fullscreenElement?document.exitFullscreen&&document.exitFullscreen().then(()=>{k(),ee()}):document.documentElement.requestFullscreen().then(()=>{k(),ee()})}const ge="floatingButtonX",he="floatingButtonY";function f(e,t){localStorage.setItem(e,t)}function R(e){localStorage.removeItem(e)}function a(e){return localStorage.getItem(e)}const me="fontSize",_="lineHeight",T="wordSpacing",Le="align",U="english",V="punjabi",N="darkMode",z="fontColor",x="backgroundColor";function Ke(){localStorage.clear()}function Ee(e){Ge(e)}function Ie(e){Ve(e)}function Ze(){window.addEventListener("resize",()=>{ee()})}function h(e){return e!=null&&!isNaN(e)&&e!=="undefined"&&e!==""}function pe(...e){for(const t of e)if(t==null||isNaN(t)||t==="undefined")return!1;return!0}function p(e,t,n){return n>=e&&n<=t}function m(e){return e&&typeof e=="string"&&e.length>0}function qe(){const e=document.getElementById("leftAlign"),t=document.getElementById("middleAlign"),n=document.getElementById("rightAlign"),o=document.getElementById("justifyAlign"),c=document.getElementById("bani");tt(e,t,n,o,c),Je(e,t,n,o,c)}function Je(e,t,n,o,c){e.addEventListener("change",i=>{F("start",i.target.checked,c)}),t.addEventListener("change",i=>{F("center",i.target.checked,c)}),n.addEventListener("change",i=>{F("end",i.target.checked,c)}),o.addEventListener("change",i=>{F("justify",i.target.checked,c)})}function F(e,t,n){!t&&!m(e)||(n.style.textAlign=e,Qe(e))}function Qe(e){m(e)&&f(Le,e)}function et(e,t,n,o,c,i){switch(c){case"start":i.style.textAlign=c,e.checked=!0;break;case"end":i.style.textAlign=c,n.checked=!0;break;case"center":i.style.textAlign=c,t.checked=!0;break;case"justify":i.style.textAlign=c,o.checked=!0;break}}function tt(e,t,n,o,c){const i=a(Le);m(i)&&et(e,t,n,o,i,c)}function nt(){const e=document.getElementById("background-color");it(e),ot(e),ct(e)}function ot(e){e.addEventListener("change",t=>{ye(t.target.value),f(x,t.target.value)})}function ye(e){document.documentElement.style.setProperty("--background-color",e)}function Se(e,t){e.value=t}function it(e){let t=a(x);m(t)&&Se(e,t)}const ae="#ffffff";function ct(e){document.getElementById("background-reset-icon").addEventListener("click",()=>{document.documentElement.style.setProperty("--background-color",ae),R(x),Se(e,ae)})}function rt(){let e=a(x);m(e)&&ye(e)}function st(){const e=document.getElementById("dark-mode");lt(e),at(e)}function at(e){e.addEventListener("change",t=>{t.target.checked?(Y("true"),f(N,"true")):(Y("false"),f(N,"false"))})}function Y(e){e==="true"?H(!0):e==="false"&&H(!1)}function K(e,t){t==="true"?e.checked=!0:t==="false"&&(e.checked=!1)}function lt(e){let t=a(N);m(t)||(t="false"),K(e,t)}function ut(){let e=a(N);m(e)||(e="false"),Y(e)}const dt="#121212",ft="#E0E0E0",gt="#ffffff",ht="#000000";function H(e){if(e){document.documentElement.style.setProperty("--font-color",ft),document.documentElement.style.setProperty("--background-color",dt);return}document.documentElement.style.setProperty("--font-color",ht),document.documentElement.style.setProperty("--background-color",gt)}const mt=window.matchMedia("(prefers-color-scheme: dark)");mt.addEventListener("change",e=>{const t=document.getElementById("dark-mode");e.matches?(H(!0),K(t,"true")):(H(!1),K(t,"false"))});function Lt(e){const t=document.getElementById("english");pt(e,t),Et(e,t)}function Et(e,t){t.addEventListener("change",n=>{n.target.checked?(Z(e,"true"),f(V,"true")):(Z(e,"false"),f(V,"false")),k()})}function Z(e,t){t==="true"?e.classList.remove("hide-shabad-en"):t==="false"&&e.classList.add("hide-shabad-en")}function It(e,t){t==="true"?e.checked=!0:t==="false"&&(e.checked=!1)}function pt(e,t){let n=a(V);m(n)||(n="false"),Z(e,n),It(t,n)}function yt(){const e=document.getElementById("font-color");Bt(e),St(e),bt(e)}function St(e){e.addEventListener("change",t=>{Be(t.target.value),f(z,t.target.value)})}function Be(e){document.documentElement.style.setProperty("--font-color",e)}function be(e,t){e.value=t}function Bt(e){let t=a(z);m(t)&&be(e,t)}const le="#000000";function bt(e){document.getElementById("font-reset-icon").addEventListener("click",()=>{document.documentElement.style.setProperty("--font-color",le),R(z),be(e,le)})}function kt(){let e=a(z);m(e)&&Be(e)}function y(e,t){e.value=Number.parseFloat(t).toFixed(2)}let ke;function Ct(e,t){ke=setInterval(()=>{e()},t)}function ue(e){clearInterval(ke),e()}function S(e,t,n,o){e.addEventListener("pointerdown",c=>{Ct(()=>{t()},o)}),e.addEventListener("pointerup",c=>{ue(()=>{n()})}),e.addEventListener("pointerleave",c=>{ue(()=>{n()})})}const Ce=1,ve=200,we=1,Fe=.04;function vt(){const e=document.getElementById("font-input"),t=document.getElementById("bani");Ft(e,t),At(e,t),wt(e,t)}function wt(e,t){e.addEventListener("change",n=>{h(n.target.value)&&p(Ce,ve,n.target.value)&&(t.style.fontSize=n.target.value+"px",te(t))})}function Ft(e,t){const n=document.getElementById("font-increase");S(n,()=>{Ae(Fe,t,e)},()=>{te(t)},we)}function At(e,t){const n=document.getElementById("font-decrease");S(n,()=>{Ae(-Fe,t,e)},()=>{te(t)},we)}function Nt(){const e=document.getElementById("bani"),t=window.getComputedStyle(e).getPropertyValue("font-size"),n=Number.parseFloat(t.substring(0,t.length-2)),o=document.getElementById("font-input");y(o,n)}function Ae(e,t,n){const o=window.getComputedStyle(t).getPropertyValue("font-size");let i=Number.parseFloat(o.substring(0,o.length-2))+e;p(Ce,ve,i)&&(y(n,i),t.style.fontSize=i+"px")}function Ht(e){const t=a(me);if(h(t)){e.style.fontSize=t+"px";return}}function te(e){const t=window.getComputedStyle(e).getPropertyValue("font-size"),n=Number.parseFloat(t.substring(0,t.length-2));if(h(n)){f(me,n);return}}const q=1,Ne=10,He=10,Re=.01;let u=null;function Rt(){const e=document.getElementById("line-height-input"),t=document.getElementById("bani");Tt(e,t),zt(e,t),_t(e,t)}function _t(e,t){e.addEventListener("change",n=>{const o=n.target.value;h(o)&&p(q,Ne,o)?(t.style.lineHeight=o,u=Number.parseFloat(o),ne(u)):(u=null,t.style.lineHeight="normal",R(_))})}function Tt(e,t){const n=document.getElementById("line-height-increase");S(n,()=>{_e(Re,t,e)},()=>{ne(u)},He)}function zt(e,t){const n=document.getElementById("line-height-decrease");S(n,()=>{_e(-Re,t,e)},()=>{ne(u)},He)}function _e(e,t,n){let o;u?o=u+e:o=q+e,p(q,Ne,o)&&(u=o,y(n,u),t.style.lineHeight=u)}function xt(){const e=a(_);if(!h(e)){u=null;return}const t=document.getElementById("line-height-input");u=Number.parseFloat(e),y(t,e)}function Pt(e){const t=a(_);if(h(t)){u=Number.parseFloat(t),e.style.lineHeight=u;return}u=null}function ne(e){if(h(e)){f(_,e);return}}function Dt(e){const t=document.getElementById("punjabi");Wt(e,t),Mt(e,t)}function Mt(e,t){t.addEventListener("change",n=>{n.target.checked?(J(e,"true"),f(U,"true")):(J(e,"false"),f(U,"false")),k()})}function J(e,t){t==="true"?e.classList.remove("hide-shabad-pu"):t==="false"&&e.classList.add("hide-shabad-pu")}function Ot(e,t){t==="true"?e.checked=!0:t==="false"&&(e.checked=!1)}function Wt(e,t){let n=a(U);m(n)||(n="false"),J(e,n),Ot(t,n)}const Q=1,Te=20,ze=10,xe=.01;let d=null;function $t(){const e=document.getElementById("word-spacing-input"),t=document.getElementById("bani");Gt(e,t),Xt(e,t),jt(e,t)}function jt(e,t){e.addEventListener("change",n=>{let o=n.target.value;o&&(o=Number.parseFloat(o)),h(o)&&p(Q,Te,o)?(t.style.wordSpacing=o+"px",d=Number.parseFloat(o),oe(d)):(d=null,t.style.wordSpacing="normal",R(T))})}function Gt(e,t){const n=document.getElementById("word-spacing-increase");S(n,()=>{Pe(xe,t,e)},()=>{oe(d)},ze)}function Xt(e,t){const n=document.getElementById("word-spacing-decrease");S(n,()=>{Pe(-xe,t,e)},()=>{oe(d)},ze)}function Pe(e,t,n){let o;d?o=d+e:o=Q+e,p(Q,Te,o)&&(d=o,y(n,d),t.style.wordSpacing=d+"px")}function Ut(){const e=a(T);if(!h(e)){d=null;return}const t=document.getElementById("word-spacing-input");d=Number.parseFloat(e),y(t,e)}function Vt(e){const t=a(T);if(h(t)){d=Number.parseFloat(t),e.style.wordSpacing=d+"px";return}d=null}function oe(e){if(h(e)){f(T,e);return}}let A=!1;function Yt(e,t){fetch("components/menu/menu.html").then(n=>{n.text().then(o=>{e.innerHTML=o,Kt(t)})}).catch(n=>{console.log(n)})}let I;function Kt(e){I||(I=document.getElementById("menu")),tn(e)}function Zt(){I||(I=document.getElementById("menu")),A?I.classList.add("menuClose"):I.classList.remove("menuClose"),A=!A}function qt(){document.getElementById("reset-icon").addEventListener("click",()=>{Ke(),location.reload()})}function Jt(){document.getElementById("restart-icon").addEventListener("click",()=>{k(1)})}function Qt(e){vt(),Rt(),$t(),qe(),Dt(e),Lt(e),st(),yt(),nt()}function en(e){Nt(),xt(),Ut(),je(e)}function tn(e){qt(),Jt(),Qt(e),en(e)}let j=window.innerWidth,G=window.innerHeight;function nn(e,t){fetch("components/floating-button/floating-button.html").then(n=>n.text()).then(n=>{e.innerHTML=n;const o=document.getElementById("menu-container");o&&Yt(o,t),rn(t)}).catch(console.error)}function on(e){let t=a(ge),n=a(he);if(pe(t,n)){t=Number.parseFloat(t),n=Number.parseFloat(n);const o=e.offsetWidth;e.offsetHeight,ie(e,t,n,o)}}let De=0,Me=0;function cn(e,t){pe(e,t)&&(f(ge,e),f(he,t))}function rn(e){const t=document.getElementById("floating-button");on(t);let n=!1,o=!1,c=!1,i=!1,g=!1,P=!1,D,M,ce,re;function C(s,E){return s.closest(`#${E}`)!==null}t.addEventListener("pointerdown",s=>{i=C(s.target,"left-icon"),g=C(s.target,"right-icon"),c=C(s.target,"menu-icon"),P=C(s.target,"fullscreen-icon"),o=!0,n=!0,t.classList.remove("inactive"),D=s.clientX,M=s.clientY,ce=t.offsetLeft,re=t.offsetTop,t.setPointerCapture(s.pointerId)}),t.addEventListener("pointermove",s=>{if(n){const E=s.clientX-D,B=s.clientY-M;if(Math.abs(E)>v||Math.abs(B)>v){const O=t.offsetWidth;t.offsetHeight;let W=ce+E,Oe=re+B;ie(t,W,Oe,O),c=!1,i=!1,g=!1,P=!1,o=!1}}});const v=15;t.addEventListener("pointerup",s=>{const E=s.clientX,B=s.clientY,se=Math.abs(E-D),O=Math.abs(B-M),W=se<=v&&O<=v;o&&W?(c&&Zt(),i&&Ee(e),g&&Ie(e),P&&fe()):n&&cn(De,Me),n=!1,A||t.classList.add("inactive"),t.releasePointerCapture(s.pointerId)}),Ze()}function ie(e,t,n,o,c){j=window.innerWidth,G=window.innerHeight;const i=o/2,g=10;t-i-g<0&&(t=i+g),t+i+g>j&&(t=j-i-g),n-i-g<0&&(n=i+g),n+i+g>G&&(n=G-i-g),De=t,Me=n,e.style.left=`${t}px`,e.style.top=`${n}px`,e.style.bottom="auto",e.style.right="auto"}function ee(){const e=document.getElementById("floating-button");if(!e)return;const t=e.offsetLeft,n=e.offsetTop,o=e.offsetWidth;e.offsetHeight,ie(e,t,n,o)}function sn(e){an(e)}function an(e){document.addEventListener("keydown",t=>{t.key==="ArrowLeft"||t.key==="A"||t.key==="a"?Ee(e):t.key==="ArrowRight"||t.key==="D"||t.key==="d"?Ie(e):(t.key==="F"||t.key==="f")&&fe()})}function ln(e){document.readyState==="complete"||document.readyState==="interactive"?e():document.addEventListener?document.addEventListener("DOMContentLoaded",e):document.attachEvent&&document.attachEvent("onreadystatechange",function(){document.readyState==="complete"&&e()})}function un(){const e=document.getElementById("bani");if(!e)return;const t=document.getElementById("floating-button-container");t!=null&&nn(t,e);function n(){Ht(e),Pt(e),Vt(e)}n(),sn(e)}ln(un);rt();ut();kt(); diff --git a/package.json b/package.json index 4065129..e44b29b 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "dev": "vite", + "build": "vite build", "start": "live-server --port=8090 --no-browser", "check-format": "prettier . --check", "format": "prettier . --write" diff --git a/scripts/bani.js b/scripts/bani.js index 1f6b6b7..5059c35 100644 --- a/scripts/bani.js +++ b/scripts/bani.js @@ -51,6 +51,6 @@ onDomReady(initializeBaniApp); // Functions which load immediatly after js starts +setBackgroundColorFromLocalGlobal(); setDarkModeCheckFromLocalGlobal(); setFontColorFromLocalGlobal(); -setBackgroundColorFromLocalGlobal(); \ No newline at end of file