yanki
Version:
A CLI tool and TypeScript library for syncing Markdown to Anki flashcards.
2 lines • 819 kB
JavaScript
var Am=Object.defineProperty;var s=(e,t)=>Am(e,"name",{value:t,configurable:!0});import Dm from"process";import Cm from"rehype-parse";import"node:path";import{webcrypto as Qo}from"node:crypto";const Bt={defaultMerge:Symbol("deepmerge-ts: default merge"),skip:Symbol("deepmerge-ts: skip")};Bt.defaultMerge;function Tm(e,t){return t}s(Tm,"defaultMetaDataUpdater");function ym(e,t){return e.filter(n=>n!==void 0)}s(ym,"defaultFilterValues");var Xo;(function(e){e[e.NOT=0]="NOT",e[e.RECORD=1]="RECORD",e[e.ARRAY=2]="ARRAY",e[e.SET=3]="SET",e[e.MAP=4]="MAP",e[e.OTHER=5]="OTHER"})(Xo||(Xo={}));function Jo(e){return typeof e!="object"||e===null?0:Array.isArray(e)?2:Sm(e)?1:e instanceof Set?3:e instanceof Map?4:5}s(Jo,"getObjectType");function bm(e){const t=new Set;for(const n of e)for(const r of[...Object.keys(n),...Object.getOwnPropertySymbols(n)])t.add(r);return t}s(bm,"getKeys");function km(e,t){return typeof e=="object"&&Object.prototype.propertyIsEnumerable.call(e,t)}s(km,"objectHasProperty");function Zo(e){let t=0,n=e[0]?.[Symbol.iterator]();return{[Symbol.iterator](){return{next(){do{if(n===void 0)return{done:!0,value:void 0};const r=n.next();if(r.done===!0){t+=1,n=e[t]?.[Symbol.iterator]();continue}return{done:!1,value:r.value}}while(!0)}}}}}s(Zo,"getIterableOfIterables");const el=["[object Object]","[object Module]"];function Sm(e){if(!el.includes(Object.prototype.toString.call(e)))return!1;const{constructor:t}=e;if(t===void 0)return!0;const n=t.prototype;return!(n===null||typeof n!="object"||!el.includes(Object.prototype.toString.call(n))||!n.hasOwnProperty("isPrototypeOf"))}s(Sm,"isRecord");function _m(e,t,n){const r={};for(const i of bm(e)){const u=[];for(const l of e)km(l,i)&&u.push(l[i]);if(u.length===0)continue;const a=t.metaDataUpdater(n,{key:i,parents:e}),o=tl(u,t,a);o!==Bt.skip&&(i==="__proto__"?Object.defineProperty(r,i,{value:o,configurable:!0,enumerable:!0,writable:!0}):r[i]=o)}return r}s(_m,"mergeRecords$1");function Bm(e){return e.flat()}s(Bm,"mergeArrays$1");function wm(e){return new Set(Zo(e))}s(wm,"mergeSets$1");function Fm(e){return new Map(Zo(e))}s(Fm,"mergeMaps$1");function Nm(e){return e.at(-1)}s(Nm,"mergeOthers$1");const Vr={mergeRecords:_m,mergeArrays:Bm,mergeSets:wm,mergeMaps:Fm,mergeOthers:Nm};function Le(...e){return xm({})(...e)}s(Le,"deepmerge");function xm(e,t){const n=Im(e,r);function r(...i){return tl(i,n,t)}return s(r,"customizedDeepmerge"),r}s(xm,"deepmergeCustom");function Im(e,t){return{defaultMergeFunctions:Vr,mergeFunctions:{...Vr,...Object.fromEntries(Object.entries(e).filter(([n,r])=>Object.hasOwn(Vr,n)).map(([n,r])=>r===!1?[n,Vr.mergeOthers]:[n,r]))},metaDataUpdater:e.metaDataUpdater??Tm,deepmerge:t,useImplicitDefaultMerging:e.enableImplicitDefaultMerging??!1,filterValues:e.filterValues===!1?void 0:e.filterValues??ym,actions:Bt}}s(Im,"getUtils");function tl(e,t,n){const r=t.filterValues?.(e,n)??e;if(r.length===0)return;if(r.length===1)return Es(r,t,n);const i=Jo(r[0]);if(i!==0&&i!==5){for(let u=1;u<r.length;u++)if(Jo(r[u])!==i)return Es(r,t,n)}switch(i){case 1:return vm(r,t,n);case 2:return Lm(r,t,n);case 3:return Om(r,t,n);case 4:return Rm(r,t,n);default:return Es(r,t,n)}}s(tl,"mergeUnknowns");function vm(e,t,n){const r=t.mergeFunctions.mergeRecords(e,t,n);return r===Bt.defaultMerge||t.useImplicitDefaultMerging&&r===void 0&&t.mergeFunctions.mergeRecords!==t.defaultMergeFunctions.mergeRecords?t.defaultMergeFunctions.mergeRecords(e,t,n):r}s(vm,"mergeRecords");function Lm(e,t,n){const r=t.mergeFunctions.mergeArrays(e,t,n);return r===Bt.defaultMerge||t.useImplicitDefaultMerging&&r===void 0&&t.mergeFunctions.mergeArrays!==t.defaultMergeFunctions.mergeArrays?t.defaultMergeFunctions.mergeArrays(e):r}s(Lm,"mergeArrays");function Om(e,t,n){const r=t.mergeFunctions.mergeSets(e,t,n);return r===Bt.defaultMerge||t.useImplicitDefaultMerging&&r===void 0&&t.mergeFunctions.mergeSets!==t.defaultMergeFunctions.mergeSets?t.defaultMergeFunctions.mergeSets(e):r}s(Om,"mergeSets");function Rm(e,t,n){const r=t.mergeFunctions.mergeMaps(e,t,n);return r===Bt.defaultMerge||t.useImplicitDefaultMerging&&r===void 0&&t.mergeFunctions.mergeMaps!==t.defaultMergeFunctions.mergeMaps?t.defaultMergeFunctions.mergeMaps(e):r}s(Rm,"mergeMaps");function Es(e,t,n){const r=t.mergeFunctions.mergeOthers(e,t,n);return r===Bt.defaultMerge||t.useImplicitDefaultMerging&&r===void 0&&t.mergeFunctions.mergeOthers!==t.defaultMergeFunctions.mergeOthers?t.defaultMergeFunctions.mergeOthers(e):r}s(Es,"mergeOthers");function Wn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}s(Wn,"getDefaultExportFromCjs");var Pm="addenda",Mm="aircraft",Um="algae",Hm="alumnae",$m="alumni",qm="alveoli",zm="amoebae",Ym="analyses",jm="antennae",Gm="antitheses",Vm="apices",Wm="appendices",Km="automata",Qm="axes",Xm="bacilli",Jm="bacteria",Zm="bacula",e1="barracks",t1="bases",n1="beaux",r1="bison",i1="buffalo",s1="bureaus",u1="cacti",a1="calves",o1="carcinomata",l1="carp",c1="censuses",h1="chassis",f1="cherubim",d1="children",p1="cloacae",m1="cod",g1="codices",E1="concerti",A1="consortia",D1="corpora",C1="crises",T1="criteria",y1="curricula",b1="cystomata",k1="data",S1="deer",_1="diagnoses",B1="dice",w1="dwarfs",F1="echoes",N1="elves",x1="elk",I1="ellipses",v1="embargoes",L1="emphases",O1="errata",R1="fezes",P1="firmware",M1="fish",U1="foci",H1="feet",$1="formulae",q1="fungi",z1="gallows",Y1="genera",j1="glomeruli",G1="geese",V1="graffiti",W1="grouse",K1="halves",Q1="hamuli",X1="heroes",J1="hippopotami",Z1="hooves",eg="hovercraft",tg="hypotheses",ng="ilia",rg="incubi",ig="indices",sg="interstitia",ug="kakapo",ag="knives",og="larvae",lg="leaves",cg="libretti",hg="lives",fg="loaves",dg="loculi",pg="loci",mg="lice",gg="men",Eg="matrices",Ag="means",Dg="measles",Cg="media",Tg="media",yg="memoranda",bg="millennia",kg="minutiae",Sg="moose",_g="mice",Bg="nebulae",wg="nemeses",Fg="neuroses",Ng="news",xg="nucleoli",Ig="nuclei",vg="oases",Lg="occipita",Og="offspring",Rg="omphaloi",Pg="opera",Mg="ova",Ug="oxen",Hg="paralyses",$g="parentheses",qg="people",zg="phenomena",Yg="phyla",jg="pike",Gg="polyhedra",Vg="potatoes",Wg="primi",Kg="prognoses",Qg="quizzes",Xg="radii",Jg="referenda",Zg="salmon",eE="scarves",tE="scrota",nE="selves",rE="seminomata",iE="series",sE="sheep",uE="shelves",aE="shrimp",oE="simulacra",lE="soliloquies",cE="spacecraft",hE="species",fE="spectra",dE="squid",pE="stimuli",mE="strata",gE="swine",EE="syconia",AE="syllabi",DE="symposia",CE="synopses",TE="syntheses",yE="tableaus",bE="testes",kE="those",SE="theses",_E="thieves",BE="thrombi",wE="tomatoes",FE="teeth",NE="tori",xE="trout",IE="tuna",vE="umbilici",LE="uteri",OE="vertebrae",RE="vertices",PE="vetoes",ME="vitae",UE="vortices",HE="watercraft",$E="wharves",qE="wives",zE="wolves",YE="women",jE={addendum:Pm,aircraft:Mm,alga:Um,alumna:Hm,alumnus:$m,alveolus:qm,amoeba:zm,analysis:Ym,antenna:jm,antithesis:Gm,apex:Vm,appendix:Wm,automaton:Km,axis:Qm,bacillus:Xm,bacterium:Jm,baculum:Zm,barracks:e1,basis:t1,beau:n1,bison:r1,buffalo:i1,bureau:s1,cactus:u1,calf:a1,carcinoma:o1,carp:l1,census:c1,chassis:h1,cherub:f1,child:d1,ch\u00E2teau:"ch\xE2teaus",cloaca:p1,cod:m1,codex:g1,concerto:E1,consortium:A1,corpus:D1,crisis:C1,criterion:T1,curriculum:y1,cystoma:b1,datum:k1,deer:S1,diagnosis:_1,die:B1,dwarf:w1,echo:F1,elf:N1,elk:x1,ellipsis:I1,embargo:v1,emphasis:L1,erratum:O1,"faux pas":"faux pas",fez:R1,firmware:P1,fish:M1,focus:U1,foot:H1,formula:$1,fungus:q1,gallows:z1,genus:Y1,glomerulus:j1,goose:G1,graffito:V1,grouse:W1,half:K1,hamulus:Q1,hero:X1,hippopotamus:J1,hoof:Z1,hovercraft:eg,hypothesis:tg,iliac:ng,incubus:rg,index:ig,interstitium:sg,kakapo:ug,knife:ag,larva:og,leaf:lg,libretto:cg,life:hg,loaf:fg,loculus:dg,locus:pg,louse:mg,man:gg,matrix:Eg,means:Ag,measles:Dg,media:Cg,medium:Tg,memorandum:yg,millennium:bg,minutia:kg,moose:Sg,mouse:_g,nebula:Bg,nemesis:wg,neurosis:Fg,news:Ng,nucleolus:xg,nucleus:Ig,oasis:vg,occiput:Lg,offspring:Og,omphalos:Rg,opus:Pg,ovum:Mg,ox:Ug,paralysis:Hg,parenthesis:$g,person:qg,phenomenon:zg,phylum:Yg,pike:jg,polyhedron:Gg,potato:Vg,primus:Wg,prognosis:Kg,quiz:Qg,radius:Xg,referendum:Jg,salmon:Zg,scarf:eE,scrotum:tE,self:nE,seminoma:rE,series:iE,sheep:sE,shelf:uE,shrimp:aE,simulacrum:oE,soliloquy:lE,spacecraft:cE,species:hE,spectrum:fE,squid:dE,stimulus:pE,stratum:mE,swine:gE,syconium:EE,syllabus:AE,symposium:DE,synopsis:CE,synthesis:TE,tableau:yE,testis:bE,that:kE,thesis:SE,thief:_E,this:"these",thrombus:BE,tomato:wE,tooth:FE,torus:NE,trout:xE,tuna:IE,umbilicus:vE,uterus:LE,vertebra:OE,vertex:RE,veto:PE,vita:ME,vortex:UE,watercraft:HE,wharf:$E,wife:qE,wolf:zE,woman:YE},As,nl;function GE(){if(nl)return As;nl=1;const e=jE;return As=new Map(Object.entries(e)),As}s(GE,"requireIrregularPlurals");var VE=GE(),rl=Wn(VE);function fn(e,t,n){if(typeof t=="number"&&(n=t),rl.has(e.toLowerCase())){t=rl.get(e.toLowerCase());const r=e.charAt(0);r===r.toUpperCase()&&(t=r+t.slice(1)),e===e.toUpperCase()&&(t=t.toUpperCase())}else typeof t!="string"&&(t=(e.replace(/(?:s|x|z|ch|sh)$/i,"$&e").replace(/([^aeiou])y$/i,"$1ie")+"s").replace(/i?e?s$/i,r=>e.slice(-1)===e.slice(-1).toLowerCase()?r.toLowerCase():r.toUpperCase()));return Math.abs(n)===1?e:t}s(fn,"plur");const il=s(e=>Number.isFinite(e)?e:0,"toZeroIfInfinity");function WE(e){return{days:Math.trunc(e/864e5),hours:Math.trunc(e/36e5%24),minutes:Math.trunc(e/6e4%60),seconds:Math.trunc(e/1e3%60),milliseconds:Math.trunc(e%1e3),microseconds:Math.trunc(il(e*1e3)%1e3),nanoseconds:Math.trunc(il(e*1e6)%1e3)}}s(WE,"parseNumber");function KE(e){return{days:e/86400000n,hours:e/3600000n%24n,minutes:e/60000n%60n,seconds:e/1000n%60n,milliseconds:e%1000n,microseconds:0n,nanoseconds:0n}}s(KE,"parseBigint");function QE(e){switch(typeof e){case"number":{if(Number.isFinite(e))return WE(e);break}case"bigint":return KE(e)}throw new TypeError("Expected a finite number or bigint")}s(QE,"parseMilliseconds");const XE=s(e=>e===0||e===0n,"isZero"),JE=s((e,t)=>t===1||t===1n?e:`${e}s`,"pluralize"),ZE=1e-7,e2=24n*60n*60n*1000n;function Ds(e,t){const n=typeof e=="bigint";if(!n&&!Number.isFinite(e))throw new TypeError("Expected a finite number or bigint");t={...t};const r=e<0?"-":"";e=e<0?-e:e,t.colonNotation&&(t.compact=!1,t.formatSubMilliseconds=!1,t.separateMilliseconds=!1,t.verbose=!1),t.compact&&(t.unitCount=1,t.secondsDecimalDigits=0,t.millisecondsDecimalDigits=0);let i=[];const u=s((f,h)=>{const m=Math.floor(f*10**h+ZE);return(Math.round(m)/10**h).toFixed(h)},"floorDecimals"),a=s((f,h,m,p)=>{if(!((i.length===0||!t.colonNotation)&&XE(f)&&!(t.colonNotation&&m==="m"))){if(p??=String(f),t.colonNotation){const g=p.includes(".")?p.split(".")[0].length:p.length,E=i.length>0?2:1;p="0".repeat(Math.max(0,E-g))+p}else p+=t.verbose?" "+JE(h,f):m;i.push(p)}},"add"),o=QE(e),l=BigInt(o.days);if(t.hideYearAndDays?a(BigInt(l)*24n+BigInt(o.hours),"hour","h"):(t.hideYear?a(l,"day","d"):(a(l/365n,"year","y"),a(l%365n,"day","d")),a(Number(o.hours),"hour","h")),a(Number(o.minutes),"minute","m"),!t.hideSeconds)if(t.separateMilliseconds||t.formatSubMilliseconds||!t.colonNotation&&e<1e3){const f=Number(o.seconds),h=Number(o.milliseconds),m=Number(o.microseconds),p=Number(o.nanoseconds);if(a(f,"second","s"),t.formatSubMilliseconds)a(h,"millisecond","ms"),a(m,"microsecond","\xB5s"),a(p,"nanosecond","ns");else{const g=h+m/1e3+p/1e6,E=typeof t.millisecondsDecimalDigits=="number"?t.millisecondsDecimalDigits:0,D=g>=1?Math.round(g):Math.ceil(g),A=E?g.toFixed(E):D;a(Number.parseFloat(A),"millisecond","ms",A)}}else{const f=(n?Number(e%e2):e)/1e3%60,h=typeof t.secondsDecimalDigits=="number"?t.secondsDecimalDigits:1,m=u(f,h),p=t.keepDecimalsOnWholeSeconds?m:m.replace(/\.0+$/,"");a(Number.parseFloat(p),"second","s",p)}if(i.length===0)return r+"0"+(t.verbose?" milliseconds":"ms");const c=t.colonNotation?":":" ";return typeof t.unitCount=="number"&&(i=i.slice(0,Math.max(t.unitCount,1))),r+i.join(c)}s(Ds,"prettyMilliseconds");var t2=Object.defineProperty,sl=s((e,t)=>t2(e,"name",{value:t,configurable:!0}),"a");const Wr=typeof window>"u"?typeof process>"u"?"other":"node":"browser",ul=Wr==="browser"?/windows/i.test(navigator.userAgent)?"windows":/mac/i.test(navigator.userAgent)?"mac":"other":Wr==="node"?process.platform==="win32"?"windows":process.platform==="darwin"?"mac":"other":"other";let Cs=0;const n2=5e3;let al=0;const r2=100;async function Ts(){if(ul==="mac"&&Wr==="node"){const{openApp:e}=await import("./index-DOC1EDpy.js");if(al>=r2){console.warn("Too many Anki App launch attempts this session, ignoring");return}(Cs===0||Date.now()-Cs>n2)&&(console.warn("Attempting to launch Anki app"),Cs=Date.now(),al++,await e("/Applications/Anki.app",{background:!0,newInstance:!1,wait:!1}))}else console.warn("Automatic Anki App launch is only supported on Mac OS in Node.js environment")}s(Ts,"h$1"),sl(Ts,"launchAnkiApp");const wt={autoLaunch:!1,fetchAdapter:fetch.bind(globalThis),host:"http://127.0.0.1",key:void 0,port:8765,version:6};class Kn{static{s(this,"f")}static{sl(this,"YankiConnect")}card={answerCards:this.build("answerCards"),areDue:this.build("areDue"),areSuspended:this.build("areSuspended"),cardsInfo:this.build("cardsInfo"),cardsModTime:this.build("cardsModTime"),cardsToNotes:this.build("cardsToNotes"),findCards:this.build("findCards"),forgetCards:this.build("forgetCards"),getEaseFactors:this.build("getEaseFactors"),getIntervals:this.build("getIntervals"),relearnCards:this.build("relearnCards"),setDueDate:this.build("setDueDate"),setEaseFactors:this.build("setEaseFactors"),setSpecificValueOfCard:this.build("setSpecificValueOfCard"),suspend:this.build("suspend"),suspended:this.build("suspended"),unsuspend:this.build("unsuspend")};deck={changeDeck:this.build("changeDeck"),cloneDeckConfigId:this.build("cloneDeckConfigId"),createDeck:this.build("createDeck"),deckNames:this.build("deckNames"),deckNamesAndIds:this.build("deckNamesAndIds"),deleteDecks:this.build("deleteDecks"),getDeckConfig:this.build("getDeckConfig"),getDecks:this.build("getDecks"),getDeckStats:this.build("getDeckStats"),removeDeckConfigId:this.build("removeDeckConfigId"),saveDeckConfig:this.build("saveDeckConfig"),setDeckConfigId:this.build("setDeckConfigId")};graphical={guiAddCards:this.build("guiAddCards"),guiAnswerCard:this.build("guiAnswerCard"),guiBrowse:this.build("guiBrowse"),guiCheckDatabase:this.build("guiCheckDatabase"),guiCurrentCard:this.build("guiCurrentCard"),guiDeckBrowser:this.build("guiDeckBrowser"),guiDeckOverview:this.build("guiDeckOverview"),guiDeckReview:this.build("guiDeckReview"),guiEditNote:this.build("guiEditNote"),guiExitAnki:this.build("guiExitAnki"),guiImportFile:this.build("guiImportFile"),guiSelectCard:this.build("guiSelectCard"),guiSelectedNotes:this.build("guiSelectedNotes"),guiSelectNote:this.build("guiSelectNote"),guiShowAnswer:this.build("guiShowAnswer"),guiShowQuestion:this.build("guiShowQuestion"),guiStartCardTimer:this.build("guiStartCardTimer"),guiUndo:this.build("guiUndo")};media={deleteMediaFile:this.build("deleteMediaFile"),getMediaDirPath:this.build("getMediaDirPath"),getMediaFilesNames:this.build("getMediaFilesNames"),retrieveMediaFile:this.build("retrieveMediaFile"),storeMediaFile:this.build("storeMediaFile")};miscellaneous={apiReflect:this.build("apiReflect"),exportPackage:this.build("exportPackage"),getActiveProfile:this.build("getActiveProfile"),getProfiles:this.build("getProfiles"),importPackage:this.build("importPackage"),loadProfile:this.build("loadProfile"),multi:this.build("multi"),reloadCollection:this.build("reloadCollection"),requestPermission:this.build("requestPermission"),sync:this.build("sync"),version:this.build("version")};model={createModel:this.build("createModel"),findAndReplaceInModels:this.build("findAndReplaceInModels"),findModelsById:this.build("findModelsById"),findModelsByName:this.build("findModelsByName"),modelFieldAdd:this.build("modelFieldAdd"),modelFieldDescriptions:this.build("modelFieldDescriptions"),modelFieldFonts:this.build("modelFieldFonts"),modelFieldNames:this.build("modelFieldNames"),modelFieldRemove:this.build("modelFieldRemove"),modelFieldRename:this.build("modelFieldRename"),modelFieldReposition:this.build("modelFieldReposition"),modelFieldSetDescription:this.build("modelFieldSetDescription"),modelFieldSetFont:this.build("modelFieldSetFont"),modelFieldSetFontSize:this.build("modelFieldSetFontSize"),modelFieldsOnTemplates:this.build("modelFieldsOnTemplates"),modelNames:this.build("modelNames"),modelNamesAndIds:this.build("modelNamesAndIds"),modelStyling:this.build("modelStyling"),modelTemplateAdd:this.build("modelTemplateAdd"),modelTemplateRemove:this.build("modelTemplateRemove"),modelTemplateRename:this.build("modelTemplateRename"),modelTemplateReposition:this.build("modelTemplateReposition"),modelTemplates:this.build("modelTemplates"),updateModelStyling:this.build("updateModelStyling"),updateModelTemplates:this.build("updateModelTemplates")};note={addNote:this.build("addNote"),addNotes:this.build("addNotes"),addTags:this.build("addTags"),canAddNotes:this.build("canAddNotes"),canAddNotesWithErrorDetail:this.build("canAddNotesWithErrorDetail"),clearUnusedTags:this.build("clearUnusedTags"),deleteNotes:this.build("deleteNotes"),findNotes:this.build("findNotes"),getNoteTags:this.build("getNoteTags"),getTags:this.build("getTags"),notesInfo:this.build("notesInfo"),notesModTime:this.build("notesInfo"),removeEmptyNotes:this.build("removeEmptyNotes"),removeTags:this.build("removeTags"),replaceTags:this.build("replaceTags"),replaceTagsInAllNotes:this.build("replaceTagsInAllNotes"),updateNote:this.build("updateNote"),updateNoteFields:this.build("updateNoteFields"),updateNoteModel:this.build("updateNoteModel"),updateNoteTags:this.build("updateNoteTags")};statistic={cardReviews:this.build("cardReviews"),getCollectionStatsHTML:this.build("getCollectionStatsHTML"),getLatestReviewID:this.build("getLatestReviewID"),getNumCardsReviewedByDay:this.build("getNumCardsReviewedByDay"),getNumCardsReviewedToday:this.build("getNumCardsReviewedToday"),getReviewsOfCards:this.build("getReviewsOfCards"),insertReviews:this.build("insertReviews")};autoLaunch;fetchAdapter;host;key;port;version;constructor(t){if(this.host=t?.host??wt.host,this.port=t?.port??wt.port,this.version=t?.version??wt.version,this.key=t?.key??wt.key,this.autoLaunch=t?.autoLaunch??wt.autoLaunch,wt.fetchAdapter===void 0)throw new Error("A fetch implementation is required");if(this.fetchAdapter=t?.fetchAdapter??wt.fetchAdapter,(ul!=="mac"||Wr!=="node")&&this.autoLaunch!==!1&&(console.warn("The autoLaunch option is only supported in a Node environment on macOS"),this.autoLaunch=!1),this.version!==6)throw new Error("YankiConnect currently only supports Anki-Connect API version 6");this.autoLaunch==="immediately"&&Ts()}async invoke(t,n){let r,i;try{if(r=await this.fetchAdapter(`${this.host}:${this.port}`,{body:JSON.stringify({action:t,...this.key===void 0?{}:{key:this.key},params:n,version:this.version}),headers:{"Access-Control-Allow-Origin":"*","Content-Type":"application/json"},method:"POST",mode:"cors"}),r===void 0)throw new Error("Anki-Connect response is undefined");if(r.status!==200)throw new Error(`Anki-Connect response status is ${r.status}`);if(i=await r.json(),this.autoLaunch!==!1&&i.error==="collection is not available")throw new Error(i.error)}catch(u){if(this.autoLaunch!==!1)return console.warn("Can't connect to Anki app, retrying with auto-launch..."),await Ts(),await new Promise(a=>{setTimeout(a,500)}),n===void 0?this.invoke(t):this.invoke(t,n);throw u}if(!("error"in i))throw new Error("response is missing required error field");if(!("result"in i))throw new Error("response is missing required result field");return i}build(t){return async n=>{const r=await this.invoke(t,n);if(r.error!==null)throw new Error(String(r.error));return r.result}}}let Ee=class extends Error{static{s(this,"ShikiError")}constructor(t){super(t),this.name="ShikiError"}};function i2(e){return ys(e)}s(i2,"clone");function ys(e){return Array.isArray(e)?s2(e):e instanceof RegExp?e:typeof e=="object"?u2(e):e}s(ys,"doClone");function s2(e){let t=[];for(let n=0,r=e.length;n<r;n++)t[n]=ys(e[n]);return t}s(s2,"cloneArray");function u2(e){let t={};for(let n in e)t[n]=ys(e[n]);return t}s(u2,"cloneObj");function ol(e,...t){return t.forEach(n=>{for(let r in n)e[r]=n[r]}),e}s(ol,"mergeObjects");function ll(e){const t=~e.lastIndexOf("/")||~e.lastIndexOf("\\");return t===0?e:~t===e.length-1?ll(e.substring(0,e.length-1)):e.substr(~t+1)}s(ll,"basename$1");var bs=/\$(\d+)|\${(\d+):\/(downcase|upcase)}/g,Kr=class{static{s(this,"RegexSource")}static hasCaptures(e){return e===null?!1:(bs.lastIndex=0,bs.test(e))}static replaceCaptures(e,t,n){return e.replace(bs,(r,i,u,a)=>{let o=n[parseInt(i||u,10)];if(o){let l=t.substring(o.start,o.end);for(;l[0]===".";)l=l.substring(1);switch(a){case"downcase":return l.toLowerCase();case"upcase":return l.toUpperCase();default:return l}}else return r})}};function cl(e,t){return e<t?-1:e>t?1:0}s(cl,"strcmp");function hl(e,t){if(e===null&&t===null)return 0;if(!e)return-1;if(!t)return 1;let n=e.length,r=t.length;if(n===r){for(let i=0;i<n;i++){let u=cl(e[i],t[i]);if(u!==0)return u}return 0}return n-r}s(hl,"strArrCmp");function fl(e){return!!(/^#[0-9a-f]{6}$/i.test(e)||/^#[0-9a-f]{8}$/i.test(e)||/^#[0-9a-f]{3}$/i.test(e)||/^#[0-9a-f]{4}$/i.test(e))}s(fl,"isValidHexColor");function dl(e){return e.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g,"\\$&")}s(dl,"escapeRegExpCharacters");var pl=class{static{s(this,"CachedFn")}constructor(e){this.fn=e}cache=new Map;get(e){if(this.cache.has(e))return this.cache.get(e);const t=this.fn(e);return this.cache.set(e,t),t}},Qr=class{static{s(this,"Theme")}constructor(e,t,n){this._colorMap=e,this._defaults=t,this._root=n}static createFromRawTheme(e,t){return this.createFromParsedTheme(l2(e),t)}static createFromParsedTheme(e,t){return h2(e,t)}_cachedMatchRoot=new pl(e=>this._root.match(e));getColorMap(){return this._colorMap.getColorMap()}getDefaults(){return this._defaults}match(e){if(e===null)return this._defaults;const t=e.scopeName,r=this._cachedMatchRoot.get(t).find(i=>a2(e.parent,i.parentScopes));return r?new ml(r.fontStyle,r.foreground,r.background):null}},ks=class ms{static{s(this,"_ScopeStack")}constructor(t,n){this.parent=t,this.scopeName=n}static push(t,n){for(const r of n)t=new ms(t,r);return t}static from(...t){let n=null;for(let r=0;r<t.length;r++)n=new ms(n,t[r]);return n}push(t){return new ms(this,t)}getSegments(){let t=this;const n=[];for(;t;)n.push(t.scopeName),t=t.parent;return n.reverse(),n}toString(){return this.getSegments().join(" ")}extends(t){return this===t?!0:this.parent===null?!1:this.parent.extends(t)}getExtensionIfDefined(t){const n=[];let r=this;for(;r&&r!==t;)n.push(r.scopeName),r=r.parent;return r===t?n.reverse():void 0}};function a2(e,t){if(t.length===0)return!0;for(let n=0;n<t.length;n++){let r=t[n],i=!1;if(r===">"){if(n===t.length-1)return!1;r=t[++n],i=!0}for(;e&&!o2(e.scopeName,r);){if(i)return!1;e=e.parent}if(!e)return!1;e=e.parent}return!0}s(a2,"_scopePathMatchesParentScopes");function o2(e,t){return t===e||e.startsWith(t)&&e[t.length]==="."}s(o2,"_matchesScope");var ml=class{static{s(this,"StyleAttributes")}constructor(e,t,n){this.fontStyle=e,this.foregroundId=t,this.backgroundId=n}};function l2(e){if(!e)return[];if(!e.settings||!Array.isArray(e.settings))return[];let t=e.settings,n=[],r=0;for(let i=0,u=t.length;i<u;i++){let a=t[i];if(!a.settings)continue;let o;if(typeof a.scope=="string"){let h=a.scope;h=h.replace(/^[,]+/,""),h=h.replace(/[,]+$/,""),o=h.split(",")}else Array.isArray(a.scope)?o=a.scope:o=[""];let l=-1;if(typeof a.settings.fontStyle=="string"){l=0;let h=a.settings.fontStyle.split(" ");for(let m=0,p=h.length;m<p;m++)switch(h[m]){case"italic":l=l|1;break;case"bold":l=l|2;break;case"underline":l=l|4;break;case"strikethrough":l=l|8;break}}let c=null;typeof a.settings.foreground=="string"&&fl(a.settings.foreground)&&(c=a.settings.foreground);let f=null;typeof a.settings.background=="string"&&fl(a.settings.background)&&(f=a.settings.background);for(let h=0,m=o.length;h<m;h++){let g=o[h].trim().split(" "),E=g[g.length-1],D=null;g.length>1&&(D=g.slice(0,g.length-1),D.reverse()),n[r++]=new c2(E,D,i,l,c,f)}}return n}s(l2,"parseTheme");var c2=class{static{s(this,"ParsedThemeRule")}constructor(e,t,n,r,i,u){this.scope=e,this.parentScopes=t,this.index=n,this.fontStyle=r,this.foreground=i,this.background=u}},Be=(e=>(e[e.NotSet=-1]="NotSet",e[e.None=0]="None",e[e.Italic=1]="Italic",e[e.Bold=2]="Bold",e[e.Underline=4]="Underline",e[e.Strikethrough=8]="Strikethrough",e))(Be||{});function h2(e,t){e.sort((l,c)=>{let f=cl(l.scope,c.scope);return f!==0||(f=hl(l.parentScopes,c.parentScopes),f!==0)?f:l.index-c.index});let n=0,r="#000000",i="#ffffff";for(;e.length>=1&&e[0].scope==="";){let l=e.shift();l.fontStyle!==-1&&(n=l.fontStyle),l.foreground!==null&&(r=l.foreground),l.background!==null&&(i=l.background)}let u=new f2(t),a=new ml(n,u.getId(r),u.getId(i)),o=new p2(new Ss(0,null,-1,0,0),[]);for(let l=0,c=e.length;l<c;l++){let f=e[l];o.insert(0,f.scope,f.parentScopes,f.fontStyle,u.getId(f.foreground),u.getId(f.background))}return new Qr(u,a,o)}s(h2,"resolveParsedThemeRules");var f2=class{static{s(this,"ColorMap")}_isFrozen;_lastColorId;_id2color;_color2id;constructor(e){if(this._lastColorId=0,this._id2color=[],this._color2id=Object.create(null),Array.isArray(e)){this._isFrozen=!0;for(let t=0,n=e.length;t<n;t++)this._color2id[e[t]]=t,this._id2color[t]=e[t]}else this._isFrozen=!1}getId(e){if(e===null)return 0;e=e.toUpperCase();let t=this._color2id[e];if(t)return t;if(this._isFrozen)throw new Error(`Missing color in color map - ${e}`);return t=++this._lastColorId,this._color2id[e]=t,this._id2color[t]=e,t}getColorMap(){return this._id2color.slice(0)}},d2=Object.freeze([]),Ss=class am{static{s(this,"_ThemeTrieElementRule")}scopeDepth;parentScopes;fontStyle;foreground;background;constructor(t,n,r,i,u){this.scopeDepth=t,this.parentScopes=n||d2,this.fontStyle=r,this.foreground=i,this.background=u}clone(){return new am(this.scopeDepth,this.parentScopes,this.fontStyle,this.foreground,this.background)}static cloneArr(t){let n=[];for(let r=0,i=t.length;r<i;r++)n[r]=t[r].clone();return n}acceptOverwrite(t,n,r,i){this.scopeDepth>t?console.log("how did this happen?"):this.scopeDepth=t,n!==-1&&(this.fontStyle=n),r!==0&&(this.foreground=r),i!==0&&(this.background=i)}},p2=class $o{static{s(this,"_ThemeTrieElement")}constructor(t,n=[],r={}){this._mainRule=t,this._children=r,this._rulesWithParentScopes=n}_rulesWithParentScopes;static _cmpBySpecificity(t,n){if(t.scopeDepth!==n.scopeDepth)return n.scopeDepth-t.scopeDepth;let r=0,i=0;for(;t.parentScopes[r]===">"&&r++,n.parentScopes[i]===">"&&i++,!(r>=t.parentScopes.length||i>=n.parentScopes.length);){const u=n.parentScopes[i].length-t.parentScopes[r].length;if(u!==0)return u;r++,i++}return n.parentScopes.length-t.parentScopes.length}match(t){if(t!==""){let r=t.indexOf("."),i,u;if(r===-1?(i=t,u=""):(i=t.substring(0,r),u=t.substring(r+1)),this._children.hasOwnProperty(i))return this._children[i].match(u)}const n=this._rulesWithParentScopes.concat(this._mainRule);return n.sort($o._cmpBySpecificity),n}insert(t,n,r,i,u,a){if(n===""){this._doInsertHere(t,r,i,u,a);return}let o=n.indexOf("."),l,c;o===-1?(l=n,c=""):(l=n.substring(0,o),c=n.substring(o+1));let f;this._children.hasOwnProperty(l)?f=this._children[l]:(f=new $o(this._mainRule.clone(),Ss.cloneArr(this._rulesWithParentScopes)),this._children[l]=f),f.insert(t+1,c,r,i,u,a)}_doInsertHere(t,n,r,i,u){if(n===null){this._mainRule.acceptOverwrite(t,r,i,u);return}for(let a=0,o=this._rulesWithParentScopes.length;a<o;a++){let l=this._rulesWithParentScopes[a];if(hl(l.parentScopes,n)===0){l.acceptOverwrite(t,r,i,u);return}}r===-1&&(r=this._mainRule.fontStyle),i===0&&(i=this._mainRule.foreground),u===0&&(u=this._mainRule.background),this._rulesWithParentScopes.push(new Ss(t,n,r,i,u))}},dn=class Je{static{s(this,"_EncodedTokenMetadata")}static toBinaryStr(t){return t.toString(2).padStart(32,"0")}static print(t){const n=Je.getLanguageId(t),r=Je.getTokenType(t),i=Je.getFontStyle(t),u=Je.getForeground(t),a=Je.getBackground(t);console.log({languageId:n,tokenType:r,fontStyle:i,foreground:u,background:a})}static getLanguageId(t){return(t&255)>>>0}static getTokenType(t){return(t&768)>>>8}static containsBalancedBrackets(t){return(t&1024)!==0}static getFontStyle(t){return(t&30720)>>>11}static getForeground(t){return(t&16744448)>>>15}static getBackground(t){return(t&4278190080)>>>24}static set(t,n,r,i,u,a,o){let l=Je.getLanguageId(t),c=Je.getTokenType(t),f=Je.containsBalancedBrackets(t)?1:0,h=Je.getFontStyle(t),m=Je.getForeground(t),p=Je.getBackground(t);return n!==0&&(l=n),r!==8&&(c=r),i!==null&&(f=i?1:0),u!==-1&&(h=u),a!==0&&(m=a),o!==0&&(p=o),(l<<0|c<<8|f<<10|h<<11|m<<15|p<<24)>>>0}};function Rx(e){return e}s(Rx,"toOptionalTokenType");function Px(e){return e}s(Px,"fromOptionalTokenType");function Xr(e,t){const n=[],r=m2(e);let i=r.next();for(;i!==null;){let l=0;if(i.length===2&&i.charAt(1)===":"){switch(i.charAt(0)){case"R":l=1;break;case"L":l=-1;break;default:console.log(`Unknown priority ${i} in scope selector`)}i=r.next()}let c=a();if(n.push({matcher:c,priority:l}),i!==",")break;i=r.next()}return n;function u(){if(i==="-"){i=r.next();const l=u();return c=>!!l&&!l(c)}if(i==="("){i=r.next();const l=o();return i===")"&&(i=r.next()),l}if(gl(i)){const l=[];do l.push(i),i=r.next();while(gl(i));return c=>t(l,c)}return null}function a(){const l=[];let c=u();for(;c;)l.push(c),c=u();return f=>l.every(h=>h(f))}function o(){const l=[];let c=a();for(;c&&(l.push(c),i==="|"||i===",");){do i=r.next();while(i==="|"||i===",");c=a()}return f=>l.some(h=>h(f))}}s(Xr,"createMatchers");function gl(e){return!!e&&!!e.match(/[\w\.:]+/)}s(gl,"isIdentifier");function m2(e){let t=/([LR]:|[\w\.:][\w\.:\-]*|[\,\|\-\(\)])/g,n=t.exec(e);return{next:s(()=>{if(!n)return null;const r=n[0];return n=t.exec(e),r},"next")}}s(m2,"newTokenizer");function El(e){typeof e.dispose=="function"&&e.dispose()}s(El,"disposeOnigString");var Qn=class{static{s(this,"TopLevelRuleReference")}constructor(e){this.scopeName=e}toKey(){return this.scopeName}},g2=class{static{s(this,"TopLevelRepositoryRuleReference")}constructor(e,t){this.scopeName=e,this.ruleName=t}toKey(){return`${this.scopeName}#${this.ruleName}`}},E2=class{static{s(this,"ExternalReferenceCollector")}_references=[];_seenReferenceKeys=new Set;get references(){return this._references}visitedRule=new Set;add(e){const t=e.toKey();this._seenReferenceKeys.has(t)||(this._seenReferenceKeys.add(t),this._references.push(e))}},A2=class{static{s(this,"ScopeDependencyProcessor")}constructor(e,t){this.repo=e,this.initialScopeName=t,this.seenFullScopeRequests.add(this.initialScopeName),this.Q=[new Qn(this.initialScopeName)]}seenFullScopeRequests=new Set;seenPartialScopeRequests=new Set;Q;processQueue(){const e=this.Q;this.Q=[];const t=new E2;for(const n of e)D2(n,this.initialScopeName,this.repo,t);for(const n of t.references)if(n instanceof Qn){if(this.seenFullScopeRequests.has(n.scopeName))continue;this.seenFullScopeRequests.add(n.scopeName),this.Q.push(n)}else{if(this.seenFullScopeRequests.has(n.scopeName)||this.seenPartialScopeRequests.has(n.toKey()))continue;this.seenPartialScopeRequests.add(n.toKey()),this.Q.push(n)}}};function D2(e,t,n,r){const i=n.lookup(e.scopeName);if(!i){if(e.scopeName===t)throw new Error(`No grammar provided for <${t}>`);return}const u=n.lookup(t);e instanceof Qn?Jr({baseGrammar:u,selfGrammar:i},r):_s(e.ruleName,{baseGrammar:u,selfGrammar:i,repository:i.repository},r);const a=n.injections(e.scopeName);if(a)for(const o of a)r.add(new Qn(o))}s(D2,"collectReferencesOfReference");function _s(e,t,n){if(t.repository&&t.repository[e]){const r=t.repository[e];Zr([r],t,n)}}s(_s,"collectExternalReferencesInTopLevelRepositoryRule");function Jr(e,t){e.selfGrammar.patterns&&Array.isArray(e.selfGrammar.patterns)&&Zr(e.selfGrammar.patterns,{...e,repository:e.selfGrammar.repository},t),e.selfGrammar.injections&&Zr(Object.values(e.selfGrammar.injections),{...e,repository:e.selfGrammar.repository},t)}s(Jr,"collectExternalReferencesInTopLevelRule");function Zr(e,t,n){for(const r of e){if(n.visitedRule.has(r))continue;n.visitedRule.add(r);const i=r.repository?ol({},t.repository,r.repository):t.repository;Array.isArray(r.patterns)&&Zr(r.patterns,{...t,repository:i},n);const u=r.include;if(!u)continue;const a=Al(u);switch(a.kind){case 0:Jr({...t,selfGrammar:t.baseGrammar},n);break;case 1:Jr(t,n);break;case 2:_s(a.ruleName,{...t,repository:i},n);break;case 3:case 4:const o=a.scopeName===t.selfGrammar.scopeName?t.selfGrammar:a.scopeName===t.baseGrammar.scopeName?t.baseGrammar:void 0;if(o){const l={baseGrammar:t.baseGrammar,selfGrammar:o,repository:i};a.kind===4?_s(a.ruleName,l,n):Jr(l,n)}else a.kind===4?n.add(new g2(a.scopeName,a.ruleName)):n.add(new Qn(a.scopeName));break}}}s(Zr,"collectExternalReferencesInRules");var C2=class{static{s(this,"BaseReference")}kind=0},T2=class{static{s(this,"SelfReference")}kind=1},y2=class{static{s(this,"RelativeReference")}constructor(e){this.ruleName=e}kind=2},b2=class{static{s(this,"TopLevelReference")}constructor(e){this.scopeName=e}kind=3},k2=class{static{s(this,"TopLevelRepositoryReference")}constructor(e,t){this.scopeName=e,this.ruleName=t}kind=4};function Al(e){if(e==="$base")return new C2;if(e==="$self")return new T2;const t=e.indexOf("#");if(t===-1)return new b2(e);if(t===0)return new y2(e.substring(1));{const n=e.substring(0,t),r=e.substring(t+1);return new k2(n,r)}}s(Al,"parseInclude");var S2=/\\(\d+)/,Dl=/\\(\d+)/g,_2=-1,Cl=-2;function Mx(e){return e}s(Mx,"ruleIdFromNumber");function Ux(e){return e}s(Ux,"ruleIdToNumber");var Xn=class{static{s(this,"Rule")}$location;id;_nameIsCapturing;_name;_contentNameIsCapturing;_contentName;constructor(e,t,n,r){this.$location=e,this.id=t,this._name=n||null,this._nameIsCapturing=Kr.hasCaptures(this._name),this._contentName=r||null,this._contentNameIsCapturing=Kr.hasCaptures(this._contentName)}get debugName(){const e=this.$location?`${ll(this.$location.filename)}:${this.$location.line}`:"unknown";return`${this.constructor.name}#${this.id} @ ${e}`}getName(e,t){return!this._nameIsCapturing||this._name===null||e===null||t===null?this._name:Kr.replaceCaptures(this._name,e,t)}getContentName(e,t){return!this._contentNameIsCapturing||this._contentName===null?this._contentName:Kr.replaceCaptures(this._contentName,e,t)}},B2=class extends Xn{static{s(this,"CaptureRule")}retokenizeCapturedWithRuleId;constructor(e,t,n,r,i){super(e,t,n,r),this.retokenizeCapturedWithRuleId=i}dispose(){}collectPatterns(e,t){throw new Error("Not supported!")}compile(e,t){throw new Error("Not supported!")}compileAG(e,t,n,r){throw new Error("Not supported!")}},w2=class extends Xn{static{s(this,"MatchRule")}_match;captures;_cachedCompiledPatterns;constructor(e,t,n,r,i){super(e,t,n,null),this._match=new Jn(r,this.id),this.captures=i,this._cachedCompiledPatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null)}get debugMatchRegExp(){return`${this._match.source}`}collectPatterns(e,t){t.push(this._match)}compile(e,t){return this._getCachedCompiledPatterns(e).compile(e)}compileAG(e,t,n,r){return this._getCachedCompiledPatterns(e).compileAG(e,n,r)}_getCachedCompiledPatterns(e){return this._cachedCompiledPatterns||(this._cachedCompiledPatterns=new Zn,this.collectPatterns(e,this._cachedCompiledPatterns)),this._cachedCompiledPatterns}},Tl=class extends Xn{static{s(this,"IncludeOnlyRule")}hasMissingPatterns;patterns;_cachedCompiledPatterns;constructor(e,t,n,r,i){super(e,t,n,r),this.patterns=i.patterns,this.hasMissingPatterns=i.hasMissingPatterns,this._cachedCompiledPatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null)}collectPatterns(e,t){for(const n of this.patterns)e.getRule(n).collectPatterns(e,t)}compile(e,t){return this._getCachedCompiledPatterns(e).compile(e)}compileAG(e,t,n,r){return this._getCachedCompiledPatterns(e).compileAG(e,n,r)}_getCachedCompiledPatterns(e){return this._cachedCompiledPatterns||(this._cachedCompiledPatterns=new Zn,this.collectPatterns(e,this._cachedCompiledPatterns)),this._cachedCompiledPatterns}},Bs=class extends Xn{static{s(this,"BeginEndRule")}_begin;beginCaptures;_end;endHasBackReferences;endCaptures;applyEndPatternLast;hasMissingPatterns;patterns;_cachedCompiledPatterns;constructor(e,t,n,r,i,u,a,o,l,c){super(e,t,n,r),this._begin=new Jn(i,this.id),this.beginCaptures=u,this._end=new Jn(a||"\uFFFF",-1),this.endHasBackReferences=this._end.hasBackReferences,this.endCaptures=o,this.applyEndPatternLast=l||!1,this.patterns=c.patterns,this.hasMissingPatterns=c.hasMissingPatterns,this._cachedCompiledPatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null)}get debugBeginRegExp(){return`${this._begin.source}`}get debugEndRegExp(){return`${this._end.source}`}getEndWithResolvedBackReferences(e,t){return this._end.resolveBackReferences(e,t)}collectPatterns(e,t){t.push(this._begin)}compile(e,t){return this._getCachedCompiledPatterns(e,t).compile(e)}compileAG(e,t,n,r){return this._getCachedCompiledPatterns(e,t).compileAG(e,n,r)}_getCachedCompiledPatterns(e,t){if(!this._cachedCompiledPatterns){this._cachedCompiledPatterns=new Zn;for(const n of this.patterns)e.getRule(n).collectPatterns(e,this._cachedCompiledPatterns);this.applyEndPatternLast?this._cachedCompiledPatterns.push(this._end.hasBackReferences?this._end.clone():this._end):this._cachedCompiledPatterns.unshift(this._end.hasBackReferences?this._end.clone():this._end)}return this._end.hasBackReferences&&(this.applyEndPatternLast?this._cachedCompiledPatterns.setSource(this._cachedCompiledPatterns.length()-1,t):this._cachedCompiledPatterns.setSource(0,t)),this._cachedCompiledPatterns}},ei=class extends Xn{static{s(this,"BeginWhileRule")}_begin;beginCaptures;whileCaptures;_while;whileHasBackReferences;hasMissingPatterns;patterns;_cachedCompiledPatterns;_cachedCompiledWhilePatterns;constructor(e,t,n,r,i,u,a,o,l){super(e,t,n,r),this._begin=new Jn(i,this.id),this.beginCaptures=u,this.whileCaptures=o,this._while=new Jn(a,Cl),this.whileHasBackReferences=this._while.hasBackReferences,this.patterns=l.patterns,this.hasMissingPatterns=l.hasMissingPatterns,this._cachedCompiledPatterns=null,this._cachedCompiledWhilePatterns=null}dispose(){this._cachedCompiledPatterns&&(this._cachedCompiledPatterns.dispose(),this._cachedCompiledPatterns=null),this._cachedCompiledWhilePatterns&&(this._cachedCompiledWhilePatterns.dispose(),this._cachedCompiledWhilePatterns=null)}get debugBeginRegExp(){return`${this._begin.source}`}get debugWhileRegExp(){return`${this._while.source}`}getWhileWithResolvedBackReferences(e,t){return this._while.resolveBackReferences(e,t)}collectPatterns(e,t){t.push(this._begin)}compile(e,t){return this._getCachedCompiledPatterns(e).compile(e)}compileAG(e,t,n,r){return this._getCachedCompiledPatterns(e).compileAG(e,n,r)}_getCachedCompiledPatterns(e){if(!this._cachedCompiledPatterns){this._cachedCompiledPatterns=new Zn;for(const t of this.patterns)e.getRule(t).collectPatterns(e,this._cachedCompiledPatterns)}return this._cachedCompiledPatterns}compileWhile(e,t){return this._getCachedCompiledWhilePatterns(e,t).compile(e)}compileWhileAG(e,t,n,r){return this._getCachedCompiledWhilePatterns(e,t).compileAG(e,n,r)}_getCachedCompiledWhilePatterns(e,t){return this._cachedCompiledWhilePatterns||(this._cachedCompiledWhilePatterns=new Zn,this._cachedCompiledWhilePatterns.push(this._while.hasBackReferences?this._while.clone():this._while)),this._while.hasBackReferences&&this._cachedCompiledWhilePatterns.setSource(0,t||"\uFFFF"),this._cachedCompiledWhilePatterns}},yl=class Ne{static{s(this,"_RuleFactory")}static createCaptureRule(t,n,r,i,u){return t.registerRule(a=>new B2(n,a,r,i,u))}static getCompiledRuleId(t,n,r){return t.id||n.registerRule(i=>{if(t.id=i,t.match)return new w2(t.$vscodeTextmateLocation,t.id,t.name,t.match,Ne._compileCaptures(t.captures,n,r));if(typeof t.begin>"u"){t.repository&&(r=ol({},r,t.repository));let u=t.patterns;return typeof u>"u"&&t.include&&(u=[{include:t.include}]),new Tl(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,Ne._compilePatterns(u,n,r))}return t.while?new ei(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,t.begin,Ne._compileCaptures(t.beginCaptures||t.captures,n,r),t.while,Ne._compileCaptures(t.whileCaptures||t.captures,n,r),Ne._compilePatterns(t.patterns,n,r)):new Bs(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,t.begin,Ne._compileCaptures(t.beginCaptures||t.captures,n,r),t.end,Ne._compileCaptures(t.endCaptures||t.captures,n,r),t.applyEndPatternLast,Ne._compilePatterns(t.patterns,n,r))}),t.id}static _compileCaptures(t,n,r){let i=[];if(t){let u=0;for(const a in t){if(a==="$vscodeTextmateLocation")continue;const o=parseInt(a,10);o>u&&(u=o)}for(let a=0;a<=u;a++)i[a]=null;for(const a in t){if(a==="$vscodeTextmateLocation")continue;const o=parseInt(a,10);let l=0;t[a].patterns&&(l=Ne.getCompiledRuleId(t[a],n,r)),i[o]=Ne.createCaptureRule(n,t[a].$vscodeTextmateLocation,t[a].name,t[a].contentName,l)}}return i}static _compilePatterns(t,n,r){let i=[];if(t)for(let u=0,a=t.length;u<a;u++){const o=t[u];let l=-1;if(o.include){const c=Al(o.include);switch(c.kind){case 0:case 1:l=Ne.getCompiledRuleId(r[o.include],n,r);break;case 2:let f=r[c.ruleName];f&&(l=Ne.getCompiledRuleId(f,n,r));break;case 3:case 4:const h=c.scopeName,m=c.kind===4?c.ruleName:null,p=n.getExternalGrammar(h,r);if(p)if(m){let g=p.repository[m];g&&(l=Ne.getCompiledRuleId(g,n,p.repository))}else l=Ne.getCompiledRuleId(p.repository.$self,n,p.repository);break}}else l=Ne.getCompiledRuleId(o,n,r);if(l!==-1){const c=n.getRule(l);let f=!1;if((c instanceof Tl||c instanceof Bs||c instanceof ei)&&c.hasMissingPatterns&&c.patterns.length===0&&(f=!0),f)continue;i.push(l)}}return{patterns:i,hasMissingPatterns:(t?t.length:0)!==i.length}}},Jn=class om{static{s(this,"_RegExpSource")}source;ruleId;hasAnchor;hasBackReferences;_anchorCache;constructor(t,n){if(t&&typeof t=="string"){const r=t.length;let i=0,u=[],a=!1;for(let o=0;o<r;o++)if(t.charAt(o)==="\\"&&o+1<r){const c=t.charAt(o+1);c==="z"?(u.push(t.substring(i,o)),u.push("$(?!\\n)(?<!\\n)"),i=o+2):(c==="A"||c==="G")&&(a=!0),o++}this.hasAnchor=a,i===0?this.source=t:(u.push(t.substring(i,r)),this.source=u.join(""))}else this.hasAnchor=!1,this.source=t;this.hasAnchor?this._anchorCache=this._buildAnchorCache():this._anchorCache=null,this.ruleId=n,typeof this.source=="string"?this.hasBackReferences=S2.test(this.source):this.hasBackReferences=!1}clone(){return new om(this.source,this.ruleId)}setSource(t){this.source!==t&&(this.source=t,this.hasAnchor&&(this._anchorCache=this._buildAnchorCache()))}resolveBackReferences(t,n){if(typeof this.source!="string")throw new Error("This method should only be called if the source is a string");let r=n.map(i=>t.substring(i.start,i.end));return Dl.lastIndex=0,this.source.replace(Dl,(i,u)=>dl(r[parseInt(u,10)]||""))}_buildAnchorCache(){if(typeof this.source!="string")throw new Error("This method should only be called if the source is a string");let t=[],n=[],r=[],i=[],u,a,o,l;for(u=0,a=this.source.length;u<a;u++)o=this.source.charAt(u),t[u]=o,n[u]=o,r[u]=o,i[u]=o,o==="\\"&&u+1<a&&(l=this.source.charAt(u+1),l==="A"?(t[u+1]="\uFFFF",n[u+1]="\uFFFF",r[u+1]="A",i[u+1]="A"):l==="G"?(t[u+1]="\uFFFF",n[u+1]="G",r[u+1]="\uFFFF",i[u+1]="G"):(t[u+1]=l,n[u+1]=l,r[u+1]=l,i[u+1]=l),u++);return{A0_G0:t.join(""),A0_G1:n.join(""),A1_G0:r.join(""),A1_G1:i.join("")}}resolveAnchors(t,n){return!this.hasAnchor||!this._anchorCache||typeof this.source!="string"?this.source:t?n?this._anchorCache.A1_G1:this._anchorCache.A1_G0:n?this._anchorCache.A0_G1:this._anchorCache.A0_G0}},Zn=class{static{s(this,"RegExpSourceList")}_items;_hasAnchors;_cached;_anchorCache;constructor(){this._items=[],this._hasAnchors=!1,this._cached=null,this._anchorCache={A0_G0:null,A0_G1:null,A1_G0:null,A1_G1:null}}dispose(){this._disposeCaches()}_disposeCaches(){this._cached&&(this._cached.dispose(),this._cached=null),this._anchorCache.A0_G0&&(this._anchorCache.A0_G0.dispose(),this._anchorCache.A0_G0=null),this._anchorCache.A0_G1&&(this._anchorCache.A0_G1.dispose(),this._anchorCache.A0_G1=null),this._anchorCache.A1_G0&&(this._anchorCache.A1_G0.dispose(),this._anchorCache.A1_G0=null),this._anchorCache.A1_G1&&(this._anchorCache.A1_G1.dispose(),this._anchorCache.A1_G1=null)}push(e){this._items.push(e),this._hasAnchors=this._hasAnchors||e.hasAnchor}unshift(e){this._items.unshift(e),this._hasAnchors=this._hasAnchors||e.hasAnchor}length(){return this._items.length}setSource(e,t){this._items[e].source!==t&&(this._disposeCaches(),this._items[e].setSource(t))}compile(e){if(!this._cached){let t=this._items.map(n=>n.source);this._cached=new bl(e,t,this._items.map(n=>n.ruleId))}return this._cached}compileAG(e,t,n){return this._hasAnchors?t?n?(this._anchorCache.A1_G1||(this._anchorCache.A1_G1=this._resolveAnchors(e,t,n)),this._anchorCache.A1_G1):(this._anchorCache.A1_G0||(this._anchorCache.A1_G0=this._resolveAnchors(e,t,n)),this._anchorCache.A1_G0):n?(this._anchorCache.A0_G1||(this._anchorCache.A0_G1=this._resolveAnchors(e,t,n)),this._anchorCache.A0_G1):(this._anchorCache.A0_G0||(this._anchorCache.A0_G0=this._resolveAnchors(e,t,n)),this._anchorCache.A0_G0):this.compile(e)}_resolveAnchors(e,t,n){let r=this._items.map(i=>i.resolveAnchors(t,n));return new bl(e,r,this._items.map(i=>i.ruleId))}},bl=class{static{s(this,"CompiledRule")}constructor(e,t,n){this.regExps=t,this.rules=n,this.scanner=e.createOnigScanner(t)}scanner;dispose(){typeof this.scanner.dispose=="function"&&this.scanner.dispose()}toString(){const e=[];for(let t=0,n=this.rules.length;t<n;t++)e.push(" - "+this.rules[t]+": "+this.regExps[t]);return e.join(`
`)}findNextMatchSync(e,t,n){const r=this.scanner.findNextMatchSync(e,t,n);return r?{ruleId:this.rules[r.index],captureIndices:r.captureIndices}:null}},ws=class{static{s(this,"BasicScopeAttributes")}constructor(e,t){this.languageId=e,this.tokenType=t}},F2=class qo{static{s(this,"_BasicScopeAttributesProvider")}_defaultAttributes;_embeddedLanguagesMatcher;constructor(t,n){this._defaultAttributes=new ws(t,8),this._embeddedLanguagesMatcher=new N2(Object.entries(n||{}))}getDefaultAttributes(){return this._defaultAttributes}getBasicScopeAttributes(t){return t===null?qo._NULL_SCOPE_METADATA:this._getBasicScopeAttributes.get(t)}static _NULL_SCOPE_METADATA=new ws(0,0);_getBasicScopeAttributes=new pl(t=>{const n=this._scopeToLanguage(t),r=this._toStandardTokenType(t);return new ws(n,r)});_scopeToLanguage(t){return this._embeddedLanguagesMatcher.match(t)||0}_toStandardTokenType(t){const n=t.match(qo.STANDARD_TOKEN_TYPE_REGEXP);if(!n)return 8;switch(n[1]){case"comment":return 1;case"string":return 2;case"regex":return 3;case"meta.embedded":return 0}throw new Error("Unexpected match for standard token type!")}static STANDARD_TOKEN_TYPE_REGEXP=/\b(comment|string|regex|meta\.embedded)\b/},N2=class{static{s(this,"ScopeMatcher")}values;scopesRegExp;constructor(e){if(e.length===0)this.values=null,this.scopesRegExp=null;else{this.values=new Map(e);const t=e.map(([n,r])=>dl(n));t.sort(),t.reverse(),this.scopesRegExp=new RegExp(`^((${t.join(")|(")}))($|\\.)`,"")}}match(e){if(!this.scopesRegExp)return;const t=e.match(this.scopesRegExp);if(t)return this.values.get(t[1])}};typeof process<"u"&&process.env.VSCODE_TEXTMATE_DEBUG;var kl=class{static{s(this,"TokenizeStringResult")}constructor(e,t){this.stack=e,this.stoppedEarly=t}};function Sl(e,t,n,r,i,u,a,o){const l=t.content.length;let c=!1,f=-1;if(a){const p=x2(e,t,n,r,i,u);i=p.stack,r=p.linePos,n=p.isFirstLine,f=p.anchorPosition}const h=Date.now();for(;!c;){if(o!==0&&Date.now()-h>o)return new kl(i,!0);m()}return new kl(i,!1);function m(){const p=I2(e,t,n,r,i,f);if(!p){u.produce(i,l),c=!0;return}const g=p.captureIndices,E=p.matchedRuleId,D=g&&g.length>0?g[0].end>r:!1;if(E===_2){const A=i.getRule(e);u.produce(i,g[0].start),i=i.withContentNameScopesList(i.nameScopesList),er(e,t,n,i,u,A.endCaptures,g),u.produce(i,g[0].end);const C=i;if(i=i.parent,f=C.getAnchorPos(),!D&&C.getEnterPos()===r){i=C,u.produce(i,l),c=!0;return}}else{const A=e.getRule(E);u.produce(i,g[0].start);const C=i,y=A.getName(t.content,g),x=i.contentNameScopesList.pushAttributed(y,e);if(i=i.push(E,r,f,g[0].end===l,null,x,x),A instanceof Bs){const I=A;er(e,t,n,i,u,I.beginCaptures,g),u.produce(i,g[0].end),f=g[0].end;const k=I.getContentName(t.content,g),v=x.pushAttributed(k,e);if(i=i.withContentNameScopesList(v),I.endHasBackReferences&&(i=i.withEndRule(I.getEndWithResolvedBackReferences(t.content,g))),!D&&C.hasSameRuleAs(i)){i=i.pop(),u.produce(i,l),c=!0;return}}else if(A instanceof ei){const I=A;er(e,t,n,i,u,I.beginCaptures,g),u.produce(i,g[0].end),f=g[0].end;const k=I.getContentName(t.content,g),v=x.pushAttributed(k,e);if(i=i.withContentNameScopesList(v),I.whileHasBackReferences&&(i=i.withEndRule(I.getWhileWithResolvedBackReferences(t.content,g))),!D&&C.hasSameRuleAs(i)){i=i.pop(),u.produce(i,l),c=!0;return}}else if(er(e,t,n,i,u,A.captures,g),u.produce(i,g[0].end),i=i.pop(),!D){i=i.safePop(),u.produce(i,l),c=!0;return}}g[0].end>r&&(r=g[0].end,n=!1)}}s(Sl,"_tokenizeString");function x2(e,t,n,r,i,u){let a=i.beginRuleCapturedEOL?0:-1;const o=[];for(let l=i;l;l=l.pop()){const c=l.getRule(e);c instanceof ei&&o.push({rule:c,stack:l})}for(let l=o.pop();l;l=o.pop()){const{ruleScanner:c,findOptions:f}=O2(l.rule,e,l.stack.endRule,n,r===a),h=c.findNextMatchSync(t,r,f);if(h){if(h.ruleId!==Cl){i=l.stack.pop();break}h.captureIndices&&h.captureIndices.length&&(u.produce(l.stack,h.captureIndices[0].start),er(e,t,n,l.stack,u,l.rule.whileCaptures,h.captureIndices),u.produce(l.stack,h.captureIndices[0].end),a=h.captureIndices[0].end,h.captureIndices[0].end>r&&(r=h.captureIndices[0].end,n=!1))}else{i=l.stack.pop();break}}return{stack:i,linePos:r,anchorPosition:a,isFirstLine:n}}s(x2,"_chec