index.es-HPHM6KTN.js 210 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864
  1. import {
  2. init_stackblur_es,
  3. processCanvasRGBA,
  4. require_es_array_index_of,
  5. require_es_array_iterator,
  6. require_es_array_reduce,
  7. require_es_array_reverse,
  8. require_es_promise,
  9. require_es_regexp_to_string,
  10. require_es_string_ends_with,
  11. require_es_string_includes,
  12. require_es_string_match,
  13. require_es_string_replace,
  14. require_es_string_split,
  15. require_es_string_starts_with,
  16. require_es_string_trim,
  17. require_raf,
  18. require_rgbcolor,
  19. require_web_dom_collections_iterator
  20. } from "./chunk-YOIY3QGO.js";
  21. import {
  22. _defineProperty,
  23. init_defineProperty
  24. } from "./chunk-G3TCJNWO.js";
  25. import "./chunk-LDZ6JXE5.js";
  26. import {
  27. __esm,
  28. __toESM
  29. } from "./chunk-2LSFTFF7.js";
  30. // node_modules/.pnpm/@babel+runtime@7.28.3/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
  31. function asyncGeneratorStep(n2, t2, e2, r2, o2, a2, c3) {
  32. try {
  33. var i2 = n2[a2](c3), u2 = i2.value;
  34. } catch (n3) {
  35. return void e2(n3);
  36. }
  37. i2.done ? t2(u2) : Promise.resolve(u2).then(r2, o2);
  38. }
  39. function _asyncToGenerator(n2) {
  40. return function() {
  41. var t2 = this, e2 = arguments;
  42. return new Promise(function(r2, o2) {
  43. var a2 = n2.apply(t2, e2);
  44. function _next(n3) {
  45. asyncGeneratorStep(a2, r2, o2, _next, _throw, "next", n3);
  46. }
  47. function _throw(n3) {
  48. asyncGeneratorStep(a2, r2, o2, _next, _throw, "throw", n3);
  49. }
  50. _next(void 0);
  51. });
  52. };
  53. }
  54. var init_asyncToGenerator = __esm({
  55. "node_modules/.pnpm/@babel+runtime@7.28.3/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js"() {
  56. }
  57. });
  58. // node_modules/.pnpm/svg-pathdata@6.0.3/node_modules/svg-pathdata/lib/SVGPathData.module.js
  59. function r(r2, e2) {
  60. if ("function" != typeof e2 && null !== e2)
  61. throw new TypeError("Class extends value " + String(e2) + " is not a constructor or null");
  62. function i2() {
  63. this.constructor = r2;
  64. }
  65. t(r2, e2), r2.prototype = null === e2 ? Object.create(e2) : (i2.prototype = e2.prototype, new i2());
  66. }
  67. function e(t2) {
  68. var r2 = "";
  69. Array.isArray(t2) || (t2 = [t2]);
  70. for (var e2 = 0; e2 < t2.length; e2++) {
  71. var i2 = t2[e2];
  72. if (i2.type === _.CLOSE_PATH)
  73. r2 += "z";
  74. else if (i2.type === _.HORIZ_LINE_TO)
  75. r2 += (i2.relative ? "h" : "H") + i2.x;
  76. else if (i2.type === _.VERT_LINE_TO)
  77. r2 += (i2.relative ? "v" : "V") + i2.y;
  78. else if (i2.type === _.MOVE_TO)
  79. r2 += (i2.relative ? "m" : "M") + i2.x + " " + i2.y;
  80. else if (i2.type === _.LINE_TO)
  81. r2 += (i2.relative ? "l" : "L") + i2.x + " " + i2.y;
  82. else if (i2.type === _.CURVE_TO)
  83. r2 += (i2.relative ? "c" : "C") + i2.x1 + " " + i2.y1 + " " + i2.x2 + " " + i2.y2 + " " + i2.x + " " + i2.y;
  84. else if (i2.type === _.SMOOTH_CURVE_TO)
  85. r2 += (i2.relative ? "s" : "S") + i2.x2 + " " + i2.y2 + " " + i2.x + " " + i2.y;
  86. else if (i2.type === _.QUAD_TO)
  87. r2 += (i2.relative ? "q" : "Q") + i2.x1 + " " + i2.y1 + " " + i2.x + " " + i2.y;
  88. else if (i2.type === _.SMOOTH_QUAD_TO)
  89. r2 += (i2.relative ? "t" : "T") + i2.x + " " + i2.y;
  90. else {
  91. if (i2.type !== _.ARC)
  92. throw new Error('Unexpected command type "' + i2.type + '" at index ' + e2 + ".");
  93. r2 += (i2.relative ? "a" : "A") + i2.rX + " " + i2.rY + " " + i2.xRot + " " + +i2.lArcFlag + " " + +i2.sweepFlag + " " + i2.x + " " + i2.y;
  94. }
  95. }
  96. return r2;
  97. }
  98. function i(t2, r2) {
  99. var e2 = t2[0], i2 = t2[1];
  100. return [e2 * Math.cos(r2) - i2 * Math.sin(r2), e2 * Math.sin(r2) + i2 * Math.cos(r2)];
  101. }
  102. function a() {
  103. for (var t2 = [], r2 = 0; r2 < arguments.length; r2++)
  104. t2[r2] = arguments[r2];
  105. for (var e2 = 0; e2 < t2.length; e2++)
  106. if ("number" != typeof t2[e2])
  107. throw new Error("assertNumbers arguments[" + e2 + "] is not a number. " + typeof t2[e2] + " == typeof " + t2[e2]);
  108. return true;
  109. }
  110. function o(t2, r2, e2) {
  111. t2.lArcFlag = 0 === t2.lArcFlag ? 0 : 1, t2.sweepFlag = 0 === t2.sweepFlag ? 0 : 1;
  112. var a2 = t2.rX, o2 = t2.rY, s2 = t2.x, u2 = t2.y;
  113. a2 = Math.abs(t2.rX), o2 = Math.abs(t2.rY);
  114. var h2 = i([(r2 - s2) / 2, (e2 - u2) / 2], -t2.xRot / 180 * n), c3 = h2[0], y2 = h2[1], p2 = Math.pow(c3, 2) / Math.pow(a2, 2) + Math.pow(y2, 2) / Math.pow(o2, 2);
  115. 1 < p2 && (a2 *= Math.sqrt(p2), o2 *= Math.sqrt(p2)), t2.rX = a2, t2.rY = o2;
  116. var m3 = Math.pow(a2, 2) * Math.pow(y2, 2) + Math.pow(o2, 2) * Math.pow(c3, 2), O2 = (t2.lArcFlag !== t2.sweepFlag ? 1 : -1) * Math.sqrt(Math.max(0, (Math.pow(a2, 2) * Math.pow(o2, 2) - m3) / m3)), l2 = a2 * y2 / o2 * O2, T2 = -o2 * c3 / a2 * O2, v2 = i([l2, T2], t2.xRot / 180 * n);
  117. t2.cX = v2[0] + (r2 + s2) / 2, t2.cY = v2[1] + (e2 + u2) / 2, t2.phi1 = Math.atan2((y2 - T2) / o2, (c3 - l2) / a2), t2.phi2 = Math.atan2((-y2 - T2) / o2, (-c3 - l2) / a2), 0 === t2.sweepFlag && t2.phi2 > t2.phi1 && (t2.phi2 -= 2 * n), 1 === t2.sweepFlag && t2.phi2 < t2.phi1 && (t2.phi2 += 2 * n), t2.phi1 *= 180 / n, t2.phi2 *= 180 / n;
  118. }
  119. function s(t2, r2, e2) {
  120. a(t2, r2, e2);
  121. var i2 = t2 * t2 + r2 * r2 - e2 * e2;
  122. if (0 > i2)
  123. return [];
  124. if (0 === i2)
  125. return [[t2 * e2 / (t2 * t2 + r2 * r2), r2 * e2 / (t2 * t2 + r2 * r2)]];
  126. var n2 = Math.sqrt(i2);
  127. return [[(t2 * e2 + r2 * n2) / (t2 * t2 + r2 * r2), (r2 * e2 - t2 * n2) / (t2 * t2 + r2 * r2)], [(t2 * e2 - r2 * n2) / (t2 * t2 + r2 * r2), (r2 * e2 + t2 * n2) / (t2 * t2 + r2 * r2)]];
  128. }
  129. function c(t2, r2, e2) {
  130. return (1 - e2) * t2 + e2 * r2;
  131. }
  132. function y(t2, r2, e2, i2) {
  133. return t2 + Math.cos(i2 / 180 * n) * r2 + Math.sin(i2 / 180 * n) * e2;
  134. }
  135. function p(t2, r2, e2, i2) {
  136. var a2 = 1e-6, n2 = r2 - t2, o2 = e2 - r2, s2 = 3 * n2 + 3 * (i2 - e2) - 6 * o2, u2 = 6 * (o2 - n2), h2 = 3 * n2;
  137. return Math.abs(s2) < a2 ? [-h2 / u2] : function(t3, r3, e3) {
  138. void 0 === e3 && (e3 = 1e-6);
  139. var i3 = t3 * t3 / 4 - r3;
  140. if (i3 < -e3)
  141. return [];
  142. if (i3 <= e3)
  143. return [-t3 / 2];
  144. var a3 = Math.sqrt(i3);
  145. return [-t3 / 2 - a3, -t3 / 2 + a3];
  146. }(u2 / s2, h2 / s2, a2);
  147. }
  148. function m(t2, r2, e2, i2, a2) {
  149. var n2 = 1 - a2;
  150. return t2 * (n2 * n2 * n2) + r2 * (3 * n2 * n2 * a2) + e2 * (3 * n2 * a2 * a2) + i2 * (a2 * a2 * a2);
  151. }
  152. var t, n, u, h, O, l, T, v, f, _, N;
  153. var init_SVGPathData_module = __esm({
  154. "node_modules/.pnpm/svg-pathdata@6.0.3/node_modules/svg-pathdata/lib/SVGPathData.module.js"() {
  155. t = function(r2, e2) {
  156. return (t = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t2, r3) {
  157. t2.__proto__ = r3;
  158. } || function(t2, r3) {
  159. for (var e3 in r3)
  160. Object.prototype.hasOwnProperty.call(r3, e3) && (t2[e3] = r3[e3]);
  161. })(r2, e2);
  162. };
  163. n = Math.PI;
  164. h = Math.PI / 180;
  165. !function(t2) {
  166. function r2() {
  167. return u2(function(t3, r3, e3) {
  168. return t3.relative && (void 0 !== t3.x1 && (t3.x1 += r3), void 0 !== t3.y1 && (t3.y1 += e3), void 0 !== t3.x2 && (t3.x2 += r3), void 0 !== t3.y2 && (t3.y2 += e3), void 0 !== t3.x && (t3.x += r3), void 0 !== t3.y && (t3.y += e3), t3.relative = false), t3;
  169. });
  170. }
  171. function e2() {
  172. var t3 = NaN, r3 = NaN, e3 = NaN, i2 = NaN;
  173. return u2(function(a2, n3, o2) {
  174. return a2.type & _.SMOOTH_CURVE_TO && (a2.type = _.CURVE_TO, t3 = isNaN(t3) ? n3 : t3, r3 = isNaN(r3) ? o2 : r3, a2.x1 = a2.relative ? n3 - t3 : 2 * n3 - t3, a2.y1 = a2.relative ? o2 - r3 : 2 * o2 - r3), a2.type & _.CURVE_TO ? (t3 = a2.relative ? n3 + a2.x2 : a2.x2, r3 = a2.relative ? o2 + a2.y2 : a2.y2) : (t3 = NaN, r3 = NaN), a2.type & _.SMOOTH_QUAD_TO && (a2.type = _.QUAD_TO, e3 = isNaN(e3) ? n3 : e3, i2 = isNaN(i2) ? o2 : i2, a2.x1 = a2.relative ? n3 - e3 : 2 * n3 - e3, a2.y1 = a2.relative ? o2 - i2 : 2 * o2 - i2), a2.type & _.QUAD_TO ? (e3 = a2.relative ? n3 + a2.x1 : a2.x1, i2 = a2.relative ? o2 + a2.y1 : a2.y1) : (e3 = NaN, i2 = NaN), a2;
  175. });
  176. }
  177. function n2() {
  178. var t3 = NaN, r3 = NaN;
  179. return u2(function(e3, i2, a2) {
  180. if (e3.type & _.SMOOTH_QUAD_TO && (e3.type = _.QUAD_TO, t3 = isNaN(t3) ? i2 : t3, r3 = isNaN(r3) ? a2 : r3, e3.x1 = e3.relative ? i2 - t3 : 2 * i2 - t3, e3.y1 = e3.relative ? a2 - r3 : 2 * a2 - r3), e3.type & _.QUAD_TO) {
  181. t3 = e3.relative ? i2 + e3.x1 : e3.x1, r3 = e3.relative ? a2 + e3.y1 : e3.y1;
  182. var n3 = e3.x1, o2 = e3.y1;
  183. e3.type = _.CURVE_TO, e3.x1 = ((e3.relative ? 0 : i2) + 2 * n3) / 3, e3.y1 = ((e3.relative ? 0 : a2) + 2 * o2) / 3, e3.x2 = (e3.x + 2 * n3) / 3, e3.y2 = (e3.y + 2 * o2) / 3;
  184. } else
  185. t3 = NaN, r3 = NaN;
  186. return e3;
  187. });
  188. }
  189. function u2(t3) {
  190. var r3 = 0, e3 = 0, i2 = NaN, a2 = NaN;
  191. return function(n3) {
  192. if (isNaN(i2) && !(n3.type & _.MOVE_TO))
  193. throw new Error("path must start with moveto");
  194. var o2 = t3(n3, r3, e3, i2, a2);
  195. return n3.type & _.CLOSE_PATH && (r3 = i2, e3 = a2), void 0 !== n3.x && (r3 = n3.relative ? r3 + n3.x : n3.x), void 0 !== n3.y && (e3 = n3.relative ? e3 + n3.y : n3.y), n3.type & _.MOVE_TO && (i2 = r3, a2 = e3), o2;
  196. };
  197. }
  198. function O2(t3, r3, e3, i2, n3, o2) {
  199. return a(t3, r3, e3, i2, n3, o2), u2(function(a2, s2, u3, h2) {
  200. var c3 = a2.x1, y2 = a2.x2, p2 = a2.relative && !isNaN(h2), m3 = void 0 !== a2.x ? a2.x : p2 ? 0 : s2, O3 = void 0 !== a2.y ? a2.y : p2 ? 0 : u3;
  201. function l3(t4) {
  202. return t4 * t4;
  203. }
  204. a2.type & _.HORIZ_LINE_TO && 0 !== r3 && (a2.type = _.LINE_TO, a2.y = a2.relative ? 0 : u3), a2.type & _.VERT_LINE_TO && 0 !== e3 && (a2.type = _.LINE_TO, a2.x = a2.relative ? 0 : s2), void 0 !== a2.x && (a2.x = a2.x * t3 + O3 * e3 + (p2 ? 0 : n3)), void 0 !== a2.y && (a2.y = m3 * r3 + a2.y * i2 + (p2 ? 0 : o2)), void 0 !== a2.x1 && (a2.x1 = a2.x1 * t3 + a2.y1 * e3 + (p2 ? 0 : n3)), void 0 !== a2.y1 && (a2.y1 = c3 * r3 + a2.y1 * i2 + (p2 ? 0 : o2)), void 0 !== a2.x2 && (a2.x2 = a2.x2 * t3 + a2.y2 * e3 + (p2 ? 0 : n3)), void 0 !== a2.y2 && (a2.y2 = y2 * r3 + a2.y2 * i2 + (p2 ? 0 : o2));
  205. var T2 = t3 * i2 - r3 * e3;
  206. if (void 0 !== a2.xRot && (1 !== t3 || 0 !== r3 || 0 !== e3 || 1 !== i2))
  207. if (0 === T2)
  208. delete a2.rX, delete a2.rY, delete a2.xRot, delete a2.lArcFlag, delete a2.sweepFlag, a2.type = _.LINE_TO;
  209. else {
  210. var v2 = a2.xRot * Math.PI / 180, f2 = Math.sin(v2), N2 = Math.cos(v2), x = 1 / l3(a2.rX), d = 1 / l3(a2.rY), E = l3(N2) * x + l3(f2) * d, A = 2 * f2 * N2 * (x - d), C = l3(f2) * x + l3(N2) * d, M = E * i2 * i2 - A * r3 * i2 + C * r3 * r3, R = A * (t3 * i2 + r3 * e3) - 2 * (E * e3 * i2 + C * t3 * r3), g = E * e3 * e3 - A * t3 * e3 + C * t3 * t3, I = (Math.atan2(R, M - g) + Math.PI) % Math.PI / 2, S = Math.sin(I), L = Math.cos(I);
  211. a2.rX = Math.abs(T2) / Math.sqrt(M * l3(L) + R * S * L + g * l3(S)), a2.rY = Math.abs(T2) / Math.sqrt(M * l3(S) - R * S * L + g * l3(L)), a2.xRot = 180 * I / Math.PI;
  212. }
  213. return void 0 !== a2.sweepFlag && 0 > T2 && (a2.sweepFlag = +!a2.sweepFlag), a2;
  214. });
  215. }
  216. function l2() {
  217. return function(t3) {
  218. var r3 = {};
  219. for (var e3 in t3)
  220. r3[e3] = t3[e3];
  221. return r3;
  222. };
  223. }
  224. t2.ROUND = function(t3) {
  225. function r3(r4) {
  226. return Math.round(r4 * t3) / t3;
  227. }
  228. return void 0 === t3 && (t3 = 1e13), a(t3), function(t4) {
  229. return void 0 !== t4.x1 && (t4.x1 = r3(t4.x1)), void 0 !== t4.y1 && (t4.y1 = r3(t4.y1)), void 0 !== t4.x2 && (t4.x2 = r3(t4.x2)), void 0 !== t4.y2 && (t4.y2 = r3(t4.y2)), void 0 !== t4.x && (t4.x = r3(t4.x)), void 0 !== t4.y && (t4.y = r3(t4.y)), void 0 !== t4.rX && (t4.rX = r3(t4.rX)), void 0 !== t4.rY && (t4.rY = r3(t4.rY)), t4;
  230. };
  231. }, t2.TO_ABS = r2, t2.TO_REL = function() {
  232. return u2(function(t3, r3, e3) {
  233. return t3.relative || (void 0 !== t3.x1 && (t3.x1 -= r3), void 0 !== t3.y1 && (t3.y1 -= e3), void 0 !== t3.x2 && (t3.x2 -= r3), void 0 !== t3.y2 && (t3.y2 -= e3), void 0 !== t3.x && (t3.x -= r3), void 0 !== t3.y && (t3.y -= e3), t3.relative = true), t3;
  234. });
  235. }, t2.NORMALIZE_HVZ = function(t3, r3, e3) {
  236. return void 0 === t3 && (t3 = true), void 0 === r3 && (r3 = true), void 0 === e3 && (e3 = true), u2(function(i2, a2, n3, o2, s2) {
  237. if (isNaN(o2) && !(i2.type & _.MOVE_TO))
  238. throw new Error("path must start with moveto");
  239. return r3 && i2.type & _.HORIZ_LINE_TO && (i2.type = _.LINE_TO, i2.y = i2.relative ? 0 : n3), e3 && i2.type & _.VERT_LINE_TO && (i2.type = _.LINE_TO, i2.x = i2.relative ? 0 : a2), t3 && i2.type & _.CLOSE_PATH && (i2.type = _.LINE_TO, i2.x = i2.relative ? o2 - a2 : o2, i2.y = i2.relative ? s2 - n3 : s2), i2.type & _.ARC && (0 === i2.rX || 0 === i2.rY) && (i2.type = _.LINE_TO, delete i2.rX, delete i2.rY, delete i2.xRot, delete i2.lArcFlag, delete i2.sweepFlag), i2;
  240. });
  241. }, t2.NORMALIZE_ST = e2, t2.QT_TO_C = n2, t2.INFO = u2, t2.SANITIZE = function(t3) {
  242. void 0 === t3 && (t3 = 0), a(t3);
  243. var r3 = NaN, e3 = NaN, i2 = NaN, n3 = NaN;
  244. return u2(function(a2, o2, s2, u3, h2) {
  245. var c3 = Math.abs, y2 = false, p2 = 0, m3 = 0;
  246. if (a2.type & _.SMOOTH_CURVE_TO && (p2 = isNaN(r3) ? 0 : o2 - r3, m3 = isNaN(e3) ? 0 : s2 - e3), a2.type & (_.CURVE_TO | _.SMOOTH_CURVE_TO) ? (r3 = a2.relative ? o2 + a2.x2 : a2.x2, e3 = a2.relative ? s2 + a2.y2 : a2.y2) : (r3 = NaN, e3 = NaN), a2.type & _.SMOOTH_QUAD_TO ? (i2 = isNaN(i2) ? o2 : 2 * o2 - i2, n3 = isNaN(n3) ? s2 : 2 * s2 - n3) : a2.type & _.QUAD_TO ? (i2 = a2.relative ? o2 + a2.x1 : a2.x1, n3 = a2.relative ? s2 + a2.y1 : a2.y2) : (i2 = NaN, n3 = NaN), a2.type & _.LINE_COMMANDS || a2.type & _.ARC && (0 === a2.rX || 0 === a2.rY || !a2.lArcFlag) || a2.type & _.CURVE_TO || a2.type & _.SMOOTH_CURVE_TO || a2.type & _.QUAD_TO || a2.type & _.SMOOTH_QUAD_TO) {
  247. var O3 = void 0 === a2.x ? 0 : a2.relative ? a2.x : a2.x - o2, l3 = void 0 === a2.y ? 0 : a2.relative ? a2.y : a2.y - s2;
  248. p2 = isNaN(i2) ? void 0 === a2.x1 ? p2 : a2.relative ? a2.x : a2.x1 - o2 : i2 - o2, m3 = isNaN(n3) ? void 0 === a2.y1 ? m3 : a2.relative ? a2.y : a2.y1 - s2 : n3 - s2;
  249. var T2 = void 0 === a2.x2 ? 0 : a2.relative ? a2.x : a2.x2 - o2, v2 = void 0 === a2.y2 ? 0 : a2.relative ? a2.y : a2.y2 - s2;
  250. c3(O3) <= t3 && c3(l3) <= t3 && c3(p2) <= t3 && c3(m3) <= t3 && c3(T2) <= t3 && c3(v2) <= t3 && (y2 = true);
  251. }
  252. return a2.type & _.CLOSE_PATH && c3(o2 - u3) <= t3 && c3(s2 - h2) <= t3 && (y2 = true), y2 ? [] : a2;
  253. });
  254. }, t2.MATRIX = O2, t2.ROTATE = function(t3, r3, e3) {
  255. void 0 === r3 && (r3 = 0), void 0 === e3 && (e3 = 0), a(t3, r3, e3);
  256. var i2 = Math.sin(t3), n3 = Math.cos(t3);
  257. return O2(n3, i2, -i2, n3, r3 - r3 * n3 + e3 * i2, e3 - r3 * i2 - e3 * n3);
  258. }, t2.TRANSLATE = function(t3, r3) {
  259. return void 0 === r3 && (r3 = 0), a(t3, r3), O2(1, 0, 0, 1, t3, r3);
  260. }, t2.SCALE = function(t3, r3) {
  261. return void 0 === r3 && (r3 = t3), a(t3, r3), O2(t3, 0, 0, r3, 0, 0);
  262. }, t2.SKEW_X = function(t3) {
  263. return a(t3), O2(1, 0, Math.atan(t3), 1, 0, 0);
  264. }, t2.SKEW_Y = function(t3) {
  265. return a(t3), O2(1, Math.atan(t3), 0, 1, 0, 0);
  266. }, t2.X_AXIS_SYMMETRY = function(t3) {
  267. return void 0 === t3 && (t3 = 0), a(t3), O2(-1, 0, 0, 1, t3, 0);
  268. }, t2.Y_AXIS_SYMMETRY = function(t3) {
  269. return void 0 === t3 && (t3 = 0), a(t3), O2(1, 0, 0, -1, 0, t3);
  270. }, t2.A_TO_C = function() {
  271. return u2(function(t3, r3, e3) {
  272. return _.ARC === t3.type ? function(t4, r4, e4) {
  273. var a2, n3, s2, u3;
  274. t4.cX || o(t4, r4, e4);
  275. for (var y2 = Math.min(t4.phi1, t4.phi2), p2 = Math.max(t4.phi1, t4.phi2) - y2, m3 = Math.ceil(p2 / 90), O3 = new Array(m3), l3 = r4, T2 = e4, v2 = 0; v2 < m3; v2++) {
  276. var f2 = c(t4.phi1, t4.phi2, v2 / m3), N2 = c(t4.phi1, t4.phi2, (v2 + 1) / m3), x = N2 - f2, d = 4 / 3 * Math.tan(x * h / 4), E = [Math.cos(f2 * h) - d * Math.sin(f2 * h), Math.sin(f2 * h) + d * Math.cos(f2 * h)], A = E[0], C = E[1], M = [Math.cos(N2 * h), Math.sin(N2 * h)], R = M[0], g = M[1], I = [R + d * Math.sin(N2 * h), g - d * Math.cos(N2 * h)], S = I[0], L = I[1];
  277. O3[v2] = { relative: t4.relative, type: _.CURVE_TO };
  278. var H = function(r5, e5) {
  279. var a3 = i([r5 * t4.rX, e5 * t4.rY], t4.xRot), n4 = a3[0], o2 = a3[1];
  280. return [t4.cX + n4, t4.cY + o2];
  281. };
  282. a2 = H(A, C), O3[v2].x1 = a2[0], O3[v2].y1 = a2[1], n3 = H(S, L), O3[v2].x2 = n3[0], O3[v2].y2 = n3[1], s2 = H(R, g), O3[v2].x = s2[0], O3[v2].y = s2[1], t4.relative && (O3[v2].x1 -= l3, O3[v2].y1 -= T2, O3[v2].x2 -= l3, O3[v2].y2 -= T2, O3[v2].x -= l3, O3[v2].y -= T2), l3 = (u3 = [O3[v2].x, O3[v2].y])[0], T2 = u3[1];
  283. }
  284. return O3;
  285. }(t3, t3.relative ? 0 : r3, t3.relative ? 0 : e3) : t3;
  286. });
  287. }, t2.ANNOTATE_ARCS = function() {
  288. return u2(function(t3, r3, e3) {
  289. return t3.relative && (r3 = 0, e3 = 0), _.ARC === t3.type && o(t3, r3, e3), t3;
  290. });
  291. }, t2.CLONE = l2, t2.CALCULATE_BOUNDS = function() {
  292. var t3 = function(t4) {
  293. var r3 = {};
  294. for (var e3 in t4)
  295. r3[e3] = t4[e3];
  296. return r3;
  297. }, i2 = r2(), a2 = n2(), h2 = e2(), c3 = u2(function(r3, e3, n3) {
  298. var u3 = h2(a2(i2(t3(r3))));
  299. function O3(t4) {
  300. t4 > c3.maxX && (c3.maxX = t4), t4 < c3.minX && (c3.minX = t4);
  301. }
  302. function l3(t4) {
  303. t4 > c3.maxY && (c3.maxY = t4), t4 < c3.minY && (c3.minY = t4);
  304. }
  305. if (u3.type & _.DRAWING_COMMANDS && (O3(e3), l3(n3)), u3.type & _.HORIZ_LINE_TO && O3(u3.x), u3.type & _.VERT_LINE_TO && l3(u3.y), u3.type & _.LINE_TO && (O3(u3.x), l3(u3.y)), u3.type & _.CURVE_TO) {
  306. O3(u3.x), l3(u3.y);
  307. for (var T2 = 0, v2 = p(e3, u3.x1, u3.x2, u3.x); T2 < v2.length; T2++) {
  308. 0 < (w = v2[T2]) && 1 > w && O3(m(e3, u3.x1, u3.x2, u3.x, w));
  309. }
  310. for (var f2 = 0, N2 = p(n3, u3.y1, u3.y2, u3.y); f2 < N2.length; f2++) {
  311. 0 < (w = N2[f2]) && 1 > w && l3(m(n3, u3.y1, u3.y2, u3.y, w));
  312. }
  313. }
  314. if (u3.type & _.ARC) {
  315. O3(u3.x), l3(u3.y), o(u3, e3, n3);
  316. for (var x = u3.xRot / 180 * Math.PI, d = Math.cos(x) * u3.rX, E = Math.sin(x) * u3.rX, A = -Math.sin(x) * u3.rY, C = Math.cos(x) * u3.rY, M = u3.phi1 < u3.phi2 ? [u3.phi1, u3.phi2] : -180 > u3.phi2 ? [u3.phi2 + 360, u3.phi1 + 360] : [u3.phi2, u3.phi1], R = M[0], g = M[1], I = function(t4) {
  317. var r4 = t4[0], e4 = t4[1], i3 = 180 * Math.atan2(e4, r4) / Math.PI;
  318. return i3 < R ? i3 + 360 : i3;
  319. }, S = 0, L = s(A, -d, 0).map(I); S < L.length; S++) {
  320. (w = L[S]) > R && w < g && O3(y(u3.cX, d, A, w));
  321. }
  322. for (var H = 0, U = s(C, -E, 0).map(I); H < U.length; H++) {
  323. var w;
  324. (w = U[H]) > R && w < g && l3(y(u3.cY, E, C, w));
  325. }
  326. }
  327. return r3;
  328. });
  329. return c3.minX = 1 / 0, c3.maxX = -1 / 0, c3.minY = 1 / 0, c3.maxY = -1 / 0, c3;
  330. };
  331. }(u || (u = {}));
  332. l = function() {
  333. function t2() {
  334. }
  335. return t2.prototype.round = function(t3) {
  336. return this.transform(u.ROUND(t3));
  337. }, t2.prototype.toAbs = function() {
  338. return this.transform(u.TO_ABS());
  339. }, t2.prototype.toRel = function() {
  340. return this.transform(u.TO_REL());
  341. }, t2.prototype.normalizeHVZ = function(t3, r2, e2) {
  342. return this.transform(u.NORMALIZE_HVZ(t3, r2, e2));
  343. }, t2.prototype.normalizeST = function() {
  344. return this.transform(u.NORMALIZE_ST());
  345. }, t2.prototype.qtToC = function() {
  346. return this.transform(u.QT_TO_C());
  347. }, t2.prototype.aToC = function() {
  348. return this.transform(u.A_TO_C());
  349. }, t2.prototype.sanitize = function(t3) {
  350. return this.transform(u.SANITIZE(t3));
  351. }, t2.prototype.translate = function(t3, r2) {
  352. return this.transform(u.TRANSLATE(t3, r2));
  353. }, t2.prototype.scale = function(t3, r2) {
  354. return this.transform(u.SCALE(t3, r2));
  355. }, t2.prototype.rotate = function(t3, r2, e2) {
  356. return this.transform(u.ROTATE(t3, r2, e2));
  357. }, t2.prototype.matrix = function(t3, r2, e2, i2, a2, n2) {
  358. return this.transform(u.MATRIX(t3, r2, e2, i2, a2, n2));
  359. }, t2.prototype.skewX = function(t3) {
  360. return this.transform(u.SKEW_X(t3));
  361. }, t2.prototype.skewY = function(t3) {
  362. return this.transform(u.SKEW_Y(t3));
  363. }, t2.prototype.xSymmetry = function(t3) {
  364. return this.transform(u.X_AXIS_SYMMETRY(t3));
  365. }, t2.prototype.ySymmetry = function(t3) {
  366. return this.transform(u.Y_AXIS_SYMMETRY(t3));
  367. }, t2.prototype.annotateArcs = function() {
  368. return this.transform(u.ANNOTATE_ARCS());
  369. }, t2;
  370. }();
  371. T = function(t2) {
  372. return " " === t2 || " " === t2 || "\r" === t2 || "\n" === t2;
  373. };
  374. v = function(t2) {
  375. return "0".charCodeAt(0) <= t2.charCodeAt(0) && t2.charCodeAt(0) <= "9".charCodeAt(0);
  376. };
  377. f = function(t2) {
  378. function e2() {
  379. var r2 = t2.call(this) || this;
  380. return r2.curNumber = "", r2.curCommandType = -1, r2.curCommandRelative = false, r2.canParseCommandOrComma = true, r2.curNumberHasExp = false, r2.curNumberHasExpDigits = false, r2.curNumberHasDecimal = false, r2.curArgs = [], r2;
  381. }
  382. return r(e2, t2), e2.prototype.finish = function(t3) {
  383. if (void 0 === t3 && (t3 = []), this.parse(" ", t3), 0 !== this.curArgs.length || !this.canParseCommandOrComma)
  384. throw new SyntaxError("Unterminated command at the path end.");
  385. return t3;
  386. }, e2.prototype.parse = function(t3, r2) {
  387. var e3 = this;
  388. void 0 === r2 && (r2 = []);
  389. for (var i2 = function(t4) {
  390. r2.push(t4), e3.curArgs.length = 0, e3.canParseCommandOrComma = true;
  391. }, a2 = 0; a2 < t3.length; a2++) {
  392. var n2 = t3[a2], o2 = !(this.curCommandType !== _.ARC || 3 !== this.curArgs.length && 4 !== this.curArgs.length || 1 !== this.curNumber.length || "0" !== this.curNumber && "1" !== this.curNumber), s2 = v(n2) && ("0" === this.curNumber && "0" === n2 || o2);
  393. if (!v(n2) || s2)
  394. if ("e" !== n2 && "E" !== n2)
  395. if ("-" !== n2 && "+" !== n2 || !this.curNumberHasExp || this.curNumberHasExpDigits)
  396. if ("." !== n2 || this.curNumberHasExp || this.curNumberHasDecimal || o2) {
  397. if (this.curNumber && -1 !== this.curCommandType) {
  398. var u2 = Number(this.curNumber);
  399. if (isNaN(u2))
  400. throw new SyntaxError("Invalid number ending at " + a2);
  401. if (this.curCommandType === _.ARC) {
  402. if (0 === this.curArgs.length || 1 === this.curArgs.length) {
  403. if (0 > u2)
  404. throw new SyntaxError('Expected positive number, got "' + u2 + '" at index "' + a2 + '"');
  405. } else if ((3 === this.curArgs.length || 4 === this.curArgs.length) && "0" !== this.curNumber && "1" !== this.curNumber)
  406. throw new SyntaxError('Expected a flag, got "' + this.curNumber + '" at index "' + a2 + '"');
  407. }
  408. this.curArgs.push(u2), this.curArgs.length === N[this.curCommandType] && (_.HORIZ_LINE_TO === this.curCommandType ? i2({ type: _.HORIZ_LINE_TO, relative: this.curCommandRelative, x: u2 }) : _.VERT_LINE_TO === this.curCommandType ? i2({ type: _.VERT_LINE_TO, relative: this.curCommandRelative, y: u2 }) : this.curCommandType === _.MOVE_TO || this.curCommandType === _.LINE_TO || this.curCommandType === _.SMOOTH_QUAD_TO ? (i2({ type: this.curCommandType, relative: this.curCommandRelative, x: this.curArgs[0], y: this.curArgs[1] }), _.MOVE_TO === this.curCommandType && (this.curCommandType = _.LINE_TO)) : this.curCommandType === _.CURVE_TO ? i2({ type: _.CURVE_TO, relative: this.curCommandRelative, x1: this.curArgs[0], y1: this.curArgs[1], x2: this.curArgs[2], y2: this.curArgs[3], x: this.curArgs[4], y: this.curArgs[5] }) : this.curCommandType === _.SMOOTH_CURVE_TO ? i2({ type: _.SMOOTH_CURVE_TO, relative: this.curCommandRelative, x2: this.curArgs[0], y2: this.curArgs[1], x: this.curArgs[2], y: this.curArgs[3] }) : this.curCommandType === _.QUAD_TO ? i2({ type: _.QUAD_TO, relative: this.curCommandRelative, x1: this.curArgs[0], y1: this.curArgs[1], x: this.curArgs[2], y: this.curArgs[3] }) : this.curCommandType === _.ARC && i2({ type: _.ARC, relative: this.curCommandRelative, rX: this.curArgs[0], rY: this.curArgs[1], xRot: this.curArgs[2], lArcFlag: this.curArgs[3], sweepFlag: this.curArgs[4], x: this.curArgs[5], y: this.curArgs[6] })), this.curNumber = "", this.curNumberHasExpDigits = false, this.curNumberHasExp = false, this.curNumberHasDecimal = false, this.canParseCommandOrComma = true;
  409. }
  410. if (!T(n2))
  411. if ("," === n2 && this.canParseCommandOrComma)
  412. this.canParseCommandOrComma = false;
  413. else if ("+" !== n2 && "-" !== n2 && "." !== n2)
  414. if (s2)
  415. this.curNumber = n2, this.curNumberHasDecimal = false;
  416. else {
  417. if (0 !== this.curArgs.length)
  418. throw new SyntaxError("Unterminated command at index " + a2 + ".");
  419. if (!this.canParseCommandOrComma)
  420. throw new SyntaxError('Unexpected character "' + n2 + '" at index ' + a2 + ". Command cannot follow comma");
  421. if (this.canParseCommandOrComma = false, "z" !== n2 && "Z" !== n2)
  422. if ("h" === n2 || "H" === n2)
  423. this.curCommandType = _.HORIZ_LINE_TO, this.curCommandRelative = "h" === n2;
  424. else if ("v" === n2 || "V" === n2)
  425. this.curCommandType = _.VERT_LINE_TO, this.curCommandRelative = "v" === n2;
  426. else if ("m" === n2 || "M" === n2)
  427. this.curCommandType = _.MOVE_TO, this.curCommandRelative = "m" === n2;
  428. else if ("l" === n2 || "L" === n2)
  429. this.curCommandType = _.LINE_TO, this.curCommandRelative = "l" === n2;
  430. else if ("c" === n2 || "C" === n2)
  431. this.curCommandType = _.CURVE_TO, this.curCommandRelative = "c" === n2;
  432. else if ("s" === n2 || "S" === n2)
  433. this.curCommandType = _.SMOOTH_CURVE_TO, this.curCommandRelative = "s" === n2;
  434. else if ("q" === n2 || "Q" === n2)
  435. this.curCommandType = _.QUAD_TO, this.curCommandRelative = "q" === n2;
  436. else if ("t" === n2 || "T" === n2)
  437. this.curCommandType = _.SMOOTH_QUAD_TO, this.curCommandRelative = "t" === n2;
  438. else {
  439. if ("a" !== n2 && "A" !== n2)
  440. throw new SyntaxError('Unexpected character "' + n2 + '" at index ' + a2 + ".");
  441. this.curCommandType = _.ARC, this.curCommandRelative = "a" === n2;
  442. }
  443. else
  444. r2.push({ type: _.CLOSE_PATH }), this.canParseCommandOrComma = true, this.curCommandType = -1;
  445. }
  446. else
  447. this.curNumber = n2, this.curNumberHasDecimal = "." === n2;
  448. } else
  449. this.curNumber += n2, this.curNumberHasDecimal = true;
  450. else
  451. this.curNumber += n2;
  452. else
  453. this.curNumber += n2, this.curNumberHasExp = true;
  454. else
  455. this.curNumber += n2, this.curNumberHasExpDigits = this.curNumberHasExp;
  456. }
  457. return r2;
  458. }, e2.prototype.transform = function(t3) {
  459. return Object.create(this, { parse: { value: function(r2, e3) {
  460. void 0 === e3 && (e3 = []);
  461. for (var i2 = 0, a2 = Object.getPrototypeOf(this).parse.call(this, r2); i2 < a2.length; i2++) {
  462. var n2 = a2[i2], o2 = t3(n2);
  463. Array.isArray(o2) ? e3.push.apply(e3, o2) : e3.push(o2);
  464. }
  465. return e3;
  466. } } });
  467. }, e2;
  468. }(l);
  469. _ = function(t2) {
  470. function i2(r2) {
  471. var e2 = t2.call(this) || this;
  472. return e2.commands = "string" == typeof r2 ? i2.parse(r2) : r2, e2;
  473. }
  474. return r(i2, t2), i2.prototype.encode = function() {
  475. return i2.encode(this.commands);
  476. }, i2.prototype.getBounds = function() {
  477. var t3 = u.CALCULATE_BOUNDS();
  478. return this.transform(t3), t3;
  479. }, i2.prototype.transform = function(t3) {
  480. for (var r2 = [], e2 = 0, i3 = this.commands; e2 < i3.length; e2++) {
  481. var a2 = t3(i3[e2]);
  482. Array.isArray(a2) ? r2.push.apply(r2, a2) : r2.push(a2);
  483. }
  484. return this.commands = r2, this;
  485. }, i2.encode = function(t3) {
  486. return e(t3);
  487. }, i2.parse = function(t3) {
  488. var r2 = new f(), e2 = [];
  489. return r2.parse(t3, e2), r2.finish(e2), e2;
  490. }, i2.CLOSE_PATH = 1, i2.MOVE_TO = 2, i2.HORIZ_LINE_TO = 4, i2.VERT_LINE_TO = 8, i2.LINE_TO = 16, i2.CURVE_TO = 32, i2.SMOOTH_CURVE_TO = 64, i2.QUAD_TO = 128, i2.SMOOTH_QUAD_TO = 256, i2.ARC = 512, i2.LINE_COMMANDS = i2.LINE_TO | i2.HORIZ_LINE_TO | i2.VERT_LINE_TO, i2.DRAWING_COMMANDS = i2.HORIZ_LINE_TO | i2.VERT_LINE_TO | i2.LINE_TO | i2.CURVE_TO | i2.SMOOTH_CURVE_TO | i2.QUAD_TO | i2.SMOOTH_QUAD_TO | i2.ARC, i2;
  491. }(l);
  492. N = ((O = {})[_.MOVE_TO] = 2, O[_.LINE_TO] = 2, O[_.HORIZ_LINE_TO] = 1, O[_.VERT_LINE_TO] = 1, O[_.CLOSE_PATH] = 0, O[_.QUAD_TO] = 4, O[_.SMOOTH_QUAD_TO] = 2, O[_.CURVE_TO] = 6, O[_.SMOOTH_CURVE_TO] = 4, O[_.ARC] = 7, O);
  493. }
  494. });
  495. // node_modules/.pnpm/canvg@3.0.11/node_modules/canvg/lib/index.es.js
  496. function offscreen() {
  497. var {
  498. DOMParser: DOMParserFallback
  499. } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
  500. var preset = {
  501. window: null,
  502. ignoreAnimation: true,
  503. ignoreMouse: true,
  504. DOMParser: DOMParserFallback,
  505. createCanvas(width, height) {
  506. return new OffscreenCanvas(width, height);
  507. },
  508. createImage(url) {
  509. return _asyncToGenerator(function* () {
  510. var response = yield fetch(url);
  511. var blob = yield response.blob();
  512. var img = yield createImageBitmap(blob);
  513. return img;
  514. })();
  515. }
  516. };
  517. if (typeof DOMParser !== "undefined" || typeof DOMParserFallback === "undefined") {
  518. Reflect.deleteProperty(preset, "DOMParser");
  519. }
  520. return preset;
  521. }
  522. function node(_ref) {
  523. var {
  524. DOMParser: DOMParser2,
  525. canvas,
  526. fetch: fetch2
  527. } = _ref;
  528. return {
  529. window: null,
  530. ignoreAnimation: true,
  531. ignoreMouse: true,
  532. DOMParser: DOMParser2,
  533. fetch: fetch2,
  534. createCanvas: canvas.createCanvas,
  535. createImage: canvas.loadImage
  536. };
  537. }
  538. function compressSpaces(str) {
  539. return str.replace(/(?!\u3000)\s+/gm, " ");
  540. }
  541. function trimLeft(str) {
  542. return str.replace(/^[\n \t]+/, "");
  543. }
  544. function trimRight(str) {
  545. return str.replace(/[\n \t]+$/, "");
  546. }
  547. function toNumbers(str) {
  548. var matches = (str || "").match(/-?(\d+(?:\.\d*(?:[eE][+-]?\d+)?)?|\.\d+)(?=\D|$)/gm) || [];
  549. return matches.map(parseFloat);
  550. }
  551. function normalizeAttributeName(name) {
  552. if (allUppercase.test(name)) {
  553. return name.toLowerCase();
  554. }
  555. return name;
  556. }
  557. function parseExternalUrl(url) {
  558. var urlMatch = /url\(('([^']+)'|"([^"]+)"|([^'")]+))\)/.exec(url) || [];
  559. return urlMatch[2] || urlMatch[3] || urlMatch[4];
  560. }
  561. function normalizeColor(color) {
  562. if (!color.startsWith("rgb")) {
  563. return color;
  564. }
  565. var rgbParts = 3;
  566. var normalizedColor = color.replace(/\d+(\.\d+)?/g, (num, isFloat) => rgbParts-- && isFloat ? String(Math.round(parseFloat(num))) : num);
  567. return normalizedColor;
  568. }
  569. function findSelectorMatch(selector, regex) {
  570. var matches = regex.exec(selector);
  571. if (!matches) {
  572. return [selector, 0];
  573. }
  574. return [selector.replace(regex, " "), matches.length];
  575. }
  576. function getSelectorSpecificity(selector) {
  577. var specificity = [0, 0, 0];
  578. var currentSelector = selector.replace(/:not\(([^)]*)\)/g, " $1 ").replace(/{[\s\S]*/gm, " ");
  579. var delta = 0;
  580. [currentSelector, delta] = findSelectorMatch(currentSelector, attributeRegex);
  581. specificity[1] += delta;
  582. [currentSelector, delta] = findSelectorMatch(currentSelector, idRegex);
  583. specificity[0] += delta;
  584. [currentSelector, delta] = findSelectorMatch(currentSelector, classRegex);
  585. specificity[1] += delta;
  586. [currentSelector, delta] = findSelectorMatch(currentSelector, pseudoElementRegex);
  587. specificity[2] += delta;
  588. [currentSelector, delta] = findSelectorMatch(currentSelector, pseudoClassWithBracketsRegex);
  589. specificity[1] += delta;
  590. [currentSelector, delta] = findSelectorMatch(currentSelector, pseudoClassRegex);
  591. specificity[1] += delta;
  592. currentSelector = currentSelector.replace(/[*\s+>~]/g, " ").replace(/[#.]/g, " ");
  593. [currentSelector, delta] = findSelectorMatch(currentSelector, elementRegex);
  594. specificity[2] += delta;
  595. return specificity.join("");
  596. }
  597. function vectorMagnitude(v2) {
  598. return Math.sqrt(Math.pow(v2[0], 2) + Math.pow(v2[1], 2));
  599. }
  600. function vectorsRatio(u2, v2) {
  601. return (u2[0] * v2[0] + u2[1] * v2[1]) / (vectorMagnitude(u2) * vectorMagnitude(v2));
  602. }
  603. function vectorsAngle(u2, v2) {
  604. return (u2[0] * v2[1] < u2[1] * v2[0] ? -1 : 1) * Math.acos(vectorsRatio(u2, v2));
  605. }
  606. function CB1(t2) {
  607. return t2 * t2 * t2;
  608. }
  609. function CB2(t2) {
  610. return 3 * t2 * t2 * (1 - t2);
  611. }
  612. function CB3(t2) {
  613. return 3 * t2 * (1 - t2) * (1 - t2);
  614. }
  615. function CB4(t2) {
  616. return (1 - t2) * (1 - t2) * (1 - t2);
  617. }
  618. function QB1(t2) {
  619. return t2 * t2;
  620. }
  621. function QB2(t2) {
  622. return 2 * t2 * (1 - t2);
  623. }
  624. function QB3(t2) {
  625. return (1 - t2) * (1 - t2);
  626. }
  627. function parseTransforms(transform) {
  628. return compressSpaces(transform).trim().replace(/\)([a-zA-Z])/g, ") $1").replace(/\)(\s?,\s?)/g, ") ").split(/\s(?=[a-z])/);
  629. }
  630. function parseTransform(transform) {
  631. var [type, value] = transform.split("(");
  632. return [type.trim(), value.trim().replace(")", "")];
  633. }
  634. function wrapFontFamily(fontFamily) {
  635. var trimmed = fontFamily.trim();
  636. return /^('|")/.test(trimmed) ? trimmed : '"'.concat(trimmed, '"');
  637. }
  638. function prepareFontFamily(fontFamily) {
  639. return typeof process === "undefined" ? fontFamily : fontFamily.trim().split(",").map(wrapFontFamily).join(",");
  640. }
  641. function prepareFontStyle(fontStyle) {
  642. if (!fontStyle) {
  643. return "";
  644. }
  645. var targetFontStyle = fontStyle.trim().toLowerCase();
  646. switch (targetFontStyle) {
  647. case "normal":
  648. case "italic":
  649. case "oblique":
  650. case "inherit":
  651. case "initial":
  652. case "unset":
  653. return targetFontStyle;
  654. default:
  655. if (/^oblique\s+(-|)\d+deg$/.test(targetFontStyle)) {
  656. return targetFontStyle;
  657. }
  658. return "";
  659. }
  660. }
  661. function prepareFontWeight(fontWeight) {
  662. if (!fontWeight) {
  663. return "";
  664. }
  665. var targetFontWeight = fontWeight.trim().toLowerCase();
  666. switch (targetFontWeight) {
  667. case "normal":
  668. case "bold":
  669. case "lighter":
  670. case "bolder":
  671. case "inherit":
  672. case "initial":
  673. case "unset":
  674. return targetFontWeight;
  675. default:
  676. if (/^[\d.]+$/.test(targetFontWeight)) {
  677. return targetFontWeight;
  678. }
  679. return "";
  680. }
  681. }
  682. function ownKeys$2(object, enumerableOnly) {
  683. var keys = Object.keys(object);
  684. if (Object.getOwnPropertySymbols) {
  685. var symbols = Object.getOwnPropertySymbols(object);
  686. if (enumerableOnly) {
  687. symbols = symbols.filter(function(sym) {
  688. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  689. });
  690. }
  691. keys.push.apply(keys, symbols);
  692. }
  693. return keys;
  694. }
  695. function _objectSpread$2(target) {
  696. for (var i2 = 1; i2 < arguments.length; i2++) {
  697. var source = arguments[i2] != null ? arguments[i2] : {};
  698. if (i2 % 2) {
  699. ownKeys$2(Object(source), true).forEach(function(key) {
  700. _defineProperty(target, key, source[key]);
  701. });
  702. } else if (Object.getOwnPropertyDescriptors) {
  703. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  704. } else {
  705. ownKeys$2(Object(source)).forEach(function(key) {
  706. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  707. });
  708. }
  709. }
  710. return target;
  711. }
  712. function imGet(img, x, y2, width, _height, rgba) {
  713. return img[y2 * width * 4 + x * 4 + rgba];
  714. }
  715. function imSet(img, x, y2, width, _height, rgba, val) {
  716. img[y2 * width * 4 + x * 4 + rgba] = val;
  717. }
  718. function m2(matrix, i2, v2) {
  719. var mi = matrix[i2];
  720. return mi * v2;
  721. }
  722. function c2(a2, m1, m22, m3) {
  723. return m1 + Math.cos(a2) * m22 + Math.sin(a2) * m3;
  724. }
  725. function ownKeys$1(object, enumerableOnly) {
  726. var keys = Object.keys(object);
  727. if (Object.getOwnPropertySymbols) {
  728. var symbols = Object.getOwnPropertySymbols(object);
  729. if (enumerableOnly) {
  730. symbols = symbols.filter(function(sym) {
  731. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  732. });
  733. }
  734. keys.push.apply(keys, symbols);
  735. }
  736. return keys;
  737. }
  738. function _objectSpread$1(target) {
  739. for (var i2 = 1; i2 < arguments.length; i2++) {
  740. var source = arguments[i2] != null ? arguments[i2] : {};
  741. if (i2 % 2) {
  742. ownKeys$1(Object(source), true).forEach(function(key) {
  743. _defineProperty(target, key, source[key]);
  744. });
  745. } else if (Object.getOwnPropertyDescriptors) {
  746. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  747. } else {
  748. ownKeys$1(Object(source)).forEach(function(key) {
  749. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  750. });
  751. }
  752. }
  753. return target;
  754. }
  755. function createCanvas(width, height) {
  756. var canvas = document.createElement("canvas");
  757. canvas.width = width;
  758. canvas.height = height;
  759. return canvas;
  760. }
  761. function createImage(_x) {
  762. return _createImage.apply(this, arguments);
  763. }
  764. function _createImage() {
  765. _createImage = _asyncToGenerator(function* (src) {
  766. var anonymousCrossOrigin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
  767. var image = document.createElement("img");
  768. if (anonymousCrossOrigin) {
  769. image.crossOrigin = "Anonymous";
  770. }
  771. return new Promise((resolve, reject) => {
  772. image.onload = () => {
  773. resolve(image);
  774. };
  775. image.onerror = (_event, _source, _lineno, _colno, error) => {
  776. reject(error);
  777. };
  778. image.src = src;
  779. });
  780. });
  781. return _createImage.apply(this, arguments);
  782. }
  783. function ownKeys(object, enumerableOnly) {
  784. var keys = Object.keys(object);
  785. if (Object.getOwnPropertySymbols) {
  786. var symbols = Object.getOwnPropertySymbols(object);
  787. if (enumerableOnly) {
  788. symbols = symbols.filter(function(sym) {
  789. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  790. });
  791. }
  792. keys.push.apply(keys, symbols);
  793. }
  794. return keys;
  795. }
  796. function _objectSpread(target) {
  797. for (var i2 = 1; i2 < arguments.length; i2++) {
  798. var source = arguments[i2] != null ? arguments[i2] : {};
  799. if (i2 % 2) {
  800. ownKeys(Object(source), true).forEach(function(key) {
  801. _defineProperty(target, key, source[key]);
  802. });
  803. } else if (Object.getOwnPropertyDescriptors) {
  804. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  805. } else {
  806. ownKeys(Object(source)).forEach(function(key) {
  807. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  808. });
  809. }
  810. }
  811. return target;
  812. }
  813. var import_es_promise, import_es_string_match, import_es_string_replace, import_es_string_starts_with, import_es_array_iterator, import_web_dom_collections_iterator, import_es_array_reduce, import_es_string_ends_with, import_es_string_split, import_raf, import_es_string_trim, import_rgbcolor, import_es_array_index_of, import_es_string_includes, import_es_array_reverse, import_es_regexp_to_string, index, allUppercase, attributeRegex, idRegex, classRegex, pseudoElementRegex, pseudoClassWithBracketsRegex, pseudoClassRegex, elementRegex, PSEUDO_ZERO, Property, ViewPort, Point, Mouse, defaultWindow, defaultFetch$1, Screen, defaultFetch, DefaultDOMParser, Parser, Translate, Rotate, Scale, Matrix, Skew, SkewX, SkewY, Transform, Element, UnknownElement, Font, BoundingBox, PathParser, RenderedElement, PathElement, GlyphElement, TextElement, TSpanElement, TextNode, SVGElement, RectElement, CircleElement, EllipseElement, LineElement, PolylineElement, PolygonElement, PatternElement, MarkerElement, DefsElement, GElement, GradientElement, LinearGradientElement, RadialGradientElement, StopElement, AnimateElement, AnimateColorElement, AnimateTransformElement, FontElement, FontFaceElement, MissingGlyphElement, TRefElement, AElement, TextPathElement, dataUriRegex, ImageElement, SymbolElement, SVGFontLoader, StyleElement, UseElement, FeColorMatrixElement, MaskElement, noop, ClipPathElement, FilterElement, FeDropShadowElement, FeMorphologyElement, FeCompositeElement, FeGaussianBlurElement, TitleElement, DescElement, elements, Document, Canvg;
  814. var init_index_es = __esm({
  815. "node_modules/.pnpm/canvg@3.0.11/node_modules/canvg/lib/index.es.js"() {
  816. import_es_promise = __toESM(require_es_promise());
  817. init_asyncToGenerator();
  818. import_es_string_match = __toESM(require_es_string_match());
  819. import_es_string_replace = __toESM(require_es_string_replace());
  820. import_es_string_starts_with = __toESM(require_es_string_starts_with());
  821. import_es_array_iterator = __toESM(require_es_array_iterator());
  822. import_web_dom_collections_iterator = __toESM(require_web_dom_collections_iterator());
  823. init_defineProperty();
  824. import_es_array_reduce = __toESM(require_es_array_reduce());
  825. import_es_string_ends_with = __toESM(require_es_string_ends_with());
  826. import_es_string_split = __toESM(require_es_string_split());
  827. import_raf = __toESM(require_raf());
  828. import_es_string_trim = __toESM(require_es_string_trim());
  829. import_rgbcolor = __toESM(require_rgbcolor());
  830. import_es_array_index_of = __toESM(require_es_array_index_of());
  831. import_es_string_includes = __toESM(require_es_string_includes());
  832. import_es_array_reverse = __toESM(require_es_array_reverse());
  833. init_SVGPathData_module();
  834. import_es_regexp_to_string = __toESM(require_es_regexp_to_string());
  835. init_stackblur_es();
  836. index = Object.freeze({
  837. __proto__: null,
  838. offscreen,
  839. node
  840. });
  841. allUppercase = /^[A-Z-]+$/;
  842. attributeRegex = /(\[[^\]]+\])/g;
  843. idRegex = /(#[^\s+>~.[:]+)/g;
  844. classRegex = /(\.[^\s+>~.[:]+)/g;
  845. pseudoElementRegex = /(::[^\s+>~.[:]+|:first-line|:first-letter|:before|:after)/gi;
  846. pseudoClassWithBracketsRegex = /(:[\w-]+\([^)]*\))/gi;
  847. pseudoClassRegex = /(:[^\s+>~.[:]+)/g;
  848. elementRegex = /([^\s+>~.[:]+)/g;
  849. PSEUDO_ZERO = 1e-8;
  850. Property = class _Property {
  851. constructor(document2, name, value) {
  852. this.document = document2;
  853. this.name = name;
  854. this.value = value;
  855. this.isNormalizedColor = false;
  856. }
  857. static empty(document2) {
  858. return new _Property(document2, "EMPTY", "");
  859. }
  860. split() {
  861. var separator = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : " ";
  862. var {
  863. document: document2,
  864. name
  865. } = this;
  866. return compressSpaces(this.getString()).trim().split(separator).map((value) => new _Property(document2, name, value));
  867. }
  868. hasValue(zeroIsValue) {
  869. var {
  870. value
  871. } = this;
  872. return value !== null && value !== "" && (zeroIsValue || value !== 0) && typeof value !== "undefined";
  873. }
  874. isString(regexp) {
  875. var {
  876. value
  877. } = this;
  878. var result = typeof value === "string";
  879. if (!result || !regexp) {
  880. return result;
  881. }
  882. return regexp.test(value);
  883. }
  884. isUrlDefinition() {
  885. return this.isString(/^url\(/);
  886. }
  887. isPixels() {
  888. if (!this.hasValue()) {
  889. return false;
  890. }
  891. var asString = this.getString();
  892. switch (true) {
  893. case asString.endsWith("px"):
  894. case /^[0-9]+$/.test(asString):
  895. return true;
  896. default:
  897. return false;
  898. }
  899. }
  900. setValue(value) {
  901. this.value = value;
  902. return this;
  903. }
  904. getValue(def) {
  905. if (typeof def === "undefined" || this.hasValue()) {
  906. return this.value;
  907. }
  908. return def;
  909. }
  910. getNumber(def) {
  911. if (!this.hasValue()) {
  912. if (typeof def === "undefined") {
  913. return 0;
  914. }
  915. return parseFloat(def);
  916. }
  917. var {
  918. value
  919. } = this;
  920. var n2 = parseFloat(value);
  921. if (this.isString(/%$/)) {
  922. n2 /= 100;
  923. }
  924. return n2;
  925. }
  926. getString(def) {
  927. if (typeof def === "undefined" || this.hasValue()) {
  928. return typeof this.value === "undefined" ? "" : String(this.value);
  929. }
  930. return String(def);
  931. }
  932. getColor(def) {
  933. var color = this.getString(def);
  934. if (this.isNormalizedColor) {
  935. return color;
  936. }
  937. this.isNormalizedColor = true;
  938. color = normalizeColor(color);
  939. this.value = color;
  940. return color;
  941. }
  942. getDpi() {
  943. return 96;
  944. }
  945. getRem() {
  946. return this.document.rootEmSize;
  947. }
  948. getEm() {
  949. return this.document.emSize;
  950. }
  951. getUnits() {
  952. return this.getString().replace(/[0-9.-]/g, "");
  953. }
  954. getPixels(axisOrIsFontSize) {
  955. var processPercent = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
  956. if (!this.hasValue()) {
  957. return 0;
  958. }
  959. var [axis, isFontSize] = typeof axisOrIsFontSize === "boolean" ? [void 0, axisOrIsFontSize] : [axisOrIsFontSize];
  960. var {
  961. viewPort
  962. } = this.document.screen;
  963. switch (true) {
  964. case this.isString(/vmin$/):
  965. return this.getNumber() / 100 * Math.min(viewPort.computeSize("x"), viewPort.computeSize("y"));
  966. case this.isString(/vmax$/):
  967. return this.getNumber() / 100 * Math.max(viewPort.computeSize("x"), viewPort.computeSize("y"));
  968. case this.isString(/vw$/):
  969. return this.getNumber() / 100 * viewPort.computeSize("x");
  970. case this.isString(/vh$/):
  971. return this.getNumber() / 100 * viewPort.computeSize("y");
  972. case this.isString(/rem$/):
  973. return this.getNumber() * this.getRem();
  974. case this.isString(/em$/):
  975. return this.getNumber() * this.getEm();
  976. case this.isString(/ex$/):
  977. return this.getNumber() * this.getEm() / 2;
  978. case this.isString(/px$/):
  979. return this.getNumber();
  980. case this.isString(/pt$/):
  981. return this.getNumber() * this.getDpi() * (1 / 72);
  982. case this.isString(/pc$/):
  983. return this.getNumber() * 15;
  984. case this.isString(/cm$/):
  985. return this.getNumber() * this.getDpi() / 2.54;
  986. case this.isString(/mm$/):
  987. return this.getNumber() * this.getDpi() / 25.4;
  988. case this.isString(/in$/):
  989. return this.getNumber() * this.getDpi();
  990. case (this.isString(/%$/) && isFontSize):
  991. return this.getNumber() * this.getEm();
  992. case this.isString(/%$/):
  993. return this.getNumber() * viewPort.computeSize(axis);
  994. default: {
  995. var n2 = this.getNumber();
  996. if (processPercent && n2 < 1) {
  997. return n2 * viewPort.computeSize(axis);
  998. }
  999. return n2;
  1000. }
  1001. }
  1002. }
  1003. getMilliseconds() {
  1004. if (!this.hasValue()) {
  1005. return 0;
  1006. }
  1007. if (this.isString(/ms$/)) {
  1008. return this.getNumber();
  1009. }
  1010. return this.getNumber() * 1e3;
  1011. }
  1012. getRadians() {
  1013. if (!this.hasValue()) {
  1014. return 0;
  1015. }
  1016. switch (true) {
  1017. case this.isString(/deg$/):
  1018. return this.getNumber() * (Math.PI / 180);
  1019. case this.isString(/grad$/):
  1020. return this.getNumber() * (Math.PI / 200);
  1021. case this.isString(/rad$/):
  1022. return this.getNumber();
  1023. default:
  1024. return this.getNumber() * (Math.PI / 180);
  1025. }
  1026. }
  1027. getDefinition() {
  1028. var asString = this.getString();
  1029. var name = /#([^)'"]+)/.exec(asString);
  1030. if (name) {
  1031. name = name[1];
  1032. }
  1033. if (!name) {
  1034. name = asString;
  1035. }
  1036. return this.document.definitions[name];
  1037. }
  1038. getFillStyleDefinition(element, opacity) {
  1039. var def = this.getDefinition();
  1040. if (!def) {
  1041. return null;
  1042. }
  1043. if (typeof def.createGradient === "function") {
  1044. return def.createGradient(this.document.ctx, element, opacity);
  1045. }
  1046. if (typeof def.createPattern === "function") {
  1047. if (def.getHrefAttribute().hasValue()) {
  1048. var patternTransform = def.getAttribute("patternTransform");
  1049. def = def.getHrefAttribute().getDefinition();
  1050. if (patternTransform.hasValue()) {
  1051. def.getAttribute("patternTransform", true).setValue(patternTransform.value);
  1052. }
  1053. }
  1054. return def.createPattern(this.document.ctx, element, opacity);
  1055. }
  1056. return null;
  1057. }
  1058. getTextBaseline() {
  1059. if (!this.hasValue()) {
  1060. return null;
  1061. }
  1062. return _Property.textBaselineMapping[this.getString()];
  1063. }
  1064. addOpacity(opacity) {
  1065. var value = this.getColor();
  1066. var len = value.length;
  1067. var commas = 0;
  1068. for (var i2 = 0; i2 < len; i2++) {
  1069. if (value[i2] === ",") {
  1070. commas++;
  1071. }
  1072. if (commas === 3) {
  1073. break;
  1074. }
  1075. }
  1076. if (opacity.hasValue() && this.isString() && commas !== 3) {
  1077. var color = new import_rgbcolor.default(value);
  1078. if (color.ok) {
  1079. color.alpha = opacity.getNumber();
  1080. value = color.toRGBA();
  1081. }
  1082. }
  1083. return new _Property(this.document, this.name, value);
  1084. }
  1085. };
  1086. Property.textBaselineMapping = {
  1087. "baseline": "alphabetic",
  1088. "before-edge": "top",
  1089. "text-before-edge": "top",
  1090. "middle": "middle",
  1091. "central": "middle",
  1092. "after-edge": "bottom",
  1093. "text-after-edge": "bottom",
  1094. "ideographic": "ideographic",
  1095. "alphabetic": "alphabetic",
  1096. "hanging": "hanging",
  1097. "mathematical": "alphabetic"
  1098. };
  1099. ViewPort = class {
  1100. constructor() {
  1101. this.viewPorts = [];
  1102. }
  1103. clear() {
  1104. this.viewPorts = [];
  1105. }
  1106. setCurrent(width, height) {
  1107. this.viewPorts.push({
  1108. width,
  1109. height
  1110. });
  1111. }
  1112. removeCurrent() {
  1113. this.viewPorts.pop();
  1114. }
  1115. getCurrent() {
  1116. var {
  1117. viewPorts
  1118. } = this;
  1119. return viewPorts[viewPorts.length - 1];
  1120. }
  1121. get width() {
  1122. return this.getCurrent().width;
  1123. }
  1124. get height() {
  1125. return this.getCurrent().height;
  1126. }
  1127. computeSize(d) {
  1128. if (typeof d === "number") {
  1129. return d;
  1130. }
  1131. if (d === "x") {
  1132. return this.width;
  1133. }
  1134. if (d === "y") {
  1135. return this.height;
  1136. }
  1137. return Math.sqrt(Math.pow(this.width, 2) + Math.pow(this.height, 2)) / Math.sqrt(2);
  1138. }
  1139. };
  1140. Point = class _Point {
  1141. constructor(x, y2) {
  1142. this.x = x;
  1143. this.y = y2;
  1144. }
  1145. static parse(point) {
  1146. var defaultValue = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
  1147. var [x = defaultValue, y2 = defaultValue] = toNumbers(point);
  1148. return new _Point(x, y2);
  1149. }
  1150. static parseScale(scale) {
  1151. var defaultValue = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
  1152. var [x = defaultValue, y2 = x] = toNumbers(scale);
  1153. return new _Point(x, y2);
  1154. }
  1155. static parsePath(path) {
  1156. var points = toNumbers(path);
  1157. var len = points.length;
  1158. var pathPoints = [];
  1159. for (var i2 = 0; i2 < len; i2 += 2) {
  1160. pathPoints.push(new _Point(points[i2], points[i2 + 1]));
  1161. }
  1162. return pathPoints;
  1163. }
  1164. angleTo(point) {
  1165. return Math.atan2(point.y - this.y, point.x - this.x);
  1166. }
  1167. applyTransform(transform) {
  1168. var {
  1169. x,
  1170. y: y2
  1171. } = this;
  1172. var xp = x * transform[0] + y2 * transform[2] + transform[4];
  1173. var yp = x * transform[1] + y2 * transform[3] + transform[5];
  1174. this.x = xp;
  1175. this.y = yp;
  1176. }
  1177. };
  1178. Mouse = class {
  1179. constructor(screen) {
  1180. this.screen = screen;
  1181. this.working = false;
  1182. this.events = [];
  1183. this.eventElements = [];
  1184. this.onClick = this.onClick.bind(this);
  1185. this.onMouseMove = this.onMouseMove.bind(this);
  1186. }
  1187. isWorking() {
  1188. return this.working;
  1189. }
  1190. start() {
  1191. if (this.working) {
  1192. return;
  1193. }
  1194. var {
  1195. screen,
  1196. onClick,
  1197. onMouseMove
  1198. } = this;
  1199. var canvas = screen.ctx.canvas;
  1200. canvas.onclick = onClick;
  1201. canvas.onmousemove = onMouseMove;
  1202. this.working = true;
  1203. }
  1204. stop() {
  1205. if (!this.working) {
  1206. return;
  1207. }
  1208. var canvas = this.screen.ctx.canvas;
  1209. this.working = false;
  1210. canvas.onclick = null;
  1211. canvas.onmousemove = null;
  1212. }
  1213. hasEvents() {
  1214. return this.working && this.events.length > 0;
  1215. }
  1216. runEvents() {
  1217. if (!this.working) {
  1218. return;
  1219. }
  1220. var {
  1221. screen: document2,
  1222. events,
  1223. eventElements
  1224. } = this;
  1225. var {
  1226. style
  1227. } = document2.ctx.canvas;
  1228. if (style) {
  1229. style.cursor = "";
  1230. }
  1231. events.forEach((_ref, i2) => {
  1232. var {
  1233. run
  1234. } = _ref;
  1235. var element = eventElements[i2];
  1236. while (element) {
  1237. run(element);
  1238. element = element.parent;
  1239. }
  1240. });
  1241. this.events = [];
  1242. this.eventElements = [];
  1243. }
  1244. checkPath(element, ctx) {
  1245. if (!this.working || !ctx) {
  1246. return;
  1247. }
  1248. var {
  1249. events,
  1250. eventElements
  1251. } = this;
  1252. events.forEach((_ref2, i2) => {
  1253. var {
  1254. x,
  1255. y: y2
  1256. } = _ref2;
  1257. if (!eventElements[i2] && ctx.isPointInPath && ctx.isPointInPath(x, y2)) {
  1258. eventElements[i2] = element;
  1259. }
  1260. });
  1261. }
  1262. checkBoundingBox(element, boundingBox) {
  1263. if (!this.working || !boundingBox) {
  1264. return;
  1265. }
  1266. var {
  1267. events,
  1268. eventElements
  1269. } = this;
  1270. events.forEach((_ref3, i2) => {
  1271. var {
  1272. x,
  1273. y: y2
  1274. } = _ref3;
  1275. if (!eventElements[i2] && boundingBox.isPointInBox(x, y2)) {
  1276. eventElements[i2] = element;
  1277. }
  1278. });
  1279. }
  1280. mapXY(x, y2) {
  1281. var {
  1282. window: window2,
  1283. ctx
  1284. } = this.screen;
  1285. var point = new Point(x, y2);
  1286. var element = ctx.canvas;
  1287. while (element) {
  1288. point.x -= element.offsetLeft;
  1289. point.y -= element.offsetTop;
  1290. element = element.offsetParent;
  1291. }
  1292. if (window2.scrollX) {
  1293. point.x += window2.scrollX;
  1294. }
  1295. if (window2.scrollY) {
  1296. point.y += window2.scrollY;
  1297. }
  1298. return point;
  1299. }
  1300. onClick(event) {
  1301. var {
  1302. x,
  1303. y: y2
  1304. } = this.mapXY(event.clientX, event.clientY);
  1305. this.events.push({
  1306. type: "onclick",
  1307. x,
  1308. y: y2,
  1309. run(eventTarget) {
  1310. if (eventTarget.onClick) {
  1311. eventTarget.onClick();
  1312. }
  1313. }
  1314. });
  1315. }
  1316. onMouseMove(event) {
  1317. var {
  1318. x,
  1319. y: y2
  1320. } = this.mapXY(event.clientX, event.clientY);
  1321. this.events.push({
  1322. type: "onmousemove",
  1323. x,
  1324. y: y2,
  1325. run(eventTarget) {
  1326. if (eventTarget.onMouseMove) {
  1327. eventTarget.onMouseMove();
  1328. }
  1329. }
  1330. });
  1331. }
  1332. };
  1333. defaultWindow = typeof window !== "undefined" ? window : null;
  1334. defaultFetch$1 = typeof fetch !== "undefined" ? fetch.bind(void 0) : null;
  1335. Screen = class {
  1336. constructor(ctx) {
  1337. var {
  1338. fetch: fetch2 = defaultFetch$1,
  1339. window: window2 = defaultWindow
  1340. } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  1341. this.ctx = ctx;
  1342. this.FRAMERATE = 30;
  1343. this.MAX_VIRTUAL_PIXELS = 3e4;
  1344. this.CLIENT_WIDTH = 800;
  1345. this.CLIENT_HEIGHT = 600;
  1346. this.viewPort = new ViewPort();
  1347. this.mouse = new Mouse(this);
  1348. this.animations = [];
  1349. this.waits = [];
  1350. this.frameDuration = 0;
  1351. this.isReadyLock = false;
  1352. this.isFirstRender = true;
  1353. this.intervalId = null;
  1354. this.window = window2;
  1355. this.fetch = fetch2;
  1356. }
  1357. wait(checker) {
  1358. this.waits.push(checker);
  1359. }
  1360. ready() {
  1361. if (!this.readyPromise) {
  1362. return Promise.resolve();
  1363. }
  1364. return this.readyPromise;
  1365. }
  1366. isReady() {
  1367. if (this.isReadyLock) {
  1368. return true;
  1369. }
  1370. var isReadyLock = this.waits.every((_2) => _2());
  1371. if (isReadyLock) {
  1372. this.waits = [];
  1373. if (this.resolveReady) {
  1374. this.resolveReady();
  1375. }
  1376. }
  1377. this.isReadyLock = isReadyLock;
  1378. return isReadyLock;
  1379. }
  1380. setDefaults(ctx) {
  1381. ctx.strokeStyle = "rgba(0,0,0,0)";
  1382. ctx.lineCap = "butt";
  1383. ctx.lineJoin = "miter";
  1384. ctx.miterLimit = 4;
  1385. }
  1386. setViewBox(_ref) {
  1387. var {
  1388. document: document2,
  1389. ctx,
  1390. aspectRatio,
  1391. width,
  1392. desiredWidth,
  1393. height,
  1394. desiredHeight,
  1395. minX = 0,
  1396. minY = 0,
  1397. refX,
  1398. refY,
  1399. clip = false,
  1400. clipX = 0,
  1401. clipY = 0
  1402. } = _ref;
  1403. var cleanAspectRatio = compressSpaces(aspectRatio).replace(/^defer\s/, "");
  1404. var [aspectRatioAlign, aspectRatioMeetOrSlice] = cleanAspectRatio.split(" ");
  1405. var align = aspectRatioAlign || "xMidYMid";
  1406. var meetOrSlice = aspectRatioMeetOrSlice || "meet";
  1407. var scaleX = width / desiredWidth;
  1408. var scaleY = height / desiredHeight;
  1409. var scaleMin = Math.min(scaleX, scaleY);
  1410. var scaleMax = Math.max(scaleX, scaleY);
  1411. var finalDesiredWidth = desiredWidth;
  1412. var finalDesiredHeight = desiredHeight;
  1413. if (meetOrSlice === "meet") {
  1414. finalDesiredWidth *= scaleMin;
  1415. finalDesiredHeight *= scaleMin;
  1416. }
  1417. if (meetOrSlice === "slice") {
  1418. finalDesiredWidth *= scaleMax;
  1419. finalDesiredHeight *= scaleMax;
  1420. }
  1421. var refXProp = new Property(document2, "refX", refX);
  1422. var refYProp = new Property(document2, "refY", refY);
  1423. var hasRefs = refXProp.hasValue() && refYProp.hasValue();
  1424. if (hasRefs) {
  1425. ctx.translate(-scaleMin * refXProp.getPixels("x"), -scaleMin * refYProp.getPixels("y"));
  1426. }
  1427. if (clip) {
  1428. var scaledClipX = scaleMin * clipX;
  1429. var scaledClipY = scaleMin * clipY;
  1430. ctx.beginPath();
  1431. ctx.moveTo(scaledClipX, scaledClipY);
  1432. ctx.lineTo(width, scaledClipY);
  1433. ctx.lineTo(width, height);
  1434. ctx.lineTo(scaledClipX, height);
  1435. ctx.closePath();
  1436. ctx.clip();
  1437. }
  1438. if (!hasRefs) {
  1439. var isMeetMinY = meetOrSlice === "meet" && scaleMin === scaleY;
  1440. var isSliceMaxY = meetOrSlice === "slice" && scaleMax === scaleY;
  1441. var isMeetMinX = meetOrSlice === "meet" && scaleMin === scaleX;
  1442. var isSliceMaxX = meetOrSlice === "slice" && scaleMax === scaleX;
  1443. if (align.startsWith("xMid") && (isMeetMinY || isSliceMaxY)) {
  1444. ctx.translate(width / 2 - finalDesiredWidth / 2, 0);
  1445. }
  1446. if (align.endsWith("YMid") && (isMeetMinX || isSliceMaxX)) {
  1447. ctx.translate(0, height / 2 - finalDesiredHeight / 2);
  1448. }
  1449. if (align.startsWith("xMax") && (isMeetMinY || isSliceMaxY)) {
  1450. ctx.translate(width - finalDesiredWidth, 0);
  1451. }
  1452. if (align.endsWith("YMax") && (isMeetMinX || isSliceMaxX)) {
  1453. ctx.translate(0, height - finalDesiredHeight);
  1454. }
  1455. }
  1456. switch (true) {
  1457. case align === "none":
  1458. ctx.scale(scaleX, scaleY);
  1459. break;
  1460. case meetOrSlice === "meet":
  1461. ctx.scale(scaleMin, scaleMin);
  1462. break;
  1463. case meetOrSlice === "slice":
  1464. ctx.scale(scaleMax, scaleMax);
  1465. break;
  1466. }
  1467. ctx.translate(-minX, -minY);
  1468. }
  1469. start(element) {
  1470. var {
  1471. enableRedraw = false,
  1472. ignoreMouse = false,
  1473. ignoreAnimation = false,
  1474. ignoreDimensions = false,
  1475. ignoreClear = false,
  1476. forceRedraw,
  1477. scaleWidth,
  1478. scaleHeight,
  1479. offsetX,
  1480. offsetY
  1481. } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  1482. var {
  1483. FRAMERATE,
  1484. mouse
  1485. } = this;
  1486. var frameDuration = 1e3 / FRAMERATE;
  1487. this.frameDuration = frameDuration;
  1488. this.readyPromise = new Promise((resolve) => {
  1489. this.resolveReady = resolve;
  1490. });
  1491. if (this.isReady()) {
  1492. this.render(element, ignoreDimensions, ignoreClear, scaleWidth, scaleHeight, offsetX, offsetY);
  1493. }
  1494. if (!enableRedraw) {
  1495. return;
  1496. }
  1497. var now = Date.now();
  1498. var then = now;
  1499. var delta = 0;
  1500. var tick = () => {
  1501. now = Date.now();
  1502. delta = now - then;
  1503. if (delta >= frameDuration) {
  1504. then = now - delta % frameDuration;
  1505. if (this.shouldUpdate(ignoreAnimation, forceRedraw)) {
  1506. this.render(element, ignoreDimensions, ignoreClear, scaleWidth, scaleHeight, offsetX, offsetY);
  1507. mouse.runEvents();
  1508. }
  1509. }
  1510. this.intervalId = (0, import_raf.default)(tick);
  1511. };
  1512. if (!ignoreMouse) {
  1513. mouse.start();
  1514. }
  1515. this.intervalId = (0, import_raf.default)(tick);
  1516. }
  1517. stop() {
  1518. if (this.intervalId) {
  1519. import_raf.default.cancel(this.intervalId);
  1520. this.intervalId = null;
  1521. }
  1522. this.mouse.stop();
  1523. }
  1524. shouldUpdate(ignoreAnimation, forceRedraw) {
  1525. if (!ignoreAnimation) {
  1526. var {
  1527. frameDuration
  1528. } = this;
  1529. var shouldUpdate = this.animations.reduce((shouldUpdate2, animation) => animation.update(frameDuration) || shouldUpdate2, false);
  1530. if (shouldUpdate) {
  1531. return true;
  1532. }
  1533. }
  1534. if (typeof forceRedraw === "function" && forceRedraw()) {
  1535. return true;
  1536. }
  1537. if (!this.isReadyLock && this.isReady()) {
  1538. return true;
  1539. }
  1540. if (this.mouse.hasEvents()) {
  1541. return true;
  1542. }
  1543. return false;
  1544. }
  1545. render(element, ignoreDimensions, ignoreClear, scaleWidth, scaleHeight, offsetX, offsetY) {
  1546. var {
  1547. CLIENT_WIDTH,
  1548. CLIENT_HEIGHT,
  1549. viewPort,
  1550. ctx,
  1551. isFirstRender
  1552. } = this;
  1553. var canvas = ctx.canvas;
  1554. viewPort.clear();
  1555. if (canvas.width && canvas.height) {
  1556. viewPort.setCurrent(canvas.width, canvas.height);
  1557. } else {
  1558. viewPort.setCurrent(CLIENT_WIDTH, CLIENT_HEIGHT);
  1559. }
  1560. var widthStyle = element.getStyle("width");
  1561. var heightStyle = element.getStyle("height");
  1562. if (!ignoreDimensions && (isFirstRender || typeof scaleWidth !== "number" && typeof scaleHeight !== "number")) {
  1563. if (widthStyle.hasValue()) {
  1564. canvas.width = widthStyle.getPixels("x");
  1565. if (canvas.style) {
  1566. canvas.style.width = "".concat(canvas.width, "px");
  1567. }
  1568. }
  1569. if (heightStyle.hasValue()) {
  1570. canvas.height = heightStyle.getPixels("y");
  1571. if (canvas.style) {
  1572. canvas.style.height = "".concat(canvas.height, "px");
  1573. }
  1574. }
  1575. }
  1576. var cWidth = canvas.clientWidth || canvas.width;
  1577. var cHeight = canvas.clientHeight || canvas.height;
  1578. if (ignoreDimensions && widthStyle.hasValue() && heightStyle.hasValue()) {
  1579. cWidth = widthStyle.getPixels("x");
  1580. cHeight = heightStyle.getPixels("y");
  1581. }
  1582. viewPort.setCurrent(cWidth, cHeight);
  1583. if (typeof offsetX === "number") {
  1584. element.getAttribute("x", true).setValue(offsetX);
  1585. }
  1586. if (typeof offsetY === "number") {
  1587. element.getAttribute("y", true).setValue(offsetY);
  1588. }
  1589. if (typeof scaleWidth === "number" || typeof scaleHeight === "number") {
  1590. var viewBox = toNumbers(element.getAttribute("viewBox").getString());
  1591. var xRatio = 0;
  1592. var yRatio = 0;
  1593. if (typeof scaleWidth === "number") {
  1594. var _widthStyle = element.getStyle("width");
  1595. if (_widthStyle.hasValue()) {
  1596. xRatio = _widthStyle.getPixels("x") / scaleWidth;
  1597. } else if (!isNaN(viewBox[2])) {
  1598. xRatio = viewBox[2] / scaleWidth;
  1599. }
  1600. }
  1601. if (typeof scaleHeight === "number") {
  1602. var _heightStyle = element.getStyle("height");
  1603. if (_heightStyle.hasValue()) {
  1604. yRatio = _heightStyle.getPixels("y") / scaleHeight;
  1605. } else if (!isNaN(viewBox[3])) {
  1606. yRatio = viewBox[3] / scaleHeight;
  1607. }
  1608. }
  1609. if (!xRatio) {
  1610. xRatio = yRatio;
  1611. }
  1612. if (!yRatio) {
  1613. yRatio = xRatio;
  1614. }
  1615. element.getAttribute("width", true).setValue(scaleWidth);
  1616. element.getAttribute("height", true).setValue(scaleHeight);
  1617. var transformStyle = element.getStyle("transform", true, true);
  1618. transformStyle.setValue("".concat(transformStyle.getString(), " scale(").concat(1 / xRatio, ", ").concat(1 / yRatio, ")"));
  1619. }
  1620. if (!ignoreClear) {
  1621. ctx.clearRect(0, 0, cWidth, cHeight);
  1622. }
  1623. element.render(ctx);
  1624. if (isFirstRender) {
  1625. this.isFirstRender = false;
  1626. }
  1627. }
  1628. };
  1629. Screen.defaultWindow = defaultWindow;
  1630. Screen.defaultFetch = defaultFetch$1;
  1631. ({
  1632. defaultFetch
  1633. } = Screen);
  1634. DefaultDOMParser = typeof DOMParser !== "undefined" ? DOMParser : null;
  1635. Parser = class {
  1636. constructor() {
  1637. var {
  1638. fetch: fetch2 = defaultFetch,
  1639. DOMParser: DOMParser2 = DefaultDOMParser
  1640. } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
  1641. this.fetch = fetch2;
  1642. this.DOMParser = DOMParser2;
  1643. }
  1644. parse(resource) {
  1645. var _this = this;
  1646. return _asyncToGenerator(function* () {
  1647. if (resource.startsWith("<")) {
  1648. return _this.parseFromString(resource);
  1649. }
  1650. return _this.load(resource);
  1651. })();
  1652. }
  1653. parseFromString(xml) {
  1654. var parser = new this.DOMParser();
  1655. try {
  1656. return this.checkDocument(parser.parseFromString(xml, "image/svg+xml"));
  1657. } catch (err) {
  1658. return this.checkDocument(parser.parseFromString(xml, "text/xml"));
  1659. }
  1660. }
  1661. checkDocument(document2) {
  1662. var parserError = document2.getElementsByTagName("parsererror")[0];
  1663. if (parserError) {
  1664. throw new Error(parserError.textContent);
  1665. }
  1666. return document2;
  1667. }
  1668. load(url) {
  1669. var _this2 = this;
  1670. return _asyncToGenerator(function* () {
  1671. var response = yield _this2.fetch(url);
  1672. var xml = yield response.text();
  1673. return _this2.parseFromString(xml);
  1674. })();
  1675. }
  1676. };
  1677. Translate = class {
  1678. constructor(_2, point) {
  1679. this.type = "translate";
  1680. this.point = null;
  1681. this.point = Point.parse(point);
  1682. }
  1683. apply(ctx) {
  1684. var {
  1685. x,
  1686. y: y2
  1687. } = this.point;
  1688. ctx.translate(x || 0, y2 || 0);
  1689. }
  1690. unapply(ctx) {
  1691. var {
  1692. x,
  1693. y: y2
  1694. } = this.point;
  1695. ctx.translate(-1 * x || 0, -1 * y2 || 0);
  1696. }
  1697. applyToPoint(point) {
  1698. var {
  1699. x,
  1700. y: y2
  1701. } = this.point;
  1702. point.applyTransform([1, 0, 0, 1, x || 0, y2 || 0]);
  1703. }
  1704. };
  1705. Rotate = class {
  1706. constructor(document2, rotate, transformOrigin) {
  1707. this.type = "rotate";
  1708. this.angle = null;
  1709. this.originX = null;
  1710. this.originY = null;
  1711. this.cx = 0;
  1712. this.cy = 0;
  1713. var numbers = toNumbers(rotate);
  1714. this.angle = new Property(document2, "angle", numbers[0]);
  1715. this.originX = transformOrigin[0];
  1716. this.originY = transformOrigin[1];
  1717. this.cx = numbers[1] || 0;
  1718. this.cy = numbers[2] || 0;
  1719. }
  1720. apply(ctx) {
  1721. var {
  1722. cx,
  1723. cy,
  1724. originX,
  1725. originY,
  1726. angle
  1727. } = this;
  1728. var tx = cx + originX.getPixels("x");
  1729. var ty = cy + originY.getPixels("y");
  1730. ctx.translate(tx, ty);
  1731. ctx.rotate(angle.getRadians());
  1732. ctx.translate(-tx, -ty);
  1733. }
  1734. unapply(ctx) {
  1735. var {
  1736. cx,
  1737. cy,
  1738. originX,
  1739. originY,
  1740. angle
  1741. } = this;
  1742. var tx = cx + originX.getPixels("x");
  1743. var ty = cy + originY.getPixels("y");
  1744. ctx.translate(tx, ty);
  1745. ctx.rotate(-1 * angle.getRadians());
  1746. ctx.translate(-tx, -ty);
  1747. }
  1748. applyToPoint(point) {
  1749. var {
  1750. cx,
  1751. cy,
  1752. angle
  1753. } = this;
  1754. var rad = angle.getRadians();
  1755. point.applyTransform([
  1756. 1,
  1757. 0,
  1758. 0,
  1759. 1,
  1760. cx || 0,
  1761. cy || 0
  1762. // this.p.y
  1763. ]);
  1764. point.applyTransform([Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), 0, 0]);
  1765. point.applyTransform([
  1766. 1,
  1767. 0,
  1768. 0,
  1769. 1,
  1770. -cx || 0,
  1771. -cy || 0
  1772. // -this.p.y
  1773. ]);
  1774. }
  1775. };
  1776. Scale = class {
  1777. constructor(_2, scale, transformOrigin) {
  1778. this.type = "scale";
  1779. this.scale = null;
  1780. this.originX = null;
  1781. this.originY = null;
  1782. var scaleSize = Point.parseScale(scale);
  1783. if (scaleSize.x === 0 || scaleSize.y === 0) {
  1784. scaleSize.x = PSEUDO_ZERO;
  1785. scaleSize.y = PSEUDO_ZERO;
  1786. }
  1787. this.scale = scaleSize;
  1788. this.originX = transformOrigin[0];
  1789. this.originY = transformOrigin[1];
  1790. }
  1791. apply(ctx) {
  1792. var {
  1793. scale: {
  1794. x,
  1795. y: y2
  1796. },
  1797. originX,
  1798. originY
  1799. } = this;
  1800. var tx = originX.getPixels("x");
  1801. var ty = originY.getPixels("y");
  1802. ctx.translate(tx, ty);
  1803. ctx.scale(x, y2 || x);
  1804. ctx.translate(-tx, -ty);
  1805. }
  1806. unapply(ctx) {
  1807. var {
  1808. scale: {
  1809. x,
  1810. y: y2
  1811. },
  1812. originX,
  1813. originY
  1814. } = this;
  1815. var tx = originX.getPixels("x");
  1816. var ty = originY.getPixels("y");
  1817. ctx.translate(tx, ty);
  1818. ctx.scale(1 / x, 1 / y2 || x);
  1819. ctx.translate(-tx, -ty);
  1820. }
  1821. applyToPoint(point) {
  1822. var {
  1823. x,
  1824. y: y2
  1825. } = this.scale;
  1826. point.applyTransform([x || 0, 0, 0, y2 || 0, 0, 0]);
  1827. }
  1828. };
  1829. Matrix = class {
  1830. constructor(_2, matrix, transformOrigin) {
  1831. this.type = "matrix";
  1832. this.matrix = [];
  1833. this.originX = null;
  1834. this.originY = null;
  1835. this.matrix = toNumbers(matrix);
  1836. this.originX = transformOrigin[0];
  1837. this.originY = transformOrigin[1];
  1838. }
  1839. apply(ctx) {
  1840. var {
  1841. originX,
  1842. originY,
  1843. matrix
  1844. } = this;
  1845. var tx = originX.getPixels("x");
  1846. var ty = originY.getPixels("y");
  1847. ctx.translate(tx, ty);
  1848. ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  1849. ctx.translate(-tx, -ty);
  1850. }
  1851. unapply(ctx) {
  1852. var {
  1853. originX,
  1854. originY,
  1855. matrix
  1856. } = this;
  1857. var a2 = matrix[0];
  1858. var b = matrix[2];
  1859. var c3 = matrix[4];
  1860. var d = matrix[1];
  1861. var e2 = matrix[3];
  1862. var f2 = matrix[5];
  1863. var g = 0;
  1864. var h2 = 0;
  1865. var i2 = 1;
  1866. var det = 1 / (a2 * (e2 * i2 - f2 * h2) - b * (d * i2 - f2 * g) + c3 * (d * h2 - e2 * g));
  1867. var tx = originX.getPixels("x");
  1868. var ty = originY.getPixels("y");
  1869. ctx.translate(tx, ty);
  1870. ctx.transform(det * (e2 * i2 - f2 * h2), det * (f2 * g - d * i2), det * (c3 * h2 - b * i2), det * (a2 * i2 - c3 * g), det * (b * f2 - c3 * e2), det * (c3 * d - a2 * f2));
  1871. ctx.translate(-tx, -ty);
  1872. }
  1873. applyToPoint(point) {
  1874. point.applyTransform(this.matrix);
  1875. }
  1876. };
  1877. Skew = class extends Matrix {
  1878. constructor(document2, skew, transformOrigin) {
  1879. super(document2, skew, transformOrigin);
  1880. this.type = "skew";
  1881. this.angle = null;
  1882. this.angle = new Property(document2, "angle", skew);
  1883. }
  1884. };
  1885. SkewX = class extends Skew {
  1886. constructor(document2, skew, transformOrigin) {
  1887. super(document2, skew, transformOrigin);
  1888. this.type = "skewX";
  1889. this.matrix = [1, 0, Math.tan(this.angle.getRadians()), 1, 0, 0];
  1890. }
  1891. };
  1892. SkewY = class extends Skew {
  1893. constructor(document2, skew, transformOrigin) {
  1894. super(document2, skew, transformOrigin);
  1895. this.type = "skewY";
  1896. this.matrix = [1, Math.tan(this.angle.getRadians()), 0, 1, 0, 0];
  1897. }
  1898. };
  1899. Transform = class _Transform {
  1900. constructor(document2, transform, transformOrigin) {
  1901. this.document = document2;
  1902. this.transforms = [];
  1903. var data = parseTransforms(transform);
  1904. data.forEach((transform2) => {
  1905. if (transform2 === "none") {
  1906. return;
  1907. }
  1908. var [type, value] = parseTransform(transform2);
  1909. var TransformType = _Transform.transformTypes[type];
  1910. if (typeof TransformType !== "undefined") {
  1911. this.transforms.push(new TransformType(this.document, value, transformOrigin));
  1912. }
  1913. });
  1914. }
  1915. static fromElement(document2, element) {
  1916. var transformStyle = element.getStyle("transform", false, true);
  1917. var [transformOriginXProperty, transformOriginYProperty = transformOriginXProperty] = element.getStyle("transform-origin", false, true).split();
  1918. var transformOrigin = [transformOriginXProperty, transformOriginYProperty];
  1919. if (transformStyle.hasValue()) {
  1920. return new _Transform(document2, transformStyle.getString(), transformOrigin);
  1921. }
  1922. return null;
  1923. }
  1924. apply(ctx) {
  1925. var {
  1926. transforms
  1927. } = this;
  1928. var len = transforms.length;
  1929. for (var i2 = 0; i2 < len; i2++) {
  1930. transforms[i2].apply(ctx);
  1931. }
  1932. }
  1933. unapply(ctx) {
  1934. var {
  1935. transforms
  1936. } = this;
  1937. var len = transforms.length;
  1938. for (var i2 = len - 1; i2 >= 0; i2--) {
  1939. transforms[i2].unapply(ctx);
  1940. }
  1941. }
  1942. // TODO: applyToPoint unused ... remove?
  1943. applyToPoint(point) {
  1944. var {
  1945. transforms
  1946. } = this;
  1947. var len = transforms.length;
  1948. for (var i2 = 0; i2 < len; i2++) {
  1949. transforms[i2].applyToPoint(point);
  1950. }
  1951. }
  1952. };
  1953. Transform.transformTypes = {
  1954. translate: Translate,
  1955. rotate: Rotate,
  1956. scale: Scale,
  1957. matrix: Matrix,
  1958. skewX: SkewX,
  1959. skewY: SkewY
  1960. };
  1961. Element = class _Element {
  1962. constructor(document2, node2) {
  1963. var captureTextNodes = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
  1964. this.document = document2;
  1965. this.node = node2;
  1966. this.captureTextNodes = captureTextNodes;
  1967. this.attributes = /* @__PURE__ */ Object.create(null);
  1968. this.styles = /* @__PURE__ */ Object.create(null);
  1969. this.stylesSpecificity = /* @__PURE__ */ Object.create(null);
  1970. this.animationFrozen = false;
  1971. this.animationFrozenValue = "";
  1972. this.parent = null;
  1973. this.children = [];
  1974. if (!node2 || node2.nodeType !== 1) {
  1975. return;
  1976. }
  1977. Array.from(node2.attributes).forEach((attribute) => {
  1978. var nodeName = normalizeAttributeName(attribute.nodeName);
  1979. this.attributes[nodeName] = new Property(document2, nodeName, attribute.value);
  1980. });
  1981. this.addStylesFromStyleDefinition();
  1982. if (this.getAttribute("style").hasValue()) {
  1983. var styles = this.getAttribute("style").getString().split(";").map((_2) => _2.trim());
  1984. styles.forEach((style) => {
  1985. if (!style) {
  1986. return;
  1987. }
  1988. var [name, value] = style.split(":").map((_2) => _2.trim());
  1989. this.styles[name] = new Property(document2, name, value);
  1990. });
  1991. }
  1992. var {
  1993. definitions
  1994. } = document2;
  1995. var id = this.getAttribute("id");
  1996. if (id.hasValue()) {
  1997. if (!definitions[id.getString()]) {
  1998. definitions[id.getString()] = this;
  1999. }
  2000. }
  2001. Array.from(node2.childNodes).forEach((childNode) => {
  2002. if (childNode.nodeType === 1) {
  2003. this.addChild(childNode);
  2004. } else if (captureTextNodes && (childNode.nodeType === 3 || childNode.nodeType === 4)) {
  2005. var textNode = document2.createTextNode(childNode);
  2006. if (textNode.getText().length > 0) {
  2007. this.addChild(textNode);
  2008. }
  2009. }
  2010. });
  2011. }
  2012. getAttribute(name) {
  2013. var createIfNotExists = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
  2014. var attr = this.attributes[name];
  2015. if (!attr && createIfNotExists) {
  2016. var _attr = new Property(this.document, name, "");
  2017. this.attributes[name] = _attr;
  2018. return _attr;
  2019. }
  2020. return attr || Property.empty(this.document);
  2021. }
  2022. getHrefAttribute() {
  2023. for (var key in this.attributes) {
  2024. if (key === "href" || key.endsWith(":href")) {
  2025. return this.attributes[key];
  2026. }
  2027. }
  2028. return Property.empty(this.document);
  2029. }
  2030. getStyle(name) {
  2031. var createIfNotExists = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
  2032. var skipAncestors = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
  2033. var style = this.styles[name];
  2034. if (style) {
  2035. return style;
  2036. }
  2037. var attr = this.getAttribute(name);
  2038. if (attr !== null && attr !== void 0 && attr.hasValue()) {
  2039. this.styles[name] = attr;
  2040. return attr;
  2041. }
  2042. if (!skipAncestors) {
  2043. var {
  2044. parent
  2045. } = this;
  2046. if (parent) {
  2047. var parentStyle = parent.getStyle(name);
  2048. if (parentStyle !== null && parentStyle !== void 0 && parentStyle.hasValue()) {
  2049. return parentStyle;
  2050. }
  2051. }
  2052. }
  2053. if (createIfNotExists) {
  2054. var _style = new Property(this.document, name, "");
  2055. this.styles[name] = _style;
  2056. return _style;
  2057. }
  2058. return style || Property.empty(this.document);
  2059. }
  2060. render(ctx) {
  2061. if (this.getStyle("display").getString() === "none" || this.getStyle("visibility").getString() === "hidden") {
  2062. return;
  2063. }
  2064. ctx.save();
  2065. if (this.getStyle("mask").hasValue()) {
  2066. var mask = this.getStyle("mask").getDefinition();
  2067. if (mask) {
  2068. this.applyEffects(ctx);
  2069. mask.apply(ctx, this);
  2070. }
  2071. } else if (this.getStyle("filter").getValue("none") !== "none") {
  2072. var filter = this.getStyle("filter").getDefinition();
  2073. if (filter) {
  2074. this.applyEffects(ctx);
  2075. filter.apply(ctx, this);
  2076. }
  2077. } else {
  2078. this.setContext(ctx);
  2079. this.renderChildren(ctx);
  2080. this.clearContext(ctx);
  2081. }
  2082. ctx.restore();
  2083. }
  2084. setContext(_2) {
  2085. }
  2086. applyEffects(ctx) {
  2087. var transform = Transform.fromElement(this.document, this);
  2088. if (transform) {
  2089. transform.apply(ctx);
  2090. }
  2091. var clipPathStyleProp = this.getStyle("clip-path", false, true);
  2092. if (clipPathStyleProp.hasValue()) {
  2093. var clip = clipPathStyleProp.getDefinition();
  2094. if (clip) {
  2095. clip.apply(ctx);
  2096. }
  2097. }
  2098. }
  2099. clearContext(_2) {
  2100. }
  2101. renderChildren(ctx) {
  2102. this.children.forEach((child) => {
  2103. child.render(ctx);
  2104. });
  2105. }
  2106. addChild(childNode) {
  2107. var child = childNode instanceof _Element ? childNode : this.document.createElement(childNode);
  2108. child.parent = this;
  2109. if (!_Element.ignoreChildTypes.includes(child.type)) {
  2110. this.children.push(child);
  2111. }
  2112. }
  2113. matchesSelector(selector) {
  2114. var _node$getAttribute;
  2115. var {
  2116. node: node2
  2117. } = this;
  2118. if (typeof node2.matches === "function") {
  2119. return node2.matches(selector);
  2120. }
  2121. var styleClasses = (_node$getAttribute = node2.getAttribute) === null || _node$getAttribute === void 0 ? void 0 : _node$getAttribute.call(node2, "class");
  2122. if (!styleClasses || styleClasses === "") {
  2123. return false;
  2124. }
  2125. return styleClasses.split(" ").some((styleClass) => ".".concat(styleClass) === selector);
  2126. }
  2127. addStylesFromStyleDefinition() {
  2128. var {
  2129. styles,
  2130. stylesSpecificity
  2131. } = this.document;
  2132. for (var selector in styles) {
  2133. if (!selector.startsWith("@") && this.matchesSelector(selector)) {
  2134. var style = styles[selector];
  2135. var specificity = stylesSpecificity[selector];
  2136. if (style) {
  2137. for (var name in style) {
  2138. var existingSpecificity = this.stylesSpecificity[name];
  2139. if (typeof existingSpecificity === "undefined") {
  2140. existingSpecificity = "000";
  2141. }
  2142. if (specificity >= existingSpecificity) {
  2143. this.styles[name] = style[name];
  2144. this.stylesSpecificity[name] = specificity;
  2145. }
  2146. }
  2147. }
  2148. }
  2149. }
  2150. }
  2151. removeStyles(element, ignoreStyles) {
  2152. var toRestore = ignoreStyles.reduce((toRestore2, name) => {
  2153. var styleProp = element.getStyle(name);
  2154. if (!styleProp.hasValue()) {
  2155. return toRestore2;
  2156. }
  2157. var value = styleProp.getString();
  2158. styleProp.setValue("");
  2159. return [...toRestore2, [name, value]];
  2160. }, []);
  2161. return toRestore;
  2162. }
  2163. restoreStyles(element, styles) {
  2164. styles.forEach((_ref) => {
  2165. var [name, value] = _ref;
  2166. element.getStyle(name, true).setValue(value);
  2167. });
  2168. }
  2169. isFirstChild() {
  2170. var _this$parent;
  2171. return ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.children.indexOf(this)) === 0;
  2172. }
  2173. };
  2174. Element.ignoreChildTypes = ["title"];
  2175. UnknownElement = class extends Element {
  2176. constructor(document2, node2, captureTextNodes) {
  2177. super(document2, node2, captureTextNodes);
  2178. }
  2179. };
  2180. Font = class _Font {
  2181. constructor(fontStyle, fontVariant, fontWeight, fontSize, fontFamily, inherit) {
  2182. var inheritFont = inherit ? typeof inherit === "string" ? _Font.parse(inherit) : inherit : {};
  2183. this.fontFamily = fontFamily || inheritFont.fontFamily;
  2184. this.fontSize = fontSize || inheritFont.fontSize;
  2185. this.fontStyle = fontStyle || inheritFont.fontStyle;
  2186. this.fontWeight = fontWeight || inheritFont.fontWeight;
  2187. this.fontVariant = fontVariant || inheritFont.fontVariant;
  2188. }
  2189. static parse() {
  2190. var font = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "";
  2191. var inherit = arguments.length > 1 ? arguments[1] : void 0;
  2192. var fontStyle = "";
  2193. var fontVariant = "";
  2194. var fontWeight = "";
  2195. var fontSize = "";
  2196. var fontFamily = "";
  2197. var parts = compressSpaces(font).trim().split(" ");
  2198. var set = {
  2199. fontSize: false,
  2200. fontStyle: false,
  2201. fontWeight: false,
  2202. fontVariant: false
  2203. };
  2204. parts.forEach((part) => {
  2205. switch (true) {
  2206. case (!set.fontStyle && _Font.styles.includes(part)):
  2207. if (part !== "inherit") {
  2208. fontStyle = part;
  2209. }
  2210. set.fontStyle = true;
  2211. break;
  2212. case (!set.fontVariant && _Font.variants.includes(part)):
  2213. if (part !== "inherit") {
  2214. fontVariant = part;
  2215. }
  2216. set.fontStyle = true;
  2217. set.fontVariant = true;
  2218. break;
  2219. case (!set.fontWeight && _Font.weights.includes(part)):
  2220. if (part !== "inherit") {
  2221. fontWeight = part;
  2222. }
  2223. set.fontStyle = true;
  2224. set.fontVariant = true;
  2225. set.fontWeight = true;
  2226. break;
  2227. case !set.fontSize:
  2228. if (part !== "inherit") {
  2229. [fontSize] = part.split("/");
  2230. }
  2231. set.fontStyle = true;
  2232. set.fontVariant = true;
  2233. set.fontWeight = true;
  2234. set.fontSize = true;
  2235. break;
  2236. default:
  2237. if (part !== "inherit") {
  2238. fontFamily += part;
  2239. }
  2240. }
  2241. });
  2242. return new _Font(fontStyle, fontVariant, fontWeight, fontSize, fontFamily, inherit);
  2243. }
  2244. toString() {
  2245. return [
  2246. prepareFontStyle(this.fontStyle),
  2247. this.fontVariant,
  2248. prepareFontWeight(this.fontWeight),
  2249. this.fontSize,
  2250. // Wrap fontFamily only on nodejs and only for canvas.ctx
  2251. prepareFontFamily(this.fontFamily)
  2252. ].join(" ").trim();
  2253. }
  2254. };
  2255. Font.styles = "normal|italic|oblique|inherit";
  2256. Font.variants = "normal|small-caps|inherit";
  2257. Font.weights = "normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900|inherit";
  2258. BoundingBox = class {
  2259. constructor() {
  2260. var x1 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : Number.NaN;
  2261. var y1 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Number.NaN;
  2262. var x2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : Number.NaN;
  2263. var y2 = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : Number.NaN;
  2264. this.x1 = x1;
  2265. this.y1 = y1;
  2266. this.x2 = x2;
  2267. this.y2 = y2;
  2268. this.addPoint(x1, y1);
  2269. this.addPoint(x2, y2);
  2270. }
  2271. get x() {
  2272. return this.x1;
  2273. }
  2274. get y() {
  2275. return this.y1;
  2276. }
  2277. get width() {
  2278. return this.x2 - this.x1;
  2279. }
  2280. get height() {
  2281. return this.y2 - this.y1;
  2282. }
  2283. addPoint(x, y2) {
  2284. if (typeof x !== "undefined") {
  2285. if (isNaN(this.x1) || isNaN(this.x2)) {
  2286. this.x1 = x;
  2287. this.x2 = x;
  2288. }
  2289. if (x < this.x1) {
  2290. this.x1 = x;
  2291. }
  2292. if (x > this.x2) {
  2293. this.x2 = x;
  2294. }
  2295. }
  2296. if (typeof y2 !== "undefined") {
  2297. if (isNaN(this.y1) || isNaN(this.y2)) {
  2298. this.y1 = y2;
  2299. this.y2 = y2;
  2300. }
  2301. if (y2 < this.y1) {
  2302. this.y1 = y2;
  2303. }
  2304. if (y2 > this.y2) {
  2305. this.y2 = y2;
  2306. }
  2307. }
  2308. }
  2309. addX(x) {
  2310. this.addPoint(x, null);
  2311. }
  2312. addY(y2) {
  2313. this.addPoint(null, y2);
  2314. }
  2315. addBoundingBox(boundingBox) {
  2316. if (!boundingBox) {
  2317. return;
  2318. }
  2319. var {
  2320. x1,
  2321. y1,
  2322. x2,
  2323. y2
  2324. } = boundingBox;
  2325. this.addPoint(x1, y1);
  2326. this.addPoint(x2, y2);
  2327. }
  2328. sumCubic(t2, p0, p1, p2, p3) {
  2329. return Math.pow(1 - t2, 3) * p0 + 3 * Math.pow(1 - t2, 2) * t2 * p1 + 3 * (1 - t2) * Math.pow(t2, 2) * p2 + Math.pow(t2, 3) * p3;
  2330. }
  2331. bezierCurveAdd(forX, p0, p1, p2, p3) {
  2332. var b = 6 * p0 - 12 * p1 + 6 * p2;
  2333. var a2 = -3 * p0 + 9 * p1 - 9 * p2 + 3 * p3;
  2334. var c3 = 3 * p1 - 3 * p0;
  2335. if (a2 === 0) {
  2336. if (b === 0) {
  2337. return;
  2338. }
  2339. var t2 = -c3 / b;
  2340. if (0 < t2 && t2 < 1) {
  2341. if (forX) {
  2342. this.addX(this.sumCubic(t2, p0, p1, p2, p3));
  2343. } else {
  2344. this.addY(this.sumCubic(t2, p0, p1, p2, p3));
  2345. }
  2346. }
  2347. return;
  2348. }
  2349. var b2ac = Math.pow(b, 2) - 4 * c3 * a2;
  2350. if (b2ac < 0) {
  2351. return;
  2352. }
  2353. var t1 = (-b + Math.sqrt(b2ac)) / (2 * a2);
  2354. if (0 < t1 && t1 < 1) {
  2355. if (forX) {
  2356. this.addX(this.sumCubic(t1, p0, p1, p2, p3));
  2357. } else {
  2358. this.addY(this.sumCubic(t1, p0, p1, p2, p3));
  2359. }
  2360. }
  2361. var t22 = (-b - Math.sqrt(b2ac)) / (2 * a2);
  2362. if (0 < t22 && t22 < 1) {
  2363. if (forX) {
  2364. this.addX(this.sumCubic(t22, p0, p1, p2, p3));
  2365. } else {
  2366. this.addY(this.sumCubic(t22, p0, p1, p2, p3));
  2367. }
  2368. }
  2369. }
  2370. // from http://blog.hackers-cafe.net/2009/06/how-to-calculate-bezier-curves-bounding.html
  2371. addBezierCurve(p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y) {
  2372. this.addPoint(p0x, p0y);
  2373. this.addPoint(p3x, p3y);
  2374. this.bezierCurveAdd(true, p0x, p1x, p2x, p3x);
  2375. this.bezierCurveAdd(false, p0y, p1y, p2y, p3y);
  2376. }
  2377. addQuadraticCurve(p0x, p0y, p1x, p1y, p2x, p2y) {
  2378. var cp1x = p0x + 2 / 3 * (p1x - p0x);
  2379. var cp1y = p0y + 2 / 3 * (p1y - p0y);
  2380. var cp2x = cp1x + 1 / 3 * (p2x - p0x);
  2381. var cp2y = cp1y + 1 / 3 * (p2y - p0y);
  2382. this.addBezierCurve(p0x, p0y, cp1x, cp2x, cp1y, cp2y, p2x, p2y);
  2383. }
  2384. isPointInBox(x, y2) {
  2385. var {
  2386. x1,
  2387. y1,
  2388. x2,
  2389. y2: y22
  2390. } = this;
  2391. return x1 <= x && x <= x2 && y1 <= y2 && y2 <= y22;
  2392. }
  2393. };
  2394. PathParser = class extends _ {
  2395. constructor(path) {
  2396. super(path.replace(/([+\-.])\s+/gm, "$1").replace(/[^MmZzLlHhVvCcSsQqTtAae\d\s.,+-].*/g, ""));
  2397. this.control = null;
  2398. this.start = null;
  2399. this.current = null;
  2400. this.command = null;
  2401. this.commands = this.commands;
  2402. this.i = -1;
  2403. this.previousCommand = null;
  2404. this.points = [];
  2405. this.angles = [];
  2406. }
  2407. reset() {
  2408. this.i = -1;
  2409. this.command = null;
  2410. this.previousCommand = null;
  2411. this.start = new Point(0, 0);
  2412. this.control = new Point(0, 0);
  2413. this.current = new Point(0, 0);
  2414. this.points = [];
  2415. this.angles = [];
  2416. }
  2417. isEnd() {
  2418. var {
  2419. i: i2,
  2420. commands
  2421. } = this;
  2422. return i2 >= commands.length - 1;
  2423. }
  2424. next() {
  2425. var command = this.commands[++this.i];
  2426. this.previousCommand = this.command;
  2427. this.command = command;
  2428. return command;
  2429. }
  2430. getPoint() {
  2431. var xProp = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "x";
  2432. var yProp = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "y";
  2433. var point = new Point(this.command[xProp], this.command[yProp]);
  2434. return this.makeAbsolute(point);
  2435. }
  2436. getAsControlPoint(xProp, yProp) {
  2437. var point = this.getPoint(xProp, yProp);
  2438. this.control = point;
  2439. return point;
  2440. }
  2441. getAsCurrentPoint(xProp, yProp) {
  2442. var point = this.getPoint(xProp, yProp);
  2443. this.current = point;
  2444. return point;
  2445. }
  2446. getReflectedControlPoint() {
  2447. var previousCommand = this.previousCommand.type;
  2448. if (previousCommand !== _.CURVE_TO && previousCommand !== _.SMOOTH_CURVE_TO && previousCommand !== _.QUAD_TO && previousCommand !== _.SMOOTH_QUAD_TO) {
  2449. return this.current;
  2450. }
  2451. var {
  2452. current: {
  2453. x: cx,
  2454. y: cy
  2455. },
  2456. control: {
  2457. x: ox,
  2458. y: oy
  2459. }
  2460. } = this;
  2461. var point = new Point(2 * cx - ox, 2 * cy - oy);
  2462. return point;
  2463. }
  2464. makeAbsolute(point) {
  2465. if (this.command.relative) {
  2466. var {
  2467. x,
  2468. y: y2
  2469. } = this.current;
  2470. point.x += x;
  2471. point.y += y2;
  2472. }
  2473. return point;
  2474. }
  2475. addMarker(point, from, priorTo) {
  2476. var {
  2477. points,
  2478. angles
  2479. } = this;
  2480. if (priorTo && angles.length > 0 && !angles[angles.length - 1]) {
  2481. angles[angles.length - 1] = points[points.length - 1].angleTo(priorTo);
  2482. }
  2483. this.addMarkerAngle(point, from ? from.angleTo(point) : null);
  2484. }
  2485. addMarkerAngle(point, angle) {
  2486. this.points.push(point);
  2487. this.angles.push(angle);
  2488. }
  2489. getMarkerPoints() {
  2490. return this.points;
  2491. }
  2492. getMarkerAngles() {
  2493. var {
  2494. angles
  2495. } = this;
  2496. var len = angles.length;
  2497. for (var i2 = 0; i2 < len; i2++) {
  2498. if (!angles[i2]) {
  2499. for (var j = i2 + 1; j < len; j++) {
  2500. if (angles[j]) {
  2501. angles[i2] = angles[j];
  2502. break;
  2503. }
  2504. }
  2505. }
  2506. }
  2507. return angles;
  2508. }
  2509. };
  2510. RenderedElement = class extends Element {
  2511. constructor() {
  2512. super(...arguments);
  2513. this.modifiedEmSizeStack = false;
  2514. }
  2515. calculateOpacity() {
  2516. var opacity = 1;
  2517. var element = this;
  2518. while (element) {
  2519. var opacityStyle = element.getStyle("opacity", false, true);
  2520. if (opacityStyle.hasValue(true)) {
  2521. opacity *= opacityStyle.getNumber();
  2522. }
  2523. element = element.parent;
  2524. }
  2525. return opacity;
  2526. }
  2527. setContext(ctx) {
  2528. var fromMeasure = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
  2529. if (!fromMeasure) {
  2530. var fillStyleProp = this.getStyle("fill");
  2531. var fillOpacityStyleProp = this.getStyle("fill-opacity");
  2532. var strokeStyleProp = this.getStyle("stroke");
  2533. var strokeOpacityProp = this.getStyle("stroke-opacity");
  2534. if (fillStyleProp.isUrlDefinition()) {
  2535. var fillStyle = fillStyleProp.getFillStyleDefinition(this, fillOpacityStyleProp);
  2536. if (fillStyle) {
  2537. ctx.fillStyle = fillStyle;
  2538. }
  2539. } else if (fillStyleProp.hasValue()) {
  2540. if (fillStyleProp.getString() === "currentColor") {
  2541. fillStyleProp.setValue(this.getStyle("color").getColor());
  2542. }
  2543. var _fillStyle = fillStyleProp.getColor();
  2544. if (_fillStyle !== "inherit") {
  2545. ctx.fillStyle = _fillStyle === "none" ? "rgba(0,0,0,0)" : _fillStyle;
  2546. }
  2547. }
  2548. if (fillOpacityStyleProp.hasValue()) {
  2549. var _fillStyle2 = new Property(this.document, "fill", ctx.fillStyle).addOpacity(fillOpacityStyleProp).getColor();
  2550. ctx.fillStyle = _fillStyle2;
  2551. }
  2552. if (strokeStyleProp.isUrlDefinition()) {
  2553. var strokeStyle = strokeStyleProp.getFillStyleDefinition(this, strokeOpacityProp);
  2554. if (strokeStyle) {
  2555. ctx.strokeStyle = strokeStyle;
  2556. }
  2557. } else if (strokeStyleProp.hasValue()) {
  2558. if (strokeStyleProp.getString() === "currentColor") {
  2559. strokeStyleProp.setValue(this.getStyle("color").getColor());
  2560. }
  2561. var _strokeStyle = strokeStyleProp.getString();
  2562. if (_strokeStyle !== "inherit") {
  2563. ctx.strokeStyle = _strokeStyle === "none" ? "rgba(0,0,0,0)" : _strokeStyle;
  2564. }
  2565. }
  2566. if (strokeOpacityProp.hasValue()) {
  2567. var _strokeStyle2 = new Property(this.document, "stroke", ctx.strokeStyle).addOpacity(strokeOpacityProp).getString();
  2568. ctx.strokeStyle = _strokeStyle2;
  2569. }
  2570. var strokeWidthStyleProp = this.getStyle("stroke-width");
  2571. if (strokeWidthStyleProp.hasValue()) {
  2572. var newLineWidth = strokeWidthStyleProp.getPixels();
  2573. ctx.lineWidth = !newLineWidth ? PSEUDO_ZERO : newLineWidth;
  2574. }
  2575. var strokeLinecapStyleProp = this.getStyle("stroke-linecap");
  2576. var strokeLinejoinStyleProp = this.getStyle("stroke-linejoin");
  2577. var strokeMiterlimitProp = this.getStyle("stroke-miterlimit");
  2578. var strokeDasharrayStyleProp = this.getStyle("stroke-dasharray");
  2579. var strokeDashoffsetProp = this.getStyle("stroke-dashoffset");
  2580. if (strokeLinecapStyleProp.hasValue()) {
  2581. ctx.lineCap = strokeLinecapStyleProp.getString();
  2582. }
  2583. if (strokeLinejoinStyleProp.hasValue()) {
  2584. ctx.lineJoin = strokeLinejoinStyleProp.getString();
  2585. }
  2586. if (strokeMiterlimitProp.hasValue()) {
  2587. ctx.miterLimit = strokeMiterlimitProp.getNumber();
  2588. }
  2589. if (strokeDasharrayStyleProp.hasValue() && strokeDasharrayStyleProp.getString() !== "none") {
  2590. var gaps = toNumbers(strokeDasharrayStyleProp.getString());
  2591. if (typeof ctx.setLineDash !== "undefined") {
  2592. ctx.setLineDash(gaps);
  2593. } else if (typeof ctx.webkitLineDash !== "undefined") {
  2594. ctx.webkitLineDash = gaps;
  2595. } else if (typeof ctx.mozDash !== "undefined" && !(gaps.length === 1 && gaps[0] === 0)) {
  2596. ctx.mozDash = gaps;
  2597. }
  2598. var offset = strokeDashoffsetProp.getPixels();
  2599. if (typeof ctx.lineDashOffset !== "undefined") {
  2600. ctx.lineDashOffset = offset;
  2601. } else if (typeof ctx.webkitLineDashOffset !== "undefined") {
  2602. ctx.webkitLineDashOffset = offset;
  2603. } else if (typeof ctx.mozDashOffset !== "undefined") {
  2604. ctx.mozDashOffset = offset;
  2605. }
  2606. }
  2607. }
  2608. this.modifiedEmSizeStack = false;
  2609. if (typeof ctx.font !== "undefined") {
  2610. var fontStyleProp = this.getStyle("font");
  2611. var fontStyleStyleProp = this.getStyle("font-style");
  2612. var fontVariantStyleProp = this.getStyle("font-variant");
  2613. var fontWeightStyleProp = this.getStyle("font-weight");
  2614. var fontSizeStyleProp = this.getStyle("font-size");
  2615. var fontFamilyStyleProp = this.getStyle("font-family");
  2616. var font = new Font(fontStyleStyleProp.getString(), fontVariantStyleProp.getString(), fontWeightStyleProp.getString(), fontSizeStyleProp.hasValue() ? "".concat(fontSizeStyleProp.getPixels(true), "px") : "", fontFamilyStyleProp.getString(), Font.parse(fontStyleProp.getString(), ctx.font));
  2617. fontStyleStyleProp.setValue(font.fontStyle);
  2618. fontVariantStyleProp.setValue(font.fontVariant);
  2619. fontWeightStyleProp.setValue(font.fontWeight);
  2620. fontSizeStyleProp.setValue(font.fontSize);
  2621. fontFamilyStyleProp.setValue(font.fontFamily);
  2622. ctx.font = font.toString();
  2623. if (fontSizeStyleProp.isPixels()) {
  2624. this.document.emSize = fontSizeStyleProp.getPixels();
  2625. this.modifiedEmSizeStack = true;
  2626. }
  2627. }
  2628. if (!fromMeasure) {
  2629. this.applyEffects(ctx);
  2630. ctx.globalAlpha = this.calculateOpacity();
  2631. }
  2632. }
  2633. clearContext(ctx) {
  2634. super.clearContext(ctx);
  2635. if (this.modifiedEmSizeStack) {
  2636. this.document.popEmSize();
  2637. }
  2638. }
  2639. };
  2640. PathElement = class _PathElement extends RenderedElement {
  2641. constructor(document2, node2, captureTextNodes) {
  2642. super(document2, node2, captureTextNodes);
  2643. this.type = "path";
  2644. this.pathParser = null;
  2645. this.pathParser = new PathParser(this.getAttribute("d").getString());
  2646. }
  2647. path(ctx) {
  2648. var {
  2649. pathParser
  2650. } = this;
  2651. var boundingBox = new BoundingBox();
  2652. pathParser.reset();
  2653. if (ctx) {
  2654. ctx.beginPath();
  2655. }
  2656. while (!pathParser.isEnd()) {
  2657. switch (pathParser.next().type) {
  2658. case PathParser.MOVE_TO:
  2659. this.pathM(ctx, boundingBox);
  2660. break;
  2661. case PathParser.LINE_TO:
  2662. this.pathL(ctx, boundingBox);
  2663. break;
  2664. case PathParser.HORIZ_LINE_TO:
  2665. this.pathH(ctx, boundingBox);
  2666. break;
  2667. case PathParser.VERT_LINE_TO:
  2668. this.pathV(ctx, boundingBox);
  2669. break;
  2670. case PathParser.CURVE_TO:
  2671. this.pathC(ctx, boundingBox);
  2672. break;
  2673. case PathParser.SMOOTH_CURVE_TO:
  2674. this.pathS(ctx, boundingBox);
  2675. break;
  2676. case PathParser.QUAD_TO:
  2677. this.pathQ(ctx, boundingBox);
  2678. break;
  2679. case PathParser.SMOOTH_QUAD_TO:
  2680. this.pathT(ctx, boundingBox);
  2681. break;
  2682. case PathParser.ARC:
  2683. this.pathA(ctx, boundingBox);
  2684. break;
  2685. case PathParser.CLOSE_PATH:
  2686. this.pathZ(ctx, boundingBox);
  2687. break;
  2688. }
  2689. }
  2690. return boundingBox;
  2691. }
  2692. getBoundingBox(_2) {
  2693. return this.path();
  2694. }
  2695. getMarkers() {
  2696. var {
  2697. pathParser
  2698. } = this;
  2699. var points = pathParser.getMarkerPoints();
  2700. var angles = pathParser.getMarkerAngles();
  2701. var markers = points.map((point, i2) => [point, angles[i2]]);
  2702. return markers;
  2703. }
  2704. renderChildren(ctx) {
  2705. this.path(ctx);
  2706. this.document.screen.mouse.checkPath(this, ctx);
  2707. var fillRuleStyleProp = this.getStyle("fill-rule");
  2708. if (ctx.fillStyle !== "") {
  2709. if (fillRuleStyleProp.getString("inherit") !== "inherit") {
  2710. ctx.fill(fillRuleStyleProp.getString());
  2711. } else {
  2712. ctx.fill();
  2713. }
  2714. }
  2715. if (ctx.strokeStyle !== "") {
  2716. if (this.getAttribute("vector-effect").getString() === "non-scaling-stroke") {
  2717. ctx.save();
  2718. ctx.setTransform(1, 0, 0, 1, 0, 0);
  2719. ctx.stroke();
  2720. ctx.restore();
  2721. } else {
  2722. ctx.stroke();
  2723. }
  2724. }
  2725. var markers = this.getMarkers();
  2726. if (markers) {
  2727. var markersLastIndex = markers.length - 1;
  2728. var markerStartStyleProp = this.getStyle("marker-start");
  2729. var markerMidStyleProp = this.getStyle("marker-mid");
  2730. var markerEndStyleProp = this.getStyle("marker-end");
  2731. if (markerStartStyleProp.isUrlDefinition()) {
  2732. var marker = markerStartStyleProp.getDefinition();
  2733. var [point, angle] = markers[0];
  2734. marker.render(ctx, point, angle);
  2735. }
  2736. if (markerMidStyleProp.isUrlDefinition()) {
  2737. var _marker = markerMidStyleProp.getDefinition();
  2738. for (var i2 = 1; i2 < markersLastIndex; i2++) {
  2739. var [_point, _angle] = markers[i2];
  2740. _marker.render(ctx, _point, _angle);
  2741. }
  2742. }
  2743. if (markerEndStyleProp.isUrlDefinition()) {
  2744. var _marker2 = markerEndStyleProp.getDefinition();
  2745. var [_point2, _angle2] = markers[markersLastIndex];
  2746. _marker2.render(ctx, _point2, _angle2);
  2747. }
  2748. }
  2749. }
  2750. static pathM(pathParser) {
  2751. var point = pathParser.getAsCurrentPoint();
  2752. pathParser.start = pathParser.current;
  2753. return {
  2754. point
  2755. };
  2756. }
  2757. pathM(ctx, boundingBox) {
  2758. var {
  2759. pathParser
  2760. } = this;
  2761. var {
  2762. point
  2763. } = _PathElement.pathM(pathParser);
  2764. var {
  2765. x,
  2766. y: y2
  2767. } = point;
  2768. pathParser.addMarker(point);
  2769. boundingBox.addPoint(x, y2);
  2770. if (ctx) {
  2771. ctx.moveTo(x, y2);
  2772. }
  2773. }
  2774. static pathL(pathParser) {
  2775. var {
  2776. current
  2777. } = pathParser;
  2778. var point = pathParser.getAsCurrentPoint();
  2779. return {
  2780. current,
  2781. point
  2782. };
  2783. }
  2784. pathL(ctx, boundingBox) {
  2785. var {
  2786. pathParser
  2787. } = this;
  2788. var {
  2789. current,
  2790. point
  2791. } = _PathElement.pathL(pathParser);
  2792. var {
  2793. x,
  2794. y: y2
  2795. } = point;
  2796. pathParser.addMarker(point, current);
  2797. boundingBox.addPoint(x, y2);
  2798. if (ctx) {
  2799. ctx.lineTo(x, y2);
  2800. }
  2801. }
  2802. static pathH(pathParser) {
  2803. var {
  2804. current,
  2805. command
  2806. } = pathParser;
  2807. var point = new Point((command.relative ? current.x : 0) + command.x, current.y);
  2808. pathParser.current = point;
  2809. return {
  2810. current,
  2811. point
  2812. };
  2813. }
  2814. pathH(ctx, boundingBox) {
  2815. var {
  2816. pathParser
  2817. } = this;
  2818. var {
  2819. current,
  2820. point
  2821. } = _PathElement.pathH(pathParser);
  2822. var {
  2823. x,
  2824. y: y2
  2825. } = point;
  2826. pathParser.addMarker(point, current);
  2827. boundingBox.addPoint(x, y2);
  2828. if (ctx) {
  2829. ctx.lineTo(x, y2);
  2830. }
  2831. }
  2832. static pathV(pathParser) {
  2833. var {
  2834. current,
  2835. command
  2836. } = pathParser;
  2837. var point = new Point(current.x, (command.relative ? current.y : 0) + command.y);
  2838. pathParser.current = point;
  2839. return {
  2840. current,
  2841. point
  2842. };
  2843. }
  2844. pathV(ctx, boundingBox) {
  2845. var {
  2846. pathParser
  2847. } = this;
  2848. var {
  2849. current,
  2850. point
  2851. } = _PathElement.pathV(pathParser);
  2852. var {
  2853. x,
  2854. y: y2
  2855. } = point;
  2856. pathParser.addMarker(point, current);
  2857. boundingBox.addPoint(x, y2);
  2858. if (ctx) {
  2859. ctx.lineTo(x, y2);
  2860. }
  2861. }
  2862. static pathC(pathParser) {
  2863. var {
  2864. current
  2865. } = pathParser;
  2866. var point = pathParser.getPoint("x1", "y1");
  2867. var controlPoint = pathParser.getAsControlPoint("x2", "y2");
  2868. var currentPoint = pathParser.getAsCurrentPoint();
  2869. return {
  2870. current,
  2871. point,
  2872. controlPoint,
  2873. currentPoint
  2874. };
  2875. }
  2876. pathC(ctx, boundingBox) {
  2877. var {
  2878. pathParser
  2879. } = this;
  2880. var {
  2881. current,
  2882. point,
  2883. controlPoint,
  2884. currentPoint
  2885. } = _PathElement.pathC(pathParser);
  2886. pathParser.addMarker(currentPoint, controlPoint, point);
  2887. boundingBox.addBezierCurve(current.x, current.y, point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  2888. if (ctx) {
  2889. ctx.bezierCurveTo(point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  2890. }
  2891. }
  2892. static pathS(pathParser) {
  2893. var {
  2894. current
  2895. } = pathParser;
  2896. var point = pathParser.getReflectedControlPoint();
  2897. var controlPoint = pathParser.getAsControlPoint("x2", "y2");
  2898. var currentPoint = pathParser.getAsCurrentPoint();
  2899. return {
  2900. current,
  2901. point,
  2902. controlPoint,
  2903. currentPoint
  2904. };
  2905. }
  2906. pathS(ctx, boundingBox) {
  2907. var {
  2908. pathParser
  2909. } = this;
  2910. var {
  2911. current,
  2912. point,
  2913. controlPoint,
  2914. currentPoint
  2915. } = _PathElement.pathS(pathParser);
  2916. pathParser.addMarker(currentPoint, controlPoint, point);
  2917. boundingBox.addBezierCurve(current.x, current.y, point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  2918. if (ctx) {
  2919. ctx.bezierCurveTo(point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  2920. }
  2921. }
  2922. static pathQ(pathParser) {
  2923. var {
  2924. current
  2925. } = pathParser;
  2926. var controlPoint = pathParser.getAsControlPoint("x1", "y1");
  2927. var currentPoint = pathParser.getAsCurrentPoint();
  2928. return {
  2929. current,
  2930. controlPoint,
  2931. currentPoint
  2932. };
  2933. }
  2934. pathQ(ctx, boundingBox) {
  2935. var {
  2936. pathParser
  2937. } = this;
  2938. var {
  2939. current,
  2940. controlPoint,
  2941. currentPoint
  2942. } = _PathElement.pathQ(pathParser);
  2943. pathParser.addMarker(currentPoint, controlPoint, controlPoint);
  2944. boundingBox.addQuadraticCurve(current.x, current.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  2945. if (ctx) {
  2946. ctx.quadraticCurveTo(controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  2947. }
  2948. }
  2949. static pathT(pathParser) {
  2950. var {
  2951. current
  2952. } = pathParser;
  2953. var controlPoint = pathParser.getReflectedControlPoint();
  2954. pathParser.control = controlPoint;
  2955. var currentPoint = pathParser.getAsCurrentPoint();
  2956. return {
  2957. current,
  2958. controlPoint,
  2959. currentPoint
  2960. };
  2961. }
  2962. pathT(ctx, boundingBox) {
  2963. var {
  2964. pathParser
  2965. } = this;
  2966. var {
  2967. current,
  2968. controlPoint,
  2969. currentPoint
  2970. } = _PathElement.pathT(pathParser);
  2971. pathParser.addMarker(currentPoint, controlPoint, controlPoint);
  2972. boundingBox.addQuadraticCurve(current.x, current.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  2973. if (ctx) {
  2974. ctx.quadraticCurveTo(controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  2975. }
  2976. }
  2977. static pathA(pathParser) {
  2978. var {
  2979. current,
  2980. command
  2981. } = pathParser;
  2982. var {
  2983. rX,
  2984. rY,
  2985. xRot,
  2986. lArcFlag,
  2987. sweepFlag
  2988. } = command;
  2989. var xAxisRotation = xRot * (Math.PI / 180);
  2990. var currentPoint = pathParser.getAsCurrentPoint();
  2991. var currp = new Point(Math.cos(xAxisRotation) * (current.x - currentPoint.x) / 2 + Math.sin(xAxisRotation) * (current.y - currentPoint.y) / 2, -Math.sin(xAxisRotation) * (current.x - currentPoint.x) / 2 + Math.cos(xAxisRotation) * (current.y - currentPoint.y) / 2);
  2992. var l2 = Math.pow(currp.x, 2) / Math.pow(rX, 2) + Math.pow(currp.y, 2) / Math.pow(rY, 2);
  2993. if (l2 > 1) {
  2994. rX *= Math.sqrt(l2);
  2995. rY *= Math.sqrt(l2);
  2996. }
  2997. var s2 = (lArcFlag === sweepFlag ? -1 : 1) * Math.sqrt((Math.pow(rX, 2) * Math.pow(rY, 2) - Math.pow(rX, 2) * Math.pow(currp.y, 2) - Math.pow(rY, 2) * Math.pow(currp.x, 2)) / (Math.pow(rX, 2) * Math.pow(currp.y, 2) + Math.pow(rY, 2) * Math.pow(currp.x, 2)));
  2998. if (isNaN(s2)) {
  2999. s2 = 0;
  3000. }
  3001. var cpp = new Point(s2 * rX * currp.y / rY, s2 * -rY * currp.x / rX);
  3002. var centp = new Point((current.x + currentPoint.x) / 2 + Math.cos(xAxisRotation) * cpp.x - Math.sin(xAxisRotation) * cpp.y, (current.y + currentPoint.y) / 2 + Math.sin(xAxisRotation) * cpp.x + Math.cos(xAxisRotation) * cpp.y);
  3003. var a1 = vectorsAngle([1, 0], [(currp.x - cpp.x) / rX, (currp.y - cpp.y) / rY]);
  3004. var u2 = [(currp.x - cpp.x) / rX, (currp.y - cpp.y) / rY];
  3005. var v2 = [(-currp.x - cpp.x) / rX, (-currp.y - cpp.y) / rY];
  3006. var ad = vectorsAngle(u2, v2);
  3007. if (vectorsRatio(u2, v2) <= -1) {
  3008. ad = Math.PI;
  3009. }
  3010. if (vectorsRatio(u2, v2) >= 1) {
  3011. ad = 0;
  3012. }
  3013. return {
  3014. currentPoint,
  3015. rX,
  3016. rY,
  3017. sweepFlag,
  3018. xAxisRotation,
  3019. centp,
  3020. a1,
  3021. ad
  3022. };
  3023. }
  3024. pathA(ctx, boundingBox) {
  3025. var {
  3026. pathParser
  3027. } = this;
  3028. var {
  3029. currentPoint,
  3030. rX,
  3031. rY,
  3032. sweepFlag,
  3033. xAxisRotation,
  3034. centp,
  3035. a1,
  3036. ad
  3037. } = _PathElement.pathA(pathParser);
  3038. var dir = 1 - sweepFlag ? 1 : -1;
  3039. var ah = a1 + dir * (ad / 2);
  3040. var halfWay = new Point(centp.x + rX * Math.cos(ah), centp.y + rY * Math.sin(ah));
  3041. pathParser.addMarkerAngle(halfWay, ah - dir * Math.PI / 2);
  3042. pathParser.addMarkerAngle(currentPoint, ah - dir * Math.PI);
  3043. boundingBox.addPoint(currentPoint.x, currentPoint.y);
  3044. if (ctx && !isNaN(a1) && !isNaN(ad)) {
  3045. var r2 = rX > rY ? rX : rY;
  3046. var sx = rX > rY ? 1 : rX / rY;
  3047. var sy = rX > rY ? rY / rX : 1;
  3048. ctx.translate(centp.x, centp.y);
  3049. ctx.rotate(xAxisRotation);
  3050. ctx.scale(sx, sy);
  3051. ctx.arc(0, 0, r2, a1, a1 + ad, Boolean(1 - sweepFlag));
  3052. ctx.scale(1 / sx, 1 / sy);
  3053. ctx.rotate(-xAxisRotation);
  3054. ctx.translate(-centp.x, -centp.y);
  3055. }
  3056. }
  3057. static pathZ(pathParser) {
  3058. pathParser.current = pathParser.start;
  3059. }
  3060. pathZ(ctx, boundingBox) {
  3061. _PathElement.pathZ(this.pathParser);
  3062. if (ctx) {
  3063. if (boundingBox.x1 !== boundingBox.x2 && boundingBox.y1 !== boundingBox.y2) {
  3064. ctx.closePath();
  3065. }
  3066. }
  3067. }
  3068. };
  3069. GlyphElement = class extends PathElement {
  3070. constructor(document2, node2, captureTextNodes) {
  3071. super(document2, node2, captureTextNodes);
  3072. this.type = "glyph";
  3073. this.horizAdvX = this.getAttribute("horiz-adv-x").getNumber();
  3074. this.unicode = this.getAttribute("unicode").getString();
  3075. this.arabicForm = this.getAttribute("arabic-form").getString();
  3076. }
  3077. };
  3078. TextElement = class _TextElement extends RenderedElement {
  3079. constructor(document2, node2, captureTextNodes) {
  3080. super(document2, node2, new.target === _TextElement ? true : captureTextNodes);
  3081. this.type = "text";
  3082. this.x = 0;
  3083. this.y = 0;
  3084. this.measureCache = -1;
  3085. }
  3086. setContext(ctx) {
  3087. var fromMeasure = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
  3088. super.setContext(ctx, fromMeasure);
  3089. var textBaseline = this.getStyle("dominant-baseline").getTextBaseline() || this.getStyle("alignment-baseline").getTextBaseline();
  3090. if (textBaseline) {
  3091. ctx.textBaseline = textBaseline;
  3092. }
  3093. }
  3094. initializeCoordinates() {
  3095. this.x = 0;
  3096. this.y = 0;
  3097. this.leafTexts = [];
  3098. this.textChunkStart = 0;
  3099. this.minX = Number.POSITIVE_INFINITY;
  3100. this.maxX = Number.NEGATIVE_INFINITY;
  3101. }
  3102. getBoundingBox(ctx) {
  3103. if (this.type !== "text") {
  3104. return this.getTElementBoundingBox(ctx);
  3105. }
  3106. this.initializeCoordinates();
  3107. this.adjustChildCoordinatesRecursive(ctx);
  3108. var boundingBox = null;
  3109. this.children.forEach((_2, i2) => {
  3110. var childBoundingBox = this.getChildBoundingBox(ctx, this, this, i2);
  3111. if (!boundingBox) {
  3112. boundingBox = childBoundingBox;
  3113. } else {
  3114. boundingBox.addBoundingBox(childBoundingBox);
  3115. }
  3116. });
  3117. return boundingBox;
  3118. }
  3119. getFontSize() {
  3120. var {
  3121. document: document2,
  3122. parent
  3123. } = this;
  3124. var inheritFontSize = Font.parse(document2.ctx.font).fontSize;
  3125. var fontSize = parent.getStyle("font-size").getNumber(inheritFontSize);
  3126. return fontSize;
  3127. }
  3128. getTElementBoundingBox(ctx) {
  3129. var fontSize = this.getFontSize();
  3130. return new BoundingBox(this.x, this.y - fontSize, this.x + this.measureText(ctx), this.y);
  3131. }
  3132. getGlyph(font, text, i2) {
  3133. var char = text[i2];
  3134. var glyph = null;
  3135. if (font.isArabic) {
  3136. var len = text.length;
  3137. var prevChar = text[i2 - 1];
  3138. var nextChar = text[i2 + 1];
  3139. var arabicForm = "isolated";
  3140. if ((i2 === 0 || prevChar === " ") && i2 < len - 1 && nextChar !== " ") {
  3141. arabicForm = "terminal";
  3142. }
  3143. if (i2 > 0 && prevChar !== " " && i2 < len - 1 && nextChar !== " ") {
  3144. arabicForm = "medial";
  3145. }
  3146. if (i2 > 0 && prevChar !== " " && (i2 === len - 1 || nextChar === " ")) {
  3147. arabicForm = "initial";
  3148. }
  3149. if (typeof font.glyphs[char] !== "undefined") {
  3150. var maybeGlyph = font.glyphs[char];
  3151. glyph = maybeGlyph instanceof GlyphElement ? maybeGlyph : maybeGlyph[arabicForm];
  3152. }
  3153. } else {
  3154. glyph = font.glyphs[char];
  3155. }
  3156. if (!glyph) {
  3157. glyph = font.missingGlyph;
  3158. }
  3159. return glyph;
  3160. }
  3161. getText() {
  3162. return "";
  3163. }
  3164. getTextFromNode(node2) {
  3165. var textNode = node2 || this.node;
  3166. var childNodes = Array.from(textNode.parentNode.childNodes);
  3167. var index2 = childNodes.indexOf(textNode);
  3168. var lastIndex = childNodes.length - 1;
  3169. var text = compressSpaces(
  3170. // textNode.value
  3171. // || textNode.text
  3172. textNode.textContent || ""
  3173. );
  3174. if (index2 === 0) {
  3175. text = trimLeft(text);
  3176. }
  3177. if (index2 === lastIndex) {
  3178. text = trimRight(text);
  3179. }
  3180. return text;
  3181. }
  3182. renderChildren(ctx) {
  3183. if (this.type !== "text") {
  3184. this.renderTElementChildren(ctx);
  3185. return;
  3186. }
  3187. this.initializeCoordinates();
  3188. this.adjustChildCoordinatesRecursive(ctx);
  3189. this.children.forEach((_2, i2) => {
  3190. this.renderChild(ctx, this, this, i2);
  3191. });
  3192. var {
  3193. mouse
  3194. } = this.document.screen;
  3195. if (mouse.isWorking()) {
  3196. mouse.checkBoundingBox(this, this.getBoundingBox(ctx));
  3197. }
  3198. }
  3199. renderTElementChildren(ctx) {
  3200. var {
  3201. document: document2,
  3202. parent
  3203. } = this;
  3204. var renderText = this.getText();
  3205. var customFont = parent.getStyle("font-family").getDefinition();
  3206. if (customFont) {
  3207. var {
  3208. unitsPerEm
  3209. } = customFont.fontFace;
  3210. var ctxFont = Font.parse(document2.ctx.font);
  3211. var fontSize = parent.getStyle("font-size").getNumber(ctxFont.fontSize);
  3212. var fontStyle = parent.getStyle("font-style").getString(ctxFont.fontStyle);
  3213. var scale = fontSize / unitsPerEm;
  3214. var text = customFont.isRTL ? renderText.split("").reverse().join("") : renderText;
  3215. var dx = toNumbers(parent.getAttribute("dx").getString());
  3216. var len = text.length;
  3217. for (var i2 = 0; i2 < len; i2++) {
  3218. var glyph = this.getGlyph(customFont, text, i2);
  3219. ctx.translate(this.x, this.y);
  3220. ctx.scale(scale, -scale);
  3221. var lw = ctx.lineWidth;
  3222. ctx.lineWidth = ctx.lineWidth * unitsPerEm / fontSize;
  3223. if (fontStyle === "italic") {
  3224. ctx.transform(1, 0, 0.4, 1, 0, 0);
  3225. }
  3226. glyph.render(ctx);
  3227. if (fontStyle === "italic") {
  3228. ctx.transform(1, 0, -0.4, 1, 0, 0);
  3229. }
  3230. ctx.lineWidth = lw;
  3231. ctx.scale(1 / scale, -1 / scale);
  3232. ctx.translate(-this.x, -this.y);
  3233. this.x += fontSize * (glyph.horizAdvX || customFont.horizAdvX) / unitsPerEm;
  3234. if (typeof dx[i2] !== "undefined" && !isNaN(dx[i2])) {
  3235. this.x += dx[i2];
  3236. }
  3237. }
  3238. return;
  3239. }
  3240. var {
  3241. x,
  3242. y: y2
  3243. } = this;
  3244. if (ctx.fillStyle) {
  3245. ctx.fillText(renderText, x, y2);
  3246. }
  3247. if (ctx.strokeStyle) {
  3248. ctx.strokeText(renderText, x, y2);
  3249. }
  3250. }
  3251. applyAnchoring() {
  3252. if (this.textChunkStart >= this.leafTexts.length) {
  3253. return;
  3254. }
  3255. var firstElement = this.leafTexts[this.textChunkStart];
  3256. var textAnchor = firstElement.getStyle("text-anchor").getString("start");
  3257. var isRTL = false;
  3258. var shift = 0;
  3259. if (textAnchor === "start" && !isRTL || textAnchor === "end" && isRTL) {
  3260. shift = firstElement.x - this.minX;
  3261. } else if (textAnchor === "end" && !isRTL || textAnchor === "start" && isRTL) {
  3262. shift = firstElement.x - this.maxX;
  3263. } else {
  3264. shift = firstElement.x - (this.minX + this.maxX) / 2;
  3265. }
  3266. for (var i2 = this.textChunkStart; i2 < this.leafTexts.length; i2++) {
  3267. this.leafTexts[i2].x += shift;
  3268. }
  3269. this.minX = Number.POSITIVE_INFINITY;
  3270. this.maxX = Number.NEGATIVE_INFINITY;
  3271. this.textChunkStart = this.leafTexts.length;
  3272. }
  3273. adjustChildCoordinatesRecursive(ctx) {
  3274. this.children.forEach((_2, i2) => {
  3275. this.adjustChildCoordinatesRecursiveCore(ctx, this, this, i2);
  3276. });
  3277. this.applyAnchoring();
  3278. }
  3279. adjustChildCoordinatesRecursiveCore(ctx, textParent, parent, i2) {
  3280. var child = parent.children[i2];
  3281. if (child.children.length > 0) {
  3282. child.children.forEach((_2, i3) => {
  3283. textParent.adjustChildCoordinatesRecursiveCore(ctx, textParent, child, i3);
  3284. });
  3285. } else {
  3286. this.adjustChildCoordinates(ctx, textParent, parent, i2);
  3287. }
  3288. }
  3289. adjustChildCoordinates(ctx, textParent, parent, i2) {
  3290. var child = parent.children[i2];
  3291. if (typeof child.measureText !== "function") {
  3292. return child;
  3293. }
  3294. ctx.save();
  3295. child.setContext(ctx, true);
  3296. var xAttr = child.getAttribute("x");
  3297. var yAttr = child.getAttribute("y");
  3298. var dxAttr = child.getAttribute("dx");
  3299. var dyAttr = child.getAttribute("dy");
  3300. var customFont = child.getStyle("font-family").getDefinition();
  3301. var isRTL = Boolean(customFont) && customFont.isRTL;
  3302. if (i2 === 0) {
  3303. if (!xAttr.hasValue()) {
  3304. xAttr.setValue(child.getInheritedAttribute("x"));
  3305. }
  3306. if (!yAttr.hasValue()) {
  3307. yAttr.setValue(child.getInheritedAttribute("y"));
  3308. }
  3309. if (!dxAttr.hasValue()) {
  3310. dxAttr.setValue(child.getInheritedAttribute("dx"));
  3311. }
  3312. if (!dyAttr.hasValue()) {
  3313. dyAttr.setValue(child.getInheritedAttribute("dy"));
  3314. }
  3315. }
  3316. var width = child.measureText(ctx);
  3317. if (isRTL) {
  3318. textParent.x -= width;
  3319. }
  3320. if (xAttr.hasValue()) {
  3321. textParent.applyAnchoring();
  3322. child.x = xAttr.getPixels("x");
  3323. if (dxAttr.hasValue()) {
  3324. child.x += dxAttr.getPixels("x");
  3325. }
  3326. } else {
  3327. if (dxAttr.hasValue()) {
  3328. textParent.x += dxAttr.getPixels("x");
  3329. }
  3330. child.x = textParent.x;
  3331. }
  3332. textParent.x = child.x;
  3333. if (!isRTL) {
  3334. textParent.x += width;
  3335. }
  3336. if (yAttr.hasValue()) {
  3337. child.y = yAttr.getPixels("y");
  3338. if (dyAttr.hasValue()) {
  3339. child.y += dyAttr.getPixels("y");
  3340. }
  3341. } else {
  3342. if (dyAttr.hasValue()) {
  3343. textParent.y += dyAttr.getPixels("y");
  3344. }
  3345. child.y = textParent.y;
  3346. }
  3347. textParent.y = child.y;
  3348. textParent.leafTexts.push(child);
  3349. textParent.minX = Math.min(textParent.minX, child.x, child.x + width);
  3350. textParent.maxX = Math.max(textParent.maxX, child.x, child.x + width);
  3351. child.clearContext(ctx);
  3352. ctx.restore();
  3353. return child;
  3354. }
  3355. getChildBoundingBox(ctx, textParent, parent, i2) {
  3356. var child = parent.children[i2];
  3357. if (typeof child.getBoundingBox !== "function") {
  3358. return null;
  3359. }
  3360. var boundingBox = child.getBoundingBox(ctx);
  3361. if (!boundingBox) {
  3362. return null;
  3363. }
  3364. child.children.forEach((_2, i3) => {
  3365. var childBoundingBox = textParent.getChildBoundingBox(ctx, textParent, child, i3);
  3366. boundingBox.addBoundingBox(childBoundingBox);
  3367. });
  3368. return boundingBox;
  3369. }
  3370. renderChild(ctx, textParent, parent, i2) {
  3371. var child = parent.children[i2];
  3372. child.render(ctx);
  3373. child.children.forEach((_2, i3) => {
  3374. textParent.renderChild(ctx, textParent, child, i3);
  3375. });
  3376. }
  3377. measureText(ctx) {
  3378. var {
  3379. measureCache
  3380. } = this;
  3381. if (~measureCache) {
  3382. return measureCache;
  3383. }
  3384. var renderText = this.getText();
  3385. var measure = this.measureTargetText(ctx, renderText);
  3386. this.measureCache = measure;
  3387. return measure;
  3388. }
  3389. measureTargetText(ctx, targetText) {
  3390. if (!targetText.length) {
  3391. return 0;
  3392. }
  3393. var {
  3394. parent
  3395. } = this;
  3396. var customFont = parent.getStyle("font-family").getDefinition();
  3397. if (customFont) {
  3398. var fontSize = this.getFontSize();
  3399. var text = customFont.isRTL ? targetText.split("").reverse().join("") : targetText;
  3400. var dx = toNumbers(parent.getAttribute("dx").getString());
  3401. var len = text.length;
  3402. var _measure = 0;
  3403. for (var i2 = 0; i2 < len; i2++) {
  3404. var glyph = this.getGlyph(customFont, text, i2);
  3405. _measure += (glyph.horizAdvX || customFont.horizAdvX) * fontSize / customFont.fontFace.unitsPerEm;
  3406. if (typeof dx[i2] !== "undefined" && !isNaN(dx[i2])) {
  3407. _measure += dx[i2];
  3408. }
  3409. }
  3410. return _measure;
  3411. }
  3412. if (!ctx.measureText) {
  3413. return targetText.length * 10;
  3414. }
  3415. ctx.save();
  3416. this.setContext(ctx, true);
  3417. var {
  3418. width: measure
  3419. } = ctx.measureText(targetText);
  3420. this.clearContext(ctx);
  3421. ctx.restore();
  3422. return measure;
  3423. }
  3424. /**
  3425. * Inherits positional attributes from {@link TextElement} parent(s). Attributes
  3426. * are only inherited from a parent to its first child.
  3427. * @param name - The attribute name.
  3428. * @returns The attribute value or null.
  3429. */
  3430. getInheritedAttribute(name) {
  3431. var current = this;
  3432. while (current instanceof _TextElement && current.isFirstChild()) {
  3433. var parentAttr = current.parent.getAttribute(name);
  3434. if (parentAttr.hasValue(true)) {
  3435. return parentAttr.getValue("0");
  3436. }
  3437. current = current.parent;
  3438. }
  3439. return null;
  3440. }
  3441. };
  3442. TSpanElement = class _TSpanElement extends TextElement {
  3443. constructor(document2, node2, captureTextNodes) {
  3444. super(document2, node2, new.target === _TSpanElement ? true : captureTextNodes);
  3445. this.type = "tspan";
  3446. this.text = this.children.length > 0 ? "" : this.getTextFromNode();
  3447. }
  3448. getText() {
  3449. return this.text;
  3450. }
  3451. };
  3452. TextNode = class extends TSpanElement {
  3453. constructor() {
  3454. super(...arguments);
  3455. this.type = "textNode";
  3456. }
  3457. };
  3458. SVGElement = class extends RenderedElement {
  3459. constructor() {
  3460. super(...arguments);
  3461. this.type = "svg";
  3462. this.root = false;
  3463. }
  3464. setContext(ctx) {
  3465. var _this$node$parentNode;
  3466. var {
  3467. document: document2
  3468. } = this;
  3469. var {
  3470. screen,
  3471. window: window2
  3472. } = document2;
  3473. var canvas = ctx.canvas;
  3474. screen.setDefaults(ctx);
  3475. if (canvas.style && typeof ctx.font !== "undefined" && window2 && typeof window2.getComputedStyle !== "undefined") {
  3476. ctx.font = window2.getComputedStyle(canvas).getPropertyValue("font");
  3477. var fontSizeProp = new Property(document2, "fontSize", Font.parse(ctx.font).fontSize);
  3478. if (fontSizeProp.hasValue()) {
  3479. document2.rootEmSize = fontSizeProp.getPixels("y");
  3480. document2.emSize = document2.rootEmSize;
  3481. }
  3482. }
  3483. if (!this.getAttribute("x").hasValue()) {
  3484. this.getAttribute("x", true).setValue(0);
  3485. }
  3486. if (!this.getAttribute("y").hasValue()) {
  3487. this.getAttribute("y", true).setValue(0);
  3488. }
  3489. var {
  3490. width,
  3491. height
  3492. } = screen.viewPort;
  3493. if (!this.getStyle("width").hasValue()) {
  3494. this.getStyle("width", true).setValue("100%");
  3495. }
  3496. if (!this.getStyle("height").hasValue()) {
  3497. this.getStyle("height", true).setValue("100%");
  3498. }
  3499. if (!this.getStyle("color").hasValue()) {
  3500. this.getStyle("color", true).setValue("black");
  3501. }
  3502. var refXAttr = this.getAttribute("refX");
  3503. var refYAttr = this.getAttribute("refY");
  3504. var viewBoxAttr = this.getAttribute("viewBox");
  3505. var viewBox = viewBoxAttr.hasValue() ? toNumbers(viewBoxAttr.getString()) : null;
  3506. var clip = !this.root && this.getStyle("overflow").getValue("hidden") !== "visible";
  3507. var minX = 0;
  3508. var minY = 0;
  3509. var clipX = 0;
  3510. var clipY = 0;
  3511. if (viewBox) {
  3512. minX = viewBox[0];
  3513. minY = viewBox[1];
  3514. }
  3515. if (!this.root) {
  3516. width = this.getStyle("width").getPixels("x");
  3517. height = this.getStyle("height").getPixels("y");
  3518. if (this.type === "marker") {
  3519. clipX = minX;
  3520. clipY = minY;
  3521. minX = 0;
  3522. minY = 0;
  3523. }
  3524. }
  3525. screen.viewPort.setCurrent(width, height);
  3526. if (this.node && (!this.parent || ((_this$node$parentNode = this.node.parentNode) === null || _this$node$parentNode === void 0 ? void 0 : _this$node$parentNode.nodeName) === "foreignObject") && this.getStyle("transform", false, true).hasValue() && !this.getStyle("transform-origin", false, true).hasValue()) {
  3527. this.getStyle("transform-origin", true, true).setValue("50% 50%");
  3528. }
  3529. super.setContext(ctx);
  3530. ctx.translate(this.getAttribute("x").getPixels("x"), this.getAttribute("y").getPixels("y"));
  3531. if (viewBox) {
  3532. width = viewBox[2];
  3533. height = viewBox[3];
  3534. }
  3535. document2.setViewBox({
  3536. ctx,
  3537. aspectRatio: this.getAttribute("preserveAspectRatio").getString(),
  3538. width: screen.viewPort.width,
  3539. desiredWidth: width,
  3540. height: screen.viewPort.height,
  3541. desiredHeight: height,
  3542. minX,
  3543. minY,
  3544. refX: refXAttr.getValue(),
  3545. refY: refYAttr.getValue(),
  3546. clip,
  3547. clipX,
  3548. clipY
  3549. });
  3550. if (viewBox) {
  3551. screen.viewPort.removeCurrent();
  3552. screen.viewPort.setCurrent(width, height);
  3553. }
  3554. }
  3555. clearContext(ctx) {
  3556. super.clearContext(ctx);
  3557. this.document.screen.viewPort.removeCurrent();
  3558. }
  3559. /**
  3560. * Resize SVG to fit in given size.
  3561. * @param width
  3562. * @param height
  3563. * @param preserveAspectRatio
  3564. */
  3565. resize(width) {
  3566. var height = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : width;
  3567. var preserveAspectRatio = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
  3568. var widthAttr = this.getAttribute("width", true);
  3569. var heightAttr = this.getAttribute("height", true);
  3570. var viewBoxAttr = this.getAttribute("viewBox");
  3571. var styleAttr = this.getAttribute("style");
  3572. var originWidth = widthAttr.getNumber(0);
  3573. var originHeight = heightAttr.getNumber(0);
  3574. if (preserveAspectRatio) {
  3575. if (typeof preserveAspectRatio === "string") {
  3576. this.getAttribute("preserveAspectRatio", true).setValue(preserveAspectRatio);
  3577. } else {
  3578. var preserveAspectRatioAttr = this.getAttribute("preserveAspectRatio");
  3579. if (preserveAspectRatioAttr.hasValue()) {
  3580. preserveAspectRatioAttr.setValue(preserveAspectRatioAttr.getString().replace(/^\s*(\S.*\S)\s*$/, "$1"));
  3581. }
  3582. }
  3583. }
  3584. widthAttr.setValue(width);
  3585. heightAttr.setValue(height);
  3586. if (!viewBoxAttr.hasValue()) {
  3587. viewBoxAttr.setValue("0 0 ".concat(originWidth || width, " ").concat(originHeight || height));
  3588. }
  3589. if (styleAttr.hasValue()) {
  3590. var widthStyle = this.getStyle("width");
  3591. var heightStyle = this.getStyle("height");
  3592. if (widthStyle.hasValue()) {
  3593. widthStyle.setValue("".concat(width, "px"));
  3594. }
  3595. if (heightStyle.hasValue()) {
  3596. heightStyle.setValue("".concat(height, "px"));
  3597. }
  3598. }
  3599. }
  3600. };
  3601. RectElement = class extends PathElement {
  3602. constructor() {
  3603. super(...arguments);
  3604. this.type = "rect";
  3605. }
  3606. path(ctx) {
  3607. var x = this.getAttribute("x").getPixels("x");
  3608. var y2 = this.getAttribute("y").getPixels("y");
  3609. var width = this.getStyle("width", false, true).getPixels("x");
  3610. var height = this.getStyle("height", false, true).getPixels("y");
  3611. var rxAttr = this.getAttribute("rx");
  3612. var ryAttr = this.getAttribute("ry");
  3613. var rx = rxAttr.getPixels("x");
  3614. var ry = ryAttr.getPixels("y");
  3615. if (rxAttr.hasValue() && !ryAttr.hasValue()) {
  3616. ry = rx;
  3617. }
  3618. if (ryAttr.hasValue() && !rxAttr.hasValue()) {
  3619. rx = ry;
  3620. }
  3621. rx = Math.min(rx, width / 2);
  3622. ry = Math.min(ry, height / 2);
  3623. if (ctx) {
  3624. var KAPPA = 4 * ((Math.sqrt(2) - 1) / 3);
  3625. ctx.beginPath();
  3626. if (height > 0 && width > 0) {
  3627. ctx.moveTo(x + rx, y2);
  3628. ctx.lineTo(x + width - rx, y2);
  3629. ctx.bezierCurveTo(x + width - rx + KAPPA * rx, y2, x + width, y2 + ry - KAPPA * ry, x + width, y2 + ry);
  3630. ctx.lineTo(x + width, y2 + height - ry);
  3631. ctx.bezierCurveTo(x + width, y2 + height - ry + KAPPA * ry, x + width - rx + KAPPA * rx, y2 + height, x + width - rx, y2 + height);
  3632. ctx.lineTo(x + rx, y2 + height);
  3633. ctx.bezierCurveTo(x + rx - KAPPA * rx, y2 + height, x, y2 + height - ry + KAPPA * ry, x, y2 + height - ry);
  3634. ctx.lineTo(x, y2 + ry);
  3635. ctx.bezierCurveTo(x, y2 + ry - KAPPA * ry, x + rx - KAPPA * rx, y2, x + rx, y2);
  3636. ctx.closePath();
  3637. }
  3638. }
  3639. return new BoundingBox(x, y2, x + width, y2 + height);
  3640. }
  3641. getMarkers() {
  3642. return null;
  3643. }
  3644. };
  3645. CircleElement = class extends PathElement {
  3646. constructor() {
  3647. super(...arguments);
  3648. this.type = "circle";
  3649. }
  3650. path(ctx) {
  3651. var cx = this.getAttribute("cx").getPixels("x");
  3652. var cy = this.getAttribute("cy").getPixels("y");
  3653. var r2 = this.getAttribute("r").getPixels();
  3654. if (ctx && r2 > 0) {
  3655. ctx.beginPath();
  3656. ctx.arc(cx, cy, r2, 0, Math.PI * 2, false);
  3657. ctx.closePath();
  3658. }
  3659. return new BoundingBox(cx - r2, cy - r2, cx + r2, cy + r2);
  3660. }
  3661. getMarkers() {
  3662. return null;
  3663. }
  3664. };
  3665. EllipseElement = class extends PathElement {
  3666. constructor() {
  3667. super(...arguments);
  3668. this.type = "ellipse";
  3669. }
  3670. path(ctx) {
  3671. var KAPPA = 4 * ((Math.sqrt(2) - 1) / 3);
  3672. var rx = this.getAttribute("rx").getPixels("x");
  3673. var ry = this.getAttribute("ry").getPixels("y");
  3674. var cx = this.getAttribute("cx").getPixels("x");
  3675. var cy = this.getAttribute("cy").getPixels("y");
  3676. if (ctx && rx > 0 && ry > 0) {
  3677. ctx.beginPath();
  3678. ctx.moveTo(cx + rx, cy);
  3679. ctx.bezierCurveTo(cx + rx, cy + KAPPA * ry, cx + KAPPA * rx, cy + ry, cx, cy + ry);
  3680. ctx.bezierCurveTo(cx - KAPPA * rx, cy + ry, cx - rx, cy + KAPPA * ry, cx - rx, cy);
  3681. ctx.bezierCurveTo(cx - rx, cy - KAPPA * ry, cx - KAPPA * rx, cy - ry, cx, cy - ry);
  3682. ctx.bezierCurveTo(cx + KAPPA * rx, cy - ry, cx + rx, cy - KAPPA * ry, cx + rx, cy);
  3683. ctx.closePath();
  3684. }
  3685. return new BoundingBox(cx - rx, cy - ry, cx + rx, cy + ry);
  3686. }
  3687. getMarkers() {
  3688. return null;
  3689. }
  3690. };
  3691. LineElement = class extends PathElement {
  3692. constructor() {
  3693. super(...arguments);
  3694. this.type = "line";
  3695. }
  3696. getPoints() {
  3697. return [new Point(this.getAttribute("x1").getPixels("x"), this.getAttribute("y1").getPixels("y")), new Point(this.getAttribute("x2").getPixels("x"), this.getAttribute("y2").getPixels("y"))];
  3698. }
  3699. path(ctx) {
  3700. var [{
  3701. x: x0,
  3702. y: y0
  3703. }, {
  3704. x: x1,
  3705. y: y1
  3706. }] = this.getPoints();
  3707. if (ctx) {
  3708. ctx.beginPath();
  3709. ctx.moveTo(x0, y0);
  3710. ctx.lineTo(x1, y1);
  3711. }
  3712. return new BoundingBox(x0, y0, x1, y1);
  3713. }
  3714. getMarkers() {
  3715. var [p0, p1] = this.getPoints();
  3716. var a2 = p0.angleTo(p1);
  3717. return [[p0, a2], [p1, a2]];
  3718. }
  3719. };
  3720. PolylineElement = class extends PathElement {
  3721. constructor(document2, node2, captureTextNodes) {
  3722. super(document2, node2, captureTextNodes);
  3723. this.type = "polyline";
  3724. this.points = [];
  3725. this.points = Point.parsePath(this.getAttribute("points").getString());
  3726. }
  3727. path(ctx) {
  3728. var {
  3729. points
  3730. } = this;
  3731. var [{
  3732. x: x0,
  3733. y: y0
  3734. }] = points;
  3735. var boundingBox = new BoundingBox(x0, y0);
  3736. if (ctx) {
  3737. ctx.beginPath();
  3738. ctx.moveTo(x0, y0);
  3739. }
  3740. points.forEach((_ref) => {
  3741. var {
  3742. x,
  3743. y: y2
  3744. } = _ref;
  3745. boundingBox.addPoint(x, y2);
  3746. if (ctx) {
  3747. ctx.lineTo(x, y2);
  3748. }
  3749. });
  3750. return boundingBox;
  3751. }
  3752. getMarkers() {
  3753. var {
  3754. points
  3755. } = this;
  3756. var lastIndex = points.length - 1;
  3757. var markers = [];
  3758. points.forEach((point, i2) => {
  3759. if (i2 === lastIndex) {
  3760. return;
  3761. }
  3762. markers.push([point, point.angleTo(points[i2 + 1])]);
  3763. });
  3764. if (markers.length > 0) {
  3765. markers.push([points[points.length - 1], markers[markers.length - 1][1]]);
  3766. }
  3767. return markers;
  3768. }
  3769. };
  3770. PolygonElement = class extends PolylineElement {
  3771. constructor() {
  3772. super(...arguments);
  3773. this.type = "polygon";
  3774. }
  3775. path(ctx) {
  3776. var boundingBox = super.path(ctx);
  3777. var [{
  3778. x,
  3779. y: y2
  3780. }] = this.points;
  3781. if (ctx) {
  3782. ctx.lineTo(x, y2);
  3783. ctx.closePath();
  3784. }
  3785. return boundingBox;
  3786. }
  3787. };
  3788. PatternElement = class extends Element {
  3789. constructor() {
  3790. super(...arguments);
  3791. this.type = "pattern";
  3792. }
  3793. createPattern(ctx, _2, parentOpacityProp) {
  3794. var width = this.getStyle("width").getPixels("x", true);
  3795. var height = this.getStyle("height").getPixels("y", true);
  3796. var patternSvg = new SVGElement(this.document, null);
  3797. patternSvg.attributes.viewBox = new Property(this.document, "viewBox", this.getAttribute("viewBox").getValue());
  3798. patternSvg.attributes.width = new Property(this.document, "width", "".concat(width, "px"));
  3799. patternSvg.attributes.height = new Property(this.document, "height", "".concat(height, "px"));
  3800. patternSvg.attributes.transform = new Property(this.document, "transform", this.getAttribute("patternTransform").getValue());
  3801. patternSvg.children = this.children;
  3802. var patternCanvas = this.document.createCanvas(width, height);
  3803. var patternCtx = patternCanvas.getContext("2d");
  3804. var xAttr = this.getAttribute("x");
  3805. var yAttr = this.getAttribute("y");
  3806. if (xAttr.hasValue() && yAttr.hasValue()) {
  3807. patternCtx.translate(xAttr.getPixels("x", true), yAttr.getPixels("y", true));
  3808. }
  3809. if (parentOpacityProp.hasValue()) {
  3810. this.styles["fill-opacity"] = parentOpacityProp;
  3811. } else {
  3812. Reflect.deleteProperty(this.styles, "fill-opacity");
  3813. }
  3814. for (var x = -1; x <= 1; x++) {
  3815. for (var y2 = -1; y2 <= 1; y2++) {
  3816. patternCtx.save();
  3817. patternSvg.attributes.x = new Property(this.document, "x", x * patternCanvas.width);
  3818. patternSvg.attributes.y = new Property(this.document, "y", y2 * patternCanvas.height);
  3819. patternSvg.render(patternCtx);
  3820. patternCtx.restore();
  3821. }
  3822. }
  3823. var pattern = ctx.createPattern(patternCanvas, "repeat");
  3824. return pattern;
  3825. }
  3826. };
  3827. MarkerElement = class extends Element {
  3828. constructor() {
  3829. super(...arguments);
  3830. this.type = "marker";
  3831. }
  3832. render(ctx, point, angle) {
  3833. if (!point) {
  3834. return;
  3835. }
  3836. var {
  3837. x,
  3838. y: y2
  3839. } = point;
  3840. var orient = this.getAttribute("orient").getString("auto");
  3841. var markerUnits = this.getAttribute("markerUnits").getString("strokeWidth");
  3842. ctx.translate(x, y2);
  3843. if (orient === "auto") {
  3844. ctx.rotate(angle);
  3845. }
  3846. if (markerUnits === "strokeWidth") {
  3847. ctx.scale(ctx.lineWidth, ctx.lineWidth);
  3848. }
  3849. ctx.save();
  3850. var markerSvg = new SVGElement(this.document, null);
  3851. markerSvg.type = this.type;
  3852. markerSvg.attributes.viewBox = new Property(this.document, "viewBox", this.getAttribute("viewBox").getValue());
  3853. markerSvg.attributes.refX = new Property(this.document, "refX", this.getAttribute("refX").getValue());
  3854. markerSvg.attributes.refY = new Property(this.document, "refY", this.getAttribute("refY").getValue());
  3855. markerSvg.attributes.width = new Property(this.document, "width", this.getAttribute("markerWidth").getValue());
  3856. markerSvg.attributes.height = new Property(this.document, "height", this.getAttribute("markerHeight").getValue());
  3857. markerSvg.attributes.overflow = new Property(this.document, "overflow", this.getAttribute("overflow").getValue());
  3858. markerSvg.attributes.fill = new Property(this.document, "fill", this.getAttribute("fill").getColor("black"));
  3859. markerSvg.attributes.stroke = new Property(this.document, "stroke", this.getAttribute("stroke").getValue("none"));
  3860. markerSvg.children = this.children;
  3861. markerSvg.render(ctx);
  3862. ctx.restore();
  3863. if (markerUnits === "strokeWidth") {
  3864. ctx.scale(1 / ctx.lineWidth, 1 / ctx.lineWidth);
  3865. }
  3866. if (orient === "auto") {
  3867. ctx.rotate(-angle);
  3868. }
  3869. ctx.translate(-x, -y2);
  3870. }
  3871. };
  3872. DefsElement = class extends Element {
  3873. constructor() {
  3874. super(...arguments);
  3875. this.type = "defs";
  3876. }
  3877. render() {
  3878. }
  3879. };
  3880. GElement = class extends RenderedElement {
  3881. constructor() {
  3882. super(...arguments);
  3883. this.type = "g";
  3884. }
  3885. getBoundingBox(ctx) {
  3886. var boundingBox = new BoundingBox();
  3887. this.children.forEach((child) => {
  3888. boundingBox.addBoundingBox(child.getBoundingBox(ctx));
  3889. });
  3890. return boundingBox;
  3891. }
  3892. };
  3893. GradientElement = class extends Element {
  3894. constructor(document2, node2, captureTextNodes) {
  3895. super(document2, node2, captureTextNodes);
  3896. this.attributesToInherit = ["gradientUnits"];
  3897. this.stops = [];
  3898. var {
  3899. stops,
  3900. children
  3901. } = this;
  3902. children.forEach((child) => {
  3903. if (child.type === "stop") {
  3904. stops.push(child);
  3905. }
  3906. });
  3907. }
  3908. getGradientUnits() {
  3909. return this.getAttribute("gradientUnits").getString("objectBoundingBox");
  3910. }
  3911. createGradient(ctx, element, parentOpacityProp) {
  3912. var stopsContainer = this;
  3913. if (this.getHrefAttribute().hasValue()) {
  3914. stopsContainer = this.getHrefAttribute().getDefinition();
  3915. this.inheritStopContainer(stopsContainer);
  3916. }
  3917. var {
  3918. stops
  3919. } = stopsContainer;
  3920. var gradient = this.getGradient(ctx, element);
  3921. if (!gradient) {
  3922. return this.addParentOpacity(parentOpacityProp, stops[stops.length - 1].color);
  3923. }
  3924. stops.forEach((stop) => {
  3925. gradient.addColorStop(stop.offset, this.addParentOpacity(parentOpacityProp, stop.color));
  3926. });
  3927. if (this.getAttribute("gradientTransform").hasValue()) {
  3928. var {
  3929. document: document2
  3930. } = this;
  3931. var {
  3932. MAX_VIRTUAL_PIXELS,
  3933. viewPort
  3934. } = document2.screen;
  3935. var [rootView] = viewPort.viewPorts;
  3936. var rect = new RectElement(document2, null);
  3937. rect.attributes.x = new Property(document2, "x", -MAX_VIRTUAL_PIXELS / 3);
  3938. rect.attributes.y = new Property(document2, "y", -MAX_VIRTUAL_PIXELS / 3);
  3939. rect.attributes.width = new Property(document2, "width", MAX_VIRTUAL_PIXELS);
  3940. rect.attributes.height = new Property(document2, "height", MAX_VIRTUAL_PIXELS);
  3941. var group = new GElement(document2, null);
  3942. group.attributes.transform = new Property(document2, "transform", this.getAttribute("gradientTransform").getValue());
  3943. group.children = [rect];
  3944. var patternSvg = new SVGElement(document2, null);
  3945. patternSvg.attributes.x = new Property(document2, "x", 0);
  3946. patternSvg.attributes.y = new Property(document2, "y", 0);
  3947. patternSvg.attributes.width = new Property(document2, "width", rootView.width);
  3948. patternSvg.attributes.height = new Property(document2, "height", rootView.height);
  3949. patternSvg.children = [group];
  3950. var patternCanvas = document2.createCanvas(rootView.width, rootView.height);
  3951. var patternCtx = patternCanvas.getContext("2d");
  3952. patternCtx.fillStyle = gradient;
  3953. patternSvg.render(patternCtx);
  3954. return patternCtx.createPattern(patternCanvas, "no-repeat");
  3955. }
  3956. return gradient;
  3957. }
  3958. inheritStopContainer(stopsContainer) {
  3959. this.attributesToInherit.forEach((attributeToInherit) => {
  3960. if (!this.getAttribute(attributeToInherit).hasValue() && stopsContainer.getAttribute(attributeToInherit).hasValue()) {
  3961. this.getAttribute(attributeToInherit, true).setValue(stopsContainer.getAttribute(attributeToInherit).getValue());
  3962. }
  3963. });
  3964. }
  3965. addParentOpacity(parentOpacityProp, color) {
  3966. if (parentOpacityProp.hasValue()) {
  3967. var colorProp = new Property(this.document, "color", color);
  3968. return colorProp.addOpacity(parentOpacityProp).getColor();
  3969. }
  3970. return color;
  3971. }
  3972. };
  3973. LinearGradientElement = class extends GradientElement {
  3974. constructor(document2, node2, captureTextNodes) {
  3975. super(document2, node2, captureTextNodes);
  3976. this.type = "linearGradient";
  3977. this.attributesToInherit.push("x1", "y1", "x2", "y2");
  3978. }
  3979. getGradient(ctx, element) {
  3980. var isBoundingBoxUnits = this.getGradientUnits() === "objectBoundingBox";
  3981. var boundingBox = isBoundingBoxUnits ? element.getBoundingBox(ctx) : null;
  3982. if (isBoundingBoxUnits && !boundingBox) {
  3983. return null;
  3984. }
  3985. if (!this.getAttribute("x1").hasValue() && !this.getAttribute("y1").hasValue() && !this.getAttribute("x2").hasValue() && !this.getAttribute("y2").hasValue()) {
  3986. this.getAttribute("x1", true).setValue(0);
  3987. this.getAttribute("y1", true).setValue(0);
  3988. this.getAttribute("x2", true).setValue(1);
  3989. this.getAttribute("y2", true).setValue(0);
  3990. }
  3991. var x1 = isBoundingBoxUnits ? boundingBox.x + boundingBox.width * this.getAttribute("x1").getNumber() : this.getAttribute("x1").getPixels("x");
  3992. var y1 = isBoundingBoxUnits ? boundingBox.y + boundingBox.height * this.getAttribute("y1").getNumber() : this.getAttribute("y1").getPixels("y");
  3993. var x2 = isBoundingBoxUnits ? boundingBox.x + boundingBox.width * this.getAttribute("x2").getNumber() : this.getAttribute("x2").getPixels("x");
  3994. var y2 = isBoundingBoxUnits ? boundingBox.y + boundingBox.height * this.getAttribute("y2").getNumber() : this.getAttribute("y2").getPixels("y");
  3995. if (x1 === x2 && y1 === y2) {
  3996. return null;
  3997. }
  3998. return ctx.createLinearGradient(x1, y1, x2, y2);
  3999. }
  4000. };
  4001. RadialGradientElement = class extends GradientElement {
  4002. constructor(document2, node2, captureTextNodes) {
  4003. super(document2, node2, captureTextNodes);
  4004. this.type = "radialGradient";
  4005. this.attributesToInherit.push("cx", "cy", "r", "fx", "fy", "fr");
  4006. }
  4007. getGradient(ctx, element) {
  4008. var isBoundingBoxUnits = this.getGradientUnits() === "objectBoundingBox";
  4009. var boundingBox = element.getBoundingBox(ctx);
  4010. if (isBoundingBoxUnits && !boundingBox) {
  4011. return null;
  4012. }
  4013. if (!this.getAttribute("cx").hasValue()) {
  4014. this.getAttribute("cx", true).setValue("50%");
  4015. }
  4016. if (!this.getAttribute("cy").hasValue()) {
  4017. this.getAttribute("cy", true).setValue("50%");
  4018. }
  4019. if (!this.getAttribute("r").hasValue()) {
  4020. this.getAttribute("r", true).setValue("50%");
  4021. }
  4022. var cx = isBoundingBoxUnits ? boundingBox.x + boundingBox.width * this.getAttribute("cx").getNumber() : this.getAttribute("cx").getPixels("x");
  4023. var cy = isBoundingBoxUnits ? boundingBox.y + boundingBox.height * this.getAttribute("cy").getNumber() : this.getAttribute("cy").getPixels("y");
  4024. var fx = cx;
  4025. var fy = cy;
  4026. if (this.getAttribute("fx").hasValue()) {
  4027. fx = isBoundingBoxUnits ? boundingBox.x + boundingBox.width * this.getAttribute("fx").getNumber() : this.getAttribute("fx").getPixels("x");
  4028. }
  4029. if (this.getAttribute("fy").hasValue()) {
  4030. fy = isBoundingBoxUnits ? boundingBox.y + boundingBox.height * this.getAttribute("fy").getNumber() : this.getAttribute("fy").getPixels("y");
  4031. }
  4032. var r2 = isBoundingBoxUnits ? (boundingBox.width + boundingBox.height) / 2 * this.getAttribute("r").getNumber() : this.getAttribute("r").getPixels();
  4033. var fr = this.getAttribute("fr").getPixels();
  4034. return ctx.createRadialGradient(fx, fy, fr, cx, cy, r2);
  4035. }
  4036. };
  4037. StopElement = class extends Element {
  4038. constructor(document2, node2, captureTextNodes) {
  4039. super(document2, node2, captureTextNodes);
  4040. this.type = "stop";
  4041. var offset = Math.max(0, Math.min(1, this.getAttribute("offset").getNumber()));
  4042. var stopOpacity = this.getStyle("stop-opacity");
  4043. var stopColor = this.getStyle("stop-color", true);
  4044. if (stopColor.getString() === "") {
  4045. stopColor.setValue("#000");
  4046. }
  4047. if (stopOpacity.hasValue()) {
  4048. stopColor = stopColor.addOpacity(stopOpacity);
  4049. }
  4050. this.offset = offset;
  4051. this.color = stopColor.getColor();
  4052. }
  4053. };
  4054. AnimateElement = class extends Element {
  4055. constructor(document2, node2, captureTextNodes) {
  4056. super(document2, node2, captureTextNodes);
  4057. this.type = "animate";
  4058. this.duration = 0;
  4059. this.initialValue = null;
  4060. this.initialUnits = "";
  4061. this.removed = false;
  4062. this.frozen = false;
  4063. document2.screen.animations.push(this);
  4064. this.begin = this.getAttribute("begin").getMilliseconds();
  4065. this.maxDuration = this.begin + this.getAttribute("dur").getMilliseconds();
  4066. this.from = this.getAttribute("from");
  4067. this.to = this.getAttribute("to");
  4068. this.values = new Property(document2, "values", null);
  4069. var valuesAttr = this.getAttribute("values");
  4070. if (valuesAttr.hasValue()) {
  4071. this.values.setValue(valuesAttr.getString().split(";"));
  4072. }
  4073. }
  4074. getProperty() {
  4075. var attributeType = this.getAttribute("attributeType").getString();
  4076. var attributeName = this.getAttribute("attributeName").getString();
  4077. if (attributeType === "CSS") {
  4078. return this.parent.getStyle(attributeName, true);
  4079. }
  4080. return this.parent.getAttribute(attributeName, true);
  4081. }
  4082. calcValue() {
  4083. var {
  4084. initialUnits
  4085. } = this;
  4086. var {
  4087. progress,
  4088. from,
  4089. to
  4090. } = this.getProgress();
  4091. var newValue = from.getNumber() + (to.getNumber() - from.getNumber()) * progress;
  4092. if (initialUnits === "%") {
  4093. newValue *= 100;
  4094. }
  4095. return "".concat(newValue).concat(initialUnits);
  4096. }
  4097. update(delta) {
  4098. var {
  4099. parent
  4100. } = this;
  4101. var prop = this.getProperty();
  4102. if (!this.initialValue) {
  4103. this.initialValue = prop.getString();
  4104. this.initialUnits = prop.getUnits();
  4105. }
  4106. if (this.duration > this.maxDuration) {
  4107. var fill = this.getAttribute("fill").getString("remove");
  4108. if (this.getAttribute("repeatCount").getString() === "indefinite" || this.getAttribute("repeatDur").getString() === "indefinite") {
  4109. this.duration = 0;
  4110. } else if (fill === "freeze" && !this.frozen) {
  4111. this.frozen = true;
  4112. parent.animationFrozen = true;
  4113. parent.animationFrozenValue = prop.getString();
  4114. } else if (fill === "remove" && !this.removed) {
  4115. this.removed = true;
  4116. prop.setValue(parent.animationFrozen ? parent.animationFrozenValue : this.initialValue);
  4117. return true;
  4118. }
  4119. return false;
  4120. }
  4121. this.duration += delta;
  4122. var updated = false;
  4123. if (this.begin < this.duration) {
  4124. var newValue = this.calcValue();
  4125. var typeAttr = this.getAttribute("type");
  4126. if (typeAttr.hasValue()) {
  4127. var type = typeAttr.getString();
  4128. newValue = "".concat(type, "(").concat(newValue, ")");
  4129. }
  4130. prop.setValue(newValue);
  4131. updated = true;
  4132. }
  4133. return updated;
  4134. }
  4135. getProgress() {
  4136. var {
  4137. document: document2,
  4138. values
  4139. } = this;
  4140. var result = {
  4141. progress: (this.duration - this.begin) / (this.maxDuration - this.begin)
  4142. };
  4143. if (values.hasValue()) {
  4144. var p2 = result.progress * (values.getValue().length - 1);
  4145. var lb = Math.floor(p2);
  4146. var ub = Math.ceil(p2);
  4147. result.from = new Property(document2, "from", parseFloat(values.getValue()[lb]));
  4148. result.to = new Property(document2, "to", parseFloat(values.getValue()[ub]));
  4149. result.progress = (p2 - lb) / (ub - lb);
  4150. } else {
  4151. result.from = this.from;
  4152. result.to = this.to;
  4153. }
  4154. return result;
  4155. }
  4156. };
  4157. AnimateColorElement = class extends AnimateElement {
  4158. constructor() {
  4159. super(...arguments);
  4160. this.type = "animateColor";
  4161. }
  4162. calcValue() {
  4163. var {
  4164. progress,
  4165. from,
  4166. to
  4167. } = this.getProgress();
  4168. var colorFrom = new import_rgbcolor.default(from.getColor());
  4169. var colorTo = new import_rgbcolor.default(to.getColor());
  4170. if (colorFrom.ok && colorTo.ok) {
  4171. var r2 = colorFrom.r + (colorTo.r - colorFrom.r) * progress;
  4172. var g = colorFrom.g + (colorTo.g - colorFrom.g) * progress;
  4173. var b = colorFrom.b + (colorTo.b - colorFrom.b) * progress;
  4174. return "rgb(".concat(Math.floor(r2), ", ").concat(Math.floor(g), ", ").concat(Math.floor(b), ")");
  4175. }
  4176. return this.getAttribute("from").getColor();
  4177. }
  4178. };
  4179. AnimateTransformElement = class extends AnimateElement {
  4180. constructor() {
  4181. super(...arguments);
  4182. this.type = "animateTransform";
  4183. }
  4184. calcValue() {
  4185. var {
  4186. progress,
  4187. from,
  4188. to
  4189. } = this.getProgress();
  4190. var transformFrom = toNumbers(from.getString());
  4191. var transformTo = toNumbers(to.getString());
  4192. var newValue = transformFrom.map((from2, i2) => {
  4193. var to2 = transformTo[i2];
  4194. return from2 + (to2 - from2) * progress;
  4195. }).join(" ");
  4196. return newValue;
  4197. }
  4198. };
  4199. FontElement = class extends Element {
  4200. constructor(document2, node2, captureTextNodes) {
  4201. super(document2, node2, captureTextNodes);
  4202. this.type = "font";
  4203. this.glyphs = /* @__PURE__ */ Object.create(null);
  4204. this.horizAdvX = this.getAttribute("horiz-adv-x").getNumber();
  4205. var {
  4206. definitions
  4207. } = document2;
  4208. var {
  4209. children
  4210. } = this;
  4211. for (var child of children) {
  4212. switch (child.type) {
  4213. case "font-face": {
  4214. this.fontFace = child;
  4215. var fontFamilyStyle = child.getStyle("font-family");
  4216. if (fontFamilyStyle.hasValue()) {
  4217. definitions[fontFamilyStyle.getString()] = this;
  4218. }
  4219. break;
  4220. }
  4221. case "missing-glyph":
  4222. this.missingGlyph = child;
  4223. break;
  4224. case "glyph": {
  4225. var glyph = child;
  4226. if (glyph.arabicForm) {
  4227. this.isRTL = true;
  4228. this.isArabic = true;
  4229. if (typeof this.glyphs[glyph.unicode] === "undefined") {
  4230. this.glyphs[glyph.unicode] = /* @__PURE__ */ Object.create(null);
  4231. }
  4232. this.glyphs[glyph.unicode][glyph.arabicForm] = glyph;
  4233. } else {
  4234. this.glyphs[glyph.unicode] = glyph;
  4235. }
  4236. break;
  4237. }
  4238. }
  4239. }
  4240. }
  4241. render() {
  4242. }
  4243. };
  4244. FontFaceElement = class extends Element {
  4245. constructor(document2, node2, captureTextNodes) {
  4246. super(document2, node2, captureTextNodes);
  4247. this.type = "font-face";
  4248. this.ascent = this.getAttribute("ascent").getNumber();
  4249. this.descent = this.getAttribute("descent").getNumber();
  4250. this.unitsPerEm = this.getAttribute("units-per-em").getNumber();
  4251. }
  4252. };
  4253. MissingGlyphElement = class extends PathElement {
  4254. constructor() {
  4255. super(...arguments);
  4256. this.type = "missing-glyph";
  4257. this.horizAdvX = 0;
  4258. }
  4259. };
  4260. TRefElement = class extends TextElement {
  4261. constructor() {
  4262. super(...arguments);
  4263. this.type = "tref";
  4264. }
  4265. getText() {
  4266. var element = this.getHrefAttribute().getDefinition();
  4267. if (element) {
  4268. var firstChild = element.children[0];
  4269. if (firstChild) {
  4270. return firstChild.getText();
  4271. }
  4272. }
  4273. return "";
  4274. }
  4275. };
  4276. AElement = class extends TextElement {
  4277. constructor(document2, node2, captureTextNodes) {
  4278. super(document2, node2, captureTextNodes);
  4279. this.type = "a";
  4280. var {
  4281. childNodes
  4282. } = node2;
  4283. var firstChild = childNodes[0];
  4284. var hasText = childNodes.length > 0 && Array.from(childNodes).every((node3) => node3.nodeType === 3);
  4285. this.hasText = hasText;
  4286. this.text = hasText ? this.getTextFromNode(firstChild) : "";
  4287. }
  4288. getText() {
  4289. return this.text;
  4290. }
  4291. renderChildren(ctx) {
  4292. if (this.hasText) {
  4293. super.renderChildren(ctx);
  4294. var {
  4295. document: document2,
  4296. x,
  4297. y: y2
  4298. } = this;
  4299. var {
  4300. mouse
  4301. } = document2.screen;
  4302. var fontSize = new Property(document2, "fontSize", Font.parse(document2.ctx.font).fontSize);
  4303. if (mouse.isWorking()) {
  4304. mouse.checkBoundingBox(this, new BoundingBox(x, y2 - fontSize.getPixels("y"), x + this.measureText(ctx), y2));
  4305. }
  4306. } else if (this.children.length > 0) {
  4307. var g = new GElement(this.document, null);
  4308. g.children = this.children;
  4309. g.parent = this;
  4310. g.render(ctx);
  4311. }
  4312. }
  4313. onClick() {
  4314. var {
  4315. window: window2
  4316. } = this.document;
  4317. if (window2) {
  4318. window2.open(this.getHrefAttribute().getString());
  4319. }
  4320. }
  4321. onMouseMove() {
  4322. var ctx = this.document.ctx;
  4323. ctx.canvas.style.cursor = "pointer";
  4324. }
  4325. };
  4326. TextPathElement = class extends TextElement {
  4327. constructor(document2, node2, captureTextNodes) {
  4328. super(document2, node2, captureTextNodes);
  4329. this.type = "textPath";
  4330. this.textWidth = 0;
  4331. this.textHeight = 0;
  4332. this.pathLength = -1;
  4333. this.glyphInfo = null;
  4334. this.letterSpacingCache = [];
  4335. this.measuresCache = /* @__PURE__ */ new Map([["", 0]]);
  4336. var pathElement = this.getHrefAttribute().getDefinition();
  4337. this.text = this.getTextFromNode();
  4338. this.dataArray = this.parsePathData(pathElement);
  4339. }
  4340. getText() {
  4341. return this.text;
  4342. }
  4343. path(ctx) {
  4344. var {
  4345. dataArray
  4346. } = this;
  4347. if (ctx) {
  4348. ctx.beginPath();
  4349. }
  4350. dataArray.forEach((_ref) => {
  4351. var {
  4352. type,
  4353. points
  4354. } = _ref;
  4355. switch (type) {
  4356. case PathParser.LINE_TO:
  4357. if (ctx) {
  4358. ctx.lineTo(points[0], points[1]);
  4359. }
  4360. break;
  4361. case PathParser.MOVE_TO:
  4362. if (ctx) {
  4363. ctx.moveTo(points[0], points[1]);
  4364. }
  4365. break;
  4366. case PathParser.CURVE_TO:
  4367. if (ctx) {
  4368. ctx.bezierCurveTo(points[0], points[1], points[2], points[3], points[4], points[5]);
  4369. }
  4370. break;
  4371. case PathParser.QUAD_TO:
  4372. if (ctx) {
  4373. ctx.quadraticCurveTo(points[0], points[1], points[2], points[3]);
  4374. }
  4375. break;
  4376. case PathParser.ARC: {
  4377. var [cx, cy, rx, ry, theta, dTheta, psi, fs] = points;
  4378. var r2 = rx > ry ? rx : ry;
  4379. var scaleX = rx > ry ? 1 : rx / ry;
  4380. var scaleY = rx > ry ? ry / rx : 1;
  4381. if (ctx) {
  4382. ctx.translate(cx, cy);
  4383. ctx.rotate(psi);
  4384. ctx.scale(scaleX, scaleY);
  4385. ctx.arc(0, 0, r2, theta, theta + dTheta, Boolean(1 - fs));
  4386. ctx.scale(1 / scaleX, 1 / scaleY);
  4387. ctx.rotate(-psi);
  4388. ctx.translate(-cx, -cy);
  4389. }
  4390. break;
  4391. }
  4392. case PathParser.CLOSE_PATH:
  4393. if (ctx) {
  4394. ctx.closePath();
  4395. }
  4396. break;
  4397. }
  4398. });
  4399. }
  4400. renderChildren(ctx) {
  4401. this.setTextData(ctx);
  4402. ctx.save();
  4403. var textDecoration = this.parent.getStyle("text-decoration").getString();
  4404. var fontSize = this.getFontSize();
  4405. var {
  4406. glyphInfo
  4407. } = this;
  4408. var fill = ctx.fillStyle;
  4409. if (textDecoration === "underline") {
  4410. ctx.beginPath();
  4411. }
  4412. glyphInfo.forEach((glyph, i2) => {
  4413. var {
  4414. p0,
  4415. p1,
  4416. rotation,
  4417. text: partialText
  4418. } = glyph;
  4419. ctx.save();
  4420. ctx.translate(p0.x, p0.y);
  4421. ctx.rotate(rotation);
  4422. if (ctx.fillStyle) {
  4423. ctx.fillText(partialText, 0, 0);
  4424. }
  4425. if (ctx.strokeStyle) {
  4426. ctx.strokeText(partialText, 0, 0);
  4427. }
  4428. ctx.restore();
  4429. if (textDecoration === "underline") {
  4430. if (i2 === 0) {
  4431. ctx.moveTo(p0.x, p0.y + fontSize / 8);
  4432. }
  4433. ctx.lineTo(p1.x, p1.y + fontSize / 5);
  4434. }
  4435. });
  4436. if (textDecoration === "underline") {
  4437. ctx.lineWidth = fontSize / 20;
  4438. ctx.strokeStyle = fill;
  4439. ctx.stroke();
  4440. ctx.closePath();
  4441. }
  4442. ctx.restore();
  4443. }
  4444. getLetterSpacingAt() {
  4445. var idx = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
  4446. return this.letterSpacingCache[idx] || 0;
  4447. }
  4448. findSegmentToFitChar(ctx, anchor, textFullWidth, fullPathWidth, spacesNumber, inputOffset, dy, c3, charI) {
  4449. var offset = inputOffset;
  4450. var glyphWidth = this.measureText(ctx, c3);
  4451. if (c3 === " " && anchor === "justify" && textFullWidth < fullPathWidth) {
  4452. glyphWidth += (fullPathWidth - textFullWidth) / spacesNumber;
  4453. }
  4454. if (charI > -1) {
  4455. offset += this.getLetterSpacingAt(charI);
  4456. }
  4457. var splineStep = this.textHeight / 20;
  4458. var p0 = this.getEquidistantPointOnPath(offset, splineStep, 0);
  4459. var p1 = this.getEquidistantPointOnPath(offset + glyphWidth, splineStep, 0);
  4460. var segment = {
  4461. p0,
  4462. p1
  4463. };
  4464. var rotation = p0 && p1 ? Math.atan2(p1.y - p0.y, p1.x - p0.x) : 0;
  4465. if (dy) {
  4466. var dyX = Math.cos(Math.PI / 2 + rotation) * dy;
  4467. var dyY = Math.cos(-rotation) * dy;
  4468. segment.p0 = _objectSpread$2(_objectSpread$2({}, p0), {}, {
  4469. x: p0.x + dyX,
  4470. y: p0.y + dyY
  4471. });
  4472. segment.p1 = _objectSpread$2(_objectSpread$2({}, p1), {}, {
  4473. x: p1.x + dyX,
  4474. y: p1.y + dyY
  4475. });
  4476. }
  4477. offset += glyphWidth;
  4478. return {
  4479. offset,
  4480. segment,
  4481. rotation
  4482. };
  4483. }
  4484. measureText(ctx, text) {
  4485. var {
  4486. measuresCache
  4487. } = this;
  4488. var targetText = text || this.getText();
  4489. if (measuresCache.has(targetText)) {
  4490. return measuresCache.get(targetText);
  4491. }
  4492. var measure = this.measureTargetText(ctx, targetText);
  4493. measuresCache.set(targetText, measure);
  4494. return measure;
  4495. }
  4496. // This method supposes what all custom fonts already loaded.
  4497. // If some font will be loaded after this method call, <textPath> will not be rendered correctly.
  4498. // You need to call this method manually to update glyphs cache.
  4499. setTextData(ctx) {
  4500. if (this.glyphInfo) {
  4501. return;
  4502. }
  4503. var renderText = this.getText();
  4504. var chars = renderText.split("");
  4505. var spacesNumber = renderText.split(" ").length - 1;
  4506. var dx = this.parent.getAttribute("dx").split().map((_2) => _2.getPixels("x"));
  4507. var dy = this.parent.getAttribute("dy").getPixels("y");
  4508. var anchor = this.parent.getStyle("text-anchor").getString("start");
  4509. var thisSpacing = this.getStyle("letter-spacing");
  4510. var parentSpacing = this.parent.getStyle("letter-spacing");
  4511. var letterSpacing = 0;
  4512. if (!thisSpacing.hasValue() || thisSpacing.getValue() === "inherit") {
  4513. letterSpacing = parentSpacing.getPixels();
  4514. } else if (thisSpacing.hasValue()) {
  4515. if (thisSpacing.getValue() !== "initial" && thisSpacing.getValue() !== "unset") {
  4516. letterSpacing = thisSpacing.getPixels();
  4517. }
  4518. }
  4519. var letterSpacingCache = [];
  4520. var textLen = renderText.length;
  4521. this.letterSpacingCache = letterSpacingCache;
  4522. for (var i2 = 0; i2 < textLen; i2++) {
  4523. letterSpacingCache.push(typeof dx[i2] !== "undefined" ? dx[i2] : letterSpacing);
  4524. }
  4525. var dxSum = letterSpacingCache.reduce((acc, cur, i3) => i3 === 0 ? 0 : acc + cur || 0, 0);
  4526. var textWidth = this.measureText(ctx);
  4527. var textFullWidth = Math.max(textWidth + dxSum, 0);
  4528. this.textWidth = textWidth;
  4529. this.textHeight = this.getFontSize();
  4530. this.glyphInfo = [];
  4531. var fullPathWidth = this.getPathLength();
  4532. var startOffset = this.getStyle("startOffset").getNumber(0) * fullPathWidth;
  4533. var offset = 0;
  4534. if (anchor === "middle" || anchor === "center") {
  4535. offset = -textFullWidth / 2;
  4536. }
  4537. if (anchor === "end" || anchor === "right") {
  4538. offset = -textFullWidth;
  4539. }
  4540. offset += startOffset;
  4541. chars.forEach((char, i3) => {
  4542. var {
  4543. offset: nextOffset,
  4544. segment,
  4545. rotation
  4546. } = this.findSegmentToFitChar(ctx, anchor, textFullWidth, fullPathWidth, spacesNumber, offset, dy, char, i3);
  4547. offset = nextOffset;
  4548. if (!segment.p0 || !segment.p1) {
  4549. return;
  4550. }
  4551. this.glyphInfo.push({
  4552. // transposeX: midpoint.x,
  4553. // transposeY: midpoint.y,
  4554. text: chars[i3],
  4555. p0: segment.p0,
  4556. p1: segment.p1,
  4557. rotation
  4558. });
  4559. });
  4560. }
  4561. parsePathData(path) {
  4562. this.pathLength = -1;
  4563. if (!path) {
  4564. return [];
  4565. }
  4566. var pathCommands = [];
  4567. var {
  4568. pathParser
  4569. } = path;
  4570. pathParser.reset();
  4571. while (!pathParser.isEnd()) {
  4572. var {
  4573. current
  4574. } = pathParser;
  4575. var startX = current ? current.x : 0;
  4576. var startY = current ? current.y : 0;
  4577. var command = pathParser.next();
  4578. var nextCommandType = command.type;
  4579. var points = [];
  4580. switch (command.type) {
  4581. case PathParser.MOVE_TO:
  4582. this.pathM(pathParser, points);
  4583. break;
  4584. case PathParser.LINE_TO:
  4585. nextCommandType = this.pathL(pathParser, points);
  4586. break;
  4587. case PathParser.HORIZ_LINE_TO:
  4588. nextCommandType = this.pathH(pathParser, points);
  4589. break;
  4590. case PathParser.VERT_LINE_TO:
  4591. nextCommandType = this.pathV(pathParser, points);
  4592. break;
  4593. case PathParser.CURVE_TO:
  4594. this.pathC(pathParser, points);
  4595. break;
  4596. case PathParser.SMOOTH_CURVE_TO:
  4597. nextCommandType = this.pathS(pathParser, points);
  4598. break;
  4599. case PathParser.QUAD_TO:
  4600. this.pathQ(pathParser, points);
  4601. break;
  4602. case PathParser.SMOOTH_QUAD_TO:
  4603. nextCommandType = this.pathT(pathParser, points);
  4604. break;
  4605. case PathParser.ARC:
  4606. points = this.pathA(pathParser);
  4607. break;
  4608. case PathParser.CLOSE_PATH:
  4609. PathElement.pathZ(pathParser);
  4610. break;
  4611. }
  4612. if (command.type !== PathParser.CLOSE_PATH) {
  4613. pathCommands.push({
  4614. type: nextCommandType,
  4615. points,
  4616. start: {
  4617. x: startX,
  4618. y: startY
  4619. },
  4620. pathLength: this.calcLength(startX, startY, nextCommandType, points)
  4621. });
  4622. } else {
  4623. pathCommands.push({
  4624. type: PathParser.CLOSE_PATH,
  4625. points: [],
  4626. pathLength: 0
  4627. });
  4628. }
  4629. }
  4630. return pathCommands;
  4631. }
  4632. pathM(pathParser, points) {
  4633. var {
  4634. x,
  4635. y: y2
  4636. } = PathElement.pathM(pathParser).point;
  4637. points.push(x, y2);
  4638. }
  4639. pathL(pathParser, points) {
  4640. var {
  4641. x,
  4642. y: y2
  4643. } = PathElement.pathL(pathParser).point;
  4644. points.push(x, y2);
  4645. return PathParser.LINE_TO;
  4646. }
  4647. pathH(pathParser, points) {
  4648. var {
  4649. x,
  4650. y: y2
  4651. } = PathElement.pathH(pathParser).point;
  4652. points.push(x, y2);
  4653. return PathParser.LINE_TO;
  4654. }
  4655. pathV(pathParser, points) {
  4656. var {
  4657. x,
  4658. y: y2
  4659. } = PathElement.pathV(pathParser).point;
  4660. points.push(x, y2);
  4661. return PathParser.LINE_TO;
  4662. }
  4663. pathC(pathParser, points) {
  4664. var {
  4665. point,
  4666. controlPoint,
  4667. currentPoint
  4668. } = PathElement.pathC(pathParser);
  4669. points.push(point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  4670. }
  4671. pathS(pathParser, points) {
  4672. var {
  4673. point,
  4674. controlPoint,
  4675. currentPoint
  4676. } = PathElement.pathS(pathParser);
  4677. points.push(point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  4678. return PathParser.CURVE_TO;
  4679. }
  4680. pathQ(pathParser, points) {
  4681. var {
  4682. controlPoint,
  4683. currentPoint
  4684. } = PathElement.pathQ(pathParser);
  4685. points.push(controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  4686. }
  4687. pathT(pathParser, points) {
  4688. var {
  4689. controlPoint,
  4690. currentPoint
  4691. } = PathElement.pathT(pathParser);
  4692. points.push(controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
  4693. return PathParser.QUAD_TO;
  4694. }
  4695. pathA(pathParser) {
  4696. var {
  4697. rX,
  4698. rY,
  4699. sweepFlag,
  4700. xAxisRotation,
  4701. centp,
  4702. a1,
  4703. ad
  4704. } = PathElement.pathA(pathParser);
  4705. if (sweepFlag === 0 && ad > 0) {
  4706. ad -= 2 * Math.PI;
  4707. }
  4708. if (sweepFlag === 1 && ad < 0) {
  4709. ad += 2 * Math.PI;
  4710. }
  4711. return [centp.x, centp.y, rX, rY, a1, ad, xAxisRotation, sweepFlag];
  4712. }
  4713. calcLength(x, y2, commandType, points) {
  4714. var len = 0;
  4715. var p1 = null;
  4716. var p2 = null;
  4717. var t2 = 0;
  4718. switch (commandType) {
  4719. case PathParser.LINE_TO:
  4720. return this.getLineLength(x, y2, points[0], points[1]);
  4721. case PathParser.CURVE_TO:
  4722. len = 0;
  4723. p1 = this.getPointOnCubicBezier(0, x, y2, points[0], points[1], points[2], points[3], points[4], points[5]);
  4724. for (t2 = 0.01; t2 <= 1; t2 += 0.01) {
  4725. p2 = this.getPointOnCubicBezier(t2, x, y2, points[0], points[1], points[2], points[3], points[4], points[5]);
  4726. len += this.getLineLength(p1.x, p1.y, p2.x, p2.y);
  4727. p1 = p2;
  4728. }
  4729. return len;
  4730. case PathParser.QUAD_TO:
  4731. len = 0;
  4732. p1 = this.getPointOnQuadraticBezier(0, x, y2, points[0], points[1], points[2], points[3]);
  4733. for (t2 = 0.01; t2 <= 1; t2 += 0.01) {
  4734. p2 = this.getPointOnQuadraticBezier(t2, x, y2, points[0], points[1], points[2], points[3]);
  4735. len += this.getLineLength(p1.x, p1.y, p2.x, p2.y);
  4736. p1 = p2;
  4737. }
  4738. return len;
  4739. case PathParser.ARC: {
  4740. len = 0;
  4741. var start = points[4];
  4742. var dTheta = points[5];
  4743. var end = points[4] + dTheta;
  4744. var inc = Math.PI / 180;
  4745. if (Math.abs(start - end) < inc) {
  4746. inc = Math.abs(start - end);
  4747. }
  4748. p1 = this.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], start, 0);
  4749. if (dTheta < 0) {
  4750. for (t2 = start - inc; t2 > end; t2 -= inc) {
  4751. p2 = this.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], t2, 0);
  4752. len += this.getLineLength(p1.x, p1.y, p2.x, p2.y);
  4753. p1 = p2;
  4754. }
  4755. } else {
  4756. for (t2 = start + inc; t2 < end; t2 += inc) {
  4757. p2 = this.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], t2, 0);
  4758. len += this.getLineLength(p1.x, p1.y, p2.x, p2.y);
  4759. p1 = p2;
  4760. }
  4761. }
  4762. p2 = this.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], end, 0);
  4763. len += this.getLineLength(p1.x, p1.y, p2.x, p2.y);
  4764. return len;
  4765. }
  4766. }
  4767. return 0;
  4768. }
  4769. getPointOnLine(dist, p1x, p1y, p2x, p2y) {
  4770. var fromX = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : p1x;
  4771. var fromY = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : p1y;
  4772. var m3 = (p2y - p1y) / (p2x - p1x + PSEUDO_ZERO);
  4773. var run = Math.sqrt(dist * dist / (1 + m3 * m3));
  4774. if (p2x < p1x) {
  4775. run *= -1;
  4776. }
  4777. var rise = m3 * run;
  4778. var pt = null;
  4779. if (p2x === p1x) {
  4780. pt = {
  4781. x: fromX,
  4782. y: fromY + rise
  4783. };
  4784. } else if ((fromY - p1y) / (fromX - p1x + PSEUDO_ZERO) === m3) {
  4785. pt = {
  4786. x: fromX + run,
  4787. y: fromY + rise
  4788. };
  4789. } else {
  4790. var ix = 0;
  4791. var iy = 0;
  4792. var len = this.getLineLength(p1x, p1y, p2x, p2y);
  4793. if (len < PSEUDO_ZERO) {
  4794. return null;
  4795. }
  4796. var u2 = (fromX - p1x) * (p2x - p1x) + (fromY - p1y) * (p2y - p1y);
  4797. u2 /= len * len;
  4798. ix = p1x + u2 * (p2x - p1x);
  4799. iy = p1y + u2 * (p2y - p1y);
  4800. var pRise = this.getLineLength(fromX, fromY, ix, iy);
  4801. var pRun = Math.sqrt(dist * dist - pRise * pRise);
  4802. run = Math.sqrt(pRun * pRun / (1 + m3 * m3));
  4803. if (p2x < p1x) {
  4804. run *= -1;
  4805. }
  4806. rise = m3 * run;
  4807. pt = {
  4808. x: ix + run,
  4809. y: iy + rise
  4810. };
  4811. }
  4812. return pt;
  4813. }
  4814. getPointOnPath(distance) {
  4815. var fullLen = this.getPathLength();
  4816. var cumulativePathLength = 0;
  4817. var p2 = null;
  4818. if (distance < -5e-5 || distance - 5e-5 > fullLen) {
  4819. return null;
  4820. }
  4821. var {
  4822. dataArray
  4823. } = this;
  4824. for (var command of dataArray) {
  4825. if (command && (command.pathLength < 5e-5 || cumulativePathLength + command.pathLength + 5e-5 < distance)) {
  4826. cumulativePathLength += command.pathLength;
  4827. continue;
  4828. }
  4829. var delta = distance - cumulativePathLength;
  4830. var currentT = 0;
  4831. switch (command.type) {
  4832. case PathParser.LINE_TO:
  4833. p2 = this.getPointOnLine(delta, command.start.x, command.start.y, command.points[0], command.points[1], command.start.x, command.start.y);
  4834. break;
  4835. case PathParser.ARC: {
  4836. var start = command.points[4];
  4837. var dTheta = command.points[5];
  4838. var end = command.points[4] + dTheta;
  4839. currentT = start + delta / command.pathLength * dTheta;
  4840. if (dTheta < 0 && currentT < end || dTheta >= 0 && currentT > end) {
  4841. break;
  4842. }
  4843. p2 = this.getPointOnEllipticalArc(command.points[0], command.points[1], command.points[2], command.points[3], currentT, command.points[6]);
  4844. break;
  4845. }
  4846. case PathParser.CURVE_TO:
  4847. currentT = delta / command.pathLength;
  4848. if (currentT > 1) {
  4849. currentT = 1;
  4850. }
  4851. p2 = this.getPointOnCubicBezier(currentT, command.start.x, command.start.y, command.points[0], command.points[1], command.points[2], command.points[3], command.points[4], command.points[5]);
  4852. break;
  4853. case PathParser.QUAD_TO:
  4854. currentT = delta / command.pathLength;
  4855. if (currentT > 1) {
  4856. currentT = 1;
  4857. }
  4858. p2 = this.getPointOnQuadraticBezier(currentT, command.start.x, command.start.y, command.points[0], command.points[1], command.points[2], command.points[3]);
  4859. break;
  4860. }
  4861. if (p2) {
  4862. return p2;
  4863. }
  4864. break;
  4865. }
  4866. return null;
  4867. }
  4868. getLineLength(x1, y1, x2, y2) {
  4869. return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  4870. }
  4871. getPathLength() {
  4872. if (this.pathLength === -1) {
  4873. this.pathLength = this.dataArray.reduce((length, command) => command.pathLength > 0 ? length + command.pathLength : length, 0);
  4874. }
  4875. return this.pathLength;
  4876. }
  4877. getPointOnCubicBezier(pct, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y) {
  4878. var x = p4x * CB1(pct) + p3x * CB2(pct) + p2x * CB3(pct) + p1x * CB4(pct);
  4879. var y2 = p4y * CB1(pct) + p3y * CB2(pct) + p2y * CB3(pct) + p1y * CB4(pct);
  4880. return {
  4881. x,
  4882. y: y2
  4883. };
  4884. }
  4885. getPointOnQuadraticBezier(pct, p1x, p1y, p2x, p2y, p3x, p3y) {
  4886. var x = p3x * QB1(pct) + p2x * QB2(pct) + p1x * QB3(pct);
  4887. var y2 = p3y * QB1(pct) + p2y * QB2(pct) + p1y * QB3(pct);
  4888. return {
  4889. x,
  4890. y: y2
  4891. };
  4892. }
  4893. getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi) {
  4894. var cosPsi = Math.cos(psi);
  4895. var sinPsi = Math.sin(psi);
  4896. var pt = {
  4897. x: rx * Math.cos(theta),
  4898. y: ry * Math.sin(theta)
  4899. };
  4900. return {
  4901. x: cx + (pt.x * cosPsi - pt.y * sinPsi),
  4902. y: cy + (pt.x * sinPsi + pt.y * cosPsi)
  4903. };
  4904. }
  4905. // TODO need some optimisations. possibly build cache only for curved segments?
  4906. buildEquidistantCache(inputStep, inputPrecision) {
  4907. var fullLen = this.getPathLength();
  4908. var precision = inputPrecision || 0.25;
  4909. var step = inputStep || fullLen / 100;
  4910. if (!this.equidistantCache || this.equidistantCache.step !== step || this.equidistantCache.precision !== precision) {
  4911. this.equidistantCache = {
  4912. step,
  4913. precision,
  4914. points: []
  4915. };
  4916. var s2 = 0;
  4917. for (var l2 = 0; l2 <= fullLen; l2 += precision) {
  4918. var p0 = this.getPointOnPath(l2);
  4919. var p1 = this.getPointOnPath(l2 + precision);
  4920. if (!p0 || !p1) {
  4921. continue;
  4922. }
  4923. s2 += this.getLineLength(p0.x, p0.y, p1.x, p1.y);
  4924. if (s2 >= step) {
  4925. this.equidistantCache.points.push({
  4926. x: p0.x,
  4927. y: p0.y,
  4928. distance: l2
  4929. });
  4930. s2 -= step;
  4931. }
  4932. }
  4933. }
  4934. }
  4935. getEquidistantPointOnPath(targetDistance, step, precision) {
  4936. this.buildEquidistantCache(step, precision);
  4937. if (targetDistance < 0 || targetDistance - this.getPathLength() > 5e-5) {
  4938. return null;
  4939. }
  4940. var idx = Math.round(targetDistance / this.getPathLength() * (this.equidistantCache.points.length - 1));
  4941. return this.equidistantCache.points[idx] || null;
  4942. }
  4943. };
  4944. dataUriRegex = /^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,(.*)$/i;
  4945. ImageElement = class extends RenderedElement {
  4946. constructor(document2, node2, captureTextNodes) {
  4947. super(document2, node2, captureTextNodes);
  4948. this.type = "image";
  4949. this.loaded = false;
  4950. var href = this.getHrefAttribute().getString();
  4951. if (!href) {
  4952. return;
  4953. }
  4954. var isSvg = href.endsWith(".svg") || /^\s*data:image\/svg\+xml/i.test(href);
  4955. document2.images.push(this);
  4956. if (!isSvg) {
  4957. void this.loadImage(href);
  4958. } else {
  4959. void this.loadSvg(href);
  4960. }
  4961. this.isSvg = isSvg;
  4962. }
  4963. loadImage(href) {
  4964. var _this = this;
  4965. return _asyncToGenerator(function* () {
  4966. try {
  4967. var image = yield _this.document.createImage(href);
  4968. _this.image = image;
  4969. } catch (err) {
  4970. console.error('Error while loading image "'.concat(href, '":'), err);
  4971. }
  4972. _this.loaded = true;
  4973. })();
  4974. }
  4975. loadSvg(href) {
  4976. var _this2 = this;
  4977. return _asyncToGenerator(function* () {
  4978. var match = dataUriRegex.exec(href);
  4979. if (match) {
  4980. var data = match[5];
  4981. if (match[4] === "base64") {
  4982. _this2.image = atob(data);
  4983. } else {
  4984. _this2.image = decodeURIComponent(data);
  4985. }
  4986. } else {
  4987. try {
  4988. var response = yield _this2.document.fetch(href);
  4989. var svg = yield response.text();
  4990. _this2.image = svg;
  4991. } catch (err) {
  4992. console.error('Error while loading image "'.concat(href, '":'), err);
  4993. }
  4994. }
  4995. _this2.loaded = true;
  4996. })();
  4997. }
  4998. renderChildren(ctx) {
  4999. var {
  5000. document: document2,
  5001. image,
  5002. loaded
  5003. } = this;
  5004. var x = this.getAttribute("x").getPixels("x");
  5005. var y2 = this.getAttribute("y").getPixels("y");
  5006. var width = this.getStyle("width").getPixels("x");
  5007. var height = this.getStyle("height").getPixels("y");
  5008. if (!loaded || !image || !width || !height) {
  5009. return;
  5010. }
  5011. ctx.save();
  5012. ctx.translate(x, y2);
  5013. if (this.isSvg) {
  5014. var subDocument = document2.canvg.forkString(ctx, this.image, {
  5015. ignoreMouse: true,
  5016. ignoreAnimation: true,
  5017. ignoreDimensions: true,
  5018. ignoreClear: true,
  5019. offsetX: 0,
  5020. offsetY: 0,
  5021. scaleWidth: width,
  5022. scaleHeight: height
  5023. });
  5024. subDocument.document.documentElement.parent = this;
  5025. void subDocument.render();
  5026. } else {
  5027. var _image = this.image;
  5028. document2.setViewBox({
  5029. ctx,
  5030. aspectRatio: this.getAttribute("preserveAspectRatio").getString(),
  5031. width,
  5032. desiredWidth: _image.width,
  5033. height,
  5034. desiredHeight: _image.height
  5035. });
  5036. if (this.loaded) {
  5037. if (typeof _image.complete === "undefined" || _image.complete) {
  5038. ctx.drawImage(_image, 0, 0);
  5039. }
  5040. }
  5041. }
  5042. ctx.restore();
  5043. }
  5044. getBoundingBox() {
  5045. var x = this.getAttribute("x").getPixels("x");
  5046. var y2 = this.getAttribute("y").getPixels("y");
  5047. var width = this.getStyle("width").getPixels("x");
  5048. var height = this.getStyle("height").getPixels("y");
  5049. return new BoundingBox(x, y2, x + width, y2 + height);
  5050. }
  5051. };
  5052. SymbolElement = class extends RenderedElement {
  5053. constructor() {
  5054. super(...arguments);
  5055. this.type = "symbol";
  5056. }
  5057. render(_2) {
  5058. }
  5059. };
  5060. SVGFontLoader = class {
  5061. constructor(document2) {
  5062. this.document = document2;
  5063. this.loaded = false;
  5064. document2.fonts.push(this);
  5065. }
  5066. load(fontFamily, url) {
  5067. var _this = this;
  5068. return _asyncToGenerator(function* () {
  5069. try {
  5070. var {
  5071. document: document2
  5072. } = _this;
  5073. var svgDocument = yield document2.canvg.parser.load(url);
  5074. var fonts = svgDocument.getElementsByTagName("font");
  5075. Array.from(fonts).forEach((fontNode) => {
  5076. var font = document2.createElement(fontNode);
  5077. document2.definitions[fontFamily] = font;
  5078. });
  5079. } catch (err) {
  5080. console.error('Error while loading font "'.concat(url, '":'), err);
  5081. }
  5082. _this.loaded = true;
  5083. })();
  5084. }
  5085. };
  5086. StyleElement = class extends Element {
  5087. constructor(document2, node2, captureTextNodes) {
  5088. super(document2, node2, captureTextNodes);
  5089. this.type = "style";
  5090. var css = compressSpaces(
  5091. Array.from(node2.childNodes).map((_2) => _2.textContent).join("").replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm, "").replace(/@import.*;/g, "")
  5092. // remove imports
  5093. );
  5094. var cssDefs = css.split("}");
  5095. cssDefs.forEach((_2) => {
  5096. var def = _2.trim();
  5097. if (!def) {
  5098. return;
  5099. }
  5100. var cssParts = def.split("{");
  5101. var cssClasses = cssParts[0].split(",");
  5102. var cssProps = cssParts[1].split(";");
  5103. cssClasses.forEach((_3) => {
  5104. var cssClass = _3.trim();
  5105. if (!cssClass) {
  5106. return;
  5107. }
  5108. var props = document2.styles[cssClass] || {};
  5109. cssProps.forEach((cssProp) => {
  5110. var prop = cssProp.indexOf(":");
  5111. var name = cssProp.substr(0, prop).trim();
  5112. var value = cssProp.substr(prop + 1, cssProp.length - prop).trim();
  5113. if (name && value) {
  5114. props[name] = new Property(document2, name, value);
  5115. }
  5116. });
  5117. document2.styles[cssClass] = props;
  5118. document2.stylesSpecificity[cssClass] = getSelectorSpecificity(cssClass);
  5119. if (cssClass === "@font-face") {
  5120. var fontFamily = props["font-family"].getString().replace(/"|'/g, "");
  5121. var srcs = props.src.getString().split(",");
  5122. srcs.forEach((src) => {
  5123. if (src.indexOf('format("svg")') > 0) {
  5124. var url = parseExternalUrl(src);
  5125. if (url) {
  5126. void new SVGFontLoader(document2).load(fontFamily, url);
  5127. }
  5128. }
  5129. });
  5130. }
  5131. });
  5132. });
  5133. }
  5134. };
  5135. StyleElement.parseExternalUrl = parseExternalUrl;
  5136. UseElement = class extends RenderedElement {
  5137. constructor() {
  5138. super(...arguments);
  5139. this.type = "use";
  5140. }
  5141. setContext(ctx) {
  5142. super.setContext(ctx);
  5143. var xAttr = this.getAttribute("x");
  5144. var yAttr = this.getAttribute("y");
  5145. if (xAttr.hasValue()) {
  5146. ctx.translate(xAttr.getPixels("x"), 0);
  5147. }
  5148. if (yAttr.hasValue()) {
  5149. ctx.translate(0, yAttr.getPixels("y"));
  5150. }
  5151. }
  5152. path(ctx) {
  5153. var {
  5154. element
  5155. } = this;
  5156. if (element) {
  5157. element.path(ctx);
  5158. }
  5159. }
  5160. renderChildren(ctx) {
  5161. var {
  5162. document: document2,
  5163. element
  5164. } = this;
  5165. if (element) {
  5166. var tempSvg = element;
  5167. if (element.type === "symbol") {
  5168. tempSvg = new SVGElement(document2, null);
  5169. tempSvg.attributes.viewBox = new Property(document2, "viewBox", element.getAttribute("viewBox").getString());
  5170. tempSvg.attributes.preserveAspectRatio = new Property(document2, "preserveAspectRatio", element.getAttribute("preserveAspectRatio").getString());
  5171. tempSvg.attributes.overflow = new Property(document2, "overflow", element.getAttribute("overflow").getString());
  5172. tempSvg.children = element.children;
  5173. element.styles.opacity = new Property(document2, "opacity", this.calculateOpacity());
  5174. }
  5175. if (tempSvg.type === "svg") {
  5176. var widthStyle = this.getStyle("width", false, true);
  5177. var heightStyle = this.getStyle("height", false, true);
  5178. if (widthStyle.hasValue()) {
  5179. tempSvg.attributes.width = new Property(document2, "width", widthStyle.getString());
  5180. }
  5181. if (heightStyle.hasValue()) {
  5182. tempSvg.attributes.height = new Property(document2, "height", heightStyle.getString());
  5183. }
  5184. }
  5185. var oldParent = tempSvg.parent;
  5186. tempSvg.parent = this;
  5187. tempSvg.render(ctx);
  5188. tempSvg.parent = oldParent;
  5189. }
  5190. }
  5191. getBoundingBox(ctx) {
  5192. var {
  5193. element
  5194. } = this;
  5195. if (element) {
  5196. return element.getBoundingBox(ctx);
  5197. }
  5198. return null;
  5199. }
  5200. elementTransform() {
  5201. var {
  5202. document: document2,
  5203. element
  5204. } = this;
  5205. return Transform.fromElement(document2, element);
  5206. }
  5207. get element() {
  5208. if (!this.cachedElement) {
  5209. this.cachedElement = this.getHrefAttribute().getDefinition();
  5210. }
  5211. return this.cachedElement;
  5212. }
  5213. };
  5214. FeColorMatrixElement = class extends Element {
  5215. constructor(document2, node2, captureTextNodes) {
  5216. super(document2, node2, captureTextNodes);
  5217. this.type = "feColorMatrix";
  5218. var matrix = toNumbers(this.getAttribute("values").getString());
  5219. switch (this.getAttribute("type").getString("matrix")) {
  5220. case "saturate": {
  5221. var s2 = matrix[0];
  5222. matrix = [0.213 + 0.787 * s2, 0.715 - 0.715 * s2, 0.072 - 0.072 * s2, 0, 0, 0.213 - 0.213 * s2, 0.715 + 0.285 * s2, 0.072 - 0.072 * s2, 0, 0, 0.213 - 0.213 * s2, 0.715 - 0.715 * s2, 0.072 + 0.928 * s2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1];
  5223. break;
  5224. }
  5225. case "hueRotate": {
  5226. var a2 = matrix[0] * Math.PI / 180;
  5227. matrix = [c2(a2, 0.213, 0.787, -0.213), c2(a2, 0.715, -0.715, -0.715), c2(a2, 0.072, -0.072, 0.928), 0, 0, c2(a2, 0.213, -0.213, 0.143), c2(a2, 0.715, 0.285, 0.14), c2(a2, 0.072, -0.072, -0.283), 0, 0, c2(a2, 0.213, -0.213, -0.787), c2(a2, 0.715, -0.715, 0.715), c2(a2, 0.072, 0.928, 0.072), 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1];
  5228. break;
  5229. }
  5230. case "luminanceToAlpha":
  5231. matrix = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.2125, 0.7154, 0.0721, 0, 0, 0, 0, 0, 0, 1];
  5232. break;
  5233. }
  5234. this.matrix = matrix;
  5235. this.includeOpacity = this.getAttribute("includeOpacity").hasValue();
  5236. }
  5237. apply(ctx, _x, _y, width, height) {
  5238. var {
  5239. includeOpacity,
  5240. matrix
  5241. } = this;
  5242. var srcData = ctx.getImageData(0, 0, width, height);
  5243. for (var y2 = 0; y2 < height; y2++) {
  5244. for (var x = 0; x < width; x++) {
  5245. var r2 = imGet(srcData.data, x, y2, width, height, 0);
  5246. var g = imGet(srcData.data, x, y2, width, height, 1);
  5247. var b = imGet(srcData.data, x, y2, width, height, 2);
  5248. var a2 = imGet(srcData.data, x, y2, width, height, 3);
  5249. var nr = m2(matrix, 0, r2) + m2(matrix, 1, g) + m2(matrix, 2, b) + m2(matrix, 3, a2) + m2(matrix, 4, 1);
  5250. var ng = m2(matrix, 5, r2) + m2(matrix, 6, g) + m2(matrix, 7, b) + m2(matrix, 8, a2) + m2(matrix, 9, 1);
  5251. var nb = m2(matrix, 10, r2) + m2(matrix, 11, g) + m2(matrix, 12, b) + m2(matrix, 13, a2) + m2(matrix, 14, 1);
  5252. var na = m2(matrix, 15, r2) + m2(matrix, 16, g) + m2(matrix, 17, b) + m2(matrix, 18, a2) + m2(matrix, 19, 1);
  5253. if (includeOpacity) {
  5254. nr = 0;
  5255. ng = 0;
  5256. nb = 0;
  5257. na *= a2 / 255;
  5258. }
  5259. imSet(srcData.data, x, y2, width, height, 0, nr);
  5260. imSet(srcData.data, x, y2, width, height, 1, ng);
  5261. imSet(srcData.data, x, y2, width, height, 2, nb);
  5262. imSet(srcData.data, x, y2, width, height, 3, na);
  5263. }
  5264. }
  5265. ctx.clearRect(0, 0, width, height);
  5266. ctx.putImageData(srcData, 0, 0);
  5267. }
  5268. };
  5269. MaskElement = class _MaskElement extends Element {
  5270. constructor() {
  5271. super(...arguments);
  5272. this.type = "mask";
  5273. }
  5274. apply(ctx, element) {
  5275. var {
  5276. document: document2
  5277. } = this;
  5278. var x = this.getAttribute("x").getPixels("x");
  5279. var y2 = this.getAttribute("y").getPixels("y");
  5280. var width = this.getStyle("width").getPixels("x");
  5281. var height = this.getStyle("height").getPixels("y");
  5282. if (!width && !height) {
  5283. var boundingBox = new BoundingBox();
  5284. this.children.forEach((child) => {
  5285. boundingBox.addBoundingBox(child.getBoundingBox(ctx));
  5286. });
  5287. x = Math.floor(boundingBox.x1);
  5288. y2 = Math.floor(boundingBox.y1);
  5289. width = Math.floor(boundingBox.width);
  5290. height = Math.floor(boundingBox.height);
  5291. }
  5292. var ignoredStyles = this.removeStyles(element, _MaskElement.ignoreStyles);
  5293. var maskCanvas = document2.createCanvas(x + width, y2 + height);
  5294. var maskCtx = maskCanvas.getContext("2d");
  5295. document2.screen.setDefaults(maskCtx);
  5296. this.renderChildren(maskCtx);
  5297. new FeColorMatrixElement(document2, {
  5298. nodeType: 1,
  5299. childNodes: [],
  5300. attributes: [{
  5301. nodeName: "type",
  5302. value: "luminanceToAlpha"
  5303. }, {
  5304. nodeName: "includeOpacity",
  5305. value: "true"
  5306. }]
  5307. }).apply(maskCtx, 0, 0, x + width, y2 + height);
  5308. var tmpCanvas = document2.createCanvas(x + width, y2 + height);
  5309. var tmpCtx = tmpCanvas.getContext("2d");
  5310. document2.screen.setDefaults(tmpCtx);
  5311. element.render(tmpCtx);
  5312. tmpCtx.globalCompositeOperation = "destination-in";
  5313. tmpCtx.fillStyle = maskCtx.createPattern(maskCanvas, "no-repeat");
  5314. tmpCtx.fillRect(0, 0, x + width, y2 + height);
  5315. ctx.fillStyle = tmpCtx.createPattern(tmpCanvas, "no-repeat");
  5316. ctx.fillRect(0, 0, x + width, y2 + height);
  5317. this.restoreStyles(element, ignoredStyles);
  5318. }
  5319. render(_2) {
  5320. }
  5321. };
  5322. MaskElement.ignoreStyles = ["mask", "transform", "clip-path"];
  5323. noop = () => {
  5324. };
  5325. ClipPathElement = class extends Element {
  5326. constructor() {
  5327. super(...arguments);
  5328. this.type = "clipPath";
  5329. }
  5330. apply(ctx) {
  5331. var {
  5332. document: document2
  5333. } = this;
  5334. var contextProto = Reflect.getPrototypeOf(ctx);
  5335. var {
  5336. beginPath,
  5337. closePath
  5338. } = ctx;
  5339. if (contextProto) {
  5340. contextProto.beginPath = noop;
  5341. contextProto.closePath = noop;
  5342. }
  5343. Reflect.apply(beginPath, ctx, []);
  5344. this.children.forEach((child) => {
  5345. if (typeof child.path === "undefined") {
  5346. return;
  5347. }
  5348. var transform = typeof child.elementTransform !== "undefined" ? child.elementTransform() : null;
  5349. if (!transform) {
  5350. transform = Transform.fromElement(document2, child);
  5351. }
  5352. if (transform) {
  5353. transform.apply(ctx);
  5354. }
  5355. child.path(ctx);
  5356. if (contextProto) {
  5357. contextProto.closePath = closePath;
  5358. }
  5359. if (transform) {
  5360. transform.unapply(ctx);
  5361. }
  5362. });
  5363. Reflect.apply(closePath, ctx, []);
  5364. ctx.clip();
  5365. if (contextProto) {
  5366. contextProto.beginPath = beginPath;
  5367. contextProto.closePath = closePath;
  5368. }
  5369. }
  5370. render(_2) {
  5371. }
  5372. };
  5373. FilterElement = class _FilterElement extends Element {
  5374. constructor() {
  5375. super(...arguments);
  5376. this.type = "filter";
  5377. }
  5378. apply(ctx, element) {
  5379. var {
  5380. document: document2,
  5381. children
  5382. } = this;
  5383. var boundingBox = element.getBoundingBox(ctx);
  5384. if (!boundingBox) {
  5385. return;
  5386. }
  5387. var px = 0;
  5388. var py = 0;
  5389. children.forEach((child) => {
  5390. var efd = child.extraFilterDistance || 0;
  5391. px = Math.max(px, efd);
  5392. py = Math.max(py, efd);
  5393. });
  5394. var width = Math.floor(boundingBox.width);
  5395. var height = Math.floor(boundingBox.height);
  5396. var tmpCanvasWidth = width + 2 * px;
  5397. var tmpCanvasHeight = height + 2 * py;
  5398. if (tmpCanvasWidth < 1 || tmpCanvasHeight < 1) {
  5399. return;
  5400. }
  5401. var x = Math.floor(boundingBox.x);
  5402. var y2 = Math.floor(boundingBox.y);
  5403. var ignoredStyles = this.removeStyles(element, _FilterElement.ignoreStyles);
  5404. var tmpCanvas = document2.createCanvas(tmpCanvasWidth, tmpCanvasHeight);
  5405. var tmpCtx = tmpCanvas.getContext("2d");
  5406. document2.screen.setDefaults(tmpCtx);
  5407. tmpCtx.translate(-x + px, -y2 + py);
  5408. element.render(tmpCtx);
  5409. children.forEach((child) => {
  5410. if (typeof child.apply === "function") {
  5411. child.apply(tmpCtx, 0, 0, tmpCanvasWidth, tmpCanvasHeight);
  5412. }
  5413. });
  5414. ctx.drawImage(tmpCanvas, 0, 0, tmpCanvasWidth, tmpCanvasHeight, x - px, y2 - py, tmpCanvasWidth, tmpCanvasHeight);
  5415. this.restoreStyles(element, ignoredStyles);
  5416. }
  5417. render(_2) {
  5418. }
  5419. };
  5420. FilterElement.ignoreStyles = ["filter", "transform", "clip-path"];
  5421. FeDropShadowElement = class extends Element {
  5422. constructor(document2, node2, captureTextNodes) {
  5423. super(document2, node2, captureTextNodes);
  5424. this.type = "feDropShadow";
  5425. this.addStylesFromStyleDefinition();
  5426. }
  5427. apply(_2, _x, _y, _width, _height) {
  5428. }
  5429. };
  5430. FeMorphologyElement = class extends Element {
  5431. constructor() {
  5432. super(...arguments);
  5433. this.type = "feMorphology";
  5434. }
  5435. apply(_2, _x, _y, _width, _height) {
  5436. }
  5437. };
  5438. FeCompositeElement = class extends Element {
  5439. constructor() {
  5440. super(...arguments);
  5441. this.type = "feComposite";
  5442. }
  5443. apply(_2, _x, _y, _width, _height) {
  5444. }
  5445. };
  5446. FeGaussianBlurElement = class extends Element {
  5447. constructor(document2, node2, captureTextNodes) {
  5448. super(document2, node2, captureTextNodes);
  5449. this.type = "feGaussianBlur";
  5450. this.blurRadius = Math.floor(this.getAttribute("stdDeviation").getNumber());
  5451. this.extraFilterDistance = this.blurRadius;
  5452. }
  5453. apply(ctx, x, y2, width, height) {
  5454. var {
  5455. document: document2,
  5456. blurRadius
  5457. } = this;
  5458. var body = document2.window ? document2.window.document.body : null;
  5459. var canvas = ctx.canvas;
  5460. canvas.id = document2.getUniqueId();
  5461. if (body) {
  5462. canvas.style.display = "none";
  5463. body.appendChild(canvas);
  5464. }
  5465. processCanvasRGBA(canvas, x, y2, width, height, blurRadius);
  5466. if (body) {
  5467. body.removeChild(canvas);
  5468. }
  5469. }
  5470. };
  5471. TitleElement = class extends Element {
  5472. constructor() {
  5473. super(...arguments);
  5474. this.type = "title";
  5475. }
  5476. };
  5477. DescElement = class extends Element {
  5478. constructor() {
  5479. super(...arguments);
  5480. this.type = "desc";
  5481. }
  5482. };
  5483. elements = {
  5484. "svg": SVGElement,
  5485. "rect": RectElement,
  5486. "circle": CircleElement,
  5487. "ellipse": EllipseElement,
  5488. "line": LineElement,
  5489. "polyline": PolylineElement,
  5490. "polygon": PolygonElement,
  5491. "path": PathElement,
  5492. "pattern": PatternElement,
  5493. "marker": MarkerElement,
  5494. "defs": DefsElement,
  5495. "linearGradient": LinearGradientElement,
  5496. "radialGradient": RadialGradientElement,
  5497. "stop": StopElement,
  5498. "animate": AnimateElement,
  5499. "animateColor": AnimateColorElement,
  5500. "animateTransform": AnimateTransformElement,
  5501. "font": FontElement,
  5502. "font-face": FontFaceElement,
  5503. "missing-glyph": MissingGlyphElement,
  5504. "glyph": GlyphElement,
  5505. "text": TextElement,
  5506. "tspan": TSpanElement,
  5507. "tref": TRefElement,
  5508. "a": AElement,
  5509. "textPath": TextPathElement,
  5510. "image": ImageElement,
  5511. "g": GElement,
  5512. "symbol": SymbolElement,
  5513. "style": StyleElement,
  5514. "use": UseElement,
  5515. "mask": MaskElement,
  5516. "clipPath": ClipPathElement,
  5517. "filter": FilterElement,
  5518. "feDropShadow": FeDropShadowElement,
  5519. "feMorphology": FeMorphologyElement,
  5520. "feComposite": FeCompositeElement,
  5521. "feColorMatrix": FeColorMatrixElement,
  5522. "feGaussianBlur": FeGaussianBlurElement,
  5523. "title": TitleElement,
  5524. "desc": DescElement
  5525. };
  5526. Document = class _Document {
  5527. constructor(canvg) {
  5528. var {
  5529. rootEmSize = 12,
  5530. emSize = 12,
  5531. createCanvas: createCanvas2 = _Document.createCanvas,
  5532. createImage: createImage2 = _Document.createImage,
  5533. anonymousCrossOrigin
  5534. } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  5535. this.canvg = canvg;
  5536. this.definitions = /* @__PURE__ */ Object.create(null);
  5537. this.styles = /* @__PURE__ */ Object.create(null);
  5538. this.stylesSpecificity = /* @__PURE__ */ Object.create(null);
  5539. this.images = [];
  5540. this.fonts = [];
  5541. this.emSizeStack = [];
  5542. this.uniqueId = 0;
  5543. this.screen = canvg.screen;
  5544. this.rootEmSize = rootEmSize;
  5545. this.emSize = emSize;
  5546. this.createCanvas = createCanvas2;
  5547. this.createImage = this.bindCreateImage(createImage2, anonymousCrossOrigin);
  5548. this.screen.wait(this.isImagesLoaded.bind(this));
  5549. this.screen.wait(this.isFontsLoaded.bind(this));
  5550. }
  5551. bindCreateImage(createImage2, anonymousCrossOrigin) {
  5552. if (typeof anonymousCrossOrigin === "boolean") {
  5553. return (source, forceAnonymousCrossOrigin) => createImage2(source, typeof forceAnonymousCrossOrigin === "boolean" ? forceAnonymousCrossOrigin : anonymousCrossOrigin);
  5554. }
  5555. return createImage2;
  5556. }
  5557. get window() {
  5558. return this.screen.window;
  5559. }
  5560. get fetch() {
  5561. return this.screen.fetch;
  5562. }
  5563. get ctx() {
  5564. return this.screen.ctx;
  5565. }
  5566. get emSize() {
  5567. var {
  5568. emSizeStack
  5569. } = this;
  5570. return emSizeStack[emSizeStack.length - 1];
  5571. }
  5572. set emSize(value) {
  5573. var {
  5574. emSizeStack
  5575. } = this;
  5576. emSizeStack.push(value);
  5577. }
  5578. popEmSize() {
  5579. var {
  5580. emSizeStack
  5581. } = this;
  5582. emSizeStack.pop();
  5583. }
  5584. getUniqueId() {
  5585. return "canvg".concat(++this.uniqueId);
  5586. }
  5587. isImagesLoaded() {
  5588. return this.images.every((_2) => _2.loaded);
  5589. }
  5590. isFontsLoaded() {
  5591. return this.fonts.every((_2) => _2.loaded);
  5592. }
  5593. createDocumentElement(document2) {
  5594. var documentElement = this.createElement(document2.documentElement);
  5595. documentElement.root = true;
  5596. documentElement.addStylesFromStyleDefinition();
  5597. this.documentElement = documentElement;
  5598. return documentElement;
  5599. }
  5600. createElement(node2) {
  5601. var elementType = node2.nodeName.replace(/^[^:]+:/, "");
  5602. var ElementType = _Document.elementTypes[elementType];
  5603. if (typeof ElementType !== "undefined") {
  5604. return new ElementType(this, node2);
  5605. }
  5606. return new UnknownElement(this, node2);
  5607. }
  5608. createTextNode(node2) {
  5609. return new TextNode(this, node2);
  5610. }
  5611. setViewBox(config) {
  5612. this.screen.setViewBox(_objectSpread$1({
  5613. document: this
  5614. }, config));
  5615. }
  5616. };
  5617. Document.createCanvas = createCanvas;
  5618. Document.createImage = createImage;
  5619. Document.elementTypes = elements;
  5620. Canvg = class _Canvg {
  5621. /**
  5622. * Main constructor.
  5623. * @param ctx - Rendering context.
  5624. * @param svg - SVG Document.
  5625. * @param options - Rendering options.
  5626. */
  5627. constructor(ctx, svg) {
  5628. var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
  5629. this.parser = new Parser(options);
  5630. this.screen = new Screen(ctx, options);
  5631. this.options = options;
  5632. var document2 = new Document(this, options);
  5633. var documentElement = document2.createDocumentElement(svg);
  5634. this.document = document2;
  5635. this.documentElement = documentElement;
  5636. }
  5637. /**
  5638. * Create Canvg instance from SVG source string or URL.
  5639. * @param ctx - Rendering context.
  5640. * @param svg - SVG source string or URL.
  5641. * @param options - Rendering options.
  5642. * @returns Canvg instance.
  5643. */
  5644. static from(ctx, svg) {
  5645. var _arguments = arguments;
  5646. return _asyncToGenerator(function* () {
  5647. var options = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
  5648. var parser = new Parser(options);
  5649. var svgDocument = yield parser.parse(svg);
  5650. return new _Canvg(ctx, svgDocument, options);
  5651. })();
  5652. }
  5653. /**
  5654. * Create Canvg instance from SVG source string.
  5655. * @param ctx - Rendering context.
  5656. * @param svg - SVG source string.
  5657. * @param options - Rendering options.
  5658. * @returns Canvg instance.
  5659. */
  5660. static fromString(ctx, svg) {
  5661. var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
  5662. var parser = new Parser(options);
  5663. var svgDocument = parser.parseFromString(svg);
  5664. return new _Canvg(ctx, svgDocument, options);
  5665. }
  5666. /**
  5667. * Create new Canvg instance with inherited options.
  5668. * @param ctx - Rendering context.
  5669. * @param svg - SVG source string or URL.
  5670. * @param options - Rendering options.
  5671. * @returns Canvg instance.
  5672. */
  5673. fork(ctx, svg) {
  5674. var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
  5675. return _Canvg.from(ctx, svg, _objectSpread(_objectSpread({}, this.options), options));
  5676. }
  5677. /**
  5678. * Create new Canvg instance with inherited options.
  5679. * @param ctx - Rendering context.
  5680. * @param svg - SVG source string.
  5681. * @param options - Rendering options.
  5682. * @returns Canvg instance.
  5683. */
  5684. forkString(ctx, svg) {
  5685. var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
  5686. return _Canvg.fromString(ctx, svg, _objectSpread(_objectSpread({}, this.options), options));
  5687. }
  5688. /**
  5689. * Document is ready promise.
  5690. * @returns Ready promise.
  5691. */
  5692. ready() {
  5693. return this.screen.ready();
  5694. }
  5695. /**
  5696. * Document is ready value.
  5697. * @returns Is ready or not.
  5698. */
  5699. isReady() {
  5700. return this.screen.isReady();
  5701. }
  5702. /**
  5703. * Render only first frame, ignoring animations and mouse.
  5704. * @param options - Rendering options.
  5705. */
  5706. render() {
  5707. var _arguments2 = arguments, _this = this;
  5708. return _asyncToGenerator(function* () {
  5709. var options = _arguments2.length > 0 && _arguments2[0] !== void 0 ? _arguments2[0] : {};
  5710. _this.start(_objectSpread({
  5711. enableRedraw: true,
  5712. ignoreAnimation: true,
  5713. ignoreMouse: true
  5714. }, options));
  5715. yield _this.ready();
  5716. _this.stop();
  5717. })();
  5718. }
  5719. /**
  5720. * Start rendering.
  5721. * @param options - Render options.
  5722. */
  5723. start() {
  5724. var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
  5725. var {
  5726. documentElement,
  5727. screen,
  5728. options: baseOptions
  5729. } = this;
  5730. screen.start(documentElement, _objectSpread(_objectSpread({
  5731. enableRedraw: true
  5732. }, baseOptions), options));
  5733. }
  5734. /**
  5735. * Stop rendering.
  5736. */
  5737. stop() {
  5738. this.screen.stop();
  5739. }
  5740. /**
  5741. * Resize SVG to fit in given size.
  5742. * @param width
  5743. * @param height
  5744. * @param preserveAspectRatio
  5745. */
  5746. resize(width) {
  5747. var height = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : width;
  5748. var preserveAspectRatio = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
  5749. this.documentElement.resize(width, height, preserveAspectRatio);
  5750. }
  5751. };
  5752. }
  5753. });
  5754. init_index_es();
  5755. export {
  5756. AElement,
  5757. AnimateColorElement,
  5758. AnimateElement,
  5759. AnimateTransformElement,
  5760. BoundingBox,
  5761. CB1,
  5762. CB2,
  5763. CB3,
  5764. CB4,
  5765. Canvg,
  5766. CircleElement,
  5767. ClipPathElement,
  5768. DefsElement,
  5769. DescElement,
  5770. Document,
  5771. Element,
  5772. EllipseElement,
  5773. FeColorMatrixElement,
  5774. FeCompositeElement,
  5775. FeDropShadowElement,
  5776. FeGaussianBlurElement,
  5777. FeMorphologyElement,
  5778. FilterElement,
  5779. Font,
  5780. FontElement,
  5781. FontFaceElement,
  5782. GElement,
  5783. GlyphElement,
  5784. GradientElement,
  5785. ImageElement,
  5786. LineElement,
  5787. LinearGradientElement,
  5788. MarkerElement,
  5789. MaskElement,
  5790. Matrix,
  5791. MissingGlyphElement,
  5792. Mouse,
  5793. PSEUDO_ZERO,
  5794. Parser,
  5795. PathElement,
  5796. PathParser,
  5797. PatternElement,
  5798. Point,
  5799. PolygonElement,
  5800. PolylineElement,
  5801. Property,
  5802. QB1,
  5803. QB2,
  5804. QB3,
  5805. RadialGradientElement,
  5806. RectElement,
  5807. RenderedElement,
  5808. Rotate,
  5809. SVGElement,
  5810. SVGFontLoader,
  5811. Scale,
  5812. Screen,
  5813. Skew,
  5814. SkewX,
  5815. SkewY,
  5816. StopElement,
  5817. StyleElement,
  5818. SymbolElement,
  5819. TRefElement,
  5820. TSpanElement,
  5821. TextElement,
  5822. TextPathElement,
  5823. TitleElement,
  5824. Transform,
  5825. Translate,
  5826. UnknownElement,
  5827. UseElement,
  5828. ViewPort,
  5829. compressSpaces,
  5830. Canvg as default,
  5831. getSelectorSpecificity,
  5832. normalizeAttributeName,
  5833. normalizeColor,
  5834. parseExternalUrl,
  5835. index as presets,
  5836. toNumbers,
  5837. trimLeft,
  5838. trimRight,
  5839. vectorMagnitude,
  5840. vectorsAngle,
  5841. vectorsRatio
  5842. };
  5843. /*! Bundled license information:
  5844. svg-pathdata/lib/SVGPathData.module.js:
  5845. (*! *****************************************************************************
  5846. Copyright (c) Microsoft Corporation.
  5847. Permission to use, copy, modify, and/or distribute this software for any
  5848. purpose with or without fee is hereby granted.
  5849. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  5850. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  5851. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  5852. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  5853. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  5854. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  5855. PERFORMANCE OF THIS SOFTWARE.
  5856. ***************************************************************************** *)
  5857. */
  5858. //# sourceMappingURL=index.es-HPHM6KTN.js.map