electron-findbar
Version:
Chrome-like findbar for your Electron app.
1 lines • 2.78 kB
JavaScript
(()=>{"use strict";var e={213(e,n,t){var o=this&&this.__awaiter||function(e,n,t,o){return new(t||(t=Promise))(function(c,a){function s(e){try{r(o.next(e))}catch(e){a(e)}}function i(e){try{r(o.throw(e))}catch(e){a(e)}}function r(e){var n;e.done?c(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(s,i)}r((o=o.apply(e,n||[])).next())})};const c=(a=t(288).ipcRenderer,{getLastState:()=>o(void 0,void 0,void 0,function*(){return a.invoke("electron-findbar/last-state")}),inputChange:e=>{a.send("electron-findbar/input-change",e,!0)},matchCase:e=>{a.send("electron-findbar/match-case",e,!0)},previous:()=>{a.send("electron-findbar/previous")},next:()=>{a.send("electron-findbar/next")},close:()=>{a.send("electron-findbar/close")},onMatchesChange:e=>{a.on("electron-findbar/matches",e)},onInputFocus:e=>{a.on("electron-findbar/input-focus",e)},onTextChange:e=>{a.on("electron-findbar/text-change",e)},onMatchCaseChange:e=>{a.on("electron-findbar/match-case-change",e)},onForceTheme:e=>{a.on("electron-findbar/force-theme",e)}});var a;let s=!0,i=!1;function r(e){const n=e.target;s=!1,c.inputChange(n.value)}function d(e){s&&i&&(s=!1,e?c.next():c.previous())}function l(e,n){e.classList[n?"remove":"add"]("disabled")}function u(e){document.body.classList.remove("light","dark"),"system"!==e&&document.body.classList.add(e)}document.addEventListener("DOMContentLoaded",()=>o(void 0,void 0,void 0,function*(){const e=document.getElementById("input"),n=document.getElementById("match-case"),t=document.getElementById("previous"),o=document.getElementById("next"),a=document.getElementById("close"),v=document.getElementById("matches"),f=[t,o].filter(e=>null!==e);if(!(e&&n&&t&&o&&a&&v))return void console.error("Required elements not found in the DOM");n.addEventListener("click",()=>function(e){const n=function(e){return e.classList.contains("disabled")}(e);l(e,n),c.matchCase(n)}(n)),t.addEventListener("click",()=>d(!1)),o.addEventListener("click",()=>d(!0)),a.addEventListener("click",()=>c.close()),e.addEventListener("input",r),c.onTextChange((n,t)=>{e.value=t}),c.onInputFocus(()=>{e.setSelectionRange(0,e.value.length),e.focus()}),c.onMatchCaseChange((e,t)=>l(n,t)),c.onMatchesChange((n,t)=>{s=!0,v.innerText=e.value?t.active+"/"+t.total:"";for(const e of f)l(e,i=t.total>1)}),c.onForceTheme((e,n)=>{u(n)});const h=yield c.getLastState();e.value=h.text||"",h.movable||document.body.classList.remove("movable"),"linux"===process.platform&&document.body.classList.add("linux"),u(h.theme),l(n,h.matchCase),c.inputChange(e.value),e.setSelectionRange(0,e.value.length),e.focus()}))},288(e){e.exports=require("electron")}},n={};!function t(o){var c=n[o];if(void 0!==c)return c.exports;var a=n[o]={exports:{}};return e[o].call(a.exports,a,a.exports,t),a.exports}(213)})();