vue-json-search
Version:
Headless Vue (3.x) search component based on [Fuse.js](https://github.com/krisk/Fuse). Designed for static generators like [Hugo](https://github.com/gohugoio/hugo) but works with any site that's cabable of producing a JSON corpus.
3 lines (2 loc) • 20.8 kB
JavaScript
var Mt=Object.defineProperty,yt=Object.defineProperties;var Et=Object.getOwnPropertyDescriptors;var _e=Object.getOwnPropertySymbols;var St=Object.prototype.hasOwnProperty,xt=Object.prototype.propertyIsEnumerable;var Me=(_,r,M)=>r in _?Mt(_,r,{enumerable:!0,configurable:!0,writable:!0,value:M}):_[r]=M,w=(_,r)=>{for(var M in r||(r={}))St.call(r,M)&&Me(_,M,r[M]);if(_e)for(var M of _e(r))xt.call(r,M)&&Me(_,M,r[M]);return _},Q=(_,r)=>yt(_,Et(r));(function(_,r){typeof exports=="object"&&typeof module!="undefined"?r(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],r):(_=typeof globalThis!="undefined"?globalThis:_||self,r(_["vue-json-search"]={},_.Vue))})(this,function(_,r){"use strict";function M(s){return Array.isArray?Array.isArray(s):q(s)==="[object Array]"}const ye=1/0;function Ee(s){if(typeof s=="string")return s;let e=s+"";return e=="0"&&1/s==-ye?"-0":e}function Se(s){return s==null?"":Ee(s)}function I(s){return typeof s=="string"}function X(s){return typeof s=="number"}function xe(s){return s===!0||s===!1||Re(s)&&q(s)=="[object Boolean]"}function Z(s){return typeof s=="object"}function Re(s){return Z(s)&&s!==null}function E(s){return s!=null}function V(s){return!s.trim().length}function q(s){return s==null?s===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(s)}const Rt="Extended search is not available",Ie="Incorrect 'index' type",ke=s=>`Invalid value for key ${s}`,we=s=>`Pattern length exceeds max of ${s}.`,Ae=s=>`Missing ${s} property in key`,Te=s=>`Property 'weight' in key '${s}' must be a positive integer`,v=Object.prototype.hasOwnProperty;class $e{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(n=>{let i=ee(n);t+=i.weight,this._keys.push(i),this._keyMap[i.id]=i,t+=i.weight}),this._keys.forEach(n=>{n.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ee(s){let e=null,t=null,n=null,i=1;if(I(s)||M(s))n=s,e=te(s),t=D(s);else{if(!v.call(s,"name"))throw new Error(Ae("name"));const c=s.name;if(n=c,v.call(s,"weight")&&(i=s.weight,i<=0))throw new Error(Te(c));e=te(c),t=D(c)}return{path:e,id:t,weight:i,src:n}}function te(s){return M(s)?s:s.split(".")}function D(s){return M(s)?s.join("."):s}function Le(s,e){let t=[],n=!1;const i=(c,o,l)=>{if(!!E(c))if(!o[l])t.push(c);else{let a=o[l];const h=c[a];if(!E(h))return;if(l===o.length-1&&(I(h)||X(h)||xe(h)))t.push(Se(h));else if(M(h)){n=!0;for(let u=0,d=h.length;u<d;u+=1)i(h[u],o,l+1)}else o.length&&i(h,o,l+1)}};return i(s,I(e)?e.split("."):e,0),n?t:t[0]}const Ne={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},be={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(s,e)=>s.score===e.score?s.idx<e.idx?-1:1:s.score<e.score?-1:1},Oe={location:0,threshold:.6,distance:100},Ce={useExtendedSearch:!1,getFn:Le,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var f=w(w(w(w({},be),Ne),Oe),Ce);const je=/[^ ]+/g;function Pe(s=1,e=3){const t=new Map,n=Math.pow(10,e);return{get(i){const c=i.match(je).length;if(t.has(c))return t.get(c);const o=1/Math.pow(c,.5*s),l=parseFloat(Math.round(o*n)/n);return t.set(c,l),l},clear(){t.clear()}}}class K{constructor({getFn:e=f.getFn,fieldNormWeight:t=f.fieldNormWeight}={}){this.norm=Pe(t,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((t,n)=>{this._keysMap[t.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,I(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){const t=this.size();I(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,n=this.size();t<n;t+=1)this.records[t].i-=1}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!E(e)||V(e))return;let n={v:e,i:t,n:this.norm.get(e)};this.records.push(n)}_addObject(e,t){let n={i:t,$:{}};this.keys.forEach((i,c)=>{let o=this.getFn(e,i.path);if(!!E(o)){if(M(o)){let l=[];const a=[{nestedArrIndex:-1,value:o}];for(;a.length;){const{nestedArrIndex:h,value:u}=a.pop();if(!!E(u))if(I(u)&&!V(u)){let d={v:u,i:h,n:this.norm.get(u)};l.push(d)}else M(u)&&u.forEach((d,g)=>{a.push({nestedArrIndex:g,value:d})})}n.$[c]=l}else if(!V(o)){let l={v:o,n:this.norm.get(o)};n.$[c]=l}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function se(s,e,{getFn:t=f.getFn,fieldNormWeight:n=f.fieldNormWeight}={}){const i=new K({getFn:t,fieldNormWeight:n});return i.setKeys(s.map(ee)),i.setSources(e),i.create(),i}function Be(s,{getFn:e=f.getFn,fieldNormWeight:t=f.fieldNormWeight}={}){const{keys:n,records:i}=s,c=new K({getFn:e,fieldNormWeight:t});return c.setKeys(n),c.setIndexRecords(i),c}function j(s,{errors:e=0,currentLocation:t=0,expectedLocation:n=0,distance:i=f.distance,ignoreLocation:c=f.ignoreLocation}={}){const o=e/s.length;if(c)return o;const l=Math.abs(n-t);return i?o+l/i:l?1:o}function Fe(s=[],e=f.minMatchCharLength){let t=[],n=-1,i=-1,c=0;for(let o=s.length;c<o;c+=1){let l=s[c];l&&n===-1?n=c:!l&&n!==-1&&(i=c-1,i-n+1>=e&&t.push([n,i]),n=-1)}return s[c-1]&&c-n>=e&&t.push([n,c-1]),t}const L=32;function Ve(s,e,t,{location:n=f.location,distance:i=f.distance,threshold:c=f.threshold,findAllMatches:o=f.findAllMatches,minMatchCharLength:l=f.minMatchCharLength,includeMatches:a=f.includeMatches,ignoreLocation:h=f.ignoreLocation}={}){if(e.length>L)throw new Error(we(L));const u=e.length,d=s.length,g=Math.max(0,Math.min(n,d));let m=c,p=g;const y=l>1||a,S=y?Array(d):[];let k;for(;(k=s.indexOf(e,p))>-1;){let x=j(e,{currentLocation:k,expectedLocation:g,distance:i,ignoreLocation:h});if(m=Math.min(x,m),p=k+u,y){let T=0;for(;T<u;)S[k+T]=1,T+=1}}p=-1;let O=[],N=1,B=u+d;const _t=1<<u-1;for(let x=0;x<u;x+=1){let T=0,$=B;for(;T<$;)j(e,{errors:x,currentLocation:g+$,expectedLocation:g,distance:i,ignoreLocation:h})<=m?T=$:B=$,$=Math.floor((B-T)/2+T);B=$;let pe=Math.max(1,g-$+1),J=o?d:Math.min(g+$,d)+u,C=Array(J+2);C[J+1]=(1<<x)-1;for(let R=J;R>=pe;R-=1){let F=R-1,me=t[s.charAt(F)];if(y&&(S[F]=+!!me),C[R]=(C[R+1]<<1|1)&me,x&&(C[R]|=(O[R+1]|O[R])<<1|1|O[R+1]),C[R]&_t&&(N=j(e,{errors:x,currentLocation:F,expectedLocation:g,distance:i,ignoreLocation:h}),N<=m)){if(m=N,p=F,p<=g)break;pe=Math.max(1,2*g-p)}}if(j(e,{errors:x+1,currentLocation:g,expectedLocation:g,distance:i,ignoreLocation:h})>m)break;O=C}const G={isMatch:p>=0,score:Math.max(.001,N)};if(y){const x=Fe(S,l);x.length?a&&(G.indices=x):G.isMatch=!1}return G}function De(s){let e={};for(let t=0,n=s.length;t<n;t+=1){const i=s.charAt(t);e[i]=(e[i]||0)|1<<n-t-1}return e}class ne{constructor(e,{location:t=f.location,threshold:n=f.threshold,distance:i=f.distance,includeMatches:c=f.includeMatches,findAllMatches:o=f.findAllMatches,minMatchCharLength:l=f.minMatchCharLength,isCaseSensitive:a=f.isCaseSensitive,ignoreLocation:h=f.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:l,isCaseSensitive:a,ignoreLocation:h},this.pattern=a?e:e.toLowerCase(),this.chunks=[],!this.pattern.length)return;const u=(g,m)=>{this.chunks.push({pattern:g,alphabet:De(g),startIndex:m})},d=this.pattern.length;if(d>L){let g=0;const m=d%L,p=d-m;for(;g<p;)u(this.pattern.substr(g,L),g),g+=L;if(m){const y=d-L;u(this.pattern.substr(y),y)}}else u(this.pattern,0)}searchIn(e){const{isCaseSensitive:t,includeMatches:n}=this.options;if(t||(e=e.toLowerCase()),this.pattern===e){let p={isMatch:!0,score:0};return n&&(p.indices=[[0,e.length-1]]),p}const{location:i,distance:c,threshold:o,findAllMatches:l,minMatchCharLength:a,ignoreLocation:h}=this.options;let u=[],d=0,g=!1;this.chunks.forEach(({pattern:p,alphabet:y,startIndex:S})=>{const{isMatch:k,score:O,indices:N}=Ve(e,p,y,{location:i+S,distance:c,threshold:o,findAllMatches:l,minMatchCharLength:a,includeMatches:n,ignoreLocation:h});k&&(g=!0),d+=O,k&&N&&(u=[...u,...N])});let m={isMatch:g,score:g?d/this.chunks.length:1};return g&&n&&(m.indices=u),m}}class A{constructor(e){this.pattern=e}static isMultiMatch(e){return re(e,this.multiRegex)}static isSingleMatch(e){return re(e,this.singleRegex)}search(){}}function re(s,e){const t=s.match(e);return t?t[1]:null}class Ke extends A{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}class ze extends A{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const n=e.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class We extends A{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}class He extends A{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}class Ue extends A{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class Ye extends A{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}class ie extends A{constructor(e,{location:t=f.location,threshold:n=f.threshold,distance:i=f.distance,includeMatches:c=f.includeMatches,findAllMatches:o=f.findAllMatches,minMatchCharLength:l=f.minMatchCharLength,isCaseSensitive:a=f.isCaseSensitive,ignoreLocation:h=f.ignoreLocation}={}){super(e);this._bitapSearch=new ne(e,{location:t,threshold:n,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:l,isCaseSensitive:a,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class ce extends A{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0,n;const i=[],c=this.pattern.length;for(;(n=e.indexOf(this.pattern,t))>-1;)t=n+c,i.push([n,t-1]);const o=!!i.length;return{isMatch:o,score:o?0:1,indices:i}}}const z=[Ke,ce,We,He,Ye,Ue,ze,ie],oe=z.length,Ge=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/,Je="|";function Qe(s,e={}){return s.split(Je).map(t=>{let n=t.trim().split(Ge).filter(c=>c&&!!c.trim()),i=[];for(let c=0,o=n.length;c<o;c+=1){const l=n[c];let a=!1,h=-1;for(;!a&&++h<oe;){const u=z[h];let d=u.isMultiMatch(l);d&&(i.push(new u(d,e)),a=!0)}if(!a)for(h=-1;++h<oe;){const u=z[h];let d=u.isSingleMatch(l);if(d){i.push(new u(d,e));break}}}return i})}const Xe=new Set([ie.type,ce.type]);class Ze{constructor(e,{isCaseSensitive:t=f.isCaseSensitive,includeMatches:n=f.includeMatches,minMatchCharLength:i=f.minMatchCharLength,ignoreLocation:c=f.ignoreLocation,findAllMatches:o=f.findAllMatches,location:l=f.location,threshold:a=f.threshold,distance:h=f.distance}={}){this.query=null,this.options={isCaseSensitive:t,includeMatches:n,minMatchCharLength:i,findAllMatches:o,ignoreLocation:c,location:l,threshold:a,distance:h},this.pattern=t?e:e.toLowerCase(),this.query=Qe(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){const t=this.query;if(!t)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:i}=this.options;e=i?e:e.toLowerCase();let c=0,o=[],l=0;for(let a=0,h=t.length;a<h;a+=1){const u=t[a];o.length=0,c=0;for(let d=0,g=u.length;d<g;d+=1){const m=u[d],{isMatch:p,indices:y,score:S}=m.search(e);if(p){if(c+=1,l+=S,n){const k=m.constructor.type;Xe.has(k)?o=[...o,...y]:o.push(y)}}else{l=0,c=0,o.length=0;break}}if(c){let d={isMatch:!0,score:l/c};return n&&(d.indices=o),d}}return{isMatch:!1,score:1}}}const W=[];function qe(...s){W.push(...s)}function H(s,e){for(let t=0,n=W.length;t<n;t+=1){let i=W[t];if(i.condition(s,e))return new i(s,e)}return new ne(s,e)}const P={AND:"$and",OR:"$or"},U={PATH:"$path",PATTERN:"$val"},Y=s=>!!(s[P.AND]||s[P.OR]),ve=s=>!!s[U.PATH],et=s=>!M(s)&&Z(s)&&!Y(s),le=s=>({[P.AND]:Object.keys(s).map(e=>({[e]:s[e]}))});function ae(s,e,{auto:t=!0}={}){const n=i=>{let c=Object.keys(i);const o=ve(i);if(!o&&c.length>1&&!Y(i))return n(le(i));if(et(i)){const a=o?i[U.PATH]:c[0],h=o?i[U.PATTERN]:i[a];if(!I(h))throw new Error(ke(a));const u={keyId:D(a),pattern:h};return t&&(u.searcher=H(h,e)),u}let l={children:[],operator:c[0]};return c.forEach(a=>{const h=i[a];M(h)&&h.forEach(u=>{l.children.push(n(u))})}),l};return Y(s)||(s=le(s)),n(s)}function tt(s,{ignoreFieldNorm:e=f.ignoreFieldNorm}){s.forEach(t=>{let n=1;t.matches.forEach(({key:i,norm:c,score:o})=>{const l=i?i.weight:null;n*=Math.pow(o===0&&l?Number.EPSILON:o,(l||1)*(e?1:c))}),t.score=n})}function st(s,e){const t=s.matches;e.matches=[],!!E(t)&&t.forEach(n=>{if(!E(n.indices)||!n.indices.length)return;const{indices:i,value:c}=n;let o={indices:i,value:c};n.key&&(o.key=n.key.src),n.idx>-1&&(o.refIndex=n.idx),e.matches.push(o)})}function nt(s,e){e.score=s.score}function rt(s,e,{includeMatches:t=f.includeMatches,includeScore:n=f.includeScore}={}){const i=[];return t&&i.push(st),n&&i.push(nt),s.map(c=>{const{idx:o}=c,l={item:e[o],refIndex:o};return i.length&&i.forEach(a=>{a(c,l)}),l})}class b{constructor(e,t={},n){this.options=w(w({},f),t),this.options.useExtendedSearch,this._keyStore=new $e(this.options.keys),this.setCollection(e,n)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof K))throw new Error(Ie);this._myIndex=t||se(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){!E(e)||(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let n=0,i=this._docs.length;n<i;n+=1){const c=this._docs[n];e(c,n)&&(this.removeAt(n),n-=1,i-=1,t.push(c))}return t}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:t=-1}={}){const{includeMatches:n,includeScore:i,shouldSort:c,sortFn:o,ignoreFieldNorm:l}=this.options;let a=I(e)?I(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return tt(a,{ignoreFieldNorm:l}),c&&a.sort(o),X(t)&&t>-1&&(a=a.slice(0,t)),rt(a,this._docs,{includeMatches:n,includeScore:i})}_searchStringList(e){const t=H(e,this.options),{records:n}=this._myIndex,i=[];return n.forEach(({v:c,i:o,n:l})=>{if(!E(c))return;const{isMatch:a,score:h,indices:u}=t.searchIn(c);a&&i.push({item:c,idx:o,matches:[{score:h,value:c,norm:l,indices:u}]})}),i}_searchLogical(e){const t=ae(e,this.options),n=(l,a,h)=>{if(!l.children){const{keyId:d,searcher:g}=l,m=this._findMatches({key:this._keyStore.get(d),value:this._myIndex.getValueForItemAtKeyId(a,d),searcher:g});return m&&m.length?[{idx:h,item:a,matches:m}]:[]}const u=[];for(let d=0,g=l.children.length;d<g;d+=1){const m=l.children[d],p=n(m,a,h);if(p.length)u.push(...p);else if(l.operator===P.AND)return[]}return u},i=this._myIndex.records,c={},o=[];return i.forEach(({$:l,i:a})=>{if(E(l)){let h=n(t,l,a);h.length&&(c[a]||(c[a]={idx:a,item:l,matches:[]},o.push(c[a])),h.forEach(({matches:u})=>{c[a].matches.push(...u)}))}}),o}_searchObjectList(e){const t=H(e,this.options),{keys:n,records:i}=this._myIndex,c=[];return i.forEach(({$:o,i:l})=>{if(!E(o))return;let a=[];n.forEach((h,u)=>{a.push(...this._findMatches({key:h,value:o[u],searcher:t}))}),a.length&&c.push({idx:l,item:o,matches:a})}),c}_findMatches({key:e,value:t,searcher:n}){if(!E(t))return[];let i=[];if(M(t))t.forEach(({v:c,i:o,n:l})=>{if(!E(c))return;const{isMatch:a,score:h,indices:u}=n.searchIn(c);a&&i.push({score:h,key:e,value:c,idx:o,norm:l,indices:u})});else{const{v:c,n:o}=t,{isMatch:l,score:a,indices:h}=n.searchIn(c);l&&i.push({score:a,key:e,value:c,norm:o,indices:h})}return i}}b.version="6.5.3",b.createIndex=se,b.parseIndex=Be,b.config=f,b.parseQuery=ae,qe(Ze);const it={for:"jsonsearchinput"},ct={inheritAttrs:!1},he=r.defineComponent(Q(w({},ct),{props:{label:null},setup(s){const e=s,t=e.label!==void 0?e.label:"Search",n=r.inject("searchTerm");return(i,c)=>r.renderSlot(i.$slots,"default",r.normalizeProps(r.guardReactiveProps({searchTerm:r.unref(n)})),()=>[r.createElementVNode("label",it,r.toDisplayString(r.unref(t)),1),r.withDirectives(r.createElementVNode("input",r.mergeProps(i.$attrs,{name:"jsonsearchinput",class:"jsonsearchinput",autocomplete:"off",placeholder:"Search",type:"text","onUpdate:modelValue":c[0]||(c[0]=o=>r.isRef(n)?n.value=o:null)}),null,16),[[r.vModelText,r.unref(n)]])])}})),ot={key:0},ue=r.defineComponent({setup(s){const e=r.inject("numResults"),t=r.inject("resultsTitle"),n=r.inject("searchTerm");return(i,c)=>r.renderSlot(i.$slots,"default",r.normalizeProps(r.guardReactiveProps({numResults:r.unref(e),resultsTitle:r.unref(t)})),()=>[r.unref(n)&&r.unref(n).length>1?(r.openBlock(),r.createElementBlock("h3",ot,r.toDisplayString(r.unref(t)),1)):r.createCommentVNode("",!0)])}});function lt(s,e,t,n){let i="";return e.length>0&&(i+='<a href="'+s+e+'/" rel="tag" class="tag">'+e+"</a>",t<n.length-1&&(i+=", ")),i}const at={class:"result"},ht={class:"title"},ut=["href"],ft={key:0,class:"tags"},dt=["innerHTML"],fe=r.defineComponent({props:{result:null},setup(s){const e=r.inject("showTags"),t=r.inject("tagRoot");return(n,i)=>r.renderSlot(n.$slots,"default",r.normalizeProps(r.guardReactiveProps({result:s.result})),()=>[r.createElementVNode("div",at,[r.createElementVNode("div",ht,[r.createElementVNode("a",{href:s.result.permalink},r.toDisplayString(s.result.title),9,ut)]),r.unref(e)?(r.openBlock(),r.createElementBlock("div",ft,[(r.openBlock(!0),r.createElementBlock(r.Fragment,null,r.renderList(s.result.tags,(c,o)=>(r.openBlock(),r.createElementBlock("span",{key:c,innerHTML:r.unref(lt)(r.unref(t),c,o,s.result.tags)},null,8,dt))),128))])):r.createCommentVNode("",!0)])])}}),de=r.defineComponent({setup(s){const e=r.inject("results");return(t,n)=>(r.openBlock(),r.createElementBlock("ol",null,[(r.openBlock(!0),r.createElementBlock(r.Fragment,null,r.renderList(r.unref(e),i=>r.renderSlot(t.$slots,"default",r.mergeProps({key:i.refIndex},{results:r.unref(e)}),()=>[r.createVNode(fe,{result:i.item},null,8,["result"])])),128))]))}}),gt={key:0,class:"searchresults"},ge=r.defineComponent({setup(s){const e=r.inject("searchTerm");return(t,n)=>r.renderSlot(t.$slots,"default",{},()=>[r.unref(e)&&r.unref(e).length>1?(r.openBlock(),r.createElementBlock("div",gt,[r.renderSlot(t.$slots,"result-title",{},()=>[r.createVNode(ue)]),r.renderSlot(t.$slots,"result-list",{},()=>[r.createVNode(de)])])):r.createCommentVNode("",!0)])}}),pt={inheritAttrs:!1},mt=r.defineComponent(Q(w({},pt),{props:{url:null,fuseOptions:null,maxResults:null,showTags:{type:Boolean},tagRoot:null},setup(s){const e=s,t={shouldSort:!0,location:0,distance:100,threshold:.4,minMatchCharLength:2,keys:["title","permalink","contents","tags"]},n=r.ref(!1),i=r.ref(""),c=r.ref(""),o=r.ref(0),l=r.ref([]),a=r.ref([]);let h;const u=e.url!==void 0?e.url:"/index.json",d=e.maxResults!==void 0?e.maxResults:10,g=e.fuseOptions!==void 0?e.fuseOptions:t;function m(){return new Promise((p,y)=>{fetch(u).then(S=>S.json()).then(S=>{h=new b(S,g),p()}).catch(S=>y(S))})}return r.watch(i,p=>{p.length>1?(l.value=h.search(p),a.value=l.value.slice(0,d),o.value=l.value.length,l.value.length===1?c.value="1 result":c.value=l.value.length+" results"):(l.value=[],a.value=[],o.value=0)}),r.provide("searchTerm",i),r.provide("showTags",e.showTags!==void 0?e.showTags:!1),r.provide("tagRoot",e.tagRoot!==void 0?e.tagRoot:"/tags/"),r.provide("numResults",o),r.provide("results",a),r.provide("resultsTitle",c),m().then(()=>{n.value=!0}).catch(p=>{console.error(p),n.value=!1}),(p,y)=>r.renderSlot(p.$slots,"default",r.normalizeProps(r.guardReactiveProps({searchTerm:i.value,results:a.value})),()=>[n.value?(r.openBlock(),r.createElementBlock("div",r.mergeProps({key:0,class:"jsonsearch"},p.$attrs),[r.createVNode(he),r.createVNode(ge)],16)):r.createCommentVNode("",!0)])}}));_.JsonSearch=mt,_.ResultList=de,_.ResultListItem=fe,_.ResultTitle=ue,_.SearchInput=he,_.SearchResults=ge,Object.defineProperty(_,"__esModule",{value:!0}),_[Symbol.toStringTag]="Module"});
//# sourceMappingURL=index.umd.js.map