@eslint/config-inspector
Version:
A visual tool for inspecting and understanding your ESLint flat configs
3 lines (2 loc) • 29.2 kB
JavaScript
import{e as H,i as O,k as N,w as j,n as A,Z as Be,o as d,c as g,t as K,q as ze,s as M,p as x,a as y,$ as We,S as ie,D as oe,a0 as Se,a1 as Ke,h as He,b as U,F as $,d as z,l as Y,B as Ge,a2 as Ue,T as Ye,v as Je,x as ve,U as ee,y as X,a3 as Z,_ as Qe,z as ne,W as Xe,a4 as Ze}from"./_x1AcwyA.js";import{g as qe,s as xe,c as et,_ as tt,a as st}from"./Dd3cz-zO.js";const nt={key:1,op30:""},rt={key:2},it={op75:""},ot=H({__name:"ColorizedRuleName",props:{name:{},prefix:{},url:{},as:{},deprecated:{type:Boolean},borderless:{type:Boolean},break:{type:Boolean}},setup(t){const e=t,s=O(()=>{if(e.prefix)return e.name.startsWith(e.prefix)?{scope:e.prefix,name:e.name.slice(e.prefix.length).replace(/^\/+/,"")}:{scope:void 0,name:e.name};const r=e.name.split("/");return r.length===1?{scope:void 0,name:r[0]}:{scope:r[0],name:r.slice(1).join("/")}});return(r,i)=>(d(),N(Be(r.as||"div"),{"of-hidden":"","text-ellipsis":"","ws-nowrap":"","font-mono":"",class:A([r.deprecated?"line-through":"",r.borderless?"":"badge"])},{default:j(()=>[s.value.scope?(d(),g("span",{key:0,style:ze({color:("getPluginColor"in r?r.getPluginColor:M(qe))(s.value.scope)})},K(s.value.scope),5)):x("",!0),s.value.scope?(d(),g("span",nt,"/")):x("",!0),s.value.scope&&e.break?(d(),g("br",rt)):x("",!0),y("span",it,K(s.value.name),1)]),_:1},8,["class"]))}});function Ae(t){const e=`${t}`;return e.endsWith("1")&&t!==11?`${e}st`:e.endsWith("2")&&t!==12?`${e}nd`:e.endsWith("3")&&t!==13?`${e}rd`:`${t}th`}function _e(t){return lt(t).replace(/\[\s*'--',\s*(\S.+),\s*'--'\s*\],?/g,"$1, // [!code muted]")}function lt(t){return JSON.stringify(t,null,2).replace(/"(\w+)":/g,"$1:").replace(/"/g,"'")}const at=["title"],Re=H({__name:"RuleLevelIcon",props:{level:{},hasOptions:{type:Boolean},hasRedundantOptions:{type:Boolean},configIndex:{},class:{}},setup(t){const e=t,s=O(()=>e.configIndex==null?`Enabled as '${e.level}'`:`Enabled as '${e.level}', in the ${Ae(e.configIndex+1)} config item`),r=O(()=>({error:"text-red op80",warn:"text-yellow5 op80 dark:text-yellow4",off:"text-gray op50"})[e.level]),i=O(()=>({error:"i-ph-warning-circle-duotone",warn:"i-ph-warning-duotone",off:"i-ph-circle-half-tilt-duotone"})[e.level]);return(o,l)=>(d(),g("div",{relative:"",class:A([r.value,e.class]),title:s.value},[y("div",{class:A(i.value)},null,2),o.hasOptions?(d(),g("div",{key:0,absolute:"","right--2px":"","top--2px":"","h-6px":"","w-6px":"","rounded-full":"","bg-current":"",op75:"",class:A(o.hasRedundantOptions?"text-blue5":"")},null,2)):x("",!0)],10,at))}});function ct(t,e,s,r=!1){return{name:t,code(i){const o=i.children.filter(n=>n.type==="element"),l=[];o.forEach((n,c)=>{let h;for(const u of n.children){if(u.type!=="element")continue;const a=u.children[0];if(a.type!=="text")continue;let f=!1;a.value=a.value.replace(e,(...m)=>s.call(this,m,n,u,o,c)?(f=!0,""):m[0]),f&&!a.value.trim()&&(h=u)}if(h&&(n.children.splice(n.children.indexOf(h),1),n.children.length===0&&(l.push(n),r))){const u=i.children[i.children.indexOf(n)+1];u&&u.type==="text"&&u.value===`
`&&l.push(u)}});for(const n of l)i.children.splice(i.children.indexOf(n),1)}}}function ut(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ht(t={},e="@shikijs/transformers:notation-map"){const{classMap:s={},classActivePre:r=void 0}=t;return ct(e,new RegExp(`\\s*(?://|/\\*|<!--|#|--|%{1,2}|;{1,2}|"|')\\s+\\[!code (${Object.keys(s).map(ut).join("|")})(:\\d+)?\\]\\s*(?:\\*/|-->)?\\s*$`),function([i,o,l=":1"],n,c,h,u){const a=Number.parseInt(l.slice(1),10);return h.slice(u,u+a).forEach(f=>{this.addClassToHast(f,s[o])}),r&&this.addClassToHast(this.pre,r),!0})}const dt=H({name:"Shiki",props:{code:{type:String,required:!0},lang:{type:String,required:!0}},setup(t){const e=O(()=>xe.value?xe.value.codeToHtml(t.code,{lang:t.lang,theme:We.value?"vitesse-dark":"vitesse-light",transformers:[{pre(s){s.properties.style=""}},ht({classMap:{muted:"muted"}},"@shikijs/transformers:notation-muted")]}):et(t.code));return()=>ie("div",{class:"filter-hue-rotate-90",innerHTML:e.value})}});let le;function ke(t){return le=!0,["--",t,"--"]}function ae(t,e){if(e===void 0||typeof t!=typeof e)return t;if(t===e)return ke(t);if(typeof t=="object"&&t!==null&&e!==null){if(Array.isArray(t)&&Array.isArray(e)&&t.length===e.length)return t.length===0?ke(t):t.map((s,r)=>ae(s,e[r]));if(!Array.isArray(t)&&!Array.isArray(e))return Object.keys(t).reduce((r,i)=>(r[i]=ae(t[i],e[i]),r),{})}return t}function Ee(t,e){return le=!1,{options:t.map((r,i)=>ae(r,i<e.length?e[i]:void 0)),hasRedundantOptions:le}}const pt={"min-w-100":"",p4:"",flex:"~ col gap-2"},ft={flex:"~ gap-1 items-center"},gt={key:0,ml1:"",op50:""},mt={key:1,ml1:"",op50:""},yt={key:3,op50:""},vt={key:0,flex:"~ gap-2"},xt={flex:"~ col gap-2"},_t={flex:"~ gap-2 items-center wrap"},kt={"items-center":"","justify-between":"","md:flex":""},bt={flex:"~ gap-1",op50:""},Mt={key:2,op50:""},Ce=H({__name:"RuleStateItem",props:{state:{},isLocal:{type:Boolean}},setup(t){const e=t,s={error:"text-red",warn:"text-amber",off:"text-gray"},r=O(()=>oe.value.configs[e.state.configIndex]),i=O(()=>Se(e.state.name)),o=O(()=>Ee(e.state.options??[],i.value)),l=O(()=>{var u,a;return!((u=e.state.options)!=null&&u.length)&&((a=i.value)!=null&&a.length)?"default":"state"}),n=Ke({viewType:l.value}),c=He();function h(){Ge.rule=e.state.name,c.push("/configs")}return(u,a)=>{var I,w,R,k,E;const f=Re,m=tt,v=st,_=dt;return d(),g("div",pt,[y("div",ft,[U(f,{level:u.state.level,"config-index":u.state.configIndex},null,8,["level","config-index"]),u.state.level==="off"?(d(),g("span",gt,"Turned ")):(d(),g("span",mt,"Set to ")),y("span",{"font-mono":"",class:A(s[u.state.level])},K(u.state.level),3),u.isLocal?(d(),g("div",yt," in this config ")):(d(),g($,{key:2},[a[5]||(a[5]=y("span",{op50:""},"in",-1)),y("button",{hover:"!color-base","text-gray":"",onClick:a[0]||(a[0]=b=>h())},[r.value.name?(d(),N(m,{key:0,name:r.value.name,px2:"","font-mono":"",border:"~ base rounded"},null,8,["name"])):x("",!0),a[3]||(a[3]=y("span",{op50:""}," the ",-1)),z(" "+K(M(Ae)(u.state.configIndex+1))+" ",1),a[4]||(a[4]=y("span",{op50:""}," config item ",-1))])],64))]),u.isLocal?x("",!0):(d(),g("div",vt,[r.value.files?(d(),g($,{key:0},[a[7]||(a[7]=y("div",{"i-ph-file-magnifying-glass-duotone":"",my1:"","flex-none":"",op75:""},null,-1)),y("div",xt,[a[6]||(a[6]=y("div",{op50:""}," Applies to files matching ",-1)),y("div",_t,[(d(!0),g($,null,Y((I=r.value.files)==null?void 0:I.flat(),(b,F)=>(d(),N(v,{key:F,glob:b},null,8,["glob"]))),128))])])],64)):r.value.rules?(d(),g($,{key:1},[a[8]||(a[8]=y("div",{"i-ph-files-duotone":"",my1:"","flex-none":"",op75:""},null,-1)),a[9]||(a[9]=y("div",{op50:""}," Applied generally for all files ",-1))],64)):x("",!0)])),(w=u.state.options)!=null&&w.length||(R=i.value)!=null&&R.length?(d(),g($,{key:1},[y("div",kt,[y("div",bt,[(k=u.state.options)!=null&&k.length?(d(),g("button",{key:0,"btn-action":"",class:A({"btn-action-active":n.viewType==="state"}),onClick:a[1]||(a[1]=b=>n.viewType="state")},a[10]||(a[10]=[y("div",{"i-ph-sliders-duotone":"",my1:"","flex-none":"",op75:""},null,-1),z(" Rule options ")]),2)):x("",!0),(E=i.value)!=null&&E.length?(d(),g("button",{key:1,"btn-action":"",class:A({"btn-action-active":n.viewType==="default"}),onClick:a[2]||(a[2]=b=>n.viewType="default")},a[11]||(a[11]=[y("div",{"i-ph-faders-duotone":"",my1:"","flex-none":"",op75:""},null,-1),z(" Option defaults ")]),2)):x("",!0)])]),n.viewType==="state"?(d(!0),g($,{key:0},Y(o.value.options,(b,F)=>(d(),N(_,{key:F,lang:"ts",code:M(_e)(b),rounded:"","bg-code":"",p2:"","text-sm":""},null,8,["code"]))),128)):x("",!0),n.viewType==="default"?(d(!0),g($,{key:1},Y(i.value,(b,F)=>(d(),N(_,{key:F,lang:"ts",code:M(_e)(b),rounded:"","bg-code":"",p2:"","text-sm":""},null,8,["code"]))),128)):x("",!0)],64)):x("",!0),n.viewType==="state"&&o.value.hasRedundantOptions?(d(),g("div",Mt,a[12]||(a[12]=[z(" Options "),y("span",{italic:"",op75:""},"italicized",-1),z(" match the default for the rule ")]))):x("",!0)])}}}),wt={key:0,"max-h":"50vh"},It={flex:"~ items-center gap-2",p3:""},$t={key:2,grid:"~ cols-2 items-center gap1",mx2:""},St={key:0,"i-ph-check-square-duotone":"",op50:""},At={key:1},Rt={key:2,"i-ph-wrench-duotone":"",op50:""},Et={key:3},Ct={key:0,border:"~ red/25 rounded","bg-red:5":"",px1:"","text-xs":"","text-red":""},Lt={key:3,flex:"","flex-auto":"","flex-col":"","items-start":"","justify-end":""},Ot={flex:"~ gap-2",mt1:""},Nt={key:0,border:"~ red/25 rounded","bg-red:5":"",px1:"","text-xs":"","text-red":""},Tt={key:1,"i-ph-check-square-duotone":"",op50:""},Ft={key:2,"i-ph-wrench-duotone":"",op50:""},jt=H({__name:"RuleItem",props:{rule:{},ruleStates:{},value:{},class:{},gridView:{type:Boolean}},emits:["badgeClick","stateClick"],setup(t,{emit:e}){const s=t,r=e;function i(n){const{hasRedundantOptions:c}=Ee(n??[],Se(s.rule.name));return c}const{copy:o}=Ue();function l(n){return n&&n[0].toUpperCase()+n.slice(1)}return(n,c)=>{var v,_,I,w,R;const h=Re,u=Ce,a=Ye("VDropdown"),f=ot,m=Qe;return d(),g($,null,[n.ruleStates?(d(),g("div",{key:0,flex:"~ items-center gap-0.5 justify-end","text-lg":"",class:A(n.gridView?"absolute top-2 right-2 flex-col":"")},[(d(!0),g($,null,Y(n.ruleStates,(k,E)=>(d(),N(a,{key:E},{popper:j(({shown:b})=>[b?(d(),N(u,{key:0,state:k},null,8,["state"])):x("",!0)]),default:j(()=>{var b;return[U(h,{level:k.level,"config-index":k.configIndex,"has-options":!!((b=k.options)!=null&&b.length),"has-redundant-options":i(k.options)},null,8,["level","config-index","has-options","has-redundant-options"])]}),_:2},1024))),128))],2)):x("",!0),n.value!=null?(d(),g("div",{key:1,class:A([s.class,n.gridView?"absolute top-2 right-2 flex-col":""])},[U(h,{level:M(Je)(n.value),"has-options":!!((v=M(ve)(n.value))!=null&&v.length),"has-redundant-options":i(M(ve)(n.value))},null,8,["level","has-options","has-redundant-options"])],2)):x("",!0),y("div",{class:A(s.class)},[U(a,{"inline-block":""},{popper:j(({shown:k})=>{var E;return[k?(d(),g("div",wt,[y("div",It,[n.rule.invalid?x("",!0):(d(),N(m,{key:0,"btn-action-sm":"",to:(E=n.rule.docs)==null?void 0:E.url,target:"_blank",rel:"noopener noreferrer",title:"Docs"},{default:j(()=>c[2]||(c[2]=[y("div",{"i-ph-book-duotone":""},null,-1),z(" Docs ")])),_:1},8,["to"])),y("button",{"btn-action-sm":"",title:"Copy",onClick:c[1]||(c[1]=b=>M(o)(n.rule.name))},c[3]||(c[3]=[y("div",{"i-ph-copy-duotone":""},null,-1),z(" Copy name ")])),ee(n.$slots,"popup-actions")]),ee(n.$slots,"popup")])):x("",!0)]}),default:j(()=>[U(f,{name:n.rule.name,prefix:n.rule.plugin,deprecated:n.rule.deprecated,borderless:n.gridView,break:n.gridView,"text-start":"",as:"button",onClick:c[0]||(c[0]=k=>r("badgeClick",k))},null,8,["name","prefix","deprecated","borderless","break"])]),_:3})],2),n.gridView?x("",!0):(d(),g("div",$t,[(_=n.rule.docs)!=null&&_.recommended?X((d(),g("div",St,null,512)),[[M(Z),"✅ Recommended"]]):(d(),g("div",At)),n.rule.fixable?X((d(),g("div",Rt,null,512)),[[M(Z),"🔧 Fixable"]]):(d(),g("div",Et))])),y("div",{class:A(s.class),flex:"~ gap-2 items-center"},[y("div",{class:A([n.rule.deprecated?"line-through":"",n.rule.invalid?"text-red":"",n.gridView?"op50 text-sm":"op75 ws-nowrap of-hidden text-ellipsis line-clamp-1"])},K(n.rule.invalid?"Invalid rule has no description":l((I=n.rule.docs)==null?void 0:I.description)),3),!n.gridView&&(n.rule.invalid||n.rule.deprecated)?(d(),g("div",Ct,K(n.rule.invalid?"INVALID":"DEPRECATED"),1)):x("",!0)],2),n.gridView&&(n.rule.invalid||n.rule.deprecated||n.rule.fixable||(w=n.rule.docs)!=null&&w.recommended)?(d(),g("div",Lt,[y("div",Ot,[n.rule.invalid||n.rule.deprecated?(d(),g("div",Nt,K(n.rule.invalid?"INVALID":"DEPRECATED"),1)):x("",!0),(R=n.rule.docs)!=null&&R.recommended?X((d(),g("div",Tt,null,512)),[[M(Z),"✅ Recommended"]]):x("",!0),n.rule.fixable?X((d(),g("div",Ft,null,512)),[[M(Z),"🔧 Fixable"]]):x("",!0)])])):x("",!0)],64)}}}),$s=H({__name:"RuleList",props:{rules:{},getBind:{type:Function},filter:{type:Function}},setup(t){const e=t,s=O(()=>Array.isArray(e.rules)?e.rules.map(n=>n.name):Object.keys(e.rules)),r=function(n){return Array.isArray(e.rules)?e.rules.find(c=>c.name===n):Ze(n)},i=function(n){return Array.isArray(e.rules)?void 0:e.rules[n]},o=O(()=>ne.value?"grid grid-cols-[repeat(auto-fill,minmax(min(100%,350px),1fr))] gap-2":(Array.isArray(e.rules),"grid grid-cols-[max-content_max-content_max-content_1fr] gap-x-2 gap-y-2 items-center")),l=H({setup(n,{slots:c}){return()=>{var h,u;return ne.value?ie("div",{class:"relative border border-base max-w-full rounded-lg p4 py3 flex flex-col gap-2 of-hidden justify-start"},(h=c.default)==null?void 0:h.call(c)):ie($,(u=c.default)==null?void 0:u.call(c))}}});return(n,c)=>{const h=Ce,u=jt;return d(),g("div",{class:A(o.value)},[(d(!0),g($,null,Y(s.value,a=>{var f;return d(),g($,{key:a},[((f=e.filter)==null?void 0:f.call(e,a))!==!1?(d(),N(M(l),{key:0},{default:j(()=>{var m;return[U(u,Xe({rule:r(a),"rule-states":Array.isArray(n.rules)?M(oe).ruleToState.get(a)||[]:void 0,"grid-view":M(ne),value:i(a),ref_for:!0},(m=n.getBind)==null?void 0:m.call(n,a)),{popup:j(()=>[ee(n.$slots,"popup",{ruleName:a,value:i(a)},()=>[(d(!0),g($,null,Y(M(oe).ruleToState.get(a)||[],(v,_)=>(d(),N(h,{key:_,border:"t base",state:v},null,8,["state"]))),128))])]),"popup-actions":j(()=>[ee(n.$slots,"popup-actions",{ruleName:a})]),_:2},1040,["rule","rule-states","grid-view","value"])]}),_:2},1024)):x("",!0)],64)}),128))],2)}}});function P(t){return Array.isArray?Array.isArray(t):Ne(t)==="[object Array]"}function Pt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Vt(t){return t==null?"":Pt(t)}function T(t){return typeof t=="string"}function Le(t){return typeof t=="number"}function Dt(t){return t===!0||t===!1||Bt(t)&&Ne(t)=="[object Boolean]"}function Oe(t){return typeof t=="object"}function Bt(t){return Oe(t)&&t!==null}function S(t){return t!=null}function re(t){return!t.trim().length}function Ne(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const zt="Incorrect 'index' type",Wt=t=>`Invalid value for key ${t}`,Kt=t=>`Pattern length exceeds max of ${t}.`,Ht=t=>`Missing ${t} property in key`,Gt=t=>`Property 'weight' in key '${t}' must be a positive integer`,be=Object.prototype.hasOwnProperty;class Ut{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(r=>{let i=Te(r);this._keys.push(i),this._keyMap[i.id]=i,s+=i.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 Te(t){let e=null,s=null,r=null,i=1,o=null;if(T(t)||P(t))r=t,e=Me(t),s=ce(t);else{if(!be.call(t,"name"))throw new Error(Ht("name"));const l=t.name;if(r=l,be.call(t,"weight")&&(i=t.weight,i<=0))throw new Error(Gt(l));e=Me(l),s=ce(l),o=t.getFn}return{path:e,id:s,weight:i,src:r,getFn:o}}function Me(t){return P(t)?t:t.split(".")}function ce(t){return P(t)?t.join("."):t}function Yt(t,e){let s=[],r=!1;const i=(o,l,n)=>{if(S(o))if(!l[n])s.push(o);else{let c=l[n];const h=o[c];if(!S(h))return;if(n===l.length-1&&(T(h)||Le(h)||Dt(h)))s.push(Vt(h));else if(P(h)){r=!0;for(let u=0,a=h.length;u<a;u+=1)i(h[u],l,n+1)}else l.length&&i(h,l,n+1)}};return i(t,T(e)?e.split("."):e,0),r?s:s[0]}const Jt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Qt={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},Xt={location:0,threshold:.6,distance:100},Zt={useExtendedSearch:!1,getFn:Yt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var p={...Qt,...Jt,...Xt,...Zt};const qt=/[^ ]+/g;function es(t=1,e=3){const s=new Map,r=Math.pow(10,e);return{get(i){const o=i.match(qt).length;if(s.has(o))return s.get(o);const l=1/Math.pow(o,.5*t),n=parseFloat(Math.round(l*r)/r);return s.set(o,n),n},clear(){s.clear()}}}class ge{constructor({getFn:e=p.getFn,fieldNormWeight:s=p.fieldNormWeight}={}){this.norm=es(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,T(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();T(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(!S(e)||re(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((i,o)=>{let l=i.getFn?i.getFn(e):this.getFn(e,i.path);if(S(l)){if(P(l)){let n=[];const c=[{nestedArrIndex:-1,value:l}];for(;c.length;){const{nestedArrIndex:h,value:u}=c.pop();if(S(u))if(T(u)&&!re(u)){let a={v:u,i:h,n:this.norm.get(u)};n.push(a)}else P(u)&&u.forEach((a,f)=>{c.push({nestedArrIndex:f,value:a})})}r.$[o]=n}else if(T(l)&&!re(l)){let n={v:l,n:this.norm.get(l)};r.$[o]=n}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function Fe(t,e,{getFn:s=p.getFn,fieldNormWeight:r=p.fieldNormWeight}={}){const i=new ge({getFn:s,fieldNormWeight:r});return i.setKeys(t.map(Te)),i.setSources(e),i.create(),i}function ts(t,{getFn:e=p.getFn,fieldNormWeight:s=p.fieldNormWeight}={}){const{keys:r,records:i}=t,o=new ge({getFn:e,fieldNormWeight:s});return o.setKeys(r),o.setIndexRecords(i),o}function q(t,{errors:e=0,currentLocation:s=0,expectedLocation:r=0,distance:i=p.distance,ignoreLocation:o=p.ignoreLocation}={}){const l=e/t.length;if(o)return l;const n=Math.abs(r-s);return i?l+n/i:n?1:l}function ss(t=[],e=p.minMatchCharLength){let s=[],r=-1,i=-1,o=0;for(let l=t.length;o<l;o+=1){let n=t[o];n&&r===-1?r=o:!n&&r!==-1&&(i=o-1,i-r+1>=e&&s.push([r,i]),r=-1)}return t[o-1]&&o-r>=e&&s.push([r,o-1]),s}const W=32;function ns(t,e,s,{location:r=p.location,distance:i=p.distance,threshold:o=p.threshold,findAllMatches:l=p.findAllMatches,minMatchCharLength:n=p.minMatchCharLength,includeMatches:c=p.includeMatches,ignoreLocation:h=p.ignoreLocation}={}){if(e.length>W)throw new Error(Kt(W));const u=e.length,a=t.length,f=Math.max(0,Math.min(r,a));let m=o,v=f;const _=n>1||c,I=_?Array(a):[];let w;for(;(w=t.indexOf(e,v))>-1;){let C=q(e,{currentLocation:w,expectedLocation:f,distance:i,ignoreLocation:h});if(m=Math.min(C,m),v=w+u,_){let V=0;for(;V<u;)I[w+V]=1,V+=1}}v=-1;let R=[],k=1,E=u+a;const b=1<<u-1;for(let C=0;C<u;C+=1){let V=0,D=E;for(;V<D;)q(e,{errors:C,currentLocation:f+D,expectedLocation:f,distance:i,ignoreLocation:h})<=m?V=D:E=D,D=Math.floor((E-V)/2+V);E=D;let me=Math.max(1,f-D+1),se=l?a:Math.min(f+D,a)+u,G=Array(se+2);G[se+1]=(1<<C)-1;for(let L=se;L>=me;L-=1){let Q=L-1,ye=s[t.charAt(Q)];if(_&&(I[Q]=+!!ye),G[L]=(G[L+1]<<1|1)&ye,C&&(G[L]|=(R[L+1]|R[L])<<1|1|R[L+1]),G[L]&b&&(k=q(e,{errors:C,currentLocation:Q,expectedLocation:f,distance:i,ignoreLocation:h}),k<=m)){if(m=k,v=Q,v<=f)break;me=Math.max(1,2*f-v)}}if(q(e,{errors:C+1,currentLocation:f,expectedLocation:f,distance:i,ignoreLocation:h})>m)break;R=G}const F={isMatch:v>=0,score:Math.max(.001,k)};if(_){const C=ss(I,n);C.length?c&&(F.indices=C):F.isMatch=!1}return F}function rs(t){let e={};for(let s=0,r=t.length;s<r;s+=1){const i=t.charAt(s);e[i]=(e[i]||0)|1<<r-s-1}return e}class je{constructor(e,{location:s=p.location,threshold:r=p.threshold,distance:i=p.distance,includeMatches:o=p.includeMatches,findAllMatches:l=p.findAllMatches,minMatchCharLength:n=p.minMatchCharLength,isCaseSensitive:c=p.isCaseSensitive,ignoreLocation:h=p.ignoreLocation}={}){if(this.options={location:s,threshold:r,distance:i,includeMatches:o,findAllMatches:l,minMatchCharLength:n,isCaseSensitive:c,ignoreLocation:h},this.pattern=c?e:e.toLowerCase(),this.chunks=[],!this.pattern.length)return;const u=(f,m)=>{this.chunks.push({pattern:f,alphabet:rs(f),startIndex:m})},a=this.pattern.length;if(a>W){let f=0;const m=a%W,v=a-m;for(;f<v;)u(this.pattern.substr(f,W),f),f+=W;if(m){const _=a-W;u(this.pattern.substr(_),_)}}else u(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,includeMatches:r}=this.options;if(s||(e=e.toLowerCase()),this.pattern===e){let v={isMatch:!0,score:0};return r&&(v.indices=[[0,e.length-1]]),v}const{location:i,distance:o,threshold:l,findAllMatches:n,minMatchCharLength:c,ignoreLocation:h}=this.options;let u=[],a=0,f=!1;this.chunks.forEach(({pattern:v,alphabet:_,startIndex:I})=>{const{isMatch:w,score:R,indices:k}=ns(e,v,_,{location:i+I,distance:o,threshold:l,findAllMatches:n,minMatchCharLength:c,includeMatches:r,ignoreLocation:h});w&&(f=!0),a+=R,w&&k&&(u=[...u,...k])});let m={isMatch:f,score:f?a/this.chunks.length:1};return f&&r&&(m.indices=u),m}}class B{constructor(e){this.pattern=e}static isMultiMatch(e){return we(e,this.multiRegex)}static isSingleMatch(e){return we(e,this.singleRegex)}search(){}}function we(t,e){const s=t.match(e);return s?s[1]:null}class is extends B{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 os extends B{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 ls extends B{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 as extends B{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 cs extends B{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 us extends B{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 Pe extends B{constructor(e,{location:s=p.location,threshold:r=p.threshold,distance:i=p.distance,includeMatches:o=p.includeMatches,findAllMatches:l=p.findAllMatches,minMatchCharLength:n=p.minMatchCharLength,isCaseSensitive:c=p.isCaseSensitive,ignoreLocation:h=p.ignoreLocation}={}){super(e),this._bitapSearch=new je(e,{location:s,threshold:r,distance:i,includeMatches:o,findAllMatches:l,minMatchCharLength:n,isCaseSensitive:c,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class Ve extends B{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let s=0,r;const i=[],o=this.pattern.length;for(;(r=e.indexOf(this.pattern,s))>-1;)s=r+o,i.push([r,s-1]);const l=!!i.length;return{isMatch:l,score:l?0:1,indices:i}}}const ue=[is,Ve,ls,as,us,cs,os,Pe],Ie=ue.length,hs=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,ds="|";function ps(t,e={}){return t.split(ds).map(s=>{let r=s.trim().split(hs).filter(o=>o&&!!o.trim()),i=[];for(let o=0,l=r.length;o<l;o+=1){const n=r[o];let c=!1,h=-1;for(;!c&&++h<Ie;){const u=ue[h];let a=u.isMultiMatch(n);a&&(i.push(new u(a,e)),c=!0)}if(!c)for(h=-1;++h<Ie;){const u=ue[h];let a=u.isSingleMatch(n);if(a){i.push(new u(a,e));break}}}return i})}const fs=new Set([Pe.type,Ve.type]);class gs{constructor(e,{isCaseSensitive:s=p.isCaseSensitive,includeMatches:r=p.includeMatches,minMatchCharLength:i=p.minMatchCharLength,ignoreLocation:o=p.ignoreLocation,findAllMatches:l=p.findAllMatches,location:n=p.location,threshold:c=p.threshold,distance:h=p.distance}={}){this.query=null,this.options={isCaseSensitive:s,includeMatches:r,minMatchCharLength:i,findAllMatches:l,ignoreLocation:o,location:n,threshold:c,distance:h},this.pattern=s?e:e.toLowerCase(),this.query=ps(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:i}=this.options;e=i?e:e.toLowerCase();let o=0,l=[],n=0;for(let c=0,h=s.length;c<h;c+=1){const u=s[c];l.length=0,o=0;for(let a=0,f=u.length;a<f;a+=1){const m=u[a],{isMatch:v,indices:_,score:I}=m.search(e);if(v){if(o+=1,n+=I,r){const w=m.constructor.type;fs.has(w)?l=[...l,..._]:l.push(_)}}else{n=0,o=0,l.length=0;break}}if(o){let a={isMatch:!0,score:n/o};return r&&(a.indices=l),a}}return{isMatch:!1,score:1}}}const he=[];function ms(...t){he.push(...t)}function de(t,e){for(let s=0,r=he.length;s<r;s+=1){let i=he[s];if(i.condition(t,e))return new i(t,e)}return new je(t,e)}const te={AND:"$and",OR:"$or"},pe={PATH:"$path",PATTERN:"$val"},fe=t=>!!(t[te.AND]||t[te.OR]),ys=t=>!!t[pe.PATH],vs=t=>!P(t)&&Oe(t)&&!fe(t),$e=t=>({[te.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function De(t,e,{auto:s=!0}={}){const r=i=>{let o=Object.keys(i);const l=ys(i);if(!l&&o.length>1&&!fe(i))return r($e(i));if(vs(i)){const c=l?i[pe.PATH]:o[0],h=l?i[pe.PATTERN]:i[c];if(!T(h))throw new Error(Wt(c));const u={keyId:ce(c),pattern:h};return s&&(u.searcher=de(h,e)),u}let n={children:[],operator:o[0]};return o.forEach(c=>{const h=i[c];P(h)&&h.forEach(u=>{n.children.push(r(u))})}),n};return fe(t)||(t=$e(t)),r(t)}function xs(t,{ignoreFieldNorm:e=p.ignoreFieldNorm}){t.forEach(s=>{let r=1;s.matches.forEach(({key:i,norm:o,score:l})=>{const n=i?i.weight:null;r*=Math.pow(l===0&&n?Number.EPSILON:l,(n||1)*(e?1:o))}),s.score=r})}function _s(t,e){const s=t.matches;e.matches=[],S(s)&&s.forEach(r=>{if(!S(r.indices)||!r.indices.length)return;const{indices:i,value:o}=r;let l={indices:i,value:o};r.key&&(l.key=r.key.src),r.idx>-1&&(l.refIndex=r.idx),e.matches.push(l)})}function ks(t,e){e.score=t.score}function bs(t,e,{includeMatches:s=p.includeMatches,includeScore:r=p.includeScore}={}){const i=[];return s&&i.push(_s),r&&i.push(ks),t.map(o=>{const{idx:l}=o,n={item:e[l],refIndex:l};return i.length&&i.forEach(c=>{c(o,n)}),n})}class J{constructor(e,s={},r){this.options={...p,...s},this.options.useExtendedSearch,this._keyStore=new Ut(this.options.keys),this.setCollection(e,r)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof ge))throw new Error(zt);this._myIndex=s||Fe(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){S(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const s=[];for(let r=0,i=this._docs.length;r<i;r+=1){const o=this._docs[r];e(o,r)&&(this.removeAt(r),r-=1,i-=1,s.push(o))}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:i,shouldSort:o,sortFn:l,ignoreFieldNorm:n}=this.options;let c=T(e)?T(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return xs(c,{ignoreFieldNorm:n}),o&&c.sort(l),Le(s)&&s>-1&&(c=c.slice(0,s)),bs(c,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e){const s=de(e,this.options),{records:r}=this._myIndex,i=[];return r.forEach(({v:o,i:l,n})=>{if(!S(o))return;const{isMatch:c,score:h,indices:u}=s.searchIn(o);c&&i.push({item:o,idx:l,matches:[{score:h,value:o,norm:n,indices:u}]})}),i}_searchLogical(e){const s=De(e,this.options),r=(n,c,h)=>{if(!n.children){const{keyId:a,searcher:f}=n,m=this._findMatches({key:this._keyStore.get(a),value:this._myIndex.getValueForItemAtKeyId(c,a),searcher:f});return m&&m.length?[{idx:h,item:c,matches:m}]:[]}const u=[];for(let a=0,f=n.children.length;a<f;a+=1){const m=n.children[a],v=r(m,c,h);if(v.length)u.push(...v);else if(n.operator===te.AND)return[]}return u},i=this._myIndex.records,o={},l=[];return i.forEach(({$:n,i:c})=>{if(S(n)){let h=r(s,n,c);h.length&&(o[c]||(o[c]={idx:c,item:n,matches:[]},l.push(o[c])),h.forEach(({matches:u})=>{o[c].matches.push(...u)}))}}),l}_searchObjectList(e){const s=de(e,this.options),{keys:r,records:i}=this._myIndex,o=[];return i.forEach(({$:l,i:n})=>{if(!S(l))return;let c=[];r.forEach((h,u)=>{c.push(...this._findMatches({key:h,value:l[u],searcher:s}))}),c.length&&o.push({idx:n,item:l,matches:c})}),o}_findMatches({key:e,value:s,searcher:r}){if(!S(s))return[];let i=[];if(P(s))s.forEach(({v:o,i:l,n})=>{if(!S(o))return;const{isMatch:c,score:h,indices:u}=r.searchIn(o);c&&i.push({score:h,key:e,value:o,idx:l,norm:n,indices:u})});else{const{v:o,n:l}=s,{isMatch:n,score:c,indices:h}=r.searchIn(o);n&&i.push({score:c,key:e,value:o,norm:l,indices:h})}return i}}J.version="7.0.0";J.createIndex=Fe;J.parseIndex=ts;J.config=p;J.parseQuery=De;ms(gs);export{J as F,Ce as _,$s as a,dt as b,ot as c,Re as d,lt as s};