Added support for search within the template as suggested in #581. I decided to go with a client side search based on [Ninja keys](https://github.com/ssleptsov/ninja-keys), but using [deepdub's fork](https://github.com/deepdub-ai/ninja-keys) as basis since it supports fuzzy search. Had to do a bunch of changes to their code to make it work without using node to install everything. Also changed to use some colors defined in our side and using both pages' titles and descriptions for search. Also had to increase the template max width to better accomodate the new item in navigation bar. Missing implementations: - [ ] One thing I'd love to do (but currently have no idea how) would be to change the text next to the search button depending on the platform. For example, if the user is accessing the site on a mac they should use ⌘k instead of ctrl k. - [x] Test how this looks like (and how it is supposed to work) on devices with smaller screens - [x] Support for offline mode Some screenshots: --- ## Dark version    --- ## Light version    --------- Signed-off-by: George Araujo <george.gcac@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
18 lines
7.8 KiB
JavaScript
18 lines
7.8 KiB
JavaScript
/**
|
|
* Bundled by jsDelivr using Rollup v2.79.1 and Terser v5.19.2.
|
|
* Original file: /npm/hotkeys-js@3.13.7/dist/hotkeys.esm.js
|
|
*
|
|
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
|
*/
|
|
/**!
|
|
* hotkeys-js v3.13.7
|
|
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
|
|
*
|
|
* Copyright (c) 2024 kenny wong <wowohoo@qq.com>
|
|
* https://github.com/jaywcjlove/hotkeys-js.git
|
|
*
|
|
* @website: https://jaywcjlove.github.io/hotkeys-js
|
|
|
|
* Licensed under the MIT license
|
|
*/
|
|
const e="undefined"!=typeof navigator&&navigator.userAgent.toLowerCase().indexOf("firefox")>0;function t(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent("on".concat(t),n)}function n(e,t,n,o){e.removeEventListener?e.removeEventListener(t,n,o):e.detachEvent&&e.detachEvent("on".concat(t),n)}function o(e,t){const n=t.slice(0,t.length-1);for(let t=0;t<n.length;t++)n[t]=e[n[t].toLowerCase()];return n}function r(e){"string"!=typeof e&&(e="");const t=(e=e.replace(/\s/g,"")).split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}const i={backspace:8,"⌫":8,tab:9,clear:12,enter:13,"↩":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"⇪":20,",":188,".":190,"/":191,"`":192,"-":e?173:189,"=":e?61:187,";":e?59:186,"'":222,"[":219,"]":221,"\\":220},c={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},s={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},l={16:!1,18:!1,17:!1,91:!1},f={};for(let e=1;e<20;e++)i["f".concat(e)]=111+e;let a=[],u=null,p="all";const d=new Map,y=e=>i[e.toLowerCase()]||c[e.toLowerCase()]||e.toUpperCase().charCodeAt(0);function h(e){p=e||"all"}function m(){return p||"all"}function k(e){if(void 0===e)Object.keys(f).forEach((e=>{Array.isArray(f[e])&&f[e].forEach((e=>g(e))),delete f[e]})),v(null);else if(Array.isArray(e))e.forEach((e=>{e.key&&g(e)}));else if("object"==typeof e)e.key&&g(e);else if("string"==typeof e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];let[r,i]=n;"function"==typeof r&&(i=r,r=""),g({key:e,scope:r,method:i,splitKey:"+"})}}const g=e=>{let{key:t,scope:n,method:i,splitKey:s="+"}=e;r(t).forEach((e=>{const t=e.split(s),r=t.length,l=t[r-1],a="*"===l?"*":y(l);if(!f[a])return;n||(n=m());const u=r>1?o(c,t):[],p=[];f[a]=f[a].filter((e=>{const t=(!i||e.method===i)&&e.scope===n&&function(e,t){const n=e.length>=t.length?e:t,o=e.length>=t.length?t:e;let r=!0;for(let e=0;e<n.length;e++)-1===o.indexOf(n[e])&&(r=!1);return r}(e.mods,u);return t&&p.push(e.element),!t})),p.forEach((e=>v(e)))}))};function w(e,t,n,o){if(t.element!==o)return;let r;if(t.scope===n||"all"===t.scope){r=t.mods.length>0;for(const e in l)Object.prototype.hasOwnProperty.call(l,e)&&(!l[e]&&t.mods.indexOf(+e)>-1||l[e]&&-1===t.mods.indexOf(+e))&&(r=!1);(0!==t.mods.length||l[16]||l[18]||l[17]||l[91])&&!r&&"*"!==t.shortcut||(t.keys=[],t.keys=t.keys.concat(a),!1===t.method(e,t)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function O(e,t){const n=f["*"];let o=e.keyCode||e.which||e.charCode;if(!b.filter.call(this,e))return;if(93!==o&&224!==o||(o=91),-1===a.indexOf(o)&&229!==o&&a.push(o),["ctrlKey","altKey","shiftKey","metaKey"].forEach((t=>{const n=s[t];e[t]&&-1===a.indexOf(n)?a.push(n):!e[t]&&a.indexOf(n)>-1?a.splice(a.indexOf(n),1):"metaKey"===t&&e[t]&&3===a.length&&(e.ctrlKey||e.shiftKey||e.altKey||(a=a.slice(a.indexOf(n))))})),o in l){l[o]=!0;for(const e in c)c[e]===o&&(b[e]=!0);if(!n)return}for(const t in l)Object.prototype.hasOwnProperty.call(l,t)&&(l[t]=e[s[t]]);e.getModifierState&&(!e.altKey||e.ctrlKey)&&e.getModifierState("AltGraph")&&(-1===a.indexOf(17)&&a.push(17),-1===a.indexOf(18)&&a.push(18),l[17]=!0,l[18]=!0);const r=m();if(n)for(let o=0;o<n.length;o++)n[o].scope===r&&("keydown"===e.type&&n[o].keydown||"keyup"===e.type&&n[o].keyup)&&w(e,n[o],r,t);if(!(o in f))return;const i=f[o],u=i.length;for(let n=0;n<u;n++)if(("keydown"===e.type&&i[n].keydown||"keyup"===e.type&&i[n].keyup)&&i[n].key){const o=i[n],{splitKey:c}=o,s=o.key.split(c),l=[];for(let e=0;e<s.length;e++)l.push(y(s[e]));l.sort().join("")===a.sort().join("")&&w(e,o,r,t)}}function b(e,n,i){a=[];const s=r(e);let p=[],h="all",m=document,g=0,w=!1,v=!0,E="+",K=!1,x=!1;for(void 0===i&&"function"==typeof n&&(i=n),"[object Object]"===Object.prototype.toString.call(n)&&(n.scope&&(h=n.scope),n.element&&(m=n.element),n.keyup&&(w=n.keyup),void 0!==n.keydown&&(v=n.keydown),void 0!==n.capture&&(K=n.capture),"string"==typeof n.splitKey&&(E=n.splitKey),!0===n.single&&(x=!0)),"string"==typeof n&&(h=n),x&&k(e,h);g<s.length;g++)p=[],(e=s[g].split(E)).length>1&&(p=o(c,e)),(e="*"===(e=e[e.length-1])?"*":y(e))in f||(f[e]=[]),f[e].push({keyup:w,keydown:v,scope:h,mods:p,shortcut:s[g],method:i,key:s[g],splitKey:E,element:m});if(void 0!==m&&window){if(!d.has(m)){const e=function(){return O(arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.event,m)},n=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.event;O(e,m),function(e){let t=e.keyCode||e.which||e.charCode;const n=a.indexOf(t);if(n>=0&&a.splice(n,1),e.key&&"meta"===e.key.toLowerCase()&&a.splice(0,a.length),93!==t&&224!==t||(t=91),t in l){l[t]=!1;for(const e in c)c[e]===t&&(b[e]=!1)}}(e)};d.set(m,{keydownListener:e,keyupListenr:n,capture:K}),t(m,"keydown",e,K),t(m,"keyup",n,K)}if(!u){const e=()=>{a=[]};u={listener:e,capture:K},t(window,"focus",e,K)}}}function v(e){const t=Object.values(f).flat();if(t.findIndex((t=>{let{element:n}=t;return n===e}))<0){const{keydownListener:t,keyupListenr:o,capture:r}=d.get(e)||{};t&&o&&(n(e,"keyup",o,r),n(e,"keydown",t,r),d.delete(e))}if(t.length<=0||d.size<=0){if(Object.keys(d).forEach((e=>{const{keydownListener:t,keyupListenr:o,capture:r}=d.get(e)||{};t&&o&&(n(e,"keyup",o,r),n(e,"keydown",t,r),d.delete(e))})),d.clear(),Object.keys(f).forEach((e=>delete f[e])),u){const{listener:e,capture:t}=u;n(window,"focus",e,t),u=null}}}const E={getPressedKeyString:function(){return a.map((e=>{return t=e,Object.keys(i).find((e=>i[e]===t))||(e=>Object.keys(c).find((t=>c[t]===e)))(e)||String.fromCharCode(e);var t}))},setScope:h,getScope:m,deleteScope:function(e,t){let n,o;e||(e=m());for(const t in f)if(Object.prototype.hasOwnProperty.call(f,t))for(n=f[t],o=0;o<n.length;)if(n[o].scope===e){n.splice(o,1).forEach((e=>{let{element:t}=e;return v(t)}))}else o++;m()===e&&h(t||"all")},getPressedKeyCodes:function(){return a.slice(0)},getAllKeyCodes:function(){const e=[];return Object.keys(f).forEach((t=>{f[t].forEach((t=>{let{key:n,scope:o,mods:r,shortcut:i}=t;e.push({scope:o,shortcut:i,mods:r,keys:n.split("+").map((e=>y(e)))})}))})),e},isPressed:function(e){return"string"==typeof e&&(e=y(e)),-1!==a.indexOf(e)},filter:function(e){const t=e.target||e.srcElement,{tagName:n}=t;let o=!0;const r="INPUT"===n&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(r||"TEXTAREA"===n||"SELECT"===n)&&!t.readOnly)&&(o=!1),o},trigger:function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(f).forEach((n=>{f[n].filter((n=>n.scope===t&&n.shortcut===e)).forEach((e=>{e&&e.method&&e.method()}))}))},unbind:k,keyMap:i,modifier:c,modifierMap:s};for(const e in E)Object.prototype.hasOwnProperty.call(E,e)&&(b[e]=E[e]);if("undefined"!=typeof window){const e=window.hotkeys;b.noConflict=t=>(t&&window.hotkeys===b&&(window.hotkeys=e),b),window.hotkeys=b}export{b as default}; |