metacubexd/assets/Rules-DrUtyF7O.js

10 lines
24 KiB
JavaScript
Raw Normal View History

import{A as $,aY as Ce,aZ as Oe,a_ as ae,q as te,as as Ae,o as B,p as we,at as Me,a$ as Te,b0 as ze,b as _e,y as Re,u as ke,b1 as Pe,D as ce,i as f,f as M,g as _,$ as $e,a0 as J,F as Ue,B as ue,aS as he,S as H,d as q,ag as Z,t as U,l as Ve}from"./index-DWMGWNy8.js";import{f as Ne}from"./global-BCvoRSag.js";const Fe=()=>{const[n,i]=$([]),[e,t]=$([]),s=async()=>{const[{rules:o},{providers:a}]=await Promise.all([Ce(),Oe()]);i(Object.values(o)),t(Object.values(a))};return{rules:n,ruleProviders:e,updateRules:s,updateAllRuleProvider:async()=>{await Promise.all(e().map(o=>ae(o.name))),await s()},updateRuleProviderByName:async o=>{await ae(o),await s()}}};function P(n,i,e){let t=e.initialDeps??[],s;return()=>{var r,l,o,a;let u;e.key&&((r=e.debug)!=null&&r.call(e))&&(u=Date.now());const c=n();if(!(c.length!==t.length||c.some((y,m)=>t[m]!==y)))return s;t=c;let v;if(e.key&&((l=e.debug)!=null&&l.call(e))&&(v=Date.now()),s=i(...c),e.key&&((o=e.debug)!=null&&o.call(e))){const y=Math.round((Date.now()-u)*100)/100,m=Math.round((Date.now()-v)*100)/100,A=m/16,E=(S,T)=>{for(S=String(S);S.length<T;)S=" "+S;return S};console.info(`%c⏱ ${E(m,5)} /${E(y,5)} ms`,`
font-size: .6rem;
font-weight: bold;
color: hsl(${Math.max(0,Math.min(120-120*A,120))}deg 100% 31%);`,e==null?void 0:e.key)}return(a=e==null?void 0:e.onChange)==null||a.call(e,s),s}}function ee(n,i){if(n===void 0)throw new Error("Unexpected undefined");return n}const We=(n,i)=>Math.abs(n-i)<1,De=(n,i,e)=>{let t;return function(...s){n.clearTimeout(t),t=n.setTimeout(()=>i.apply(this,s),e)}},je=n=>n,He=n=>{const i=Math.max(n.startIndex-n.overscan,0),e=Math.min(n.endIndex+n.overscan,n.count-1),t=[];for(let s=i;s<=e;s++)t.push(s);return t},Be=(n,i)=>{const e=n.scrollElement;if(!e)return;const t=n.targetWindow;if(!t)return;const s=l=>{const{width:o,height:a}=l;i({width:Math.round(o),height:Math.round(a)})};if(s(e.getBoundingClientRect()),!t.ResizeObserver)return()=>{};const r=new t.ResizeObserver(l=>{const o=l[0];if(o!=null&&o.borderBoxSize){const a=o.borderBoxSize[0];if(a){s({width:a.inlineSize,height:a.blockSize});return}}s(e.getBoundingClientRect())});return r.observe(e,{box:"border-box"}),()=>{r.unobserve(e)}},de={passive:!0},Ke=typeof window>"u"?!0:"onscrollend"in window,Le=(n,i)=>{const e=n.scrollElement;if(!e)return;const t=n.targetWindow;if(!t)return;let s=0;const r=Ke?()=>{}:De(t,()=>{i(s,!1)},n.options.isScrollingResetDelay),l=u=>()=>{const{horizontal:c,isRtl:h}=n.options;s=c?e.scrollLeft*(h&&-1||1):e.scrollTop,r(),i(s,u)},o=l(!0),a=l(!1);return a(),e.addEventListener("scroll",o,de),e.addEventListener("scrollend",a,de),()=>{e.removeEventListener("scroll",o),e.removeEventListener("scrollend",a)}},Ye=(n,i,e)=>{if(i!=null&&i.borderBoxSize){const t=i.borderBoxSize[0];if(t)return Math.round(t[e.options.horizontal?"inlineSize":"blockSize"])}return Math.round(n.getBoundingClientRect()[e.options.horizontal?"width":"height"])},Qe=(n,{adjustments:i=0,behavior:e},t)=>{var s,r;const l=n+i;(r=(s=t.scrollElement)==null?void 0:s.scrollTo)==null||r.call(s,{[t.options.horizontal?"left":"top"]:l,behavior:e})};class Xe{constructor(i){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollToIndexTimeoutId=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.pendingMeasuredCacheIndexes=[],this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let e=null;const t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(s=>{s.forEach(r=>{this._measureElement(r.target,r)})}));return{disconnect:()=>{var s;(s=t())==null||s.disconnect(),e=null},observe:s=>{var r;return(r=t())==null?void 0:r.observe(s,{box:"border-box"})},unobserve:s=>{var r;return(r=t())==null?void 0:r.unobserve(s)}}})(),this.range=null,this.setOptions=e=>{Object.entries(e).forEach(([t,s])=>{typeof s>"u"&&delete e[t]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:je,rangeExtractor:He,onChange:()=>{},measureElement:Ye,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,...e}},this.notify=e=>{var t,s;(s=(t=this.options).onChange)==null||s.call(t,this,e)},this.maybeNotify=P(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var e;const t=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==t){if(this.cleanup(),!t){this.maybeNotify();return}this.scrollElement=t,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((e=this.scrollElement)==null?void 0:e.window)??null,thi
* @name match-sorter
* @license MIT license.
* @copyright (c) 2020 Kent C. Dodds
* @author Kent C. Dodds <me@kentcdodds.com> (https://kentcdodds.com)
*/const x={CASE_SENSITIVE_EQUAL:7,EQUAL:6,STARTS_WITH:5,WORD_STARTS_WITH:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0},it=(n,i)=>String(n.rankedValue).localeCompare(String(i.rankedValue));function se(n,i,e){e===void 0&&(e={});const{keys:t,threshold:s=x.MATCHES,baseSort:r=it,sorter:l=u=>u.sort((c,h)=>at(c,h,r))}=e,o=n.reduce(a,[]);return l(o).map(u=>{let{item:c}=u;return c});function a(u,c,h){const v=rt(c,t,i,e),{rank:y,keyThreshold:m=s}=v;return y>=m&&u.push({...v,item:c,index:h}),u}}se.rankings=x;function rt(n,i,e,t){if(!i){const r=n;return{rankedValue:r,rank:me(r,e,t),keyIndex:-1,keyThreshold:t.threshold}}return ht(n,i).reduce((r,l,o)=>{let{rank:a,rankedValue:u,keyIndex:c,keyThreshold:h}=r,{itemValue:v,attributes:y}=l,m=me(v,e,t),A=u;const{minRanking:E,maxRanking:S,threshold:T}=y;return m<E&&m>=x.MATCHES?m=E:m>S&&(m=S),m>a&&(a=m,c=o,h=T,A=v),{rankedValue:A,rank:a,keyIndex:c,keyThreshold:h}},{rankedValue:n,rank:x.NO_MATCH,keyIndex:-1,keyThreshold:t.threshold})}function me(n,i,e){return n=ge(n,e),i=ge(i,e),i.length>n.length?x.NO_MATCH:n===i?x.CASE_SENSITIVE_EQUAL:(n=n.toLowerCase(),i=i.toLowerCase(),n===i?x.EQUAL:n.startsWith(i)?x.STARTS_WITH:n.includes(` ${i}`)?x.WORD_STARTS_WITH:n.includes(i)?x.CONTAINS:i.length===1?x.NO_MATCH:lt(n).includes(i)?x.ACRONYM:ot(n,i))}function lt(n){let i="";return n.split(" ").forEach(t=>{t.split("-").forEach(r=>{i+=r.substr(0,1)})}),i}function ot(n,i){let e=0,t=0;function s(a,u,c){for(let h=c,v=u.length;h<v;h++)if(u[h]===a)return e+=1,h+1;return-1}function r(a){const u=1/a,c=e/i.length;return x.MATCHES+c*u}const l=s(i[0],n,0);if(l<0)return x.NO_MATCH;t=l;for(let a=1,u=i.length;a<u;a++){const c=i[a];if(t=s(c,n,t),!(t>-1))return x.NO_MATCH}const o=t-l;return r(o)}function at(n,i,e){const{rank:r,keyIndex:l}=n,{rank:o,keyIndex:a}=i;return r===o?l===a?e(n,i):l<a?-1:1:r>o?-1:1}function ge(n,i){let{keepDiacritics:e}=i;return n=`${n}`,e||(n=nt(n)),n}function ct(n,i){typeof i=="object"&&(i=i.key);let e;if(typeof i=="function")e=i(n);else if(n==null)e=null;else if(Object.hasOwnProperty.call(n,i))e=n[i];else{if(i.includes("."))return ut(i,n);e=null}return e==null?[]:Array.isArray(e)?e:[String(e)]}function ut(n,i){const e=n.split(".");let t=[i];for(let s=0,r=e.length;s<r;s++){const l=e[s];let o=[];for(let a=0,u=t.length;a<u;a++){const c=t[a];if(c!=null)if(Object.hasOwnProperty.call(c,l)){const h=c[l];h!=null&&o.push(h)}else l==="*"&&(o=o.concat(c))}t=o}return Array.isArray(t[0])?[].concat(...t):t}function ht(n,i){const e=[];for(let t=0,s=i.length;t<s;t++){const r=i[t],l=dt(r),o=ct(n,r);for(let a=0,u=o.length;a<u;a++)e.push({itemValue:o[a],attributes:l})}return e}const pe={maxRanking:1/0,minRanking:-1/0};function dt(n){return typeof n=="string"?pe:{...pe,...n}}var ve=U("<div class=relative>"),ft=U('<div class="flex h-full flex-col gap-2"><div class="flex items-center gap-2"><div class="tabs-boxed tabs gap-2"></div></div><input class="input input-sm input-bordered input-primary"><div class="flex-1 overflow-y-auto">'),mt=U('<button><span></span><div class="badge badge-sm">'),gt=U('<div class="badge badge-sm">'),pt=U('<div class="absolute inset-x-0 top-0 pb-2 last:pb-0"><div class="card card-bordered card-compact bg-base-200 p-4"><div class="flex items-center gap-2"><span class=break-all></span></div><div class="text-xs text-slate-500"> :: '),vt=U('<div class="absolute inset-x-0 top-0 pb-2 last:pb-0"><div class="card card-bordered card-compact bg-base-200 p-4"><div class="flex items-center gap-2 pr-8"><span class=break-all></span><div class="badge badge-sm"></div></div><div class="text-xs text-slate-500"> / <!> /<!> ');const xt=()=>{const n=_e();if(!Re())return n("/setup",{replace:!0}),null;const[i]=ke(),{rules:e,ruleProviders:t,updateRules:s,updateAllRuleProvider:r,updateRuleProviderByName:l}=Fe();B(s);const{map:o,setWithCallback:a}=Pe(),[u,c]=$(!1),h=(I,O)=>{I.stopPropagation(),a(O,()=>l(O))},v=async I=>{I.stopPropagation(),c(!0);try{await r()}catch{}c(!1)},[y,m]=$("rules"),A=()=>[{type:"rules",name:i("rules"),count:e().length},{type:"ruleProviders",name:i("ruleProviders"),count:t().length}],[E,S]=$("