zrender.js 634 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.zrender = {}));
  5. }(this, (function (exports) { 'use strict';
  6. var Browser = (function () {
  7. function Browser() {
  8. this.firefox = false;
  9. this.ie = false;
  10. this.edge = false;
  11. this.newEdge = false;
  12. this.weChat = false;
  13. }
  14. return Browser;
  15. }());
  16. var Env = (function () {
  17. function Env() {
  18. this.browser = new Browser();
  19. this.node = false;
  20. this.wxa = false;
  21. this.worker = false;
  22. this.svgSupported = false;
  23. this.touchEventsSupported = false;
  24. this.pointerEventsSupported = false;
  25. this.domSupported = false;
  26. this.transformSupported = false;
  27. this.transform3dSupported = false;
  28. this.hasGlobalWindow = typeof window !== 'undefined';
  29. }
  30. return Env;
  31. }());
  32. var env = new Env();
  33. if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
  34. env.wxa = true;
  35. env.touchEventsSupported = true;
  36. }
  37. else if (typeof document === 'undefined' && typeof self !== 'undefined') {
  38. env.worker = true;
  39. }
  40. else if (typeof navigator === 'undefined') {
  41. env.node = true;
  42. env.svgSupported = true;
  43. }
  44. else {
  45. detect(navigator.userAgent, env);
  46. }
  47. function detect(ua, env) {
  48. var browser = env.browser;
  49. var firefox = ua.match(/Firefox\/([\d.]+)/);
  50. var ie = ua.match(/MSIE\s([\d.]+)/)
  51. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  52. var edge = ua.match(/Edge?\/([\d.]+)/);
  53. var weChat = (/micromessenger/i).test(ua);
  54. if (firefox) {
  55. browser.firefox = true;
  56. browser.version = firefox[1];
  57. }
  58. if (ie) {
  59. browser.ie = true;
  60. browser.version = ie[1];
  61. }
  62. if (edge) {
  63. browser.edge = true;
  64. browser.version = edge[1];
  65. browser.newEdge = +edge[1].split('.')[0] > 18;
  66. }
  67. if (weChat) {
  68. browser.weChat = true;
  69. }
  70. env.svgSupported = typeof SVGRect !== 'undefined';
  71. env.touchEventsSupported = 'ontouchstart' in window && !browser.ie && !browser.edge;
  72. env.pointerEventsSupported = 'onpointerdown' in window
  73. && (browser.edge || (browser.ie && +browser.version >= 11));
  74. env.domSupported = typeof document !== 'undefined';
  75. var style = document.documentElement.style;
  76. env.transform3dSupported = ((browser.ie && 'transition' in style)
  77. || browser.edge
  78. || (('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()))
  79. || 'MozPerspective' in style)
  80. && !('OTransition' in style);
  81. env.transformSupported = env.transform3dSupported
  82. || (browser.ie && +browser.version >= 9);
  83. }
  84. var DEFAULT_FONT_SIZE = 12;
  85. var DEFAULT_FONT_FAMILY = 'sans-serif';
  86. var DEFAULT_FONT = DEFAULT_FONT_SIZE + "px " + DEFAULT_FONT_FAMILY;
  87. var OFFSET = 20;
  88. var SCALE = 100;
  89. var defaultWidthMapStr = "007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N";
  90. function getTextWidthMap(mapStr) {
  91. var map = {};
  92. if (typeof JSON === 'undefined') {
  93. return map;
  94. }
  95. for (var i = 0; i < mapStr.length; i++) {
  96. var char = String.fromCharCode(i + 32);
  97. var size = (mapStr.charCodeAt(i) - OFFSET) / SCALE;
  98. map[char] = size;
  99. }
  100. return map;
  101. }
  102. var DEFAULT_TEXT_WIDTH_MAP = getTextWidthMap(defaultWidthMapStr);
  103. var platformApi = {
  104. createCanvas: function () {
  105. return typeof document !== 'undefined'
  106. && document.createElement('canvas');
  107. },
  108. measureText: (function () {
  109. var _ctx;
  110. var _cachedFont;
  111. return function (text, font) {
  112. if (!_ctx) {
  113. var canvas = platformApi.createCanvas();
  114. _ctx = canvas && canvas.getContext('2d');
  115. }
  116. if (_ctx) {
  117. if (_cachedFont !== font) {
  118. _cachedFont = _ctx.font = font || DEFAULT_FONT;
  119. }
  120. return _ctx.measureText(text);
  121. }
  122. else {
  123. text = text || '';
  124. font = font || DEFAULT_FONT;
  125. var res = /(\d+)px/.exec(font);
  126. var fontSize = res && +res[1] || DEFAULT_FONT_SIZE;
  127. var width = 0;
  128. if (font.indexOf('mono') >= 0) {
  129. width = fontSize * text.length;
  130. }
  131. else {
  132. for (var i = 0; i < text.length; i++) {
  133. var preCalcWidth = DEFAULT_TEXT_WIDTH_MAP[text[i]];
  134. width += preCalcWidth == null ? fontSize : (preCalcWidth * fontSize);
  135. }
  136. }
  137. return { width: width };
  138. }
  139. };
  140. })(),
  141. loadImage: function (src, onload, onerror) {
  142. var image = new Image();
  143. image.onload = onload;
  144. image.onerror = onerror;
  145. image.src = src;
  146. return image;
  147. }
  148. };
  149. function setPlatformAPI(newPlatformApis) {
  150. for (var key in platformApi) {
  151. if (newPlatformApis[key]) {
  152. platformApi[key] = newPlatformApis[key];
  153. }
  154. }
  155. }
  156. var BUILTIN_OBJECT = reduce([
  157. 'Function',
  158. 'RegExp',
  159. 'Date',
  160. 'Error',
  161. 'CanvasGradient',
  162. 'CanvasPattern',
  163. 'Image',
  164. 'Canvas'
  165. ], function (obj, val) {
  166. obj['[object ' + val + ']'] = true;
  167. return obj;
  168. }, {});
  169. var TYPED_ARRAY = reduce([
  170. 'Int8',
  171. 'Uint8',
  172. 'Uint8Clamped',
  173. 'Int16',
  174. 'Uint16',
  175. 'Int32',
  176. 'Uint32',
  177. 'Float32',
  178. 'Float64'
  179. ], function (obj, val) {
  180. obj['[object ' + val + 'Array]'] = true;
  181. return obj;
  182. }, {});
  183. var objToString = Object.prototype.toString;
  184. var arrayProto = Array.prototype;
  185. var nativeForEach = arrayProto.forEach;
  186. var nativeFilter = arrayProto.filter;
  187. var nativeSlice = arrayProto.slice;
  188. var nativeMap = arrayProto.map;
  189. var ctorFunction = function () { }.constructor;
  190. var protoFunction = ctorFunction ? ctorFunction.prototype : null;
  191. var protoKey = '__proto__';
  192. var idStart = 0x0907;
  193. function guid() {
  194. return idStart++;
  195. }
  196. function logError() {
  197. var args = [];
  198. for (var _i = 0; _i < arguments.length; _i++) {
  199. args[_i] = arguments[_i];
  200. }
  201. if (typeof console !== 'undefined') {
  202. console.error.apply(console, args);
  203. }
  204. }
  205. function clone(source) {
  206. if (source == null || typeof source !== 'object') {
  207. return source;
  208. }
  209. var result = source;
  210. var typeStr = objToString.call(source);
  211. if (typeStr === '[object Array]') {
  212. if (!isPrimitive(source)) {
  213. result = [];
  214. for (var i = 0, len = source.length; i < len; i++) {
  215. result[i] = clone(source[i]);
  216. }
  217. }
  218. }
  219. else if (TYPED_ARRAY[typeStr]) {
  220. if (!isPrimitive(source)) {
  221. var Ctor = source.constructor;
  222. if (Ctor.from) {
  223. result = Ctor.from(source);
  224. }
  225. else {
  226. result = new Ctor(source.length);
  227. for (var i = 0, len = source.length; i < len; i++) {
  228. result[i] = source[i];
  229. }
  230. }
  231. }
  232. }
  233. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  234. result = {};
  235. for (var key in source) {
  236. if (source.hasOwnProperty(key) && key !== protoKey) {
  237. result[key] = clone(source[key]);
  238. }
  239. }
  240. }
  241. return result;
  242. }
  243. function merge(target, source, overwrite) {
  244. if (!isObject(source) || !isObject(target)) {
  245. return overwrite ? clone(source) : target;
  246. }
  247. for (var key in source) {
  248. if (source.hasOwnProperty(key) && key !== protoKey) {
  249. var targetProp = target[key];
  250. var sourceProp = source[key];
  251. if (isObject(sourceProp)
  252. && isObject(targetProp)
  253. && !isArray(sourceProp)
  254. && !isArray(targetProp)
  255. && !isDom(sourceProp)
  256. && !isDom(targetProp)
  257. && !isBuiltInObject(sourceProp)
  258. && !isBuiltInObject(targetProp)
  259. && !isPrimitive(sourceProp)
  260. && !isPrimitive(targetProp)) {
  261. merge(targetProp, sourceProp, overwrite);
  262. }
  263. else if (overwrite || !(key in target)) {
  264. target[key] = clone(source[key]);
  265. }
  266. }
  267. }
  268. return target;
  269. }
  270. function mergeAll(targetAndSources, overwrite) {
  271. var result = targetAndSources[0];
  272. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  273. result = merge(result, targetAndSources[i], overwrite);
  274. }
  275. return result;
  276. }
  277. function extend(target, source) {
  278. if (Object.assign) {
  279. Object.assign(target, source);
  280. }
  281. else {
  282. for (var key in source) {
  283. if (source.hasOwnProperty(key) && key !== protoKey) {
  284. target[key] = source[key];
  285. }
  286. }
  287. }
  288. return target;
  289. }
  290. function defaults(target, source, overlay) {
  291. var keysArr = keys(source);
  292. for (var i = 0; i < keysArr.length; i++) {
  293. var key = keysArr[i];
  294. if ((overlay ? source[key] != null : target[key] == null)) {
  295. target[key] = source[key];
  296. }
  297. }
  298. return target;
  299. }
  300. var createCanvas = platformApi.createCanvas;
  301. function indexOf(array, value) {
  302. if (array) {
  303. if (array.indexOf) {
  304. return array.indexOf(value);
  305. }
  306. for (var i = 0, len = array.length; i < len; i++) {
  307. if (array[i] === value) {
  308. return i;
  309. }
  310. }
  311. }
  312. return -1;
  313. }
  314. function inherits(clazz, baseClazz) {
  315. var clazzPrototype = clazz.prototype;
  316. function F() { }
  317. F.prototype = baseClazz.prototype;
  318. clazz.prototype = new F();
  319. for (var prop in clazzPrototype) {
  320. if (clazzPrototype.hasOwnProperty(prop)) {
  321. clazz.prototype[prop] = clazzPrototype[prop];
  322. }
  323. }
  324. clazz.prototype.constructor = clazz;
  325. clazz.superClass = baseClazz;
  326. }
  327. function mixin(target, source, override) {
  328. target = 'prototype' in target ? target.prototype : target;
  329. source = 'prototype' in source ? source.prototype : source;
  330. if (Object.getOwnPropertyNames) {
  331. var keyList = Object.getOwnPropertyNames(source);
  332. for (var i = 0; i < keyList.length; i++) {
  333. var key = keyList[i];
  334. if (key !== 'constructor') {
  335. if ((override ? source[key] != null : target[key] == null)) {
  336. target[key] = source[key];
  337. }
  338. }
  339. }
  340. }
  341. else {
  342. defaults(target, source, override);
  343. }
  344. }
  345. function isArrayLike(data) {
  346. if (!data) {
  347. return false;
  348. }
  349. if (typeof data === 'string') {
  350. return false;
  351. }
  352. return typeof data.length === 'number';
  353. }
  354. function each(arr, cb, context) {
  355. if (!(arr && cb)) {
  356. return;
  357. }
  358. if (arr.forEach && arr.forEach === nativeForEach) {
  359. arr.forEach(cb, context);
  360. }
  361. else if (arr.length === +arr.length) {
  362. for (var i = 0, len = arr.length; i < len; i++) {
  363. cb.call(context, arr[i], i, arr);
  364. }
  365. }
  366. else {
  367. for (var key in arr) {
  368. if (arr.hasOwnProperty(key)) {
  369. cb.call(context, arr[key], key, arr);
  370. }
  371. }
  372. }
  373. }
  374. function map(arr, cb, context) {
  375. if (!arr) {
  376. return [];
  377. }
  378. if (!cb) {
  379. return slice(arr);
  380. }
  381. if (arr.map && arr.map === nativeMap) {
  382. return arr.map(cb, context);
  383. }
  384. else {
  385. var result = [];
  386. for (var i = 0, len = arr.length; i < len; i++) {
  387. result.push(cb.call(context, arr[i], i, arr));
  388. }
  389. return result;
  390. }
  391. }
  392. function reduce(arr, cb, memo, context) {
  393. if (!(arr && cb)) {
  394. return;
  395. }
  396. for (var i = 0, len = arr.length; i < len; i++) {
  397. memo = cb.call(context, memo, arr[i], i, arr);
  398. }
  399. return memo;
  400. }
  401. function filter(arr, cb, context) {
  402. if (!arr) {
  403. return [];
  404. }
  405. if (!cb) {
  406. return slice(arr);
  407. }
  408. if (arr.filter && arr.filter === nativeFilter) {
  409. return arr.filter(cb, context);
  410. }
  411. else {
  412. var result = [];
  413. for (var i = 0, len = arr.length; i < len; i++) {
  414. if (cb.call(context, arr[i], i, arr)) {
  415. result.push(arr[i]);
  416. }
  417. }
  418. return result;
  419. }
  420. }
  421. function find(arr, cb, context) {
  422. if (!(arr && cb)) {
  423. return;
  424. }
  425. for (var i = 0, len = arr.length; i < len; i++) {
  426. if (cb.call(context, arr[i], i, arr)) {
  427. return arr[i];
  428. }
  429. }
  430. }
  431. function keys(obj) {
  432. if (!obj) {
  433. return [];
  434. }
  435. if (Object.keys) {
  436. return Object.keys(obj);
  437. }
  438. var keyList = [];
  439. for (var key in obj) {
  440. if (obj.hasOwnProperty(key)) {
  441. keyList.push(key);
  442. }
  443. }
  444. return keyList;
  445. }
  446. function bindPolyfill(func, context) {
  447. var args = [];
  448. for (var _i = 2; _i < arguments.length; _i++) {
  449. args[_i - 2] = arguments[_i];
  450. }
  451. return function () {
  452. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  453. };
  454. }
  455. var bind = (protoFunction && isFunction(protoFunction.bind))
  456. ? protoFunction.call.bind(protoFunction.bind)
  457. : bindPolyfill;
  458. function curry(func) {
  459. var args = [];
  460. for (var _i = 1; _i < arguments.length; _i++) {
  461. args[_i - 1] = arguments[_i];
  462. }
  463. return function () {
  464. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  465. };
  466. }
  467. function isArray(value) {
  468. if (Array.isArray) {
  469. return Array.isArray(value);
  470. }
  471. return objToString.call(value) === '[object Array]';
  472. }
  473. function isFunction(value) {
  474. return typeof value === 'function';
  475. }
  476. function isString(value) {
  477. return typeof value === 'string';
  478. }
  479. function isStringSafe(value) {
  480. return objToString.call(value) === '[object String]';
  481. }
  482. function isNumber(value) {
  483. return typeof value === 'number';
  484. }
  485. function isObject(value) {
  486. var type = typeof value;
  487. return type === 'function' || (!!value && type === 'object');
  488. }
  489. function isBuiltInObject(value) {
  490. return !!BUILTIN_OBJECT[objToString.call(value)];
  491. }
  492. function isTypedArray(value) {
  493. return !!TYPED_ARRAY[objToString.call(value)];
  494. }
  495. function isDom(value) {
  496. return typeof value === 'object'
  497. && typeof value.nodeType === 'number'
  498. && typeof value.ownerDocument === 'object';
  499. }
  500. function isGradientObject(value) {
  501. return value.colorStops != null;
  502. }
  503. function isImagePatternObject(value) {
  504. return value.image != null;
  505. }
  506. function isRegExp(value) {
  507. return objToString.call(value) === '[object RegExp]';
  508. }
  509. function eqNaN(value) {
  510. return value !== value;
  511. }
  512. function retrieve() {
  513. var args = [];
  514. for (var _i = 0; _i < arguments.length; _i++) {
  515. args[_i] = arguments[_i];
  516. }
  517. for (var i = 0, len = args.length; i < len; i++) {
  518. if (args[i] != null) {
  519. return args[i];
  520. }
  521. }
  522. }
  523. function retrieve2(value0, value1) {
  524. return value0 != null
  525. ? value0
  526. : value1;
  527. }
  528. function retrieve3(value0, value1, value2) {
  529. return value0 != null
  530. ? value0
  531. : value1 != null
  532. ? value1
  533. : value2;
  534. }
  535. function slice(arr) {
  536. var args = [];
  537. for (var _i = 1; _i < arguments.length; _i++) {
  538. args[_i - 1] = arguments[_i];
  539. }
  540. return nativeSlice.apply(arr, args);
  541. }
  542. function normalizeCssArray(val) {
  543. if (typeof (val) === 'number') {
  544. return [val, val, val, val];
  545. }
  546. var len = val.length;
  547. if (len === 2) {
  548. return [val[0], val[1], val[0], val[1]];
  549. }
  550. else if (len === 3) {
  551. return [val[0], val[1], val[2], val[1]];
  552. }
  553. return val;
  554. }
  555. function assert(condition, message) {
  556. if (!condition) {
  557. throw new Error(message);
  558. }
  559. }
  560. function trim(str) {
  561. if (str == null) {
  562. return null;
  563. }
  564. else if (typeof str.trim === 'function') {
  565. return str.trim();
  566. }
  567. else {
  568. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  569. }
  570. }
  571. var primitiveKey = '__ec_primitive__';
  572. function setAsPrimitive(obj) {
  573. obj[primitiveKey] = true;
  574. }
  575. function isPrimitive(obj) {
  576. return obj[primitiveKey];
  577. }
  578. var MapPolyfill = (function () {
  579. function MapPolyfill() {
  580. this.data = {};
  581. }
  582. MapPolyfill.prototype["delete"] = function (key) {
  583. var existed = this.has(key);
  584. if (existed) {
  585. delete this.data[key];
  586. }
  587. return existed;
  588. };
  589. MapPolyfill.prototype.has = function (key) {
  590. return this.data.hasOwnProperty(key);
  591. };
  592. MapPolyfill.prototype.get = function (key) {
  593. return this.data[key];
  594. };
  595. MapPolyfill.prototype.set = function (key, value) {
  596. this.data[key] = value;
  597. return this;
  598. };
  599. MapPolyfill.prototype.keys = function () {
  600. return keys(this.data);
  601. };
  602. MapPolyfill.prototype.forEach = function (callback) {
  603. var data = this.data;
  604. for (var key in data) {
  605. if (data.hasOwnProperty(key)) {
  606. callback(data[key], key);
  607. }
  608. }
  609. };
  610. return MapPolyfill;
  611. }());
  612. var isNativeMapSupported = typeof Map === 'function';
  613. function maybeNativeMap() {
  614. return (isNativeMapSupported ? new Map() : new MapPolyfill());
  615. }
  616. var HashMap = (function () {
  617. function HashMap(obj) {
  618. var isArr = isArray(obj);
  619. this.data = maybeNativeMap();
  620. var thisMap = this;
  621. (obj instanceof HashMap)
  622. ? obj.each(visit)
  623. : (obj && each(obj, visit));
  624. function visit(value, key) {
  625. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  626. }
  627. }
  628. HashMap.prototype.hasKey = function (key) {
  629. return this.data.has(key);
  630. };
  631. HashMap.prototype.get = function (key) {
  632. return this.data.get(key);
  633. };
  634. HashMap.prototype.set = function (key, value) {
  635. this.data.set(key, value);
  636. return value;
  637. };
  638. HashMap.prototype.each = function (cb, context) {
  639. this.data.forEach(function (value, key) {
  640. cb.call(context, value, key);
  641. });
  642. };
  643. HashMap.prototype.keys = function () {
  644. var keys = this.data.keys();
  645. return isNativeMapSupported
  646. ? Array.from(keys)
  647. : keys;
  648. };
  649. HashMap.prototype.removeKey = function (key) {
  650. this.data["delete"](key);
  651. };
  652. return HashMap;
  653. }());
  654. function createHashMap(obj) {
  655. return new HashMap(obj);
  656. }
  657. function concatArray(a, b) {
  658. var newArray = new a.constructor(a.length + b.length);
  659. for (var i = 0; i < a.length; i++) {
  660. newArray[i] = a[i];
  661. }
  662. var offset = a.length;
  663. for (var i = 0; i < b.length; i++) {
  664. newArray[i + offset] = b[i];
  665. }
  666. return newArray;
  667. }
  668. function createObject(proto, properties) {
  669. var obj;
  670. if (Object.create) {
  671. obj = Object.create(proto);
  672. }
  673. else {
  674. var StyleCtor = function () { };
  675. StyleCtor.prototype = proto;
  676. obj = new StyleCtor();
  677. }
  678. if (properties) {
  679. extend(obj, properties);
  680. }
  681. return obj;
  682. }
  683. function disableUserSelect(dom) {
  684. var domStyle = dom.style;
  685. domStyle.webkitUserSelect = 'none';
  686. domStyle.userSelect = 'none';
  687. domStyle.webkitTapHighlightColor = 'rgba(0,0,0,0)';
  688. domStyle['-webkit-touch-callout'] = 'none';
  689. }
  690. function hasOwn(own, prop) {
  691. return own.hasOwnProperty(prop);
  692. }
  693. function noop() { }
  694. var RADIAN_TO_DEGREE = 180 / Math.PI;
  695. var util = /*#__PURE__*/Object.freeze({
  696. __proto__: null,
  697. guid: guid,
  698. logError: logError,
  699. clone: clone,
  700. merge: merge,
  701. mergeAll: mergeAll,
  702. extend: extend,
  703. defaults: defaults,
  704. createCanvas: createCanvas,
  705. indexOf: indexOf,
  706. inherits: inherits,
  707. mixin: mixin,
  708. isArrayLike: isArrayLike,
  709. each: each,
  710. map: map,
  711. reduce: reduce,
  712. filter: filter,
  713. find: find,
  714. keys: keys,
  715. bind: bind,
  716. curry: curry,
  717. isArray: isArray,
  718. isFunction: isFunction,
  719. isString: isString,
  720. isStringSafe: isStringSafe,
  721. isNumber: isNumber,
  722. isObject: isObject,
  723. isBuiltInObject: isBuiltInObject,
  724. isTypedArray: isTypedArray,
  725. isDom: isDom,
  726. isGradientObject: isGradientObject,
  727. isImagePatternObject: isImagePatternObject,
  728. isRegExp: isRegExp,
  729. eqNaN: eqNaN,
  730. retrieve: retrieve,
  731. retrieve2: retrieve2,
  732. retrieve3: retrieve3,
  733. slice: slice,
  734. normalizeCssArray: normalizeCssArray,
  735. assert: assert,
  736. trim: trim,
  737. setAsPrimitive: setAsPrimitive,
  738. isPrimitive: isPrimitive,
  739. HashMap: HashMap,
  740. createHashMap: createHashMap,
  741. concatArray: concatArray,
  742. createObject: createObject,
  743. disableUserSelect: disableUserSelect,
  744. hasOwn: hasOwn,
  745. noop: noop,
  746. RADIAN_TO_DEGREE: RADIAN_TO_DEGREE
  747. });
  748. /*! *****************************************************************************
  749. Copyright (c) Microsoft Corporation. All rights reserved.
  750. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  751. this file except in compliance with the License. You may obtain a copy of the
  752. License at http://www.apache.org/licenses/LICENSE-2.0
  753. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  754. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  755. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  756. MERCHANTABLITY OR NON-INFRINGEMENT.
  757. See the Apache Version 2.0 License for specific language governing permissions
  758. and limitations under the License.
  759. ***************************************************************************** */
  760. /* global Reflect, Promise */
  761. var extendStatics = function(d, b) {
  762. extendStatics = Object.setPrototypeOf ||
  763. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  764. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  765. return extendStatics(d, b);
  766. };
  767. function __extends(d, b) {
  768. extendStatics(d, b);
  769. function __() { this.constructor = d; }
  770. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  771. }
  772. function create(x, y) {
  773. if (x == null) {
  774. x = 0;
  775. }
  776. if (y == null) {
  777. y = 0;
  778. }
  779. return [x, y];
  780. }
  781. function copy(out, v) {
  782. out[0] = v[0];
  783. out[1] = v[1];
  784. return out;
  785. }
  786. function clone$1(v) {
  787. return [v[0], v[1]];
  788. }
  789. function set(out, a, b) {
  790. out[0] = a;
  791. out[1] = b;
  792. return out;
  793. }
  794. function add(out, v1, v2) {
  795. out[0] = v1[0] + v2[0];
  796. out[1] = v1[1] + v2[1];
  797. return out;
  798. }
  799. function scaleAndAdd(out, v1, v2, a) {
  800. out[0] = v1[0] + v2[0] * a;
  801. out[1] = v1[1] + v2[1] * a;
  802. return out;
  803. }
  804. function sub(out, v1, v2) {
  805. out[0] = v1[0] - v2[0];
  806. out[1] = v1[1] - v2[1];
  807. return out;
  808. }
  809. function len(v) {
  810. return Math.sqrt(lenSquare(v));
  811. }
  812. var length = len;
  813. function lenSquare(v) {
  814. return v[0] * v[0] + v[1] * v[1];
  815. }
  816. var lengthSquare = lenSquare;
  817. function mul(out, v1, v2) {
  818. out[0] = v1[0] * v2[0];
  819. out[1] = v1[1] * v2[1];
  820. return out;
  821. }
  822. function div(out, v1, v2) {
  823. out[0] = v1[0] / v2[0];
  824. out[1] = v1[1] / v2[1];
  825. return out;
  826. }
  827. function dot(v1, v2) {
  828. return v1[0] * v2[0] + v1[1] * v2[1];
  829. }
  830. function scale(out, v, s) {
  831. out[0] = v[0] * s;
  832. out[1] = v[1] * s;
  833. return out;
  834. }
  835. function normalize(out, v) {
  836. var d = len(v);
  837. if (d === 0) {
  838. out[0] = 0;
  839. out[1] = 0;
  840. }
  841. else {
  842. out[0] = v[0] / d;
  843. out[1] = v[1] / d;
  844. }
  845. return out;
  846. }
  847. function distance(v1, v2) {
  848. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0])
  849. + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  850. }
  851. var dist = distance;
  852. function distanceSquare(v1, v2) {
  853. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  854. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  855. }
  856. var distSquare = distanceSquare;
  857. function negate(out, v) {
  858. out[0] = -v[0];
  859. out[1] = -v[1];
  860. return out;
  861. }
  862. function lerp(out, v1, v2, t) {
  863. out[0] = v1[0] + t * (v2[0] - v1[0]);
  864. out[1] = v1[1] + t * (v2[1] - v1[1]);
  865. return out;
  866. }
  867. function applyTransform(out, v, m) {
  868. var x = v[0];
  869. var y = v[1];
  870. out[0] = m[0] * x + m[2] * y + m[4];
  871. out[1] = m[1] * x + m[3] * y + m[5];
  872. return out;
  873. }
  874. function min(out, v1, v2) {
  875. out[0] = Math.min(v1[0], v2[0]);
  876. out[1] = Math.min(v1[1], v2[1]);
  877. return out;
  878. }
  879. function max(out, v1, v2) {
  880. out[0] = Math.max(v1[0], v2[0]);
  881. out[1] = Math.max(v1[1], v2[1]);
  882. return out;
  883. }
  884. var vector = /*#__PURE__*/Object.freeze({
  885. __proto__: null,
  886. create: create,
  887. copy: copy,
  888. clone: clone$1,
  889. set: set,
  890. add: add,
  891. scaleAndAdd: scaleAndAdd,
  892. sub: sub,
  893. len: len,
  894. length: length,
  895. lenSquare: lenSquare,
  896. lengthSquare: lengthSquare,
  897. mul: mul,
  898. div: div,
  899. dot: dot,
  900. scale: scale,
  901. normalize: normalize,
  902. distance: distance,
  903. dist: dist,
  904. distanceSquare: distanceSquare,
  905. distSquare: distSquare,
  906. negate: negate,
  907. lerp: lerp,
  908. applyTransform: applyTransform,
  909. min: min,
  910. max: max
  911. });
  912. var Param = (function () {
  913. function Param(target, e) {
  914. this.target = target;
  915. this.topTarget = e && e.topTarget;
  916. }
  917. return Param;
  918. }());
  919. var Draggable = (function () {
  920. function Draggable(handler) {
  921. this.handler = handler;
  922. handler.on('mousedown', this._dragStart, this);
  923. handler.on('mousemove', this._drag, this);
  924. handler.on('mouseup', this._dragEnd, this);
  925. }
  926. Draggable.prototype._dragStart = function (e) {
  927. var draggingTarget = e.target;
  928. while (draggingTarget && !draggingTarget.draggable) {
  929. draggingTarget = draggingTarget.parent || draggingTarget.__hostTarget;
  930. }
  931. if (draggingTarget) {
  932. this._draggingTarget = draggingTarget;
  933. draggingTarget.dragging = true;
  934. this._x = e.offsetX;
  935. this._y = e.offsetY;
  936. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragstart', e.event);
  937. }
  938. };
  939. Draggable.prototype._drag = function (e) {
  940. var draggingTarget = this._draggingTarget;
  941. if (draggingTarget) {
  942. var x = e.offsetX;
  943. var y = e.offsetY;
  944. var dx = x - this._x;
  945. var dy = y - this._y;
  946. this._x = x;
  947. this._y = y;
  948. draggingTarget.drift(dx, dy, e);
  949. this.handler.dispatchToElement(new Param(draggingTarget, e), 'drag', e.event);
  950. var dropTarget = this.handler.findHover(x, y, draggingTarget).target;
  951. var lastDropTarget = this._dropTarget;
  952. this._dropTarget = dropTarget;
  953. if (draggingTarget !== dropTarget) {
  954. if (lastDropTarget && dropTarget !== lastDropTarget) {
  955. this.handler.dispatchToElement(new Param(lastDropTarget, e), 'dragleave', e.event);
  956. }
  957. if (dropTarget && dropTarget !== lastDropTarget) {
  958. this.handler.dispatchToElement(new Param(dropTarget, e), 'dragenter', e.event);
  959. }
  960. }
  961. }
  962. };
  963. Draggable.prototype._dragEnd = function (e) {
  964. var draggingTarget = this._draggingTarget;
  965. if (draggingTarget) {
  966. draggingTarget.dragging = false;
  967. }
  968. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragend', e.event);
  969. if (this._dropTarget) {
  970. this.handler.dispatchToElement(new Param(this._dropTarget, e), 'drop', e.event);
  971. }
  972. this._draggingTarget = null;
  973. this._dropTarget = null;
  974. };
  975. return Draggable;
  976. }());
  977. var Eventful = (function () {
  978. function Eventful(eventProcessors) {
  979. if (eventProcessors) {
  980. this._$eventProcessor = eventProcessors;
  981. }
  982. }
  983. Eventful.prototype.on = function (event, query, handler, context) {
  984. if (!this._$handlers) {
  985. this._$handlers = {};
  986. }
  987. var _h = this._$handlers;
  988. if (typeof query === 'function') {
  989. context = handler;
  990. handler = query;
  991. query = null;
  992. }
  993. if (!handler || !event) {
  994. return this;
  995. }
  996. var eventProcessor = this._$eventProcessor;
  997. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  998. query = eventProcessor.normalizeQuery(query);
  999. }
  1000. if (!_h[event]) {
  1001. _h[event] = [];
  1002. }
  1003. for (var i = 0; i < _h[event].length; i++) {
  1004. if (_h[event][i].h === handler) {
  1005. return this;
  1006. }
  1007. }
  1008. var wrap = {
  1009. h: handler,
  1010. query: query,
  1011. ctx: (context || this),
  1012. callAtLast: handler.zrEventfulCallAtLast
  1013. };
  1014. var lastIndex = _h[event].length - 1;
  1015. var lastWrap = _h[event][lastIndex];
  1016. (lastWrap && lastWrap.callAtLast)
  1017. ? _h[event].splice(lastIndex, 0, wrap)
  1018. : _h[event].push(wrap);
  1019. return this;
  1020. };
  1021. Eventful.prototype.isSilent = function (eventName) {
  1022. var _h = this._$handlers;
  1023. return !_h || !_h[eventName] || !_h[eventName].length;
  1024. };
  1025. Eventful.prototype.off = function (eventType, handler) {
  1026. var _h = this._$handlers;
  1027. if (!_h) {
  1028. return this;
  1029. }
  1030. if (!eventType) {
  1031. this._$handlers = {};
  1032. return this;
  1033. }
  1034. if (handler) {
  1035. if (_h[eventType]) {
  1036. var newList = [];
  1037. for (var i = 0, l = _h[eventType].length; i < l; i++) {
  1038. if (_h[eventType][i].h !== handler) {
  1039. newList.push(_h[eventType][i]);
  1040. }
  1041. }
  1042. _h[eventType] = newList;
  1043. }
  1044. if (_h[eventType] && _h[eventType].length === 0) {
  1045. delete _h[eventType];
  1046. }
  1047. }
  1048. else {
  1049. delete _h[eventType];
  1050. }
  1051. return this;
  1052. };
  1053. Eventful.prototype.trigger = function (eventType) {
  1054. var args = [];
  1055. for (var _i = 1; _i < arguments.length; _i++) {
  1056. args[_i - 1] = arguments[_i];
  1057. }
  1058. if (!this._$handlers) {
  1059. return this;
  1060. }
  1061. var _h = this._$handlers[eventType];
  1062. var eventProcessor = this._$eventProcessor;
  1063. if (_h) {
  1064. var argLen = args.length;
  1065. var len = _h.length;
  1066. for (var i = 0; i < len; i++) {
  1067. var hItem = _h[i];
  1068. if (eventProcessor
  1069. && eventProcessor.filter
  1070. && hItem.query != null
  1071. && !eventProcessor.filter(eventType, hItem.query)) {
  1072. continue;
  1073. }
  1074. switch (argLen) {
  1075. case 0:
  1076. hItem.h.call(hItem.ctx);
  1077. break;
  1078. case 1:
  1079. hItem.h.call(hItem.ctx, args[0]);
  1080. break;
  1081. case 2:
  1082. hItem.h.call(hItem.ctx, args[0], args[1]);
  1083. break;
  1084. default:
  1085. hItem.h.apply(hItem.ctx, args);
  1086. break;
  1087. }
  1088. }
  1089. }
  1090. eventProcessor && eventProcessor.afterTrigger
  1091. && eventProcessor.afterTrigger(eventType);
  1092. return this;
  1093. };
  1094. Eventful.prototype.triggerWithContext = function (type) {
  1095. var args = [];
  1096. for (var _i = 1; _i < arguments.length; _i++) {
  1097. args[_i - 1] = arguments[_i];
  1098. }
  1099. if (!this._$handlers) {
  1100. return this;
  1101. }
  1102. var _h = this._$handlers[type];
  1103. var eventProcessor = this._$eventProcessor;
  1104. if (_h) {
  1105. var argLen = args.length;
  1106. var ctx = args[argLen - 1];
  1107. var len = _h.length;
  1108. for (var i = 0; i < len; i++) {
  1109. var hItem = _h[i];
  1110. if (eventProcessor
  1111. && eventProcessor.filter
  1112. && hItem.query != null
  1113. && !eventProcessor.filter(type, hItem.query)) {
  1114. continue;
  1115. }
  1116. switch (argLen) {
  1117. case 0:
  1118. hItem.h.call(ctx);
  1119. break;
  1120. case 1:
  1121. hItem.h.call(ctx, args[0]);
  1122. break;
  1123. case 2:
  1124. hItem.h.call(ctx, args[0], args[1]);
  1125. break;
  1126. default:
  1127. hItem.h.apply(ctx, args.slice(1, argLen - 1));
  1128. break;
  1129. }
  1130. }
  1131. }
  1132. eventProcessor && eventProcessor.afterTrigger
  1133. && eventProcessor.afterTrigger(type);
  1134. return this;
  1135. };
  1136. return Eventful;
  1137. }());
  1138. var LN2 = Math.log(2);
  1139. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1140. var cacheKey = rowMask + '-' + colMask;
  1141. var fullRank = rows.length;
  1142. if (detCache.hasOwnProperty(cacheKey)) {
  1143. return detCache[cacheKey];
  1144. }
  1145. if (rank === 1) {
  1146. var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);
  1147. return rows[rowStart][colStart];
  1148. }
  1149. var subRowMask = rowMask | (1 << rowStart);
  1150. var subRowStart = rowStart + 1;
  1151. while (rowMask & (1 << subRowStart)) {
  1152. subRowStart++;
  1153. }
  1154. var sum = 0;
  1155. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1156. var colTag = 1 << j;
  1157. if (!(colTag & colMask)) {
  1158. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]
  1159. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1160. colLocalIdx++;
  1161. }
  1162. }
  1163. detCache[cacheKey] = sum;
  1164. return sum;
  1165. }
  1166. function buildTransformer(src, dest) {
  1167. var mA = [
  1168. [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],
  1169. [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],
  1170. [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],
  1171. [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],
  1172. [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],
  1173. [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],
  1174. [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],
  1175. [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]
  1176. ];
  1177. var detCache = {};
  1178. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1179. if (det === 0) {
  1180. return;
  1181. }
  1182. var vh = [];
  1183. for (var i = 0; i < 8; i++) {
  1184. for (var j = 0; j < 8; j++) {
  1185. vh[j] == null && (vh[j] = 0);
  1186. vh[j] += ((i + j) % 2 ? -1 : 1)
  1187. * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)
  1188. / det * dest[i];
  1189. }
  1190. }
  1191. return function (out, srcPointX, srcPointY) {
  1192. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1193. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1194. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1195. };
  1196. }
  1197. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1198. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1199. if (el.getBoundingClientRect && env.domSupported && !isCanvasEl(el)) {
  1200. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1201. var markers = prepareCoordMarkers(el, saved);
  1202. var transformer = preparePointerTransformer(markers, saved, inverse);
  1203. if (transformer) {
  1204. transformer(out, inX, inY);
  1205. return true;
  1206. }
  1207. }
  1208. return false;
  1209. }
  1210. function prepareCoordMarkers(el, saved) {
  1211. var markers = saved.markers;
  1212. if (markers) {
  1213. return markers;
  1214. }
  1215. markers = saved.markers = [];
  1216. var propLR = ['left', 'right'];
  1217. var propTB = ['top', 'bottom'];
  1218. for (var i = 0; i < 4; i++) {
  1219. var marker = document.createElement('div');
  1220. var stl = marker.style;
  1221. var idxLR = i % 2;
  1222. var idxTB = (i >> 1) % 2;
  1223. stl.cssText = [
  1224. 'position: absolute',
  1225. 'visibility: hidden',
  1226. 'padding: 0',
  1227. 'margin: 0',
  1228. 'border-width: 0',
  1229. 'user-select: none',
  1230. 'width:0',
  1231. 'height:0',
  1232. propLR[idxLR] + ':0',
  1233. propTB[idxTB] + ':0',
  1234. propLR[1 - idxLR] + ':auto',
  1235. propTB[1 - idxTB] + ':auto',
  1236. ''
  1237. ].join('!important;');
  1238. el.appendChild(marker);
  1239. markers.push(marker);
  1240. }
  1241. return markers;
  1242. }
  1243. function preparePointerTransformer(markers, saved, inverse) {
  1244. var transformerName = inverse ? 'invTrans' : 'trans';
  1245. var transformer = saved[transformerName];
  1246. var oldSrcCoords = saved.srcCoords;
  1247. var srcCoords = [];
  1248. var destCoords = [];
  1249. var oldCoordTheSame = true;
  1250. for (var i = 0; i < 4; i++) {
  1251. var rect = markers[i].getBoundingClientRect();
  1252. var ii = 2 * i;
  1253. var x = rect.left;
  1254. var y = rect.top;
  1255. srcCoords.push(x, y);
  1256. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1257. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1258. }
  1259. return (oldCoordTheSame && transformer)
  1260. ? transformer
  1261. : (saved.srcCoords = srcCoords,
  1262. saved[transformerName] = inverse
  1263. ? buildTransformer(destCoords, srcCoords)
  1264. : buildTransformer(srcCoords, destCoords));
  1265. }
  1266. function isCanvasEl(el) {
  1267. return el.nodeName.toUpperCase() === 'CANVAS';
  1268. }
  1269. var replaceReg = /([&<>"'])/g;
  1270. var replaceMap = {
  1271. '&': '&amp;',
  1272. '<': '&lt;',
  1273. '>': '&gt;',
  1274. '"': '&quot;',
  1275. '\'': '&#39;'
  1276. };
  1277. function encodeHTML(source) {
  1278. return source == null
  1279. ? ''
  1280. : (source + '').replace(replaceReg, function (str, c) {
  1281. return replaceMap[c];
  1282. });
  1283. }
  1284. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1285. var _calcOut = [];
  1286. var firefoxNotSupportOffsetXY = env.browser.firefox
  1287. && +env.browser.version.split('.')[0] < 39;
  1288. function clientToLocal(el, e, out, calculate) {
  1289. out = out || {};
  1290. if (calculate) {
  1291. calculateZrXY(el, e, out);
  1292. }
  1293. else if (firefoxNotSupportOffsetXY
  1294. && e.layerX != null
  1295. && e.layerX !== e.offsetX) {
  1296. out.zrX = e.layerX;
  1297. out.zrY = e.layerY;
  1298. }
  1299. else if (e.offsetX != null) {
  1300. out.zrX = e.offsetX;
  1301. out.zrY = e.offsetY;
  1302. }
  1303. else {
  1304. calculateZrXY(el, e, out);
  1305. }
  1306. return out;
  1307. }
  1308. function calculateZrXY(el, e, out) {
  1309. if (env.domSupported && el.getBoundingClientRect) {
  1310. var ex = e.clientX;
  1311. var ey = e.clientY;
  1312. if (isCanvasEl(el)) {
  1313. var box = el.getBoundingClientRect();
  1314. out.zrX = ex - box.left;
  1315. out.zrY = ey - box.top;
  1316. return;
  1317. }
  1318. else {
  1319. if (transformCoordWithViewport(_calcOut, el, ex, ey)) {
  1320. out.zrX = _calcOut[0];
  1321. out.zrY = _calcOut[1];
  1322. return;
  1323. }
  1324. }
  1325. }
  1326. out.zrX = out.zrY = 0;
  1327. }
  1328. function getNativeEvent(e) {
  1329. return e
  1330. || window.event;
  1331. }
  1332. function normalizeEvent(el, e, calculate) {
  1333. e = getNativeEvent(e);
  1334. if (e.zrX != null) {
  1335. return e;
  1336. }
  1337. var eventType = e.type;
  1338. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1339. if (!isTouch) {
  1340. clientToLocal(el, e, e, calculate);
  1341. var wheelDelta = getWheelDeltaMayPolyfill(e);
  1342. e.zrDelta = wheelDelta ? wheelDelta / 120 : -(e.detail || 0) / 3;
  1343. }
  1344. else {
  1345. var touch = eventType !== 'touchend'
  1346. ? e.targetTouches[0]
  1347. : e.changedTouches[0];
  1348. touch && clientToLocal(el, touch, e, calculate);
  1349. }
  1350. var button = e.button;
  1351. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1352. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1353. }
  1354. return e;
  1355. }
  1356. function getWheelDeltaMayPolyfill(e) {
  1357. var rawWheelDelta = e.wheelDelta;
  1358. if (rawWheelDelta) {
  1359. return rawWheelDelta;
  1360. }
  1361. var deltaX = e.deltaX;
  1362. var deltaY = e.deltaY;
  1363. if (deltaX == null || deltaY == null) {
  1364. return rawWheelDelta;
  1365. }
  1366. var delta = deltaY !== 0 ? Math.abs(deltaY) : Math.abs(deltaX);
  1367. var sign = deltaY > 0 ? -1
  1368. : deltaY < 0 ? 1
  1369. : deltaX > 0 ? -1
  1370. : 1;
  1371. return 3 * delta * sign;
  1372. }
  1373. function addEventListener(el, name, handler, opt) {
  1374. el.addEventListener(name, handler, opt);
  1375. }
  1376. function removeEventListener(el, name, handler, opt) {
  1377. el.removeEventListener(name, handler, opt);
  1378. }
  1379. var stop = function (e) {
  1380. e.preventDefault();
  1381. e.stopPropagation();
  1382. e.cancelBubble = true;
  1383. };
  1384. var GestureMgr = (function () {
  1385. function GestureMgr() {
  1386. this._track = [];
  1387. }
  1388. GestureMgr.prototype.recognize = function (event, target, root) {
  1389. this._doTrack(event, target, root);
  1390. return this._recognize(event);
  1391. };
  1392. GestureMgr.prototype.clear = function () {
  1393. this._track.length = 0;
  1394. return this;
  1395. };
  1396. GestureMgr.prototype._doTrack = function (event, target, root) {
  1397. var touches = event.touches;
  1398. if (!touches) {
  1399. return;
  1400. }
  1401. var trackItem = {
  1402. points: [],
  1403. touches: [],
  1404. target: target,
  1405. event: event
  1406. };
  1407. for (var i = 0, len = touches.length; i < len; i++) {
  1408. var touch = touches[i];
  1409. var pos = clientToLocal(root, touch, {});
  1410. trackItem.points.push([pos.zrX, pos.zrY]);
  1411. trackItem.touches.push(touch);
  1412. }
  1413. this._track.push(trackItem);
  1414. };
  1415. GestureMgr.prototype._recognize = function (event) {
  1416. for (var eventName in recognizers) {
  1417. if (recognizers.hasOwnProperty(eventName)) {
  1418. var gestureInfo = recognizers[eventName](this._track, event);
  1419. if (gestureInfo) {
  1420. return gestureInfo;
  1421. }
  1422. }
  1423. }
  1424. };
  1425. return GestureMgr;
  1426. }());
  1427. function dist$1(pointPair) {
  1428. var dx = pointPair[1][0] - pointPair[0][0];
  1429. var dy = pointPair[1][1] - pointPair[0][1];
  1430. return Math.sqrt(dx * dx + dy * dy);
  1431. }
  1432. function center(pointPair) {
  1433. return [
  1434. (pointPair[0][0] + pointPair[1][0]) / 2,
  1435. (pointPair[0][1] + pointPair[1][1]) / 2
  1436. ];
  1437. }
  1438. var recognizers = {
  1439. pinch: function (tracks, event) {
  1440. var trackLen = tracks.length;
  1441. if (!trackLen) {
  1442. return;
  1443. }
  1444. var pinchEnd = (tracks[trackLen - 1] || {}).points;
  1445. var pinchPre = (tracks[trackLen - 2] || {}).points || pinchEnd;
  1446. if (pinchPre
  1447. && pinchPre.length > 1
  1448. && pinchEnd
  1449. && pinchEnd.length > 1) {
  1450. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1451. !isFinite(pinchScale) && (pinchScale = 1);
  1452. event.pinchScale = pinchScale;
  1453. var pinchCenter = center(pinchEnd);
  1454. event.pinchX = pinchCenter[0];
  1455. event.pinchY = pinchCenter[1];
  1456. return {
  1457. type: 'pinch',
  1458. target: tracks[0].target,
  1459. event: event
  1460. };
  1461. }
  1462. }
  1463. };
  1464. function create$1() {
  1465. return [1, 0, 0, 1, 0, 0];
  1466. }
  1467. function identity(out) {
  1468. out[0] = 1;
  1469. out[1] = 0;
  1470. out[2] = 0;
  1471. out[3] = 1;
  1472. out[4] = 0;
  1473. out[5] = 0;
  1474. return out;
  1475. }
  1476. function copy$1(out, m) {
  1477. out[0] = m[0];
  1478. out[1] = m[1];
  1479. out[2] = m[2];
  1480. out[3] = m[3];
  1481. out[4] = m[4];
  1482. out[5] = m[5];
  1483. return out;
  1484. }
  1485. function mul$1(out, m1, m2) {
  1486. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  1487. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  1488. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  1489. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  1490. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1491. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1492. out[0] = out0;
  1493. out[1] = out1;
  1494. out[2] = out2;
  1495. out[3] = out3;
  1496. out[4] = out4;
  1497. out[5] = out5;
  1498. return out;
  1499. }
  1500. function translate(out, a, v) {
  1501. out[0] = a[0];
  1502. out[1] = a[1];
  1503. out[2] = a[2];
  1504. out[3] = a[3];
  1505. out[4] = a[4] + v[0];
  1506. out[5] = a[5] + v[1];
  1507. return out;
  1508. }
  1509. function rotate(out, a, rad) {
  1510. var aa = a[0];
  1511. var ac = a[2];
  1512. var atx = a[4];
  1513. var ab = a[1];
  1514. var ad = a[3];
  1515. var aty = a[5];
  1516. var st = Math.sin(rad);
  1517. var ct = Math.cos(rad);
  1518. out[0] = aa * ct + ab * st;
  1519. out[1] = -aa * st + ab * ct;
  1520. out[2] = ac * ct + ad * st;
  1521. out[3] = -ac * st + ct * ad;
  1522. out[4] = ct * atx + st * aty;
  1523. out[5] = ct * aty - st * atx;
  1524. return out;
  1525. }
  1526. function scale$1(out, a, v) {
  1527. var vx = v[0];
  1528. var vy = v[1];
  1529. out[0] = a[0] * vx;
  1530. out[1] = a[1] * vy;
  1531. out[2] = a[2] * vx;
  1532. out[3] = a[3] * vy;
  1533. out[4] = a[4] * vx;
  1534. out[5] = a[5] * vy;
  1535. return out;
  1536. }
  1537. function invert(out, a) {
  1538. var aa = a[0];
  1539. var ac = a[2];
  1540. var atx = a[4];
  1541. var ab = a[1];
  1542. var ad = a[3];
  1543. var aty = a[5];
  1544. var det = aa * ad - ab * ac;
  1545. if (!det) {
  1546. return null;
  1547. }
  1548. det = 1.0 / det;
  1549. out[0] = ad * det;
  1550. out[1] = -ab * det;
  1551. out[2] = -ac * det;
  1552. out[3] = aa * det;
  1553. out[4] = (ac * aty - ad * atx) * det;
  1554. out[5] = (ab * atx - aa * aty) * det;
  1555. return out;
  1556. }
  1557. function clone$2(a) {
  1558. var b = create$1();
  1559. copy$1(b, a);
  1560. return b;
  1561. }
  1562. var matrix = /*#__PURE__*/Object.freeze({
  1563. __proto__: null,
  1564. create: create$1,
  1565. identity: identity,
  1566. copy: copy$1,
  1567. mul: mul$1,
  1568. translate: translate,
  1569. rotate: rotate,
  1570. scale: scale$1,
  1571. invert: invert,
  1572. clone: clone$2
  1573. });
  1574. var Point = (function () {
  1575. function Point(x, y) {
  1576. this.x = x || 0;
  1577. this.y = y || 0;
  1578. }
  1579. Point.prototype.copy = function (other) {
  1580. this.x = other.x;
  1581. this.y = other.y;
  1582. return this;
  1583. };
  1584. Point.prototype.clone = function () {
  1585. return new Point(this.x, this.y);
  1586. };
  1587. Point.prototype.set = function (x, y) {
  1588. this.x = x;
  1589. this.y = y;
  1590. return this;
  1591. };
  1592. Point.prototype.equal = function (other) {
  1593. return other.x === this.x && other.y === this.y;
  1594. };
  1595. Point.prototype.add = function (other) {
  1596. this.x += other.x;
  1597. this.y += other.y;
  1598. return this;
  1599. };
  1600. Point.prototype.scale = function (scalar) {
  1601. this.x *= scalar;
  1602. this.y *= scalar;
  1603. };
  1604. Point.prototype.scaleAndAdd = function (other, scalar) {
  1605. this.x += other.x * scalar;
  1606. this.y += other.y * scalar;
  1607. };
  1608. Point.prototype.sub = function (other) {
  1609. this.x -= other.x;
  1610. this.y -= other.y;
  1611. return this;
  1612. };
  1613. Point.prototype.dot = function (other) {
  1614. return this.x * other.x + this.y * other.y;
  1615. };
  1616. Point.prototype.len = function () {
  1617. return Math.sqrt(this.x * this.x + this.y * this.y);
  1618. };
  1619. Point.prototype.lenSquare = function () {
  1620. return this.x * this.x + this.y * this.y;
  1621. };
  1622. Point.prototype.normalize = function () {
  1623. var len = this.len();
  1624. this.x /= len;
  1625. this.y /= len;
  1626. return this;
  1627. };
  1628. Point.prototype.distance = function (other) {
  1629. var dx = this.x - other.x;
  1630. var dy = this.y - other.y;
  1631. return Math.sqrt(dx * dx + dy * dy);
  1632. };
  1633. Point.prototype.distanceSquare = function (other) {
  1634. var dx = this.x - other.x;
  1635. var dy = this.y - other.y;
  1636. return dx * dx + dy * dy;
  1637. };
  1638. Point.prototype.negate = function () {
  1639. this.x = -this.x;
  1640. this.y = -this.y;
  1641. return this;
  1642. };
  1643. Point.prototype.transform = function (m) {
  1644. if (!m) {
  1645. return;
  1646. }
  1647. var x = this.x;
  1648. var y = this.y;
  1649. this.x = m[0] * x + m[2] * y + m[4];
  1650. this.y = m[1] * x + m[3] * y + m[5];
  1651. return this;
  1652. };
  1653. Point.prototype.toArray = function (out) {
  1654. out[0] = this.x;
  1655. out[1] = this.y;
  1656. return out;
  1657. };
  1658. Point.prototype.fromArray = function (input) {
  1659. this.x = input[0];
  1660. this.y = input[1];
  1661. };
  1662. Point.set = function (p, x, y) {
  1663. p.x = x;
  1664. p.y = y;
  1665. };
  1666. Point.copy = function (p, p2) {
  1667. p.x = p2.x;
  1668. p.y = p2.y;
  1669. };
  1670. Point.len = function (p) {
  1671. return Math.sqrt(p.x * p.x + p.y * p.y);
  1672. };
  1673. Point.lenSquare = function (p) {
  1674. return p.x * p.x + p.y * p.y;
  1675. };
  1676. Point.dot = function (p0, p1) {
  1677. return p0.x * p1.x + p0.y * p1.y;
  1678. };
  1679. Point.add = function (out, p0, p1) {
  1680. out.x = p0.x + p1.x;
  1681. out.y = p0.y + p1.y;
  1682. };
  1683. Point.sub = function (out, p0, p1) {
  1684. out.x = p0.x - p1.x;
  1685. out.y = p0.y - p1.y;
  1686. };
  1687. Point.scale = function (out, p0, scalar) {
  1688. out.x = p0.x * scalar;
  1689. out.y = p0.y * scalar;
  1690. };
  1691. Point.scaleAndAdd = function (out, p0, p1, scalar) {
  1692. out.x = p0.x + p1.x * scalar;
  1693. out.y = p0.y + p1.y * scalar;
  1694. };
  1695. Point.lerp = function (out, p0, p1, t) {
  1696. var onet = 1 - t;
  1697. out.x = onet * p0.x + t * p1.x;
  1698. out.y = onet * p0.y + t * p1.y;
  1699. };
  1700. return Point;
  1701. }());
  1702. var mathMin = Math.min;
  1703. var mathMax = Math.max;
  1704. var lt = new Point();
  1705. var rb = new Point();
  1706. var lb = new Point();
  1707. var rt = new Point();
  1708. var minTv = new Point();
  1709. var maxTv = new Point();
  1710. var BoundingRect = (function () {
  1711. function BoundingRect(x, y, width, height) {
  1712. if (width < 0) {
  1713. x = x + width;
  1714. width = -width;
  1715. }
  1716. if (height < 0) {
  1717. y = y + height;
  1718. height = -height;
  1719. }
  1720. this.x = x;
  1721. this.y = y;
  1722. this.width = width;
  1723. this.height = height;
  1724. }
  1725. BoundingRect.prototype.union = function (other) {
  1726. var x = mathMin(other.x, this.x);
  1727. var y = mathMin(other.y, this.y);
  1728. if (isFinite(this.x) && isFinite(this.width)) {
  1729. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  1730. }
  1731. else {
  1732. this.width = other.width;
  1733. }
  1734. if (isFinite(this.y) && isFinite(this.height)) {
  1735. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  1736. }
  1737. else {
  1738. this.height = other.height;
  1739. }
  1740. this.x = x;
  1741. this.y = y;
  1742. };
  1743. BoundingRect.prototype.applyTransform = function (m) {
  1744. BoundingRect.applyTransform(this, this, m);
  1745. };
  1746. BoundingRect.prototype.calculateTransform = function (b) {
  1747. var a = this;
  1748. var sx = b.width / a.width;
  1749. var sy = b.height / a.height;
  1750. var m = create$1();
  1751. translate(m, m, [-a.x, -a.y]);
  1752. scale$1(m, m, [sx, sy]);
  1753. translate(m, m, [b.x, b.y]);
  1754. return m;
  1755. };
  1756. BoundingRect.prototype.intersect = function (b, mtv) {
  1757. if (!b) {
  1758. return false;
  1759. }
  1760. if (!(b instanceof BoundingRect)) {
  1761. b = BoundingRect.create(b);
  1762. }
  1763. var a = this;
  1764. var ax0 = a.x;
  1765. var ax1 = a.x + a.width;
  1766. var ay0 = a.y;
  1767. var ay1 = a.y + a.height;
  1768. var bx0 = b.x;
  1769. var bx1 = b.x + b.width;
  1770. var by0 = b.y;
  1771. var by1 = b.y + b.height;
  1772. var overlap = !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  1773. if (mtv) {
  1774. var dMin = Infinity;
  1775. var dMax = 0;
  1776. var d0 = Math.abs(ax1 - bx0);
  1777. var d1 = Math.abs(bx1 - ax0);
  1778. var d2 = Math.abs(ay1 - by0);
  1779. var d3 = Math.abs(by1 - ay0);
  1780. var dx = Math.min(d0, d1);
  1781. var dy = Math.min(d2, d3);
  1782. if (ax1 < bx0 || bx1 < ax0) {
  1783. if (dx > dMax) {
  1784. dMax = dx;
  1785. if (d0 < d1) {
  1786. Point.set(maxTv, -d0, 0);
  1787. }
  1788. else {
  1789. Point.set(maxTv, d1, 0);
  1790. }
  1791. }
  1792. }
  1793. else {
  1794. if (dx < dMin) {
  1795. dMin = dx;
  1796. if (d0 < d1) {
  1797. Point.set(minTv, d0, 0);
  1798. }
  1799. else {
  1800. Point.set(minTv, -d1, 0);
  1801. }
  1802. }
  1803. }
  1804. if (ay1 < by0 || by1 < ay0) {
  1805. if (dy > dMax) {
  1806. dMax = dy;
  1807. if (d2 < d3) {
  1808. Point.set(maxTv, 0, -d2);
  1809. }
  1810. else {
  1811. Point.set(maxTv, 0, d3);
  1812. }
  1813. }
  1814. }
  1815. else {
  1816. if (dx < dMin) {
  1817. dMin = dx;
  1818. if (d2 < d3) {
  1819. Point.set(minTv, 0, d2);
  1820. }
  1821. else {
  1822. Point.set(minTv, 0, -d3);
  1823. }
  1824. }
  1825. }
  1826. }
  1827. if (mtv) {
  1828. Point.copy(mtv, overlap ? minTv : maxTv);
  1829. }
  1830. return overlap;
  1831. };
  1832. BoundingRect.prototype.contain = function (x, y) {
  1833. var rect = this;
  1834. return x >= rect.x
  1835. && x <= (rect.x + rect.width)
  1836. && y >= rect.y
  1837. && y <= (rect.y + rect.height);
  1838. };
  1839. BoundingRect.prototype.clone = function () {
  1840. return new BoundingRect(this.x, this.y, this.width, this.height);
  1841. };
  1842. BoundingRect.prototype.copy = function (other) {
  1843. BoundingRect.copy(this, other);
  1844. };
  1845. BoundingRect.prototype.plain = function () {
  1846. return {
  1847. x: this.x,
  1848. y: this.y,
  1849. width: this.width,
  1850. height: this.height
  1851. };
  1852. };
  1853. BoundingRect.prototype.isFinite = function () {
  1854. return isFinite(this.x)
  1855. && isFinite(this.y)
  1856. && isFinite(this.width)
  1857. && isFinite(this.height);
  1858. };
  1859. BoundingRect.prototype.isZero = function () {
  1860. return this.width === 0 || this.height === 0;
  1861. };
  1862. BoundingRect.create = function (rect) {
  1863. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  1864. };
  1865. BoundingRect.copy = function (target, source) {
  1866. target.x = source.x;
  1867. target.y = source.y;
  1868. target.width = source.width;
  1869. target.height = source.height;
  1870. };
  1871. BoundingRect.applyTransform = function (target, source, m) {
  1872. if (!m) {
  1873. if (target !== source) {
  1874. BoundingRect.copy(target, source);
  1875. }
  1876. return;
  1877. }
  1878. if (m[1] < 1e-5 && m[1] > -1e-5 && m[2] < 1e-5 && m[2] > -1e-5) {
  1879. var sx = m[0];
  1880. var sy = m[3];
  1881. var tx = m[4];
  1882. var ty = m[5];
  1883. target.x = source.x * sx + tx;
  1884. target.y = source.y * sy + ty;
  1885. target.width = source.width * sx;
  1886. target.height = source.height * sy;
  1887. if (target.width < 0) {
  1888. target.x += target.width;
  1889. target.width = -target.width;
  1890. }
  1891. if (target.height < 0) {
  1892. target.y += target.height;
  1893. target.height = -target.height;
  1894. }
  1895. return;
  1896. }
  1897. lt.x = lb.x = source.x;
  1898. lt.y = rt.y = source.y;
  1899. rb.x = rt.x = source.x + source.width;
  1900. rb.y = lb.y = source.y + source.height;
  1901. lt.transform(m);
  1902. rt.transform(m);
  1903. rb.transform(m);
  1904. lb.transform(m);
  1905. target.x = mathMin(lt.x, rb.x, lb.x, rt.x);
  1906. target.y = mathMin(lt.y, rb.y, lb.y, rt.y);
  1907. var maxX = mathMax(lt.x, rb.x, lb.x, rt.x);
  1908. var maxY = mathMax(lt.y, rb.y, lb.y, rt.y);
  1909. target.width = maxX - target.x;
  1910. target.height = maxY - target.y;
  1911. };
  1912. return BoundingRect;
  1913. }());
  1914. var SILENT = 'silent';
  1915. function makeEventPacket(eveType, targetInfo, event) {
  1916. return {
  1917. type: eveType,
  1918. event: event,
  1919. target: targetInfo.target,
  1920. topTarget: targetInfo.topTarget,
  1921. cancelBubble: false,
  1922. offsetX: event.zrX,
  1923. offsetY: event.zrY,
  1924. gestureEvent: event.gestureEvent,
  1925. pinchX: event.pinchX,
  1926. pinchY: event.pinchY,
  1927. pinchScale: event.pinchScale,
  1928. wheelDelta: event.zrDelta,
  1929. zrByTouch: event.zrByTouch,
  1930. which: event.which,
  1931. stop: stopEvent
  1932. };
  1933. }
  1934. function stopEvent() {
  1935. stop(this.event);
  1936. }
  1937. var EmptyProxy = (function (_super) {
  1938. __extends(EmptyProxy, _super);
  1939. function EmptyProxy() {
  1940. var _this = _super !== null && _super.apply(this, arguments) || this;
  1941. _this.handler = null;
  1942. return _this;
  1943. }
  1944. EmptyProxy.prototype.dispose = function () { };
  1945. EmptyProxy.prototype.setCursor = function () { };
  1946. return EmptyProxy;
  1947. }(Eventful));
  1948. var HoveredResult = (function () {
  1949. function HoveredResult(x, y) {
  1950. this.x = x;
  1951. this.y = y;
  1952. }
  1953. return HoveredResult;
  1954. }());
  1955. var handlerNames = [
  1956. 'click', 'dblclick', 'mousewheel', 'mouseout',
  1957. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  1958. ];
  1959. var tmpRect = new BoundingRect(0, 0, 0, 0);
  1960. var Handler = (function (_super) {
  1961. __extends(Handler, _super);
  1962. function Handler(storage, painter, proxy, painterRoot, pointerSize) {
  1963. var _this = _super.call(this) || this;
  1964. _this._hovered = new HoveredResult(0, 0);
  1965. _this.storage = storage;
  1966. _this.painter = painter;
  1967. _this.painterRoot = painterRoot;
  1968. _this._pointerSize = pointerSize;
  1969. proxy = proxy || new EmptyProxy();
  1970. _this.proxy = null;
  1971. _this.setHandlerProxy(proxy);
  1972. _this._draggingMgr = new Draggable(_this);
  1973. return _this;
  1974. }
  1975. Handler.prototype.setHandlerProxy = function (proxy) {
  1976. if (this.proxy) {
  1977. this.proxy.dispose();
  1978. }
  1979. if (proxy) {
  1980. each(handlerNames, function (name) {
  1981. proxy.on && proxy.on(name, this[name], this);
  1982. }, this);
  1983. proxy.handler = this;
  1984. }
  1985. this.proxy = proxy;
  1986. };
  1987. Handler.prototype.mousemove = function (event) {
  1988. var x = event.zrX;
  1989. var y = event.zrY;
  1990. var isOutside = isOutsideBoundary(this, x, y);
  1991. var lastHovered = this._hovered;
  1992. var lastHoveredTarget = lastHovered.target;
  1993. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  1994. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  1995. lastHoveredTarget = lastHovered.target;
  1996. }
  1997. var hovered = this._hovered = isOutside ? new HoveredResult(x, y) : this.findHover(x, y);
  1998. var hoveredTarget = hovered.target;
  1999. var proxy = this.proxy;
  2000. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  2001. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2002. this.dispatchToElement(lastHovered, 'mouseout', event);
  2003. }
  2004. this.dispatchToElement(hovered, 'mousemove', event);
  2005. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2006. this.dispatchToElement(hovered, 'mouseover', event);
  2007. }
  2008. };
  2009. Handler.prototype.mouseout = function (event) {
  2010. var eventControl = event.zrEventControl;
  2011. if (eventControl !== 'only_globalout') {
  2012. this.dispatchToElement(this._hovered, 'mouseout', event);
  2013. }
  2014. if (eventControl !== 'no_globalout') {
  2015. this.trigger('globalout', { type: 'globalout', event: event });
  2016. }
  2017. };
  2018. Handler.prototype.resize = function () {
  2019. this._hovered = new HoveredResult(0, 0);
  2020. };
  2021. Handler.prototype.dispatch = function (eventName, eventArgs) {
  2022. var handler = this[eventName];
  2023. handler && handler.call(this, eventArgs);
  2024. };
  2025. Handler.prototype.dispose = function () {
  2026. this.proxy.dispose();
  2027. this.storage = null;
  2028. this.proxy = null;
  2029. this.painter = null;
  2030. };
  2031. Handler.prototype.setCursorStyle = function (cursorStyle) {
  2032. var proxy = this.proxy;
  2033. proxy.setCursor && proxy.setCursor(cursorStyle);
  2034. };
  2035. Handler.prototype.dispatchToElement = function (targetInfo, eventName, event) {
  2036. targetInfo = targetInfo || {};
  2037. var el = targetInfo.target;
  2038. if (el && el.silent) {
  2039. return;
  2040. }
  2041. var eventKey = ('on' + eventName);
  2042. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2043. while (el) {
  2044. el[eventKey]
  2045. && (eventPacket.cancelBubble = !!el[eventKey].call(el, eventPacket));
  2046. el.trigger(eventName, eventPacket);
  2047. el = el.__hostTarget ? el.__hostTarget : el.parent;
  2048. if (eventPacket.cancelBubble) {
  2049. break;
  2050. }
  2051. }
  2052. if (!eventPacket.cancelBubble) {
  2053. this.trigger(eventName, eventPacket);
  2054. if (this.painter && this.painter.eachOtherLayer) {
  2055. this.painter.eachOtherLayer(function (layer) {
  2056. if (typeof (layer[eventKey]) === 'function') {
  2057. layer[eventKey].call(layer, eventPacket);
  2058. }
  2059. if (layer.trigger) {
  2060. layer.trigger(eventName, eventPacket);
  2061. }
  2062. });
  2063. }
  2064. }
  2065. };
  2066. Handler.prototype.findHover = function (x, y, exclude) {
  2067. var list = this.storage.getDisplayList();
  2068. var out = new HoveredResult(x, y);
  2069. setHoverTarget(list, out, x, y, exclude);
  2070. if (this._pointerSize && !out.target) {
  2071. var candidates = [];
  2072. var pointerSize = this._pointerSize;
  2073. var targetSizeHalf = pointerSize / 2;
  2074. var pointerRect = new BoundingRect(x - targetSizeHalf, y - targetSizeHalf, pointerSize, pointerSize);
  2075. for (var i = list.length - 1; i >= 0; i--) {
  2076. var el = list[i];
  2077. if (el !== exclude
  2078. && !el.ignore
  2079. && !el.ignoreCoarsePointer
  2080. && (!el.parent || !el.parent.ignoreCoarsePointer)) {
  2081. tmpRect.copy(el.getBoundingRect());
  2082. if (el.transform) {
  2083. tmpRect.applyTransform(el.transform);
  2084. }
  2085. if (tmpRect.intersect(pointerRect)) {
  2086. candidates.push(el);
  2087. }
  2088. }
  2089. }
  2090. if (candidates.length) {
  2091. var rStep = 4;
  2092. var thetaStep = Math.PI / 12;
  2093. var PI2 = Math.PI * 2;
  2094. for (var r = 0; r < targetSizeHalf; r += rStep) {
  2095. for (var theta = 0; theta < PI2; theta += thetaStep) {
  2096. var x1 = x + r * Math.cos(theta);
  2097. var y1 = y + r * Math.sin(theta);
  2098. setHoverTarget(candidates, out, x1, y1, exclude);
  2099. if (out.target) {
  2100. return out;
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. return out;
  2107. };
  2108. Handler.prototype.processGesture = function (event, stage) {
  2109. if (!this._gestureMgr) {
  2110. this._gestureMgr = new GestureMgr();
  2111. }
  2112. var gestureMgr = this._gestureMgr;
  2113. stage === 'start' && gestureMgr.clear();
  2114. var gestureInfo = gestureMgr.recognize(event, this.findHover(event.zrX, event.zrY, null).target, this.proxy.dom);
  2115. stage === 'end' && gestureMgr.clear();
  2116. if (gestureInfo) {
  2117. var type = gestureInfo.type;
  2118. event.gestureEvent = type;
  2119. var res = new HoveredResult();
  2120. res.target = gestureInfo.target;
  2121. this.dispatchToElement(res, type, gestureInfo.event);
  2122. }
  2123. };
  2124. return Handler;
  2125. }(Eventful));
  2126. each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2127. Handler.prototype[name] = function (event) {
  2128. var x = event.zrX;
  2129. var y = event.zrY;
  2130. var isOutside = isOutsideBoundary(this, x, y);
  2131. var hovered;
  2132. var hoveredTarget;
  2133. if (name !== 'mouseup' || !isOutside) {
  2134. hovered = this.findHover(x, y);
  2135. hoveredTarget = hovered.target;
  2136. }
  2137. if (name === 'mousedown') {
  2138. this._downEl = hoveredTarget;
  2139. this._downPoint = [event.zrX, event.zrY];
  2140. this._upEl = hoveredTarget;
  2141. }
  2142. else if (name === 'mouseup') {
  2143. this._upEl = hoveredTarget;
  2144. }
  2145. else if (name === 'click') {
  2146. if (this._downEl !== this._upEl
  2147. || !this._downPoint
  2148. || dist(this._downPoint, [event.zrX, event.zrY]) > 4) {
  2149. return;
  2150. }
  2151. this._downPoint = null;
  2152. }
  2153. this.dispatchToElement(hovered, name, event);
  2154. };
  2155. });
  2156. function isHover(displayable, x, y) {
  2157. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2158. var el = displayable;
  2159. var isSilent = void 0;
  2160. var ignoreClip = false;
  2161. while (el) {
  2162. if (el.ignoreClip) {
  2163. ignoreClip = true;
  2164. }
  2165. if (!ignoreClip) {
  2166. var clipPath = el.getClipPath();
  2167. if (clipPath && !clipPath.contain(x, y)) {
  2168. return false;
  2169. }
  2170. if (el.silent) {
  2171. isSilent = true;
  2172. }
  2173. }
  2174. var hostEl = el.__hostTarget;
  2175. el = hostEl ? hostEl : el.parent;
  2176. }
  2177. return isSilent ? SILENT : true;
  2178. }
  2179. return false;
  2180. }
  2181. function setHoverTarget(list, out, x, y, exclude) {
  2182. for (var i = list.length - 1; i >= 0; i--) {
  2183. var el = list[i];
  2184. var hoverCheckResult = void 0;
  2185. if (el !== exclude
  2186. && !el.ignore
  2187. && (hoverCheckResult = isHover(el, x, y))) {
  2188. !out.topTarget && (out.topTarget = el);
  2189. if (hoverCheckResult !== SILENT) {
  2190. out.target = el;
  2191. break;
  2192. }
  2193. }
  2194. }
  2195. }
  2196. function isOutsideBoundary(handlerInstance, x, y) {
  2197. var painter = handlerInstance.painter;
  2198. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  2199. }
  2200. var DEFAULT_MIN_MERGE = 32;
  2201. var DEFAULT_MIN_GALLOPING = 7;
  2202. function minRunLength(n) {
  2203. var r = 0;
  2204. while (n >= DEFAULT_MIN_MERGE) {
  2205. r |= n & 1;
  2206. n >>= 1;
  2207. }
  2208. return n + r;
  2209. }
  2210. function makeAscendingRun(array, lo, hi, compare) {
  2211. var runHi = lo + 1;
  2212. if (runHi === hi) {
  2213. return 1;
  2214. }
  2215. if (compare(array[runHi++], array[lo]) < 0) {
  2216. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  2217. runHi++;
  2218. }
  2219. reverseRun(array, lo, runHi);
  2220. }
  2221. else {
  2222. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  2223. runHi++;
  2224. }
  2225. }
  2226. return runHi - lo;
  2227. }
  2228. function reverseRun(array, lo, hi) {
  2229. hi--;
  2230. while (lo < hi) {
  2231. var t = array[lo];
  2232. array[lo++] = array[hi];
  2233. array[hi--] = t;
  2234. }
  2235. }
  2236. function binaryInsertionSort(array, lo, hi, start, compare) {
  2237. if (start === lo) {
  2238. start++;
  2239. }
  2240. for (; start < hi; start++) {
  2241. var pivot = array[start];
  2242. var left = lo;
  2243. var right = start;
  2244. var mid;
  2245. while (left < right) {
  2246. mid = left + right >>> 1;
  2247. if (compare(pivot, array[mid]) < 0) {
  2248. right = mid;
  2249. }
  2250. else {
  2251. left = mid + 1;
  2252. }
  2253. }
  2254. var n = start - left;
  2255. switch (n) {
  2256. case 3:
  2257. array[left + 3] = array[left + 2];
  2258. case 2:
  2259. array[left + 2] = array[left + 1];
  2260. case 1:
  2261. array[left + 1] = array[left];
  2262. break;
  2263. default:
  2264. while (n > 0) {
  2265. array[left + n] = array[left + n - 1];
  2266. n--;
  2267. }
  2268. }
  2269. array[left] = pivot;
  2270. }
  2271. }
  2272. function gallopLeft(value, array, start, length, hint, compare) {
  2273. var lastOffset = 0;
  2274. var maxOffset = 0;
  2275. var offset = 1;
  2276. if (compare(value, array[start + hint]) > 0) {
  2277. maxOffset = length - hint;
  2278. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  2279. lastOffset = offset;
  2280. offset = (offset << 1) + 1;
  2281. if (offset <= 0) {
  2282. offset = maxOffset;
  2283. }
  2284. }
  2285. if (offset > maxOffset) {
  2286. offset = maxOffset;
  2287. }
  2288. lastOffset += hint;
  2289. offset += hint;
  2290. }
  2291. else {
  2292. maxOffset = hint + 1;
  2293. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  2294. lastOffset = offset;
  2295. offset = (offset << 1) + 1;
  2296. if (offset <= 0) {
  2297. offset = maxOffset;
  2298. }
  2299. }
  2300. if (offset > maxOffset) {
  2301. offset = maxOffset;
  2302. }
  2303. var tmp = lastOffset;
  2304. lastOffset = hint - offset;
  2305. offset = hint - tmp;
  2306. }
  2307. lastOffset++;
  2308. while (lastOffset < offset) {
  2309. var m = lastOffset + (offset - lastOffset >>> 1);
  2310. if (compare(value, array[start + m]) > 0) {
  2311. lastOffset = m + 1;
  2312. }
  2313. else {
  2314. offset = m;
  2315. }
  2316. }
  2317. return offset;
  2318. }
  2319. function gallopRight(value, array, start, length, hint, compare) {
  2320. var lastOffset = 0;
  2321. var maxOffset = 0;
  2322. var offset = 1;
  2323. if (compare(value, array[start + hint]) < 0) {
  2324. maxOffset = hint + 1;
  2325. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  2326. lastOffset = offset;
  2327. offset = (offset << 1) + 1;
  2328. if (offset <= 0) {
  2329. offset = maxOffset;
  2330. }
  2331. }
  2332. if (offset > maxOffset) {
  2333. offset = maxOffset;
  2334. }
  2335. var tmp = lastOffset;
  2336. lastOffset = hint - offset;
  2337. offset = hint - tmp;
  2338. }
  2339. else {
  2340. maxOffset = length - hint;
  2341. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  2342. lastOffset = offset;
  2343. offset = (offset << 1) + 1;
  2344. if (offset <= 0) {
  2345. offset = maxOffset;
  2346. }
  2347. }
  2348. if (offset > maxOffset) {
  2349. offset = maxOffset;
  2350. }
  2351. lastOffset += hint;
  2352. offset += hint;
  2353. }
  2354. lastOffset++;
  2355. while (lastOffset < offset) {
  2356. var m = lastOffset + (offset - lastOffset >>> 1);
  2357. if (compare(value, array[start + m]) < 0) {
  2358. offset = m;
  2359. }
  2360. else {
  2361. lastOffset = m + 1;
  2362. }
  2363. }
  2364. return offset;
  2365. }
  2366. function TimSort(array, compare) {
  2367. var minGallop = DEFAULT_MIN_GALLOPING;
  2368. var length = 0;
  2369. var runStart;
  2370. var runLength;
  2371. var stackSize = 0;
  2372. length = array.length;
  2373. var tmp = [];
  2374. runStart = [];
  2375. runLength = [];
  2376. function pushRun(_runStart, _runLength) {
  2377. runStart[stackSize] = _runStart;
  2378. runLength[stackSize] = _runLength;
  2379. stackSize += 1;
  2380. }
  2381. function mergeRuns() {
  2382. while (stackSize > 1) {
  2383. var n = stackSize - 2;
  2384. if ((n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1])
  2385. || (n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1])) {
  2386. if (runLength[n - 1] < runLength[n + 1]) {
  2387. n--;
  2388. }
  2389. }
  2390. else if (runLength[n] > runLength[n + 1]) {
  2391. break;
  2392. }
  2393. mergeAt(n);
  2394. }
  2395. }
  2396. function forceMergeRuns() {
  2397. while (stackSize > 1) {
  2398. var n = stackSize - 2;
  2399. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  2400. n--;
  2401. }
  2402. mergeAt(n);
  2403. }
  2404. }
  2405. function mergeAt(i) {
  2406. var start1 = runStart[i];
  2407. var length1 = runLength[i];
  2408. var start2 = runStart[i + 1];
  2409. var length2 = runLength[i + 1];
  2410. runLength[i] = length1 + length2;
  2411. if (i === stackSize - 3) {
  2412. runStart[i + 1] = runStart[i + 2];
  2413. runLength[i + 1] = runLength[i + 2];
  2414. }
  2415. stackSize--;
  2416. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  2417. start1 += k;
  2418. length1 -= k;
  2419. if (length1 === 0) {
  2420. return;
  2421. }
  2422. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  2423. if (length2 === 0) {
  2424. return;
  2425. }
  2426. if (length1 <= length2) {
  2427. mergeLow(start1, length1, start2, length2);
  2428. }
  2429. else {
  2430. mergeHigh(start1, length1, start2, length2);
  2431. }
  2432. }
  2433. function mergeLow(start1, length1, start2, length2) {
  2434. var i = 0;
  2435. for (i = 0; i < length1; i++) {
  2436. tmp[i] = array[start1 + i];
  2437. }
  2438. var cursor1 = 0;
  2439. var cursor2 = start2;
  2440. var dest = start1;
  2441. array[dest++] = array[cursor2++];
  2442. if (--length2 === 0) {
  2443. for (i = 0; i < length1; i++) {
  2444. array[dest + i] = tmp[cursor1 + i];
  2445. }
  2446. return;
  2447. }
  2448. if (length1 === 1) {
  2449. for (i = 0; i < length2; i++) {
  2450. array[dest + i] = array[cursor2 + i];
  2451. }
  2452. array[dest + length2] = tmp[cursor1];
  2453. return;
  2454. }
  2455. var _minGallop = minGallop;
  2456. var count1;
  2457. var count2;
  2458. var exit;
  2459. while (1) {
  2460. count1 = 0;
  2461. count2 = 0;
  2462. exit = false;
  2463. do {
  2464. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  2465. array[dest++] = array[cursor2++];
  2466. count2++;
  2467. count1 = 0;
  2468. if (--length2 === 0) {
  2469. exit = true;
  2470. break;
  2471. }
  2472. }
  2473. else {
  2474. array[dest++] = tmp[cursor1++];
  2475. count1++;
  2476. count2 = 0;
  2477. if (--length1 === 1) {
  2478. exit = true;
  2479. break;
  2480. }
  2481. }
  2482. } while ((count1 | count2) < _minGallop);
  2483. if (exit) {
  2484. break;
  2485. }
  2486. do {
  2487. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  2488. if (count1 !== 0) {
  2489. for (i = 0; i < count1; i++) {
  2490. array[dest + i] = tmp[cursor1 + i];
  2491. }
  2492. dest += count1;
  2493. cursor1 += count1;
  2494. length1 -= count1;
  2495. if (length1 <= 1) {
  2496. exit = true;
  2497. break;
  2498. }
  2499. }
  2500. array[dest++] = array[cursor2++];
  2501. if (--length2 === 0) {
  2502. exit = true;
  2503. break;
  2504. }
  2505. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  2506. if (count2 !== 0) {
  2507. for (i = 0; i < count2; i++) {
  2508. array[dest + i] = array[cursor2 + i];
  2509. }
  2510. dest += count2;
  2511. cursor2 += count2;
  2512. length2 -= count2;
  2513. if (length2 === 0) {
  2514. exit = true;
  2515. break;
  2516. }
  2517. }
  2518. array[dest++] = tmp[cursor1++];
  2519. if (--length1 === 1) {
  2520. exit = true;
  2521. break;
  2522. }
  2523. _minGallop--;
  2524. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2525. if (exit) {
  2526. break;
  2527. }
  2528. if (_minGallop < 0) {
  2529. _minGallop = 0;
  2530. }
  2531. _minGallop += 2;
  2532. }
  2533. minGallop = _minGallop;
  2534. minGallop < 1 && (minGallop = 1);
  2535. if (length1 === 1) {
  2536. for (i = 0; i < length2; i++) {
  2537. array[dest + i] = array[cursor2 + i];
  2538. }
  2539. array[dest + length2] = tmp[cursor1];
  2540. }
  2541. else if (length1 === 0) {
  2542. throw new Error();
  2543. }
  2544. else {
  2545. for (i = 0; i < length1; i++) {
  2546. array[dest + i] = tmp[cursor1 + i];
  2547. }
  2548. }
  2549. }
  2550. function mergeHigh(start1, length1, start2, length2) {
  2551. var i = 0;
  2552. for (i = 0; i < length2; i++) {
  2553. tmp[i] = array[start2 + i];
  2554. }
  2555. var cursor1 = start1 + length1 - 1;
  2556. var cursor2 = length2 - 1;
  2557. var dest = start2 + length2 - 1;
  2558. var customCursor = 0;
  2559. var customDest = 0;
  2560. array[dest--] = array[cursor1--];
  2561. if (--length1 === 0) {
  2562. customCursor = dest - (length2 - 1);
  2563. for (i = 0; i < length2; i++) {
  2564. array[customCursor + i] = tmp[i];
  2565. }
  2566. return;
  2567. }
  2568. if (length2 === 1) {
  2569. dest -= length1;
  2570. cursor1 -= length1;
  2571. customDest = dest + 1;
  2572. customCursor = cursor1 + 1;
  2573. for (i = length1 - 1; i >= 0; i--) {
  2574. array[customDest + i] = array[customCursor + i];
  2575. }
  2576. array[dest] = tmp[cursor2];
  2577. return;
  2578. }
  2579. var _minGallop = minGallop;
  2580. while (true) {
  2581. var count1 = 0;
  2582. var count2 = 0;
  2583. var exit = false;
  2584. do {
  2585. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  2586. array[dest--] = array[cursor1--];
  2587. count1++;
  2588. count2 = 0;
  2589. if (--length1 === 0) {
  2590. exit = true;
  2591. break;
  2592. }
  2593. }
  2594. else {
  2595. array[dest--] = tmp[cursor2--];
  2596. count2++;
  2597. count1 = 0;
  2598. if (--length2 === 1) {
  2599. exit = true;
  2600. break;
  2601. }
  2602. }
  2603. } while ((count1 | count2) < _minGallop);
  2604. if (exit) {
  2605. break;
  2606. }
  2607. do {
  2608. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  2609. if (count1 !== 0) {
  2610. dest -= count1;
  2611. cursor1 -= count1;
  2612. length1 -= count1;
  2613. customDest = dest + 1;
  2614. customCursor = cursor1 + 1;
  2615. for (i = count1 - 1; i >= 0; i--) {
  2616. array[customDest + i] = array[customCursor + i];
  2617. }
  2618. if (length1 === 0) {
  2619. exit = true;
  2620. break;
  2621. }
  2622. }
  2623. array[dest--] = tmp[cursor2--];
  2624. if (--length2 === 1) {
  2625. exit = true;
  2626. break;
  2627. }
  2628. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  2629. if (count2 !== 0) {
  2630. dest -= count2;
  2631. cursor2 -= count2;
  2632. length2 -= count2;
  2633. customDest = dest + 1;
  2634. customCursor = cursor2 + 1;
  2635. for (i = 0; i < count2; i++) {
  2636. array[customDest + i] = tmp[customCursor + i];
  2637. }
  2638. if (length2 <= 1) {
  2639. exit = true;
  2640. break;
  2641. }
  2642. }
  2643. array[dest--] = array[cursor1--];
  2644. if (--length1 === 0) {
  2645. exit = true;
  2646. break;
  2647. }
  2648. _minGallop--;
  2649. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2650. if (exit) {
  2651. break;
  2652. }
  2653. if (_minGallop < 0) {
  2654. _minGallop = 0;
  2655. }
  2656. _minGallop += 2;
  2657. }
  2658. minGallop = _minGallop;
  2659. if (minGallop < 1) {
  2660. minGallop = 1;
  2661. }
  2662. if (length2 === 1) {
  2663. dest -= length1;
  2664. cursor1 -= length1;
  2665. customDest = dest + 1;
  2666. customCursor = cursor1 + 1;
  2667. for (i = length1 - 1; i >= 0; i--) {
  2668. array[customDest + i] = array[customCursor + i];
  2669. }
  2670. array[dest] = tmp[cursor2];
  2671. }
  2672. else if (length2 === 0) {
  2673. throw new Error();
  2674. }
  2675. else {
  2676. customCursor = dest - (length2 - 1);
  2677. for (i = 0; i < length2; i++) {
  2678. array[customCursor + i] = tmp[i];
  2679. }
  2680. }
  2681. }
  2682. return {
  2683. mergeRuns: mergeRuns,
  2684. forceMergeRuns: forceMergeRuns,
  2685. pushRun: pushRun
  2686. };
  2687. }
  2688. function sort(array, compare, lo, hi) {
  2689. if (!lo) {
  2690. lo = 0;
  2691. }
  2692. if (!hi) {
  2693. hi = array.length;
  2694. }
  2695. var remaining = hi - lo;
  2696. if (remaining < 2) {
  2697. return;
  2698. }
  2699. var runLength = 0;
  2700. if (remaining < DEFAULT_MIN_MERGE) {
  2701. runLength = makeAscendingRun(array, lo, hi, compare);
  2702. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  2703. return;
  2704. }
  2705. var ts = TimSort(array, compare);
  2706. var minRun = minRunLength(remaining);
  2707. do {
  2708. runLength = makeAscendingRun(array, lo, hi, compare);
  2709. if (runLength < minRun) {
  2710. var force = remaining;
  2711. if (force > minRun) {
  2712. force = minRun;
  2713. }
  2714. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  2715. runLength = force;
  2716. }
  2717. ts.pushRun(lo, runLength);
  2718. ts.mergeRuns();
  2719. remaining -= runLength;
  2720. lo += runLength;
  2721. } while (remaining !== 0);
  2722. ts.forceMergeRuns();
  2723. }
  2724. var REDRAW_BIT = 1;
  2725. var STYLE_CHANGED_BIT = 2;
  2726. var SHAPE_CHANGED_BIT = 4;
  2727. var invalidZErrorLogged = false;
  2728. function logInvalidZError() {
  2729. if (invalidZErrorLogged) {
  2730. return;
  2731. }
  2732. invalidZErrorLogged = true;
  2733. console.warn('z / z2 / zlevel of displayable is invalid, which may cause unexpected errors');
  2734. }
  2735. function shapeCompareFunc(a, b) {
  2736. if (a.zlevel === b.zlevel) {
  2737. if (a.z === b.z) {
  2738. return a.z2 - b.z2;
  2739. }
  2740. return a.z - b.z;
  2741. }
  2742. return a.zlevel - b.zlevel;
  2743. }
  2744. var Storage = (function () {
  2745. function Storage() {
  2746. this._roots = [];
  2747. this._displayList = [];
  2748. this._displayListLen = 0;
  2749. this.displayableSortFunc = shapeCompareFunc;
  2750. }
  2751. Storage.prototype.traverse = function (cb, context) {
  2752. for (var i = 0; i < this._roots.length; i++) {
  2753. this._roots[i].traverse(cb, context);
  2754. }
  2755. };
  2756. Storage.prototype.getDisplayList = function (update, includeIgnore) {
  2757. includeIgnore = includeIgnore || false;
  2758. var displayList = this._displayList;
  2759. if (update || !displayList.length) {
  2760. this.updateDisplayList(includeIgnore);
  2761. }
  2762. return displayList;
  2763. };
  2764. Storage.prototype.updateDisplayList = function (includeIgnore) {
  2765. this._displayListLen = 0;
  2766. var roots = this._roots;
  2767. var displayList = this._displayList;
  2768. for (var i = 0, len = roots.length; i < len; i++) {
  2769. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  2770. }
  2771. displayList.length = this._displayListLen;
  2772. sort(displayList, shapeCompareFunc);
  2773. };
  2774. Storage.prototype._updateAndAddDisplayable = function (el, clipPaths, includeIgnore) {
  2775. if (el.ignore && !includeIgnore) {
  2776. return;
  2777. }
  2778. el.beforeUpdate();
  2779. el.update();
  2780. el.afterUpdate();
  2781. var userSetClipPath = el.getClipPath();
  2782. if (el.ignoreClip) {
  2783. clipPaths = null;
  2784. }
  2785. else if (userSetClipPath) {
  2786. if (clipPaths) {
  2787. clipPaths = clipPaths.slice();
  2788. }
  2789. else {
  2790. clipPaths = [];
  2791. }
  2792. var currentClipPath = userSetClipPath;
  2793. var parentClipPath = el;
  2794. while (currentClipPath) {
  2795. currentClipPath.parent = parentClipPath;
  2796. currentClipPath.updateTransform();
  2797. clipPaths.push(currentClipPath);
  2798. parentClipPath = currentClipPath;
  2799. currentClipPath = currentClipPath.getClipPath();
  2800. }
  2801. }
  2802. if (el.childrenRef) {
  2803. var children = el.childrenRef();
  2804. for (var i = 0; i < children.length; i++) {
  2805. var child = children[i];
  2806. if (el.__dirty) {
  2807. child.__dirty |= REDRAW_BIT;
  2808. }
  2809. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  2810. }
  2811. el.__dirty = 0;
  2812. }
  2813. else {
  2814. var disp = el;
  2815. if (clipPaths && clipPaths.length) {
  2816. disp.__clipPaths = clipPaths;
  2817. }
  2818. else if (disp.__clipPaths && disp.__clipPaths.length > 0) {
  2819. disp.__clipPaths = [];
  2820. }
  2821. if (isNaN(disp.z)) {
  2822. logInvalidZError();
  2823. disp.z = 0;
  2824. }
  2825. if (isNaN(disp.z2)) {
  2826. logInvalidZError();
  2827. disp.z2 = 0;
  2828. }
  2829. if (isNaN(disp.zlevel)) {
  2830. logInvalidZError();
  2831. disp.zlevel = 0;
  2832. }
  2833. this._displayList[this._displayListLen++] = disp;
  2834. }
  2835. var decalEl = el.getDecalElement && el.getDecalElement();
  2836. if (decalEl) {
  2837. this._updateAndAddDisplayable(decalEl, clipPaths, includeIgnore);
  2838. }
  2839. var textGuide = el.getTextGuideLine();
  2840. if (textGuide) {
  2841. this._updateAndAddDisplayable(textGuide, clipPaths, includeIgnore);
  2842. }
  2843. var textEl = el.getTextContent();
  2844. if (textEl) {
  2845. this._updateAndAddDisplayable(textEl, clipPaths, includeIgnore);
  2846. }
  2847. };
  2848. Storage.prototype.addRoot = function (el) {
  2849. if (el.__zr && el.__zr.storage === this) {
  2850. return;
  2851. }
  2852. this._roots.push(el);
  2853. };
  2854. Storage.prototype.delRoot = function (el) {
  2855. if (el instanceof Array) {
  2856. for (var i = 0, l = el.length; i < l; i++) {
  2857. this.delRoot(el[i]);
  2858. }
  2859. return;
  2860. }
  2861. var idx = indexOf(this._roots, el);
  2862. if (idx >= 0) {
  2863. this._roots.splice(idx, 1);
  2864. }
  2865. };
  2866. Storage.prototype.delAllRoots = function () {
  2867. this._roots = [];
  2868. this._displayList = [];
  2869. this._displayListLen = 0;
  2870. return;
  2871. };
  2872. Storage.prototype.getRoots = function () {
  2873. return this._roots;
  2874. };
  2875. Storage.prototype.dispose = function () {
  2876. this._displayList = null;
  2877. this._roots = null;
  2878. };
  2879. return Storage;
  2880. }());
  2881. var requestAnimationFrame;
  2882. requestAnimationFrame = (env.hasGlobalWindow
  2883. && ((window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  2884. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  2885. || window.mozRequestAnimationFrame
  2886. || window.webkitRequestAnimationFrame)) || function (func) {
  2887. return setTimeout(func, 16);
  2888. };
  2889. var requestAnimationFrame$1 = requestAnimationFrame;
  2890. var easingFuncs = {
  2891. linear: function (k) {
  2892. return k;
  2893. },
  2894. quadraticIn: function (k) {
  2895. return k * k;
  2896. },
  2897. quadraticOut: function (k) {
  2898. return k * (2 - k);
  2899. },
  2900. quadraticInOut: function (k) {
  2901. if ((k *= 2) < 1) {
  2902. return 0.5 * k * k;
  2903. }
  2904. return -0.5 * (--k * (k - 2) - 1);
  2905. },
  2906. cubicIn: function (k) {
  2907. return k * k * k;
  2908. },
  2909. cubicOut: function (k) {
  2910. return --k * k * k + 1;
  2911. },
  2912. cubicInOut: function (k) {
  2913. if ((k *= 2) < 1) {
  2914. return 0.5 * k * k * k;
  2915. }
  2916. return 0.5 * ((k -= 2) * k * k + 2);
  2917. },
  2918. quarticIn: function (k) {
  2919. return k * k * k * k;
  2920. },
  2921. quarticOut: function (k) {
  2922. return 1 - (--k * k * k * k);
  2923. },
  2924. quarticInOut: function (k) {
  2925. if ((k *= 2) < 1) {
  2926. return 0.5 * k * k * k * k;
  2927. }
  2928. return -0.5 * ((k -= 2) * k * k * k - 2);
  2929. },
  2930. quinticIn: function (k) {
  2931. return k * k * k * k * k;
  2932. },
  2933. quinticOut: function (k) {
  2934. return --k * k * k * k * k + 1;
  2935. },
  2936. quinticInOut: function (k) {
  2937. if ((k *= 2) < 1) {
  2938. return 0.5 * k * k * k * k * k;
  2939. }
  2940. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2941. },
  2942. sinusoidalIn: function (k) {
  2943. return 1 - Math.cos(k * Math.PI / 2);
  2944. },
  2945. sinusoidalOut: function (k) {
  2946. return Math.sin(k * Math.PI / 2);
  2947. },
  2948. sinusoidalInOut: function (k) {
  2949. return 0.5 * (1 - Math.cos(Math.PI * k));
  2950. },
  2951. exponentialIn: function (k) {
  2952. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2953. },
  2954. exponentialOut: function (k) {
  2955. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2956. },
  2957. exponentialInOut: function (k) {
  2958. if (k === 0) {
  2959. return 0;
  2960. }
  2961. if (k === 1) {
  2962. return 1;
  2963. }
  2964. if ((k *= 2) < 1) {
  2965. return 0.5 * Math.pow(1024, k - 1);
  2966. }
  2967. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2968. },
  2969. circularIn: function (k) {
  2970. return 1 - Math.sqrt(1 - k * k);
  2971. },
  2972. circularOut: function (k) {
  2973. return Math.sqrt(1 - (--k * k));
  2974. },
  2975. circularInOut: function (k) {
  2976. if ((k *= 2) < 1) {
  2977. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2978. }
  2979. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2980. },
  2981. elasticIn: function (k) {
  2982. var s;
  2983. var a = 0.1;
  2984. var p = 0.4;
  2985. if (k === 0) {
  2986. return 0;
  2987. }
  2988. if (k === 1) {
  2989. return 1;
  2990. }
  2991. if (!a || a < 1) {
  2992. a = 1;
  2993. s = p / 4;
  2994. }
  2995. else {
  2996. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2997. }
  2998. return -(a * Math.pow(2, 10 * (k -= 1))
  2999. * Math.sin((k - s) * (2 * Math.PI) / p));
  3000. },
  3001. elasticOut: function (k) {
  3002. var s;
  3003. var a = 0.1;
  3004. var p = 0.4;
  3005. if (k === 0) {
  3006. return 0;
  3007. }
  3008. if (k === 1) {
  3009. return 1;
  3010. }
  3011. if (!a || a < 1) {
  3012. a = 1;
  3013. s = p / 4;
  3014. }
  3015. else {
  3016. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3017. }
  3018. return (a * Math.pow(2, -10 * k)
  3019. * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  3020. },
  3021. elasticInOut: function (k) {
  3022. var s;
  3023. var a = 0.1;
  3024. var p = 0.4;
  3025. if (k === 0) {
  3026. return 0;
  3027. }
  3028. if (k === 1) {
  3029. return 1;
  3030. }
  3031. if (!a || a < 1) {
  3032. a = 1;
  3033. s = p / 4;
  3034. }
  3035. else {
  3036. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3037. }
  3038. if ((k *= 2) < 1) {
  3039. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  3040. * Math.sin((k - s) * (2 * Math.PI) / p));
  3041. }
  3042. return a * Math.pow(2, -10 * (k -= 1))
  3043. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  3044. },
  3045. backIn: function (k) {
  3046. var s = 1.70158;
  3047. return k * k * ((s + 1) * k - s);
  3048. },
  3049. backOut: function (k) {
  3050. var s = 1.70158;
  3051. return --k * k * ((s + 1) * k + s) + 1;
  3052. },
  3053. backInOut: function (k) {
  3054. var s = 1.70158 * 1.525;
  3055. if ((k *= 2) < 1) {
  3056. return 0.5 * (k * k * ((s + 1) * k - s));
  3057. }
  3058. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  3059. },
  3060. bounceIn: function (k) {
  3061. return 1 - easingFuncs.bounceOut(1 - k);
  3062. },
  3063. bounceOut: function (k) {
  3064. if (k < (1 / 2.75)) {
  3065. return 7.5625 * k * k;
  3066. }
  3067. else if (k < (2 / 2.75)) {
  3068. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  3069. }
  3070. else if (k < (2.5 / 2.75)) {
  3071. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  3072. }
  3073. else {
  3074. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  3075. }
  3076. },
  3077. bounceInOut: function (k) {
  3078. if (k < 0.5) {
  3079. return easingFuncs.bounceIn(k * 2) * 0.5;
  3080. }
  3081. return easingFuncs.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  3082. }
  3083. };
  3084. var mathPow = Math.pow;
  3085. var mathSqrt = Math.sqrt;
  3086. var EPSILON = 1e-8;
  3087. var EPSILON_NUMERIC = 1e-4;
  3088. var THREE_SQRT = mathSqrt(3);
  3089. var ONE_THIRD = 1 / 3;
  3090. var _v0 = create();
  3091. var _v1 = create();
  3092. var _v2 = create();
  3093. function isAroundZero(val) {
  3094. return val > -EPSILON && val < EPSILON;
  3095. }
  3096. function isNotAroundZero(val) {
  3097. return val > EPSILON || val < -EPSILON;
  3098. }
  3099. function cubicAt(p0, p1, p2, p3, t) {
  3100. var onet = 1 - t;
  3101. return onet * onet * (onet * p0 + 3 * t * p1)
  3102. + t * t * (t * p3 + 3 * onet * p2);
  3103. }
  3104. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  3105. var onet = 1 - t;
  3106. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  3107. + (p3 - p2) * t * t);
  3108. }
  3109. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  3110. var a = p3 + 3 * (p1 - p2) - p0;
  3111. var b = 3 * (p2 - p1 * 2 + p0);
  3112. var c = 3 * (p1 - p0);
  3113. var d = p0 - val;
  3114. var A = b * b - 3 * a * c;
  3115. var B = b * c - 9 * a * d;
  3116. var C = c * c - 3 * b * d;
  3117. var n = 0;
  3118. if (isAroundZero(A) && isAroundZero(B)) {
  3119. if (isAroundZero(b)) {
  3120. roots[0] = 0;
  3121. }
  3122. else {
  3123. var t1 = -c / b;
  3124. if (t1 >= 0 && t1 <= 1) {
  3125. roots[n++] = t1;
  3126. }
  3127. }
  3128. }
  3129. else {
  3130. var disc = B * B - 4 * A * C;
  3131. if (isAroundZero(disc)) {
  3132. var K = B / A;
  3133. var t1 = -b / a + K;
  3134. var t2 = -K / 2;
  3135. if (t1 >= 0 && t1 <= 1) {
  3136. roots[n++] = t1;
  3137. }
  3138. if (t2 >= 0 && t2 <= 1) {
  3139. roots[n++] = t2;
  3140. }
  3141. }
  3142. else if (disc > 0) {
  3143. var discSqrt = mathSqrt(disc);
  3144. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  3145. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  3146. if (Y1 < 0) {
  3147. Y1 = -mathPow(-Y1, ONE_THIRD);
  3148. }
  3149. else {
  3150. Y1 = mathPow(Y1, ONE_THIRD);
  3151. }
  3152. if (Y2 < 0) {
  3153. Y2 = -mathPow(-Y2, ONE_THIRD);
  3154. }
  3155. else {
  3156. Y2 = mathPow(Y2, ONE_THIRD);
  3157. }
  3158. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  3159. if (t1 >= 0 && t1 <= 1) {
  3160. roots[n++] = t1;
  3161. }
  3162. }
  3163. else {
  3164. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  3165. var theta = Math.acos(T) / 3;
  3166. var ASqrt = mathSqrt(A);
  3167. var tmp = Math.cos(theta);
  3168. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  3169. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  3170. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  3171. if (t1 >= 0 && t1 <= 1) {
  3172. roots[n++] = t1;
  3173. }
  3174. if (t2 >= 0 && t2 <= 1) {
  3175. roots[n++] = t2;
  3176. }
  3177. if (t3 >= 0 && t3 <= 1) {
  3178. roots[n++] = t3;
  3179. }
  3180. }
  3181. }
  3182. return n;
  3183. }
  3184. function cubicExtrema(p0, p1, p2, p3, extrema) {
  3185. var b = 6 * p2 - 12 * p1 + 6 * p0;
  3186. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  3187. var c = 3 * p1 - 3 * p0;
  3188. var n = 0;
  3189. if (isAroundZero(a)) {
  3190. if (isNotAroundZero(b)) {
  3191. var t1 = -c / b;
  3192. if (t1 >= 0 && t1 <= 1) {
  3193. extrema[n++] = t1;
  3194. }
  3195. }
  3196. }
  3197. else {
  3198. var disc = b * b - 4 * a * c;
  3199. if (isAroundZero(disc)) {
  3200. extrema[0] = -b / (2 * a);
  3201. }
  3202. else if (disc > 0) {
  3203. var discSqrt = mathSqrt(disc);
  3204. var t1 = (-b + discSqrt) / (2 * a);
  3205. var t2 = (-b - discSqrt) / (2 * a);
  3206. if (t1 >= 0 && t1 <= 1) {
  3207. extrema[n++] = t1;
  3208. }
  3209. if (t2 >= 0 && t2 <= 1) {
  3210. extrema[n++] = t2;
  3211. }
  3212. }
  3213. }
  3214. return n;
  3215. }
  3216. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  3217. var p01 = (p1 - p0) * t + p0;
  3218. var p12 = (p2 - p1) * t + p1;
  3219. var p23 = (p3 - p2) * t + p2;
  3220. var p012 = (p12 - p01) * t + p01;
  3221. var p123 = (p23 - p12) * t + p12;
  3222. var p0123 = (p123 - p012) * t + p012;
  3223. out[0] = p0;
  3224. out[1] = p01;
  3225. out[2] = p012;
  3226. out[3] = p0123;
  3227. out[4] = p0123;
  3228. out[5] = p123;
  3229. out[6] = p23;
  3230. out[7] = p3;
  3231. }
  3232. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  3233. var t;
  3234. var interval = 0.005;
  3235. var d = Infinity;
  3236. var prev;
  3237. var next;
  3238. var d1;
  3239. var d2;
  3240. _v0[0] = x;
  3241. _v0[1] = y;
  3242. for (var _t = 0; _t < 1; _t += 0.05) {
  3243. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  3244. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  3245. d1 = distSquare(_v0, _v1);
  3246. if (d1 < d) {
  3247. t = _t;
  3248. d = d1;
  3249. }
  3250. }
  3251. d = Infinity;
  3252. for (var i = 0; i < 32; i++) {
  3253. if (interval < EPSILON_NUMERIC) {
  3254. break;
  3255. }
  3256. prev = t - interval;
  3257. next = t + interval;
  3258. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  3259. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  3260. d1 = distSquare(_v1, _v0);
  3261. if (prev >= 0 && d1 < d) {
  3262. t = prev;
  3263. d = d1;
  3264. }
  3265. else {
  3266. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  3267. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  3268. d2 = distSquare(_v2, _v0);
  3269. if (next <= 1 && d2 < d) {
  3270. t = next;
  3271. d = d2;
  3272. }
  3273. else {
  3274. interval *= 0.5;
  3275. }
  3276. }
  3277. }
  3278. if (out) {
  3279. out[0] = cubicAt(x0, x1, x2, x3, t);
  3280. out[1] = cubicAt(y0, y1, y2, y3, t);
  3281. }
  3282. return mathSqrt(d);
  3283. }
  3284. function cubicLength(x0, y0, x1, y1, x2, y2, x3, y3, iteration) {
  3285. var px = x0;
  3286. var py = y0;
  3287. var d = 0;
  3288. var step = 1 / iteration;
  3289. for (var i = 1; i <= iteration; i++) {
  3290. var t = i * step;
  3291. var x = cubicAt(x0, x1, x2, x3, t);
  3292. var y = cubicAt(y0, y1, y2, y3, t);
  3293. var dx = x - px;
  3294. var dy = y - py;
  3295. d += Math.sqrt(dx * dx + dy * dy);
  3296. px = x;
  3297. py = y;
  3298. }
  3299. return d;
  3300. }
  3301. function quadraticAt(p0, p1, p2, t) {
  3302. var onet = 1 - t;
  3303. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  3304. }
  3305. function quadraticDerivativeAt(p0, p1, p2, t) {
  3306. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  3307. }
  3308. function quadraticRootAt(p0, p1, p2, val, roots) {
  3309. var a = p0 - 2 * p1 + p2;
  3310. var b = 2 * (p1 - p0);
  3311. var c = p0 - val;
  3312. var n = 0;
  3313. if (isAroundZero(a)) {
  3314. if (isNotAroundZero(b)) {
  3315. var t1 = -c / b;
  3316. if (t1 >= 0 && t1 <= 1) {
  3317. roots[n++] = t1;
  3318. }
  3319. }
  3320. }
  3321. else {
  3322. var disc = b * b - 4 * a * c;
  3323. if (isAroundZero(disc)) {
  3324. var t1 = -b / (2 * a);
  3325. if (t1 >= 0 && t1 <= 1) {
  3326. roots[n++] = t1;
  3327. }
  3328. }
  3329. else if (disc > 0) {
  3330. var discSqrt = mathSqrt(disc);
  3331. var t1 = (-b + discSqrt) / (2 * a);
  3332. var t2 = (-b - discSqrt) / (2 * a);
  3333. if (t1 >= 0 && t1 <= 1) {
  3334. roots[n++] = t1;
  3335. }
  3336. if (t2 >= 0 && t2 <= 1) {
  3337. roots[n++] = t2;
  3338. }
  3339. }
  3340. }
  3341. return n;
  3342. }
  3343. function quadraticExtremum(p0, p1, p2) {
  3344. var divider = p0 + p2 - 2 * p1;
  3345. if (divider === 0) {
  3346. return 0.5;
  3347. }
  3348. else {
  3349. return (p0 - p1) / divider;
  3350. }
  3351. }
  3352. function quadraticSubdivide(p0, p1, p2, t, out) {
  3353. var p01 = (p1 - p0) * t + p0;
  3354. var p12 = (p2 - p1) * t + p1;
  3355. var p012 = (p12 - p01) * t + p01;
  3356. out[0] = p0;
  3357. out[1] = p01;
  3358. out[2] = p012;
  3359. out[3] = p012;
  3360. out[4] = p12;
  3361. out[5] = p2;
  3362. }
  3363. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  3364. var t;
  3365. var interval = 0.005;
  3366. var d = Infinity;
  3367. _v0[0] = x;
  3368. _v0[1] = y;
  3369. for (var _t = 0; _t < 1; _t += 0.05) {
  3370. _v1[0] = quadraticAt(x0, x1, x2, _t);
  3371. _v1[1] = quadraticAt(y0, y1, y2, _t);
  3372. var d1 = distSquare(_v0, _v1);
  3373. if (d1 < d) {
  3374. t = _t;
  3375. d = d1;
  3376. }
  3377. }
  3378. d = Infinity;
  3379. for (var i = 0; i < 32; i++) {
  3380. if (interval < EPSILON_NUMERIC) {
  3381. break;
  3382. }
  3383. var prev = t - interval;
  3384. var next = t + interval;
  3385. _v1[0] = quadraticAt(x0, x1, x2, prev);
  3386. _v1[1] = quadraticAt(y0, y1, y2, prev);
  3387. var d1 = distSquare(_v1, _v0);
  3388. if (prev >= 0 && d1 < d) {
  3389. t = prev;
  3390. d = d1;
  3391. }
  3392. else {
  3393. _v2[0] = quadraticAt(x0, x1, x2, next);
  3394. _v2[1] = quadraticAt(y0, y1, y2, next);
  3395. var d2 = distSquare(_v2, _v0);
  3396. if (next <= 1 && d2 < d) {
  3397. t = next;
  3398. d = d2;
  3399. }
  3400. else {
  3401. interval *= 0.5;
  3402. }
  3403. }
  3404. }
  3405. if (out) {
  3406. out[0] = quadraticAt(x0, x1, x2, t);
  3407. out[1] = quadraticAt(y0, y1, y2, t);
  3408. }
  3409. return mathSqrt(d);
  3410. }
  3411. function quadraticLength(x0, y0, x1, y1, x2, y2, iteration) {
  3412. var px = x0;
  3413. var py = y0;
  3414. var d = 0;
  3415. var step = 1 / iteration;
  3416. for (var i = 1; i <= iteration; i++) {
  3417. var t = i * step;
  3418. var x = quadraticAt(x0, x1, x2, t);
  3419. var y = quadraticAt(y0, y1, y2, t);
  3420. var dx = x - px;
  3421. var dy = y - py;
  3422. d += Math.sqrt(dx * dx + dy * dy);
  3423. px = x;
  3424. py = y;
  3425. }
  3426. return d;
  3427. }
  3428. var regexp = /cubic-bezier\(([0-9,\.e ]+)\)/;
  3429. function createCubicEasingFunc(cubicEasingStr) {
  3430. var cubic = cubicEasingStr && regexp.exec(cubicEasingStr);
  3431. if (cubic) {
  3432. var points = cubic[1].split(',');
  3433. var a_1 = +trim(points[0]);
  3434. var b_1 = +trim(points[1]);
  3435. var c_1 = +trim(points[2]);
  3436. var d_1 = +trim(points[3]);
  3437. if (isNaN(a_1 + b_1 + c_1 + d_1)) {
  3438. return;
  3439. }
  3440. var roots_1 = [];
  3441. return function (p) {
  3442. return p <= 0
  3443. ? 0 : p >= 1
  3444. ? 1
  3445. : cubicRootAt(0, a_1, c_1, 1, p, roots_1) && cubicAt(0, b_1, d_1, 1, roots_1[0]);
  3446. };
  3447. }
  3448. }
  3449. var Clip = (function () {
  3450. function Clip(opts) {
  3451. this._inited = false;
  3452. this._startTime = 0;
  3453. this._pausedTime = 0;
  3454. this._paused = false;
  3455. this._life = opts.life || 1000;
  3456. this._delay = opts.delay || 0;
  3457. this.loop = opts.loop || false;
  3458. this.onframe = opts.onframe || noop;
  3459. this.ondestroy = opts.ondestroy || noop;
  3460. this.onrestart = opts.onrestart || noop;
  3461. opts.easing && this.setEasing(opts.easing);
  3462. }
  3463. Clip.prototype.step = function (globalTime, deltaTime) {
  3464. if (!this._inited) {
  3465. this._startTime = globalTime + this._delay;
  3466. this._inited = true;
  3467. }
  3468. if (this._paused) {
  3469. this._pausedTime += deltaTime;
  3470. return;
  3471. }
  3472. var life = this._life;
  3473. var elapsedTime = globalTime - this._startTime - this._pausedTime;
  3474. var percent = elapsedTime / life;
  3475. if (percent < 0) {
  3476. percent = 0;
  3477. }
  3478. percent = Math.min(percent, 1);
  3479. var easingFunc = this.easingFunc;
  3480. var schedule = easingFunc ? easingFunc(percent) : percent;
  3481. this.onframe(schedule);
  3482. if (percent === 1) {
  3483. if (this.loop) {
  3484. var remainder = elapsedTime % life;
  3485. this._startTime = globalTime - remainder;
  3486. this._pausedTime = 0;
  3487. this.onrestart();
  3488. }
  3489. else {
  3490. return true;
  3491. }
  3492. }
  3493. return false;
  3494. };
  3495. Clip.prototype.pause = function () {
  3496. this._paused = true;
  3497. };
  3498. Clip.prototype.resume = function () {
  3499. this._paused = false;
  3500. };
  3501. Clip.prototype.setEasing = function (easing) {
  3502. this.easing = easing;
  3503. this.easingFunc = isFunction(easing)
  3504. ? easing
  3505. : easingFuncs[easing] || createCubicEasingFunc(easing);
  3506. };
  3507. return Clip;
  3508. }());
  3509. var Entry = (function () {
  3510. function Entry(val) {
  3511. this.value = val;
  3512. }
  3513. return Entry;
  3514. }());
  3515. var LinkedList = (function () {
  3516. function LinkedList() {
  3517. this._len = 0;
  3518. }
  3519. LinkedList.prototype.insert = function (val) {
  3520. var entry = new Entry(val);
  3521. this.insertEntry(entry);
  3522. return entry;
  3523. };
  3524. LinkedList.prototype.insertEntry = function (entry) {
  3525. if (!this.head) {
  3526. this.head = this.tail = entry;
  3527. }
  3528. else {
  3529. this.tail.next = entry;
  3530. entry.prev = this.tail;
  3531. entry.next = null;
  3532. this.tail = entry;
  3533. }
  3534. this._len++;
  3535. };
  3536. LinkedList.prototype.remove = function (entry) {
  3537. var prev = entry.prev;
  3538. var next = entry.next;
  3539. if (prev) {
  3540. prev.next = next;
  3541. }
  3542. else {
  3543. this.head = next;
  3544. }
  3545. if (next) {
  3546. next.prev = prev;
  3547. }
  3548. else {
  3549. this.tail = prev;
  3550. }
  3551. entry.next = entry.prev = null;
  3552. this._len--;
  3553. };
  3554. LinkedList.prototype.len = function () {
  3555. return this._len;
  3556. };
  3557. LinkedList.prototype.clear = function () {
  3558. this.head = this.tail = null;
  3559. this._len = 0;
  3560. };
  3561. return LinkedList;
  3562. }());
  3563. var LRU = (function () {
  3564. function LRU(maxSize) {
  3565. this._list = new LinkedList();
  3566. this._maxSize = 10;
  3567. this._map = {};
  3568. this._maxSize = maxSize;
  3569. }
  3570. LRU.prototype.put = function (key, value) {
  3571. var list = this._list;
  3572. var map = this._map;
  3573. var removed = null;
  3574. if (map[key] == null) {
  3575. var len = list.len();
  3576. var entry = this._lastRemovedEntry;
  3577. if (len >= this._maxSize && len > 0) {
  3578. var leastUsedEntry = list.head;
  3579. list.remove(leastUsedEntry);
  3580. delete map[leastUsedEntry.key];
  3581. removed = leastUsedEntry.value;
  3582. this._lastRemovedEntry = leastUsedEntry;
  3583. }
  3584. if (entry) {
  3585. entry.value = value;
  3586. }
  3587. else {
  3588. entry = new Entry(value);
  3589. }
  3590. entry.key = key;
  3591. list.insertEntry(entry);
  3592. map[key] = entry;
  3593. }
  3594. return removed;
  3595. };
  3596. LRU.prototype.get = function (key) {
  3597. var entry = this._map[key];
  3598. var list = this._list;
  3599. if (entry != null) {
  3600. if (entry !== list.tail) {
  3601. list.remove(entry);
  3602. list.insertEntry(entry);
  3603. }
  3604. return entry.value;
  3605. }
  3606. };
  3607. LRU.prototype.clear = function () {
  3608. this._list.clear();
  3609. this._map = {};
  3610. };
  3611. LRU.prototype.len = function () {
  3612. return this._list.len();
  3613. };
  3614. return LRU;
  3615. }());
  3616. var kCSSColorTable = {
  3617. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  3618. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  3619. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  3620. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  3621. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  3622. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  3623. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  3624. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  3625. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  3626. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  3627. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  3628. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  3629. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  3630. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  3631. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  3632. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  3633. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  3634. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  3635. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  3636. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  3637. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  3638. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  3639. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  3640. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  3641. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  3642. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  3643. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  3644. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  3645. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  3646. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  3647. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  3648. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  3649. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  3650. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  3651. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  3652. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  3653. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  3654. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  3655. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  3656. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  3657. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  3658. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  3659. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  3660. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  3661. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  3662. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  3663. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  3664. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  3665. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  3666. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  3667. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  3668. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  3669. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  3670. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  3671. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  3672. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  3673. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  3674. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  3675. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  3676. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  3677. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  3678. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  3679. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  3680. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  3681. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  3682. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  3683. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  3684. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  3685. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  3686. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  3687. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  3688. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  3689. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  3690. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  3691. };
  3692. function clampCssByte(i) {
  3693. i = Math.round(i);
  3694. return i < 0 ? 0 : i > 255 ? 255 : i;
  3695. }
  3696. function clampCssAngle(i) {
  3697. i = Math.round(i);
  3698. return i < 0 ? 0 : i > 360 ? 360 : i;
  3699. }
  3700. function clampCssFloat(f) {
  3701. return f < 0 ? 0 : f > 1 ? 1 : f;
  3702. }
  3703. function parseCssInt(val) {
  3704. var str = val;
  3705. if (str.length && str.charAt(str.length - 1) === '%') {
  3706. return clampCssByte(parseFloat(str) / 100 * 255);
  3707. }
  3708. return clampCssByte(parseInt(str, 10));
  3709. }
  3710. function parseCssFloat(val) {
  3711. var str = val;
  3712. if (str.length && str.charAt(str.length - 1) === '%') {
  3713. return clampCssFloat(parseFloat(str) / 100);
  3714. }
  3715. return clampCssFloat(parseFloat(str));
  3716. }
  3717. function cssHueToRgb(m1, m2, h) {
  3718. if (h < 0) {
  3719. h += 1;
  3720. }
  3721. else if (h > 1) {
  3722. h -= 1;
  3723. }
  3724. if (h * 6 < 1) {
  3725. return m1 + (m2 - m1) * h * 6;
  3726. }
  3727. if (h * 2 < 1) {
  3728. return m2;
  3729. }
  3730. if (h * 3 < 2) {
  3731. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3732. }
  3733. return m1;
  3734. }
  3735. function lerpNumber(a, b, p) {
  3736. return a + (b - a) * p;
  3737. }
  3738. function setRgba(out, r, g, b, a) {
  3739. out[0] = r;
  3740. out[1] = g;
  3741. out[2] = b;
  3742. out[3] = a;
  3743. return out;
  3744. }
  3745. function copyRgba(out, a) {
  3746. out[0] = a[0];
  3747. out[1] = a[1];
  3748. out[2] = a[2];
  3749. out[3] = a[3];
  3750. return out;
  3751. }
  3752. var colorCache = new LRU(20);
  3753. var lastRemovedArr = null;
  3754. function putToCache(colorStr, rgbaArr) {
  3755. if (lastRemovedArr) {
  3756. copyRgba(lastRemovedArr, rgbaArr);
  3757. }
  3758. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  3759. }
  3760. function parse(colorStr, rgbaArr) {
  3761. if (!colorStr) {
  3762. return;
  3763. }
  3764. rgbaArr = rgbaArr || [];
  3765. var cached = colorCache.get(colorStr);
  3766. if (cached) {
  3767. return copyRgba(rgbaArr, cached);
  3768. }
  3769. colorStr = colorStr + '';
  3770. var str = colorStr.replace(/ /g, '').toLowerCase();
  3771. if (str in kCSSColorTable) {
  3772. copyRgba(rgbaArr, kCSSColorTable[str]);
  3773. putToCache(colorStr, rgbaArr);
  3774. return rgbaArr;
  3775. }
  3776. var strLen = str.length;
  3777. if (str.charAt(0) === '#') {
  3778. if (strLen === 4 || strLen === 5) {
  3779. var iv = parseInt(str.slice(1, 4), 16);
  3780. if (!(iv >= 0 && iv <= 0xfff)) {
  3781. setRgba(rgbaArr, 0, 0, 0, 1);
  3782. return;
  3783. }
  3784. setRgba(rgbaArr, ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8), (iv & 0xf0) | ((iv & 0xf0) >> 4), (iv & 0xf) | ((iv & 0xf) << 4), strLen === 5 ? parseInt(str.slice(4), 16) / 0xf : 1);
  3785. putToCache(colorStr, rgbaArr);
  3786. return rgbaArr;
  3787. }
  3788. else if (strLen === 7 || strLen === 9) {
  3789. var iv = parseInt(str.slice(1, 7), 16);
  3790. if (!(iv >= 0 && iv <= 0xffffff)) {
  3791. setRgba(rgbaArr, 0, 0, 0, 1);
  3792. return;
  3793. }
  3794. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, strLen === 9 ? parseInt(str.slice(7), 16) / 0xff : 1);
  3795. putToCache(colorStr, rgbaArr);
  3796. return rgbaArr;
  3797. }
  3798. return;
  3799. }
  3800. var op = str.indexOf('(');
  3801. var ep = str.indexOf(')');
  3802. if (op !== -1 && ep + 1 === strLen) {
  3803. var fname = str.substr(0, op);
  3804. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3805. var alpha = 1;
  3806. switch (fname) {
  3807. case 'rgba':
  3808. if (params.length !== 4) {
  3809. return params.length === 3
  3810. ? setRgba(rgbaArr, +params[0], +params[1], +params[2], 1)
  3811. : setRgba(rgbaArr, 0, 0, 0, 1);
  3812. }
  3813. alpha = parseCssFloat(params.pop());
  3814. case 'rgb':
  3815. if (params.length >= 3) {
  3816. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), params.length === 3 ? alpha : parseCssFloat(params[3]));
  3817. putToCache(colorStr, rgbaArr);
  3818. return rgbaArr;
  3819. }
  3820. else {
  3821. setRgba(rgbaArr, 0, 0, 0, 1);
  3822. return;
  3823. }
  3824. case 'hsla':
  3825. if (params.length !== 4) {
  3826. setRgba(rgbaArr, 0, 0, 0, 1);
  3827. return;
  3828. }
  3829. params[3] = parseCssFloat(params[3]);
  3830. hsla2rgba(params, rgbaArr);
  3831. putToCache(colorStr, rgbaArr);
  3832. return rgbaArr;
  3833. case 'hsl':
  3834. if (params.length !== 3) {
  3835. setRgba(rgbaArr, 0, 0, 0, 1);
  3836. return;
  3837. }
  3838. hsla2rgba(params, rgbaArr);
  3839. putToCache(colorStr, rgbaArr);
  3840. return rgbaArr;
  3841. default:
  3842. return;
  3843. }
  3844. }
  3845. setRgba(rgbaArr, 0, 0, 0, 1);
  3846. return;
  3847. }
  3848. function hsla2rgba(hsla, rgba) {
  3849. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360;
  3850. var s = parseCssFloat(hsla[1]);
  3851. var l = parseCssFloat(hsla[2]);
  3852. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  3853. var m1 = l * 2 - m2;
  3854. rgba = rgba || [];
  3855. setRgba(rgba, clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255), clampCssByte(cssHueToRgb(m1, m2, h) * 255), clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255), 1);
  3856. if (hsla.length === 4) {
  3857. rgba[3] = hsla[3];
  3858. }
  3859. return rgba;
  3860. }
  3861. function rgba2hsla(rgba) {
  3862. if (!rgba) {
  3863. return;
  3864. }
  3865. var R = rgba[0] / 255;
  3866. var G = rgba[1] / 255;
  3867. var B = rgba[2] / 255;
  3868. var vMin = Math.min(R, G, B);
  3869. var vMax = Math.max(R, G, B);
  3870. var delta = vMax - vMin;
  3871. var L = (vMax + vMin) / 2;
  3872. var H;
  3873. var S;
  3874. if (delta === 0) {
  3875. H = 0;
  3876. S = 0;
  3877. }
  3878. else {
  3879. if (L < 0.5) {
  3880. S = delta / (vMax + vMin);
  3881. }
  3882. else {
  3883. S = delta / (2 - vMax - vMin);
  3884. }
  3885. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  3886. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  3887. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  3888. if (R === vMax) {
  3889. H = deltaB - deltaG;
  3890. }
  3891. else if (G === vMax) {
  3892. H = (1 / 3) + deltaR - deltaB;
  3893. }
  3894. else if (B === vMax) {
  3895. H = (2 / 3) + deltaG - deltaR;
  3896. }
  3897. if (H < 0) {
  3898. H += 1;
  3899. }
  3900. if (H > 1) {
  3901. H -= 1;
  3902. }
  3903. }
  3904. var hsla = [H * 360, S, L];
  3905. if (rgba[3] != null) {
  3906. hsla.push(rgba[3]);
  3907. }
  3908. return hsla;
  3909. }
  3910. function lift(color, level) {
  3911. var colorArr = parse(color);
  3912. if (colorArr) {
  3913. for (var i = 0; i < 3; i++) {
  3914. if (level < 0) {
  3915. colorArr[i] = colorArr[i] * (1 - level) | 0;
  3916. }
  3917. else {
  3918. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  3919. }
  3920. if (colorArr[i] > 255) {
  3921. colorArr[i] = 255;
  3922. }
  3923. else if (colorArr[i] < 0) {
  3924. colorArr[i] = 0;
  3925. }
  3926. }
  3927. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  3928. }
  3929. }
  3930. function toHex(color) {
  3931. var colorArr = parse(color);
  3932. if (colorArr) {
  3933. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  3934. }
  3935. }
  3936. function fastLerp(normalizedValue, colors, out) {
  3937. if (!(colors && colors.length)
  3938. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3939. return;
  3940. }
  3941. out = out || [];
  3942. var value = normalizedValue * (colors.length - 1);
  3943. var leftIndex = Math.floor(value);
  3944. var rightIndex = Math.ceil(value);
  3945. var leftColor = colors[leftIndex];
  3946. var rightColor = colors[rightIndex];
  3947. var dv = value - leftIndex;
  3948. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  3949. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  3950. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  3951. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  3952. return out;
  3953. }
  3954. var fastMapToColor = fastLerp;
  3955. function lerp$1(normalizedValue, colors, fullOutput) {
  3956. if (!(colors && colors.length)
  3957. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3958. return;
  3959. }
  3960. var value = normalizedValue * (colors.length - 1);
  3961. var leftIndex = Math.floor(value);
  3962. var rightIndex = Math.ceil(value);
  3963. var leftColor = parse(colors[leftIndex]);
  3964. var rightColor = parse(colors[rightIndex]);
  3965. var dv = value - leftIndex;
  3966. var color = stringify([
  3967. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  3968. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  3969. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  3970. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  3971. ], 'rgba');
  3972. return fullOutput
  3973. ? {
  3974. color: color,
  3975. leftIndex: leftIndex,
  3976. rightIndex: rightIndex,
  3977. value: value
  3978. }
  3979. : color;
  3980. }
  3981. var mapToColor = lerp$1;
  3982. function modifyHSL(color, h, s, l) {
  3983. var colorArr = parse(color);
  3984. if (color) {
  3985. colorArr = rgba2hsla(colorArr);
  3986. h != null && (colorArr[0] = clampCssAngle(h));
  3987. s != null && (colorArr[1] = parseCssFloat(s));
  3988. l != null && (colorArr[2] = parseCssFloat(l));
  3989. return stringify(hsla2rgba(colorArr), 'rgba');
  3990. }
  3991. }
  3992. function modifyAlpha(color, alpha) {
  3993. var colorArr = parse(color);
  3994. if (colorArr && alpha != null) {
  3995. colorArr[3] = clampCssFloat(alpha);
  3996. return stringify(colorArr, 'rgba');
  3997. }
  3998. }
  3999. function stringify(arrColor, type) {
  4000. if (!arrColor || !arrColor.length) {
  4001. return;
  4002. }
  4003. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  4004. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  4005. colorStr += ',' + arrColor[3];
  4006. }
  4007. return type + '(' + colorStr + ')';
  4008. }
  4009. function lum(color, backgroundLum) {
  4010. var arr = parse(color);
  4011. return arr
  4012. ? (0.299 * arr[0] + 0.587 * arr[1] + 0.114 * arr[2]) * arr[3] / 255
  4013. + (1 - arr[3]) * backgroundLum
  4014. : 0;
  4015. }
  4016. function random() {
  4017. return stringify([
  4018. Math.round(Math.random() * 255),
  4019. Math.round(Math.random() * 255),
  4020. Math.round(Math.random() * 255)
  4021. ], 'rgb');
  4022. }
  4023. var color = /*#__PURE__*/Object.freeze({
  4024. __proto__: null,
  4025. parse: parse,
  4026. lift: lift,
  4027. toHex: toHex,
  4028. fastLerp: fastLerp,
  4029. fastMapToColor: fastMapToColor,
  4030. lerp: lerp$1,
  4031. mapToColor: mapToColor,
  4032. modifyHSL: modifyHSL,
  4033. modifyAlpha: modifyAlpha,
  4034. stringify: stringify,
  4035. lum: lum,
  4036. random: random
  4037. });
  4038. var mathRound = Math.round;
  4039. function normalizeColor(color) {
  4040. var opacity;
  4041. if (!color || color === 'transparent') {
  4042. color = 'none';
  4043. }
  4044. else if (typeof color === 'string' && color.indexOf('rgba') > -1) {
  4045. var arr = parse(color);
  4046. if (arr) {
  4047. color = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')';
  4048. opacity = arr[3];
  4049. }
  4050. }
  4051. return {
  4052. color: color,
  4053. opacity: opacity == null ? 1 : opacity
  4054. };
  4055. }
  4056. var EPSILON$1 = 1e-4;
  4057. function isAroundZero$1(transform) {
  4058. return transform < EPSILON$1 && transform > -EPSILON$1;
  4059. }
  4060. function round3(transform) {
  4061. return mathRound(transform * 1e3) / 1e3;
  4062. }
  4063. function round4(transform) {
  4064. return mathRound(transform * 1e4) / 1e4;
  4065. }
  4066. function getMatrixStr(m) {
  4067. return 'matrix('
  4068. + round3(m[0]) + ','
  4069. + round3(m[1]) + ','
  4070. + round3(m[2]) + ','
  4071. + round3(m[3]) + ','
  4072. + round4(m[4]) + ','
  4073. + round4(m[5])
  4074. + ')';
  4075. }
  4076. var TEXT_ALIGN_TO_ANCHOR = {
  4077. left: 'start',
  4078. right: 'end',
  4079. center: 'middle',
  4080. middle: 'middle'
  4081. };
  4082. function adjustTextY(y, lineHeight, textBaseline) {
  4083. if (textBaseline === 'top') {
  4084. y += lineHeight / 2;
  4085. }
  4086. else if (textBaseline === 'bottom') {
  4087. y -= lineHeight / 2;
  4088. }
  4089. return y;
  4090. }
  4091. function hasShadow(style) {
  4092. return style
  4093. && (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY);
  4094. }
  4095. function getShadowKey(displayable) {
  4096. var style = displayable.style;
  4097. var globalScale = displayable.getGlobalScale();
  4098. return [
  4099. style.shadowColor,
  4100. (style.shadowBlur || 0).toFixed(2),
  4101. (style.shadowOffsetX || 0).toFixed(2),
  4102. (style.shadowOffsetY || 0).toFixed(2),
  4103. globalScale[0],
  4104. globalScale[1]
  4105. ].join(',');
  4106. }
  4107. function isImagePattern(val) {
  4108. return val && (!!val.image);
  4109. }
  4110. function isSVGPattern(val) {
  4111. return val && (!!val.svgElement);
  4112. }
  4113. function isPattern(val) {
  4114. return isImagePattern(val) || isSVGPattern(val);
  4115. }
  4116. function isLinearGradient(val) {
  4117. return val.type === 'linear';
  4118. }
  4119. function isRadialGradient(val) {
  4120. return val.type === 'radial';
  4121. }
  4122. function isGradient(val) {
  4123. return val && (val.type === 'linear'
  4124. || val.type === 'radial');
  4125. }
  4126. function getIdURL(id) {
  4127. return "url(#" + id + ")";
  4128. }
  4129. function getPathPrecision(el) {
  4130. var scale = el.getGlobalScale();
  4131. var size = Math.max(scale[0], scale[1]);
  4132. return Math.max(Math.ceil(Math.log(size) / Math.log(10)), 1);
  4133. }
  4134. function getSRTTransformString(transform) {
  4135. var x = transform.x || 0;
  4136. var y = transform.y || 0;
  4137. var rotation = (transform.rotation || 0) * RADIAN_TO_DEGREE;
  4138. var scaleX = retrieve2(transform.scaleX, 1);
  4139. var scaleY = retrieve2(transform.scaleY, 1);
  4140. var skewX = transform.skewX || 0;
  4141. var skewY = transform.skewY || 0;
  4142. var res = [];
  4143. if (x || y) {
  4144. res.push("translate(" + x + "px," + y + "px)");
  4145. }
  4146. if (rotation) {
  4147. res.push("rotate(" + rotation + ")");
  4148. }
  4149. if (scaleX !== 1 || scaleY !== 1) {
  4150. res.push("scale(" + scaleX + "," + scaleY + ")");
  4151. }
  4152. if (skewX || skewY) {
  4153. res.push("skew(" + mathRound(skewX * RADIAN_TO_DEGREE) + "deg, " + mathRound(skewY * RADIAN_TO_DEGREE) + "deg)");
  4154. }
  4155. return res.join(' ');
  4156. }
  4157. var encodeBase64 = (function () {
  4158. if (env.hasGlobalWindow && isFunction(window.btoa)) {
  4159. return function (str) {
  4160. return window.btoa(unescape(encodeURIComponent(str)));
  4161. };
  4162. }
  4163. if (typeof Buffer !== 'undefined') {
  4164. return function (str) {
  4165. return Buffer.from(str).toString('base64');
  4166. };
  4167. }
  4168. return function (str) {
  4169. {
  4170. logError('Base64 isn\'t natively supported in the current environment.');
  4171. }
  4172. return null;
  4173. };
  4174. })();
  4175. var arraySlice = Array.prototype.slice;
  4176. function interpolateNumber(p0, p1, percent) {
  4177. return (p1 - p0) * percent + p0;
  4178. }
  4179. function interpolate1DArray(out, p0, p1, percent) {
  4180. var len = p0.length;
  4181. for (var i = 0; i < len; i++) {
  4182. out[i] = interpolateNumber(p0[i], p1[i], percent);
  4183. }
  4184. return out;
  4185. }
  4186. function interpolate2DArray(out, p0, p1, percent) {
  4187. var len = p0.length;
  4188. var len2 = len && p0[0].length;
  4189. for (var i = 0; i < len; i++) {
  4190. if (!out[i]) {
  4191. out[i] = [];
  4192. }
  4193. for (var j = 0; j < len2; j++) {
  4194. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  4195. }
  4196. }
  4197. return out;
  4198. }
  4199. function add1DArray(out, p0, p1, sign) {
  4200. var len = p0.length;
  4201. for (var i = 0; i < len; i++) {
  4202. out[i] = p0[i] + p1[i] * sign;
  4203. }
  4204. return out;
  4205. }
  4206. function add2DArray(out, p0, p1, sign) {
  4207. var len = p0.length;
  4208. var len2 = len && p0[0].length;
  4209. for (var i = 0; i < len; i++) {
  4210. if (!out[i]) {
  4211. out[i] = [];
  4212. }
  4213. for (var j = 0; j < len2; j++) {
  4214. out[i][j] = p0[i][j] + p1[i][j] * sign;
  4215. }
  4216. }
  4217. return out;
  4218. }
  4219. function fillColorStops(val0, val1) {
  4220. var len0 = val0.length;
  4221. var len1 = val1.length;
  4222. var shorterArr = len0 > len1 ? val1 : val0;
  4223. var shorterLen = Math.min(len0, len1);
  4224. var last = shorterArr[shorterLen - 1] || { color: [0, 0, 0, 0], offset: 0 };
  4225. for (var i = shorterLen; i < Math.max(len0, len1); i++) {
  4226. shorterArr.push({
  4227. offset: last.offset,
  4228. color: last.color.slice()
  4229. });
  4230. }
  4231. }
  4232. function fillArray(val0, val1, arrDim) {
  4233. var arr0 = val0;
  4234. var arr1 = val1;
  4235. if (!arr0.push || !arr1.push) {
  4236. return;
  4237. }
  4238. var arr0Len = arr0.length;
  4239. var arr1Len = arr1.length;
  4240. if (arr0Len !== arr1Len) {
  4241. var isPreviousLarger = arr0Len > arr1Len;
  4242. if (isPreviousLarger) {
  4243. arr0.length = arr1Len;
  4244. }
  4245. else {
  4246. for (var i = arr0Len; i < arr1Len; i++) {
  4247. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  4248. }
  4249. }
  4250. }
  4251. var len2 = arr0[0] && arr0[0].length;
  4252. for (var i = 0; i < arr0.length; i++) {
  4253. if (arrDim === 1) {
  4254. if (isNaN(arr0[i])) {
  4255. arr0[i] = arr1[i];
  4256. }
  4257. }
  4258. else {
  4259. for (var j = 0; j < len2; j++) {
  4260. if (isNaN(arr0[i][j])) {
  4261. arr0[i][j] = arr1[i][j];
  4262. }
  4263. }
  4264. }
  4265. }
  4266. }
  4267. function cloneValue(value) {
  4268. if (isArrayLike(value)) {
  4269. var len = value.length;
  4270. if (isArrayLike(value[0])) {
  4271. var ret = [];
  4272. for (var i = 0; i < len; i++) {
  4273. ret.push(arraySlice.call(value[i]));
  4274. }
  4275. return ret;
  4276. }
  4277. return arraySlice.call(value);
  4278. }
  4279. return value;
  4280. }
  4281. function rgba2String(rgba) {
  4282. rgba[0] = Math.floor(rgba[0]) || 0;
  4283. rgba[1] = Math.floor(rgba[1]) || 0;
  4284. rgba[2] = Math.floor(rgba[2]) || 0;
  4285. rgba[3] = rgba[3] == null ? 1 : rgba[3];
  4286. return 'rgba(' + rgba.join(',') + ')';
  4287. }
  4288. function guessArrayDim(value) {
  4289. return isArrayLike(value && value[0]) ? 2 : 1;
  4290. }
  4291. var VALUE_TYPE_NUMBER = 0;
  4292. var VALUE_TYPE_1D_ARRAY = 1;
  4293. var VALUE_TYPE_2D_ARRAY = 2;
  4294. var VALUE_TYPE_COLOR = 3;
  4295. var VALUE_TYPE_LINEAR_GRADIENT = 4;
  4296. var VALUE_TYPE_RADIAL_GRADIENT = 5;
  4297. var VALUE_TYPE_UNKOWN = 6;
  4298. function isGradientValueType(valType) {
  4299. return valType === VALUE_TYPE_LINEAR_GRADIENT || valType === VALUE_TYPE_RADIAL_GRADIENT;
  4300. }
  4301. function isArrayValueType(valType) {
  4302. return valType === VALUE_TYPE_1D_ARRAY || valType === VALUE_TYPE_2D_ARRAY;
  4303. }
  4304. var tmpRgba = [0, 0, 0, 0];
  4305. var Track = (function () {
  4306. function Track(propName) {
  4307. this.keyframes = [];
  4308. this.discrete = false;
  4309. this._invalid = false;
  4310. this._needsSort = false;
  4311. this._lastFr = 0;
  4312. this._lastFrP = 0;
  4313. this.propName = propName;
  4314. }
  4315. Track.prototype.isFinished = function () {
  4316. return this._finished;
  4317. };
  4318. Track.prototype.setFinished = function () {
  4319. this._finished = true;
  4320. if (this._additiveTrack) {
  4321. this._additiveTrack.setFinished();
  4322. }
  4323. };
  4324. Track.prototype.needsAnimate = function () {
  4325. return this.keyframes.length >= 1;
  4326. };
  4327. Track.prototype.getAdditiveTrack = function () {
  4328. return this._additiveTrack;
  4329. };
  4330. Track.prototype.addKeyframe = function (time, rawValue, easing) {
  4331. this._needsSort = true;
  4332. var keyframes = this.keyframes;
  4333. var len = keyframes.length;
  4334. var discrete = false;
  4335. var valType = VALUE_TYPE_UNKOWN;
  4336. var value = rawValue;
  4337. if (isArrayLike(rawValue)) {
  4338. var arrayDim = guessArrayDim(rawValue);
  4339. valType = arrayDim;
  4340. if (arrayDim === 1 && !isNumber(rawValue[0])
  4341. || arrayDim === 2 && !isNumber(rawValue[0][0])) {
  4342. discrete = true;
  4343. }
  4344. }
  4345. else {
  4346. if (isNumber(rawValue) && !eqNaN(rawValue)) {
  4347. valType = VALUE_TYPE_NUMBER;
  4348. }
  4349. else if (isString(rawValue)) {
  4350. if (!isNaN(+rawValue)) {
  4351. valType = VALUE_TYPE_NUMBER;
  4352. }
  4353. else {
  4354. var colorArray = parse(rawValue);
  4355. if (colorArray) {
  4356. value = colorArray;
  4357. valType = VALUE_TYPE_COLOR;
  4358. }
  4359. }
  4360. }
  4361. else if (isGradientObject(rawValue)) {
  4362. var parsedGradient = extend({}, value);
  4363. parsedGradient.colorStops = map(rawValue.colorStops, function (colorStop) { return ({
  4364. offset: colorStop.offset,
  4365. color: parse(colorStop.color)
  4366. }); });
  4367. if (isLinearGradient(rawValue)) {
  4368. valType = VALUE_TYPE_LINEAR_GRADIENT;
  4369. }
  4370. else if (isRadialGradient(rawValue)) {
  4371. valType = VALUE_TYPE_RADIAL_GRADIENT;
  4372. }
  4373. value = parsedGradient;
  4374. }
  4375. }
  4376. if (len === 0) {
  4377. this.valType = valType;
  4378. }
  4379. else if (valType !== this.valType || valType === VALUE_TYPE_UNKOWN) {
  4380. discrete = true;
  4381. }
  4382. this.discrete = this.discrete || discrete;
  4383. var kf = {
  4384. time: time,
  4385. value: value,
  4386. rawValue: rawValue,
  4387. percent: 0
  4388. };
  4389. if (easing) {
  4390. kf.easing = easing;
  4391. kf.easingFunc = isFunction(easing)
  4392. ? easing
  4393. : easingFuncs[easing] || createCubicEasingFunc(easing);
  4394. }
  4395. keyframes.push(kf);
  4396. return kf;
  4397. };
  4398. Track.prototype.prepare = function (maxTime, additiveTrack) {
  4399. var kfs = this.keyframes;
  4400. if (this._needsSort) {
  4401. kfs.sort(function (a, b) {
  4402. return a.time - b.time;
  4403. });
  4404. }
  4405. var valType = this.valType;
  4406. var kfsLen = kfs.length;
  4407. var lastKf = kfs[kfsLen - 1];
  4408. var isDiscrete = this.discrete;
  4409. var isArr = isArrayValueType(valType);
  4410. var isGradient = isGradientValueType(valType);
  4411. for (var i = 0; i < kfsLen; i++) {
  4412. var kf = kfs[i];
  4413. var value = kf.value;
  4414. var lastValue = lastKf.value;
  4415. kf.percent = kf.time / maxTime;
  4416. if (!isDiscrete) {
  4417. if (isArr && i !== kfsLen - 1) {
  4418. fillArray(value, lastValue, valType);
  4419. }
  4420. else if (isGradient) {
  4421. fillColorStops(value.colorStops, lastValue.colorStops);
  4422. }
  4423. }
  4424. }
  4425. if (!isDiscrete
  4426. && valType !== VALUE_TYPE_RADIAL_GRADIENT
  4427. && additiveTrack
  4428. && this.needsAnimate()
  4429. && additiveTrack.needsAnimate()
  4430. && valType === additiveTrack.valType
  4431. && !additiveTrack._finished) {
  4432. this._additiveTrack = additiveTrack;
  4433. var startValue = kfs[0].value;
  4434. for (var i = 0; i < kfsLen; i++) {
  4435. if (valType === VALUE_TYPE_NUMBER) {
  4436. kfs[i].additiveValue = kfs[i].value - startValue;
  4437. }
  4438. else if (valType === VALUE_TYPE_COLOR) {
  4439. kfs[i].additiveValue =
  4440. add1DArray([], kfs[i].value, startValue, -1);
  4441. }
  4442. else if (isArrayValueType(valType)) {
  4443. kfs[i].additiveValue = valType === VALUE_TYPE_1D_ARRAY
  4444. ? add1DArray([], kfs[i].value, startValue, -1)
  4445. : add2DArray([], kfs[i].value, startValue, -1);
  4446. }
  4447. }
  4448. }
  4449. };
  4450. Track.prototype.step = function (target, percent) {
  4451. if (this._finished) {
  4452. return;
  4453. }
  4454. if (this._additiveTrack && this._additiveTrack._finished) {
  4455. this._additiveTrack = null;
  4456. }
  4457. var isAdditive = this._additiveTrack != null;
  4458. var valueKey = isAdditive ? 'additiveValue' : 'value';
  4459. var valType = this.valType;
  4460. var keyframes = this.keyframes;
  4461. var kfsNum = keyframes.length;
  4462. var propName = this.propName;
  4463. var isValueColor = valType === VALUE_TYPE_COLOR;
  4464. var frameIdx;
  4465. var lastFrame = this._lastFr;
  4466. var mathMin = Math.min;
  4467. var frame;
  4468. var nextFrame;
  4469. if (kfsNum === 1) {
  4470. frame = nextFrame = keyframes[0];
  4471. }
  4472. else {
  4473. if (percent < 0) {
  4474. frameIdx = 0;
  4475. }
  4476. else if (percent < this._lastFrP) {
  4477. var start = mathMin(lastFrame + 1, kfsNum - 1);
  4478. for (frameIdx = start; frameIdx >= 0; frameIdx--) {
  4479. if (keyframes[frameIdx].percent <= percent) {
  4480. break;
  4481. }
  4482. }
  4483. frameIdx = mathMin(frameIdx, kfsNum - 2);
  4484. }
  4485. else {
  4486. for (frameIdx = lastFrame; frameIdx < kfsNum; frameIdx++) {
  4487. if (keyframes[frameIdx].percent > percent) {
  4488. break;
  4489. }
  4490. }
  4491. frameIdx = mathMin(frameIdx - 1, kfsNum - 2);
  4492. }
  4493. nextFrame = keyframes[frameIdx + 1];
  4494. frame = keyframes[frameIdx];
  4495. }
  4496. if (!(frame && nextFrame)) {
  4497. return;
  4498. }
  4499. this._lastFr = frameIdx;
  4500. this._lastFrP = percent;
  4501. var interval = (nextFrame.percent - frame.percent);
  4502. var w = interval === 0 ? 1 : mathMin((percent - frame.percent) / interval, 1);
  4503. if (nextFrame.easingFunc) {
  4504. w = nextFrame.easingFunc(w);
  4505. }
  4506. var targetArr = isAdditive ? this._additiveValue
  4507. : (isValueColor ? tmpRgba : target[propName]);
  4508. if ((isArrayValueType(valType) || isValueColor) && !targetArr) {
  4509. targetArr = this._additiveValue = [];
  4510. }
  4511. if (this.discrete) {
  4512. target[propName] = w < 1 ? frame.rawValue : nextFrame.rawValue;
  4513. }
  4514. else if (isArrayValueType(valType)) {
  4515. valType === VALUE_TYPE_1D_ARRAY
  4516. ? interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w)
  4517. : interpolate2DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4518. }
  4519. else if (isGradientValueType(valType)) {
  4520. var val = frame[valueKey];
  4521. var nextVal_1 = nextFrame[valueKey];
  4522. var isLinearGradient_1 = valType === VALUE_TYPE_LINEAR_GRADIENT;
  4523. target[propName] = {
  4524. type: isLinearGradient_1 ? 'linear' : 'radial',
  4525. x: interpolateNumber(val.x, nextVal_1.x, w),
  4526. y: interpolateNumber(val.y, nextVal_1.y, w),
  4527. colorStops: map(val.colorStops, function (colorStop, idx) {
  4528. var nextColorStop = nextVal_1.colorStops[idx];
  4529. return {
  4530. offset: interpolateNumber(colorStop.offset, nextColorStop.offset, w),
  4531. color: rgba2String(interpolate1DArray([], colorStop.color, nextColorStop.color, w))
  4532. };
  4533. }),
  4534. global: nextVal_1.global
  4535. };
  4536. if (isLinearGradient_1) {
  4537. target[propName].x2 = interpolateNumber(val.x2, nextVal_1.x2, w);
  4538. target[propName].y2 = interpolateNumber(val.y2, nextVal_1.y2, w);
  4539. }
  4540. else {
  4541. target[propName].r = interpolateNumber(val.r, nextVal_1.r, w);
  4542. }
  4543. }
  4544. else if (isValueColor) {
  4545. interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4546. if (!isAdditive) {
  4547. target[propName] = rgba2String(targetArr);
  4548. }
  4549. }
  4550. else {
  4551. var value = interpolateNumber(frame[valueKey], nextFrame[valueKey], w);
  4552. if (isAdditive) {
  4553. this._additiveValue = value;
  4554. }
  4555. else {
  4556. target[propName] = value;
  4557. }
  4558. }
  4559. if (isAdditive) {
  4560. this._addToTarget(target);
  4561. }
  4562. };
  4563. Track.prototype._addToTarget = function (target) {
  4564. var valType = this.valType;
  4565. var propName = this.propName;
  4566. var additiveValue = this._additiveValue;
  4567. if (valType === VALUE_TYPE_NUMBER) {
  4568. target[propName] = target[propName] + additiveValue;
  4569. }
  4570. else if (valType === VALUE_TYPE_COLOR) {
  4571. parse(target[propName], tmpRgba);
  4572. add1DArray(tmpRgba, tmpRgba, additiveValue, 1);
  4573. target[propName] = rgba2String(tmpRgba);
  4574. }
  4575. else if (valType === VALUE_TYPE_1D_ARRAY) {
  4576. add1DArray(target[propName], target[propName], additiveValue, 1);
  4577. }
  4578. else if (valType === VALUE_TYPE_2D_ARRAY) {
  4579. add2DArray(target[propName], target[propName], additiveValue, 1);
  4580. }
  4581. };
  4582. return Track;
  4583. }());
  4584. var Animator = (function () {
  4585. function Animator(target, loop, allowDiscreteAnimation, additiveTo) {
  4586. this._tracks = {};
  4587. this._trackKeys = [];
  4588. this._maxTime = 0;
  4589. this._started = 0;
  4590. this._clip = null;
  4591. this._target = target;
  4592. this._loop = loop;
  4593. if (loop && additiveTo) {
  4594. logError('Can\' use additive animation on looped animation.');
  4595. return;
  4596. }
  4597. this._additiveAnimators = additiveTo;
  4598. this._allowDiscrete = allowDiscreteAnimation;
  4599. }
  4600. Animator.prototype.getMaxTime = function () {
  4601. return this._maxTime;
  4602. };
  4603. Animator.prototype.getDelay = function () {
  4604. return this._delay;
  4605. };
  4606. Animator.prototype.getLoop = function () {
  4607. return this._loop;
  4608. };
  4609. Animator.prototype.getTarget = function () {
  4610. return this._target;
  4611. };
  4612. Animator.prototype.changeTarget = function (target) {
  4613. this._target = target;
  4614. };
  4615. Animator.prototype.when = function (time, props, easing) {
  4616. return this.whenWithKeys(time, props, keys(props), easing);
  4617. };
  4618. Animator.prototype.whenWithKeys = function (time, props, propNames, easing) {
  4619. var tracks = this._tracks;
  4620. for (var i = 0; i < propNames.length; i++) {
  4621. var propName = propNames[i];
  4622. var track = tracks[propName];
  4623. if (!track) {
  4624. track = tracks[propName] = new Track(propName);
  4625. var initialValue = void 0;
  4626. var additiveTrack = this._getAdditiveTrack(propName);
  4627. if (additiveTrack) {
  4628. var addtiveTrackKfs = additiveTrack.keyframes;
  4629. var lastFinalKf = addtiveTrackKfs[addtiveTrackKfs.length - 1];
  4630. initialValue = lastFinalKf && lastFinalKf.value;
  4631. if (additiveTrack.valType === VALUE_TYPE_COLOR && initialValue) {
  4632. initialValue = rgba2String(initialValue);
  4633. }
  4634. }
  4635. else {
  4636. initialValue = this._target[propName];
  4637. }
  4638. if (initialValue == null) {
  4639. continue;
  4640. }
  4641. if (time > 0) {
  4642. track.addKeyframe(0, cloneValue(initialValue), easing);
  4643. }
  4644. this._trackKeys.push(propName);
  4645. }
  4646. track.addKeyframe(time, cloneValue(props[propName]), easing);
  4647. }
  4648. this._maxTime = Math.max(this._maxTime, time);
  4649. return this;
  4650. };
  4651. Animator.prototype.pause = function () {
  4652. this._clip.pause();
  4653. this._paused = true;
  4654. };
  4655. Animator.prototype.resume = function () {
  4656. this._clip.resume();
  4657. this._paused = false;
  4658. };
  4659. Animator.prototype.isPaused = function () {
  4660. return !!this._paused;
  4661. };
  4662. Animator.prototype.duration = function (duration) {
  4663. this._maxTime = duration;
  4664. this._force = true;
  4665. return this;
  4666. };
  4667. Animator.prototype._doneCallback = function () {
  4668. this._setTracksFinished();
  4669. this._clip = null;
  4670. var doneList = this._doneCbs;
  4671. if (doneList) {
  4672. var len = doneList.length;
  4673. for (var i = 0; i < len; i++) {
  4674. doneList[i].call(this);
  4675. }
  4676. }
  4677. };
  4678. Animator.prototype._abortedCallback = function () {
  4679. this._setTracksFinished();
  4680. var animation = this.animation;
  4681. var abortedList = this._abortedCbs;
  4682. if (animation) {
  4683. animation.removeClip(this._clip);
  4684. }
  4685. this._clip = null;
  4686. if (abortedList) {
  4687. for (var i = 0; i < abortedList.length; i++) {
  4688. abortedList[i].call(this);
  4689. }
  4690. }
  4691. };
  4692. Animator.prototype._setTracksFinished = function () {
  4693. var tracks = this._tracks;
  4694. var tracksKeys = this._trackKeys;
  4695. for (var i = 0; i < tracksKeys.length; i++) {
  4696. tracks[tracksKeys[i]].setFinished();
  4697. }
  4698. };
  4699. Animator.prototype._getAdditiveTrack = function (trackName) {
  4700. var additiveTrack;
  4701. var additiveAnimators = this._additiveAnimators;
  4702. if (additiveAnimators) {
  4703. for (var i = 0; i < additiveAnimators.length; i++) {
  4704. var track = additiveAnimators[i].getTrack(trackName);
  4705. if (track) {
  4706. additiveTrack = track;
  4707. }
  4708. }
  4709. }
  4710. return additiveTrack;
  4711. };
  4712. Animator.prototype.start = function (easing) {
  4713. if (this._started > 0) {
  4714. return;
  4715. }
  4716. this._started = 1;
  4717. var self = this;
  4718. var tracks = [];
  4719. var maxTime = this._maxTime || 0;
  4720. for (var i = 0; i < this._trackKeys.length; i++) {
  4721. var propName = this._trackKeys[i];
  4722. var track = this._tracks[propName];
  4723. var additiveTrack = this._getAdditiveTrack(propName);
  4724. var kfs = track.keyframes;
  4725. var kfsNum = kfs.length;
  4726. track.prepare(maxTime, additiveTrack);
  4727. if (track.needsAnimate()) {
  4728. if (!this._allowDiscrete && track.discrete) {
  4729. var lastKf = kfs[kfsNum - 1];
  4730. if (lastKf) {
  4731. self._target[track.propName] = lastKf.rawValue;
  4732. }
  4733. track.setFinished();
  4734. }
  4735. else {
  4736. tracks.push(track);
  4737. }
  4738. }
  4739. }
  4740. if (tracks.length || this._force) {
  4741. var clip = new Clip({
  4742. life: maxTime,
  4743. loop: this._loop,
  4744. delay: this._delay || 0,
  4745. onframe: function (percent) {
  4746. self._started = 2;
  4747. var additiveAnimators = self._additiveAnimators;
  4748. if (additiveAnimators) {
  4749. var stillHasAdditiveAnimator = false;
  4750. for (var i = 0; i < additiveAnimators.length; i++) {
  4751. if (additiveAnimators[i]._clip) {
  4752. stillHasAdditiveAnimator = true;
  4753. break;
  4754. }
  4755. }
  4756. if (!stillHasAdditiveAnimator) {
  4757. self._additiveAnimators = null;
  4758. }
  4759. }
  4760. for (var i = 0; i < tracks.length; i++) {
  4761. tracks[i].step(self._target, percent);
  4762. }
  4763. var onframeList = self._onframeCbs;
  4764. if (onframeList) {
  4765. for (var i = 0; i < onframeList.length; i++) {
  4766. onframeList[i](self._target, percent);
  4767. }
  4768. }
  4769. },
  4770. ondestroy: function () {
  4771. self._doneCallback();
  4772. }
  4773. });
  4774. this._clip = clip;
  4775. if (this.animation) {
  4776. this.animation.addClip(clip);
  4777. }
  4778. if (easing) {
  4779. clip.setEasing(easing);
  4780. }
  4781. }
  4782. else {
  4783. this._doneCallback();
  4784. }
  4785. return this;
  4786. };
  4787. Animator.prototype.stop = function (forwardToLast) {
  4788. if (!this._clip) {
  4789. return;
  4790. }
  4791. var clip = this._clip;
  4792. if (forwardToLast) {
  4793. clip.onframe(1);
  4794. }
  4795. this._abortedCallback();
  4796. };
  4797. Animator.prototype.delay = function (time) {
  4798. this._delay = time;
  4799. return this;
  4800. };
  4801. Animator.prototype.during = function (cb) {
  4802. if (cb) {
  4803. if (!this._onframeCbs) {
  4804. this._onframeCbs = [];
  4805. }
  4806. this._onframeCbs.push(cb);
  4807. }
  4808. return this;
  4809. };
  4810. Animator.prototype.done = function (cb) {
  4811. if (cb) {
  4812. if (!this._doneCbs) {
  4813. this._doneCbs = [];
  4814. }
  4815. this._doneCbs.push(cb);
  4816. }
  4817. return this;
  4818. };
  4819. Animator.prototype.aborted = function (cb) {
  4820. if (cb) {
  4821. if (!this._abortedCbs) {
  4822. this._abortedCbs = [];
  4823. }
  4824. this._abortedCbs.push(cb);
  4825. }
  4826. return this;
  4827. };
  4828. Animator.prototype.getClip = function () {
  4829. return this._clip;
  4830. };
  4831. Animator.prototype.getTrack = function (propName) {
  4832. return this._tracks[propName];
  4833. };
  4834. Animator.prototype.getTracks = function () {
  4835. var _this = this;
  4836. return map(this._trackKeys, function (key) { return _this._tracks[key]; });
  4837. };
  4838. Animator.prototype.stopTracks = function (propNames, forwardToLast) {
  4839. if (!propNames.length || !this._clip) {
  4840. return true;
  4841. }
  4842. var tracks = this._tracks;
  4843. var tracksKeys = this._trackKeys;
  4844. for (var i = 0; i < propNames.length; i++) {
  4845. var track = tracks[propNames[i]];
  4846. if (track && !track.isFinished()) {
  4847. if (forwardToLast) {
  4848. track.step(this._target, 1);
  4849. }
  4850. else if (this._started === 1) {
  4851. track.step(this._target, 0);
  4852. }
  4853. track.setFinished();
  4854. }
  4855. }
  4856. var allAborted = true;
  4857. for (var i = 0; i < tracksKeys.length; i++) {
  4858. if (!tracks[tracksKeys[i]].isFinished()) {
  4859. allAborted = false;
  4860. break;
  4861. }
  4862. }
  4863. if (allAborted) {
  4864. this._abortedCallback();
  4865. }
  4866. return allAborted;
  4867. };
  4868. Animator.prototype.saveTo = function (target, trackKeys, firstOrLast) {
  4869. if (!target) {
  4870. return;
  4871. }
  4872. trackKeys = trackKeys || this._trackKeys;
  4873. for (var i = 0; i < trackKeys.length; i++) {
  4874. var propName = trackKeys[i];
  4875. var track = this._tracks[propName];
  4876. if (!track || track.isFinished()) {
  4877. continue;
  4878. }
  4879. var kfs = track.keyframes;
  4880. var kf = kfs[firstOrLast ? 0 : kfs.length - 1];
  4881. if (kf) {
  4882. target[propName] = cloneValue(kf.rawValue);
  4883. }
  4884. }
  4885. };
  4886. Animator.prototype.__changeFinalValue = function (finalProps, trackKeys) {
  4887. trackKeys = trackKeys || keys(finalProps);
  4888. for (var i = 0; i < trackKeys.length; i++) {
  4889. var propName = trackKeys[i];
  4890. var track = this._tracks[propName];
  4891. if (!track) {
  4892. continue;
  4893. }
  4894. var kfs = track.keyframes;
  4895. if (kfs.length > 1) {
  4896. var lastKf = kfs.pop();
  4897. track.addKeyframe(lastKf.time, finalProps[propName]);
  4898. track.prepare(this._maxTime, track.getAdditiveTrack());
  4899. }
  4900. }
  4901. };
  4902. return Animator;
  4903. }());
  4904. function getTime() {
  4905. return new Date().getTime();
  4906. }
  4907. var Animation = (function (_super) {
  4908. __extends(Animation, _super);
  4909. function Animation(opts) {
  4910. var _this = _super.call(this) || this;
  4911. _this._running = false;
  4912. _this._time = 0;
  4913. _this._pausedTime = 0;
  4914. _this._pauseStart = 0;
  4915. _this._paused = false;
  4916. opts = opts || {};
  4917. _this.stage = opts.stage || {};
  4918. return _this;
  4919. }
  4920. Animation.prototype.addClip = function (clip) {
  4921. if (clip.animation) {
  4922. this.removeClip(clip);
  4923. }
  4924. if (!this._head) {
  4925. this._head = this._tail = clip;
  4926. }
  4927. else {
  4928. this._tail.next = clip;
  4929. clip.prev = this._tail;
  4930. clip.next = null;
  4931. this._tail = clip;
  4932. }
  4933. clip.animation = this;
  4934. };
  4935. Animation.prototype.addAnimator = function (animator) {
  4936. animator.animation = this;
  4937. var clip = animator.getClip();
  4938. if (clip) {
  4939. this.addClip(clip);
  4940. }
  4941. };
  4942. Animation.prototype.removeClip = function (clip) {
  4943. if (!clip.animation) {
  4944. return;
  4945. }
  4946. var prev = clip.prev;
  4947. var next = clip.next;
  4948. if (prev) {
  4949. prev.next = next;
  4950. }
  4951. else {
  4952. this._head = next;
  4953. }
  4954. if (next) {
  4955. next.prev = prev;
  4956. }
  4957. else {
  4958. this._tail = prev;
  4959. }
  4960. clip.next = clip.prev = clip.animation = null;
  4961. };
  4962. Animation.prototype.removeAnimator = function (animator) {
  4963. var clip = animator.getClip();
  4964. if (clip) {
  4965. this.removeClip(clip);
  4966. }
  4967. animator.animation = null;
  4968. };
  4969. Animation.prototype.update = function (notTriggerFrameAndStageUpdate) {
  4970. var time = getTime() - this._pausedTime;
  4971. var delta = time - this._time;
  4972. var clip = this._head;
  4973. while (clip) {
  4974. var nextClip = clip.next;
  4975. var finished = clip.step(time, delta);
  4976. if (finished) {
  4977. clip.ondestroy();
  4978. this.removeClip(clip);
  4979. clip = nextClip;
  4980. }
  4981. else {
  4982. clip = nextClip;
  4983. }
  4984. }
  4985. this._time = time;
  4986. if (!notTriggerFrameAndStageUpdate) {
  4987. this.trigger('frame', delta);
  4988. this.stage.update && this.stage.update();
  4989. }
  4990. };
  4991. Animation.prototype._startLoop = function () {
  4992. var self = this;
  4993. this._running = true;
  4994. function step() {
  4995. if (self._running) {
  4996. requestAnimationFrame$1(step);
  4997. !self._paused && self.update();
  4998. }
  4999. }
  5000. requestAnimationFrame$1(step);
  5001. };
  5002. Animation.prototype.start = function () {
  5003. if (this._running) {
  5004. return;
  5005. }
  5006. this._time = getTime();
  5007. this._pausedTime = 0;
  5008. this._startLoop();
  5009. };
  5010. Animation.prototype.stop = function () {
  5011. this._running = false;
  5012. };
  5013. Animation.prototype.pause = function () {
  5014. if (!this._paused) {
  5015. this._pauseStart = getTime();
  5016. this._paused = true;
  5017. }
  5018. };
  5019. Animation.prototype.resume = function () {
  5020. if (this._paused) {
  5021. this._pausedTime += getTime() - this._pauseStart;
  5022. this._paused = false;
  5023. }
  5024. };
  5025. Animation.prototype.clear = function () {
  5026. var clip = this._head;
  5027. while (clip) {
  5028. var nextClip = clip.next;
  5029. clip.prev = clip.next = clip.animation = null;
  5030. clip = nextClip;
  5031. }
  5032. this._head = this._tail = null;
  5033. };
  5034. Animation.prototype.isFinished = function () {
  5035. return this._head == null;
  5036. };
  5037. Animation.prototype.animate = function (target, options) {
  5038. options = options || {};
  5039. this.start();
  5040. var animator = new Animator(target, options.loop);
  5041. this.addAnimator(animator);
  5042. return animator;
  5043. };
  5044. return Animation;
  5045. }(Eventful));
  5046. var TOUCH_CLICK_DELAY = 300;
  5047. var globalEventSupported = env.domSupported;
  5048. var localNativeListenerNames = (function () {
  5049. var mouseHandlerNames = [
  5050. 'click', 'dblclick', 'mousewheel', 'wheel', 'mouseout',
  5051. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  5052. ];
  5053. var touchHandlerNames = [
  5054. 'touchstart', 'touchend', 'touchmove'
  5055. ];
  5056. var pointerEventNameMap = {
  5057. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  5058. };
  5059. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  5060. var nm = name.replace('mouse', 'pointer');
  5061. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  5062. });
  5063. return {
  5064. mouse: mouseHandlerNames,
  5065. touch: touchHandlerNames,
  5066. pointer: pointerHandlerNames
  5067. };
  5068. })();
  5069. var globalNativeListenerNames = {
  5070. mouse: ['mousemove', 'mouseup'],
  5071. pointer: ['pointermove', 'pointerup']
  5072. };
  5073. var wheelEventSupported = false;
  5074. function isPointerFromTouch(event) {
  5075. var pointerType = event.pointerType;
  5076. return pointerType === 'pen' || pointerType === 'touch';
  5077. }
  5078. function setTouchTimer(scope) {
  5079. scope.touching = true;
  5080. if (scope.touchTimer != null) {
  5081. clearTimeout(scope.touchTimer);
  5082. scope.touchTimer = null;
  5083. }
  5084. scope.touchTimer = setTimeout(function () {
  5085. scope.touching = false;
  5086. scope.touchTimer = null;
  5087. }, 700);
  5088. }
  5089. function markTouch(event) {
  5090. event && (event.zrByTouch = true);
  5091. }
  5092. function normalizeGlobalEvent(instance, event) {
  5093. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  5094. }
  5095. function isLocalEl(instance, el) {
  5096. var elTmp = el;
  5097. var isLocal = false;
  5098. while (elTmp && elTmp.nodeType !== 9
  5099. && !(isLocal = elTmp.domBelongToZr
  5100. || (elTmp !== el && elTmp === instance.painterRoot))) {
  5101. elTmp = elTmp.parentNode;
  5102. }
  5103. return isLocal;
  5104. }
  5105. var FakeGlobalEvent = (function () {
  5106. function FakeGlobalEvent(instance, event) {
  5107. this.stopPropagation = noop;
  5108. this.stopImmediatePropagation = noop;
  5109. this.preventDefault = noop;
  5110. this.type = event.type;
  5111. this.target = this.currentTarget = instance.dom;
  5112. this.pointerType = event.pointerType;
  5113. this.clientX = event.clientX;
  5114. this.clientY = event.clientY;
  5115. }
  5116. return FakeGlobalEvent;
  5117. }());
  5118. var localDOMHandlers = {
  5119. mousedown: function (event) {
  5120. event = normalizeEvent(this.dom, event);
  5121. this.__mayPointerCapture = [event.zrX, event.zrY];
  5122. this.trigger('mousedown', event);
  5123. },
  5124. mousemove: function (event) {
  5125. event = normalizeEvent(this.dom, event);
  5126. var downPoint = this.__mayPointerCapture;
  5127. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  5128. this.__togglePointerCapture(true);
  5129. }
  5130. this.trigger('mousemove', event);
  5131. },
  5132. mouseup: function (event) {
  5133. event = normalizeEvent(this.dom, event);
  5134. this.__togglePointerCapture(false);
  5135. this.trigger('mouseup', event);
  5136. },
  5137. mouseout: function (event) {
  5138. event = normalizeEvent(this.dom, event);
  5139. var element = event.toElement || event.relatedTarget;
  5140. if (!isLocalEl(this, element)) {
  5141. if (this.__pointerCapturing) {
  5142. event.zrEventControl = 'no_globalout';
  5143. }
  5144. this.trigger('mouseout', event);
  5145. }
  5146. },
  5147. wheel: function (event) {
  5148. wheelEventSupported = true;
  5149. event = normalizeEvent(this.dom, event);
  5150. this.trigger('mousewheel', event);
  5151. },
  5152. mousewheel: function (event) {
  5153. if (wheelEventSupported) {
  5154. return;
  5155. }
  5156. event = normalizeEvent(this.dom, event);
  5157. this.trigger('mousewheel', event);
  5158. },
  5159. touchstart: function (event) {
  5160. event = normalizeEvent(this.dom, event);
  5161. markTouch(event);
  5162. this.__lastTouchMoment = new Date();
  5163. this.handler.processGesture(event, 'start');
  5164. localDOMHandlers.mousemove.call(this, event);
  5165. localDOMHandlers.mousedown.call(this, event);
  5166. },
  5167. touchmove: function (event) {
  5168. event = normalizeEvent(this.dom, event);
  5169. markTouch(event);
  5170. this.handler.processGesture(event, 'change');
  5171. localDOMHandlers.mousemove.call(this, event);
  5172. },
  5173. touchend: function (event) {
  5174. event = normalizeEvent(this.dom, event);
  5175. markTouch(event);
  5176. this.handler.processGesture(event, 'end');
  5177. localDOMHandlers.mouseup.call(this, event);
  5178. if (+new Date() - (+this.__lastTouchMoment) < TOUCH_CLICK_DELAY) {
  5179. localDOMHandlers.click.call(this, event);
  5180. }
  5181. },
  5182. pointerdown: function (event) {
  5183. localDOMHandlers.mousedown.call(this, event);
  5184. },
  5185. pointermove: function (event) {
  5186. if (!isPointerFromTouch(event)) {
  5187. localDOMHandlers.mousemove.call(this, event);
  5188. }
  5189. },
  5190. pointerup: function (event) {
  5191. localDOMHandlers.mouseup.call(this, event);
  5192. },
  5193. pointerout: function (event) {
  5194. if (!isPointerFromTouch(event)) {
  5195. localDOMHandlers.mouseout.call(this, event);
  5196. }
  5197. }
  5198. };
  5199. each(['click', 'dblclick', 'contextmenu'], function (name) {
  5200. localDOMHandlers[name] = function (event) {
  5201. event = normalizeEvent(this.dom, event);
  5202. this.trigger(name, event);
  5203. };
  5204. });
  5205. var globalDOMHandlers = {
  5206. pointermove: function (event) {
  5207. if (!isPointerFromTouch(event)) {
  5208. globalDOMHandlers.mousemove.call(this, event);
  5209. }
  5210. },
  5211. pointerup: function (event) {
  5212. globalDOMHandlers.mouseup.call(this, event);
  5213. },
  5214. mousemove: function (event) {
  5215. this.trigger('mousemove', event);
  5216. },
  5217. mouseup: function (event) {
  5218. var pointerCaptureReleasing = this.__pointerCapturing;
  5219. this.__togglePointerCapture(false);
  5220. this.trigger('mouseup', event);
  5221. if (pointerCaptureReleasing) {
  5222. event.zrEventControl = 'only_globalout';
  5223. this.trigger('mouseout', event);
  5224. }
  5225. }
  5226. };
  5227. function mountLocalDOMEventListeners(instance, scope) {
  5228. var domHandlers = scope.domHandlers;
  5229. if (env.pointerEventsSupported) {
  5230. each(localNativeListenerNames.pointer, function (nativeEventName) {
  5231. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5232. domHandlers[nativeEventName].call(instance, event);
  5233. });
  5234. });
  5235. }
  5236. else {
  5237. if (env.touchEventsSupported) {
  5238. each(localNativeListenerNames.touch, function (nativeEventName) {
  5239. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5240. domHandlers[nativeEventName].call(instance, event);
  5241. setTouchTimer(scope);
  5242. });
  5243. });
  5244. }
  5245. each(localNativeListenerNames.mouse, function (nativeEventName) {
  5246. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5247. event = getNativeEvent(event);
  5248. if (!scope.touching) {
  5249. domHandlers[nativeEventName].call(instance, event);
  5250. }
  5251. });
  5252. });
  5253. }
  5254. }
  5255. function mountGlobalDOMEventListeners(instance, scope) {
  5256. if (env.pointerEventsSupported) {
  5257. each(globalNativeListenerNames.pointer, mount);
  5258. }
  5259. else if (!env.touchEventsSupported) {
  5260. each(globalNativeListenerNames.mouse, mount);
  5261. }
  5262. function mount(nativeEventName) {
  5263. function nativeEventListener(event) {
  5264. event = getNativeEvent(event);
  5265. if (!isLocalEl(instance, event.target)) {
  5266. event = normalizeGlobalEvent(instance, event);
  5267. scope.domHandlers[nativeEventName].call(instance, event);
  5268. }
  5269. }
  5270. mountSingleDOMEventListener(scope, nativeEventName, nativeEventListener, { capture: true });
  5271. }
  5272. }
  5273. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  5274. scope.mounted[nativeEventName] = listener;
  5275. scope.listenerOpts[nativeEventName] = opt;
  5276. addEventListener(scope.domTarget, nativeEventName, listener, opt);
  5277. }
  5278. function unmountDOMEventListeners(scope) {
  5279. var mounted = scope.mounted;
  5280. for (var nativeEventName in mounted) {
  5281. if (mounted.hasOwnProperty(nativeEventName)) {
  5282. removeEventListener(scope.domTarget, nativeEventName, mounted[nativeEventName], scope.listenerOpts[nativeEventName]);
  5283. }
  5284. }
  5285. scope.mounted = {};
  5286. }
  5287. var DOMHandlerScope = (function () {
  5288. function DOMHandlerScope(domTarget, domHandlers) {
  5289. this.mounted = {};
  5290. this.listenerOpts = {};
  5291. this.touching = false;
  5292. this.domTarget = domTarget;
  5293. this.domHandlers = domHandlers;
  5294. }
  5295. return DOMHandlerScope;
  5296. }());
  5297. var HandlerDomProxy = (function (_super) {
  5298. __extends(HandlerDomProxy, _super);
  5299. function HandlerDomProxy(dom, painterRoot) {
  5300. var _this = _super.call(this) || this;
  5301. _this.__pointerCapturing = false;
  5302. _this.dom = dom;
  5303. _this.painterRoot = painterRoot;
  5304. _this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  5305. if (globalEventSupported) {
  5306. _this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  5307. }
  5308. mountLocalDOMEventListeners(_this, _this._localHandlerScope);
  5309. return _this;
  5310. }
  5311. HandlerDomProxy.prototype.dispose = function () {
  5312. unmountDOMEventListeners(this._localHandlerScope);
  5313. if (globalEventSupported) {
  5314. unmountDOMEventListeners(this._globalHandlerScope);
  5315. }
  5316. };
  5317. HandlerDomProxy.prototype.setCursor = function (cursorStyle) {
  5318. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  5319. };
  5320. HandlerDomProxy.prototype.__togglePointerCapture = function (isPointerCapturing) {
  5321. this.__mayPointerCapture = null;
  5322. if (globalEventSupported
  5323. && ((+this.__pointerCapturing) ^ (+isPointerCapturing))) {
  5324. this.__pointerCapturing = isPointerCapturing;
  5325. var globalHandlerScope = this._globalHandlerScope;
  5326. isPointerCapturing
  5327. ? mountGlobalDOMEventListeners(this, globalHandlerScope)
  5328. : unmountDOMEventListeners(globalHandlerScope);
  5329. }
  5330. };
  5331. return HandlerDomProxy;
  5332. }(Eventful));
  5333. var dpr = 1;
  5334. if (env.hasGlobalWindow) {
  5335. dpr = Math.max(window.devicePixelRatio
  5336. || (window.screen && window.screen.deviceXDPI / window.screen.logicalXDPI)
  5337. || 1, 1);
  5338. }
  5339. var devicePixelRatio = dpr;
  5340. var DARK_MODE_THRESHOLD = 0.4;
  5341. var DARK_LABEL_COLOR = '#333';
  5342. var LIGHT_LABEL_COLOR = '#ccc';
  5343. var LIGHTER_LABEL_COLOR = '#eee';
  5344. var mIdentity = identity;
  5345. var EPSILON$2 = 5e-5;
  5346. function isNotAroundZero$1(val) {
  5347. return val > EPSILON$2 || val < -EPSILON$2;
  5348. }
  5349. var scaleTmp = [];
  5350. var tmpTransform = [];
  5351. var originTransform = create$1();
  5352. var abs = Math.abs;
  5353. var Transformable = (function () {
  5354. function Transformable() {
  5355. }
  5356. Transformable.prototype.getLocalTransform = function (m) {
  5357. return Transformable.getLocalTransform(this, m);
  5358. };
  5359. Transformable.prototype.setPosition = function (arr) {
  5360. this.x = arr[0];
  5361. this.y = arr[1];
  5362. };
  5363. Transformable.prototype.setScale = function (arr) {
  5364. this.scaleX = arr[0];
  5365. this.scaleY = arr[1];
  5366. };
  5367. Transformable.prototype.setSkew = function (arr) {
  5368. this.skewX = arr[0];
  5369. this.skewY = arr[1];
  5370. };
  5371. Transformable.prototype.setOrigin = function (arr) {
  5372. this.originX = arr[0];
  5373. this.originY = arr[1];
  5374. };
  5375. Transformable.prototype.needLocalTransform = function () {
  5376. return isNotAroundZero$1(this.rotation)
  5377. || isNotAroundZero$1(this.x)
  5378. || isNotAroundZero$1(this.y)
  5379. || isNotAroundZero$1(this.scaleX - 1)
  5380. || isNotAroundZero$1(this.scaleY - 1)
  5381. || isNotAroundZero$1(this.skewX)
  5382. || isNotAroundZero$1(this.skewY);
  5383. };
  5384. Transformable.prototype.updateTransform = function () {
  5385. var parentTransform = this.parent && this.parent.transform;
  5386. var needLocalTransform = this.needLocalTransform();
  5387. var m = this.transform;
  5388. if (!(needLocalTransform || parentTransform)) {
  5389. if (m) {
  5390. mIdentity(m);
  5391. this.invTransform = null;
  5392. }
  5393. return;
  5394. }
  5395. m = m || create$1();
  5396. if (needLocalTransform) {
  5397. this.getLocalTransform(m);
  5398. }
  5399. else {
  5400. mIdentity(m);
  5401. }
  5402. if (parentTransform) {
  5403. if (needLocalTransform) {
  5404. mul$1(m, parentTransform, m);
  5405. }
  5406. else {
  5407. copy$1(m, parentTransform);
  5408. }
  5409. }
  5410. this.transform = m;
  5411. this._resolveGlobalScaleRatio(m);
  5412. };
  5413. Transformable.prototype._resolveGlobalScaleRatio = function (m) {
  5414. var globalScaleRatio = this.globalScaleRatio;
  5415. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  5416. this.getGlobalScale(scaleTmp);
  5417. var relX = scaleTmp[0] < 0 ? -1 : 1;
  5418. var relY = scaleTmp[1] < 0 ? -1 : 1;
  5419. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  5420. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  5421. m[0] *= sx;
  5422. m[1] *= sx;
  5423. m[2] *= sy;
  5424. m[3] *= sy;
  5425. }
  5426. this.invTransform = this.invTransform || create$1();
  5427. invert(this.invTransform, m);
  5428. };
  5429. Transformable.prototype.getComputedTransform = function () {
  5430. var transformNode = this;
  5431. var ancestors = [];
  5432. while (transformNode) {
  5433. ancestors.push(transformNode);
  5434. transformNode = transformNode.parent;
  5435. }
  5436. while (transformNode = ancestors.pop()) {
  5437. transformNode.updateTransform();
  5438. }
  5439. return this.transform;
  5440. };
  5441. Transformable.prototype.setLocalTransform = function (m) {
  5442. if (!m) {
  5443. return;
  5444. }
  5445. var sx = m[0] * m[0] + m[1] * m[1];
  5446. var sy = m[2] * m[2] + m[3] * m[3];
  5447. var rotation = Math.atan2(m[1], m[0]);
  5448. var shearX = Math.PI / 2 + rotation - Math.atan2(m[3], m[2]);
  5449. sy = Math.sqrt(sy) * Math.cos(shearX);
  5450. sx = Math.sqrt(sx);
  5451. this.skewX = shearX;
  5452. this.skewY = 0;
  5453. this.rotation = -rotation;
  5454. this.x = +m[4];
  5455. this.y = +m[5];
  5456. this.scaleX = sx;
  5457. this.scaleY = sy;
  5458. this.originX = 0;
  5459. this.originY = 0;
  5460. };
  5461. Transformable.prototype.decomposeTransform = function () {
  5462. if (!this.transform) {
  5463. return;
  5464. }
  5465. var parent = this.parent;
  5466. var m = this.transform;
  5467. if (parent && parent.transform) {
  5468. mul$1(tmpTransform, parent.invTransform, m);
  5469. m = tmpTransform;
  5470. }
  5471. var ox = this.originX;
  5472. var oy = this.originY;
  5473. if (ox || oy) {
  5474. originTransform[4] = ox;
  5475. originTransform[5] = oy;
  5476. mul$1(tmpTransform, m, originTransform);
  5477. tmpTransform[4] -= ox;
  5478. tmpTransform[5] -= oy;
  5479. m = tmpTransform;
  5480. }
  5481. this.setLocalTransform(m);
  5482. };
  5483. Transformable.prototype.getGlobalScale = function (out) {
  5484. var m = this.transform;
  5485. out = out || [];
  5486. if (!m) {
  5487. out[0] = 1;
  5488. out[1] = 1;
  5489. return out;
  5490. }
  5491. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  5492. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  5493. if (m[0] < 0) {
  5494. out[0] = -out[0];
  5495. }
  5496. if (m[3] < 0) {
  5497. out[1] = -out[1];
  5498. }
  5499. return out;
  5500. };
  5501. Transformable.prototype.transformCoordToLocal = function (x, y) {
  5502. var v2 = [x, y];
  5503. var invTransform = this.invTransform;
  5504. if (invTransform) {
  5505. applyTransform(v2, v2, invTransform);
  5506. }
  5507. return v2;
  5508. };
  5509. Transformable.prototype.transformCoordToGlobal = function (x, y) {
  5510. var v2 = [x, y];
  5511. var transform = this.transform;
  5512. if (transform) {
  5513. applyTransform(v2, v2, transform);
  5514. }
  5515. return v2;
  5516. };
  5517. Transformable.prototype.getLineScale = function () {
  5518. var m = this.transform;
  5519. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  5520. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  5521. : 1;
  5522. };
  5523. Transformable.prototype.copyTransform = function (source) {
  5524. copyTransform(this, source);
  5525. };
  5526. Transformable.getLocalTransform = function (target, m) {
  5527. m = m || [];
  5528. var ox = target.originX || 0;
  5529. var oy = target.originY || 0;
  5530. var sx = target.scaleX;
  5531. var sy = target.scaleY;
  5532. var ax = target.anchorX;
  5533. var ay = target.anchorY;
  5534. var rotation = target.rotation || 0;
  5535. var x = target.x;
  5536. var y = target.y;
  5537. var skewX = target.skewX ? Math.tan(target.skewX) : 0;
  5538. var skewY = target.skewY ? Math.tan(-target.skewY) : 0;
  5539. if (ox || oy || ax || ay) {
  5540. var dx = ox + ax;
  5541. var dy = oy + ay;
  5542. m[4] = -dx * sx - skewX * dy * sy;
  5543. m[5] = -dy * sy - skewY * dx * sx;
  5544. }
  5545. else {
  5546. m[4] = m[5] = 0;
  5547. }
  5548. m[0] = sx;
  5549. m[3] = sy;
  5550. m[1] = skewY * sx;
  5551. m[2] = skewX * sy;
  5552. rotation && rotate(m, m, rotation);
  5553. m[4] += ox + x;
  5554. m[5] += oy + y;
  5555. return m;
  5556. };
  5557. Transformable.initDefaultProps = (function () {
  5558. var proto = Transformable.prototype;
  5559. proto.scaleX =
  5560. proto.scaleY =
  5561. proto.globalScaleRatio = 1;
  5562. proto.x =
  5563. proto.y =
  5564. proto.originX =
  5565. proto.originY =
  5566. proto.skewX =
  5567. proto.skewY =
  5568. proto.rotation =
  5569. proto.anchorX =
  5570. proto.anchorY = 0;
  5571. })();
  5572. return Transformable;
  5573. }());
  5574. var TRANSFORMABLE_PROPS = [
  5575. 'x', 'y', 'originX', 'originY', 'anchorX', 'anchorY', 'rotation', 'scaleX', 'scaleY', 'skewX', 'skewY'
  5576. ];
  5577. function copyTransform(target, source) {
  5578. for (var i = 0; i < TRANSFORMABLE_PROPS.length; i++) {
  5579. var propName = TRANSFORMABLE_PROPS[i];
  5580. target[propName] = source[propName];
  5581. }
  5582. }
  5583. var textWidthCache = {};
  5584. function getWidth(text, font) {
  5585. font = font || DEFAULT_FONT;
  5586. var cacheOfFont = textWidthCache[font];
  5587. if (!cacheOfFont) {
  5588. cacheOfFont = textWidthCache[font] = new LRU(500);
  5589. }
  5590. var width = cacheOfFont.get(text);
  5591. if (width == null) {
  5592. width = platformApi.measureText(text, font).width;
  5593. cacheOfFont.put(text, width);
  5594. }
  5595. return width;
  5596. }
  5597. function innerGetBoundingRect(text, font, textAlign, textBaseline) {
  5598. var width = getWidth(text, font);
  5599. var height = getLineHeight(font);
  5600. var x = adjustTextX(0, width, textAlign);
  5601. var y = adjustTextY$1(0, height, textBaseline);
  5602. var rect = new BoundingRect(x, y, width, height);
  5603. return rect;
  5604. }
  5605. function getBoundingRect(text, font, textAlign, textBaseline) {
  5606. var textLines = ((text || '') + '').split('\n');
  5607. var len = textLines.length;
  5608. if (len === 1) {
  5609. return innerGetBoundingRect(textLines[0], font, textAlign, textBaseline);
  5610. }
  5611. else {
  5612. var uniondRect = new BoundingRect(0, 0, 0, 0);
  5613. for (var i = 0; i < textLines.length; i++) {
  5614. var rect = innerGetBoundingRect(textLines[i], font, textAlign, textBaseline);
  5615. i === 0 ? uniondRect.copy(rect) : uniondRect.union(rect);
  5616. }
  5617. return uniondRect;
  5618. }
  5619. }
  5620. function adjustTextX(x, width, textAlign) {
  5621. if (textAlign === 'right') {
  5622. x -= width;
  5623. }
  5624. else if (textAlign === 'center') {
  5625. x -= width / 2;
  5626. }
  5627. return x;
  5628. }
  5629. function adjustTextY$1(y, height, verticalAlign) {
  5630. if (verticalAlign === 'middle') {
  5631. y -= height / 2;
  5632. }
  5633. else if (verticalAlign === 'bottom') {
  5634. y -= height;
  5635. }
  5636. return y;
  5637. }
  5638. function getLineHeight(font) {
  5639. return getWidth('国', font);
  5640. }
  5641. function parsePercent(value, maxValue) {
  5642. if (typeof value === 'string') {
  5643. if (value.lastIndexOf('%') >= 0) {
  5644. return parseFloat(value) / 100 * maxValue;
  5645. }
  5646. return parseFloat(value);
  5647. }
  5648. return value;
  5649. }
  5650. function calculateTextPosition(out, opts, rect) {
  5651. var textPosition = opts.position || 'inside';
  5652. var distance = opts.distance != null ? opts.distance : 5;
  5653. var height = rect.height;
  5654. var width = rect.width;
  5655. var halfHeight = height / 2;
  5656. var x = rect.x;
  5657. var y = rect.y;
  5658. var textAlign = 'left';
  5659. var textVerticalAlign = 'top';
  5660. if (textPosition instanceof Array) {
  5661. x += parsePercent(textPosition[0], rect.width);
  5662. y += parsePercent(textPosition[1], rect.height);
  5663. textAlign = null;
  5664. textVerticalAlign = null;
  5665. }
  5666. else {
  5667. switch (textPosition) {
  5668. case 'left':
  5669. x -= distance;
  5670. y += halfHeight;
  5671. textAlign = 'right';
  5672. textVerticalAlign = 'middle';
  5673. break;
  5674. case 'right':
  5675. x += distance + width;
  5676. y += halfHeight;
  5677. textVerticalAlign = 'middle';
  5678. break;
  5679. case 'top':
  5680. x += width / 2;
  5681. y -= distance;
  5682. textAlign = 'center';
  5683. textVerticalAlign = 'bottom';
  5684. break;
  5685. case 'bottom':
  5686. x += width / 2;
  5687. y += height + distance;
  5688. textAlign = 'center';
  5689. break;
  5690. case 'inside':
  5691. x += width / 2;
  5692. y += halfHeight;
  5693. textAlign = 'center';
  5694. textVerticalAlign = 'middle';
  5695. break;
  5696. case 'insideLeft':
  5697. x += distance;
  5698. y += halfHeight;
  5699. textVerticalAlign = 'middle';
  5700. break;
  5701. case 'insideRight':
  5702. x += width - distance;
  5703. y += halfHeight;
  5704. textAlign = 'right';
  5705. textVerticalAlign = 'middle';
  5706. break;
  5707. case 'insideTop':
  5708. x += width / 2;
  5709. y += distance;
  5710. textAlign = 'center';
  5711. break;
  5712. case 'insideBottom':
  5713. x += width / 2;
  5714. y += height - distance;
  5715. textAlign = 'center';
  5716. textVerticalAlign = 'bottom';
  5717. break;
  5718. case 'insideTopLeft':
  5719. x += distance;
  5720. y += distance;
  5721. break;
  5722. case 'insideTopRight':
  5723. x += width - distance;
  5724. y += distance;
  5725. textAlign = 'right';
  5726. break;
  5727. case 'insideBottomLeft':
  5728. x += distance;
  5729. y += height - distance;
  5730. textVerticalAlign = 'bottom';
  5731. break;
  5732. case 'insideBottomRight':
  5733. x += width - distance;
  5734. y += height - distance;
  5735. textAlign = 'right';
  5736. textVerticalAlign = 'bottom';
  5737. break;
  5738. }
  5739. }
  5740. out = out || {};
  5741. out.x = x;
  5742. out.y = y;
  5743. out.align = textAlign;
  5744. out.verticalAlign = textVerticalAlign;
  5745. return out;
  5746. }
  5747. var PRESERVED_NORMAL_STATE = '__zr_normal__';
  5748. var PRIMARY_STATES_KEYS = TRANSFORMABLE_PROPS.concat(['ignore']);
  5749. var DEFAULT_ANIMATABLE_MAP = reduce(TRANSFORMABLE_PROPS, function (obj, key) {
  5750. obj[key] = true;
  5751. return obj;
  5752. }, { ignore: false });
  5753. var tmpTextPosCalcRes = {};
  5754. var tmpBoundingRect = new BoundingRect(0, 0, 0, 0);
  5755. var Element = (function () {
  5756. function Element(props) {
  5757. this.id = guid();
  5758. this.animators = [];
  5759. this.currentStates = [];
  5760. this.states = {};
  5761. this._init(props);
  5762. }
  5763. Element.prototype._init = function (props) {
  5764. this.attr(props);
  5765. };
  5766. Element.prototype.drift = function (dx, dy, e) {
  5767. switch (this.draggable) {
  5768. case 'horizontal':
  5769. dy = 0;
  5770. break;
  5771. case 'vertical':
  5772. dx = 0;
  5773. break;
  5774. }
  5775. var m = this.transform;
  5776. if (!m) {
  5777. m = this.transform = [1, 0, 0, 1, 0, 0];
  5778. }
  5779. m[4] += dx;
  5780. m[5] += dy;
  5781. this.decomposeTransform();
  5782. this.markRedraw();
  5783. };
  5784. Element.prototype.beforeUpdate = function () { };
  5785. Element.prototype.afterUpdate = function () { };
  5786. Element.prototype.update = function () {
  5787. this.updateTransform();
  5788. if (this.__dirty) {
  5789. this.updateInnerText();
  5790. }
  5791. };
  5792. Element.prototype.updateInnerText = function (forceUpdate) {
  5793. var textEl = this._textContent;
  5794. if (textEl && (!textEl.ignore || forceUpdate)) {
  5795. if (!this.textConfig) {
  5796. this.textConfig = {};
  5797. }
  5798. var textConfig = this.textConfig;
  5799. var isLocal = textConfig.local;
  5800. var innerTransformable = textEl.innerTransformable;
  5801. var textAlign = void 0;
  5802. var textVerticalAlign = void 0;
  5803. var textStyleChanged = false;
  5804. innerTransformable.parent = isLocal ? this : null;
  5805. var innerOrigin = false;
  5806. innerTransformable.copyTransform(textEl);
  5807. if (textConfig.position != null) {
  5808. var layoutRect = tmpBoundingRect;
  5809. if (textConfig.layoutRect) {
  5810. layoutRect.copy(textConfig.layoutRect);
  5811. }
  5812. else {
  5813. layoutRect.copy(this.getBoundingRect());
  5814. }
  5815. if (!isLocal) {
  5816. layoutRect.applyTransform(this.transform);
  5817. }
  5818. if (this.calculateTextPosition) {
  5819. this.calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5820. }
  5821. else {
  5822. calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5823. }
  5824. innerTransformable.x = tmpTextPosCalcRes.x;
  5825. innerTransformable.y = tmpTextPosCalcRes.y;
  5826. textAlign = tmpTextPosCalcRes.align;
  5827. textVerticalAlign = tmpTextPosCalcRes.verticalAlign;
  5828. var textOrigin = textConfig.origin;
  5829. if (textOrigin && textConfig.rotation != null) {
  5830. var relOriginX = void 0;
  5831. var relOriginY = void 0;
  5832. if (textOrigin === 'center') {
  5833. relOriginX = layoutRect.width * 0.5;
  5834. relOriginY = layoutRect.height * 0.5;
  5835. }
  5836. else {
  5837. relOriginX = parsePercent(textOrigin[0], layoutRect.width);
  5838. relOriginY = parsePercent(textOrigin[1], layoutRect.height);
  5839. }
  5840. innerOrigin = true;
  5841. innerTransformable.originX = -innerTransformable.x + relOriginX + (isLocal ? 0 : layoutRect.x);
  5842. innerTransformable.originY = -innerTransformable.y + relOriginY + (isLocal ? 0 : layoutRect.y);
  5843. }
  5844. }
  5845. if (textConfig.rotation != null) {
  5846. innerTransformable.rotation = textConfig.rotation;
  5847. }
  5848. var textOffset = textConfig.offset;
  5849. if (textOffset) {
  5850. innerTransformable.x += textOffset[0];
  5851. innerTransformable.y += textOffset[1];
  5852. if (!innerOrigin) {
  5853. innerTransformable.originX = -textOffset[0];
  5854. innerTransformable.originY = -textOffset[1];
  5855. }
  5856. }
  5857. var isInside = textConfig.inside == null
  5858. ? (typeof textConfig.position === 'string' && textConfig.position.indexOf('inside') >= 0)
  5859. : textConfig.inside;
  5860. var innerTextDefaultStyle = this._innerTextDefaultStyle || (this._innerTextDefaultStyle = {});
  5861. var textFill = void 0;
  5862. var textStroke = void 0;
  5863. var autoStroke = void 0;
  5864. if (isInside && this.canBeInsideText()) {
  5865. textFill = textConfig.insideFill;
  5866. textStroke = textConfig.insideStroke;
  5867. if (textFill == null || textFill === 'auto') {
  5868. textFill = this.getInsideTextFill();
  5869. }
  5870. if (textStroke == null || textStroke === 'auto') {
  5871. textStroke = this.getInsideTextStroke(textFill);
  5872. autoStroke = true;
  5873. }
  5874. }
  5875. else {
  5876. textFill = textConfig.outsideFill;
  5877. textStroke = textConfig.outsideStroke;
  5878. if (textFill == null || textFill === 'auto') {
  5879. textFill = this.getOutsideFill();
  5880. }
  5881. if (textStroke == null || textStroke === 'auto') {
  5882. textStroke = this.getOutsideStroke(textFill);
  5883. autoStroke = true;
  5884. }
  5885. }
  5886. textFill = textFill || '#000';
  5887. if (textFill !== innerTextDefaultStyle.fill
  5888. || textStroke !== innerTextDefaultStyle.stroke
  5889. || autoStroke !== innerTextDefaultStyle.autoStroke
  5890. || textAlign !== innerTextDefaultStyle.align
  5891. || textVerticalAlign !== innerTextDefaultStyle.verticalAlign) {
  5892. textStyleChanged = true;
  5893. innerTextDefaultStyle.fill = textFill;
  5894. innerTextDefaultStyle.stroke = textStroke;
  5895. innerTextDefaultStyle.autoStroke = autoStroke;
  5896. innerTextDefaultStyle.align = textAlign;
  5897. innerTextDefaultStyle.verticalAlign = textVerticalAlign;
  5898. textEl.setDefaultTextStyle(innerTextDefaultStyle);
  5899. }
  5900. textEl.__dirty |= REDRAW_BIT;
  5901. if (textStyleChanged) {
  5902. textEl.dirtyStyle(true);
  5903. }
  5904. }
  5905. };
  5906. Element.prototype.canBeInsideText = function () {
  5907. return true;
  5908. };
  5909. Element.prototype.getInsideTextFill = function () {
  5910. return '#fff';
  5911. };
  5912. Element.prototype.getInsideTextStroke = function (textFill) {
  5913. return '#000';
  5914. };
  5915. Element.prototype.getOutsideFill = function () {
  5916. return this.__zr && this.__zr.isDarkMode() ? LIGHT_LABEL_COLOR : DARK_LABEL_COLOR;
  5917. };
  5918. Element.prototype.getOutsideStroke = function (textFill) {
  5919. var backgroundColor = this.__zr && this.__zr.getBackgroundColor();
  5920. var colorArr = typeof backgroundColor === 'string' && parse(backgroundColor);
  5921. if (!colorArr) {
  5922. colorArr = [255, 255, 255, 1];
  5923. }
  5924. var alpha = colorArr[3];
  5925. var isDark = this.__zr.isDarkMode();
  5926. for (var i = 0; i < 3; i++) {
  5927. colorArr[i] = colorArr[i] * alpha + (isDark ? 0 : 255) * (1 - alpha);
  5928. }
  5929. colorArr[3] = 1;
  5930. return stringify(colorArr, 'rgba');
  5931. };
  5932. Element.prototype.traverse = function (cb, context) { };
  5933. Element.prototype.attrKV = function (key, value) {
  5934. if (key === 'textConfig') {
  5935. this.setTextConfig(value);
  5936. }
  5937. else if (key === 'textContent') {
  5938. this.setTextContent(value);
  5939. }
  5940. else if (key === 'clipPath') {
  5941. this.setClipPath(value);
  5942. }
  5943. else if (key === 'extra') {
  5944. this.extra = this.extra || {};
  5945. extend(this.extra, value);
  5946. }
  5947. else {
  5948. this[key] = value;
  5949. }
  5950. };
  5951. Element.prototype.hide = function () {
  5952. this.ignore = true;
  5953. this.markRedraw();
  5954. };
  5955. Element.prototype.show = function () {
  5956. this.ignore = false;
  5957. this.markRedraw();
  5958. };
  5959. Element.prototype.attr = function (keyOrObj, value) {
  5960. if (typeof keyOrObj === 'string') {
  5961. this.attrKV(keyOrObj, value);
  5962. }
  5963. else if (isObject(keyOrObj)) {
  5964. var obj = keyOrObj;
  5965. var keysArr = keys(obj);
  5966. for (var i = 0; i < keysArr.length; i++) {
  5967. var key = keysArr[i];
  5968. this.attrKV(key, keyOrObj[key]);
  5969. }
  5970. }
  5971. this.markRedraw();
  5972. return this;
  5973. };
  5974. Element.prototype.saveCurrentToNormalState = function (toState) {
  5975. this._innerSaveToNormal(toState);
  5976. var normalState = this._normalState;
  5977. for (var i = 0; i < this.animators.length; i++) {
  5978. var animator = this.animators[i];
  5979. var fromStateTransition = animator.__fromStateTransition;
  5980. if (animator.getLoop() || fromStateTransition && fromStateTransition !== PRESERVED_NORMAL_STATE) {
  5981. continue;
  5982. }
  5983. var targetName = animator.targetName;
  5984. var target = targetName
  5985. ? normalState[targetName] : normalState;
  5986. animator.saveTo(target);
  5987. }
  5988. };
  5989. Element.prototype._innerSaveToNormal = function (toState) {
  5990. var normalState = this._normalState;
  5991. if (!normalState) {
  5992. normalState = this._normalState = {};
  5993. }
  5994. if (toState.textConfig && !normalState.textConfig) {
  5995. normalState.textConfig = this.textConfig;
  5996. }
  5997. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS);
  5998. };
  5999. Element.prototype._savePrimaryToNormal = function (toState, normalState, primaryKeys) {
  6000. for (var i = 0; i < primaryKeys.length; i++) {
  6001. var key = primaryKeys[i];
  6002. if (toState[key] != null && !(key in normalState)) {
  6003. normalState[key] = this[key];
  6004. }
  6005. }
  6006. };
  6007. Element.prototype.hasState = function () {
  6008. return this.currentStates.length > 0;
  6009. };
  6010. Element.prototype.getState = function (name) {
  6011. return this.states[name];
  6012. };
  6013. Element.prototype.ensureState = function (name) {
  6014. var states = this.states;
  6015. if (!states[name]) {
  6016. states[name] = {};
  6017. }
  6018. return states[name];
  6019. };
  6020. Element.prototype.clearStates = function (noAnimation) {
  6021. this.useState(PRESERVED_NORMAL_STATE, false, noAnimation);
  6022. };
  6023. Element.prototype.useState = function (stateName, keepCurrentStates, noAnimation, forceUseHoverLayer) {
  6024. var toNormalState = stateName === PRESERVED_NORMAL_STATE;
  6025. var hasStates = this.hasState();
  6026. if (!hasStates && toNormalState) {
  6027. return;
  6028. }
  6029. var currentStates = this.currentStates;
  6030. var animationCfg = this.stateTransition;
  6031. if (indexOf(currentStates, stateName) >= 0 && (keepCurrentStates || currentStates.length === 1)) {
  6032. return;
  6033. }
  6034. var state;
  6035. if (this.stateProxy && !toNormalState) {
  6036. state = this.stateProxy(stateName);
  6037. }
  6038. if (!state) {
  6039. state = (this.states && this.states[stateName]);
  6040. }
  6041. if (!state && !toNormalState) {
  6042. logError("State " + stateName + " not exists.");
  6043. return;
  6044. }
  6045. if (!toNormalState) {
  6046. this.saveCurrentToNormalState(state);
  6047. }
  6048. var useHoverLayer = !!((state && state.hoverLayer) || forceUseHoverLayer);
  6049. if (useHoverLayer) {
  6050. this._toggleHoverLayerFlag(true);
  6051. }
  6052. this._applyStateObj(stateName, state, this._normalState, keepCurrentStates, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6053. var textContent = this._textContent;
  6054. var textGuide = this._textGuide;
  6055. if (textContent) {
  6056. textContent.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6057. }
  6058. if (textGuide) {
  6059. textGuide.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6060. }
  6061. if (toNormalState) {
  6062. this.currentStates = [];
  6063. this._normalState = {};
  6064. }
  6065. else {
  6066. if (!keepCurrentStates) {
  6067. this.currentStates = [stateName];
  6068. }
  6069. else {
  6070. this.currentStates.push(stateName);
  6071. }
  6072. }
  6073. this._updateAnimationTargets();
  6074. this.markRedraw();
  6075. if (!useHoverLayer && this.__inHover) {
  6076. this._toggleHoverLayerFlag(false);
  6077. this.__dirty &= ~REDRAW_BIT;
  6078. }
  6079. return state;
  6080. };
  6081. Element.prototype.useStates = function (states, noAnimation, forceUseHoverLayer) {
  6082. if (!states.length) {
  6083. this.clearStates();
  6084. }
  6085. else {
  6086. var stateObjects = [];
  6087. var currentStates = this.currentStates;
  6088. var len = states.length;
  6089. var notChange = len === currentStates.length;
  6090. if (notChange) {
  6091. for (var i = 0; i < len; i++) {
  6092. if (states[i] !== currentStates[i]) {
  6093. notChange = false;
  6094. break;
  6095. }
  6096. }
  6097. }
  6098. if (notChange) {
  6099. return;
  6100. }
  6101. for (var i = 0; i < len; i++) {
  6102. var stateName = states[i];
  6103. var stateObj = void 0;
  6104. if (this.stateProxy) {
  6105. stateObj = this.stateProxy(stateName, states);
  6106. }
  6107. if (!stateObj) {
  6108. stateObj = this.states[stateName];
  6109. }
  6110. if (stateObj) {
  6111. stateObjects.push(stateObj);
  6112. }
  6113. }
  6114. var lastStateObj = stateObjects[len - 1];
  6115. var useHoverLayer = !!((lastStateObj && lastStateObj.hoverLayer) || forceUseHoverLayer);
  6116. if (useHoverLayer) {
  6117. this._toggleHoverLayerFlag(true);
  6118. }
  6119. var mergedState = this._mergeStates(stateObjects);
  6120. var animationCfg = this.stateTransition;
  6121. this.saveCurrentToNormalState(mergedState);
  6122. this._applyStateObj(states.join(','), mergedState, this._normalState, false, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6123. var textContent = this._textContent;
  6124. var textGuide = this._textGuide;
  6125. if (textContent) {
  6126. textContent.useStates(states, noAnimation, useHoverLayer);
  6127. }
  6128. if (textGuide) {
  6129. textGuide.useStates(states, noAnimation, useHoverLayer);
  6130. }
  6131. this._updateAnimationTargets();
  6132. this.currentStates = states.slice();
  6133. this.markRedraw();
  6134. if (!useHoverLayer && this.__inHover) {
  6135. this._toggleHoverLayerFlag(false);
  6136. this.__dirty &= ~REDRAW_BIT;
  6137. }
  6138. }
  6139. };
  6140. Element.prototype._updateAnimationTargets = function () {
  6141. for (var i = 0; i < this.animators.length; i++) {
  6142. var animator = this.animators[i];
  6143. if (animator.targetName) {
  6144. animator.changeTarget(this[animator.targetName]);
  6145. }
  6146. }
  6147. };
  6148. Element.prototype.removeState = function (state) {
  6149. var idx = indexOf(this.currentStates, state);
  6150. if (idx >= 0) {
  6151. var currentStates = this.currentStates.slice();
  6152. currentStates.splice(idx, 1);
  6153. this.useStates(currentStates);
  6154. }
  6155. };
  6156. Element.prototype.replaceState = function (oldState, newState, forceAdd) {
  6157. var currentStates = this.currentStates.slice();
  6158. var idx = indexOf(currentStates, oldState);
  6159. var newStateExists = indexOf(currentStates, newState) >= 0;
  6160. if (idx >= 0) {
  6161. if (!newStateExists) {
  6162. currentStates[idx] = newState;
  6163. }
  6164. else {
  6165. currentStates.splice(idx, 1);
  6166. }
  6167. }
  6168. else if (forceAdd && !newStateExists) {
  6169. currentStates.push(newState);
  6170. }
  6171. this.useStates(currentStates);
  6172. };
  6173. Element.prototype.toggleState = function (state, enable) {
  6174. if (enable) {
  6175. this.useState(state, true);
  6176. }
  6177. else {
  6178. this.removeState(state);
  6179. }
  6180. };
  6181. Element.prototype._mergeStates = function (states) {
  6182. var mergedState = {};
  6183. var mergedTextConfig;
  6184. for (var i = 0; i < states.length; i++) {
  6185. var state = states[i];
  6186. extend(mergedState, state);
  6187. if (state.textConfig) {
  6188. mergedTextConfig = mergedTextConfig || {};
  6189. extend(mergedTextConfig, state.textConfig);
  6190. }
  6191. }
  6192. if (mergedTextConfig) {
  6193. mergedState.textConfig = mergedTextConfig;
  6194. }
  6195. return mergedState;
  6196. };
  6197. Element.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  6198. var needsRestoreToNormal = !(state && keepCurrentStates);
  6199. if (state && state.textConfig) {
  6200. this.textConfig = extend({}, keepCurrentStates ? this.textConfig : normalState.textConfig);
  6201. extend(this.textConfig, state.textConfig);
  6202. }
  6203. else if (needsRestoreToNormal) {
  6204. if (normalState.textConfig) {
  6205. this.textConfig = normalState.textConfig;
  6206. }
  6207. }
  6208. var transitionTarget = {};
  6209. var hasTransition = false;
  6210. for (var i = 0; i < PRIMARY_STATES_KEYS.length; i++) {
  6211. var key = PRIMARY_STATES_KEYS[i];
  6212. var propNeedsTransition = transition && DEFAULT_ANIMATABLE_MAP[key];
  6213. if (state && state[key] != null) {
  6214. if (propNeedsTransition) {
  6215. hasTransition = true;
  6216. transitionTarget[key] = state[key];
  6217. }
  6218. else {
  6219. this[key] = state[key];
  6220. }
  6221. }
  6222. else if (needsRestoreToNormal) {
  6223. if (normalState[key] != null) {
  6224. if (propNeedsTransition) {
  6225. hasTransition = true;
  6226. transitionTarget[key] = normalState[key];
  6227. }
  6228. else {
  6229. this[key] = normalState[key];
  6230. }
  6231. }
  6232. }
  6233. }
  6234. if (!transition) {
  6235. for (var i = 0; i < this.animators.length; i++) {
  6236. var animator = this.animators[i];
  6237. var targetName = animator.targetName;
  6238. if (!animator.getLoop()) {
  6239. animator.__changeFinalValue(targetName
  6240. ? (state || normalState)[targetName]
  6241. : (state || normalState));
  6242. }
  6243. }
  6244. }
  6245. if (hasTransition) {
  6246. this._transitionState(stateName, transitionTarget, animationCfg);
  6247. }
  6248. };
  6249. Element.prototype._attachComponent = function (componentEl) {
  6250. if (componentEl.__zr && !componentEl.__hostTarget) {
  6251. {
  6252. throw new Error('Text element has been added to zrender.');
  6253. }
  6254. }
  6255. if (componentEl === this) {
  6256. {
  6257. throw new Error('Recursive component attachment.');
  6258. }
  6259. }
  6260. var zr = this.__zr;
  6261. if (zr) {
  6262. componentEl.addSelfToZr(zr);
  6263. }
  6264. componentEl.__zr = zr;
  6265. componentEl.__hostTarget = this;
  6266. };
  6267. Element.prototype._detachComponent = function (componentEl) {
  6268. if (componentEl.__zr) {
  6269. componentEl.removeSelfFromZr(componentEl.__zr);
  6270. }
  6271. componentEl.__zr = null;
  6272. componentEl.__hostTarget = null;
  6273. };
  6274. Element.prototype.getClipPath = function () {
  6275. return this._clipPath;
  6276. };
  6277. Element.prototype.setClipPath = function (clipPath) {
  6278. if (this._clipPath && this._clipPath !== clipPath) {
  6279. this.removeClipPath();
  6280. }
  6281. this._attachComponent(clipPath);
  6282. this._clipPath = clipPath;
  6283. this.markRedraw();
  6284. };
  6285. Element.prototype.removeClipPath = function () {
  6286. var clipPath = this._clipPath;
  6287. if (clipPath) {
  6288. this._detachComponent(clipPath);
  6289. this._clipPath = null;
  6290. this.markRedraw();
  6291. }
  6292. };
  6293. Element.prototype.getTextContent = function () {
  6294. return this._textContent;
  6295. };
  6296. Element.prototype.setTextContent = function (textEl) {
  6297. var previousTextContent = this._textContent;
  6298. if (previousTextContent === textEl) {
  6299. return;
  6300. }
  6301. if (previousTextContent && previousTextContent !== textEl) {
  6302. this.removeTextContent();
  6303. }
  6304. {
  6305. if (textEl.__zr && !textEl.__hostTarget) {
  6306. throw new Error('Text element has been added to zrender.');
  6307. }
  6308. }
  6309. textEl.innerTransformable = new Transformable();
  6310. this._attachComponent(textEl);
  6311. this._textContent = textEl;
  6312. this.markRedraw();
  6313. };
  6314. Element.prototype.setTextConfig = function (cfg) {
  6315. if (!this.textConfig) {
  6316. this.textConfig = {};
  6317. }
  6318. extend(this.textConfig, cfg);
  6319. this.markRedraw();
  6320. };
  6321. Element.prototype.removeTextConfig = function () {
  6322. this.textConfig = null;
  6323. this.markRedraw();
  6324. };
  6325. Element.prototype.removeTextContent = function () {
  6326. var textEl = this._textContent;
  6327. if (textEl) {
  6328. textEl.innerTransformable = null;
  6329. this._detachComponent(textEl);
  6330. this._textContent = null;
  6331. this._innerTextDefaultStyle = null;
  6332. this.markRedraw();
  6333. }
  6334. };
  6335. Element.prototype.getTextGuideLine = function () {
  6336. return this._textGuide;
  6337. };
  6338. Element.prototype.setTextGuideLine = function (guideLine) {
  6339. if (this._textGuide && this._textGuide !== guideLine) {
  6340. this.removeTextGuideLine();
  6341. }
  6342. this._attachComponent(guideLine);
  6343. this._textGuide = guideLine;
  6344. this.markRedraw();
  6345. };
  6346. Element.prototype.removeTextGuideLine = function () {
  6347. var textGuide = this._textGuide;
  6348. if (textGuide) {
  6349. this._detachComponent(textGuide);
  6350. this._textGuide = null;
  6351. this.markRedraw();
  6352. }
  6353. };
  6354. Element.prototype.markRedraw = function () {
  6355. this.__dirty |= REDRAW_BIT;
  6356. var zr = this.__zr;
  6357. if (zr) {
  6358. if (this.__inHover) {
  6359. zr.refreshHover();
  6360. }
  6361. else {
  6362. zr.refresh();
  6363. }
  6364. }
  6365. if (this.__hostTarget) {
  6366. this.__hostTarget.markRedraw();
  6367. }
  6368. };
  6369. Element.prototype.dirty = function () {
  6370. this.markRedraw();
  6371. };
  6372. Element.prototype._toggleHoverLayerFlag = function (inHover) {
  6373. this.__inHover = inHover;
  6374. var textContent = this._textContent;
  6375. var textGuide = this._textGuide;
  6376. if (textContent) {
  6377. textContent.__inHover = inHover;
  6378. }
  6379. if (textGuide) {
  6380. textGuide.__inHover = inHover;
  6381. }
  6382. };
  6383. Element.prototype.addSelfToZr = function (zr) {
  6384. if (this.__zr === zr) {
  6385. return;
  6386. }
  6387. this.__zr = zr;
  6388. var animators = this.animators;
  6389. if (animators) {
  6390. for (var i = 0; i < animators.length; i++) {
  6391. zr.animation.addAnimator(animators[i]);
  6392. }
  6393. }
  6394. if (this._clipPath) {
  6395. this._clipPath.addSelfToZr(zr);
  6396. }
  6397. if (this._textContent) {
  6398. this._textContent.addSelfToZr(zr);
  6399. }
  6400. if (this._textGuide) {
  6401. this._textGuide.addSelfToZr(zr);
  6402. }
  6403. };
  6404. Element.prototype.removeSelfFromZr = function (zr) {
  6405. if (!this.__zr) {
  6406. return;
  6407. }
  6408. this.__zr = null;
  6409. var animators = this.animators;
  6410. if (animators) {
  6411. for (var i = 0; i < animators.length; i++) {
  6412. zr.animation.removeAnimator(animators[i]);
  6413. }
  6414. }
  6415. if (this._clipPath) {
  6416. this._clipPath.removeSelfFromZr(zr);
  6417. }
  6418. if (this._textContent) {
  6419. this._textContent.removeSelfFromZr(zr);
  6420. }
  6421. if (this._textGuide) {
  6422. this._textGuide.removeSelfFromZr(zr);
  6423. }
  6424. };
  6425. Element.prototype.animate = function (key, loop, allowDiscreteAnimation) {
  6426. var target = key ? this[key] : this;
  6427. {
  6428. if (!target) {
  6429. logError('Property "'
  6430. + key
  6431. + '" is not existed in element '
  6432. + this.id);
  6433. return;
  6434. }
  6435. }
  6436. var animator = new Animator(target, loop, allowDiscreteAnimation);
  6437. key && (animator.targetName = key);
  6438. this.addAnimator(animator, key);
  6439. return animator;
  6440. };
  6441. Element.prototype.addAnimator = function (animator, key) {
  6442. var zr = this.__zr;
  6443. var el = this;
  6444. animator.during(function () {
  6445. el.updateDuringAnimation(key);
  6446. }).done(function () {
  6447. var animators = el.animators;
  6448. var idx = indexOf(animators, animator);
  6449. if (idx >= 0) {
  6450. animators.splice(idx, 1);
  6451. }
  6452. });
  6453. this.animators.push(animator);
  6454. if (zr) {
  6455. zr.animation.addAnimator(animator);
  6456. }
  6457. zr && zr.wakeUp();
  6458. };
  6459. Element.prototype.updateDuringAnimation = function (key) {
  6460. this.markRedraw();
  6461. };
  6462. Element.prototype.stopAnimation = function (scope, forwardToLast) {
  6463. var animators = this.animators;
  6464. var len = animators.length;
  6465. var leftAnimators = [];
  6466. for (var i = 0; i < len; i++) {
  6467. var animator = animators[i];
  6468. if (!scope || scope === animator.scope) {
  6469. animator.stop(forwardToLast);
  6470. }
  6471. else {
  6472. leftAnimators.push(animator);
  6473. }
  6474. }
  6475. this.animators = leftAnimators;
  6476. return this;
  6477. };
  6478. Element.prototype.animateTo = function (target, cfg, animationProps) {
  6479. animateTo(this, target, cfg, animationProps);
  6480. };
  6481. Element.prototype.animateFrom = function (target, cfg, animationProps) {
  6482. animateTo(this, target, cfg, animationProps, true);
  6483. };
  6484. Element.prototype._transitionState = function (stateName, target, cfg, animationProps) {
  6485. var animators = animateTo(this, target, cfg, animationProps);
  6486. for (var i = 0; i < animators.length; i++) {
  6487. animators[i].__fromStateTransition = stateName;
  6488. }
  6489. };
  6490. Element.prototype.getBoundingRect = function () {
  6491. return null;
  6492. };
  6493. Element.prototype.getPaintRect = function () {
  6494. return null;
  6495. };
  6496. Element.initDefaultProps = (function () {
  6497. var elProto = Element.prototype;
  6498. elProto.type = 'element';
  6499. elProto.name = '';
  6500. elProto.ignore =
  6501. elProto.silent =
  6502. elProto.isGroup =
  6503. elProto.draggable =
  6504. elProto.dragging =
  6505. elProto.ignoreClip =
  6506. elProto.__inHover = false;
  6507. elProto.__dirty = REDRAW_BIT;
  6508. var logs = {};
  6509. function logDeprecatedError(key, xKey, yKey) {
  6510. if (!logs[key + xKey + yKey]) {
  6511. console.warn("DEPRECATED: '" + key + "' has been deprecated. use '" + xKey + "', '" + yKey + "' instead");
  6512. logs[key + xKey + yKey] = true;
  6513. }
  6514. }
  6515. function createLegacyProperty(key, privateKey, xKey, yKey) {
  6516. Object.defineProperty(elProto, key, {
  6517. get: function () {
  6518. {
  6519. logDeprecatedError(key, xKey, yKey);
  6520. }
  6521. if (!this[privateKey]) {
  6522. var pos = this[privateKey] = [];
  6523. enhanceArray(this, pos);
  6524. }
  6525. return this[privateKey];
  6526. },
  6527. set: function (pos) {
  6528. {
  6529. logDeprecatedError(key, xKey, yKey);
  6530. }
  6531. this[xKey] = pos[0];
  6532. this[yKey] = pos[1];
  6533. this[privateKey] = pos;
  6534. enhanceArray(this, pos);
  6535. }
  6536. });
  6537. function enhanceArray(self, pos) {
  6538. Object.defineProperty(pos, 0, {
  6539. get: function () {
  6540. return self[xKey];
  6541. },
  6542. set: function (val) {
  6543. self[xKey] = val;
  6544. }
  6545. });
  6546. Object.defineProperty(pos, 1, {
  6547. get: function () {
  6548. return self[yKey];
  6549. },
  6550. set: function (val) {
  6551. self[yKey] = val;
  6552. }
  6553. });
  6554. }
  6555. }
  6556. if (Object.defineProperty) {
  6557. createLegacyProperty('position', '_legacyPos', 'x', 'y');
  6558. createLegacyProperty('scale', '_legacyScale', 'scaleX', 'scaleY');
  6559. createLegacyProperty('origin', '_legacyOrigin', 'originX', 'originY');
  6560. }
  6561. })();
  6562. return Element;
  6563. }());
  6564. mixin(Element, Eventful);
  6565. mixin(Element, Transformable);
  6566. function animateTo(animatable, target, cfg, animationProps, reverse) {
  6567. cfg = cfg || {};
  6568. var animators = [];
  6569. animateToShallow(animatable, '', animatable, target, cfg, animationProps, animators, reverse);
  6570. var finishCount = animators.length;
  6571. var doneHappened = false;
  6572. var cfgDone = cfg.done;
  6573. var cfgAborted = cfg.aborted;
  6574. var doneCb = function () {
  6575. doneHappened = true;
  6576. finishCount--;
  6577. if (finishCount <= 0) {
  6578. doneHappened
  6579. ? (cfgDone && cfgDone())
  6580. : (cfgAborted && cfgAborted());
  6581. }
  6582. };
  6583. var abortedCb = function () {
  6584. finishCount--;
  6585. if (finishCount <= 0) {
  6586. doneHappened
  6587. ? (cfgDone && cfgDone())
  6588. : (cfgAborted && cfgAborted());
  6589. }
  6590. };
  6591. if (!finishCount) {
  6592. cfgDone && cfgDone();
  6593. }
  6594. if (animators.length > 0 && cfg.during) {
  6595. animators[0].during(function (target, percent) {
  6596. cfg.during(percent);
  6597. });
  6598. }
  6599. for (var i = 0; i < animators.length; i++) {
  6600. var animator = animators[i];
  6601. if (doneCb) {
  6602. animator.done(doneCb);
  6603. }
  6604. if (abortedCb) {
  6605. animator.aborted(abortedCb);
  6606. }
  6607. if (cfg.force) {
  6608. animator.duration(cfg.duration);
  6609. }
  6610. animator.start(cfg.easing);
  6611. }
  6612. return animators;
  6613. }
  6614. function copyArrShallow(source, target, len) {
  6615. for (var i = 0; i < len; i++) {
  6616. source[i] = target[i];
  6617. }
  6618. }
  6619. function is2DArray(value) {
  6620. return isArrayLike(value[0]);
  6621. }
  6622. function copyValue(target, source, key) {
  6623. if (isArrayLike(source[key])) {
  6624. if (!isArrayLike(target[key])) {
  6625. target[key] = [];
  6626. }
  6627. if (isTypedArray(source[key])) {
  6628. var len = source[key].length;
  6629. if (target[key].length !== len) {
  6630. target[key] = new (source[key].constructor)(len);
  6631. copyArrShallow(target[key], source[key], len);
  6632. }
  6633. }
  6634. else {
  6635. var sourceArr = source[key];
  6636. var targetArr = target[key];
  6637. var len0 = sourceArr.length;
  6638. if (is2DArray(sourceArr)) {
  6639. var len1 = sourceArr[0].length;
  6640. for (var i = 0; i < len0; i++) {
  6641. if (!targetArr[i]) {
  6642. targetArr[i] = Array.prototype.slice.call(sourceArr[i]);
  6643. }
  6644. else {
  6645. copyArrShallow(targetArr[i], sourceArr[i], len1);
  6646. }
  6647. }
  6648. }
  6649. else {
  6650. copyArrShallow(targetArr, sourceArr, len0);
  6651. }
  6652. targetArr.length = sourceArr.length;
  6653. }
  6654. }
  6655. else {
  6656. target[key] = source[key];
  6657. }
  6658. }
  6659. function isValueSame(val1, val2) {
  6660. return val1 === val2
  6661. || isArrayLike(val1) && isArrayLike(val2) && is1DArraySame(val1, val2);
  6662. }
  6663. function is1DArraySame(arr0, arr1) {
  6664. var len = arr0.length;
  6665. if (len !== arr1.length) {
  6666. return false;
  6667. }
  6668. for (var i = 0; i < len; i++) {
  6669. if (arr0[i] !== arr1[i]) {
  6670. return false;
  6671. }
  6672. }
  6673. return true;
  6674. }
  6675. function animateToShallow(animatable, topKey, animateObj, target, cfg, animationProps, animators, reverse) {
  6676. var targetKeys = keys(target);
  6677. var duration = cfg.duration;
  6678. var delay = cfg.delay;
  6679. var additive = cfg.additive;
  6680. var setToFinal = cfg.setToFinal;
  6681. var animateAll = !isObject(animationProps);
  6682. var existsAnimators = animatable.animators;
  6683. var animationKeys = [];
  6684. for (var k = 0; k < targetKeys.length; k++) {
  6685. var innerKey = targetKeys[k];
  6686. var targetVal = target[innerKey];
  6687. if (targetVal != null && animateObj[innerKey] != null
  6688. && (animateAll || animationProps[innerKey])) {
  6689. if (isObject(targetVal)
  6690. && !isArrayLike(targetVal)
  6691. && !isGradientObject(targetVal)) {
  6692. if (topKey) {
  6693. if (!reverse) {
  6694. animateObj[innerKey] = targetVal;
  6695. animatable.updateDuringAnimation(topKey);
  6696. }
  6697. continue;
  6698. }
  6699. animateToShallow(animatable, innerKey, animateObj[innerKey], targetVal, cfg, animationProps && animationProps[innerKey], animators, reverse);
  6700. }
  6701. else {
  6702. animationKeys.push(innerKey);
  6703. }
  6704. }
  6705. else if (!reverse) {
  6706. animateObj[innerKey] = targetVal;
  6707. animatable.updateDuringAnimation(topKey);
  6708. animationKeys.push(innerKey);
  6709. }
  6710. }
  6711. var keyLen = animationKeys.length;
  6712. if (!additive && keyLen) {
  6713. for (var i = 0; i < existsAnimators.length; i++) {
  6714. var animator = existsAnimators[i];
  6715. if (animator.targetName === topKey) {
  6716. var allAborted = animator.stopTracks(animationKeys);
  6717. if (allAborted) {
  6718. var idx = indexOf(existsAnimators, animator);
  6719. existsAnimators.splice(idx, 1);
  6720. }
  6721. }
  6722. }
  6723. }
  6724. if (!cfg.force) {
  6725. animationKeys = filter(animationKeys, function (key) { return !isValueSame(target[key], animateObj[key]); });
  6726. keyLen = animationKeys.length;
  6727. }
  6728. if (keyLen > 0
  6729. || (cfg.force && !animators.length)) {
  6730. var revertedSource = void 0;
  6731. var reversedTarget = void 0;
  6732. var sourceClone = void 0;
  6733. if (reverse) {
  6734. reversedTarget = {};
  6735. if (setToFinal) {
  6736. revertedSource = {};
  6737. }
  6738. for (var i = 0; i < keyLen; i++) {
  6739. var innerKey = animationKeys[i];
  6740. reversedTarget[innerKey] = animateObj[innerKey];
  6741. if (setToFinal) {
  6742. revertedSource[innerKey] = target[innerKey];
  6743. }
  6744. else {
  6745. animateObj[innerKey] = target[innerKey];
  6746. }
  6747. }
  6748. }
  6749. else if (setToFinal) {
  6750. sourceClone = {};
  6751. for (var i = 0; i < keyLen; i++) {
  6752. var innerKey = animationKeys[i];
  6753. sourceClone[innerKey] = cloneValue(animateObj[innerKey]);
  6754. copyValue(animateObj, target, innerKey);
  6755. }
  6756. }
  6757. var animator = new Animator(animateObj, false, false, additive ? filter(existsAnimators, function (animator) { return animator.targetName === topKey; }) : null);
  6758. animator.targetName = topKey;
  6759. if (cfg.scope) {
  6760. animator.scope = cfg.scope;
  6761. }
  6762. if (setToFinal && revertedSource) {
  6763. animator.whenWithKeys(0, revertedSource, animationKeys);
  6764. }
  6765. if (sourceClone) {
  6766. animator.whenWithKeys(0, sourceClone, animationKeys);
  6767. }
  6768. animator.whenWithKeys(duration == null ? 500 : duration, reverse ? reversedTarget : target, animationKeys).delay(delay || 0);
  6769. animatable.addAnimator(animator, topKey);
  6770. animators.push(animator);
  6771. }
  6772. }
  6773. var Group = (function (_super) {
  6774. __extends(Group, _super);
  6775. function Group(opts) {
  6776. var _this = _super.call(this) || this;
  6777. _this.isGroup = true;
  6778. _this._children = [];
  6779. _this.attr(opts);
  6780. return _this;
  6781. }
  6782. Group.prototype.childrenRef = function () {
  6783. return this._children;
  6784. };
  6785. Group.prototype.children = function () {
  6786. return this._children.slice();
  6787. };
  6788. Group.prototype.childAt = function (idx) {
  6789. return this._children[idx];
  6790. };
  6791. Group.prototype.childOfName = function (name) {
  6792. var children = this._children;
  6793. for (var i = 0; i < children.length; i++) {
  6794. if (children[i].name === name) {
  6795. return children[i];
  6796. }
  6797. }
  6798. };
  6799. Group.prototype.childCount = function () {
  6800. return this._children.length;
  6801. };
  6802. Group.prototype.add = function (child) {
  6803. if (child) {
  6804. if (child !== this && child.parent !== this) {
  6805. this._children.push(child);
  6806. this._doAdd(child);
  6807. }
  6808. {
  6809. if (child.__hostTarget) {
  6810. throw 'This elemenet has been used as an attachment';
  6811. }
  6812. }
  6813. }
  6814. return this;
  6815. };
  6816. Group.prototype.addBefore = function (child, nextSibling) {
  6817. if (child && child !== this && child.parent !== this
  6818. && nextSibling && nextSibling.parent === this) {
  6819. var children = this._children;
  6820. var idx = children.indexOf(nextSibling);
  6821. if (idx >= 0) {
  6822. children.splice(idx, 0, child);
  6823. this._doAdd(child);
  6824. }
  6825. }
  6826. return this;
  6827. };
  6828. Group.prototype.replace = function (oldChild, newChild) {
  6829. var idx = indexOf(this._children, oldChild);
  6830. if (idx >= 0) {
  6831. this.replaceAt(newChild, idx);
  6832. }
  6833. return this;
  6834. };
  6835. Group.prototype.replaceAt = function (child, index) {
  6836. var children = this._children;
  6837. var old = children[index];
  6838. if (child && child !== this && child.parent !== this && child !== old) {
  6839. children[index] = child;
  6840. old.parent = null;
  6841. var zr = this.__zr;
  6842. if (zr) {
  6843. old.removeSelfFromZr(zr);
  6844. }
  6845. this._doAdd(child);
  6846. }
  6847. return this;
  6848. };
  6849. Group.prototype._doAdd = function (child) {
  6850. if (child.parent) {
  6851. child.parent.remove(child);
  6852. }
  6853. child.parent = this;
  6854. var zr = this.__zr;
  6855. if (zr && zr !== child.__zr) {
  6856. child.addSelfToZr(zr);
  6857. }
  6858. zr && zr.refresh();
  6859. };
  6860. Group.prototype.remove = function (child) {
  6861. var zr = this.__zr;
  6862. var children = this._children;
  6863. var idx = indexOf(children, child);
  6864. if (idx < 0) {
  6865. return this;
  6866. }
  6867. children.splice(idx, 1);
  6868. child.parent = null;
  6869. if (zr) {
  6870. child.removeSelfFromZr(zr);
  6871. }
  6872. zr && zr.refresh();
  6873. return this;
  6874. };
  6875. Group.prototype.removeAll = function () {
  6876. var children = this._children;
  6877. var zr = this.__zr;
  6878. for (var i = 0; i < children.length; i++) {
  6879. var child = children[i];
  6880. if (zr) {
  6881. child.removeSelfFromZr(zr);
  6882. }
  6883. child.parent = null;
  6884. }
  6885. children.length = 0;
  6886. return this;
  6887. };
  6888. Group.prototype.eachChild = function (cb, context) {
  6889. var children = this._children;
  6890. for (var i = 0; i < children.length; i++) {
  6891. var child = children[i];
  6892. cb.call(context, child, i);
  6893. }
  6894. return this;
  6895. };
  6896. Group.prototype.traverse = function (cb, context) {
  6897. for (var i = 0; i < this._children.length; i++) {
  6898. var child = this._children[i];
  6899. var stopped = cb.call(context, child);
  6900. if (child.isGroup && !stopped) {
  6901. child.traverse(cb, context);
  6902. }
  6903. }
  6904. return this;
  6905. };
  6906. Group.prototype.addSelfToZr = function (zr) {
  6907. _super.prototype.addSelfToZr.call(this, zr);
  6908. for (var i = 0; i < this._children.length; i++) {
  6909. var child = this._children[i];
  6910. child.addSelfToZr(zr);
  6911. }
  6912. };
  6913. Group.prototype.removeSelfFromZr = function (zr) {
  6914. _super.prototype.removeSelfFromZr.call(this, zr);
  6915. for (var i = 0; i < this._children.length; i++) {
  6916. var child = this._children[i];
  6917. child.removeSelfFromZr(zr);
  6918. }
  6919. };
  6920. Group.prototype.getBoundingRect = function (includeChildren) {
  6921. var tmpRect = new BoundingRect(0, 0, 0, 0);
  6922. var children = includeChildren || this._children;
  6923. var tmpMat = [];
  6924. var rect = null;
  6925. for (var i = 0; i < children.length; i++) {
  6926. var child = children[i];
  6927. if (child.ignore || child.invisible) {
  6928. continue;
  6929. }
  6930. var childRect = child.getBoundingRect();
  6931. var transform = child.getLocalTransform(tmpMat);
  6932. if (transform) {
  6933. BoundingRect.applyTransform(tmpRect, childRect, transform);
  6934. rect = rect || tmpRect.clone();
  6935. rect.union(tmpRect);
  6936. }
  6937. else {
  6938. rect = rect || childRect.clone();
  6939. rect.union(childRect);
  6940. }
  6941. }
  6942. return rect || tmpRect;
  6943. };
  6944. return Group;
  6945. }(Element));
  6946. Group.prototype.type = 'group';
  6947. /*!
  6948. * ZRender, a high performance 2d drawing library.
  6949. *
  6950. * Copyright (c) 2013, Baidu Inc.
  6951. * All rights reserved.
  6952. *
  6953. * LICENSE
  6954. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  6955. */
  6956. var painterCtors = {};
  6957. var instances = {};
  6958. function delInstance(id) {
  6959. delete instances[id];
  6960. }
  6961. function isDarkMode(backgroundColor) {
  6962. if (!backgroundColor) {
  6963. return false;
  6964. }
  6965. if (typeof backgroundColor === 'string') {
  6966. return lum(backgroundColor, 1) < DARK_MODE_THRESHOLD;
  6967. }
  6968. else if (backgroundColor.colorStops) {
  6969. var colorStops = backgroundColor.colorStops;
  6970. var totalLum = 0;
  6971. var len = colorStops.length;
  6972. for (var i = 0; i < len; i++) {
  6973. totalLum += lum(colorStops[i].color, 1);
  6974. }
  6975. totalLum /= len;
  6976. return totalLum < DARK_MODE_THRESHOLD;
  6977. }
  6978. return false;
  6979. }
  6980. var ZRender = (function () {
  6981. function ZRender(id, dom, opts) {
  6982. var _this = this;
  6983. this._sleepAfterStill = 10;
  6984. this._stillFrameAccum = 0;
  6985. this._needsRefresh = true;
  6986. this._needsRefreshHover = true;
  6987. this._darkMode = false;
  6988. opts = opts || {};
  6989. this.dom = dom;
  6990. this.id = id;
  6991. var storage = new Storage();
  6992. var rendererType = opts.renderer || 'canvas';
  6993. if (!painterCtors[rendererType]) {
  6994. rendererType = keys(painterCtors)[0];
  6995. }
  6996. {
  6997. if (!painterCtors[rendererType]) {
  6998. throw new Error("Renderer '" + rendererType + "' is not imported. Please import it first.");
  6999. }
  7000. }
  7001. opts.useDirtyRect = opts.useDirtyRect == null
  7002. ? false
  7003. : opts.useDirtyRect;
  7004. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  7005. var ssrMode = opts.ssr || painter.ssrOnly;
  7006. this.storage = storage;
  7007. this.painter = painter;
  7008. var handerProxy = (!env.node && !env.worker && !ssrMode)
  7009. ? new HandlerDomProxy(painter.getViewportRoot(), painter.root)
  7010. : null;
  7011. var useCoarsePointer = opts.useCoarsePointer;
  7012. var usePointerSize = (useCoarsePointer == null || useCoarsePointer === 'auto')
  7013. ? env.touchEventsSupported
  7014. : !!useCoarsePointer;
  7015. var defaultPointerSize = 44;
  7016. var pointerSize;
  7017. if (usePointerSize) {
  7018. pointerSize = retrieve2(opts.pointerSize, defaultPointerSize);
  7019. }
  7020. this.handler = new Handler(storage, painter, handerProxy, painter.root, pointerSize);
  7021. this.animation = new Animation({
  7022. stage: {
  7023. update: ssrMode ? null : function () { return _this._flush(true); }
  7024. }
  7025. });
  7026. if (!ssrMode) {
  7027. this.animation.start();
  7028. }
  7029. }
  7030. ZRender.prototype.add = function (el) {
  7031. if (!el) {
  7032. return;
  7033. }
  7034. this.storage.addRoot(el);
  7035. el.addSelfToZr(this);
  7036. this.refresh();
  7037. };
  7038. ZRender.prototype.remove = function (el) {
  7039. if (!el) {
  7040. return;
  7041. }
  7042. this.storage.delRoot(el);
  7043. el.removeSelfFromZr(this);
  7044. this.refresh();
  7045. };
  7046. ZRender.prototype.configLayer = function (zLevel, config) {
  7047. if (this.painter.configLayer) {
  7048. this.painter.configLayer(zLevel, config);
  7049. }
  7050. this.refresh();
  7051. };
  7052. ZRender.prototype.setBackgroundColor = function (backgroundColor) {
  7053. if (this.painter.setBackgroundColor) {
  7054. this.painter.setBackgroundColor(backgroundColor);
  7055. }
  7056. this.refresh();
  7057. this._backgroundColor = backgroundColor;
  7058. this._darkMode = isDarkMode(backgroundColor);
  7059. };
  7060. ZRender.prototype.getBackgroundColor = function () {
  7061. return this._backgroundColor;
  7062. };
  7063. ZRender.prototype.setDarkMode = function (darkMode) {
  7064. this._darkMode = darkMode;
  7065. };
  7066. ZRender.prototype.isDarkMode = function () {
  7067. return this._darkMode;
  7068. };
  7069. ZRender.prototype.refreshImmediately = function (fromInside) {
  7070. if (!fromInside) {
  7071. this.animation.update(true);
  7072. }
  7073. this._needsRefresh = false;
  7074. this.painter.refresh();
  7075. this._needsRefresh = false;
  7076. };
  7077. ZRender.prototype.refresh = function () {
  7078. this._needsRefresh = true;
  7079. this.animation.start();
  7080. };
  7081. ZRender.prototype.flush = function () {
  7082. this._flush(false);
  7083. };
  7084. ZRender.prototype._flush = function (fromInside) {
  7085. var triggerRendered;
  7086. var start = getTime();
  7087. if (this._needsRefresh) {
  7088. triggerRendered = true;
  7089. this.refreshImmediately(fromInside);
  7090. }
  7091. if (this._needsRefreshHover) {
  7092. triggerRendered = true;
  7093. this.refreshHoverImmediately();
  7094. }
  7095. var end = getTime();
  7096. if (triggerRendered) {
  7097. this._stillFrameAccum = 0;
  7098. this.trigger('rendered', {
  7099. elapsedTime: end - start
  7100. });
  7101. }
  7102. else if (this._sleepAfterStill > 0) {
  7103. this._stillFrameAccum++;
  7104. if (this._stillFrameAccum > this._sleepAfterStill) {
  7105. this.animation.stop();
  7106. }
  7107. }
  7108. };
  7109. ZRender.prototype.setSleepAfterStill = function (stillFramesCount) {
  7110. this._sleepAfterStill = stillFramesCount;
  7111. };
  7112. ZRender.prototype.wakeUp = function () {
  7113. this.animation.start();
  7114. this._stillFrameAccum = 0;
  7115. };
  7116. ZRender.prototype.refreshHover = function () {
  7117. this._needsRefreshHover = true;
  7118. };
  7119. ZRender.prototype.refreshHoverImmediately = function () {
  7120. this._needsRefreshHover = false;
  7121. if (this.painter.refreshHover && this.painter.getType() === 'canvas') {
  7122. this.painter.refreshHover();
  7123. }
  7124. };
  7125. ZRender.prototype.resize = function (opts) {
  7126. opts = opts || {};
  7127. this.painter.resize(opts.width, opts.height);
  7128. this.handler.resize();
  7129. };
  7130. ZRender.prototype.clearAnimation = function () {
  7131. this.animation.clear();
  7132. };
  7133. ZRender.prototype.getWidth = function () {
  7134. return this.painter.getWidth();
  7135. };
  7136. ZRender.prototype.getHeight = function () {
  7137. return this.painter.getHeight();
  7138. };
  7139. ZRender.prototype.setCursorStyle = function (cursorStyle) {
  7140. this.handler.setCursorStyle(cursorStyle);
  7141. };
  7142. ZRender.prototype.findHover = function (x, y) {
  7143. return this.handler.findHover(x, y);
  7144. };
  7145. ZRender.prototype.on = function (eventName, eventHandler, context) {
  7146. this.handler.on(eventName, eventHandler, context);
  7147. return this;
  7148. };
  7149. ZRender.prototype.off = function (eventName, eventHandler) {
  7150. this.handler.off(eventName, eventHandler);
  7151. };
  7152. ZRender.prototype.trigger = function (eventName, event) {
  7153. this.handler.trigger(eventName, event);
  7154. };
  7155. ZRender.prototype.clear = function () {
  7156. var roots = this.storage.getRoots();
  7157. for (var i = 0; i < roots.length; i++) {
  7158. if (roots[i] instanceof Group) {
  7159. roots[i].removeSelfFromZr(this);
  7160. }
  7161. }
  7162. this.storage.delAllRoots();
  7163. this.painter.clear();
  7164. };
  7165. ZRender.prototype.dispose = function () {
  7166. this.animation.stop();
  7167. this.clear();
  7168. this.storage.dispose();
  7169. this.painter.dispose();
  7170. this.handler.dispose();
  7171. this.animation =
  7172. this.storage =
  7173. this.painter =
  7174. this.handler = null;
  7175. delInstance(this.id);
  7176. };
  7177. return ZRender;
  7178. }());
  7179. function init(dom, opts) {
  7180. var zr = new ZRender(guid(), dom, opts);
  7181. instances[zr.id] = zr;
  7182. return zr;
  7183. }
  7184. function dispose(zr) {
  7185. zr.dispose();
  7186. }
  7187. function disposeAll() {
  7188. for (var key in instances) {
  7189. if (instances.hasOwnProperty(key)) {
  7190. instances[key].dispose();
  7191. }
  7192. }
  7193. instances = {};
  7194. }
  7195. function getInstance(id) {
  7196. return instances[id];
  7197. }
  7198. function registerPainter(name, Ctor) {
  7199. painterCtors[name] = Ctor;
  7200. }
  7201. var version = '5.4.4';
  7202. var STYLE_MAGIC_KEY = '__zr_style_' + Math.round((Math.random() * 10));
  7203. var DEFAULT_COMMON_STYLE = {
  7204. shadowBlur: 0,
  7205. shadowOffsetX: 0,
  7206. shadowOffsetY: 0,
  7207. shadowColor: '#000',
  7208. opacity: 1,
  7209. blend: 'source-over'
  7210. };
  7211. var DEFAULT_COMMON_ANIMATION_PROPS = {
  7212. style: {
  7213. shadowBlur: true,
  7214. shadowOffsetX: true,
  7215. shadowOffsetY: true,
  7216. shadowColor: true,
  7217. opacity: true
  7218. }
  7219. };
  7220. DEFAULT_COMMON_STYLE[STYLE_MAGIC_KEY] = true;
  7221. var PRIMARY_STATES_KEYS$1 = ['z', 'z2', 'invisible'];
  7222. var PRIMARY_STATES_KEYS_IN_HOVER_LAYER = ['invisible'];
  7223. var Displayable = (function (_super) {
  7224. __extends(Displayable, _super);
  7225. function Displayable(props) {
  7226. return _super.call(this, props) || this;
  7227. }
  7228. Displayable.prototype._init = function (props) {
  7229. var keysArr = keys(props);
  7230. for (var i = 0; i < keysArr.length; i++) {
  7231. var key = keysArr[i];
  7232. if (key === 'style') {
  7233. this.useStyle(props[key]);
  7234. }
  7235. else {
  7236. _super.prototype.attrKV.call(this, key, props[key]);
  7237. }
  7238. }
  7239. if (!this.style) {
  7240. this.useStyle({});
  7241. }
  7242. };
  7243. Displayable.prototype.beforeBrush = function () { };
  7244. Displayable.prototype.afterBrush = function () { };
  7245. Displayable.prototype.innerBeforeBrush = function () { };
  7246. Displayable.prototype.innerAfterBrush = function () { };
  7247. Displayable.prototype.shouldBePainted = function (viewWidth, viewHeight, considerClipPath, considerAncestors) {
  7248. var m = this.transform;
  7249. if (this.ignore
  7250. || this.invisible
  7251. || this.style.opacity === 0
  7252. || (this.culling
  7253. && isDisplayableCulled(this, viewWidth, viewHeight))
  7254. || (m && !m[0] && !m[3])) {
  7255. return false;
  7256. }
  7257. if (considerClipPath && this.__clipPaths) {
  7258. for (var i = 0; i < this.__clipPaths.length; ++i) {
  7259. if (this.__clipPaths[i].isZeroArea()) {
  7260. return false;
  7261. }
  7262. }
  7263. }
  7264. if (considerAncestors && this.parent) {
  7265. var parent_1 = this.parent;
  7266. while (parent_1) {
  7267. if (parent_1.ignore) {
  7268. return false;
  7269. }
  7270. parent_1 = parent_1.parent;
  7271. }
  7272. }
  7273. return true;
  7274. };
  7275. Displayable.prototype.contain = function (x, y) {
  7276. return this.rectContain(x, y);
  7277. };
  7278. Displayable.prototype.traverse = function (cb, context) {
  7279. cb.call(context, this);
  7280. };
  7281. Displayable.prototype.rectContain = function (x, y) {
  7282. var coord = this.transformCoordToLocal(x, y);
  7283. var rect = this.getBoundingRect();
  7284. return rect.contain(coord[0], coord[1]);
  7285. };
  7286. Displayable.prototype.getPaintRect = function () {
  7287. var rect = this._paintRect;
  7288. if (!this._paintRect || this.__dirty) {
  7289. var transform = this.transform;
  7290. var elRect = this.getBoundingRect();
  7291. var style = this.style;
  7292. var shadowSize = style.shadowBlur || 0;
  7293. var shadowOffsetX = style.shadowOffsetX || 0;
  7294. var shadowOffsetY = style.shadowOffsetY || 0;
  7295. rect = this._paintRect || (this._paintRect = new BoundingRect(0, 0, 0, 0));
  7296. if (transform) {
  7297. BoundingRect.applyTransform(rect, elRect, transform);
  7298. }
  7299. else {
  7300. rect.copy(elRect);
  7301. }
  7302. if (shadowSize || shadowOffsetX || shadowOffsetY) {
  7303. rect.width += shadowSize * 2 + Math.abs(shadowOffsetX);
  7304. rect.height += shadowSize * 2 + Math.abs(shadowOffsetY);
  7305. rect.x = Math.min(rect.x, rect.x + shadowOffsetX - shadowSize);
  7306. rect.y = Math.min(rect.y, rect.y + shadowOffsetY - shadowSize);
  7307. }
  7308. var tolerance = this.dirtyRectTolerance;
  7309. if (!rect.isZero()) {
  7310. rect.x = Math.floor(rect.x - tolerance);
  7311. rect.y = Math.floor(rect.y - tolerance);
  7312. rect.width = Math.ceil(rect.width + 1 + tolerance * 2);
  7313. rect.height = Math.ceil(rect.height + 1 + tolerance * 2);
  7314. }
  7315. }
  7316. return rect;
  7317. };
  7318. Displayable.prototype.setPrevPaintRect = function (paintRect) {
  7319. if (paintRect) {
  7320. this._prevPaintRect = this._prevPaintRect || new BoundingRect(0, 0, 0, 0);
  7321. this._prevPaintRect.copy(paintRect);
  7322. }
  7323. else {
  7324. this._prevPaintRect = null;
  7325. }
  7326. };
  7327. Displayable.prototype.getPrevPaintRect = function () {
  7328. return this._prevPaintRect;
  7329. };
  7330. Displayable.prototype.animateStyle = function (loop) {
  7331. return this.animate('style', loop);
  7332. };
  7333. Displayable.prototype.updateDuringAnimation = function (targetKey) {
  7334. if (targetKey === 'style') {
  7335. this.dirtyStyle();
  7336. }
  7337. else {
  7338. this.markRedraw();
  7339. }
  7340. };
  7341. Displayable.prototype.attrKV = function (key, value) {
  7342. if (key !== 'style') {
  7343. _super.prototype.attrKV.call(this, key, value);
  7344. }
  7345. else {
  7346. if (!this.style) {
  7347. this.useStyle(value);
  7348. }
  7349. else {
  7350. this.setStyle(value);
  7351. }
  7352. }
  7353. };
  7354. Displayable.prototype.setStyle = function (keyOrObj, value) {
  7355. if (typeof keyOrObj === 'string') {
  7356. this.style[keyOrObj] = value;
  7357. }
  7358. else {
  7359. extend(this.style, keyOrObj);
  7360. }
  7361. this.dirtyStyle();
  7362. return this;
  7363. };
  7364. Displayable.prototype.dirtyStyle = function (notRedraw) {
  7365. if (!notRedraw) {
  7366. this.markRedraw();
  7367. }
  7368. this.__dirty |= STYLE_CHANGED_BIT;
  7369. if (this._rect) {
  7370. this._rect = null;
  7371. }
  7372. };
  7373. Displayable.prototype.dirty = function () {
  7374. this.dirtyStyle();
  7375. };
  7376. Displayable.prototype.styleChanged = function () {
  7377. return !!(this.__dirty & STYLE_CHANGED_BIT);
  7378. };
  7379. Displayable.prototype.styleUpdated = function () {
  7380. this.__dirty &= ~STYLE_CHANGED_BIT;
  7381. };
  7382. Displayable.prototype.createStyle = function (obj) {
  7383. return createObject(DEFAULT_COMMON_STYLE, obj);
  7384. };
  7385. Displayable.prototype.useStyle = function (obj) {
  7386. if (!obj[STYLE_MAGIC_KEY]) {
  7387. obj = this.createStyle(obj);
  7388. }
  7389. if (this.__inHover) {
  7390. this.__hoverStyle = obj;
  7391. }
  7392. else {
  7393. this.style = obj;
  7394. }
  7395. this.dirtyStyle();
  7396. };
  7397. Displayable.prototype.isStyleObject = function (obj) {
  7398. return obj[STYLE_MAGIC_KEY];
  7399. };
  7400. Displayable.prototype._innerSaveToNormal = function (toState) {
  7401. _super.prototype._innerSaveToNormal.call(this, toState);
  7402. var normalState = this._normalState;
  7403. if (toState.style && !normalState.style) {
  7404. normalState.style = this._mergeStyle(this.createStyle(), this.style);
  7405. }
  7406. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS$1);
  7407. };
  7408. Displayable.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  7409. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  7410. var needsRestoreToNormal = !(state && keepCurrentStates);
  7411. var targetStyle;
  7412. if (state && state.style) {
  7413. if (transition) {
  7414. if (keepCurrentStates) {
  7415. targetStyle = state.style;
  7416. }
  7417. else {
  7418. targetStyle = this._mergeStyle(this.createStyle(), normalState.style);
  7419. this._mergeStyle(targetStyle, state.style);
  7420. }
  7421. }
  7422. else {
  7423. targetStyle = this._mergeStyle(this.createStyle(), keepCurrentStates ? this.style : normalState.style);
  7424. this._mergeStyle(targetStyle, state.style);
  7425. }
  7426. }
  7427. else if (needsRestoreToNormal) {
  7428. targetStyle = normalState.style;
  7429. }
  7430. if (targetStyle) {
  7431. if (transition) {
  7432. var sourceStyle = this.style;
  7433. this.style = this.createStyle(needsRestoreToNormal ? {} : sourceStyle);
  7434. if (needsRestoreToNormal) {
  7435. var changedKeys = keys(sourceStyle);
  7436. for (var i = 0; i < changedKeys.length; i++) {
  7437. var key = changedKeys[i];
  7438. if (key in targetStyle) {
  7439. targetStyle[key] = targetStyle[key];
  7440. this.style[key] = sourceStyle[key];
  7441. }
  7442. }
  7443. }
  7444. var targetKeys = keys(targetStyle);
  7445. for (var i = 0; i < targetKeys.length; i++) {
  7446. var key = targetKeys[i];
  7447. this.style[key] = this.style[key];
  7448. }
  7449. this._transitionState(stateName, {
  7450. style: targetStyle
  7451. }, animationCfg, this.getAnimationStyleProps());
  7452. }
  7453. else {
  7454. this.useStyle(targetStyle);
  7455. }
  7456. }
  7457. var statesKeys = this.__inHover ? PRIMARY_STATES_KEYS_IN_HOVER_LAYER : PRIMARY_STATES_KEYS$1;
  7458. for (var i = 0; i < statesKeys.length; i++) {
  7459. var key = statesKeys[i];
  7460. if (state && state[key] != null) {
  7461. this[key] = state[key];
  7462. }
  7463. else if (needsRestoreToNormal) {
  7464. if (normalState[key] != null) {
  7465. this[key] = normalState[key];
  7466. }
  7467. }
  7468. }
  7469. };
  7470. Displayable.prototype._mergeStates = function (states) {
  7471. var mergedState = _super.prototype._mergeStates.call(this, states);
  7472. var mergedStyle;
  7473. for (var i = 0; i < states.length; i++) {
  7474. var state = states[i];
  7475. if (state.style) {
  7476. mergedStyle = mergedStyle || {};
  7477. this._mergeStyle(mergedStyle, state.style);
  7478. }
  7479. }
  7480. if (mergedStyle) {
  7481. mergedState.style = mergedStyle;
  7482. }
  7483. return mergedState;
  7484. };
  7485. Displayable.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  7486. extend(targetStyle, sourceStyle);
  7487. return targetStyle;
  7488. };
  7489. Displayable.prototype.getAnimationStyleProps = function () {
  7490. return DEFAULT_COMMON_ANIMATION_PROPS;
  7491. };
  7492. Displayable.initDefaultProps = (function () {
  7493. var dispProto = Displayable.prototype;
  7494. dispProto.type = 'displayable';
  7495. dispProto.invisible = false;
  7496. dispProto.z = 0;
  7497. dispProto.z2 = 0;
  7498. dispProto.zlevel = 0;
  7499. dispProto.culling = false;
  7500. dispProto.cursor = 'pointer';
  7501. dispProto.rectHover = false;
  7502. dispProto.incremental = false;
  7503. dispProto._rect = null;
  7504. dispProto.dirtyRectTolerance = 0;
  7505. dispProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT;
  7506. })();
  7507. return Displayable;
  7508. }(Element));
  7509. var tmpRect$1 = new BoundingRect(0, 0, 0, 0);
  7510. var viewRect = new BoundingRect(0, 0, 0, 0);
  7511. function isDisplayableCulled(el, width, height) {
  7512. tmpRect$1.copy(el.getBoundingRect());
  7513. if (el.transform) {
  7514. tmpRect$1.applyTransform(el.transform);
  7515. }
  7516. viewRect.width = width;
  7517. viewRect.height = height;
  7518. return !tmpRect$1.intersect(viewRect);
  7519. }
  7520. var mathMin$1 = Math.min;
  7521. var mathMax$1 = Math.max;
  7522. var mathSin = Math.sin;
  7523. var mathCos = Math.cos;
  7524. var PI2 = Math.PI * 2;
  7525. var start = create();
  7526. var end = create();
  7527. var extremity = create();
  7528. function fromPoints(points, min, max) {
  7529. if (points.length === 0) {
  7530. return;
  7531. }
  7532. var p = points[0];
  7533. var left = p[0];
  7534. var right = p[0];
  7535. var top = p[1];
  7536. var bottom = p[1];
  7537. for (var i = 1; i < points.length; i++) {
  7538. p = points[i];
  7539. left = mathMin$1(left, p[0]);
  7540. right = mathMax$1(right, p[0]);
  7541. top = mathMin$1(top, p[1]);
  7542. bottom = mathMax$1(bottom, p[1]);
  7543. }
  7544. min[0] = left;
  7545. min[1] = top;
  7546. max[0] = right;
  7547. max[1] = bottom;
  7548. }
  7549. function fromLine(x0, y0, x1, y1, min, max) {
  7550. min[0] = mathMin$1(x0, x1);
  7551. min[1] = mathMin$1(y0, y1);
  7552. max[0] = mathMax$1(x0, x1);
  7553. max[1] = mathMax$1(y0, y1);
  7554. }
  7555. var xDim = [];
  7556. var yDim = [];
  7557. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min, max) {
  7558. var cubicExtrema$1 = cubicExtrema;
  7559. var cubicAt$1 = cubicAt;
  7560. var n = cubicExtrema$1(x0, x1, x2, x3, xDim);
  7561. min[0] = Infinity;
  7562. min[1] = Infinity;
  7563. max[0] = -Infinity;
  7564. max[1] = -Infinity;
  7565. for (var i = 0; i < n; i++) {
  7566. var x = cubicAt$1(x0, x1, x2, x3, xDim[i]);
  7567. min[0] = mathMin$1(x, min[0]);
  7568. max[0] = mathMax$1(x, max[0]);
  7569. }
  7570. n = cubicExtrema$1(y0, y1, y2, y3, yDim);
  7571. for (var i = 0; i < n; i++) {
  7572. var y = cubicAt$1(y0, y1, y2, y3, yDim[i]);
  7573. min[1] = mathMin$1(y, min[1]);
  7574. max[1] = mathMax$1(y, max[1]);
  7575. }
  7576. min[0] = mathMin$1(x0, min[0]);
  7577. max[0] = mathMax$1(x0, max[0]);
  7578. min[0] = mathMin$1(x3, min[0]);
  7579. max[0] = mathMax$1(x3, max[0]);
  7580. min[1] = mathMin$1(y0, min[1]);
  7581. max[1] = mathMax$1(y0, max[1]);
  7582. min[1] = mathMin$1(y3, min[1]);
  7583. max[1] = mathMax$1(y3, max[1]);
  7584. }
  7585. function fromQuadratic(x0, y0, x1, y1, x2, y2, min, max) {
  7586. var quadraticExtremum$1 = quadraticExtremum;
  7587. var quadraticAt$1 = quadraticAt;
  7588. var tx = mathMax$1(mathMin$1(quadraticExtremum$1(x0, x1, x2), 1), 0);
  7589. var ty = mathMax$1(mathMin$1(quadraticExtremum$1(y0, y1, y2), 1), 0);
  7590. var x = quadraticAt$1(x0, x1, x2, tx);
  7591. var y = quadraticAt$1(y0, y1, y2, ty);
  7592. min[0] = mathMin$1(x0, x2, x);
  7593. min[1] = mathMin$1(y0, y2, y);
  7594. max[0] = mathMax$1(x0, x2, x);
  7595. max[1] = mathMax$1(y0, y2, y);
  7596. }
  7597. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min$1, max$1) {
  7598. var vec2Min = min;
  7599. var vec2Max = max;
  7600. var diff = Math.abs(startAngle - endAngle);
  7601. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  7602. min$1[0] = x - rx;
  7603. min$1[1] = y - ry;
  7604. max$1[0] = x + rx;
  7605. max$1[1] = y + ry;
  7606. return;
  7607. }
  7608. start[0] = mathCos(startAngle) * rx + x;
  7609. start[1] = mathSin(startAngle) * ry + y;
  7610. end[0] = mathCos(endAngle) * rx + x;
  7611. end[1] = mathSin(endAngle) * ry + y;
  7612. vec2Min(min$1, start, end);
  7613. vec2Max(max$1, start, end);
  7614. startAngle = startAngle % (PI2);
  7615. if (startAngle < 0) {
  7616. startAngle = startAngle + PI2;
  7617. }
  7618. endAngle = endAngle % (PI2);
  7619. if (endAngle < 0) {
  7620. endAngle = endAngle + PI2;
  7621. }
  7622. if (startAngle > endAngle && !anticlockwise) {
  7623. endAngle += PI2;
  7624. }
  7625. else if (startAngle < endAngle && anticlockwise) {
  7626. startAngle += PI2;
  7627. }
  7628. if (anticlockwise) {
  7629. var tmp = endAngle;
  7630. endAngle = startAngle;
  7631. startAngle = tmp;
  7632. }
  7633. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  7634. if (angle > startAngle) {
  7635. extremity[0] = mathCos(angle) * rx + x;
  7636. extremity[1] = mathSin(angle) * ry + y;
  7637. vec2Min(min$1, extremity, min$1);
  7638. vec2Max(max$1, extremity, max$1);
  7639. }
  7640. }
  7641. }
  7642. var CMD = {
  7643. M: 1,
  7644. L: 2,
  7645. C: 3,
  7646. Q: 4,
  7647. A: 5,
  7648. Z: 6,
  7649. R: 7
  7650. };
  7651. var tmpOutX = [];
  7652. var tmpOutY = [];
  7653. var min$1 = [];
  7654. var max$1 = [];
  7655. var min2 = [];
  7656. var max2 = [];
  7657. var mathMin$2 = Math.min;
  7658. var mathMax$2 = Math.max;
  7659. var mathCos$1 = Math.cos;
  7660. var mathSin$1 = Math.sin;
  7661. var mathAbs = Math.abs;
  7662. var PI = Math.PI;
  7663. var PI2$1 = PI * 2;
  7664. var hasTypedArray = typeof Float32Array !== 'undefined';
  7665. var tmpAngles = [];
  7666. function modPI2(radian) {
  7667. var n = Math.round(radian / PI * 1e8) / 1e8;
  7668. return (n % 2) * PI;
  7669. }
  7670. function normalizeArcAngles(angles, anticlockwise) {
  7671. var newStartAngle = modPI2(angles[0]);
  7672. if (newStartAngle < 0) {
  7673. newStartAngle += PI2$1;
  7674. }
  7675. var delta = newStartAngle - angles[0];
  7676. var newEndAngle = angles[1];
  7677. newEndAngle += delta;
  7678. if (!anticlockwise && newEndAngle - newStartAngle >= PI2$1) {
  7679. newEndAngle = newStartAngle + PI2$1;
  7680. }
  7681. else if (anticlockwise && newStartAngle - newEndAngle >= PI2$1) {
  7682. newEndAngle = newStartAngle - PI2$1;
  7683. }
  7684. else if (!anticlockwise && newStartAngle > newEndAngle) {
  7685. newEndAngle = newStartAngle + (PI2$1 - modPI2(newStartAngle - newEndAngle));
  7686. }
  7687. else if (anticlockwise && newStartAngle < newEndAngle) {
  7688. newEndAngle = newStartAngle - (PI2$1 - modPI2(newEndAngle - newStartAngle));
  7689. }
  7690. angles[0] = newStartAngle;
  7691. angles[1] = newEndAngle;
  7692. }
  7693. var PathProxy = (function () {
  7694. function PathProxy(notSaveData) {
  7695. this.dpr = 1;
  7696. this._xi = 0;
  7697. this._yi = 0;
  7698. this._x0 = 0;
  7699. this._y0 = 0;
  7700. this._len = 0;
  7701. if (notSaveData) {
  7702. this._saveData = false;
  7703. }
  7704. if (this._saveData) {
  7705. this.data = [];
  7706. }
  7707. }
  7708. PathProxy.prototype.increaseVersion = function () {
  7709. this._version++;
  7710. };
  7711. PathProxy.prototype.getVersion = function () {
  7712. return this._version;
  7713. };
  7714. PathProxy.prototype.setScale = function (sx, sy, segmentIgnoreThreshold) {
  7715. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  7716. if (segmentIgnoreThreshold > 0) {
  7717. this._ux = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  7718. this._uy = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  7719. }
  7720. };
  7721. PathProxy.prototype.setDPR = function (dpr) {
  7722. this.dpr = dpr;
  7723. };
  7724. PathProxy.prototype.setContext = function (ctx) {
  7725. this._ctx = ctx;
  7726. };
  7727. PathProxy.prototype.getContext = function () {
  7728. return this._ctx;
  7729. };
  7730. PathProxy.prototype.beginPath = function () {
  7731. this._ctx && this._ctx.beginPath();
  7732. this.reset();
  7733. return this;
  7734. };
  7735. PathProxy.prototype.reset = function () {
  7736. if (this._saveData) {
  7737. this._len = 0;
  7738. }
  7739. if (this._pathSegLen) {
  7740. this._pathSegLen = null;
  7741. this._pathLen = 0;
  7742. }
  7743. this._version++;
  7744. };
  7745. PathProxy.prototype.moveTo = function (x, y) {
  7746. this._drawPendingPt();
  7747. this.addData(CMD.M, x, y);
  7748. this._ctx && this._ctx.moveTo(x, y);
  7749. this._x0 = x;
  7750. this._y0 = y;
  7751. this._xi = x;
  7752. this._yi = y;
  7753. return this;
  7754. };
  7755. PathProxy.prototype.lineTo = function (x, y) {
  7756. var dx = mathAbs(x - this._xi);
  7757. var dy = mathAbs(y - this._yi);
  7758. var exceedUnit = dx > this._ux || dy > this._uy;
  7759. this.addData(CMD.L, x, y);
  7760. if (this._ctx && exceedUnit) {
  7761. this._ctx.lineTo(x, y);
  7762. }
  7763. if (exceedUnit) {
  7764. this._xi = x;
  7765. this._yi = y;
  7766. this._pendingPtDist = 0;
  7767. }
  7768. else {
  7769. var d2 = dx * dx + dy * dy;
  7770. if (d2 > this._pendingPtDist) {
  7771. this._pendingPtX = x;
  7772. this._pendingPtY = y;
  7773. this._pendingPtDist = d2;
  7774. }
  7775. }
  7776. return this;
  7777. };
  7778. PathProxy.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
  7779. this._drawPendingPt();
  7780. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  7781. if (this._ctx) {
  7782. this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  7783. }
  7784. this._xi = x3;
  7785. this._yi = y3;
  7786. return this;
  7787. };
  7788. PathProxy.prototype.quadraticCurveTo = function (x1, y1, x2, y2) {
  7789. this._drawPendingPt();
  7790. this.addData(CMD.Q, x1, y1, x2, y2);
  7791. if (this._ctx) {
  7792. this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  7793. }
  7794. this._xi = x2;
  7795. this._yi = y2;
  7796. return this;
  7797. };
  7798. PathProxy.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  7799. this._drawPendingPt();
  7800. tmpAngles[0] = startAngle;
  7801. tmpAngles[1] = endAngle;
  7802. normalizeArcAngles(tmpAngles, anticlockwise);
  7803. startAngle = tmpAngles[0];
  7804. endAngle = tmpAngles[1];
  7805. var delta = endAngle - startAngle;
  7806. this.addData(CMD.A, cx, cy, r, r, startAngle, delta, 0, anticlockwise ? 0 : 1);
  7807. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  7808. this._xi = mathCos$1(endAngle) * r + cx;
  7809. this._yi = mathSin$1(endAngle) * r + cy;
  7810. return this;
  7811. };
  7812. PathProxy.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  7813. this._drawPendingPt();
  7814. if (this._ctx) {
  7815. this._ctx.arcTo(x1, y1, x2, y2, radius);
  7816. }
  7817. return this;
  7818. };
  7819. PathProxy.prototype.rect = function (x, y, w, h) {
  7820. this._drawPendingPt();
  7821. this._ctx && this._ctx.rect(x, y, w, h);
  7822. this.addData(CMD.R, x, y, w, h);
  7823. return this;
  7824. };
  7825. PathProxy.prototype.closePath = function () {
  7826. this._drawPendingPt();
  7827. this.addData(CMD.Z);
  7828. var ctx = this._ctx;
  7829. var x0 = this._x0;
  7830. var y0 = this._y0;
  7831. if (ctx) {
  7832. ctx.closePath();
  7833. }
  7834. this._xi = x0;
  7835. this._yi = y0;
  7836. return this;
  7837. };
  7838. PathProxy.prototype.fill = function (ctx) {
  7839. ctx && ctx.fill();
  7840. this.toStatic();
  7841. };
  7842. PathProxy.prototype.stroke = function (ctx) {
  7843. ctx && ctx.stroke();
  7844. this.toStatic();
  7845. };
  7846. PathProxy.prototype.len = function () {
  7847. return this._len;
  7848. };
  7849. PathProxy.prototype.setData = function (data) {
  7850. var len = data.length;
  7851. if (!(this.data && this.data.length === len) && hasTypedArray) {
  7852. this.data = new Float32Array(len);
  7853. }
  7854. for (var i = 0; i < len; i++) {
  7855. this.data[i] = data[i];
  7856. }
  7857. this._len = len;
  7858. };
  7859. PathProxy.prototype.appendPath = function (path) {
  7860. if (!(path instanceof Array)) {
  7861. path = [path];
  7862. }
  7863. var len = path.length;
  7864. var appendSize = 0;
  7865. var offset = this._len;
  7866. for (var i = 0; i < len; i++) {
  7867. appendSize += path[i].len();
  7868. }
  7869. if (hasTypedArray && (this.data instanceof Float32Array)) {
  7870. this.data = new Float32Array(offset + appendSize);
  7871. }
  7872. for (var i = 0; i < len; i++) {
  7873. var appendPathData = path[i].data;
  7874. for (var k = 0; k < appendPathData.length; k++) {
  7875. this.data[offset++] = appendPathData[k];
  7876. }
  7877. }
  7878. this._len = offset;
  7879. };
  7880. PathProxy.prototype.addData = function (cmd, a, b, c, d, e, f, g, h) {
  7881. if (!this._saveData) {
  7882. return;
  7883. }
  7884. var data = this.data;
  7885. if (this._len + arguments.length > data.length) {
  7886. this._expandData();
  7887. data = this.data;
  7888. }
  7889. for (var i = 0; i < arguments.length; i++) {
  7890. data[this._len++] = arguments[i];
  7891. }
  7892. };
  7893. PathProxy.prototype._drawPendingPt = function () {
  7894. if (this._pendingPtDist > 0) {
  7895. this._ctx && this._ctx.lineTo(this._pendingPtX, this._pendingPtY);
  7896. this._pendingPtDist = 0;
  7897. }
  7898. };
  7899. PathProxy.prototype._expandData = function () {
  7900. if (!(this.data instanceof Array)) {
  7901. var newData = [];
  7902. for (var i = 0; i < this._len; i++) {
  7903. newData[i] = this.data[i];
  7904. }
  7905. this.data = newData;
  7906. }
  7907. };
  7908. PathProxy.prototype.toStatic = function () {
  7909. if (!this._saveData) {
  7910. return;
  7911. }
  7912. this._drawPendingPt();
  7913. var data = this.data;
  7914. if (data instanceof Array) {
  7915. data.length = this._len;
  7916. if (hasTypedArray && this._len > 11) {
  7917. this.data = new Float32Array(data);
  7918. }
  7919. }
  7920. };
  7921. PathProxy.prototype.getBoundingRect = function () {
  7922. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  7923. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  7924. var data = this.data;
  7925. var xi = 0;
  7926. var yi = 0;
  7927. var x0 = 0;
  7928. var y0 = 0;
  7929. var i;
  7930. for (i = 0; i < this._len;) {
  7931. var cmd = data[i++];
  7932. var isFirst = i === 1;
  7933. if (isFirst) {
  7934. xi = data[i];
  7935. yi = data[i + 1];
  7936. x0 = xi;
  7937. y0 = yi;
  7938. }
  7939. switch (cmd) {
  7940. case CMD.M:
  7941. xi = x0 = data[i++];
  7942. yi = y0 = data[i++];
  7943. min2[0] = x0;
  7944. min2[1] = y0;
  7945. max2[0] = x0;
  7946. max2[1] = y0;
  7947. break;
  7948. case CMD.L:
  7949. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  7950. xi = data[i++];
  7951. yi = data[i++];
  7952. break;
  7953. case CMD.C:
  7954. fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  7955. xi = data[i++];
  7956. yi = data[i++];
  7957. break;
  7958. case CMD.Q:
  7959. fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  7960. xi = data[i++];
  7961. yi = data[i++];
  7962. break;
  7963. case CMD.A:
  7964. var cx = data[i++];
  7965. var cy = data[i++];
  7966. var rx = data[i++];
  7967. var ry = data[i++];
  7968. var startAngle = data[i++];
  7969. var endAngle = data[i++] + startAngle;
  7970. i += 1;
  7971. var anticlockwise = !data[i++];
  7972. if (isFirst) {
  7973. x0 = mathCos$1(startAngle) * rx + cx;
  7974. y0 = mathSin$1(startAngle) * ry + cy;
  7975. }
  7976. fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  7977. xi = mathCos$1(endAngle) * rx + cx;
  7978. yi = mathSin$1(endAngle) * ry + cy;
  7979. break;
  7980. case CMD.R:
  7981. x0 = xi = data[i++];
  7982. y0 = yi = data[i++];
  7983. var width = data[i++];
  7984. var height = data[i++];
  7985. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  7986. break;
  7987. case CMD.Z:
  7988. xi = x0;
  7989. yi = y0;
  7990. break;
  7991. }
  7992. min(min$1, min$1, min2);
  7993. max(max$1, max$1, max2);
  7994. }
  7995. if (i === 0) {
  7996. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  7997. }
  7998. return new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  7999. };
  8000. PathProxy.prototype._calculateLength = function () {
  8001. var data = this.data;
  8002. var len = this._len;
  8003. var ux = this._ux;
  8004. var uy = this._uy;
  8005. var xi = 0;
  8006. var yi = 0;
  8007. var x0 = 0;
  8008. var y0 = 0;
  8009. if (!this._pathSegLen) {
  8010. this._pathSegLen = [];
  8011. }
  8012. var pathSegLen = this._pathSegLen;
  8013. var pathTotalLen = 0;
  8014. var segCount = 0;
  8015. for (var i = 0; i < len;) {
  8016. var cmd = data[i++];
  8017. var isFirst = i === 1;
  8018. if (isFirst) {
  8019. xi = data[i];
  8020. yi = data[i + 1];
  8021. x0 = xi;
  8022. y0 = yi;
  8023. }
  8024. var l = -1;
  8025. switch (cmd) {
  8026. case CMD.M:
  8027. xi = x0 = data[i++];
  8028. yi = y0 = data[i++];
  8029. break;
  8030. case CMD.L: {
  8031. var x2 = data[i++];
  8032. var y2 = data[i++];
  8033. var dx = x2 - xi;
  8034. var dy = y2 - yi;
  8035. if (mathAbs(dx) > ux || mathAbs(dy) > uy || i === len - 1) {
  8036. l = Math.sqrt(dx * dx + dy * dy);
  8037. xi = x2;
  8038. yi = y2;
  8039. }
  8040. break;
  8041. }
  8042. case CMD.C: {
  8043. var x1 = data[i++];
  8044. var y1 = data[i++];
  8045. var x2 = data[i++];
  8046. var y2 = data[i++];
  8047. var x3 = data[i++];
  8048. var y3 = data[i++];
  8049. l = cubicLength(xi, yi, x1, y1, x2, y2, x3, y3, 10);
  8050. xi = x3;
  8051. yi = y3;
  8052. break;
  8053. }
  8054. case CMD.Q: {
  8055. var x1 = data[i++];
  8056. var y1 = data[i++];
  8057. var x2 = data[i++];
  8058. var y2 = data[i++];
  8059. l = quadraticLength(xi, yi, x1, y1, x2, y2, 10);
  8060. xi = x2;
  8061. yi = y2;
  8062. break;
  8063. }
  8064. case CMD.A:
  8065. var cx = data[i++];
  8066. var cy = data[i++];
  8067. var rx = data[i++];
  8068. var ry = data[i++];
  8069. var startAngle = data[i++];
  8070. var delta = data[i++];
  8071. var endAngle = delta + startAngle;
  8072. i += 1;
  8073. var anticlockwise = !data[i++];
  8074. if (isFirst) {
  8075. x0 = mathCos$1(startAngle) * rx + cx;
  8076. y0 = mathSin$1(startAngle) * ry + cy;
  8077. }
  8078. l = mathMax$2(rx, ry) * mathMin$2(PI2$1, Math.abs(delta));
  8079. xi = mathCos$1(endAngle) * rx + cx;
  8080. yi = mathSin$1(endAngle) * ry + cy;
  8081. break;
  8082. case CMD.R: {
  8083. x0 = xi = data[i++];
  8084. y0 = yi = data[i++];
  8085. var width = data[i++];
  8086. var height = data[i++];
  8087. l = width * 2 + height * 2;
  8088. break;
  8089. }
  8090. case CMD.Z: {
  8091. var dx = x0 - xi;
  8092. var dy = y0 - yi;
  8093. l = Math.sqrt(dx * dx + dy * dy);
  8094. xi = x0;
  8095. yi = y0;
  8096. break;
  8097. }
  8098. }
  8099. if (l >= 0) {
  8100. pathSegLen[segCount++] = l;
  8101. pathTotalLen += l;
  8102. }
  8103. }
  8104. this._pathLen = pathTotalLen;
  8105. return pathTotalLen;
  8106. };
  8107. PathProxy.prototype.rebuildPath = function (ctx, percent) {
  8108. var d = this.data;
  8109. var ux = this._ux;
  8110. var uy = this._uy;
  8111. var len = this._len;
  8112. var x0;
  8113. var y0;
  8114. var xi;
  8115. var yi;
  8116. var x;
  8117. var y;
  8118. var drawPart = percent < 1;
  8119. var pathSegLen;
  8120. var pathTotalLen;
  8121. var accumLength = 0;
  8122. var segCount = 0;
  8123. var displayedLength;
  8124. var pendingPtDist = 0;
  8125. var pendingPtX;
  8126. var pendingPtY;
  8127. if (drawPart) {
  8128. if (!this._pathSegLen) {
  8129. this._calculateLength();
  8130. }
  8131. pathSegLen = this._pathSegLen;
  8132. pathTotalLen = this._pathLen;
  8133. displayedLength = percent * pathTotalLen;
  8134. if (!displayedLength) {
  8135. return;
  8136. }
  8137. }
  8138. lo: for (var i = 0; i < len;) {
  8139. var cmd = d[i++];
  8140. var isFirst = i === 1;
  8141. if (isFirst) {
  8142. xi = d[i];
  8143. yi = d[i + 1];
  8144. x0 = xi;
  8145. y0 = yi;
  8146. }
  8147. if (cmd !== CMD.L && pendingPtDist > 0) {
  8148. ctx.lineTo(pendingPtX, pendingPtY);
  8149. pendingPtDist = 0;
  8150. }
  8151. switch (cmd) {
  8152. case CMD.M:
  8153. x0 = xi = d[i++];
  8154. y0 = yi = d[i++];
  8155. ctx.moveTo(xi, yi);
  8156. break;
  8157. case CMD.L: {
  8158. x = d[i++];
  8159. y = d[i++];
  8160. var dx = mathAbs(x - xi);
  8161. var dy = mathAbs(y - yi);
  8162. if (dx > ux || dy > uy) {
  8163. if (drawPart) {
  8164. var l = pathSegLen[segCount++];
  8165. if (accumLength + l > displayedLength) {
  8166. var t = (displayedLength - accumLength) / l;
  8167. ctx.lineTo(xi * (1 - t) + x * t, yi * (1 - t) + y * t);
  8168. break lo;
  8169. }
  8170. accumLength += l;
  8171. }
  8172. ctx.lineTo(x, y);
  8173. xi = x;
  8174. yi = y;
  8175. pendingPtDist = 0;
  8176. }
  8177. else {
  8178. var d2 = dx * dx + dy * dy;
  8179. if (d2 > pendingPtDist) {
  8180. pendingPtX = x;
  8181. pendingPtY = y;
  8182. pendingPtDist = d2;
  8183. }
  8184. }
  8185. break;
  8186. }
  8187. case CMD.C: {
  8188. var x1 = d[i++];
  8189. var y1 = d[i++];
  8190. var x2 = d[i++];
  8191. var y2 = d[i++];
  8192. var x3 = d[i++];
  8193. var y3 = d[i++];
  8194. if (drawPart) {
  8195. var l = pathSegLen[segCount++];
  8196. if (accumLength + l > displayedLength) {
  8197. var t = (displayedLength - accumLength) / l;
  8198. cubicSubdivide(xi, x1, x2, x3, t, tmpOutX);
  8199. cubicSubdivide(yi, y1, y2, y3, t, tmpOutY);
  8200. ctx.bezierCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2], tmpOutX[3], tmpOutY[3]);
  8201. break lo;
  8202. }
  8203. accumLength += l;
  8204. }
  8205. ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  8206. xi = x3;
  8207. yi = y3;
  8208. break;
  8209. }
  8210. case CMD.Q: {
  8211. var x1 = d[i++];
  8212. var y1 = d[i++];
  8213. var x2 = d[i++];
  8214. var y2 = d[i++];
  8215. if (drawPart) {
  8216. var l = pathSegLen[segCount++];
  8217. if (accumLength + l > displayedLength) {
  8218. var t = (displayedLength - accumLength) / l;
  8219. quadraticSubdivide(xi, x1, x2, t, tmpOutX);
  8220. quadraticSubdivide(yi, y1, y2, t, tmpOutY);
  8221. ctx.quadraticCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2]);
  8222. break lo;
  8223. }
  8224. accumLength += l;
  8225. }
  8226. ctx.quadraticCurveTo(x1, y1, x2, y2);
  8227. xi = x2;
  8228. yi = y2;
  8229. break;
  8230. }
  8231. case CMD.A:
  8232. var cx = d[i++];
  8233. var cy = d[i++];
  8234. var rx = d[i++];
  8235. var ry = d[i++];
  8236. var startAngle = d[i++];
  8237. var delta = d[i++];
  8238. var psi = d[i++];
  8239. var anticlockwise = !d[i++];
  8240. var r = (rx > ry) ? rx : ry;
  8241. var isEllipse = mathAbs(rx - ry) > 1e-3;
  8242. var endAngle = startAngle + delta;
  8243. var breakBuild = false;
  8244. if (drawPart) {
  8245. var l = pathSegLen[segCount++];
  8246. if (accumLength + l > displayedLength) {
  8247. endAngle = startAngle + delta * (displayedLength - accumLength) / l;
  8248. breakBuild = true;
  8249. }
  8250. accumLength += l;
  8251. }
  8252. if (isEllipse && ctx.ellipse) {
  8253. ctx.ellipse(cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise);
  8254. }
  8255. else {
  8256. ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  8257. }
  8258. if (breakBuild) {
  8259. break lo;
  8260. }
  8261. if (isFirst) {
  8262. x0 = mathCos$1(startAngle) * rx + cx;
  8263. y0 = mathSin$1(startAngle) * ry + cy;
  8264. }
  8265. xi = mathCos$1(endAngle) * rx + cx;
  8266. yi = mathSin$1(endAngle) * ry + cy;
  8267. break;
  8268. case CMD.R:
  8269. x0 = xi = d[i];
  8270. y0 = yi = d[i + 1];
  8271. x = d[i++];
  8272. y = d[i++];
  8273. var width = d[i++];
  8274. var height = d[i++];
  8275. if (drawPart) {
  8276. var l = pathSegLen[segCount++];
  8277. if (accumLength + l > displayedLength) {
  8278. var d_1 = displayedLength - accumLength;
  8279. ctx.moveTo(x, y);
  8280. ctx.lineTo(x + mathMin$2(d_1, width), y);
  8281. d_1 -= width;
  8282. if (d_1 > 0) {
  8283. ctx.lineTo(x + width, y + mathMin$2(d_1, height));
  8284. }
  8285. d_1 -= height;
  8286. if (d_1 > 0) {
  8287. ctx.lineTo(x + mathMax$2(width - d_1, 0), y + height);
  8288. }
  8289. d_1 -= width;
  8290. if (d_1 > 0) {
  8291. ctx.lineTo(x, y + mathMax$2(height - d_1, 0));
  8292. }
  8293. break lo;
  8294. }
  8295. accumLength += l;
  8296. }
  8297. ctx.rect(x, y, width, height);
  8298. break;
  8299. case CMD.Z:
  8300. if (drawPart) {
  8301. var l = pathSegLen[segCount++];
  8302. if (accumLength + l > displayedLength) {
  8303. var t = (displayedLength - accumLength) / l;
  8304. ctx.lineTo(xi * (1 - t) + x0 * t, yi * (1 - t) + y0 * t);
  8305. break lo;
  8306. }
  8307. accumLength += l;
  8308. }
  8309. ctx.closePath();
  8310. xi = x0;
  8311. yi = y0;
  8312. }
  8313. }
  8314. };
  8315. PathProxy.prototype.clone = function () {
  8316. var newProxy = new PathProxy();
  8317. var data = this.data;
  8318. newProxy.data = data.slice ? data.slice()
  8319. : Array.prototype.slice.call(data);
  8320. newProxy._len = this._len;
  8321. return newProxy;
  8322. };
  8323. PathProxy.CMD = CMD;
  8324. PathProxy.initDefaultProps = (function () {
  8325. var proto = PathProxy.prototype;
  8326. proto._saveData = true;
  8327. proto._ux = 0;
  8328. proto._uy = 0;
  8329. proto._pendingPtDist = 0;
  8330. proto._version = 0;
  8331. })();
  8332. return PathProxy;
  8333. }());
  8334. function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
  8335. if (lineWidth === 0) {
  8336. return false;
  8337. }
  8338. var _l = lineWidth;
  8339. var _a = 0;
  8340. var _b = x0;
  8341. if ((y > y0 + _l && y > y1 + _l)
  8342. || (y < y0 - _l && y < y1 - _l)
  8343. || (x > x0 + _l && x > x1 + _l)
  8344. || (x < x0 - _l && x < x1 - _l)) {
  8345. return false;
  8346. }
  8347. if (x0 !== x1) {
  8348. _a = (y0 - y1) / (x0 - x1);
  8349. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  8350. }
  8351. else {
  8352. return Math.abs(x - x0) <= _l / 2;
  8353. }
  8354. var tmp = _a * x - y + _b;
  8355. var _s = tmp * tmp / (_a * _a + 1);
  8356. return _s <= _l / 2 * _l / 2;
  8357. }
  8358. function containStroke$1(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  8359. if (lineWidth === 0) {
  8360. return false;
  8361. }
  8362. var _l = lineWidth;
  8363. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  8364. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  8365. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  8366. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)) {
  8367. return false;
  8368. }
  8369. var d = cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  8370. return d <= _l / 2;
  8371. }
  8372. function containStroke$2(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  8373. if (lineWidth === 0) {
  8374. return false;
  8375. }
  8376. var _l = lineWidth;
  8377. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l)
  8378. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  8379. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  8380. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)) {
  8381. return false;
  8382. }
  8383. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  8384. return d <= _l / 2;
  8385. }
  8386. var PI2$2 = Math.PI * 2;
  8387. function normalizeRadian(angle) {
  8388. angle %= PI2$2;
  8389. if (angle < 0) {
  8390. angle += PI2$2;
  8391. }
  8392. return angle;
  8393. }
  8394. var PI2$3 = Math.PI * 2;
  8395. function containStroke$3(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  8396. if (lineWidth === 0) {
  8397. return false;
  8398. }
  8399. var _l = lineWidth;
  8400. x -= cx;
  8401. y -= cy;
  8402. var d = Math.sqrt(x * x + y * y);
  8403. if ((d - _l > r) || (d + _l < r)) {
  8404. return false;
  8405. }
  8406. if (Math.abs(startAngle - endAngle) % PI2$3 < 1e-4) {
  8407. return true;
  8408. }
  8409. if (anticlockwise) {
  8410. var tmp = startAngle;
  8411. startAngle = normalizeRadian(endAngle);
  8412. endAngle = normalizeRadian(tmp);
  8413. }
  8414. else {
  8415. startAngle = normalizeRadian(startAngle);
  8416. endAngle = normalizeRadian(endAngle);
  8417. }
  8418. if (startAngle > endAngle) {
  8419. endAngle += PI2$3;
  8420. }
  8421. var angle = Math.atan2(y, x);
  8422. if (angle < 0) {
  8423. angle += PI2$3;
  8424. }
  8425. return (angle >= startAngle && angle <= endAngle)
  8426. || (angle + PI2$3 >= startAngle && angle + PI2$3 <= endAngle);
  8427. }
  8428. function windingLine(x0, y0, x1, y1, x, y) {
  8429. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  8430. return 0;
  8431. }
  8432. if (y1 === y0) {
  8433. return 0;
  8434. }
  8435. var t = (y - y0) / (y1 - y0);
  8436. var dir = y1 < y0 ? 1 : -1;
  8437. if (t === 1 || t === 0) {
  8438. dir = y1 < y0 ? 0.5 : -0.5;
  8439. }
  8440. var x_ = t * (x1 - x0) + x0;
  8441. return x_ === x ? Infinity : x_ > x ? dir : 0;
  8442. }
  8443. var CMD$1 = PathProxy.CMD;
  8444. var PI2$4 = Math.PI * 2;
  8445. var EPSILON$3 = 1e-4;
  8446. function isAroundEqual(a, b) {
  8447. return Math.abs(a - b) < EPSILON$3;
  8448. }
  8449. var roots = [-1, -1, -1];
  8450. var extrema = [-1, -1];
  8451. function swapExtrema() {
  8452. var tmp = extrema[0];
  8453. extrema[0] = extrema[1];
  8454. extrema[1] = tmp;
  8455. }
  8456. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  8457. if ((y > y0 && y > y1 && y > y2 && y > y3)
  8458. || (y < y0 && y < y1 && y < y2 && y < y3)) {
  8459. return 0;
  8460. }
  8461. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  8462. if (nRoots === 0) {
  8463. return 0;
  8464. }
  8465. else {
  8466. var w = 0;
  8467. var nExtrema = -1;
  8468. var y0_ = void 0;
  8469. var y1_ = void 0;
  8470. for (var i = 0; i < nRoots; i++) {
  8471. var t = roots[i];
  8472. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  8473. var x_ = cubicAt(x0, x1, x2, x3, t);
  8474. if (x_ < x) {
  8475. continue;
  8476. }
  8477. if (nExtrema < 0) {
  8478. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  8479. if (extrema[1] < extrema[0] && nExtrema > 1) {
  8480. swapExtrema();
  8481. }
  8482. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  8483. if (nExtrema > 1) {
  8484. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  8485. }
  8486. }
  8487. if (nExtrema === 2) {
  8488. if (t < extrema[0]) {
  8489. w += y0_ < y0 ? unit : -unit;
  8490. }
  8491. else if (t < extrema[1]) {
  8492. w += y1_ < y0_ ? unit : -unit;
  8493. }
  8494. else {
  8495. w += y3 < y1_ ? unit : -unit;
  8496. }
  8497. }
  8498. else {
  8499. if (t < extrema[0]) {
  8500. w += y0_ < y0 ? unit : -unit;
  8501. }
  8502. else {
  8503. w += y3 < y0_ ? unit : -unit;
  8504. }
  8505. }
  8506. }
  8507. return w;
  8508. }
  8509. }
  8510. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  8511. if ((y > y0 && y > y1 && y > y2)
  8512. || (y < y0 && y < y1 && y < y2)) {
  8513. return 0;
  8514. }
  8515. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  8516. if (nRoots === 0) {
  8517. return 0;
  8518. }
  8519. else {
  8520. var t = quadraticExtremum(y0, y1, y2);
  8521. if (t >= 0 && t <= 1) {
  8522. var w = 0;
  8523. var y_ = quadraticAt(y0, y1, y2, t);
  8524. for (var i = 0; i < nRoots; i++) {
  8525. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  8526. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  8527. if (x_ < x) {
  8528. continue;
  8529. }
  8530. if (roots[i] < t) {
  8531. w += y_ < y0 ? unit : -unit;
  8532. }
  8533. else {
  8534. w += y2 < y_ ? unit : -unit;
  8535. }
  8536. }
  8537. return w;
  8538. }
  8539. else {
  8540. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  8541. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  8542. if (x_ < x) {
  8543. return 0;
  8544. }
  8545. return y2 < y0 ? unit : -unit;
  8546. }
  8547. }
  8548. }
  8549. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  8550. y -= cy;
  8551. if (y > r || y < -r) {
  8552. return 0;
  8553. }
  8554. var tmp = Math.sqrt(r * r - y * y);
  8555. roots[0] = -tmp;
  8556. roots[1] = tmp;
  8557. var dTheta = Math.abs(startAngle - endAngle);
  8558. if (dTheta < 1e-4) {
  8559. return 0;
  8560. }
  8561. if (dTheta >= PI2$4 - 1e-4) {
  8562. startAngle = 0;
  8563. endAngle = PI2$4;
  8564. var dir = anticlockwise ? 1 : -1;
  8565. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  8566. return dir;
  8567. }
  8568. else {
  8569. return 0;
  8570. }
  8571. }
  8572. if (startAngle > endAngle) {
  8573. var tmp_1 = startAngle;
  8574. startAngle = endAngle;
  8575. endAngle = tmp_1;
  8576. }
  8577. if (startAngle < 0) {
  8578. startAngle += PI2$4;
  8579. endAngle += PI2$4;
  8580. }
  8581. var w = 0;
  8582. for (var i = 0; i < 2; i++) {
  8583. var x_ = roots[i];
  8584. if (x_ + cx > x) {
  8585. var angle = Math.atan2(y, x_);
  8586. var dir = anticlockwise ? 1 : -1;
  8587. if (angle < 0) {
  8588. angle = PI2$4 + angle;
  8589. }
  8590. if ((angle >= startAngle && angle <= endAngle)
  8591. || (angle + PI2$4 >= startAngle && angle + PI2$4 <= endAngle)) {
  8592. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  8593. dir = -dir;
  8594. }
  8595. w += dir;
  8596. }
  8597. }
  8598. }
  8599. return w;
  8600. }
  8601. function containPath(path, lineWidth, isStroke, x, y) {
  8602. var data = path.data;
  8603. var len = path.len();
  8604. var w = 0;
  8605. var xi = 0;
  8606. var yi = 0;
  8607. var x0 = 0;
  8608. var y0 = 0;
  8609. var x1;
  8610. var y1;
  8611. for (var i = 0; i < len;) {
  8612. var cmd = data[i++];
  8613. var isFirst = i === 1;
  8614. if (cmd === CMD$1.M && i > 1) {
  8615. if (!isStroke) {
  8616. w += windingLine(xi, yi, x0, y0, x, y);
  8617. }
  8618. }
  8619. if (isFirst) {
  8620. xi = data[i];
  8621. yi = data[i + 1];
  8622. x0 = xi;
  8623. y0 = yi;
  8624. }
  8625. switch (cmd) {
  8626. case CMD$1.M:
  8627. x0 = data[i++];
  8628. y0 = data[i++];
  8629. xi = x0;
  8630. yi = y0;
  8631. break;
  8632. case CMD$1.L:
  8633. if (isStroke) {
  8634. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  8635. return true;
  8636. }
  8637. }
  8638. else {
  8639. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  8640. }
  8641. xi = data[i++];
  8642. yi = data[i++];
  8643. break;
  8644. case CMD$1.C:
  8645. if (isStroke) {
  8646. if (containStroke$1(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8647. return true;
  8648. }
  8649. }
  8650. else {
  8651. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8652. }
  8653. xi = data[i++];
  8654. yi = data[i++];
  8655. break;
  8656. case CMD$1.Q:
  8657. if (isStroke) {
  8658. if (containStroke$2(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8659. return true;
  8660. }
  8661. }
  8662. else {
  8663. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8664. }
  8665. xi = data[i++];
  8666. yi = data[i++];
  8667. break;
  8668. case CMD$1.A:
  8669. var cx = data[i++];
  8670. var cy = data[i++];
  8671. var rx = data[i++];
  8672. var ry = data[i++];
  8673. var theta = data[i++];
  8674. var dTheta = data[i++];
  8675. i += 1;
  8676. var anticlockwise = !!(1 - data[i++]);
  8677. x1 = Math.cos(theta) * rx + cx;
  8678. y1 = Math.sin(theta) * ry + cy;
  8679. if (!isFirst) {
  8680. w += windingLine(xi, yi, x1, y1, x, y);
  8681. }
  8682. else {
  8683. x0 = x1;
  8684. y0 = y1;
  8685. }
  8686. var _x = (x - cx) * ry / rx + cx;
  8687. if (isStroke) {
  8688. if (containStroke$3(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  8689. return true;
  8690. }
  8691. }
  8692. else {
  8693. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  8694. }
  8695. xi = Math.cos(theta + dTheta) * rx + cx;
  8696. yi = Math.sin(theta + dTheta) * ry + cy;
  8697. break;
  8698. case CMD$1.R:
  8699. x0 = xi = data[i++];
  8700. y0 = yi = data[i++];
  8701. var width = data[i++];
  8702. var height = data[i++];
  8703. x1 = x0 + width;
  8704. y1 = y0 + height;
  8705. if (isStroke) {
  8706. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  8707. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  8708. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  8709. || containStroke(x0, y1, x0, y0, lineWidth, x, y)) {
  8710. return true;
  8711. }
  8712. }
  8713. else {
  8714. w += windingLine(x1, y0, x1, y1, x, y);
  8715. w += windingLine(x0, y1, x0, y0, x, y);
  8716. }
  8717. break;
  8718. case CMD$1.Z:
  8719. if (isStroke) {
  8720. if (containStroke(xi, yi, x0, y0, lineWidth, x, y)) {
  8721. return true;
  8722. }
  8723. }
  8724. else {
  8725. w += windingLine(xi, yi, x0, y0, x, y);
  8726. }
  8727. xi = x0;
  8728. yi = y0;
  8729. break;
  8730. }
  8731. }
  8732. if (!isStroke && !isAroundEqual(yi, y0)) {
  8733. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  8734. }
  8735. return w !== 0;
  8736. }
  8737. function contain(pathProxy, x, y) {
  8738. return containPath(pathProxy, 0, false, x, y);
  8739. }
  8740. function containStroke$4(pathProxy, lineWidth, x, y) {
  8741. return containPath(pathProxy, lineWidth, true, x, y);
  8742. }
  8743. var DEFAULT_PATH_STYLE = defaults({
  8744. fill: '#000',
  8745. stroke: null,
  8746. strokePercent: 1,
  8747. fillOpacity: 1,
  8748. strokeOpacity: 1,
  8749. lineDashOffset: 0,
  8750. lineWidth: 1,
  8751. lineCap: 'butt',
  8752. miterLimit: 10,
  8753. strokeNoScale: false,
  8754. strokeFirst: false
  8755. }, DEFAULT_COMMON_STYLE);
  8756. var DEFAULT_PATH_ANIMATION_PROPS = {
  8757. style: defaults({
  8758. fill: true,
  8759. stroke: true,
  8760. strokePercent: true,
  8761. fillOpacity: true,
  8762. strokeOpacity: true,
  8763. lineDashOffset: true,
  8764. lineWidth: true,
  8765. miterLimit: true
  8766. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  8767. };
  8768. var pathCopyParams = TRANSFORMABLE_PROPS.concat(['invisible',
  8769. 'culling', 'z', 'z2', 'zlevel', 'parent'
  8770. ]);
  8771. var Path = (function (_super) {
  8772. __extends(Path, _super);
  8773. function Path(opts) {
  8774. return _super.call(this, opts) || this;
  8775. }
  8776. Path.prototype.update = function () {
  8777. var _this = this;
  8778. _super.prototype.update.call(this);
  8779. var style = this.style;
  8780. if (style.decal) {
  8781. var decalEl = this._decalEl = this._decalEl || new Path();
  8782. if (decalEl.buildPath === Path.prototype.buildPath) {
  8783. decalEl.buildPath = function (ctx) {
  8784. _this.buildPath(ctx, _this.shape);
  8785. };
  8786. }
  8787. decalEl.silent = true;
  8788. var decalElStyle = decalEl.style;
  8789. for (var key in style) {
  8790. if (decalElStyle[key] !== style[key]) {
  8791. decalElStyle[key] = style[key];
  8792. }
  8793. }
  8794. decalElStyle.fill = style.fill ? style.decal : null;
  8795. decalElStyle.decal = null;
  8796. decalElStyle.shadowColor = null;
  8797. style.strokeFirst && (decalElStyle.stroke = null);
  8798. for (var i = 0; i < pathCopyParams.length; ++i) {
  8799. decalEl[pathCopyParams[i]] = this[pathCopyParams[i]];
  8800. }
  8801. decalEl.__dirty |= REDRAW_BIT;
  8802. }
  8803. else if (this._decalEl) {
  8804. this._decalEl = null;
  8805. }
  8806. };
  8807. Path.prototype.getDecalElement = function () {
  8808. return this._decalEl;
  8809. };
  8810. Path.prototype._init = function (props) {
  8811. var keysArr = keys(props);
  8812. this.shape = this.getDefaultShape();
  8813. var defaultStyle = this.getDefaultStyle();
  8814. if (defaultStyle) {
  8815. this.useStyle(defaultStyle);
  8816. }
  8817. for (var i = 0; i < keysArr.length; i++) {
  8818. var key = keysArr[i];
  8819. var value = props[key];
  8820. if (key === 'style') {
  8821. if (!this.style) {
  8822. this.useStyle(value);
  8823. }
  8824. else {
  8825. extend(this.style, value);
  8826. }
  8827. }
  8828. else if (key === 'shape') {
  8829. extend(this.shape, value);
  8830. }
  8831. else {
  8832. _super.prototype.attrKV.call(this, key, value);
  8833. }
  8834. }
  8835. if (!this.style) {
  8836. this.useStyle({});
  8837. }
  8838. };
  8839. Path.prototype.getDefaultStyle = function () {
  8840. return null;
  8841. };
  8842. Path.prototype.getDefaultShape = function () {
  8843. return {};
  8844. };
  8845. Path.prototype.canBeInsideText = function () {
  8846. return this.hasFill();
  8847. };
  8848. Path.prototype.getInsideTextFill = function () {
  8849. var pathFill = this.style.fill;
  8850. if (pathFill !== 'none') {
  8851. if (isString(pathFill)) {
  8852. var fillLum = lum(pathFill, 0);
  8853. if (fillLum > 0.5) {
  8854. return DARK_LABEL_COLOR;
  8855. }
  8856. else if (fillLum > 0.2) {
  8857. return LIGHTER_LABEL_COLOR;
  8858. }
  8859. return LIGHT_LABEL_COLOR;
  8860. }
  8861. else if (pathFill) {
  8862. return LIGHT_LABEL_COLOR;
  8863. }
  8864. }
  8865. return DARK_LABEL_COLOR;
  8866. };
  8867. Path.prototype.getInsideTextStroke = function (textFill) {
  8868. var pathFill = this.style.fill;
  8869. if (isString(pathFill)) {
  8870. var zr = this.__zr;
  8871. var isDarkMode = !!(zr && zr.isDarkMode());
  8872. var isDarkLabel = lum(textFill, 0) < DARK_MODE_THRESHOLD;
  8873. if (isDarkMode === isDarkLabel) {
  8874. return pathFill;
  8875. }
  8876. }
  8877. };
  8878. Path.prototype.buildPath = function (ctx, shapeCfg, inBatch) { };
  8879. Path.prototype.pathUpdated = function () {
  8880. this.__dirty &= ~SHAPE_CHANGED_BIT;
  8881. };
  8882. Path.prototype.getUpdatedPathProxy = function (inBatch) {
  8883. !this.path && this.createPathProxy();
  8884. this.path.beginPath();
  8885. this.buildPath(this.path, this.shape, inBatch);
  8886. return this.path;
  8887. };
  8888. Path.prototype.createPathProxy = function () {
  8889. this.path = new PathProxy(false);
  8890. };
  8891. Path.prototype.hasStroke = function () {
  8892. var style = this.style;
  8893. var stroke = style.stroke;
  8894. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  8895. };
  8896. Path.prototype.hasFill = function () {
  8897. var style = this.style;
  8898. var fill = style.fill;
  8899. return fill != null && fill !== 'none';
  8900. };
  8901. Path.prototype.getBoundingRect = function () {
  8902. var rect = this._rect;
  8903. var style = this.style;
  8904. var needsUpdateRect = !rect;
  8905. if (needsUpdateRect) {
  8906. var firstInvoke = false;
  8907. if (!this.path) {
  8908. firstInvoke = true;
  8909. this.createPathProxy();
  8910. }
  8911. var path = this.path;
  8912. if (firstInvoke || (this.__dirty & SHAPE_CHANGED_BIT)) {
  8913. path.beginPath();
  8914. this.buildPath(path, this.shape, false);
  8915. this.pathUpdated();
  8916. }
  8917. rect = path.getBoundingRect();
  8918. }
  8919. this._rect = rect;
  8920. if (this.hasStroke() && this.path && this.path.len() > 0) {
  8921. var rectStroke = this._rectStroke || (this._rectStroke = rect.clone());
  8922. if (this.__dirty || needsUpdateRect) {
  8923. rectStroke.copy(rect);
  8924. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  8925. var w = style.lineWidth;
  8926. if (!this.hasFill()) {
  8927. var strokeContainThreshold = this.strokeContainThreshold;
  8928. w = Math.max(w, strokeContainThreshold == null ? 4 : strokeContainThreshold);
  8929. }
  8930. if (lineScale > 1e-10) {
  8931. rectStroke.width += w / lineScale;
  8932. rectStroke.height += w / lineScale;
  8933. rectStroke.x -= w / lineScale / 2;
  8934. rectStroke.y -= w / lineScale / 2;
  8935. }
  8936. }
  8937. return rectStroke;
  8938. }
  8939. return rect;
  8940. };
  8941. Path.prototype.contain = function (x, y) {
  8942. var localPos = this.transformCoordToLocal(x, y);
  8943. var rect = this.getBoundingRect();
  8944. var style = this.style;
  8945. x = localPos[0];
  8946. y = localPos[1];
  8947. if (rect.contain(x, y)) {
  8948. var pathProxy = this.path;
  8949. if (this.hasStroke()) {
  8950. var lineWidth = style.lineWidth;
  8951. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  8952. if (lineScale > 1e-10) {
  8953. if (!this.hasFill()) {
  8954. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  8955. }
  8956. if (containStroke$4(pathProxy, lineWidth / lineScale, x, y)) {
  8957. return true;
  8958. }
  8959. }
  8960. }
  8961. if (this.hasFill()) {
  8962. return contain(pathProxy, x, y);
  8963. }
  8964. }
  8965. return false;
  8966. };
  8967. Path.prototype.dirtyShape = function () {
  8968. this.__dirty |= SHAPE_CHANGED_BIT;
  8969. if (this._rect) {
  8970. this._rect = null;
  8971. }
  8972. if (this._decalEl) {
  8973. this._decalEl.dirtyShape();
  8974. }
  8975. this.markRedraw();
  8976. };
  8977. Path.prototype.dirty = function () {
  8978. this.dirtyStyle();
  8979. this.dirtyShape();
  8980. };
  8981. Path.prototype.animateShape = function (loop) {
  8982. return this.animate('shape', loop);
  8983. };
  8984. Path.prototype.updateDuringAnimation = function (targetKey) {
  8985. if (targetKey === 'style') {
  8986. this.dirtyStyle();
  8987. }
  8988. else if (targetKey === 'shape') {
  8989. this.dirtyShape();
  8990. }
  8991. else {
  8992. this.markRedraw();
  8993. }
  8994. };
  8995. Path.prototype.attrKV = function (key, value) {
  8996. if (key === 'shape') {
  8997. this.setShape(value);
  8998. }
  8999. else {
  9000. _super.prototype.attrKV.call(this, key, value);
  9001. }
  9002. };
  9003. Path.prototype.setShape = function (keyOrObj, value) {
  9004. var shape = this.shape;
  9005. if (!shape) {
  9006. shape = this.shape = {};
  9007. }
  9008. if (typeof keyOrObj === 'string') {
  9009. shape[keyOrObj] = value;
  9010. }
  9011. else {
  9012. extend(shape, keyOrObj);
  9013. }
  9014. this.dirtyShape();
  9015. return this;
  9016. };
  9017. Path.prototype.shapeChanged = function () {
  9018. return !!(this.__dirty & SHAPE_CHANGED_BIT);
  9019. };
  9020. Path.prototype.createStyle = function (obj) {
  9021. return createObject(DEFAULT_PATH_STYLE, obj);
  9022. };
  9023. Path.prototype._innerSaveToNormal = function (toState) {
  9024. _super.prototype._innerSaveToNormal.call(this, toState);
  9025. var normalState = this._normalState;
  9026. if (toState.shape && !normalState.shape) {
  9027. normalState.shape = extend({}, this.shape);
  9028. }
  9029. };
  9030. Path.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  9031. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  9032. var needsRestoreToNormal = !(state && keepCurrentStates);
  9033. var targetShape;
  9034. if (state && state.shape) {
  9035. if (transition) {
  9036. if (keepCurrentStates) {
  9037. targetShape = state.shape;
  9038. }
  9039. else {
  9040. targetShape = extend({}, normalState.shape);
  9041. extend(targetShape, state.shape);
  9042. }
  9043. }
  9044. else {
  9045. targetShape = extend({}, keepCurrentStates ? this.shape : normalState.shape);
  9046. extend(targetShape, state.shape);
  9047. }
  9048. }
  9049. else if (needsRestoreToNormal) {
  9050. targetShape = normalState.shape;
  9051. }
  9052. if (targetShape) {
  9053. if (transition) {
  9054. this.shape = extend({}, this.shape);
  9055. var targetShapePrimaryProps = {};
  9056. var shapeKeys = keys(targetShape);
  9057. for (var i = 0; i < shapeKeys.length; i++) {
  9058. var key = shapeKeys[i];
  9059. if (typeof targetShape[key] === 'object') {
  9060. this.shape[key] = targetShape[key];
  9061. }
  9062. else {
  9063. targetShapePrimaryProps[key] = targetShape[key];
  9064. }
  9065. }
  9066. this._transitionState(stateName, {
  9067. shape: targetShapePrimaryProps
  9068. }, animationCfg);
  9069. }
  9070. else {
  9071. this.shape = targetShape;
  9072. this.dirtyShape();
  9073. }
  9074. }
  9075. };
  9076. Path.prototype._mergeStates = function (states) {
  9077. var mergedState = _super.prototype._mergeStates.call(this, states);
  9078. var mergedShape;
  9079. for (var i = 0; i < states.length; i++) {
  9080. var state = states[i];
  9081. if (state.shape) {
  9082. mergedShape = mergedShape || {};
  9083. this._mergeStyle(mergedShape, state.shape);
  9084. }
  9085. }
  9086. if (mergedShape) {
  9087. mergedState.shape = mergedShape;
  9088. }
  9089. return mergedState;
  9090. };
  9091. Path.prototype.getAnimationStyleProps = function () {
  9092. return DEFAULT_PATH_ANIMATION_PROPS;
  9093. };
  9094. Path.prototype.isZeroArea = function () {
  9095. return false;
  9096. };
  9097. Path.extend = function (defaultProps) {
  9098. var Sub = (function (_super) {
  9099. __extends(Sub, _super);
  9100. function Sub(opts) {
  9101. var _this = _super.call(this, opts) || this;
  9102. defaultProps.init && defaultProps.init.call(_this, opts);
  9103. return _this;
  9104. }
  9105. Sub.prototype.getDefaultStyle = function () {
  9106. return clone(defaultProps.style);
  9107. };
  9108. Sub.prototype.getDefaultShape = function () {
  9109. return clone(defaultProps.shape);
  9110. };
  9111. return Sub;
  9112. }(Path));
  9113. for (var key in defaultProps) {
  9114. if (typeof defaultProps[key] === 'function') {
  9115. Sub.prototype[key] = defaultProps[key];
  9116. }
  9117. }
  9118. return Sub;
  9119. };
  9120. Path.initDefaultProps = (function () {
  9121. var pathProto = Path.prototype;
  9122. pathProto.type = 'path';
  9123. pathProto.strokeContainThreshold = 5;
  9124. pathProto.segmentIgnoreThreshold = 0;
  9125. pathProto.subPixelOptimize = false;
  9126. pathProto.autoBatch = false;
  9127. pathProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT | SHAPE_CHANGED_BIT;
  9128. })();
  9129. return Path;
  9130. }(Displayable));
  9131. var CMD$2 = PathProxy.CMD;
  9132. var points = [[], [], []];
  9133. var mathSqrt$1 = Math.sqrt;
  9134. var mathAtan2 = Math.atan2;
  9135. function transformPath(path, m) {
  9136. if (!m) {
  9137. return;
  9138. }
  9139. var data = path.data;
  9140. var len = path.len();
  9141. var cmd;
  9142. var nPoint;
  9143. var i;
  9144. var j;
  9145. var k;
  9146. var p;
  9147. var M = CMD$2.M;
  9148. var C = CMD$2.C;
  9149. var L = CMD$2.L;
  9150. var R = CMD$2.R;
  9151. var A = CMD$2.A;
  9152. var Q = CMD$2.Q;
  9153. for (i = 0, j = 0; i < len;) {
  9154. cmd = data[i++];
  9155. j = i;
  9156. nPoint = 0;
  9157. switch (cmd) {
  9158. case M:
  9159. nPoint = 1;
  9160. break;
  9161. case L:
  9162. nPoint = 1;
  9163. break;
  9164. case C:
  9165. nPoint = 3;
  9166. break;
  9167. case Q:
  9168. nPoint = 2;
  9169. break;
  9170. case A:
  9171. var x = m[4];
  9172. var y = m[5];
  9173. var sx = mathSqrt$1(m[0] * m[0] + m[1] * m[1]);
  9174. var sy = mathSqrt$1(m[2] * m[2] + m[3] * m[3]);
  9175. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  9176. data[i] *= sx;
  9177. data[i++] += x;
  9178. data[i] *= sy;
  9179. data[i++] += y;
  9180. data[i++] *= sx;
  9181. data[i++] *= sy;
  9182. data[i++] += angle;
  9183. data[i++] += angle;
  9184. i += 2;
  9185. j = i;
  9186. break;
  9187. case R:
  9188. p[0] = data[i++];
  9189. p[1] = data[i++];
  9190. applyTransform(p, p, m);
  9191. data[j++] = p[0];
  9192. data[j++] = p[1];
  9193. p[0] += data[i++];
  9194. p[1] += data[i++];
  9195. applyTransform(p, p, m);
  9196. data[j++] = p[0];
  9197. data[j++] = p[1];
  9198. }
  9199. for (k = 0; k < nPoint; k++) {
  9200. var p_1 = points[k];
  9201. p_1[0] = data[i++];
  9202. p_1[1] = data[i++];
  9203. applyTransform(p_1, p_1, m);
  9204. data[j++] = p_1[0];
  9205. data[j++] = p_1[1];
  9206. }
  9207. }
  9208. path.increaseVersion();
  9209. }
  9210. var mathSqrt$2 = Math.sqrt;
  9211. var mathSin$2 = Math.sin;
  9212. var mathCos$2 = Math.cos;
  9213. var PI$1 = Math.PI;
  9214. function vMag(v) {
  9215. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  9216. }
  9217. function vRatio(u, v) {
  9218. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  9219. }
  9220. function vAngle(u, v) {
  9221. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  9222. * Math.acos(vRatio(u, v));
  9223. }
  9224. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  9225. var psi = psiDeg * (PI$1 / 180.0);
  9226. var xp = mathCos$2(psi) * (x1 - x2) / 2.0
  9227. + mathSin$2(psi) * (y1 - y2) / 2.0;
  9228. var yp = -1 * mathSin$2(psi) * (x1 - x2) / 2.0
  9229. + mathCos$2(psi) * (y1 - y2) / 2.0;
  9230. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  9231. if (lambda > 1) {
  9232. rx *= mathSqrt$2(lambda);
  9233. ry *= mathSqrt$2(lambda);
  9234. }
  9235. var f = (fa === fs ? -1 : 1)
  9236. * mathSqrt$2((((rx * rx) * (ry * ry))
  9237. - ((rx * rx) * (yp * yp))
  9238. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  9239. + (ry * ry) * (xp * xp))) || 0;
  9240. var cxp = f * rx * yp / ry;
  9241. var cyp = f * -ry * xp / rx;
  9242. var cx = (x1 + x2) / 2.0
  9243. + mathCos$2(psi) * cxp
  9244. - mathSin$2(psi) * cyp;
  9245. var cy = (y1 + y2) / 2.0
  9246. + mathSin$2(psi) * cxp
  9247. + mathCos$2(psi) * cyp;
  9248. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  9249. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  9250. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  9251. var dTheta = vAngle(u, v);
  9252. if (vRatio(u, v) <= -1) {
  9253. dTheta = PI$1;
  9254. }
  9255. if (vRatio(u, v) >= 1) {
  9256. dTheta = 0;
  9257. }
  9258. if (dTheta < 0) {
  9259. var n = Math.round(dTheta / PI$1 * 1e6) / 1e6;
  9260. dTheta = PI$1 * 2 + (n % 2) * PI$1;
  9261. }
  9262. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  9263. }
  9264. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  9265. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  9266. function createPathProxyFromString(data) {
  9267. var path = new PathProxy();
  9268. if (!data) {
  9269. return path;
  9270. }
  9271. var cpx = 0;
  9272. var cpy = 0;
  9273. var subpathX = cpx;
  9274. var subpathY = cpy;
  9275. var prevCmd;
  9276. var CMD = PathProxy.CMD;
  9277. var cmdList = data.match(commandReg);
  9278. if (!cmdList) {
  9279. return path;
  9280. }
  9281. for (var l = 0; l < cmdList.length; l++) {
  9282. var cmdText = cmdList[l];
  9283. var cmdStr = cmdText.charAt(0);
  9284. var cmd = void 0;
  9285. var p = cmdText.match(numberReg) || [];
  9286. var pLen = p.length;
  9287. for (var i = 0; i < pLen; i++) {
  9288. p[i] = parseFloat(p[i]);
  9289. }
  9290. var off = 0;
  9291. while (off < pLen) {
  9292. var ctlPtx = void 0;
  9293. var ctlPty = void 0;
  9294. var rx = void 0;
  9295. var ry = void 0;
  9296. var psi = void 0;
  9297. var fa = void 0;
  9298. var fs = void 0;
  9299. var x1 = cpx;
  9300. var y1 = cpy;
  9301. var len = void 0;
  9302. var pathData = void 0;
  9303. switch (cmdStr) {
  9304. case 'l':
  9305. cpx += p[off++];
  9306. cpy += p[off++];
  9307. cmd = CMD.L;
  9308. path.addData(cmd, cpx, cpy);
  9309. break;
  9310. case 'L':
  9311. cpx = p[off++];
  9312. cpy = p[off++];
  9313. cmd = CMD.L;
  9314. path.addData(cmd, cpx, cpy);
  9315. break;
  9316. case 'm':
  9317. cpx += p[off++];
  9318. cpy += p[off++];
  9319. cmd = CMD.M;
  9320. path.addData(cmd, cpx, cpy);
  9321. subpathX = cpx;
  9322. subpathY = cpy;
  9323. cmdStr = 'l';
  9324. break;
  9325. case 'M':
  9326. cpx = p[off++];
  9327. cpy = p[off++];
  9328. cmd = CMD.M;
  9329. path.addData(cmd, cpx, cpy);
  9330. subpathX = cpx;
  9331. subpathY = cpy;
  9332. cmdStr = 'L';
  9333. break;
  9334. case 'h':
  9335. cpx += p[off++];
  9336. cmd = CMD.L;
  9337. path.addData(cmd, cpx, cpy);
  9338. break;
  9339. case 'H':
  9340. cpx = p[off++];
  9341. cmd = CMD.L;
  9342. path.addData(cmd, cpx, cpy);
  9343. break;
  9344. case 'v':
  9345. cpy += p[off++];
  9346. cmd = CMD.L;
  9347. path.addData(cmd, cpx, cpy);
  9348. break;
  9349. case 'V':
  9350. cpy = p[off++];
  9351. cmd = CMD.L;
  9352. path.addData(cmd, cpx, cpy);
  9353. break;
  9354. case 'C':
  9355. cmd = CMD.C;
  9356. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  9357. cpx = p[off - 2];
  9358. cpy = p[off - 1];
  9359. break;
  9360. case 'c':
  9361. cmd = CMD.C;
  9362. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  9363. cpx += p[off - 2];
  9364. cpy += p[off - 1];
  9365. break;
  9366. case 'S':
  9367. ctlPtx = cpx;
  9368. ctlPty = cpy;
  9369. len = path.len();
  9370. pathData = path.data;
  9371. if (prevCmd === CMD.C) {
  9372. ctlPtx += cpx - pathData[len - 4];
  9373. ctlPty += cpy - pathData[len - 3];
  9374. }
  9375. cmd = CMD.C;
  9376. x1 = p[off++];
  9377. y1 = p[off++];
  9378. cpx = p[off++];
  9379. cpy = p[off++];
  9380. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9381. break;
  9382. case 's':
  9383. ctlPtx = cpx;
  9384. ctlPty = cpy;
  9385. len = path.len();
  9386. pathData = path.data;
  9387. if (prevCmd === CMD.C) {
  9388. ctlPtx += cpx - pathData[len - 4];
  9389. ctlPty += cpy - pathData[len - 3];
  9390. }
  9391. cmd = CMD.C;
  9392. x1 = cpx + p[off++];
  9393. y1 = cpy + p[off++];
  9394. cpx += p[off++];
  9395. cpy += p[off++];
  9396. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9397. break;
  9398. case 'Q':
  9399. x1 = p[off++];
  9400. y1 = p[off++];
  9401. cpx = p[off++];
  9402. cpy = p[off++];
  9403. cmd = CMD.Q;
  9404. path.addData(cmd, x1, y1, cpx, cpy);
  9405. break;
  9406. case 'q':
  9407. x1 = p[off++] + cpx;
  9408. y1 = p[off++] + cpy;
  9409. cpx += p[off++];
  9410. cpy += p[off++];
  9411. cmd = CMD.Q;
  9412. path.addData(cmd, x1, y1, cpx, cpy);
  9413. break;
  9414. case 'T':
  9415. ctlPtx = cpx;
  9416. ctlPty = cpy;
  9417. len = path.len();
  9418. pathData = path.data;
  9419. if (prevCmd === CMD.Q) {
  9420. ctlPtx += cpx - pathData[len - 4];
  9421. ctlPty += cpy - pathData[len - 3];
  9422. }
  9423. cpx = p[off++];
  9424. cpy = p[off++];
  9425. cmd = CMD.Q;
  9426. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9427. break;
  9428. case 't':
  9429. ctlPtx = cpx;
  9430. ctlPty = cpy;
  9431. len = path.len();
  9432. pathData = path.data;
  9433. if (prevCmd === CMD.Q) {
  9434. ctlPtx += cpx - pathData[len - 4];
  9435. ctlPty += cpy - pathData[len - 3];
  9436. }
  9437. cpx += p[off++];
  9438. cpy += p[off++];
  9439. cmd = CMD.Q;
  9440. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9441. break;
  9442. case 'A':
  9443. rx = p[off++];
  9444. ry = p[off++];
  9445. psi = p[off++];
  9446. fa = p[off++];
  9447. fs = p[off++];
  9448. x1 = cpx, y1 = cpy;
  9449. cpx = p[off++];
  9450. cpy = p[off++];
  9451. cmd = CMD.A;
  9452. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9453. break;
  9454. case 'a':
  9455. rx = p[off++];
  9456. ry = p[off++];
  9457. psi = p[off++];
  9458. fa = p[off++];
  9459. fs = p[off++];
  9460. x1 = cpx, y1 = cpy;
  9461. cpx += p[off++];
  9462. cpy += p[off++];
  9463. cmd = CMD.A;
  9464. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9465. break;
  9466. }
  9467. }
  9468. if (cmdStr === 'z' || cmdStr === 'Z') {
  9469. cmd = CMD.Z;
  9470. path.addData(cmd);
  9471. cpx = subpathX;
  9472. cpy = subpathY;
  9473. }
  9474. prevCmd = cmd;
  9475. }
  9476. path.toStatic();
  9477. return path;
  9478. }
  9479. var SVGPath = (function (_super) {
  9480. __extends(SVGPath, _super);
  9481. function SVGPath() {
  9482. return _super !== null && _super.apply(this, arguments) || this;
  9483. }
  9484. SVGPath.prototype.applyTransform = function (m) { };
  9485. return SVGPath;
  9486. }(Path));
  9487. function isPathProxy(path) {
  9488. return path.setData != null;
  9489. }
  9490. function createPathOptions(str, opts) {
  9491. var pathProxy = createPathProxyFromString(str);
  9492. var innerOpts = extend({}, opts);
  9493. innerOpts.buildPath = function (path) {
  9494. if (isPathProxy(path)) {
  9495. path.setData(pathProxy.data);
  9496. var ctx = path.getContext();
  9497. if (ctx) {
  9498. path.rebuildPath(ctx, 1);
  9499. }
  9500. }
  9501. else {
  9502. var ctx = path;
  9503. pathProxy.rebuildPath(ctx, 1);
  9504. }
  9505. };
  9506. innerOpts.applyTransform = function (m) {
  9507. transformPath(pathProxy, m);
  9508. this.dirtyShape();
  9509. };
  9510. return innerOpts;
  9511. }
  9512. function createFromString(str, opts) {
  9513. return new SVGPath(createPathOptions(str, opts));
  9514. }
  9515. function extendFromString(str, defaultOpts) {
  9516. var innerOpts = createPathOptions(str, defaultOpts);
  9517. var Sub = (function (_super) {
  9518. __extends(Sub, _super);
  9519. function Sub(opts) {
  9520. var _this = _super.call(this, opts) || this;
  9521. _this.applyTransform = innerOpts.applyTransform;
  9522. _this.buildPath = innerOpts.buildPath;
  9523. return _this;
  9524. }
  9525. return Sub;
  9526. }(SVGPath));
  9527. return Sub;
  9528. }
  9529. function mergePath(pathEls, opts) {
  9530. var pathList = [];
  9531. var len = pathEls.length;
  9532. for (var i = 0; i < len; i++) {
  9533. var pathEl = pathEls[i];
  9534. pathList.push(pathEl.getUpdatedPathProxy(true));
  9535. }
  9536. var pathBundle = new Path(opts);
  9537. pathBundle.createPathProxy();
  9538. pathBundle.buildPath = function (path) {
  9539. if (isPathProxy(path)) {
  9540. path.appendPath(pathList);
  9541. var ctx = path.getContext();
  9542. if (ctx) {
  9543. path.rebuildPath(ctx, 1);
  9544. }
  9545. }
  9546. };
  9547. return pathBundle;
  9548. }
  9549. function clonePath(sourcePath, opts) {
  9550. opts = opts || {};
  9551. var path = new Path();
  9552. if (sourcePath.shape) {
  9553. path.setShape(sourcePath.shape);
  9554. }
  9555. path.setStyle(sourcePath.style);
  9556. if (opts.bakeTransform) {
  9557. transformPath(path.path, sourcePath.getComputedTransform());
  9558. }
  9559. else {
  9560. if (opts.toLocal) {
  9561. path.setLocalTransform(sourcePath.getComputedTransform());
  9562. }
  9563. else {
  9564. path.copyTransform(sourcePath);
  9565. }
  9566. }
  9567. path.buildPath = sourcePath.buildPath;
  9568. path.applyTransform = path.applyTransform;
  9569. path.z = sourcePath.z;
  9570. path.z2 = sourcePath.z2;
  9571. path.zlevel = sourcePath.zlevel;
  9572. return path;
  9573. }
  9574. var path = /*#__PURE__*/Object.freeze({
  9575. __proto__: null,
  9576. createFromString: createFromString,
  9577. extendFromString: extendFromString,
  9578. mergePath: mergePath,
  9579. clonePath: clonePath
  9580. });
  9581. var DEFAULT_IMAGE_STYLE = defaults({
  9582. x: 0,
  9583. y: 0
  9584. }, DEFAULT_COMMON_STYLE);
  9585. var DEFAULT_IMAGE_ANIMATION_PROPS = {
  9586. style: defaults({
  9587. x: true,
  9588. y: true,
  9589. width: true,
  9590. height: true,
  9591. sx: true,
  9592. sy: true,
  9593. sWidth: true,
  9594. sHeight: true
  9595. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  9596. };
  9597. function isImageLike(source) {
  9598. return !!(source
  9599. && typeof source !== 'string'
  9600. && source.width && source.height);
  9601. }
  9602. var ZRImage = (function (_super) {
  9603. __extends(ZRImage, _super);
  9604. function ZRImage() {
  9605. return _super !== null && _super.apply(this, arguments) || this;
  9606. }
  9607. ZRImage.prototype.createStyle = function (obj) {
  9608. return createObject(DEFAULT_IMAGE_STYLE, obj);
  9609. };
  9610. ZRImage.prototype._getSize = function (dim) {
  9611. var style = this.style;
  9612. var size = style[dim];
  9613. if (size != null) {
  9614. return size;
  9615. }
  9616. var imageSource = isImageLike(style.image)
  9617. ? style.image : this.__image;
  9618. if (!imageSource) {
  9619. return 0;
  9620. }
  9621. var otherDim = dim === 'width' ? 'height' : 'width';
  9622. var otherDimSize = style[otherDim];
  9623. if (otherDimSize == null) {
  9624. return imageSource[dim];
  9625. }
  9626. else {
  9627. return imageSource[dim] / imageSource[otherDim] * otherDimSize;
  9628. }
  9629. };
  9630. ZRImage.prototype.getWidth = function () {
  9631. return this._getSize('width');
  9632. };
  9633. ZRImage.prototype.getHeight = function () {
  9634. return this._getSize('height');
  9635. };
  9636. ZRImage.prototype.getAnimationStyleProps = function () {
  9637. return DEFAULT_IMAGE_ANIMATION_PROPS;
  9638. };
  9639. ZRImage.prototype.getBoundingRect = function () {
  9640. var style = this.style;
  9641. if (!this._rect) {
  9642. this._rect = new BoundingRect(style.x || 0, style.y || 0, this.getWidth(), this.getHeight());
  9643. }
  9644. return this._rect;
  9645. };
  9646. return ZRImage;
  9647. }(Displayable));
  9648. ZRImage.prototype.type = 'image';
  9649. var CircleShape = (function () {
  9650. function CircleShape() {
  9651. this.cx = 0;
  9652. this.cy = 0;
  9653. this.r = 0;
  9654. }
  9655. return CircleShape;
  9656. }());
  9657. var Circle = (function (_super) {
  9658. __extends(Circle, _super);
  9659. function Circle(opts) {
  9660. return _super.call(this, opts) || this;
  9661. }
  9662. Circle.prototype.getDefaultShape = function () {
  9663. return new CircleShape();
  9664. };
  9665. Circle.prototype.buildPath = function (ctx, shape) {
  9666. ctx.moveTo(shape.cx + shape.r, shape.cy);
  9667. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2);
  9668. };
  9669. return Circle;
  9670. }(Path));
  9671. Circle.prototype.type = 'circle';
  9672. function buildPath(ctx, shape) {
  9673. var x = shape.x;
  9674. var y = shape.y;
  9675. var width = shape.width;
  9676. var height = shape.height;
  9677. var r = shape.r;
  9678. var r1;
  9679. var r2;
  9680. var r3;
  9681. var r4;
  9682. if (width < 0) {
  9683. x = x + width;
  9684. width = -width;
  9685. }
  9686. if (height < 0) {
  9687. y = y + height;
  9688. height = -height;
  9689. }
  9690. if (typeof r === 'number') {
  9691. r1 = r2 = r3 = r4 = r;
  9692. }
  9693. else if (r instanceof Array) {
  9694. if (r.length === 1) {
  9695. r1 = r2 = r3 = r4 = r[0];
  9696. }
  9697. else if (r.length === 2) {
  9698. r1 = r3 = r[0];
  9699. r2 = r4 = r[1];
  9700. }
  9701. else if (r.length === 3) {
  9702. r1 = r[0];
  9703. r2 = r4 = r[1];
  9704. r3 = r[2];
  9705. }
  9706. else {
  9707. r1 = r[0];
  9708. r2 = r[1];
  9709. r3 = r[2];
  9710. r4 = r[3];
  9711. }
  9712. }
  9713. else {
  9714. r1 = r2 = r3 = r4 = 0;
  9715. }
  9716. var total;
  9717. if (r1 + r2 > width) {
  9718. total = r1 + r2;
  9719. r1 *= width / total;
  9720. r2 *= width / total;
  9721. }
  9722. if (r3 + r4 > width) {
  9723. total = r3 + r4;
  9724. r3 *= width / total;
  9725. r4 *= width / total;
  9726. }
  9727. if (r2 + r3 > height) {
  9728. total = r2 + r3;
  9729. r2 *= height / total;
  9730. r3 *= height / total;
  9731. }
  9732. if (r1 + r4 > height) {
  9733. total = r1 + r4;
  9734. r1 *= height / total;
  9735. r4 *= height / total;
  9736. }
  9737. ctx.moveTo(x + r1, y);
  9738. ctx.lineTo(x + width - r2, y);
  9739. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  9740. ctx.lineTo(x + width, y + height - r3);
  9741. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  9742. ctx.lineTo(x + r4, y + height);
  9743. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  9744. ctx.lineTo(x, y + r1);
  9745. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  9746. }
  9747. var round = Math.round;
  9748. function subPixelOptimizeLine(outputShape, inputShape, style) {
  9749. if (!inputShape) {
  9750. return;
  9751. }
  9752. var x1 = inputShape.x1;
  9753. var x2 = inputShape.x2;
  9754. var y1 = inputShape.y1;
  9755. var y2 = inputShape.y2;
  9756. outputShape.x1 = x1;
  9757. outputShape.x2 = x2;
  9758. outputShape.y1 = y1;
  9759. outputShape.y2 = y2;
  9760. var lineWidth = style && style.lineWidth;
  9761. if (!lineWidth) {
  9762. return outputShape;
  9763. }
  9764. if (round(x1 * 2) === round(x2 * 2)) {
  9765. outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true);
  9766. }
  9767. if (round(y1 * 2) === round(y2 * 2)) {
  9768. outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true);
  9769. }
  9770. return outputShape;
  9771. }
  9772. function subPixelOptimizeRect(outputShape, inputShape, style) {
  9773. if (!inputShape) {
  9774. return;
  9775. }
  9776. var originX = inputShape.x;
  9777. var originY = inputShape.y;
  9778. var originWidth = inputShape.width;
  9779. var originHeight = inputShape.height;
  9780. outputShape.x = originX;
  9781. outputShape.y = originY;
  9782. outputShape.width = originWidth;
  9783. outputShape.height = originHeight;
  9784. var lineWidth = style && style.lineWidth;
  9785. if (!lineWidth) {
  9786. return outputShape;
  9787. }
  9788. outputShape.x = subPixelOptimize(originX, lineWidth, true);
  9789. outputShape.y = subPixelOptimize(originY, lineWidth, true);
  9790. outputShape.width = Math.max(subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
  9791. outputShape.height = Math.max(subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
  9792. return outputShape;
  9793. }
  9794. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  9795. if (!lineWidth) {
  9796. return position;
  9797. }
  9798. var doubledPosition = round(position * 2);
  9799. return (doubledPosition + round(lineWidth)) % 2 === 0
  9800. ? doubledPosition / 2
  9801. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  9802. }
  9803. var RectShape = (function () {
  9804. function RectShape() {
  9805. this.x = 0;
  9806. this.y = 0;
  9807. this.width = 0;
  9808. this.height = 0;
  9809. }
  9810. return RectShape;
  9811. }());
  9812. var subPixelOptimizeOutputShape = {};
  9813. var Rect = (function (_super) {
  9814. __extends(Rect, _super);
  9815. function Rect(opts) {
  9816. return _super.call(this, opts) || this;
  9817. }
  9818. Rect.prototype.getDefaultShape = function () {
  9819. return new RectShape();
  9820. };
  9821. Rect.prototype.buildPath = function (ctx, shape) {
  9822. var x;
  9823. var y;
  9824. var width;
  9825. var height;
  9826. if (this.subPixelOptimize) {
  9827. var optimizedShape = subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style);
  9828. x = optimizedShape.x;
  9829. y = optimizedShape.y;
  9830. width = optimizedShape.width;
  9831. height = optimizedShape.height;
  9832. optimizedShape.r = shape.r;
  9833. shape = optimizedShape;
  9834. }
  9835. else {
  9836. x = shape.x;
  9837. y = shape.y;
  9838. width = shape.width;
  9839. height = shape.height;
  9840. }
  9841. if (!shape.r) {
  9842. ctx.rect(x, y, width, height);
  9843. }
  9844. else {
  9845. buildPath(ctx, shape);
  9846. }
  9847. };
  9848. Rect.prototype.isZeroArea = function () {
  9849. return !this.shape.width || !this.shape.height;
  9850. };
  9851. return Rect;
  9852. }(Path));
  9853. Rect.prototype.type = 'rect';
  9854. var EllipseShape = (function () {
  9855. function EllipseShape() {
  9856. this.cx = 0;
  9857. this.cy = 0;
  9858. this.rx = 0;
  9859. this.ry = 0;
  9860. }
  9861. return EllipseShape;
  9862. }());
  9863. var Ellipse = (function (_super) {
  9864. __extends(Ellipse, _super);
  9865. function Ellipse(opts) {
  9866. return _super.call(this, opts) || this;
  9867. }
  9868. Ellipse.prototype.getDefaultShape = function () {
  9869. return new EllipseShape();
  9870. };
  9871. Ellipse.prototype.buildPath = function (ctx, shape) {
  9872. var k = 0.5522848;
  9873. var x = shape.cx;
  9874. var y = shape.cy;
  9875. var a = shape.rx;
  9876. var b = shape.ry;
  9877. var ox = a * k;
  9878. var oy = b * k;
  9879. ctx.moveTo(x - a, y);
  9880. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  9881. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  9882. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  9883. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  9884. ctx.closePath();
  9885. };
  9886. return Ellipse;
  9887. }(Path));
  9888. Ellipse.prototype.type = 'ellipse';
  9889. var subPixelOptimizeOutputShape$1 = {};
  9890. var LineShape = (function () {
  9891. function LineShape() {
  9892. this.x1 = 0;
  9893. this.y1 = 0;
  9894. this.x2 = 0;
  9895. this.y2 = 0;
  9896. this.percent = 1;
  9897. }
  9898. return LineShape;
  9899. }());
  9900. var Line = (function (_super) {
  9901. __extends(Line, _super);
  9902. function Line(opts) {
  9903. return _super.call(this, opts) || this;
  9904. }
  9905. Line.prototype.getDefaultStyle = function () {
  9906. return {
  9907. stroke: '#000',
  9908. fill: null
  9909. };
  9910. };
  9911. Line.prototype.getDefaultShape = function () {
  9912. return new LineShape();
  9913. };
  9914. Line.prototype.buildPath = function (ctx, shape) {
  9915. var x1;
  9916. var y1;
  9917. var x2;
  9918. var y2;
  9919. if (this.subPixelOptimize) {
  9920. var optimizedShape = subPixelOptimizeLine(subPixelOptimizeOutputShape$1, shape, this.style);
  9921. x1 = optimizedShape.x1;
  9922. y1 = optimizedShape.y1;
  9923. x2 = optimizedShape.x2;
  9924. y2 = optimizedShape.y2;
  9925. }
  9926. else {
  9927. x1 = shape.x1;
  9928. y1 = shape.y1;
  9929. x2 = shape.x2;
  9930. y2 = shape.y2;
  9931. }
  9932. var percent = shape.percent;
  9933. if (percent === 0) {
  9934. return;
  9935. }
  9936. ctx.moveTo(x1, y1);
  9937. if (percent < 1) {
  9938. x2 = x1 * (1 - percent) + x2 * percent;
  9939. y2 = y1 * (1 - percent) + y2 * percent;
  9940. }
  9941. ctx.lineTo(x2, y2);
  9942. };
  9943. Line.prototype.pointAt = function (p) {
  9944. var shape = this.shape;
  9945. return [
  9946. shape.x1 * (1 - p) + shape.x2 * p,
  9947. shape.y1 * (1 - p) + shape.y2 * p
  9948. ];
  9949. };
  9950. return Line;
  9951. }(Path));
  9952. Line.prototype.type = 'line';
  9953. function smoothBezier(points, smooth, isLoop, constraint) {
  9954. var cps = [];
  9955. var v = [];
  9956. var v1 = [];
  9957. var v2 = [];
  9958. var prevPoint;
  9959. var nextPoint;
  9960. var min$1;
  9961. var max$1;
  9962. if (constraint) {
  9963. min$1 = [Infinity, Infinity];
  9964. max$1 = [-Infinity, -Infinity];
  9965. for (var i = 0, len = points.length; i < len; i++) {
  9966. min(min$1, min$1, points[i]);
  9967. max(max$1, max$1, points[i]);
  9968. }
  9969. min(min$1, min$1, constraint[0]);
  9970. max(max$1, max$1, constraint[1]);
  9971. }
  9972. for (var i = 0, len = points.length; i < len; i++) {
  9973. var point = points[i];
  9974. if (isLoop) {
  9975. prevPoint = points[i ? i - 1 : len - 1];
  9976. nextPoint = points[(i + 1) % len];
  9977. }
  9978. else {
  9979. if (i === 0 || i === len - 1) {
  9980. cps.push(clone$1(points[i]));
  9981. continue;
  9982. }
  9983. else {
  9984. prevPoint = points[i - 1];
  9985. nextPoint = points[i + 1];
  9986. }
  9987. }
  9988. sub(v, nextPoint, prevPoint);
  9989. scale(v, v, smooth);
  9990. var d0 = distance(point, prevPoint);
  9991. var d1 = distance(point, nextPoint);
  9992. var sum = d0 + d1;
  9993. if (sum !== 0) {
  9994. d0 /= sum;
  9995. d1 /= sum;
  9996. }
  9997. scale(v1, v, -d0);
  9998. scale(v2, v, d1);
  9999. var cp0 = add([], point, v1);
  10000. var cp1 = add([], point, v2);
  10001. if (constraint) {
  10002. max(cp0, cp0, min$1);
  10003. min(cp0, cp0, max$1);
  10004. max(cp1, cp1, min$1);
  10005. min(cp1, cp1, max$1);
  10006. }
  10007. cps.push(cp0);
  10008. cps.push(cp1);
  10009. }
  10010. if (isLoop) {
  10011. cps.push(cps.shift());
  10012. }
  10013. return cps;
  10014. }
  10015. function buildPath$1(ctx, shape, closePath) {
  10016. var smooth = shape.smooth;
  10017. var points = shape.points;
  10018. if (points && points.length >= 2) {
  10019. if (smooth) {
  10020. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  10021. ctx.moveTo(points[0][0], points[0][1]);
  10022. var len = points.length;
  10023. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  10024. var cp1 = controlPoints[i * 2];
  10025. var cp2 = controlPoints[i * 2 + 1];
  10026. var p = points[(i + 1) % len];
  10027. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  10028. }
  10029. }
  10030. else {
  10031. ctx.moveTo(points[0][0], points[0][1]);
  10032. for (var i = 1, l = points.length; i < l; i++) {
  10033. ctx.lineTo(points[i][0], points[i][1]);
  10034. }
  10035. }
  10036. closePath && ctx.closePath();
  10037. }
  10038. }
  10039. var PolygonShape = (function () {
  10040. function PolygonShape() {
  10041. this.points = null;
  10042. this.smooth = 0;
  10043. this.smoothConstraint = null;
  10044. }
  10045. return PolygonShape;
  10046. }());
  10047. var Polygon = (function (_super) {
  10048. __extends(Polygon, _super);
  10049. function Polygon(opts) {
  10050. return _super.call(this, opts) || this;
  10051. }
  10052. Polygon.prototype.getDefaultShape = function () {
  10053. return new PolygonShape();
  10054. };
  10055. Polygon.prototype.buildPath = function (ctx, shape) {
  10056. buildPath$1(ctx, shape, true);
  10057. };
  10058. return Polygon;
  10059. }(Path));
  10060. Polygon.prototype.type = 'polygon';
  10061. var PolylineShape = (function () {
  10062. function PolylineShape() {
  10063. this.points = null;
  10064. this.percent = 1;
  10065. this.smooth = 0;
  10066. this.smoothConstraint = null;
  10067. }
  10068. return PolylineShape;
  10069. }());
  10070. var Polyline = (function (_super) {
  10071. __extends(Polyline, _super);
  10072. function Polyline(opts) {
  10073. return _super.call(this, opts) || this;
  10074. }
  10075. Polyline.prototype.getDefaultStyle = function () {
  10076. return {
  10077. stroke: '#000',
  10078. fill: null
  10079. };
  10080. };
  10081. Polyline.prototype.getDefaultShape = function () {
  10082. return new PolylineShape();
  10083. };
  10084. Polyline.prototype.buildPath = function (ctx, shape) {
  10085. buildPath$1(ctx, shape, false);
  10086. };
  10087. return Polyline;
  10088. }(Path));
  10089. Polyline.prototype.type = 'polyline';
  10090. var Gradient = (function () {
  10091. function Gradient(colorStops) {
  10092. this.colorStops = colorStops || [];
  10093. }
  10094. Gradient.prototype.addColorStop = function (offset, color) {
  10095. this.colorStops.push({
  10096. offset: offset,
  10097. color: color
  10098. });
  10099. };
  10100. return Gradient;
  10101. }());
  10102. var LinearGradient = (function (_super) {
  10103. __extends(LinearGradient, _super);
  10104. function LinearGradient(x, y, x2, y2, colorStops, globalCoord) {
  10105. var _this = _super.call(this, colorStops) || this;
  10106. _this.x = x == null ? 0 : x;
  10107. _this.y = y == null ? 0 : y;
  10108. _this.x2 = x2 == null ? 1 : x2;
  10109. _this.y2 = y2 == null ? 0 : y2;
  10110. _this.type = 'linear';
  10111. _this.global = globalCoord || false;
  10112. return _this;
  10113. }
  10114. return LinearGradient;
  10115. }(Gradient));
  10116. var RadialGradient = (function (_super) {
  10117. __extends(RadialGradient, _super);
  10118. function RadialGradient(x, y, r, colorStops, globalCoord) {
  10119. var _this = _super.call(this, colorStops) || this;
  10120. _this.x = x == null ? 0.5 : x;
  10121. _this.y = y == null ? 0.5 : y;
  10122. _this.r = r == null ? 0.5 : r;
  10123. _this.type = 'radial';
  10124. _this.global = globalCoord || false;
  10125. return _this;
  10126. }
  10127. return RadialGradient;
  10128. }(Gradient));
  10129. var DEFAULT_TSPAN_STYLE = defaults({
  10130. strokeFirst: true,
  10131. font: DEFAULT_FONT,
  10132. x: 0,
  10133. y: 0,
  10134. textAlign: 'left',
  10135. textBaseline: 'top',
  10136. miterLimit: 2
  10137. }, DEFAULT_PATH_STYLE);
  10138. var TSpan = (function (_super) {
  10139. __extends(TSpan, _super);
  10140. function TSpan() {
  10141. return _super !== null && _super.apply(this, arguments) || this;
  10142. }
  10143. TSpan.prototype.hasStroke = function () {
  10144. var style = this.style;
  10145. var stroke = style.stroke;
  10146. return stroke != null && stroke !== 'none' && style.lineWidth > 0;
  10147. };
  10148. TSpan.prototype.hasFill = function () {
  10149. var style = this.style;
  10150. var fill = style.fill;
  10151. return fill != null && fill !== 'none';
  10152. };
  10153. TSpan.prototype.createStyle = function (obj) {
  10154. return createObject(DEFAULT_TSPAN_STYLE, obj);
  10155. };
  10156. TSpan.prototype.setBoundingRect = function (rect) {
  10157. this._rect = rect;
  10158. };
  10159. TSpan.prototype.getBoundingRect = function () {
  10160. var style = this.style;
  10161. if (!this._rect) {
  10162. var text = style.text;
  10163. text != null ? (text += '') : (text = '');
  10164. var rect = getBoundingRect(text, style.font, style.textAlign, style.textBaseline);
  10165. rect.x += style.x || 0;
  10166. rect.y += style.y || 0;
  10167. if (this.hasStroke()) {
  10168. var w = style.lineWidth;
  10169. rect.x -= w / 2;
  10170. rect.y -= w / 2;
  10171. rect.width += w;
  10172. rect.height += w;
  10173. }
  10174. this._rect = rect;
  10175. }
  10176. return this._rect;
  10177. };
  10178. TSpan.initDefaultProps = (function () {
  10179. var tspanProto = TSpan.prototype;
  10180. tspanProto.dirtyRectTolerance = 10;
  10181. })();
  10182. return TSpan;
  10183. }(Displayable));
  10184. TSpan.prototype.type = 'tspan';
  10185. function parseXML(svg) {
  10186. if (isString(svg)) {
  10187. var parser = new DOMParser();
  10188. svg = parser.parseFromString(svg, 'text/xml');
  10189. }
  10190. var svgNode = svg;
  10191. if (svgNode.nodeType === 9) {
  10192. svgNode = svgNode.firstChild;
  10193. }
  10194. while (svgNode.nodeName.toLowerCase() !== 'svg' || svgNode.nodeType !== 1) {
  10195. svgNode = svgNode.nextSibling;
  10196. }
  10197. return svgNode;
  10198. }
  10199. var nodeParsers;
  10200. var INHERITABLE_STYLE_ATTRIBUTES_MAP = {
  10201. 'fill': 'fill',
  10202. 'stroke': 'stroke',
  10203. 'stroke-width': 'lineWidth',
  10204. 'opacity': 'opacity',
  10205. 'fill-opacity': 'fillOpacity',
  10206. 'stroke-opacity': 'strokeOpacity',
  10207. 'stroke-dasharray': 'lineDash',
  10208. 'stroke-dashoffset': 'lineDashOffset',
  10209. 'stroke-linecap': 'lineCap',
  10210. 'stroke-linejoin': 'lineJoin',
  10211. 'stroke-miterlimit': 'miterLimit',
  10212. 'font-family': 'fontFamily',
  10213. 'font-size': 'fontSize',
  10214. 'font-style': 'fontStyle',
  10215. 'font-weight': 'fontWeight',
  10216. 'text-anchor': 'textAlign',
  10217. 'visibility': 'visibility',
  10218. 'display': 'display'
  10219. };
  10220. var INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS = keys(INHERITABLE_STYLE_ATTRIBUTES_MAP);
  10221. var SELF_STYLE_ATTRIBUTES_MAP = {
  10222. 'alignment-baseline': 'textBaseline',
  10223. 'stop-color': 'stopColor'
  10224. };
  10225. var SELF_STYLE_ATTRIBUTES_MAP_KEYS = keys(SELF_STYLE_ATTRIBUTES_MAP);
  10226. var SVGParser = (function () {
  10227. function SVGParser() {
  10228. this._defs = {};
  10229. this._root = null;
  10230. }
  10231. SVGParser.prototype.parse = function (xml, opt) {
  10232. opt = opt || {};
  10233. var svg = parseXML(xml);
  10234. {
  10235. if (!svg) {
  10236. throw new Error('Illegal svg');
  10237. }
  10238. }
  10239. this._defsUsePending = [];
  10240. var root = new Group();
  10241. this._root = root;
  10242. var named = [];
  10243. var viewBox = svg.getAttribute('viewBox') || '';
  10244. var width = parseFloat((svg.getAttribute('width') || opt.width));
  10245. var height = parseFloat((svg.getAttribute('height') || opt.height));
  10246. isNaN(width) && (width = null);
  10247. isNaN(height) && (height = null);
  10248. parseAttributes(svg, root, null, true, false);
  10249. var child = svg.firstChild;
  10250. while (child) {
  10251. this._parseNode(child, root, named, null, false, false);
  10252. child = child.nextSibling;
  10253. }
  10254. applyDefs(this._defs, this._defsUsePending);
  10255. this._defsUsePending = [];
  10256. var viewBoxRect;
  10257. var viewBoxTransform;
  10258. if (viewBox) {
  10259. var viewBoxArr = splitNumberSequence(viewBox);
  10260. if (viewBoxArr.length >= 4) {
  10261. viewBoxRect = {
  10262. x: parseFloat((viewBoxArr[0] || 0)),
  10263. y: parseFloat((viewBoxArr[1] || 0)),
  10264. width: parseFloat(viewBoxArr[2]),
  10265. height: parseFloat(viewBoxArr[3])
  10266. };
  10267. }
  10268. }
  10269. if (viewBoxRect && width != null && height != null) {
  10270. viewBoxTransform = makeViewBoxTransform(viewBoxRect, { x: 0, y: 0, width: width, height: height });
  10271. if (!opt.ignoreViewBox) {
  10272. var elRoot = root;
  10273. root = new Group();
  10274. root.add(elRoot);
  10275. elRoot.scaleX = elRoot.scaleY = viewBoxTransform.scale;
  10276. elRoot.x = viewBoxTransform.x;
  10277. elRoot.y = viewBoxTransform.y;
  10278. }
  10279. }
  10280. if (!opt.ignoreRootClip && width != null && height != null) {
  10281. root.setClipPath(new Rect({
  10282. shape: { x: 0, y: 0, width: width, height: height }
  10283. }));
  10284. }
  10285. return {
  10286. root: root,
  10287. width: width,
  10288. height: height,
  10289. viewBoxRect: viewBoxRect,
  10290. viewBoxTransform: viewBoxTransform,
  10291. named: named
  10292. };
  10293. };
  10294. SVGParser.prototype._parseNode = function (xmlNode, parentGroup, named, namedFrom, isInDefs, isInText) {
  10295. var nodeName = xmlNode.nodeName.toLowerCase();
  10296. var el;
  10297. var namedFromForSub = namedFrom;
  10298. if (nodeName === 'defs') {
  10299. isInDefs = true;
  10300. }
  10301. if (nodeName === 'text') {
  10302. isInText = true;
  10303. }
  10304. if (nodeName === 'defs' || nodeName === 'switch') {
  10305. el = parentGroup;
  10306. }
  10307. else {
  10308. if (!isInDefs) {
  10309. var parser_1 = nodeParsers[nodeName];
  10310. if (parser_1 && hasOwn(nodeParsers, nodeName)) {
  10311. el = parser_1.call(this, xmlNode, parentGroup);
  10312. var nameAttr = xmlNode.getAttribute('name');
  10313. if (nameAttr) {
  10314. var newNamed = {
  10315. name: nameAttr,
  10316. namedFrom: null,
  10317. svgNodeTagLower: nodeName,
  10318. el: el
  10319. };
  10320. named.push(newNamed);
  10321. if (nodeName === 'g') {
  10322. namedFromForSub = newNamed;
  10323. }
  10324. }
  10325. else if (namedFrom) {
  10326. named.push({
  10327. name: namedFrom.name,
  10328. namedFrom: namedFrom,
  10329. svgNodeTagLower: nodeName,
  10330. el: el
  10331. });
  10332. }
  10333. parentGroup.add(el);
  10334. }
  10335. }
  10336. var parser = paintServerParsers[nodeName];
  10337. if (parser && hasOwn(paintServerParsers, nodeName)) {
  10338. var def = parser.call(this, xmlNode);
  10339. var id = xmlNode.getAttribute('id');
  10340. if (id) {
  10341. this._defs[id] = def;
  10342. }
  10343. }
  10344. }
  10345. if (el && el.isGroup) {
  10346. var child = xmlNode.firstChild;
  10347. while (child) {
  10348. if (child.nodeType === 1) {
  10349. this._parseNode(child, el, named, namedFromForSub, isInDefs, isInText);
  10350. }
  10351. else if (child.nodeType === 3 && isInText) {
  10352. this._parseText(child, el);
  10353. }
  10354. child = child.nextSibling;
  10355. }
  10356. }
  10357. };
  10358. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  10359. var text = new TSpan({
  10360. style: {
  10361. text: xmlNode.textContent
  10362. },
  10363. silent: true,
  10364. x: this._textX || 0,
  10365. y: this._textY || 0
  10366. });
  10367. inheritStyle(parentGroup, text);
  10368. parseAttributes(xmlNode, text, this._defsUsePending, false, false);
  10369. applyTextAlignment(text, parentGroup);
  10370. var textStyle = text.style;
  10371. var fontSize = textStyle.fontSize;
  10372. if (fontSize && fontSize < 9) {
  10373. textStyle.fontSize = 9;
  10374. text.scaleX *= fontSize / 9;
  10375. text.scaleY *= fontSize / 9;
  10376. }
  10377. var font = (textStyle.fontSize || textStyle.fontFamily) && [
  10378. textStyle.fontStyle,
  10379. textStyle.fontWeight,
  10380. (textStyle.fontSize || 12) + 'px',
  10381. textStyle.fontFamily || 'sans-serif'
  10382. ].join(' ');
  10383. textStyle.font = font;
  10384. var rect = text.getBoundingRect();
  10385. this._textX += rect.width;
  10386. parentGroup.add(text);
  10387. return text;
  10388. };
  10389. SVGParser.internalField = (function () {
  10390. nodeParsers = {
  10391. 'g': function (xmlNode, parentGroup) {
  10392. var g = new Group();
  10393. inheritStyle(parentGroup, g);
  10394. parseAttributes(xmlNode, g, this._defsUsePending, false, false);
  10395. return g;
  10396. },
  10397. 'rect': function (xmlNode, parentGroup) {
  10398. var rect = new Rect();
  10399. inheritStyle(parentGroup, rect);
  10400. parseAttributes(xmlNode, rect, this._defsUsePending, false, false);
  10401. rect.setShape({
  10402. x: parseFloat(xmlNode.getAttribute('x') || '0'),
  10403. y: parseFloat(xmlNode.getAttribute('y') || '0'),
  10404. width: parseFloat(xmlNode.getAttribute('width') || '0'),
  10405. height: parseFloat(xmlNode.getAttribute('height') || '0')
  10406. });
  10407. rect.silent = true;
  10408. return rect;
  10409. },
  10410. 'circle': function (xmlNode, parentGroup) {
  10411. var circle = new Circle();
  10412. inheritStyle(parentGroup, circle);
  10413. parseAttributes(xmlNode, circle, this._defsUsePending, false, false);
  10414. circle.setShape({
  10415. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  10416. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  10417. r: parseFloat(xmlNode.getAttribute('r') || '0')
  10418. });
  10419. circle.silent = true;
  10420. return circle;
  10421. },
  10422. 'line': function (xmlNode, parentGroup) {
  10423. var line = new Line();
  10424. inheritStyle(parentGroup, line);
  10425. parseAttributes(xmlNode, line, this._defsUsePending, false, false);
  10426. line.setShape({
  10427. x1: parseFloat(xmlNode.getAttribute('x1') || '0'),
  10428. y1: parseFloat(xmlNode.getAttribute('y1') || '0'),
  10429. x2: parseFloat(xmlNode.getAttribute('x2') || '0'),
  10430. y2: parseFloat(xmlNode.getAttribute('y2') || '0')
  10431. });
  10432. line.silent = true;
  10433. return line;
  10434. },
  10435. 'ellipse': function (xmlNode, parentGroup) {
  10436. var ellipse = new Ellipse();
  10437. inheritStyle(parentGroup, ellipse);
  10438. parseAttributes(xmlNode, ellipse, this._defsUsePending, false, false);
  10439. ellipse.setShape({
  10440. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  10441. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  10442. rx: parseFloat(xmlNode.getAttribute('rx') || '0'),
  10443. ry: parseFloat(xmlNode.getAttribute('ry') || '0')
  10444. });
  10445. ellipse.silent = true;
  10446. return ellipse;
  10447. },
  10448. 'polygon': function (xmlNode, parentGroup) {
  10449. var pointsStr = xmlNode.getAttribute('points');
  10450. var pointsArr;
  10451. if (pointsStr) {
  10452. pointsArr = parsePoints(pointsStr);
  10453. }
  10454. var polygon = new Polygon({
  10455. shape: {
  10456. points: pointsArr || []
  10457. },
  10458. silent: true
  10459. });
  10460. inheritStyle(parentGroup, polygon);
  10461. parseAttributes(xmlNode, polygon, this._defsUsePending, false, false);
  10462. return polygon;
  10463. },
  10464. 'polyline': function (xmlNode, parentGroup) {
  10465. var pointsStr = xmlNode.getAttribute('points');
  10466. var pointsArr;
  10467. if (pointsStr) {
  10468. pointsArr = parsePoints(pointsStr);
  10469. }
  10470. var polyline = new Polyline({
  10471. shape: {
  10472. points: pointsArr || []
  10473. },
  10474. silent: true
  10475. });
  10476. inheritStyle(parentGroup, polyline);
  10477. parseAttributes(xmlNode, polyline, this._defsUsePending, false, false);
  10478. return polyline;
  10479. },
  10480. 'image': function (xmlNode, parentGroup) {
  10481. var img = new ZRImage();
  10482. inheritStyle(parentGroup, img);
  10483. parseAttributes(xmlNode, img, this._defsUsePending, false, false);
  10484. img.setStyle({
  10485. image: xmlNode.getAttribute('xlink:href') || xmlNode.getAttribute('href'),
  10486. x: +xmlNode.getAttribute('x'),
  10487. y: +xmlNode.getAttribute('y'),
  10488. width: +xmlNode.getAttribute('width'),
  10489. height: +xmlNode.getAttribute('height')
  10490. });
  10491. img.silent = true;
  10492. return img;
  10493. },
  10494. 'text': function (xmlNode, parentGroup) {
  10495. var x = xmlNode.getAttribute('x') || '0';
  10496. var y = xmlNode.getAttribute('y') || '0';
  10497. var dx = xmlNode.getAttribute('dx') || '0';
  10498. var dy = xmlNode.getAttribute('dy') || '0';
  10499. this._textX = parseFloat(x) + parseFloat(dx);
  10500. this._textY = parseFloat(y) + parseFloat(dy);
  10501. var g = new Group();
  10502. inheritStyle(parentGroup, g);
  10503. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  10504. return g;
  10505. },
  10506. 'tspan': function (xmlNode, parentGroup) {
  10507. var x = xmlNode.getAttribute('x');
  10508. var y = xmlNode.getAttribute('y');
  10509. if (x != null) {
  10510. this._textX = parseFloat(x);
  10511. }
  10512. if (y != null) {
  10513. this._textY = parseFloat(y);
  10514. }
  10515. var dx = xmlNode.getAttribute('dx') || '0';
  10516. var dy = xmlNode.getAttribute('dy') || '0';
  10517. var g = new Group();
  10518. inheritStyle(parentGroup, g);
  10519. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  10520. this._textX += parseFloat(dx);
  10521. this._textY += parseFloat(dy);
  10522. return g;
  10523. },
  10524. 'path': function (xmlNode, parentGroup) {
  10525. var d = xmlNode.getAttribute('d') || '';
  10526. var path = createFromString(d);
  10527. inheritStyle(parentGroup, path);
  10528. parseAttributes(xmlNode, path, this._defsUsePending, false, false);
  10529. path.silent = true;
  10530. return path;
  10531. }
  10532. };
  10533. })();
  10534. return SVGParser;
  10535. }());
  10536. var paintServerParsers = {
  10537. 'lineargradient': function (xmlNode) {
  10538. var x1 = parseInt(xmlNode.getAttribute('x1') || '0', 10);
  10539. var y1 = parseInt(xmlNode.getAttribute('y1') || '0', 10);
  10540. var x2 = parseInt(xmlNode.getAttribute('x2') || '10', 10);
  10541. var y2 = parseInt(xmlNode.getAttribute('y2') || '0', 10);
  10542. var gradient = new LinearGradient(x1, y1, x2, y2);
  10543. parsePaintServerUnit(xmlNode, gradient);
  10544. parseGradientColorStops(xmlNode, gradient);
  10545. return gradient;
  10546. },
  10547. 'radialgradient': function (xmlNode) {
  10548. var cx = parseInt(xmlNode.getAttribute('cx') || '0', 10);
  10549. var cy = parseInt(xmlNode.getAttribute('cy') || '0', 10);
  10550. var r = parseInt(xmlNode.getAttribute('r') || '0', 10);
  10551. var gradient = new RadialGradient(cx, cy, r);
  10552. parsePaintServerUnit(xmlNode, gradient);
  10553. parseGradientColorStops(xmlNode, gradient);
  10554. return gradient;
  10555. }
  10556. };
  10557. function parsePaintServerUnit(xmlNode, gradient) {
  10558. var gradientUnits = xmlNode.getAttribute('gradientUnits');
  10559. if (gradientUnits === 'userSpaceOnUse') {
  10560. gradient.global = true;
  10561. }
  10562. }
  10563. function parseGradientColorStops(xmlNode, gradient) {
  10564. var stop = xmlNode.firstChild;
  10565. while (stop) {
  10566. if (stop.nodeType === 1
  10567. && stop.nodeName.toLocaleLowerCase() === 'stop') {
  10568. var offsetStr = stop.getAttribute('offset');
  10569. var offset = void 0;
  10570. if (offsetStr && offsetStr.indexOf('%') > 0) {
  10571. offset = parseInt(offsetStr, 10) / 100;
  10572. }
  10573. else if (offsetStr) {
  10574. offset = parseFloat(offsetStr);
  10575. }
  10576. else {
  10577. offset = 0;
  10578. }
  10579. var styleVals = {};
  10580. parseInlineStyle(stop, styleVals, styleVals);
  10581. var stopColor = styleVals.stopColor
  10582. || stop.getAttribute('stop-color')
  10583. || '#000000';
  10584. gradient.colorStops.push({
  10585. offset: offset,
  10586. color: stopColor
  10587. });
  10588. }
  10589. stop = stop.nextSibling;
  10590. }
  10591. }
  10592. function inheritStyle(parent, child) {
  10593. if (parent && parent.__inheritedStyle) {
  10594. if (!child.__inheritedStyle) {
  10595. child.__inheritedStyle = {};
  10596. }
  10597. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  10598. }
  10599. }
  10600. function parsePoints(pointsString) {
  10601. var list = splitNumberSequence(pointsString);
  10602. var points = [];
  10603. for (var i = 0; i < list.length; i += 2) {
  10604. var x = parseFloat(list[i]);
  10605. var y = parseFloat(list[i + 1]);
  10606. points.push([x, y]);
  10607. }
  10608. return points;
  10609. }
  10610. function parseAttributes(xmlNode, el, defsUsePending, onlyInlineStyle, isTextGroup) {
  10611. var disp = el;
  10612. var inheritedStyle = disp.__inheritedStyle = disp.__inheritedStyle || {};
  10613. var selfStyle = {};
  10614. if (xmlNode.nodeType === 1) {
  10615. parseTransformAttribute(xmlNode, el);
  10616. parseInlineStyle(xmlNode, inheritedStyle, selfStyle);
  10617. if (!onlyInlineStyle) {
  10618. parseAttributeStyle(xmlNode, inheritedStyle, selfStyle);
  10619. }
  10620. }
  10621. disp.style = disp.style || {};
  10622. if (inheritedStyle.fill != null) {
  10623. disp.style.fill = getFillStrokeStyle(disp, 'fill', inheritedStyle.fill, defsUsePending);
  10624. }
  10625. if (inheritedStyle.stroke != null) {
  10626. disp.style.stroke = getFillStrokeStyle(disp, 'stroke', inheritedStyle.stroke, defsUsePending);
  10627. }
  10628. each([
  10629. 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'
  10630. ], function (propName) {
  10631. if (inheritedStyle[propName] != null) {
  10632. disp.style[propName] = parseFloat(inheritedStyle[propName]);
  10633. }
  10634. });
  10635. each([
  10636. 'lineDashOffset', 'lineCap', 'lineJoin', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign'
  10637. ], function (propName) {
  10638. if (inheritedStyle[propName] != null) {
  10639. disp.style[propName] = inheritedStyle[propName];
  10640. }
  10641. });
  10642. if (isTextGroup) {
  10643. disp.__selfStyle = selfStyle;
  10644. }
  10645. if (inheritedStyle.lineDash) {
  10646. disp.style.lineDash = map(splitNumberSequence(inheritedStyle.lineDash), function (str) {
  10647. return parseFloat(str);
  10648. });
  10649. }
  10650. if (inheritedStyle.visibility === 'hidden' || inheritedStyle.visibility === 'collapse') {
  10651. disp.invisible = true;
  10652. }
  10653. if (inheritedStyle.display === 'none') {
  10654. disp.ignore = true;
  10655. }
  10656. }
  10657. function applyTextAlignment(text, parentGroup) {
  10658. var parentSelfStyle = parentGroup.__selfStyle;
  10659. if (parentSelfStyle) {
  10660. var textBaseline = parentSelfStyle.textBaseline;
  10661. var zrTextBaseline = textBaseline;
  10662. if (!textBaseline || textBaseline === 'auto') {
  10663. zrTextBaseline = 'alphabetic';
  10664. }
  10665. else if (textBaseline === 'baseline') {
  10666. zrTextBaseline = 'alphabetic';
  10667. }
  10668. else if (textBaseline === 'before-edge' || textBaseline === 'text-before-edge') {
  10669. zrTextBaseline = 'top';
  10670. }
  10671. else if (textBaseline === 'after-edge' || textBaseline === 'text-after-edge') {
  10672. zrTextBaseline = 'bottom';
  10673. }
  10674. else if (textBaseline === 'central' || textBaseline === 'mathematical') {
  10675. zrTextBaseline = 'middle';
  10676. }
  10677. text.style.textBaseline = zrTextBaseline;
  10678. }
  10679. var parentInheritedStyle = parentGroup.__inheritedStyle;
  10680. if (parentInheritedStyle) {
  10681. var textAlign = parentInheritedStyle.textAlign;
  10682. var zrTextAlign = textAlign;
  10683. if (textAlign) {
  10684. if (textAlign === 'middle') {
  10685. zrTextAlign = 'center';
  10686. }
  10687. text.style.textAlign = zrTextAlign;
  10688. }
  10689. }
  10690. }
  10691. var urlRegex = /^url\(\s*#(.*?)\)/;
  10692. function getFillStrokeStyle(el, method, str, defsUsePending) {
  10693. var urlMatch = str && str.match(urlRegex);
  10694. if (urlMatch) {
  10695. var url = trim(urlMatch[1]);
  10696. defsUsePending.push([el, method, url]);
  10697. return;
  10698. }
  10699. if (str === 'none') {
  10700. str = null;
  10701. }
  10702. return str;
  10703. }
  10704. function applyDefs(defs, defsUsePending) {
  10705. for (var i = 0; i < defsUsePending.length; i++) {
  10706. var item = defsUsePending[i];
  10707. item[0].style[item[1]] = defs[item[2]];
  10708. }
  10709. }
  10710. var numberReg$1 = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  10711. function splitNumberSequence(rawStr) {
  10712. return rawStr.match(numberReg$1) || [];
  10713. }
  10714. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.eE,]*)\)/g;
  10715. var DEGREE_TO_ANGLE = Math.PI / 180;
  10716. function parseTransformAttribute(xmlNode, node) {
  10717. var transform = xmlNode.getAttribute('transform');
  10718. if (transform) {
  10719. transform = transform.replace(/,/g, ' ');
  10720. var transformOps_1 = [];
  10721. var mt = null;
  10722. transform.replace(transformRegex, function (str, type, value) {
  10723. transformOps_1.push(type, value);
  10724. return '';
  10725. });
  10726. for (var i = transformOps_1.length - 1; i > 0; i -= 2) {
  10727. var value = transformOps_1[i];
  10728. var type = transformOps_1[i - 1];
  10729. var valueArr = splitNumberSequence(value);
  10730. mt = mt || create$1();
  10731. switch (type) {
  10732. case 'translate':
  10733. translate(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || '0')]);
  10734. break;
  10735. case 'scale':
  10736. scale$1(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || valueArr[0])]);
  10737. break;
  10738. case 'rotate':
  10739. rotate(mt, mt, -parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10740. break;
  10741. case 'skewX':
  10742. var sx = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10743. mul$1(mt, [1, 0, sx, 1, 0, 0], mt);
  10744. break;
  10745. case 'skewY':
  10746. var sy = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10747. mul$1(mt, [1, sy, 0, 1, 0, 0], mt);
  10748. break;
  10749. case 'matrix':
  10750. mt[0] = parseFloat(valueArr[0]);
  10751. mt[1] = parseFloat(valueArr[1]);
  10752. mt[2] = parseFloat(valueArr[2]);
  10753. mt[3] = parseFloat(valueArr[3]);
  10754. mt[4] = parseFloat(valueArr[4]);
  10755. mt[5] = parseFloat(valueArr[5]);
  10756. break;
  10757. }
  10758. }
  10759. node.setLocalTransform(mt);
  10760. }
  10761. }
  10762. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  10763. function parseInlineStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  10764. var style = xmlNode.getAttribute('style');
  10765. if (!style) {
  10766. return;
  10767. }
  10768. styleRegex.lastIndex = 0;
  10769. var styleRegResult;
  10770. while ((styleRegResult = styleRegex.exec(style)) != null) {
  10771. var svgStlAttr = styleRegResult[1];
  10772. var zrInheritableStlAttr = hasOwn(INHERITABLE_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  10773. ? INHERITABLE_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  10774. : null;
  10775. if (zrInheritableStlAttr) {
  10776. inheritableStyleResult[zrInheritableStlAttr] = styleRegResult[2];
  10777. }
  10778. var zrSelfStlAttr = hasOwn(SELF_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  10779. ? SELF_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  10780. : null;
  10781. if (zrSelfStlAttr) {
  10782. selfStyleResult[zrSelfStlAttr] = styleRegResult[2];
  10783. }
  10784. }
  10785. }
  10786. function parseAttributeStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  10787. for (var i = 0; i < INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  10788. var svgAttrName = INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS[i];
  10789. var attrValue = xmlNode.getAttribute(svgAttrName);
  10790. if (attrValue != null) {
  10791. inheritableStyleResult[INHERITABLE_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  10792. }
  10793. }
  10794. for (var i = 0; i < SELF_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  10795. var svgAttrName = SELF_STYLE_ATTRIBUTES_MAP_KEYS[i];
  10796. var attrValue = xmlNode.getAttribute(svgAttrName);
  10797. if (attrValue != null) {
  10798. selfStyleResult[SELF_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  10799. }
  10800. }
  10801. }
  10802. function makeViewBoxTransform(viewBoxRect, boundingRect) {
  10803. var scaleX = boundingRect.width / viewBoxRect.width;
  10804. var scaleY = boundingRect.height / viewBoxRect.height;
  10805. var scale = Math.min(scaleX, scaleY);
  10806. return {
  10807. scale: scale,
  10808. x: -(viewBoxRect.x + viewBoxRect.width / 2) * scale + (boundingRect.x + boundingRect.width / 2),
  10809. y: -(viewBoxRect.y + viewBoxRect.height / 2) * scale + (boundingRect.y + boundingRect.height / 2)
  10810. };
  10811. }
  10812. function parseSVG(xml, opt) {
  10813. var parser = new SVGParser();
  10814. return parser.parse(xml, opt);
  10815. }
  10816. var PI$2 = Math.PI;
  10817. var PI2$5 = PI$2 * 2;
  10818. var mathSin$3 = Math.sin;
  10819. var mathCos$3 = Math.cos;
  10820. var mathACos = Math.acos;
  10821. var mathATan2 = Math.atan2;
  10822. var mathAbs$1 = Math.abs;
  10823. var mathSqrt$3 = Math.sqrt;
  10824. var mathMax$3 = Math.max;
  10825. var mathMin$3 = Math.min;
  10826. var e = 1e-4;
  10827. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  10828. var dx10 = x1 - x0;
  10829. var dy10 = y1 - y0;
  10830. var dx32 = x3 - x2;
  10831. var dy32 = y3 - y2;
  10832. var t = dy32 * dx10 - dx32 * dy10;
  10833. if (t * t < e) {
  10834. return;
  10835. }
  10836. t = (dx32 * (y0 - y2) - dy32 * (x0 - x2)) / t;
  10837. return [x0 + t * dx10, y0 + t * dy10];
  10838. }
  10839. function computeCornerTangents(x0, y0, x1, y1, radius, cr, clockwise) {
  10840. var x01 = x0 - x1;
  10841. var y01 = y0 - y1;
  10842. var lo = (clockwise ? cr : -cr) / mathSqrt$3(x01 * x01 + y01 * y01);
  10843. var ox = lo * y01;
  10844. var oy = -lo * x01;
  10845. var x11 = x0 + ox;
  10846. var y11 = y0 + oy;
  10847. var x10 = x1 + ox;
  10848. var y10 = y1 + oy;
  10849. var x00 = (x11 + x10) / 2;
  10850. var y00 = (y11 + y10) / 2;
  10851. var dx = x10 - x11;
  10852. var dy = y10 - y11;
  10853. var d2 = dx * dx + dy * dy;
  10854. var r = radius - cr;
  10855. var s = x11 * y10 - x10 * y11;
  10856. var d = (dy < 0 ? -1 : 1) * mathSqrt$3(mathMax$3(0, r * r * d2 - s * s));
  10857. var cx0 = (s * dy - dx * d) / d2;
  10858. var cy0 = (-s * dx - dy * d) / d2;
  10859. var cx1 = (s * dy + dx * d) / d2;
  10860. var cy1 = (-s * dx + dy * d) / d2;
  10861. var dx0 = cx0 - x00;
  10862. var dy0 = cy0 - y00;
  10863. var dx1 = cx1 - x00;
  10864. var dy1 = cy1 - y00;
  10865. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
  10866. cx0 = cx1;
  10867. cy0 = cy1;
  10868. }
  10869. return {
  10870. cx: cx0,
  10871. cy: cy0,
  10872. x0: -ox,
  10873. y0: -oy,
  10874. x1: cx0 * (radius / r - 1),
  10875. y1: cy0 * (radius / r - 1)
  10876. };
  10877. }
  10878. function normalizeCornerRadius(cr) {
  10879. var arr;
  10880. if (isArray(cr)) {
  10881. var len = cr.length;
  10882. if (!len) {
  10883. return cr;
  10884. }
  10885. if (len === 1) {
  10886. arr = [cr[0], cr[0], 0, 0];
  10887. }
  10888. else if (len === 2) {
  10889. arr = [cr[0], cr[0], cr[1], cr[1]];
  10890. }
  10891. else if (len === 3) {
  10892. arr = cr.concat(cr[2]);
  10893. }
  10894. else {
  10895. arr = cr;
  10896. }
  10897. }
  10898. else {
  10899. arr = [cr, cr, cr, cr];
  10900. }
  10901. return arr;
  10902. }
  10903. function buildPath$2(ctx, shape) {
  10904. var _a;
  10905. var radius = mathMax$3(shape.r, 0);
  10906. var innerRadius = mathMax$3(shape.r0 || 0, 0);
  10907. var hasRadius = radius > 0;
  10908. var hasInnerRadius = innerRadius > 0;
  10909. if (!hasRadius && !hasInnerRadius) {
  10910. return;
  10911. }
  10912. if (!hasRadius) {
  10913. radius = innerRadius;
  10914. innerRadius = 0;
  10915. }
  10916. if (innerRadius > radius) {
  10917. var tmp = radius;
  10918. radius = innerRadius;
  10919. innerRadius = tmp;
  10920. }
  10921. var startAngle = shape.startAngle, endAngle = shape.endAngle;
  10922. if (isNaN(startAngle) || isNaN(endAngle)) {
  10923. return;
  10924. }
  10925. var cx = shape.cx, cy = shape.cy;
  10926. var clockwise = !!shape.clockwise;
  10927. var arc = mathAbs$1(endAngle - startAngle);
  10928. var mod = arc > PI2$5 && arc % PI2$5;
  10929. mod > e && (arc = mod);
  10930. if (!(radius > e)) {
  10931. ctx.moveTo(cx, cy);
  10932. }
  10933. else if (arc > PI2$5 - e) {
  10934. ctx.moveTo(cx + radius * mathCos$3(startAngle), cy + radius * mathSin$3(startAngle));
  10935. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  10936. if (innerRadius > e) {
  10937. ctx.moveTo(cx + innerRadius * mathCos$3(endAngle), cy + innerRadius * mathSin$3(endAngle));
  10938. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  10939. }
  10940. }
  10941. else {
  10942. var icrStart = void 0;
  10943. var icrEnd = void 0;
  10944. var ocrStart = void 0;
  10945. var ocrEnd = void 0;
  10946. var ocrs = void 0;
  10947. var ocre = void 0;
  10948. var icrs = void 0;
  10949. var icre = void 0;
  10950. var ocrMax = void 0;
  10951. var icrMax = void 0;
  10952. var limitedOcrMax = void 0;
  10953. var limitedIcrMax = void 0;
  10954. var xre = void 0;
  10955. var yre = void 0;
  10956. var xirs = void 0;
  10957. var yirs = void 0;
  10958. var xrs = radius * mathCos$3(startAngle);
  10959. var yrs = radius * mathSin$3(startAngle);
  10960. var xire = innerRadius * mathCos$3(endAngle);
  10961. var yire = innerRadius * mathSin$3(endAngle);
  10962. var hasArc = arc > e;
  10963. if (hasArc) {
  10964. var cornerRadius = shape.cornerRadius;
  10965. if (cornerRadius) {
  10966. _a = normalizeCornerRadius(cornerRadius), icrStart = _a[0], icrEnd = _a[1], ocrStart = _a[2], ocrEnd = _a[3];
  10967. }
  10968. var halfRd = mathAbs$1(radius - innerRadius) / 2;
  10969. ocrs = mathMin$3(halfRd, ocrStart);
  10970. ocre = mathMin$3(halfRd, ocrEnd);
  10971. icrs = mathMin$3(halfRd, icrStart);
  10972. icre = mathMin$3(halfRd, icrEnd);
  10973. limitedOcrMax = ocrMax = mathMax$3(ocrs, ocre);
  10974. limitedIcrMax = icrMax = mathMax$3(icrs, icre);
  10975. if (ocrMax > e || icrMax > e) {
  10976. xre = radius * mathCos$3(endAngle);
  10977. yre = radius * mathSin$3(endAngle);
  10978. xirs = innerRadius * mathCos$3(startAngle);
  10979. yirs = innerRadius * mathSin$3(startAngle);
  10980. if (arc < PI$2) {
  10981. var it_1 = intersect(xrs, yrs, xirs, yirs, xre, yre, xire, yire);
  10982. if (it_1) {
  10983. var x0 = xrs - it_1[0];
  10984. var y0 = yrs - it_1[1];
  10985. var x1 = xre - it_1[0];
  10986. var y1 = yre - it_1[1];
  10987. var a = 1 / mathSin$3(mathACos((x0 * x1 + y0 * y1) / (mathSqrt$3(x0 * x0 + y0 * y0) * mathSqrt$3(x1 * x1 + y1 * y1))) / 2);
  10988. var b = mathSqrt$3(it_1[0] * it_1[0] + it_1[1] * it_1[1]);
  10989. limitedOcrMax = mathMin$3(ocrMax, (radius - b) / (a + 1));
  10990. limitedIcrMax = mathMin$3(icrMax, (innerRadius - b) / (a - 1));
  10991. }
  10992. }
  10993. }
  10994. }
  10995. if (!hasArc) {
  10996. ctx.moveTo(cx + xrs, cy + yrs);
  10997. }
  10998. else if (limitedOcrMax > e) {
  10999. var crStart = mathMin$3(ocrStart, limitedOcrMax);
  11000. var crEnd = mathMin$3(ocrEnd, limitedOcrMax);
  11001. var ct0 = computeCornerTangents(xirs, yirs, xrs, yrs, radius, crStart, clockwise);
  11002. var ct1 = computeCornerTangents(xre, yre, xire, yire, radius, crEnd, clockwise);
  11003. ctx.moveTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  11004. if (limitedOcrMax < ocrMax && crStart === crEnd) {
  11005. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedOcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11006. }
  11007. else {
  11008. crStart > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crStart, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  11009. ctx.arc(cx, cy, radius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), !clockwise);
  11010. crEnd > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crEnd, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11011. }
  11012. }
  11013. else {
  11014. ctx.moveTo(cx + xrs, cy + yrs);
  11015. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  11016. }
  11017. if (!(innerRadius > e) || !hasArc) {
  11018. ctx.lineTo(cx + xire, cy + yire);
  11019. }
  11020. else if (limitedIcrMax > e) {
  11021. var crStart = mathMin$3(icrStart, limitedIcrMax);
  11022. var crEnd = mathMin$3(icrEnd, limitedIcrMax);
  11023. var ct0 = computeCornerTangents(xire, yire, xre, yre, innerRadius, -crEnd, clockwise);
  11024. var ct1 = computeCornerTangents(xrs, yrs, xirs, yirs, innerRadius, -crStart, clockwise);
  11025. ctx.lineTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  11026. if (limitedIcrMax < icrMax && crStart === crEnd) {
  11027. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedIcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11028. }
  11029. else {
  11030. crEnd > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crEnd, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  11031. ctx.arc(cx, cy, innerRadius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), clockwise);
  11032. crStart > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crStart, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11033. }
  11034. }
  11035. else {
  11036. ctx.lineTo(cx + xire, cy + yire);
  11037. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  11038. }
  11039. }
  11040. ctx.closePath();
  11041. }
  11042. var SectorShape = (function () {
  11043. function SectorShape() {
  11044. this.cx = 0;
  11045. this.cy = 0;
  11046. this.r0 = 0;
  11047. this.r = 0;
  11048. this.startAngle = 0;
  11049. this.endAngle = Math.PI * 2;
  11050. this.clockwise = true;
  11051. this.cornerRadius = 0;
  11052. }
  11053. return SectorShape;
  11054. }());
  11055. var Sector = (function (_super) {
  11056. __extends(Sector, _super);
  11057. function Sector(opts) {
  11058. return _super.call(this, opts) || this;
  11059. }
  11060. Sector.prototype.getDefaultShape = function () {
  11061. return new SectorShape();
  11062. };
  11063. Sector.prototype.buildPath = function (ctx, shape) {
  11064. buildPath$2(ctx, shape);
  11065. };
  11066. Sector.prototype.isZeroArea = function () {
  11067. return this.shape.startAngle === this.shape.endAngle
  11068. || this.shape.r === this.shape.r0;
  11069. };
  11070. return Sector;
  11071. }(Path));
  11072. Sector.prototype.type = 'sector';
  11073. var CMD$3 = PathProxy.CMD;
  11074. function aroundEqual(a, b) {
  11075. return Math.abs(a - b) < 1e-5;
  11076. }
  11077. function pathToBezierCurves(path) {
  11078. var data = path.data;
  11079. var len = path.len();
  11080. var bezierArrayGroups = [];
  11081. var currentSubpath;
  11082. var xi = 0;
  11083. var yi = 0;
  11084. var x0 = 0;
  11085. var y0 = 0;
  11086. function createNewSubpath(x, y) {
  11087. if (currentSubpath && currentSubpath.length > 2) {
  11088. bezierArrayGroups.push(currentSubpath);
  11089. }
  11090. currentSubpath = [x, y];
  11091. }
  11092. function addLine(x0, y0, x1, y1) {
  11093. if (!(aroundEqual(x0, x1) && aroundEqual(y0, y1))) {
  11094. currentSubpath.push(x0, y0, x1, y1, x1, y1);
  11095. }
  11096. }
  11097. function addArc(startAngle, endAngle, cx, cy, rx, ry) {
  11098. var delta = Math.abs(endAngle - startAngle);
  11099. var len = Math.tan(delta / 4) * 4 / 3;
  11100. var dir = endAngle < startAngle ? -1 : 1;
  11101. var c1 = Math.cos(startAngle);
  11102. var s1 = Math.sin(startAngle);
  11103. var c2 = Math.cos(endAngle);
  11104. var s2 = Math.sin(endAngle);
  11105. var x1 = c1 * rx + cx;
  11106. var y1 = s1 * ry + cy;
  11107. var x4 = c2 * rx + cx;
  11108. var y4 = s2 * ry + cy;
  11109. var hx = rx * len * dir;
  11110. var hy = ry * len * dir;
  11111. currentSubpath.push(x1 - hx * s1, y1 + hy * c1, x4 + hx * s2, y4 - hy * c2, x4, y4);
  11112. }
  11113. var x1;
  11114. var y1;
  11115. var x2;
  11116. var y2;
  11117. for (var i = 0; i < len;) {
  11118. var cmd = data[i++];
  11119. var isFirst = i === 1;
  11120. if (isFirst) {
  11121. xi = data[i];
  11122. yi = data[i + 1];
  11123. x0 = xi;
  11124. y0 = yi;
  11125. if (cmd === CMD$3.L || cmd === CMD$3.C || cmd === CMD$3.Q) {
  11126. currentSubpath = [x0, y0];
  11127. }
  11128. }
  11129. switch (cmd) {
  11130. case CMD$3.M:
  11131. xi = x0 = data[i++];
  11132. yi = y0 = data[i++];
  11133. createNewSubpath(x0, y0);
  11134. break;
  11135. case CMD$3.L:
  11136. x1 = data[i++];
  11137. y1 = data[i++];
  11138. addLine(xi, yi, x1, y1);
  11139. xi = x1;
  11140. yi = y1;
  11141. break;
  11142. case CMD$3.C:
  11143. currentSubpath.push(data[i++], data[i++], data[i++], data[i++], xi = data[i++], yi = data[i++]);
  11144. break;
  11145. case CMD$3.Q:
  11146. x1 = data[i++];
  11147. y1 = data[i++];
  11148. x2 = data[i++];
  11149. y2 = data[i++];
  11150. currentSubpath.push(xi + 2 / 3 * (x1 - xi), yi + 2 / 3 * (y1 - yi), x2 + 2 / 3 * (x1 - x2), y2 + 2 / 3 * (y1 - y2), x2, y2);
  11151. xi = x2;
  11152. yi = y2;
  11153. break;
  11154. case CMD$3.A:
  11155. var cx = data[i++];
  11156. var cy = data[i++];
  11157. var rx = data[i++];
  11158. var ry = data[i++];
  11159. var startAngle = data[i++];
  11160. var endAngle = data[i++] + startAngle;
  11161. i += 1;
  11162. var anticlockwise = !data[i++];
  11163. x1 = Math.cos(startAngle) * rx + cx;
  11164. y1 = Math.sin(startAngle) * ry + cy;
  11165. if (isFirst) {
  11166. x0 = x1;
  11167. y0 = y1;
  11168. createNewSubpath(x0, y0);
  11169. }
  11170. else {
  11171. addLine(xi, yi, x1, y1);
  11172. }
  11173. xi = Math.cos(endAngle) * rx + cx;
  11174. yi = Math.sin(endAngle) * ry + cy;
  11175. var step = (anticlockwise ? -1 : 1) * Math.PI / 2;
  11176. for (var angle = startAngle; anticlockwise ? angle > endAngle : angle < endAngle; angle += step) {
  11177. var nextAngle = anticlockwise ? Math.max(angle + step, endAngle)
  11178. : Math.min(angle + step, endAngle);
  11179. addArc(angle, nextAngle, cx, cy, rx, ry);
  11180. }
  11181. break;
  11182. case CMD$3.R:
  11183. x0 = xi = data[i++];
  11184. y0 = yi = data[i++];
  11185. x1 = x0 + data[i++];
  11186. y1 = y0 + data[i++];
  11187. createNewSubpath(x1, y0);
  11188. addLine(x1, y0, x1, y1);
  11189. addLine(x1, y1, x0, y1);
  11190. addLine(x0, y1, x0, y0);
  11191. addLine(x0, y0, x1, y0);
  11192. break;
  11193. case CMD$3.Z:
  11194. currentSubpath && addLine(xi, yi, x0, y0);
  11195. xi = x0;
  11196. yi = y0;
  11197. break;
  11198. }
  11199. }
  11200. if (currentSubpath && currentSubpath.length > 2) {
  11201. bezierArrayGroups.push(currentSubpath);
  11202. }
  11203. return bezierArrayGroups;
  11204. }
  11205. function adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, out, scale) {
  11206. if (aroundEqual(x0, x1) && aroundEqual(y0, y1) && aroundEqual(x2, x3) && aroundEqual(y2, y3)) {
  11207. out.push(x3, y3);
  11208. return;
  11209. }
  11210. var PIXEL_DISTANCE = 2 / scale;
  11211. var PIXEL_DISTANCE_SQR = PIXEL_DISTANCE * PIXEL_DISTANCE;
  11212. var dx = x3 - x0;
  11213. var dy = y3 - y0;
  11214. var d = Math.sqrt(dx * dx + dy * dy);
  11215. dx /= d;
  11216. dy /= d;
  11217. var dx1 = x1 - x0;
  11218. var dy1 = y1 - y0;
  11219. var dx2 = x2 - x3;
  11220. var dy2 = y2 - y3;
  11221. var cp1LenSqr = dx1 * dx1 + dy1 * dy1;
  11222. var cp2LenSqr = dx2 * dx2 + dy2 * dy2;
  11223. if (cp1LenSqr < PIXEL_DISTANCE_SQR && cp2LenSqr < PIXEL_DISTANCE_SQR) {
  11224. out.push(x3, y3);
  11225. return;
  11226. }
  11227. var projLen1 = dx * dx1 + dy * dy1;
  11228. var projLen2 = -dx * dx2 - dy * dy2;
  11229. var d1Sqr = cp1LenSqr - projLen1 * projLen1;
  11230. var d2Sqr = cp2LenSqr - projLen2 * projLen2;
  11231. if (d1Sqr < PIXEL_DISTANCE_SQR && projLen1 >= 0
  11232. && d2Sqr < PIXEL_DISTANCE_SQR && projLen2 >= 0) {
  11233. out.push(x3, y3);
  11234. return;
  11235. }
  11236. var tmpSegX = [];
  11237. var tmpSegY = [];
  11238. cubicSubdivide(x0, x1, x2, x3, 0.5, tmpSegX);
  11239. cubicSubdivide(y0, y1, y2, y3, 0.5, tmpSegY);
  11240. adpativeBezier(tmpSegX[0], tmpSegY[0], tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], tmpSegX[3], tmpSegY[3], out, scale);
  11241. adpativeBezier(tmpSegX[4], tmpSegY[4], tmpSegX[5], tmpSegY[5], tmpSegX[6], tmpSegY[6], tmpSegX[7], tmpSegY[7], out, scale);
  11242. }
  11243. function pathToPolygons(path, scale) {
  11244. var bezierArrayGroups = pathToBezierCurves(path);
  11245. var polygons = [];
  11246. scale = scale || 1;
  11247. for (var i = 0; i < bezierArrayGroups.length; i++) {
  11248. var beziers = bezierArrayGroups[i];
  11249. var polygon = [];
  11250. var x0 = beziers[0];
  11251. var y0 = beziers[1];
  11252. polygon.push(x0, y0);
  11253. for (var k = 2; k < beziers.length;) {
  11254. var x1 = beziers[k++];
  11255. var y1 = beziers[k++];
  11256. var x2 = beziers[k++];
  11257. var y2 = beziers[k++];
  11258. var x3 = beziers[k++];
  11259. var y3 = beziers[k++];
  11260. adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, polygon, scale);
  11261. x0 = x3;
  11262. y0 = y3;
  11263. }
  11264. polygons.push(polygon);
  11265. }
  11266. return polygons;
  11267. }
  11268. function getDividingGrids(dimSize, rowDim, count) {
  11269. var rowSize = dimSize[rowDim];
  11270. var columnSize = dimSize[1 - rowDim];
  11271. var ratio = Math.abs(rowSize / columnSize);
  11272. var rowCount = Math.ceil(Math.sqrt(ratio * count));
  11273. var columnCount = Math.floor(count / rowCount);
  11274. if (columnCount === 0) {
  11275. columnCount = 1;
  11276. rowCount = count;
  11277. }
  11278. var grids = [];
  11279. for (var i = 0; i < rowCount; i++) {
  11280. grids.push(columnCount);
  11281. }
  11282. var currentCount = rowCount * columnCount;
  11283. var remained = count - currentCount;
  11284. if (remained > 0) {
  11285. for (var i = 0; i < remained; i++) {
  11286. grids[i % rowCount] += 1;
  11287. }
  11288. }
  11289. return grids;
  11290. }
  11291. function divideSector(sectorShape, count, outShapes) {
  11292. var r0 = sectorShape.r0;
  11293. var r = sectorShape.r;
  11294. var startAngle = sectorShape.startAngle;
  11295. var endAngle = sectorShape.endAngle;
  11296. var angle = Math.abs(endAngle - startAngle);
  11297. var arcLen = angle * r;
  11298. var deltaR = r - r0;
  11299. var isAngleRow = arcLen > Math.abs(deltaR);
  11300. var grids = getDividingGrids([arcLen, deltaR], isAngleRow ? 0 : 1, count);
  11301. var rowSize = (isAngleRow ? angle : deltaR) / grids.length;
  11302. for (var row = 0; row < grids.length; row++) {
  11303. var columnSize = (isAngleRow ? deltaR : angle) / grids[row];
  11304. for (var column = 0; column < grids[row]; column++) {
  11305. var newShape = {};
  11306. if (isAngleRow) {
  11307. newShape.startAngle = startAngle + rowSize * row;
  11308. newShape.endAngle = startAngle + rowSize * (row + 1);
  11309. newShape.r0 = r0 + columnSize * column;
  11310. newShape.r = r0 + columnSize * (column + 1);
  11311. }
  11312. else {
  11313. newShape.startAngle = startAngle + columnSize * column;
  11314. newShape.endAngle = startAngle + columnSize * (column + 1);
  11315. newShape.r0 = r0 + rowSize * row;
  11316. newShape.r = r0 + rowSize * (row + 1);
  11317. }
  11318. newShape.clockwise = sectorShape.clockwise;
  11319. newShape.cx = sectorShape.cx;
  11320. newShape.cy = sectorShape.cy;
  11321. outShapes.push(newShape);
  11322. }
  11323. }
  11324. }
  11325. function divideRect(rectShape, count, outShapes) {
  11326. var width = rectShape.width;
  11327. var height = rectShape.height;
  11328. var isHorizontalRow = width > height;
  11329. var grids = getDividingGrids([width, height], isHorizontalRow ? 0 : 1, count);
  11330. var rowSizeDim = isHorizontalRow ? 'width' : 'height';
  11331. var columnSizeDim = isHorizontalRow ? 'height' : 'width';
  11332. var rowDim = isHorizontalRow ? 'x' : 'y';
  11333. var columnDim = isHorizontalRow ? 'y' : 'x';
  11334. var rowSize = rectShape[rowSizeDim] / grids.length;
  11335. for (var row = 0; row < grids.length; row++) {
  11336. var columnSize = rectShape[columnSizeDim] / grids[row];
  11337. for (var column = 0; column < grids[row]; column++) {
  11338. var newShape = {};
  11339. newShape[rowDim] = row * rowSize;
  11340. newShape[columnDim] = column * columnSize;
  11341. newShape[rowSizeDim] = rowSize;
  11342. newShape[columnSizeDim] = columnSize;
  11343. newShape.x += rectShape.x;
  11344. newShape.y += rectShape.y;
  11345. outShapes.push(newShape);
  11346. }
  11347. }
  11348. }
  11349. function crossProduct2d(x1, y1, x2, y2) {
  11350. return x1 * y2 - x2 * y1;
  11351. }
  11352. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  11353. var mx = a2x - a1x;
  11354. var my = a2y - a1y;
  11355. var nx = b2x - b1x;
  11356. var ny = b2y - b1y;
  11357. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  11358. if (Math.abs(nmCrossProduct) < 1e-6) {
  11359. return null;
  11360. }
  11361. var b1a1x = a1x - b1x;
  11362. var b1a1y = a1y - b1y;
  11363. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  11364. if (p < 0 || p > 1) {
  11365. return null;
  11366. }
  11367. return new Point(p * mx + a1x, p * my + a1y);
  11368. }
  11369. function projPtOnLine(pt, lineA, lineB) {
  11370. var dir = new Point();
  11371. Point.sub(dir, lineB, lineA);
  11372. dir.normalize();
  11373. var dir2 = new Point();
  11374. Point.sub(dir2, pt, lineA);
  11375. var len = dir2.dot(dir);
  11376. return len;
  11377. }
  11378. function addToPoly(poly, pt) {
  11379. var last = poly[poly.length - 1];
  11380. if (last && last[0] === pt[0] && last[1] === pt[1]) {
  11381. return;
  11382. }
  11383. poly.push(pt);
  11384. }
  11385. function splitPolygonByLine(points, lineA, lineB) {
  11386. var len = points.length;
  11387. var intersections = [];
  11388. for (var i = 0; i < len; i++) {
  11389. var p0 = points[i];
  11390. var p1 = points[(i + 1) % len];
  11391. var intersectionPt = lineLineIntersect(p0[0], p0[1], p1[0], p1[1], lineA.x, lineA.y, lineB.x, lineB.y);
  11392. if (intersectionPt) {
  11393. intersections.push({
  11394. projPt: projPtOnLine(intersectionPt, lineA, lineB),
  11395. pt: intersectionPt,
  11396. idx: i
  11397. });
  11398. }
  11399. }
  11400. if (intersections.length < 2) {
  11401. return [{ points: points }, { points: points }];
  11402. }
  11403. intersections.sort(function (a, b) {
  11404. return a.projPt - b.projPt;
  11405. });
  11406. var splitPt0 = intersections[0];
  11407. var splitPt1 = intersections[intersections.length - 1];
  11408. if (splitPt1.idx < splitPt0.idx) {
  11409. var tmp = splitPt0;
  11410. splitPt0 = splitPt1;
  11411. splitPt1 = tmp;
  11412. }
  11413. var splitPt0Arr = [splitPt0.pt.x, splitPt0.pt.y];
  11414. var splitPt1Arr = [splitPt1.pt.x, splitPt1.pt.y];
  11415. var newPolyA = [splitPt0Arr];
  11416. var newPolyB = [splitPt1Arr];
  11417. for (var i = splitPt0.idx + 1; i <= splitPt1.idx; i++) {
  11418. addToPoly(newPolyA, points[i].slice());
  11419. }
  11420. addToPoly(newPolyA, splitPt1Arr);
  11421. addToPoly(newPolyA, splitPt0Arr);
  11422. for (var i = splitPt1.idx + 1; i <= splitPt0.idx + len; i++) {
  11423. addToPoly(newPolyB, points[i % len].slice());
  11424. }
  11425. addToPoly(newPolyB, splitPt0Arr);
  11426. addToPoly(newPolyB, splitPt1Arr);
  11427. return [{
  11428. points: newPolyA
  11429. }, {
  11430. points: newPolyB
  11431. }];
  11432. }
  11433. function binaryDividePolygon(polygonShape) {
  11434. var points = polygonShape.points;
  11435. var min = [];
  11436. var max = [];
  11437. fromPoints(points, min, max);
  11438. var boundingRect = new BoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  11439. var width = boundingRect.width;
  11440. var height = boundingRect.height;
  11441. var x = boundingRect.x;
  11442. var y = boundingRect.y;
  11443. var pt0 = new Point();
  11444. var pt1 = new Point();
  11445. if (width > height) {
  11446. pt0.x = pt1.x = x + width / 2;
  11447. pt0.y = y;
  11448. pt1.y = y + height;
  11449. }
  11450. else {
  11451. pt0.y = pt1.y = y + height / 2;
  11452. pt0.x = x;
  11453. pt1.x = x + width;
  11454. }
  11455. return splitPolygonByLine(points, pt0, pt1);
  11456. }
  11457. function binaryDivideRecursive(divider, shape, count, out) {
  11458. if (count === 1) {
  11459. out.push(shape);
  11460. }
  11461. else {
  11462. var mid = Math.floor(count / 2);
  11463. var sub = divider(shape);
  11464. binaryDivideRecursive(divider, sub[0], mid, out);
  11465. binaryDivideRecursive(divider, sub[1], count - mid, out);
  11466. }
  11467. return out;
  11468. }
  11469. function clone$3(path, count) {
  11470. var paths = [];
  11471. for (var i = 0; i < count; i++) {
  11472. paths.push(clonePath(path));
  11473. }
  11474. return paths;
  11475. }
  11476. function copyPathProps(source, target) {
  11477. target.setStyle(source.style);
  11478. target.z = source.z;
  11479. target.z2 = source.z2;
  11480. target.zlevel = source.zlevel;
  11481. }
  11482. function polygonConvert(points) {
  11483. var out = [];
  11484. for (var i = 0; i < points.length;) {
  11485. out.push([points[i++], points[i++]]);
  11486. }
  11487. return out;
  11488. }
  11489. function split(path, count) {
  11490. var outShapes = [];
  11491. var shape = path.shape;
  11492. var OutShapeCtor;
  11493. switch (path.type) {
  11494. case 'rect':
  11495. divideRect(shape, count, outShapes);
  11496. OutShapeCtor = Rect;
  11497. break;
  11498. case 'sector':
  11499. divideSector(shape, count, outShapes);
  11500. OutShapeCtor = Sector;
  11501. break;
  11502. case 'circle':
  11503. divideSector({
  11504. r0: 0, r: shape.r, startAngle: 0, endAngle: Math.PI * 2,
  11505. cx: shape.cx, cy: shape.cy
  11506. }, count, outShapes);
  11507. OutShapeCtor = Sector;
  11508. break;
  11509. default:
  11510. var m = path.getComputedTransform();
  11511. var scale = m ? Math.sqrt(Math.max(m[0] * m[0] + m[1] * m[1], m[2] * m[2] + m[3] * m[3])) : 1;
  11512. var polygons = map(pathToPolygons(path.getUpdatedPathProxy(), scale), function (poly) { return polygonConvert(poly); });
  11513. var polygonCount = polygons.length;
  11514. if (polygonCount === 0) {
  11515. binaryDivideRecursive(binaryDividePolygon, {
  11516. points: polygons[0]
  11517. }, count, outShapes);
  11518. }
  11519. else if (polygonCount === count) {
  11520. for (var i = 0; i < polygonCount; i++) {
  11521. outShapes.push({
  11522. points: polygons[i]
  11523. });
  11524. }
  11525. }
  11526. else {
  11527. var totalArea_1 = 0;
  11528. var items = map(polygons, function (poly) {
  11529. var min = [];
  11530. var max = [];
  11531. fromPoints(poly, min, max);
  11532. var area = (max[1] - min[1]) * (max[0] - min[0]);
  11533. totalArea_1 += area;
  11534. return { poly: poly, area: area };
  11535. });
  11536. items.sort(function (a, b) { return b.area - a.area; });
  11537. var left = count;
  11538. for (var i = 0; i < polygonCount; i++) {
  11539. var item = items[i];
  11540. if (left <= 0) {
  11541. break;
  11542. }
  11543. var selfCount = i === polygonCount - 1
  11544. ? left
  11545. : Math.ceil(item.area / totalArea_1 * count);
  11546. if (selfCount < 0) {
  11547. continue;
  11548. }
  11549. binaryDivideRecursive(binaryDividePolygon, {
  11550. points: item.poly
  11551. }, selfCount, outShapes);
  11552. left -= selfCount;
  11553. }
  11554. }
  11555. OutShapeCtor = Polygon;
  11556. break;
  11557. }
  11558. if (!OutShapeCtor) {
  11559. return clone$3(path, count);
  11560. }
  11561. var out = [];
  11562. for (var i = 0; i < outShapes.length; i++) {
  11563. var subPath = new OutShapeCtor();
  11564. subPath.setShape(outShapes[i]);
  11565. copyPathProps(path, subPath);
  11566. out.push(subPath);
  11567. }
  11568. return out;
  11569. }
  11570. function alignSubpath(subpath1, subpath2) {
  11571. var len1 = subpath1.length;
  11572. var len2 = subpath2.length;
  11573. if (len1 === len2) {
  11574. return [subpath1, subpath2];
  11575. }
  11576. var tmpSegX = [];
  11577. var tmpSegY = [];
  11578. var shorterPath = len1 < len2 ? subpath1 : subpath2;
  11579. var shorterLen = Math.min(len1, len2);
  11580. var diff = Math.abs(len2 - len1) / 6;
  11581. var shorterBezierCount = (shorterLen - 2) / 6;
  11582. var eachCurveSubDivCount = Math.ceil(diff / shorterBezierCount) + 1;
  11583. var newSubpath = [shorterPath[0], shorterPath[1]];
  11584. var remained = diff;
  11585. for (var i = 2; i < shorterLen;) {
  11586. var x0 = shorterPath[i - 2];
  11587. var y0 = shorterPath[i - 1];
  11588. var x1 = shorterPath[i++];
  11589. var y1 = shorterPath[i++];
  11590. var x2 = shorterPath[i++];
  11591. var y2 = shorterPath[i++];
  11592. var x3 = shorterPath[i++];
  11593. var y3 = shorterPath[i++];
  11594. if (remained <= 0) {
  11595. newSubpath.push(x1, y1, x2, y2, x3, y3);
  11596. continue;
  11597. }
  11598. var actualSubDivCount = Math.min(remained, eachCurveSubDivCount - 1) + 1;
  11599. for (var k = 1; k <= actualSubDivCount; k++) {
  11600. var p = k / actualSubDivCount;
  11601. cubicSubdivide(x0, x1, x2, x3, p, tmpSegX);
  11602. cubicSubdivide(y0, y1, y2, y3, p, tmpSegY);
  11603. x0 = tmpSegX[3];
  11604. y0 = tmpSegY[3];
  11605. newSubpath.push(tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], x0, y0);
  11606. x1 = tmpSegX[5];
  11607. y1 = tmpSegY[5];
  11608. x2 = tmpSegX[6];
  11609. y2 = tmpSegY[6];
  11610. }
  11611. remained -= actualSubDivCount - 1;
  11612. }
  11613. return shorterPath === subpath1 ? [newSubpath, subpath2] : [subpath1, newSubpath];
  11614. }
  11615. function createSubpath(lastSubpathSubpath, otherSubpath) {
  11616. var len = lastSubpathSubpath.length;
  11617. var lastX = lastSubpathSubpath[len - 2];
  11618. var lastY = lastSubpathSubpath[len - 1];
  11619. var newSubpath = [];
  11620. for (var i = 0; i < otherSubpath.length;) {
  11621. newSubpath[i++] = lastX;
  11622. newSubpath[i++] = lastY;
  11623. }
  11624. return newSubpath;
  11625. }
  11626. function alignBezierCurves(array1, array2) {
  11627. var _a;
  11628. var lastSubpath1;
  11629. var lastSubpath2;
  11630. var newArray1 = [];
  11631. var newArray2 = [];
  11632. for (var i = 0; i < Math.max(array1.length, array2.length); i++) {
  11633. var subpath1 = array1[i];
  11634. var subpath2 = array2[i];
  11635. var newSubpath1 = void 0;
  11636. var newSubpath2 = void 0;
  11637. if (!subpath1) {
  11638. newSubpath1 = createSubpath(lastSubpath1 || subpath2, subpath2);
  11639. newSubpath2 = subpath2;
  11640. }
  11641. else if (!subpath2) {
  11642. newSubpath2 = createSubpath(lastSubpath2 || subpath1, subpath1);
  11643. newSubpath1 = subpath1;
  11644. }
  11645. else {
  11646. _a = alignSubpath(subpath1, subpath2), newSubpath1 = _a[0], newSubpath2 = _a[1];
  11647. lastSubpath1 = newSubpath1;
  11648. lastSubpath2 = newSubpath2;
  11649. }
  11650. newArray1.push(newSubpath1);
  11651. newArray2.push(newSubpath2);
  11652. }
  11653. return [newArray1, newArray2];
  11654. }
  11655. function centroid(array) {
  11656. var signedArea = 0;
  11657. var cx = 0;
  11658. var cy = 0;
  11659. var len = array.length;
  11660. for (var i = 0, j = len - 2; i < len; j = i, i += 2) {
  11661. var x0 = array[j];
  11662. var y0 = array[j + 1];
  11663. var x1 = array[i];
  11664. var y1 = array[i + 1];
  11665. var a = x0 * y1 - x1 * y0;
  11666. signedArea += a;
  11667. cx += (x0 + x1) * a;
  11668. cy += (y0 + y1) * a;
  11669. }
  11670. if (signedArea === 0) {
  11671. return [array[0] || 0, array[1] || 0];
  11672. }
  11673. return [cx / signedArea / 3, cy / signedArea / 3, signedArea];
  11674. }
  11675. function findBestRingOffset(fromSubBeziers, toSubBeziers, fromCp, toCp) {
  11676. var bezierCount = (fromSubBeziers.length - 2) / 6;
  11677. var bestScore = Infinity;
  11678. var bestOffset = 0;
  11679. var len = fromSubBeziers.length;
  11680. var len2 = len - 2;
  11681. for (var offset = 0; offset < bezierCount; offset++) {
  11682. var cursorOffset = offset * 6;
  11683. var score = 0;
  11684. for (var k = 0; k < len; k += 2) {
  11685. var idx = k === 0 ? cursorOffset : ((cursorOffset + k - 2) % len2 + 2);
  11686. var x0 = fromSubBeziers[idx] - fromCp[0];
  11687. var y0 = fromSubBeziers[idx + 1] - fromCp[1];
  11688. var x1 = toSubBeziers[k] - toCp[0];
  11689. var y1 = toSubBeziers[k + 1] - toCp[1];
  11690. var dx = x1 - x0;
  11691. var dy = y1 - y0;
  11692. score += dx * dx + dy * dy;
  11693. }
  11694. if (score < bestScore) {
  11695. bestScore = score;
  11696. bestOffset = offset;
  11697. }
  11698. }
  11699. return bestOffset;
  11700. }
  11701. function reverse(array) {
  11702. var newArr = [];
  11703. var len = array.length;
  11704. for (var i = 0; i < len; i += 2) {
  11705. newArr[i] = array[len - i - 2];
  11706. newArr[i + 1] = array[len - i - 1];
  11707. }
  11708. return newArr;
  11709. }
  11710. function findBestMorphingRotation(fromArr, toArr, searchAngleIteration, searchAngleRange) {
  11711. var result = [];
  11712. var fromNeedsReverse;
  11713. for (var i = 0; i < fromArr.length; i++) {
  11714. var fromSubpathBezier = fromArr[i];
  11715. var toSubpathBezier = toArr[i];
  11716. var fromCp = centroid(fromSubpathBezier);
  11717. var toCp = centroid(toSubpathBezier);
  11718. if (fromNeedsReverse == null) {
  11719. fromNeedsReverse = fromCp[2] < 0 !== toCp[2] < 0;
  11720. }
  11721. var newFromSubpathBezier = [];
  11722. var newToSubpathBezier = [];
  11723. var bestAngle = 0;
  11724. var bestScore = Infinity;
  11725. var tmpArr = [];
  11726. var len = fromSubpathBezier.length;
  11727. if (fromNeedsReverse) {
  11728. fromSubpathBezier = reverse(fromSubpathBezier);
  11729. }
  11730. var offset = findBestRingOffset(fromSubpathBezier, toSubpathBezier, fromCp, toCp) * 6;
  11731. var len2 = len - 2;
  11732. for (var k = 0; k < len2; k += 2) {
  11733. var idx = (offset + k) % len2 + 2;
  11734. newFromSubpathBezier[k + 2] = fromSubpathBezier[idx] - fromCp[0];
  11735. newFromSubpathBezier[k + 3] = fromSubpathBezier[idx + 1] - fromCp[1];
  11736. }
  11737. newFromSubpathBezier[0] = fromSubpathBezier[offset] - fromCp[0];
  11738. newFromSubpathBezier[1] = fromSubpathBezier[offset + 1] - fromCp[1];
  11739. if (searchAngleIteration > 0) {
  11740. var step = searchAngleRange / searchAngleIteration;
  11741. for (var angle = -searchAngleRange / 2; angle <= searchAngleRange / 2; angle += step) {
  11742. var sa = Math.sin(angle);
  11743. var ca = Math.cos(angle);
  11744. var score = 0;
  11745. for (var k = 0; k < fromSubpathBezier.length; k += 2) {
  11746. var x0 = newFromSubpathBezier[k];
  11747. var y0 = newFromSubpathBezier[k + 1];
  11748. var x1 = toSubpathBezier[k] - toCp[0];
  11749. var y1 = toSubpathBezier[k + 1] - toCp[1];
  11750. var newX1 = x1 * ca - y1 * sa;
  11751. var newY1 = x1 * sa + y1 * ca;
  11752. tmpArr[k] = newX1;
  11753. tmpArr[k + 1] = newY1;
  11754. var dx = newX1 - x0;
  11755. var dy = newY1 - y0;
  11756. score += dx * dx + dy * dy;
  11757. }
  11758. if (score < bestScore) {
  11759. bestScore = score;
  11760. bestAngle = angle;
  11761. for (var m = 0; m < tmpArr.length; m++) {
  11762. newToSubpathBezier[m] = tmpArr[m];
  11763. }
  11764. }
  11765. }
  11766. }
  11767. else {
  11768. for (var i_1 = 0; i_1 < len; i_1 += 2) {
  11769. newToSubpathBezier[i_1] = toSubpathBezier[i_1] - toCp[0];
  11770. newToSubpathBezier[i_1 + 1] = toSubpathBezier[i_1 + 1] - toCp[1];
  11771. }
  11772. }
  11773. result.push({
  11774. from: newFromSubpathBezier,
  11775. to: newToSubpathBezier,
  11776. fromCp: fromCp,
  11777. toCp: toCp,
  11778. rotation: -bestAngle
  11779. });
  11780. }
  11781. return result;
  11782. }
  11783. function isCombineMorphing(path) {
  11784. return path.__isCombineMorphing;
  11785. }
  11786. function isMorphing(el) {
  11787. return el.__morphT >= 0;
  11788. }
  11789. var SAVED_METHOD_PREFIX = '__mOriginal_';
  11790. function saveAndModifyMethod(obj, methodName, modifiers) {
  11791. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  11792. var originalMethod = obj[savedMethodName] || obj[methodName];
  11793. if (!obj[savedMethodName]) {
  11794. obj[savedMethodName] = obj[methodName];
  11795. }
  11796. var replace = modifiers.replace;
  11797. var after = modifiers.after;
  11798. var before = modifiers.before;
  11799. obj[methodName] = function () {
  11800. var args = arguments;
  11801. var res;
  11802. before && before.apply(this, args);
  11803. if (replace) {
  11804. res = replace.apply(this, args);
  11805. }
  11806. else {
  11807. res = originalMethod.apply(this, args);
  11808. }
  11809. after && after.apply(this, args);
  11810. return res;
  11811. };
  11812. }
  11813. function restoreMethod(obj, methodName) {
  11814. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  11815. if (obj[savedMethodName]) {
  11816. obj[methodName] = obj[savedMethodName];
  11817. obj[savedMethodName] = null;
  11818. }
  11819. }
  11820. function applyTransformOnBeziers(bezierCurves, mm) {
  11821. for (var i = 0; i < bezierCurves.length; i++) {
  11822. var subBeziers = bezierCurves[i];
  11823. for (var k = 0; k < subBeziers.length;) {
  11824. var x = subBeziers[k];
  11825. var y = subBeziers[k + 1];
  11826. subBeziers[k++] = mm[0] * x + mm[2] * y + mm[4];
  11827. subBeziers[k++] = mm[1] * x + mm[3] * y + mm[5];
  11828. }
  11829. }
  11830. }
  11831. function prepareMorphPath(fromPath, toPath) {
  11832. var fromPathProxy = fromPath.getUpdatedPathProxy();
  11833. var toPathProxy = toPath.getUpdatedPathProxy();
  11834. var _a = alignBezierCurves(pathToBezierCurves(fromPathProxy), pathToBezierCurves(toPathProxy)), fromBezierCurves = _a[0], toBezierCurves = _a[1];
  11835. var fromPathTransform = fromPath.getComputedTransform();
  11836. var toPathTransform = toPath.getComputedTransform();
  11837. function updateIdentityTransform() {
  11838. this.transform = null;
  11839. }
  11840. fromPathTransform && applyTransformOnBeziers(fromBezierCurves, fromPathTransform);
  11841. toPathTransform && applyTransformOnBeziers(toBezierCurves, toPathTransform);
  11842. saveAndModifyMethod(toPath, 'updateTransform', { replace: updateIdentityTransform });
  11843. toPath.transform = null;
  11844. var morphingData = findBestMorphingRotation(fromBezierCurves, toBezierCurves, 10, Math.PI);
  11845. var tmpArr = [];
  11846. saveAndModifyMethod(toPath, 'buildPath', { replace: function (path) {
  11847. var t = toPath.__morphT;
  11848. var onet = 1 - t;
  11849. var newCp = [];
  11850. for (var i = 0; i < morphingData.length; i++) {
  11851. var item = morphingData[i];
  11852. var from = item.from;
  11853. var to = item.to;
  11854. var angle = item.rotation * t;
  11855. var fromCp = item.fromCp;
  11856. var toCp = item.toCp;
  11857. var sa = Math.sin(angle);
  11858. var ca = Math.cos(angle);
  11859. lerp(newCp, fromCp, toCp, t);
  11860. for (var m = 0; m < from.length; m += 2) {
  11861. var x0_1 = from[m];
  11862. var y0_1 = from[m + 1];
  11863. var x1 = to[m];
  11864. var y1 = to[m + 1];
  11865. var x = x0_1 * onet + x1 * t;
  11866. var y = y0_1 * onet + y1 * t;
  11867. tmpArr[m] = (x * ca - y * sa) + newCp[0];
  11868. tmpArr[m + 1] = (x * sa + y * ca) + newCp[1];
  11869. }
  11870. var x0 = tmpArr[0];
  11871. var y0 = tmpArr[1];
  11872. path.moveTo(x0, y0);
  11873. for (var m = 2; m < from.length;) {
  11874. var x1 = tmpArr[m++];
  11875. var y1 = tmpArr[m++];
  11876. var x2 = tmpArr[m++];
  11877. var y2 = tmpArr[m++];
  11878. var x3 = tmpArr[m++];
  11879. var y3 = tmpArr[m++];
  11880. if (x0 === x1 && y0 === y1 && x2 === x3 && y2 === y3) {
  11881. path.lineTo(x3, y3);
  11882. }
  11883. else {
  11884. path.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11885. }
  11886. x0 = x3;
  11887. y0 = y3;
  11888. }
  11889. }
  11890. } });
  11891. }
  11892. function morphPath(fromPath, toPath, animationOpts) {
  11893. if (!fromPath || !toPath) {
  11894. return toPath;
  11895. }
  11896. var oldDone = animationOpts.done;
  11897. var oldDuring = animationOpts.during;
  11898. prepareMorphPath(fromPath, toPath);
  11899. toPath.__morphT = 0;
  11900. function restoreToPath() {
  11901. restoreMethod(toPath, 'buildPath');
  11902. restoreMethod(toPath, 'updateTransform');
  11903. toPath.__morphT = -1;
  11904. toPath.createPathProxy();
  11905. toPath.dirtyShape();
  11906. }
  11907. toPath.animateTo({
  11908. __morphT: 1
  11909. }, defaults({
  11910. during: function (p) {
  11911. toPath.dirtyShape();
  11912. oldDuring && oldDuring(p);
  11913. },
  11914. done: function () {
  11915. restoreToPath();
  11916. oldDone && oldDone();
  11917. }
  11918. }, animationOpts));
  11919. return toPath;
  11920. }
  11921. function hilbert(x, y, minX, minY, maxX, maxY) {
  11922. var bits = 16;
  11923. x = (maxX === minX) ? 0 : Math.round(32767 * (x - minX) / (maxX - minX));
  11924. y = (maxY === minY) ? 0 : Math.round(32767 * (y - minY) / (maxY - minY));
  11925. var d = 0;
  11926. var tmp;
  11927. for (var s = (1 << bits) / 2; s > 0; s /= 2) {
  11928. var rx = 0;
  11929. var ry = 0;
  11930. if ((x & s) > 0) {
  11931. rx = 1;
  11932. }
  11933. if ((y & s) > 0) {
  11934. ry = 1;
  11935. }
  11936. d += s * s * ((3 * rx) ^ ry);
  11937. if (ry === 0) {
  11938. if (rx === 1) {
  11939. x = s - 1 - x;
  11940. y = s - 1 - y;
  11941. }
  11942. tmp = x;
  11943. x = y;
  11944. y = tmp;
  11945. }
  11946. }
  11947. return d;
  11948. }
  11949. function sortPaths(pathList) {
  11950. var xMin = Infinity;
  11951. var yMin = Infinity;
  11952. var xMax = -Infinity;
  11953. var yMax = -Infinity;
  11954. var cps = map(pathList, function (path) {
  11955. var rect = path.getBoundingRect();
  11956. var m = path.getComputedTransform();
  11957. var x = rect.x + rect.width / 2 + (m ? m[4] : 0);
  11958. var y = rect.y + rect.height / 2 + (m ? m[5] : 0);
  11959. xMin = Math.min(x, xMin);
  11960. yMin = Math.min(y, yMin);
  11961. xMax = Math.max(x, xMax);
  11962. yMax = Math.max(y, yMax);
  11963. return [x, y];
  11964. });
  11965. var items = map(cps, function (cp, idx) {
  11966. return {
  11967. cp: cp,
  11968. z: hilbert(cp[0], cp[1], xMin, yMin, xMax, yMax),
  11969. path: pathList[idx]
  11970. };
  11971. });
  11972. return items.sort(function (a, b) { return a.z - b.z; }).map(function (item) { return item.path; });
  11973. }
  11974. function defaultDividePath(param) {
  11975. return split(param.path, param.count);
  11976. }
  11977. function createEmptyReturn() {
  11978. return {
  11979. fromIndividuals: [],
  11980. toIndividuals: [],
  11981. count: 0
  11982. };
  11983. }
  11984. function combineMorph(fromList, toPath, animationOpts) {
  11985. var fromPathList = [];
  11986. function addFromPath(fromList) {
  11987. for (var i = 0; i < fromList.length; i++) {
  11988. var from = fromList[i];
  11989. if (isCombineMorphing(from)) {
  11990. addFromPath(from.childrenRef());
  11991. }
  11992. else if (from instanceof Path) {
  11993. fromPathList.push(from);
  11994. }
  11995. }
  11996. }
  11997. addFromPath(fromList);
  11998. var separateCount = fromPathList.length;
  11999. if (!separateCount) {
  12000. return createEmptyReturn();
  12001. }
  12002. var dividePath = animationOpts.dividePath || defaultDividePath;
  12003. var toSubPathList = dividePath({
  12004. path: toPath, count: separateCount
  12005. });
  12006. if (toSubPathList.length !== separateCount) {
  12007. console.error('Invalid morphing: unmatched splitted path');
  12008. return createEmptyReturn();
  12009. }
  12010. fromPathList = sortPaths(fromPathList);
  12011. toSubPathList = sortPaths(toSubPathList);
  12012. var oldDone = animationOpts.done;
  12013. var oldDuring = animationOpts.during;
  12014. var individualDelay = animationOpts.individualDelay;
  12015. var identityTransform = new Transformable();
  12016. for (var i = 0; i < separateCount; i++) {
  12017. var from = fromPathList[i];
  12018. var to = toSubPathList[i];
  12019. to.parent = toPath;
  12020. to.copyTransform(identityTransform);
  12021. if (!individualDelay) {
  12022. prepareMorphPath(from, to);
  12023. }
  12024. }
  12025. toPath.__isCombineMorphing = true;
  12026. toPath.childrenRef = function () {
  12027. return toSubPathList;
  12028. };
  12029. function addToSubPathListToZr(zr) {
  12030. for (var i = 0; i < toSubPathList.length; i++) {
  12031. toSubPathList[i].addSelfToZr(zr);
  12032. }
  12033. }
  12034. saveAndModifyMethod(toPath, 'addSelfToZr', {
  12035. after: function (zr) {
  12036. addToSubPathListToZr(zr);
  12037. }
  12038. });
  12039. saveAndModifyMethod(toPath, 'removeSelfFromZr', {
  12040. after: function (zr) {
  12041. for (var i = 0; i < toSubPathList.length; i++) {
  12042. toSubPathList[i].removeSelfFromZr(zr);
  12043. }
  12044. }
  12045. });
  12046. function restoreToPath() {
  12047. toPath.__isCombineMorphing = false;
  12048. toPath.__morphT = -1;
  12049. toPath.childrenRef = null;
  12050. restoreMethod(toPath, 'addSelfToZr');
  12051. restoreMethod(toPath, 'removeSelfFromZr');
  12052. }
  12053. var toLen = toSubPathList.length;
  12054. if (individualDelay) {
  12055. var animating_1 = toLen;
  12056. var eachDone = function () {
  12057. animating_1--;
  12058. if (animating_1 === 0) {
  12059. restoreToPath();
  12060. oldDone && oldDone();
  12061. }
  12062. };
  12063. for (var i = 0; i < toLen; i++) {
  12064. var indivdualAnimationOpts = individualDelay ? defaults({
  12065. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toSubPathList[i]),
  12066. done: eachDone
  12067. }, animationOpts) : animationOpts;
  12068. morphPath(fromPathList[i], toSubPathList[i], indivdualAnimationOpts);
  12069. }
  12070. }
  12071. else {
  12072. toPath.__morphT = 0;
  12073. toPath.animateTo({
  12074. __morphT: 1
  12075. }, defaults({
  12076. during: function (p) {
  12077. for (var i = 0; i < toLen; i++) {
  12078. var child = toSubPathList[i];
  12079. child.__morphT = toPath.__morphT;
  12080. child.dirtyShape();
  12081. }
  12082. oldDuring && oldDuring(p);
  12083. },
  12084. done: function () {
  12085. restoreToPath();
  12086. for (var i = 0; i < fromList.length; i++) {
  12087. restoreMethod(fromList[i], 'updateTransform');
  12088. }
  12089. oldDone && oldDone();
  12090. }
  12091. }, animationOpts));
  12092. }
  12093. if (toPath.__zr) {
  12094. addToSubPathListToZr(toPath.__zr);
  12095. }
  12096. return {
  12097. fromIndividuals: fromPathList,
  12098. toIndividuals: toSubPathList,
  12099. count: toLen
  12100. };
  12101. }
  12102. function separateMorph(fromPath, toPathList, animationOpts) {
  12103. var toLen = toPathList.length;
  12104. var fromPathList = [];
  12105. var dividePath = animationOpts.dividePath || defaultDividePath;
  12106. function addFromPath(fromList) {
  12107. for (var i = 0; i < fromList.length; i++) {
  12108. var from = fromList[i];
  12109. if (isCombineMorphing(from)) {
  12110. addFromPath(from.childrenRef());
  12111. }
  12112. else if (from instanceof Path) {
  12113. fromPathList.push(from);
  12114. }
  12115. }
  12116. }
  12117. if (isCombineMorphing(fromPath)) {
  12118. addFromPath(fromPath.childrenRef());
  12119. var fromLen = fromPathList.length;
  12120. if (fromLen < toLen) {
  12121. var k = 0;
  12122. for (var i = fromLen; i < toLen; i++) {
  12123. fromPathList.push(clonePath(fromPathList[k++ % fromLen]));
  12124. }
  12125. }
  12126. fromPathList.length = toLen;
  12127. }
  12128. else {
  12129. fromPathList = dividePath({ path: fromPath, count: toLen });
  12130. var fromPathTransform = fromPath.getComputedTransform();
  12131. for (var i = 0; i < fromPathList.length; i++) {
  12132. fromPathList[i].setLocalTransform(fromPathTransform);
  12133. }
  12134. if (fromPathList.length !== toLen) {
  12135. console.error('Invalid morphing: unmatched splitted path');
  12136. return createEmptyReturn();
  12137. }
  12138. }
  12139. fromPathList = sortPaths(fromPathList);
  12140. toPathList = sortPaths(toPathList);
  12141. var individualDelay = animationOpts.individualDelay;
  12142. for (var i = 0; i < toLen; i++) {
  12143. var indivdualAnimationOpts = individualDelay ? defaults({
  12144. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toPathList[i])
  12145. }, animationOpts) : animationOpts;
  12146. morphPath(fromPathList[i], toPathList[i], indivdualAnimationOpts);
  12147. }
  12148. return {
  12149. fromIndividuals: fromPathList,
  12150. toIndividuals: toPathList,
  12151. count: toPathList.length
  12152. };
  12153. }
  12154. var morphPath$1 = /*#__PURE__*/Object.freeze({
  12155. __proto__: null,
  12156. alignBezierCurves: alignBezierCurves,
  12157. centroid: centroid,
  12158. isCombineMorphing: isCombineMorphing,
  12159. isMorphing: isMorphing,
  12160. morphPath: morphPath,
  12161. combineMorph: combineMorph,
  12162. separateMorph: separateMorph,
  12163. defaultDividePath: split
  12164. });
  12165. var CompoundPath = (function (_super) {
  12166. __extends(CompoundPath, _super);
  12167. function CompoundPath() {
  12168. var _this = _super !== null && _super.apply(this, arguments) || this;
  12169. _this.type = 'compound';
  12170. return _this;
  12171. }
  12172. CompoundPath.prototype._updatePathDirty = function () {
  12173. var paths = this.shape.paths;
  12174. var dirtyPath = this.shapeChanged();
  12175. for (var i = 0; i < paths.length; i++) {
  12176. dirtyPath = dirtyPath || paths[i].shapeChanged();
  12177. }
  12178. if (dirtyPath) {
  12179. this.dirtyShape();
  12180. }
  12181. };
  12182. CompoundPath.prototype.beforeBrush = function () {
  12183. this._updatePathDirty();
  12184. var paths = this.shape.paths || [];
  12185. var scale = this.getGlobalScale();
  12186. for (var i = 0; i < paths.length; i++) {
  12187. if (!paths[i].path) {
  12188. paths[i].createPathProxy();
  12189. }
  12190. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  12191. }
  12192. };
  12193. CompoundPath.prototype.buildPath = function (ctx, shape) {
  12194. var paths = shape.paths || [];
  12195. for (var i = 0; i < paths.length; i++) {
  12196. paths[i].buildPath(ctx, paths[i].shape, true);
  12197. }
  12198. };
  12199. CompoundPath.prototype.afterBrush = function () {
  12200. var paths = this.shape.paths || [];
  12201. for (var i = 0; i < paths.length; i++) {
  12202. paths[i].pathUpdated();
  12203. }
  12204. };
  12205. CompoundPath.prototype.getBoundingRect = function () {
  12206. this._updatePathDirty.call(this);
  12207. return Path.prototype.getBoundingRect.call(this);
  12208. };
  12209. return CompoundPath;
  12210. }(Path));
  12211. var m = [];
  12212. var IncrementalDisplayable = (function (_super) {
  12213. __extends(IncrementalDisplayable, _super);
  12214. function IncrementalDisplayable() {
  12215. var _this = _super !== null && _super.apply(this, arguments) || this;
  12216. _this.notClear = true;
  12217. _this.incremental = true;
  12218. _this._displayables = [];
  12219. _this._temporaryDisplayables = [];
  12220. _this._cursor = 0;
  12221. return _this;
  12222. }
  12223. IncrementalDisplayable.prototype.traverse = function (cb, context) {
  12224. cb.call(context, this);
  12225. };
  12226. IncrementalDisplayable.prototype.useStyle = function () {
  12227. this.style = {};
  12228. };
  12229. IncrementalDisplayable.prototype.getCursor = function () {
  12230. return this._cursor;
  12231. };
  12232. IncrementalDisplayable.prototype.innerAfterBrush = function () {
  12233. this._cursor = this._displayables.length;
  12234. };
  12235. IncrementalDisplayable.prototype.clearDisplaybles = function () {
  12236. this._displayables = [];
  12237. this._temporaryDisplayables = [];
  12238. this._cursor = 0;
  12239. this.markRedraw();
  12240. this.notClear = false;
  12241. };
  12242. IncrementalDisplayable.prototype.clearTemporalDisplayables = function () {
  12243. this._temporaryDisplayables = [];
  12244. };
  12245. IncrementalDisplayable.prototype.addDisplayable = function (displayable, notPersistent) {
  12246. if (notPersistent) {
  12247. this._temporaryDisplayables.push(displayable);
  12248. }
  12249. else {
  12250. this._displayables.push(displayable);
  12251. }
  12252. this.markRedraw();
  12253. };
  12254. IncrementalDisplayable.prototype.addDisplayables = function (displayables, notPersistent) {
  12255. notPersistent = notPersistent || false;
  12256. for (var i = 0; i < displayables.length; i++) {
  12257. this.addDisplayable(displayables[i], notPersistent);
  12258. }
  12259. };
  12260. IncrementalDisplayable.prototype.getDisplayables = function () {
  12261. return this._displayables;
  12262. };
  12263. IncrementalDisplayable.prototype.getTemporalDisplayables = function () {
  12264. return this._temporaryDisplayables;
  12265. };
  12266. IncrementalDisplayable.prototype.eachPendingDisplayable = function (cb) {
  12267. for (var i = this._cursor; i < this._displayables.length; i++) {
  12268. cb && cb(this._displayables[i]);
  12269. }
  12270. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  12271. cb && cb(this._temporaryDisplayables[i]);
  12272. }
  12273. };
  12274. IncrementalDisplayable.prototype.update = function () {
  12275. this.updateTransform();
  12276. for (var i = this._cursor; i < this._displayables.length; i++) {
  12277. var displayable = this._displayables[i];
  12278. displayable.parent = this;
  12279. displayable.update();
  12280. displayable.parent = null;
  12281. }
  12282. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  12283. var displayable = this._temporaryDisplayables[i];
  12284. displayable.parent = this;
  12285. displayable.update();
  12286. displayable.parent = null;
  12287. }
  12288. };
  12289. IncrementalDisplayable.prototype.getBoundingRect = function () {
  12290. if (!this._rect) {
  12291. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  12292. for (var i = 0; i < this._displayables.length; i++) {
  12293. var displayable = this._displayables[i];
  12294. var childRect = displayable.getBoundingRect().clone();
  12295. if (displayable.needLocalTransform()) {
  12296. childRect.applyTransform(displayable.getLocalTransform(m));
  12297. }
  12298. rect.union(childRect);
  12299. }
  12300. this._rect = rect;
  12301. }
  12302. return this._rect;
  12303. };
  12304. IncrementalDisplayable.prototype.contain = function (x, y) {
  12305. var localPos = this.transformCoordToLocal(x, y);
  12306. var rect = this.getBoundingRect();
  12307. if (rect.contain(localPos[0], localPos[1])) {
  12308. for (var i = 0; i < this._displayables.length; i++) {
  12309. var displayable = this._displayables[i];
  12310. if (displayable.contain(x, y)) {
  12311. return true;
  12312. }
  12313. }
  12314. }
  12315. return false;
  12316. };
  12317. return IncrementalDisplayable;
  12318. }(Displayable));
  12319. var globalImageCache = new LRU(50);
  12320. function findExistImage(newImageOrSrc) {
  12321. if (typeof newImageOrSrc === 'string') {
  12322. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  12323. return cachedImgObj && cachedImgObj.image;
  12324. }
  12325. else {
  12326. return newImageOrSrc;
  12327. }
  12328. }
  12329. function createOrUpdateImage(newImageOrSrc, image, hostEl, onload, cbPayload) {
  12330. if (!newImageOrSrc) {
  12331. return image;
  12332. }
  12333. else if (typeof newImageOrSrc === 'string') {
  12334. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  12335. return image;
  12336. }
  12337. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  12338. var pendingWrap = { hostEl: hostEl, cb: onload, cbPayload: cbPayload };
  12339. if (cachedImgObj) {
  12340. image = cachedImgObj.image;
  12341. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  12342. }
  12343. else {
  12344. image = platformApi.loadImage(newImageOrSrc, imageOnLoad, imageOnLoad);
  12345. image.__zrImageSrc = newImageOrSrc;
  12346. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  12347. image: image,
  12348. pending: [pendingWrap]
  12349. });
  12350. }
  12351. return image;
  12352. }
  12353. else {
  12354. return newImageOrSrc;
  12355. }
  12356. }
  12357. function imageOnLoad() {
  12358. var cachedImgObj = this.__cachedImgObj;
  12359. this.onload = this.onerror = this.__cachedImgObj = null;
  12360. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  12361. var pendingWrap = cachedImgObj.pending[i];
  12362. var cb = pendingWrap.cb;
  12363. cb && cb(this, pendingWrap.cbPayload);
  12364. pendingWrap.hostEl.dirty();
  12365. }
  12366. cachedImgObj.pending.length = 0;
  12367. }
  12368. function isImageReady(image) {
  12369. return image && image.width && image.height;
  12370. }
  12371. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  12372. function truncateText(text, containerWidth, font, ellipsis, options) {
  12373. if (!containerWidth) {
  12374. return '';
  12375. }
  12376. var textLines = (text + '').split('\n');
  12377. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  12378. for (var i = 0, len = textLines.length; i < len; i++) {
  12379. textLines[i] = truncateSingleLine(textLines[i], options);
  12380. }
  12381. return textLines.join('\n');
  12382. }
  12383. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  12384. options = options || {};
  12385. var preparedOpts = extend({}, options);
  12386. preparedOpts.font = font;
  12387. ellipsis = retrieve2(ellipsis, '...');
  12388. preparedOpts.maxIterations = retrieve2(options.maxIterations, 2);
  12389. var minChar = preparedOpts.minChar = retrieve2(options.minChar, 0);
  12390. preparedOpts.cnCharWidth = getWidth('国', font);
  12391. var ascCharWidth = preparedOpts.ascCharWidth = getWidth('a', font);
  12392. preparedOpts.placeholder = retrieve2(options.placeholder, '');
  12393. var contentWidth = containerWidth = Math.max(0, containerWidth - 1);
  12394. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  12395. contentWidth -= ascCharWidth;
  12396. }
  12397. var ellipsisWidth = getWidth(ellipsis, font);
  12398. if (ellipsisWidth > contentWidth) {
  12399. ellipsis = '';
  12400. ellipsisWidth = 0;
  12401. }
  12402. contentWidth = containerWidth - ellipsisWidth;
  12403. preparedOpts.ellipsis = ellipsis;
  12404. preparedOpts.ellipsisWidth = ellipsisWidth;
  12405. preparedOpts.contentWidth = contentWidth;
  12406. preparedOpts.containerWidth = containerWidth;
  12407. return preparedOpts;
  12408. }
  12409. function truncateSingleLine(textLine, options) {
  12410. var containerWidth = options.containerWidth;
  12411. var font = options.font;
  12412. var contentWidth = options.contentWidth;
  12413. if (!containerWidth) {
  12414. return '';
  12415. }
  12416. var lineWidth = getWidth(textLine, font);
  12417. if (lineWidth <= containerWidth) {
  12418. return textLine;
  12419. }
  12420. for (var j = 0;; j++) {
  12421. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  12422. textLine += options.ellipsis;
  12423. break;
  12424. }
  12425. var subLength = j === 0
  12426. ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
  12427. : lineWidth > 0
  12428. ? Math.floor(textLine.length * contentWidth / lineWidth)
  12429. : 0;
  12430. textLine = textLine.substr(0, subLength);
  12431. lineWidth = getWidth(textLine, font);
  12432. }
  12433. if (textLine === '') {
  12434. textLine = options.placeholder;
  12435. }
  12436. return textLine;
  12437. }
  12438. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  12439. var width = 0;
  12440. var i = 0;
  12441. for (var len = text.length; i < len && width < contentWidth; i++) {
  12442. var charCode = text.charCodeAt(i);
  12443. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  12444. }
  12445. return i;
  12446. }
  12447. function parsePlainText(text, style) {
  12448. text != null && (text += '');
  12449. var overflow = style.overflow;
  12450. var padding = style.padding;
  12451. var font = style.font;
  12452. var truncate = overflow === 'truncate';
  12453. var calculatedLineHeight = getLineHeight(font);
  12454. var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
  12455. var bgColorDrawn = !!(style.backgroundColor);
  12456. var truncateLineOverflow = style.lineOverflow === 'truncate';
  12457. var width = style.width;
  12458. var lines;
  12459. if (width != null && (overflow === 'break' || overflow === 'breakAll')) {
  12460. lines = text ? wrapText(text, style.font, width, overflow === 'breakAll', 0).lines : [];
  12461. }
  12462. else {
  12463. lines = text ? text.split('\n') : [];
  12464. }
  12465. var contentHeight = lines.length * lineHeight;
  12466. var height = retrieve2(style.height, contentHeight);
  12467. if (contentHeight > height && truncateLineOverflow) {
  12468. var lineCount = Math.floor(height / lineHeight);
  12469. lines = lines.slice(0, lineCount);
  12470. }
  12471. if (text && truncate && width != null) {
  12472. var options = prepareTruncateOptions(width, font, style.ellipsis, {
  12473. minChar: style.truncateMinChar,
  12474. placeholder: style.placeholder
  12475. });
  12476. for (var i = 0; i < lines.length; i++) {
  12477. lines[i] = truncateSingleLine(lines[i], options);
  12478. }
  12479. }
  12480. var outerHeight = height;
  12481. var contentWidth = 0;
  12482. for (var i = 0; i < lines.length; i++) {
  12483. contentWidth = Math.max(getWidth(lines[i], font), contentWidth);
  12484. }
  12485. if (width == null) {
  12486. width = contentWidth;
  12487. }
  12488. var outerWidth = contentWidth;
  12489. if (padding) {
  12490. outerHeight += padding[0] + padding[2];
  12491. outerWidth += padding[1] + padding[3];
  12492. width += padding[1] + padding[3];
  12493. }
  12494. if (bgColorDrawn) {
  12495. outerWidth = width;
  12496. }
  12497. return {
  12498. lines: lines,
  12499. height: height,
  12500. outerWidth: outerWidth,
  12501. outerHeight: outerHeight,
  12502. lineHeight: lineHeight,
  12503. calculatedLineHeight: calculatedLineHeight,
  12504. contentWidth: contentWidth,
  12505. contentHeight: contentHeight,
  12506. width: width
  12507. };
  12508. }
  12509. var RichTextToken = (function () {
  12510. function RichTextToken() {
  12511. }
  12512. return RichTextToken;
  12513. }());
  12514. var RichTextLine = (function () {
  12515. function RichTextLine(tokens) {
  12516. this.tokens = [];
  12517. if (tokens) {
  12518. this.tokens = tokens;
  12519. }
  12520. }
  12521. return RichTextLine;
  12522. }());
  12523. var RichTextContentBlock = (function () {
  12524. function RichTextContentBlock() {
  12525. this.width = 0;
  12526. this.height = 0;
  12527. this.contentWidth = 0;
  12528. this.contentHeight = 0;
  12529. this.outerWidth = 0;
  12530. this.outerHeight = 0;
  12531. this.lines = [];
  12532. }
  12533. return RichTextContentBlock;
  12534. }());
  12535. function parseRichText(text, style) {
  12536. var contentBlock = new RichTextContentBlock();
  12537. text != null && (text += '');
  12538. if (!text) {
  12539. return contentBlock;
  12540. }
  12541. var topWidth = style.width;
  12542. var topHeight = style.height;
  12543. var overflow = style.overflow;
  12544. var wrapInfo = (overflow === 'break' || overflow === 'breakAll') && topWidth != null
  12545. ? { width: topWidth, accumWidth: 0, breakAll: overflow === 'breakAll' }
  12546. : null;
  12547. var lastIndex = STYLE_REG.lastIndex = 0;
  12548. var result;
  12549. while ((result = STYLE_REG.exec(text)) != null) {
  12550. var matchedIndex = result.index;
  12551. if (matchedIndex > lastIndex) {
  12552. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex), style, wrapInfo);
  12553. }
  12554. pushTokens(contentBlock, result[2], style, wrapInfo, result[1]);
  12555. lastIndex = STYLE_REG.lastIndex;
  12556. }
  12557. if (lastIndex < text.length) {
  12558. pushTokens(contentBlock, text.substring(lastIndex, text.length), style, wrapInfo);
  12559. }
  12560. var pendingList = [];
  12561. var calculatedHeight = 0;
  12562. var calculatedWidth = 0;
  12563. var stlPadding = style.padding;
  12564. var truncate = overflow === 'truncate';
  12565. var truncateLine = style.lineOverflow === 'truncate';
  12566. function finishLine(line, lineWidth, lineHeight) {
  12567. line.width = lineWidth;
  12568. line.lineHeight = lineHeight;
  12569. calculatedHeight += lineHeight;
  12570. calculatedWidth = Math.max(calculatedWidth, lineWidth);
  12571. }
  12572. outer: for (var i = 0; i < contentBlock.lines.length; i++) {
  12573. var line = contentBlock.lines[i];
  12574. var lineHeight = 0;
  12575. var lineWidth = 0;
  12576. for (var j = 0; j < line.tokens.length; j++) {
  12577. var token = line.tokens[j];
  12578. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  12579. var textPadding = token.textPadding = tokenStyle.padding;
  12580. var paddingH = textPadding ? textPadding[1] + textPadding[3] : 0;
  12581. var font = token.font = tokenStyle.font || style.font;
  12582. token.contentHeight = getLineHeight(font);
  12583. var tokenHeight = retrieve2(tokenStyle.height, token.contentHeight);
  12584. token.innerHeight = tokenHeight;
  12585. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  12586. token.height = tokenHeight;
  12587. token.lineHeight = retrieve3(tokenStyle.lineHeight, style.lineHeight, tokenHeight);
  12588. token.align = tokenStyle && tokenStyle.align || style.align;
  12589. token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
  12590. if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
  12591. if (j > 0) {
  12592. line.tokens = line.tokens.slice(0, j);
  12593. finishLine(line, lineWidth, lineHeight);
  12594. contentBlock.lines = contentBlock.lines.slice(0, i + 1);
  12595. }
  12596. else {
  12597. contentBlock.lines = contentBlock.lines.slice(0, i);
  12598. }
  12599. break outer;
  12600. }
  12601. var styleTokenWidth = tokenStyle.width;
  12602. var tokenWidthNotSpecified = styleTokenWidth == null || styleTokenWidth === 'auto';
  12603. if (typeof styleTokenWidth === 'string' && styleTokenWidth.charAt(styleTokenWidth.length - 1) === '%') {
  12604. token.percentWidth = styleTokenWidth;
  12605. pendingList.push(token);
  12606. token.contentWidth = getWidth(token.text, font);
  12607. }
  12608. else {
  12609. if (tokenWidthNotSpecified) {
  12610. var textBackgroundColor = tokenStyle.backgroundColor;
  12611. var bgImg = textBackgroundColor && textBackgroundColor.image;
  12612. if (bgImg) {
  12613. bgImg = findExistImage(bgImg);
  12614. if (isImageReady(bgImg)) {
  12615. token.width = Math.max(token.width, bgImg.width * tokenHeight / bgImg.height);
  12616. }
  12617. }
  12618. }
  12619. var remainTruncWidth = truncate && topWidth != null
  12620. ? topWidth - lineWidth : null;
  12621. if (remainTruncWidth != null && remainTruncWidth < token.width) {
  12622. if (!tokenWidthNotSpecified || remainTruncWidth < paddingH) {
  12623. token.text = '';
  12624. token.width = token.contentWidth = 0;
  12625. }
  12626. else {
  12627. token.text = truncateText(token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
  12628. token.width = token.contentWidth = getWidth(token.text, font);
  12629. }
  12630. }
  12631. else {
  12632. token.contentWidth = getWidth(token.text, font);
  12633. }
  12634. }
  12635. token.width += paddingH;
  12636. lineWidth += token.width;
  12637. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  12638. }
  12639. finishLine(line, lineWidth, lineHeight);
  12640. }
  12641. contentBlock.outerWidth = contentBlock.width = retrieve2(topWidth, calculatedWidth);
  12642. contentBlock.outerHeight = contentBlock.height = retrieve2(topHeight, calculatedHeight);
  12643. contentBlock.contentHeight = calculatedHeight;
  12644. contentBlock.contentWidth = calculatedWidth;
  12645. if (stlPadding) {
  12646. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  12647. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  12648. }
  12649. for (var i = 0; i < pendingList.length; i++) {
  12650. var token = pendingList[i];
  12651. var percentWidth = token.percentWidth;
  12652. token.width = parseInt(percentWidth, 10) / 100 * contentBlock.width;
  12653. }
  12654. return contentBlock;
  12655. }
  12656. function pushTokens(block, str, style, wrapInfo, styleName) {
  12657. var isEmptyStr = str === '';
  12658. var tokenStyle = styleName && style.rich[styleName] || {};
  12659. var lines = block.lines;
  12660. var font = tokenStyle.font || style.font;
  12661. var newLine = false;
  12662. var strLines;
  12663. var linesWidths;
  12664. if (wrapInfo) {
  12665. var tokenPadding = tokenStyle.padding;
  12666. var tokenPaddingH = tokenPadding ? tokenPadding[1] + tokenPadding[3] : 0;
  12667. if (tokenStyle.width != null && tokenStyle.width !== 'auto') {
  12668. var outerWidth_1 = parsePercent(tokenStyle.width, wrapInfo.width) + tokenPaddingH;
  12669. if (lines.length > 0) {
  12670. if (outerWidth_1 + wrapInfo.accumWidth > wrapInfo.width) {
  12671. strLines = str.split('\n');
  12672. newLine = true;
  12673. }
  12674. }
  12675. wrapInfo.accumWidth = outerWidth_1;
  12676. }
  12677. else {
  12678. var res = wrapText(str, font, wrapInfo.width, wrapInfo.breakAll, wrapInfo.accumWidth);
  12679. wrapInfo.accumWidth = res.accumWidth + tokenPaddingH;
  12680. linesWidths = res.linesWidths;
  12681. strLines = res.lines;
  12682. }
  12683. }
  12684. else {
  12685. strLines = str.split('\n');
  12686. }
  12687. for (var i = 0; i < strLines.length; i++) {
  12688. var text = strLines[i];
  12689. var token = new RichTextToken();
  12690. token.styleName = styleName;
  12691. token.text = text;
  12692. token.isLineHolder = !text && !isEmptyStr;
  12693. if (typeof tokenStyle.width === 'number') {
  12694. token.width = tokenStyle.width;
  12695. }
  12696. else {
  12697. token.width = linesWidths
  12698. ? linesWidths[i]
  12699. : getWidth(text, font);
  12700. }
  12701. if (!i && !newLine) {
  12702. var tokens = (lines[lines.length - 1] || (lines[0] = new RichTextLine())).tokens;
  12703. var tokensLen = tokens.length;
  12704. (tokensLen === 1 && tokens[0].isLineHolder)
  12705. ? (tokens[0] = token)
  12706. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  12707. }
  12708. else {
  12709. lines.push(new RichTextLine([token]));
  12710. }
  12711. }
  12712. }
  12713. function isAlphabeticLetter(ch) {
  12714. var code = ch.charCodeAt(0);
  12715. return code >= 0x20 && code <= 0x24F
  12716. || code >= 0x370 && code <= 0x10FF
  12717. || code >= 0x1200 && code <= 0x13FF
  12718. || code >= 0x1E00 && code <= 0x206F;
  12719. }
  12720. var breakCharMap = reduce(',&?/;] '.split(''), function (obj, ch) {
  12721. obj[ch] = true;
  12722. return obj;
  12723. }, {});
  12724. function isWordBreakChar(ch) {
  12725. if (isAlphabeticLetter(ch)) {
  12726. if (breakCharMap[ch]) {
  12727. return true;
  12728. }
  12729. return false;
  12730. }
  12731. return true;
  12732. }
  12733. function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
  12734. var lines = [];
  12735. var linesWidths = [];
  12736. var line = '';
  12737. var currentWord = '';
  12738. var currentWordWidth = 0;
  12739. var accumWidth = 0;
  12740. for (var i = 0; i < text.length; i++) {
  12741. var ch = text.charAt(i);
  12742. if (ch === '\n') {
  12743. if (currentWord) {
  12744. line += currentWord;
  12745. accumWidth += currentWordWidth;
  12746. }
  12747. lines.push(line);
  12748. linesWidths.push(accumWidth);
  12749. line = '';
  12750. currentWord = '';
  12751. currentWordWidth = 0;
  12752. accumWidth = 0;
  12753. continue;
  12754. }
  12755. var chWidth = getWidth(ch, font);
  12756. var inWord = isBreakAll ? false : !isWordBreakChar(ch);
  12757. if (!lines.length
  12758. ? lastAccumWidth + accumWidth + chWidth > lineWidth
  12759. : accumWidth + chWidth > lineWidth) {
  12760. if (!accumWidth) {
  12761. if (inWord) {
  12762. lines.push(currentWord);
  12763. linesWidths.push(currentWordWidth);
  12764. currentWord = ch;
  12765. currentWordWidth = chWidth;
  12766. }
  12767. else {
  12768. lines.push(ch);
  12769. linesWidths.push(chWidth);
  12770. }
  12771. }
  12772. else if (line || currentWord) {
  12773. if (inWord) {
  12774. if (!line) {
  12775. line = currentWord;
  12776. currentWord = '';
  12777. currentWordWidth = 0;
  12778. accumWidth = currentWordWidth;
  12779. }
  12780. lines.push(line);
  12781. linesWidths.push(accumWidth - currentWordWidth);
  12782. currentWord += ch;
  12783. currentWordWidth += chWidth;
  12784. line = '';
  12785. accumWidth = currentWordWidth;
  12786. }
  12787. else {
  12788. if (currentWord) {
  12789. line += currentWord;
  12790. currentWord = '';
  12791. currentWordWidth = 0;
  12792. }
  12793. lines.push(line);
  12794. linesWidths.push(accumWidth);
  12795. line = ch;
  12796. accumWidth = chWidth;
  12797. }
  12798. }
  12799. continue;
  12800. }
  12801. accumWidth += chWidth;
  12802. if (inWord) {
  12803. currentWord += ch;
  12804. currentWordWidth += chWidth;
  12805. }
  12806. else {
  12807. if (currentWord) {
  12808. line += currentWord;
  12809. currentWord = '';
  12810. currentWordWidth = 0;
  12811. }
  12812. line += ch;
  12813. }
  12814. }
  12815. if (!lines.length && !line) {
  12816. line = text;
  12817. currentWord = '';
  12818. currentWordWidth = 0;
  12819. }
  12820. if (currentWord) {
  12821. line += currentWord;
  12822. }
  12823. if (line) {
  12824. lines.push(line);
  12825. linesWidths.push(accumWidth);
  12826. }
  12827. if (lines.length === 1) {
  12828. accumWidth += lastAccumWidth;
  12829. }
  12830. return {
  12831. accumWidth: accumWidth,
  12832. lines: lines,
  12833. linesWidths: linesWidths
  12834. };
  12835. }
  12836. var DEFAULT_RICH_TEXT_COLOR = {
  12837. fill: '#000'
  12838. };
  12839. var DEFAULT_STROKE_LINE_WIDTH = 2;
  12840. var DEFAULT_TEXT_ANIMATION_PROPS = {
  12841. style: defaults({
  12842. fill: true,
  12843. stroke: true,
  12844. fillOpacity: true,
  12845. strokeOpacity: true,
  12846. lineWidth: true,
  12847. fontSize: true,
  12848. lineHeight: true,
  12849. width: true,
  12850. height: true,
  12851. textShadowColor: true,
  12852. textShadowBlur: true,
  12853. textShadowOffsetX: true,
  12854. textShadowOffsetY: true,
  12855. backgroundColor: true,
  12856. padding: true,
  12857. borderColor: true,
  12858. borderWidth: true,
  12859. borderRadius: true
  12860. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  12861. };
  12862. var ZRText = (function (_super) {
  12863. __extends(ZRText, _super);
  12864. function ZRText(opts) {
  12865. var _this = _super.call(this) || this;
  12866. _this.type = 'text';
  12867. _this._children = [];
  12868. _this._defaultStyle = DEFAULT_RICH_TEXT_COLOR;
  12869. _this.attr(opts);
  12870. return _this;
  12871. }
  12872. ZRText.prototype.childrenRef = function () {
  12873. return this._children;
  12874. };
  12875. ZRText.prototype.update = function () {
  12876. _super.prototype.update.call(this);
  12877. if (this.styleChanged()) {
  12878. this._updateSubTexts();
  12879. }
  12880. for (var i = 0; i < this._children.length; i++) {
  12881. var child = this._children[i];
  12882. child.zlevel = this.zlevel;
  12883. child.z = this.z;
  12884. child.z2 = this.z2;
  12885. child.culling = this.culling;
  12886. child.cursor = this.cursor;
  12887. child.invisible = this.invisible;
  12888. }
  12889. };
  12890. ZRText.prototype.updateTransform = function () {
  12891. var innerTransformable = this.innerTransformable;
  12892. if (innerTransformable) {
  12893. innerTransformable.updateTransform();
  12894. if (innerTransformable.transform) {
  12895. this.transform = innerTransformable.transform;
  12896. }
  12897. }
  12898. else {
  12899. _super.prototype.updateTransform.call(this);
  12900. }
  12901. };
  12902. ZRText.prototype.getLocalTransform = function (m) {
  12903. var innerTransformable = this.innerTransformable;
  12904. return innerTransformable
  12905. ? innerTransformable.getLocalTransform(m)
  12906. : _super.prototype.getLocalTransform.call(this, m);
  12907. };
  12908. ZRText.prototype.getComputedTransform = function () {
  12909. if (this.__hostTarget) {
  12910. this.__hostTarget.getComputedTransform();
  12911. this.__hostTarget.updateInnerText(true);
  12912. }
  12913. return _super.prototype.getComputedTransform.call(this);
  12914. };
  12915. ZRText.prototype._updateSubTexts = function () {
  12916. this._childCursor = 0;
  12917. normalizeTextStyle(this.style);
  12918. this.style.rich
  12919. ? this._updateRichTexts()
  12920. : this._updatePlainTexts();
  12921. this._children.length = this._childCursor;
  12922. this.styleUpdated();
  12923. };
  12924. ZRText.prototype.addSelfToZr = function (zr) {
  12925. _super.prototype.addSelfToZr.call(this, zr);
  12926. for (var i = 0; i < this._children.length; i++) {
  12927. this._children[i].__zr = zr;
  12928. }
  12929. };
  12930. ZRText.prototype.removeSelfFromZr = function (zr) {
  12931. _super.prototype.removeSelfFromZr.call(this, zr);
  12932. for (var i = 0; i < this._children.length; i++) {
  12933. this._children[i].__zr = null;
  12934. }
  12935. };
  12936. ZRText.prototype.getBoundingRect = function () {
  12937. if (this.styleChanged()) {
  12938. this._updateSubTexts();
  12939. }
  12940. if (!this._rect) {
  12941. var tmpRect = new BoundingRect(0, 0, 0, 0);
  12942. var children = this._children;
  12943. var tmpMat = [];
  12944. var rect = null;
  12945. for (var i = 0; i < children.length; i++) {
  12946. var child = children[i];
  12947. var childRect = child.getBoundingRect();
  12948. var transform = child.getLocalTransform(tmpMat);
  12949. if (transform) {
  12950. tmpRect.copy(childRect);
  12951. tmpRect.applyTransform(transform);
  12952. rect = rect || tmpRect.clone();
  12953. rect.union(tmpRect);
  12954. }
  12955. else {
  12956. rect = rect || childRect.clone();
  12957. rect.union(childRect);
  12958. }
  12959. }
  12960. this._rect = rect || tmpRect;
  12961. }
  12962. return this._rect;
  12963. };
  12964. ZRText.prototype.setDefaultTextStyle = function (defaultTextStyle) {
  12965. this._defaultStyle = defaultTextStyle || DEFAULT_RICH_TEXT_COLOR;
  12966. };
  12967. ZRText.prototype.setTextContent = function (textContent) {
  12968. {
  12969. throw new Error('Can\'t attach text on another text');
  12970. }
  12971. };
  12972. ZRText.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  12973. if (!sourceStyle) {
  12974. return targetStyle;
  12975. }
  12976. var sourceRich = sourceStyle.rich;
  12977. var targetRich = targetStyle.rich || (sourceRich && {});
  12978. extend(targetStyle, sourceStyle);
  12979. if (sourceRich && targetRich) {
  12980. this._mergeRich(targetRich, sourceRich);
  12981. targetStyle.rich = targetRich;
  12982. }
  12983. else if (targetRich) {
  12984. targetStyle.rich = targetRich;
  12985. }
  12986. return targetStyle;
  12987. };
  12988. ZRText.prototype._mergeRich = function (targetRich, sourceRich) {
  12989. var richNames = keys(sourceRich);
  12990. for (var i = 0; i < richNames.length; i++) {
  12991. var richName = richNames[i];
  12992. targetRich[richName] = targetRich[richName] || {};
  12993. extend(targetRich[richName], sourceRich[richName]);
  12994. }
  12995. };
  12996. ZRText.prototype.getAnimationStyleProps = function () {
  12997. return DEFAULT_TEXT_ANIMATION_PROPS;
  12998. };
  12999. ZRText.prototype._getOrCreateChild = function (Ctor) {
  13000. var child = this._children[this._childCursor];
  13001. if (!child || !(child instanceof Ctor)) {
  13002. child = new Ctor();
  13003. }
  13004. this._children[this._childCursor++] = child;
  13005. child.__zr = this.__zr;
  13006. child.parent = this;
  13007. return child;
  13008. };
  13009. ZRText.prototype._updatePlainTexts = function () {
  13010. var style = this.style;
  13011. var textFont = style.font || DEFAULT_FONT;
  13012. var textPadding = style.padding;
  13013. var text = getStyleText(style);
  13014. var contentBlock = parsePlainText(text, style);
  13015. var needDrawBg = needDrawBackground(style);
  13016. var bgColorDrawn = !!(style.backgroundColor);
  13017. var outerHeight = contentBlock.outerHeight;
  13018. var outerWidth = contentBlock.outerWidth;
  13019. var contentWidth = contentBlock.contentWidth;
  13020. var textLines = contentBlock.lines;
  13021. var lineHeight = contentBlock.lineHeight;
  13022. var defaultStyle = this._defaultStyle;
  13023. var baseX = style.x || 0;
  13024. var baseY = style.y || 0;
  13025. var textAlign = style.align || defaultStyle.align || 'left';
  13026. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
  13027. var textX = baseX;
  13028. var textY = adjustTextY$1(baseY, contentBlock.contentHeight, verticalAlign);
  13029. if (needDrawBg || textPadding) {
  13030. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  13031. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  13032. needDrawBg && this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  13033. }
  13034. textY += lineHeight / 2;
  13035. if (textPadding) {
  13036. textX = getTextXForPadding(baseX, textAlign, textPadding);
  13037. if (verticalAlign === 'top') {
  13038. textY += textPadding[0];
  13039. }
  13040. else if (verticalAlign === 'bottom') {
  13041. textY -= textPadding[2];
  13042. }
  13043. }
  13044. var defaultLineWidth = 0;
  13045. var useDefaultFill = false;
  13046. var textFill = getFill('fill' in style
  13047. ? style.fill
  13048. : (useDefaultFill = true, defaultStyle.fill));
  13049. var textStroke = getStroke('stroke' in style
  13050. ? style.stroke
  13051. : (!bgColorDrawn
  13052. && (!defaultStyle.autoStroke || useDefaultFill))
  13053. ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  13054. : null);
  13055. var hasShadow = style.textShadowBlur > 0;
  13056. var fixedBoundingRect = style.width != null
  13057. && (style.overflow === 'truncate' || style.overflow === 'break' || style.overflow === 'breakAll');
  13058. var calculatedLineHeight = contentBlock.calculatedLineHeight;
  13059. for (var i = 0; i < textLines.length; i++) {
  13060. var el = this._getOrCreateChild(TSpan);
  13061. var subElStyle = el.createStyle();
  13062. el.useStyle(subElStyle);
  13063. subElStyle.text = textLines[i];
  13064. subElStyle.x = textX;
  13065. subElStyle.y = textY;
  13066. if (textAlign) {
  13067. subElStyle.textAlign = textAlign;
  13068. }
  13069. subElStyle.textBaseline = 'middle';
  13070. subElStyle.opacity = style.opacity;
  13071. subElStyle.strokeFirst = true;
  13072. if (hasShadow) {
  13073. subElStyle.shadowBlur = style.textShadowBlur || 0;
  13074. subElStyle.shadowColor = style.textShadowColor || 'transparent';
  13075. subElStyle.shadowOffsetX = style.textShadowOffsetX || 0;
  13076. subElStyle.shadowOffsetY = style.textShadowOffsetY || 0;
  13077. }
  13078. subElStyle.stroke = textStroke;
  13079. subElStyle.fill = textFill;
  13080. if (textStroke) {
  13081. subElStyle.lineWidth = style.lineWidth || defaultLineWidth;
  13082. subElStyle.lineDash = style.lineDash;
  13083. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13084. }
  13085. subElStyle.font = textFont;
  13086. setSeparateFont(subElStyle, style);
  13087. textY += lineHeight;
  13088. if (fixedBoundingRect) {
  13089. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, style.width, subElStyle.textAlign), adjustTextY$1(subElStyle.y, calculatedLineHeight, subElStyle.textBaseline), contentWidth, calculatedLineHeight));
  13090. }
  13091. }
  13092. };
  13093. ZRText.prototype._updateRichTexts = function () {
  13094. var style = this.style;
  13095. var text = getStyleText(style);
  13096. var contentBlock = parseRichText(text, style);
  13097. var contentWidth = contentBlock.width;
  13098. var outerWidth = contentBlock.outerWidth;
  13099. var outerHeight = contentBlock.outerHeight;
  13100. var textPadding = style.padding;
  13101. var baseX = style.x || 0;
  13102. var baseY = style.y || 0;
  13103. var defaultStyle = this._defaultStyle;
  13104. var textAlign = style.align || defaultStyle.align;
  13105. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
  13106. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  13107. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  13108. var xLeft = boxX;
  13109. var lineTop = boxY;
  13110. if (textPadding) {
  13111. xLeft += textPadding[3];
  13112. lineTop += textPadding[0];
  13113. }
  13114. var xRight = xLeft + contentWidth;
  13115. if (needDrawBackground(style)) {
  13116. this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  13117. }
  13118. var bgColorDrawn = !!(style.backgroundColor);
  13119. for (var i = 0; i < contentBlock.lines.length; i++) {
  13120. var line = contentBlock.lines[i];
  13121. var tokens = line.tokens;
  13122. var tokenCount = tokens.length;
  13123. var lineHeight = line.lineHeight;
  13124. var remainedWidth = line.width;
  13125. var leftIndex = 0;
  13126. var lineXLeft = xLeft;
  13127. var lineXRight = xRight;
  13128. var rightIndex = tokenCount - 1;
  13129. var token = void 0;
  13130. while (leftIndex < tokenCount
  13131. && (token = tokens[leftIndex], !token.align || token.align === 'left')) {
  13132. this._placeToken(token, style, lineHeight, lineTop, lineXLeft, 'left', bgColorDrawn);
  13133. remainedWidth -= token.width;
  13134. lineXLeft += token.width;
  13135. leftIndex++;
  13136. }
  13137. while (rightIndex >= 0
  13138. && (token = tokens[rightIndex], token.align === 'right')) {
  13139. this._placeToken(token, style, lineHeight, lineTop, lineXRight, 'right', bgColorDrawn);
  13140. remainedWidth -= token.width;
  13141. lineXRight -= token.width;
  13142. rightIndex--;
  13143. }
  13144. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - remainedWidth) / 2;
  13145. while (leftIndex <= rightIndex) {
  13146. token = tokens[leftIndex];
  13147. this._placeToken(token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center', bgColorDrawn);
  13148. lineXLeft += token.width;
  13149. leftIndex++;
  13150. }
  13151. lineTop += lineHeight;
  13152. }
  13153. };
  13154. ZRText.prototype._placeToken = function (token, style, lineHeight, lineTop, x, textAlign, parentBgColorDrawn) {
  13155. var tokenStyle = style.rich[token.styleName] || {};
  13156. tokenStyle.text = token.text;
  13157. var verticalAlign = token.verticalAlign;
  13158. var y = lineTop + lineHeight / 2;
  13159. if (verticalAlign === 'top') {
  13160. y = lineTop + token.height / 2;
  13161. }
  13162. else if (verticalAlign === 'bottom') {
  13163. y = lineTop + lineHeight - token.height / 2;
  13164. }
  13165. var needDrawBg = !token.isLineHolder && needDrawBackground(tokenStyle);
  13166. needDrawBg && this._renderBackground(tokenStyle, style, textAlign === 'right'
  13167. ? x - token.width
  13168. : textAlign === 'center'
  13169. ? x - token.width / 2
  13170. : x, y - token.height / 2, token.width, token.height);
  13171. var bgColorDrawn = !!tokenStyle.backgroundColor;
  13172. var textPadding = token.textPadding;
  13173. if (textPadding) {
  13174. x = getTextXForPadding(x, textAlign, textPadding);
  13175. y -= token.height / 2 - textPadding[0] - token.innerHeight / 2;
  13176. }
  13177. var el = this._getOrCreateChild(TSpan);
  13178. var subElStyle = el.createStyle();
  13179. el.useStyle(subElStyle);
  13180. var defaultStyle = this._defaultStyle;
  13181. var useDefaultFill = false;
  13182. var defaultLineWidth = 0;
  13183. var textFill = getFill('fill' in tokenStyle ? tokenStyle.fill
  13184. : 'fill' in style ? style.fill
  13185. : (useDefaultFill = true, defaultStyle.fill));
  13186. var textStroke = getStroke('stroke' in tokenStyle ? tokenStyle.stroke
  13187. : 'stroke' in style ? style.stroke
  13188. : (!bgColorDrawn
  13189. && !parentBgColorDrawn
  13190. && (!defaultStyle.autoStroke || useDefaultFill)) ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  13191. : null);
  13192. var hasShadow = tokenStyle.textShadowBlur > 0
  13193. || style.textShadowBlur > 0;
  13194. subElStyle.text = token.text;
  13195. subElStyle.x = x;
  13196. subElStyle.y = y;
  13197. if (hasShadow) {
  13198. subElStyle.shadowBlur = tokenStyle.textShadowBlur || style.textShadowBlur || 0;
  13199. subElStyle.shadowColor = tokenStyle.textShadowColor || style.textShadowColor || 'transparent';
  13200. subElStyle.shadowOffsetX = tokenStyle.textShadowOffsetX || style.textShadowOffsetX || 0;
  13201. subElStyle.shadowOffsetY = tokenStyle.textShadowOffsetY || style.textShadowOffsetY || 0;
  13202. }
  13203. subElStyle.textAlign = textAlign;
  13204. subElStyle.textBaseline = 'middle';
  13205. subElStyle.font = token.font || DEFAULT_FONT;
  13206. subElStyle.opacity = retrieve3(tokenStyle.opacity, style.opacity, 1);
  13207. setSeparateFont(subElStyle, tokenStyle);
  13208. if (textStroke) {
  13209. subElStyle.lineWidth = retrieve3(tokenStyle.lineWidth, style.lineWidth, defaultLineWidth);
  13210. subElStyle.lineDash = retrieve2(tokenStyle.lineDash, style.lineDash);
  13211. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13212. subElStyle.stroke = textStroke;
  13213. }
  13214. if (textFill) {
  13215. subElStyle.fill = textFill;
  13216. }
  13217. var textWidth = token.contentWidth;
  13218. var textHeight = token.contentHeight;
  13219. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, textWidth, subElStyle.textAlign), adjustTextY$1(subElStyle.y, textHeight, subElStyle.textBaseline), textWidth, textHeight));
  13220. };
  13221. ZRText.prototype._renderBackground = function (style, topStyle, x, y, width, height) {
  13222. var textBackgroundColor = style.backgroundColor;
  13223. var textBorderWidth = style.borderWidth;
  13224. var textBorderColor = style.borderColor;
  13225. var isImageBg = textBackgroundColor && textBackgroundColor.image;
  13226. var isPlainOrGradientBg = textBackgroundColor && !isImageBg;
  13227. var textBorderRadius = style.borderRadius;
  13228. var self = this;
  13229. var rectEl;
  13230. var imgEl;
  13231. if (isPlainOrGradientBg || style.lineHeight || (textBorderWidth && textBorderColor)) {
  13232. rectEl = this._getOrCreateChild(Rect);
  13233. rectEl.useStyle(rectEl.createStyle());
  13234. rectEl.style.fill = null;
  13235. var rectShape = rectEl.shape;
  13236. rectShape.x = x;
  13237. rectShape.y = y;
  13238. rectShape.width = width;
  13239. rectShape.height = height;
  13240. rectShape.r = textBorderRadius;
  13241. rectEl.dirtyShape();
  13242. }
  13243. if (isPlainOrGradientBg) {
  13244. var rectStyle = rectEl.style;
  13245. rectStyle.fill = textBackgroundColor || null;
  13246. rectStyle.fillOpacity = retrieve2(style.fillOpacity, 1);
  13247. }
  13248. else if (isImageBg) {
  13249. imgEl = this._getOrCreateChild(ZRImage);
  13250. imgEl.onload = function () {
  13251. self.dirtyStyle();
  13252. };
  13253. var imgStyle = imgEl.style;
  13254. imgStyle.image = textBackgroundColor.image;
  13255. imgStyle.x = x;
  13256. imgStyle.y = y;
  13257. imgStyle.width = width;
  13258. imgStyle.height = height;
  13259. }
  13260. if (textBorderWidth && textBorderColor) {
  13261. var rectStyle = rectEl.style;
  13262. rectStyle.lineWidth = textBorderWidth;
  13263. rectStyle.stroke = textBorderColor;
  13264. rectStyle.strokeOpacity = retrieve2(style.strokeOpacity, 1);
  13265. rectStyle.lineDash = style.borderDash;
  13266. rectStyle.lineDashOffset = style.borderDashOffset || 0;
  13267. rectEl.strokeContainThreshold = 0;
  13268. if (rectEl.hasFill() && rectEl.hasStroke()) {
  13269. rectStyle.strokeFirst = true;
  13270. rectStyle.lineWidth *= 2;
  13271. }
  13272. }
  13273. var commonStyle = (rectEl || imgEl).style;
  13274. commonStyle.shadowBlur = style.shadowBlur || 0;
  13275. commonStyle.shadowColor = style.shadowColor || 'transparent';
  13276. commonStyle.shadowOffsetX = style.shadowOffsetX || 0;
  13277. commonStyle.shadowOffsetY = style.shadowOffsetY || 0;
  13278. commonStyle.opacity = retrieve3(style.opacity, topStyle.opacity, 1);
  13279. };
  13280. ZRText.makeFont = function (style) {
  13281. var font = '';
  13282. if (hasSeparateFont(style)) {
  13283. font = [
  13284. style.fontStyle,
  13285. style.fontWeight,
  13286. parseFontSize(style.fontSize),
  13287. style.fontFamily || 'sans-serif'
  13288. ].join(' ');
  13289. }
  13290. return font && trim(font) || style.textFont || style.font;
  13291. };
  13292. return ZRText;
  13293. }(Displayable));
  13294. var VALID_TEXT_ALIGN = { left: true, right: 1, center: 1 };
  13295. var VALID_TEXT_VERTICAL_ALIGN = { top: 1, bottom: 1, middle: 1 };
  13296. var FONT_PARTS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily'];
  13297. function parseFontSize(fontSize) {
  13298. if (typeof fontSize === 'string'
  13299. && (fontSize.indexOf('px') !== -1
  13300. || fontSize.indexOf('rem') !== -1
  13301. || fontSize.indexOf('em') !== -1)) {
  13302. return fontSize;
  13303. }
  13304. else if (!isNaN(+fontSize)) {
  13305. return fontSize + 'px';
  13306. }
  13307. else {
  13308. return DEFAULT_FONT_SIZE + 'px';
  13309. }
  13310. }
  13311. function setSeparateFont(targetStyle, sourceStyle) {
  13312. for (var i = 0; i < FONT_PARTS.length; i++) {
  13313. var fontProp = FONT_PARTS[i];
  13314. var val = sourceStyle[fontProp];
  13315. if (val != null) {
  13316. targetStyle[fontProp] = val;
  13317. }
  13318. }
  13319. }
  13320. function hasSeparateFont(style) {
  13321. return style.fontSize != null || style.fontFamily || style.fontWeight;
  13322. }
  13323. function normalizeTextStyle(style) {
  13324. normalizeStyle(style);
  13325. each(style.rich, normalizeStyle);
  13326. return style;
  13327. }
  13328. function normalizeStyle(style) {
  13329. if (style) {
  13330. style.font = ZRText.makeFont(style);
  13331. var textAlign = style.align;
  13332. textAlign === 'middle' && (textAlign = 'center');
  13333. style.align = (textAlign == null || VALID_TEXT_ALIGN[textAlign]) ? textAlign : 'left';
  13334. var verticalAlign = style.verticalAlign;
  13335. verticalAlign === 'center' && (verticalAlign = 'middle');
  13336. style.verticalAlign = (verticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[verticalAlign]) ? verticalAlign : 'top';
  13337. var textPadding = style.padding;
  13338. if (textPadding) {
  13339. style.padding = normalizeCssArray(style.padding);
  13340. }
  13341. }
  13342. }
  13343. function getStroke(stroke, lineWidth) {
  13344. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  13345. ? null
  13346. : (stroke.image || stroke.colorStops)
  13347. ? '#000'
  13348. : stroke;
  13349. }
  13350. function getFill(fill) {
  13351. return (fill == null || fill === 'none')
  13352. ? null
  13353. : (fill.image || fill.colorStops)
  13354. ? '#000'
  13355. : fill;
  13356. }
  13357. function getTextXForPadding(x, textAlign, textPadding) {
  13358. return textAlign === 'right'
  13359. ? (x - textPadding[1])
  13360. : textAlign === 'center'
  13361. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  13362. : (x + textPadding[3]);
  13363. }
  13364. function getStyleText(style) {
  13365. var text = style.text;
  13366. text != null && (text += '');
  13367. return text;
  13368. }
  13369. function needDrawBackground(style) {
  13370. return !!(style.backgroundColor
  13371. || style.lineHeight
  13372. || (style.borderWidth && style.borderColor));
  13373. }
  13374. var ArcShape = (function () {
  13375. function ArcShape() {
  13376. this.cx = 0;
  13377. this.cy = 0;
  13378. this.r = 0;
  13379. this.startAngle = 0;
  13380. this.endAngle = Math.PI * 2;
  13381. this.clockwise = true;
  13382. }
  13383. return ArcShape;
  13384. }());
  13385. var Arc = (function (_super) {
  13386. __extends(Arc, _super);
  13387. function Arc(opts) {
  13388. return _super.call(this, opts) || this;
  13389. }
  13390. Arc.prototype.getDefaultStyle = function () {
  13391. return {
  13392. stroke: '#000',
  13393. fill: null
  13394. };
  13395. };
  13396. Arc.prototype.getDefaultShape = function () {
  13397. return new ArcShape();
  13398. };
  13399. Arc.prototype.buildPath = function (ctx, shape) {
  13400. var x = shape.cx;
  13401. var y = shape.cy;
  13402. var r = Math.max(shape.r, 0);
  13403. var startAngle = shape.startAngle;
  13404. var endAngle = shape.endAngle;
  13405. var clockwise = shape.clockwise;
  13406. var unitX = Math.cos(startAngle);
  13407. var unitY = Math.sin(startAngle);
  13408. ctx.moveTo(unitX * r + x, unitY * r + y);
  13409. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13410. };
  13411. return Arc;
  13412. }(Path));
  13413. Arc.prototype.type = 'arc';
  13414. var out = [];
  13415. var BezierCurveShape = (function () {
  13416. function BezierCurveShape() {
  13417. this.x1 = 0;
  13418. this.y1 = 0;
  13419. this.x2 = 0;
  13420. this.y2 = 0;
  13421. this.cpx1 = 0;
  13422. this.cpy1 = 0;
  13423. this.percent = 1;
  13424. }
  13425. return BezierCurveShape;
  13426. }());
  13427. function someVectorAt(shape, t, isTangent) {
  13428. var cpx2 = shape.cpx2;
  13429. var cpy2 = shape.cpy2;
  13430. if (cpx2 != null || cpy2 != null) {
  13431. return [
  13432. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  13433. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  13434. ];
  13435. }
  13436. else {
  13437. return [
  13438. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  13439. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  13440. ];
  13441. }
  13442. }
  13443. var BezierCurve = (function (_super) {
  13444. __extends(BezierCurve, _super);
  13445. function BezierCurve(opts) {
  13446. return _super.call(this, opts) || this;
  13447. }
  13448. BezierCurve.prototype.getDefaultStyle = function () {
  13449. return {
  13450. stroke: '#000',
  13451. fill: null
  13452. };
  13453. };
  13454. BezierCurve.prototype.getDefaultShape = function () {
  13455. return new BezierCurveShape();
  13456. };
  13457. BezierCurve.prototype.buildPath = function (ctx, shape) {
  13458. var x1 = shape.x1;
  13459. var y1 = shape.y1;
  13460. var x2 = shape.x2;
  13461. var y2 = shape.y2;
  13462. var cpx1 = shape.cpx1;
  13463. var cpy1 = shape.cpy1;
  13464. var cpx2 = shape.cpx2;
  13465. var cpy2 = shape.cpy2;
  13466. var percent = shape.percent;
  13467. if (percent === 0) {
  13468. return;
  13469. }
  13470. ctx.moveTo(x1, y1);
  13471. if (cpx2 == null || cpy2 == null) {
  13472. if (percent < 1) {
  13473. quadraticSubdivide(x1, cpx1, x2, percent, out);
  13474. cpx1 = out[1];
  13475. x2 = out[2];
  13476. quadraticSubdivide(y1, cpy1, y2, percent, out);
  13477. cpy1 = out[1];
  13478. y2 = out[2];
  13479. }
  13480. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  13481. }
  13482. else {
  13483. if (percent < 1) {
  13484. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  13485. cpx1 = out[1];
  13486. cpx2 = out[2];
  13487. x2 = out[3];
  13488. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  13489. cpy1 = out[1];
  13490. cpy2 = out[2];
  13491. y2 = out[3];
  13492. }
  13493. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  13494. }
  13495. };
  13496. BezierCurve.prototype.pointAt = function (t) {
  13497. return someVectorAt(this.shape, t, false);
  13498. };
  13499. BezierCurve.prototype.tangentAt = function (t) {
  13500. var p = someVectorAt(this.shape, t, true);
  13501. return normalize(p, p);
  13502. };
  13503. return BezierCurve;
  13504. }(Path));
  13505. BezierCurve.prototype.type = 'bezier-curve';
  13506. var DropletShape = (function () {
  13507. function DropletShape() {
  13508. this.cx = 0;
  13509. this.cy = 0;
  13510. this.width = 0;
  13511. this.height = 0;
  13512. }
  13513. return DropletShape;
  13514. }());
  13515. var Droplet = (function (_super) {
  13516. __extends(Droplet, _super);
  13517. function Droplet(opts) {
  13518. return _super.call(this, opts) || this;
  13519. }
  13520. Droplet.prototype.getDefaultShape = function () {
  13521. return new DropletShape();
  13522. };
  13523. Droplet.prototype.buildPath = function (ctx, shape) {
  13524. var x = shape.cx;
  13525. var y = shape.cy;
  13526. var a = shape.width;
  13527. var b = shape.height;
  13528. ctx.moveTo(x, y + a);
  13529. ctx.bezierCurveTo(x + a, y + a, x + a * 3 / 2, y - a / 3, x, y - b);
  13530. ctx.bezierCurveTo(x - a * 3 / 2, y - a / 3, x - a, y + a, x, y + a);
  13531. ctx.closePath();
  13532. };
  13533. return Droplet;
  13534. }(Path));
  13535. Droplet.prototype.type = 'droplet';
  13536. var HeartShape = (function () {
  13537. function HeartShape() {
  13538. this.cx = 0;
  13539. this.cy = 0;
  13540. this.width = 0;
  13541. this.height = 0;
  13542. }
  13543. return HeartShape;
  13544. }());
  13545. var Heart = (function (_super) {
  13546. __extends(Heart, _super);
  13547. function Heart(opts) {
  13548. return _super.call(this, opts) || this;
  13549. }
  13550. Heart.prototype.getDefaultShape = function () {
  13551. return new HeartShape();
  13552. };
  13553. Heart.prototype.buildPath = function (ctx, shape) {
  13554. var x = shape.cx;
  13555. var y = shape.cy;
  13556. var a = shape.width;
  13557. var b = shape.height;
  13558. ctx.moveTo(x, y);
  13559. ctx.bezierCurveTo(x + a / 2, y - b * 2 / 3, x + a * 2, y + b / 3, x, y + b);
  13560. ctx.bezierCurveTo(x - a * 2, y + b / 3, x - a / 2, y - b * 2 / 3, x, y);
  13561. };
  13562. return Heart;
  13563. }(Path));
  13564. Heart.prototype.type = 'heart';
  13565. var PI$3 = Math.PI;
  13566. var sin = Math.sin;
  13567. var cos = Math.cos;
  13568. var IsogonShape = (function () {
  13569. function IsogonShape() {
  13570. this.x = 0;
  13571. this.y = 0;
  13572. this.r = 0;
  13573. this.n = 0;
  13574. }
  13575. return IsogonShape;
  13576. }());
  13577. var Isogon = (function (_super) {
  13578. __extends(Isogon, _super);
  13579. function Isogon(opts) {
  13580. return _super.call(this, opts) || this;
  13581. }
  13582. Isogon.prototype.getDefaultShape = function () {
  13583. return new IsogonShape();
  13584. };
  13585. Isogon.prototype.buildPath = function (ctx, shape) {
  13586. var n = shape.n;
  13587. if (!n || n < 2) {
  13588. return;
  13589. }
  13590. var x = shape.x;
  13591. var y = shape.y;
  13592. var r = shape.r;
  13593. var dStep = 2 * PI$3 / n;
  13594. var deg = -PI$3 / 2;
  13595. ctx.moveTo(x + r * cos(deg), y + r * sin(deg));
  13596. for (var i = 0, end = n - 1; i < end; i++) {
  13597. deg += dStep;
  13598. ctx.lineTo(x + r * cos(deg), y + r * sin(deg));
  13599. }
  13600. ctx.closePath();
  13601. return;
  13602. };
  13603. return Isogon;
  13604. }(Path));
  13605. Isogon.prototype.type = 'isogon';
  13606. var RingShape = (function () {
  13607. function RingShape() {
  13608. this.cx = 0;
  13609. this.cy = 0;
  13610. this.r = 0;
  13611. this.r0 = 0;
  13612. }
  13613. return RingShape;
  13614. }());
  13615. var Ring = (function (_super) {
  13616. __extends(Ring, _super);
  13617. function Ring(opts) {
  13618. return _super.call(this, opts) || this;
  13619. }
  13620. Ring.prototype.getDefaultShape = function () {
  13621. return new RingShape();
  13622. };
  13623. Ring.prototype.buildPath = function (ctx, shape) {
  13624. var x = shape.cx;
  13625. var y = shape.cy;
  13626. var PI2 = Math.PI * 2;
  13627. ctx.moveTo(x + shape.r, y);
  13628. ctx.arc(x, y, shape.r, 0, PI2, false);
  13629. ctx.moveTo(x + shape.r0, y);
  13630. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13631. };
  13632. return Ring;
  13633. }(Path));
  13634. Ring.prototype.type = 'ring';
  13635. var sin$1 = Math.sin;
  13636. var cos$1 = Math.cos;
  13637. var radian = Math.PI / 180;
  13638. var RoseShape = (function () {
  13639. function RoseShape() {
  13640. this.cx = 0;
  13641. this.cy = 0;
  13642. this.r = [];
  13643. this.k = 0;
  13644. this.n = 1;
  13645. }
  13646. return RoseShape;
  13647. }());
  13648. var Rose = (function (_super) {
  13649. __extends(Rose, _super);
  13650. function Rose(opts) {
  13651. return _super.call(this, opts) || this;
  13652. }
  13653. Rose.prototype.getDefaultStyle = function () {
  13654. return {
  13655. stroke: '#000',
  13656. fill: null
  13657. };
  13658. };
  13659. Rose.prototype.getDefaultShape = function () {
  13660. return new RoseShape();
  13661. };
  13662. Rose.prototype.buildPath = function (ctx, shape) {
  13663. var R = shape.r;
  13664. var k = shape.k;
  13665. var n = shape.n;
  13666. var x0 = shape.cx;
  13667. var y0 = shape.cy;
  13668. var x;
  13669. var y;
  13670. var r;
  13671. ctx.moveTo(x0, y0);
  13672. for (var i = 0, len = R.length; i < len; i++) {
  13673. r = R[i];
  13674. for (var j = 0; j <= 360 * n; j++) {
  13675. x = r
  13676. * sin$1(k / n * j % 360 * radian)
  13677. * cos$1(j * radian)
  13678. + x0;
  13679. y = r
  13680. * sin$1(k / n * j % 360 * radian)
  13681. * sin$1(j * radian)
  13682. + y0;
  13683. ctx.lineTo(x, y);
  13684. }
  13685. }
  13686. };
  13687. return Rose;
  13688. }(Path));
  13689. Rose.prototype.type = 'rose';
  13690. var PI$4 = Math.PI;
  13691. var cos$2 = Math.cos;
  13692. var sin$2 = Math.sin;
  13693. var StarShape = (function () {
  13694. function StarShape() {
  13695. this.cx = 0;
  13696. this.cy = 0;
  13697. this.n = 3;
  13698. this.r = 0;
  13699. }
  13700. return StarShape;
  13701. }());
  13702. var Star = (function (_super) {
  13703. __extends(Star, _super);
  13704. function Star(opts) {
  13705. return _super.call(this, opts) || this;
  13706. }
  13707. Star.prototype.getDefaultShape = function () {
  13708. return new StarShape();
  13709. };
  13710. Star.prototype.buildPath = function (ctx, shape) {
  13711. var n = shape.n;
  13712. if (!n || n < 2) {
  13713. return;
  13714. }
  13715. var x = shape.cx;
  13716. var y = shape.cy;
  13717. var r = shape.r;
  13718. var r0 = shape.r0;
  13719. if (r0 == null) {
  13720. r0 = n > 4
  13721. ? r * cos$2(2 * PI$4 / n) / cos$2(PI$4 / n)
  13722. : r / 3;
  13723. }
  13724. var dStep = PI$4 / n;
  13725. var deg = -PI$4 / 2;
  13726. var xStart = x + r * cos$2(deg);
  13727. var yStart = y + r * sin$2(deg);
  13728. deg += dStep;
  13729. ctx.moveTo(xStart, yStart);
  13730. for (var i = 0, end = n * 2 - 1, ri = void 0; i < end; i++) {
  13731. ri = i % 2 === 0 ? r0 : r;
  13732. ctx.lineTo(x + ri * cos$2(deg), y + ri * sin$2(deg));
  13733. deg += dStep;
  13734. }
  13735. ctx.closePath();
  13736. };
  13737. return Star;
  13738. }(Path));
  13739. Star.prototype.type = 'star';
  13740. var cos$3 = Math.cos;
  13741. var sin$3 = Math.sin;
  13742. var TrochoidShape = (function () {
  13743. function TrochoidShape() {
  13744. this.cx = 0;
  13745. this.cy = 0;
  13746. this.r = 0;
  13747. this.r0 = 0;
  13748. this.d = 0;
  13749. this.location = 'out';
  13750. }
  13751. return TrochoidShape;
  13752. }());
  13753. var Trochoid = (function (_super) {
  13754. __extends(Trochoid, _super);
  13755. function Trochoid(opts) {
  13756. return _super.call(this, opts) || this;
  13757. }
  13758. Trochoid.prototype.getDefaultStyle = function () {
  13759. return {
  13760. stroke: '#000',
  13761. fill: null
  13762. };
  13763. };
  13764. Trochoid.prototype.getDefaultShape = function () {
  13765. return new TrochoidShape();
  13766. };
  13767. Trochoid.prototype.buildPath = function (ctx, shape) {
  13768. var R = shape.r;
  13769. var r = shape.r0;
  13770. var d = shape.d;
  13771. var offsetX = shape.cx;
  13772. var offsetY = shape.cy;
  13773. var delta = shape.location === 'out' ? 1 : -1;
  13774. var x1;
  13775. var y1;
  13776. var x2;
  13777. var y2;
  13778. if (shape.location && R <= r) {
  13779. return;
  13780. }
  13781. var num = 0;
  13782. var i = 1;
  13783. var theta;
  13784. x1 = (R + delta * r) * cos$3(0)
  13785. - delta * d * cos$3(0) + offsetX;
  13786. y1 = (R + delta * r) * sin$3(0)
  13787. - d * sin$3(0) + offsetY;
  13788. ctx.moveTo(x1, y1);
  13789. do {
  13790. num++;
  13791. } while ((r * num) % (R + delta * r) !== 0);
  13792. do {
  13793. theta = Math.PI / 180 * i;
  13794. x2 = (R + delta * r) * cos$3(theta)
  13795. - delta * d * cos$3((R / r + delta) * theta)
  13796. + offsetX;
  13797. y2 = (R + delta * r) * sin$3(theta)
  13798. - d * sin$3((R / r + delta) * theta)
  13799. + offsetY;
  13800. ctx.lineTo(x2, y2);
  13801. i++;
  13802. } while (i <= (r * num) / (R + delta * r) * 360);
  13803. };
  13804. return Trochoid;
  13805. }(Path));
  13806. Trochoid.prototype.type = 'trochoid';
  13807. var Pattern = (function () {
  13808. function Pattern(image, repeat) {
  13809. this.image = image;
  13810. this.repeat = repeat;
  13811. this.x = 0;
  13812. this.y = 0;
  13813. this.rotation = 0;
  13814. this.scaleX = 1;
  13815. this.scaleY = 1;
  13816. }
  13817. return Pattern;
  13818. }());
  13819. var extent = [0, 0];
  13820. var extent2 = [0, 0];
  13821. var minTv$1 = new Point();
  13822. var maxTv$1 = new Point();
  13823. var OrientedBoundingRect = (function () {
  13824. function OrientedBoundingRect(rect, transform) {
  13825. this._corners = [];
  13826. this._axes = [];
  13827. this._origin = [0, 0];
  13828. for (var i = 0; i < 4; i++) {
  13829. this._corners[i] = new Point();
  13830. }
  13831. for (var i = 0; i < 2; i++) {
  13832. this._axes[i] = new Point();
  13833. }
  13834. if (rect) {
  13835. this.fromBoundingRect(rect, transform);
  13836. }
  13837. }
  13838. OrientedBoundingRect.prototype.fromBoundingRect = function (rect, transform) {
  13839. var corners = this._corners;
  13840. var axes = this._axes;
  13841. var x = rect.x;
  13842. var y = rect.y;
  13843. var x2 = x + rect.width;
  13844. var y2 = y + rect.height;
  13845. corners[0].set(x, y);
  13846. corners[1].set(x2, y);
  13847. corners[2].set(x2, y2);
  13848. corners[3].set(x, y2);
  13849. if (transform) {
  13850. for (var i = 0; i < 4; i++) {
  13851. corners[i].transform(transform);
  13852. }
  13853. }
  13854. Point.sub(axes[0], corners[1], corners[0]);
  13855. Point.sub(axes[1], corners[3], corners[0]);
  13856. axes[0].normalize();
  13857. axes[1].normalize();
  13858. for (var i = 0; i < 2; i++) {
  13859. this._origin[i] = axes[i].dot(corners[0]);
  13860. }
  13861. };
  13862. OrientedBoundingRect.prototype.intersect = function (other, mtv) {
  13863. var overlapped = true;
  13864. var noMtv = !mtv;
  13865. minTv$1.set(Infinity, Infinity);
  13866. maxTv$1.set(0, 0);
  13867. if (!this._intersectCheckOneSide(this, other, minTv$1, maxTv$1, noMtv, 1)) {
  13868. overlapped = false;
  13869. if (noMtv) {
  13870. return overlapped;
  13871. }
  13872. }
  13873. if (!this._intersectCheckOneSide(other, this, minTv$1, maxTv$1, noMtv, -1)) {
  13874. overlapped = false;
  13875. if (noMtv) {
  13876. return overlapped;
  13877. }
  13878. }
  13879. if (!noMtv) {
  13880. Point.copy(mtv, overlapped ? minTv$1 : maxTv$1);
  13881. }
  13882. return overlapped;
  13883. };
  13884. OrientedBoundingRect.prototype._intersectCheckOneSide = function (self, other, minTv, maxTv, noMtv, inverse) {
  13885. var overlapped = true;
  13886. for (var i = 0; i < 2; i++) {
  13887. var axis = this._axes[i];
  13888. this._getProjMinMaxOnAxis(i, self._corners, extent);
  13889. this._getProjMinMaxOnAxis(i, other._corners, extent2);
  13890. if (extent[1] < extent2[0] || extent[0] > extent2[1]) {
  13891. overlapped = false;
  13892. if (noMtv) {
  13893. return overlapped;
  13894. }
  13895. var dist0 = Math.abs(extent2[0] - extent[1]);
  13896. var dist1 = Math.abs(extent[0] - extent2[1]);
  13897. if (Math.min(dist0, dist1) > maxTv.len()) {
  13898. if (dist0 < dist1) {
  13899. Point.scale(maxTv, axis, -dist0 * inverse);
  13900. }
  13901. else {
  13902. Point.scale(maxTv, axis, dist1 * inverse);
  13903. }
  13904. }
  13905. }
  13906. else if (minTv) {
  13907. var dist0 = Math.abs(extent2[0] - extent[1]);
  13908. var dist1 = Math.abs(extent[0] - extent2[1]);
  13909. if (Math.min(dist0, dist1) < minTv.len()) {
  13910. if (dist0 < dist1) {
  13911. Point.scale(minTv, axis, dist0 * inverse);
  13912. }
  13913. else {
  13914. Point.scale(minTv, axis, -dist1 * inverse);
  13915. }
  13916. }
  13917. }
  13918. }
  13919. return overlapped;
  13920. };
  13921. OrientedBoundingRect.prototype._getProjMinMaxOnAxis = function (dim, corners, out) {
  13922. var axis = this._axes[dim];
  13923. var origin = this._origin;
  13924. var proj = corners[0].dot(axis) + origin[dim];
  13925. var min = proj;
  13926. var max = proj;
  13927. for (var i = 1; i < corners.length; i++) {
  13928. var proj_1 = corners[i].dot(axis) + origin[dim];
  13929. min = Math.min(proj_1, min);
  13930. max = Math.max(proj_1, max);
  13931. }
  13932. out[0] = min;
  13933. out[1] = max;
  13934. };
  13935. return OrientedBoundingRect;
  13936. }());
  13937. var DebugRect = (function () {
  13938. function DebugRect(style) {
  13939. var dom = this.dom = document.createElement('div');
  13940. dom.className = 'ec-debug-dirty-rect';
  13941. style = extend({}, style);
  13942. extend(style, {
  13943. backgroundColor: 'rgba(0, 0, 255, 0.2)',
  13944. border: '1px solid #00f'
  13945. });
  13946. dom.style.cssText = "\nposition: absolute;\nopacity: 0;\ntransition: opacity 0.5s linear;\npointer-events: none;\n";
  13947. for (var key in style) {
  13948. if (style.hasOwnProperty(key)) {
  13949. dom.style[key] = style[key];
  13950. }
  13951. }
  13952. }
  13953. DebugRect.prototype.update = function (rect) {
  13954. var domStyle = this.dom.style;
  13955. domStyle.width = rect.width + 'px';
  13956. domStyle.height = rect.height + 'px';
  13957. domStyle.left = rect.x + 'px';
  13958. domStyle.top = rect.y + 'px';
  13959. };
  13960. DebugRect.prototype.hide = function () {
  13961. this.dom.style.opacity = '0';
  13962. };
  13963. DebugRect.prototype.show = function (autoHideDelay) {
  13964. var _this = this;
  13965. clearTimeout(this._hideTimeout);
  13966. this.dom.style.opacity = '1';
  13967. this._hideTimeout = setTimeout(function () {
  13968. _this.hide();
  13969. }, autoHideDelay || 1000);
  13970. };
  13971. return DebugRect;
  13972. }());
  13973. function showDebugDirtyRect(zr, opts) {
  13974. opts = opts || {};
  13975. var painter = zr.painter;
  13976. if (!painter.getLayers) {
  13977. throw new Error('Debug dirty rect can only been used on canvas renderer.');
  13978. }
  13979. if (painter.isSingleCanvas()) {
  13980. throw new Error('Debug dirty rect can only been used on zrender inited with container.');
  13981. }
  13982. var debugViewRoot = document.createElement('div');
  13983. debugViewRoot.style.cssText = "\nposition:absolute;\nleft:0;\ntop:0;\nright:0;\nbottom:0;\npointer-events:none;\n";
  13984. debugViewRoot.className = 'ec-debug-dirty-rect-container';
  13985. var debugRects = [];
  13986. var dom = zr.dom;
  13987. dom.appendChild(debugViewRoot);
  13988. var computedStyle = getComputedStyle(dom);
  13989. if (computedStyle.position === 'static') {
  13990. dom.style.position = 'relative';
  13991. }
  13992. zr.on('rendered', function () {
  13993. if (painter.getLayers) {
  13994. var idx_1 = 0;
  13995. painter.eachBuiltinLayer(function (layer) {
  13996. if (!layer.debugGetPaintRects) {
  13997. return;
  13998. }
  13999. var paintRects = layer.debugGetPaintRects();
  14000. for (var i = 0; i < paintRects.length; i++) {
  14001. if (!paintRects[i].width || !paintRects[i].height) {
  14002. continue;
  14003. }
  14004. if (!debugRects[idx_1]) {
  14005. debugRects[idx_1] = new DebugRect(opts.style);
  14006. debugViewRoot.appendChild(debugRects[idx_1].dom);
  14007. }
  14008. debugRects[idx_1].show(opts.autoHideDelay);
  14009. debugRects[idx_1].update(paintRects[i]);
  14010. idx_1++;
  14011. }
  14012. });
  14013. for (var i = idx_1; i < debugRects.length; i++) {
  14014. debugRects[i].hide();
  14015. }
  14016. }
  14017. });
  14018. }
  14019. function isSafeNum(num) {
  14020. return isFinite(num);
  14021. }
  14022. function createLinearGradient(ctx, obj, rect) {
  14023. var x = obj.x == null ? 0 : obj.x;
  14024. var x2 = obj.x2 == null ? 1 : obj.x2;
  14025. var y = obj.y == null ? 0 : obj.y;
  14026. var y2 = obj.y2 == null ? 0 : obj.y2;
  14027. if (!obj.global) {
  14028. x = x * rect.width + rect.x;
  14029. x2 = x2 * rect.width + rect.x;
  14030. y = y * rect.height + rect.y;
  14031. y2 = y2 * rect.height + rect.y;
  14032. }
  14033. x = isSafeNum(x) ? x : 0;
  14034. x2 = isSafeNum(x2) ? x2 : 1;
  14035. y = isSafeNum(y) ? y : 0;
  14036. y2 = isSafeNum(y2) ? y2 : 0;
  14037. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  14038. return canvasGradient;
  14039. }
  14040. function createRadialGradient(ctx, obj, rect) {
  14041. var width = rect.width;
  14042. var height = rect.height;
  14043. var min = Math.min(width, height);
  14044. var x = obj.x == null ? 0.5 : obj.x;
  14045. var y = obj.y == null ? 0.5 : obj.y;
  14046. var r = obj.r == null ? 0.5 : obj.r;
  14047. if (!obj.global) {
  14048. x = x * width + rect.x;
  14049. y = y * height + rect.y;
  14050. r = r * min;
  14051. }
  14052. x = isSafeNum(x) ? x : 0.5;
  14053. y = isSafeNum(y) ? y : 0.5;
  14054. r = r >= 0 && isSafeNum(r) ? r : 0.5;
  14055. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  14056. return canvasGradient;
  14057. }
  14058. function getCanvasGradient(ctx, obj, rect) {
  14059. var canvasGradient = obj.type === 'radial'
  14060. ? createRadialGradient(ctx, obj, rect)
  14061. : createLinearGradient(ctx, obj, rect);
  14062. var colorStops = obj.colorStops;
  14063. for (var i = 0; i < colorStops.length; i++) {
  14064. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  14065. }
  14066. return canvasGradient;
  14067. }
  14068. function isClipPathChanged(clipPaths, prevClipPaths) {
  14069. if (clipPaths === prevClipPaths || (!clipPaths && !prevClipPaths)) {
  14070. return false;
  14071. }
  14072. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  14073. return true;
  14074. }
  14075. for (var i = 0; i < clipPaths.length; i++) {
  14076. if (clipPaths[i] !== prevClipPaths[i]) {
  14077. return true;
  14078. }
  14079. }
  14080. return false;
  14081. }
  14082. function parseInt10(val) {
  14083. return parseInt(val, 10);
  14084. }
  14085. function getSize(root, whIdx, opts) {
  14086. var wh = ['width', 'height'][whIdx];
  14087. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  14088. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  14089. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  14090. if (opts[wh] != null && opts[wh] !== 'auto') {
  14091. return parseFloat(opts[wh]);
  14092. }
  14093. var stl = document.defaultView.getComputedStyle(root);
  14094. return ((root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  14095. - (parseInt10(stl[plt]) || 0)
  14096. - (parseInt10(stl[prb]) || 0)) | 0;
  14097. }
  14098. function normalizeLineDash(lineType, lineWidth) {
  14099. if (!lineType || lineType === 'solid' || !(lineWidth > 0)) {
  14100. return null;
  14101. }
  14102. return lineType === 'dashed'
  14103. ? [4 * lineWidth, 2 * lineWidth]
  14104. : lineType === 'dotted'
  14105. ? [lineWidth]
  14106. : isNumber(lineType)
  14107. ? [lineType] : isArray(lineType) ? lineType : null;
  14108. }
  14109. function getLineDash(el) {
  14110. var style = el.style;
  14111. var lineDash = style.lineDash && style.lineWidth > 0 && normalizeLineDash(style.lineDash, style.lineWidth);
  14112. var lineDashOffset = style.lineDashOffset;
  14113. if (lineDash) {
  14114. var lineScale_1 = (style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1;
  14115. if (lineScale_1 && lineScale_1 !== 1) {
  14116. lineDash = map(lineDash, function (rawVal) {
  14117. return rawVal / lineScale_1;
  14118. });
  14119. lineDashOffset /= lineScale_1;
  14120. }
  14121. }
  14122. return [lineDash, lineDashOffset];
  14123. }
  14124. var pathProxyForDraw = new PathProxy(true);
  14125. function styleHasStroke(style) {
  14126. var stroke = style.stroke;
  14127. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  14128. }
  14129. function isValidStrokeFillStyle(strokeOrFill) {
  14130. return typeof strokeOrFill === 'string' && strokeOrFill !== 'none';
  14131. }
  14132. function styleHasFill(style) {
  14133. var fill = style.fill;
  14134. return fill != null && fill !== 'none';
  14135. }
  14136. function doFillPath(ctx, style) {
  14137. if (style.fillOpacity != null && style.fillOpacity !== 1) {
  14138. var originalGlobalAlpha = ctx.globalAlpha;
  14139. ctx.globalAlpha = style.fillOpacity * style.opacity;
  14140. ctx.fill();
  14141. ctx.globalAlpha = originalGlobalAlpha;
  14142. }
  14143. else {
  14144. ctx.fill();
  14145. }
  14146. }
  14147. function doStrokePath(ctx, style) {
  14148. if (style.strokeOpacity != null && style.strokeOpacity !== 1) {
  14149. var originalGlobalAlpha = ctx.globalAlpha;
  14150. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  14151. ctx.stroke();
  14152. ctx.globalAlpha = originalGlobalAlpha;
  14153. }
  14154. else {
  14155. ctx.stroke();
  14156. }
  14157. }
  14158. function createCanvasPattern(ctx, pattern, el) {
  14159. var image = createOrUpdateImage(pattern.image, pattern.__image, el);
  14160. if (isImageReady(image)) {
  14161. var canvasPattern = ctx.createPattern(image, pattern.repeat || 'repeat');
  14162. if (typeof DOMMatrix === 'function'
  14163. && canvasPattern
  14164. && canvasPattern.setTransform) {
  14165. var matrix = new DOMMatrix();
  14166. matrix.translateSelf((pattern.x || 0), (pattern.y || 0));
  14167. matrix.rotateSelf(0, 0, (pattern.rotation || 0) * RADIAN_TO_DEGREE);
  14168. matrix.scaleSelf((pattern.scaleX || 1), (pattern.scaleY || 1));
  14169. canvasPattern.setTransform(matrix);
  14170. }
  14171. return canvasPattern;
  14172. }
  14173. }
  14174. function brushPath(ctx, el, style, inBatch) {
  14175. var _a;
  14176. var hasStroke = styleHasStroke(style);
  14177. var hasFill = styleHasFill(style);
  14178. var strokePercent = style.strokePercent;
  14179. var strokePart = strokePercent < 1;
  14180. var firstDraw = !el.path;
  14181. if ((!el.silent || strokePart) && firstDraw) {
  14182. el.createPathProxy();
  14183. }
  14184. var path = el.path || pathProxyForDraw;
  14185. var dirtyFlag = el.__dirty;
  14186. if (!inBatch) {
  14187. var fill = style.fill;
  14188. var stroke = style.stroke;
  14189. var hasFillGradient = hasFill && !!fill.colorStops;
  14190. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  14191. var hasFillPattern = hasFill && !!fill.image;
  14192. var hasStrokePattern = hasStroke && !!stroke.image;
  14193. var fillGradient = void 0;
  14194. var strokeGradient = void 0;
  14195. var fillPattern = void 0;
  14196. var strokePattern = void 0;
  14197. var rect = void 0;
  14198. if (hasFillGradient || hasStrokeGradient) {
  14199. rect = el.getBoundingRect();
  14200. }
  14201. if (hasFillGradient) {
  14202. fillGradient = dirtyFlag
  14203. ? getCanvasGradient(ctx, fill, rect)
  14204. : el.__canvasFillGradient;
  14205. el.__canvasFillGradient = fillGradient;
  14206. }
  14207. if (hasStrokeGradient) {
  14208. strokeGradient = dirtyFlag
  14209. ? getCanvasGradient(ctx, stroke, rect)
  14210. : el.__canvasStrokeGradient;
  14211. el.__canvasStrokeGradient = strokeGradient;
  14212. }
  14213. if (hasFillPattern) {
  14214. fillPattern = (dirtyFlag || !el.__canvasFillPattern)
  14215. ? createCanvasPattern(ctx, fill, el)
  14216. : el.__canvasFillPattern;
  14217. el.__canvasFillPattern = fillPattern;
  14218. }
  14219. if (hasStrokePattern) {
  14220. strokePattern = (dirtyFlag || !el.__canvasStrokePattern)
  14221. ? createCanvasPattern(ctx, stroke, el)
  14222. : el.__canvasStrokePattern;
  14223. el.__canvasStrokePattern = fillPattern;
  14224. }
  14225. if (hasFillGradient) {
  14226. ctx.fillStyle = fillGradient;
  14227. }
  14228. else if (hasFillPattern) {
  14229. if (fillPattern) {
  14230. ctx.fillStyle = fillPattern;
  14231. }
  14232. else {
  14233. hasFill = false;
  14234. }
  14235. }
  14236. if (hasStrokeGradient) {
  14237. ctx.strokeStyle = strokeGradient;
  14238. }
  14239. else if (hasStrokePattern) {
  14240. if (strokePattern) {
  14241. ctx.strokeStyle = strokePattern;
  14242. }
  14243. else {
  14244. hasStroke = false;
  14245. }
  14246. }
  14247. }
  14248. var scale = el.getGlobalScale();
  14249. path.setScale(scale[0], scale[1], el.segmentIgnoreThreshold);
  14250. var lineDash;
  14251. var lineDashOffset;
  14252. if (ctx.setLineDash && style.lineDash) {
  14253. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14254. }
  14255. var needsRebuild = true;
  14256. if (firstDraw || (dirtyFlag & SHAPE_CHANGED_BIT)) {
  14257. path.setDPR(ctx.dpr);
  14258. if (strokePart) {
  14259. path.setContext(null);
  14260. }
  14261. else {
  14262. path.setContext(ctx);
  14263. needsRebuild = false;
  14264. }
  14265. path.reset();
  14266. el.buildPath(path, el.shape, inBatch);
  14267. path.toStatic();
  14268. el.pathUpdated();
  14269. }
  14270. if (needsRebuild) {
  14271. path.rebuildPath(ctx, strokePart ? strokePercent : 1);
  14272. }
  14273. if (lineDash) {
  14274. ctx.setLineDash(lineDash);
  14275. ctx.lineDashOffset = lineDashOffset;
  14276. }
  14277. if (!inBatch) {
  14278. if (style.strokeFirst) {
  14279. if (hasStroke) {
  14280. doStrokePath(ctx, style);
  14281. }
  14282. if (hasFill) {
  14283. doFillPath(ctx, style);
  14284. }
  14285. }
  14286. else {
  14287. if (hasFill) {
  14288. doFillPath(ctx, style);
  14289. }
  14290. if (hasStroke) {
  14291. doStrokePath(ctx, style);
  14292. }
  14293. }
  14294. }
  14295. if (lineDash) {
  14296. ctx.setLineDash([]);
  14297. }
  14298. }
  14299. function brushImage(ctx, el, style) {
  14300. var image = el.__image = createOrUpdateImage(style.image, el.__image, el, el.onload);
  14301. if (!image || !isImageReady(image)) {
  14302. return;
  14303. }
  14304. var x = style.x || 0;
  14305. var y = style.y || 0;
  14306. var width = el.getWidth();
  14307. var height = el.getHeight();
  14308. var aspect = image.width / image.height;
  14309. if (width == null && height != null) {
  14310. width = height * aspect;
  14311. }
  14312. else if (height == null && width != null) {
  14313. height = width / aspect;
  14314. }
  14315. else if (width == null && height == null) {
  14316. width = image.width;
  14317. height = image.height;
  14318. }
  14319. if (style.sWidth && style.sHeight) {
  14320. var sx = style.sx || 0;
  14321. var sy = style.sy || 0;
  14322. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  14323. }
  14324. else if (style.sx && style.sy) {
  14325. var sx = style.sx;
  14326. var sy = style.sy;
  14327. var sWidth = width - sx;
  14328. var sHeight = height - sy;
  14329. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  14330. }
  14331. else {
  14332. ctx.drawImage(image, x, y, width, height);
  14333. }
  14334. }
  14335. function brushText(ctx, el, style) {
  14336. var _a;
  14337. var text = style.text;
  14338. text != null && (text += '');
  14339. if (text) {
  14340. ctx.font = style.font || DEFAULT_FONT;
  14341. ctx.textAlign = style.textAlign;
  14342. ctx.textBaseline = style.textBaseline;
  14343. var lineDash = void 0;
  14344. var lineDashOffset = void 0;
  14345. if (ctx.setLineDash && style.lineDash) {
  14346. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14347. }
  14348. if (lineDash) {
  14349. ctx.setLineDash(lineDash);
  14350. ctx.lineDashOffset = lineDashOffset;
  14351. }
  14352. if (style.strokeFirst) {
  14353. if (styleHasStroke(style)) {
  14354. ctx.strokeText(text, style.x, style.y);
  14355. }
  14356. if (styleHasFill(style)) {
  14357. ctx.fillText(text, style.x, style.y);
  14358. }
  14359. }
  14360. else {
  14361. if (styleHasFill(style)) {
  14362. ctx.fillText(text, style.x, style.y);
  14363. }
  14364. if (styleHasStroke(style)) {
  14365. ctx.strokeText(text, style.x, style.y);
  14366. }
  14367. }
  14368. if (lineDash) {
  14369. ctx.setLineDash([]);
  14370. }
  14371. }
  14372. }
  14373. var SHADOW_NUMBER_PROPS = ['shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  14374. var STROKE_PROPS = [
  14375. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  14376. ];
  14377. function bindCommonProps(ctx, style, prevStyle, forceSetAll, scope) {
  14378. var styleChanged = false;
  14379. if (!forceSetAll) {
  14380. prevStyle = prevStyle || {};
  14381. if (style === prevStyle) {
  14382. return false;
  14383. }
  14384. }
  14385. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14386. flushPathDrawn(ctx, scope);
  14387. styleChanged = true;
  14388. var opacity = Math.max(Math.min(style.opacity, 1), 0);
  14389. ctx.globalAlpha = isNaN(opacity) ? DEFAULT_COMMON_STYLE.opacity : opacity;
  14390. }
  14391. if (forceSetAll || style.blend !== prevStyle.blend) {
  14392. if (!styleChanged) {
  14393. flushPathDrawn(ctx, scope);
  14394. styleChanged = true;
  14395. }
  14396. ctx.globalCompositeOperation = style.blend || DEFAULT_COMMON_STYLE.blend;
  14397. }
  14398. for (var i = 0; i < SHADOW_NUMBER_PROPS.length; i++) {
  14399. var propName = SHADOW_NUMBER_PROPS[i];
  14400. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14401. if (!styleChanged) {
  14402. flushPathDrawn(ctx, scope);
  14403. styleChanged = true;
  14404. }
  14405. ctx[propName] = ctx.dpr * (style[propName] || 0);
  14406. }
  14407. }
  14408. if (forceSetAll || style.shadowColor !== prevStyle.shadowColor) {
  14409. if (!styleChanged) {
  14410. flushPathDrawn(ctx, scope);
  14411. styleChanged = true;
  14412. }
  14413. ctx.shadowColor = style.shadowColor || DEFAULT_COMMON_STYLE.shadowColor;
  14414. }
  14415. return styleChanged;
  14416. }
  14417. function bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetAll, scope) {
  14418. var style = getStyle(el, scope.inHover);
  14419. var prevStyle = forceSetAll
  14420. ? null
  14421. : (prevEl && getStyle(prevEl, scope.inHover) || {});
  14422. if (style === prevStyle) {
  14423. return false;
  14424. }
  14425. var styleChanged = bindCommonProps(ctx, style, prevStyle, forceSetAll, scope);
  14426. if (forceSetAll || style.fill !== prevStyle.fill) {
  14427. if (!styleChanged) {
  14428. flushPathDrawn(ctx, scope);
  14429. styleChanged = true;
  14430. }
  14431. isValidStrokeFillStyle(style.fill) && (ctx.fillStyle = style.fill);
  14432. }
  14433. if (forceSetAll || style.stroke !== prevStyle.stroke) {
  14434. if (!styleChanged) {
  14435. flushPathDrawn(ctx, scope);
  14436. styleChanged = true;
  14437. }
  14438. isValidStrokeFillStyle(style.stroke) && (ctx.strokeStyle = style.stroke);
  14439. }
  14440. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14441. if (!styleChanged) {
  14442. flushPathDrawn(ctx, scope);
  14443. styleChanged = true;
  14444. }
  14445. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  14446. }
  14447. if (el.hasStroke()) {
  14448. var lineWidth = style.lineWidth;
  14449. var newLineWidth = lineWidth / ((style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1);
  14450. if (ctx.lineWidth !== newLineWidth) {
  14451. if (!styleChanged) {
  14452. flushPathDrawn(ctx, scope);
  14453. styleChanged = true;
  14454. }
  14455. ctx.lineWidth = newLineWidth;
  14456. }
  14457. }
  14458. for (var i = 0; i < STROKE_PROPS.length; i++) {
  14459. var prop = STROKE_PROPS[i];
  14460. var propName = prop[0];
  14461. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14462. if (!styleChanged) {
  14463. flushPathDrawn(ctx, scope);
  14464. styleChanged = true;
  14465. }
  14466. ctx[propName] = style[propName] || prop[1];
  14467. }
  14468. }
  14469. return styleChanged;
  14470. }
  14471. function bindImageStyle(ctx, el, prevEl, forceSetAll, scope) {
  14472. return bindCommonProps(ctx, getStyle(el, scope.inHover), prevEl && getStyle(prevEl, scope.inHover), forceSetAll, scope);
  14473. }
  14474. function setContextTransform(ctx, el) {
  14475. var m = el.transform;
  14476. var dpr = ctx.dpr || 1;
  14477. if (m) {
  14478. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  14479. }
  14480. else {
  14481. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  14482. }
  14483. }
  14484. function updateClipStatus(clipPaths, ctx, scope) {
  14485. var allClipped = false;
  14486. for (var i = 0; i < clipPaths.length; i++) {
  14487. var clipPath = clipPaths[i];
  14488. allClipped = allClipped || clipPath.isZeroArea();
  14489. setContextTransform(ctx, clipPath);
  14490. ctx.beginPath();
  14491. clipPath.buildPath(ctx, clipPath.shape);
  14492. ctx.clip();
  14493. }
  14494. scope.allClipped = allClipped;
  14495. }
  14496. function isTransformChanged(m0, m1) {
  14497. if (m0 && m1) {
  14498. return m0[0] !== m1[0]
  14499. || m0[1] !== m1[1]
  14500. || m0[2] !== m1[2]
  14501. || m0[3] !== m1[3]
  14502. || m0[4] !== m1[4]
  14503. || m0[5] !== m1[5];
  14504. }
  14505. else if (!m0 && !m1) {
  14506. return false;
  14507. }
  14508. return true;
  14509. }
  14510. var DRAW_TYPE_PATH = 1;
  14511. var DRAW_TYPE_IMAGE = 2;
  14512. var DRAW_TYPE_TEXT = 3;
  14513. var DRAW_TYPE_INCREMENTAL = 4;
  14514. function canPathBatch(style) {
  14515. var hasFill = styleHasFill(style);
  14516. var hasStroke = styleHasStroke(style);
  14517. return !(style.lineDash
  14518. || !(+hasFill ^ +hasStroke)
  14519. || (hasFill && typeof style.fill !== 'string')
  14520. || (hasStroke && typeof style.stroke !== 'string')
  14521. || style.strokePercent < 1
  14522. || style.strokeOpacity < 1
  14523. || style.fillOpacity < 1);
  14524. }
  14525. function flushPathDrawn(ctx, scope) {
  14526. scope.batchFill && ctx.fill();
  14527. scope.batchStroke && ctx.stroke();
  14528. scope.batchFill = '';
  14529. scope.batchStroke = '';
  14530. }
  14531. function getStyle(el, inHover) {
  14532. return inHover ? (el.__hoverStyle || el.style) : el.style;
  14533. }
  14534. function brushSingle(ctx, el) {
  14535. brush(ctx, el, { inHover: false, viewWidth: 0, viewHeight: 0 }, true);
  14536. }
  14537. function brush(ctx, el, scope, isLast) {
  14538. var m = el.transform;
  14539. if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false)) {
  14540. el.__dirty &= ~REDRAW_BIT;
  14541. el.__isRendered = false;
  14542. return;
  14543. }
  14544. var clipPaths = el.__clipPaths;
  14545. var prevElClipPaths = scope.prevElClipPaths;
  14546. var forceSetTransform = false;
  14547. var forceSetStyle = false;
  14548. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  14549. if (prevElClipPaths && prevElClipPaths.length) {
  14550. flushPathDrawn(ctx, scope);
  14551. ctx.restore();
  14552. forceSetStyle = forceSetTransform = true;
  14553. scope.prevElClipPaths = null;
  14554. scope.allClipped = false;
  14555. scope.prevEl = null;
  14556. }
  14557. if (clipPaths && clipPaths.length) {
  14558. flushPathDrawn(ctx, scope);
  14559. ctx.save();
  14560. updateClipStatus(clipPaths, ctx, scope);
  14561. forceSetTransform = true;
  14562. }
  14563. scope.prevElClipPaths = clipPaths;
  14564. }
  14565. if (scope.allClipped) {
  14566. el.__isRendered = false;
  14567. return;
  14568. }
  14569. el.beforeBrush && el.beforeBrush();
  14570. el.innerBeforeBrush();
  14571. var prevEl = scope.prevEl;
  14572. if (!prevEl) {
  14573. forceSetStyle = forceSetTransform = true;
  14574. }
  14575. var canBatchPath = el instanceof Path
  14576. && el.autoBatch
  14577. && canPathBatch(el.style);
  14578. if (forceSetTransform || isTransformChanged(m, prevEl.transform)) {
  14579. flushPathDrawn(ctx, scope);
  14580. setContextTransform(ctx, el);
  14581. }
  14582. else if (!canBatchPath) {
  14583. flushPathDrawn(ctx, scope);
  14584. }
  14585. var style = getStyle(el, scope.inHover);
  14586. if (el instanceof Path) {
  14587. if (scope.lastDrawType !== DRAW_TYPE_PATH) {
  14588. forceSetStyle = true;
  14589. scope.lastDrawType = DRAW_TYPE_PATH;
  14590. }
  14591. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14592. if (!canBatchPath || (!scope.batchFill && !scope.batchStroke)) {
  14593. ctx.beginPath();
  14594. }
  14595. brushPath(ctx, el, style, canBatchPath);
  14596. if (canBatchPath) {
  14597. scope.batchFill = style.fill || '';
  14598. scope.batchStroke = style.stroke || '';
  14599. }
  14600. }
  14601. else {
  14602. if (el instanceof TSpan) {
  14603. if (scope.lastDrawType !== DRAW_TYPE_TEXT) {
  14604. forceSetStyle = true;
  14605. scope.lastDrawType = DRAW_TYPE_TEXT;
  14606. }
  14607. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14608. brushText(ctx, el, style);
  14609. }
  14610. else if (el instanceof ZRImage) {
  14611. if (scope.lastDrawType !== DRAW_TYPE_IMAGE) {
  14612. forceSetStyle = true;
  14613. scope.lastDrawType = DRAW_TYPE_IMAGE;
  14614. }
  14615. bindImageStyle(ctx, el, prevEl, forceSetStyle, scope);
  14616. brushImage(ctx, el, style);
  14617. }
  14618. else if (el.getTemporalDisplayables) {
  14619. if (scope.lastDrawType !== DRAW_TYPE_INCREMENTAL) {
  14620. forceSetStyle = true;
  14621. scope.lastDrawType = DRAW_TYPE_INCREMENTAL;
  14622. }
  14623. brushIncremental(ctx, el, scope);
  14624. }
  14625. }
  14626. if (canBatchPath && isLast) {
  14627. flushPathDrawn(ctx, scope);
  14628. }
  14629. el.innerAfterBrush();
  14630. el.afterBrush && el.afterBrush();
  14631. scope.prevEl = el;
  14632. el.__dirty = 0;
  14633. el.__isRendered = true;
  14634. }
  14635. function brushIncremental(ctx, el, scope) {
  14636. var displayables = el.getDisplayables();
  14637. var temporalDisplayables = el.getTemporalDisplayables();
  14638. ctx.save();
  14639. var innerScope = {
  14640. prevElClipPaths: null,
  14641. prevEl: null,
  14642. allClipped: false,
  14643. viewWidth: scope.viewWidth,
  14644. viewHeight: scope.viewHeight,
  14645. inHover: scope.inHover
  14646. };
  14647. var i;
  14648. var len;
  14649. for (i = el.getCursor(), len = displayables.length; i < len; i++) {
  14650. var displayable = displayables[i];
  14651. displayable.beforeBrush && displayable.beforeBrush();
  14652. displayable.innerBeforeBrush();
  14653. brush(ctx, displayable, innerScope, i === len - 1);
  14654. displayable.innerAfterBrush();
  14655. displayable.afterBrush && displayable.afterBrush();
  14656. innerScope.prevEl = displayable;
  14657. }
  14658. for (var i_1 = 0, len_1 = temporalDisplayables.length; i_1 < len_1; i_1++) {
  14659. var displayable = temporalDisplayables[i_1];
  14660. displayable.beforeBrush && displayable.beforeBrush();
  14661. displayable.innerBeforeBrush();
  14662. brush(ctx, displayable, innerScope, i_1 === len_1 - 1);
  14663. displayable.innerAfterBrush();
  14664. displayable.afterBrush && displayable.afterBrush();
  14665. innerScope.prevEl = displayable;
  14666. }
  14667. el.clearTemporalDisplayables();
  14668. el.notClear = true;
  14669. ctx.restore();
  14670. }
  14671. function createDom(id, painter, dpr) {
  14672. var newDom = platformApi.createCanvas();
  14673. var width = painter.getWidth();
  14674. var height = painter.getHeight();
  14675. var newDomStyle = newDom.style;
  14676. if (newDomStyle) {
  14677. newDomStyle.position = 'absolute';
  14678. newDomStyle.left = '0';
  14679. newDomStyle.top = '0';
  14680. newDomStyle.width = width + 'px';
  14681. newDomStyle.height = height + 'px';
  14682. newDom.setAttribute('data-zr-dom-id', id);
  14683. }
  14684. newDom.width = width * dpr;
  14685. newDom.height = height * dpr;
  14686. return newDom;
  14687. }
  14688. var Layer = (function (_super) {
  14689. __extends(Layer, _super);
  14690. function Layer(id, painter, dpr) {
  14691. var _this = _super.call(this) || this;
  14692. _this.motionBlur = false;
  14693. _this.lastFrameAlpha = 0.7;
  14694. _this.dpr = 1;
  14695. _this.virtual = false;
  14696. _this.config = {};
  14697. _this.incremental = false;
  14698. _this.zlevel = 0;
  14699. _this.maxRepaintRectCount = 5;
  14700. _this.__dirty = true;
  14701. _this.__firstTimePaint = true;
  14702. _this.__used = false;
  14703. _this.__drawIndex = 0;
  14704. _this.__startIndex = 0;
  14705. _this.__endIndex = 0;
  14706. _this.__prevStartIndex = null;
  14707. _this.__prevEndIndex = null;
  14708. var dom;
  14709. dpr = dpr || devicePixelRatio;
  14710. if (typeof id === 'string') {
  14711. dom = createDom(id, painter, dpr);
  14712. }
  14713. else if (isObject(id)) {
  14714. dom = id;
  14715. id = dom.id;
  14716. }
  14717. _this.id = id;
  14718. _this.dom = dom;
  14719. var domStyle = dom.style;
  14720. if (domStyle) {
  14721. disableUserSelect(dom);
  14722. dom.onselectstart = function () { return false; };
  14723. domStyle.padding = '0';
  14724. domStyle.margin = '0';
  14725. domStyle.borderWidth = '0';
  14726. }
  14727. _this.painter = painter;
  14728. _this.dpr = dpr;
  14729. return _this;
  14730. }
  14731. Layer.prototype.getElementCount = function () {
  14732. return this.__endIndex - this.__startIndex;
  14733. };
  14734. Layer.prototype.afterBrush = function () {
  14735. this.__prevStartIndex = this.__startIndex;
  14736. this.__prevEndIndex = this.__endIndex;
  14737. };
  14738. Layer.prototype.initContext = function () {
  14739. this.ctx = this.dom.getContext('2d');
  14740. this.ctx.dpr = this.dpr;
  14741. };
  14742. Layer.prototype.setUnpainted = function () {
  14743. this.__firstTimePaint = true;
  14744. };
  14745. Layer.prototype.createBackBuffer = function () {
  14746. var dpr = this.dpr;
  14747. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  14748. this.ctxBack = this.domBack.getContext('2d');
  14749. if (dpr !== 1) {
  14750. this.ctxBack.scale(dpr, dpr);
  14751. }
  14752. };
  14753. Layer.prototype.createRepaintRects = function (displayList, prevList, viewWidth, viewHeight) {
  14754. if (this.__firstTimePaint) {
  14755. this.__firstTimePaint = false;
  14756. return null;
  14757. }
  14758. var mergedRepaintRects = [];
  14759. var maxRepaintRectCount = this.maxRepaintRectCount;
  14760. var full = false;
  14761. var pendingRect = new BoundingRect(0, 0, 0, 0);
  14762. function addRectToMergePool(rect) {
  14763. if (!rect.isFinite() || rect.isZero()) {
  14764. return;
  14765. }
  14766. if (mergedRepaintRects.length === 0) {
  14767. var boundingRect = new BoundingRect(0, 0, 0, 0);
  14768. boundingRect.copy(rect);
  14769. mergedRepaintRects.push(boundingRect);
  14770. }
  14771. else {
  14772. var isMerged = false;
  14773. var minDeltaArea = Infinity;
  14774. var bestRectToMergeIdx = 0;
  14775. for (var i = 0; i < mergedRepaintRects.length; ++i) {
  14776. var mergedRect = mergedRepaintRects[i];
  14777. if (mergedRect.intersect(rect)) {
  14778. var pendingRect_1 = new BoundingRect(0, 0, 0, 0);
  14779. pendingRect_1.copy(mergedRect);
  14780. pendingRect_1.union(rect);
  14781. mergedRepaintRects[i] = pendingRect_1;
  14782. isMerged = true;
  14783. break;
  14784. }
  14785. else if (full) {
  14786. pendingRect.copy(rect);
  14787. pendingRect.union(mergedRect);
  14788. var aArea = rect.width * rect.height;
  14789. var bArea = mergedRect.width * mergedRect.height;
  14790. var pendingArea = pendingRect.width * pendingRect.height;
  14791. var deltaArea = pendingArea - aArea - bArea;
  14792. if (deltaArea < minDeltaArea) {
  14793. minDeltaArea = deltaArea;
  14794. bestRectToMergeIdx = i;
  14795. }
  14796. }
  14797. }
  14798. if (full) {
  14799. mergedRepaintRects[bestRectToMergeIdx].union(rect);
  14800. isMerged = true;
  14801. }
  14802. if (!isMerged) {
  14803. var boundingRect = new BoundingRect(0, 0, 0, 0);
  14804. boundingRect.copy(rect);
  14805. mergedRepaintRects.push(boundingRect);
  14806. }
  14807. if (!full) {
  14808. full = mergedRepaintRects.length >= maxRepaintRectCount;
  14809. }
  14810. }
  14811. }
  14812. for (var i = this.__startIndex; i < this.__endIndex; ++i) {
  14813. var el = displayList[i];
  14814. if (el) {
  14815. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  14816. var prevRect = el.__isRendered && ((el.__dirty & REDRAW_BIT) || !shouldPaint)
  14817. ? el.getPrevPaintRect()
  14818. : null;
  14819. if (prevRect) {
  14820. addRectToMergePool(prevRect);
  14821. }
  14822. var curRect = shouldPaint && ((el.__dirty & REDRAW_BIT) || !el.__isRendered)
  14823. ? el.getPaintRect()
  14824. : null;
  14825. if (curRect) {
  14826. addRectToMergePool(curRect);
  14827. }
  14828. }
  14829. }
  14830. for (var i = this.__prevStartIndex; i < this.__prevEndIndex; ++i) {
  14831. var el = prevList[i];
  14832. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  14833. if (el && (!shouldPaint || !el.__zr) && el.__isRendered) {
  14834. var prevRect = el.getPrevPaintRect();
  14835. if (prevRect) {
  14836. addRectToMergePool(prevRect);
  14837. }
  14838. }
  14839. }
  14840. var hasIntersections;
  14841. do {
  14842. hasIntersections = false;
  14843. for (var i = 0; i < mergedRepaintRects.length;) {
  14844. if (mergedRepaintRects[i].isZero()) {
  14845. mergedRepaintRects.splice(i, 1);
  14846. continue;
  14847. }
  14848. for (var j = i + 1; j < mergedRepaintRects.length;) {
  14849. if (mergedRepaintRects[i].intersect(mergedRepaintRects[j])) {
  14850. hasIntersections = true;
  14851. mergedRepaintRects[i].union(mergedRepaintRects[j]);
  14852. mergedRepaintRects.splice(j, 1);
  14853. }
  14854. else {
  14855. j++;
  14856. }
  14857. }
  14858. i++;
  14859. }
  14860. } while (hasIntersections);
  14861. this._paintRects = mergedRepaintRects;
  14862. return mergedRepaintRects;
  14863. };
  14864. Layer.prototype.debugGetPaintRects = function () {
  14865. return (this._paintRects || []).slice();
  14866. };
  14867. Layer.prototype.resize = function (width, height) {
  14868. var dpr = this.dpr;
  14869. var dom = this.dom;
  14870. var domStyle = dom.style;
  14871. var domBack = this.domBack;
  14872. if (domStyle) {
  14873. domStyle.width = width + 'px';
  14874. domStyle.height = height + 'px';
  14875. }
  14876. dom.width = width * dpr;
  14877. dom.height = height * dpr;
  14878. if (domBack) {
  14879. domBack.width = width * dpr;
  14880. domBack.height = height * dpr;
  14881. if (dpr !== 1) {
  14882. this.ctxBack.scale(dpr, dpr);
  14883. }
  14884. }
  14885. };
  14886. Layer.prototype.clear = function (clearAll, clearColor, repaintRects) {
  14887. var dom = this.dom;
  14888. var ctx = this.ctx;
  14889. var width = dom.width;
  14890. var height = dom.height;
  14891. clearColor = clearColor || this.clearColor;
  14892. var haveMotionBLur = this.motionBlur && !clearAll;
  14893. var lastFrameAlpha = this.lastFrameAlpha;
  14894. var dpr = this.dpr;
  14895. var self = this;
  14896. if (haveMotionBLur) {
  14897. if (!this.domBack) {
  14898. this.createBackBuffer();
  14899. }
  14900. this.ctxBack.globalCompositeOperation = 'copy';
  14901. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  14902. }
  14903. var domBack = this.domBack;
  14904. function doClear(x, y, width, height) {
  14905. ctx.clearRect(x, y, width, height);
  14906. if (clearColor && clearColor !== 'transparent') {
  14907. var clearColorGradientOrPattern = void 0;
  14908. if (isGradientObject(clearColor)) {
  14909. var shouldCache = clearColor.global || (clearColor.__width === width
  14910. && clearColor.__height === height);
  14911. clearColorGradientOrPattern = shouldCache
  14912. && clearColor.__canvasGradient
  14913. || getCanvasGradient(ctx, clearColor, {
  14914. x: 0,
  14915. y: 0,
  14916. width: width,
  14917. height: height
  14918. });
  14919. clearColor.__canvasGradient = clearColorGradientOrPattern;
  14920. clearColor.__width = width;
  14921. clearColor.__height = height;
  14922. }
  14923. else if (isImagePatternObject(clearColor)) {
  14924. clearColor.scaleX = clearColor.scaleX || dpr;
  14925. clearColor.scaleY = clearColor.scaleY || dpr;
  14926. clearColorGradientOrPattern = createCanvasPattern(ctx, clearColor, {
  14927. dirty: function () {
  14928. self.setUnpainted();
  14929. self.__painter.refresh();
  14930. }
  14931. });
  14932. }
  14933. ctx.save();
  14934. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  14935. ctx.fillRect(x, y, width, height);
  14936. ctx.restore();
  14937. }
  14938. if (haveMotionBLur) {
  14939. ctx.save();
  14940. ctx.globalAlpha = lastFrameAlpha;
  14941. ctx.drawImage(domBack, x, y, width, height);
  14942. ctx.restore();
  14943. }
  14944. }
  14945. if (!repaintRects || haveMotionBLur) {
  14946. doClear(0, 0, width, height);
  14947. }
  14948. else if (repaintRects.length) {
  14949. each(repaintRects, function (rect) {
  14950. doClear(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  14951. });
  14952. }
  14953. };
  14954. return Layer;
  14955. }(Eventful));
  14956. var HOVER_LAYER_ZLEVEL = 1e5;
  14957. var CANVAS_ZLEVEL = 314159;
  14958. var EL_AFTER_INCREMENTAL_INC = 0.01;
  14959. var INCREMENTAL_INC = 0.001;
  14960. function isLayerValid(layer) {
  14961. if (!layer) {
  14962. return false;
  14963. }
  14964. if (layer.__builtin__) {
  14965. return true;
  14966. }
  14967. if (typeof (layer.resize) !== 'function'
  14968. || typeof (layer.refresh) !== 'function') {
  14969. return false;
  14970. }
  14971. return true;
  14972. }
  14973. function createRoot(width, height) {
  14974. var domRoot = document.createElement('div');
  14975. domRoot.style.cssText = [
  14976. 'position:relative',
  14977. 'width:' + width + 'px',
  14978. 'height:' + height + 'px',
  14979. 'padding:0',
  14980. 'margin:0',
  14981. 'border-width:0'
  14982. ].join(';') + ';';
  14983. return domRoot;
  14984. }
  14985. var CanvasPainter = (function () {
  14986. function CanvasPainter(root, storage, opts, id) {
  14987. this.type = 'canvas';
  14988. this._zlevelList = [];
  14989. this._prevDisplayList = [];
  14990. this._layers = {};
  14991. this._layerConfig = {};
  14992. this._needsManuallyCompositing = false;
  14993. this.type = 'canvas';
  14994. var singleCanvas = !root.nodeName
  14995. || root.nodeName.toUpperCase() === 'CANVAS';
  14996. this._opts = opts = extend({}, opts || {});
  14997. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  14998. this._singleCanvas = singleCanvas;
  14999. this.root = root;
  15000. var rootStyle = root.style;
  15001. if (rootStyle) {
  15002. disableUserSelect(root);
  15003. root.innerHTML = '';
  15004. }
  15005. this.storage = storage;
  15006. var zlevelList = this._zlevelList;
  15007. this._prevDisplayList = [];
  15008. var layers = this._layers;
  15009. if (!singleCanvas) {
  15010. this._width = getSize(root, 0, opts);
  15011. this._height = getSize(root, 1, opts);
  15012. var domRoot = this._domRoot = createRoot(this._width, this._height);
  15013. root.appendChild(domRoot);
  15014. }
  15015. else {
  15016. var rootCanvas = root;
  15017. var width = rootCanvas.width;
  15018. var height = rootCanvas.height;
  15019. if (opts.width != null) {
  15020. width = opts.width;
  15021. }
  15022. if (opts.height != null) {
  15023. height = opts.height;
  15024. }
  15025. this.dpr = opts.devicePixelRatio || 1;
  15026. rootCanvas.width = width * this.dpr;
  15027. rootCanvas.height = height * this.dpr;
  15028. this._width = width;
  15029. this._height = height;
  15030. var mainLayer = new Layer(rootCanvas, this, this.dpr);
  15031. mainLayer.__builtin__ = true;
  15032. mainLayer.initContext();
  15033. layers[CANVAS_ZLEVEL] = mainLayer;
  15034. mainLayer.zlevel = CANVAS_ZLEVEL;
  15035. zlevelList.push(CANVAS_ZLEVEL);
  15036. this._domRoot = root;
  15037. }
  15038. }
  15039. CanvasPainter.prototype.getType = function () {
  15040. return 'canvas';
  15041. };
  15042. CanvasPainter.prototype.isSingleCanvas = function () {
  15043. return this._singleCanvas;
  15044. };
  15045. CanvasPainter.prototype.getViewportRoot = function () {
  15046. return this._domRoot;
  15047. };
  15048. CanvasPainter.prototype.getViewportRootOffset = function () {
  15049. var viewportRoot = this.getViewportRoot();
  15050. if (viewportRoot) {
  15051. return {
  15052. offsetLeft: viewportRoot.offsetLeft || 0,
  15053. offsetTop: viewportRoot.offsetTop || 0
  15054. };
  15055. }
  15056. };
  15057. CanvasPainter.prototype.refresh = function (paintAll) {
  15058. var list = this.storage.getDisplayList(true);
  15059. var prevList = this._prevDisplayList;
  15060. var zlevelList = this._zlevelList;
  15061. this._redrawId = Math.random();
  15062. this._paintList(list, prevList, paintAll, this._redrawId);
  15063. for (var i = 0; i < zlevelList.length; i++) {
  15064. var z = zlevelList[i];
  15065. var layer = this._layers[z];
  15066. if (!layer.__builtin__ && layer.refresh) {
  15067. var clearColor = i === 0 ? this._backgroundColor : null;
  15068. layer.refresh(clearColor);
  15069. }
  15070. }
  15071. if (this._opts.useDirtyRect) {
  15072. this._prevDisplayList = list.slice();
  15073. }
  15074. return this;
  15075. };
  15076. CanvasPainter.prototype.refreshHover = function () {
  15077. this._paintHoverList(this.storage.getDisplayList(false));
  15078. };
  15079. CanvasPainter.prototype._paintHoverList = function (list) {
  15080. var len = list.length;
  15081. var hoverLayer = this._hoverlayer;
  15082. hoverLayer && hoverLayer.clear();
  15083. if (!len) {
  15084. return;
  15085. }
  15086. var scope = {
  15087. inHover: true,
  15088. viewWidth: this._width,
  15089. viewHeight: this._height
  15090. };
  15091. var ctx;
  15092. for (var i = 0; i < len; i++) {
  15093. var el = list[i];
  15094. if (el.__inHover) {
  15095. if (!hoverLayer) {
  15096. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  15097. }
  15098. if (!ctx) {
  15099. ctx = hoverLayer.ctx;
  15100. ctx.save();
  15101. }
  15102. brush(ctx, el, scope, i === len - 1);
  15103. }
  15104. }
  15105. if (ctx) {
  15106. ctx.restore();
  15107. }
  15108. };
  15109. CanvasPainter.prototype.getHoverLayer = function () {
  15110. return this.getLayer(HOVER_LAYER_ZLEVEL);
  15111. };
  15112. CanvasPainter.prototype.paintOne = function (ctx, el) {
  15113. brushSingle(ctx, el);
  15114. };
  15115. CanvasPainter.prototype._paintList = function (list, prevList, paintAll, redrawId) {
  15116. if (this._redrawId !== redrawId) {
  15117. return;
  15118. }
  15119. paintAll = paintAll || false;
  15120. this._updateLayerStatus(list);
  15121. var _a = this._doPaintList(list, prevList, paintAll), finished = _a.finished, needsRefreshHover = _a.needsRefreshHover;
  15122. if (this._needsManuallyCompositing) {
  15123. this._compositeManually();
  15124. }
  15125. if (needsRefreshHover) {
  15126. this._paintHoverList(list);
  15127. }
  15128. if (!finished) {
  15129. var self_1 = this;
  15130. requestAnimationFrame$1(function () {
  15131. self_1._paintList(list, prevList, paintAll, redrawId);
  15132. });
  15133. }
  15134. else {
  15135. this.eachLayer(function (layer) {
  15136. layer.afterBrush && layer.afterBrush();
  15137. });
  15138. }
  15139. };
  15140. CanvasPainter.prototype._compositeManually = function () {
  15141. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  15142. var width = this._domRoot.width;
  15143. var height = this._domRoot.height;
  15144. ctx.clearRect(0, 0, width, height);
  15145. this.eachBuiltinLayer(function (layer) {
  15146. if (layer.virtual) {
  15147. ctx.drawImage(layer.dom, 0, 0, width, height);
  15148. }
  15149. });
  15150. };
  15151. CanvasPainter.prototype._doPaintList = function (list, prevList, paintAll) {
  15152. var _this = this;
  15153. var layerList = [];
  15154. var useDirtyRect = this._opts.useDirtyRect;
  15155. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  15156. var zlevel = this._zlevelList[zi];
  15157. var layer = this._layers[zlevel];
  15158. if (layer.__builtin__
  15159. && layer !== this._hoverlayer
  15160. && (layer.__dirty || paintAll)) {
  15161. layerList.push(layer);
  15162. }
  15163. }
  15164. var finished = true;
  15165. var needsRefreshHover = false;
  15166. var _loop_1 = function (k) {
  15167. var layer = layerList[k];
  15168. var ctx = layer.ctx;
  15169. var repaintRects = useDirtyRect
  15170. && layer.createRepaintRects(list, prevList, this_1._width, this_1._height);
  15171. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  15172. var useTimer = !paintAll && layer.incremental && Date.now;
  15173. var startTime = useTimer && Date.now();
  15174. var clearColor = layer.zlevel === this_1._zlevelList[0]
  15175. ? this_1._backgroundColor : null;
  15176. if (layer.__startIndex === layer.__endIndex) {
  15177. layer.clear(false, clearColor, repaintRects);
  15178. }
  15179. else if (start === layer.__startIndex) {
  15180. var firstEl = list[start];
  15181. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  15182. layer.clear(false, clearColor, repaintRects);
  15183. }
  15184. }
  15185. if (start === -1) {
  15186. console.error('For some unknown reason. drawIndex is -1');
  15187. start = layer.__startIndex;
  15188. }
  15189. var i;
  15190. var repaint = function (repaintRect) {
  15191. var scope = {
  15192. inHover: false,
  15193. allClipped: false,
  15194. prevEl: null,
  15195. viewWidth: _this._width,
  15196. viewHeight: _this._height
  15197. };
  15198. for (i = start; i < layer.__endIndex; i++) {
  15199. var el = list[i];
  15200. if (el.__inHover) {
  15201. needsRefreshHover = true;
  15202. }
  15203. _this._doPaintEl(el, layer, useDirtyRect, repaintRect, scope, i === layer.__endIndex - 1);
  15204. if (useTimer) {
  15205. var dTime = Date.now() - startTime;
  15206. if (dTime > 15) {
  15207. break;
  15208. }
  15209. }
  15210. }
  15211. if (scope.prevElClipPaths) {
  15212. ctx.restore();
  15213. }
  15214. };
  15215. if (repaintRects) {
  15216. if (repaintRects.length === 0) {
  15217. i = layer.__endIndex;
  15218. }
  15219. else {
  15220. var dpr = this_1.dpr;
  15221. for (var r = 0; r < repaintRects.length; ++r) {
  15222. var rect = repaintRects[r];
  15223. ctx.save();
  15224. ctx.beginPath();
  15225. ctx.rect(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  15226. ctx.clip();
  15227. repaint(rect);
  15228. ctx.restore();
  15229. }
  15230. }
  15231. }
  15232. else {
  15233. ctx.save();
  15234. repaint();
  15235. ctx.restore();
  15236. }
  15237. layer.__drawIndex = i;
  15238. if (layer.__drawIndex < layer.__endIndex) {
  15239. finished = false;
  15240. }
  15241. };
  15242. var this_1 = this;
  15243. for (var k = 0; k < layerList.length; k++) {
  15244. _loop_1(k);
  15245. }
  15246. if (env.wxa) {
  15247. each(this._layers, function (layer) {
  15248. if (layer && layer.ctx && layer.ctx.draw) {
  15249. layer.ctx.draw();
  15250. }
  15251. });
  15252. }
  15253. return {
  15254. finished: finished,
  15255. needsRefreshHover: needsRefreshHover
  15256. };
  15257. };
  15258. CanvasPainter.prototype._doPaintEl = function (el, currentLayer, useDirtyRect, repaintRect, scope, isLast) {
  15259. var ctx = currentLayer.ctx;
  15260. if (useDirtyRect) {
  15261. var paintRect = el.getPaintRect();
  15262. if (!repaintRect || paintRect && paintRect.intersect(repaintRect)) {
  15263. brush(ctx, el, scope, isLast);
  15264. el.setPrevPaintRect(paintRect);
  15265. }
  15266. }
  15267. else {
  15268. brush(ctx, el, scope, isLast);
  15269. }
  15270. };
  15271. CanvasPainter.prototype.getLayer = function (zlevel, virtual) {
  15272. if (this._singleCanvas && !this._needsManuallyCompositing) {
  15273. zlevel = CANVAS_ZLEVEL;
  15274. }
  15275. var layer = this._layers[zlevel];
  15276. if (!layer) {
  15277. layer = new Layer('zr_' + zlevel, this, this.dpr);
  15278. layer.zlevel = zlevel;
  15279. layer.__builtin__ = true;
  15280. if (this._layerConfig[zlevel]) {
  15281. merge(layer, this._layerConfig[zlevel], true);
  15282. }
  15283. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  15284. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  15285. }
  15286. if (virtual) {
  15287. layer.virtual = virtual;
  15288. }
  15289. this.insertLayer(zlevel, layer);
  15290. layer.initContext();
  15291. }
  15292. return layer;
  15293. };
  15294. CanvasPainter.prototype.insertLayer = function (zlevel, layer) {
  15295. var layersMap = this._layers;
  15296. var zlevelList = this._zlevelList;
  15297. var len = zlevelList.length;
  15298. var domRoot = this._domRoot;
  15299. var prevLayer = null;
  15300. var i = -1;
  15301. if (layersMap[zlevel]) {
  15302. {
  15303. logError('ZLevel ' + zlevel + ' has been used already');
  15304. }
  15305. return;
  15306. }
  15307. if (!isLayerValid(layer)) {
  15308. {
  15309. logError('Layer of zlevel ' + zlevel + ' is not valid');
  15310. }
  15311. return;
  15312. }
  15313. if (len > 0 && zlevel > zlevelList[0]) {
  15314. for (i = 0; i < len - 1; i++) {
  15315. if (zlevelList[i] < zlevel
  15316. && zlevelList[i + 1] > zlevel) {
  15317. break;
  15318. }
  15319. }
  15320. prevLayer = layersMap[zlevelList[i]];
  15321. }
  15322. zlevelList.splice(i + 1, 0, zlevel);
  15323. layersMap[zlevel] = layer;
  15324. if (!layer.virtual) {
  15325. if (prevLayer) {
  15326. var prevDom = prevLayer.dom;
  15327. if (prevDom.nextSibling) {
  15328. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  15329. }
  15330. else {
  15331. domRoot.appendChild(layer.dom);
  15332. }
  15333. }
  15334. else {
  15335. if (domRoot.firstChild) {
  15336. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  15337. }
  15338. else {
  15339. domRoot.appendChild(layer.dom);
  15340. }
  15341. }
  15342. }
  15343. layer.__painter = this;
  15344. };
  15345. CanvasPainter.prototype.eachLayer = function (cb, context) {
  15346. var zlevelList = this._zlevelList;
  15347. for (var i = 0; i < zlevelList.length; i++) {
  15348. var z = zlevelList[i];
  15349. cb.call(context, this._layers[z], z);
  15350. }
  15351. };
  15352. CanvasPainter.prototype.eachBuiltinLayer = function (cb, context) {
  15353. var zlevelList = this._zlevelList;
  15354. for (var i = 0; i < zlevelList.length; i++) {
  15355. var z = zlevelList[i];
  15356. var layer = this._layers[z];
  15357. if (layer.__builtin__) {
  15358. cb.call(context, layer, z);
  15359. }
  15360. }
  15361. };
  15362. CanvasPainter.prototype.eachOtherLayer = function (cb, context) {
  15363. var zlevelList = this._zlevelList;
  15364. for (var i = 0; i < zlevelList.length; i++) {
  15365. var z = zlevelList[i];
  15366. var layer = this._layers[z];
  15367. if (!layer.__builtin__) {
  15368. cb.call(context, layer, z);
  15369. }
  15370. }
  15371. };
  15372. CanvasPainter.prototype.getLayers = function () {
  15373. return this._layers;
  15374. };
  15375. CanvasPainter.prototype._updateLayerStatus = function (list) {
  15376. this.eachBuiltinLayer(function (layer, z) {
  15377. layer.__dirty = layer.__used = false;
  15378. });
  15379. function updatePrevLayer(idx) {
  15380. if (prevLayer) {
  15381. if (prevLayer.__endIndex !== idx) {
  15382. prevLayer.__dirty = true;
  15383. }
  15384. prevLayer.__endIndex = idx;
  15385. }
  15386. }
  15387. if (this._singleCanvas) {
  15388. for (var i_1 = 1; i_1 < list.length; i_1++) {
  15389. var el = list[i_1];
  15390. if (el.zlevel !== list[i_1 - 1].zlevel || el.incremental) {
  15391. this._needsManuallyCompositing = true;
  15392. break;
  15393. }
  15394. }
  15395. }
  15396. var prevLayer = null;
  15397. var incrementalLayerCount = 0;
  15398. var prevZlevel;
  15399. var i;
  15400. for (i = 0; i < list.length; i++) {
  15401. var el = list[i];
  15402. var zlevel = el.zlevel;
  15403. var layer = void 0;
  15404. if (prevZlevel !== zlevel) {
  15405. prevZlevel = zlevel;
  15406. incrementalLayerCount = 0;
  15407. }
  15408. if (el.incremental) {
  15409. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  15410. layer.incremental = true;
  15411. incrementalLayerCount = 1;
  15412. }
  15413. else {
  15414. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  15415. }
  15416. if (!layer.__builtin__) {
  15417. logError('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  15418. }
  15419. if (layer !== prevLayer) {
  15420. layer.__used = true;
  15421. if (layer.__startIndex !== i) {
  15422. layer.__dirty = true;
  15423. }
  15424. layer.__startIndex = i;
  15425. if (!layer.incremental) {
  15426. layer.__drawIndex = i;
  15427. }
  15428. else {
  15429. layer.__drawIndex = -1;
  15430. }
  15431. updatePrevLayer(i);
  15432. prevLayer = layer;
  15433. }
  15434. if ((el.__dirty & REDRAW_BIT) && !el.__inHover) {
  15435. layer.__dirty = true;
  15436. if (layer.incremental && layer.__drawIndex < 0) {
  15437. layer.__drawIndex = i;
  15438. }
  15439. }
  15440. }
  15441. updatePrevLayer(i);
  15442. this.eachBuiltinLayer(function (layer, z) {
  15443. if (!layer.__used && layer.getElementCount() > 0) {
  15444. layer.__dirty = true;
  15445. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  15446. }
  15447. if (layer.__dirty && layer.__drawIndex < 0) {
  15448. layer.__drawIndex = layer.__startIndex;
  15449. }
  15450. });
  15451. };
  15452. CanvasPainter.prototype.clear = function () {
  15453. this.eachBuiltinLayer(this._clearLayer);
  15454. return this;
  15455. };
  15456. CanvasPainter.prototype._clearLayer = function (layer) {
  15457. layer.clear();
  15458. };
  15459. CanvasPainter.prototype.setBackgroundColor = function (backgroundColor) {
  15460. this._backgroundColor = backgroundColor;
  15461. each(this._layers, function (layer) {
  15462. layer.setUnpainted();
  15463. });
  15464. };
  15465. CanvasPainter.prototype.configLayer = function (zlevel, config) {
  15466. if (config) {
  15467. var layerConfig = this._layerConfig;
  15468. if (!layerConfig[zlevel]) {
  15469. layerConfig[zlevel] = config;
  15470. }
  15471. else {
  15472. merge(layerConfig[zlevel], config, true);
  15473. }
  15474. for (var i = 0; i < this._zlevelList.length; i++) {
  15475. var _zlevel = this._zlevelList[i];
  15476. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  15477. var layer = this._layers[_zlevel];
  15478. merge(layer, layerConfig[zlevel], true);
  15479. }
  15480. }
  15481. }
  15482. };
  15483. CanvasPainter.prototype.delLayer = function (zlevel) {
  15484. var layers = this._layers;
  15485. var zlevelList = this._zlevelList;
  15486. var layer = layers[zlevel];
  15487. if (!layer) {
  15488. return;
  15489. }
  15490. layer.dom.parentNode.removeChild(layer.dom);
  15491. delete layers[zlevel];
  15492. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  15493. };
  15494. CanvasPainter.prototype.resize = function (width, height) {
  15495. if (!this._domRoot.style) {
  15496. if (width == null || height == null) {
  15497. return;
  15498. }
  15499. this._width = width;
  15500. this._height = height;
  15501. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  15502. }
  15503. else {
  15504. var domRoot = this._domRoot;
  15505. domRoot.style.display = 'none';
  15506. var opts = this._opts;
  15507. var root = this.root;
  15508. width != null && (opts.width = width);
  15509. height != null && (opts.height = height);
  15510. width = getSize(root, 0, opts);
  15511. height = getSize(root, 1, opts);
  15512. domRoot.style.display = '';
  15513. if (this._width !== width || height !== this._height) {
  15514. domRoot.style.width = width + 'px';
  15515. domRoot.style.height = height + 'px';
  15516. for (var id in this._layers) {
  15517. if (this._layers.hasOwnProperty(id)) {
  15518. this._layers[id].resize(width, height);
  15519. }
  15520. }
  15521. this.refresh(true);
  15522. }
  15523. this._width = width;
  15524. this._height = height;
  15525. }
  15526. return this;
  15527. };
  15528. CanvasPainter.prototype.clearLayer = function (zlevel) {
  15529. var layer = this._layers[zlevel];
  15530. if (layer) {
  15531. layer.clear();
  15532. }
  15533. };
  15534. CanvasPainter.prototype.dispose = function () {
  15535. this.root.innerHTML = '';
  15536. this.root =
  15537. this.storage =
  15538. this._domRoot =
  15539. this._layers = null;
  15540. };
  15541. CanvasPainter.prototype.getRenderedCanvas = function (opts) {
  15542. opts = opts || {};
  15543. if (this._singleCanvas && !this._compositeManually) {
  15544. return this._layers[CANVAS_ZLEVEL].dom;
  15545. }
  15546. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  15547. imageLayer.initContext();
  15548. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  15549. var ctx = imageLayer.ctx;
  15550. if (opts.pixelRatio <= this.dpr) {
  15551. this.refresh();
  15552. var width_1 = imageLayer.dom.width;
  15553. var height_1 = imageLayer.dom.height;
  15554. this.eachLayer(function (layer) {
  15555. if (layer.__builtin__) {
  15556. ctx.drawImage(layer.dom, 0, 0, width_1, height_1);
  15557. }
  15558. else if (layer.renderToCanvas) {
  15559. ctx.save();
  15560. layer.renderToCanvas(ctx);
  15561. ctx.restore();
  15562. }
  15563. });
  15564. }
  15565. else {
  15566. var scope = {
  15567. inHover: false,
  15568. viewWidth: this._width,
  15569. viewHeight: this._height
  15570. };
  15571. var displayList = this.storage.getDisplayList(true);
  15572. for (var i = 0, len = displayList.length; i < len; i++) {
  15573. var el = displayList[i];
  15574. brush(ctx, el, scope, i === len - 1);
  15575. }
  15576. }
  15577. return imageLayer.dom;
  15578. };
  15579. CanvasPainter.prototype.getWidth = function () {
  15580. return this._width;
  15581. };
  15582. CanvasPainter.prototype.getHeight = function () {
  15583. return this._height;
  15584. };
  15585. return CanvasPainter;
  15586. }());
  15587. var mathSin$4 = Math.sin;
  15588. var mathCos$4 = Math.cos;
  15589. var PI$5 = Math.PI;
  15590. var PI2$6 = Math.PI * 2;
  15591. var degree = 180 / PI$5;
  15592. var SVGPathRebuilder = (function () {
  15593. function SVGPathRebuilder() {
  15594. }
  15595. SVGPathRebuilder.prototype.reset = function (precision) {
  15596. this._start = true;
  15597. this._d = [];
  15598. this._str = '';
  15599. this._p = Math.pow(10, precision || 4);
  15600. };
  15601. SVGPathRebuilder.prototype.moveTo = function (x, y) {
  15602. this._add('M', x, y);
  15603. };
  15604. SVGPathRebuilder.prototype.lineTo = function (x, y) {
  15605. this._add('L', x, y);
  15606. };
  15607. SVGPathRebuilder.prototype.bezierCurveTo = function (x, y, x2, y2, x3, y3) {
  15608. this._add('C', x, y, x2, y2, x3, y3);
  15609. };
  15610. SVGPathRebuilder.prototype.quadraticCurveTo = function (x, y, x2, y2) {
  15611. this._add('Q', x, y, x2, y2);
  15612. };
  15613. SVGPathRebuilder.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  15614. this.ellipse(cx, cy, r, r, 0, startAngle, endAngle, anticlockwise);
  15615. };
  15616. SVGPathRebuilder.prototype.ellipse = function (cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise) {
  15617. var dTheta = endAngle - startAngle;
  15618. var clockwise = !anticlockwise;
  15619. var dThetaPositive = Math.abs(dTheta);
  15620. var isCircle = isAroundZero$1(dThetaPositive - PI2$6)
  15621. || (clockwise ? dTheta >= PI2$6 : -dTheta >= PI2$6);
  15622. var unifiedTheta = dTheta > 0 ? dTheta % PI2$6 : (dTheta % PI2$6 + PI2$6);
  15623. var large = false;
  15624. if (isCircle) {
  15625. large = true;
  15626. }
  15627. else if (isAroundZero$1(dThetaPositive)) {
  15628. large = false;
  15629. }
  15630. else {
  15631. large = (unifiedTheta >= PI$5) === !!clockwise;
  15632. }
  15633. var x0 = cx + rx * mathCos$4(startAngle);
  15634. var y0 = cy + ry * mathSin$4(startAngle);
  15635. if (this._start) {
  15636. this._add('M', x0, y0);
  15637. }
  15638. var xRot = Math.round(psi * degree);
  15639. if (isCircle) {
  15640. var p = 1 / this._p;
  15641. var dTheta_1 = (clockwise ? 1 : -1) * (PI2$6 - p);
  15642. this._add('A', rx, ry, xRot, 1, +clockwise, cx + rx * mathCos$4(startAngle + dTheta_1), cy + ry * mathSin$4(startAngle + dTheta_1));
  15643. if (p > 1e-2) {
  15644. this._add('A', rx, ry, xRot, 0, +clockwise, x0, y0);
  15645. }
  15646. }
  15647. else {
  15648. var x = cx + rx * mathCos$4(endAngle);
  15649. var y = cy + ry * mathSin$4(endAngle);
  15650. this._add('A', rx, ry, xRot, +large, +clockwise, x, y);
  15651. }
  15652. };
  15653. SVGPathRebuilder.prototype.rect = function (x, y, w, h) {
  15654. this._add('M', x, y);
  15655. this._add('l', w, 0);
  15656. this._add('l', 0, h);
  15657. this._add('l', -w, 0);
  15658. this._add('Z');
  15659. };
  15660. SVGPathRebuilder.prototype.closePath = function () {
  15661. if (this._d.length > 0) {
  15662. this._add('Z');
  15663. }
  15664. };
  15665. SVGPathRebuilder.prototype._add = function (cmd, a, b, c, d, e, f, g, h) {
  15666. var vals = [];
  15667. var p = this._p;
  15668. for (var i = 1; i < arguments.length; i++) {
  15669. var val = arguments[i];
  15670. if (isNaN(val)) {
  15671. this._invalid = true;
  15672. return;
  15673. }
  15674. vals.push(Math.round(val * p) / p);
  15675. }
  15676. this._d.push(cmd + vals.join(' '));
  15677. this._start = cmd === 'Z';
  15678. };
  15679. SVGPathRebuilder.prototype.generateStr = function () {
  15680. this._str = this._invalid ? '' : this._d.join('');
  15681. this._d = [];
  15682. };
  15683. SVGPathRebuilder.prototype.getStr = function () {
  15684. return this._str;
  15685. };
  15686. return SVGPathRebuilder;
  15687. }());
  15688. var NONE = 'none';
  15689. var mathRound$1 = Math.round;
  15690. function pathHasFill(style) {
  15691. var fill = style.fill;
  15692. return fill != null && fill !== NONE;
  15693. }
  15694. function pathHasStroke(style) {
  15695. var stroke = style.stroke;
  15696. return stroke != null && stroke !== NONE;
  15697. }
  15698. var strokeProps = ['lineCap', 'miterLimit', 'lineJoin'];
  15699. var svgStrokeProps = map(strokeProps, function (prop) { return "stroke-" + prop.toLowerCase(); });
  15700. function mapStyleToAttrs(updateAttr, style, el, forceUpdate) {
  15701. var opacity = style.opacity == null ? 1 : style.opacity;
  15702. if (el instanceof ZRImage) {
  15703. updateAttr('opacity', opacity);
  15704. return;
  15705. }
  15706. if (pathHasFill(style)) {
  15707. var fill = normalizeColor(style.fill);
  15708. updateAttr('fill', fill.color);
  15709. var fillOpacity = style.fillOpacity != null
  15710. ? style.fillOpacity * fill.opacity * opacity
  15711. : fill.opacity * opacity;
  15712. if (forceUpdate || fillOpacity < 1) {
  15713. updateAttr('fill-opacity', fillOpacity);
  15714. }
  15715. }
  15716. else {
  15717. updateAttr('fill', NONE);
  15718. }
  15719. if (pathHasStroke(style)) {
  15720. var stroke = normalizeColor(style.stroke);
  15721. updateAttr('stroke', stroke.color);
  15722. var strokeScale = style.strokeNoScale
  15723. ? el.getLineScale()
  15724. : 1;
  15725. var strokeWidth = (strokeScale ? (style.lineWidth || 0) / strokeScale : 0);
  15726. var strokeOpacity = style.strokeOpacity != null
  15727. ? style.strokeOpacity * stroke.opacity * opacity
  15728. : stroke.opacity * opacity;
  15729. var strokeFirst = style.strokeFirst;
  15730. if (forceUpdate || strokeWidth !== 1) {
  15731. updateAttr('stroke-width', strokeWidth);
  15732. }
  15733. if (forceUpdate || strokeFirst) {
  15734. updateAttr('paint-order', strokeFirst ? 'stroke' : 'fill');
  15735. }
  15736. if (forceUpdate || strokeOpacity < 1) {
  15737. updateAttr('stroke-opacity', strokeOpacity);
  15738. }
  15739. if (style.lineDash) {
  15740. var _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  15741. if (lineDash) {
  15742. lineDashOffset = mathRound$1(lineDashOffset || 0);
  15743. updateAttr('stroke-dasharray', lineDash.join(','));
  15744. if (lineDashOffset || forceUpdate) {
  15745. updateAttr('stroke-dashoffset', lineDashOffset);
  15746. }
  15747. }
  15748. }
  15749. else if (forceUpdate) {
  15750. updateAttr('stroke-dasharray', NONE);
  15751. }
  15752. for (var i = 0; i < strokeProps.length; i++) {
  15753. var propName = strokeProps[i];
  15754. if (forceUpdate || style[propName] !== DEFAULT_PATH_STYLE[propName]) {
  15755. var val = style[propName] || DEFAULT_PATH_STYLE[propName];
  15756. val && updateAttr(svgStrokeProps[i], val);
  15757. }
  15758. }
  15759. }
  15760. else if (forceUpdate) {
  15761. updateAttr('stroke', NONE);
  15762. }
  15763. }
  15764. var SVGNS = 'http://www.w3.org/2000/svg';
  15765. var XLINKNS = 'http://www.w3.org/1999/xlink';
  15766. var XMLNS = 'http://www.w3.org/2000/xmlns/';
  15767. var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
  15768. function createElement(name) {
  15769. return document.createElementNS(SVGNS, name);
  15770. }
  15771. function createVNode(tag, key, attrs, children, text) {
  15772. return {
  15773. tag: tag,
  15774. attrs: attrs || {},
  15775. children: children,
  15776. text: text,
  15777. key: key
  15778. };
  15779. }
  15780. function createElementOpen(name, attrs) {
  15781. var attrsStr = [];
  15782. if (attrs) {
  15783. for (var key in attrs) {
  15784. var val = attrs[key];
  15785. var part = key;
  15786. if (val === false) {
  15787. continue;
  15788. }
  15789. else if (val !== true && val != null) {
  15790. part += "=\"" + val + "\"";
  15791. }
  15792. attrsStr.push(part);
  15793. }
  15794. }
  15795. return "<" + name + " " + attrsStr.join(' ') + ">";
  15796. }
  15797. function createElementClose(name) {
  15798. return "</" + name + ">";
  15799. }
  15800. function vNodeToString(el, opts) {
  15801. opts = opts || {};
  15802. var S = opts.newline ? '\n' : '';
  15803. function convertElToString(el) {
  15804. var children = el.children, tag = el.tag, attrs = el.attrs, text = el.text;
  15805. return createElementOpen(tag, attrs)
  15806. + (tag !== 'style' ? encodeHTML(text) : text || '')
  15807. + (children ? "" + S + map(children, function (child) { return convertElToString(child); }).join(S) + S : '')
  15808. + createElementClose(tag);
  15809. }
  15810. return convertElToString(el);
  15811. }
  15812. function getCssString(selectorNodes, animationNodes, opts) {
  15813. opts = opts || {};
  15814. var S = opts.newline ? '\n' : '';
  15815. var bracketBegin = " {" + S;
  15816. var bracketEnd = S + "}";
  15817. var selectors = map(keys(selectorNodes), function (className) {
  15818. return className + bracketBegin + map(keys(selectorNodes[className]), function (attrName) {
  15819. return attrName + ":" + selectorNodes[className][attrName] + ";";
  15820. }).join(S) + bracketEnd;
  15821. }).join(S);
  15822. var animations = map(keys(animationNodes), function (animationName) {
  15823. return "@keyframes " + animationName + bracketBegin + map(keys(animationNodes[animationName]), function (percent) {
  15824. return percent + bracketBegin + map(keys(animationNodes[animationName][percent]), function (attrName) {
  15825. var val = animationNodes[animationName][percent][attrName];
  15826. if (attrName === 'd') {
  15827. val = "path(\"" + val + "\")";
  15828. }
  15829. return attrName + ":" + val + ";";
  15830. }).join(S) + bracketEnd;
  15831. }).join(S) + bracketEnd;
  15832. }).join(S);
  15833. if (!selectors && !animations) {
  15834. return '';
  15835. }
  15836. return ['<![CDATA[', selectors, animations, ']]>'].join(S);
  15837. }
  15838. function createBrushScope(zrId) {
  15839. return {
  15840. zrId: zrId,
  15841. shadowCache: {},
  15842. patternCache: {},
  15843. gradientCache: {},
  15844. clipPathCache: {},
  15845. defs: {},
  15846. cssNodes: {},
  15847. cssAnims: {},
  15848. cssClassIdx: 0,
  15849. cssAnimIdx: 0,
  15850. shadowIdx: 0,
  15851. gradientIdx: 0,
  15852. patternIdx: 0,
  15853. clipPathIdx: 0
  15854. };
  15855. }
  15856. function createSVGVNode(width, height, children, useViewBox) {
  15857. return createVNode('svg', 'root', {
  15858. 'width': width,
  15859. 'height': height,
  15860. 'xmlns': SVGNS,
  15861. 'xmlns:xlink': XLINKNS,
  15862. 'version': '1.1',
  15863. 'baseProfile': 'full',
  15864. 'viewBox': useViewBox ? "0 0 " + width + " " + height : false
  15865. }, children);
  15866. }
  15867. var EASING_MAP = {
  15868. cubicIn: '0.32,0,0.67,0',
  15869. cubicOut: '0.33,1,0.68,1',
  15870. cubicInOut: '0.65,0,0.35,1',
  15871. quadraticIn: '0.11,0,0.5,0',
  15872. quadraticOut: '0.5,1,0.89,1',
  15873. quadraticInOut: '0.45,0,0.55,1',
  15874. quarticIn: '0.5,0,0.75,0',
  15875. quarticOut: '0.25,1,0.5,1',
  15876. quarticInOut: '0.76,0,0.24,1',
  15877. quinticIn: '0.64,0,0.78,0',
  15878. quinticOut: '0.22,1,0.36,1',
  15879. quinticInOut: '0.83,0,0.17,1',
  15880. sinusoidalIn: '0.12,0,0.39,0',
  15881. sinusoidalOut: '0.61,1,0.88,1',
  15882. sinusoidalInOut: '0.37,0,0.63,1',
  15883. exponentialIn: '0.7,0,0.84,0',
  15884. exponentialOut: '0.16,1,0.3,1',
  15885. exponentialInOut: '0.87,0,0.13,1',
  15886. circularIn: '0.55,0,1,0.45',
  15887. circularOut: '0,0.55,0.45,1',
  15888. circularInOut: '0.85,0,0.15,1'
  15889. };
  15890. var transformOriginKey = 'transform-origin';
  15891. function buildPathString(el, kfShape, path) {
  15892. var shape = extend({}, el.shape);
  15893. extend(shape, kfShape);
  15894. el.buildPath(path, shape);
  15895. var svgPathBuilder = new SVGPathRebuilder();
  15896. svgPathBuilder.reset(getPathPrecision(el));
  15897. path.rebuildPath(svgPathBuilder, 1);
  15898. svgPathBuilder.generateStr();
  15899. return svgPathBuilder.getStr();
  15900. }
  15901. function setTransformOrigin(target, transform) {
  15902. var originX = transform.originX, originY = transform.originY;
  15903. if (originX || originY) {
  15904. target[transformOriginKey] = originX + "px " + originY + "px";
  15905. }
  15906. }
  15907. var ANIMATE_STYLE_MAP = {
  15908. fill: 'fill',
  15909. opacity: 'opacity',
  15910. lineWidth: 'stroke-width',
  15911. lineDashOffset: 'stroke-dashoffset'
  15912. };
  15913. function addAnimation(cssAnim, scope) {
  15914. var animationName = scope.zrId + '-ani-' + scope.cssAnimIdx++;
  15915. scope.cssAnims[animationName] = cssAnim;
  15916. return animationName;
  15917. }
  15918. function createCompoundPathCSSAnimation(el, attrs, scope) {
  15919. var paths = el.shape.paths;
  15920. var composedAnim = {};
  15921. var cssAnimationCfg;
  15922. var cssAnimationName;
  15923. each(paths, function (path) {
  15924. var subScope = createBrushScope(scope.zrId);
  15925. subScope.animation = true;
  15926. createCSSAnimation(path, {}, subScope, true);
  15927. var cssAnims = subScope.cssAnims;
  15928. var cssNodes = subScope.cssNodes;
  15929. var animNames = keys(cssAnims);
  15930. var len = animNames.length;
  15931. if (!len) {
  15932. return;
  15933. }
  15934. cssAnimationName = animNames[len - 1];
  15935. var lastAnim = cssAnims[cssAnimationName];
  15936. for (var percent in lastAnim) {
  15937. var kf = lastAnim[percent];
  15938. composedAnim[percent] = composedAnim[percent] || { d: '' };
  15939. composedAnim[percent].d += kf.d || '';
  15940. }
  15941. for (var className in cssNodes) {
  15942. var val = cssNodes[className].animation;
  15943. if (val.indexOf(cssAnimationName) >= 0) {
  15944. cssAnimationCfg = val;
  15945. }
  15946. }
  15947. });
  15948. if (!cssAnimationCfg) {
  15949. return;
  15950. }
  15951. attrs.d = false;
  15952. var animationName = addAnimation(composedAnim, scope);
  15953. return cssAnimationCfg.replace(cssAnimationName, animationName);
  15954. }
  15955. function getEasingFunc(easing) {
  15956. return isString(easing)
  15957. ? EASING_MAP[easing]
  15958. ? "cubic-bezier(" + EASING_MAP[easing] + ")"
  15959. : createCubicEasingFunc(easing) ? easing : ''
  15960. : '';
  15961. }
  15962. function createCSSAnimation(el, attrs, scope, onlyShape) {
  15963. var animators = el.animators;
  15964. var len = animators.length;
  15965. var cssAnimations = [];
  15966. if (el instanceof CompoundPath) {
  15967. var animationCfg = createCompoundPathCSSAnimation(el, attrs, scope);
  15968. if (animationCfg) {
  15969. cssAnimations.push(animationCfg);
  15970. }
  15971. else if (!len) {
  15972. return;
  15973. }
  15974. }
  15975. else if (!len) {
  15976. return;
  15977. }
  15978. var groupAnimators = {};
  15979. for (var i = 0; i < len; i++) {
  15980. var animator = animators[i];
  15981. var cfgArr = [animator.getMaxTime() / 1000 + 's'];
  15982. var easing = getEasingFunc(animator.getClip().easing);
  15983. var delay = animator.getDelay();
  15984. if (easing) {
  15985. cfgArr.push(easing);
  15986. }
  15987. else {
  15988. cfgArr.push('linear');
  15989. }
  15990. if (delay) {
  15991. cfgArr.push(delay / 1000 + 's');
  15992. }
  15993. if (animator.getLoop()) {
  15994. cfgArr.push('infinite');
  15995. }
  15996. var cfg = cfgArr.join(' ');
  15997. groupAnimators[cfg] = groupAnimators[cfg] || [cfg, []];
  15998. groupAnimators[cfg][1].push(animator);
  15999. }
  16000. function createSingleCSSAnimation(groupAnimator) {
  16001. var animators = groupAnimator[1];
  16002. var len = animators.length;
  16003. var transformKfs = {};
  16004. var shapeKfs = {};
  16005. var finalKfs = {};
  16006. var animationTimingFunctionAttrName = 'animation-timing-function';
  16007. function saveAnimatorTrackToCssKfs(animator, cssKfs, toCssAttrName) {
  16008. var tracks = animator.getTracks();
  16009. var maxTime = animator.getMaxTime();
  16010. for (var k = 0; k < tracks.length; k++) {
  16011. var track = tracks[k];
  16012. if (track.needsAnimate()) {
  16013. var kfs = track.keyframes;
  16014. var attrName = track.propName;
  16015. toCssAttrName && (attrName = toCssAttrName(attrName));
  16016. if (attrName) {
  16017. for (var i = 0; i < kfs.length; i++) {
  16018. var kf = kfs[i];
  16019. var percent = Math.round(kf.time / maxTime * 100) + '%';
  16020. var kfEasing = getEasingFunc(kf.easing);
  16021. var rawValue = kf.rawValue;
  16022. if (isString(rawValue) || isNumber(rawValue)) {
  16023. cssKfs[percent] = cssKfs[percent] || {};
  16024. cssKfs[percent][attrName] = kf.rawValue;
  16025. if (kfEasing) {
  16026. cssKfs[percent][animationTimingFunctionAttrName] = kfEasing;
  16027. }
  16028. }
  16029. }
  16030. }
  16031. }
  16032. }
  16033. }
  16034. for (var i = 0; i < len; i++) {
  16035. var animator = animators[i];
  16036. var targetProp = animator.targetName;
  16037. if (!targetProp) {
  16038. !onlyShape && saveAnimatorTrackToCssKfs(animator, transformKfs);
  16039. }
  16040. else if (targetProp === 'shape') {
  16041. saveAnimatorTrackToCssKfs(animator, shapeKfs);
  16042. }
  16043. }
  16044. for (var percent in transformKfs) {
  16045. var transform = {};
  16046. copyTransform(transform, el);
  16047. extend(transform, transformKfs[percent]);
  16048. var str = getSRTTransformString(transform);
  16049. var timingFunction = transformKfs[percent][animationTimingFunctionAttrName];
  16050. finalKfs[percent] = str ? {
  16051. transform: str
  16052. } : {};
  16053. setTransformOrigin(finalKfs[percent], transform);
  16054. if (timingFunction) {
  16055. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16056. }
  16057. }
  16058. var path;
  16059. var canAnimateShape = true;
  16060. for (var percent in shapeKfs) {
  16061. finalKfs[percent] = finalKfs[percent] || {};
  16062. var isFirst = !path;
  16063. var timingFunction = shapeKfs[percent][animationTimingFunctionAttrName];
  16064. if (isFirst) {
  16065. path = new PathProxy();
  16066. }
  16067. var len_1 = path.len();
  16068. path.reset();
  16069. finalKfs[percent].d = buildPathString(el, shapeKfs[percent], path);
  16070. var newLen = path.len();
  16071. if (!isFirst && len_1 !== newLen) {
  16072. canAnimateShape = false;
  16073. break;
  16074. }
  16075. if (timingFunction) {
  16076. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16077. }
  16078. }
  16079. if (!canAnimateShape) {
  16080. for (var percent in finalKfs) {
  16081. delete finalKfs[percent].d;
  16082. }
  16083. }
  16084. if (!onlyShape) {
  16085. for (var i = 0; i < len; i++) {
  16086. var animator = animators[i];
  16087. var targetProp = animator.targetName;
  16088. if (targetProp === 'style') {
  16089. saveAnimatorTrackToCssKfs(animator, finalKfs, function (propName) { return ANIMATE_STYLE_MAP[propName]; });
  16090. }
  16091. }
  16092. }
  16093. var percents = keys(finalKfs);
  16094. var allTransformOriginSame = true;
  16095. var transformOrigin;
  16096. for (var i = 1; i < percents.length; i++) {
  16097. var p0 = percents[i - 1];
  16098. var p1 = percents[i];
  16099. if (finalKfs[p0][transformOriginKey] !== finalKfs[p1][transformOriginKey]) {
  16100. allTransformOriginSame = false;
  16101. break;
  16102. }
  16103. transformOrigin = finalKfs[p0][transformOriginKey];
  16104. }
  16105. if (allTransformOriginSame && transformOrigin) {
  16106. for (var percent in finalKfs) {
  16107. if (finalKfs[percent][transformOriginKey]) {
  16108. delete finalKfs[percent][transformOriginKey];
  16109. }
  16110. }
  16111. attrs[transformOriginKey] = transformOrigin;
  16112. }
  16113. if (filter(percents, function (percent) { return keys(finalKfs[percent]).length > 0; }).length) {
  16114. var animationName = addAnimation(finalKfs, scope);
  16115. return animationName + " " + groupAnimator[0] + " both";
  16116. }
  16117. }
  16118. for (var key in groupAnimators) {
  16119. var animationCfg = createSingleCSSAnimation(groupAnimators[key]);
  16120. if (animationCfg) {
  16121. cssAnimations.push(animationCfg);
  16122. }
  16123. }
  16124. if (cssAnimations.length) {
  16125. var className = scope.zrId + '-cls-' + scope.cssClassIdx++;
  16126. scope.cssNodes['.' + className] = {
  16127. animation: cssAnimations.join(',')
  16128. };
  16129. attrs["class"] = className;
  16130. }
  16131. }
  16132. var round$1 = Math.round;
  16133. function isImageLike$1(val) {
  16134. return val && isString(val.src);
  16135. }
  16136. function isCanvasLike(val) {
  16137. return val && isFunction(val.toDataURL);
  16138. }
  16139. function setStyleAttrs(attrs, style, el, scope) {
  16140. mapStyleToAttrs(function (key, val) {
  16141. var isFillStroke = key === 'fill' || key === 'stroke';
  16142. if (isFillStroke && isGradient(val)) {
  16143. setGradient(style, attrs, key, scope);
  16144. }
  16145. else if (isFillStroke && isPattern(val)) {
  16146. setPattern(el, attrs, key, scope);
  16147. }
  16148. else {
  16149. attrs[key] = val;
  16150. }
  16151. }, style, el, false);
  16152. setShadow(el, attrs, scope);
  16153. }
  16154. function noRotateScale(m) {
  16155. return isAroundZero$1(m[0] - 1)
  16156. && isAroundZero$1(m[1])
  16157. && isAroundZero$1(m[2])
  16158. && isAroundZero$1(m[3] - 1);
  16159. }
  16160. function noTranslate(m) {
  16161. return isAroundZero$1(m[4]) && isAroundZero$1(m[5]);
  16162. }
  16163. function setTransform(attrs, m, compress) {
  16164. if (m && !(noTranslate(m) && noRotateScale(m))) {
  16165. var mul = compress ? 10 : 1e4;
  16166. attrs.transform = noRotateScale(m)
  16167. ? "translate(" + round$1(m[4] * mul) / mul + " " + round$1(m[5] * mul) / mul + ")" : getMatrixStr(m);
  16168. }
  16169. }
  16170. function convertPolyShape(shape, attrs, mul) {
  16171. var points = shape.points;
  16172. var strArr = [];
  16173. for (var i = 0; i < points.length; i++) {
  16174. strArr.push(round$1(points[i][0] * mul) / mul);
  16175. strArr.push(round$1(points[i][1] * mul) / mul);
  16176. }
  16177. attrs.points = strArr.join(' ');
  16178. }
  16179. function validatePolyShape(shape) {
  16180. return !shape.smooth;
  16181. }
  16182. function createAttrsConvert(desc) {
  16183. var normalizedDesc = map(desc, function (item) {
  16184. return (typeof item === 'string' ? [item, item] : item);
  16185. });
  16186. return function (shape, attrs, mul) {
  16187. for (var i = 0; i < normalizedDesc.length; i++) {
  16188. var item = normalizedDesc[i];
  16189. var val = shape[item[0]];
  16190. if (val != null) {
  16191. attrs[item[1]] = round$1(val * mul) / mul;
  16192. }
  16193. }
  16194. };
  16195. }
  16196. var builtinShapesDef = {
  16197. circle: [createAttrsConvert(['cx', 'cy', 'r'])],
  16198. polyline: [convertPolyShape, validatePolyShape],
  16199. polygon: [convertPolyShape, validatePolyShape]
  16200. };
  16201. function hasShapeAnimation(el) {
  16202. var animators = el.animators;
  16203. for (var i = 0; i < animators.length; i++) {
  16204. if (animators[i].targetName === 'shape') {
  16205. return true;
  16206. }
  16207. }
  16208. return false;
  16209. }
  16210. function brushSVGPath(el, scope) {
  16211. var style = el.style;
  16212. var shape = el.shape;
  16213. var builtinShpDef = builtinShapesDef[el.type];
  16214. var attrs = {};
  16215. var needsAnimate = scope.animation;
  16216. var svgElType = 'path';
  16217. var strokePercent = el.style.strokePercent;
  16218. var precision = (scope.compress && getPathPrecision(el)) || 4;
  16219. if (builtinShpDef
  16220. && !scope.willUpdate
  16221. && !(builtinShpDef[1] && !builtinShpDef[1](shape))
  16222. && !(needsAnimate && hasShapeAnimation(el))
  16223. && !(strokePercent < 1)) {
  16224. svgElType = el.type;
  16225. var mul = Math.pow(10, precision);
  16226. builtinShpDef[0](shape, attrs, mul);
  16227. }
  16228. else {
  16229. var needBuildPath = !el.path || el.shapeChanged();
  16230. if (!el.path) {
  16231. el.createPathProxy();
  16232. }
  16233. var path = el.path;
  16234. if (needBuildPath) {
  16235. path.beginPath();
  16236. el.buildPath(path, el.shape);
  16237. el.pathUpdated();
  16238. }
  16239. var pathVersion = path.getVersion();
  16240. var elExt = el;
  16241. var svgPathBuilder = elExt.__svgPathBuilder;
  16242. if (elExt.__svgPathVersion !== pathVersion
  16243. || !svgPathBuilder
  16244. || strokePercent !== elExt.__svgPathStrokePercent) {
  16245. if (!svgPathBuilder) {
  16246. svgPathBuilder = elExt.__svgPathBuilder = new SVGPathRebuilder();
  16247. }
  16248. svgPathBuilder.reset(precision);
  16249. path.rebuildPath(svgPathBuilder, strokePercent);
  16250. svgPathBuilder.generateStr();
  16251. elExt.__svgPathVersion = pathVersion;
  16252. elExt.__svgPathStrokePercent = strokePercent;
  16253. }
  16254. attrs.d = svgPathBuilder.getStr();
  16255. }
  16256. setTransform(attrs, el.transform);
  16257. setStyleAttrs(attrs, style, el, scope);
  16258. scope.animation && createCSSAnimation(el, attrs, scope);
  16259. return createVNode(svgElType, el.id + '', attrs);
  16260. }
  16261. function brushSVGImage(el, scope) {
  16262. var style = el.style;
  16263. var image = style.image;
  16264. if (image && !isString(image)) {
  16265. if (isImageLike$1(image)) {
  16266. image = image.src;
  16267. }
  16268. else if (isCanvasLike(image)) {
  16269. image = image.toDataURL();
  16270. }
  16271. }
  16272. if (!image) {
  16273. return;
  16274. }
  16275. var x = style.x || 0;
  16276. var y = style.y || 0;
  16277. var dw = style.width;
  16278. var dh = style.height;
  16279. var attrs = {
  16280. href: image,
  16281. width: dw,
  16282. height: dh
  16283. };
  16284. if (x) {
  16285. attrs.x = x;
  16286. }
  16287. if (y) {
  16288. attrs.y = y;
  16289. }
  16290. setTransform(attrs, el.transform);
  16291. setStyleAttrs(attrs, style, el, scope);
  16292. scope.animation && createCSSAnimation(el, attrs, scope);
  16293. return createVNode('image', el.id + '', attrs);
  16294. }
  16295. function brushSVGTSpan(el, scope) {
  16296. var style = el.style;
  16297. var text = style.text;
  16298. text != null && (text += '');
  16299. if (!text || isNaN(style.x) || isNaN(style.y)) {
  16300. return;
  16301. }
  16302. var font = style.font || DEFAULT_FONT;
  16303. var x = style.x || 0;
  16304. var y = adjustTextY(style.y || 0, getLineHeight(font), style.textBaseline);
  16305. var textAlign = TEXT_ALIGN_TO_ANCHOR[style.textAlign]
  16306. || style.textAlign;
  16307. var attrs = {
  16308. 'dominant-baseline': 'central',
  16309. 'text-anchor': textAlign
  16310. };
  16311. if (hasSeparateFont(style)) {
  16312. var separatedFontStr = '';
  16313. var fontStyle = style.fontStyle;
  16314. var fontSize = parseFontSize(style.fontSize);
  16315. if (!parseFloat(fontSize)) {
  16316. return;
  16317. }
  16318. var fontFamily = style.fontFamily || DEFAULT_FONT_FAMILY;
  16319. var fontWeight = style.fontWeight;
  16320. separatedFontStr += "font-size:" + fontSize + ";font-family:" + fontFamily + ";";
  16321. if (fontStyle && fontStyle !== 'normal') {
  16322. separatedFontStr += "font-style:" + fontStyle + ";";
  16323. }
  16324. if (fontWeight && fontWeight !== 'normal') {
  16325. separatedFontStr += "font-weight:" + fontWeight + ";";
  16326. }
  16327. attrs.style = separatedFontStr;
  16328. }
  16329. else {
  16330. attrs.style = "font: " + font;
  16331. }
  16332. if (text.match(/\s/)) {
  16333. attrs['xml:space'] = 'preserve';
  16334. }
  16335. if (x) {
  16336. attrs.x = x;
  16337. }
  16338. if (y) {
  16339. attrs.y = y;
  16340. }
  16341. setTransform(attrs, el.transform);
  16342. setStyleAttrs(attrs, style, el, scope);
  16343. scope.animation && createCSSAnimation(el, attrs, scope);
  16344. return createVNode('text', el.id + '', attrs, undefined, text);
  16345. }
  16346. function brush$1(el, scope) {
  16347. if (el instanceof Path) {
  16348. return brushSVGPath(el, scope);
  16349. }
  16350. else if (el instanceof ZRImage) {
  16351. return brushSVGImage(el, scope);
  16352. }
  16353. else if (el instanceof TSpan) {
  16354. return brushSVGTSpan(el, scope);
  16355. }
  16356. }
  16357. function setShadow(el, attrs, scope) {
  16358. var style = el.style;
  16359. if (hasShadow(style)) {
  16360. var shadowKey = getShadowKey(el);
  16361. var shadowCache = scope.shadowCache;
  16362. var shadowId = shadowCache[shadowKey];
  16363. if (!shadowId) {
  16364. var globalScale = el.getGlobalScale();
  16365. var scaleX = globalScale[0];
  16366. var scaleY = globalScale[1];
  16367. if (!scaleX || !scaleY) {
  16368. return;
  16369. }
  16370. var offsetX = style.shadowOffsetX || 0;
  16371. var offsetY = style.shadowOffsetY || 0;
  16372. var blur_1 = style.shadowBlur;
  16373. var _a = normalizeColor(style.shadowColor), opacity = _a.opacity, color = _a.color;
  16374. var stdDx = blur_1 / 2 / scaleX;
  16375. var stdDy = blur_1 / 2 / scaleY;
  16376. var stdDeviation = stdDx + ' ' + stdDy;
  16377. shadowId = scope.zrId + '-s' + scope.shadowIdx++;
  16378. scope.defs[shadowId] = createVNode('filter', shadowId, {
  16379. 'id': shadowId,
  16380. 'x': '-100%',
  16381. 'y': '-100%',
  16382. 'width': '300%',
  16383. 'height': '300%'
  16384. }, [
  16385. createVNode('feDropShadow', '', {
  16386. 'dx': offsetX / scaleX,
  16387. 'dy': offsetY / scaleY,
  16388. 'stdDeviation': stdDeviation,
  16389. 'flood-color': color,
  16390. 'flood-opacity': opacity
  16391. })
  16392. ]);
  16393. shadowCache[shadowKey] = shadowId;
  16394. }
  16395. attrs.filter = getIdURL(shadowId);
  16396. }
  16397. }
  16398. function setGradient(style, attrs, target, scope) {
  16399. var val = style[target];
  16400. var gradientTag;
  16401. var gradientAttrs = {
  16402. 'gradientUnits': val.global
  16403. ? 'userSpaceOnUse'
  16404. : 'objectBoundingBox'
  16405. };
  16406. if (isLinearGradient(val)) {
  16407. gradientTag = 'linearGradient';
  16408. gradientAttrs.x1 = val.x;
  16409. gradientAttrs.y1 = val.y;
  16410. gradientAttrs.x2 = val.x2;
  16411. gradientAttrs.y2 = val.y2;
  16412. }
  16413. else if (isRadialGradient(val)) {
  16414. gradientTag = 'radialGradient';
  16415. gradientAttrs.cx = retrieve2(val.x, 0.5);
  16416. gradientAttrs.cy = retrieve2(val.y, 0.5);
  16417. gradientAttrs.r = retrieve2(val.r, 0.5);
  16418. }
  16419. else {
  16420. {
  16421. logError('Illegal gradient type.');
  16422. }
  16423. return;
  16424. }
  16425. var colors = val.colorStops;
  16426. var colorStops = [];
  16427. for (var i = 0, len = colors.length; i < len; ++i) {
  16428. var offset = round4(colors[i].offset) * 100 + '%';
  16429. var stopColor = colors[i].color;
  16430. var _a = normalizeColor(stopColor), color = _a.color, opacity = _a.opacity;
  16431. var stopsAttrs = {
  16432. 'offset': offset
  16433. };
  16434. stopsAttrs['stop-color'] = color;
  16435. if (opacity < 1) {
  16436. stopsAttrs['stop-opacity'] = opacity;
  16437. }
  16438. colorStops.push(createVNode('stop', i + '', stopsAttrs));
  16439. }
  16440. var gradientVNode = createVNode(gradientTag, '', gradientAttrs, colorStops);
  16441. var gradientKey = vNodeToString(gradientVNode);
  16442. var gradientCache = scope.gradientCache;
  16443. var gradientId = gradientCache[gradientKey];
  16444. if (!gradientId) {
  16445. gradientId = scope.zrId + '-g' + scope.gradientIdx++;
  16446. gradientCache[gradientKey] = gradientId;
  16447. gradientAttrs.id = gradientId;
  16448. scope.defs[gradientId] = createVNode(gradientTag, gradientId, gradientAttrs, colorStops);
  16449. }
  16450. attrs[target] = getIdURL(gradientId);
  16451. }
  16452. function setPattern(el, attrs, target, scope) {
  16453. var val = el.style[target];
  16454. var boundingRect = el.getBoundingRect();
  16455. var patternAttrs = {};
  16456. var repeat = val.repeat;
  16457. var noRepeat = repeat === 'no-repeat';
  16458. var repeatX = repeat === 'repeat-x';
  16459. var repeatY = repeat === 'repeat-y';
  16460. var child;
  16461. if (isImagePattern(val)) {
  16462. var imageWidth_1 = val.imageWidth;
  16463. var imageHeight_1 = val.imageHeight;
  16464. var imageSrc = void 0;
  16465. var patternImage = val.image;
  16466. if (isString(patternImage)) {
  16467. imageSrc = patternImage;
  16468. }
  16469. else if (isImageLike$1(patternImage)) {
  16470. imageSrc = patternImage.src;
  16471. }
  16472. else if (isCanvasLike(patternImage)) {
  16473. imageSrc = patternImage.toDataURL();
  16474. }
  16475. if (typeof Image === 'undefined') {
  16476. var errMsg = 'Image width/height must been given explictly in svg-ssr renderer.';
  16477. assert(imageWidth_1, errMsg);
  16478. assert(imageHeight_1, errMsg);
  16479. }
  16480. else if (imageWidth_1 == null || imageHeight_1 == null) {
  16481. var setSizeToVNode_1 = function (vNode, img) {
  16482. if (vNode) {
  16483. var svgEl = vNode.elm;
  16484. var width = imageWidth_1 || img.width;
  16485. var height = imageHeight_1 || img.height;
  16486. if (vNode.tag === 'pattern') {
  16487. if (repeatX) {
  16488. height = 1;
  16489. width /= boundingRect.width;
  16490. }
  16491. else if (repeatY) {
  16492. width = 1;
  16493. height /= boundingRect.height;
  16494. }
  16495. }
  16496. vNode.attrs.width = width;
  16497. vNode.attrs.height = height;
  16498. if (svgEl) {
  16499. svgEl.setAttribute('width', width);
  16500. svgEl.setAttribute('height', height);
  16501. }
  16502. }
  16503. };
  16504. var createdImage = createOrUpdateImage(imageSrc, null, el, function (img) {
  16505. noRepeat || setSizeToVNode_1(patternVNode, img);
  16506. setSizeToVNode_1(child, img);
  16507. });
  16508. if (createdImage && createdImage.width && createdImage.height) {
  16509. imageWidth_1 = imageWidth_1 || createdImage.width;
  16510. imageHeight_1 = imageHeight_1 || createdImage.height;
  16511. }
  16512. }
  16513. child = createVNode('image', 'img', {
  16514. href: imageSrc,
  16515. width: imageWidth_1,
  16516. height: imageHeight_1
  16517. });
  16518. patternAttrs.width = imageWidth_1;
  16519. patternAttrs.height = imageHeight_1;
  16520. }
  16521. else if (val.svgElement) {
  16522. child = clone(val.svgElement);
  16523. patternAttrs.width = val.svgWidth;
  16524. patternAttrs.height = val.svgHeight;
  16525. }
  16526. if (!child) {
  16527. return;
  16528. }
  16529. var patternWidth;
  16530. var patternHeight;
  16531. if (noRepeat) {
  16532. patternWidth = patternHeight = 1;
  16533. }
  16534. else if (repeatX) {
  16535. patternHeight = 1;
  16536. patternWidth = patternAttrs.width / boundingRect.width;
  16537. }
  16538. else if (repeatY) {
  16539. patternWidth = 1;
  16540. patternHeight = patternAttrs.height / boundingRect.height;
  16541. }
  16542. else {
  16543. patternAttrs.patternUnits = 'userSpaceOnUse';
  16544. }
  16545. if (patternWidth != null && !isNaN(patternWidth)) {
  16546. patternAttrs.width = patternWidth;
  16547. }
  16548. if (patternHeight != null && !isNaN(patternHeight)) {
  16549. patternAttrs.height = patternHeight;
  16550. }
  16551. var patternTransform = getSRTTransformString(val);
  16552. patternTransform && (patternAttrs.patternTransform = patternTransform);
  16553. var patternVNode = createVNode('pattern', '', patternAttrs, [child]);
  16554. var patternKey = vNodeToString(patternVNode);
  16555. var patternCache = scope.patternCache;
  16556. var patternId = patternCache[patternKey];
  16557. if (!patternId) {
  16558. patternId = scope.zrId + '-p' + scope.patternIdx++;
  16559. patternCache[patternKey] = patternId;
  16560. patternAttrs.id = patternId;
  16561. patternVNode = scope.defs[patternId] = createVNode('pattern', patternId, patternAttrs, [child]);
  16562. }
  16563. attrs[target] = getIdURL(patternId);
  16564. }
  16565. function setClipPath(clipPath, attrs, scope) {
  16566. var clipPathCache = scope.clipPathCache, defs = scope.defs;
  16567. var clipPathId = clipPathCache[clipPath.id];
  16568. if (!clipPathId) {
  16569. clipPathId = scope.zrId + '-c' + scope.clipPathIdx++;
  16570. var clipPathAttrs = {
  16571. id: clipPathId
  16572. };
  16573. clipPathCache[clipPath.id] = clipPathId;
  16574. defs[clipPathId] = createVNode('clipPath', clipPathId, clipPathAttrs, [brushSVGPath(clipPath, scope)]);
  16575. }
  16576. attrs['clip-path'] = getIdURL(clipPathId);
  16577. }
  16578. function createTextNode(text) {
  16579. return document.createTextNode(text);
  16580. }
  16581. function insertBefore(parentNode, newNode, referenceNode) {
  16582. parentNode.insertBefore(newNode, referenceNode);
  16583. }
  16584. function removeChild(node, child) {
  16585. node.removeChild(child);
  16586. }
  16587. function appendChild(node, child) {
  16588. node.appendChild(child);
  16589. }
  16590. function parentNode(node) {
  16591. return node.parentNode;
  16592. }
  16593. function nextSibling(node) {
  16594. return node.nextSibling;
  16595. }
  16596. function setTextContent(node, text) {
  16597. node.textContent = text;
  16598. }
  16599. var colonChar = 58;
  16600. var xChar = 120;
  16601. var emptyNode = createVNode('', '');
  16602. function isUndef(s) {
  16603. return s === undefined;
  16604. }
  16605. function isDef(s) {
  16606. return s !== undefined;
  16607. }
  16608. function createKeyToOldIdx(children, beginIdx, endIdx) {
  16609. var map = {};
  16610. for (var i = beginIdx; i <= endIdx; ++i) {
  16611. var key = children[i].key;
  16612. if (key !== undefined) {
  16613. {
  16614. if (map[key] != null) {
  16615. console.error("Duplicate key " + key);
  16616. }
  16617. }
  16618. map[key] = i;
  16619. }
  16620. }
  16621. return map;
  16622. }
  16623. function sameVnode(vnode1, vnode2) {
  16624. var isSameKey = vnode1.key === vnode2.key;
  16625. var isSameTag = vnode1.tag === vnode2.tag;
  16626. return isSameTag && isSameKey;
  16627. }
  16628. function createElm(vnode) {
  16629. var i;
  16630. var children = vnode.children;
  16631. var tag = vnode.tag;
  16632. if (isDef(tag)) {
  16633. var elm = (vnode.elm = createElement(tag));
  16634. updateAttrs(emptyNode, vnode);
  16635. if (isArray(children)) {
  16636. for (i = 0; i < children.length; ++i) {
  16637. var ch = children[i];
  16638. if (ch != null) {
  16639. appendChild(elm, createElm(ch));
  16640. }
  16641. }
  16642. }
  16643. else if (isDef(vnode.text) && !isObject(vnode.text)) {
  16644. appendChild(elm, createTextNode(vnode.text));
  16645. }
  16646. }
  16647. else {
  16648. vnode.elm = createTextNode(vnode.text);
  16649. }
  16650. return vnode.elm;
  16651. }
  16652. function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
  16653. for (; startIdx <= endIdx; ++startIdx) {
  16654. var ch = vnodes[startIdx];
  16655. if (ch != null) {
  16656. insertBefore(parentElm, createElm(ch), before);
  16657. }
  16658. }
  16659. }
  16660. function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
  16661. for (; startIdx <= endIdx; ++startIdx) {
  16662. var ch = vnodes[startIdx];
  16663. if (ch != null) {
  16664. if (isDef(ch.tag)) {
  16665. var parent_1 = parentNode(ch.elm);
  16666. removeChild(parent_1, ch.elm);
  16667. }
  16668. else {
  16669. removeChild(parentElm, ch.elm);
  16670. }
  16671. }
  16672. }
  16673. }
  16674. function updateAttrs(oldVnode, vnode) {
  16675. var key;
  16676. var elm = vnode.elm;
  16677. var oldAttrs = oldVnode && oldVnode.attrs || {};
  16678. var attrs = vnode.attrs || {};
  16679. if (oldAttrs === attrs) {
  16680. return;
  16681. }
  16682. for (key in attrs) {
  16683. var cur = attrs[key];
  16684. var old = oldAttrs[key];
  16685. if (old !== cur) {
  16686. if (cur === true) {
  16687. elm.setAttribute(key, '');
  16688. }
  16689. else if (cur === false) {
  16690. elm.removeAttribute(key);
  16691. }
  16692. else {
  16693. if (key.charCodeAt(0) !== xChar) {
  16694. elm.setAttribute(key, cur);
  16695. }
  16696. else if (key === 'xmlns:xlink' || key === 'xmlns') {
  16697. elm.setAttributeNS(XMLNS, key, cur);
  16698. }
  16699. else if (key.charCodeAt(3) === colonChar) {
  16700. elm.setAttributeNS(XML_NAMESPACE, key, cur);
  16701. }
  16702. else if (key.charCodeAt(5) === colonChar) {
  16703. elm.setAttributeNS(XLINKNS, key, cur);
  16704. }
  16705. else {
  16706. elm.setAttribute(key, cur);
  16707. }
  16708. }
  16709. }
  16710. }
  16711. for (key in oldAttrs) {
  16712. if (!(key in attrs)) {
  16713. elm.removeAttribute(key);
  16714. }
  16715. }
  16716. }
  16717. function updateChildren(parentElm, oldCh, newCh) {
  16718. var oldStartIdx = 0;
  16719. var newStartIdx = 0;
  16720. var oldEndIdx = oldCh.length - 1;
  16721. var oldStartVnode = oldCh[0];
  16722. var oldEndVnode = oldCh[oldEndIdx];
  16723. var newEndIdx = newCh.length - 1;
  16724. var newStartVnode = newCh[0];
  16725. var newEndVnode = newCh[newEndIdx];
  16726. var oldKeyToIdx;
  16727. var idxInOld;
  16728. var elmToMove;
  16729. var before;
  16730. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  16731. if (oldStartVnode == null) {
  16732. oldStartVnode = oldCh[++oldStartIdx];
  16733. }
  16734. else if (oldEndVnode == null) {
  16735. oldEndVnode = oldCh[--oldEndIdx];
  16736. }
  16737. else if (newStartVnode == null) {
  16738. newStartVnode = newCh[++newStartIdx];
  16739. }
  16740. else if (newEndVnode == null) {
  16741. newEndVnode = newCh[--newEndIdx];
  16742. }
  16743. else if (sameVnode(oldStartVnode, newStartVnode)) {
  16744. patchVnode(oldStartVnode, newStartVnode);
  16745. oldStartVnode = oldCh[++oldStartIdx];
  16746. newStartVnode = newCh[++newStartIdx];
  16747. }
  16748. else if (sameVnode(oldEndVnode, newEndVnode)) {
  16749. patchVnode(oldEndVnode, newEndVnode);
  16750. oldEndVnode = oldCh[--oldEndIdx];
  16751. newEndVnode = newCh[--newEndIdx];
  16752. }
  16753. else if (sameVnode(oldStartVnode, newEndVnode)) {
  16754. patchVnode(oldStartVnode, newEndVnode);
  16755. insertBefore(parentElm, oldStartVnode.elm, nextSibling(oldEndVnode.elm));
  16756. oldStartVnode = oldCh[++oldStartIdx];
  16757. newEndVnode = newCh[--newEndIdx];
  16758. }
  16759. else if (sameVnode(oldEndVnode, newStartVnode)) {
  16760. patchVnode(oldEndVnode, newStartVnode);
  16761. insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
  16762. oldEndVnode = oldCh[--oldEndIdx];
  16763. newStartVnode = newCh[++newStartIdx];
  16764. }
  16765. else {
  16766. if (isUndef(oldKeyToIdx)) {
  16767. oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
  16768. }
  16769. idxInOld = oldKeyToIdx[newStartVnode.key];
  16770. if (isUndef(idxInOld)) {
  16771. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  16772. }
  16773. else {
  16774. elmToMove = oldCh[idxInOld];
  16775. if (elmToMove.tag !== newStartVnode.tag) {
  16776. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  16777. }
  16778. else {
  16779. patchVnode(elmToMove, newStartVnode);
  16780. oldCh[idxInOld] = undefined;
  16781. insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
  16782. }
  16783. }
  16784. newStartVnode = newCh[++newStartIdx];
  16785. }
  16786. }
  16787. if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
  16788. if (oldStartIdx > oldEndIdx) {
  16789. before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm;
  16790. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
  16791. }
  16792. else {
  16793. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
  16794. }
  16795. }
  16796. }
  16797. function patchVnode(oldVnode, vnode) {
  16798. var elm = (vnode.elm = oldVnode.elm);
  16799. var oldCh = oldVnode.children;
  16800. var ch = vnode.children;
  16801. if (oldVnode === vnode) {
  16802. return;
  16803. }
  16804. updateAttrs(oldVnode, vnode);
  16805. if (isUndef(vnode.text)) {
  16806. if (isDef(oldCh) && isDef(ch)) {
  16807. if (oldCh !== ch) {
  16808. updateChildren(elm, oldCh, ch);
  16809. }
  16810. }
  16811. else if (isDef(ch)) {
  16812. if (isDef(oldVnode.text)) {
  16813. setTextContent(elm, '');
  16814. }
  16815. addVnodes(elm, null, ch, 0, ch.length - 1);
  16816. }
  16817. else if (isDef(oldCh)) {
  16818. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  16819. }
  16820. else if (isDef(oldVnode.text)) {
  16821. setTextContent(elm, '');
  16822. }
  16823. }
  16824. else if (oldVnode.text !== vnode.text) {
  16825. if (isDef(oldCh)) {
  16826. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  16827. }
  16828. setTextContent(elm, vnode.text);
  16829. }
  16830. }
  16831. function patch(oldVnode, vnode) {
  16832. if (sameVnode(oldVnode, vnode)) {
  16833. patchVnode(oldVnode, vnode);
  16834. }
  16835. else {
  16836. var elm = oldVnode.elm;
  16837. var parent_2 = parentNode(elm);
  16838. createElm(vnode);
  16839. if (parent_2 !== null) {
  16840. insertBefore(parent_2, vnode.elm, nextSibling(elm));
  16841. removeVnodes(parent_2, [oldVnode], 0, 0);
  16842. }
  16843. }
  16844. return vnode;
  16845. }
  16846. var svgId = 0;
  16847. var SVGPainter = (function () {
  16848. function SVGPainter(root, storage, opts) {
  16849. this.type = 'svg';
  16850. this.refreshHover = createMethodNotSupport('refreshHover');
  16851. this.configLayer = createMethodNotSupport('configLayer');
  16852. this.storage = storage;
  16853. this._opts = opts = extend({}, opts);
  16854. this.root = root;
  16855. this._id = 'zr' + svgId++;
  16856. this._oldVNode = createSVGVNode(opts.width, opts.height);
  16857. if (root && !opts.ssr) {
  16858. var viewport = this._viewport = document.createElement('div');
  16859. viewport.style.cssText = 'position:relative;overflow:hidden';
  16860. var svgDom = this._svgDom = this._oldVNode.elm = createElement('svg');
  16861. updateAttrs(null, this._oldVNode);
  16862. viewport.appendChild(svgDom);
  16863. root.appendChild(viewport);
  16864. }
  16865. this.resize(opts.width, opts.height);
  16866. }
  16867. SVGPainter.prototype.getType = function () {
  16868. return this.type;
  16869. };
  16870. SVGPainter.prototype.getViewportRoot = function () {
  16871. return this._viewport;
  16872. };
  16873. SVGPainter.prototype.getViewportRootOffset = function () {
  16874. var viewportRoot = this.getViewportRoot();
  16875. if (viewportRoot) {
  16876. return {
  16877. offsetLeft: viewportRoot.offsetLeft || 0,
  16878. offsetTop: viewportRoot.offsetTop || 0
  16879. };
  16880. }
  16881. };
  16882. SVGPainter.prototype.getSvgDom = function () {
  16883. return this._svgDom;
  16884. };
  16885. SVGPainter.prototype.refresh = function () {
  16886. if (this.root) {
  16887. var vnode = this.renderToVNode({
  16888. willUpdate: true
  16889. });
  16890. vnode.attrs.style = 'position:absolute;left:0;top:0;user-select:none';
  16891. patch(this._oldVNode, vnode);
  16892. this._oldVNode = vnode;
  16893. }
  16894. };
  16895. SVGPainter.prototype.renderOneToVNode = function (el) {
  16896. return brush$1(el, createBrushScope(this._id));
  16897. };
  16898. SVGPainter.prototype.renderToVNode = function (opts) {
  16899. opts = opts || {};
  16900. var list = this.storage.getDisplayList(true);
  16901. var width = this._width;
  16902. var height = this._height;
  16903. var scope = createBrushScope(this._id);
  16904. scope.animation = opts.animation;
  16905. scope.willUpdate = opts.willUpdate;
  16906. scope.compress = opts.compress;
  16907. var children = [];
  16908. var bgVNode = this._bgVNode = createBackgroundVNode(width, height, this._backgroundColor, scope);
  16909. bgVNode && children.push(bgVNode);
  16910. var mainVNode = !opts.compress
  16911. ? (this._mainVNode = createVNode('g', 'main', {}, [])) : null;
  16912. this._paintList(list, scope, mainVNode ? mainVNode.children : children);
  16913. mainVNode && children.push(mainVNode);
  16914. var defs = map(keys(scope.defs), function (id) { return scope.defs[id]; });
  16915. if (defs.length) {
  16916. children.push(createVNode('defs', 'defs', {}, defs));
  16917. }
  16918. if (opts.animation) {
  16919. var animationCssStr = getCssString(scope.cssNodes, scope.cssAnims, { newline: true });
  16920. if (animationCssStr) {
  16921. var styleNode = createVNode('style', 'stl', {}, [], animationCssStr);
  16922. children.push(styleNode);
  16923. }
  16924. }
  16925. return createSVGVNode(width, height, children, opts.useViewBox);
  16926. };
  16927. SVGPainter.prototype.renderToString = function (opts) {
  16928. opts = opts || {};
  16929. return vNodeToString(this.renderToVNode({
  16930. animation: retrieve2(opts.cssAnimation, true),
  16931. willUpdate: false,
  16932. compress: true,
  16933. useViewBox: retrieve2(opts.useViewBox, true)
  16934. }), { newline: true });
  16935. };
  16936. SVGPainter.prototype.setBackgroundColor = function (backgroundColor) {
  16937. this._backgroundColor = backgroundColor;
  16938. };
  16939. SVGPainter.prototype.getSvgRoot = function () {
  16940. return this._mainVNode && this._mainVNode.elm;
  16941. };
  16942. SVGPainter.prototype._paintList = function (list, scope, out) {
  16943. var listLen = list.length;
  16944. var clipPathsGroupsStack = [];
  16945. var clipPathsGroupsStackDepth = 0;
  16946. var currentClipPathGroup;
  16947. var prevClipPaths;
  16948. var clipGroupNodeIdx = 0;
  16949. for (var i = 0; i < listLen; i++) {
  16950. var displayable = list[i];
  16951. if (!displayable.invisible) {
  16952. var clipPaths = displayable.__clipPaths;
  16953. var len = clipPaths && clipPaths.length || 0;
  16954. var prevLen = prevClipPaths && prevClipPaths.length || 0;
  16955. var lca = void 0;
  16956. for (lca = Math.max(len - 1, prevLen - 1); lca >= 0; lca--) {
  16957. if (clipPaths && prevClipPaths
  16958. && clipPaths[lca] === prevClipPaths[lca]) {
  16959. break;
  16960. }
  16961. }
  16962. for (var i_1 = prevLen - 1; i_1 > lca; i_1--) {
  16963. clipPathsGroupsStackDepth--;
  16964. currentClipPathGroup = clipPathsGroupsStack[clipPathsGroupsStackDepth - 1];
  16965. }
  16966. for (var i_2 = lca + 1; i_2 < len; i_2++) {
  16967. var groupAttrs = {};
  16968. setClipPath(clipPaths[i_2], groupAttrs, scope);
  16969. var g = createVNode('g', 'clip-g-' + clipGroupNodeIdx++, groupAttrs, []);
  16970. (currentClipPathGroup ? currentClipPathGroup.children : out).push(g);
  16971. clipPathsGroupsStack[clipPathsGroupsStackDepth++] = g;
  16972. currentClipPathGroup = g;
  16973. }
  16974. prevClipPaths = clipPaths;
  16975. var ret = brush$1(displayable, scope);
  16976. if (ret) {
  16977. (currentClipPathGroup ? currentClipPathGroup.children : out).push(ret);
  16978. }
  16979. }
  16980. }
  16981. };
  16982. SVGPainter.prototype.resize = function (width, height) {
  16983. var opts = this._opts;
  16984. var root = this.root;
  16985. var viewport = this._viewport;
  16986. width != null && (opts.width = width);
  16987. height != null && (opts.height = height);
  16988. if (root && viewport) {
  16989. viewport.style.display = 'none';
  16990. width = getSize(root, 0, opts);
  16991. height = getSize(root, 1, opts);
  16992. viewport.style.display = '';
  16993. }
  16994. if (this._width !== width || this._height !== height) {
  16995. this._width = width;
  16996. this._height = height;
  16997. if (viewport) {
  16998. var viewportStyle = viewport.style;
  16999. viewportStyle.width = width + 'px';
  17000. viewportStyle.height = height + 'px';
  17001. }
  17002. if (!isPattern(this._backgroundColor)) {
  17003. var svgDom = this._svgDom;
  17004. if (svgDom) {
  17005. svgDom.setAttribute('width', width);
  17006. svgDom.setAttribute('height', height);
  17007. }
  17008. var bgEl = this._bgVNode && this._bgVNode.elm;
  17009. if (bgEl) {
  17010. bgEl.setAttribute('width', width);
  17011. bgEl.setAttribute('height', height);
  17012. }
  17013. }
  17014. else {
  17015. this.refresh();
  17016. }
  17017. }
  17018. };
  17019. SVGPainter.prototype.getWidth = function () {
  17020. return this._width;
  17021. };
  17022. SVGPainter.prototype.getHeight = function () {
  17023. return this._height;
  17024. };
  17025. SVGPainter.prototype.dispose = function () {
  17026. if (this.root) {
  17027. this.root.innerHTML = '';
  17028. }
  17029. this._svgDom =
  17030. this._viewport =
  17031. this.storage =
  17032. this._oldVNode =
  17033. this._bgVNode =
  17034. this._mainVNode = null;
  17035. };
  17036. SVGPainter.prototype.clear = function () {
  17037. if (this._svgDom) {
  17038. this._svgDom.innerHTML = null;
  17039. }
  17040. this._oldVNode = null;
  17041. };
  17042. SVGPainter.prototype.toDataURL = function (base64) {
  17043. var str = this.renderToString();
  17044. var prefix = 'data:image/svg+xml;';
  17045. if (base64) {
  17046. str = encodeBase64(str);
  17047. return str && prefix + 'base64,' + str;
  17048. }
  17049. return prefix + 'charset=UTF-8,' + encodeURIComponent(str);
  17050. };
  17051. return SVGPainter;
  17052. }());
  17053. function createMethodNotSupport(method) {
  17054. return function () {
  17055. {
  17056. logError('In SVG mode painter not support method "' + method + '"');
  17057. }
  17058. };
  17059. }
  17060. function createBackgroundVNode(width, height, backgroundColor, scope) {
  17061. var bgVNode;
  17062. if (backgroundColor && backgroundColor !== 'none') {
  17063. bgVNode = createVNode('rect', 'bg', {
  17064. width: width,
  17065. height: height,
  17066. x: '0',
  17067. y: '0',
  17068. id: '0'
  17069. });
  17070. if (isGradient(backgroundColor)) {
  17071. setGradient({ fill: backgroundColor }, bgVNode.attrs, 'fill', scope);
  17072. }
  17073. else if (isPattern(backgroundColor)) {
  17074. setPattern({
  17075. style: {
  17076. fill: backgroundColor
  17077. },
  17078. dirty: noop,
  17079. getBoundingRect: function () { return ({ width: width, height: height }); }
  17080. }, bgVNode.attrs, 'fill', scope);
  17081. }
  17082. else {
  17083. var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
  17084. bgVNode.attrs.fill = color;
  17085. opacity < 1 && (bgVNode.attrs['fill-opacity'] = opacity);
  17086. }
  17087. }
  17088. return bgVNode;
  17089. }
  17090. registerPainter('canvas', CanvasPainter);
  17091. registerPainter('svg', SVGPainter);
  17092. exports.Arc = Arc;
  17093. exports.ArcShape = ArcShape;
  17094. exports.BezierCurve = BezierCurve;
  17095. exports.BezierCurveShape = BezierCurveShape;
  17096. exports.BoundingRect = BoundingRect;
  17097. exports.Circle = Circle;
  17098. exports.CircleShape = CircleShape;
  17099. exports.CompoundPath = CompoundPath;
  17100. exports.Displayable = Displayable;
  17101. exports.Droplet = Droplet;
  17102. exports.DropletShape = DropletShape;
  17103. exports.Element = Element;
  17104. exports.Ellipse = Ellipse;
  17105. exports.EllipseShape = EllipseShape;
  17106. exports.Group = Group;
  17107. exports.Heart = Heart;
  17108. exports.HeartShape = HeartShape;
  17109. exports.Image = ZRImage;
  17110. exports.IncrementalDisplayable = IncrementalDisplayable;
  17111. exports.Isogon = Isogon;
  17112. exports.IsogonShape = IsogonShape;
  17113. exports.Line = Line;
  17114. exports.LineShape = LineShape;
  17115. exports.LinearGradient = LinearGradient;
  17116. exports.OrientedBoundingRect = OrientedBoundingRect;
  17117. exports.Path = Path;
  17118. exports.Pattern = Pattern;
  17119. exports.Point = Point;
  17120. exports.Polygon = Polygon;
  17121. exports.PolygonShape = PolygonShape;
  17122. exports.Polyline = Polyline;
  17123. exports.PolylineShape = PolylineShape;
  17124. exports.RadialGradient = RadialGradient;
  17125. exports.Rect = Rect;
  17126. exports.RectShape = RectShape;
  17127. exports.Ring = Ring;
  17128. exports.RingShape = RingShape;
  17129. exports.Rose = Rose;
  17130. exports.RoseShape = RoseShape;
  17131. exports.Sector = Sector;
  17132. exports.SectorShape = SectorShape;
  17133. exports.Star = Star;
  17134. exports.StarShape = StarShape;
  17135. exports.TSpan = TSpan;
  17136. exports.Text = ZRText;
  17137. exports.Trochoid = Trochoid;
  17138. exports.TrochoidShape = TrochoidShape;
  17139. exports.color = color;
  17140. exports.dispose = dispose;
  17141. exports.disposeAll = disposeAll;
  17142. exports.getInstance = getInstance;
  17143. exports.init = init;
  17144. exports.matrix = matrix;
  17145. exports.morph = morphPath$1;
  17146. exports.parseSVG = parseSVG;
  17147. exports.path = path;
  17148. exports.registerPainter = registerPainter;
  17149. exports.setPlatformAPI = setPlatformAPI;
  17150. exports.showDebugDirtyRect = showDebugDirtyRect;
  17151. exports.util = util;
  17152. exports.vector = vector;
  17153. exports.version = version;
  17154. Object.defineProperty(exports, '__esModule', { value: true });
  17155. })));
  17156. //# sourceMappingURL=zrender.js.map