@bilions/search-js
Version:
Instance search UI component
2 lines • 22.9 kB
JavaScript
/* Search JS | Version : 0.5.5 | Date : Sat, 08 Apr 2023 12:31:24 GMT */
(()=>{"use strict";var e={155:(e,t,o)=>{o.d(t,{Z:()=>i});var n=o(81),r=o.n(n),a=o(645),s=o.n(a)()(r());s.push([e.id,"#search-js.github-dark.container .modal{border:1px solid #30363d}#search-js.github-dark.container .modal .modal-header{padding:0px;border-bottom:1px solid #30363d}#search-js.github-dark.container .modal .modal-header .search-container .search-icon{width:50px}#search-js.github-dark.container .modal .modal-header .search-container .search-icon svg{fill:var(--search-js-input-placeholder-color)}#search-js.github-dark.container .modal .modal-content .items .item:hover{background:#161b22}#search-js.github-dark.container .modal .modal-footer .keyboard-button{border:1px solid #30363d;border-radius:4px;padding:0px 2px}#search-js.github-light.container .modal{border:1px solid #d0d7de}#search-js.github-light.container .modal .modal-header{padding:0px;border-bottom:1px solid #d0d7de}#search-js.github-light.container .modal .modal-header .search-container .search-icon{width:50px}#search-js.github-light.container .modal .modal-header .search-container .search-icon svg{fill:var(--search-js-input-placeholder-color)}#search-js.github-light.container .modal .modal-content .items .item:hover{background:#f6f8fa}#search-js.github-light.container .modal .modal-content .items .item:hover svg path{stroke:var(--search-js-text-color) !important}#search-js.github-light.container .modal .modal-content .items .item:hover .item-title{color:var(--search-js-text-color)}#search-js.github-light.container .modal .modal-content .items .item:hover .item-description{color:var(--search-js-text-color)}#search-js.github-light.container .modal .modal-footer .keyboard-button{border:1px solid #d0d7de;border-radius:4px;padding:0px 2px}\n",""]);const i=s},948:(e,t,o)=>{o.d(t,{Z:()=>i});var n=o(81),r=o.n(n),a=o(645),s=o.n(a)()(r());s.push([e.id,"#search-js.container{display:none;position:fixed;left:0;right:0;top:0;bottom:0;width:100%;background:var(--search-js-backdrop-bg);justify-content:center;align-items:flex-start;padding-top:var(--search-js-top)}#search-js.container .modal{width:var(--search-js-width);max-height:var(--search-js-height);display:flex;background:var(--search-js-modal-bg);border-radius:8px;flex-direction:column;box-shadow:var(--search-js-modal-box-shadow);animation-name:animatetop;animation-duration:0.8s}@keyframes spin{from{transform:rotate(360deg)}to{transform:rotate(0deg)}}@keyframes animatetop{from{top:-300px;opacity:0}to{top:0;opacity:1}}#search-js.container .modal .modal-header{padding:10px 10px 0px 10px}#search-js.container .modal .modal-header .search-container{background:var(--search-js-search-input-bg);width:100%;height:50px;border-radius:6px;outline:none;box-shadow:none;border:0.11em solid var(--search-js-theme);-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;display:flex;align-items:center;justify-content:space-between}#search-js.container .modal .modal-header .search-container .search-icon{width:60px;height:40px;background:transparent;display:flex;align-items:center;justify-content:center}#search-js.container .modal .modal-header .search-container .clear-icon{width:60px;height:40px;background:transparent;display:flex;align-items:center;justify-content:center;cursor:pointer}#search-js.container .modal .modal-header .search-container .clear-icon svg path{fill:var(--search-js-input-placeholder-color)}#search-js.container .modal .modal-header .search-container .search-input{width:100%;color:var(--search-js-text-color);height:40px;outline:none;font-family:var(--search-js-font-family);box-shadow:none;background:transparent;border:none;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;font-size:16px}#search-js.container .modal .modal-header .search-container ::-webkit-input-placeholder{color:var(--search-js-input-placeholder-color)}#search-js.container .modal .modal-header .search-container ::-moz-placeholder{color:var(--search-js-input-placeholder-color)}#search-js.container .modal .modal-header .search-container ::-ms-placeholder{color:var(--search-js-input-placeholder-color)}#search-js.container .modal .modal-header .search-container ::placeholder{color:var(--search-js-input-placeholder-color)}#search-js.container .modal #search-js-result{display:none}#search-js.container .modal #search-js-loading{display:none;align-items:center;justify-content:center;height:52px;padding:30px !important;color:var(--search-js-text-color);font-size:14px}#search-js.container .modal #search-js-loading svg{animation-name:spin;animation-duration:2000ms;animation-iteration-count:infinite;animation-timing-function:linear}#search-js.container .modal .modal-content{padding:10px;padding-top:10px;flex:1;overflow:scroll}#search-js.container .modal .modal-content .not-found-label{color:var(--search-js-text-color);font-size:14px;display:flex;align-items:center;justify-content:center;height:52px}#search-js.container .modal .modal-content .items{display:flex;flex-direction:column}#search-js.container .modal .modal-content .items .item{display:flex;cursor:pointer;flex-direction:row;background:var(--search-js-item-bg);padding:10px;margin-bottom:5px;border-radius:5px;align-items:center;box-shadow:var(--search-js-item-box-shadow)}#search-js.container .modal .modal-content .items .item .item-icon{margin-right:8px}#search-js.container .modal .modal-content .items .item .item-title{color:var(--search-js-text-color);font-size:15px;margin-bottom:4px}#search-js.container .modal .modal-content .items .item .item-description{font-size:13px;color:var(--search-js-text-color)}#search-js.container .modal .modal-content .items .item:hover{background:var(--search-js-theme);color:white}#search-js.container .modal .modal-content .items .item:hover svg path{stroke:white !important}#search-js.container .modal .modal-content .items .item:hover .item-title{color:white}#search-js.container .modal .modal-content .items .item:hover .item-description{font-size:13px;color:white}#search-js.container .modal .modal-footer{box-shadow:var(--search-js-modal-footer-box-shadow);max-height:40px;display:flex;flex-direction:row;align-items:center;padding:10px;color:var(--search-js-text-color);font-weight:300;font-size:13px}#search-js.container .modal .modal-footer .keyboard-button{align-items:center;background:var(--search-js-keyboard-button-bg);border:0;border-radius:2px;box-shadow:var(--search-js-keyboard-button-box-shadow);color:var(--search-js-text-color);display:flex;height:18px;justify-content:center;margin-right:0.6em;padding:0 0 1px;font-size:10px;width:20px;font-weight:bold}\n",""]);const i=s},645:e=>{e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var o="",n=void 0!==t[5];return t[4]&&(o+="@supports (".concat(t[4],") {")),t[2]&&(o+="@media ".concat(t[2]," {")),n&&(o+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),o+=e(t),n&&(o+="}"),t[2]&&(o+="}"),t[4]&&(o+="}"),o})).join("")},t.i=function(e,o,n,r,a){"string"==typeof e&&(e=[[null,e,void 0]]);var s={};if(n)for(var i=0;i<this.length;i++){var c=this[i][0];null!=c&&(s[c]=!0)}for(var d=0;d<e.length;d++){var h=[].concat(e[d]);n&&s[h[0]]||(void 0!==a&&(void 0===h[5]||(h[1]="@layer".concat(h[5].length>0?" ".concat(h[5]):""," {").concat(h[1],"}")),h[5]=a),o&&(h[2]?(h[1]="@media ".concat(h[2]," {").concat(h[1],"}"),h[2]=o):h[2]=o),r&&(h[4]?(h[1]="@supports (".concat(h[4],") {").concat(h[1],"}"),h[4]=r):h[4]="".concat(r)),t.push(h))}},t}},81:e=>{e.exports=function(e){return e[1]}},379:e=>{var t=[];function o(e){for(var o=-1,n=0;n<t.length;n++)if(t[n].identifier===e){o=n;break}return o}function n(e,n){for(var a={},s=[],i=0;i<e.length;i++){var c=e[i],d=n.base?c[0]+n.base:c[0],h=a[d]||0,l="".concat(d," ").concat(h);a[d]=h+1;var p=o(l),m={css:c[1],media:c[2],sourceMap:c[3],supports:c[4],layer:c[5]};if(-1!==p)t[p].references++,t[p].updater(m);else{var u=r(m,n);n.byIndex=i,t.splice(i,0,{identifier:l,updater:u,references:1})}s.push(l)}return s}function r(e,t){var o=t.domAPI(t);o.update(e);return function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap&&t.supports===e.supports&&t.layer===e.layer)return;o.update(e=t)}else o.remove()}}e.exports=function(e,r){var a=n(e=e||[],r=r||{});return function(e){e=e||[];for(var s=0;s<a.length;s++){var i=o(a[s]);t[i].references--}for(var c=n(e,r),d=0;d<a.length;d++){var h=o(a[d]);0===t[h].references&&(t[h].updater(),t.splice(h,1))}a=c}}},569:e=>{var t={};e.exports=function(e,o){var n=function(e){if(void 0===t[e]){var o=document.querySelector(e);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(e){o=null}t[e]=o}return t[e]}(e);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");n.appendChild(o)}},216:e=>{e.exports=function(e){var t=document.createElement("style");return e.setAttributes(t,e.attributes),e.insert(t,e.options),t}},565:(e,t,o)=>{e.exports=function(e){var t=o.nc;t&&e.setAttribute("nonce",t)}},795:e=>{e.exports=function(e){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var t=e.insertStyleElement(e);return{update:function(o){!function(e,t,o){var n="";o.supports&&(n+="@supports (".concat(o.supports,") {")),o.media&&(n+="@media ".concat(o.media," {"));var r=void 0!==o.layer;r&&(n+="@layer".concat(o.layer.length>0?" ".concat(o.layer):""," {")),n+=o.css,r&&(n+="}"),o.media&&(n+="}"),o.supports&&(n+="}");var a=o.sourceMap;a&&"undefined"!=typeof btoa&&(n+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(a))))," */")),t.styleTagTransform(n,e,t.options)}(t,e,o)},remove:function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(t)}}}},589:e=>{e.exports=function(e,t){if(t.styleSheet)t.styleSheet.cssText=e;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(e))}}}},t={};function o(n){var r=t[n];if(void 0!==r)return r.exports;var a=t[n]={id:n,exports:{}};return e[n](a,a.exports,o),a.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.nc=void 0,(()=>{var e=o(379),t=o.n(e),n=o(795),r=o.n(n),a=o(569),s=o.n(a),i=o(565),c=o.n(i),d=o(216),h=o.n(d),l=o(589),p=o.n(l),m=o(948),u={};u.styleTagTransform=p(),u.setAttributes=c(),u.insert=s().bind(null,"head"),u.domAPI=r(),u.insertStyleElement=h();t()(m.Z,u);m.Z&&m.Z.locals&&m.Z.locals;var g=o(155),f={};f.styleTagTransform=p(),f.setAttributes=c(),f.insert=s().bind(null,"head"),f.domAPI=r(),f.insertStyleElement=h();t()(g.Z,f);g.Z&&g.Z.locals&&g.Z.locals;const v="#FF2E1F",b="search-js",x="search-js-histories",y="search-js-result",w="search-js-loading",j="container",k="clear-icon",C="search-input",L="item",$="item-close",E="modal-content",T="data-payload";class S{static encode(e){return window.btoa(escape(JSON.stringify(e)))}static decode(e){return JSON.parse(unescape(window.atob(e)))}}class I{constructor(){this.EVENT_CLICK="click",this.EVENT_KEYUP="keyup"}onBackDropClick(e){const t=document.querySelector(`#${b}.${j}`);t.addEventListener(this.EVENT_CLICK,(o=>{o.target===t&&e()}))}onSearch(e){const t=document.querySelector(`#${b} .${C}`);t.addEventListener(this.EVENT_KEYUP,(t=>{const o=t.target.value.toLowerCase();e(o)})),document.querySelector(`.${k}`).addEventListener(this.EVENT_CLICK,(()=>{t.value="",e(null)}))}onItemClick(e,t){document.querySelectorAll(`#${b} .${L}`).forEach((t=>t.addEventListener(this.EVENT_CLICK,(t=>{const o=t.target.closest(`.${$} *`);if(t.target==o)return;const n=t.target.closest(`.${L}`).getAttribute(T);e(S.decode(n))}))));document.querySelectorAll(`#${b} .${$}`).forEach((e=>e.addEventListener(this.EVENT_CLICK,(e=>{const o=e.target.closest(`.${$}`).getAttribute(T);t(S.decode(o))}))))}}const M=(e="#969faf")=>`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M10 3L8 21" stroke="${e}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M16 3L14 21" stroke="${e}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M3.5 9H21.5" stroke="${e}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M2.5 15H20.5" stroke="${e}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n</svg>`,N=(e="#969faf")=>`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M22 12C22 17.52 17.52 22 12 22C6.48 22 2 17.52 2 12C2 6.48 6.48 2 12 2C17.52 2 22 6.48 22 12Z" stroke="${e}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M15.71 15.18L12.61 13.33C12.07 13.01 11.63 12.24 11.63 11.61V7.51001" stroke="${e}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n</svg>`;class H{render(){return'<div class="keyboard-button">Esc</div> <span>to close</span>'}}class K{render(e){var t,o,n;let r=((e="#000000")=>`<svg fill="${e}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="25px"><path d="M 21 3 C 11.601563 3 4 10.601563 4 20 C 4 29.398438 11.601563 37 21 37 C 24.355469 37 27.460938 36.015625 30.09375 34.34375 L 42.375 46.625 L 46.625 42.375 L 34.5 30.28125 C 36.679688 27.421875 38 23.878906 38 20 C 38 10.601563 30.398438 3 21 3 Z M 21 7 C 28.199219 7 34 12.800781 34 20 C 34 27.199219 28.199219 33 21 33 C 13.800781 33 8 27.199219 8 20 C 8 12.800781 13.800781 7 21 7 Z"/></svg>`)(null!==(t=e.theme)&&void 0!==t?t:v),a="Search";return(null===(o=e.search)||void 0===o?void 0:o.icon)&&(r=e.search.icon),(null===(n=e.search)||void 0===n?void 0:n.placeholder)&&(a=e.search.placeholder),`<div class="search-container">\n<div class="search-icon">${r}</div>\n<input placeholder="${a}" class="${C}" type="text"/>\n<div class="${k}"><svg class="clear-svg" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M12 2C6.49 2 2 6.49 2 12C2 17.51 6.49 22 12 22C17.51 22 22 17.51 22 12C22 6.49 17.51 2 12 2ZM15.36 14.3C15.65 14.59 15.65 15.07 15.36 15.36C15.21 15.51 15.02 15.58 14.83 15.58C14.64 15.58 14.45 15.51 14.3 15.36L12 13.06L9.7 15.36C9.55 15.51 9.36 15.58 9.17 15.58C8.98 15.58 8.79 15.51 8.64 15.36C8.35 15.07 8.35 14.59 8.64 14.3L10.94 12L8.64 9.7C8.35 9.41 8.35 8.93 8.64 8.64C8.93 8.35 9.41 8.35 9.7 8.64L12 10.94L14.3 8.64C14.59 8.35 15.07 8.35 15.36 8.64C15.65 8.93 15.65 9.41 15.36 9.7L13.06 12L15.36 14.3Z" fill="#969faf"/>\n</svg></div>\n</div>`}}class O{renderList({id:e,items:t,hideRemoveButton:o,notFoundLabel:n,icon:r}){const a=document.getElementById(e);a.innerHTML="";let s='<div class="items">';0==t.length&&(s+=`<div class="not-found-label">${n}</div>`),t.forEach((e=>{s+=this.render({item:e,icon:r,hideRemoveButton:o})})),s+="</div>",a.innerHTML=s,a.style.display="block"}render({item:e,icon:t,hideRemoveButton:o=!1}){const n=S.encode(e);return`<div class="item" ${T}='${n}'>\n<div class="item-icon">${t}</div>\n<div style="flex: 1">\n<div class="item-title">${e.title}</div>\n${e.description?`<div class="item-description">${e.description}</div>`:""}\n</div>${this.getCloseIcon(o,n)}</div>`}getCloseIcon(e,t){return e?"":`<div class='${$}' ${T}='${t}'>${((e="#969faf")=>`<svg width="35" height="35" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M9.16998 14.83L14.83 9.17004" stroke="${e}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M14.83 14.83L9.16998 9.17004" stroke="${e}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n</svg>`)()}</div>`}}var B,z=function(e,t,o,n){return new(o||(o=Promise))((function(r,a){function s(e){try{c(n.next(e))}catch(e){a(e)}}function i(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,i)}c((n=n.apply(e,t||[])).next())}))};class V{constructor(e,t,o,n){this.app=e,this.domListener=t,this.searchHistory=o,this.theme=n,this.theme.createGlobalCssVariable(this.app.config),this.getParentElement().appendChild(this.createElement()),this.showHistory(this.searchHistory.getList()),this.domListener.onBackDropClick((()=>{this.app.close()})),this.handleOnSearch()}handleOnSearch(){this.domListener.onSearch((e=>z(this,void 0,void 0,(function*(){var t;if(!e)return clearTimeout(this.searchTimer),this.hideLoading(),this.showHistory(this.searchHistory.getList()),void this.hideSearchResult();this.hideHistories(),this.hideSearchResult(),this.app.config.onSearch?(this.showLoading(),clearTimeout(this.searchTimer),this.searchTimer=setTimeout((()=>z(this,void 0,void 0,(function*(){const t=yield this.app.config.onSearch(e);this.hideLoading(),this.showSearchResult(t)}))),null!==(t=this.app.config.onSearchDelay)&&void 0!==t?t:500)):this.showSearchResult(this.getItems(e))}))))}getItems(e){return this.app.config.data.filter((t=>t.title&&t.title.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e)))}getParentElement(){var e;return null!==(e=this.app.config.element)&&void 0!==e?e:document.body}createElement(){const e=document.createElement("div");e.id=b,this.theme.getReadyMadeThemes().includes(this.app.config.theme)&&e.classList.add(this.app.config.theme),e.classList.add(j);const t=new H,o=new K;return e.innerHTML=`<div class="modal"> \n<div class="modal-header">${o.render(this.app.config)}</div>\n<div id="${w}" class="${E}">${((e="#969faf")=>`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M14.55 21.67C18.84 20.54 22 16.64 22 12C22 6.48 17.56 2 12 2C5.33 2 2 7.56 2 7.56M2 7.56V3M2 7.56H4.01H6.44" stroke="${e}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M2 12C2 17.52 6.48 22 12 22" stroke="${e}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="3 3"/>\n</svg>\n `)()}</div>\n<div id="${x}" class="${E}"></div>\n<div id="${y}" class="${E}"></div>\n<div class="modal-footer">${t.render()}</div>\n</div>\n`,this.element=e,this.element}showSearchResult(e){(new O).renderList({id:y,items:e,hideRemoveButton:!0,notFoundLabel:"No match found",icon:M()}),this.handleItemClickListener()}hideSearchResult(){document.getElementById(y).style.display="none"}showHistory(e){(new O).renderList({id:x,items:e,hideRemoveButton:!1,notFoundLabel:"No recent data",icon:N()}),this.handleItemClickListener()}hideHistories(){document.getElementById(x).style.display="none"}handleItemClickListener(){this.domListener.onItemClick((e=>{this.searchHistory.add(e),this.app.config.onSelected(e)}),(e=>{this.searchHistory.remove(e),this.showHistory(this.searchHistory.getList())}))}showLoading(){document.getElementById(w).style.display="flex"}hideLoading(){document.getElementById(w).style.display="none"}}class R{constructor(){this.maxItems=4,this.storageKey="search-js-histories",this.db=window.localStorage}getList(){let e=this.db.getItem(this.storageKey);return e||(e="[]"),JSON.parse(e).reverse()}clear(){this.db.setItem(this.storageKey,"[]")}remove(e){let t=this.db.getItem(this.storageKey);t||(t="[]");const o=JSON.parse(t),n=o.findIndex((t=>JSON.stringify(t)==JSON.stringify(e)));-1!=n&&o.splice(n,1),this.db.setItem(this.storageKey,JSON.stringify(o))}add(e){let t=this.db.getItem(this.storageKey);t||(t="[]");const o=JSON.parse(t);o.length==this.maxItems&&o.pop();o.find((t=>JSON.stringify(t)==JSON.stringify(e)))||o.push(e),this.db.setItem(this.storageKey,JSON.stringify(o))}}!function(e){e.ThemeGithubLight="github-light",e.ThemeGithubDark="github-dark",e.ThemeLight="light-theme",e.ThemeDark="dark-theme"}(B||(B={}));const F="--search-js-backdrop-bg",Z="--search-js-modal-bg",D="--search-js-modal-box-shadow",J="--search-js-modal-footer-box-shadow",P="--search-js-keyboard-button-box-shadow",A="--search-js-keyboard-button-bg",_="--search-js-search-input-bg",G="--search-js-input-placeholder-color",q="--search-js-item-bg",U="--search-js-item-box-shadow",Y="--search-js-text-color",Q="--search-js-theme",W={[B.ThemeDark]:{[F]:"rgba(47, 55, 69, 0.7)",[Z]:"#1b1b1d",[D]:"inset 1px 1px 0 0 #2c2e40, 0 3px 8px 0 #000309",[J]:"inset 0 1px 0 0 rgba(73, 76, 106, 0.5), 0 -4px 8px 0 rgba(0, 0, 0, 0.2)",[P]:"inset 0 -2px 0 0 #282d55, inset 0 0 1px 1px #51577d, 0 2px 2px 0 rgba(3, 4, 9, 0.3)",[A]:"linear-gradient(-26.5deg, transparent 0%, transparent 100%)",[_]:"black",[G]:"#aeaeae",[q]:"#1c1e21",[U]:"none",[Y]:"#b3b3b3"},[B.ThemeLight]:{[F]:"rgba(101, 108, 133, 0.8)",[Z]:"#f5f6f7",[D]:"inset 1px 1px 0 0 hsla(0, 0%, 100%, 0.5), 0 3px 8px 0 #555a64",[J]:"0 -1px 0 0 #e0e3e8, 0 -3px 6px 0 rgba(69, 98, 155, 0.12)",[P]:"inset 0 -2px 0 0 #cdcde6, inset 0 0 1px 1px #fff, 0 1px 2px 1px rgba(30, 35, 90, 0.4)",[A]:"linear-gradient(-225deg, #d5dbe4, #f8f8f8)",[_]:"white",[G]:"#969faf",[q]:"white",[U]:"0 1px 3px 0 #d4d9e1",[Y]:"#969faf"},[B.ThemeGithubDark]:{[F]:"rgba(1,4,9,0.8)",[Z]:"#0D1116",[D]:"none",[J]:"none",[P]:"none",[A]:"none",[_]:"transparent",[G]:"#6D7681",[q]:"transparent",[U]:"none",[Y]:"#C5CED6",[Q]:"transparent"},[B.ThemeGithubLight]:{[F]:"rgba(27,31,36,0.5)",[Z]:"#FFFFFF",[D]:"none",[J]:"none",[P]:"none",[A]:"none",[_]:"transparent",[G]:"#6E7781",[q]:"transparent",[U]:"none",[Y]:"#1F2329",[Q]:"transparent"}};class X{createGlobalCssVariable(e){var t,o,n,r;const a=window.getComputedStyle(document.body),s=document.createElement("style"),i={"--search-js-width":null!==(t=e.width)&&void 0!==t?t:"400px","--search-js-height":null!==(o=e.height)&&void 0!==o?o:"450px",[Q]:null!==(n=e.theme)&&void 0!==n?n:v,"--search-js-font-family":a.getPropertyValue("font-family"),"--search-js-top":null!==(r=e.positionTop)&&void 0!==r?r:"85px"};s.innerHTML=`:root{${this.getCssVariables(i)} ${this.getTheme(e)}}`,document.head.appendChild(s)}getReadyMadeThemes(){return[B.ThemeGithubLight,B.ThemeGithubDark]}getTheme(e){const t=e.darkMode?B.ThemeDark:B.ThemeLight,o=this.getReadyMadeThemes().includes(e.theme)?e.theme:t;return this.getCssVariables(this.getThemeValues(o))}getThemeValues(e){return W[e]}getCssVariables(e){let t="";return Object.entries(e).forEach((([e,o])=>{t+=`${e} : ${o};`})),t}}class ee{constructor(e){this.config=e,this.component=new V(this,new I,new R,new X),this.listenKeyboardKeyPress()}static getInstance(e){return this._instance||(this._instance=new this(e))}open(){this.component.element.style.display="flex",this.focusOnSearch()}close(){this.component.element.style.display="none"}focusOnSearch(){document.querySelector("#search-js .search-input").focus()}listenKeyboardKeyPress(){const e=()=>this.open(),t=()=>this.close();window.onkeydown=function(o){(o.ctrlKey&&"k"===o.key||o.metaKey&&"k"===o.key)&&e(),"Escape"!==o.key&&"Esc"!==o.key||t()}}}const te=e=>ee.getInstance(e);window.SearchJS=te})()})();