import {J,na as Vc,nb as Bn}from'./main-WUGO6e7n.js';var c,h=J(()=>{c=class r{constructor(s=null,e=null,t=null,o=null,a=null){this.clone=()=>new r(this.name,this.tone,this.colors,this.theme,this.isCustom),this.name=s??"",this.tone=e,this.colors=t,this.theme=o,this.isCustom=a??!1;}get backgroundColor(){return (this.theme?.isDark?this.colors?.darkBackgroundColor:this.colors?.lightBackgroundColor)??null}get textColor(){return (this.theme?.isDark?this.colors?.darkTextColor:this.colors?.lightTextColor)??null}};});var g,C=J(()=>{Vc();h();g=class r{static{this.regexCache=new Map;}static toInt(s){return s.reduce((e,t)=>e|t,0)}static fromInt(s){let e=[],t=1;for(;s>0;)s&t&&(e.push(t),s^=t),t<<=1;return e}static sameTagNames(s,e){let t=s??[],o=e??[];if(t.length!==o.length)return !1;let a=new Set(o);return t.every(i=>a.has(i))}static getMatchPriority(s){switch(s){case Bn.ExactMatch:return 1;case Bn.Regex:return 2;case Bn.StartsWith:case Bn.EndsWith:return 3;case Bn.Contains:return 5;default:return 999}}static toCssHex(s){let e=(s??"").trim(),t=/^#([0-9a-fA-F]{2})([0-9a-fA-F]{6})$/.exec(e);return t?`#${t[2]}`:/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(e)?e:null}static resolveCustomTagColors(s,e){let t=r.getBestMatchingTagColor(e?.colors?.tagColors??[],s);return t?{lightBackgroundColor:r.toCssHex(t.colorHex),lightTextColor:r.toCssHex(t.foreColorHex),darkBackgroundColor:r.toCssHex(t.darkColorHex),darkTextColor:r.toCssHex(t.darkForeColorHex)}:null}static getBestMatchingTagColor(s,e){return s.filter(t=>r.isTagMatch(e,t)).sort((t,o)=>r.getMatchPriority(t.matchMode)-r.getMatchPriority(o.matchMode))[0]??null}static isTagMatch(s,e){if(!e.tagName)return !1;let t=e.caseSensitive?s:s.toLowerCase(),o=e.caseSensitive?e.tagName:e.tagName.toLowerCase();switch(e.matchMode){case Bn.StartsWith:return t.startsWith(o);case Bn.EndsWith:return t.endsWith(o);case Bn.Contains:return t.includes(o);case Bn.Regex:return r.isRegexMatch(s,e.tagName,e.caseSensitive);default:return t===o}}static isRegexMatch(s,e,t){let o=t?"":"i",a=`${o} ${e}`,i;if(r.regexCache.has(a))i=r.regexCache.get(a);else {try{i=new RegExp(e,o);}catch(m){i=null;}r.regexCache.set(a,i);}return i?.test(s)??!1}static toVMTags(s,e){if(!s)return null;let t=r.fromInt(s.systemTags).map(a=>new c(String(a),"brand")),o=(s.customTags??[]).filter(a=>!!a?.trim()).map(a=>new c(a,"brand",r.resolveCustomTagColors(a,e),e,!0));return [...t,...o]}};});export{C,g};