yanki
Version:
A CLI tool and TypeScript library for syncing Markdown to Anki flashcards.
2 lines • 765 kB
JavaScript
var lg=Object.defineProperty;var s=(e,t)=>lg(e,"name",{value:t,configurable:!0});import ug from"process";import cg from"rehype-parse";import{EntityDecoder as hg,htmlDecodeTree as fg,DecodingMode as ql}from"entities/lib/decode.js";import"entities/lib/escape.js";import"node:path";import{webcrypto as zl}from"node:crypto";const kt={defaultMerge:Symbol("deepmerge-ts: default merge"),skip:Symbol("deepmerge-ts: skip")};kt.defaultMerge;function pg(e,t){return t}s(pg,"defaultMetaDataUpdater");function dg(e,t){return e.filter(n=>n!==void 0)}s(dg,"defaultFilterValues");var Yl;(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"})(Yl||(Yl={}));function jl(e){return typeof e!="object"||e===null?0:Array.isArray(e)?2:Eg(e)?1:e instanceof Set?3:e instanceof Map?4:5}s(jl,"getObjectType");function mg(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(mg,"getKeys");function gg(e,t){return typeof e=="object"&&Object.prototype.propertyIsEnumerable.call(e,t)}s(gg,"objectHasProperty");function Gl(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(Gl,"getIterableOfIterables");const Vl=["[object Object]","[object Module]"];function Eg(e){if(!Vl.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"||!Vl.includes(Object.prototype.toString.call(n))||!n.hasOwnProperty("isPrototypeOf"))}s(Eg,"isRecord");function Tg(e,t,n){const r={};for(const i of mg(e)){const a=[];for(const u of e)gg(u,i)&&a.push(u[i]);if(a.length===0)continue;const o=t.metaDataUpdater(n,{key:i,parents:e}),l=Wl(a,t,o);l!==kt.skip&&(i==="__proto__"?Object.defineProperty(r,i,{value:l,configurable:!0,enumerable:!0,writable:!0}):r[i]=l)}return r}s(Tg,"mergeRecords$1");function yg(e){return e.flat()}s(yg,"mergeArrays$1");function Ag(e){return new Set(Gl(e))}s(Ag,"mergeSets$1");function bg(e){return new Map(Gl(e))}s(bg,"mergeMaps$1");function Dg(e){return e.at(-1)}s(Dg,"mergeOthers$1");const qr={mergeRecords:Tg,mergeArrays:yg,mergeSets:Ag,mergeMaps:bg,mergeOthers:Dg};function Le(...e){return Cg({})(...e)}s(Le,"deepmerge");function Cg(e,t){const n=kg(e,r);function r(...i){return Wl(i,n,t)}return s(r,"customizedDeepmerge"),r}s(Cg,"deepmergeCustom");function kg(e,t){return{defaultMergeFunctions:qr,mergeFunctions:{...qr,...Object.fromEntries(Object.entries(e).filter(([n,r])=>Object.hasOwn(qr,n)).map(([n,r])=>r===!1?[n,qr.mergeOthers]:[n,r]))},metaDataUpdater:e.metaDataUpdater??pg,deepmerge:t,useImplicitDefaultMerging:e.enableImplicitDefaultMerging??!1,filterValues:e.filterValues===!1?void 0:e.filterValues??dg,actions:kt}}s(kg,"getUtils");function Wl(e,t,n){const r=t.filterValues?.(e,n)??e;if(r.length===0)return;if(r.length===1)return ps(r,t,n);const i=jl(r[0]);if(i!==0&&i!==5){for(let a=1;a<r.length;a++)if(jl(r[a])!==i)return ps(r,t,n)}switch(i){case 1:return _g(r,t,n);case 2:return Sg(r,t,n);case 3:return wg(r,t,n);case 4:return Ng(r,t,n);default:return ps(r,t,n)}}s(Wl,"mergeUnknowns");function _g(e,t,n){const r=t.mergeFunctions.mergeRecords(e,t,n);return r===kt.defaultMerge||t.useImplicitDefaultMerging&&r===void 0&&t.mergeFunctions.mergeRecords!==t.defaultMergeFunctions.mergeRecords?t.defaultMergeFunctions.mergeRecords(e,t,n):r}s(_g,"mergeRecords");function Sg(e,t,n){const r=t.mergeFunctions.mergeArrays(e,t,n);return r===kt.defaultMerge||t.useImplicitDefaultMerging&&r===void 0&&t.mergeFunctions.mergeArrays!==t.defaultMergeFunctions.mergeArrays?t.defaultMergeFunctions.mergeArrays(e):r}s(Sg,"mergeArrays");function wg(e,t,n){const r=t.mergeFunctions.mergeSets(e,t,n);return r===kt.defaultMerge||t.useImplicitDefaultMerging&&r===void 0&&t.mergeFunctions.mergeSets!==t.defaultMergeFunctions.mergeSets?t.defaultMergeFunctions.mergeSets(e):r}s(wg,"mergeSets");function Ng(e,t,n){const r=t.mergeFunctions.mergeMaps(e,t,n);return r===kt.defaultMerge||t.useImplicitDefaultMerging&&r===void 0&&t.mergeFunctions.mergeMaps!==t.defaultMergeFunctions.mergeMaps?t.defaultMergeFunctions.mergeMaps(e):r}s(Ng,"mergeMaps");function ps(e,t,n){const r=t.mergeFunctions.mergeOthers(e,t,n);return r===kt.defaultMerge||t.useImplicitDefaultMerging&&r===void 0&&t.mergeFunctions.mergeOthers!==t.defaultMergeFunctions.mergeOthers?t.defaultMergeFunctions.mergeOthers(e):r}s(ps,"mergeOthers");function zr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}s(zr,"getDefaultExportFromCjs");var Ig="addenda",vg="aircraft",Lg="algae",xg="alumnae",Og="alumni",Rg="alveoli",Fg="amoebae",Bg="analyses",Pg="antennae",Mg="antitheses",Ug="apices",Hg="appendices",$g="automata",qg="axes",zg="bacilli",Yg="bacteria",jg="bacula",Gg="barracks",Vg="bases",Wg="beaux",Kg="bison",Qg="buffalo",Xg="bureaus",Jg="cacti",Zg="calves",eE="carcinomata",tE="carp",nE="censuses",rE="chassis",iE="cherubim",sE="children",aE="cloacae",oE="cod",lE="codices",uE="concerti",cE="consortia",hE="corpora",fE="crises",pE="criteria",dE="curricula",mE="cystomata",gE="data",EE="deer",TE="diagnoses",yE="dice",AE="dwarfs",bE="echoes",DE="elves",CE="elk",kE="ellipses",_E="embargoes",SE="emphases",wE="errata",NE="fezes",IE="firmware",vE="fish",LE="foci",xE="feet",OE="formulae",RE="fungi",FE="gallows",BE="genera",PE="glomeruli",ME="geese",UE="graffiti",HE="grouse",$E="halves",qE="hamuli",zE="heroes",YE="hippopotami",jE="hooves",GE="hovercraft",VE="hypotheses",WE="ilia",KE="incubi",QE="indices",XE="interstitia",JE="kakapo",ZE="knives",e1="larvae",t1="leaves",n1="libretti",r1="lives",i1="loaves",s1="loculi",a1="loci",o1="lice",l1="men",u1="matrices",c1="means",h1="measles",f1="media",p1="media",d1="memoranda",m1="millennia",g1="minutiae",E1="moose",T1="mice",y1="nebulae",A1="nemeses",b1="neuroses",D1="news",C1="nucleoli",k1="nuclei",_1="oases",S1="occipita",w1="offspring",N1="omphaloi",I1="opera",v1="ova",L1="oxen",x1="paralyses",O1="parentheses",R1="people",F1="phenomena",B1="phyla",P1="pike",M1="polyhedra",U1="potatoes",H1="primi",$1="prognoses",q1="quizzes",z1="radii",Y1="referenda",j1="salmon",G1="scarves",V1="scrota",W1="selves",K1="seminomata",Q1="series",X1="sheep",J1="shelves",Z1="shrimp",e0="simulacra",t0="soliloquies",n0="spacecraft",r0="species",i0="spectra",s0="squid",a0="stimuli",o0="strata",l0="swine",u0="syconia",c0="syllabi",h0="symposia",f0="synopses",p0="syntheses",d0="tableaus",m0="testes",g0="those",E0="theses",T0="thieves",y0="thrombi",A0="tomatoes",b0="teeth",D0="tori",C0="trout",k0="tuna",_0="umbilici",S0="uteri",w0="vertebrae",N0="vertices",I0="vetoes",v0="vitae",L0="vortices",x0="watercraft",O0="wharves",R0="wives",F0="wolves",B0="women",P0={addendum:Ig,aircraft:vg,alga:Lg,alumna:xg,alumnus:Og,alveolus:Rg,amoeba:Fg,analysis:Bg,antenna:Pg,antithesis:Mg,apex:Ug,appendix:Hg,automaton:$g,axis:qg,bacillus:zg,bacterium:Yg,baculum:jg,barracks:Gg,basis:Vg,beau:Wg,bison:Kg,buffalo:Qg,bureau:Xg,cactus:Jg,calf:Zg,carcinoma:eE,carp:tE,census:nE,chassis:rE,cherub:iE,child:sE,ch\u00E2teau:"ch\xE2teaus",cloaca:aE,cod:oE,codex:lE,concerto:uE,consortium:cE,corpus:hE,crisis:fE,criterion:pE,curriculum:dE,cystoma:mE,datum:gE,deer:EE,diagnosis:TE,die:yE,dwarf:AE,echo:bE,elf:DE,elk:CE,ellipsis:kE,embargo:_E,emphasis:SE,erratum:wE,"faux pas":"faux pas",fez:NE,firmware:IE,fish:vE,focus:LE,foot:xE,formula:OE,fungus:RE,gallows:FE,genus:BE,glomerulus:PE,goose:ME,graffito:UE,grouse:HE,half:$E,hamulus:qE,hero:zE,hippopotamus:YE,hoof:jE,hovercraft:GE,hypothesis:VE,iliac:WE,incubus:KE,index:QE,interstitium:XE,kakapo:JE,knife:ZE,larva:e1,leaf:t1,libretto:n1,life:r1,loaf:i1,loculus:s1,locus:a1,louse:o1,man:l1,matrix:u1,means:c1,measles:h1,media:f1,medium:p1,memorandum:d1,millennium:m1,minutia:g1,moose:E1,mouse:T1,nebula:y1,nemesis:A1,neurosis:b1,news:D1,nucleolus:C1,nucleus:k1,oasis:_1,occiput:S1,offspring:w1,omphalos:N1,opus:I1,ovum:v1,ox:L1,paralysis:x1,parenthesis:O1,person:R1,phenomenon:F1,phylum:B1,pike:P1,polyhedron:M1,potato:U1,primus:H1,prognosis:$1,quiz:q1,radius:z1,referendum:Y1,salmon:j1,scarf:G1,scrotum:V1,self:W1,seminoma:K1,series:Q1,sheep:X1,shelf:J1,shrimp:Z1,simulacrum:e0,soliloquy:t0,spacecraft:n0,species:r0,spectrum:i0,squid:s0,stimulus:a0,stratum:o0,swine:l0,syconium:u0,syllabus:c0,symposium:h0,synopsis:f0,synthesis:p0,tableau:d0,testis:m0,that:g0,thesis:E0,thief:T0,this:"these",thrombus:y0,tomato:A0,tooth:b0,torus:D0,trout:C0,tuna:k0,umbilicus:_0,uterus:S0,vertebra:w0,vertex:N0,veto:I0,vita:v0,vortex:L0,watercraft:x0,wharf:O0,wife:R0,wolf:F0,woman:B0},ds,Kl;function M0(){if(Kl)return ds;Kl=1;const e=P0;return ds=new Map(Object.entries(e)),ds}s(M0,"requireIrregularPlurals");var U0=M0(),Ql=zr(U0);function ln(e,t,n){if(typeof t=="number"&&(n=t),Ql.has(e.toLowerCase())){t=Ql.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(ln,"plur");const Xl=s(e=>Number.isFinite(e)?e:0,"toZeroIfInfinity");function H0(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(Xl(e*1e3)%1e3),nanoseconds:Math.trunc(Xl(e*1e6)%1e3)}}s(H0,"parseNumber");function $0(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($0,"parseBigint");function q0(e){switch(typeof e){case"number":{if(Number.isFinite(e))return H0(e);break}case"bigint":return $0(e)}throw new TypeError("Expected a finite number or bigint")}s(q0,"parseMilliseconds");const z0=s(e=>e===0||e===0n,"isZero"),Y0=s((e,t)=>t===1||t===1n?e:`${e}s`,"pluralize"),j0=1e-7,G0=24n*60n*60n*1000n;function ms(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 a=s((f,h)=>{const m=Math.floor(f*10**h+j0);return(Math.round(m)/10**h).toFixed(h)},"floorDecimals"),o=s((f,h,m,d)=>{if(!((i.length===0||!t.colonNotation)&&z0(f)&&!(t.colonNotation&&m==="m"))){if(d??=String(f),t.colonNotation){const g=d.includes(".")?d.split(".")[0].length:d.length,E=i.length>0?2:1;d="0".repeat(Math.max(0,E-g))+d}else d+=t.verbose?" "+Y0(h,f):m;i.push(d)}},"add"),l=q0(e),u=BigInt(l.days);if(t.hideYearAndDays?o(BigInt(u)*24n+BigInt(l.hours),"hour","h"):(t.hideYear?o(u,"day","d"):(o(u/365n,"year","y"),o(u%365n,"day","d")),o(Number(l.hours),"hour","h")),o(Number(l.minutes),"minute","m"),!t.hideSeconds)if(t.separateMilliseconds||t.formatSubMilliseconds||!t.colonNotation&&e<1e3){const f=Number(l.seconds),h=Number(l.milliseconds),m=Number(l.microseconds),d=Number(l.nanoseconds);if(o(f,"second","s"),t.formatSubMilliseconds)o(h,"millisecond","ms"),o(m,"microsecond","\xB5s"),o(d,"nanosecond","ns");else{const g=h+m/1e3+d/1e6,E=typeof t.millisecondsDecimalDigits=="number"?t.millisecondsDecimalDigits:0,T=g>=1?Math.round(g):Math.ceil(g),y=E?g.toFixed(E):T;o(Number.parseFloat(y),"millisecond","ms",y)}}else{const f=(n?Number(e%G0):e)/1e3%60,h=typeof t.secondsDecimalDigits=="number"?t.secondsDecimalDigits:1,m=a(f,h),d=t.keepDecimalsOnWholeSeconds?m:m.replace(/\.0+$/,"");o(Number.parseFloat(d),"second","s",d)}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(ms,"prettyMilliseconds");var V0=Object.defineProperty,Jl=s((e,t)=>V0(e,"name",{value:t,configurable:!0}),"a");const Yr=typeof window>"u"?typeof process>"u"?"other":"node":"browser",Zl=Yr==="browser"?/windows/i.test(navigator.userAgent)?"windows":/mac/i.test(navigator.userAgent)?"mac":"other":Yr==="node"?process.platform==="win32"?"windows":process.platform==="darwin"?"mac":"other":"other";let gs=0;const W0=5e3;let eu=0;const K0=100;async function Es(){if(Zl==="mac"&&Yr==="node"){const{openApp:e}=await import("./index-CUVsbCmX.js");if(eu>=K0){console.warn("Too many Anki App launch attempts this session, ignoring");return}(gs===0||Date.now()-gs>W0)&&(console.warn("Attempting to launch Anki app"),gs=Date.now(),eu++,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(Es,"h$1"),Jl(Es,"launchAnkiApp");const _t={autoLaunch:!1,fetchAdapter:fetch.bind(globalThis),host:"http://127.0.0.1",key:void 0,port:8765,version:6};class Yn{static{s(this,"f")}static{Jl(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??_t.host,this.port=t?.port??_t.port,this.version=t?.version??_t.version,this.key=t?.key??_t.key,this.autoLaunch=t?.autoLaunch??_t.autoLaunch,_t.fetchAdapter===void 0)throw new Error("A fetch implementation is required");if(this.fetchAdapter=t?.fetchAdapter??_t.fetchAdapter,(Zl!=="mac"||Yr!=="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"&&Es()}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(a){if(this.autoLaunch!==!1)return console.warn("Can't connect to Anki app, retrying with auto-launch..."),await Es(),await new Promise(o=>{setTimeout(o,500)}),n===void 0?this.invoke(t):this.invoke(t,n);throw a}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 be=class extends Error{static{s(this,"ShikiError")}constructor(t){super(t),this.name="ShikiError"}};function Q0(e){return Ts(e)}s(Q0,"clone");function Ts(e){return Array.isArray(e)?X0(e):e instanceof RegExp?e:typeof e=="object"?J0(e):e}s(Ts,"doClone");function X0(e){let t=[];for(let n=0,r=e.length;n<r;n++)t[n]=Ts(e[n]);return t}s(X0,"cloneArray");function J0(e){let t={};for(let n in e)t[n]=Ts(e[n]);return t}s(J0,"cloneObj");function tu(e,...t){return t.forEach(n=>{for(let r in n)e[r]=n[r]}),e}s(tu,"mergeObjects");function nu(e){const t=~e.lastIndexOf("/")||~e.lastIndexOf("\\");return t===0?e:~t===e.length-1?nu(e.substring(0,e.length-1)):e.substr(~t+1)}s(nu,"basename$1");var ys=/\$(\d+)|\${(\d+):\/(downcase|upcase)}/g,jr=class{static{s(this,"RegexSource")}static hasCaptures(e){return e===null?!1:(ys.lastIndex=0,ys.test(e))}static replaceCaptures(e,t,n){return e.replace(ys,(r,i,a,o)=>{let l=n[parseInt(i||a,10)];if(l){let u=t.substring(l.start,l.end);for(;u[0]===".";)u=u.substring(1);switch(o){case"downcase":return u.toLowerCase();case"upcase":return u.toUpperCase();default:return u}}else return r})}};function ru(e,t){return e<t?-1:e>t?1:0}s(ru,"strcmp");function iu(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 a=ru(e[i],t[i]);if(a!==0)return a}return 0}return n-r}s(iu,"strArrCmp");function su(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(su,"isValidHexColor");function au(e){return e.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g,"\\$&")}s(au,"escapeRegExpCharacters");var ou=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}},Gr=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(tT(e),t)}static createFromParsedTheme(e,t){return rT(e,t)}_cachedMatchRoot=new ou(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=>Z0(e.parent,i.parentScopes));return r?new lu(r.fontStyle,r.foreground,r.background):null}},As=class hs{static{s(this,"_ScopeStack")}constructor(t,n){this.parent=t,this.scopeName=n}static push(t,n){for(const r of n)t=new hs(t,r);return t}static from(...t){let n=null;for(let r=0;r<t.length;r++)n=new hs(n,t[r]);return n}push(t){return new hs(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 Z0(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&&!eT(e.scopeName,r);){if(i)return!1;e=e.parent}if(!e)return!1;e=e.parent}return!0}s(Z0,"_scopePathMatchesParentScopes");function eT(e,t){return t===e||e.startsWith(t)&&e[t.length]==="."}s(eT,"_matchesScope");var lu=class{static{s(this,"StyleAttributes")}constructor(e,t,n){this.fontStyle=e,this.foregroundId=t,this.backgroundId=n}};function tT(e){if(!e)return[];if(!e.settings||!Array.isArray(e.settings))return[];let t=e.settings,n=[],r=0;for(let i=0,a=t.length;i<a;i++){let o=t[i];if(!o.settings)continue;let l;if(typeof o.scope=="string"){let h=o.scope;h=h.replace(/^[,]+/,""),h=h.replace(/[,]+$/,""),l=h.split(",")}else Array.isArray(o.scope)?l=o.scope:l=[""];let u=-1;if(typeof o.settings.fontStyle=="string"){u=0;let h=o.settings.fontStyle.split(" ");for(let m=0,d=h.length;m<d;m++)switch(h[m]){case"italic":u=u|1;break;case"bold":u=u|2;break;case"underline":u=u|4;break;case"strikethrough":u=u|8;break}}let c=null;typeof o.settings.foreground=="string"&&su(o.settings.foreground)&&(c=o.settings.foreground);let f=null;typeof o.settings.background=="string"&&su(o.settings.background)&&(f=o.settings.background);for(let h=0,m=l.length;h<m;h++){let g=l[h].trim().split(" "),E=g[g.length-1],T=null;g.length>1&&(T=g.slice(0,g.length-1),T.reverse()),n[r++]=new nT(E,T,i,u,c,f)}}return n}s(tT,"parseTheme");var nT=class{static{s(this,"ParsedThemeRule")}constructor(e,t,n,r,i,a){this.scope=e,this.parentScopes=t,this.index=n,this.fontStyle=r,this.foreground=i,this.background=a}},Et=(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))(Et||{});function rT(e,t){e.sort((u,c)=>{let f=ru(u.scope,c.scope);return f!==0||(f=iu(u.parentScopes,c.parentScopes),f!==0)?f:u.index-c.index});let n=0,r="#000000",i="#ffffff";for(;e.length>=1&&e[0].scope==="";){let u=e.shift();u.fontStyle!==-1&&(n=u.fontStyle),u.foreground!==null&&(r=u.foreground),u.background!==null&&(i=u.background)}let a=new iT(t),o=new lu(n,a.getId(r),a.getId(i)),l=new aT(new bs(0,null,-1,0,0),[]);for(let u=0,c=e.length;u<c;u++){let f=e[u];l.insert(0,f.scope,f.parentScopes,f.fontStyle,a.getId(f.foreground),a.getId(f.background))}return new Gr(a,o,l)}s(rT,"resolveParsedThemeRules");var iT=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)}},sT=Object.freeze([]),bs=class Xm{static{s(this,"_ThemeTrieElementRule")}scopeDepth;parentScopes;fontStyle;foreground;background;constructor(t,n,r,i,a){this.scopeDepth=t,this.parentScopes=n||sT,this.fontStyle=r,this.foreground=i,this.background=a}clone(){return new Xm(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)}},aT=class Ol{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 a=n.parentScopes[i].length-t.parentScopes[r].length;if(a!==0)return a;r++,i++}return n.parentScopes.length-t.parentScopes.length}match(t){if(t!==""){let r=t.indexOf("."),i,a;if(r===-1?(i=t,a=""):(i=t.substring(0,r),a=t.substring(r+1)),this._children.hasOwnProperty(i))return this._children[i].match(a)}const n=this._rulesWithParentScopes.concat(this._mainRule);return n.sort(Ol._cmpBySpecificity),n}insert(t,n,r,i,a,o){if(n===""){this._doInsertHere(t,r,i,a,o);return}let l=n.indexOf("."),u,c;l===-1?(u=n,c=""):(u=n.substring(0,l),c=n.substring(l+1));let f;this._children.hasOwnProperty(u)?f=this._children[u]:(f=new Ol(this._mainRule.clone(),bs.cloneArr(this._rulesWithParentScopes)),this._children[u]=f),f.insert(t+1,c,r,i,a,o)}_doInsertHere(t,n,r,i,a){if(n===null){this._mainRule.acceptOverwrite(t,r,i,a);return}for(let o=0,l=this._rulesWithParentScopes.length;o<l;o++){let u=this._rulesWithParentScopes[o];if(iu(u.parentScopes,n)===0){u.acceptOverwrite(t,r,i,a);return}}r===-1&&(r=this._mainRule.fontStyle),i===0&&(i=this._mainRule.foreground),a===0&&(a=this._mainRule.background),this._rulesWithParentScopes.push(new bs(t,n,r,i,a))}},un=class Ke{static{s(this,"_EncodedTokenMetadata")}static toBinaryStr(t){return t.toString(2).padStart(32,"0")}static print(t){const n=Ke.getLanguageId(t),r=Ke.getTokenType(t),i=Ke.getFontStyle(t),a=Ke.getForeground(t),o=Ke.getBackground(t);console.log({languageId:n,tokenType:r,fontStyle:i,foreground:a,background:o})}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,a,o,l){let u=Ke.getLanguageId(t),c=Ke.getTokenType(t),f=Ke.containsBalancedBrackets(t)?1:0,h=Ke.getFontStyle(t),m=Ke.getForeground(t),d=Ke.getBackground(t);return n!==0&&(u=n),r!==8&&(c=r),i!==null&&(f=i?1:0),a!==-1&&(h=a),o!==0&&(m=o),l!==0&&(d=l),(u<<0|c<<8|f<<10|h<<11|m<<15|d<<24)>>>0}};function kR(e){return e}s(kR,"toOptionalTokenType");function _R(e){return e}s(_R,"fromOptionalTokenType");function Vr(e,t){const n=[],r=oT(e);let i=r.next();for(;i!==null;){let u=0;if(i.length===2&&i.charAt(1)===":"){switch(i.charAt(0)){case"R":u=1;break;case"L":u=-1;break;default:console.log(`Unknown priority ${i} in scope selector`)}i=r.next()}let c=o();if(n.push({matcher:c,priority:u}),i!==",")break;i=r.next()}return n;function a(){if(i==="-"){i=r.next();const u=a();return c=>!!u&&!u(c)}if(i==="("){i=r.next();const u=l();return i===")"&&(i=r.next()),u}if(uu(i)){const u=[];do u.push(i),i=r.next();while(uu(i));return c=>t(u,c)}return null}function o(){const u=[];let c=a();for(;c;)u.push(c),c=a();return f=>u.every(h=>h(f))}function l(){const u=[];let c=o();for(;c&&(u.push(c),i==="|"||i===",");){do i=r.next();while(i==="|"||i===",");c=o()}return f=>u.some(h=>h(f))}}s(Vr,"createMatchers");function uu(e){return!!e&&!!e.match(/[\w\.:]+/)}s(uu,"isIdentifier");function oT(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(oT,"newTokenizer");function cu(e){typeof e.dispose=="function"&&e.dispose()}s(cu,"disposeOnigString");var jn=class{static{s(this,"TopLevelRuleReference")}constructor(e){this.scopeName=e}toKey(){return this.scopeName}},lT=class{static{s(this,"TopLevelRepositoryRuleReference")}constructor(e,t){this.scopeName=e,this.ruleName=t}toKey(){return`${this.scopeName}#${this.ruleName}`}},uT=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))}},cT=class{static{s(this,"ScopeDependencyProcessor")}constructor(e,t){this.repo=e,this.initialScopeName=t,this.seenFullScopeRequests.add(this.initialScopeName),this.Q=[new jn(this.initialScopeName)]}seenFullScopeRequests=new Set;seenPartialScopeRequests=new Set;Q;processQueue(){const e=this.Q;this.Q=[];const t=new uT;for(const n of e)hT(n,this.initialScopeName,this.repo,t);for(const n of t.references)if(n instanceof jn){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 hT(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 a=n.lookup(t);e instanceof jn?Wr({baseGrammar:a,selfGrammar:i},r):Ds(e.ruleName,{baseGrammar:a,selfGrammar:i,repository:i.repository},r);const o=n.injections(e.scopeName);if(o)for(const l of o)r.add(new jn(l))}s(hT,"collectReferencesOfReference");function Ds(e,t,n){if(t.repository&&t.repository[e]){const r=t.repository[e];Kr([r],t,n)}}s(Ds,"collectExternalReferencesInTopLevelRepositoryRule");function Wr(e,t){e.selfGrammar.patterns&&Array.isArray(e.selfGrammar.patterns)&&Kr(e.selfGrammar.patterns,{...e,repository:e.selfGrammar.repository},t),e.selfGrammar.injections&&Kr(Object.values(e.selfGrammar.injections),{...e,repository:e.selfGrammar.repository},t)}s(Wr,"collectExternalReferencesInTopLevelRule");function Kr(e,t,n){for(const r of e){if(n.visitedRule.has(r))continue;n.visitedRule.add(r);const i=r.repository?tu({},t.repository,r.repository):t.repository;Array.isArray(r.patterns)&&Kr(r.patterns,{...t,repository:i},n);const a=r.include;if(!a)continue;const o=hu(a);switch(o.kind){case 0:Wr({...t,selfGrammar:t.baseGrammar},n);break;case 1:Wr(t,n);break;case 2:Ds(o.ruleName,{...t,repository:i},n);break;case 3:case 4:const l=o.scopeName===t.selfGrammar.scopeName?t.selfGrammar:o.scopeName===t.baseGrammar.scopeName?t.baseGrammar:void 0;if(l){const u={baseGrammar:t.baseGrammar,selfGrammar:l,repository:i};o.kind===4?Ds(o.ruleName,u,n):Wr(u,n)}else o.kind===4?n.add(new lT(o.scopeName,o.ruleName)):n.add(new jn(o.scopeName));break}}}s(Kr,"collectExternalReferencesInRules");var fT=class{static{s(this,"BaseReference")}kind=0},pT=class{static{s(this,"SelfReference")}kind=1},dT=class{static{s(this,"RelativeReference")}constructor(e){this.ruleName=e}kind=2},mT=class{static{s(this,"TopLevelReference")}constructor(e){this.scopeName=e}kind=3},gT=class{static{s(this,"TopLevelRepositoryReference")}constructor(e,t){this.scopeName=e,this.ruleName=t}kind=4};function hu(e){if(e==="$base")return new fT;if(e==="$self")return new pT;const t=e.indexOf("#");if(t===-1)return new mT(e);if(t===0)return new dT(e.substring(1));{const n=e.substring(0,t),r=e.substring(t+1);return new gT(n,r)}}s(hu,"parseInclude");var ET=/\\(\d+)/,fu=/\\(\d+)/g,TT=-1,pu=-2;function SR(e){return e}s(SR,"ruleIdFromNumber");function wR(e){return e}s(wR,"ruleIdToNumber");var Gn=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=jr.hasCaptures(this._name),this._contentName=r||null,this._contentNameIsCapturing=jr.hasCaptures(this._contentName)}get debugName(){const e=this.$location?`${nu(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:jr.replaceCaptures(this._name,e,t)}getContentName(e,t){return!this._contentNameIsCapturing||this._contentName===null?this._contentName:jr.replaceCaptures(this._contentName,e,t)}},yT=class extends Gn{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!")}},AT=class extends Gn{static{s(this,"MatchRule")}_match;captures;_cachedCompiledPatterns;constructor(e,t,n,r,i){super(e,t,n,null),this._match=new Vn(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 Wn,this.collectPatterns(e,this._cachedCompiledPatterns)),this._cachedCompiledPatterns}},du=class extends Gn{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 Wn,this.collectPatterns(e,this._cachedCompiledPatterns)),this._cachedCompiledPatterns}},Cs=class extends Gn{static{s(this,"BeginEndRule")}_begin;beginCaptures;_end;endHasBackReferences;endCaptures;applyEndPatternLast;hasMissingPatterns;patterns;_cachedCompiledPatterns;constructor(e,t,n,r,i,a,o,l,u,c){super(e,t,n,r),this._begin=new Vn(i,this.id),this.beginCaptures=a,this._end=new Vn(o||"\uFFFF",-1),this.endHasBackReferences=this._end.hasBackReferences,this.endCaptures=l,this.applyEndPatternLast=u||!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 Wn;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}},Qr=class extends Gn{static{s(this,"BeginWhileRule")}_begin;beginCaptures;whileCaptures;_while;whileHasBackReferences;hasMissingPatterns;patterns;_cachedCompiledPatterns;_cachedCompiledWhilePatterns;constructor(e,t,n,r,i,a,o,l,u){super(e,t,n,r),this._begin=new Vn(i,this.id),this.beginCaptures=a,this.whileCaptures=l,this._while=new Vn(o,pu),this.whileHasBackReferences=this._while.hasBackReferences,this.patterns=u.patterns,this.hasMissingPatterns=u.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 Wn;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 Wn,this._cachedCompiledWhilePatterns.push(this._while.hasBackReferences?this._while.clone():this._while)),this._while.hasBackReferences&&this._cachedCompiledWhilePatterns.setSource(0,t||"\uFFFF"),this._cachedCompiledWhilePatterns}},mu=class we{static{s(this,"_RuleFactory")}static createCaptureRule(t,n,r,i,a){return t.registerRule(o=>new yT(n,o,r,i,a))}static getCompiledRuleId(t,n,r){return t.id||n.registerRule(i=>{if(t.id=i,t.match)return new AT(t.$vscodeTextmateLocation,t.id,t.name,t.match,we._compileCaptures(t.captures,n,r));if(typeof t.begin>"u"){t.repository&&(r=tu({},r,t.repository));let a=t.patterns;return typeof a>"u"&&t.include&&(a=[{include:t.include}]),new du(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,we._compilePatterns(a,n,r))}return t.while?new Qr(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,t.begin,we._compileCaptures(t.beginCaptures||t.captures,n,r),t.while,we._compileCaptures(t.whileCaptures||t.captures,n,r),we._compilePatterns(t.patterns,n,r)):new Cs(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,t.begin,we._compileCaptures(t.beginCaptures||t.captures,n,r),t.end,we._compileCaptures(t.endCaptures||t.captures,n,r),t.applyEndPatternLast,we._compilePatterns(t.patterns,n,r))}),t.id}static _compileCaptures(t,n,r){let i=[];if(t){let a=0;for(const o in t){if(o==="$vscodeTextmateLocation")continue;const l=parseInt(o,10);l>a&&(a=l)}for(let o=0;o<=a;o++)i[o]=null;for(const o in t){if(o==="$vscodeTextmateLocation")continue;const l=parseInt(o,10);let u=0;t[o].patterns&&(u=we.getCompiledRuleId(t[o],n,r)),i[l]=we.createCaptureRule(n,t[o].$vscodeTextmateLocation,t[o].name,t[o].contentName,u)}}return i}static _compilePatterns(t,n,r){let i=[];if(t)for(let a=0,o=t.length;a<o;a++){const l=t[a];let u=-1;if(l.include){const c=hu(l.include);switch(c.kind){case 0:case 1:u=we.getCompiledRuleId(r[l.include],n,r);break;case 2:let f=r[c.ruleName];f&&(u=we.getCompiledRuleId(f,n,r));break;case 3:case 4:const h=c.scopeName,m=c.kind===4?c.ruleName:null,d=n.getExternalGrammar(h,r);if(d)if(m){let g=d.repository[m];g&&(u=we.getCompiledRuleId(g,n,d.repository))}else u=we.getCompiledRuleId(d.repository.$self,n,d.repository);break}}else u=we.getCompiledRuleId(l,n,r);if(u!==-1){const c=n.getRule(u);let f=!1;if((c instanceof du||c instanceof Cs||c instanceof Qr)&&c.hasMissingPatterns&&c.patterns.length===0&&(f=!0),f)continue;i.push(u)}}return{patterns:i,hasMissingPatterns:(t?t.length:0)!==i.length}}},Vn=class Jm{static{s(this,"_RegExpSource")}source;ruleId;hasAnchor;hasBackReferences;_anchorCache;constructor(t,n){if(t&&typeof t=="string"){const r=t.length;let i=0,a=[],o=!1;for(let l=0;l<r;l++)if(t.charAt(l)==="\\"&&l+1<r){const c=t.charAt(l+1);c==="z"?(a.push(t.substring(i,l)),a.push("$(?!\\n)(?<!\\n)"),i=l+2):(c==="A"||c==="G")&&(o=!0),l++}this.hasAnchor=o,i===0?this.source=t:(a.push(t.substring(i,r)),this.source=a.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=ET.test(this.source):this.hasBackReferences=!1}clone(){return new Jm(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 fu.lastIndex=0,this.source.replace(fu,(i,a)=>au(r[parseInt(a,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=[],a,o,l,u;for(a=0,o=this.source.length;a<o;a++)l=this.source.charAt(a),t[a]=l,n[a]=l,r[a]=l,i[a]=l,l==="\\"&&a+1<o&&(u=this.source.charAt(a+1),u==="A"?(t[a+1]="\uFFFF",n[a+1]="\uFFFF",r[a+1]="A",i[a+1]="A"):u==="G"?(t[a+1]="\uFFFF",n[a+1]="G",r[a+1]="\uFFFF",i[a+1]="G"):(t[a+1]=u,n[a+1]=u,r[a+1]=u,i[a+1]=u),a++);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}},Wn=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 gu(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 gu(e,r,this._items.map(i=>i.ruleId))}},gu=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}},ks=class{static{s(this,"BasicScopeAttributes")}constructor(e,t){this.languageId=e,this.tokenType=t}},bT=class Rl{static{s(this,"_BasicScopeAttributesProvider")}_defaultAttributes;_embeddedLanguagesMatcher;constructor(t,n){this._defaultAttributes=new ks(t,8),this._embeddedLanguagesMatcher=new DT(Object.entries(n||{}))}getDefaultAttributes(){return this._defaultAttributes}getBasicScopeAttributes(t){return t===null?Rl._NULL_SCOPE_METADATA:this._getBasicScopeAttributes.get(t)}static _NULL_SCOPE_METADATA=new ks(0,0);_getBasicScopeAttributes=new ou(t=>{const n=this._scopeToLanguage(t),r=this._toStandardTokenType(t);return new ks(n,r)});_scopeToLanguage(t){return this._embeddedLanguagesMatcher.match(t)||0}_toStandardTokenType(t){const n=t.match(Rl.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/},DT=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])=>au(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 Eu=class{static{s(this,"TokenizeStringResult")}constructor(e,t){this.stack=e,this.stoppedEarly=t}};function Tu(e,t,n,r,i,a,o,l){const u=t.content.length;let c=!1,f=-1;if(o){const d=CT(e,t,n,r,i,a);i=d.stack,r=d.linePos,n=d.isFirstLine,f=d.anchorPosition}const h=Date.now();for(;!c;){if(l!==0&&Date.now()-h>l)return new Eu(i,!0);m()}return new Eu(i,!1);function m(){const d=kT(e,t,n,r,i,f);if(!d){a.produce(i,u),c=!0;return}const g=d.captureIndices,E=d.matchedRuleId,T=g&&g.length>0?g[0].end>r:!1;if(E===TT){const y=i.getRule(e);a.produce(i,g[0].start),i=i.withContentNameScopesList(i.nameScopesList),Kn(e,t,n,i,a,y.endCaptures,g),a.produce(i,g[0].end);const A=i;if(i=i.parent,f=A.getAnchorPos(),!T&&A.getEnterPos()===r){i=A,a.produce(i,u),c=!0;return}}else{const y=e.getRule(E);a.produce(i,g[0].start);const A=i,D=y.getName(t.content,g),L=i.contentNameScopesList.pushAttributed(D,e);if(i=i.push(E,r,f,g[0].end===u,null,L,L),y instanceof Cs){const x=y;Kn(e,t,n,i,a,x.beginCaptures,g),a.produce(i,g[0].end),f=g[0].end;const k=x.getContentName(t.content,g),O=L.pushAttributed(k,e);if(i=i.withContentNameScopesList(O),x.endHasBackReferences&&(i=i.withEndRule(x.getEndWithResolvedBackReferences(t.content,g))),!T&&A.hasSameRuleAs(i)){i=i.pop(),a.produce(i,u),c=!0;return}}else if(y instanceof Qr){const x=y;Kn(e,t,n,i,a,x.beginCaptures,g),a.produce(i,g[0].end),f=g[0].end;const k=x.getContentName(t.content,g),O=L.pushAttributed(k,e);if(i=i.withContentNameScopesList(O),x.whileHasBackReferences&&(i=i.withEndRule(x.getWhileWithResolvedBackReferences(t.content,g))),!T&&A.hasSameRuleAs(i)){i=i.pop(),a.produce(i,u),c=!0;return}}else if(Kn(e,t,n,i,a,y.captures,g),a.produce(i,g[0].end),i=i.pop(),!T){i=i.safePop(),a.produce(i,u),c=!0;return}}g[0].end>r&&(r=g[0].end,n=!1)}}s(Tu,"_tokenizeString");function CT(e,t,n,r,i,a){let o=i.beginRuleCapturedEOL?0:-1;const l=[];for(let u=i;u;u=u.pop()){const c=u.getRule(e);c instanceof Qr&&l.push({rule:c,stack:u})}for(let u=l.pop();u;u=l.pop()){const{ruleScanner:c,findOptions:f}=wT(u.rule,e,u.stack.endRule,n,r===o),h=c.findNextMatchSync(t,r,f);if(h){if(h.ruleId!==pu){i=u.stack.pop();break}h.captureIndices&&h.captureIndices.length&&(a.produce(u.stack,h.captureIndices[0].start),Kn(e,t,n,u.stack,a,u.rule.whileCaptures,h.captureIndices),a.produce(u.stack,h.captureIndices[0].end),o=h.captureIndices[0].end,h.captureIndices[0].end>r&&(r=