@eox/itemfilter 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,171 @@
1
- (function(M,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(M=typeof globalThis<"u"?globalThis:M||self,m(M["eox-itemfilter"]={}))})(this,function(M){"use strict";var Ze=Object.defineProperty;var et=(M,m,b)=>m in M?Ze(M,m,{enumerable:!0,configurable:!0,writable:!0,value:b}):M[m]=b;var A=(M,m,b)=>(et(M,typeof m!="symbol"?m+"":m,b),b);function m(t){return Array.isArray?Array.isArray(t):J(t)==="[object Array]"}const b=1/0;function de(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-b?"-0":e}function ge(t){return t==null?"":de(t)}function I(t){return typeof t=="string"}function Q(t){return typeof t=="number"}function pe(t){return t===!0||t===!1||me(t)&&J(t)=="[object Boolean]"}function X(t){return typeof t=="object"}function me(t){return X(t)&&t!==null}function y(t){return t!=null}function H(t){return!t.trim().length}function J(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const tt="Extended search is not available",ye="Incorrect 'index' type",Me=t=>`Invalid value for key ${t}`,Ee=t=>`Pattern length exceeds max of ${t}.`,xe=t=>`Missing ${t} property in key`,Se=t=>`Property 'weight' in key '${t}' must be a positive integer`,q=Object.prototype.hasOwnProperty;class Ie{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(r=>{let n=Z(r);s+=n.weight,this._keys.push(n),this._keyMap[n.id]=n,s+=n.weight}),this._keys.forEach(r=>{r.weight/=s})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function Z(t){let e=null,s=null,r=null,n=1,i=null;if(I(t)||m(t))r=t,e=ee(t),s=B(t);else{if(!q.call(t,"name"))throw new Error(xe("name"));const c=t.name;if(r=c,q.call(t,"weight")&&(n=t.weight,n<=0))throw new Error(Se(c));e=ee(c),s=B(c),i=t.getFn}return{path:e,id:s,weight:n,src:r,getFn:i}}function ee(t){return m(t)?t:t.split(".")}function B(t){return m(t)?t.join("."):t}function Ae(t,e){let s=[],r=!1;const n=(i,c,o)=>{if(y(i))if(!c[o])s.push(i);else{let a=c[o];const h=i[a];if(!y(h))return;if(o===c.length-1&&(I(h)||Q(h)||pe(h)))s.push(ge(h));else if(m(h)){r=!0;for(let l=0,u=h.length;l<u;l+=1)n(h[l],c,o+1)}else c.length&&n(h,c,o+1)}};return n(t,I(e)?e.split("."):e,0),r?s:s[0]}var f={...{isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,getFn:Ae,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const _e=/[^ ]+/g;function we(t=1,e=3){const s=new Map,r=Math.pow(10,e);return{get(n){const i=n.match(_e).length;if(s.has(i))return s.get(i);const c=1/Math.pow(i,.5*t),o=parseFloat(Math.round(c*r)/r);return s.set(i,o),o},clear(){s.clear()}}}class K{constructor({getFn:e=f.getFn,fieldNormWeight:s=f.fieldNormWeight}={}){this.norm=we(s,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((s,r)=>{this._keysMap[s.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,I(this.docs[0])?this.docs.forEach((e,s)=>{this._addString(e,s)}):this.docs.forEach((e,s)=>{this._addObject(e,s)}),this.norm.clear())}add(e){const s=this.size();I(e)?this._addString(e,s):this._addObject(e,s)}removeAt(e){this.records.splice(e,1);for(let s=e,r=this.size();s<r;s+=1)this.records[s].i-=1}getValueForItemAtKeyId(e,s){return e[this._keysMap[s]]}size(){return this.records.length}_addString(e,s){if(!y(e)||H(e))return;let r={v:e,i:s,n:this.norm.get(e)};this.records.push(r)}_addObject(e,s){let r={i:s,$:{}};this.keys.forEach((n,i)=>{let c=n.getFn?n.getFn(e):this.getFn(e,n.path);if(y(c)){if(m(c)){let o=[];const a=[{nestedArrIndex:-1,value:c}];for(;a.length;){const{nestedArrIndex:h,value:l}=a.pop();if(y(l))if(I(l)&&!H(l)){let u={v:l,i:h,n:this.norm.get(l)};o.push(u)}else m(l)&&l.forEach((u,d)=>{a.push({nestedArrIndex:d,value:u})})}r.$[i]=o}else if(I(c)&&!H(c)){let o={v:c,n:this.norm.get(c)};r.$[i]=o}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function te(t,e,{getFn:s=f.getFn,fieldNormWeight:r=f.fieldNormWeight}={}){const n=new K({getFn:s,fieldNormWeight:r});return n.setKeys(t.map(Z)),n.setSources(e),n.create(),n}function Le(t,{getFn:e=f.getFn,fieldNormWeight:s=f.fieldNormWeight}={}){const{keys:r,records:n}=t,i=new K({getFn:e,fieldNormWeight:s});return i.setKeys(r),i.setIndexRecords(n),i}function v(t,{errors:e=0,currentLocation:s=0,expectedLocation:r=0,distance:n=f.distance,ignoreLocation:i=f.ignoreLocation}={}){const c=e/t.length;if(i)return c;const o=Math.abs(r-s);return n?c+o/n:o?1:c}function Re(t=[],e=f.minMatchCharLength){let s=[],r=-1,n=-1,i=0;for(let c=t.length;i<c;i+=1){let o=t[i];o&&r===-1?r=i:!o&&r!==-1&&(n=i-1,n-r+1>=e&&s.push([r,n]),r=-1)}return t[i-1]&&i-r>=e&&s.push([r,i-1]),s}const k=32;function be(t,e,s,{location:r=f.location,distance:n=f.distance,threshold:i=f.threshold,findAllMatches:c=f.findAllMatches,minMatchCharLength:o=f.minMatchCharLength,includeMatches:a=f.includeMatches,ignoreLocation:h=f.ignoreLocation}={}){if(e.length>k)throw new Error(Ee(k));const l=e.length,u=t.length,d=Math.max(0,Math.min(r,u));let g=i,p=d;const E=o>1||a,T=E?Array(u):[];let _;for(;(_=t.indexOf(e,p))>-1;){let x=v(e,{currentLocation:_,expectedLocation:d,distance:n,ignoreLocation:h});if(g=Math.min(x,g),p=_+l,E){let L=0;for(;L<l;)T[_+L]=1,L+=1}}p=-1;let N=[],O=1,P=l+u;const qe=1<<l-1;for(let x=0;x<l;x+=1){let L=0,R=P;for(;L<R;)v(e,{errors:x,currentLocation:d+R,expectedLocation:d,distance:n,ignoreLocation:h})<=g?L=R:P=R,R=Math.floor((P-L)/2+L);P=R;let ue=Math.max(1,d-R+1),U=c?u:Math.min(d+R,u)+l,C=Array(U+2);C[U+1]=(1<<x)-1;for(let S=U;S>=ue;S-=1){let j=S-1,fe=s[t.charAt(j)];if(E&&(T[j]=+!!fe),C[S]=(C[S+1]<<1|1)&fe,x&&(C[S]|=(N[S+1]|N[S])<<1|1|N[S+1]),C[S]&qe&&(O=v(e,{errors:x,currentLocation:j,expectedLocation:d,distance:n,ignoreLocation:h}),O<=g)){if(g=O,p=j,p<=d)break;ue=Math.max(1,2*d-p)}}if(v(e,{errors:x+1,currentLocation:d,expectedLocation:d,distance:n,ignoreLocation:h})>g)break;N=C}const G={isMatch:p>=0,score:Math.max(.001,O)};if(E){const x=Re(T,o);x.length?a&&(G.indices=x):G.isMatch=!1}return G}function ke(t){let e={};for(let s=0,r=t.length;s<r;s+=1){const n=t.charAt(s);e[n]=(e[n]||0)|1<<r-s-1}return e}class se{constructor(e,{location:s=f.location,threshold:r=f.threshold,distance:n=f.distance,includeMatches:i=f.includeMatches,findAllMatches:c=f.findAllMatches,minMatchCharLength:o=f.minMatchCharLength,isCaseSensitive:a=f.isCaseSensitive,ignoreLocation:h=f.ignoreLocation}={}){if(this.options={location:s,threshold:r,distance:n,includeMatches:i,findAllMatches:c,minMatchCharLength:o,isCaseSensitive:a,ignoreLocation:h},this.pattern=a?e:e.toLowerCase(),this.chunks=[],!this.pattern.length)return;const l=(d,g)=>{this.chunks.push({pattern:d,alphabet:ke(d),startIndex:g})},u=this.pattern.length;if(u>k){let d=0;const g=u%k,p=u-g;for(;d<p;)l(this.pattern.substr(d,k),d),d+=k;if(g){const E=u-k;l(this.pattern.substr(E),E)}}else l(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,includeMatches:r}=this.options;if(s||(e=e.toLowerCase()),this.pattern===e){let p={isMatch:!0,score:0};return r&&(p.indices=[[0,e.length-1]]),p}const{location:n,distance:i,threshold:c,findAllMatches:o,minMatchCharLength:a,ignoreLocation:h}=this.options;let l=[],u=0,d=!1;this.chunks.forEach(({pattern:p,alphabet:E,startIndex:T})=>{const{isMatch:_,score:N,indices:O}=be(e,p,E,{location:n+T,distance:i,threshold:c,findAllMatches:o,minMatchCharLength:a,includeMatches:r,ignoreLocation:h});_&&(d=!0),u+=N,_&&O&&(l=[...l,...O])});let g={isMatch:d,score:d?u/this.chunks.length:1};return d&&r&&(g.indices=l),g}}class w{constructor(e){this.pattern=e}static isMultiMatch(e){return ne(e,this.multiRegex)}static isSingleMatch(e){return ne(e,this.singleRegex)}search(){}}function ne(t,e){const s=t.match(e);return s?s[1]:null}class Te extends w{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const s=e===this.pattern;return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Oe extends w{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class $e extends w{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const s=e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Ne extends w{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const s=!e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class Ce extends w{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const s=e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class ve extends w{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const s=!e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class re extends w{constructor(e,{location:s=f.location,threshold:r=f.threshold,distance:n=f.distance,includeMatches:i=f.includeMatches,findAllMatches:c=f.findAllMatches,minMatchCharLength:o=f.minMatchCharLength,isCaseSensitive:a=f.isCaseSensitive,ignoreLocation:h=f.ignoreLocation}={}){super(e),this._bitapSearch=new se(e,{location:s,threshold:r,distance:n,includeMatches:i,findAllMatches:c,minMatchCharLength:o,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 ie extends w{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let s=0,r;const n=[],i=this.pattern.length;for(;(r=e.indexOf(this.pattern,s))>-1;)s=r+i,n.push([r,s-1]);const c=!!n.length;return{isMatch:c,score:c?0:1,indices:n}}}const D=[Te,ie,$e,Ne,ve,Ce,Oe,re],ce=D.length,Fe=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Pe="|";function je(t,e={}){return t.split(Pe).map(s=>{let r=s.trim().split(Fe).filter(i=>i&&!!i.trim()),n=[];for(let i=0,c=r.length;i<c;i+=1){const o=r[i];let a=!1,h=-1;for(;!a&&++h<ce;){const l=D[h];let u=l.isMultiMatch(o);u&&(n.push(new l(u,e)),a=!0)}if(!a)for(h=-1;++h<ce;){const l=D[h];let u=l.isSingleMatch(o);if(u){n.push(new l(u,e));break}}}return n})}const He=new Set([re.type,ie.type]);class Be{constructor(e,{isCaseSensitive:s=f.isCaseSensitive,includeMatches:r=f.includeMatches,minMatchCharLength:n=f.minMatchCharLength,ignoreLocation:i=f.ignoreLocation,findAllMatches:c=f.findAllMatches,location:o=f.location,threshold:a=f.threshold,distance:h=f.distance}={}){this.query=null,this.options={isCaseSensitive:s,includeMatches:r,minMatchCharLength:n,findAllMatches:c,ignoreLocation:i,location:o,threshold:a,distance:h},this.pattern=s?e:e.toLowerCase(),this.query=je(this.pattern,this.options)}static condition(e,s){return s.useExtendedSearch}searchIn(e){const s=this.query;if(!s)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:n}=this.options;e=n?e:e.toLowerCase();let i=0,c=[],o=0;for(let a=0,h=s.length;a<h;a+=1){const l=s[a];c.length=0,i=0;for(let u=0,d=l.length;u<d;u+=1){const g=l[u],{isMatch:p,indices:E,score:T}=g.search(e);if(p){if(i+=1,o+=T,r){const _=g.constructor.type;He.has(_)?c=[...c,...E]:c.push(E)}}else{o=0,i=0,c.length=0;break}}if(i){let u={isMatch:!0,score:o/i};return r&&(u.indices=c),u}}return{isMatch:!1,score:1}}}const W=[];function Ke(...t){W.push(...t)}function z(t,e){for(let s=0,r=W.length;s<r;s+=1){let n=W[s];if(n.condition(t,e))return new n(t,e)}return new se(t,e)}const F={AND:"$and",OR:"$or"},V={PATH:"$path",PATTERN:"$val"},Y=t=>!!(t[F.AND]||t[F.OR]),De=t=>!!t[V.PATH],We=t=>!m(t)&&X(t)&&!Y(t),oe=t=>({[F.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function ae(t,e,{auto:s=!0}={}){const r=n=>{let i=Object.keys(n);const c=De(n);if(!c&&i.length>1&&!Y(n))return r(oe(n));if(We(n)){const a=c?n[V.PATH]:i[0],h=c?n[V.PATTERN]:n[a];if(!I(h))throw new Error(Me(a));const l={keyId:B(a),pattern:h};return s&&(l.searcher=z(h,e)),l}let o={children:[],operator:i[0]};return i.forEach(a=>{const h=n[a];m(h)&&h.forEach(l=>{o.children.push(r(l))})}),o};return Y(t)||(t=oe(t)),r(t)}function ze(t,{ignoreFieldNorm:e=f.ignoreFieldNorm}){t.forEach(s=>{let r=1;s.matches.forEach(({key:n,norm:i,score:c})=>{const o=n?n.weight:null;r*=Math.pow(c===0&&o?Number.EPSILON:c,(o||1)*(e?1:i))}),s.score=r})}function Ve(t,e){const s=t.matches;e.matches=[],y(s)&&s.forEach(r=>{if(!y(r.indices)||!r.indices.length)return;const{indices:n,value:i}=r;let c={indices:n,value:i};r.key&&(c.key=r.key.src),r.idx>-1&&(c.refIndex=r.idx),e.matches.push(c)})}function Ye(t,e){e.score=t.score}function Ge(t,e,{includeMatches:s=f.includeMatches,includeScore:r=f.includeScore}={}){const n=[];return s&&n.push(Ve),r&&n.push(Ye),t.map(i=>{const{idx:c}=i,o={item:e[c],refIndex:c};return n.length&&n.forEach(a=>{a(i,o)}),o})}class ${constructor(e,s={},r){this.options={...f,...s},this.options.useExtendedSearch,this._keyStore=new Ie(this.options.keys),this.setCollection(e,r)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof K))throw new Error(ye);this._myIndex=s||te(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){y(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const s=[];for(let r=0,n=this._docs.length;r<n;r+=1){const i=this._docs[r];e(i,r)&&(this.removeAt(r),r-=1,n-=1,s.push(i))}return s}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:s=-1}={}){const{includeMatches:r,includeScore:n,shouldSort:i,sortFn:c,ignoreFieldNorm:o}=this.options;let a=I(e)?I(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return ze(a,{ignoreFieldNorm:o}),i&&a.sort(c),Q(s)&&s>-1&&(a=a.slice(0,s)),Ge(a,this._docs,{includeMatches:r,includeScore:n})}_searchStringList(e){const s=z(e,this.options),{records:r}=this._myIndex,n=[];return r.forEach(({v:i,i:c,n:o})=>{if(!y(i))return;const{isMatch:a,score:h,indices:l}=s.searchIn(i);a&&n.push({item:i,idx:c,matches:[{score:h,value:i,norm:o,indices:l}]})}),n}_searchLogical(e){const s=ae(e,this.options),r=(o,a,h)=>{if(!o.children){const{keyId:u,searcher:d}=o,g=this._findMatches({key:this._keyStore.get(u),value:this._myIndex.getValueForItemAtKeyId(a,u),searcher:d});return g&&g.length?[{idx:h,item:a,matches:g}]:[]}const l=[];for(let u=0,d=o.children.length;u<d;u+=1){const g=o.children[u],p=r(g,a,h);if(p.length)l.push(...p);else if(o.operator===F.AND)return[]}return l},n=this._myIndex.records,i={},c=[];return n.forEach(({$:o,i:a})=>{if(y(o)){let h=r(s,o,a);h.length&&(i[a]||(i[a]={idx:a,item:o,matches:[]},c.push(i[a])),h.forEach(({matches:l})=>{i[a].matches.push(...l)}))}}),c}_searchObjectList(e){const s=z(e,this.options),{keys:r,records:n}=this._myIndex,i=[];return n.forEach(({$:c,i:o})=>{if(!y(c))return;let a=[];r.forEach((h,l)=>{a.push(...this._findMatches({key:h,value:c[l],searcher:s}))}),a.length&&i.push({idx:o,item:c,matches:a})}),i}_findMatches({key:e,value:s,searcher:r}){if(!y(s))return[];let n=[];if(m(s))s.forEach(({v:i,i:c,n:o})=>{if(!y(i))return;const{isMatch:a,score:h,indices:l}=r.searchIn(i);a&&n.push({score:h,key:e,value:i,idx:c,norm:o,indices:l})});else{const{v:i,n:c}=s,{isMatch:o,score:a,indices:h}=r.searchIn(i);o&&n.push({score:a,key:e,value:i,norm:c,indices:h})}return n}}$.version="6.6.2",$.createIndex=te,$.parseIndex=Le,$.config=f,$.parseQuery=ae,Ke(Be);const Ue=`
1
+ (function(M,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(M=typeof globalThis<"u"?globalThis:M||self,m(M["eox-itemfilter"]={}))})(this,function(M){"use strict";var et=Object.defineProperty;var tt=(M,m,v)=>m in M?et(M,m,{enumerable:!0,configurable:!0,writable:!0,value:v}):M[m]=v;var R=(M,m,v)=>(tt(M,typeof m!="symbol"?m+"":m,v),v);function m(s){return Array.isArray?Array.isArray(s):X(s)==="[object Array]"}const v=1/0;function fe(s){if(typeof s=="string")return s;let e=s+"";return e=="0"&&1/s==-v?"-0":e}function de(s){return s==null?"":fe(s)}function S(s){return typeof s=="string"}function G(s){return typeof s=="number"}function ge(s){return s===!0||s===!1||pe(s)&&X(s)=="[object Boolean]"}function Q(s){return typeof s=="object"}function pe(s){return Q(s)&&s!==null}function x(s){return s!=null}function P(s){return!s.trim().length}function X(s){return s==null?s===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(s)}const st="Extended search is not available",me="Incorrect 'index' type",ye=s=>`Invalid value for key ${s}`,xe=s=>`Pattern length exceeds max of ${s}.`,Me=s=>`Missing ${s} property in key`,Ee=s=>`Property 'weight' in key '${s}' must be a positive integer`,J=Object.prototype.hasOwnProperty;class we{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(n=>{let i=Z(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 Z(s){let e=null,t=null,n=null,i=1,c=null;if(S(s)||m(s))n=s,e=ee(s),t=B(s);else{if(!J.call(s,"name"))throw new Error(Me("name"));const r=s.name;if(n=r,J.call(s,"weight")&&(i=s.weight,i<=0))throw new Error(Ee(r));e=ee(r),t=B(r),c=s.getFn}return{path:e,id:t,weight:i,src:n,getFn:c}}function ee(s){return m(s)?s:s.split(".")}function B(s){return m(s)?s.join("."):s}function Se(s,e){let t=[],n=!1;const i=(c,r,o)=>{if(x(c))if(!r[o])t.push(c);else{let l=r[o];const a=c[l];if(!x(a))return;if(o===r.length-1&&(S(a)||G(a)||ge(a)))t.push(de(a));else if(m(a)){n=!0;for(let h=0,u=a.length;h<u;h+=1)i(a[h],r,o+1)}else r.length&&i(a,r,o+1)}};return i(s,S(e)?e.split("."):e,0),n?t:t[0]}var d={...{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},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,getFn:Se,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const Le=/[^ ]+/g;function Ae(s=1,e=3){const t=new Map,n=Math.pow(10,e);return{get(i){const c=i.match(Le).length;if(t.has(c))return t.get(c);const r=1/Math.pow(c,.5*s),o=parseFloat(Math.round(r*n)/n);return t.set(c,o),o},clear(){t.clear()}}}class z{constructor({getFn:e=d.getFn,fieldNormWeight:t=d.fieldNormWeight}={}){this.norm=Ae(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,S(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();S(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(!x(e)||P(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 r=i.getFn?i.getFn(e):this.getFn(e,i.path);if(x(r)){if(m(r)){let o=[];const l=[{nestedArrIndex:-1,value:r}];for(;l.length;){const{nestedArrIndex:a,value:h}=l.pop();if(x(h))if(S(h)&&!P(h)){let u={v:h,i:a,n:this.norm.get(h)};o.push(u)}else m(h)&&h.forEach((u,f)=>{l.push({nestedArrIndex:f,value:u})})}n.$[c]=o}else if(S(r)&&!P(r)){let o={v:r,n:this.norm.get(r)};n.$[c]=o}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function te(s,e,{getFn:t=d.getFn,fieldNormWeight:n=d.fieldNormWeight}={}){const i=new z({getFn:t,fieldNormWeight:n});return i.setKeys(s.map(Z)),i.setSources(e),i.create(),i}function Ie(s,{getFn:e=d.getFn,fieldNormWeight:t=d.fieldNormWeight}={}){const{keys:n,records:i}=s,c=new z({getFn:e,fieldNormWeight:t});return c.setKeys(n),c.setIndexRecords(i),c}function F(s,{errors:e=0,currentLocation:t=0,expectedLocation:n=0,distance:i=d.distance,ignoreLocation:c=d.ignoreLocation}={}){const r=e/s.length;if(c)return r;const o=Math.abs(n-t);return i?r+o/i:o?1:r}function be(s=[],e=d.minMatchCharLength){let t=[],n=-1,i=-1,c=0;for(let r=s.length;c<r;c+=1){let o=s[c];o&&n===-1?n=c:!o&&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 T=32;function _e(s,e,t,{location:n=d.location,distance:i=d.distance,threshold:c=d.threshold,findAllMatches:r=d.findAllMatches,minMatchCharLength:o=d.minMatchCharLength,includeMatches:l=d.includeMatches,ignoreLocation:a=d.ignoreLocation}={}){if(e.length>T)throw new Error(xe(T));const h=e.length,u=s.length,f=Math.max(0,Math.min(n,u));let g=c,p=f;const y=o>1||l,L=y?Array(u):[];let A;for(;(A=s.indexOf(e,p))>-1;){let E=F(e,{currentLocation:A,expectedLocation:f,distance:i,ignoreLocation:a});if(g=Math.min(E,g),p=A+h,y){let b=0;for(;b<h;)L[A+b]=1,b+=1}}p=-1;let $=[],k=1,j=h+u;const Ze=1<<h-1;for(let E=0;E<h;E+=1){let b=0,_=j;for(;b<_;)F(e,{errors:E,currentLocation:f+_,expectedLocation:f,distance:i,ignoreLocation:a})<=g?b=_:j=_,_=Math.floor((j-b)/2+b);j=_;let he=Math.max(1,f-_+1),Y=r?u:Math.min(f+_,u)+h,N=Array(Y+2);N[Y+1]=(1<<E)-1;for(let w=Y;w>=he;w-=1){let H=w-1,ue=t[s.charAt(H)];if(y&&(L[H]=+!!ue),N[w]=(N[w+1]<<1|1)&ue,E&&(N[w]|=($[w+1]|$[w])<<1|1|$[w+1]),N[w]&Ze&&(k=F(e,{errors:E,currentLocation:H,expectedLocation:f,distance:i,ignoreLocation:a}),k<=g)){if(g=k,p=H,p<=f)break;he=Math.max(1,2*f-p)}}if(F(e,{errors:E+1,currentLocation:f,expectedLocation:f,distance:i,ignoreLocation:a})>g)break;$=N}const U={isMatch:p>=0,score:Math.max(.001,k)};if(y){const E=be(L,o);E.length?l&&(U.indices=E):U.isMatch=!1}return U}function Re(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 se{constructor(e,{location:t=d.location,threshold:n=d.threshold,distance:i=d.distance,includeMatches:c=d.includeMatches,findAllMatches:r=d.findAllMatches,minMatchCharLength:o=d.minMatchCharLength,isCaseSensitive:l=d.isCaseSensitive,ignoreLocation:a=d.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:i,includeMatches:c,findAllMatches:r,minMatchCharLength:o,isCaseSensitive:l,ignoreLocation:a},this.pattern=l?e:e.toLowerCase(),this.chunks=[],!this.pattern.length)return;const h=(f,g)=>{this.chunks.push({pattern:f,alphabet:Re(f),startIndex:g})},u=this.pattern.length;if(u>T){let f=0;const g=u%T,p=u-g;for(;f<p;)h(this.pattern.substr(f,T),f),f+=T;if(g){const y=u-T;h(this.pattern.substr(y),y)}}else h(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:r,findAllMatches:o,minMatchCharLength:l,ignoreLocation:a}=this.options;let h=[],u=0,f=!1;this.chunks.forEach(({pattern:p,alphabet:y,startIndex:L})=>{const{isMatch:A,score:$,indices:k}=_e(e,p,y,{location:i+L,distance:c,threshold:r,findAllMatches:o,minMatchCharLength:l,includeMatches:n,ignoreLocation:a});A&&(f=!0),u+=$,A&&k&&(h=[...h,...k])});let g={isMatch:f,score:f?u/this.chunks.length:1};return f&&n&&(g.indices=h),g}}class I{constructor(e){this.pattern=e}static isMultiMatch(e){return ie(e,this.multiRegex)}static isSingleMatch(e){return ie(e,this.singleRegex)}search(){}}function ie(s,e){const t=s.match(e);return t?t[1]:null}class ve extends I{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 Te extends I{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 ke extends I{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 Oe extends I{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 $e extends I{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 Ne extends I{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 ne extends I{constructor(e,{location:t=d.location,threshold:n=d.threshold,distance:i=d.distance,includeMatches:c=d.includeMatches,findAllMatches:r=d.findAllMatches,minMatchCharLength:o=d.minMatchCharLength,isCaseSensitive:l=d.isCaseSensitive,ignoreLocation:a=d.ignoreLocation}={}){super(e),this._bitapSearch=new se(e,{location:t,threshold:n,distance:i,includeMatches:c,findAllMatches:r,minMatchCharLength:o,isCaseSensitive:l,ignoreLocation:a})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class re extends I{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 r=!!i.length;return{isMatch:r,score:r?0:1,indices:i}}}const K=[ve,re,ke,Oe,Ne,$e,Te,ne],ce=K.length,Fe=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Ce="|";function je(s,e={}){return s.split(Ce).map(t=>{let n=t.trim().split(Fe).filter(c=>c&&!!c.trim()),i=[];for(let c=0,r=n.length;c<r;c+=1){const o=n[c];let l=!1,a=-1;for(;!l&&++a<ce;){const h=K[a];let u=h.isMultiMatch(o);u&&(i.push(new h(u,e)),l=!0)}if(!l)for(a=-1;++a<ce;){const h=K[a];let u=h.isSingleMatch(o);if(u){i.push(new h(u,e));break}}}return i})}const He=new Set([ne.type,re.type]);class Pe{constructor(e,{isCaseSensitive:t=d.isCaseSensitive,includeMatches:n=d.includeMatches,minMatchCharLength:i=d.minMatchCharLength,ignoreLocation:c=d.ignoreLocation,findAllMatches:r=d.findAllMatches,location:o=d.location,threshold:l=d.threshold,distance:a=d.distance}={}){this.query=null,this.options={isCaseSensitive:t,includeMatches:n,minMatchCharLength:i,findAllMatches:r,ignoreLocation:c,location:o,threshold:l,distance:a},this.pattern=t?e:e.toLowerCase(),this.query=je(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,r=[],o=0;for(let l=0,a=t.length;l<a;l+=1){const h=t[l];r.length=0,c=0;for(let u=0,f=h.length;u<f;u+=1){const g=h[u],{isMatch:p,indices:y,score:L}=g.search(e);if(p){if(c+=1,o+=L,n){const A=g.constructor.type;He.has(A)?r=[...r,...y]:r.push(y)}}else{o=0,c=0,r.length=0;break}}if(c){let u={isMatch:!0,score:o/c};return n&&(u.indices=r),u}}return{isMatch:!1,score:1}}}const W=[];function Be(...s){W.push(...s)}function D(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 se(s,e)}const C={AND:"$and",OR:"$or"},q={PATH:"$path",PATTERN:"$val"},V=s=>!!(s[C.AND]||s[C.OR]),ze=s=>!!s[q.PATH],Ke=s=>!m(s)&&Q(s)&&!V(s),oe=s=>({[C.AND]:Object.keys(s).map(e=>({[e]:s[e]}))});function le(s,e,{auto:t=!0}={}){const n=i=>{let c=Object.keys(i);const r=ze(i);if(!r&&c.length>1&&!V(i))return n(oe(i));if(Ke(i)){const l=r?i[q.PATH]:c[0],a=r?i[q.PATTERN]:i[l];if(!S(a))throw new Error(ye(l));const h={keyId:B(l),pattern:a};return t&&(h.searcher=D(a,e)),h}let o={children:[],operator:c[0]};return c.forEach(l=>{const a=i[l];m(a)&&a.forEach(h=>{o.children.push(n(h))})}),o};return V(s)||(s=oe(s)),n(s)}function We(s,{ignoreFieldNorm:e=d.ignoreFieldNorm}){s.forEach(t=>{let n=1;t.matches.forEach(({key:i,norm:c,score:r})=>{const o=i?i.weight:null;n*=Math.pow(r===0&&o?Number.EPSILON:r,(o||1)*(e?1:c))}),t.score=n})}function De(s,e){const t=s.matches;e.matches=[],x(t)&&t.forEach(n=>{if(!x(n.indices)||!n.indices.length)return;const{indices:i,value:c}=n;let r={indices:i,value:c};n.key&&(r.key=n.key.src),n.idx>-1&&(r.refIndex=n.idx),e.matches.push(r)})}function qe(s,e){e.score=s.score}function Ve(s,e,{includeMatches:t=d.includeMatches,includeScore:n=d.includeScore}={}){const i=[];return t&&i.push(De),n&&i.push(qe),s.map(c=>{const{idx:r}=c,o={item:e[r],refIndex:r};return i.length&&i.forEach(l=>{l(c,o)}),o})}class O{constructor(e,t={},n){this.options={...d,...t},this.options.useExtendedSearch,this._keyStore=new we(this.options.keys),this.setCollection(e,n)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof z))throw new Error(me);this._myIndex=t||te(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){x(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:r,ignoreFieldNorm:o}=this.options;let l=S(e)?S(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return We(l,{ignoreFieldNorm:o}),c&&l.sort(r),G(t)&&t>-1&&(l=l.slice(0,t)),Ve(l,this._docs,{includeMatches:n,includeScore:i})}_searchStringList(e){const t=D(e,this.options),{records:n}=this._myIndex,i=[];return n.forEach(({v:c,i:r,n:o})=>{if(!x(c))return;const{isMatch:l,score:a,indices:h}=t.searchIn(c);l&&i.push({item:c,idx:r,matches:[{score:a,value:c,norm:o,indices:h}]})}),i}_searchLogical(e){const t=le(e,this.options),n=(o,l,a)=>{if(!o.children){const{keyId:u,searcher:f}=o,g=this._findMatches({key:this._keyStore.get(u),value:this._myIndex.getValueForItemAtKeyId(l,u),searcher:f});return g&&g.length?[{idx:a,item:l,matches:g}]:[]}const h=[];for(let u=0,f=o.children.length;u<f;u+=1){const g=o.children[u],p=n(g,l,a);if(p.length)h.push(...p);else if(o.operator===C.AND)return[]}return h},i=this._myIndex.records,c={},r=[];return i.forEach(({$:o,i:l})=>{if(x(o)){let a=n(t,o,l);a.length&&(c[l]||(c[l]={idx:l,item:o,matches:[]},r.push(c[l])),a.forEach(({matches:h})=>{c[l].matches.push(...h)}))}}),r}_searchObjectList(e){const t=D(e,this.options),{keys:n,records:i}=this._myIndex,c=[];return i.forEach(({$:r,i:o})=>{if(!x(r))return;let l=[];n.forEach((a,h)=>{l.push(...this._findMatches({key:a,value:r[h],searcher:t}))}),l.length&&c.push({idx:o,item:r,matches:l})}),c}_findMatches({key:e,value:t,searcher:n}){if(!x(t))return[];let i=[];if(m(t))t.forEach(({v:c,i:r,n:o})=>{if(!x(c))return;const{isMatch:l,score:a,indices:h}=n.searchIn(c);l&&i.push({score:a,key:e,value:c,idx:r,norm:o,indices:h})});else{const{v:c,n:r}=t,{isMatch:o,score:l,indices:a}=n.searchIn(c);o&&i.push({score:l,key:e,value:c,norm:r,indices:a})}return i}}O.version="6.6.2",O.createIndex=te,O.parseIndex=Ie,O.config=d,O.parseQuery=le,Be(Pe);const Ue=`
2
2
  <style>
3
3
  :host {
4
- display: block;
4
+ display: flex;
5
+ box-sizing: border-box;
6
+ height: 100%;
7
+ overflow: hidden;
8
+ }
9
+ *, *:before, *:after {
10
+ box-sizing: inherit;
11
+ }
12
+ form {
13
+ height: 100%;
14
+ max-width: 100%;
15
+ display: flex;
16
+ flex-direction: column;
17
+ }
18
+ ul {
19
+ padding-left: 0;
20
+ margin-top: 0;
21
+ }
22
+ li {
23
+ list-style: none;
24
+ }
25
+ li span {
26
+ font-size: small;
27
+ overflow: hidden;
28
+ text-overflow: ellipsis;
29
+ white-space: nowrap;
30
+ }
31
+ label {
32
+ display: flex;
33
+ align-items: center;
34
+ }
35
+ details {
36
+ margin-bottom: 0.5rem;
37
+ }
38
+ details summary > * {
39
+ display: inline;
40
+ }
41
+ details summary {
42
+ display: flex;
43
+ align-items: center;
44
+ }
45
+ #details-filter summary {
46
+ justify-content: space-between;
47
+ }
48
+ #details-results summary {
49
+ list-style: none;
50
+ }
51
+ #details-filter summary svg,
52
+ #details-results summary svg {
53
+ width: 24px;
54
+ height: 24px;
55
+ transition: all ease-in-out 0.3s;
56
+ }
57
+ #details-results summary svg {
58
+ transform: rotate(-90deg);
59
+ }
60
+ #details-filter[open] summary svg {
61
+ transform: rotate(180deg);
62
+ }
63
+ #details-results[open] summary svg {
64
+ transform: rotate(0deg);
65
+ }
66
+ li span,
67
+ details summary {
68
+ text-transform: capitalize;
69
+ }
70
+ li,
71
+ label,
72
+ details,
73
+ input[type=checkbox],
74
+ input[type=radio] {
75
+ cursor: pointer;
76
+ }
77
+ input[type=checkbox],
78
+ input[type=radio] {
79
+ margin: 0;
80
+ margin-right: 0.5rem;
81
+ }
82
+ input[type=text] {
83
+ display: none;
84
+ width: 100%;
85
+ margin-bottom: 0.5rem;
86
+ }
87
+ section {
88
+ padding-left: 1rem;
89
+ padding-right: 1rem;
90
+ }
91
+ section:first-of-type {
92
+ padding-top: 1rem;
93
+ }
94
+ #section-results {
95
+ overflow: hidden;
96
+ flex: 1;
97
+ display: flex;
98
+ flex-direction: column;
99
+ }
100
+ #container-results {
101
+ margin-right: -1rem;
102
+ }
103
+ ul#results {
104
+ padding-right: 1rem;
105
+ }
106
+ ul#results li {
107
+ padding-left: 0.5rem;
108
+ }
109
+ .scroll {
110
+ height: 100%;
111
+ overflow-x: hidden;
112
+ overflow-y: auto;
5
113
  }
6
114
  </style>
7
- <div>
8
- <slot></slot>
9
- <ul id="filters"></ul>
10
- <input type="text" />
11
- <ul id="results"></ul>
12
- </div>
13
- `,Qe=`
115
+ <form>
116
+ <section>
117
+ <input type="text" placeholder="Search" />
118
+ </section>
119
+ <section>
120
+ <slot name="filterstitle"></slot>
121
+ <ul id="filters"></ul>
122
+ </section>
123
+ <section id="section-results">
124
+ <div>
125
+ <slot name="resultstitle"></slot>
126
+ </div>
127
+ <div id="container-results" class="scroll">
128
+ <ul id="results"></ul>
129
+ </div>
130
+ </section>
131
+ </form>
132
+ `,Ye=`
14
133
  <li>
15
134
  <label>
16
135
  <input type="checkbox" />
17
136
  <span class="title">FILTERITEMTITLE</span>
18
137
  </label>
19
138
  </li>
139
+ `,Ge=`
140
+ <details id="details-filter">
141
+ <summary>
142
+ <small>
143
+ <strong class="title">
144
+ FILTERTITLE
145
+ </strong>
146
+ </small>
147
+ <div>
148
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>chevron-down</title><path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" /></svg>
149
+ </div>
150
+ </summary>
151
+ <ul></ul>
152
+ </details>
153
+ `,Qe=`
154
+ <li>
155
+ <label>
156
+ <input type="radio" name="result" />
157
+ <span class="title">RESULTTITLE</span>
158
+ </label>
159
+ </li>
20
160
  `,Xe=`
21
- <details open>
22
- <summary>TITLE</summar>
161
+ <details id="details-results" open>
162
+ <summary>
163
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>chevron-down</title><path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" /></svg>
164
+ <strong class="title">
165
+ SUMMARYTITLE
166
+ </strong>
167
+ <span style="margin-left: 0.25rem">(<span class="count"></span>)</span>
168
+ </summary>
23
169
  <ul></ul>
24
170
  </details>
25
- `,Je=(t,e="highlight")=>{const s=(n,i,c)=>{const o=i.split(".");let a;for(a=0;a<o.length-1;a++)n=n[o[a]];n[o[a]]=c},r=(n,i=[])=>{let c="",o=0;return i.forEach(a=>{const h=a[1]+1;c+=[n.substring(o,a[0]),`<mark class="${e}">`,n.substring(a[0],h),"</mark>"].join(""),o=h}),c+=n.substring(o),c};return t.filter(({matches:n})=>n&&n.length).map(({item:n,matches:i})=>{const c={...n};return i.forEach(o=>{o.key==="name"&&s(c,o.key,r(o.value,o.indices))}),c})},he=document.createElement("template");he.innerHTML=Ue;class le extends HTMLElement{constructor(){super();A(this,"shadowRoot");A(this,"apply");A(this,"filterProperties");A(this,"items");A(this,"fuse");A(this,"filters");A(this,"aggregateBy");A(this,"aggregateResults");A(this,"fuseConfig");this.filters={},this.shadowRoot=this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(he.content.cloneNode(!0)),this.apply=n=>{this.items=n,this.fuse=new $(this.items,{minMatchCharLength:1,includeMatches:!0,keys:["name",...this.filterProperties],useExtendedSearch:!0,...this.fuseConfig}),this.filterProperties.forEach(i=>{const c=[...new Set(this.items.reduce((a,h)=>a.concat(h[i]),[]))].sort(),o=this.shadowRoot.querySelector("ul#filters");c.forEach(a=>{const h=document.createElement("template");h.innerHTML=Qe;const l=h.content.cloneNode(!0);l.querySelector("input[type='checkbox']").setAttribute("data-filter-key",i),l.querySelector("input[type='checkbox']").setAttribute("data-filter-value",a),l.querySelector("span.title").innerHTML=a,o.appendChild(l)}),this.aggregateResults===i&&(this.aggregateBy=c)}),s()};const s=()=>{this.shadowRoot.querySelectorAll("input[type='checkbox']").forEach(n=>{n.addEventListener("click",i=>{const c=i.target,o=c.getAttribute("data-filter-key"),a=c.getAttribute("data-filter-value");c.checked?(this.filters[o]||(this.filters[o]=[]),this.filters[o].push(a)):(this.filters[o].splice(this.filters[o].indexOf(a),1),this.filters[o].length===0&&delete this.filters[o]),r(this.shadowRoot.querySelector("input[type='text']").value)})})},r=(n,i=this.filters)=>{const c=Object.entries(i).reduce((h,[l,u])=>{const d=g=>{const p={};p[l]=`=${g}`,h.push(p)};return Array.isArray(u)?u.forEach(g=>d(g)):d(u),h},[]),o=Je(this.fuse.search({...n.length&&Object.keys(c).length?{$and:[{name:n},{$or:c}]}:{$or:[{name:n},{$or:c}]}})),a=this.shadowRoot.querySelector("ul#results");if(a.innerHTML="",this.aggregateResults){const h=document.createElement("template");h.innerHTML=Xe,this.aggregateBy.forEach(l=>{if(!o.find(d=>Array.isArray(d[this.aggregateResults])?d[this.aggregateResults].includes(l):d[this.aggregateResults]===l))return;const u=h.content.cloneNode(!0);u.querySelector("summary").innerHTML=l,u.querySelector("details").setAttribute("data-aggregate",l),a.appendChild(u)})}o.forEach(h=>{if(this.aggregateBy){const l=h[this.aggregateResults];if(Array.isArray(l))l.forEach(u=>{const d=document.createElement("li");d.innerHTML=h.name,this.shadowRoot.querySelector(`details[data-aggregate=${u}]`).appendChild(d)});else{const u=document.createElement("li");u.innerHTML=h.name,this.shadowRoot.querySelector(`details[data-aggregate=${l}]`).appendChild(u)}}else{const l=document.createElement("li");l.innerHTML=h.name,a.appendChild(l)}})};this.shadowRoot.querySelector("input[type='text']").addEventListener("input",n=>{r(n.target.value)})}}customElements.define("eox-itemfilter",le),M.EOxItemFilter=le,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
171
+ `,Je=(s,e="highlight")=>{const t=(i,c,r)=>{const o=c.split(".");let l;for(l=0;l<o.length-1;l++)i=i[o[l]];i[o[l]]=r},n=(i,c=[])=>{let r="",o=0;return c.forEach(l=>{const a=l[1]+1;r+=[i.substring(o,l[0]),`<mark class="${e}">`,i.substring(l[0],a),"</mark>"].join(""),o=a}),r+=i.substring(o),r};return s.filter(({matches:i})=>i&&i.length).map(({item:i,matches:c})=>{const r={...i};return c.forEach(o=>{o.key==="name"&&t(r,o.key,n(o.value,o.indices))}),r})};class ae extends HTMLElement{constructor(){super();R(this,"shadowRoot");R(this,"apply");R(this,"items");R(this,"fuse");R(this,"filters");R(this,"aggregateBy");R(this,"config");this.filters={},this.shadowRoot=this.attachShadow({mode:"open"});const t=document.createElement("template");t.innerHTML=Ue,this.shadowRoot.appendChild(t.content.cloneNode(!0)),this.apply=r=>{this.config.enableSearch&&(this.shadowRoot.querySelector("input[type=text").style.display="block"),this.items=r,this.fuse=new O(this.items,{minMatchCharLength:1,includeMatches:!0,keys:["name",...this.config.filterProperties],useExtendedSearch:!0,...this.config.fuseConfig}),this.config.filterProperties.forEach(o=>{const l=[...new Set(this.items.reduce((f,g)=>f.concat(g[o]),[]))].sort(),a=this.shadowRoot.querySelector("ul#filters"),h=document.createElement("template");h.innerHTML=Ge;const u=h.content.cloneNode(!0);u.querySelector(".title").innerHTML=o,u.querySelector("details").setAttribute("data-filter",o),a.appendChild(u),l.forEach(f=>{const g=document.createElement("template");g.innerHTML=Ye;const p=g.content.cloneNode(!0),y=p.querySelector("input[type='checkbox']");y.setAttribute("data-filter-key",o),y.setAttribute("name","filter"),this.config.exclusiveFilters===!0&&(y.type="radio"),y.setAttribute("data-filter-value",f),p.querySelector("span.title").innerHTML=f,this.shadowRoot.querySelector(`details[data-filter='${o}']`).appendChild(p)}),this.config.aggregateResults===o&&(this.aggregateBy=l)}),n(),this.config.matchAllWhenEmpty!==!1&&i(this.items)};const n=()=>{const r=this.shadowRoot.querySelectorAll(`input[type="${this.config.exclusiveFilters===!0?"radio":"checkbox"}"]`),o=l=>{r.forEach(a=>{var f,g;const h=a.getAttribute("data-filter-key"),u=a.getAttribute("data-filter-value");if(a.checked)this.filters[h]||(this.filters[h]=[]),this.filters[h].includes(u)||this.filters[h].push(u);else{if(l===a){if(!this.filters[h])return;this.filters[h].splice(this.filters[h].indexOf(u),1)}else this.config.exclusiveFilters===!0&&this.filters[h]&&this.filters[h].includes(u)&&((f=this.filters[h])==null||f.splice(this.filters[h].indexOf(u),1));((g=this.filters[h])==null?void 0:g.length)===0&&delete this.filters[h]}})};r.forEach(l=>{l.addEventListener("click",a=>{o(a.target),this.config.matchAllWhenEmpty!==!1&&Object.keys(this.filters).length===0?i(this.items):c(this.shadowRoot.querySelector("input[type='text']").value)})})},i=r=>{const o=this.shadowRoot.querySelector("ul#results");if(o.innerHTML="",this.config.aggregateResults){const l=document.createElement("template");l.innerHTML=Xe,this.aggregateBy.forEach(a=>{if(!r.find(u=>Array.isArray(u[this.config.aggregateResults])?u[this.config.aggregateResults].includes(a):u[this.config.aggregateResults]===a))return;const h=l.content.cloneNode(!0);h.querySelector("summary .title").innerHTML=a,h.querySelector("details").setAttribute("data-aggregate",a),o.appendChild(h)})}r.forEach(l=>{const a=document.createElement("template");a.innerHTML=Qe;const h=a.content.cloneNode(!0);h.querySelector(".title").innerHTML=l.name;let u;if(this.aggregateBy){const f=l[this.config.aggregateResults];Array.isArray(f)?f.forEach(g=>{u=this.shadowRoot.querySelector(`details[data-aggregate=${g}]`)}):u=this.shadowRoot.querySelector(`details[data-aggregate=${f}]`)}else u=o;h.querySelector("input").addEventListener("click",()=>{this.config.onSelect&&this.config.onSelect(l)}),u.appendChild(h)}),this.config.aggregateResults&&this.shadowRoot.querySelectorAll("#results details").forEach(a=>{a.querySelector("summary .count").innerHTML=a.querySelectorAll("li").length})},c=(r,o=this.filters)=>{const l=Object.entries(o).reduce((u,[f,g])=>{const p=y=>{const L={};L[f]=`=${y}`,u.push(L)};return Array.isArray(g)?g.forEach(y=>p(y)):p(g),u},[]),a=this.fuse.search({...r.length&&Object.keys(l).length?{$and:[{name:r},{$or:l}]}:{$or:[{name:r},{$or:l}]}}),h=this.config.enableHighlighting?Je(a):a.map(u=>u.item);i(h)};this.shadowRoot.querySelector("input[type='text']").addEventListener("input",r=>{const o=r.target.value;!o&&this.config.matchAllWhenEmpty!==!1?i(this.items):c(o)})}}customElements.define("eox-itemfilter",ae),M.EOxItemFilter=ae,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/itemfilter",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
6
  "@eox/eslint-config": "^1.0.0",
@@ -9,8 +9,17 @@ describe("Item Filter", () => {
9
9
  it("loads the itemfilter", () => {
10
10
  cy.get("eox-itemfilter").should(($el) => {
11
11
  const EOxItemFilter = <EOxItemFilter>$el[0];
12
- EOxItemFilter.filterProperties = ["themes", "code"];
13
- EOxItemFilter.aggregateResults = "themes";
12
+ EOxItemFilter.config = {
13
+ filterProperties: ["themes"],
14
+ aggregateResults: "themes",
15
+ enableSearch: true,
16
+ // enableHighlighting: false,
17
+ // onSelect: (item: any) => {
18
+ // console.log(item);
19
+ // },
20
+ // matchAllWhenEmpty: true,
21
+ // exclusiveFilters: true,
22
+ };
14
23
  EOxItemFilter.apply(testItems);
15
24
  });
16
25
  });
package/test/general.html CHANGED
@@ -3,14 +3,20 @@
3
3
  <head>
4
4
  <style>
5
5
  html,
6
- body {
6
+ body,
7
+ eox-itemfilter {
7
8
  padding: 0;
8
9
  margin: 0;
10
+ width: 100%;
11
+ height: 100%;
9
12
  }
10
13
  </style>
11
14
  <script type="module" defer src="../dist/eox-itemfilter.js"></script>
12
15
  </head>
13
16
  <body>
14
- <eox-itemfilter> Filter! </eox-itemfilter>
17
+ <eox-itemfilter>
18
+ <h4 slot="filterstitle">Filter</h4>
19
+ <h4 slot="resultstitle">Results</h4>
20
+ </eox-itemfilter>
15
21
  </body>
16
22
  </html>
@@ -0,0 +1,32 @@
1
+ import { EOxItemFilter } from "../src/main";
2
+ import testItems from "./testItems.json";
3
+
4
+ describe("Item Filter", () => {
5
+ beforeEach(() => {
6
+ cy.visit("/elements/itemfilter/test/general.html");
7
+ });
8
+
9
+ it("loads the itemfilter", () => {
10
+ cy.get("eox-itemfilter").should(($el) => {
11
+ const EOxItemFilter = <EOxItemFilter>$el[0];
12
+ EOxItemFilter.config = {
13
+ filterProperties: ["themes"],
14
+ aggregateResults: "themes",
15
+ enableSearch: true,
16
+ };
17
+ EOxItemFilter.apply(testItems);
18
+ });
19
+ cy.viewport(800, 700);
20
+ cy.wait(2000);
21
+ cy.viewport(600, 700);
22
+ cy.wait(2000);
23
+ cy.viewport(400, 700);
24
+ cy.wait(2000);
25
+ cy.viewport(800, 400);
26
+ cy.wait(2000);
27
+ cy.viewport(600, 400);
28
+ cy.wait(2000);
29
+ cy.viewport(400, 400);
30
+ cy.wait(2000);
31
+ });
32
+ });