zrender.js 640 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458
  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. || navigator.userAgent.indexOf('Node.js') === 0) {
  42. env.node = true;
  43. env.svgSupported = true;
  44. }
  45. else {
  46. detect(navigator.userAgent, env);
  47. }
  48. function detect(ua, env) {
  49. var browser = env.browser;
  50. var firefox = ua.match(/Firefox\/([\d.]+)/);
  51. var ie = ua.match(/MSIE\s([\d.]+)/)
  52. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  53. var edge = ua.match(/Edge?\/([\d.]+)/);
  54. var weChat = (/micromessenger/i).test(ua);
  55. if (firefox) {
  56. browser.firefox = true;
  57. browser.version = firefox[1];
  58. }
  59. if (ie) {
  60. browser.ie = true;
  61. browser.version = ie[1];
  62. }
  63. if (edge) {
  64. browser.edge = true;
  65. browser.version = edge[1];
  66. browser.newEdge = +edge[1].split('.')[0] > 18;
  67. }
  68. if (weChat) {
  69. browser.weChat = true;
  70. }
  71. env.svgSupported = typeof SVGRect !== 'undefined';
  72. env.touchEventsSupported = 'ontouchstart' in window && !browser.ie && !browser.edge;
  73. env.pointerEventsSupported = 'onpointerdown' in window
  74. && (browser.edge || (browser.ie && +browser.version >= 11));
  75. env.domSupported = typeof document !== 'undefined';
  76. var style = document.documentElement.style;
  77. env.transform3dSupported = ((browser.ie && 'transition' in style)
  78. || browser.edge
  79. || (('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()))
  80. || 'MozPerspective' in style)
  81. && !('OTransition' in style);
  82. env.transformSupported = env.transform3dSupported
  83. || (browser.ie && +browser.version >= 9);
  84. }
  85. var DEFAULT_FONT_SIZE = 12;
  86. var DEFAULT_FONT_FAMILY = 'sans-serif';
  87. var DEFAULT_FONT = DEFAULT_FONT_SIZE + "px " + DEFAULT_FONT_FAMILY;
  88. var OFFSET = 20;
  89. var SCALE = 100;
  90. var defaultWidthMapStr = "007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N";
  91. function getTextWidthMap(mapStr) {
  92. var map = {};
  93. if (typeof JSON === 'undefined') {
  94. return map;
  95. }
  96. for (var i = 0; i < mapStr.length; i++) {
  97. var char = String.fromCharCode(i + 32);
  98. var size = (mapStr.charCodeAt(i) - OFFSET) / SCALE;
  99. map[char] = size;
  100. }
  101. return map;
  102. }
  103. var DEFAULT_TEXT_WIDTH_MAP = getTextWidthMap(defaultWidthMapStr);
  104. var platformApi = {
  105. createCanvas: function () {
  106. return typeof document !== 'undefined'
  107. && document.createElement('canvas');
  108. },
  109. measureText: (function () {
  110. var _ctx;
  111. var _cachedFont;
  112. return function (text, font) {
  113. if (!_ctx) {
  114. var canvas = platformApi.createCanvas();
  115. _ctx = canvas && canvas.getContext('2d');
  116. }
  117. if (_ctx) {
  118. if (_cachedFont !== font) {
  119. _cachedFont = _ctx.font = font || DEFAULT_FONT;
  120. }
  121. return _ctx.measureText(text);
  122. }
  123. else {
  124. text = text || '';
  125. font = font || DEFAULT_FONT;
  126. var res = /((?:\d+)?\.?\d*)px/.exec(font);
  127. var fontSize = res && +res[1] || DEFAULT_FONT_SIZE;
  128. var width = 0;
  129. if (font.indexOf('mono') >= 0) {
  130. width = fontSize * text.length;
  131. }
  132. else {
  133. for (var i = 0; i < text.length; i++) {
  134. var preCalcWidth = DEFAULT_TEXT_WIDTH_MAP[text[i]];
  135. width += preCalcWidth == null ? fontSize : (preCalcWidth * fontSize);
  136. }
  137. }
  138. return { width: width };
  139. }
  140. };
  141. })(),
  142. loadImage: function (src, onload, onerror) {
  143. var image = new Image();
  144. image.onload = onload;
  145. image.onerror = onerror;
  146. image.src = src;
  147. return image;
  148. }
  149. };
  150. function setPlatformAPI(newPlatformApis) {
  151. for (var key in platformApi) {
  152. if (newPlatformApis[key]) {
  153. platformApi[key] = newPlatformApis[key];
  154. }
  155. }
  156. }
  157. var BUILTIN_OBJECT = reduce([
  158. 'Function',
  159. 'RegExp',
  160. 'Date',
  161. 'Error',
  162. 'CanvasGradient',
  163. 'CanvasPattern',
  164. 'Image',
  165. 'Canvas'
  166. ], function (obj, val) {
  167. obj['[object ' + val + ']'] = true;
  168. return obj;
  169. }, {});
  170. var TYPED_ARRAY = reduce([
  171. 'Int8',
  172. 'Uint8',
  173. 'Uint8Clamped',
  174. 'Int16',
  175. 'Uint16',
  176. 'Int32',
  177. 'Uint32',
  178. 'Float32',
  179. 'Float64'
  180. ], function (obj, val) {
  181. obj['[object ' + val + 'Array]'] = true;
  182. return obj;
  183. }, {});
  184. var objToString = Object.prototype.toString;
  185. var arrayProto = Array.prototype;
  186. var nativeForEach = arrayProto.forEach;
  187. var nativeFilter = arrayProto.filter;
  188. var nativeSlice = arrayProto.slice;
  189. var nativeMap = arrayProto.map;
  190. var ctorFunction = function () { }.constructor;
  191. var protoFunction = ctorFunction ? ctorFunction.prototype : null;
  192. var protoKey = '__proto__';
  193. var idStart = 0x0907;
  194. function guid() {
  195. return idStart++;
  196. }
  197. function logError() {
  198. var args = [];
  199. for (var _i = 0; _i < arguments.length; _i++) {
  200. args[_i] = arguments[_i];
  201. }
  202. if (typeof console !== 'undefined') {
  203. console.error.apply(console, args);
  204. }
  205. }
  206. function clone(source) {
  207. if (source == null || typeof source !== 'object') {
  208. return source;
  209. }
  210. var result = source;
  211. var typeStr = objToString.call(source);
  212. if (typeStr === '[object Array]') {
  213. if (!isPrimitive(source)) {
  214. result = [];
  215. for (var i = 0, len = source.length; i < len; i++) {
  216. result[i] = clone(source[i]);
  217. }
  218. }
  219. }
  220. else if (TYPED_ARRAY[typeStr]) {
  221. if (!isPrimitive(source)) {
  222. var Ctor = source.constructor;
  223. if (Ctor.from) {
  224. result = Ctor.from(source);
  225. }
  226. else {
  227. result = new Ctor(source.length);
  228. for (var i = 0, len = source.length; i < len; i++) {
  229. result[i] = source[i];
  230. }
  231. }
  232. }
  233. }
  234. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  235. result = {};
  236. for (var key in source) {
  237. if (source.hasOwnProperty(key) && key !== protoKey) {
  238. result[key] = clone(source[key]);
  239. }
  240. }
  241. }
  242. return result;
  243. }
  244. function merge(target, source, overwrite) {
  245. if (!isObject(source) || !isObject(target)) {
  246. return overwrite ? clone(source) : target;
  247. }
  248. for (var key in source) {
  249. if (source.hasOwnProperty(key) && key !== protoKey) {
  250. var targetProp = target[key];
  251. var sourceProp = source[key];
  252. if (isObject(sourceProp)
  253. && isObject(targetProp)
  254. && !isArray(sourceProp)
  255. && !isArray(targetProp)
  256. && !isDom(sourceProp)
  257. && !isDom(targetProp)
  258. && !isBuiltInObject(sourceProp)
  259. && !isBuiltInObject(targetProp)
  260. && !isPrimitive(sourceProp)
  261. && !isPrimitive(targetProp)) {
  262. merge(targetProp, sourceProp, overwrite);
  263. }
  264. else if (overwrite || !(key in target)) {
  265. target[key] = clone(source[key]);
  266. }
  267. }
  268. }
  269. return target;
  270. }
  271. function mergeAll(targetAndSources, overwrite) {
  272. var result = targetAndSources[0];
  273. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  274. result = merge(result, targetAndSources[i], overwrite);
  275. }
  276. return result;
  277. }
  278. function extend(target, source) {
  279. if (Object.assign) {
  280. Object.assign(target, source);
  281. }
  282. else {
  283. for (var key in source) {
  284. if (source.hasOwnProperty(key) && key !== protoKey) {
  285. target[key] = source[key];
  286. }
  287. }
  288. }
  289. return target;
  290. }
  291. function defaults(target, source, overlay) {
  292. var keysArr = keys(source);
  293. for (var i = 0; i < keysArr.length; i++) {
  294. var key = keysArr[i];
  295. if ((overlay ? source[key] != null : target[key] == null)) {
  296. target[key] = source[key];
  297. }
  298. }
  299. return target;
  300. }
  301. var createCanvas = platformApi.createCanvas;
  302. function indexOf(array, value) {
  303. if (array) {
  304. if (array.indexOf) {
  305. return array.indexOf(value);
  306. }
  307. for (var i = 0, len = array.length; i < len; i++) {
  308. if (array[i] === value) {
  309. return i;
  310. }
  311. }
  312. }
  313. return -1;
  314. }
  315. function inherits(clazz, baseClazz) {
  316. var clazzPrototype = clazz.prototype;
  317. function F() { }
  318. F.prototype = baseClazz.prototype;
  319. clazz.prototype = new F();
  320. for (var prop in clazzPrototype) {
  321. if (clazzPrototype.hasOwnProperty(prop)) {
  322. clazz.prototype[prop] = clazzPrototype[prop];
  323. }
  324. }
  325. clazz.prototype.constructor = clazz;
  326. clazz.superClass = baseClazz;
  327. }
  328. function mixin(target, source, override) {
  329. target = 'prototype' in target ? target.prototype : target;
  330. source = 'prototype' in source ? source.prototype : source;
  331. if (Object.getOwnPropertyNames) {
  332. var keyList = Object.getOwnPropertyNames(source);
  333. for (var i = 0; i < keyList.length; i++) {
  334. var key = keyList[i];
  335. if (key !== 'constructor') {
  336. if ((override ? source[key] != null : target[key] == null)) {
  337. target[key] = source[key];
  338. }
  339. }
  340. }
  341. }
  342. else {
  343. defaults(target, source, override);
  344. }
  345. }
  346. function isArrayLike(data) {
  347. if (!data) {
  348. return false;
  349. }
  350. if (typeof data === 'string') {
  351. return false;
  352. }
  353. return typeof data.length === 'number';
  354. }
  355. function each(arr, cb, context) {
  356. if (!(arr && cb)) {
  357. return;
  358. }
  359. if (arr.forEach && arr.forEach === nativeForEach) {
  360. arr.forEach(cb, context);
  361. }
  362. else if (arr.length === +arr.length) {
  363. for (var i = 0, len = arr.length; i < len; i++) {
  364. cb.call(context, arr[i], i, arr);
  365. }
  366. }
  367. else {
  368. for (var key in arr) {
  369. if (arr.hasOwnProperty(key)) {
  370. cb.call(context, arr[key], key, arr);
  371. }
  372. }
  373. }
  374. }
  375. function map(arr, cb, context) {
  376. if (!arr) {
  377. return [];
  378. }
  379. if (!cb) {
  380. return slice(arr);
  381. }
  382. if (arr.map && arr.map === nativeMap) {
  383. return arr.map(cb, context);
  384. }
  385. else {
  386. var result = [];
  387. for (var i = 0, len = arr.length; i < len; i++) {
  388. result.push(cb.call(context, arr[i], i, arr));
  389. }
  390. return result;
  391. }
  392. }
  393. function reduce(arr, cb, memo, context) {
  394. if (!(arr && cb)) {
  395. return;
  396. }
  397. for (var i = 0, len = arr.length; i < len; i++) {
  398. memo = cb.call(context, memo, arr[i], i, arr);
  399. }
  400. return memo;
  401. }
  402. function filter(arr, cb, context) {
  403. if (!arr) {
  404. return [];
  405. }
  406. if (!cb) {
  407. return slice(arr);
  408. }
  409. if (arr.filter && arr.filter === nativeFilter) {
  410. return arr.filter(cb, context);
  411. }
  412. else {
  413. var result = [];
  414. for (var i = 0, len = arr.length; i < len; i++) {
  415. if (cb.call(context, arr[i], i, arr)) {
  416. result.push(arr[i]);
  417. }
  418. }
  419. return result;
  420. }
  421. }
  422. function find(arr, cb, context) {
  423. if (!(arr && cb)) {
  424. return;
  425. }
  426. for (var i = 0, len = arr.length; i < len; i++) {
  427. if (cb.call(context, arr[i], i, arr)) {
  428. return arr[i];
  429. }
  430. }
  431. }
  432. function keys(obj) {
  433. if (!obj) {
  434. return [];
  435. }
  436. if (Object.keys) {
  437. return Object.keys(obj);
  438. }
  439. var keyList = [];
  440. for (var key in obj) {
  441. if (obj.hasOwnProperty(key)) {
  442. keyList.push(key);
  443. }
  444. }
  445. return keyList;
  446. }
  447. function bindPolyfill(func, context) {
  448. var args = [];
  449. for (var _i = 2; _i < arguments.length; _i++) {
  450. args[_i - 2] = arguments[_i];
  451. }
  452. return function () {
  453. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  454. };
  455. }
  456. var bind = (protoFunction && isFunction(protoFunction.bind))
  457. ? protoFunction.call.bind(protoFunction.bind)
  458. : bindPolyfill;
  459. function curry(func) {
  460. var args = [];
  461. for (var _i = 1; _i < arguments.length; _i++) {
  462. args[_i - 1] = arguments[_i];
  463. }
  464. return function () {
  465. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  466. };
  467. }
  468. function isArray(value) {
  469. if (Array.isArray) {
  470. return Array.isArray(value);
  471. }
  472. return objToString.call(value) === '[object Array]';
  473. }
  474. function isFunction(value) {
  475. return typeof value === 'function';
  476. }
  477. function isString(value) {
  478. return typeof value === 'string';
  479. }
  480. function isStringSafe(value) {
  481. return objToString.call(value) === '[object String]';
  482. }
  483. function isNumber(value) {
  484. return typeof value === 'number';
  485. }
  486. function isObject(value) {
  487. var type = typeof value;
  488. return type === 'function' || (!!value && type === 'object');
  489. }
  490. function isBuiltInObject(value) {
  491. return !!BUILTIN_OBJECT[objToString.call(value)];
  492. }
  493. function isTypedArray(value) {
  494. return !!TYPED_ARRAY[objToString.call(value)];
  495. }
  496. function isDom(value) {
  497. return typeof value === 'object'
  498. && typeof value.nodeType === 'number'
  499. && typeof value.ownerDocument === 'object';
  500. }
  501. function isGradientObject(value) {
  502. return value.colorStops != null;
  503. }
  504. function isImagePatternObject(value) {
  505. return value.image != null;
  506. }
  507. function isRegExp(value) {
  508. return objToString.call(value) === '[object RegExp]';
  509. }
  510. function eqNaN(value) {
  511. return value !== value;
  512. }
  513. function retrieve() {
  514. var args = [];
  515. for (var _i = 0; _i < arguments.length; _i++) {
  516. args[_i] = arguments[_i];
  517. }
  518. for (var i = 0, len = args.length; i < len; i++) {
  519. if (args[i] != null) {
  520. return args[i];
  521. }
  522. }
  523. }
  524. function retrieve2(value0, value1) {
  525. return value0 != null
  526. ? value0
  527. : value1;
  528. }
  529. function retrieve3(value0, value1, value2) {
  530. return value0 != null
  531. ? value0
  532. : value1 != null
  533. ? value1
  534. : value2;
  535. }
  536. function slice(arr) {
  537. var args = [];
  538. for (var _i = 1; _i < arguments.length; _i++) {
  539. args[_i - 1] = arguments[_i];
  540. }
  541. return nativeSlice.apply(arr, args);
  542. }
  543. function normalizeCssArray(val) {
  544. if (typeof (val) === 'number') {
  545. return [val, val, val, val];
  546. }
  547. var len = val.length;
  548. if (len === 2) {
  549. return [val[0], val[1], val[0], val[1]];
  550. }
  551. else if (len === 3) {
  552. return [val[0], val[1], val[2], val[1]];
  553. }
  554. return val;
  555. }
  556. function assert(condition, message) {
  557. if (!condition) {
  558. throw new Error(message);
  559. }
  560. }
  561. function trim(str) {
  562. if (str == null) {
  563. return null;
  564. }
  565. else if (typeof str.trim === 'function') {
  566. return str.trim();
  567. }
  568. else {
  569. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  570. }
  571. }
  572. var primitiveKey = '__ec_primitive__';
  573. function setAsPrimitive(obj) {
  574. obj[primitiveKey] = true;
  575. }
  576. function isPrimitive(obj) {
  577. return obj[primitiveKey];
  578. }
  579. var MapPolyfill = (function () {
  580. function MapPolyfill() {
  581. this.data = {};
  582. }
  583. MapPolyfill.prototype["delete"] = function (key) {
  584. var existed = this.has(key);
  585. if (existed) {
  586. delete this.data[key];
  587. }
  588. return existed;
  589. };
  590. MapPolyfill.prototype.has = function (key) {
  591. return this.data.hasOwnProperty(key);
  592. };
  593. MapPolyfill.prototype.get = function (key) {
  594. return this.data[key];
  595. };
  596. MapPolyfill.prototype.set = function (key, value) {
  597. this.data[key] = value;
  598. return this;
  599. };
  600. MapPolyfill.prototype.keys = function () {
  601. return keys(this.data);
  602. };
  603. MapPolyfill.prototype.forEach = function (callback) {
  604. var data = this.data;
  605. for (var key in data) {
  606. if (data.hasOwnProperty(key)) {
  607. callback(data[key], key);
  608. }
  609. }
  610. };
  611. return MapPolyfill;
  612. }());
  613. var isNativeMapSupported = typeof Map === 'function';
  614. function maybeNativeMap() {
  615. return (isNativeMapSupported ? new Map() : new MapPolyfill());
  616. }
  617. var HashMap = (function () {
  618. function HashMap(obj) {
  619. var isArr = isArray(obj);
  620. this.data = maybeNativeMap();
  621. var thisMap = this;
  622. (obj instanceof HashMap)
  623. ? obj.each(visit)
  624. : (obj && each(obj, visit));
  625. function visit(value, key) {
  626. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  627. }
  628. }
  629. HashMap.prototype.hasKey = function (key) {
  630. return this.data.has(key);
  631. };
  632. HashMap.prototype.get = function (key) {
  633. return this.data.get(key);
  634. };
  635. HashMap.prototype.set = function (key, value) {
  636. this.data.set(key, value);
  637. return value;
  638. };
  639. HashMap.prototype.each = function (cb, context) {
  640. this.data.forEach(function (value, key) {
  641. cb.call(context, value, key);
  642. });
  643. };
  644. HashMap.prototype.keys = function () {
  645. var keys = this.data.keys();
  646. return isNativeMapSupported
  647. ? Array.from(keys)
  648. : keys;
  649. };
  650. HashMap.prototype.removeKey = function (key) {
  651. this.data["delete"](key);
  652. };
  653. return HashMap;
  654. }());
  655. function createHashMap(obj) {
  656. return new HashMap(obj);
  657. }
  658. function concatArray(a, b) {
  659. var newArray = new a.constructor(a.length + b.length);
  660. for (var i = 0; i < a.length; i++) {
  661. newArray[i] = a[i];
  662. }
  663. var offset = a.length;
  664. for (var i = 0; i < b.length; i++) {
  665. newArray[i + offset] = b[i];
  666. }
  667. return newArray;
  668. }
  669. function createObject(proto, properties) {
  670. var obj;
  671. if (Object.create) {
  672. obj = Object.create(proto);
  673. }
  674. else {
  675. var StyleCtor = function () { };
  676. StyleCtor.prototype = proto;
  677. obj = new StyleCtor();
  678. }
  679. if (properties) {
  680. extend(obj, properties);
  681. }
  682. return obj;
  683. }
  684. function disableUserSelect(dom) {
  685. var domStyle = dom.style;
  686. domStyle.webkitUserSelect = 'none';
  687. domStyle.userSelect = 'none';
  688. domStyle.webkitTapHighlightColor = 'rgba(0,0,0,0)';
  689. domStyle['-webkit-touch-callout'] = 'none';
  690. }
  691. function hasOwn(own, prop) {
  692. return own.hasOwnProperty(prop);
  693. }
  694. function noop() { }
  695. var RADIAN_TO_DEGREE = 180 / Math.PI;
  696. var util = /*#__PURE__*/Object.freeze({
  697. __proto__: null,
  698. guid: guid,
  699. logError: logError,
  700. clone: clone,
  701. merge: merge,
  702. mergeAll: mergeAll,
  703. extend: extend,
  704. defaults: defaults,
  705. createCanvas: createCanvas,
  706. indexOf: indexOf,
  707. inherits: inherits,
  708. mixin: mixin,
  709. isArrayLike: isArrayLike,
  710. each: each,
  711. map: map,
  712. reduce: reduce,
  713. filter: filter,
  714. find: find,
  715. keys: keys,
  716. bind: bind,
  717. curry: curry,
  718. isArray: isArray,
  719. isFunction: isFunction,
  720. isString: isString,
  721. isStringSafe: isStringSafe,
  722. isNumber: isNumber,
  723. isObject: isObject,
  724. isBuiltInObject: isBuiltInObject,
  725. isTypedArray: isTypedArray,
  726. isDom: isDom,
  727. isGradientObject: isGradientObject,
  728. isImagePatternObject: isImagePatternObject,
  729. isRegExp: isRegExp,
  730. eqNaN: eqNaN,
  731. retrieve: retrieve,
  732. retrieve2: retrieve2,
  733. retrieve3: retrieve3,
  734. slice: slice,
  735. normalizeCssArray: normalizeCssArray,
  736. assert: assert,
  737. trim: trim,
  738. setAsPrimitive: setAsPrimitive,
  739. isPrimitive: isPrimitive,
  740. HashMap: HashMap,
  741. createHashMap: createHashMap,
  742. concatArray: concatArray,
  743. createObject: createObject,
  744. disableUserSelect: disableUserSelect,
  745. hasOwn: hasOwn,
  746. noop: noop,
  747. RADIAN_TO_DEGREE: RADIAN_TO_DEGREE
  748. });
  749. /*! *****************************************************************************
  750. Copyright (c) Microsoft Corporation. All rights reserved.
  751. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  752. this file except in compliance with the License. You may obtain a copy of the
  753. License at http://www.apache.org/licenses/LICENSE-2.0
  754. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  755. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  756. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  757. MERCHANTABLITY OR NON-INFRINGEMENT.
  758. See the Apache Version 2.0 License for specific language governing permissions
  759. and limitations under the License.
  760. ***************************************************************************** */
  761. /* global Reflect, Promise */
  762. var extendStatics = function(d, b) {
  763. extendStatics = Object.setPrototypeOf ||
  764. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  765. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  766. return extendStatics(d, b);
  767. };
  768. function __extends(d, b) {
  769. extendStatics(d, b);
  770. function __() { this.constructor = d; }
  771. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  772. }
  773. function create(x, y) {
  774. if (x == null) {
  775. x = 0;
  776. }
  777. if (y == null) {
  778. y = 0;
  779. }
  780. return [x, y];
  781. }
  782. function copy(out, v) {
  783. out[0] = v[0];
  784. out[1] = v[1];
  785. return out;
  786. }
  787. function clone$1(v) {
  788. return [v[0], v[1]];
  789. }
  790. function set(out, a, b) {
  791. out[0] = a;
  792. out[1] = b;
  793. return out;
  794. }
  795. function add(out, v1, v2) {
  796. out[0] = v1[0] + v2[0];
  797. out[1] = v1[1] + v2[1];
  798. return out;
  799. }
  800. function scaleAndAdd(out, v1, v2, a) {
  801. out[0] = v1[0] + v2[0] * a;
  802. out[1] = v1[1] + v2[1] * a;
  803. return out;
  804. }
  805. function sub(out, v1, v2) {
  806. out[0] = v1[0] - v2[0];
  807. out[1] = v1[1] - v2[1];
  808. return out;
  809. }
  810. function len(v) {
  811. return Math.sqrt(lenSquare(v));
  812. }
  813. var length = len;
  814. function lenSquare(v) {
  815. return v[0] * v[0] + v[1] * v[1];
  816. }
  817. var lengthSquare = lenSquare;
  818. function mul(out, v1, v2) {
  819. out[0] = v1[0] * v2[0];
  820. out[1] = v1[1] * v2[1];
  821. return out;
  822. }
  823. function div(out, v1, v2) {
  824. out[0] = v1[0] / v2[0];
  825. out[1] = v1[1] / v2[1];
  826. return out;
  827. }
  828. function dot(v1, v2) {
  829. return v1[0] * v2[0] + v1[1] * v2[1];
  830. }
  831. function scale(out, v, s) {
  832. out[0] = v[0] * s;
  833. out[1] = v[1] * s;
  834. return out;
  835. }
  836. function normalize(out, v) {
  837. var d = len(v);
  838. if (d === 0) {
  839. out[0] = 0;
  840. out[1] = 0;
  841. }
  842. else {
  843. out[0] = v[0] / d;
  844. out[1] = v[1] / d;
  845. }
  846. return out;
  847. }
  848. function distance(v1, v2) {
  849. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0])
  850. + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  851. }
  852. var dist = distance;
  853. function distanceSquare(v1, v2) {
  854. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  855. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  856. }
  857. var distSquare = distanceSquare;
  858. function negate(out, v) {
  859. out[0] = -v[0];
  860. out[1] = -v[1];
  861. return out;
  862. }
  863. function lerp(out, v1, v2, t) {
  864. out[0] = v1[0] + t * (v2[0] - v1[0]);
  865. out[1] = v1[1] + t * (v2[1] - v1[1]);
  866. return out;
  867. }
  868. function applyTransform(out, v, m) {
  869. var x = v[0];
  870. var y = v[1];
  871. out[0] = m[0] * x + m[2] * y + m[4];
  872. out[1] = m[1] * x + m[3] * y + m[5];
  873. return out;
  874. }
  875. function min(out, v1, v2) {
  876. out[0] = Math.min(v1[0], v2[0]);
  877. out[1] = Math.min(v1[1], v2[1]);
  878. return out;
  879. }
  880. function max(out, v1, v2) {
  881. out[0] = Math.max(v1[0], v2[0]);
  882. out[1] = Math.max(v1[1], v2[1]);
  883. return out;
  884. }
  885. var vector = /*#__PURE__*/Object.freeze({
  886. __proto__: null,
  887. create: create,
  888. copy: copy,
  889. clone: clone$1,
  890. set: set,
  891. add: add,
  892. scaleAndAdd: scaleAndAdd,
  893. sub: sub,
  894. len: len,
  895. length: length,
  896. lenSquare: lenSquare,
  897. lengthSquare: lengthSquare,
  898. mul: mul,
  899. div: div,
  900. dot: dot,
  901. scale: scale,
  902. normalize: normalize,
  903. distance: distance,
  904. dist: dist,
  905. distanceSquare: distanceSquare,
  906. distSquare: distSquare,
  907. negate: negate,
  908. lerp: lerp,
  909. applyTransform: applyTransform,
  910. min: min,
  911. max: max
  912. });
  913. var Param = (function () {
  914. function Param(target, e) {
  915. this.target = target;
  916. this.topTarget = e && e.topTarget;
  917. }
  918. return Param;
  919. }());
  920. var Draggable = (function () {
  921. function Draggable(handler) {
  922. this.handler = handler;
  923. handler.on('mousedown', this._dragStart, this);
  924. handler.on('mousemove', this._drag, this);
  925. handler.on('mouseup', this._dragEnd, this);
  926. }
  927. Draggable.prototype._dragStart = function (e) {
  928. var draggingTarget = e.target;
  929. while (draggingTarget && !draggingTarget.draggable) {
  930. draggingTarget = draggingTarget.parent || draggingTarget.__hostTarget;
  931. }
  932. if (draggingTarget) {
  933. this._draggingTarget = draggingTarget;
  934. draggingTarget.dragging = true;
  935. this._x = e.offsetX;
  936. this._y = e.offsetY;
  937. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragstart', e.event);
  938. }
  939. };
  940. Draggable.prototype._drag = function (e) {
  941. var draggingTarget = this._draggingTarget;
  942. if (draggingTarget) {
  943. var x = e.offsetX;
  944. var y = e.offsetY;
  945. var dx = x - this._x;
  946. var dy = y - this._y;
  947. this._x = x;
  948. this._y = y;
  949. draggingTarget.drift(dx, dy, e);
  950. this.handler.dispatchToElement(new Param(draggingTarget, e), 'drag', e.event);
  951. var dropTarget = this.handler.findHover(x, y, draggingTarget).target;
  952. var lastDropTarget = this._dropTarget;
  953. this._dropTarget = dropTarget;
  954. if (draggingTarget !== dropTarget) {
  955. if (lastDropTarget && dropTarget !== lastDropTarget) {
  956. this.handler.dispatchToElement(new Param(lastDropTarget, e), 'dragleave', e.event);
  957. }
  958. if (dropTarget && dropTarget !== lastDropTarget) {
  959. this.handler.dispatchToElement(new Param(dropTarget, e), 'dragenter', e.event);
  960. }
  961. }
  962. }
  963. };
  964. Draggable.prototype._dragEnd = function (e) {
  965. var draggingTarget = this._draggingTarget;
  966. if (draggingTarget) {
  967. draggingTarget.dragging = false;
  968. }
  969. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragend', e.event);
  970. if (this._dropTarget) {
  971. this.handler.dispatchToElement(new Param(this._dropTarget, e), 'drop', e.event);
  972. }
  973. this._draggingTarget = null;
  974. this._dropTarget = null;
  975. };
  976. return Draggable;
  977. }());
  978. var Eventful = (function () {
  979. function Eventful(eventProcessors) {
  980. if (eventProcessors) {
  981. this._$eventProcessor = eventProcessors;
  982. }
  983. }
  984. Eventful.prototype.on = function (event, query, handler, context) {
  985. if (!this._$handlers) {
  986. this._$handlers = {};
  987. }
  988. var _h = this._$handlers;
  989. if (typeof query === 'function') {
  990. context = handler;
  991. handler = query;
  992. query = null;
  993. }
  994. if (!handler || !event) {
  995. return this;
  996. }
  997. var eventProcessor = this._$eventProcessor;
  998. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  999. query = eventProcessor.normalizeQuery(query);
  1000. }
  1001. if (!_h[event]) {
  1002. _h[event] = [];
  1003. }
  1004. for (var i = 0; i < _h[event].length; i++) {
  1005. if (_h[event][i].h === handler) {
  1006. return this;
  1007. }
  1008. }
  1009. var wrap = {
  1010. h: handler,
  1011. query: query,
  1012. ctx: (context || this),
  1013. callAtLast: handler.zrEventfulCallAtLast
  1014. };
  1015. var lastIndex = _h[event].length - 1;
  1016. var lastWrap = _h[event][lastIndex];
  1017. (lastWrap && lastWrap.callAtLast)
  1018. ? _h[event].splice(lastIndex, 0, wrap)
  1019. : _h[event].push(wrap);
  1020. return this;
  1021. };
  1022. Eventful.prototype.isSilent = function (eventName) {
  1023. var _h = this._$handlers;
  1024. return !_h || !_h[eventName] || !_h[eventName].length;
  1025. };
  1026. Eventful.prototype.off = function (eventType, handler) {
  1027. var _h = this._$handlers;
  1028. if (!_h) {
  1029. return this;
  1030. }
  1031. if (!eventType) {
  1032. this._$handlers = {};
  1033. return this;
  1034. }
  1035. if (handler) {
  1036. if (_h[eventType]) {
  1037. var newList = [];
  1038. for (var i = 0, l = _h[eventType].length; i < l; i++) {
  1039. if (_h[eventType][i].h !== handler) {
  1040. newList.push(_h[eventType][i]);
  1041. }
  1042. }
  1043. _h[eventType] = newList;
  1044. }
  1045. if (_h[eventType] && _h[eventType].length === 0) {
  1046. delete _h[eventType];
  1047. }
  1048. }
  1049. else {
  1050. delete _h[eventType];
  1051. }
  1052. return this;
  1053. };
  1054. Eventful.prototype.trigger = function (eventType) {
  1055. var args = [];
  1056. for (var _i = 1; _i < arguments.length; _i++) {
  1057. args[_i - 1] = arguments[_i];
  1058. }
  1059. if (!this._$handlers) {
  1060. return this;
  1061. }
  1062. var _h = this._$handlers[eventType];
  1063. var eventProcessor = this._$eventProcessor;
  1064. if (_h) {
  1065. var argLen = args.length;
  1066. var len = _h.length;
  1067. for (var i = 0; i < len; i++) {
  1068. var hItem = _h[i];
  1069. if (eventProcessor
  1070. && eventProcessor.filter
  1071. && hItem.query != null
  1072. && !eventProcessor.filter(eventType, hItem.query)) {
  1073. continue;
  1074. }
  1075. switch (argLen) {
  1076. case 0:
  1077. hItem.h.call(hItem.ctx);
  1078. break;
  1079. case 1:
  1080. hItem.h.call(hItem.ctx, args[0]);
  1081. break;
  1082. case 2:
  1083. hItem.h.call(hItem.ctx, args[0], args[1]);
  1084. break;
  1085. default:
  1086. hItem.h.apply(hItem.ctx, args);
  1087. break;
  1088. }
  1089. }
  1090. }
  1091. eventProcessor && eventProcessor.afterTrigger
  1092. && eventProcessor.afterTrigger(eventType);
  1093. return this;
  1094. };
  1095. Eventful.prototype.triggerWithContext = function (type) {
  1096. var args = [];
  1097. for (var _i = 1; _i < arguments.length; _i++) {
  1098. args[_i - 1] = arguments[_i];
  1099. }
  1100. if (!this._$handlers) {
  1101. return this;
  1102. }
  1103. var _h = this._$handlers[type];
  1104. var eventProcessor = this._$eventProcessor;
  1105. if (_h) {
  1106. var argLen = args.length;
  1107. var ctx = args[argLen - 1];
  1108. var len = _h.length;
  1109. for (var i = 0; i < len; i++) {
  1110. var hItem = _h[i];
  1111. if (eventProcessor
  1112. && eventProcessor.filter
  1113. && hItem.query != null
  1114. && !eventProcessor.filter(type, hItem.query)) {
  1115. continue;
  1116. }
  1117. switch (argLen) {
  1118. case 0:
  1119. hItem.h.call(ctx);
  1120. break;
  1121. case 1:
  1122. hItem.h.call(ctx, args[0]);
  1123. break;
  1124. case 2:
  1125. hItem.h.call(ctx, args[0], args[1]);
  1126. break;
  1127. default:
  1128. hItem.h.apply(ctx, args.slice(1, argLen - 1));
  1129. break;
  1130. }
  1131. }
  1132. }
  1133. eventProcessor && eventProcessor.afterTrigger
  1134. && eventProcessor.afterTrigger(type);
  1135. return this;
  1136. };
  1137. return Eventful;
  1138. }());
  1139. var LN2 = Math.log(2);
  1140. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1141. var cacheKey = rowMask + '-' + colMask;
  1142. var fullRank = rows.length;
  1143. if (detCache.hasOwnProperty(cacheKey)) {
  1144. return detCache[cacheKey];
  1145. }
  1146. if (rank === 1) {
  1147. var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);
  1148. return rows[rowStart][colStart];
  1149. }
  1150. var subRowMask = rowMask | (1 << rowStart);
  1151. var subRowStart = rowStart + 1;
  1152. while (rowMask & (1 << subRowStart)) {
  1153. subRowStart++;
  1154. }
  1155. var sum = 0;
  1156. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1157. var colTag = 1 << j;
  1158. if (!(colTag & colMask)) {
  1159. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]
  1160. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1161. colLocalIdx++;
  1162. }
  1163. }
  1164. detCache[cacheKey] = sum;
  1165. return sum;
  1166. }
  1167. function buildTransformer(src, dest) {
  1168. var mA = [
  1169. [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],
  1170. [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],
  1171. [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],
  1172. [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],
  1173. [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],
  1174. [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],
  1175. [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],
  1176. [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]
  1177. ];
  1178. var detCache = {};
  1179. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1180. if (det === 0) {
  1181. return;
  1182. }
  1183. var vh = [];
  1184. for (var i = 0; i < 8; i++) {
  1185. for (var j = 0; j < 8; j++) {
  1186. vh[j] == null && (vh[j] = 0);
  1187. vh[j] += ((i + j) % 2 ? -1 : 1)
  1188. * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)
  1189. / det * dest[i];
  1190. }
  1191. }
  1192. return function (out, srcPointX, srcPointY) {
  1193. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1194. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1195. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1196. };
  1197. }
  1198. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1199. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1200. if (el.getBoundingClientRect && env.domSupported && !isCanvasEl(el)) {
  1201. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1202. var markers = prepareCoordMarkers(el, saved);
  1203. var transformer = preparePointerTransformer(markers, saved, inverse);
  1204. if (transformer) {
  1205. transformer(out, inX, inY);
  1206. return true;
  1207. }
  1208. }
  1209. return false;
  1210. }
  1211. function prepareCoordMarkers(el, saved) {
  1212. var markers = saved.markers;
  1213. if (markers) {
  1214. return markers;
  1215. }
  1216. markers = saved.markers = [];
  1217. var propLR = ['left', 'right'];
  1218. var propTB = ['top', 'bottom'];
  1219. for (var i = 0; i < 4; i++) {
  1220. var marker = document.createElement('div');
  1221. var stl = marker.style;
  1222. var idxLR = i % 2;
  1223. var idxTB = (i >> 1) % 2;
  1224. stl.cssText = [
  1225. 'position: absolute',
  1226. 'visibility: hidden',
  1227. 'padding: 0',
  1228. 'margin: 0',
  1229. 'border-width: 0',
  1230. 'user-select: none',
  1231. 'width:0',
  1232. 'height:0',
  1233. propLR[idxLR] + ':0',
  1234. propTB[idxTB] + ':0',
  1235. propLR[1 - idxLR] + ':auto',
  1236. propTB[1 - idxTB] + ':auto',
  1237. ''
  1238. ].join('!important;');
  1239. el.appendChild(marker);
  1240. markers.push(marker);
  1241. }
  1242. return markers;
  1243. }
  1244. function preparePointerTransformer(markers, saved, inverse) {
  1245. var transformerName = inverse ? 'invTrans' : 'trans';
  1246. var transformer = saved[transformerName];
  1247. var oldSrcCoords = saved.srcCoords;
  1248. var srcCoords = [];
  1249. var destCoords = [];
  1250. var oldCoordTheSame = true;
  1251. for (var i = 0; i < 4; i++) {
  1252. var rect = markers[i].getBoundingClientRect();
  1253. var ii = 2 * i;
  1254. var x = rect.left;
  1255. var y = rect.top;
  1256. srcCoords.push(x, y);
  1257. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1258. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1259. }
  1260. return (oldCoordTheSame && transformer)
  1261. ? transformer
  1262. : (saved.srcCoords = srcCoords,
  1263. saved[transformerName] = inverse
  1264. ? buildTransformer(destCoords, srcCoords)
  1265. : buildTransformer(srcCoords, destCoords));
  1266. }
  1267. function isCanvasEl(el) {
  1268. return el.nodeName.toUpperCase() === 'CANVAS';
  1269. }
  1270. var replaceReg = /([&<>"'])/g;
  1271. var replaceMap = {
  1272. '&': '&amp;',
  1273. '<': '&lt;',
  1274. '>': '&gt;',
  1275. '"': '&quot;',
  1276. '\'': '&#39;'
  1277. };
  1278. function encodeHTML(source) {
  1279. return source == null
  1280. ? ''
  1281. : (source + '').replace(replaceReg, function (str, c) {
  1282. return replaceMap[c];
  1283. });
  1284. }
  1285. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1286. var _calcOut = [];
  1287. var firefoxNotSupportOffsetXY = env.browser.firefox
  1288. && +env.browser.version.split('.')[0] < 39;
  1289. function clientToLocal(el, e, out, calculate) {
  1290. out = out || {};
  1291. if (calculate) {
  1292. calculateZrXY(el, e, out);
  1293. }
  1294. else if (firefoxNotSupportOffsetXY
  1295. && e.layerX != null
  1296. && e.layerX !== e.offsetX) {
  1297. out.zrX = e.layerX;
  1298. out.zrY = e.layerY;
  1299. }
  1300. else if (e.offsetX != null) {
  1301. out.zrX = e.offsetX;
  1302. out.zrY = e.offsetY;
  1303. }
  1304. else {
  1305. calculateZrXY(el, e, out);
  1306. }
  1307. return out;
  1308. }
  1309. function calculateZrXY(el, e, out) {
  1310. if (env.domSupported && el.getBoundingClientRect) {
  1311. var ex = e.clientX;
  1312. var ey = e.clientY;
  1313. if (isCanvasEl(el)) {
  1314. var box = el.getBoundingClientRect();
  1315. out.zrX = ex - box.left;
  1316. out.zrY = ey - box.top;
  1317. return;
  1318. }
  1319. else {
  1320. if (transformCoordWithViewport(_calcOut, el, ex, ey)) {
  1321. out.zrX = _calcOut[0];
  1322. out.zrY = _calcOut[1];
  1323. return;
  1324. }
  1325. }
  1326. }
  1327. out.zrX = out.zrY = 0;
  1328. }
  1329. function getNativeEvent(e) {
  1330. return e
  1331. || window.event;
  1332. }
  1333. function normalizeEvent(el, e, calculate) {
  1334. e = getNativeEvent(e);
  1335. if (e.zrX != null) {
  1336. return e;
  1337. }
  1338. var eventType = e.type;
  1339. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1340. if (!isTouch) {
  1341. clientToLocal(el, e, e, calculate);
  1342. var wheelDelta = getWheelDeltaMayPolyfill(e);
  1343. e.zrDelta = wheelDelta ? wheelDelta / 120 : -(e.detail || 0) / 3;
  1344. }
  1345. else {
  1346. var touch = eventType !== 'touchend'
  1347. ? e.targetTouches[0]
  1348. : e.changedTouches[0];
  1349. touch && clientToLocal(el, touch, e, calculate);
  1350. }
  1351. var button = e.button;
  1352. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1353. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1354. }
  1355. return e;
  1356. }
  1357. function getWheelDeltaMayPolyfill(e) {
  1358. var rawWheelDelta = e.wheelDelta;
  1359. if (rawWheelDelta) {
  1360. return rawWheelDelta;
  1361. }
  1362. var deltaX = e.deltaX;
  1363. var deltaY = e.deltaY;
  1364. if (deltaX == null || deltaY == null) {
  1365. return rawWheelDelta;
  1366. }
  1367. var delta = deltaY !== 0 ? Math.abs(deltaY) : Math.abs(deltaX);
  1368. var sign = deltaY > 0 ? -1
  1369. : deltaY < 0 ? 1
  1370. : deltaX > 0 ? -1
  1371. : 1;
  1372. return 3 * delta * sign;
  1373. }
  1374. function addEventListener(el, name, handler, opt) {
  1375. el.addEventListener(name, handler, opt);
  1376. }
  1377. function removeEventListener(el, name, handler, opt) {
  1378. el.removeEventListener(name, handler, opt);
  1379. }
  1380. var stop = function (e) {
  1381. e.preventDefault();
  1382. e.stopPropagation();
  1383. e.cancelBubble = true;
  1384. };
  1385. var GestureMgr = (function () {
  1386. function GestureMgr() {
  1387. this._track = [];
  1388. }
  1389. GestureMgr.prototype.recognize = function (event, target, root) {
  1390. this._doTrack(event, target, root);
  1391. return this._recognize(event);
  1392. };
  1393. GestureMgr.prototype.clear = function () {
  1394. this._track.length = 0;
  1395. return this;
  1396. };
  1397. GestureMgr.prototype._doTrack = function (event, target, root) {
  1398. var touches = event.touches;
  1399. if (!touches) {
  1400. return;
  1401. }
  1402. var trackItem = {
  1403. points: [],
  1404. touches: [],
  1405. target: target,
  1406. event: event
  1407. };
  1408. for (var i = 0, len = touches.length; i < len; i++) {
  1409. var touch = touches[i];
  1410. var pos = clientToLocal(root, touch, {});
  1411. trackItem.points.push([pos.zrX, pos.zrY]);
  1412. trackItem.touches.push(touch);
  1413. }
  1414. this._track.push(trackItem);
  1415. };
  1416. GestureMgr.prototype._recognize = function (event) {
  1417. for (var eventName in recognizers) {
  1418. if (recognizers.hasOwnProperty(eventName)) {
  1419. var gestureInfo = recognizers[eventName](this._track, event);
  1420. if (gestureInfo) {
  1421. return gestureInfo;
  1422. }
  1423. }
  1424. }
  1425. };
  1426. return GestureMgr;
  1427. }());
  1428. function dist$1(pointPair) {
  1429. var dx = pointPair[1][0] - pointPair[0][0];
  1430. var dy = pointPair[1][1] - pointPair[0][1];
  1431. return Math.sqrt(dx * dx + dy * dy);
  1432. }
  1433. function center(pointPair) {
  1434. return [
  1435. (pointPair[0][0] + pointPair[1][0]) / 2,
  1436. (pointPair[0][1] + pointPair[1][1]) / 2
  1437. ];
  1438. }
  1439. var recognizers = {
  1440. pinch: function (tracks, event) {
  1441. var trackLen = tracks.length;
  1442. if (!trackLen) {
  1443. return;
  1444. }
  1445. var pinchEnd = (tracks[trackLen - 1] || {}).points;
  1446. var pinchPre = (tracks[trackLen - 2] || {}).points || pinchEnd;
  1447. if (pinchPre
  1448. && pinchPre.length > 1
  1449. && pinchEnd
  1450. && pinchEnd.length > 1) {
  1451. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1452. !isFinite(pinchScale) && (pinchScale = 1);
  1453. event.pinchScale = pinchScale;
  1454. var pinchCenter = center(pinchEnd);
  1455. event.pinchX = pinchCenter[0];
  1456. event.pinchY = pinchCenter[1];
  1457. return {
  1458. type: 'pinch',
  1459. target: tracks[0].target,
  1460. event: event
  1461. };
  1462. }
  1463. }
  1464. };
  1465. function create$1() {
  1466. return [1, 0, 0, 1, 0, 0];
  1467. }
  1468. function identity(out) {
  1469. out[0] = 1;
  1470. out[1] = 0;
  1471. out[2] = 0;
  1472. out[3] = 1;
  1473. out[4] = 0;
  1474. out[5] = 0;
  1475. return out;
  1476. }
  1477. function copy$1(out, m) {
  1478. out[0] = m[0];
  1479. out[1] = m[1];
  1480. out[2] = m[2];
  1481. out[3] = m[3];
  1482. out[4] = m[4];
  1483. out[5] = m[5];
  1484. return out;
  1485. }
  1486. function mul$1(out, m1, m2) {
  1487. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  1488. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  1489. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  1490. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  1491. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1492. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1493. out[0] = out0;
  1494. out[1] = out1;
  1495. out[2] = out2;
  1496. out[3] = out3;
  1497. out[4] = out4;
  1498. out[5] = out5;
  1499. return out;
  1500. }
  1501. function translate(out, a, v) {
  1502. out[0] = a[0];
  1503. out[1] = a[1];
  1504. out[2] = a[2];
  1505. out[3] = a[3];
  1506. out[4] = a[4] + v[0];
  1507. out[5] = a[5] + v[1];
  1508. return out;
  1509. }
  1510. function rotate(out, a, rad, pivot) {
  1511. if (pivot === void 0) { pivot = [0, 0]; }
  1512. var aa = a[0];
  1513. var ac = a[2];
  1514. var atx = a[4];
  1515. var ab = a[1];
  1516. var ad = a[3];
  1517. var aty = a[5];
  1518. var st = Math.sin(rad);
  1519. var ct = Math.cos(rad);
  1520. out[0] = aa * ct + ab * st;
  1521. out[1] = -aa * st + ab * ct;
  1522. out[2] = ac * ct + ad * st;
  1523. out[3] = -ac * st + ct * ad;
  1524. out[4] = ct * (atx - pivot[0]) + st * (aty - pivot[1]) + pivot[0];
  1525. out[5] = ct * (aty - pivot[1]) - st * (atx - pivot[0]) + pivot[1];
  1526. return out;
  1527. }
  1528. function scale$1(out, a, v) {
  1529. var vx = v[0];
  1530. var vy = v[1];
  1531. out[0] = a[0] * vx;
  1532. out[1] = a[1] * vy;
  1533. out[2] = a[2] * vx;
  1534. out[3] = a[3] * vy;
  1535. out[4] = a[4] * vx;
  1536. out[5] = a[5] * vy;
  1537. return out;
  1538. }
  1539. function invert(out, a) {
  1540. var aa = a[0];
  1541. var ac = a[2];
  1542. var atx = a[4];
  1543. var ab = a[1];
  1544. var ad = a[3];
  1545. var aty = a[5];
  1546. var det = aa * ad - ab * ac;
  1547. if (!det) {
  1548. return null;
  1549. }
  1550. det = 1.0 / det;
  1551. out[0] = ad * det;
  1552. out[1] = -ab * det;
  1553. out[2] = -ac * det;
  1554. out[3] = aa * det;
  1555. out[4] = (ac * aty - ad * atx) * det;
  1556. out[5] = (ab * atx - aa * aty) * det;
  1557. return out;
  1558. }
  1559. function clone$2(a) {
  1560. var b = create$1();
  1561. copy$1(b, a);
  1562. return b;
  1563. }
  1564. var matrix = /*#__PURE__*/Object.freeze({
  1565. __proto__: null,
  1566. create: create$1,
  1567. identity: identity,
  1568. copy: copy$1,
  1569. mul: mul$1,
  1570. translate: translate,
  1571. rotate: rotate,
  1572. scale: scale$1,
  1573. invert: invert,
  1574. clone: clone$2
  1575. });
  1576. var Point = (function () {
  1577. function Point(x, y) {
  1578. this.x = x || 0;
  1579. this.y = y || 0;
  1580. }
  1581. Point.prototype.copy = function (other) {
  1582. this.x = other.x;
  1583. this.y = other.y;
  1584. return this;
  1585. };
  1586. Point.prototype.clone = function () {
  1587. return new Point(this.x, this.y);
  1588. };
  1589. Point.prototype.set = function (x, y) {
  1590. this.x = x;
  1591. this.y = y;
  1592. return this;
  1593. };
  1594. Point.prototype.equal = function (other) {
  1595. return other.x === this.x && other.y === this.y;
  1596. };
  1597. Point.prototype.add = function (other) {
  1598. this.x += other.x;
  1599. this.y += other.y;
  1600. return this;
  1601. };
  1602. Point.prototype.scale = function (scalar) {
  1603. this.x *= scalar;
  1604. this.y *= scalar;
  1605. };
  1606. Point.prototype.scaleAndAdd = function (other, scalar) {
  1607. this.x += other.x * scalar;
  1608. this.y += other.y * scalar;
  1609. };
  1610. Point.prototype.sub = function (other) {
  1611. this.x -= other.x;
  1612. this.y -= other.y;
  1613. return this;
  1614. };
  1615. Point.prototype.dot = function (other) {
  1616. return this.x * other.x + this.y * other.y;
  1617. };
  1618. Point.prototype.len = function () {
  1619. return Math.sqrt(this.x * this.x + this.y * this.y);
  1620. };
  1621. Point.prototype.lenSquare = function () {
  1622. return this.x * this.x + this.y * this.y;
  1623. };
  1624. Point.prototype.normalize = function () {
  1625. var len = this.len();
  1626. this.x /= len;
  1627. this.y /= len;
  1628. return this;
  1629. };
  1630. Point.prototype.distance = function (other) {
  1631. var dx = this.x - other.x;
  1632. var dy = this.y - other.y;
  1633. return Math.sqrt(dx * dx + dy * dy);
  1634. };
  1635. Point.prototype.distanceSquare = function (other) {
  1636. var dx = this.x - other.x;
  1637. var dy = this.y - other.y;
  1638. return dx * dx + dy * dy;
  1639. };
  1640. Point.prototype.negate = function () {
  1641. this.x = -this.x;
  1642. this.y = -this.y;
  1643. return this;
  1644. };
  1645. Point.prototype.transform = function (m) {
  1646. if (!m) {
  1647. return;
  1648. }
  1649. var x = this.x;
  1650. var y = this.y;
  1651. this.x = m[0] * x + m[2] * y + m[4];
  1652. this.y = m[1] * x + m[3] * y + m[5];
  1653. return this;
  1654. };
  1655. Point.prototype.toArray = function (out) {
  1656. out[0] = this.x;
  1657. out[1] = this.y;
  1658. return out;
  1659. };
  1660. Point.prototype.fromArray = function (input) {
  1661. this.x = input[0];
  1662. this.y = input[1];
  1663. };
  1664. Point.set = function (p, x, y) {
  1665. p.x = x;
  1666. p.y = y;
  1667. };
  1668. Point.copy = function (p, p2) {
  1669. p.x = p2.x;
  1670. p.y = p2.y;
  1671. };
  1672. Point.len = function (p) {
  1673. return Math.sqrt(p.x * p.x + p.y * p.y);
  1674. };
  1675. Point.lenSquare = function (p) {
  1676. return p.x * p.x + p.y * p.y;
  1677. };
  1678. Point.dot = function (p0, p1) {
  1679. return p0.x * p1.x + p0.y * p1.y;
  1680. };
  1681. Point.add = function (out, p0, p1) {
  1682. out.x = p0.x + p1.x;
  1683. out.y = p0.y + p1.y;
  1684. };
  1685. Point.sub = function (out, p0, p1) {
  1686. out.x = p0.x - p1.x;
  1687. out.y = p0.y - p1.y;
  1688. };
  1689. Point.scale = function (out, p0, scalar) {
  1690. out.x = p0.x * scalar;
  1691. out.y = p0.y * scalar;
  1692. };
  1693. Point.scaleAndAdd = function (out, p0, p1, scalar) {
  1694. out.x = p0.x + p1.x * scalar;
  1695. out.y = p0.y + p1.y * scalar;
  1696. };
  1697. Point.lerp = function (out, p0, p1, t) {
  1698. var onet = 1 - t;
  1699. out.x = onet * p0.x + t * p1.x;
  1700. out.y = onet * p0.y + t * p1.y;
  1701. };
  1702. return Point;
  1703. }());
  1704. var mathMin = Math.min;
  1705. var mathMax = Math.max;
  1706. var lt = new Point();
  1707. var rb = new Point();
  1708. var lb = new Point();
  1709. var rt = new Point();
  1710. var minTv = new Point();
  1711. var maxTv = new Point();
  1712. var BoundingRect = (function () {
  1713. function BoundingRect(x, y, width, height) {
  1714. if (width < 0) {
  1715. x = x + width;
  1716. width = -width;
  1717. }
  1718. if (height < 0) {
  1719. y = y + height;
  1720. height = -height;
  1721. }
  1722. this.x = x;
  1723. this.y = y;
  1724. this.width = width;
  1725. this.height = height;
  1726. }
  1727. BoundingRect.prototype.union = function (other) {
  1728. var x = mathMin(other.x, this.x);
  1729. var y = mathMin(other.y, this.y);
  1730. if (isFinite(this.x) && isFinite(this.width)) {
  1731. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  1732. }
  1733. else {
  1734. this.width = other.width;
  1735. }
  1736. if (isFinite(this.y) && isFinite(this.height)) {
  1737. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  1738. }
  1739. else {
  1740. this.height = other.height;
  1741. }
  1742. this.x = x;
  1743. this.y = y;
  1744. };
  1745. BoundingRect.prototype.applyTransform = function (m) {
  1746. BoundingRect.applyTransform(this, this, m);
  1747. };
  1748. BoundingRect.prototype.calculateTransform = function (b) {
  1749. var a = this;
  1750. var sx = b.width / a.width;
  1751. var sy = b.height / a.height;
  1752. var m = create$1();
  1753. translate(m, m, [-a.x, -a.y]);
  1754. scale$1(m, m, [sx, sy]);
  1755. translate(m, m, [b.x, b.y]);
  1756. return m;
  1757. };
  1758. BoundingRect.prototype.intersect = function (b, mtv) {
  1759. if (!b) {
  1760. return false;
  1761. }
  1762. if (!(b instanceof BoundingRect)) {
  1763. b = BoundingRect.create(b);
  1764. }
  1765. var a = this;
  1766. var ax0 = a.x;
  1767. var ax1 = a.x + a.width;
  1768. var ay0 = a.y;
  1769. var ay1 = a.y + a.height;
  1770. var bx0 = b.x;
  1771. var bx1 = b.x + b.width;
  1772. var by0 = b.y;
  1773. var by1 = b.y + b.height;
  1774. var overlap = !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  1775. if (mtv) {
  1776. var dMin = Infinity;
  1777. var dMax = 0;
  1778. var d0 = Math.abs(ax1 - bx0);
  1779. var d1 = Math.abs(bx1 - ax0);
  1780. var d2 = Math.abs(ay1 - by0);
  1781. var d3 = Math.abs(by1 - ay0);
  1782. var dx = Math.min(d0, d1);
  1783. var dy = Math.min(d2, d3);
  1784. if (ax1 < bx0 || bx1 < ax0) {
  1785. if (dx > dMax) {
  1786. dMax = dx;
  1787. if (d0 < d1) {
  1788. Point.set(maxTv, -d0, 0);
  1789. }
  1790. else {
  1791. Point.set(maxTv, d1, 0);
  1792. }
  1793. }
  1794. }
  1795. else {
  1796. if (dx < dMin) {
  1797. dMin = dx;
  1798. if (d0 < d1) {
  1799. Point.set(minTv, d0, 0);
  1800. }
  1801. else {
  1802. Point.set(minTv, -d1, 0);
  1803. }
  1804. }
  1805. }
  1806. if (ay1 < by0 || by1 < ay0) {
  1807. if (dy > dMax) {
  1808. dMax = dy;
  1809. if (d2 < d3) {
  1810. Point.set(maxTv, 0, -d2);
  1811. }
  1812. else {
  1813. Point.set(maxTv, 0, d3);
  1814. }
  1815. }
  1816. }
  1817. else {
  1818. if (dx < dMin) {
  1819. dMin = dx;
  1820. if (d2 < d3) {
  1821. Point.set(minTv, 0, d2);
  1822. }
  1823. else {
  1824. Point.set(minTv, 0, -d3);
  1825. }
  1826. }
  1827. }
  1828. }
  1829. if (mtv) {
  1830. Point.copy(mtv, overlap ? minTv : maxTv);
  1831. }
  1832. return overlap;
  1833. };
  1834. BoundingRect.prototype.contain = function (x, y) {
  1835. var rect = this;
  1836. return x >= rect.x
  1837. && x <= (rect.x + rect.width)
  1838. && y >= rect.y
  1839. && y <= (rect.y + rect.height);
  1840. };
  1841. BoundingRect.prototype.clone = function () {
  1842. return new BoundingRect(this.x, this.y, this.width, this.height);
  1843. };
  1844. BoundingRect.prototype.copy = function (other) {
  1845. BoundingRect.copy(this, other);
  1846. };
  1847. BoundingRect.prototype.plain = function () {
  1848. return {
  1849. x: this.x,
  1850. y: this.y,
  1851. width: this.width,
  1852. height: this.height
  1853. };
  1854. };
  1855. BoundingRect.prototype.isFinite = function () {
  1856. return isFinite(this.x)
  1857. && isFinite(this.y)
  1858. && isFinite(this.width)
  1859. && isFinite(this.height);
  1860. };
  1861. BoundingRect.prototype.isZero = function () {
  1862. return this.width === 0 || this.height === 0;
  1863. };
  1864. BoundingRect.create = function (rect) {
  1865. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  1866. };
  1867. BoundingRect.copy = function (target, source) {
  1868. target.x = source.x;
  1869. target.y = source.y;
  1870. target.width = source.width;
  1871. target.height = source.height;
  1872. };
  1873. BoundingRect.applyTransform = function (target, source, m) {
  1874. if (!m) {
  1875. if (target !== source) {
  1876. BoundingRect.copy(target, source);
  1877. }
  1878. return;
  1879. }
  1880. if (m[1] < 1e-5 && m[1] > -1e-5 && m[2] < 1e-5 && m[2] > -1e-5) {
  1881. var sx = m[0];
  1882. var sy = m[3];
  1883. var tx = m[4];
  1884. var ty = m[5];
  1885. target.x = source.x * sx + tx;
  1886. target.y = source.y * sy + ty;
  1887. target.width = source.width * sx;
  1888. target.height = source.height * sy;
  1889. if (target.width < 0) {
  1890. target.x += target.width;
  1891. target.width = -target.width;
  1892. }
  1893. if (target.height < 0) {
  1894. target.y += target.height;
  1895. target.height = -target.height;
  1896. }
  1897. return;
  1898. }
  1899. lt.x = lb.x = source.x;
  1900. lt.y = rt.y = source.y;
  1901. rb.x = rt.x = source.x + source.width;
  1902. rb.y = lb.y = source.y + source.height;
  1903. lt.transform(m);
  1904. rt.transform(m);
  1905. rb.transform(m);
  1906. lb.transform(m);
  1907. target.x = mathMin(lt.x, rb.x, lb.x, rt.x);
  1908. target.y = mathMin(lt.y, rb.y, lb.y, rt.y);
  1909. var maxX = mathMax(lt.x, rb.x, lb.x, rt.x);
  1910. var maxY = mathMax(lt.y, rb.y, lb.y, rt.y);
  1911. target.width = maxX - target.x;
  1912. target.height = maxY - target.y;
  1913. };
  1914. return BoundingRect;
  1915. }());
  1916. var SILENT = 'silent';
  1917. function makeEventPacket(eveType, targetInfo, event) {
  1918. return {
  1919. type: eveType,
  1920. event: event,
  1921. target: targetInfo.target,
  1922. topTarget: targetInfo.topTarget,
  1923. cancelBubble: false,
  1924. offsetX: event.zrX,
  1925. offsetY: event.zrY,
  1926. gestureEvent: event.gestureEvent,
  1927. pinchX: event.pinchX,
  1928. pinchY: event.pinchY,
  1929. pinchScale: event.pinchScale,
  1930. wheelDelta: event.zrDelta,
  1931. zrByTouch: event.zrByTouch,
  1932. which: event.which,
  1933. stop: stopEvent
  1934. };
  1935. }
  1936. function stopEvent() {
  1937. stop(this.event);
  1938. }
  1939. var EmptyProxy = (function (_super) {
  1940. __extends(EmptyProxy, _super);
  1941. function EmptyProxy() {
  1942. var _this = _super !== null && _super.apply(this, arguments) || this;
  1943. _this.handler = null;
  1944. return _this;
  1945. }
  1946. EmptyProxy.prototype.dispose = function () { };
  1947. EmptyProxy.prototype.setCursor = function () { };
  1948. return EmptyProxy;
  1949. }(Eventful));
  1950. var HoveredResult = (function () {
  1951. function HoveredResult(x, y) {
  1952. this.x = x;
  1953. this.y = y;
  1954. }
  1955. return HoveredResult;
  1956. }());
  1957. var handlerNames = [
  1958. 'click', 'dblclick', 'mousewheel', 'mouseout',
  1959. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  1960. ];
  1961. var tmpRect = new BoundingRect(0, 0, 0, 0);
  1962. var Handler = (function (_super) {
  1963. __extends(Handler, _super);
  1964. function Handler(storage, painter, proxy, painterRoot, pointerSize) {
  1965. var _this = _super.call(this) || this;
  1966. _this._hovered = new HoveredResult(0, 0);
  1967. _this.storage = storage;
  1968. _this.painter = painter;
  1969. _this.painterRoot = painterRoot;
  1970. _this._pointerSize = pointerSize;
  1971. proxy = proxy || new EmptyProxy();
  1972. _this.proxy = null;
  1973. _this.setHandlerProxy(proxy);
  1974. _this._draggingMgr = new Draggable(_this);
  1975. return _this;
  1976. }
  1977. Handler.prototype.setHandlerProxy = function (proxy) {
  1978. if (this.proxy) {
  1979. this.proxy.dispose();
  1980. }
  1981. if (proxy) {
  1982. each(handlerNames, function (name) {
  1983. proxy.on && proxy.on(name, this[name], this);
  1984. }, this);
  1985. proxy.handler = this;
  1986. }
  1987. this.proxy = proxy;
  1988. };
  1989. Handler.prototype.mousemove = function (event) {
  1990. var x = event.zrX;
  1991. var y = event.zrY;
  1992. var isOutside = isOutsideBoundary(this, x, y);
  1993. var lastHovered = this._hovered;
  1994. var lastHoveredTarget = lastHovered.target;
  1995. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  1996. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  1997. lastHoveredTarget = lastHovered.target;
  1998. }
  1999. var hovered = this._hovered = isOutside ? new HoveredResult(x, y) : this.findHover(x, y);
  2000. var hoveredTarget = hovered.target;
  2001. var proxy = this.proxy;
  2002. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  2003. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2004. this.dispatchToElement(lastHovered, 'mouseout', event);
  2005. }
  2006. this.dispatchToElement(hovered, 'mousemove', event);
  2007. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2008. this.dispatchToElement(hovered, 'mouseover', event);
  2009. }
  2010. };
  2011. Handler.prototype.mouseout = function (event) {
  2012. var eventControl = event.zrEventControl;
  2013. if (eventControl !== 'only_globalout') {
  2014. this.dispatchToElement(this._hovered, 'mouseout', event);
  2015. }
  2016. if (eventControl !== 'no_globalout') {
  2017. this.trigger('globalout', { type: 'globalout', event: event });
  2018. }
  2019. };
  2020. Handler.prototype.resize = function () {
  2021. this._hovered = new HoveredResult(0, 0);
  2022. };
  2023. Handler.prototype.dispatch = function (eventName, eventArgs) {
  2024. var handler = this[eventName];
  2025. handler && handler.call(this, eventArgs);
  2026. };
  2027. Handler.prototype.dispose = function () {
  2028. this.proxy.dispose();
  2029. this.storage = null;
  2030. this.proxy = null;
  2031. this.painter = null;
  2032. };
  2033. Handler.prototype.setCursorStyle = function (cursorStyle) {
  2034. var proxy = this.proxy;
  2035. proxy.setCursor && proxy.setCursor(cursorStyle);
  2036. };
  2037. Handler.prototype.dispatchToElement = function (targetInfo, eventName, event) {
  2038. targetInfo = targetInfo || {};
  2039. var el = targetInfo.target;
  2040. if (el && el.silent) {
  2041. return;
  2042. }
  2043. var eventKey = ('on' + eventName);
  2044. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2045. while (el) {
  2046. el[eventKey]
  2047. && (eventPacket.cancelBubble = !!el[eventKey].call(el, eventPacket));
  2048. el.trigger(eventName, eventPacket);
  2049. el = el.__hostTarget ? el.__hostTarget : el.parent;
  2050. if (eventPacket.cancelBubble) {
  2051. break;
  2052. }
  2053. }
  2054. if (!eventPacket.cancelBubble) {
  2055. this.trigger(eventName, eventPacket);
  2056. if (this.painter && this.painter.eachOtherLayer) {
  2057. this.painter.eachOtherLayer(function (layer) {
  2058. if (typeof (layer[eventKey]) === 'function') {
  2059. layer[eventKey].call(layer, eventPacket);
  2060. }
  2061. if (layer.trigger) {
  2062. layer.trigger(eventName, eventPacket);
  2063. }
  2064. });
  2065. }
  2066. }
  2067. };
  2068. Handler.prototype.findHover = function (x, y, exclude) {
  2069. var list = this.storage.getDisplayList();
  2070. var out = new HoveredResult(x, y);
  2071. setHoverTarget(list, out, x, y, exclude);
  2072. if (this._pointerSize && !out.target) {
  2073. var candidates = [];
  2074. var pointerSize = this._pointerSize;
  2075. var targetSizeHalf = pointerSize / 2;
  2076. var pointerRect = new BoundingRect(x - targetSizeHalf, y - targetSizeHalf, pointerSize, pointerSize);
  2077. for (var i = list.length - 1; i >= 0; i--) {
  2078. var el = list[i];
  2079. if (el !== exclude
  2080. && !el.ignore
  2081. && !el.ignoreCoarsePointer
  2082. && (!el.parent || !el.parent.ignoreCoarsePointer)) {
  2083. tmpRect.copy(el.getBoundingRect());
  2084. if (el.transform) {
  2085. tmpRect.applyTransform(el.transform);
  2086. }
  2087. if (tmpRect.intersect(pointerRect)) {
  2088. candidates.push(el);
  2089. }
  2090. }
  2091. }
  2092. if (candidates.length) {
  2093. var rStep = 4;
  2094. var thetaStep = Math.PI / 12;
  2095. var PI2 = Math.PI * 2;
  2096. for (var r = 0; r < targetSizeHalf; r += rStep) {
  2097. for (var theta = 0; theta < PI2; theta += thetaStep) {
  2098. var x1 = x + r * Math.cos(theta);
  2099. var y1 = y + r * Math.sin(theta);
  2100. setHoverTarget(candidates, out, x1, y1, exclude);
  2101. if (out.target) {
  2102. return out;
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. return out;
  2109. };
  2110. Handler.prototype.processGesture = function (event, stage) {
  2111. if (!this._gestureMgr) {
  2112. this._gestureMgr = new GestureMgr();
  2113. }
  2114. var gestureMgr = this._gestureMgr;
  2115. stage === 'start' && gestureMgr.clear();
  2116. var gestureInfo = gestureMgr.recognize(event, this.findHover(event.zrX, event.zrY, null).target, this.proxy.dom);
  2117. stage === 'end' && gestureMgr.clear();
  2118. if (gestureInfo) {
  2119. var type = gestureInfo.type;
  2120. event.gestureEvent = type;
  2121. var res = new HoveredResult();
  2122. res.target = gestureInfo.target;
  2123. this.dispatchToElement(res, type, gestureInfo.event);
  2124. }
  2125. };
  2126. return Handler;
  2127. }(Eventful));
  2128. each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2129. Handler.prototype[name] = function (event) {
  2130. var x = event.zrX;
  2131. var y = event.zrY;
  2132. var isOutside = isOutsideBoundary(this, x, y);
  2133. var hovered;
  2134. var hoveredTarget;
  2135. if (name !== 'mouseup' || !isOutside) {
  2136. hovered = this.findHover(x, y);
  2137. hoveredTarget = hovered.target;
  2138. }
  2139. if (name === 'mousedown') {
  2140. this._downEl = hoveredTarget;
  2141. this._downPoint = [event.zrX, event.zrY];
  2142. this._upEl = hoveredTarget;
  2143. }
  2144. else if (name === 'mouseup') {
  2145. this._upEl = hoveredTarget;
  2146. }
  2147. else if (name === 'click') {
  2148. if (this._downEl !== this._upEl
  2149. || !this._downPoint
  2150. || dist(this._downPoint, [event.zrX, event.zrY]) > 4) {
  2151. return;
  2152. }
  2153. this._downPoint = null;
  2154. }
  2155. this.dispatchToElement(hovered, name, event);
  2156. };
  2157. });
  2158. function isHover(displayable, x, y) {
  2159. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2160. var el = displayable;
  2161. var isSilent = void 0;
  2162. var ignoreClip = false;
  2163. while (el) {
  2164. if (el.ignoreClip) {
  2165. ignoreClip = true;
  2166. }
  2167. if (!ignoreClip) {
  2168. var clipPath = el.getClipPath();
  2169. if (clipPath && !clipPath.contain(x, y)) {
  2170. return false;
  2171. }
  2172. }
  2173. if (el.silent) {
  2174. isSilent = true;
  2175. }
  2176. var hostEl = el.__hostTarget;
  2177. el = hostEl ? hostEl : el.parent;
  2178. }
  2179. return isSilent ? SILENT : true;
  2180. }
  2181. return false;
  2182. }
  2183. function setHoverTarget(list, out, x, y, exclude) {
  2184. for (var i = list.length - 1; i >= 0; i--) {
  2185. var el = list[i];
  2186. var hoverCheckResult = void 0;
  2187. if (el !== exclude
  2188. && !el.ignore
  2189. && (hoverCheckResult = isHover(el, x, y))) {
  2190. !out.topTarget && (out.topTarget = el);
  2191. if (hoverCheckResult !== SILENT) {
  2192. out.target = el;
  2193. break;
  2194. }
  2195. }
  2196. }
  2197. }
  2198. function isOutsideBoundary(handlerInstance, x, y) {
  2199. var painter = handlerInstance.painter;
  2200. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  2201. }
  2202. var DEFAULT_MIN_MERGE = 32;
  2203. var DEFAULT_MIN_GALLOPING = 7;
  2204. function minRunLength(n) {
  2205. var r = 0;
  2206. while (n >= DEFAULT_MIN_MERGE) {
  2207. r |= n & 1;
  2208. n >>= 1;
  2209. }
  2210. return n + r;
  2211. }
  2212. function makeAscendingRun(array, lo, hi, compare) {
  2213. var runHi = lo + 1;
  2214. if (runHi === hi) {
  2215. return 1;
  2216. }
  2217. if (compare(array[runHi++], array[lo]) < 0) {
  2218. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  2219. runHi++;
  2220. }
  2221. reverseRun(array, lo, runHi);
  2222. }
  2223. else {
  2224. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  2225. runHi++;
  2226. }
  2227. }
  2228. return runHi - lo;
  2229. }
  2230. function reverseRun(array, lo, hi) {
  2231. hi--;
  2232. while (lo < hi) {
  2233. var t = array[lo];
  2234. array[lo++] = array[hi];
  2235. array[hi--] = t;
  2236. }
  2237. }
  2238. function binaryInsertionSort(array, lo, hi, start, compare) {
  2239. if (start === lo) {
  2240. start++;
  2241. }
  2242. for (; start < hi; start++) {
  2243. var pivot = array[start];
  2244. var left = lo;
  2245. var right = start;
  2246. var mid;
  2247. while (left < right) {
  2248. mid = left + right >>> 1;
  2249. if (compare(pivot, array[mid]) < 0) {
  2250. right = mid;
  2251. }
  2252. else {
  2253. left = mid + 1;
  2254. }
  2255. }
  2256. var n = start - left;
  2257. switch (n) {
  2258. case 3:
  2259. array[left + 3] = array[left + 2];
  2260. case 2:
  2261. array[left + 2] = array[left + 1];
  2262. case 1:
  2263. array[left + 1] = array[left];
  2264. break;
  2265. default:
  2266. while (n > 0) {
  2267. array[left + n] = array[left + n - 1];
  2268. n--;
  2269. }
  2270. }
  2271. array[left] = pivot;
  2272. }
  2273. }
  2274. function gallopLeft(value, array, start, length, hint, compare) {
  2275. var lastOffset = 0;
  2276. var maxOffset = 0;
  2277. var offset = 1;
  2278. if (compare(value, array[start + hint]) > 0) {
  2279. maxOffset = length - hint;
  2280. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  2281. lastOffset = offset;
  2282. offset = (offset << 1) + 1;
  2283. if (offset <= 0) {
  2284. offset = maxOffset;
  2285. }
  2286. }
  2287. if (offset > maxOffset) {
  2288. offset = maxOffset;
  2289. }
  2290. lastOffset += hint;
  2291. offset += hint;
  2292. }
  2293. else {
  2294. maxOffset = hint + 1;
  2295. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  2296. lastOffset = offset;
  2297. offset = (offset << 1) + 1;
  2298. if (offset <= 0) {
  2299. offset = maxOffset;
  2300. }
  2301. }
  2302. if (offset > maxOffset) {
  2303. offset = maxOffset;
  2304. }
  2305. var tmp = lastOffset;
  2306. lastOffset = hint - offset;
  2307. offset = hint - tmp;
  2308. }
  2309. lastOffset++;
  2310. while (lastOffset < offset) {
  2311. var m = lastOffset + (offset - lastOffset >>> 1);
  2312. if (compare(value, array[start + m]) > 0) {
  2313. lastOffset = m + 1;
  2314. }
  2315. else {
  2316. offset = m;
  2317. }
  2318. }
  2319. return offset;
  2320. }
  2321. function gallopRight(value, array, start, length, hint, compare) {
  2322. var lastOffset = 0;
  2323. var maxOffset = 0;
  2324. var offset = 1;
  2325. if (compare(value, array[start + hint]) < 0) {
  2326. maxOffset = hint + 1;
  2327. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  2328. lastOffset = offset;
  2329. offset = (offset << 1) + 1;
  2330. if (offset <= 0) {
  2331. offset = maxOffset;
  2332. }
  2333. }
  2334. if (offset > maxOffset) {
  2335. offset = maxOffset;
  2336. }
  2337. var tmp = lastOffset;
  2338. lastOffset = hint - offset;
  2339. offset = hint - tmp;
  2340. }
  2341. else {
  2342. maxOffset = length - hint;
  2343. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  2344. lastOffset = offset;
  2345. offset = (offset << 1) + 1;
  2346. if (offset <= 0) {
  2347. offset = maxOffset;
  2348. }
  2349. }
  2350. if (offset > maxOffset) {
  2351. offset = maxOffset;
  2352. }
  2353. lastOffset += hint;
  2354. offset += hint;
  2355. }
  2356. lastOffset++;
  2357. while (lastOffset < offset) {
  2358. var m = lastOffset + (offset - lastOffset >>> 1);
  2359. if (compare(value, array[start + m]) < 0) {
  2360. offset = m;
  2361. }
  2362. else {
  2363. lastOffset = m + 1;
  2364. }
  2365. }
  2366. return offset;
  2367. }
  2368. function TimSort(array, compare) {
  2369. var minGallop = DEFAULT_MIN_GALLOPING;
  2370. var runStart;
  2371. var runLength;
  2372. var stackSize = 0;
  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 liftedColorCache = new LRU(100);
  4024. function liftColor(color) {
  4025. if (isString(color)) {
  4026. var liftedColor = liftedColorCache.get(color);
  4027. if (!liftedColor) {
  4028. liftedColor = lift(color, -0.1);
  4029. liftedColorCache.put(color, liftedColor);
  4030. }
  4031. return liftedColor;
  4032. }
  4033. else if (isGradientObject(color)) {
  4034. var ret = extend({}, color);
  4035. ret.colorStops = map(color.colorStops, function (stop) { return ({
  4036. offset: stop.offset,
  4037. color: lift(stop.color, -0.1)
  4038. }); });
  4039. return ret;
  4040. }
  4041. return color;
  4042. }
  4043. var color = /*#__PURE__*/Object.freeze({
  4044. __proto__: null,
  4045. parse: parse,
  4046. lift: lift,
  4047. toHex: toHex,
  4048. fastLerp: fastLerp,
  4049. fastMapToColor: fastMapToColor,
  4050. lerp: lerp$1,
  4051. mapToColor: mapToColor,
  4052. modifyHSL: modifyHSL,
  4053. modifyAlpha: modifyAlpha,
  4054. stringify: stringify,
  4055. lum: lum,
  4056. random: random,
  4057. liftColor: liftColor
  4058. });
  4059. var mathRound = Math.round;
  4060. function normalizeColor(color) {
  4061. var opacity;
  4062. if (!color || color === 'transparent') {
  4063. color = 'none';
  4064. }
  4065. else if (typeof color === 'string' && color.indexOf('rgba') > -1) {
  4066. var arr = parse(color);
  4067. if (arr) {
  4068. color = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')';
  4069. opacity = arr[3];
  4070. }
  4071. }
  4072. return {
  4073. color: color,
  4074. opacity: opacity == null ? 1 : opacity
  4075. };
  4076. }
  4077. var EPSILON$1 = 1e-4;
  4078. function isAroundZero$1(transform) {
  4079. return transform < EPSILON$1 && transform > -EPSILON$1;
  4080. }
  4081. function round3(transform) {
  4082. return mathRound(transform * 1e3) / 1e3;
  4083. }
  4084. function round4(transform) {
  4085. return mathRound(transform * 1e4) / 1e4;
  4086. }
  4087. function getMatrixStr(m) {
  4088. return 'matrix('
  4089. + round3(m[0]) + ','
  4090. + round3(m[1]) + ','
  4091. + round3(m[2]) + ','
  4092. + round3(m[3]) + ','
  4093. + round4(m[4]) + ','
  4094. + round4(m[5])
  4095. + ')';
  4096. }
  4097. var TEXT_ALIGN_TO_ANCHOR = {
  4098. left: 'start',
  4099. right: 'end',
  4100. center: 'middle',
  4101. middle: 'middle'
  4102. };
  4103. function adjustTextY(y, lineHeight, textBaseline) {
  4104. if (textBaseline === 'top') {
  4105. y += lineHeight / 2;
  4106. }
  4107. else if (textBaseline === 'bottom') {
  4108. y -= lineHeight / 2;
  4109. }
  4110. return y;
  4111. }
  4112. function hasShadow(style) {
  4113. return style
  4114. && (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY);
  4115. }
  4116. function getShadowKey(displayable) {
  4117. var style = displayable.style;
  4118. var globalScale = displayable.getGlobalScale();
  4119. return [
  4120. style.shadowColor,
  4121. (style.shadowBlur || 0).toFixed(2),
  4122. (style.shadowOffsetX || 0).toFixed(2),
  4123. (style.shadowOffsetY || 0).toFixed(2),
  4124. globalScale[0],
  4125. globalScale[1]
  4126. ].join(',');
  4127. }
  4128. function isImagePattern(val) {
  4129. return val && (!!val.image);
  4130. }
  4131. function isSVGPattern(val) {
  4132. return val && (!!val.svgElement);
  4133. }
  4134. function isPattern(val) {
  4135. return isImagePattern(val) || isSVGPattern(val);
  4136. }
  4137. function isLinearGradient(val) {
  4138. return val.type === 'linear';
  4139. }
  4140. function isRadialGradient(val) {
  4141. return val.type === 'radial';
  4142. }
  4143. function isGradient(val) {
  4144. return val && (val.type === 'linear'
  4145. || val.type === 'radial');
  4146. }
  4147. function getIdURL(id) {
  4148. return "url(#" + id + ")";
  4149. }
  4150. function getPathPrecision(el) {
  4151. var scale = el.getGlobalScale();
  4152. var size = Math.max(scale[0], scale[1]);
  4153. return Math.max(Math.ceil(Math.log(size) / Math.log(10)), 1);
  4154. }
  4155. function getSRTTransformString(transform) {
  4156. var x = transform.x || 0;
  4157. var y = transform.y || 0;
  4158. var rotation = (transform.rotation || 0) * RADIAN_TO_DEGREE;
  4159. var scaleX = retrieve2(transform.scaleX, 1);
  4160. var scaleY = retrieve2(transform.scaleY, 1);
  4161. var skewX = transform.skewX || 0;
  4162. var skewY = transform.skewY || 0;
  4163. var res = [];
  4164. if (x || y) {
  4165. res.push("translate(" + x + "px," + y + "px)");
  4166. }
  4167. if (rotation) {
  4168. res.push("rotate(" + rotation + ")");
  4169. }
  4170. if (scaleX !== 1 || scaleY !== 1) {
  4171. res.push("scale(" + scaleX + "," + scaleY + ")");
  4172. }
  4173. if (skewX || skewY) {
  4174. res.push("skew(" + mathRound(skewX * RADIAN_TO_DEGREE) + "deg, " + mathRound(skewY * RADIAN_TO_DEGREE) + "deg)");
  4175. }
  4176. return res.join(' ');
  4177. }
  4178. var encodeBase64 = (function () {
  4179. if (env.hasGlobalWindow && isFunction(window.btoa)) {
  4180. return function (str) {
  4181. return window.btoa(unescape(encodeURIComponent(str)));
  4182. };
  4183. }
  4184. if (typeof Buffer !== 'undefined') {
  4185. return function (str) {
  4186. return Buffer.from(str).toString('base64');
  4187. };
  4188. }
  4189. return function (str) {
  4190. {
  4191. logError('Base64 isn\'t natively supported in the current environment.');
  4192. }
  4193. return null;
  4194. };
  4195. })();
  4196. var arraySlice = Array.prototype.slice;
  4197. function interpolateNumber(p0, p1, percent) {
  4198. return (p1 - p0) * percent + p0;
  4199. }
  4200. function interpolate1DArray(out, p0, p1, percent) {
  4201. var len = p0.length;
  4202. for (var i = 0; i < len; i++) {
  4203. out[i] = interpolateNumber(p0[i], p1[i], percent);
  4204. }
  4205. return out;
  4206. }
  4207. function interpolate2DArray(out, p0, p1, percent) {
  4208. var len = p0.length;
  4209. var len2 = len && p0[0].length;
  4210. for (var i = 0; i < len; i++) {
  4211. if (!out[i]) {
  4212. out[i] = [];
  4213. }
  4214. for (var j = 0; j < len2; j++) {
  4215. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  4216. }
  4217. }
  4218. return out;
  4219. }
  4220. function add1DArray(out, p0, p1, sign) {
  4221. var len = p0.length;
  4222. for (var i = 0; i < len; i++) {
  4223. out[i] = p0[i] + p1[i] * sign;
  4224. }
  4225. return out;
  4226. }
  4227. function add2DArray(out, p0, p1, sign) {
  4228. var len = p0.length;
  4229. var len2 = len && p0[0].length;
  4230. for (var i = 0; i < len; i++) {
  4231. if (!out[i]) {
  4232. out[i] = [];
  4233. }
  4234. for (var j = 0; j < len2; j++) {
  4235. out[i][j] = p0[i][j] + p1[i][j] * sign;
  4236. }
  4237. }
  4238. return out;
  4239. }
  4240. function fillColorStops(val0, val1) {
  4241. var len0 = val0.length;
  4242. var len1 = val1.length;
  4243. var shorterArr = len0 > len1 ? val1 : val0;
  4244. var shorterLen = Math.min(len0, len1);
  4245. var last = shorterArr[shorterLen - 1] || { color: [0, 0, 0, 0], offset: 0 };
  4246. for (var i = shorterLen; i < Math.max(len0, len1); i++) {
  4247. shorterArr.push({
  4248. offset: last.offset,
  4249. color: last.color.slice()
  4250. });
  4251. }
  4252. }
  4253. function fillArray(val0, val1, arrDim) {
  4254. var arr0 = val0;
  4255. var arr1 = val1;
  4256. if (!arr0.push || !arr1.push) {
  4257. return;
  4258. }
  4259. var arr0Len = arr0.length;
  4260. var arr1Len = arr1.length;
  4261. if (arr0Len !== arr1Len) {
  4262. var isPreviousLarger = arr0Len > arr1Len;
  4263. if (isPreviousLarger) {
  4264. arr0.length = arr1Len;
  4265. }
  4266. else {
  4267. for (var i = arr0Len; i < arr1Len; i++) {
  4268. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  4269. }
  4270. }
  4271. }
  4272. var len2 = arr0[0] && arr0[0].length;
  4273. for (var i = 0; i < arr0.length; i++) {
  4274. if (arrDim === 1) {
  4275. if (isNaN(arr0[i])) {
  4276. arr0[i] = arr1[i];
  4277. }
  4278. }
  4279. else {
  4280. for (var j = 0; j < len2; j++) {
  4281. if (isNaN(arr0[i][j])) {
  4282. arr0[i][j] = arr1[i][j];
  4283. }
  4284. }
  4285. }
  4286. }
  4287. }
  4288. function cloneValue(value) {
  4289. if (isArrayLike(value)) {
  4290. var len = value.length;
  4291. if (isArrayLike(value[0])) {
  4292. var ret = [];
  4293. for (var i = 0; i < len; i++) {
  4294. ret.push(arraySlice.call(value[i]));
  4295. }
  4296. return ret;
  4297. }
  4298. return arraySlice.call(value);
  4299. }
  4300. return value;
  4301. }
  4302. function rgba2String(rgba) {
  4303. rgba[0] = Math.floor(rgba[0]) || 0;
  4304. rgba[1] = Math.floor(rgba[1]) || 0;
  4305. rgba[2] = Math.floor(rgba[2]) || 0;
  4306. rgba[3] = rgba[3] == null ? 1 : rgba[3];
  4307. return 'rgba(' + rgba.join(',') + ')';
  4308. }
  4309. function guessArrayDim(value) {
  4310. return isArrayLike(value && value[0]) ? 2 : 1;
  4311. }
  4312. var VALUE_TYPE_NUMBER = 0;
  4313. var VALUE_TYPE_1D_ARRAY = 1;
  4314. var VALUE_TYPE_2D_ARRAY = 2;
  4315. var VALUE_TYPE_COLOR = 3;
  4316. var VALUE_TYPE_LINEAR_GRADIENT = 4;
  4317. var VALUE_TYPE_RADIAL_GRADIENT = 5;
  4318. var VALUE_TYPE_UNKOWN = 6;
  4319. function isGradientValueType(valType) {
  4320. return valType === VALUE_TYPE_LINEAR_GRADIENT || valType === VALUE_TYPE_RADIAL_GRADIENT;
  4321. }
  4322. function isArrayValueType(valType) {
  4323. return valType === VALUE_TYPE_1D_ARRAY || valType === VALUE_TYPE_2D_ARRAY;
  4324. }
  4325. var tmpRgba = [0, 0, 0, 0];
  4326. var Track = (function () {
  4327. function Track(propName) {
  4328. this.keyframes = [];
  4329. this.discrete = false;
  4330. this._invalid = false;
  4331. this._needsSort = false;
  4332. this._lastFr = 0;
  4333. this._lastFrP = 0;
  4334. this.propName = propName;
  4335. }
  4336. Track.prototype.isFinished = function () {
  4337. return this._finished;
  4338. };
  4339. Track.prototype.setFinished = function () {
  4340. this._finished = true;
  4341. if (this._additiveTrack) {
  4342. this._additiveTrack.setFinished();
  4343. }
  4344. };
  4345. Track.prototype.needsAnimate = function () {
  4346. return this.keyframes.length >= 1;
  4347. };
  4348. Track.prototype.getAdditiveTrack = function () {
  4349. return this._additiveTrack;
  4350. };
  4351. Track.prototype.addKeyframe = function (time, rawValue, easing) {
  4352. this._needsSort = true;
  4353. var keyframes = this.keyframes;
  4354. var len = keyframes.length;
  4355. var discrete = false;
  4356. var valType = VALUE_TYPE_UNKOWN;
  4357. var value = rawValue;
  4358. if (isArrayLike(rawValue)) {
  4359. var arrayDim = guessArrayDim(rawValue);
  4360. valType = arrayDim;
  4361. if (arrayDim === 1 && !isNumber(rawValue[0])
  4362. || arrayDim === 2 && !isNumber(rawValue[0][0])) {
  4363. discrete = true;
  4364. }
  4365. }
  4366. else {
  4367. if (isNumber(rawValue) && !eqNaN(rawValue)) {
  4368. valType = VALUE_TYPE_NUMBER;
  4369. }
  4370. else if (isString(rawValue)) {
  4371. if (!isNaN(+rawValue)) {
  4372. valType = VALUE_TYPE_NUMBER;
  4373. }
  4374. else {
  4375. var colorArray = parse(rawValue);
  4376. if (colorArray) {
  4377. value = colorArray;
  4378. valType = VALUE_TYPE_COLOR;
  4379. }
  4380. }
  4381. }
  4382. else if (isGradientObject(rawValue)) {
  4383. var parsedGradient = extend({}, value);
  4384. parsedGradient.colorStops = map(rawValue.colorStops, function (colorStop) { return ({
  4385. offset: colorStop.offset,
  4386. color: parse(colorStop.color)
  4387. }); });
  4388. if (isLinearGradient(rawValue)) {
  4389. valType = VALUE_TYPE_LINEAR_GRADIENT;
  4390. }
  4391. else if (isRadialGradient(rawValue)) {
  4392. valType = VALUE_TYPE_RADIAL_GRADIENT;
  4393. }
  4394. value = parsedGradient;
  4395. }
  4396. }
  4397. if (len === 0) {
  4398. this.valType = valType;
  4399. }
  4400. else if (valType !== this.valType || valType === VALUE_TYPE_UNKOWN) {
  4401. discrete = true;
  4402. }
  4403. this.discrete = this.discrete || discrete;
  4404. var kf = {
  4405. time: time,
  4406. value: value,
  4407. rawValue: rawValue,
  4408. percent: 0
  4409. };
  4410. if (easing) {
  4411. kf.easing = easing;
  4412. kf.easingFunc = isFunction(easing)
  4413. ? easing
  4414. : easingFuncs[easing] || createCubicEasingFunc(easing);
  4415. }
  4416. keyframes.push(kf);
  4417. return kf;
  4418. };
  4419. Track.prototype.prepare = function (maxTime, additiveTrack) {
  4420. var kfs = this.keyframes;
  4421. if (this._needsSort) {
  4422. kfs.sort(function (a, b) {
  4423. return a.time - b.time;
  4424. });
  4425. }
  4426. var valType = this.valType;
  4427. var kfsLen = kfs.length;
  4428. var lastKf = kfs[kfsLen - 1];
  4429. var isDiscrete = this.discrete;
  4430. var isArr = isArrayValueType(valType);
  4431. var isGradient = isGradientValueType(valType);
  4432. for (var i = 0; i < kfsLen; i++) {
  4433. var kf = kfs[i];
  4434. var value = kf.value;
  4435. var lastValue = lastKf.value;
  4436. kf.percent = kf.time / maxTime;
  4437. if (!isDiscrete) {
  4438. if (isArr && i !== kfsLen - 1) {
  4439. fillArray(value, lastValue, valType);
  4440. }
  4441. else if (isGradient) {
  4442. fillColorStops(value.colorStops, lastValue.colorStops);
  4443. }
  4444. }
  4445. }
  4446. if (!isDiscrete
  4447. && valType !== VALUE_TYPE_RADIAL_GRADIENT
  4448. && additiveTrack
  4449. && this.needsAnimate()
  4450. && additiveTrack.needsAnimate()
  4451. && valType === additiveTrack.valType
  4452. && !additiveTrack._finished) {
  4453. this._additiveTrack = additiveTrack;
  4454. var startValue = kfs[0].value;
  4455. for (var i = 0; i < kfsLen; i++) {
  4456. if (valType === VALUE_TYPE_NUMBER) {
  4457. kfs[i].additiveValue = kfs[i].value - startValue;
  4458. }
  4459. else if (valType === VALUE_TYPE_COLOR) {
  4460. kfs[i].additiveValue =
  4461. add1DArray([], kfs[i].value, startValue, -1);
  4462. }
  4463. else if (isArrayValueType(valType)) {
  4464. kfs[i].additiveValue = valType === VALUE_TYPE_1D_ARRAY
  4465. ? add1DArray([], kfs[i].value, startValue, -1)
  4466. : add2DArray([], kfs[i].value, startValue, -1);
  4467. }
  4468. }
  4469. }
  4470. };
  4471. Track.prototype.step = function (target, percent) {
  4472. if (this._finished) {
  4473. return;
  4474. }
  4475. if (this._additiveTrack && this._additiveTrack._finished) {
  4476. this._additiveTrack = null;
  4477. }
  4478. var isAdditive = this._additiveTrack != null;
  4479. var valueKey = isAdditive ? 'additiveValue' : 'value';
  4480. var valType = this.valType;
  4481. var keyframes = this.keyframes;
  4482. var kfsNum = keyframes.length;
  4483. var propName = this.propName;
  4484. var isValueColor = valType === VALUE_TYPE_COLOR;
  4485. var frameIdx;
  4486. var lastFrame = this._lastFr;
  4487. var mathMin = Math.min;
  4488. var frame;
  4489. var nextFrame;
  4490. if (kfsNum === 1) {
  4491. frame = nextFrame = keyframes[0];
  4492. }
  4493. else {
  4494. if (percent < 0) {
  4495. frameIdx = 0;
  4496. }
  4497. else if (percent < this._lastFrP) {
  4498. var start = mathMin(lastFrame + 1, kfsNum - 1);
  4499. for (frameIdx = start; frameIdx >= 0; frameIdx--) {
  4500. if (keyframes[frameIdx].percent <= percent) {
  4501. break;
  4502. }
  4503. }
  4504. frameIdx = mathMin(frameIdx, kfsNum - 2);
  4505. }
  4506. else {
  4507. for (frameIdx = lastFrame; frameIdx < kfsNum; frameIdx++) {
  4508. if (keyframes[frameIdx].percent > percent) {
  4509. break;
  4510. }
  4511. }
  4512. frameIdx = mathMin(frameIdx - 1, kfsNum - 2);
  4513. }
  4514. nextFrame = keyframes[frameIdx + 1];
  4515. frame = keyframes[frameIdx];
  4516. }
  4517. if (!(frame && nextFrame)) {
  4518. return;
  4519. }
  4520. this._lastFr = frameIdx;
  4521. this._lastFrP = percent;
  4522. var interval = (nextFrame.percent - frame.percent);
  4523. var w = interval === 0 ? 1 : mathMin((percent - frame.percent) / interval, 1);
  4524. if (nextFrame.easingFunc) {
  4525. w = nextFrame.easingFunc(w);
  4526. }
  4527. var targetArr = isAdditive ? this._additiveValue
  4528. : (isValueColor ? tmpRgba : target[propName]);
  4529. if ((isArrayValueType(valType) || isValueColor) && !targetArr) {
  4530. targetArr = this._additiveValue = [];
  4531. }
  4532. if (this.discrete) {
  4533. target[propName] = w < 1 ? frame.rawValue : nextFrame.rawValue;
  4534. }
  4535. else if (isArrayValueType(valType)) {
  4536. valType === VALUE_TYPE_1D_ARRAY
  4537. ? interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w)
  4538. : interpolate2DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4539. }
  4540. else if (isGradientValueType(valType)) {
  4541. var val = frame[valueKey];
  4542. var nextVal_1 = nextFrame[valueKey];
  4543. var isLinearGradient_1 = valType === VALUE_TYPE_LINEAR_GRADIENT;
  4544. target[propName] = {
  4545. type: isLinearGradient_1 ? 'linear' : 'radial',
  4546. x: interpolateNumber(val.x, nextVal_1.x, w),
  4547. y: interpolateNumber(val.y, nextVal_1.y, w),
  4548. colorStops: map(val.colorStops, function (colorStop, idx) {
  4549. var nextColorStop = nextVal_1.colorStops[idx];
  4550. return {
  4551. offset: interpolateNumber(colorStop.offset, nextColorStop.offset, w),
  4552. color: rgba2String(interpolate1DArray([], colorStop.color, nextColorStop.color, w))
  4553. };
  4554. }),
  4555. global: nextVal_1.global
  4556. };
  4557. if (isLinearGradient_1) {
  4558. target[propName].x2 = interpolateNumber(val.x2, nextVal_1.x2, w);
  4559. target[propName].y2 = interpolateNumber(val.y2, nextVal_1.y2, w);
  4560. }
  4561. else {
  4562. target[propName].r = interpolateNumber(val.r, nextVal_1.r, w);
  4563. }
  4564. }
  4565. else if (isValueColor) {
  4566. interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4567. if (!isAdditive) {
  4568. target[propName] = rgba2String(targetArr);
  4569. }
  4570. }
  4571. else {
  4572. var value = interpolateNumber(frame[valueKey], nextFrame[valueKey], w);
  4573. if (isAdditive) {
  4574. this._additiveValue = value;
  4575. }
  4576. else {
  4577. target[propName] = value;
  4578. }
  4579. }
  4580. if (isAdditive) {
  4581. this._addToTarget(target);
  4582. }
  4583. };
  4584. Track.prototype._addToTarget = function (target) {
  4585. var valType = this.valType;
  4586. var propName = this.propName;
  4587. var additiveValue = this._additiveValue;
  4588. if (valType === VALUE_TYPE_NUMBER) {
  4589. target[propName] = target[propName] + additiveValue;
  4590. }
  4591. else if (valType === VALUE_TYPE_COLOR) {
  4592. parse(target[propName], tmpRgba);
  4593. add1DArray(tmpRgba, tmpRgba, additiveValue, 1);
  4594. target[propName] = rgba2String(tmpRgba);
  4595. }
  4596. else if (valType === VALUE_TYPE_1D_ARRAY) {
  4597. add1DArray(target[propName], target[propName], additiveValue, 1);
  4598. }
  4599. else if (valType === VALUE_TYPE_2D_ARRAY) {
  4600. add2DArray(target[propName], target[propName], additiveValue, 1);
  4601. }
  4602. };
  4603. return Track;
  4604. }());
  4605. var Animator = (function () {
  4606. function Animator(target, loop, allowDiscreteAnimation, additiveTo) {
  4607. this._tracks = {};
  4608. this._trackKeys = [];
  4609. this._maxTime = 0;
  4610. this._started = 0;
  4611. this._clip = null;
  4612. this._target = target;
  4613. this._loop = loop;
  4614. if (loop && additiveTo) {
  4615. logError('Can\' use additive animation on looped animation.');
  4616. return;
  4617. }
  4618. this._additiveAnimators = additiveTo;
  4619. this._allowDiscrete = allowDiscreteAnimation;
  4620. }
  4621. Animator.prototype.getMaxTime = function () {
  4622. return this._maxTime;
  4623. };
  4624. Animator.prototype.getDelay = function () {
  4625. return this._delay;
  4626. };
  4627. Animator.prototype.getLoop = function () {
  4628. return this._loop;
  4629. };
  4630. Animator.prototype.getTarget = function () {
  4631. return this._target;
  4632. };
  4633. Animator.prototype.changeTarget = function (target) {
  4634. this._target = target;
  4635. };
  4636. Animator.prototype.when = function (time, props, easing) {
  4637. return this.whenWithKeys(time, props, keys(props), easing);
  4638. };
  4639. Animator.prototype.whenWithKeys = function (time, props, propNames, easing) {
  4640. var tracks = this._tracks;
  4641. for (var i = 0; i < propNames.length; i++) {
  4642. var propName = propNames[i];
  4643. var track = tracks[propName];
  4644. if (!track) {
  4645. track = tracks[propName] = new Track(propName);
  4646. var initialValue = void 0;
  4647. var additiveTrack = this._getAdditiveTrack(propName);
  4648. if (additiveTrack) {
  4649. var addtiveTrackKfs = additiveTrack.keyframes;
  4650. var lastFinalKf = addtiveTrackKfs[addtiveTrackKfs.length - 1];
  4651. initialValue = lastFinalKf && lastFinalKf.value;
  4652. if (additiveTrack.valType === VALUE_TYPE_COLOR && initialValue) {
  4653. initialValue = rgba2String(initialValue);
  4654. }
  4655. }
  4656. else {
  4657. initialValue = this._target[propName];
  4658. }
  4659. if (initialValue == null) {
  4660. continue;
  4661. }
  4662. if (time > 0) {
  4663. track.addKeyframe(0, cloneValue(initialValue), easing);
  4664. }
  4665. this._trackKeys.push(propName);
  4666. }
  4667. track.addKeyframe(time, cloneValue(props[propName]), easing);
  4668. }
  4669. this._maxTime = Math.max(this._maxTime, time);
  4670. return this;
  4671. };
  4672. Animator.prototype.pause = function () {
  4673. this._clip.pause();
  4674. this._paused = true;
  4675. };
  4676. Animator.prototype.resume = function () {
  4677. this._clip.resume();
  4678. this._paused = false;
  4679. };
  4680. Animator.prototype.isPaused = function () {
  4681. return !!this._paused;
  4682. };
  4683. Animator.prototype.duration = function (duration) {
  4684. this._maxTime = duration;
  4685. this._force = true;
  4686. return this;
  4687. };
  4688. Animator.prototype._doneCallback = function () {
  4689. this._setTracksFinished();
  4690. this._clip = null;
  4691. var doneList = this._doneCbs;
  4692. if (doneList) {
  4693. var len = doneList.length;
  4694. for (var i = 0; i < len; i++) {
  4695. doneList[i].call(this);
  4696. }
  4697. }
  4698. };
  4699. Animator.prototype._abortedCallback = function () {
  4700. this._setTracksFinished();
  4701. var animation = this.animation;
  4702. var abortedList = this._abortedCbs;
  4703. if (animation) {
  4704. animation.removeClip(this._clip);
  4705. }
  4706. this._clip = null;
  4707. if (abortedList) {
  4708. for (var i = 0; i < abortedList.length; i++) {
  4709. abortedList[i].call(this);
  4710. }
  4711. }
  4712. };
  4713. Animator.prototype._setTracksFinished = function () {
  4714. var tracks = this._tracks;
  4715. var tracksKeys = this._trackKeys;
  4716. for (var i = 0; i < tracksKeys.length; i++) {
  4717. tracks[tracksKeys[i]].setFinished();
  4718. }
  4719. };
  4720. Animator.prototype._getAdditiveTrack = function (trackName) {
  4721. var additiveTrack;
  4722. var additiveAnimators = this._additiveAnimators;
  4723. if (additiveAnimators) {
  4724. for (var i = 0; i < additiveAnimators.length; i++) {
  4725. var track = additiveAnimators[i].getTrack(trackName);
  4726. if (track) {
  4727. additiveTrack = track;
  4728. }
  4729. }
  4730. }
  4731. return additiveTrack;
  4732. };
  4733. Animator.prototype.start = function (easing) {
  4734. if (this._started > 0) {
  4735. return;
  4736. }
  4737. this._started = 1;
  4738. var self = this;
  4739. var tracks = [];
  4740. var maxTime = this._maxTime || 0;
  4741. for (var i = 0; i < this._trackKeys.length; i++) {
  4742. var propName = this._trackKeys[i];
  4743. var track = this._tracks[propName];
  4744. var additiveTrack = this._getAdditiveTrack(propName);
  4745. var kfs = track.keyframes;
  4746. var kfsNum = kfs.length;
  4747. track.prepare(maxTime, additiveTrack);
  4748. if (track.needsAnimate()) {
  4749. if (!this._allowDiscrete && track.discrete) {
  4750. var lastKf = kfs[kfsNum - 1];
  4751. if (lastKf) {
  4752. self._target[track.propName] = lastKf.rawValue;
  4753. }
  4754. track.setFinished();
  4755. }
  4756. else {
  4757. tracks.push(track);
  4758. }
  4759. }
  4760. }
  4761. if (tracks.length || this._force) {
  4762. var clip = new Clip({
  4763. life: maxTime,
  4764. loop: this._loop,
  4765. delay: this._delay || 0,
  4766. onframe: function (percent) {
  4767. self._started = 2;
  4768. var additiveAnimators = self._additiveAnimators;
  4769. if (additiveAnimators) {
  4770. var stillHasAdditiveAnimator = false;
  4771. for (var i = 0; i < additiveAnimators.length; i++) {
  4772. if (additiveAnimators[i]._clip) {
  4773. stillHasAdditiveAnimator = true;
  4774. break;
  4775. }
  4776. }
  4777. if (!stillHasAdditiveAnimator) {
  4778. self._additiveAnimators = null;
  4779. }
  4780. }
  4781. for (var i = 0; i < tracks.length; i++) {
  4782. tracks[i].step(self._target, percent);
  4783. }
  4784. var onframeList = self._onframeCbs;
  4785. if (onframeList) {
  4786. for (var i = 0; i < onframeList.length; i++) {
  4787. onframeList[i](self._target, percent);
  4788. }
  4789. }
  4790. },
  4791. ondestroy: function () {
  4792. self._doneCallback();
  4793. }
  4794. });
  4795. this._clip = clip;
  4796. if (this.animation) {
  4797. this.animation.addClip(clip);
  4798. }
  4799. if (easing) {
  4800. clip.setEasing(easing);
  4801. }
  4802. }
  4803. else {
  4804. this._doneCallback();
  4805. }
  4806. return this;
  4807. };
  4808. Animator.prototype.stop = function (forwardToLast) {
  4809. if (!this._clip) {
  4810. return;
  4811. }
  4812. var clip = this._clip;
  4813. if (forwardToLast) {
  4814. clip.onframe(1);
  4815. }
  4816. this._abortedCallback();
  4817. };
  4818. Animator.prototype.delay = function (time) {
  4819. this._delay = time;
  4820. return this;
  4821. };
  4822. Animator.prototype.during = function (cb) {
  4823. if (cb) {
  4824. if (!this._onframeCbs) {
  4825. this._onframeCbs = [];
  4826. }
  4827. this._onframeCbs.push(cb);
  4828. }
  4829. return this;
  4830. };
  4831. Animator.prototype.done = function (cb) {
  4832. if (cb) {
  4833. if (!this._doneCbs) {
  4834. this._doneCbs = [];
  4835. }
  4836. this._doneCbs.push(cb);
  4837. }
  4838. return this;
  4839. };
  4840. Animator.prototype.aborted = function (cb) {
  4841. if (cb) {
  4842. if (!this._abortedCbs) {
  4843. this._abortedCbs = [];
  4844. }
  4845. this._abortedCbs.push(cb);
  4846. }
  4847. return this;
  4848. };
  4849. Animator.prototype.getClip = function () {
  4850. return this._clip;
  4851. };
  4852. Animator.prototype.getTrack = function (propName) {
  4853. return this._tracks[propName];
  4854. };
  4855. Animator.prototype.getTracks = function () {
  4856. var _this = this;
  4857. return map(this._trackKeys, function (key) { return _this._tracks[key]; });
  4858. };
  4859. Animator.prototype.stopTracks = function (propNames, forwardToLast) {
  4860. if (!propNames.length || !this._clip) {
  4861. return true;
  4862. }
  4863. var tracks = this._tracks;
  4864. var tracksKeys = this._trackKeys;
  4865. for (var i = 0; i < propNames.length; i++) {
  4866. var track = tracks[propNames[i]];
  4867. if (track && !track.isFinished()) {
  4868. if (forwardToLast) {
  4869. track.step(this._target, 1);
  4870. }
  4871. else if (this._started === 1) {
  4872. track.step(this._target, 0);
  4873. }
  4874. track.setFinished();
  4875. }
  4876. }
  4877. var allAborted = true;
  4878. for (var i = 0; i < tracksKeys.length; i++) {
  4879. if (!tracks[tracksKeys[i]].isFinished()) {
  4880. allAborted = false;
  4881. break;
  4882. }
  4883. }
  4884. if (allAborted) {
  4885. this._abortedCallback();
  4886. }
  4887. return allAborted;
  4888. };
  4889. Animator.prototype.saveTo = function (target, trackKeys, firstOrLast) {
  4890. if (!target) {
  4891. return;
  4892. }
  4893. trackKeys = trackKeys || this._trackKeys;
  4894. for (var i = 0; i < trackKeys.length; i++) {
  4895. var propName = trackKeys[i];
  4896. var track = this._tracks[propName];
  4897. if (!track || track.isFinished()) {
  4898. continue;
  4899. }
  4900. var kfs = track.keyframes;
  4901. var kf = kfs[firstOrLast ? 0 : kfs.length - 1];
  4902. if (kf) {
  4903. target[propName] = cloneValue(kf.rawValue);
  4904. }
  4905. }
  4906. };
  4907. Animator.prototype.__changeFinalValue = function (finalProps, trackKeys) {
  4908. trackKeys = trackKeys || keys(finalProps);
  4909. for (var i = 0; i < trackKeys.length; i++) {
  4910. var propName = trackKeys[i];
  4911. var track = this._tracks[propName];
  4912. if (!track) {
  4913. continue;
  4914. }
  4915. var kfs = track.keyframes;
  4916. if (kfs.length > 1) {
  4917. var lastKf = kfs.pop();
  4918. track.addKeyframe(lastKf.time, finalProps[propName]);
  4919. track.prepare(this._maxTime, track.getAdditiveTrack());
  4920. }
  4921. }
  4922. };
  4923. return Animator;
  4924. }());
  4925. function getTime() {
  4926. return new Date().getTime();
  4927. }
  4928. var Animation = (function (_super) {
  4929. __extends(Animation, _super);
  4930. function Animation(opts) {
  4931. var _this = _super.call(this) || this;
  4932. _this._running = false;
  4933. _this._time = 0;
  4934. _this._pausedTime = 0;
  4935. _this._pauseStart = 0;
  4936. _this._paused = false;
  4937. opts = opts || {};
  4938. _this.stage = opts.stage || {};
  4939. return _this;
  4940. }
  4941. Animation.prototype.addClip = function (clip) {
  4942. if (clip.animation) {
  4943. this.removeClip(clip);
  4944. }
  4945. if (!this._head) {
  4946. this._head = this._tail = clip;
  4947. }
  4948. else {
  4949. this._tail.next = clip;
  4950. clip.prev = this._tail;
  4951. clip.next = null;
  4952. this._tail = clip;
  4953. }
  4954. clip.animation = this;
  4955. };
  4956. Animation.prototype.addAnimator = function (animator) {
  4957. animator.animation = this;
  4958. var clip = animator.getClip();
  4959. if (clip) {
  4960. this.addClip(clip);
  4961. }
  4962. };
  4963. Animation.prototype.removeClip = function (clip) {
  4964. if (!clip.animation) {
  4965. return;
  4966. }
  4967. var prev = clip.prev;
  4968. var next = clip.next;
  4969. if (prev) {
  4970. prev.next = next;
  4971. }
  4972. else {
  4973. this._head = next;
  4974. }
  4975. if (next) {
  4976. next.prev = prev;
  4977. }
  4978. else {
  4979. this._tail = prev;
  4980. }
  4981. clip.next = clip.prev = clip.animation = null;
  4982. };
  4983. Animation.prototype.removeAnimator = function (animator) {
  4984. var clip = animator.getClip();
  4985. if (clip) {
  4986. this.removeClip(clip);
  4987. }
  4988. animator.animation = null;
  4989. };
  4990. Animation.prototype.update = function (notTriggerFrameAndStageUpdate) {
  4991. var time = getTime() - this._pausedTime;
  4992. var delta = time - this._time;
  4993. var clip = this._head;
  4994. while (clip) {
  4995. var nextClip = clip.next;
  4996. var finished = clip.step(time, delta);
  4997. if (finished) {
  4998. clip.ondestroy();
  4999. this.removeClip(clip);
  5000. clip = nextClip;
  5001. }
  5002. else {
  5003. clip = nextClip;
  5004. }
  5005. }
  5006. this._time = time;
  5007. if (!notTriggerFrameAndStageUpdate) {
  5008. this.trigger('frame', delta);
  5009. this.stage.update && this.stage.update();
  5010. }
  5011. };
  5012. Animation.prototype._startLoop = function () {
  5013. var self = this;
  5014. this._running = true;
  5015. function step() {
  5016. if (self._running) {
  5017. requestAnimationFrame$1(step);
  5018. !self._paused && self.update();
  5019. }
  5020. }
  5021. requestAnimationFrame$1(step);
  5022. };
  5023. Animation.prototype.start = function () {
  5024. if (this._running) {
  5025. return;
  5026. }
  5027. this._time = getTime();
  5028. this._pausedTime = 0;
  5029. this._startLoop();
  5030. };
  5031. Animation.prototype.stop = function () {
  5032. this._running = false;
  5033. };
  5034. Animation.prototype.pause = function () {
  5035. if (!this._paused) {
  5036. this._pauseStart = getTime();
  5037. this._paused = true;
  5038. }
  5039. };
  5040. Animation.prototype.resume = function () {
  5041. if (this._paused) {
  5042. this._pausedTime += getTime() - this._pauseStart;
  5043. this._paused = false;
  5044. }
  5045. };
  5046. Animation.prototype.clear = function () {
  5047. var clip = this._head;
  5048. while (clip) {
  5049. var nextClip = clip.next;
  5050. clip.prev = clip.next = clip.animation = null;
  5051. clip = nextClip;
  5052. }
  5053. this._head = this._tail = null;
  5054. };
  5055. Animation.prototype.isFinished = function () {
  5056. return this._head == null;
  5057. };
  5058. Animation.prototype.animate = function (target, options) {
  5059. options = options || {};
  5060. this.start();
  5061. var animator = new Animator(target, options.loop);
  5062. this.addAnimator(animator);
  5063. return animator;
  5064. };
  5065. return Animation;
  5066. }(Eventful));
  5067. var TOUCH_CLICK_DELAY = 300;
  5068. var globalEventSupported = env.domSupported;
  5069. var localNativeListenerNames = (function () {
  5070. var mouseHandlerNames = [
  5071. 'click', 'dblclick', 'mousewheel', 'wheel', 'mouseout',
  5072. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  5073. ];
  5074. var touchHandlerNames = [
  5075. 'touchstart', 'touchend', 'touchmove'
  5076. ];
  5077. var pointerEventNameMap = {
  5078. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  5079. };
  5080. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  5081. var nm = name.replace('mouse', 'pointer');
  5082. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  5083. });
  5084. return {
  5085. mouse: mouseHandlerNames,
  5086. touch: touchHandlerNames,
  5087. pointer: pointerHandlerNames
  5088. };
  5089. })();
  5090. var globalNativeListenerNames = {
  5091. mouse: ['mousemove', 'mouseup'],
  5092. pointer: ['pointermove', 'pointerup']
  5093. };
  5094. var wheelEventSupported = false;
  5095. function isPointerFromTouch(event) {
  5096. var pointerType = event.pointerType;
  5097. return pointerType === 'pen' || pointerType === 'touch';
  5098. }
  5099. function setTouchTimer(scope) {
  5100. scope.touching = true;
  5101. if (scope.touchTimer != null) {
  5102. clearTimeout(scope.touchTimer);
  5103. scope.touchTimer = null;
  5104. }
  5105. scope.touchTimer = setTimeout(function () {
  5106. scope.touching = false;
  5107. scope.touchTimer = null;
  5108. }, 700);
  5109. }
  5110. function markTouch(event) {
  5111. event && (event.zrByTouch = true);
  5112. }
  5113. function normalizeGlobalEvent(instance, event) {
  5114. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  5115. }
  5116. function isLocalEl(instance, el) {
  5117. var elTmp = el;
  5118. var isLocal = false;
  5119. while (elTmp && elTmp.nodeType !== 9
  5120. && !(isLocal = elTmp.domBelongToZr
  5121. || (elTmp !== el && elTmp === instance.painterRoot))) {
  5122. elTmp = elTmp.parentNode;
  5123. }
  5124. return isLocal;
  5125. }
  5126. var FakeGlobalEvent = (function () {
  5127. function FakeGlobalEvent(instance, event) {
  5128. this.stopPropagation = noop;
  5129. this.stopImmediatePropagation = noop;
  5130. this.preventDefault = noop;
  5131. this.type = event.type;
  5132. this.target = this.currentTarget = instance.dom;
  5133. this.pointerType = event.pointerType;
  5134. this.clientX = event.clientX;
  5135. this.clientY = event.clientY;
  5136. }
  5137. return FakeGlobalEvent;
  5138. }());
  5139. var localDOMHandlers = {
  5140. mousedown: function (event) {
  5141. event = normalizeEvent(this.dom, event);
  5142. this.__mayPointerCapture = [event.zrX, event.zrY];
  5143. this.trigger('mousedown', event);
  5144. },
  5145. mousemove: function (event) {
  5146. event = normalizeEvent(this.dom, event);
  5147. var downPoint = this.__mayPointerCapture;
  5148. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  5149. this.__togglePointerCapture(true);
  5150. }
  5151. this.trigger('mousemove', event);
  5152. },
  5153. mouseup: function (event) {
  5154. event = normalizeEvent(this.dom, event);
  5155. this.__togglePointerCapture(false);
  5156. this.trigger('mouseup', event);
  5157. },
  5158. mouseout: function (event) {
  5159. event = normalizeEvent(this.dom, event);
  5160. var element = event.toElement || event.relatedTarget;
  5161. if (!isLocalEl(this, element)) {
  5162. if (this.__pointerCapturing) {
  5163. event.zrEventControl = 'no_globalout';
  5164. }
  5165. this.trigger('mouseout', event);
  5166. }
  5167. },
  5168. wheel: function (event) {
  5169. wheelEventSupported = true;
  5170. event = normalizeEvent(this.dom, event);
  5171. this.trigger('mousewheel', event);
  5172. },
  5173. mousewheel: function (event) {
  5174. if (wheelEventSupported) {
  5175. return;
  5176. }
  5177. event = normalizeEvent(this.dom, event);
  5178. this.trigger('mousewheel', event);
  5179. },
  5180. touchstart: function (event) {
  5181. event = normalizeEvent(this.dom, event);
  5182. markTouch(event);
  5183. this.__lastTouchMoment = new Date();
  5184. this.handler.processGesture(event, 'start');
  5185. localDOMHandlers.mousemove.call(this, event);
  5186. localDOMHandlers.mousedown.call(this, event);
  5187. },
  5188. touchmove: function (event) {
  5189. event = normalizeEvent(this.dom, event);
  5190. markTouch(event);
  5191. this.handler.processGesture(event, 'change');
  5192. localDOMHandlers.mousemove.call(this, event);
  5193. },
  5194. touchend: function (event) {
  5195. event = normalizeEvent(this.dom, event);
  5196. markTouch(event);
  5197. this.handler.processGesture(event, 'end');
  5198. localDOMHandlers.mouseup.call(this, event);
  5199. if (+new Date() - (+this.__lastTouchMoment) < TOUCH_CLICK_DELAY) {
  5200. localDOMHandlers.click.call(this, event);
  5201. }
  5202. },
  5203. pointerdown: function (event) {
  5204. localDOMHandlers.mousedown.call(this, event);
  5205. },
  5206. pointermove: function (event) {
  5207. if (!isPointerFromTouch(event)) {
  5208. localDOMHandlers.mousemove.call(this, event);
  5209. }
  5210. },
  5211. pointerup: function (event) {
  5212. localDOMHandlers.mouseup.call(this, event);
  5213. },
  5214. pointerout: function (event) {
  5215. if (!isPointerFromTouch(event)) {
  5216. localDOMHandlers.mouseout.call(this, event);
  5217. }
  5218. }
  5219. };
  5220. each(['click', 'dblclick', 'contextmenu'], function (name) {
  5221. localDOMHandlers[name] = function (event) {
  5222. event = normalizeEvent(this.dom, event);
  5223. this.trigger(name, event);
  5224. };
  5225. });
  5226. var globalDOMHandlers = {
  5227. pointermove: function (event) {
  5228. if (!isPointerFromTouch(event)) {
  5229. globalDOMHandlers.mousemove.call(this, event);
  5230. }
  5231. },
  5232. pointerup: function (event) {
  5233. globalDOMHandlers.mouseup.call(this, event);
  5234. },
  5235. mousemove: function (event) {
  5236. this.trigger('mousemove', event);
  5237. },
  5238. mouseup: function (event) {
  5239. var pointerCaptureReleasing = this.__pointerCapturing;
  5240. this.__togglePointerCapture(false);
  5241. this.trigger('mouseup', event);
  5242. if (pointerCaptureReleasing) {
  5243. event.zrEventControl = 'only_globalout';
  5244. this.trigger('mouseout', event);
  5245. }
  5246. }
  5247. };
  5248. function mountLocalDOMEventListeners(instance, scope) {
  5249. var domHandlers = scope.domHandlers;
  5250. if (env.pointerEventsSupported) {
  5251. each(localNativeListenerNames.pointer, function (nativeEventName) {
  5252. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5253. domHandlers[nativeEventName].call(instance, event);
  5254. });
  5255. });
  5256. }
  5257. else {
  5258. if (env.touchEventsSupported) {
  5259. each(localNativeListenerNames.touch, function (nativeEventName) {
  5260. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5261. domHandlers[nativeEventName].call(instance, event);
  5262. setTouchTimer(scope);
  5263. });
  5264. });
  5265. }
  5266. each(localNativeListenerNames.mouse, function (nativeEventName) {
  5267. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5268. event = getNativeEvent(event);
  5269. if (!scope.touching) {
  5270. domHandlers[nativeEventName].call(instance, event);
  5271. }
  5272. });
  5273. });
  5274. }
  5275. }
  5276. function mountGlobalDOMEventListeners(instance, scope) {
  5277. if (env.pointerEventsSupported) {
  5278. each(globalNativeListenerNames.pointer, mount);
  5279. }
  5280. else if (!env.touchEventsSupported) {
  5281. each(globalNativeListenerNames.mouse, mount);
  5282. }
  5283. function mount(nativeEventName) {
  5284. function nativeEventListener(event) {
  5285. event = getNativeEvent(event);
  5286. if (!isLocalEl(instance, event.target)) {
  5287. event = normalizeGlobalEvent(instance, event);
  5288. scope.domHandlers[nativeEventName].call(instance, event);
  5289. }
  5290. }
  5291. mountSingleDOMEventListener(scope, nativeEventName, nativeEventListener, { capture: true });
  5292. }
  5293. }
  5294. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  5295. scope.mounted[nativeEventName] = listener;
  5296. scope.listenerOpts[nativeEventName] = opt;
  5297. addEventListener(scope.domTarget, nativeEventName, listener, opt);
  5298. }
  5299. function unmountDOMEventListeners(scope) {
  5300. var mounted = scope.mounted;
  5301. for (var nativeEventName in mounted) {
  5302. if (mounted.hasOwnProperty(nativeEventName)) {
  5303. removeEventListener(scope.domTarget, nativeEventName, mounted[nativeEventName], scope.listenerOpts[nativeEventName]);
  5304. }
  5305. }
  5306. scope.mounted = {};
  5307. }
  5308. var DOMHandlerScope = (function () {
  5309. function DOMHandlerScope(domTarget, domHandlers) {
  5310. this.mounted = {};
  5311. this.listenerOpts = {};
  5312. this.touching = false;
  5313. this.domTarget = domTarget;
  5314. this.domHandlers = domHandlers;
  5315. }
  5316. return DOMHandlerScope;
  5317. }());
  5318. var HandlerDomProxy = (function (_super) {
  5319. __extends(HandlerDomProxy, _super);
  5320. function HandlerDomProxy(dom, painterRoot) {
  5321. var _this = _super.call(this) || this;
  5322. _this.__pointerCapturing = false;
  5323. _this.dom = dom;
  5324. _this.painterRoot = painterRoot;
  5325. _this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  5326. if (globalEventSupported) {
  5327. _this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  5328. }
  5329. mountLocalDOMEventListeners(_this, _this._localHandlerScope);
  5330. return _this;
  5331. }
  5332. HandlerDomProxy.prototype.dispose = function () {
  5333. unmountDOMEventListeners(this._localHandlerScope);
  5334. if (globalEventSupported) {
  5335. unmountDOMEventListeners(this._globalHandlerScope);
  5336. }
  5337. };
  5338. HandlerDomProxy.prototype.setCursor = function (cursorStyle) {
  5339. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  5340. };
  5341. HandlerDomProxy.prototype.__togglePointerCapture = function (isPointerCapturing) {
  5342. this.__mayPointerCapture = null;
  5343. if (globalEventSupported
  5344. && ((+this.__pointerCapturing) ^ (+isPointerCapturing))) {
  5345. this.__pointerCapturing = isPointerCapturing;
  5346. var globalHandlerScope = this._globalHandlerScope;
  5347. isPointerCapturing
  5348. ? mountGlobalDOMEventListeners(this, globalHandlerScope)
  5349. : unmountDOMEventListeners(globalHandlerScope);
  5350. }
  5351. };
  5352. return HandlerDomProxy;
  5353. }(Eventful));
  5354. var dpr = 1;
  5355. if (env.hasGlobalWindow) {
  5356. dpr = Math.max(window.devicePixelRatio
  5357. || (window.screen && window.screen.deviceXDPI / window.screen.logicalXDPI)
  5358. || 1, 1);
  5359. }
  5360. var devicePixelRatio = dpr;
  5361. var DARK_MODE_THRESHOLD = 0.4;
  5362. var DARK_LABEL_COLOR = '#333';
  5363. var LIGHT_LABEL_COLOR = '#ccc';
  5364. var LIGHTER_LABEL_COLOR = '#eee';
  5365. var mIdentity = identity;
  5366. var EPSILON$2 = 5e-5;
  5367. function isNotAroundZero$1(val) {
  5368. return val > EPSILON$2 || val < -EPSILON$2;
  5369. }
  5370. var scaleTmp = [];
  5371. var tmpTransform = [];
  5372. var originTransform = create$1();
  5373. var abs = Math.abs;
  5374. var Transformable = (function () {
  5375. function Transformable() {
  5376. }
  5377. Transformable.prototype.getLocalTransform = function (m) {
  5378. return Transformable.getLocalTransform(this, m);
  5379. };
  5380. Transformable.prototype.setPosition = function (arr) {
  5381. this.x = arr[0];
  5382. this.y = arr[1];
  5383. };
  5384. Transformable.prototype.setScale = function (arr) {
  5385. this.scaleX = arr[0];
  5386. this.scaleY = arr[1];
  5387. };
  5388. Transformable.prototype.setSkew = function (arr) {
  5389. this.skewX = arr[0];
  5390. this.skewY = arr[1];
  5391. };
  5392. Transformable.prototype.setOrigin = function (arr) {
  5393. this.originX = arr[0];
  5394. this.originY = arr[1];
  5395. };
  5396. Transformable.prototype.needLocalTransform = function () {
  5397. return isNotAroundZero$1(this.rotation)
  5398. || isNotAroundZero$1(this.x)
  5399. || isNotAroundZero$1(this.y)
  5400. || isNotAroundZero$1(this.scaleX - 1)
  5401. || isNotAroundZero$1(this.scaleY - 1)
  5402. || isNotAroundZero$1(this.skewX)
  5403. || isNotAroundZero$1(this.skewY);
  5404. };
  5405. Transformable.prototype.updateTransform = function () {
  5406. var parentTransform = this.parent && this.parent.transform;
  5407. var needLocalTransform = this.needLocalTransform();
  5408. var m = this.transform;
  5409. if (!(needLocalTransform || parentTransform)) {
  5410. if (m) {
  5411. mIdentity(m);
  5412. this.invTransform = null;
  5413. }
  5414. return;
  5415. }
  5416. m = m || create$1();
  5417. if (needLocalTransform) {
  5418. this.getLocalTransform(m);
  5419. }
  5420. else {
  5421. mIdentity(m);
  5422. }
  5423. if (parentTransform) {
  5424. if (needLocalTransform) {
  5425. mul$1(m, parentTransform, m);
  5426. }
  5427. else {
  5428. copy$1(m, parentTransform);
  5429. }
  5430. }
  5431. this.transform = m;
  5432. this._resolveGlobalScaleRatio(m);
  5433. };
  5434. Transformable.prototype._resolveGlobalScaleRatio = function (m) {
  5435. var globalScaleRatio = this.globalScaleRatio;
  5436. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  5437. this.getGlobalScale(scaleTmp);
  5438. var relX = scaleTmp[0] < 0 ? -1 : 1;
  5439. var relY = scaleTmp[1] < 0 ? -1 : 1;
  5440. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  5441. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  5442. m[0] *= sx;
  5443. m[1] *= sx;
  5444. m[2] *= sy;
  5445. m[3] *= sy;
  5446. }
  5447. this.invTransform = this.invTransform || create$1();
  5448. invert(this.invTransform, m);
  5449. };
  5450. Transformable.prototype.getComputedTransform = function () {
  5451. var transformNode = this;
  5452. var ancestors = [];
  5453. while (transformNode) {
  5454. ancestors.push(transformNode);
  5455. transformNode = transformNode.parent;
  5456. }
  5457. while (transformNode = ancestors.pop()) {
  5458. transformNode.updateTransform();
  5459. }
  5460. return this.transform;
  5461. };
  5462. Transformable.prototype.setLocalTransform = function (m) {
  5463. if (!m) {
  5464. return;
  5465. }
  5466. var sx = m[0] * m[0] + m[1] * m[1];
  5467. var sy = m[2] * m[2] + m[3] * m[3];
  5468. var rotation = Math.atan2(m[1], m[0]);
  5469. var shearX = Math.PI / 2 + rotation - Math.atan2(m[3], m[2]);
  5470. sy = Math.sqrt(sy) * Math.cos(shearX);
  5471. sx = Math.sqrt(sx);
  5472. this.skewX = shearX;
  5473. this.skewY = 0;
  5474. this.rotation = -rotation;
  5475. this.x = +m[4];
  5476. this.y = +m[5];
  5477. this.scaleX = sx;
  5478. this.scaleY = sy;
  5479. this.originX = 0;
  5480. this.originY = 0;
  5481. };
  5482. Transformable.prototype.decomposeTransform = function () {
  5483. if (!this.transform) {
  5484. return;
  5485. }
  5486. var parent = this.parent;
  5487. var m = this.transform;
  5488. if (parent && parent.transform) {
  5489. parent.invTransform = parent.invTransform || create$1();
  5490. mul$1(tmpTransform, parent.invTransform, m);
  5491. m = tmpTransform;
  5492. }
  5493. var ox = this.originX;
  5494. var oy = this.originY;
  5495. if (ox || oy) {
  5496. originTransform[4] = ox;
  5497. originTransform[5] = oy;
  5498. mul$1(tmpTransform, m, originTransform);
  5499. tmpTransform[4] -= ox;
  5500. tmpTransform[5] -= oy;
  5501. m = tmpTransform;
  5502. }
  5503. this.setLocalTransform(m);
  5504. };
  5505. Transformable.prototype.getGlobalScale = function (out) {
  5506. var m = this.transform;
  5507. out = out || [];
  5508. if (!m) {
  5509. out[0] = 1;
  5510. out[1] = 1;
  5511. return out;
  5512. }
  5513. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  5514. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  5515. if (m[0] < 0) {
  5516. out[0] = -out[0];
  5517. }
  5518. if (m[3] < 0) {
  5519. out[1] = -out[1];
  5520. }
  5521. return out;
  5522. };
  5523. Transformable.prototype.transformCoordToLocal = function (x, y) {
  5524. var v2 = [x, y];
  5525. var invTransform = this.invTransform;
  5526. if (invTransform) {
  5527. applyTransform(v2, v2, invTransform);
  5528. }
  5529. return v2;
  5530. };
  5531. Transformable.prototype.transformCoordToGlobal = function (x, y) {
  5532. var v2 = [x, y];
  5533. var transform = this.transform;
  5534. if (transform) {
  5535. applyTransform(v2, v2, transform);
  5536. }
  5537. return v2;
  5538. };
  5539. Transformable.prototype.getLineScale = function () {
  5540. var m = this.transform;
  5541. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  5542. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  5543. : 1;
  5544. };
  5545. Transformable.prototype.copyTransform = function (source) {
  5546. copyTransform(this, source);
  5547. };
  5548. Transformable.getLocalTransform = function (target, m) {
  5549. m = m || [];
  5550. var ox = target.originX || 0;
  5551. var oy = target.originY || 0;
  5552. var sx = target.scaleX;
  5553. var sy = target.scaleY;
  5554. var ax = target.anchorX;
  5555. var ay = target.anchorY;
  5556. var rotation = target.rotation || 0;
  5557. var x = target.x;
  5558. var y = target.y;
  5559. var skewX = target.skewX ? Math.tan(target.skewX) : 0;
  5560. var skewY = target.skewY ? Math.tan(-target.skewY) : 0;
  5561. if (ox || oy || ax || ay) {
  5562. var dx = ox + ax;
  5563. var dy = oy + ay;
  5564. m[4] = -dx * sx - skewX * dy * sy;
  5565. m[5] = -dy * sy - skewY * dx * sx;
  5566. }
  5567. else {
  5568. m[4] = m[5] = 0;
  5569. }
  5570. m[0] = sx;
  5571. m[3] = sy;
  5572. m[1] = skewY * sx;
  5573. m[2] = skewX * sy;
  5574. rotation && rotate(m, m, rotation);
  5575. m[4] += ox + x;
  5576. m[5] += oy + y;
  5577. return m;
  5578. };
  5579. Transformable.initDefaultProps = (function () {
  5580. var proto = Transformable.prototype;
  5581. proto.scaleX =
  5582. proto.scaleY =
  5583. proto.globalScaleRatio = 1;
  5584. proto.x =
  5585. proto.y =
  5586. proto.originX =
  5587. proto.originY =
  5588. proto.skewX =
  5589. proto.skewY =
  5590. proto.rotation =
  5591. proto.anchorX =
  5592. proto.anchorY = 0;
  5593. })();
  5594. return Transformable;
  5595. }());
  5596. var TRANSFORMABLE_PROPS = [
  5597. 'x', 'y', 'originX', 'originY', 'anchorX', 'anchorY', 'rotation', 'scaleX', 'scaleY', 'skewX', 'skewY'
  5598. ];
  5599. function copyTransform(target, source) {
  5600. for (var i = 0; i < TRANSFORMABLE_PROPS.length; i++) {
  5601. var propName = TRANSFORMABLE_PROPS[i];
  5602. target[propName] = source[propName];
  5603. }
  5604. }
  5605. var textWidthCache = {};
  5606. function getWidth(text, font) {
  5607. font = font || DEFAULT_FONT;
  5608. var cacheOfFont = textWidthCache[font];
  5609. if (!cacheOfFont) {
  5610. cacheOfFont = textWidthCache[font] = new LRU(500);
  5611. }
  5612. var width = cacheOfFont.get(text);
  5613. if (width == null) {
  5614. width = platformApi.measureText(text, font).width;
  5615. cacheOfFont.put(text, width);
  5616. }
  5617. return width;
  5618. }
  5619. function innerGetBoundingRect(text, font, textAlign, textBaseline) {
  5620. var width = getWidth(text, font);
  5621. var height = getLineHeight(font);
  5622. var x = adjustTextX(0, width, textAlign);
  5623. var y = adjustTextY$1(0, height, textBaseline);
  5624. var rect = new BoundingRect(x, y, width, height);
  5625. return rect;
  5626. }
  5627. function getBoundingRect(text, font, textAlign, textBaseline) {
  5628. var textLines = ((text || '') + '').split('\n');
  5629. var len = textLines.length;
  5630. if (len === 1) {
  5631. return innerGetBoundingRect(textLines[0], font, textAlign, textBaseline);
  5632. }
  5633. else {
  5634. var uniondRect = new BoundingRect(0, 0, 0, 0);
  5635. for (var i = 0; i < textLines.length; i++) {
  5636. var rect = innerGetBoundingRect(textLines[i], font, textAlign, textBaseline);
  5637. i === 0 ? uniondRect.copy(rect) : uniondRect.union(rect);
  5638. }
  5639. return uniondRect;
  5640. }
  5641. }
  5642. function adjustTextX(x, width, textAlign) {
  5643. if (textAlign === 'right') {
  5644. x -= width;
  5645. }
  5646. else if (textAlign === 'center') {
  5647. x -= width / 2;
  5648. }
  5649. return x;
  5650. }
  5651. function adjustTextY$1(y, height, verticalAlign) {
  5652. if (verticalAlign === 'middle') {
  5653. y -= height / 2;
  5654. }
  5655. else if (verticalAlign === 'bottom') {
  5656. y -= height;
  5657. }
  5658. return y;
  5659. }
  5660. function getLineHeight(font) {
  5661. return getWidth('国', font);
  5662. }
  5663. function parsePercent(value, maxValue) {
  5664. if (typeof value === 'string') {
  5665. if (value.lastIndexOf('%') >= 0) {
  5666. return parseFloat(value) / 100 * maxValue;
  5667. }
  5668. return parseFloat(value);
  5669. }
  5670. return value;
  5671. }
  5672. function calculateTextPosition(out, opts, rect) {
  5673. var textPosition = opts.position || 'inside';
  5674. var distance = opts.distance != null ? opts.distance : 5;
  5675. var height = rect.height;
  5676. var width = rect.width;
  5677. var halfHeight = height / 2;
  5678. var x = rect.x;
  5679. var y = rect.y;
  5680. var textAlign = 'left';
  5681. var textVerticalAlign = 'top';
  5682. if (textPosition instanceof Array) {
  5683. x += parsePercent(textPosition[0], rect.width);
  5684. y += parsePercent(textPosition[1], rect.height);
  5685. textAlign = null;
  5686. textVerticalAlign = null;
  5687. }
  5688. else {
  5689. switch (textPosition) {
  5690. case 'left':
  5691. x -= distance;
  5692. y += halfHeight;
  5693. textAlign = 'right';
  5694. textVerticalAlign = 'middle';
  5695. break;
  5696. case 'right':
  5697. x += distance + width;
  5698. y += halfHeight;
  5699. textVerticalAlign = 'middle';
  5700. break;
  5701. case 'top':
  5702. x += width / 2;
  5703. y -= distance;
  5704. textAlign = 'center';
  5705. textVerticalAlign = 'bottom';
  5706. break;
  5707. case 'bottom':
  5708. x += width / 2;
  5709. y += height + distance;
  5710. textAlign = 'center';
  5711. break;
  5712. case 'inside':
  5713. x += width / 2;
  5714. y += halfHeight;
  5715. textAlign = 'center';
  5716. textVerticalAlign = 'middle';
  5717. break;
  5718. case 'insideLeft':
  5719. x += distance;
  5720. y += halfHeight;
  5721. textVerticalAlign = 'middle';
  5722. break;
  5723. case 'insideRight':
  5724. x += width - distance;
  5725. y += halfHeight;
  5726. textAlign = 'right';
  5727. textVerticalAlign = 'middle';
  5728. break;
  5729. case 'insideTop':
  5730. x += width / 2;
  5731. y += distance;
  5732. textAlign = 'center';
  5733. break;
  5734. case 'insideBottom':
  5735. x += width / 2;
  5736. y += height - distance;
  5737. textAlign = 'center';
  5738. textVerticalAlign = 'bottom';
  5739. break;
  5740. case 'insideTopLeft':
  5741. x += distance;
  5742. y += distance;
  5743. break;
  5744. case 'insideTopRight':
  5745. x += width - distance;
  5746. y += distance;
  5747. textAlign = 'right';
  5748. break;
  5749. case 'insideBottomLeft':
  5750. x += distance;
  5751. y += height - distance;
  5752. textVerticalAlign = 'bottom';
  5753. break;
  5754. case 'insideBottomRight':
  5755. x += width - distance;
  5756. y += height - distance;
  5757. textAlign = 'right';
  5758. textVerticalAlign = 'bottom';
  5759. break;
  5760. }
  5761. }
  5762. out = out || {};
  5763. out.x = x;
  5764. out.y = y;
  5765. out.align = textAlign;
  5766. out.verticalAlign = textVerticalAlign;
  5767. return out;
  5768. }
  5769. var PRESERVED_NORMAL_STATE = '__zr_normal__';
  5770. var PRIMARY_STATES_KEYS = TRANSFORMABLE_PROPS.concat(['ignore']);
  5771. var DEFAULT_ANIMATABLE_MAP = reduce(TRANSFORMABLE_PROPS, function (obj, key) {
  5772. obj[key] = true;
  5773. return obj;
  5774. }, { ignore: false });
  5775. var tmpTextPosCalcRes = {};
  5776. var tmpBoundingRect = new BoundingRect(0, 0, 0, 0);
  5777. var Element = (function () {
  5778. function Element(props) {
  5779. this.id = guid();
  5780. this.animators = [];
  5781. this.currentStates = [];
  5782. this.states = {};
  5783. this._init(props);
  5784. }
  5785. Element.prototype._init = function (props) {
  5786. this.attr(props);
  5787. };
  5788. Element.prototype.drift = function (dx, dy, e) {
  5789. switch (this.draggable) {
  5790. case 'horizontal':
  5791. dy = 0;
  5792. break;
  5793. case 'vertical':
  5794. dx = 0;
  5795. break;
  5796. }
  5797. var m = this.transform;
  5798. if (!m) {
  5799. m = this.transform = [1, 0, 0, 1, 0, 0];
  5800. }
  5801. m[4] += dx;
  5802. m[5] += dy;
  5803. this.decomposeTransform();
  5804. this.markRedraw();
  5805. };
  5806. Element.prototype.beforeUpdate = function () { };
  5807. Element.prototype.afterUpdate = function () { };
  5808. Element.prototype.update = function () {
  5809. this.updateTransform();
  5810. if (this.__dirty) {
  5811. this.updateInnerText();
  5812. }
  5813. };
  5814. Element.prototype.updateInnerText = function (forceUpdate) {
  5815. var textEl = this._textContent;
  5816. if (textEl && (!textEl.ignore || forceUpdate)) {
  5817. if (!this.textConfig) {
  5818. this.textConfig = {};
  5819. }
  5820. var textConfig = this.textConfig;
  5821. var isLocal = textConfig.local;
  5822. var innerTransformable = textEl.innerTransformable;
  5823. var textAlign = void 0;
  5824. var textVerticalAlign = void 0;
  5825. var textStyleChanged = false;
  5826. innerTransformable.parent = isLocal ? this : null;
  5827. var innerOrigin = false;
  5828. innerTransformable.copyTransform(textEl);
  5829. if (textConfig.position != null) {
  5830. var layoutRect = tmpBoundingRect;
  5831. if (textConfig.layoutRect) {
  5832. layoutRect.copy(textConfig.layoutRect);
  5833. }
  5834. else {
  5835. layoutRect.copy(this.getBoundingRect());
  5836. }
  5837. if (!isLocal) {
  5838. layoutRect.applyTransform(this.transform);
  5839. }
  5840. if (this.calculateTextPosition) {
  5841. this.calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5842. }
  5843. else {
  5844. calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5845. }
  5846. innerTransformable.x = tmpTextPosCalcRes.x;
  5847. innerTransformable.y = tmpTextPosCalcRes.y;
  5848. textAlign = tmpTextPosCalcRes.align;
  5849. textVerticalAlign = tmpTextPosCalcRes.verticalAlign;
  5850. var textOrigin = textConfig.origin;
  5851. if (textOrigin && textConfig.rotation != null) {
  5852. var relOriginX = void 0;
  5853. var relOriginY = void 0;
  5854. if (textOrigin === 'center') {
  5855. relOriginX = layoutRect.width * 0.5;
  5856. relOriginY = layoutRect.height * 0.5;
  5857. }
  5858. else {
  5859. relOriginX = parsePercent(textOrigin[0], layoutRect.width);
  5860. relOriginY = parsePercent(textOrigin[1], layoutRect.height);
  5861. }
  5862. innerOrigin = true;
  5863. innerTransformable.originX = -innerTransformable.x + relOriginX + (isLocal ? 0 : layoutRect.x);
  5864. innerTransformable.originY = -innerTransformable.y + relOriginY + (isLocal ? 0 : layoutRect.y);
  5865. }
  5866. }
  5867. if (textConfig.rotation != null) {
  5868. innerTransformable.rotation = textConfig.rotation;
  5869. }
  5870. var textOffset = textConfig.offset;
  5871. if (textOffset) {
  5872. innerTransformable.x += textOffset[0];
  5873. innerTransformable.y += textOffset[1];
  5874. if (!innerOrigin) {
  5875. innerTransformable.originX = -textOffset[0];
  5876. innerTransformable.originY = -textOffset[1];
  5877. }
  5878. }
  5879. var isInside = textConfig.inside == null
  5880. ? (typeof textConfig.position === 'string' && textConfig.position.indexOf('inside') >= 0)
  5881. : textConfig.inside;
  5882. var innerTextDefaultStyle = this._innerTextDefaultStyle || (this._innerTextDefaultStyle = {});
  5883. var textFill = void 0;
  5884. var textStroke = void 0;
  5885. var autoStroke = void 0;
  5886. if (isInside && this.canBeInsideText()) {
  5887. textFill = textConfig.insideFill;
  5888. textStroke = textConfig.insideStroke;
  5889. if (textFill == null || textFill === 'auto') {
  5890. textFill = this.getInsideTextFill();
  5891. }
  5892. if (textStroke == null || textStroke === 'auto') {
  5893. textStroke = this.getInsideTextStroke(textFill);
  5894. autoStroke = true;
  5895. }
  5896. }
  5897. else {
  5898. textFill = textConfig.outsideFill;
  5899. textStroke = textConfig.outsideStroke;
  5900. if (textFill == null || textFill === 'auto') {
  5901. textFill = this.getOutsideFill();
  5902. }
  5903. if (textStroke == null || textStroke === 'auto') {
  5904. textStroke = this.getOutsideStroke(textFill);
  5905. autoStroke = true;
  5906. }
  5907. }
  5908. textFill = textFill || '#000';
  5909. if (textFill !== innerTextDefaultStyle.fill
  5910. || textStroke !== innerTextDefaultStyle.stroke
  5911. || autoStroke !== innerTextDefaultStyle.autoStroke
  5912. || textAlign !== innerTextDefaultStyle.align
  5913. || textVerticalAlign !== innerTextDefaultStyle.verticalAlign) {
  5914. textStyleChanged = true;
  5915. innerTextDefaultStyle.fill = textFill;
  5916. innerTextDefaultStyle.stroke = textStroke;
  5917. innerTextDefaultStyle.autoStroke = autoStroke;
  5918. innerTextDefaultStyle.align = textAlign;
  5919. innerTextDefaultStyle.verticalAlign = textVerticalAlign;
  5920. textEl.setDefaultTextStyle(innerTextDefaultStyle);
  5921. }
  5922. textEl.__dirty |= REDRAW_BIT;
  5923. if (textStyleChanged) {
  5924. textEl.dirtyStyle(true);
  5925. }
  5926. }
  5927. };
  5928. Element.prototype.canBeInsideText = function () {
  5929. return true;
  5930. };
  5931. Element.prototype.getInsideTextFill = function () {
  5932. return '#fff';
  5933. };
  5934. Element.prototype.getInsideTextStroke = function (textFill) {
  5935. return '#000';
  5936. };
  5937. Element.prototype.getOutsideFill = function () {
  5938. return this.__zr && this.__zr.isDarkMode() ? LIGHT_LABEL_COLOR : DARK_LABEL_COLOR;
  5939. };
  5940. Element.prototype.getOutsideStroke = function (textFill) {
  5941. var backgroundColor = this.__zr && this.__zr.getBackgroundColor();
  5942. var colorArr = typeof backgroundColor === 'string' && parse(backgroundColor);
  5943. if (!colorArr) {
  5944. colorArr = [255, 255, 255, 1];
  5945. }
  5946. var alpha = colorArr[3];
  5947. var isDark = this.__zr.isDarkMode();
  5948. for (var i = 0; i < 3; i++) {
  5949. colorArr[i] = colorArr[i] * alpha + (isDark ? 0 : 255) * (1 - alpha);
  5950. }
  5951. colorArr[3] = 1;
  5952. return stringify(colorArr, 'rgba');
  5953. };
  5954. Element.prototype.traverse = function (cb, context) { };
  5955. Element.prototype.attrKV = function (key, value) {
  5956. if (key === 'textConfig') {
  5957. this.setTextConfig(value);
  5958. }
  5959. else if (key === 'textContent') {
  5960. this.setTextContent(value);
  5961. }
  5962. else if (key === 'clipPath') {
  5963. this.setClipPath(value);
  5964. }
  5965. else if (key === 'extra') {
  5966. this.extra = this.extra || {};
  5967. extend(this.extra, value);
  5968. }
  5969. else {
  5970. this[key] = value;
  5971. }
  5972. };
  5973. Element.prototype.hide = function () {
  5974. this.ignore = true;
  5975. this.markRedraw();
  5976. };
  5977. Element.prototype.show = function () {
  5978. this.ignore = false;
  5979. this.markRedraw();
  5980. };
  5981. Element.prototype.attr = function (keyOrObj, value) {
  5982. if (typeof keyOrObj === 'string') {
  5983. this.attrKV(keyOrObj, value);
  5984. }
  5985. else if (isObject(keyOrObj)) {
  5986. var obj = keyOrObj;
  5987. var keysArr = keys(obj);
  5988. for (var i = 0; i < keysArr.length; i++) {
  5989. var key = keysArr[i];
  5990. this.attrKV(key, keyOrObj[key]);
  5991. }
  5992. }
  5993. this.markRedraw();
  5994. return this;
  5995. };
  5996. Element.prototype.saveCurrentToNormalState = function (toState) {
  5997. this._innerSaveToNormal(toState);
  5998. var normalState = this._normalState;
  5999. for (var i = 0; i < this.animators.length; i++) {
  6000. var animator = this.animators[i];
  6001. var fromStateTransition = animator.__fromStateTransition;
  6002. if (animator.getLoop() || fromStateTransition && fromStateTransition !== PRESERVED_NORMAL_STATE) {
  6003. continue;
  6004. }
  6005. var targetName = animator.targetName;
  6006. var target = targetName
  6007. ? normalState[targetName] : normalState;
  6008. animator.saveTo(target);
  6009. }
  6010. };
  6011. Element.prototype._innerSaveToNormal = function (toState) {
  6012. var normalState = this._normalState;
  6013. if (!normalState) {
  6014. normalState = this._normalState = {};
  6015. }
  6016. if (toState.textConfig && !normalState.textConfig) {
  6017. normalState.textConfig = this.textConfig;
  6018. }
  6019. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS);
  6020. };
  6021. Element.prototype._savePrimaryToNormal = function (toState, normalState, primaryKeys) {
  6022. for (var i = 0; i < primaryKeys.length; i++) {
  6023. var key = primaryKeys[i];
  6024. if (toState[key] != null && !(key in normalState)) {
  6025. normalState[key] = this[key];
  6026. }
  6027. }
  6028. };
  6029. Element.prototype.hasState = function () {
  6030. return this.currentStates.length > 0;
  6031. };
  6032. Element.prototype.getState = function (name) {
  6033. return this.states[name];
  6034. };
  6035. Element.prototype.ensureState = function (name) {
  6036. var states = this.states;
  6037. if (!states[name]) {
  6038. states[name] = {};
  6039. }
  6040. return states[name];
  6041. };
  6042. Element.prototype.clearStates = function (noAnimation) {
  6043. this.useState(PRESERVED_NORMAL_STATE, false, noAnimation);
  6044. };
  6045. Element.prototype.useState = function (stateName, keepCurrentStates, noAnimation, forceUseHoverLayer) {
  6046. var toNormalState = stateName === PRESERVED_NORMAL_STATE;
  6047. var hasStates = this.hasState();
  6048. if (!hasStates && toNormalState) {
  6049. return;
  6050. }
  6051. var currentStates = this.currentStates;
  6052. var animationCfg = this.stateTransition;
  6053. if (indexOf(currentStates, stateName) >= 0 && (keepCurrentStates || currentStates.length === 1)) {
  6054. return;
  6055. }
  6056. var state;
  6057. if (this.stateProxy && !toNormalState) {
  6058. state = this.stateProxy(stateName);
  6059. }
  6060. if (!state) {
  6061. state = (this.states && this.states[stateName]);
  6062. }
  6063. if (!state && !toNormalState) {
  6064. logError("State " + stateName + " not exists.");
  6065. return;
  6066. }
  6067. if (!toNormalState) {
  6068. this.saveCurrentToNormalState(state);
  6069. }
  6070. var useHoverLayer = !!((state && state.hoverLayer) || forceUseHoverLayer);
  6071. if (useHoverLayer) {
  6072. this._toggleHoverLayerFlag(true);
  6073. }
  6074. this._applyStateObj(stateName, state, this._normalState, keepCurrentStates, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6075. var textContent = this._textContent;
  6076. var textGuide = this._textGuide;
  6077. if (textContent) {
  6078. textContent.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6079. }
  6080. if (textGuide) {
  6081. textGuide.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6082. }
  6083. if (toNormalState) {
  6084. this.currentStates = [];
  6085. this._normalState = {};
  6086. }
  6087. else {
  6088. if (!keepCurrentStates) {
  6089. this.currentStates = [stateName];
  6090. }
  6091. else {
  6092. this.currentStates.push(stateName);
  6093. }
  6094. }
  6095. this._updateAnimationTargets();
  6096. this.markRedraw();
  6097. if (!useHoverLayer && this.__inHover) {
  6098. this._toggleHoverLayerFlag(false);
  6099. this.__dirty &= ~REDRAW_BIT;
  6100. }
  6101. return state;
  6102. };
  6103. Element.prototype.useStates = function (states, noAnimation, forceUseHoverLayer) {
  6104. if (!states.length) {
  6105. this.clearStates();
  6106. }
  6107. else {
  6108. var stateObjects = [];
  6109. var currentStates = this.currentStates;
  6110. var len = states.length;
  6111. var notChange = len === currentStates.length;
  6112. if (notChange) {
  6113. for (var i = 0; i < len; i++) {
  6114. if (states[i] !== currentStates[i]) {
  6115. notChange = false;
  6116. break;
  6117. }
  6118. }
  6119. }
  6120. if (notChange) {
  6121. return;
  6122. }
  6123. for (var i = 0; i < len; i++) {
  6124. var stateName = states[i];
  6125. var stateObj = void 0;
  6126. if (this.stateProxy) {
  6127. stateObj = this.stateProxy(stateName, states);
  6128. }
  6129. if (!stateObj) {
  6130. stateObj = this.states[stateName];
  6131. }
  6132. if (stateObj) {
  6133. stateObjects.push(stateObj);
  6134. }
  6135. }
  6136. var lastStateObj = stateObjects[len - 1];
  6137. var useHoverLayer = !!((lastStateObj && lastStateObj.hoverLayer) || forceUseHoverLayer);
  6138. if (useHoverLayer) {
  6139. this._toggleHoverLayerFlag(true);
  6140. }
  6141. var mergedState = this._mergeStates(stateObjects);
  6142. var animationCfg = this.stateTransition;
  6143. this.saveCurrentToNormalState(mergedState);
  6144. this._applyStateObj(states.join(','), mergedState, this._normalState, false, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6145. var textContent = this._textContent;
  6146. var textGuide = this._textGuide;
  6147. if (textContent) {
  6148. textContent.useStates(states, noAnimation, useHoverLayer);
  6149. }
  6150. if (textGuide) {
  6151. textGuide.useStates(states, noAnimation, useHoverLayer);
  6152. }
  6153. this._updateAnimationTargets();
  6154. this.currentStates = states.slice();
  6155. this.markRedraw();
  6156. if (!useHoverLayer && this.__inHover) {
  6157. this._toggleHoverLayerFlag(false);
  6158. this.__dirty &= ~REDRAW_BIT;
  6159. }
  6160. }
  6161. };
  6162. Element.prototype.isSilent = function () {
  6163. var isSilent = this.silent;
  6164. var ancestor = this.parent;
  6165. while (!isSilent && ancestor) {
  6166. if (ancestor.silent) {
  6167. isSilent = true;
  6168. break;
  6169. }
  6170. ancestor = ancestor.parent;
  6171. }
  6172. return isSilent;
  6173. };
  6174. Element.prototype._updateAnimationTargets = function () {
  6175. for (var i = 0; i < this.animators.length; i++) {
  6176. var animator = this.animators[i];
  6177. if (animator.targetName) {
  6178. animator.changeTarget(this[animator.targetName]);
  6179. }
  6180. }
  6181. };
  6182. Element.prototype.removeState = function (state) {
  6183. var idx = indexOf(this.currentStates, state);
  6184. if (idx >= 0) {
  6185. var currentStates = this.currentStates.slice();
  6186. currentStates.splice(idx, 1);
  6187. this.useStates(currentStates);
  6188. }
  6189. };
  6190. Element.prototype.replaceState = function (oldState, newState, forceAdd) {
  6191. var currentStates = this.currentStates.slice();
  6192. var idx = indexOf(currentStates, oldState);
  6193. var newStateExists = indexOf(currentStates, newState) >= 0;
  6194. if (idx >= 0) {
  6195. if (!newStateExists) {
  6196. currentStates[idx] = newState;
  6197. }
  6198. else {
  6199. currentStates.splice(idx, 1);
  6200. }
  6201. }
  6202. else if (forceAdd && !newStateExists) {
  6203. currentStates.push(newState);
  6204. }
  6205. this.useStates(currentStates);
  6206. };
  6207. Element.prototype.toggleState = function (state, enable) {
  6208. if (enable) {
  6209. this.useState(state, true);
  6210. }
  6211. else {
  6212. this.removeState(state);
  6213. }
  6214. };
  6215. Element.prototype._mergeStates = function (states) {
  6216. var mergedState = {};
  6217. var mergedTextConfig;
  6218. for (var i = 0; i < states.length; i++) {
  6219. var state = states[i];
  6220. extend(mergedState, state);
  6221. if (state.textConfig) {
  6222. mergedTextConfig = mergedTextConfig || {};
  6223. extend(mergedTextConfig, state.textConfig);
  6224. }
  6225. }
  6226. if (mergedTextConfig) {
  6227. mergedState.textConfig = mergedTextConfig;
  6228. }
  6229. return mergedState;
  6230. };
  6231. Element.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  6232. var needsRestoreToNormal = !(state && keepCurrentStates);
  6233. if (state && state.textConfig) {
  6234. this.textConfig = extend({}, keepCurrentStates ? this.textConfig : normalState.textConfig);
  6235. extend(this.textConfig, state.textConfig);
  6236. }
  6237. else if (needsRestoreToNormal) {
  6238. if (normalState.textConfig) {
  6239. this.textConfig = normalState.textConfig;
  6240. }
  6241. }
  6242. var transitionTarget = {};
  6243. var hasTransition = false;
  6244. for (var i = 0; i < PRIMARY_STATES_KEYS.length; i++) {
  6245. var key = PRIMARY_STATES_KEYS[i];
  6246. var propNeedsTransition = transition && DEFAULT_ANIMATABLE_MAP[key];
  6247. if (state && state[key] != null) {
  6248. if (propNeedsTransition) {
  6249. hasTransition = true;
  6250. transitionTarget[key] = state[key];
  6251. }
  6252. else {
  6253. this[key] = state[key];
  6254. }
  6255. }
  6256. else if (needsRestoreToNormal) {
  6257. if (normalState[key] != null) {
  6258. if (propNeedsTransition) {
  6259. hasTransition = true;
  6260. transitionTarget[key] = normalState[key];
  6261. }
  6262. else {
  6263. this[key] = normalState[key];
  6264. }
  6265. }
  6266. }
  6267. }
  6268. if (!transition) {
  6269. for (var i = 0; i < this.animators.length; i++) {
  6270. var animator = this.animators[i];
  6271. var targetName = animator.targetName;
  6272. if (!animator.getLoop()) {
  6273. animator.__changeFinalValue(targetName
  6274. ? (state || normalState)[targetName]
  6275. : (state || normalState));
  6276. }
  6277. }
  6278. }
  6279. if (hasTransition) {
  6280. this._transitionState(stateName, transitionTarget, animationCfg);
  6281. }
  6282. };
  6283. Element.prototype._attachComponent = function (componentEl) {
  6284. if (componentEl.__zr && !componentEl.__hostTarget) {
  6285. {
  6286. throw new Error('Text element has been added to zrender.');
  6287. }
  6288. }
  6289. if (componentEl === this) {
  6290. {
  6291. throw new Error('Recursive component attachment.');
  6292. }
  6293. }
  6294. var zr = this.__zr;
  6295. if (zr) {
  6296. componentEl.addSelfToZr(zr);
  6297. }
  6298. componentEl.__zr = zr;
  6299. componentEl.__hostTarget = this;
  6300. };
  6301. Element.prototype._detachComponent = function (componentEl) {
  6302. if (componentEl.__zr) {
  6303. componentEl.removeSelfFromZr(componentEl.__zr);
  6304. }
  6305. componentEl.__zr = null;
  6306. componentEl.__hostTarget = null;
  6307. };
  6308. Element.prototype.getClipPath = function () {
  6309. return this._clipPath;
  6310. };
  6311. Element.prototype.setClipPath = function (clipPath) {
  6312. if (this._clipPath && this._clipPath !== clipPath) {
  6313. this.removeClipPath();
  6314. }
  6315. this._attachComponent(clipPath);
  6316. this._clipPath = clipPath;
  6317. this.markRedraw();
  6318. };
  6319. Element.prototype.removeClipPath = function () {
  6320. var clipPath = this._clipPath;
  6321. if (clipPath) {
  6322. this._detachComponent(clipPath);
  6323. this._clipPath = null;
  6324. this.markRedraw();
  6325. }
  6326. };
  6327. Element.prototype.getTextContent = function () {
  6328. return this._textContent;
  6329. };
  6330. Element.prototype.setTextContent = function (textEl) {
  6331. var previousTextContent = this._textContent;
  6332. if (previousTextContent === textEl) {
  6333. return;
  6334. }
  6335. if (previousTextContent && previousTextContent !== textEl) {
  6336. this.removeTextContent();
  6337. }
  6338. {
  6339. if (textEl.__zr && !textEl.__hostTarget) {
  6340. throw new Error('Text element has been added to zrender.');
  6341. }
  6342. }
  6343. textEl.innerTransformable = new Transformable();
  6344. this._attachComponent(textEl);
  6345. this._textContent = textEl;
  6346. this.markRedraw();
  6347. };
  6348. Element.prototype.setTextConfig = function (cfg) {
  6349. if (!this.textConfig) {
  6350. this.textConfig = {};
  6351. }
  6352. extend(this.textConfig, cfg);
  6353. this.markRedraw();
  6354. };
  6355. Element.prototype.removeTextConfig = function () {
  6356. this.textConfig = null;
  6357. this.markRedraw();
  6358. };
  6359. Element.prototype.removeTextContent = function () {
  6360. var textEl = this._textContent;
  6361. if (textEl) {
  6362. textEl.innerTransformable = null;
  6363. this._detachComponent(textEl);
  6364. this._textContent = null;
  6365. this._innerTextDefaultStyle = null;
  6366. this.markRedraw();
  6367. }
  6368. };
  6369. Element.prototype.getTextGuideLine = function () {
  6370. return this._textGuide;
  6371. };
  6372. Element.prototype.setTextGuideLine = function (guideLine) {
  6373. if (this._textGuide && this._textGuide !== guideLine) {
  6374. this.removeTextGuideLine();
  6375. }
  6376. this._attachComponent(guideLine);
  6377. this._textGuide = guideLine;
  6378. this.markRedraw();
  6379. };
  6380. Element.prototype.removeTextGuideLine = function () {
  6381. var textGuide = this._textGuide;
  6382. if (textGuide) {
  6383. this._detachComponent(textGuide);
  6384. this._textGuide = null;
  6385. this.markRedraw();
  6386. }
  6387. };
  6388. Element.prototype.markRedraw = function () {
  6389. this.__dirty |= REDRAW_BIT;
  6390. var zr = this.__zr;
  6391. if (zr) {
  6392. if (this.__inHover) {
  6393. zr.refreshHover();
  6394. }
  6395. else {
  6396. zr.refresh();
  6397. }
  6398. }
  6399. if (this.__hostTarget) {
  6400. this.__hostTarget.markRedraw();
  6401. }
  6402. };
  6403. Element.prototype.dirty = function () {
  6404. this.markRedraw();
  6405. };
  6406. Element.prototype._toggleHoverLayerFlag = function (inHover) {
  6407. this.__inHover = inHover;
  6408. var textContent = this._textContent;
  6409. var textGuide = this._textGuide;
  6410. if (textContent) {
  6411. textContent.__inHover = inHover;
  6412. }
  6413. if (textGuide) {
  6414. textGuide.__inHover = inHover;
  6415. }
  6416. };
  6417. Element.prototype.addSelfToZr = function (zr) {
  6418. if (this.__zr === zr) {
  6419. return;
  6420. }
  6421. this.__zr = zr;
  6422. var animators = this.animators;
  6423. if (animators) {
  6424. for (var i = 0; i < animators.length; i++) {
  6425. zr.animation.addAnimator(animators[i]);
  6426. }
  6427. }
  6428. if (this._clipPath) {
  6429. this._clipPath.addSelfToZr(zr);
  6430. }
  6431. if (this._textContent) {
  6432. this._textContent.addSelfToZr(zr);
  6433. }
  6434. if (this._textGuide) {
  6435. this._textGuide.addSelfToZr(zr);
  6436. }
  6437. };
  6438. Element.prototype.removeSelfFromZr = function (zr) {
  6439. if (!this.__zr) {
  6440. return;
  6441. }
  6442. this.__zr = null;
  6443. var animators = this.animators;
  6444. if (animators) {
  6445. for (var i = 0; i < animators.length; i++) {
  6446. zr.animation.removeAnimator(animators[i]);
  6447. }
  6448. }
  6449. if (this._clipPath) {
  6450. this._clipPath.removeSelfFromZr(zr);
  6451. }
  6452. if (this._textContent) {
  6453. this._textContent.removeSelfFromZr(zr);
  6454. }
  6455. if (this._textGuide) {
  6456. this._textGuide.removeSelfFromZr(zr);
  6457. }
  6458. };
  6459. Element.prototype.animate = function (key, loop, allowDiscreteAnimation) {
  6460. var target = key ? this[key] : this;
  6461. {
  6462. if (!target) {
  6463. logError('Property "'
  6464. + key
  6465. + '" is not existed in element '
  6466. + this.id);
  6467. return;
  6468. }
  6469. }
  6470. var animator = new Animator(target, loop, allowDiscreteAnimation);
  6471. key && (animator.targetName = key);
  6472. this.addAnimator(animator, key);
  6473. return animator;
  6474. };
  6475. Element.prototype.addAnimator = function (animator, key) {
  6476. var zr = this.__zr;
  6477. var el = this;
  6478. animator.during(function () {
  6479. el.updateDuringAnimation(key);
  6480. }).done(function () {
  6481. var animators = el.animators;
  6482. var idx = indexOf(animators, animator);
  6483. if (idx >= 0) {
  6484. animators.splice(idx, 1);
  6485. }
  6486. });
  6487. this.animators.push(animator);
  6488. if (zr) {
  6489. zr.animation.addAnimator(animator);
  6490. }
  6491. zr && zr.wakeUp();
  6492. };
  6493. Element.prototype.updateDuringAnimation = function (key) {
  6494. this.markRedraw();
  6495. };
  6496. Element.prototype.stopAnimation = function (scope, forwardToLast) {
  6497. var animators = this.animators;
  6498. var len = animators.length;
  6499. var leftAnimators = [];
  6500. for (var i = 0; i < len; i++) {
  6501. var animator = animators[i];
  6502. if (!scope || scope === animator.scope) {
  6503. animator.stop(forwardToLast);
  6504. }
  6505. else {
  6506. leftAnimators.push(animator);
  6507. }
  6508. }
  6509. this.animators = leftAnimators;
  6510. return this;
  6511. };
  6512. Element.prototype.animateTo = function (target, cfg, animationProps) {
  6513. animateTo(this, target, cfg, animationProps);
  6514. };
  6515. Element.prototype.animateFrom = function (target, cfg, animationProps) {
  6516. animateTo(this, target, cfg, animationProps, true);
  6517. };
  6518. Element.prototype._transitionState = function (stateName, target, cfg, animationProps) {
  6519. var animators = animateTo(this, target, cfg, animationProps);
  6520. for (var i = 0; i < animators.length; i++) {
  6521. animators[i].__fromStateTransition = stateName;
  6522. }
  6523. };
  6524. Element.prototype.getBoundingRect = function () {
  6525. return null;
  6526. };
  6527. Element.prototype.getPaintRect = function () {
  6528. return null;
  6529. };
  6530. Element.initDefaultProps = (function () {
  6531. var elProto = Element.prototype;
  6532. elProto.type = 'element';
  6533. elProto.name = '';
  6534. elProto.ignore =
  6535. elProto.silent =
  6536. elProto.isGroup =
  6537. elProto.draggable =
  6538. elProto.dragging =
  6539. elProto.ignoreClip =
  6540. elProto.__inHover = false;
  6541. elProto.__dirty = REDRAW_BIT;
  6542. var logs = {};
  6543. function logDeprecatedError(key, xKey, yKey) {
  6544. if (!logs[key + xKey + yKey]) {
  6545. console.warn("DEPRECATED: '" + key + "' has been deprecated. use '" + xKey + "', '" + yKey + "' instead");
  6546. logs[key + xKey + yKey] = true;
  6547. }
  6548. }
  6549. function createLegacyProperty(key, privateKey, xKey, yKey) {
  6550. Object.defineProperty(elProto, key, {
  6551. get: function () {
  6552. {
  6553. logDeprecatedError(key, xKey, yKey);
  6554. }
  6555. if (!this[privateKey]) {
  6556. var pos = this[privateKey] = [];
  6557. enhanceArray(this, pos);
  6558. }
  6559. return this[privateKey];
  6560. },
  6561. set: function (pos) {
  6562. {
  6563. logDeprecatedError(key, xKey, yKey);
  6564. }
  6565. this[xKey] = pos[0];
  6566. this[yKey] = pos[1];
  6567. this[privateKey] = pos;
  6568. enhanceArray(this, pos);
  6569. }
  6570. });
  6571. function enhanceArray(self, pos) {
  6572. Object.defineProperty(pos, 0, {
  6573. get: function () {
  6574. return self[xKey];
  6575. },
  6576. set: function (val) {
  6577. self[xKey] = val;
  6578. }
  6579. });
  6580. Object.defineProperty(pos, 1, {
  6581. get: function () {
  6582. return self[yKey];
  6583. },
  6584. set: function (val) {
  6585. self[yKey] = val;
  6586. }
  6587. });
  6588. }
  6589. }
  6590. if (Object.defineProperty) {
  6591. createLegacyProperty('position', '_legacyPos', 'x', 'y');
  6592. createLegacyProperty('scale', '_legacyScale', 'scaleX', 'scaleY');
  6593. createLegacyProperty('origin', '_legacyOrigin', 'originX', 'originY');
  6594. }
  6595. })();
  6596. return Element;
  6597. }());
  6598. mixin(Element, Eventful);
  6599. mixin(Element, Transformable);
  6600. function animateTo(animatable, target, cfg, animationProps, reverse) {
  6601. cfg = cfg || {};
  6602. var animators = [];
  6603. animateToShallow(animatable, '', animatable, target, cfg, animationProps, animators, reverse);
  6604. var finishCount = animators.length;
  6605. var doneHappened = false;
  6606. var cfgDone = cfg.done;
  6607. var cfgAborted = cfg.aborted;
  6608. var doneCb = function () {
  6609. doneHappened = true;
  6610. finishCount--;
  6611. if (finishCount <= 0) {
  6612. doneHappened
  6613. ? (cfgDone && cfgDone())
  6614. : (cfgAborted && cfgAborted());
  6615. }
  6616. };
  6617. var abortedCb = function () {
  6618. finishCount--;
  6619. if (finishCount <= 0) {
  6620. doneHappened
  6621. ? (cfgDone && cfgDone())
  6622. : (cfgAborted && cfgAborted());
  6623. }
  6624. };
  6625. if (!finishCount) {
  6626. cfgDone && cfgDone();
  6627. }
  6628. if (animators.length > 0 && cfg.during) {
  6629. animators[0].during(function (target, percent) {
  6630. cfg.during(percent);
  6631. });
  6632. }
  6633. for (var i = 0; i < animators.length; i++) {
  6634. var animator = animators[i];
  6635. if (doneCb) {
  6636. animator.done(doneCb);
  6637. }
  6638. if (abortedCb) {
  6639. animator.aborted(abortedCb);
  6640. }
  6641. if (cfg.force) {
  6642. animator.duration(cfg.duration);
  6643. }
  6644. animator.start(cfg.easing);
  6645. }
  6646. return animators;
  6647. }
  6648. function copyArrShallow(source, target, len) {
  6649. for (var i = 0; i < len; i++) {
  6650. source[i] = target[i];
  6651. }
  6652. }
  6653. function is2DArray(value) {
  6654. return isArrayLike(value[0]);
  6655. }
  6656. function copyValue(target, source, key) {
  6657. if (isArrayLike(source[key])) {
  6658. if (!isArrayLike(target[key])) {
  6659. target[key] = [];
  6660. }
  6661. if (isTypedArray(source[key])) {
  6662. var len = source[key].length;
  6663. if (target[key].length !== len) {
  6664. target[key] = new (source[key].constructor)(len);
  6665. copyArrShallow(target[key], source[key], len);
  6666. }
  6667. }
  6668. else {
  6669. var sourceArr = source[key];
  6670. var targetArr = target[key];
  6671. var len0 = sourceArr.length;
  6672. if (is2DArray(sourceArr)) {
  6673. var len1 = sourceArr[0].length;
  6674. for (var i = 0; i < len0; i++) {
  6675. if (!targetArr[i]) {
  6676. targetArr[i] = Array.prototype.slice.call(sourceArr[i]);
  6677. }
  6678. else {
  6679. copyArrShallow(targetArr[i], sourceArr[i], len1);
  6680. }
  6681. }
  6682. }
  6683. else {
  6684. copyArrShallow(targetArr, sourceArr, len0);
  6685. }
  6686. targetArr.length = sourceArr.length;
  6687. }
  6688. }
  6689. else {
  6690. target[key] = source[key];
  6691. }
  6692. }
  6693. function isValueSame(val1, val2) {
  6694. return val1 === val2
  6695. || isArrayLike(val1) && isArrayLike(val2) && is1DArraySame(val1, val2);
  6696. }
  6697. function is1DArraySame(arr0, arr1) {
  6698. var len = arr0.length;
  6699. if (len !== arr1.length) {
  6700. return false;
  6701. }
  6702. for (var i = 0; i < len; i++) {
  6703. if (arr0[i] !== arr1[i]) {
  6704. return false;
  6705. }
  6706. }
  6707. return true;
  6708. }
  6709. function animateToShallow(animatable, topKey, animateObj, target, cfg, animationProps, animators, reverse) {
  6710. var targetKeys = keys(target);
  6711. var duration = cfg.duration;
  6712. var delay = cfg.delay;
  6713. var additive = cfg.additive;
  6714. var setToFinal = cfg.setToFinal;
  6715. var animateAll = !isObject(animationProps);
  6716. var existsAnimators = animatable.animators;
  6717. var animationKeys = [];
  6718. for (var k = 0; k < targetKeys.length; k++) {
  6719. var innerKey = targetKeys[k];
  6720. var targetVal = target[innerKey];
  6721. if (targetVal != null && animateObj[innerKey] != null
  6722. && (animateAll || animationProps[innerKey])) {
  6723. if (isObject(targetVal)
  6724. && !isArrayLike(targetVal)
  6725. && !isGradientObject(targetVal)) {
  6726. if (topKey) {
  6727. if (!reverse) {
  6728. animateObj[innerKey] = targetVal;
  6729. animatable.updateDuringAnimation(topKey);
  6730. }
  6731. continue;
  6732. }
  6733. animateToShallow(animatable, innerKey, animateObj[innerKey], targetVal, cfg, animationProps && animationProps[innerKey], animators, reverse);
  6734. }
  6735. else {
  6736. animationKeys.push(innerKey);
  6737. }
  6738. }
  6739. else if (!reverse) {
  6740. animateObj[innerKey] = targetVal;
  6741. animatable.updateDuringAnimation(topKey);
  6742. animationKeys.push(innerKey);
  6743. }
  6744. }
  6745. var keyLen = animationKeys.length;
  6746. if (!additive && keyLen) {
  6747. for (var i = 0; i < existsAnimators.length; i++) {
  6748. var animator = existsAnimators[i];
  6749. if (animator.targetName === topKey) {
  6750. var allAborted = animator.stopTracks(animationKeys);
  6751. if (allAborted) {
  6752. var idx = indexOf(existsAnimators, animator);
  6753. existsAnimators.splice(idx, 1);
  6754. }
  6755. }
  6756. }
  6757. }
  6758. if (!cfg.force) {
  6759. animationKeys = filter(animationKeys, function (key) { return !isValueSame(target[key], animateObj[key]); });
  6760. keyLen = animationKeys.length;
  6761. }
  6762. if (keyLen > 0
  6763. || (cfg.force && !animators.length)) {
  6764. var revertedSource = void 0;
  6765. var reversedTarget = void 0;
  6766. var sourceClone = void 0;
  6767. if (reverse) {
  6768. reversedTarget = {};
  6769. if (setToFinal) {
  6770. revertedSource = {};
  6771. }
  6772. for (var i = 0; i < keyLen; i++) {
  6773. var innerKey = animationKeys[i];
  6774. reversedTarget[innerKey] = animateObj[innerKey];
  6775. if (setToFinal) {
  6776. revertedSource[innerKey] = target[innerKey];
  6777. }
  6778. else {
  6779. animateObj[innerKey] = target[innerKey];
  6780. }
  6781. }
  6782. }
  6783. else if (setToFinal) {
  6784. sourceClone = {};
  6785. for (var i = 0; i < keyLen; i++) {
  6786. var innerKey = animationKeys[i];
  6787. sourceClone[innerKey] = cloneValue(animateObj[innerKey]);
  6788. copyValue(animateObj, target, innerKey);
  6789. }
  6790. }
  6791. var animator = new Animator(animateObj, false, false, additive ? filter(existsAnimators, function (animator) { return animator.targetName === topKey; }) : null);
  6792. animator.targetName = topKey;
  6793. if (cfg.scope) {
  6794. animator.scope = cfg.scope;
  6795. }
  6796. if (setToFinal && revertedSource) {
  6797. animator.whenWithKeys(0, revertedSource, animationKeys);
  6798. }
  6799. if (sourceClone) {
  6800. animator.whenWithKeys(0, sourceClone, animationKeys);
  6801. }
  6802. animator.whenWithKeys(duration == null ? 500 : duration, reverse ? reversedTarget : target, animationKeys).delay(delay || 0);
  6803. animatable.addAnimator(animator, topKey);
  6804. animators.push(animator);
  6805. }
  6806. }
  6807. var Group = (function (_super) {
  6808. __extends(Group, _super);
  6809. function Group(opts) {
  6810. var _this = _super.call(this) || this;
  6811. _this.isGroup = true;
  6812. _this._children = [];
  6813. _this.attr(opts);
  6814. return _this;
  6815. }
  6816. Group.prototype.childrenRef = function () {
  6817. return this._children;
  6818. };
  6819. Group.prototype.children = function () {
  6820. return this._children.slice();
  6821. };
  6822. Group.prototype.childAt = function (idx) {
  6823. return this._children[idx];
  6824. };
  6825. Group.prototype.childOfName = function (name) {
  6826. var children = this._children;
  6827. for (var i = 0; i < children.length; i++) {
  6828. if (children[i].name === name) {
  6829. return children[i];
  6830. }
  6831. }
  6832. };
  6833. Group.prototype.childCount = function () {
  6834. return this._children.length;
  6835. };
  6836. Group.prototype.add = function (child) {
  6837. if (child) {
  6838. if (child !== this && child.parent !== this) {
  6839. this._children.push(child);
  6840. this._doAdd(child);
  6841. }
  6842. {
  6843. if (child.__hostTarget) {
  6844. throw 'This elemenet has been used as an attachment';
  6845. }
  6846. }
  6847. }
  6848. return this;
  6849. };
  6850. Group.prototype.addBefore = function (child, nextSibling) {
  6851. if (child && child !== this && child.parent !== this
  6852. && nextSibling && nextSibling.parent === this) {
  6853. var children = this._children;
  6854. var idx = children.indexOf(nextSibling);
  6855. if (idx >= 0) {
  6856. children.splice(idx, 0, child);
  6857. this._doAdd(child);
  6858. }
  6859. }
  6860. return this;
  6861. };
  6862. Group.prototype.replace = function (oldChild, newChild) {
  6863. var idx = indexOf(this._children, oldChild);
  6864. if (idx >= 0) {
  6865. this.replaceAt(newChild, idx);
  6866. }
  6867. return this;
  6868. };
  6869. Group.prototype.replaceAt = function (child, index) {
  6870. var children = this._children;
  6871. var old = children[index];
  6872. if (child && child !== this && child.parent !== this && child !== old) {
  6873. children[index] = child;
  6874. old.parent = null;
  6875. var zr = this.__zr;
  6876. if (zr) {
  6877. old.removeSelfFromZr(zr);
  6878. }
  6879. this._doAdd(child);
  6880. }
  6881. return this;
  6882. };
  6883. Group.prototype._doAdd = function (child) {
  6884. if (child.parent) {
  6885. child.parent.remove(child);
  6886. }
  6887. child.parent = this;
  6888. var zr = this.__zr;
  6889. if (zr && zr !== child.__zr) {
  6890. child.addSelfToZr(zr);
  6891. }
  6892. zr && zr.refresh();
  6893. };
  6894. Group.prototype.remove = function (child) {
  6895. var zr = this.__zr;
  6896. var children = this._children;
  6897. var idx = indexOf(children, child);
  6898. if (idx < 0) {
  6899. return this;
  6900. }
  6901. children.splice(idx, 1);
  6902. child.parent = null;
  6903. if (zr) {
  6904. child.removeSelfFromZr(zr);
  6905. }
  6906. zr && zr.refresh();
  6907. return this;
  6908. };
  6909. Group.prototype.removeAll = function () {
  6910. var children = this._children;
  6911. var zr = this.__zr;
  6912. for (var i = 0; i < children.length; i++) {
  6913. var child = children[i];
  6914. if (zr) {
  6915. child.removeSelfFromZr(zr);
  6916. }
  6917. child.parent = null;
  6918. }
  6919. children.length = 0;
  6920. return this;
  6921. };
  6922. Group.prototype.eachChild = function (cb, context) {
  6923. var children = this._children;
  6924. for (var i = 0; i < children.length; i++) {
  6925. var child = children[i];
  6926. cb.call(context, child, i);
  6927. }
  6928. return this;
  6929. };
  6930. Group.prototype.traverse = function (cb, context) {
  6931. for (var i = 0; i < this._children.length; i++) {
  6932. var child = this._children[i];
  6933. var stopped = cb.call(context, child);
  6934. if (child.isGroup && !stopped) {
  6935. child.traverse(cb, context);
  6936. }
  6937. }
  6938. return this;
  6939. };
  6940. Group.prototype.addSelfToZr = function (zr) {
  6941. _super.prototype.addSelfToZr.call(this, zr);
  6942. for (var i = 0; i < this._children.length; i++) {
  6943. var child = this._children[i];
  6944. child.addSelfToZr(zr);
  6945. }
  6946. };
  6947. Group.prototype.removeSelfFromZr = function (zr) {
  6948. _super.prototype.removeSelfFromZr.call(this, zr);
  6949. for (var i = 0; i < this._children.length; i++) {
  6950. var child = this._children[i];
  6951. child.removeSelfFromZr(zr);
  6952. }
  6953. };
  6954. Group.prototype.getBoundingRect = function (includeChildren) {
  6955. var tmpRect = new BoundingRect(0, 0, 0, 0);
  6956. var children = includeChildren || this._children;
  6957. var tmpMat = [];
  6958. var rect = null;
  6959. for (var i = 0; i < children.length; i++) {
  6960. var child = children[i];
  6961. if (child.ignore || child.invisible) {
  6962. continue;
  6963. }
  6964. var childRect = child.getBoundingRect();
  6965. var transform = child.getLocalTransform(tmpMat);
  6966. if (transform) {
  6967. BoundingRect.applyTransform(tmpRect, childRect, transform);
  6968. rect = rect || tmpRect.clone();
  6969. rect.union(tmpRect);
  6970. }
  6971. else {
  6972. rect = rect || childRect.clone();
  6973. rect.union(childRect);
  6974. }
  6975. }
  6976. return rect || tmpRect;
  6977. };
  6978. return Group;
  6979. }(Element));
  6980. Group.prototype.type = 'group';
  6981. /*!
  6982. * ZRender, a high performance 2d drawing library.
  6983. *
  6984. * Copyright (c) 2013, Baidu Inc.
  6985. * All rights reserved.
  6986. *
  6987. * LICENSE
  6988. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  6989. */
  6990. var painterCtors = {};
  6991. var instances = {};
  6992. function delInstance(id) {
  6993. delete instances[id];
  6994. }
  6995. function isDarkMode(backgroundColor) {
  6996. if (!backgroundColor) {
  6997. return false;
  6998. }
  6999. if (typeof backgroundColor === 'string') {
  7000. return lum(backgroundColor, 1) < DARK_MODE_THRESHOLD;
  7001. }
  7002. else if (backgroundColor.colorStops) {
  7003. var colorStops = backgroundColor.colorStops;
  7004. var totalLum = 0;
  7005. var len = colorStops.length;
  7006. for (var i = 0; i < len; i++) {
  7007. totalLum += lum(colorStops[i].color, 1);
  7008. }
  7009. totalLum /= len;
  7010. return totalLum < DARK_MODE_THRESHOLD;
  7011. }
  7012. return false;
  7013. }
  7014. var ZRender = (function () {
  7015. function ZRender(id, dom, opts) {
  7016. var _this = this;
  7017. this._sleepAfterStill = 10;
  7018. this._stillFrameAccum = 0;
  7019. this._needsRefresh = true;
  7020. this._needsRefreshHover = true;
  7021. this._darkMode = false;
  7022. opts = opts || {};
  7023. this.dom = dom;
  7024. this.id = id;
  7025. var storage = new Storage();
  7026. var rendererType = opts.renderer || 'canvas';
  7027. if (!painterCtors[rendererType]) {
  7028. rendererType = keys(painterCtors)[0];
  7029. }
  7030. {
  7031. if (!painterCtors[rendererType]) {
  7032. throw new Error("Renderer '" + rendererType + "' is not imported. Please import it first.");
  7033. }
  7034. }
  7035. opts.useDirtyRect = opts.useDirtyRect == null
  7036. ? false
  7037. : opts.useDirtyRect;
  7038. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  7039. var ssrMode = opts.ssr || painter.ssrOnly;
  7040. this.storage = storage;
  7041. this.painter = painter;
  7042. var handlerProxy = (!env.node && !env.worker && !ssrMode)
  7043. ? new HandlerDomProxy(painter.getViewportRoot(), painter.root)
  7044. : null;
  7045. var useCoarsePointer = opts.useCoarsePointer;
  7046. var usePointerSize = (useCoarsePointer == null || useCoarsePointer === 'auto')
  7047. ? env.touchEventsSupported
  7048. : !!useCoarsePointer;
  7049. var defaultPointerSize = 44;
  7050. var pointerSize;
  7051. if (usePointerSize) {
  7052. pointerSize = retrieve2(opts.pointerSize, defaultPointerSize);
  7053. }
  7054. this.handler = new Handler(storage, painter, handlerProxy, painter.root, pointerSize);
  7055. this.animation = new Animation({
  7056. stage: {
  7057. update: ssrMode ? null : function () { return _this._flush(true); }
  7058. }
  7059. });
  7060. if (!ssrMode) {
  7061. this.animation.start();
  7062. }
  7063. }
  7064. ZRender.prototype.add = function (el) {
  7065. if (this._disposed || !el) {
  7066. return;
  7067. }
  7068. this.storage.addRoot(el);
  7069. el.addSelfToZr(this);
  7070. this.refresh();
  7071. };
  7072. ZRender.prototype.remove = function (el) {
  7073. if (this._disposed || !el) {
  7074. return;
  7075. }
  7076. this.storage.delRoot(el);
  7077. el.removeSelfFromZr(this);
  7078. this.refresh();
  7079. };
  7080. ZRender.prototype.configLayer = function (zLevel, config) {
  7081. if (this._disposed) {
  7082. return;
  7083. }
  7084. if (this.painter.configLayer) {
  7085. this.painter.configLayer(zLevel, config);
  7086. }
  7087. this.refresh();
  7088. };
  7089. ZRender.prototype.setBackgroundColor = function (backgroundColor) {
  7090. if (this._disposed) {
  7091. return;
  7092. }
  7093. if (this.painter.setBackgroundColor) {
  7094. this.painter.setBackgroundColor(backgroundColor);
  7095. }
  7096. this.refresh();
  7097. this._backgroundColor = backgroundColor;
  7098. this._darkMode = isDarkMode(backgroundColor);
  7099. };
  7100. ZRender.prototype.getBackgroundColor = function () {
  7101. return this._backgroundColor;
  7102. };
  7103. ZRender.prototype.setDarkMode = function (darkMode) {
  7104. this._darkMode = darkMode;
  7105. };
  7106. ZRender.prototype.isDarkMode = function () {
  7107. return this._darkMode;
  7108. };
  7109. ZRender.prototype.refreshImmediately = function (fromInside) {
  7110. if (this._disposed) {
  7111. return;
  7112. }
  7113. if (!fromInside) {
  7114. this.animation.update(true);
  7115. }
  7116. this._needsRefresh = false;
  7117. this.painter.refresh();
  7118. this._needsRefresh = false;
  7119. };
  7120. ZRender.prototype.refresh = function () {
  7121. if (this._disposed) {
  7122. return;
  7123. }
  7124. this._needsRefresh = true;
  7125. this.animation.start();
  7126. };
  7127. ZRender.prototype.flush = function () {
  7128. if (this._disposed) {
  7129. return;
  7130. }
  7131. this._flush(false);
  7132. };
  7133. ZRender.prototype._flush = function (fromInside) {
  7134. var triggerRendered;
  7135. var start = getTime();
  7136. if (this._needsRefresh) {
  7137. triggerRendered = true;
  7138. this.refreshImmediately(fromInside);
  7139. }
  7140. if (this._needsRefreshHover) {
  7141. triggerRendered = true;
  7142. this.refreshHoverImmediately();
  7143. }
  7144. var end = getTime();
  7145. if (triggerRendered) {
  7146. this._stillFrameAccum = 0;
  7147. this.trigger('rendered', {
  7148. elapsedTime: end - start
  7149. });
  7150. }
  7151. else if (this._sleepAfterStill > 0) {
  7152. this._stillFrameAccum++;
  7153. if (this._stillFrameAccum > this._sleepAfterStill) {
  7154. this.animation.stop();
  7155. }
  7156. }
  7157. };
  7158. ZRender.prototype.setSleepAfterStill = function (stillFramesCount) {
  7159. this._sleepAfterStill = stillFramesCount;
  7160. };
  7161. ZRender.prototype.wakeUp = function () {
  7162. if (this._disposed) {
  7163. return;
  7164. }
  7165. this.animation.start();
  7166. this._stillFrameAccum = 0;
  7167. };
  7168. ZRender.prototype.refreshHover = function () {
  7169. this._needsRefreshHover = true;
  7170. };
  7171. ZRender.prototype.refreshHoverImmediately = function () {
  7172. if (this._disposed) {
  7173. return;
  7174. }
  7175. this._needsRefreshHover = false;
  7176. if (this.painter.refreshHover && this.painter.getType() === 'canvas') {
  7177. this.painter.refreshHover();
  7178. }
  7179. };
  7180. ZRender.prototype.resize = function (opts) {
  7181. if (this._disposed) {
  7182. return;
  7183. }
  7184. opts = opts || {};
  7185. this.painter.resize(opts.width, opts.height);
  7186. this.handler.resize();
  7187. };
  7188. ZRender.prototype.clearAnimation = function () {
  7189. if (this._disposed) {
  7190. return;
  7191. }
  7192. this.animation.clear();
  7193. };
  7194. ZRender.prototype.getWidth = function () {
  7195. if (this._disposed) {
  7196. return;
  7197. }
  7198. return this.painter.getWidth();
  7199. };
  7200. ZRender.prototype.getHeight = function () {
  7201. if (this._disposed) {
  7202. return;
  7203. }
  7204. return this.painter.getHeight();
  7205. };
  7206. ZRender.prototype.setCursorStyle = function (cursorStyle) {
  7207. if (this._disposed) {
  7208. return;
  7209. }
  7210. this.handler.setCursorStyle(cursorStyle);
  7211. };
  7212. ZRender.prototype.findHover = function (x, y) {
  7213. if (this._disposed) {
  7214. return;
  7215. }
  7216. return this.handler.findHover(x, y);
  7217. };
  7218. ZRender.prototype.on = function (eventName, eventHandler, context) {
  7219. if (!this._disposed) {
  7220. this.handler.on(eventName, eventHandler, context);
  7221. }
  7222. return this;
  7223. };
  7224. ZRender.prototype.off = function (eventName, eventHandler) {
  7225. if (this._disposed) {
  7226. return;
  7227. }
  7228. this.handler.off(eventName, eventHandler);
  7229. };
  7230. ZRender.prototype.trigger = function (eventName, event) {
  7231. if (this._disposed) {
  7232. return;
  7233. }
  7234. this.handler.trigger(eventName, event);
  7235. };
  7236. ZRender.prototype.clear = function () {
  7237. if (this._disposed) {
  7238. return;
  7239. }
  7240. var roots = this.storage.getRoots();
  7241. for (var i = 0; i < roots.length; i++) {
  7242. if (roots[i] instanceof Group) {
  7243. roots[i].removeSelfFromZr(this);
  7244. }
  7245. }
  7246. this.storage.delAllRoots();
  7247. this.painter.clear();
  7248. };
  7249. ZRender.prototype.dispose = function () {
  7250. if (this._disposed) {
  7251. return;
  7252. }
  7253. this.animation.stop();
  7254. this.clear();
  7255. this.storage.dispose();
  7256. this.painter.dispose();
  7257. this.handler.dispose();
  7258. this.animation =
  7259. this.storage =
  7260. this.painter =
  7261. this.handler = null;
  7262. this._disposed = true;
  7263. delInstance(this.id);
  7264. };
  7265. return ZRender;
  7266. }());
  7267. function init(dom, opts) {
  7268. var zr = new ZRender(guid(), dom, opts);
  7269. instances[zr.id] = zr;
  7270. return zr;
  7271. }
  7272. function dispose(zr) {
  7273. zr.dispose();
  7274. }
  7275. function disposeAll() {
  7276. for (var key in instances) {
  7277. if (instances.hasOwnProperty(key)) {
  7278. instances[key].dispose();
  7279. }
  7280. }
  7281. instances = {};
  7282. }
  7283. function getInstance(id) {
  7284. return instances[id];
  7285. }
  7286. function registerPainter(name, Ctor) {
  7287. painterCtors[name] = Ctor;
  7288. }
  7289. var ssrDataGetter;
  7290. function getElementSSRData(el) {
  7291. if (typeof ssrDataGetter === 'function') {
  7292. return ssrDataGetter(el);
  7293. }
  7294. }
  7295. function registerSSRDataGetter(getter) {
  7296. ssrDataGetter = getter;
  7297. }
  7298. var version = '5.6.0';
  7299. var STYLE_MAGIC_KEY = '__zr_style_' + Math.round((Math.random() * 10));
  7300. var DEFAULT_COMMON_STYLE = {
  7301. shadowBlur: 0,
  7302. shadowOffsetX: 0,
  7303. shadowOffsetY: 0,
  7304. shadowColor: '#000',
  7305. opacity: 1,
  7306. blend: 'source-over'
  7307. };
  7308. var DEFAULT_COMMON_ANIMATION_PROPS = {
  7309. style: {
  7310. shadowBlur: true,
  7311. shadowOffsetX: true,
  7312. shadowOffsetY: true,
  7313. shadowColor: true,
  7314. opacity: true
  7315. }
  7316. };
  7317. DEFAULT_COMMON_STYLE[STYLE_MAGIC_KEY] = true;
  7318. var PRIMARY_STATES_KEYS$1 = ['z', 'z2', 'invisible'];
  7319. var PRIMARY_STATES_KEYS_IN_HOVER_LAYER = ['invisible'];
  7320. var Displayable = (function (_super) {
  7321. __extends(Displayable, _super);
  7322. function Displayable(props) {
  7323. return _super.call(this, props) || this;
  7324. }
  7325. Displayable.prototype._init = function (props) {
  7326. var keysArr = keys(props);
  7327. for (var i = 0; i < keysArr.length; i++) {
  7328. var key = keysArr[i];
  7329. if (key === 'style') {
  7330. this.useStyle(props[key]);
  7331. }
  7332. else {
  7333. _super.prototype.attrKV.call(this, key, props[key]);
  7334. }
  7335. }
  7336. if (!this.style) {
  7337. this.useStyle({});
  7338. }
  7339. };
  7340. Displayable.prototype.beforeBrush = function () { };
  7341. Displayable.prototype.afterBrush = function () { };
  7342. Displayable.prototype.innerBeforeBrush = function () { };
  7343. Displayable.prototype.innerAfterBrush = function () { };
  7344. Displayable.prototype.shouldBePainted = function (viewWidth, viewHeight, considerClipPath, considerAncestors) {
  7345. var m = this.transform;
  7346. if (this.ignore
  7347. || this.invisible
  7348. || this.style.opacity === 0
  7349. || (this.culling
  7350. && isDisplayableCulled(this, viewWidth, viewHeight))
  7351. || (m && !m[0] && !m[3])) {
  7352. return false;
  7353. }
  7354. if (considerClipPath && this.__clipPaths) {
  7355. for (var i = 0; i < this.__clipPaths.length; ++i) {
  7356. if (this.__clipPaths[i].isZeroArea()) {
  7357. return false;
  7358. }
  7359. }
  7360. }
  7361. if (considerAncestors && this.parent) {
  7362. var parent_1 = this.parent;
  7363. while (parent_1) {
  7364. if (parent_1.ignore) {
  7365. return false;
  7366. }
  7367. parent_1 = parent_1.parent;
  7368. }
  7369. }
  7370. return true;
  7371. };
  7372. Displayable.prototype.contain = function (x, y) {
  7373. return this.rectContain(x, y);
  7374. };
  7375. Displayable.prototype.traverse = function (cb, context) {
  7376. cb.call(context, this);
  7377. };
  7378. Displayable.prototype.rectContain = function (x, y) {
  7379. var coord = this.transformCoordToLocal(x, y);
  7380. var rect = this.getBoundingRect();
  7381. return rect.contain(coord[0], coord[1]);
  7382. };
  7383. Displayable.prototype.getPaintRect = function () {
  7384. var rect = this._paintRect;
  7385. if (!this._paintRect || this.__dirty) {
  7386. var transform = this.transform;
  7387. var elRect = this.getBoundingRect();
  7388. var style = this.style;
  7389. var shadowSize = style.shadowBlur || 0;
  7390. var shadowOffsetX = style.shadowOffsetX || 0;
  7391. var shadowOffsetY = style.shadowOffsetY || 0;
  7392. rect = this._paintRect || (this._paintRect = new BoundingRect(0, 0, 0, 0));
  7393. if (transform) {
  7394. BoundingRect.applyTransform(rect, elRect, transform);
  7395. }
  7396. else {
  7397. rect.copy(elRect);
  7398. }
  7399. if (shadowSize || shadowOffsetX || shadowOffsetY) {
  7400. rect.width += shadowSize * 2 + Math.abs(shadowOffsetX);
  7401. rect.height += shadowSize * 2 + Math.abs(shadowOffsetY);
  7402. rect.x = Math.min(rect.x, rect.x + shadowOffsetX - shadowSize);
  7403. rect.y = Math.min(rect.y, rect.y + shadowOffsetY - shadowSize);
  7404. }
  7405. var tolerance = this.dirtyRectTolerance;
  7406. if (!rect.isZero()) {
  7407. rect.x = Math.floor(rect.x - tolerance);
  7408. rect.y = Math.floor(rect.y - tolerance);
  7409. rect.width = Math.ceil(rect.width + 1 + tolerance * 2);
  7410. rect.height = Math.ceil(rect.height + 1 + tolerance * 2);
  7411. }
  7412. }
  7413. return rect;
  7414. };
  7415. Displayable.prototype.setPrevPaintRect = function (paintRect) {
  7416. if (paintRect) {
  7417. this._prevPaintRect = this._prevPaintRect || new BoundingRect(0, 0, 0, 0);
  7418. this._prevPaintRect.copy(paintRect);
  7419. }
  7420. else {
  7421. this._prevPaintRect = null;
  7422. }
  7423. };
  7424. Displayable.prototype.getPrevPaintRect = function () {
  7425. return this._prevPaintRect;
  7426. };
  7427. Displayable.prototype.animateStyle = function (loop) {
  7428. return this.animate('style', loop);
  7429. };
  7430. Displayable.prototype.updateDuringAnimation = function (targetKey) {
  7431. if (targetKey === 'style') {
  7432. this.dirtyStyle();
  7433. }
  7434. else {
  7435. this.markRedraw();
  7436. }
  7437. };
  7438. Displayable.prototype.attrKV = function (key, value) {
  7439. if (key !== 'style') {
  7440. _super.prototype.attrKV.call(this, key, value);
  7441. }
  7442. else {
  7443. if (!this.style) {
  7444. this.useStyle(value);
  7445. }
  7446. else {
  7447. this.setStyle(value);
  7448. }
  7449. }
  7450. };
  7451. Displayable.prototype.setStyle = function (keyOrObj, value) {
  7452. if (typeof keyOrObj === 'string') {
  7453. this.style[keyOrObj] = value;
  7454. }
  7455. else {
  7456. extend(this.style, keyOrObj);
  7457. }
  7458. this.dirtyStyle();
  7459. return this;
  7460. };
  7461. Displayable.prototype.dirtyStyle = function (notRedraw) {
  7462. if (!notRedraw) {
  7463. this.markRedraw();
  7464. }
  7465. this.__dirty |= STYLE_CHANGED_BIT;
  7466. if (this._rect) {
  7467. this._rect = null;
  7468. }
  7469. };
  7470. Displayable.prototype.dirty = function () {
  7471. this.dirtyStyle();
  7472. };
  7473. Displayable.prototype.styleChanged = function () {
  7474. return !!(this.__dirty & STYLE_CHANGED_BIT);
  7475. };
  7476. Displayable.prototype.styleUpdated = function () {
  7477. this.__dirty &= ~STYLE_CHANGED_BIT;
  7478. };
  7479. Displayable.prototype.createStyle = function (obj) {
  7480. return createObject(DEFAULT_COMMON_STYLE, obj);
  7481. };
  7482. Displayable.prototype.useStyle = function (obj) {
  7483. if (!obj[STYLE_MAGIC_KEY]) {
  7484. obj = this.createStyle(obj);
  7485. }
  7486. if (this.__inHover) {
  7487. this.__hoverStyle = obj;
  7488. }
  7489. else {
  7490. this.style = obj;
  7491. }
  7492. this.dirtyStyle();
  7493. };
  7494. Displayable.prototype.isStyleObject = function (obj) {
  7495. return obj[STYLE_MAGIC_KEY];
  7496. };
  7497. Displayable.prototype._innerSaveToNormal = function (toState) {
  7498. _super.prototype._innerSaveToNormal.call(this, toState);
  7499. var normalState = this._normalState;
  7500. if (toState.style && !normalState.style) {
  7501. normalState.style = this._mergeStyle(this.createStyle(), this.style);
  7502. }
  7503. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS$1);
  7504. };
  7505. Displayable.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  7506. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  7507. var needsRestoreToNormal = !(state && keepCurrentStates);
  7508. var targetStyle;
  7509. if (state && state.style) {
  7510. if (transition) {
  7511. if (keepCurrentStates) {
  7512. targetStyle = state.style;
  7513. }
  7514. else {
  7515. targetStyle = this._mergeStyle(this.createStyle(), normalState.style);
  7516. this._mergeStyle(targetStyle, state.style);
  7517. }
  7518. }
  7519. else {
  7520. targetStyle = this._mergeStyle(this.createStyle(), keepCurrentStates ? this.style : normalState.style);
  7521. this._mergeStyle(targetStyle, state.style);
  7522. }
  7523. }
  7524. else if (needsRestoreToNormal) {
  7525. targetStyle = normalState.style;
  7526. }
  7527. if (targetStyle) {
  7528. if (transition) {
  7529. var sourceStyle = this.style;
  7530. this.style = this.createStyle(needsRestoreToNormal ? {} : sourceStyle);
  7531. if (needsRestoreToNormal) {
  7532. var changedKeys = keys(sourceStyle);
  7533. for (var i = 0; i < changedKeys.length; i++) {
  7534. var key = changedKeys[i];
  7535. if (key in targetStyle) {
  7536. targetStyle[key] = targetStyle[key];
  7537. this.style[key] = sourceStyle[key];
  7538. }
  7539. }
  7540. }
  7541. var targetKeys = keys(targetStyle);
  7542. for (var i = 0; i < targetKeys.length; i++) {
  7543. var key = targetKeys[i];
  7544. this.style[key] = this.style[key];
  7545. }
  7546. this._transitionState(stateName, {
  7547. style: targetStyle
  7548. }, animationCfg, this.getAnimationStyleProps());
  7549. }
  7550. else {
  7551. this.useStyle(targetStyle);
  7552. }
  7553. }
  7554. var statesKeys = this.__inHover ? PRIMARY_STATES_KEYS_IN_HOVER_LAYER : PRIMARY_STATES_KEYS$1;
  7555. for (var i = 0; i < statesKeys.length; i++) {
  7556. var key = statesKeys[i];
  7557. if (state && state[key] != null) {
  7558. this[key] = state[key];
  7559. }
  7560. else if (needsRestoreToNormal) {
  7561. if (normalState[key] != null) {
  7562. this[key] = normalState[key];
  7563. }
  7564. }
  7565. }
  7566. };
  7567. Displayable.prototype._mergeStates = function (states) {
  7568. var mergedState = _super.prototype._mergeStates.call(this, states);
  7569. var mergedStyle;
  7570. for (var i = 0; i < states.length; i++) {
  7571. var state = states[i];
  7572. if (state.style) {
  7573. mergedStyle = mergedStyle || {};
  7574. this._mergeStyle(mergedStyle, state.style);
  7575. }
  7576. }
  7577. if (mergedStyle) {
  7578. mergedState.style = mergedStyle;
  7579. }
  7580. return mergedState;
  7581. };
  7582. Displayable.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  7583. extend(targetStyle, sourceStyle);
  7584. return targetStyle;
  7585. };
  7586. Displayable.prototype.getAnimationStyleProps = function () {
  7587. return DEFAULT_COMMON_ANIMATION_PROPS;
  7588. };
  7589. Displayable.initDefaultProps = (function () {
  7590. var dispProto = Displayable.prototype;
  7591. dispProto.type = 'displayable';
  7592. dispProto.invisible = false;
  7593. dispProto.z = 0;
  7594. dispProto.z2 = 0;
  7595. dispProto.zlevel = 0;
  7596. dispProto.culling = false;
  7597. dispProto.cursor = 'pointer';
  7598. dispProto.rectHover = false;
  7599. dispProto.incremental = false;
  7600. dispProto._rect = null;
  7601. dispProto.dirtyRectTolerance = 0;
  7602. dispProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT;
  7603. })();
  7604. return Displayable;
  7605. }(Element));
  7606. var tmpRect$1 = new BoundingRect(0, 0, 0, 0);
  7607. var viewRect = new BoundingRect(0, 0, 0, 0);
  7608. function isDisplayableCulled(el, width, height) {
  7609. tmpRect$1.copy(el.getBoundingRect());
  7610. if (el.transform) {
  7611. tmpRect$1.applyTransform(el.transform);
  7612. }
  7613. viewRect.width = width;
  7614. viewRect.height = height;
  7615. return !tmpRect$1.intersect(viewRect);
  7616. }
  7617. var mathMin$1 = Math.min;
  7618. var mathMax$1 = Math.max;
  7619. var mathSin = Math.sin;
  7620. var mathCos = Math.cos;
  7621. var PI2 = Math.PI * 2;
  7622. var start = create();
  7623. var end = create();
  7624. var extremity = create();
  7625. function fromPoints(points, min, max) {
  7626. if (points.length === 0) {
  7627. return;
  7628. }
  7629. var p = points[0];
  7630. var left = p[0];
  7631. var right = p[0];
  7632. var top = p[1];
  7633. var bottom = p[1];
  7634. for (var i = 1; i < points.length; i++) {
  7635. p = points[i];
  7636. left = mathMin$1(left, p[0]);
  7637. right = mathMax$1(right, p[0]);
  7638. top = mathMin$1(top, p[1]);
  7639. bottom = mathMax$1(bottom, p[1]);
  7640. }
  7641. min[0] = left;
  7642. min[1] = top;
  7643. max[0] = right;
  7644. max[1] = bottom;
  7645. }
  7646. function fromLine(x0, y0, x1, y1, min, max) {
  7647. min[0] = mathMin$1(x0, x1);
  7648. min[1] = mathMin$1(y0, y1);
  7649. max[0] = mathMax$1(x0, x1);
  7650. max[1] = mathMax$1(y0, y1);
  7651. }
  7652. var xDim = [];
  7653. var yDim = [];
  7654. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min, max) {
  7655. var cubicExtrema$1 = cubicExtrema;
  7656. var cubicAt$1 = cubicAt;
  7657. var n = cubicExtrema$1(x0, x1, x2, x3, xDim);
  7658. min[0] = Infinity;
  7659. min[1] = Infinity;
  7660. max[0] = -Infinity;
  7661. max[1] = -Infinity;
  7662. for (var i = 0; i < n; i++) {
  7663. var x = cubicAt$1(x0, x1, x2, x3, xDim[i]);
  7664. min[0] = mathMin$1(x, min[0]);
  7665. max[0] = mathMax$1(x, max[0]);
  7666. }
  7667. n = cubicExtrema$1(y0, y1, y2, y3, yDim);
  7668. for (var i = 0; i < n; i++) {
  7669. var y = cubicAt$1(y0, y1, y2, y3, yDim[i]);
  7670. min[1] = mathMin$1(y, min[1]);
  7671. max[1] = mathMax$1(y, max[1]);
  7672. }
  7673. min[0] = mathMin$1(x0, min[0]);
  7674. max[0] = mathMax$1(x0, max[0]);
  7675. min[0] = mathMin$1(x3, min[0]);
  7676. max[0] = mathMax$1(x3, max[0]);
  7677. min[1] = mathMin$1(y0, min[1]);
  7678. max[1] = mathMax$1(y0, max[1]);
  7679. min[1] = mathMin$1(y3, min[1]);
  7680. max[1] = mathMax$1(y3, max[1]);
  7681. }
  7682. function fromQuadratic(x0, y0, x1, y1, x2, y2, min, max) {
  7683. var quadraticExtremum$1 = quadraticExtremum;
  7684. var quadraticAt$1 = quadraticAt;
  7685. var tx = mathMax$1(mathMin$1(quadraticExtremum$1(x0, x1, x2), 1), 0);
  7686. var ty = mathMax$1(mathMin$1(quadraticExtremum$1(y0, y1, y2), 1), 0);
  7687. var x = quadraticAt$1(x0, x1, x2, tx);
  7688. var y = quadraticAt$1(y0, y1, y2, ty);
  7689. min[0] = mathMin$1(x0, x2, x);
  7690. min[1] = mathMin$1(y0, y2, y);
  7691. max[0] = mathMax$1(x0, x2, x);
  7692. max[1] = mathMax$1(y0, y2, y);
  7693. }
  7694. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min$1, max$1) {
  7695. var vec2Min = min;
  7696. var vec2Max = max;
  7697. var diff = Math.abs(startAngle - endAngle);
  7698. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  7699. min$1[0] = x - rx;
  7700. min$1[1] = y - ry;
  7701. max$1[0] = x + rx;
  7702. max$1[1] = y + ry;
  7703. return;
  7704. }
  7705. start[0] = mathCos(startAngle) * rx + x;
  7706. start[1] = mathSin(startAngle) * ry + y;
  7707. end[0] = mathCos(endAngle) * rx + x;
  7708. end[1] = mathSin(endAngle) * ry + y;
  7709. vec2Min(min$1, start, end);
  7710. vec2Max(max$1, start, end);
  7711. startAngle = startAngle % (PI2);
  7712. if (startAngle < 0) {
  7713. startAngle = startAngle + PI2;
  7714. }
  7715. endAngle = endAngle % (PI2);
  7716. if (endAngle < 0) {
  7717. endAngle = endAngle + PI2;
  7718. }
  7719. if (startAngle > endAngle && !anticlockwise) {
  7720. endAngle += PI2;
  7721. }
  7722. else if (startAngle < endAngle && anticlockwise) {
  7723. startAngle += PI2;
  7724. }
  7725. if (anticlockwise) {
  7726. var tmp = endAngle;
  7727. endAngle = startAngle;
  7728. startAngle = tmp;
  7729. }
  7730. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  7731. if (angle > startAngle) {
  7732. extremity[0] = mathCos(angle) * rx + x;
  7733. extremity[1] = mathSin(angle) * ry + y;
  7734. vec2Min(min$1, extremity, min$1);
  7735. vec2Max(max$1, extremity, max$1);
  7736. }
  7737. }
  7738. }
  7739. var CMD = {
  7740. M: 1,
  7741. L: 2,
  7742. C: 3,
  7743. Q: 4,
  7744. A: 5,
  7745. Z: 6,
  7746. R: 7
  7747. };
  7748. var tmpOutX = [];
  7749. var tmpOutY = [];
  7750. var min$1 = [];
  7751. var max$1 = [];
  7752. var min2 = [];
  7753. var max2 = [];
  7754. var mathMin$2 = Math.min;
  7755. var mathMax$2 = Math.max;
  7756. var mathCos$1 = Math.cos;
  7757. var mathSin$1 = Math.sin;
  7758. var mathAbs = Math.abs;
  7759. var PI = Math.PI;
  7760. var PI2$1 = PI * 2;
  7761. var hasTypedArray = typeof Float32Array !== 'undefined';
  7762. var tmpAngles = [];
  7763. function modPI2(radian) {
  7764. var n = Math.round(radian / PI * 1e8) / 1e8;
  7765. return (n % 2) * PI;
  7766. }
  7767. function normalizeArcAngles(angles, anticlockwise) {
  7768. var newStartAngle = modPI2(angles[0]);
  7769. if (newStartAngle < 0) {
  7770. newStartAngle += PI2$1;
  7771. }
  7772. var delta = newStartAngle - angles[0];
  7773. var newEndAngle = angles[1];
  7774. newEndAngle += delta;
  7775. if (!anticlockwise && newEndAngle - newStartAngle >= PI2$1) {
  7776. newEndAngle = newStartAngle + PI2$1;
  7777. }
  7778. else if (anticlockwise && newStartAngle - newEndAngle >= PI2$1) {
  7779. newEndAngle = newStartAngle - PI2$1;
  7780. }
  7781. else if (!anticlockwise && newStartAngle > newEndAngle) {
  7782. newEndAngle = newStartAngle + (PI2$1 - modPI2(newStartAngle - newEndAngle));
  7783. }
  7784. else if (anticlockwise && newStartAngle < newEndAngle) {
  7785. newEndAngle = newStartAngle - (PI2$1 - modPI2(newEndAngle - newStartAngle));
  7786. }
  7787. angles[0] = newStartAngle;
  7788. angles[1] = newEndAngle;
  7789. }
  7790. var PathProxy = (function () {
  7791. function PathProxy(notSaveData) {
  7792. this.dpr = 1;
  7793. this._xi = 0;
  7794. this._yi = 0;
  7795. this._x0 = 0;
  7796. this._y0 = 0;
  7797. this._len = 0;
  7798. if (notSaveData) {
  7799. this._saveData = false;
  7800. }
  7801. if (this._saveData) {
  7802. this.data = [];
  7803. }
  7804. }
  7805. PathProxy.prototype.increaseVersion = function () {
  7806. this._version++;
  7807. };
  7808. PathProxy.prototype.getVersion = function () {
  7809. return this._version;
  7810. };
  7811. PathProxy.prototype.setScale = function (sx, sy, segmentIgnoreThreshold) {
  7812. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  7813. if (segmentIgnoreThreshold > 0) {
  7814. this._ux = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  7815. this._uy = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  7816. }
  7817. };
  7818. PathProxy.prototype.setDPR = function (dpr) {
  7819. this.dpr = dpr;
  7820. };
  7821. PathProxy.prototype.setContext = function (ctx) {
  7822. this._ctx = ctx;
  7823. };
  7824. PathProxy.prototype.getContext = function () {
  7825. return this._ctx;
  7826. };
  7827. PathProxy.prototype.beginPath = function () {
  7828. this._ctx && this._ctx.beginPath();
  7829. this.reset();
  7830. return this;
  7831. };
  7832. PathProxy.prototype.reset = function () {
  7833. if (this._saveData) {
  7834. this._len = 0;
  7835. }
  7836. if (this._pathSegLen) {
  7837. this._pathSegLen = null;
  7838. this._pathLen = 0;
  7839. }
  7840. this._version++;
  7841. };
  7842. PathProxy.prototype.moveTo = function (x, y) {
  7843. this._drawPendingPt();
  7844. this.addData(CMD.M, x, y);
  7845. this._ctx && this._ctx.moveTo(x, y);
  7846. this._x0 = x;
  7847. this._y0 = y;
  7848. this._xi = x;
  7849. this._yi = y;
  7850. return this;
  7851. };
  7852. PathProxy.prototype.lineTo = function (x, y) {
  7853. var dx = mathAbs(x - this._xi);
  7854. var dy = mathAbs(y - this._yi);
  7855. var exceedUnit = dx > this._ux || dy > this._uy;
  7856. this.addData(CMD.L, x, y);
  7857. if (this._ctx && exceedUnit) {
  7858. this._ctx.lineTo(x, y);
  7859. }
  7860. if (exceedUnit) {
  7861. this._xi = x;
  7862. this._yi = y;
  7863. this._pendingPtDist = 0;
  7864. }
  7865. else {
  7866. var d2 = dx * dx + dy * dy;
  7867. if (d2 > this._pendingPtDist) {
  7868. this._pendingPtX = x;
  7869. this._pendingPtY = y;
  7870. this._pendingPtDist = d2;
  7871. }
  7872. }
  7873. return this;
  7874. };
  7875. PathProxy.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
  7876. this._drawPendingPt();
  7877. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  7878. if (this._ctx) {
  7879. this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  7880. }
  7881. this._xi = x3;
  7882. this._yi = y3;
  7883. return this;
  7884. };
  7885. PathProxy.prototype.quadraticCurveTo = function (x1, y1, x2, y2) {
  7886. this._drawPendingPt();
  7887. this.addData(CMD.Q, x1, y1, x2, y2);
  7888. if (this._ctx) {
  7889. this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  7890. }
  7891. this._xi = x2;
  7892. this._yi = y2;
  7893. return this;
  7894. };
  7895. PathProxy.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  7896. this._drawPendingPt();
  7897. tmpAngles[0] = startAngle;
  7898. tmpAngles[1] = endAngle;
  7899. normalizeArcAngles(tmpAngles, anticlockwise);
  7900. startAngle = tmpAngles[0];
  7901. endAngle = tmpAngles[1];
  7902. var delta = endAngle - startAngle;
  7903. this.addData(CMD.A, cx, cy, r, r, startAngle, delta, 0, anticlockwise ? 0 : 1);
  7904. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  7905. this._xi = mathCos$1(endAngle) * r + cx;
  7906. this._yi = mathSin$1(endAngle) * r + cy;
  7907. return this;
  7908. };
  7909. PathProxy.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  7910. this._drawPendingPt();
  7911. if (this._ctx) {
  7912. this._ctx.arcTo(x1, y1, x2, y2, radius);
  7913. }
  7914. return this;
  7915. };
  7916. PathProxy.prototype.rect = function (x, y, w, h) {
  7917. this._drawPendingPt();
  7918. this._ctx && this._ctx.rect(x, y, w, h);
  7919. this.addData(CMD.R, x, y, w, h);
  7920. return this;
  7921. };
  7922. PathProxy.prototype.closePath = function () {
  7923. this._drawPendingPt();
  7924. this.addData(CMD.Z);
  7925. var ctx = this._ctx;
  7926. var x0 = this._x0;
  7927. var y0 = this._y0;
  7928. if (ctx) {
  7929. ctx.closePath();
  7930. }
  7931. this._xi = x0;
  7932. this._yi = y0;
  7933. return this;
  7934. };
  7935. PathProxy.prototype.fill = function (ctx) {
  7936. ctx && ctx.fill();
  7937. this.toStatic();
  7938. };
  7939. PathProxy.prototype.stroke = function (ctx) {
  7940. ctx && ctx.stroke();
  7941. this.toStatic();
  7942. };
  7943. PathProxy.prototype.len = function () {
  7944. return this._len;
  7945. };
  7946. PathProxy.prototype.setData = function (data) {
  7947. var len = data.length;
  7948. if (!(this.data && this.data.length === len) && hasTypedArray) {
  7949. this.data = new Float32Array(len);
  7950. }
  7951. for (var i = 0; i < len; i++) {
  7952. this.data[i] = data[i];
  7953. }
  7954. this._len = len;
  7955. };
  7956. PathProxy.prototype.appendPath = function (path) {
  7957. if (!(path instanceof Array)) {
  7958. path = [path];
  7959. }
  7960. var len = path.length;
  7961. var appendSize = 0;
  7962. var offset = this._len;
  7963. for (var i = 0; i < len; i++) {
  7964. appendSize += path[i].len();
  7965. }
  7966. if (hasTypedArray && (this.data instanceof Float32Array)) {
  7967. this.data = new Float32Array(offset + appendSize);
  7968. }
  7969. for (var i = 0; i < len; i++) {
  7970. var appendPathData = path[i].data;
  7971. for (var k = 0; k < appendPathData.length; k++) {
  7972. this.data[offset++] = appendPathData[k];
  7973. }
  7974. }
  7975. this._len = offset;
  7976. };
  7977. PathProxy.prototype.addData = function (cmd, a, b, c, d, e, f, g, h) {
  7978. if (!this._saveData) {
  7979. return;
  7980. }
  7981. var data = this.data;
  7982. if (this._len + arguments.length > data.length) {
  7983. this._expandData();
  7984. data = this.data;
  7985. }
  7986. for (var i = 0; i < arguments.length; i++) {
  7987. data[this._len++] = arguments[i];
  7988. }
  7989. };
  7990. PathProxy.prototype._drawPendingPt = function () {
  7991. if (this._pendingPtDist > 0) {
  7992. this._ctx && this._ctx.lineTo(this._pendingPtX, this._pendingPtY);
  7993. this._pendingPtDist = 0;
  7994. }
  7995. };
  7996. PathProxy.prototype._expandData = function () {
  7997. if (!(this.data instanceof Array)) {
  7998. var newData = [];
  7999. for (var i = 0; i < this._len; i++) {
  8000. newData[i] = this.data[i];
  8001. }
  8002. this.data = newData;
  8003. }
  8004. };
  8005. PathProxy.prototype.toStatic = function () {
  8006. if (!this._saveData) {
  8007. return;
  8008. }
  8009. this._drawPendingPt();
  8010. var data = this.data;
  8011. if (data instanceof Array) {
  8012. data.length = this._len;
  8013. if (hasTypedArray && this._len > 11) {
  8014. this.data = new Float32Array(data);
  8015. }
  8016. }
  8017. };
  8018. PathProxy.prototype.getBoundingRect = function () {
  8019. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  8020. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  8021. var data = this.data;
  8022. var xi = 0;
  8023. var yi = 0;
  8024. var x0 = 0;
  8025. var y0 = 0;
  8026. var i;
  8027. for (i = 0; i < this._len;) {
  8028. var cmd = data[i++];
  8029. var isFirst = i === 1;
  8030. if (isFirst) {
  8031. xi = data[i];
  8032. yi = data[i + 1];
  8033. x0 = xi;
  8034. y0 = yi;
  8035. }
  8036. switch (cmd) {
  8037. case CMD.M:
  8038. xi = x0 = data[i++];
  8039. yi = y0 = data[i++];
  8040. min2[0] = x0;
  8041. min2[1] = y0;
  8042. max2[0] = x0;
  8043. max2[1] = y0;
  8044. break;
  8045. case CMD.L:
  8046. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  8047. xi = data[i++];
  8048. yi = data[i++];
  8049. break;
  8050. case CMD.C:
  8051. fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  8052. xi = data[i++];
  8053. yi = data[i++];
  8054. break;
  8055. case CMD.Q:
  8056. fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  8057. xi = data[i++];
  8058. yi = data[i++];
  8059. break;
  8060. case CMD.A:
  8061. var cx = data[i++];
  8062. var cy = data[i++];
  8063. var rx = data[i++];
  8064. var ry = data[i++];
  8065. var startAngle = data[i++];
  8066. var endAngle = data[i++] + startAngle;
  8067. i += 1;
  8068. var anticlockwise = !data[i++];
  8069. if (isFirst) {
  8070. x0 = mathCos$1(startAngle) * rx + cx;
  8071. y0 = mathSin$1(startAngle) * ry + cy;
  8072. }
  8073. fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  8074. xi = mathCos$1(endAngle) * rx + cx;
  8075. yi = mathSin$1(endAngle) * ry + cy;
  8076. break;
  8077. case CMD.R:
  8078. x0 = xi = data[i++];
  8079. y0 = yi = data[i++];
  8080. var width = data[i++];
  8081. var height = data[i++];
  8082. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  8083. break;
  8084. case CMD.Z:
  8085. xi = x0;
  8086. yi = y0;
  8087. break;
  8088. }
  8089. min(min$1, min$1, min2);
  8090. max(max$1, max$1, max2);
  8091. }
  8092. if (i === 0) {
  8093. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  8094. }
  8095. return new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  8096. };
  8097. PathProxy.prototype._calculateLength = function () {
  8098. var data = this.data;
  8099. var len = this._len;
  8100. var ux = this._ux;
  8101. var uy = this._uy;
  8102. var xi = 0;
  8103. var yi = 0;
  8104. var x0 = 0;
  8105. var y0 = 0;
  8106. if (!this._pathSegLen) {
  8107. this._pathSegLen = [];
  8108. }
  8109. var pathSegLen = this._pathSegLen;
  8110. var pathTotalLen = 0;
  8111. var segCount = 0;
  8112. for (var i = 0; i < len;) {
  8113. var cmd = data[i++];
  8114. var isFirst = i === 1;
  8115. if (isFirst) {
  8116. xi = data[i];
  8117. yi = data[i + 1];
  8118. x0 = xi;
  8119. y0 = yi;
  8120. }
  8121. var l = -1;
  8122. switch (cmd) {
  8123. case CMD.M:
  8124. xi = x0 = data[i++];
  8125. yi = y0 = data[i++];
  8126. break;
  8127. case CMD.L: {
  8128. var x2 = data[i++];
  8129. var y2 = data[i++];
  8130. var dx = x2 - xi;
  8131. var dy = y2 - yi;
  8132. if (mathAbs(dx) > ux || mathAbs(dy) > uy || i === len - 1) {
  8133. l = Math.sqrt(dx * dx + dy * dy);
  8134. xi = x2;
  8135. yi = y2;
  8136. }
  8137. break;
  8138. }
  8139. case CMD.C: {
  8140. var x1 = data[i++];
  8141. var y1 = data[i++];
  8142. var x2 = data[i++];
  8143. var y2 = data[i++];
  8144. var x3 = data[i++];
  8145. var y3 = data[i++];
  8146. l = cubicLength(xi, yi, x1, y1, x2, y2, x3, y3, 10);
  8147. xi = x3;
  8148. yi = y3;
  8149. break;
  8150. }
  8151. case CMD.Q: {
  8152. var x1 = data[i++];
  8153. var y1 = data[i++];
  8154. var x2 = data[i++];
  8155. var y2 = data[i++];
  8156. l = quadraticLength(xi, yi, x1, y1, x2, y2, 10);
  8157. xi = x2;
  8158. yi = y2;
  8159. break;
  8160. }
  8161. case CMD.A:
  8162. var cx = data[i++];
  8163. var cy = data[i++];
  8164. var rx = data[i++];
  8165. var ry = data[i++];
  8166. var startAngle = data[i++];
  8167. var delta = data[i++];
  8168. var endAngle = delta + startAngle;
  8169. i += 1;
  8170. if (isFirst) {
  8171. x0 = mathCos$1(startAngle) * rx + cx;
  8172. y0 = mathSin$1(startAngle) * ry + cy;
  8173. }
  8174. l = mathMax$2(rx, ry) * mathMin$2(PI2$1, Math.abs(delta));
  8175. xi = mathCos$1(endAngle) * rx + cx;
  8176. yi = mathSin$1(endAngle) * ry + cy;
  8177. break;
  8178. case CMD.R: {
  8179. x0 = xi = data[i++];
  8180. y0 = yi = data[i++];
  8181. var width = data[i++];
  8182. var height = data[i++];
  8183. l = width * 2 + height * 2;
  8184. break;
  8185. }
  8186. case CMD.Z: {
  8187. var dx = x0 - xi;
  8188. var dy = y0 - yi;
  8189. l = Math.sqrt(dx * dx + dy * dy);
  8190. xi = x0;
  8191. yi = y0;
  8192. break;
  8193. }
  8194. }
  8195. if (l >= 0) {
  8196. pathSegLen[segCount++] = l;
  8197. pathTotalLen += l;
  8198. }
  8199. }
  8200. this._pathLen = pathTotalLen;
  8201. return pathTotalLen;
  8202. };
  8203. PathProxy.prototype.rebuildPath = function (ctx, percent) {
  8204. var d = this.data;
  8205. var ux = this._ux;
  8206. var uy = this._uy;
  8207. var len = this._len;
  8208. var x0;
  8209. var y0;
  8210. var xi;
  8211. var yi;
  8212. var x;
  8213. var y;
  8214. var drawPart = percent < 1;
  8215. var pathSegLen;
  8216. var pathTotalLen;
  8217. var accumLength = 0;
  8218. var segCount = 0;
  8219. var displayedLength;
  8220. var pendingPtDist = 0;
  8221. var pendingPtX;
  8222. var pendingPtY;
  8223. if (drawPart) {
  8224. if (!this._pathSegLen) {
  8225. this._calculateLength();
  8226. }
  8227. pathSegLen = this._pathSegLen;
  8228. pathTotalLen = this._pathLen;
  8229. displayedLength = percent * pathTotalLen;
  8230. if (!displayedLength) {
  8231. return;
  8232. }
  8233. }
  8234. lo: for (var i = 0; i < len;) {
  8235. var cmd = d[i++];
  8236. var isFirst = i === 1;
  8237. if (isFirst) {
  8238. xi = d[i];
  8239. yi = d[i + 1];
  8240. x0 = xi;
  8241. y0 = yi;
  8242. }
  8243. if (cmd !== CMD.L && pendingPtDist > 0) {
  8244. ctx.lineTo(pendingPtX, pendingPtY);
  8245. pendingPtDist = 0;
  8246. }
  8247. switch (cmd) {
  8248. case CMD.M:
  8249. x0 = xi = d[i++];
  8250. y0 = yi = d[i++];
  8251. ctx.moveTo(xi, yi);
  8252. break;
  8253. case CMD.L: {
  8254. x = d[i++];
  8255. y = d[i++];
  8256. var dx = mathAbs(x - xi);
  8257. var dy = mathAbs(y - yi);
  8258. if (dx > ux || dy > uy) {
  8259. if (drawPart) {
  8260. var l = pathSegLen[segCount++];
  8261. if (accumLength + l > displayedLength) {
  8262. var t = (displayedLength - accumLength) / l;
  8263. ctx.lineTo(xi * (1 - t) + x * t, yi * (1 - t) + y * t);
  8264. break lo;
  8265. }
  8266. accumLength += l;
  8267. }
  8268. ctx.lineTo(x, y);
  8269. xi = x;
  8270. yi = y;
  8271. pendingPtDist = 0;
  8272. }
  8273. else {
  8274. var d2 = dx * dx + dy * dy;
  8275. if (d2 > pendingPtDist) {
  8276. pendingPtX = x;
  8277. pendingPtY = y;
  8278. pendingPtDist = d2;
  8279. }
  8280. }
  8281. break;
  8282. }
  8283. case CMD.C: {
  8284. var x1 = d[i++];
  8285. var y1 = d[i++];
  8286. var x2 = d[i++];
  8287. var y2 = d[i++];
  8288. var x3 = d[i++];
  8289. var y3 = d[i++];
  8290. if (drawPart) {
  8291. var l = pathSegLen[segCount++];
  8292. if (accumLength + l > displayedLength) {
  8293. var t = (displayedLength - accumLength) / l;
  8294. cubicSubdivide(xi, x1, x2, x3, t, tmpOutX);
  8295. cubicSubdivide(yi, y1, y2, y3, t, tmpOutY);
  8296. ctx.bezierCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2], tmpOutX[3], tmpOutY[3]);
  8297. break lo;
  8298. }
  8299. accumLength += l;
  8300. }
  8301. ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  8302. xi = x3;
  8303. yi = y3;
  8304. break;
  8305. }
  8306. case CMD.Q: {
  8307. var x1 = d[i++];
  8308. var y1 = d[i++];
  8309. var x2 = d[i++];
  8310. var y2 = d[i++];
  8311. if (drawPart) {
  8312. var l = pathSegLen[segCount++];
  8313. if (accumLength + l > displayedLength) {
  8314. var t = (displayedLength - accumLength) / l;
  8315. quadraticSubdivide(xi, x1, x2, t, tmpOutX);
  8316. quadraticSubdivide(yi, y1, y2, t, tmpOutY);
  8317. ctx.quadraticCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2]);
  8318. break lo;
  8319. }
  8320. accumLength += l;
  8321. }
  8322. ctx.quadraticCurveTo(x1, y1, x2, y2);
  8323. xi = x2;
  8324. yi = y2;
  8325. break;
  8326. }
  8327. case CMD.A:
  8328. var cx = d[i++];
  8329. var cy = d[i++];
  8330. var rx = d[i++];
  8331. var ry = d[i++];
  8332. var startAngle = d[i++];
  8333. var delta = d[i++];
  8334. var psi = d[i++];
  8335. var anticlockwise = !d[i++];
  8336. var r = (rx > ry) ? rx : ry;
  8337. var isEllipse = mathAbs(rx - ry) > 1e-3;
  8338. var endAngle = startAngle + delta;
  8339. var breakBuild = false;
  8340. if (drawPart) {
  8341. var l = pathSegLen[segCount++];
  8342. if (accumLength + l > displayedLength) {
  8343. endAngle = startAngle + delta * (displayedLength - accumLength) / l;
  8344. breakBuild = true;
  8345. }
  8346. accumLength += l;
  8347. }
  8348. if (isEllipse && ctx.ellipse) {
  8349. ctx.ellipse(cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise);
  8350. }
  8351. else {
  8352. ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  8353. }
  8354. if (breakBuild) {
  8355. break lo;
  8356. }
  8357. if (isFirst) {
  8358. x0 = mathCos$1(startAngle) * rx + cx;
  8359. y0 = mathSin$1(startAngle) * ry + cy;
  8360. }
  8361. xi = mathCos$1(endAngle) * rx + cx;
  8362. yi = mathSin$1(endAngle) * ry + cy;
  8363. break;
  8364. case CMD.R:
  8365. x0 = xi = d[i];
  8366. y0 = yi = d[i + 1];
  8367. x = d[i++];
  8368. y = d[i++];
  8369. var width = d[i++];
  8370. var height = d[i++];
  8371. if (drawPart) {
  8372. var l = pathSegLen[segCount++];
  8373. if (accumLength + l > displayedLength) {
  8374. var d_1 = displayedLength - accumLength;
  8375. ctx.moveTo(x, y);
  8376. ctx.lineTo(x + mathMin$2(d_1, width), y);
  8377. d_1 -= width;
  8378. if (d_1 > 0) {
  8379. ctx.lineTo(x + width, y + mathMin$2(d_1, height));
  8380. }
  8381. d_1 -= height;
  8382. if (d_1 > 0) {
  8383. ctx.lineTo(x + mathMax$2(width - d_1, 0), y + height);
  8384. }
  8385. d_1 -= width;
  8386. if (d_1 > 0) {
  8387. ctx.lineTo(x, y + mathMax$2(height - d_1, 0));
  8388. }
  8389. break lo;
  8390. }
  8391. accumLength += l;
  8392. }
  8393. ctx.rect(x, y, width, height);
  8394. break;
  8395. case CMD.Z:
  8396. if (drawPart) {
  8397. var l = pathSegLen[segCount++];
  8398. if (accumLength + l > displayedLength) {
  8399. var t = (displayedLength - accumLength) / l;
  8400. ctx.lineTo(xi * (1 - t) + x0 * t, yi * (1 - t) + y0 * t);
  8401. break lo;
  8402. }
  8403. accumLength += l;
  8404. }
  8405. ctx.closePath();
  8406. xi = x0;
  8407. yi = y0;
  8408. }
  8409. }
  8410. };
  8411. PathProxy.prototype.clone = function () {
  8412. var newProxy = new PathProxy();
  8413. var data = this.data;
  8414. newProxy.data = data.slice ? data.slice()
  8415. : Array.prototype.slice.call(data);
  8416. newProxy._len = this._len;
  8417. return newProxy;
  8418. };
  8419. PathProxy.CMD = CMD;
  8420. PathProxy.initDefaultProps = (function () {
  8421. var proto = PathProxy.prototype;
  8422. proto._saveData = true;
  8423. proto._ux = 0;
  8424. proto._uy = 0;
  8425. proto._pendingPtDist = 0;
  8426. proto._version = 0;
  8427. })();
  8428. return PathProxy;
  8429. }());
  8430. function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
  8431. if (lineWidth === 0) {
  8432. return false;
  8433. }
  8434. var _l = lineWidth;
  8435. var _a = 0;
  8436. var _b = x0;
  8437. if ((y > y0 + _l && y > y1 + _l)
  8438. || (y < y0 - _l && y < y1 - _l)
  8439. || (x > x0 + _l && x > x1 + _l)
  8440. || (x < x0 - _l && x < x1 - _l)) {
  8441. return false;
  8442. }
  8443. if (x0 !== x1) {
  8444. _a = (y0 - y1) / (x0 - x1);
  8445. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  8446. }
  8447. else {
  8448. return Math.abs(x - x0) <= _l / 2;
  8449. }
  8450. var tmp = _a * x - y + _b;
  8451. var _s = tmp * tmp / (_a * _a + 1);
  8452. return _s <= _l / 2 * _l / 2;
  8453. }
  8454. function containStroke$1(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  8455. if (lineWidth === 0) {
  8456. return false;
  8457. }
  8458. var _l = lineWidth;
  8459. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  8460. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  8461. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  8462. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)) {
  8463. return false;
  8464. }
  8465. var d = cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  8466. return d <= _l / 2;
  8467. }
  8468. function containStroke$2(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  8469. if (lineWidth === 0) {
  8470. return false;
  8471. }
  8472. var _l = lineWidth;
  8473. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l)
  8474. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  8475. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  8476. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)) {
  8477. return false;
  8478. }
  8479. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  8480. return d <= _l / 2;
  8481. }
  8482. var PI2$2 = Math.PI * 2;
  8483. function normalizeRadian(angle) {
  8484. angle %= PI2$2;
  8485. if (angle < 0) {
  8486. angle += PI2$2;
  8487. }
  8488. return angle;
  8489. }
  8490. var PI2$3 = Math.PI * 2;
  8491. function containStroke$3(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  8492. if (lineWidth === 0) {
  8493. return false;
  8494. }
  8495. var _l = lineWidth;
  8496. x -= cx;
  8497. y -= cy;
  8498. var d = Math.sqrt(x * x + y * y);
  8499. if ((d - _l > r) || (d + _l < r)) {
  8500. return false;
  8501. }
  8502. if (Math.abs(startAngle - endAngle) % PI2$3 < 1e-4) {
  8503. return true;
  8504. }
  8505. if (anticlockwise) {
  8506. var tmp = startAngle;
  8507. startAngle = normalizeRadian(endAngle);
  8508. endAngle = normalizeRadian(tmp);
  8509. }
  8510. else {
  8511. startAngle = normalizeRadian(startAngle);
  8512. endAngle = normalizeRadian(endAngle);
  8513. }
  8514. if (startAngle > endAngle) {
  8515. endAngle += PI2$3;
  8516. }
  8517. var angle = Math.atan2(y, x);
  8518. if (angle < 0) {
  8519. angle += PI2$3;
  8520. }
  8521. return (angle >= startAngle && angle <= endAngle)
  8522. || (angle + PI2$3 >= startAngle && angle + PI2$3 <= endAngle);
  8523. }
  8524. function windingLine(x0, y0, x1, y1, x, y) {
  8525. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  8526. return 0;
  8527. }
  8528. if (y1 === y0) {
  8529. return 0;
  8530. }
  8531. var t = (y - y0) / (y1 - y0);
  8532. var dir = y1 < y0 ? 1 : -1;
  8533. if (t === 1 || t === 0) {
  8534. dir = y1 < y0 ? 0.5 : -0.5;
  8535. }
  8536. var x_ = t * (x1 - x0) + x0;
  8537. return x_ === x ? Infinity : x_ > x ? dir : 0;
  8538. }
  8539. var CMD$1 = PathProxy.CMD;
  8540. var PI2$4 = Math.PI * 2;
  8541. var EPSILON$3 = 1e-4;
  8542. function isAroundEqual(a, b) {
  8543. return Math.abs(a - b) < EPSILON$3;
  8544. }
  8545. var roots = [-1, -1, -1];
  8546. var extrema = [-1, -1];
  8547. function swapExtrema() {
  8548. var tmp = extrema[0];
  8549. extrema[0] = extrema[1];
  8550. extrema[1] = tmp;
  8551. }
  8552. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  8553. if ((y > y0 && y > y1 && y > y2 && y > y3)
  8554. || (y < y0 && y < y1 && y < y2 && y < y3)) {
  8555. return 0;
  8556. }
  8557. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  8558. if (nRoots === 0) {
  8559. return 0;
  8560. }
  8561. else {
  8562. var w = 0;
  8563. var nExtrema = -1;
  8564. var y0_ = void 0;
  8565. var y1_ = void 0;
  8566. for (var i = 0; i < nRoots; i++) {
  8567. var t = roots[i];
  8568. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  8569. var x_ = cubicAt(x0, x1, x2, x3, t);
  8570. if (x_ < x) {
  8571. continue;
  8572. }
  8573. if (nExtrema < 0) {
  8574. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  8575. if (extrema[1] < extrema[0] && nExtrema > 1) {
  8576. swapExtrema();
  8577. }
  8578. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  8579. if (nExtrema > 1) {
  8580. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  8581. }
  8582. }
  8583. if (nExtrema === 2) {
  8584. if (t < extrema[0]) {
  8585. w += y0_ < y0 ? unit : -unit;
  8586. }
  8587. else if (t < extrema[1]) {
  8588. w += y1_ < y0_ ? unit : -unit;
  8589. }
  8590. else {
  8591. w += y3 < y1_ ? unit : -unit;
  8592. }
  8593. }
  8594. else {
  8595. if (t < extrema[0]) {
  8596. w += y0_ < y0 ? unit : -unit;
  8597. }
  8598. else {
  8599. w += y3 < y0_ ? unit : -unit;
  8600. }
  8601. }
  8602. }
  8603. return w;
  8604. }
  8605. }
  8606. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  8607. if ((y > y0 && y > y1 && y > y2)
  8608. || (y < y0 && y < y1 && y < y2)) {
  8609. return 0;
  8610. }
  8611. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  8612. if (nRoots === 0) {
  8613. return 0;
  8614. }
  8615. else {
  8616. var t = quadraticExtremum(y0, y1, y2);
  8617. if (t >= 0 && t <= 1) {
  8618. var w = 0;
  8619. var y_ = quadraticAt(y0, y1, y2, t);
  8620. for (var i = 0; i < nRoots; i++) {
  8621. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  8622. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  8623. if (x_ < x) {
  8624. continue;
  8625. }
  8626. if (roots[i] < t) {
  8627. w += y_ < y0 ? unit : -unit;
  8628. }
  8629. else {
  8630. w += y2 < y_ ? unit : -unit;
  8631. }
  8632. }
  8633. return w;
  8634. }
  8635. else {
  8636. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  8637. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  8638. if (x_ < x) {
  8639. return 0;
  8640. }
  8641. return y2 < y0 ? unit : -unit;
  8642. }
  8643. }
  8644. }
  8645. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  8646. y -= cy;
  8647. if (y > r || y < -r) {
  8648. return 0;
  8649. }
  8650. var tmp = Math.sqrt(r * r - y * y);
  8651. roots[0] = -tmp;
  8652. roots[1] = tmp;
  8653. var dTheta = Math.abs(startAngle - endAngle);
  8654. if (dTheta < 1e-4) {
  8655. return 0;
  8656. }
  8657. if (dTheta >= PI2$4 - 1e-4) {
  8658. startAngle = 0;
  8659. endAngle = PI2$4;
  8660. var dir = anticlockwise ? 1 : -1;
  8661. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  8662. return dir;
  8663. }
  8664. else {
  8665. return 0;
  8666. }
  8667. }
  8668. if (startAngle > endAngle) {
  8669. var tmp_1 = startAngle;
  8670. startAngle = endAngle;
  8671. endAngle = tmp_1;
  8672. }
  8673. if (startAngle < 0) {
  8674. startAngle += PI2$4;
  8675. endAngle += PI2$4;
  8676. }
  8677. var w = 0;
  8678. for (var i = 0; i < 2; i++) {
  8679. var x_ = roots[i];
  8680. if (x_ + cx > x) {
  8681. var angle = Math.atan2(y, x_);
  8682. var dir = anticlockwise ? 1 : -1;
  8683. if (angle < 0) {
  8684. angle = PI2$4 + angle;
  8685. }
  8686. if ((angle >= startAngle && angle <= endAngle)
  8687. || (angle + PI2$4 >= startAngle && angle + PI2$4 <= endAngle)) {
  8688. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  8689. dir = -dir;
  8690. }
  8691. w += dir;
  8692. }
  8693. }
  8694. }
  8695. return w;
  8696. }
  8697. function containPath(path, lineWidth, isStroke, x, y) {
  8698. var data = path.data;
  8699. var len = path.len();
  8700. var w = 0;
  8701. var xi = 0;
  8702. var yi = 0;
  8703. var x0 = 0;
  8704. var y0 = 0;
  8705. var x1;
  8706. var y1;
  8707. for (var i = 0; i < len;) {
  8708. var cmd = data[i++];
  8709. var isFirst = i === 1;
  8710. if (cmd === CMD$1.M && i > 1) {
  8711. if (!isStroke) {
  8712. w += windingLine(xi, yi, x0, y0, x, y);
  8713. }
  8714. }
  8715. if (isFirst) {
  8716. xi = data[i];
  8717. yi = data[i + 1];
  8718. x0 = xi;
  8719. y0 = yi;
  8720. }
  8721. switch (cmd) {
  8722. case CMD$1.M:
  8723. x0 = data[i++];
  8724. y0 = data[i++];
  8725. xi = x0;
  8726. yi = y0;
  8727. break;
  8728. case CMD$1.L:
  8729. if (isStroke) {
  8730. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  8731. return true;
  8732. }
  8733. }
  8734. else {
  8735. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  8736. }
  8737. xi = data[i++];
  8738. yi = data[i++];
  8739. break;
  8740. case CMD$1.C:
  8741. if (isStroke) {
  8742. if (containStroke$1(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8743. return true;
  8744. }
  8745. }
  8746. else {
  8747. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8748. }
  8749. xi = data[i++];
  8750. yi = data[i++];
  8751. break;
  8752. case CMD$1.Q:
  8753. if (isStroke) {
  8754. if (containStroke$2(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8755. return true;
  8756. }
  8757. }
  8758. else {
  8759. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8760. }
  8761. xi = data[i++];
  8762. yi = data[i++];
  8763. break;
  8764. case CMD$1.A:
  8765. var cx = data[i++];
  8766. var cy = data[i++];
  8767. var rx = data[i++];
  8768. var ry = data[i++];
  8769. var theta = data[i++];
  8770. var dTheta = data[i++];
  8771. i += 1;
  8772. var anticlockwise = !!(1 - data[i++]);
  8773. x1 = Math.cos(theta) * rx + cx;
  8774. y1 = Math.sin(theta) * ry + cy;
  8775. if (!isFirst) {
  8776. w += windingLine(xi, yi, x1, y1, x, y);
  8777. }
  8778. else {
  8779. x0 = x1;
  8780. y0 = y1;
  8781. }
  8782. var _x = (x - cx) * ry / rx + cx;
  8783. if (isStroke) {
  8784. if (containStroke$3(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  8785. return true;
  8786. }
  8787. }
  8788. else {
  8789. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  8790. }
  8791. xi = Math.cos(theta + dTheta) * rx + cx;
  8792. yi = Math.sin(theta + dTheta) * ry + cy;
  8793. break;
  8794. case CMD$1.R:
  8795. x0 = xi = data[i++];
  8796. y0 = yi = data[i++];
  8797. var width = data[i++];
  8798. var height = data[i++];
  8799. x1 = x0 + width;
  8800. y1 = y0 + height;
  8801. if (isStroke) {
  8802. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  8803. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  8804. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  8805. || containStroke(x0, y1, x0, y0, lineWidth, x, y)) {
  8806. return true;
  8807. }
  8808. }
  8809. else {
  8810. w += windingLine(x1, y0, x1, y1, x, y);
  8811. w += windingLine(x0, y1, x0, y0, x, y);
  8812. }
  8813. break;
  8814. case CMD$1.Z:
  8815. if (isStroke) {
  8816. if (containStroke(xi, yi, x0, y0, lineWidth, x, y)) {
  8817. return true;
  8818. }
  8819. }
  8820. else {
  8821. w += windingLine(xi, yi, x0, y0, x, y);
  8822. }
  8823. xi = x0;
  8824. yi = y0;
  8825. break;
  8826. }
  8827. }
  8828. if (!isStroke && !isAroundEqual(yi, y0)) {
  8829. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  8830. }
  8831. return w !== 0;
  8832. }
  8833. function contain(pathProxy, x, y) {
  8834. return containPath(pathProxy, 0, false, x, y);
  8835. }
  8836. function containStroke$4(pathProxy, lineWidth, x, y) {
  8837. return containPath(pathProxy, lineWidth, true, x, y);
  8838. }
  8839. var DEFAULT_PATH_STYLE = defaults({
  8840. fill: '#000',
  8841. stroke: null,
  8842. strokePercent: 1,
  8843. fillOpacity: 1,
  8844. strokeOpacity: 1,
  8845. lineDashOffset: 0,
  8846. lineWidth: 1,
  8847. lineCap: 'butt',
  8848. miterLimit: 10,
  8849. strokeNoScale: false,
  8850. strokeFirst: false
  8851. }, DEFAULT_COMMON_STYLE);
  8852. var DEFAULT_PATH_ANIMATION_PROPS = {
  8853. style: defaults({
  8854. fill: true,
  8855. stroke: true,
  8856. strokePercent: true,
  8857. fillOpacity: true,
  8858. strokeOpacity: true,
  8859. lineDashOffset: true,
  8860. lineWidth: true,
  8861. miterLimit: true
  8862. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  8863. };
  8864. var pathCopyParams = TRANSFORMABLE_PROPS.concat(['invisible',
  8865. 'culling', 'z', 'z2', 'zlevel', 'parent'
  8866. ]);
  8867. var Path = (function (_super) {
  8868. __extends(Path, _super);
  8869. function Path(opts) {
  8870. return _super.call(this, opts) || this;
  8871. }
  8872. Path.prototype.update = function () {
  8873. var _this = this;
  8874. _super.prototype.update.call(this);
  8875. var style = this.style;
  8876. if (style.decal) {
  8877. var decalEl = this._decalEl = this._decalEl || new Path();
  8878. if (decalEl.buildPath === Path.prototype.buildPath) {
  8879. decalEl.buildPath = function (ctx) {
  8880. _this.buildPath(ctx, _this.shape);
  8881. };
  8882. }
  8883. decalEl.silent = true;
  8884. var decalElStyle = decalEl.style;
  8885. for (var key in style) {
  8886. if (decalElStyle[key] !== style[key]) {
  8887. decalElStyle[key] = style[key];
  8888. }
  8889. }
  8890. decalElStyle.fill = style.fill ? style.decal : null;
  8891. decalElStyle.decal = null;
  8892. decalElStyle.shadowColor = null;
  8893. style.strokeFirst && (decalElStyle.stroke = null);
  8894. for (var i = 0; i < pathCopyParams.length; ++i) {
  8895. decalEl[pathCopyParams[i]] = this[pathCopyParams[i]];
  8896. }
  8897. decalEl.__dirty |= REDRAW_BIT;
  8898. }
  8899. else if (this._decalEl) {
  8900. this._decalEl = null;
  8901. }
  8902. };
  8903. Path.prototype.getDecalElement = function () {
  8904. return this._decalEl;
  8905. };
  8906. Path.prototype._init = function (props) {
  8907. var keysArr = keys(props);
  8908. this.shape = this.getDefaultShape();
  8909. var defaultStyle = this.getDefaultStyle();
  8910. if (defaultStyle) {
  8911. this.useStyle(defaultStyle);
  8912. }
  8913. for (var i = 0; i < keysArr.length; i++) {
  8914. var key = keysArr[i];
  8915. var value = props[key];
  8916. if (key === 'style') {
  8917. if (!this.style) {
  8918. this.useStyle(value);
  8919. }
  8920. else {
  8921. extend(this.style, value);
  8922. }
  8923. }
  8924. else if (key === 'shape') {
  8925. extend(this.shape, value);
  8926. }
  8927. else {
  8928. _super.prototype.attrKV.call(this, key, value);
  8929. }
  8930. }
  8931. if (!this.style) {
  8932. this.useStyle({});
  8933. }
  8934. };
  8935. Path.prototype.getDefaultStyle = function () {
  8936. return null;
  8937. };
  8938. Path.prototype.getDefaultShape = function () {
  8939. return {};
  8940. };
  8941. Path.prototype.canBeInsideText = function () {
  8942. return this.hasFill();
  8943. };
  8944. Path.prototype.getInsideTextFill = function () {
  8945. var pathFill = this.style.fill;
  8946. if (pathFill !== 'none') {
  8947. if (isString(pathFill)) {
  8948. var fillLum = lum(pathFill, 0);
  8949. if (fillLum > 0.5) {
  8950. return DARK_LABEL_COLOR;
  8951. }
  8952. else if (fillLum > 0.2) {
  8953. return LIGHTER_LABEL_COLOR;
  8954. }
  8955. return LIGHT_LABEL_COLOR;
  8956. }
  8957. else if (pathFill) {
  8958. return LIGHT_LABEL_COLOR;
  8959. }
  8960. }
  8961. return DARK_LABEL_COLOR;
  8962. };
  8963. Path.prototype.getInsideTextStroke = function (textFill) {
  8964. var pathFill = this.style.fill;
  8965. if (isString(pathFill)) {
  8966. var zr = this.__zr;
  8967. var isDarkMode = !!(zr && zr.isDarkMode());
  8968. var isDarkLabel = lum(textFill, 0) < DARK_MODE_THRESHOLD;
  8969. if (isDarkMode === isDarkLabel) {
  8970. return pathFill;
  8971. }
  8972. }
  8973. };
  8974. Path.prototype.buildPath = function (ctx, shapeCfg, inBatch) { };
  8975. Path.prototype.pathUpdated = function () {
  8976. this.__dirty &= ~SHAPE_CHANGED_BIT;
  8977. };
  8978. Path.prototype.getUpdatedPathProxy = function (inBatch) {
  8979. !this.path && this.createPathProxy();
  8980. this.path.beginPath();
  8981. this.buildPath(this.path, this.shape, inBatch);
  8982. return this.path;
  8983. };
  8984. Path.prototype.createPathProxy = function () {
  8985. this.path = new PathProxy(false);
  8986. };
  8987. Path.prototype.hasStroke = function () {
  8988. var style = this.style;
  8989. var stroke = style.stroke;
  8990. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  8991. };
  8992. Path.prototype.hasFill = function () {
  8993. var style = this.style;
  8994. var fill = style.fill;
  8995. return fill != null && fill !== 'none';
  8996. };
  8997. Path.prototype.getBoundingRect = function () {
  8998. var rect = this._rect;
  8999. var style = this.style;
  9000. var needsUpdateRect = !rect;
  9001. if (needsUpdateRect) {
  9002. var firstInvoke = false;
  9003. if (!this.path) {
  9004. firstInvoke = true;
  9005. this.createPathProxy();
  9006. }
  9007. var path = this.path;
  9008. if (firstInvoke || (this.__dirty & SHAPE_CHANGED_BIT)) {
  9009. path.beginPath();
  9010. this.buildPath(path, this.shape, false);
  9011. this.pathUpdated();
  9012. }
  9013. rect = path.getBoundingRect();
  9014. }
  9015. this._rect = rect;
  9016. if (this.hasStroke() && this.path && this.path.len() > 0) {
  9017. var rectStroke = this._rectStroke || (this._rectStroke = rect.clone());
  9018. if (this.__dirty || needsUpdateRect) {
  9019. rectStroke.copy(rect);
  9020. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  9021. var w = style.lineWidth;
  9022. if (!this.hasFill()) {
  9023. var strokeContainThreshold = this.strokeContainThreshold;
  9024. w = Math.max(w, strokeContainThreshold == null ? 4 : strokeContainThreshold);
  9025. }
  9026. if (lineScale > 1e-10) {
  9027. rectStroke.width += w / lineScale;
  9028. rectStroke.height += w / lineScale;
  9029. rectStroke.x -= w / lineScale / 2;
  9030. rectStroke.y -= w / lineScale / 2;
  9031. }
  9032. }
  9033. return rectStroke;
  9034. }
  9035. return rect;
  9036. };
  9037. Path.prototype.contain = function (x, y) {
  9038. var localPos = this.transformCoordToLocal(x, y);
  9039. var rect = this.getBoundingRect();
  9040. var style = this.style;
  9041. x = localPos[0];
  9042. y = localPos[1];
  9043. if (rect.contain(x, y)) {
  9044. var pathProxy = this.path;
  9045. if (this.hasStroke()) {
  9046. var lineWidth = style.lineWidth;
  9047. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  9048. if (lineScale > 1e-10) {
  9049. if (!this.hasFill()) {
  9050. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  9051. }
  9052. if (containStroke$4(pathProxy, lineWidth / lineScale, x, y)) {
  9053. return true;
  9054. }
  9055. }
  9056. }
  9057. if (this.hasFill()) {
  9058. return contain(pathProxy, x, y);
  9059. }
  9060. }
  9061. return false;
  9062. };
  9063. Path.prototype.dirtyShape = function () {
  9064. this.__dirty |= SHAPE_CHANGED_BIT;
  9065. if (this._rect) {
  9066. this._rect = null;
  9067. }
  9068. if (this._decalEl) {
  9069. this._decalEl.dirtyShape();
  9070. }
  9071. this.markRedraw();
  9072. };
  9073. Path.prototype.dirty = function () {
  9074. this.dirtyStyle();
  9075. this.dirtyShape();
  9076. };
  9077. Path.prototype.animateShape = function (loop) {
  9078. return this.animate('shape', loop);
  9079. };
  9080. Path.prototype.updateDuringAnimation = function (targetKey) {
  9081. if (targetKey === 'style') {
  9082. this.dirtyStyle();
  9083. }
  9084. else if (targetKey === 'shape') {
  9085. this.dirtyShape();
  9086. }
  9087. else {
  9088. this.markRedraw();
  9089. }
  9090. };
  9091. Path.prototype.attrKV = function (key, value) {
  9092. if (key === 'shape') {
  9093. this.setShape(value);
  9094. }
  9095. else {
  9096. _super.prototype.attrKV.call(this, key, value);
  9097. }
  9098. };
  9099. Path.prototype.setShape = function (keyOrObj, value) {
  9100. var shape = this.shape;
  9101. if (!shape) {
  9102. shape = this.shape = {};
  9103. }
  9104. if (typeof keyOrObj === 'string') {
  9105. shape[keyOrObj] = value;
  9106. }
  9107. else {
  9108. extend(shape, keyOrObj);
  9109. }
  9110. this.dirtyShape();
  9111. return this;
  9112. };
  9113. Path.prototype.shapeChanged = function () {
  9114. return !!(this.__dirty & SHAPE_CHANGED_BIT);
  9115. };
  9116. Path.prototype.createStyle = function (obj) {
  9117. return createObject(DEFAULT_PATH_STYLE, obj);
  9118. };
  9119. Path.prototype._innerSaveToNormal = function (toState) {
  9120. _super.prototype._innerSaveToNormal.call(this, toState);
  9121. var normalState = this._normalState;
  9122. if (toState.shape && !normalState.shape) {
  9123. normalState.shape = extend({}, this.shape);
  9124. }
  9125. };
  9126. Path.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  9127. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  9128. var needsRestoreToNormal = !(state && keepCurrentStates);
  9129. var targetShape;
  9130. if (state && state.shape) {
  9131. if (transition) {
  9132. if (keepCurrentStates) {
  9133. targetShape = state.shape;
  9134. }
  9135. else {
  9136. targetShape = extend({}, normalState.shape);
  9137. extend(targetShape, state.shape);
  9138. }
  9139. }
  9140. else {
  9141. targetShape = extend({}, keepCurrentStates ? this.shape : normalState.shape);
  9142. extend(targetShape, state.shape);
  9143. }
  9144. }
  9145. else if (needsRestoreToNormal) {
  9146. targetShape = normalState.shape;
  9147. }
  9148. if (targetShape) {
  9149. if (transition) {
  9150. this.shape = extend({}, this.shape);
  9151. var targetShapePrimaryProps = {};
  9152. var shapeKeys = keys(targetShape);
  9153. for (var i = 0; i < shapeKeys.length; i++) {
  9154. var key = shapeKeys[i];
  9155. if (typeof targetShape[key] === 'object') {
  9156. this.shape[key] = targetShape[key];
  9157. }
  9158. else {
  9159. targetShapePrimaryProps[key] = targetShape[key];
  9160. }
  9161. }
  9162. this._transitionState(stateName, {
  9163. shape: targetShapePrimaryProps
  9164. }, animationCfg);
  9165. }
  9166. else {
  9167. this.shape = targetShape;
  9168. this.dirtyShape();
  9169. }
  9170. }
  9171. };
  9172. Path.prototype._mergeStates = function (states) {
  9173. var mergedState = _super.prototype._mergeStates.call(this, states);
  9174. var mergedShape;
  9175. for (var i = 0; i < states.length; i++) {
  9176. var state = states[i];
  9177. if (state.shape) {
  9178. mergedShape = mergedShape || {};
  9179. this._mergeStyle(mergedShape, state.shape);
  9180. }
  9181. }
  9182. if (mergedShape) {
  9183. mergedState.shape = mergedShape;
  9184. }
  9185. return mergedState;
  9186. };
  9187. Path.prototype.getAnimationStyleProps = function () {
  9188. return DEFAULT_PATH_ANIMATION_PROPS;
  9189. };
  9190. Path.prototype.isZeroArea = function () {
  9191. return false;
  9192. };
  9193. Path.extend = function (defaultProps) {
  9194. var Sub = (function (_super) {
  9195. __extends(Sub, _super);
  9196. function Sub(opts) {
  9197. var _this = _super.call(this, opts) || this;
  9198. defaultProps.init && defaultProps.init.call(_this, opts);
  9199. return _this;
  9200. }
  9201. Sub.prototype.getDefaultStyle = function () {
  9202. return clone(defaultProps.style);
  9203. };
  9204. Sub.prototype.getDefaultShape = function () {
  9205. return clone(defaultProps.shape);
  9206. };
  9207. return Sub;
  9208. }(Path));
  9209. for (var key in defaultProps) {
  9210. if (typeof defaultProps[key] === 'function') {
  9211. Sub.prototype[key] = defaultProps[key];
  9212. }
  9213. }
  9214. return Sub;
  9215. };
  9216. Path.initDefaultProps = (function () {
  9217. var pathProto = Path.prototype;
  9218. pathProto.type = 'path';
  9219. pathProto.strokeContainThreshold = 5;
  9220. pathProto.segmentIgnoreThreshold = 0;
  9221. pathProto.subPixelOptimize = false;
  9222. pathProto.autoBatch = false;
  9223. pathProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT | SHAPE_CHANGED_BIT;
  9224. })();
  9225. return Path;
  9226. }(Displayable));
  9227. var CMD$2 = PathProxy.CMD;
  9228. var points = [[], [], []];
  9229. var mathSqrt$1 = Math.sqrt;
  9230. var mathAtan2 = Math.atan2;
  9231. function transformPath(path, m) {
  9232. if (!m) {
  9233. return;
  9234. }
  9235. var data = path.data;
  9236. var len = path.len();
  9237. var cmd;
  9238. var nPoint;
  9239. var i;
  9240. var j;
  9241. var k;
  9242. var p;
  9243. var M = CMD$2.M;
  9244. var C = CMD$2.C;
  9245. var L = CMD$2.L;
  9246. var R = CMD$2.R;
  9247. var A = CMD$2.A;
  9248. var Q = CMD$2.Q;
  9249. for (i = 0, j = 0; i < len;) {
  9250. cmd = data[i++];
  9251. j = i;
  9252. nPoint = 0;
  9253. switch (cmd) {
  9254. case M:
  9255. nPoint = 1;
  9256. break;
  9257. case L:
  9258. nPoint = 1;
  9259. break;
  9260. case C:
  9261. nPoint = 3;
  9262. break;
  9263. case Q:
  9264. nPoint = 2;
  9265. break;
  9266. case A:
  9267. var x = m[4];
  9268. var y = m[5];
  9269. var sx = mathSqrt$1(m[0] * m[0] + m[1] * m[1]);
  9270. var sy = mathSqrt$1(m[2] * m[2] + m[3] * m[3]);
  9271. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  9272. data[i] *= sx;
  9273. data[i++] += x;
  9274. data[i] *= sy;
  9275. data[i++] += y;
  9276. data[i++] *= sx;
  9277. data[i++] *= sy;
  9278. data[i++] += angle;
  9279. data[i++] += angle;
  9280. i += 2;
  9281. j = i;
  9282. break;
  9283. case R:
  9284. p[0] = data[i++];
  9285. p[1] = data[i++];
  9286. applyTransform(p, p, m);
  9287. data[j++] = p[0];
  9288. data[j++] = p[1];
  9289. p[0] += data[i++];
  9290. p[1] += data[i++];
  9291. applyTransform(p, p, m);
  9292. data[j++] = p[0];
  9293. data[j++] = p[1];
  9294. }
  9295. for (k = 0; k < nPoint; k++) {
  9296. var p_1 = points[k];
  9297. p_1[0] = data[i++];
  9298. p_1[1] = data[i++];
  9299. applyTransform(p_1, p_1, m);
  9300. data[j++] = p_1[0];
  9301. data[j++] = p_1[1];
  9302. }
  9303. }
  9304. path.increaseVersion();
  9305. }
  9306. var mathSqrt$2 = Math.sqrt;
  9307. var mathSin$2 = Math.sin;
  9308. var mathCos$2 = Math.cos;
  9309. var PI$1 = Math.PI;
  9310. function vMag(v) {
  9311. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  9312. }
  9313. function vRatio(u, v) {
  9314. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  9315. }
  9316. function vAngle(u, v) {
  9317. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  9318. * Math.acos(vRatio(u, v));
  9319. }
  9320. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  9321. var psi = psiDeg * (PI$1 / 180.0);
  9322. var xp = mathCos$2(psi) * (x1 - x2) / 2.0
  9323. + mathSin$2(psi) * (y1 - y2) / 2.0;
  9324. var yp = -1 * mathSin$2(psi) * (x1 - x2) / 2.0
  9325. + mathCos$2(psi) * (y1 - y2) / 2.0;
  9326. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  9327. if (lambda > 1) {
  9328. rx *= mathSqrt$2(lambda);
  9329. ry *= mathSqrt$2(lambda);
  9330. }
  9331. var f = (fa === fs ? -1 : 1)
  9332. * mathSqrt$2((((rx * rx) * (ry * ry))
  9333. - ((rx * rx) * (yp * yp))
  9334. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  9335. + (ry * ry) * (xp * xp))) || 0;
  9336. var cxp = f * rx * yp / ry;
  9337. var cyp = f * -ry * xp / rx;
  9338. var cx = (x1 + x2) / 2.0
  9339. + mathCos$2(psi) * cxp
  9340. - mathSin$2(psi) * cyp;
  9341. var cy = (y1 + y2) / 2.0
  9342. + mathSin$2(psi) * cxp
  9343. + mathCos$2(psi) * cyp;
  9344. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  9345. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  9346. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  9347. var dTheta = vAngle(u, v);
  9348. if (vRatio(u, v) <= -1) {
  9349. dTheta = PI$1;
  9350. }
  9351. if (vRatio(u, v) >= 1) {
  9352. dTheta = 0;
  9353. }
  9354. if (dTheta < 0) {
  9355. var n = Math.round(dTheta / PI$1 * 1e6) / 1e6;
  9356. dTheta = PI$1 * 2 + (n % 2) * PI$1;
  9357. }
  9358. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  9359. }
  9360. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  9361. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  9362. function createPathProxyFromString(data) {
  9363. var path = new PathProxy();
  9364. if (!data) {
  9365. return path;
  9366. }
  9367. var cpx = 0;
  9368. var cpy = 0;
  9369. var subpathX = cpx;
  9370. var subpathY = cpy;
  9371. var prevCmd;
  9372. var CMD = PathProxy.CMD;
  9373. var cmdList = data.match(commandReg);
  9374. if (!cmdList) {
  9375. return path;
  9376. }
  9377. for (var l = 0; l < cmdList.length; l++) {
  9378. var cmdText = cmdList[l];
  9379. var cmdStr = cmdText.charAt(0);
  9380. var cmd = void 0;
  9381. var p = cmdText.match(numberReg) || [];
  9382. var pLen = p.length;
  9383. for (var i = 0; i < pLen; i++) {
  9384. p[i] = parseFloat(p[i]);
  9385. }
  9386. var off = 0;
  9387. while (off < pLen) {
  9388. var ctlPtx = void 0;
  9389. var ctlPty = void 0;
  9390. var rx = void 0;
  9391. var ry = void 0;
  9392. var psi = void 0;
  9393. var fa = void 0;
  9394. var fs = void 0;
  9395. var x1 = cpx;
  9396. var y1 = cpy;
  9397. var len = void 0;
  9398. var pathData = void 0;
  9399. switch (cmdStr) {
  9400. case 'l':
  9401. cpx += p[off++];
  9402. cpy += p[off++];
  9403. cmd = CMD.L;
  9404. path.addData(cmd, cpx, cpy);
  9405. break;
  9406. case 'L':
  9407. cpx = p[off++];
  9408. cpy = p[off++];
  9409. cmd = CMD.L;
  9410. path.addData(cmd, cpx, cpy);
  9411. break;
  9412. case 'm':
  9413. cpx += p[off++];
  9414. cpy += p[off++];
  9415. cmd = CMD.M;
  9416. path.addData(cmd, cpx, cpy);
  9417. subpathX = cpx;
  9418. subpathY = cpy;
  9419. cmdStr = 'l';
  9420. break;
  9421. case 'M':
  9422. cpx = p[off++];
  9423. cpy = p[off++];
  9424. cmd = CMD.M;
  9425. path.addData(cmd, cpx, cpy);
  9426. subpathX = cpx;
  9427. subpathY = cpy;
  9428. cmdStr = 'L';
  9429. break;
  9430. case 'h':
  9431. cpx += p[off++];
  9432. cmd = CMD.L;
  9433. path.addData(cmd, cpx, cpy);
  9434. break;
  9435. case 'H':
  9436. cpx = p[off++];
  9437. cmd = CMD.L;
  9438. path.addData(cmd, cpx, cpy);
  9439. break;
  9440. case 'v':
  9441. cpy += p[off++];
  9442. cmd = CMD.L;
  9443. path.addData(cmd, cpx, cpy);
  9444. break;
  9445. case 'V':
  9446. cpy = p[off++];
  9447. cmd = CMD.L;
  9448. path.addData(cmd, cpx, cpy);
  9449. break;
  9450. case 'C':
  9451. cmd = CMD.C;
  9452. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  9453. cpx = p[off - 2];
  9454. cpy = p[off - 1];
  9455. break;
  9456. case 'c':
  9457. cmd = CMD.C;
  9458. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  9459. cpx += p[off - 2];
  9460. cpy += p[off - 1];
  9461. break;
  9462. case 'S':
  9463. ctlPtx = cpx;
  9464. ctlPty = cpy;
  9465. len = path.len();
  9466. pathData = path.data;
  9467. if (prevCmd === CMD.C) {
  9468. ctlPtx += cpx - pathData[len - 4];
  9469. ctlPty += cpy - pathData[len - 3];
  9470. }
  9471. cmd = CMD.C;
  9472. x1 = p[off++];
  9473. y1 = p[off++];
  9474. cpx = p[off++];
  9475. cpy = p[off++];
  9476. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9477. break;
  9478. case 's':
  9479. ctlPtx = cpx;
  9480. ctlPty = cpy;
  9481. len = path.len();
  9482. pathData = path.data;
  9483. if (prevCmd === CMD.C) {
  9484. ctlPtx += cpx - pathData[len - 4];
  9485. ctlPty += cpy - pathData[len - 3];
  9486. }
  9487. cmd = CMD.C;
  9488. x1 = cpx + p[off++];
  9489. y1 = cpy + p[off++];
  9490. cpx += p[off++];
  9491. cpy += p[off++];
  9492. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9493. break;
  9494. case 'Q':
  9495. x1 = p[off++];
  9496. y1 = p[off++];
  9497. cpx = p[off++];
  9498. cpy = p[off++];
  9499. cmd = CMD.Q;
  9500. path.addData(cmd, x1, y1, cpx, cpy);
  9501. break;
  9502. case 'q':
  9503. x1 = p[off++] + cpx;
  9504. y1 = p[off++] + cpy;
  9505. cpx += p[off++];
  9506. cpy += p[off++];
  9507. cmd = CMD.Q;
  9508. path.addData(cmd, x1, y1, cpx, cpy);
  9509. break;
  9510. case 'T':
  9511. ctlPtx = cpx;
  9512. ctlPty = cpy;
  9513. len = path.len();
  9514. pathData = path.data;
  9515. if (prevCmd === CMD.Q) {
  9516. ctlPtx += cpx - pathData[len - 4];
  9517. ctlPty += cpy - pathData[len - 3];
  9518. }
  9519. cpx = p[off++];
  9520. cpy = p[off++];
  9521. cmd = CMD.Q;
  9522. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9523. break;
  9524. case 't':
  9525. ctlPtx = cpx;
  9526. ctlPty = cpy;
  9527. len = path.len();
  9528. pathData = path.data;
  9529. if (prevCmd === CMD.Q) {
  9530. ctlPtx += cpx - pathData[len - 4];
  9531. ctlPty += cpy - pathData[len - 3];
  9532. }
  9533. cpx += p[off++];
  9534. cpy += p[off++];
  9535. cmd = CMD.Q;
  9536. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9537. break;
  9538. case 'A':
  9539. rx = p[off++];
  9540. ry = p[off++];
  9541. psi = p[off++];
  9542. fa = p[off++];
  9543. fs = p[off++];
  9544. x1 = cpx, y1 = cpy;
  9545. cpx = p[off++];
  9546. cpy = p[off++];
  9547. cmd = CMD.A;
  9548. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9549. break;
  9550. case 'a':
  9551. rx = p[off++];
  9552. ry = p[off++];
  9553. psi = p[off++];
  9554. fa = p[off++];
  9555. fs = p[off++];
  9556. x1 = cpx, y1 = cpy;
  9557. cpx += p[off++];
  9558. cpy += p[off++];
  9559. cmd = CMD.A;
  9560. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9561. break;
  9562. }
  9563. }
  9564. if (cmdStr === 'z' || cmdStr === 'Z') {
  9565. cmd = CMD.Z;
  9566. path.addData(cmd);
  9567. cpx = subpathX;
  9568. cpy = subpathY;
  9569. }
  9570. prevCmd = cmd;
  9571. }
  9572. path.toStatic();
  9573. return path;
  9574. }
  9575. var SVGPath = (function (_super) {
  9576. __extends(SVGPath, _super);
  9577. function SVGPath() {
  9578. return _super !== null && _super.apply(this, arguments) || this;
  9579. }
  9580. SVGPath.prototype.applyTransform = function (m) { };
  9581. return SVGPath;
  9582. }(Path));
  9583. function isPathProxy(path) {
  9584. return path.setData != null;
  9585. }
  9586. function createPathOptions(str, opts) {
  9587. var pathProxy = createPathProxyFromString(str);
  9588. var innerOpts = extend({}, opts);
  9589. innerOpts.buildPath = function (path) {
  9590. if (isPathProxy(path)) {
  9591. path.setData(pathProxy.data);
  9592. var ctx = path.getContext();
  9593. if (ctx) {
  9594. path.rebuildPath(ctx, 1);
  9595. }
  9596. }
  9597. else {
  9598. var ctx = path;
  9599. pathProxy.rebuildPath(ctx, 1);
  9600. }
  9601. };
  9602. innerOpts.applyTransform = function (m) {
  9603. transformPath(pathProxy, m);
  9604. this.dirtyShape();
  9605. };
  9606. return innerOpts;
  9607. }
  9608. function createFromString(str, opts) {
  9609. return new SVGPath(createPathOptions(str, opts));
  9610. }
  9611. function extendFromString(str, defaultOpts) {
  9612. var innerOpts = createPathOptions(str, defaultOpts);
  9613. var Sub = (function (_super) {
  9614. __extends(Sub, _super);
  9615. function Sub(opts) {
  9616. var _this = _super.call(this, opts) || this;
  9617. _this.applyTransform = innerOpts.applyTransform;
  9618. _this.buildPath = innerOpts.buildPath;
  9619. return _this;
  9620. }
  9621. return Sub;
  9622. }(SVGPath));
  9623. return Sub;
  9624. }
  9625. function mergePath(pathEls, opts) {
  9626. var pathList = [];
  9627. var len = pathEls.length;
  9628. for (var i = 0; i < len; i++) {
  9629. var pathEl = pathEls[i];
  9630. pathList.push(pathEl.getUpdatedPathProxy(true));
  9631. }
  9632. var pathBundle = new Path(opts);
  9633. pathBundle.createPathProxy();
  9634. pathBundle.buildPath = function (path) {
  9635. if (isPathProxy(path)) {
  9636. path.appendPath(pathList);
  9637. var ctx = path.getContext();
  9638. if (ctx) {
  9639. path.rebuildPath(ctx, 1);
  9640. }
  9641. }
  9642. };
  9643. return pathBundle;
  9644. }
  9645. function clonePath(sourcePath, opts) {
  9646. opts = opts || {};
  9647. var path = new Path();
  9648. if (sourcePath.shape) {
  9649. path.setShape(sourcePath.shape);
  9650. }
  9651. path.setStyle(sourcePath.style);
  9652. if (opts.bakeTransform) {
  9653. transformPath(path.path, sourcePath.getComputedTransform());
  9654. }
  9655. else {
  9656. if (opts.toLocal) {
  9657. path.setLocalTransform(sourcePath.getComputedTransform());
  9658. }
  9659. else {
  9660. path.copyTransform(sourcePath);
  9661. }
  9662. }
  9663. path.buildPath = sourcePath.buildPath;
  9664. path.applyTransform = path.applyTransform;
  9665. path.z = sourcePath.z;
  9666. path.z2 = sourcePath.z2;
  9667. path.zlevel = sourcePath.zlevel;
  9668. return path;
  9669. }
  9670. var path = /*#__PURE__*/Object.freeze({
  9671. __proto__: null,
  9672. createFromString: createFromString,
  9673. extendFromString: extendFromString,
  9674. mergePath: mergePath,
  9675. clonePath: clonePath
  9676. });
  9677. var DEFAULT_IMAGE_STYLE = defaults({
  9678. x: 0,
  9679. y: 0
  9680. }, DEFAULT_COMMON_STYLE);
  9681. var DEFAULT_IMAGE_ANIMATION_PROPS = {
  9682. style: defaults({
  9683. x: true,
  9684. y: true,
  9685. width: true,
  9686. height: true,
  9687. sx: true,
  9688. sy: true,
  9689. sWidth: true,
  9690. sHeight: true
  9691. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  9692. };
  9693. function isImageLike(source) {
  9694. return !!(source
  9695. && typeof source !== 'string'
  9696. && source.width && source.height);
  9697. }
  9698. var ZRImage = (function (_super) {
  9699. __extends(ZRImage, _super);
  9700. function ZRImage() {
  9701. return _super !== null && _super.apply(this, arguments) || this;
  9702. }
  9703. ZRImage.prototype.createStyle = function (obj) {
  9704. return createObject(DEFAULT_IMAGE_STYLE, obj);
  9705. };
  9706. ZRImage.prototype._getSize = function (dim) {
  9707. var style = this.style;
  9708. var size = style[dim];
  9709. if (size != null) {
  9710. return size;
  9711. }
  9712. var imageSource = isImageLike(style.image)
  9713. ? style.image : this.__image;
  9714. if (!imageSource) {
  9715. return 0;
  9716. }
  9717. var otherDim = dim === 'width' ? 'height' : 'width';
  9718. var otherDimSize = style[otherDim];
  9719. if (otherDimSize == null) {
  9720. return imageSource[dim];
  9721. }
  9722. else {
  9723. return imageSource[dim] / imageSource[otherDim] * otherDimSize;
  9724. }
  9725. };
  9726. ZRImage.prototype.getWidth = function () {
  9727. return this._getSize('width');
  9728. };
  9729. ZRImage.prototype.getHeight = function () {
  9730. return this._getSize('height');
  9731. };
  9732. ZRImage.prototype.getAnimationStyleProps = function () {
  9733. return DEFAULT_IMAGE_ANIMATION_PROPS;
  9734. };
  9735. ZRImage.prototype.getBoundingRect = function () {
  9736. var style = this.style;
  9737. if (!this._rect) {
  9738. this._rect = new BoundingRect(style.x || 0, style.y || 0, this.getWidth(), this.getHeight());
  9739. }
  9740. return this._rect;
  9741. };
  9742. return ZRImage;
  9743. }(Displayable));
  9744. ZRImage.prototype.type = 'image';
  9745. var CircleShape = (function () {
  9746. function CircleShape() {
  9747. this.cx = 0;
  9748. this.cy = 0;
  9749. this.r = 0;
  9750. }
  9751. return CircleShape;
  9752. }());
  9753. var Circle = (function (_super) {
  9754. __extends(Circle, _super);
  9755. function Circle(opts) {
  9756. return _super.call(this, opts) || this;
  9757. }
  9758. Circle.prototype.getDefaultShape = function () {
  9759. return new CircleShape();
  9760. };
  9761. Circle.prototype.buildPath = function (ctx, shape) {
  9762. ctx.moveTo(shape.cx + shape.r, shape.cy);
  9763. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2);
  9764. };
  9765. return Circle;
  9766. }(Path));
  9767. Circle.prototype.type = 'circle';
  9768. function buildPath(ctx, shape) {
  9769. var x = shape.x;
  9770. var y = shape.y;
  9771. var width = shape.width;
  9772. var height = shape.height;
  9773. var r = shape.r;
  9774. var r1;
  9775. var r2;
  9776. var r3;
  9777. var r4;
  9778. if (width < 0) {
  9779. x = x + width;
  9780. width = -width;
  9781. }
  9782. if (height < 0) {
  9783. y = y + height;
  9784. height = -height;
  9785. }
  9786. if (typeof r === 'number') {
  9787. r1 = r2 = r3 = r4 = r;
  9788. }
  9789. else if (r instanceof Array) {
  9790. if (r.length === 1) {
  9791. r1 = r2 = r3 = r4 = r[0];
  9792. }
  9793. else if (r.length === 2) {
  9794. r1 = r3 = r[0];
  9795. r2 = r4 = r[1];
  9796. }
  9797. else if (r.length === 3) {
  9798. r1 = r[0];
  9799. r2 = r4 = r[1];
  9800. r3 = r[2];
  9801. }
  9802. else {
  9803. r1 = r[0];
  9804. r2 = r[1];
  9805. r3 = r[2];
  9806. r4 = r[3];
  9807. }
  9808. }
  9809. else {
  9810. r1 = r2 = r3 = r4 = 0;
  9811. }
  9812. var total;
  9813. if (r1 + r2 > width) {
  9814. total = r1 + r2;
  9815. r1 *= width / total;
  9816. r2 *= width / total;
  9817. }
  9818. if (r3 + r4 > width) {
  9819. total = r3 + r4;
  9820. r3 *= width / total;
  9821. r4 *= width / total;
  9822. }
  9823. if (r2 + r3 > height) {
  9824. total = r2 + r3;
  9825. r2 *= height / total;
  9826. r3 *= height / total;
  9827. }
  9828. if (r1 + r4 > height) {
  9829. total = r1 + r4;
  9830. r1 *= height / total;
  9831. r4 *= height / total;
  9832. }
  9833. ctx.moveTo(x + r1, y);
  9834. ctx.lineTo(x + width - r2, y);
  9835. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  9836. ctx.lineTo(x + width, y + height - r3);
  9837. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  9838. ctx.lineTo(x + r4, y + height);
  9839. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  9840. ctx.lineTo(x, y + r1);
  9841. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  9842. }
  9843. var round = Math.round;
  9844. function subPixelOptimizeLine(outputShape, inputShape, style) {
  9845. if (!inputShape) {
  9846. return;
  9847. }
  9848. var x1 = inputShape.x1;
  9849. var x2 = inputShape.x2;
  9850. var y1 = inputShape.y1;
  9851. var y2 = inputShape.y2;
  9852. outputShape.x1 = x1;
  9853. outputShape.x2 = x2;
  9854. outputShape.y1 = y1;
  9855. outputShape.y2 = y2;
  9856. var lineWidth = style && style.lineWidth;
  9857. if (!lineWidth) {
  9858. return outputShape;
  9859. }
  9860. if (round(x1 * 2) === round(x2 * 2)) {
  9861. outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true);
  9862. }
  9863. if (round(y1 * 2) === round(y2 * 2)) {
  9864. outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true);
  9865. }
  9866. return outputShape;
  9867. }
  9868. function subPixelOptimizeRect(outputShape, inputShape, style) {
  9869. if (!inputShape) {
  9870. return;
  9871. }
  9872. var originX = inputShape.x;
  9873. var originY = inputShape.y;
  9874. var originWidth = inputShape.width;
  9875. var originHeight = inputShape.height;
  9876. outputShape.x = originX;
  9877. outputShape.y = originY;
  9878. outputShape.width = originWidth;
  9879. outputShape.height = originHeight;
  9880. var lineWidth = style && style.lineWidth;
  9881. if (!lineWidth) {
  9882. return outputShape;
  9883. }
  9884. outputShape.x = subPixelOptimize(originX, lineWidth, true);
  9885. outputShape.y = subPixelOptimize(originY, lineWidth, true);
  9886. outputShape.width = Math.max(subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
  9887. outputShape.height = Math.max(subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
  9888. return outputShape;
  9889. }
  9890. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  9891. if (!lineWidth) {
  9892. return position;
  9893. }
  9894. var doubledPosition = round(position * 2);
  9895. return (doubledPosition + round(lineWidth)) % 2 === 0
  9896. ? doubledPosition / 2
  9897. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  9898. }
  9899. var RectShape = (function () {
  9900. function RectShape() {
  9901. this.x = 0;
  9902. this.y = 0;
  9903. this.width = 0;
  9904. this.height = 0;
  9905. }
  9906. return RectShape;
  9907. }());
  9908. var subPixelOptimizeOutputShape = {};
  9909. var Rect = (function (_super) {
  9910. __extends(Rect, _super);
  9911. function Rect(opts) {
  9912. return _super.call(this, opts) || this;
  9913. }
  9914. Rect.prototype.getDefaultShape = function () {
  9915. return new RectShape();
  9916. };
  9917. Rect.prototype.buildPath = function (ctx, shape) {
  9918. var x;
  9919. var y;
  9920. var width;
  9921. var height;
  9922. if (this.subPixelOptimize) {
  9923. var optimizedShape = subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style);
  9924. x = optimizedShape.x;
  9925. y = optimizedShape.y;
  9926. width = optimizedShape.width;
  9927. height = optimizedShape.height;
  9928. optimizedShape.r = shape.r;
  9929. shape = optimizedShape;
  9930. }
  9931. else {
  9932. x = shape.x;
  9933. y = shape.y;
  9934. width = shape.width;
  9935. height = shape.height;
  9936. }
  9937. if (!shape.r) {
  9938. ctx.rect(x, y, width, height);
  9939. }
  9940. else {
  9941. buildPath(ctx, shape);
  9942. }
  9943. };
  9944. Rect.prototype.isZeroArea = function () {
  9945. return !this.shape.width || !this.shape.height;
  9946. };
  9947. return Rect;
  9948. }(Path));
  9949. Rect.prototype.type = 'rect';
  9950. var EllipseShape = (function () {
  9951. function EllipseShape() {
  9952. this.cx = 0;
  9953. this.cy = 0;
  9954. this.rx = 0;
  9955. this.ry = 0;
  9956. }
  9957. return EllipseShape;
  9958. }());
  9959. var Ellipse = (function (_super) {
  9960. __extends(Ellipse, _super);
  9961. function Ellipse(opts) {
  9962. return _super.call(this, opts) || this;
  9963. }
  9964. Ellipse.prototype.getDefaultShape = function () {
  9965. return new EllipseShape();
  9966. };
  9967. Ellipse.prototype.buildPath = function (ctx, shape) {
  9968. var k = 0.5522848;
  9969. var x = shape.cx;
  9970. var y = shape.cy;
  9971. var a = shape.rx;
  9972. var b = shape.ry;
  9973. var ox = a * k;
  9974. var oy = b * k;
  9975. ctx.moveTo(x - a, y);
  9976. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  9977. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  9978. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  9979. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  9980. ctx.closePath();
  9981. };
  9982. return Ellipse;
  9983. }(Path));
  9984. Ellipse.prototype.type = 'ellipse';
  9985. var subPixelOptimizeOutputShape$1 = {};
  9986. var LineShape = (function () {
  9987. function LineShape() {
  9988. this.x1 = 0;
  9989. this.y1 = 0;
  9990. this.x2 = 0;
  9991. this.y2 = 0;
  9992. this.percent = 1;
  9993. }
  9994. return LineShape;
  9995. }());
  9996. var Line = (function (_super) {
  9997. __extends(Line, _super);
  9998. function Line(opts) {
  9999. return _super.call(this, opts) || this;
  10000. }
  10001. Line.prototype.getDefaultStyle = function () {
  10002. return {
  10003. stroke: '#000',
  10004. fill: null
  10005. };
  10006. };
  10007. Line.prototype.getDefaultShape = function () {
  10008. return new LineShape();
  10009. };
  10010. Line.prototype.buildPath = function (ctx, shape) {
  10011. var x1;
  10012. var y1;
  10013. var x2;
  10014. var y2;
  10015. if (this.subPixelOptimize) {
  10016. var optimizedShape = subPixelOptimizeLine(subPixelOptimizeOutputShape$1, shape, this.style);
  10017. x1 = optimizedShape.x1;
  10018. y1 = optimizedShape.y1;
  10019. x2 = optimizedShape.x2;
  10020. y2 = optimizedShape.y2;
  10021. }
  10022. else {
  10023. x1 = shape.x1;
  10024. y1 = shape.y1;
  10025. x2 = shape.x2;
  10026. y2 = shape.y2;
  10027. }
  10028. var percent = shape.percent;
  10029. if (percent === 0) {
  10030. return;
  10031. }
  10032. ctx.moveTo(x1, y1);
  10033. if (percent < 1) {
  10034. x2 = x1 * (1 - percent) + x2 * percent;
  10035. y2 = y1 * (1 - percent) + y2 * percent;
  10036. }
  10037. ctx.lineTo(x2, y2);
  10038. };
  10039. Line.prototype.pointAt = function (p) {
  10040. var shape = this.shape;
  10041. return [
  10042. shape.x1 * (1 - p) + shape.x2 * p,
  10043. shape.y1 * (1 - p) + shape.y2 * p
  10044. ];
  10045. };
  10046. return Line;
  10047. }(Path));
  10048. Line.prototype.type = 'line';
  10049. function smoothBezier(points, smooth, isLoop, constraint) {
  10050. var cps = [];
  10051. var v = [];
  10052. var v1 = [];
  10053. var v2 = [];
  10054. var prevPoint;
  10055. var nextPoint;
  10056. var min$1;
  10057. var max$1;
  10058. if (constraint) {
  10059. min$1 = [Infinity, Infinity];
  10060. max$1 = [-Infinity, -Infinity];
  10061. for (var i = 0, len = points.length; i < len; i++) {
  10062. min(min$1, min$1, points[i]);
  10063. max(max$1, max$1, points[i]);
  10064. }
  10065. min(min$1, min$1, constraint[0]);
  10066. max(max$1, max$1, constraint[1]);
  10067. }
  10068. for (var i = 0, len = points.length; i < len; i++) {
  10069. var point = points[i];
  10070. if (isLoop) {
  10071. prevPoint = points[i ? i - 1 : len - 1];
  10072. nextPoint = points[(i + 1) % len];
  10073. }
  10074. else {
  10075. if (i === 0 || i === len - 1) {
  10076. cps.push(clone$1(points[i]));
  10077. continue;
  10078. }
  10079. else {
  10080. prevPoint = points[i - 1];
  10081. nextPoint = points[i + 1];
  10082. }
  10083. }
  10084. sub(v, nextPoint, prevPoint);
  10085. scale(v, v, smooth);
  10086. var d0 = distance(point, prevPoint);
  10087. var d1 = distance(point, nextPoint);
  10088. var sum = d0 + d1;
  10089. if (sum !== 0) {
  10090. d0 /= sum;
  10091. d1 /= sum;
  10092. }
  10093. scale(v1, v, -d0);
  10094. scale(v2, v, d1);
  10095. var cp0 = add([], point, v1);
  10096. var cp1 = add([], point, v2);
  10097. if (constraint) {
  10098. max(cp0, cp0, min$1);
  10099. min(cp0, cp0, max$1);
  10100. max(cp1, cp1, min$1);
  10101. min(cp1, cp1, max$1);
  10102. }
  10103. cps.push(cp0);
  10104. cps.push(cp1);
  10105. }
  10106. if (isLoop) {
  10107. cps.push(cps.shift());
  10108. }
  10109. return cps;
  10110. }
  10111. function buildPath$1(ctx, shape, closePath) {
  10112. var smooth = shape.smooth;
  10113. var points = shape.points;
  10114. if (points && points.length >= 2) {
  10115. if (smooth) {
  10116. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  10117. ctx.moveTo(points[0][0], points[0][1]);
  10118. var len = points.length;
  10119. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  10120. var cp1 = controlPoints[i * 2];
  10121. var cp2 = controlPoints[i * 2 + 1];
  10122. var p = points[(i + 1) % len];
  10123. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  10124. }
  10125. }
  10126. else {
  10127. ctx.moveTo(points[0][0], points[0][1]);
  10128. for (var i = 1, l = points.length; i < l; i++) {
  10129. ctx.lineTo(points[i][0], points[i][1]);
  10130. }
  10131. }
  10132. closePath && ctx.closePath();
  10133. }
  10134. }
  10135. var PolygonShape = (function () {
  10136. function PolygonShape() {
  10137. this.points = null;
  10138. this.smooth = 0;
  10139. this.smoothConstraint = null;
  10140. }
  10141. return PolygonShape;
  10142. }());
  10143. var Polygon = (function (_super) {
  10144. __extends(Polygon, _super);
  10145. function Polygon(opts) {
  10146. return _super.call(this, opts) || this;
  10147. }
  10148. Polygon.prototype.getDefaultShape = function () {
  10149. return new PolygonShape();
  10150. };
  10151. Polygon.prototype.buildPath = function (ctx, shape) {
  10152. buildPath$1(ctx, shape, true);
  10153. };
  10154. return Polygon;
  10155. }(Path));
  10156. Polygon.prototype.type = 'polygon';
  10157. var PolylineShape = (function () {
  10158. function PolylineShape() {
  10159. this.points = null;
  10160. this.percent = 1;
  10161. this.smooth = 0;
  10162. this.smoothConstraint = null;
  10163. }
  10164. return PolylineShape;
  10165. }());
  10166. var Polyline = (function (_super) {
  10167. __extends(Polyline, _super);
  10168. function Polyline(opts) {
  10169. return _super.call(this, opts) || this;
  10170. }
  10171. Polyline.prototype.getDefaultStyle = function () {
  10172. return {
  10173. stroke: '#000',
  10174. fill: null
  10175. };
  10176. };
  10177. Polyline.prototype.getDefaultShape = function () {
  10178. return new PolylineShape();
  10179. };
  10180. Polyline.prototype.buildPath = function (ctx, shape) {
  10181. buildPath$1(ctx, shape, false);
  10182. };
  10183. return Polyline;
  10184. }(Path));
  10185. Polyline.prototype.type = 'polyline';
  10186. var Gradient = (function () {
  10187. function Gradient(colorStops) {
  10188. this.colorStops = colorStops || [];
  10189. }
  10190. Gradient.prototype.addColorStop = function (offset, color) {
  10191. this.colorStops.push({
  10192. offset: offset,
  10193. color: color
  10194. });
  10195. };
  10196. return Gradient;
  10197. }());
  10198. var LinearGradient = (function (_super) {
  10199. __extends(LinearGradient, _super);
  10200. function LinearGradient(x, y, x2, y2, colorStops, globalCoord) {
  10201. var _this = _super.call(this, colorStops) || this;
  10202. _this.x = x == null ? 0 : x;
  10203. _this.y = y == null ? 0 : y;
  10204. _this.x2 = x2 == null ? 1 : x2;
  10205. _this.y2 = y2 == null ? 0 : y2;
  10206. _this.type = 'linear';
  10207. _this.global = globalCoord || false;
  10208. return _this;
  10209. }
  10210. return LinearGradient;
  10211. }(Gradient));
  10212. var RadialGradient = (function (_super) {
  10213. __extends(RadialGradient, _super);
  10214. function RadialGradient(x, y, r, colorStops, globalCoord) {
  10215. var _this = _super.call(this, colorStops) || this;
  10216. _this.x = x == null ? 0.5 : x;
  10217. _this.y = y == null ? 0.5 : y;
  10218. _this.r = r == null ? 0.5 : r;
  10219. _this.type = 'radial';
  10220. _this.global = globalCoord || false;
  10221. return _this;
  10222. }
  10223. return RadialGradient;
  10224. }(Gradient));
  10225. var DEFAULT_TSPAN_STYLE = defaults({
  10226. strokeFirst: true,
  10227. font: DEFAULT_FONT,
  10228. x: 0,
  10229. y: 0,
  10230. textAlign: 'left',
  10231. textBaseline: 'top',
  10232. miterLimit: 2
  10233. }, DEFAULT_PATH_STYLE);
  10234. var TSpan = (function (_super) {
  10235. __extends(TSpan, _super);
  10236. function TSpan() {
  10237. return _super !== null && _super.apply(this, arguments) || this;
  10238. }
  10239. TSpan.prototype.hasStroke = function () {
  10240. var style = this.style;
  10241. var stroke = style.stroke;
  10242. return stroke != null && stroke !== 'none' && style.lineWidth > 0;
  10243. };
  10244. TSpan.prototype.hasFill = function () {
  10245. var style = this.style;
  10246. var fill = style.fill;
  10247. return fill != null && fill !== 'none';
  10248. };
  10249. TSpan.prototype.createStyle = function (obj) {
  10250. return createObject(DEFAULT_TSPAN_STYLE, obj);
  10251. };
  10252. TSpan.prototype.setBoundingRect = function (rect) {
  10253. this._rect = rect;
  10254. };
  10255. TSpan.prototype.getBoundingRect = function () {
  10256. var style = this.style;
  10257. if (!this._rect) {
  10258. var text = style.text;
  10259. text != null ? (text += '') : (text = '');
  10260. var rect = getBoundingRect(text, style.font, style.textAlign, style.textBaseline);
  10261. rect.x += style.x || 0;
  10262. rect.y += style.y || 0;
  10263. if (this.hasStroke()) {
  10264. var w = style.lineWidth;
  10265. rect.x -= w / 2;
  10266. rect.y -= w / 2;
  10267. rect.width += w;
  10268. rect.height += w;
  10269. }
  10270. this._rect = rect;
  10271. }
  10272. return this._rect;
  10273. };
  10274. TSpan.initDefaultProps = (function () {
  10275. var tspanProto = TSpan.prototype;
  10276. tspanProto.dirtyRectTolerance = 10;
  10277. })();
  10278. return TSpan;
  10279. }(Displayable));
  10280. TSpan.prototype.type = 'tspan';
  10281. function parseXML(svg) {
  10282. if (isString(svg)) {
  10283. var parser = new DOMParser();
  10284. svg = parser.parseFromString(svg, 'text/xml');
  10285. }
  10286. var svgNode = svg;
  10287. if (svgNode.nodeType === 9) {
  10288. svgNode = svgNode.firstChild;
  10289. }
  10290. while (svgNode.nodeName.toLowerCase() !== 'svg' || svgNode.nodeType !== 1) {
  10291. svgNode = svgNode.nextSibling;
  10292. }
  10293. return svgNode;
  10294. }
  10295. var nodeParsers;
  10296. var INHERITABLE_STYLE_ATTRIBUTES_MAP = {
  10297. 'fill': 'fill',
  10298. 'stroke': 'stroke',
  10299. 'stroke-width': 'lineWidth',
  10300. 'opacity': 'opacity',
  10301. 'fill-opacity': 'fillOpacity',
  10302. 'stroke-opacity': 'strokeOpacity',
  10303. 'stroke-dasharray': 'lineDash',
  10304. 'stroke-dashoffset': 'lineDashOffset',
  10305. 'stroke-linecap': 'lineCap',
  10306. 'stroke-linejoin': 'lineJoin',
  10307. 'stroke-miterlimit': 'miterLimit',
  10308. 'font-family': 'fontFamily',
  10309. 'font-size': 'fontSize',
  10310. 'font-style': 'fontStyle',
  10311. 'font-weight': 'fontWeight',
  10312. 'text-anchor': 'textAlign',
  10313. 'visibility': 'visibility',
  10314. 'display': 'display'
  10315. };
  10316. var INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS = keys(INHERITABLE_STYLE_ATTRIBUTES_MAP);
  10317. var SELF_STYLE_ATTRIBUTES_MAP = {
  10318. 'alignment-baseline': 'textBaseline',
  10319. 'stop-color': 'stopColor'
  10320. };
  10321. var SELF_STYLE_ATTRIBUTES_MAP_KEYS = keys(SELF_STYLE_ATTRIBUTES_MAP);
  10322. var SVGParser = (function () {
  10323. function SVGParser() {
  10324. this._defs = {};
  10325. this._root = null;
  10326. }
  10327. SVGParser.prototype.parse = function (xml, opt) {
  10328. opt = opt || {};
  10329. var svg = parseXML(xml);
  10330. {
  10331. if (!svg) {
  10332. throw new Error('Illegal svg');
  10333. }
  10334. }
  10335. this._defsUsePending = [];
  10336. var root = new Group();
  10337. this._root = root;
  10338. var named = [];
  10339. var viewBox = svg.getAttribute('viewBox') || '';
  10340. var width = parseFloat((svg.getAttribute('width') || opt.width));
  10341. var height = parseFloat((svg.getAttribute('height') || opt.height));
  10342. isNaN(width) && (width = null);
  10343. isNaN(height) && (height = null);
  10344. parseAttributes(svg, root, null, true, false);
  10345. var child = svg.firstChild;
  10346. while (child) {
  10347. this._parseNode(child, root, named, null, false, false);
  10348. child = child.nextSibling;
  10349. }
  10350. applyDefs(this._defs, this._defsUsePending);
  10351. this._defsUsePending = [];
  10352. var viewBoxRect;
  10353. var viewBoxTransform;
  10354. if (viewBox) {
  10355. var viewBoxArr = splitNumberSequence(viewBox);
  10356. if (viewBoxArr.length >= 4) {
  10357. viewBoxRect = {
  10358. x: parseFloat((viewBoxArr[0] || 0)),
  10359. y: parseFloat((viewBoxArr[1] || 0)),
  10360. width: parseFloat(viewBoxArr[2]),
  10361. height: parseFloat(viewBoxArr[3])
  10362. };
  10363. }
  10364. }
  10365. if (viewBoxRect && width != null && height != null) {
  10366. viewBoxTransform = makeViewBoxTransform(viewBoxRect, { x: 0, y: 0, width: width, height: height });
  10367. if (!opt.ignoreViewBox) {
  10368. var elRoot = root;
  10369. root = new Group();
  10370. root.add(elRoot);
  10371. elRoot.scaleX = elRoot.scaleY = viewBoxTransform.scale;
  10372. elRoot.x = viewBoxTransform.x;
  10373. elRoot.y = viewBoxTransform.y;
  10374. }
  10375. }
  10376. if (!opt.ignoreRootClip && width != null && height != null) {
  10377. root.setClipPath(new Rect({
  10378. shape: { x: 0, y: 0, width: width, height: height }
  10379. }));
  10380. }
  10381. return {
  10382. root: root,
  10383. width: width,
  10384. height: height,
  10385. viewBoxRect: viewBoxRect,
  10386. viewBoxTransform: viewBoxTransform,
  10387. named: named
  10388. };
  10389. };
  10390. SVGParser.prototype._parseNode = function (xmlNode, parentGroup, named, namedFrom, isInDefs, isInText) {
  10391. var nodeName = xmlNode.nodeName.toLowerCase();
  10392. var el;
  10393. var namedFromForSub = namedFrom;
  10394. if (nodeName === 'defs') {
  10395. isInDefs = true;
  10396. }
  10397. if (nodeName === 'text') {
  10398. isInText = true;
  10399. }
  10400. if (nodeName === 'defs' || nodeName === 'switch') {
  10401. el = parentGroup;
  10402. }
  10403. else {
  10404. if (!isInDefs) {
  10405. var parser_1 = nodeParsers[nodeName];
  10406. if (parser_1 && hasOwn(nodeParsers, nodeName)) {
  10407. el = parser_1.call(this, xmlNode, parentGroup);
  10408. var nameAttr = xmlNode.getAttribute('name');
  10409. if (nameAttr) {
  10410. var newNamed = {
  10411. name: nameAttr,
  10412. namedFrom: null,
  10413. svgNodeTagLower: nodeName,
  10414. el: el
  10415. };
  10416. named.push(newNamed);
  10417. if (nodeName === 'g') {
  10418. namedFromForSub = newNamed;
  10419. }
  10420. }
  10421. else if (namedFrom) {
  10422. named.push({
  10423. name: namedFrom.name,
  10424. namedFrom: namedFrom,
  10425. svgNodeTagLower: nodeName,
  10426. el: el
  10427. });
  10428. }
  10429. parentGroup.add(el);
  10430. }
  10431. }
  10432. var parser = paintServerParsers[nodeName];
  10433. if (parser && hasOwn(paintServerParsers, nodeName)) {
  10434. var def = parser.call(this, xmlNode);
  10435. var id = xmlNode.getAttribute('id');
  10436. if (id) {
  10437. this._defs[id] = def;
  10438. }
  10439. }
  10440. }
  10441. if (el && el.isGroup) {
  10442. var child = xmlNode.firstChild;
  10443. while (child) {
  10444. if (child.nodeType === 1) {
  10445. this._parseNode(child, el, named, namedFromForSub, isInDefs, isInText);
  10446. }
  10447. else if (child.nodeType === 3 && isInText) {
  10448. this._parseText(child, el);
  10449. }
  10450. child = child.nextSibling;
  10451. }
  10452. }
  10453. };
  10454. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  10455. var text = new TSpan({
  10456. style: {
  10457. text: xmlNode.textContent
  10458. },
  10459. silent: true,
  10460. x: this._textX || 0,
  10461. y: this._textY || 0
  10462. });
  10463. inheritStyle(parentGroup, text);
  10464. parseAttributes(xmlNode, text, this._defsUsePending, false, false);
  10465. applyTextAlignment(text, parentGroup);
  10466. var textStyle = text.style;
  10467. var fontSize = textStyle.fontSize;
  10468. if (fontSize && fontSize < 9) {
  10469. textStyle.fontSize = 9;
  10470. text.scaleX *= fontSize / 9;
  10471. text.scaleY *= fontSize / 9;
  10472. }
  10473. var font = (textStyle.fontSize || textStyle.fontFamily) && [
  10474. textStyle.fontStyle,
  10475. textStyle.fontWeight,
  10476. (textStyle.fontSize || 12) + 'px',
  10477. textStyle.fontFamily || 'sans-serif'
  10478. ].join(' ');
  10479. textStyle.font = font;
  10480. var rect = text.getBoundingRect();
  10481. this._textX += rect.width;
  10482. parentGroup.add(text);
  10483. return text;
  10484. };
  10485. SVGParser.internalField = (function () {
  10486. nodeParsers = {
  10487. 'g': function (xmlNode, parentGroup) {
  10488. var g = new Group();
  10489. inheritStyle(parentGroup, g);
  10490. parseAttributes(xmlNode, g, this._defsUsePending, false, false);
  10491. return g;
  10492. },
  10493. 'rect': function (xmlNode, parentGroup) {
  10494. var rect = new Rect();
  10495. inheritStyle(parentGroup, rect);
  10496. parseAttributes(xmlNode, rect, this._defsUsePending, false, false);
  10497. rect.setShape({
  10498. x: parseFloat(xmlNode.getAttribute('x') || '0'),
  10499. y: parseFloat(xmlNode.getAttribute('y') || '0'),
  10500. width: parseFloat(xmlNode.getAttribute('width') || '0'),
  10501. height: parseFloat(xmlNode.getAttribute('height') || '0')
  10502. });
  10503. rect.silent = true;
  10504. return rect;
  10505. },
  10506. 'circle': function (xmlNode, parentGroup) {
  10507. var circle = new Circle();
  10508. inheritStyle(parentGroup, circle);
  10509. parseAttributes(xmlNode, circle, this._defsUsePending, false, false);
  10510. circle.setShape({
  10511. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  10512. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  10513. r: parseFloat(xmlNode.getAttribute('r') || '0')
  10514. });
  10515. circle.silent = true;
  10516. return circle;
  10517. },
  10518. 'line': function (xmlNode, parentGroup) {
  10519. var line = new Line();
  10520. inheritStyle(parentGroup, line);
  10521. parseAttributes(xmlNode, line, this._defsUsePending, false, false);
  10522. line.setShape({
  10523. x1: parseFloat(xmlNode.getAttribute('x1') || '0'),
  10524. y1: parseFloat(xmlNode.getAttribute('y1') || '0'),
  10525. x2: parseFloat(xmlNode.getAttribute('x2') || '0'),
  10526. y2: parseFloat(xmlNode.getAttribute('y2') || '0')
  10527. });
  10528. line.silent = true;
  10529. return line;
  10530. },
  10531. 'ellipse': function (xmlNode, parentGroup) {
  10532. var ellipse = new Ellipse();
  10533. inheritStyle(parentGroup, ellipse);
  10534. parseAttributes(xmlNode, ellipse, this._defsUsePending, false, false);
  10535. ellipse.setShape({
  10536. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  10537. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  10538. rx: parseFloat(xmlNode.getAttribute('rx') || '0'),
  10539. ry: parseFloat(xmlNode.getAttribute('ry') || '0')
  10540. });
  10541. ellipse.silent = true;
  10542. return ellipse;
  10543. },
  10544. 'polygon': function (xmlNode, parentGroup) {
  10545. var pointsStr = xmlNode.getAttribute('points');
  10546. var pointsArr;
  10547. if (pointsStr) {
  10548. pointsArr = parsePoints(pointsStr);
  10549. }
  10550. var polygon = new Polygon({
  10551. shape: {
  10552. points: pointsArr || []
  10553. },
  10554. silent: true
  10555. });
  10556. inheritStyle(parentGroup, polygon);
  10557. parseAttributes(xmlNode, polygon, this._defsUsePending, false, false);
  10558. return polygon;
  10559. },
  10560. 'polyline': function (xmlNode, parentGroup) {
  10561. var pointsStr = xmlNode.getAttribute('points');
  10562. var pointsArr;
  10563. if (pointsStr) {
  10564. pointsArr = parsePoints(pointsStr);
  10565. }
  10566. var polyline = new Polyline({
  10567. shape: {
  10568. points: pointsArr || []
  10569. },
  10570. silent: true
  10571. });
  10572. inheritStyle(parentGroup, polyline);
  10573. parseAttributes(xmlNode, polyline, this._defsUsePending, false, false);
  10574. return polyline;
  10575. },
  10576. 'image': function (xmlNode, parentGroup) {
  10577. var img = new ZRImage();
  10578. inheritStyle(parentGroup, img);
  10579. parseAttributes(xmlNode, img, this._defsUsePending, false, false);
  10580. img.setStyle({
  10581. image: xmlNode.getAttribute('xlink:href') || xmlNode.getAttribute('href'),
  10582. x: +xmlNode.getAttribute('x'),
  10583. y: +xmlNode.getAttribute('y'),
  10584. width: +xmlNode.getAttribute('width'),
  10585. height: +xmlNode.getAttribute('height')
  10586. });
  10587. img.silent = true;
  10588. return img;
  10589. },
  10590. 'text': function (xmlNode, parentGroup) {
  10591. var x = xmlNode.getAttribute('x') || '0';
  10592. var y = xmlNode.getAttribute('y') || '0';
  10593. var dx = xmlNode.getAttribute('dx') || '0';
  10594. var dy = xmlNode.getAttribute('dy') || '0';
  10595. this._textX = parseFloat(x) + parseFloat(dx);
  10596. this._textY = parseFloat(y) + parseFloat(dy);
  10597. var g = new Group();
  10598. inheritStyle(parentGroup, g);
  10599. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  10600. return g;
  10601. },
  10602. 'tspan': function (xmlNode, parentGroup) {
  10603. var x = xmlNode.getAttribute('x');
  10604. var y = xmlNode.getAttribute('y');
  10605. if (x != null) {
  10606. this._textX = parseFloat(x);
  10607. }
  10608. if (y != null) {
  10609. this._textY = parseFloat(y);
  10610. }
  10611. var dx = xmlNode.getAttribute('dx') || '0';
  10612. var dy = xmlNode.getAttribute('dy') || '0';
  10613. var g = new Group();
  10614. inheritStyle(parentGroup, g);
  10615. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  10616. this._textX += parseFloat(dx);
  10617. this._textY += parseFloat(dy);
  10618. return g;
  10619. },
  10620. 'path': function (xmlNode, parentGroup) {
  10621. var d = xmlNode.getAttribute('d') || '';
  10622. var path = createFromString(d);
  10623. inheritStyle(parentGroup, path);
  10624. parseAttributes(xmlNode, path, this._defsUsePending, false, false);
  10625. path.silent = true;
  10626. return path;
  10627. }
  10628. };
  10629. })();
  10630. return SVGParser;
  10631. }());
  10632. var paintServerParsers = {
  10633. 'lineargradient': function (xmlNode) {
  10634. var x1 = parseInt(xmlNode.getAttribute('x1') || '0', 10);
  10635. var y1 = parseInt(xmlNode.getAttribute('y1') || '0', 10);
  10636. var x2 = parseInt(xmlNode.getAttribute('x2') || '10', 10);
  10637. var y2 = parseInt(xmlNode.getAttribute('y2') || '0', 10);
  10638. var gradient = new LinearGradient(x1, y1, x2, y2);
  10639. parsePaintServerUnit(xmlNode, gradient);
  10640. parseGradientColorStops(xmlNode, gradient);
  10641. return gradient;
  10642. },
  10643. 'radialgradient': function (xmlNode) {
  10644. var cx = parseInt(xmlNode.getAttribute('cx') || '0', 10);
  10645. var cy = parseInt(xmlNode.getAttribute('cy') || '0', 10);
  10646. var r = parseInt(xmlNode.getAttribute('r') || '0', 10);
  10647. var gradient = new RadialGradient(cx, cy, r);
  10648. parsePaintServerUnit(xmlNode, gradient);
  10649. parseGradientColorStops(xmlNode, gradient);
  10650. return gradient;
  10651. }
  10652. };
  10653. function parsePaintServerUnit(xmlNode, gradient) {
  10654. var gradientUnits = xmlNode.getAttribute('gradientUnits');
  10655. if (gradientUnits === 'userSpaceOnUse') {
  10656. gradient.global = true;
  10657. }
  10658. }
  10659. function parseGradientColorStops(xmlNode, gradient) {
  10660. var stop = xmlNode.firstChild;
  10661. while (stop) {
  10662. if (stop.nodeType === 1
  10663. && stop.nodeName.toLocaleLowerCase() === 'stop') {
  10664. var offsetStr = stop.getAttribute('offset');
  10665. var offset = void 0;
  10666. if (offsetStr && offsetStr.indexOf('%') > 0) {
  10667. offset = parseInt(offsetStr, 10) / 100;
  10668. }
  10669. else if (offsetStr) {
  10670. offset = parseFloat(offsetStr);
  10671. }
  10672. else {
  10673. offset = 0;
  10674. }
  10675. var styleVals = {};
  10676. parseInlineStyle(stop, styleVals, styleVals);
  10677. var stopColor = styleVals.stopColor
  10678. || stop.getAttribute('stop-color')
  10679. || '#000000';
  10680. gradient.colorStops.push({
  10681. offset: offset,
  10682. color: stopColor
  10683. });
  10684. }
  10685. stop = stop.nextSibling;
  10686. }
  10687. }
  10688. function inheritStyle(parent, child) {
  10689. if (parent && parent.__inheritedStyle) {
  10690. if (!child.__inheritedStyle) {
  10691. child.__inheritedStyle = {};
  10692. }
  10693. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  10694. }
  10695. }
  10696. function parsePoints(pointsString) {
  10697. var list = splitNumberSequence(pointsString);
  10698. var points = [];
  10699. for (var i = 0; i < list.length; i += 2) {
  10700. var x = parseFloat(list[i]);
  10701. var y = parseFloat(list[i + 1]);
  10702. points.push([x, y]);
  10703. }
  10704. return points;
  10705. }
  10706. function parseAttributes(xmlNode, el, defsUsePending, onlyInlineStyle, isTextGroup) {
  10707. var disp = el;
  10708. var inheritedStyle = disp.__inheritedStyle = disp.__inheritedStyle || {};
  10709. var selfStyle = {};
  10710. if (xmlNode.nodeType === 1) {
  10711. parseTransformAttribute(xmlNode, el);
  10712. parseInlineStyle(xmlNode, inheritedStyle, selfStyle);
  10713. if (!onlyInlineStyle) {
  10714. parseAttributeStyle(xmlNode, inheritedStyle, selfStyle);
  10715. }
  10716. }
  10717. disp.style = disp.style || {};
  10718. if (inheritedStyle.fill != null) {
  10719. disp.style.fill = getFillStrokeStyle(disp, 'fill', inheritedStyle.fill, defsUsePending);
  10720. }
  10721. if (inheritedStyle.stroke != null) {
  10722. disp.style.stroke = getFillStrokeStyle(disp, 'stroke', inheritedStyle.stroke, defsUsePending);
  10723. }
  10724. each([
  10725. 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'
  10726. ], function (propName) {
  10727. if (inheritedStyle[propName] != null) {
  10728. disp.style[propName] = parseFloat(inheritedStyle[propName]);
  10729. }
  10730. });
  10731. each([
  10732. 'lineDashOffset', 'lineCap', 'lineJoin', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign'
  10733. ], function (propName) {
  10734. if (inheritedStyle[propName] != null) {
  10735. disp.style[propName] = inheritedStyle[propName];
  10736. }
  10737. });
  10738. if (isTextGroup) {
  10739. disp.__selfStyle = selfStyle;
  10740. }
  10741. if (inheritedStyle.lineDash) {
  10742. disp.style.lineDash = map(splitNumberSequence(inheritedStyle.lineDash), function (str) {
  10743. return parseFloat(str);
  10744. });
  10745. }
  10746. if (inheritedStyle.visibility === 'hidden' || inheritedStyle.visibility === 'collapse') {
  10747. disp.invisible = true;
  10748. }
  10749. if (inheritedStyle.display === 'none') {
  10750. disp.ignore = true;
  10751. }
  10752. }
  10753. function applyTextAlignment(text, parentGroup) {
  10754. var parentSelfStyle = parentGroup.__selfStyle;
  10755. if (parentSelfStyle) {
  10756. var textBaseline = parentSelfStyle.textBaseline;
  10757. var zrTextBaseline = textBaseline;
  10758. if (!textBaseline || textBaseline === 'auto') {
  10759. zrTextBaseline = 'alphabetic';
  10760. }
  10761. else if (textBaseline === 'baseline') {
  10762. zrTextBaseline = 'alphabetic';
  10763. }
  10764. else if (textBaseline === 'before-edge' || textBaseline === 'text-before-edge') {
  10765. zrTextBaseline = 'top';
  10766. }
  10767. else if (textBaseline === 'after-edge' || textBaseline === 'text-after-edge') {
  10768. zrTextBaseline = 'bottom';
  10769. }
  10770. else if (textBaseline === 'central' || textBaseline === 'mathematical') {
  10771. zrTextBaseline = 'middle';
  10772. }
  10773. text.style.textBaseline = zrTextBaseline;
  10774. }
  10775. var parentInheritedStyle = parentGroup.__inheritedStyle;
  10776. if (parentInheritedStyle) {
  10777. var textAlign = parentInheritedStyle.textAlign;
  10778. var zrTextAlign = textAlign;
  10779. if (textAlign) {
  10780. if (textAlign === 'middle') {
  10781. zrTextAlign = 'center';
  10782. }
  10783. text.style.textAlign = zrTextAlign;
  10784. }
  10785. }
  10786. }
  10787. var urlRegex = /^url\(\s*#(.*?)\)/;
  10788. function getFillStrokeStyle(el, method, str, defsUsePending) {
  10789. var urlMatch = str && str.match(urlRegex);
  10790. if (urlMatch) {
  10791. var url = trim(urlMatch[1]);
  10792. defsUsePending.push([el, method, url]);
  10793. return;
  10794. }
  10795. if (str === 'none') {
  10796. str = null;
  10797. }
  10798. return str;
  10799. }
  10800. function applyDefs(defs, defsUsePending) {
  10801. for (var i = 0; i < defsUsePending.length; i++) {
  10802. var item = defsUsePending[i];
  10803. item[0].style[item[1]] = defs[item[2]];
  10804. }
  10805. }
  10806. var numberReg$1 = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  10807. function splitNumberSequence(rawStr) {
  10808. return rawStr.match(numberReg$1) || [];
  10809. }
  10810. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.eE,]*)\)/g;
  10811. var DEGREE_TO_ANGLE = Math.PI / 180;
  10812. function parseTransformAttribute(xmlNode, node) {
  10813. var transform = xmlNode.getAttribute('transform');
  10814. if (transform) {
  10815. transform = transform.replace(/,/g, ' ');
  10816. var transformOps_1 = [];
  10817. var mt = null;
  10818. transform.replace(transformRegex, function (str, type, value) {
  10819. transformOps_1.push(type, value);
  10820. return '';
  10821. });
  10822. for (var i = transformOps_1.length - 1; i > 0; i -= 2) {
  10823. var value = transformOps_1[i];
  10824. var type = transformOps_1[i - 1];
  10825. var valueArr = splitNumberSequence(value);
  10826. mt = mt || create$1();
  10827. switch (type) {
  10828. case 'translate':
  10829. translate(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || '0')]);
  10830. break;
  10831. case 'scale':
  10832. scale$1(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || valueArr[0])]);
  10833. break;
  10834. case 'rotate':
  10835. rotate(mt, mt, -parseFloat(valueArr[0]) * DEGREE_TO_ANGLE, [
  10836. parseFloat(valueArr[1] || '0'),
  10837. parseFloat(valueArr[2] || '0')
  10838. ]);
  10839. break;
  10840. case 'skewX':
  10841. var sx = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10842. mul$1(mt, [1, 0, sx, 1, 0, 0], mt);
  10843. break;
  10844. case 'skewY':
  10845. var sy = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10846. mul$1(mt, [1, sy, 0, 1, 0, 0], mt);
  10847. break;
  10848. case 'matrix':
  10849. mt[0] = parseFloat(valueArr[0]);
  10850. mt[1] = parseFloat(valueArr[1]);
  10851. mt[2] = parseFloat(valueArr[2]);
  10852. mt[3] = parseFloat(valueArr[3]);
  10853. mt[4] = parseFloat(valueArr[4]);
  10854. mt[5] = parseFloat(valueArr[5]);
  10855. break;
  10856. }
  10857. }
  10858. node.setLocalTransform(mt);
  10859. }
  10860. }
  10861. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  10862. function parseInlineStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  10863. var style = xmlNode.getAttribute('style');
  10864. if (!style) {
  10865. return;
  10866. }
  10867. styleRegex.lastIndex = 0;
  10868. var styleRegResult;
  10869. while ((styleRegResult = styleRegex.exec(style)) != null) {
  10870. var svgStlAttr = styleRegResult[1];
  10871. var zrInheritableStlAttr = hasOwn(INHERITABLE_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  10872. ? INHERITABLE_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  10873. : null;
  10874. if (zrInheritableStlAttr) {
  10875. inheritableStyleResult[zrInheritableStlAttr] = styleRegResult[2];
  10876. }
  10877. var zrSelfStlAttr = hasOwn(SELF_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  10878. ? SELF_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  10879. : null;
  10880. if (zrSelfStlAttr) {
  10881. selfStyleResult[zrSelfStlAttr] = styleRegResult[2];
  10882. }
  10883. }
  10884. }
  10885. function parseAttributeStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  10886. for (var i = 0; i < INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  10887. var svgAttrName = INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS[i];
  10888. var attrValue = xmlNode.getAttribute(svgAttrName);
  10889. if (attrValue != null) {
  10890. inheritableStyleResult[INHERITABLE_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  10891. }
  10892. }
  10893. for (var i = 0; i < SELF_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  10894. var svgAttrName = SELF_STYLE_ATTRIBUTES_MAP_KEYS[i];
  10895. var attrValue = xmlNode.getAttribute(svgAttrName);
  10896. if (attrValue != null) {
  10897. selfStyleResult[SELF_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  10898. }
  10899. }
  10900. }
  10901. function makeViewBoxTransform(viewBoxRect, boundingRect) {
  10902. var scaleX = boundingRect.width / viewBoxRect.width;
  10903. var scaleY = boundingRect.height / viewBoxRect.height;
  10904. var scale = Math.min(scaleX, scaleY);
  10905. return {
  10906. scale: scale,
  10907. x: -(viewBoxRect.x + viewBoxRect.width / 2) * scale + (boundingRect.x + boundingRect.width / 2),
  10908. y: -(viewBoxRect.y + viewBoxRect.height / 2) * scale + (boundingRect.y + boundingRect.height / 2)
  10909. };
  10910. }
  10911. function parseSVG(xml, opt) {
  10912. var parser = new SVGParser();
  10913. return parser.parse(xml, opt);
  10914. }
  10915. var PI$2 = Math.PI;
  10916. var PI2$5 = PI$2 * 2;
  10917. var mathSin$3 = Math.sin;
  10918. var mathCos$3 = Math.cos;
  10919. var mathACos = Math.acos;
  10920. var mathATan2 = Math.atan2;
  10921. var mathAbs$1 = Math.abs;
  10922. var mathSqrt$3 = Math.sqrt;
  10923. var mathMax$3 = Math.max;
  10924. var mathMin$3 = Math.min;
  10925. var e = 1e-4;
  10926. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  10927. var dx10 = x1 - x0;
  10928. var dy10 = y1 - y0;
  10929. var dx32 = x3 - x2;
  10930. var dy32 = y3 - y2;
  10931. var t = dy32 * dx10 - dx32 * dy10;
  10932. if (t * t < e) {
  10933. return;
  10934. }
  10935. t = (dx32 * (y0 - y2) - dy32 * (x0 - x2)) / t;
  10936. return [x0 + t * dx10, y0 + t * dy10];
  10937. }
  10938. function computeCornerTangents(x0, y0, x1, y1, radius, cr, clockwise) {
  10939. var x01 = x0 - x1;
  10940. var y01 = y0 - y1;
  10941. var lo = (clockwise ? cr : -cr) / mathSqrt$3(x01 * x01 + y01 * y01);
  10942. var ox = lo * y01;
  10943. var oy = -lo * x01;
  10944. var x11 = x0 + ox;
  10945. var y11 = y0 + oy;
  10946. var x10 = x1 + ox;
  10947. var y10 = y1 + oy;
  10948. var x00 = (x11 + x10) / 2;
  10949. var y00 = (y11 + y10) / 2;
  10950. var dx = x10 - x11;
  10951. var dy = y10 - y11;
  10952. var d2 = dx * dx + dy * dy;
  10953. var r = radius - cr;
  10954. var s = x11 * y10 - x10 * y11;
  10955. var d = (dy < 0 ? -1 : 1) * mathSqrt$3(mathMax$3(0, r * r * d2 - s * s));
  10956. var cx0 = (s * dy - dx * d) / d2;
  10957. var cy0 = (-s * dx - dy * d) / d2;
  10958. var cx1 = (s * dy + dx * d) / d2;
  10959. var cy1 = (-s * dx + dy * d) / d2;
  10960. var dx0 = cx0 - x00;
  10961. var dy0 = cy0 - y00;
  10962. var dx1 = cx1 - x00;
  10963. var dy1 = cy1 - y00;
  10964. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
  10965. cx0 = cx1;
  10966. cy0 = cy1;
  10967. }
  10968. return {
  10969. cx: cx0,
  10970. cy: cy0,
  10971. x0: -ox,
  10972. y0: -oy,
  10973. x1: cx0 * (radius / r - 1),
  10974. y1: cy0 * (radius / r - 1)
  10975. };
  10976. }
  10977. function normalizeCornerRadius(cr) {
  10978. var arr;
  10979. if (isArray(cr)) {
  10980. var len = cr.length;
  10981. if (!len) {
  10982. return cr;
  10983. }
  10984. if (len === 1) {
  10985. arr = [cr[0], cr[0], 0, 0];
  10986. }
  10987. else if (len === 2) {
  10988. arr = [cr[0], cr[0], cr[1], cr[1]];
  10989. }
  10990. else if (len === 3) {
  10991. arr = cr.concat(cr[2]);
  10992. }
  10993. else {
  10994. arr = cr;
  10995. }
  10996. }
  10997. else {
  10998. arr = [cr, cr, cr, cr];
  10999. }
  11000. return arr;
  11001. }
  11002. function buildPath$2(ctx, shape) {
  11003. var _a;
  11004. var radius = mathMax$3(shape.r, 0);
  11005. var innerRadius = mathMax$3(shape.r0 || 0, 0);
  11006. var hasRadius = radius > 0;
  11007. var hasInnerRadius = innerRadius > 0;
  11008. if (!hasRadius && !hasInnerRadius) {
  11009. return;
  11010. }
  11011. if (!hasRadius) {
  11012. radius = innerRadius;
  11013. innerRadius = 0;
  11014. }
  11015. if (innerRadius > radius) {
  11016. var tmp = radius;
  11017. radius = innerRadius;
  11018. innerRadius = tmp;
  11019. }
  11020. var startAngle = shape.startAngle, endAngle = shape.endAngle;
  11021. if (isNaN(startAngle) || isNaN(endAngle)) {
  11022. return;
  11023. }
  11024. var cx = shape.cx, cy = shape.cy;
  11025. var clockwise = !!shape.clockwise;
  11026. var arc = mathAbs$1(endAngle - startAngle);
  11027. var mod = arc > PI2$5 && arc % PI2$5;
  11028. mod > e && (arc = mod);
  11029. if (!(radius > e)) {
  11030. ctx.moveTo(cx, cy);
  11031. }
  11032. else if (arc > PI2$5 - e) {
  11033. ctx.moveTo(cx + radius * mathCos$3(startAngle), cy + radius * mathSin$3(startAngle));
  11034. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  11035. if (innerRadius > e) {
  11036. ctx.moveTo(cx + innerRadius * mathCos$3(endAngle), cy + innerRadius * mathSin$3(endAngle));
  11037. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  11038. }
  11039. }
  11040. else {
  11041. var icrStart = void 0;
  11042. var icrEnd = void 0;
  11043. var ocrStart = void 0;
  11044. var ocrEnd = void 0;
  11045. var ocrs = void 0;
  11046. var ocre = void 0;
  11047. var icrs = void 0;
  11048. var icre = void 0;
  11049. var ocrMax = void 0;
  11050. var icrMax = void 0;
  11051. var limitedOcrMax = void 0;
  11052. var limitedIcrMax = void 0;
  11053. var xre = void 0;
  11054. var yre = void 0;
  11055. var xirs = void 0;
  11056. var yirs = void 0;
  11057. var xrs = radius * mathCos$3(startAngle);
  11058. var yrs = radius * mathSin$3(startAngle);
  11059. var xire = innerRadius * mathCos$3(endAngle);
  11060. var yire = innerRadius * mathSin$3(endAngle);
  11061. var hasArc = arc > e;
  11062. if (hasArc) {
  11063. var cornerRadius = shape.cornerRadius;
  11064. if (cornerRadius) {
  11065. _a = normalizeCornerRadius(cornerRadius), icrStart = _a[0], icrEnd = _a[1], ocrStart = _a[2], ocrEnd = _a[3];
  11066. }
  11067. var halfRd = mathAbs$1(radius - innerRadius) / 2;
  11068. ocrs = mathMin$3(halfRd, ocrStart);
  11069. ocre = mathMin$3(halfRd, ocrEnd);
  11070. icrs = mathMin$3(halfRd, icrStart);
  11071. icre = mathMin$3(halfRd, icrEnd);
  11072. limitedOcrMax = ocrMax = mathMax$3(ocrs, ocre);
  11073. limitedIcrMax = icrMax = mathMax$3(icrs, icre);
  11074. if (ocrMax > e || icrMax > e) {
  11075. xre = radius * mathCos$3(endAngle);
  11076. yre = radius * mathSin$3(endAngle);
  11077. xirs = innerRadius * mathCos$3(startAngle);
  11078. yirs = innerRadius * mathSin$3(startAngle);
  11079. if (arc < PI$2) {
  11080. var it_1 = intersect(xrs, yrs, xirs, yirs, xre, yre, xire, yire);
  11081. if (it_1) {
  11082. var x0 = xrs - it_1[0];
  11083. var y0 = yrs - it_1[1];
  11084. var x1 = xre - it_1[0];
  11085. var y1 = yre - it_1[1];
  11086. var a = 1 / mathSin$3(mathACos((x0 * x1 + y0 * y1) / (mathSqrt$3(x0 * x0 + y0 * y0) * mathSqrt$3(x1 * x1 + y1 * y1))) / 2);
  11087. var b = mathSqrt$3(it_1[0] * it_1[0] + it_1[1] * it_1[1]);
  11088. limitedOcrMax = mathMin$3(ocrMax, (radius - b) / (a + 1));
  11089. limitedIcrMax = mathMin$3(icrMax, (innerRadius - b) / (a - 1));
  11090. }
  11091. }
  11092. }
  11093. }
  11094. if (!hasArc) {
  11095. ctx.moveTo(cx + xrs, cy + yrs);
  11096. }
  11097. else if (limitedOcrMax > e) {
  11098. var crStart = mathMin$3(ocrStart, limitedOcrMax);
  11099. var crEnd = mathMin$3(ocrEnd, limitedOcrMax);
  11100. var ct0 = computeCornerTangents(xirs, yirs, xrs, yrs, radius, crStart, clockwise);
  11101. var ct1 = computeCornerTangents(xre, yre, xire, yire, radius, crEnd, clockwise);
  11102. ctx.moveTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  11103. if (limitedOcrMax < ocrMax && crStart === crEnd) {
  11104. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedOcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11105. }
  11106. else {
  11107. crStart > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crStart, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  11108. ctx.arc(cx, cy, radius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), !clockwise);
  11109. crEnd > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crEnd, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11110. }
  11111. }
  11112. else {
  11113. ctx.moveTo(cx + xrs, cy + yrs);
  11114. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  11115. }
  11116. if (!(innerRadius > e) || !hasArc) {
  11117. ctx.lineTo(cx + xire, cy + yire);
  11118. }
  11119. else if (limitedIcrMax > e) {
  11120. var crStart = mathMin$3(icrStart, limitedIcrMax);
  11121. var crEnd = mathMin$3(icrEnd, limitedIcrMax);
  11122. var ct0 = computeCornerTangents(xire, yire, xre, yre, innerRadius, -crEnd, clockwise);
  11123. var ct1 = computeCornerTangents(xrs, yrs, xirs, yirs, innerRadius, -crStart, clockwise);
  11124. ctx.lineTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  11125. if (limitedIcrMax < icrMax && crStart === crEnd) {
  11126. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedIcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11127. }
  11128. else {
  11129. crEnd > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crEnd, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  11130. ctx.arc(cx, cy, innerRadius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), clockwise);
  11131. crStart > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crStart, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11132. }
  11133. }
  11134. else {
  11135. ctx.lineTo(cx + xire, cy + yire);
  11136. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  11137. }
  11138. }
  11139. ctx.closePath();
  11140. }
  11141. var SectorShape = (function () {
  11142. function SectorShape() {
  11143. this.cx = 0;
  11144. this.cy = 0;
  11145. this.r0 = 0;
  11146. this.r = 0;
  11147. this.startAngle = 0;
  11148. this.endAngle = Math.PI * 2;
  11149. this.clockwise = true;
  11150. this.cornerRadius = 0;
  11151. }
  11152. return SectorShape;
  11153. }());
  11154. var Sector = (function (_super) {
  11155. __extends(Sector, _super);
  11156. function Sector(opts) {
  11157. return _super.call(this, opts) || this;
  11158. }
  11159. Sector.prototype.getDefaultShape = function () {
  11160. return new SectorShape();
  11161. };
  11162. Sector.prototype.buildPath = function (ctx, shape) {
  11163. buildPath$2(ctx, shape);
  11164. };
  11165. Sector.prototype.isZeroArea = function () {
  11166. return this.shape.startAngle === this.shape.endAngle
  11167. || this.shape.r === this.shape.r0;
  11168. };
  11169. return Sector;
  11170. }(Path));
  11171. Sector.prototype.type = 'sector';
  11172. var CMD$3 = PathProxy.CMD;
  11173. function aroundEqual(a, b) {
  11174. return Math.abs(a - b) < 1e-5;
  11175. }
  11176. function pathToBezierCurves(path) {
  11177. var data = path.data;
  11178. var len = path.len();
  11179. var bezierArrayGroups = [];
  11180. var currentSubpath;
  11181. var xi = 0;
  11182. var yi = 0;
  11183. var x0 = 0;
  11184. var y0 = 0;
  11185. function createNewSubpath(x, y) {
  11186. if (currentSubpath && currentSubpath.length > 2) {
  11187. bezierArrayGroups.push(currentSubpath);
  11188. }
  11189. currentSubpath = [x, y];
  11190. }
  11191. function addLine(x0, y0, x1, y1) {
  11192. if (!(aroundEqual(x0, x1) && aroundEqual(y0, y1))) {
  11193. currentSubpath.push(x0, y0, x1, y1, x1, y1);
  11194. }
  11195. }
  11196. function addArc(startAngle, endAngle, cx, cy, rx, ry) {
  11197. var delta = Math.abs(endAngle - startAngle);
  11198. var len = Math.tan(delta / 4) * 4 / 3;
  11199. var dir = endAngle < startAngle ? -1 : 1;
  11200. var c1 = Math.cos(startAngle);
  11201. var s1 = Math.sin(startAngle);
  11202. var c2 = Math.cos(endAngle);
  11203. var s2 = Math.sin(endAngle);
  11204. var x1 = c1 * rx + cx;
  11205. var y1 = s1 * ry + cy;
  11206. var x4 = c2 * rx + cx;
  11207. var y4 = s2 * ry + cy;
  11208. var hx = rx * len * dir;
  11209. var hy = ry * len * dir;
  11210. currentSubpath.push(x1 - hx * s1, y1 + hy * c1, x4 + hx * s2, y4 - hy * c2, x4, y4);
  11211. }
  11212. var x1;
  11213. var y1;
  11214. var x2;
  11215. var y2;
  11216. for (var i = 0; i < len;) {
  11217. var cmd = data[i++];
  11218. var isFirst = i === 1;
  11219. if (isFirst) {
  11220. xi = data[i];
  11221. yi = data[i + 1];
  11222. x0 = xi;
  11223. y0 = yi;
  11224. if (cmd === CMD$3.L || cmd === CMD$3.C || cmd === CMD$3.Q) {
  11225. currentSubpath = [x0, y0];
  11226. }
  11227. }
  11228. switch (cmd) {
  11229. case CMD$3.M:
  11230. xi = x0 = data[i++];
  11231. yi = y0 = data[i++];
  11232. createNewSubpath(x0, y0);
  11233. break;
  11234. case CMD$3.L:
  11235. x1 = data[i++];
  11236. y1 = data[i++];
  11237. addLine(xi, yi, x1, y1);
  11238. xi = x1;
  11239. yi = y1;
  11240. break;
  11241. case CMD$3.C:
  11242. currentSubpath.push(data[i++], data[i++], data[i++], data[i++], xi = data[i++], yi = data[i++]);
  11243. break;
  11244. case CMD$3.Q:
  11245. x1 = data[i++];
  11246. y1 = data[i++];
  11247. x2 = data[i++];
  11248. y2 = data[i++];
  11249. currentSubpath.push(xi + 2 / 3 * (x1 - xi), yi + 2 / 3 * (y1 - yi), x2 + 2 / 3 * (x1 - x2), y2 + 2 / 3 * (y1 - y2), x2, y2);
  11250. xi = x2;
  11251. yi = y2;
  11252. break;
  11253. case CMD$3.A:
  11254. var cx = data[i++];
  11255. var cy = data[i++];
  11256. var rx = data[i++];
  11257. var ry = data[i++];
  11258. var startAngle = data[i++];
  11259. var endAngle = data[i++] + startAngle;
  11260. i += 1;
  11261. var anticlockwise = !data[i++];
  11262. x1 = Math.cos(startAngle) * rx + cx;
  11263. y1 = Math.sin(startAngle) * ry + cy;
  11264. if (isFirst) {
  11265. x0 = x1;
  11266. y0 = y1;
  11267. createNewSubpath(x0, y0);
  11268. }
  11269. else {
  11270. addLine(xi, yi, x1, y1);
  11271. }
  11272. xi = Math.cos(endAngle) * rx + cx;
  11273. yi = Math.sin(endAngle) * ry + cy;
  11274. var step = (anticlockwise ? -1 : 1) * Math.PI / 2;
  11275. for (var angle = startAngle; anticlockwise ? angle > endAngle : angle < endAngle; angle += step) {
  11276. var nextAngle = anticlockwise ? Math.max(angle + step, endAngle)
  11277. : Math.min(angle + step, endAngle);
  11278. addArc(angle, nextAngle, cx, cy, rx, ry);
  11279. }
  11280. break;
  11281. case CMD$3.R:
  11282. x0 = xi = data[i++];
  11283. y0 = yi = data[i++];
  11284. x1 = x0 + data[i++];
  11285. y1 = y0 + data[i++];
  11286. createNewSubpath(x1, y0);
  11287. addLine(x1, y0, x1, y1);
  11288. addLine(x1, y1, x0, y1);
  11289. addLine(x0, y1, x0, y0);
  11290. addLine(x0, y0, x1, y0);
  11291. break;
  11292. case CMD$3.Z:
  11293. currentSubpath && addLine(xi, yi, x0, y0);
  11294. xi = x0;
  11295. yi = y0;
  11296. break;
  11297. }
  11298. }
  11299. if (currentSubpath && currentSubpath.length > 2) {
  11300. bezierArrayGroups.push(currentSubpath);
  11301. }
  11302. return bezierArrayGroups;
  11303. }
  11304. function adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, out, scale) {
  11305. if (aroundEqual(x0, x1) && aroundEqual(y0, y1) && aroundEqual(x2, x3) && aroundEqual(y2, y3)) {
  11306. out.push(x3, y3);
  11307. return;
  11308. }
  11309. var PIXEL_DISTANCE = 2 / scale;
  11310. var PIXEL_DISTANCE_SQR = PIXEL_DISTANCE * PIXEL_DISTANCE;
  11311. var dx = x3 - x0;
  11312. var dy = y3 - y0;
  11313. var d = Math.sqrt(dx * dx + dy * dy);
  11314. dx /= d;
  11315. dy /= d;
  11316. var dx1 = x1 - x0;
  11317. var dy1 = y1 - y0;
  11318. var dx2 = x2 - x3;
  11319. var dy2 = y2 - y3;
  11320. var cp1LenSqr = dx1 * dx1 + dy1 * dy1;
  11321. var cp2LenSqr = dx2 * dx2 + dy2 * dy2;
  11322. if (cp1LenSqr < PIXEL_DISTANCE_SQR && cp2LenSqr < PIXEL_DISTANCE_SQR) {
  11323. out.push(x3, y3);
  11324. return;
  11325. }
  11326. var projLen1 = dx * dx1 + dy * dy1;
  11327. var projLen2 = -dx * dx2 - dy * dy2;
  11328. var d1Sqr = cp1LenSqr - projLen1 * projLen1;
  11329. var d2Sqr = cp2LenSqr - projLen2 * projLen2;
  11330. if (d1Sqr < PIXEL_DISTANCE_SQR && projLen1 >= 0
  11331. && d2Sqr < PIXEL_DISTANCE_SQR && projLen2 >= 0) {
  11332. out.push(x3, y3);
  11333. return;
  11334. }
  11335. var tmpSegX = [];
  11336. var tmpSegY = [];
  11337. cubicSubdivide(x0, x1, x2, x3, 0.5, tmpSegX);
  11338. cubicSubdivide(y0, y1, y2, y3, 0.5, tmpSegY);
  11339. adpativeBezier(tmpSegX[0], tmpSegY[0], tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], tmpSegX[3], tmpSegY[3], out, scale);
  11340. adpativeBezier(tmpSegX[4], tmpSegY[4], tmpSegX[5], tmpSegY[5], tmpSegX[6], tmpSegY[6], tmpSegX[7], tmpSegY[7], out, scale);
  11341. }
  11342. function pathToPolygons(path, scale) {
  11343. var bezierArrayGroups = pathToBezierCurves(path);
  11344. var polygons = [];
  11345. scale = scale || 1;
  11346. for (var i = 0; i < bezierArrayGroups.length; i++) {
  11347. var beziers = bezierArrayGroups[i];
  11348. var polygon = [];
  11349. var x0 = beziers[0];
  11350. var y0 = beziers[1];
  11351. polygon.push(x0, y0);
  11352. for (var k = 2; k < beziers.length;) {
  11353. var x1 = beziers[k++];
  11354. var y1 = beziers[k++];
  11355. var x2 = beziers[k++];
  11356. var y2 = beziers[k++];
  11357. var x3 = beziers[k++];
  11358. var y3 = beziers[k++];
  11359. adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, polygon, scale);
  11360. x0 = x3;
  11361. y0 = y3;
  11362. }
  11363. polygons.push(polygon);
  11364. }
  11365. return polygons;
  11366. }
  11367. function getDividingGrids(dimSize, rowDim, count) {
  11368. var rowSize = dimSize[rowDim];
  11369. var columnSize = dimSize[1 - rowDim];
  11370. var ratio = Math.abs(rowSize / columnSize);
  11371. var rowCount = Math.ceil(Math.sqrt(ratio * count));
  11372. var columnCount = Math.floor(count / rowCount);
  11373. if (columnCount === 0) {
  11374. columnCount = 1;
  11375. rowCount = count;
  11376. }
  11377. var grids = [];
  11378. for (var i = 0; i < rowCount; i++) {
  11379. grids.push(columnCount);
  11380. }
  11381. var currentCount = rowCount * columnCount;
  11382. var remained = count - currentCount;
  11383. if (remained > 0) {
  11384. for (var i = 0; i < remained; i++) {
  11385. grids[i % rowCount] += 1;
  11386. }
  11387. }
  11388. return grids;
  11389. }
  11390. function divideSector(sectorShape, count, outShapes) {
  11391. var r0 = sectorShape.r0;
  11392. var r = sectorShape.r;
  11393. var startAngle = sectorShape.startAngle;
  11394. var endAngle = sectorShape.endAngle;
  11395. var angle = Math.abs(endAngle - startAngle);
  11396. var arcLen = angle * r;
  11397. var deltaR = r - r0;
  11398. var isAngleRow = arcLen > Math.abs(deltaR);
  11399. var grids = getDividingGrids([arcLen, deltaR], isAngleRow ? 0 : 1, count);
  11400. var rowSize = (isAngleRow ? angle : deltaR) / grids.length;
  11401. for (var row = 0; row < grids.length; row++) {
  11402. var columnSize = (isAngleRow ? deltaR : angle) / grids[row];
  11403. for (var column = 0; column < grids[row]; column++) {
  11404. var newShape = {};
  11405. if (isAngleRow) {
  11406. newShape.startAngle = startAngle + rowSize * row;
  11407. newShape.endAngle = startAngle + rowSize * (row + 1);
  11408. newShape.r0 = r0 + columnSize * column;
  11409. newShape.r = r0 + columnSize * (column + 1);
  11410. }
  11411. else {
  11412. newShape.startAngle = startAngle + columnSize * column;
  11413. newShape.endAngle = startAngle + columnSize * (column + 1);
  11414. newShape.r0 = r0 + rowSize * row;
  11415. newShape.r = r0 + rowSize * (row + 1);
  11416. }
  11417. newShape.clockwise = sectorShape.clockwise;
  11418. newShape.cx = sectorShape.cx;
  11419. newShape.cy = sectorShape.cy;
  11420. outShapes.push(newShape);
  11421. }
  11422. }
  11423. }
  11424. function divideRect(rectShape, count, outShapes) {
  11425. var width = rectShape.width;
  11426. var height = rectShape.height;
  11427. var isHorizontalRow = width > height;
  11428. var grids = getDividingGrids([width, height], isHorizontalRow ? 0 : 1, count);
  11429. var rowSizeDim = isHorizontalRow ? 'width' : 'height';
  11430. var columnSizeDim = isHorizontalRow ? 'height' : 'width';
  11431. var rowDim = isHorizontalRow ? 'x' : 'y';
  11432. var columnDim = isHorizontalRow ? 'y' : 'x';
  11433. var rowSize = rectShape[rowSizeDim] / grids.length;
  11434. for (var row = 0; row < grids.length; row++) {
  11435. var columnSize = rectShape[columnSizeDim] / grids[row];
  11436. for (var column = 0; column < grids[row]; column++) {
  11437. var newShape = {};
  11438. newShape[rowDim] = row * rowSize;
  11439. newShape[columnDim] = column * columnSize;
  11440. newShape[rowSizeDim] = rowSize;
  11441. newShape[columnSizeDim] = columnSize;
  11442. newShape.x += rectShape.x;
  11443. newShape.y += rectShape.y;
  11444. outShapes.push(newShape);
  11445. }
  11446. }
  11447. }
  11448. function crossProduct2d(x1, y1, x2, y2) {
  11449. return x1 * y2 - x2 * y1;
  11450. }
  11451. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  11452. var mx = a2x - a1x;
  11453. var my = a2y - a1y;
  11454. var nx = b2x - b1x;
  11455. var ny = b2y - b1y;
  11456. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  11457. if (Math.abs(nmCrossProduct) < 1e-6) {
  11458. return null;
  11459. }
  11460. var b1a1x = a1x - b1x;
  11461. var b1a1y = a1y - b1y;
  11462. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  11463. if (p < 0 || p > 1) {
  11464. return null;
  11465. }
  11466. return new Point(p * mx + a1x, p * my + a1y);
  11467. }
  11468. function projPtOnLine(pt, lineA, lineB) {
  11469. var dir = new Point();
  11470. Point.sub(dir, lineB, lineA);
  11471. dir.normalize();
  11472. var dir2 = new Point();
  11473. Point.sub(dir2, pt, lineA);
  11474. var len = dir2.dot(dir);
  11475. return len;
  11476. }
  11477. function addToPoly(poly, pt) {
  11478. var last = poly[poly.length - 1];
  11479. if (last && last[0] === pt[0] && last[1] === pt[1]) {
  11480. return;
  11481. }
  11482. poly.push(pt);
  11483. }
  11484. function splitPolygonByLine(points, lineA, lineB) {
  11485. var len = points.length;
  11486. var intersections = [];
  11487. for (var i = 0; i < len; i++) {
  11488. var p0 = points[i];
  11489. var p1 = points[(i + 1) % len];
  11490. var intersectionPt = lineLineIntersect(p0[0], p0[1], p1[0], p1[1], lineA.x, lineA.y, lineB.x, lineB.y);
  11491. if (intersectionPt) {
  11492. intersections.push({
  11493. projPt: projPtOnLine(intersectionPt, lineA, lineB),
  11494. pt: intersectionPt,
  11495. idx: i
  11496. });
  11497. }
  11498. }
  11499. if (intersections.length < 2) {
  11500. return [{ points: points }, { points: points }];
  11501. }
  11502. intersections.sort(function (a, b) {
  11503. return a.projPt - b.projPt;
  11504. });
  11505. var splitPt0 = intersections[0];
  11506. var splitPt1 = intersections[intersections.length - 1];
  11507. if (splitPt1.idx < splitPt0.idx) {
  11508. var tmp = splitPt0;
  11509. splitPt0 = splitPt1;
  11510. splitPt1 = tmp;
  11511. }
  11512. var splitPt0Arr = [splitPt0.pt.x, splitPt0.pt.y];
  11513. var splitPt1Arr = [splitPt1.pt.x, splitPt1.pt.y];
  11514. var newPolyA = [splitPt0Arr];
  11515. var newPolyB = [splitPt1Arr];
  11516. for (var i = splitPt0.idx + 1; i <= splitPt1.idx; i++) {
  11517. addToPoly(newPolyA, points[i].slice());
  11518. }
  11519. addToPoly(newPolyA, splitPt1Arr);
  11520. addToPoly(newPolyA, splitPt0Arr);
  11521. for (var i = splitPt1.idx + 1; i <= splitPt0.idx + len; i++) {
  11522. addToPoly(newPolyB, points[i % len].slice());
  11523. }
  11524. addToPoly(newPolyB, splitPt0Arr);
  11525. addToPoly(newPolyB, splitPt1Arr);
  11526. return [{
  11527. points: newPolyA
  11528. }, {
  11529. points: newPolyB
  11530. }];
  11531. }
  11532. function binaryDividePolygon(polygonShape) {
  11533. var points = polygonShape.points;
  11534. var min = [];
  11535. var max = [];
  11536. fromPoints(points, min, max);
  11537. var boundingRect = new BoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  11538. var width = boundingRect.width;
  11539. var height = boundingRect.height;
  11540. var x = boundingRect.x;
  11541. var y = boundingRect.y;
  11542. var pt0 = new Point();
  11543. var pt1 = new Point();
  11544. if (width > height) {
  11545. pt0.x = pt1.x = x + width / 2;
  11546. pt0.y = y;
  11547. pt1.y = y + height;
  11548. }
  11549. else {
  11550. pt0.y = pt1.y = y + height / 2;
  11551. pt0.x = x;
  11552. pt1.x = x + width;
  11553. }
  11554. return splitPolygonByLine(points, pt0, pt1);
  11555. }
  11556. function binaryDivideRecursive(divider, shape, count, out) {
  11557. if (count === 1) {
  11558. out.push(shape);
  11559. }
  11560. else {
  11561. var mid = Math.floor(count / 2);
  11562. var sub = divider(shape);
  11563. binaryDivideRecursive(divider, sub[0], mid, out);
  11564. binaryDivideRecursive(divider, sub[1], count - mid, out);
  11565. }
  11566. return out;
  11567. }
  11568. function clone$3(path, count) {
  11569. var paths = [];
  11570. for (var i = 0; i < count; i++) {
  11571. paths.push(clonePath(path));
  11572. }
  11573. return paths;
  11574. }
  11575. function copyPathProps(source, target) {
  11576. target.setStyle(source.style);
  11577. target.z = source.z;
  11578. target.z2 = source.z2;
  11579. target.zlevel = source.zlevel;
  11580. }
  11581. function polygonConvert(points) {
  11582. var out = [];
  11583. for (var i = 0; i < points.length;) {
  11584. out.push([points[i++], points[i++]]);
  11585. }
  11586. return out;
  11587. }
  11588. function split(path, count) {
  11589. var outShapes = [];
  11590. var shape = path.shape;
  11591. var OutShapeCtor;
  11592. switch (path.type) {
  11593. case 'rect':
  11594. divideRect(shape, count, outShapes);
  11595. OutShapeCtor = Rect;
  11596. break;
  11597. case 'sector':
  11598. divideSector(shape, count, outShapes);
  11599. OutShapeCtor = Sector;
  11600. break;
  11601. case 'circle':
  11602. divideSector({
  11603. r0: 0, r: shape.r, startAngle: 0, endAngle: Math.PI * 2,
  11604. cx: shape.cx, cy: shape.cy
  11605. }, count, outShapes);
  11606. OutShapeCtor = Sector;
  11607. break;
  11608. default:
  11609. var m = path.getComputedTransform();
  11610. var scale = m ? Math.sqrt(Math.max(m[0] * m[0] + m[1] * m[1], m[2] * m[2] + m[3] * m[3])) : 1;
  11611. var polygons = map(pathToPolygons(path.getUpdatedPathProxy(), scale), function (poly) { return polygonConvert(poly); });
  11612. var polygonCount = polygons.length;
  11613. if (polygonCount === 0) {
  11614. binaryDivideRecursive(binaryDividePolygon, {
  11615. points: polygons[0]
  11616. }, count, outShapes);
  11617. }
  11618. else if (polygonCount === count) {
  11619. for (var i = 0; i < polygonCount; i++) {
  11620. outShapes.push({
  11621. points: polygons[i]
  11622. });
  11623. }
  11624. }
  11625. else {
  11626. var totalArea_1 = 0;
  11627. var items = map(polygons, function (poly) {
  11628. var min = [];
  11629. var max = [];
  11630. fromPoints(poly, min, max);
  11631. var area = (max[1] - min[1]) * (max[0] - min[0]);
  11632. totalArea_1 += area;
  11633. return { poly: poly, area: area };
  11634. });
  11635. items.sort(function (a, b) { return b.area - a.area; });
  11636. var left = count;
  11637. for (var i = 0; i < polygonCount; i++) {
  11638. var item = items[i];
  11639. if (left <= 0) {
  11640. break;
  11641. }
  11642. var selfCount = i === polygonCount - 1
  11643. ? left
  11644. : Math.ceil(item.area / totalArea_1 * count);
  11645. if (selfCount < 0) {
  11646. continue;
  11647. }
  11648. binaryDivideRecursive(binaryDividePolygon, {
  11649. points: item.poly
  11650. }, selfCount, outShapes);
  11651. left -= selfCount;
  11652. }
  11653. }
  11654. OutShapeCtor = Polygon;
  11655. break;
  11656. }
  11657. if (!OutShapeCtor) {
  11658. return clone$3(path, count);
  11659. }
  11660. var out = [];
  11661. for (var i = 0; i < outShapes.length; i++) {
  11662. var subPath = new OutShapeCtor();
  11663. subPath.setShape(outShapes[i]);
  11664. copyPathProps(path, subPath);
  11665. out.push(subPath);
  11666. }
  11667. return out;
  11668. }
  11669. function alignSubpath(subpath1, subpath2) {
  11670. var len1 = subpath1.length;
  11671. var len2 = subpath2.length;
  11672. if (len1 === len2) {
  11673. return [subpath1, subpath2];
  11674. }
  11675. var tmpSegX = [];
  11676. var tmpSegY = [];
  11677. var shorterPath = len1 < len2 ? subpath1 : subpath2;
  11678. var shorterLen = Math.min(len1, len2);
  11679. var diff = Math.abs(len2 - len1) / 6;
  11680. var shorterBezierCount = (shorterLen - 2) / 6;
  11681. var eachCurveSubDivCount = Math.ceil(diff / shorterBezierCount) + 1;
  11682. var newSubpath = [shorterPath[0], shorterPath[1]];
  11683. var remained = diff;
  11684. for (var i = 2; i < shorterLen;) {
  11685. var x0 = shorterPath[i - 2];
  11686. var y0 = shorterPath[i - 1];
  11687. var x1 = shorterPath[i++];
  11688. var y1 = shorterPath[i++];
  11689. var x2 = shorterPath[i++];
  11690. var y2 = shorterPath[i++];
  11691. var x3 = shorterPath[i++];
  11692. var y3 = shorterPath[i++];
  11693. if (remained <= 0) {
  11694. newSubpath.push(x1, y1, x2, y2, x3, y3);
  11695. continue;
  11696. }
  11697. var actualSubDivCount = Math.min(remained, eachCurveSubDivCount - 1) + 1;
  11698. for (var k = 1; k <= actualSubDivCount; k++) {
  11699. var p = k / actualSubDivCount;
  11700. cubicSubdivide(x0, x1, x2, x3, p, tmpSegX);
  11701. cubicSubdivide(y0, y1, y2, y3, p, tmpSegY);
  11702. x0 = tmpSegX[3];
  11703. y0 = tmpSegY[3];
  11704. newSubpath.push(tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], x0, y0);
  11705. x1 = tmpSegX[5];
  11706. y1 = tmpSegY[5];
  11707. x2 = tmpSegX[6];
  11708. y2 = tmpSegY[6];
  11709. }
  11710. remained -= actualSubDivCount - 1;
  11711. }
  11712. return shorterPath === subpath1 ? [newSubpath, subpath2] : [subpath1, newSubpath];
  11713. }
  11714. function createSubpath(lastSubpathSubpath, otherSubpath) {
  11715. var len = lastSubpathSubpath.length;
  11716. var lastX = lastSubpathSubpath[len - 2];
  11717. var lastY = lastSubpathSubpath[len - 1];
  11718. var newSubpath = [];
  11719. for (var i = 0; i < otherSubpath.length;) {
  11720. newSubpath[i++] = lastX;
  11721. newSubpath[i++] = lastY;
  11722. }
  11723. return newSubpath;
  11724. }
  11725. function alignBezierCurves(array1, array2) {
  11726. var _a;
  11727. var lastSubpath1;
  11728. var lastSubpath2;
  11729. var newArray1 = [];
  11730. var newArray2 = [];
  11731. for (var i = 0; i < Math.max(array1.length, array2.length); i++) {
  11732. var subpath1 = array1[i];
  11733. var subpath2 = array2[i];
  11734. var newSubpath1 = void 0;
  11735. var newSubpath2 = void 0;
  11736. if (!subpath1) {
  11737. newSubpath1 = createSubpath(lastSubpath1 || subpath2, subpath2);
  11738. newSubpath2 = subpath2;
  11739. }
  11740. else if (!subpath2) {
  11741. newSubpath2 = createSubpath(lastSubpath2 || subpath1, subpath1);
  11742. newSubpath1 = subpath1;
  11743. }
  11744. else {
  11745. _a = alignSubpath(subpath1, subpath2), newSubpath1 = _a[0], newSubpath2 = _a[1];
  11746. lastSubpath1 = newSubpath1;
  11747. lastSubpath2 = newSubpath2;
  11748. }
  11749. newArray1.push(newSubpath1);
  11750. newArray2.push(newSubpath2);
  11751. }
  11752. return [newArray1, newArray2];
  11753. }
  11754. function centroid(array) {
  11755. var signedArea = 0;
  11756. var cx = 0;
  11757. var cy = 0;
  11758. var len = array.length;
  11759. for (var i = 0, j = len - 2; i < len; j = i, i += 2) {
  11760. var x0 = array[j];
  11761. var y0 = array[j + 1];
  11762. var x1 = array[i];
  11763. var y1 = array[i + 1];
  11764. var a = x0 * y1 - x1 * y0;
  11765. signedArea += a;
  11766. cx += (x0 + x1) * a;
  11767. cy += (y0 + y1) * a;
  11768. }
  11769. if (signedArea === 0) {
  11770. return [array[0] || 0, array[1] || 0];
  11771. }
  11772. return [cx / signedArea / 3, cy / signedArea / 3, signedArea];
  11773. }
  11774. function findBestRingOffset(fromSubBeziers, toSubBeziers, fromCp, toCp) {
  11775. var bezierCount = (fromSubBeziers.length - 2) / 6;
  11776. var bestScore = Infinity;
  11777. var bestOffset = 0;
  11778. var len = fromSubBeziers.length;
  11779. var len2 = len - 2;
  11780. for (var offset = 0; offset < bezierCount; offset++) {
  11781. var cursorOffset = offset * 6;
  11782. var score = 0;
  11783. for (var k = 0; k < len; k += 2) {
  11784. var idx = k === 0 ? cursorOffset : ((cursorOffset + k - 2) % len2 + 2);
  11785. var x0 = fromSubBeziers[idx] - fromCp[0];
  11786. var y0 = fromSubBeziers[idx + 1] - fromCp[1];
  11787. var x1 = toSubBeziers[k] - toCp[0];
  11788. var y1 = toSubBeziers[k + 1] - toCp[1];
  11789. var dx = x1 - x0;
  11790. var dy = y1 - y0;
  11791. score += dx * dx + dy * dy;
  11792. }
  11793. if (score < bestScore) {
  11794. bestScore = score;
  11795. bestOffset = offset;
  11796. }
  11797. }
  11798. return bestOffset;
  11799. }
  11800. function reverse(array) {
  11801. var newArr = [];
  11802. var len = array.length;
  11803. for (var i = 0; i < len; i += 2) {
  11804. newArr[i] = array[len - i - 2];
  11805. newArr[i + 1] = array[len - i - 1];
  11806. }
  11807. return newArr;
  11808. }
  11809. function findBestMorphingRotation(fromArr, toArr, searchAngleIteration, searchAngleRange) {
  11810. var result = [];
  11811. var fromNeedsReverse;
  11812. for (var i = 0; i < fromArr.length; i++) {
  11813. var fromSubpathBezier = fromArr[i];
  11814. var toSubpathBezier = toArr[i];
  11815. var fromCp = centroid(fromSubpathBezier);
  11816. var toCp = centroid(toSubpathBezier);
  11817. if (fromNeedsReverse == null) {
  11818. fromNeedsReverse = fromCp[2] < 0 !== toCp[2] < 0;
  11819. }
  11820. var newFromSubpathBezier = [];
  11821. var newToSubpathBezier = [];
  11822. var bestAngle = 0;
  11823. var bestScore = Infinity;
  11824. var tmpArr = [];
  11825. var len = fromSubpathBezier.length;
  11826. if (fromNeedsReverse) {
  11827. fromSubpathBezier = reverse(fromSubpathBezier);
  11828. }
  11829. var offset = findBestRingOffset(fromSubpathBezier, toSubpathBezier, fromCp, toCp) * 6;
  11830. var len2 = len - 2;
  11831. for (var k = 0; k < len2; k += 2) {
  11832. var idx = (offset + k) % len2 + 2;
  11833. newFromSubpathBezier[k + 2] = fromSubpathBezier[idx] - fromCp[0];
  11834. newFromSubpathBezier[k + 3] = fromSubpathBezier[idx + 1] - fromCp[1];
  11835. }
  11836. newFromSubpathBezier[0] = fromSubpathBezier[offset] - fromCp[0];
  11837. newFromSubpathBezier[1] = fromSubpathBezier[offset + 1] - fromCp[1];
  11838. if (searchAngleIteration > 0) {
  11839. var step = searchAngleRange / searchAngleIteration;
  11840. for (var angle = -searchAngleRange / 2; angle <= searchAngleRange / 2; angle += step) {
  11841. var sa = Math.sin(angle);
  11842. var ca = Math.cos(angle);
  11843. var score = 0;
  11844. for (var k = 0; k < fromSubpathBezier.length; k += 2) {
  11845. var x0 = newFromSubpathBezier[k];
  11846. var y0 = newFromSubpathBezier[k + 1];
  11847. var x1 = toSubpathBezier[k] - toCp[0];
  11848. var y1 = toSubpathBezier[k + 1] - toCp[1];
  11849. var newX1 = x1 * ca - y1 * sa;
  11850. var newY1 = x1 * sa + y1 * ca;
  11851. tmpArr[k] = newX1;
  11852. tmpArr[k + 1] = newY1;
  11853. var dx = newX1 - x0;
  11854. var dy = newY1 - y0;
  11855. score += dx * dx + dy * dy;
  11856. }
  11857. if (score < bestScore) {
  11858. bestScore = score;
  11859. bestAngle = angle;
  11860. for (var m = 0; m < tmpArr.length; m++) {
  11861. newToSubpathBezier[m] = tmpArr[m];
  11862. }
  11863. }
  11864. }
  11865. }
  11866. else {
  11867. for (var i_1 = 0; i_1 < len; i_1 += 2) {
  11868. newToSubpathBezier[i_1] = toSubpathBezier[i_1] - toCp[0];
  11869. newToSubpathBezier[i_1 + 1] = toSubpathBezier[i_1 + 1] - toCp[1];
  11870. }
  11871. }
  11872. result.push({
  11873. from: newFromSubpathBezier,
  11874. to: newToSubpathBezier,
  11875. fromCp: fromCp,
  11876. toCp: toCp,
  11877. rotation: -bestAngle
  11878. });
  11879. }
  11880. return result;
  11881. }
  11882. function isCombineMorphing(path) {
  11883. return path.__isCombineMorphing;
  11884. }
  11885. function isMorphing(el) {
  11886. return el.__morphT >= 0;
  11887. }
  11888. var SAVED_METHOD_PREFIX = '__mOriginal_';
  11889. function saveAndModifyMethod(obj, methodName, modifiers) {
  11890. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  11891. var originalMethod = obj[savedMethodName] || obj[methodName];
  11892. if (!obj[savedMethodName]) {
  11893. obj[savedMethodName] = obj[methodName];
  11894. }
  11895. var replace = modifiers.replace;
  11896. var after = modifiers.after;
  11897. var before = modifiers.before;
  11898. obj[methodName] = function () {
  11899. var args = arguments;
  11900. var res;
  11901. before && before.apply(this, args);
  11902. if (replace) {
  11903. res = replace.apply(this, args);
  11904. }
  11905. else {
  11906. res = originalMethod.apply(this, args);
  11907. }
  11908. after && after.apply(this, args);
  11909. return res;
  11910. };
  11911. }
  11912. function restoreMethod(obj, methodName) {
  11913. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  11914. if (obj[savedMethodName]) {
  11915. obj[methodName] = obj[savedMethodName];
  11916. obj[savedMethodName] = null;
  11917. }
  11918. }
  11919. function applyTransformOnBeziers(bezierCurves, mm) {
  11920. for (var i = 0; i < bezierCurves.length; i++) {
  11921. var subBeziers = bezierCurves[i];
  11922. for (var k = 0; k < subBeziers.length;) {
  11923. var x = subBeziers[k];
  11924. var y = subBeziers[k + 1];
  11925. subBeziers[k++] = mm[0] * x + mm[2] * y + mm[4];
  11926. subBeziers[k++] = mm[1] * x + mm[3] * y + mm[5];
  11927. }
  11928. }
  11929. }
  11930. function prepareMorphPath(fromPath, toPath) {
  11931. var fromPathProxy = fromPath.getUpdatedPathProxy();
  11932. var toPathProxy = toPath.getUpdatedPathProxy();
  11933. var _a = alignBezierCurves(pathToBezierCurves(fromPathProxy), pathToBezierCurves(toPathProxy)), fromBezierCurves = _a[0], toBezierCurves = _a[1];
  11934. var fromPathTransform = fromPath.getComputedTransform();
  11935. var toPathTransform = toPath.getComputedTransform();
  11936. function updateIdentityTransform() {
  11937. this.transform = null;
  11938. }
  11939. fromPathTransform && applyTransformOnBeziers(fromBezierCurves, fromPathTransform);
  11940. toPathTransform && applyTransformOnBeziers(toBezierCurves, toPathTransform);
  11941. saveAndModifyMethod(toPath, 'updateTransform', { replace: updateIdentityTransform });
  11942. toPath.transform = null;
  11943. var morphingData = findBestMorphingRotation(fromBezierCurves, toBezierCurves, 10, Math.PI);
  11944. var tmpArr = [];
  11945. saveAndModifyMethod(toPath, 'buildPath', { replace: function (path) {
  11946. var t = toPath.__morphT;
  11947. var onet = 1 - t;
  11948. var newCp = [];
  11949. for (var i = 0; i < morphingData.length; i++) {
  11950. var item = morphingData[i];
  11951. var from = item.from;
  11952. var to = item.to;
  11953. var angle = item.rotation * t;
  11954. var fromCp = item.fromCp;
  11955. var toCp = item.toCp;
  11956. var sa = Math.sin(angle);
  11957. var ca = Math.cos(angle);
  11958. lerp(newCp, fromCp, toCp, t);
  11959. for (var m = 0; m < from.length; m += 2) {
  11960. var x0_1 = from[m];
  11961. var y0_1 = from[m + 1];
  11962. var x1 = to[m];
  11963. var y1 = to[m + 1];
  11964. var x = x0_1 * onet + x1 * t;
  11965. var y = y0_1 * onet + y1 * t;
  11966. tmpArr[m] = (x * ca - y * sa) + newCp[0];
  11967. tmpArr[m + 1] = (x * sa + y * ca) + newCp[1];
  11968. }
  11969. var x0 = tmpArr[0];
  11970. var y0 = tmpArr[1];
  11971. path.moveTo(x0, y0);
  11972. for (var m = 2; m < from.length;) {
  11973. var x1 = tmpArr[m++];
  11974. var y1 = tmpArr[m++];
  11975. var x2 = tmpArr[m++];
  11976. var y2 = tmpArr[m++];
  11977. var x3 = tmpArr[m++];
  11978. var y3 = tmpArr[m++];
  11979. if (x0 === x1 && y0 === y1 && x2 === x3 && y2 === y3) {
  11980. path.lineTo(x3, y3);
  11981. }
  11982. else {
  11983. path.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11984. }
  11985. x0 = x3;
  11986. y0 = y3;
  11987. }
  11988. }
  11989. } });
  11990. }
  11991. function morphPath(fromPath, toPath, animationOpts) {
  11992. if (!fromPath || !toPath) {
  11993. return toPath;
  11994. }
  11995. var oldDone = animationOpts.done;
  11996. var oldDuring = animationOpts.during;
  11997. prepareMorphPath(fromPath, toPath);
  11998. toPath.__morphT = 0;
  11999. function restoreToPath() {
  12000. restoreMethod(toPath, 'buildPath');
  12001. restoreMethod(toPath, 'updateTransform');
  12002. toPath.__morphT = -1;
  12003. toPath.createPathProxy();
  12004. toPath.dirtyShape();
  12005. }
  12006. toPath.animateTo({
  12007. __morphT: 1
  12008. }, defaults({
  12009. during: function (p) {
  12010. toPath.dirtyShape();
  12011. oldDuring && oldDuring(p);
  12012. },
  12013. done: function () {
  12014. restoreToPath();
  12015. oldDone && oldDone();
  12016. }
  12017. }, animationOpts));
  12018. return toPath;
  12019. }
  12020. function hilbert(x, y, minX, minY, maxX, maxY) {
  12021. var bits = 16;
  12022. x = (maxX === minX) ? 0 : Math.round(32767 * (x - minX) / (maxX - minX));
  12023. y = (maxY === minY) ? 0 : Math.round(32767 * (y - minY) / (maxY - minY));
  12024. var d = 0;
  12025. var tmp;
  12026. for (var s = (1 << bits) / 2; s > 0; s /= 2) {
  12027. var rx = 0;
  12028. var ry = 0;
  12029. if ((x & s) > 0) {
  12030. rx = 1;
  12031. }
  12032. if ((y & s) > 0) {
  12033. ry = 1;
  12034. }
  12035. d += s * s * ((3 * rx) ^ ry);
  12036. if (ry === 0) {
  12037. if (rx === 1) {
  12038. x = s - 1 - x;
  12039. y = s - 1 - y;
  12040. }
  12041. tmp = x;
  12042. x = y;
  12043. y = tmp;
  12044. }
  12045. }
  12046. return d;
  12047. }
  12048. function sortPaths(pathList) {
  12049. var xMin = Infinity;
  12050. var yMin = Infinity;
  12051. var xMax = -Infinity;
  12052. var yMax = -Infinity;
  12053. var cps = map(pathList, function (path) {
  12054. var rect = path.getBoundingRect();
  12055. var m = path.getComputedTransform();
  12056. var x = rect.x + rect.width / 2 + (m ? m[4] : 0);
  12057. var y = rect.y + rect.height / 2 + (m ? m[5] : 0);
  12058. xMin = Math.min(x, xMin);
  12059. yMin = Math.min(y, yMin);
  12060. xMax = Math.max(x, xMax);
  12061. yMax = Math.max(y, yMax);
  12062. return [x, y];
  12063. });
  12064. var items = map(cps, function (cp, idx) {
  12065. return {
  12066. cp: cp,
  12067. z: hilbert(cp[0], cp[1], xMin, yMin, xMax, yMax),
  12068. path: pathList[idx]
  12069. };
  12070. });
  12071. return items.sort(function (a, b) { return a.z - b.z; }).map(function (item) { return item.path; });
  12072. }
  12073. function defaultDividePath(param) {
  12074. return split(param.path, param.count);
  12075. }
  12076. function createEmptyReturn() {
  12077. return {
  12078. fromIndividuals: [],
  12079. toIndividuals: [],
  12080. count: 0
  12081. };
  12082. }
  12083. function combineMorph(fromList, toPath, animationOpts) {
  12084. var fromPathList = [];
  12085. function addFromPath(fromList) {
  12086. for (var i = 0; i < fromList.length; i++) {
  12087. var from = fromList[i];
  12088. if (isCombineMorphing(from)) {
  12089. addFromPath(from.childrenRef());
  12090. }
  12091. else if (from instanceof Path) {
  12092. fromPathList.push(from);
  12093. }
  12094. }
  12095. }
  12096. addFromPath(fromList);
  12097. var separateCount = fromPathList.length;
  12098. if (!separateCount) {
  12099. return createEmptyReturn();
  12100. }
  12101. var dividePath = animationOpts.dividePath || defaultDividePath;
  12102. var toSubPathList = dividePath({
  12103. path: toPath, count: separateCount
  12104. });
  12105. if (toSubPathList.length !== separateCount) {
  12106. console.error('Invalid morphing: unmatched splitted path');
  12107. return createEmptyReturn();
  12108. }
  12109. fromPathList = sortPaths(fromPathList);
  12110. toSubPathList = sortPaths(toSubPathList);
  12111. var oldDone = animationOpts.done;
  12112. var oldDuring = animationOpts.during;
  12113. var individualDelay = animationOpts.individualDelay;
  12114. var identityTransform = new Transformable();
  12115. for (var i = 0; i < separateCount; i++) {
  12116. var from = fromPathList[i];
  12117. var to = toSubPathList[i];
  12118. to.parent = toPath;
  12119. to.copyTransform(identityTransform);
  12120. if (!individualDelay) {
  12121. prepareMorphPath(from, to);
  12122. }
  12123. }
  12124. toPath.__isCombineMorphing = true;
  12125. toPath.childrenRef = function () {
  12126. return toSubPathList;
  12127. };
  12128. function addToSubPathListToZr(zr) {
  12129. for (var i = 0; i < toSubPathList.length; i++) {
  12130. toSubPathList[i].addSelfToZr(zr);
  12131. }
  12132. }
  12133. saveAndModifyMethod(toPath, 'addSelfToZr', {
  12134. after: function (zr) {
  12135. addToSubPathListToZr(zr);
  12136. }
  12137. });
  12138. saveAndModifyMethod(toPath, 'removeSelfFromZr', {
  12139. after: function (zr) {
  12140. for (var i = 0; i < toSubPathList.length; i++) {
  12141. toSubPathList[i].removeSelfFromZr(zr);
  12142. }
  12143. }
  12144. });
  12145. function restoreToPath() {
  12146. toPath.__isCombineMorphing = false;
  12147. toPath.__morphT = -1;
  12148. toPath.childrenRef = null;
  12149. restoreMethod(toPath, 'addSelfToZr');
  12150. restoreMethod(toPath, 'removeSelfFromZr');
  12151. }
  12152. var toLen = toSubPathList.length;
  12153. if (individualDelay) {
  12154. var animating_1 = toLen;
  12155. var eachDone = function () {
  12156. animating_1--;
  12157. if (animating_1 === 0) {
  12158. restoreToPath();
  12159. oldDone && oldDone();
  12160. }
  12161. };
  12162. for (var i = 0; i < toLen; i++) {
  12163. var indivdualAnimationOpts = individualDelay ? defaults({
  12164. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toSubPathList[i]),
  12165. done: eachDone
  12166. }, animationOpts) : animationOpts;
  12167. morphPath(fromPathList[i], toSubPathList[i], indivdualAnimationOpts);
  12168. }
  12169. }
  12170. else {
  12171. toPath.__morphT = 0;
  12172. toPath.animateTo({
  12173. __morphT: 1
  12174. }, defaults({
  12175. during: function (p) {
  12176. for (var i = 0; i < toLen; i++) {
  12177. var child = toSubPathList[i];
  12178. child.__morphT = toPath.__morphT;
  12179. child.dirtyShape();
  12180. }
  12181. oldDuring && oldDuring(p);
  12182. },
  12183. done: function () {
  12184. restoreToPath();
  12185. for (var i = 0; i < fromList.length; i++) {
  12186. restoreMethod(fromList[i], 'updateTransform');
  12187. }
  12188. oldDone && oldDone();
  12189. }
  12190. }, animationOpts));
  12191. }
  12192. if (toPath.__zr) {
  12193. addToSubPathListToZr(toPath.__zr);
  12194. }
  12195. return {
  12196. fromIndividuals: fromPathList,
  12197. toIndividuals: toSubPathList,
  12198. count: toLen
  12199. };
  12200. }
  12201. function separateMorph(fromPath, toPathList, animationOpts) {
  12202. var toLen = toPathList.length;
  12203. var fromPathList = [];
  12204. var dividePath = animationOpts.dividePath || defaultDividePath;
  12205. function addFromPath(fromList) {
  12206. for (var i = 0; i < fromList.length; i++) {
  12207. var from = fromList[i];
  12208. if (isCombineMorphing(from)) {
  12209. addFromPath(from.childrenRef());
  12210. }
  12211. else if (from instanceof Path) {
  12212. fromPathList.push(from);
  12213. }
  12214. }
  12215. }
  12216. if (isCombineMorphing(fromPath)) {
  12217. addFromPath(fromPath.childrenRef());
  12218. var fromLen = fromPathList.length;
  12219. if (fromLen < toLen) {
  12220. var k = 0;
  12221. for (var i = fromLen; i < toLen; i++) {
  12222. fromPathList.push(clonePath(fromPathList[k++ % fromLen]));
  12223. }
  12224. }
  12225. fromPathList.length = toLen;
  12226. }
  12227. else {
  12228. fromPathList = dividePath({ path: fromPath, count: toLen });
  12229. var fromPathTransform = fromPath.getComputedTransform();
  12230. for (var i = 0; i < fromPathList.length; i++) {
  12231. fromPathList[i].setLocalTransform(fromPathTransform);
  12232. }
  12233. if (fromPathList.length !== toLen) {
  12234. console.error('Invalid morphing: unmatched splitted path');
  12235. return createEmptyReturn();
  12236. }
  12237. }
  12238. fromPathList = sortPaths(fromPathList);
  12239. toPathList = sortPaths(toPathList);
  12240. var individualDelay = animationOpts.individualDelay;
  12241. for (var i = 0; i < toLen; i++) {
  12242. var indivdualAnimationOpts = individualDelay ? defaults({
  12243. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toPathList[i])
  12244. }, animationOpts) : animationOpts;
  12245. morphPath(fromPathList[i], toPathList[i], indivdualAnimationOpts);
  12246. }
  12247. return {
  12248. fromIndividuals: fromPathList,
  12249. toIndividuals: toPathList,
  12250. count: toPathList.length
  12251. };
  12252. }
  12253. var morphPath$1 = /*#__PURE__*/Object.freeze({
  12254. __proto__: null,
  12255. alignBezierCurves: alignBezierCurves,
  12256. centroid: centroid,
  12257. isCombineMorphing: isCombineMorphing,
  12258. isMorphing: isMorphing,
  12259. morphPath: morphPath,
  12260. combineMorph: combineMorph,
  12261. separateMorph: separateMorph,
  12262. defaultDividePath: split
  12263. });
  12264. var CompoundPath = (function (_super) {
  12265. __extends(CompoundPath, _super);
  12266. function CompoundPath() {
  12267. var _this = _super !== null && _super.apply(this, arguments) || this;
  12268. _this.type = 'compound';
  12269. return _this;
  12270. }
  12271. CompoundPath.prototype._updatePathDirty = function () {
  12272. var paths = this.shape.paths;
  12273. var dirtyPath = this.shapeChanged();
  12274. for (var i = 0; i < paths.length; i++) {
  12275. dirtyPath = dirtyPath || paths[i].shapeChanged();
  12276. }
  12277. if (dirtyPath) {
  12278. this.dirtyShape();
  12279. }
  12280. };
  12281. CompoundPath.prototype.beforeBrush = function () {
  12282. this._updatePathDirty();
  12283. var paths = this.shape.paths || [];
  12284. var scale = this.getGlobalScale();
  12285. for (var i = 0; i < paths.length; i++) {
  12286. if (!paths[i].path) {
  12287. paths[i].createPathProxy();
  12288. }
  12289. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  12290. }
  12291. };
  12292. CompoundPath.prototype.buildPath = function (ctx, shape) {
  12293. var paths = shape.paths || [];
  12294. for (var i = 0; i < paths.length; i++) {
  12295. paths[i].buildPath(ctx, paths[i].shape, true);
  12296. }
  12297. };
  12298. CompoundPath.prototype.afterBrush = function () {
  12299. var paths = this.shape.paths || [];
  12300. for (var i = 0; i < paths.length; i++) {
  12301. paths[i].pathUpdated();
  12302. }
  12303. };
  12304. CompoundPath.prototype.getBoundingRect = function () {
  12305. this._updatePathDirty.call(this);
  12306. return Path.prototype.getBoundingRect.call(this);
  12307. };
  12308. return CompoundPath;
  12309. }(Path));
  12310. var m = [];
  12311. var IncrementalDisplayable = (function (_super) {
  12312. __extends(IncrementalDisplayable, _super);
  12313. function IncrementalDisplayable() {
  12314. var _this = _super !== null && _super.apply(this, arguments) || this;
  12315. _this.notClear = true;
  12316. _this.incremental = true;
  12317. _this._displayables = [];
  12318. _this._temporaryDisplayables = [];
  12319. _this._cursor = 0;
  12320. return _this;
  12321. }
  12322. IncrementalDisplayable.prototype.traverse = function (cb, context) {
  12323. cb.call(context, this);
  12324. };
  12325. IncrementalDisplayable.prototype.useStyle = function () {
  12326. this.style = {};
  12327. };
  12328. IncrementalDisplayable.prototype.getCursor = function () {
  12329. return this._cursor;
  12330. };
  12331. IncrementalDisplayable.prototype.innerAfterBrush = function () {
  12332. this._cursor = this._displayables.length;
  12333. };
  12334. IncrementalDisplayable.prototype.clearDisplaybles = function () {
  12335. this._displayables = [];
  12336. this._temporaryDisplayables = [];
  12337. this._cursor = 0;
  12338. this.markRedraw();
  12339. this.notClear = false;
  12340. };
  12341. IncrementalDisplayable.prototype.clearTemporalDisplayables = function () {
  12342. this._temporaryDisplayables = [];
  12343. };
  12344. IncrementalDisplayable.prototype.addDisplayable = function (displayable, notPersistent) {
  12345. if (notPersistent) {
  12346. this._temporaryDisplayables.push(displayable);
  12347. }
  12348. else {
  12349. this._displayables.push(displayable);
  12350. }
  12351. this.markRedraw();
  12352. };
  12353. IncrementalDisplayable.prototype.addDisplayables = function (displayables, notPersistent) {
  12354. notPersistent = notPersistent || false;
  12355. for (var i = 0; i < displayables.length; i++) {
  12356. this.addDisplayable(displayables[i], notPersistent);
  12357. }
  12358. };
  12359. IncrementalDisplayable.prototype.getDisplayables = function () {
  12360. return this._displayables;
  12361. };
  12362. IncrementalDisplayable.prototype.getTemporalDisplayables = function () {
  12363. return this._temporaryDisplayables;
  12364. };
  12365. IncrementalDisplayable.prototype.eachPendingDisplayable = function (cb) {
  12366. for (var i = this._cursor; i < this._displayables.length; i++) {
  12367. cb && cb(this._displayables[i]);
  12368. }
  12369. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  12370. cb && cb(this._temporaryDisplayables[i]);
  12371. }
  12372. };
  12373. IncrementalDisplayable.prototype.update = function () {
  12374. this.updateTransform();
  12375. for (var i = this._cursor; i < this._displayables.length; i++) {
  12376. var displayable = this._displayables[i];
  12377. displayable.parent = this;
  12378. displayable.update();
  12379. displayable.parent = null;
  12380. }
  12381. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  12382. var displayable = this._temporaryDisplayables[i];
  12383. displayable.parent = this;
  12384. displayable.update();
  12385. displayable.parent = null;
  12386. }
  12387. };
  12388. IncrementalDisplayable.prototype.getBoundingRect = function () {
  12389. if (!this._rect) {
  12390. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  12391. for (var i = 0; i < this._displayables.length; i++) {
  12392. var displayable = this._displayables[i];
  12393. var childRect = displayable.getBoundingRect().clone();
  12394. if (displayable.needLocalTransform()) {
  12395. childRect.applyTransform(displayable.getLocalTransform(m));
  12396. }
  12397. rect.union(childRect);
  12398. }
  12399. this._rect = rect;
  12400. }
  12401. return this._rect;
  12402. };
  12403. IncrementalDisplayable.prototype.contain = function (x, y) {
  12404. var localPos = this.transformCoordToLocal(x, y);
  12405. var rect = this.getBoundingRect();
  12406. if (rect.contain(localPos[0], localPos[1])) {
  12407. for (var i = 0; i < this._displayables.length; i++) {
  12408. var displayable = this._displayables[i];
  12409. if (displayable.contain(x, y)) {
  12410. return true;
  12411. }
  12412. }
  12413. }
  12414. return false;
  12415. };
  12416. return IncrementalDisplayable;
  12417. }(Displayable));
  12418. var globalImageCache = new LRU(50);
  12419. function findExistImage(newImageOrSrc) {
  12420. if (typeof newImageOrSrc === 'string') {
  12421. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  12422. return cachedImgObj && cachedImgObj.image;
  12423. }
  12424. else {
  12425. return newImageOrSrc;
  12426. }
  12427. }
  12428. function createOrUpdateImage(newImageOrSrc, image, hostEl, onload, cbPayload) {
  12429. if (!newImageOrSrc) {
  12430. return image;
  12431. }
  12432. else if (typeof newImageOrSrc === 'string') {
  12433. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  12434. return image;
  12435. }
  12436. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  12437. var pendingWrap = { hostEl: hostEl, cb: onload, cbPayload: cbPayload };
  12438. if (cachedImgObj) {
  12439. image = cachedImgObj.image;
  12440. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  12441. }
  12442. else {
  12443. image = platformApi.loadImage(newImageOrSrc, imageOnLoad, imageOnLoad);
  12444. image.__zrImageSrc = newImageOrSrc;
  12445. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  12446. image: image,
  12447. pending: [pendingWrap]
  12448. });
  12449. }
  12450. return image;
  12451. }
  12452. else {
  12453. return newImageOrSrc;
  12454. }
  12455. }
  12456. function imageOnLoad() {
  12457. var cachedImgObj = this.__cachedImgObj;
  12458. this.onload = this.onerror = this.__cachedImgObj = null;
  12459. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  12460. var pendingWrap = cachedImgObj.pending[i];
  12461. var cb = pendingWrap.cb;
  12462. cb && cb(this, pendingWrap.cbPayload);
  12463. pendingWrap.hostEl.dirty();
  12464. }
  12465. cachedImgObj.pending.length = 0;
  12466. }
  12467. function isImageReady(image) {
  12468. return image && image.width && image.height;
  12469. }
  12470. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  12471. function truncateText(text, containerWidth, font, ellipsis, options) {
  12472. if (!containerWidth) {
  12473. return '';
  12474. }
  12475. var textLines = (text + '').split('\n');
  12476. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  12477. for (var i = 0, len = textLines.length; i < len; i++) {
  12478. textLines[i] = truncateSingleLine(textLines[i], options);
  12479. }
  12480. return textLines.join('\n');
  12481. }
  12482. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  12483. options = options || {};
  12484. var preparedOpts = extend({}, options);
  12485. preparedOpts.font = font;
  12486. ellipsis = retrieve2(ellipsis, '...');
  12487. preparedOpts.maxIterations = retrieve2(options.maxIterations, 2);
  12488. var minChar = preparedOpts.minChar = retrieve2(options.minChar, 0);
  12489. preparedOpts.cnCharWidth = getWidth('国', font);
  12490. var ascCharWidth = preparedOpts.ascCharWidth = getWidth('a', font);
  12491. preparedOpts.placeholder = retrieve2(options.placeholder, '');
  12492. var contentWidth = containerWidth = Math.max(0, containerWidth - 1);
  12493. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  12494. contentWidth -= ascCharWidth;
  12495. }
  12496. var ellipsisWidth = getWidth(ellipsis, font);
  12497. if (ellipsisWidth > contentWidth) {
  12498. ellipsis = '';
  12499. ellipsisWidth = 0;
  12500. }
  12501. contentWidth = containerWidth - ellipsisWidth;
  12502. preparedOpts.ellipsis = ellipsis;
  12503. preparedOpts.ellipsisWidth = ellipsisWidth;
  12504. preparedOpts.contentWidth = contentWidth;
  12505. preparedOpts.containerWidth = containerWidth;
  12506. return preparedOpts;
  12507. }
  12508. function truncateSingleLine(textLine, options) {
  12509. var containerWidth = options.containerWidth;
  12510. var font = options.font;
  12511. var contentWidth = options.contentWidth;
  12512. if (!containerWidth) {
  12513. return '';
  12514. }
  12515. var lineWidth = getWidth(textLine, font);
  12516. if (lineWidth <= containerWidth) {
  12517. return textLine;
  12518. }
  12519. for (var j = 0;; j++) {
  12520. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  12521. textLine += options.ellipsis;
  12522. break;
  12523. }
  12524. var subLength = j === 0
  12525. ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
  12526. : lineWidth > 0
  12527. ? Math.floor(textLine.length * contentWidth / lineWidth)
  12528. : 0;
  12529. textLine = textLine.substr(0, subLength);
  12530. lineWidth = getWidth(textLine, font);
  12531. }
  12532. if (textLine === '') {
  12533. textLine = options.placeholder;
  12534. }
  12535. return textLine;
  12536. }
  12537. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  12538. var width = 0;
  12539. var i = 0;
  12540. for (var len = text.length; i < len && width < contentWidth; i++) {
  12541. var charCode = text.charCodeAt(i);
  12542. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  12543. }
  12544. return i;
  12545. }
  12546. function parsePlainText(text, style) {
  12547. text != null && (text += '');
  12548. var overflow = style.overflow;
  12549. var padding = style.padding;
  12550. var font = style.font;
  12551. var truncate = overflow === 'truncate';
  12552. var calculatedLineHeight = getLineHeight(font);
  12553. var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
  12554. var bgColorDrawn = !!(style.backgroundColor);
  12555. var truncateLineOverflow = style.lineOverflow === 'truncate';
  12556. var width = style.width;
  12557. var lines;
  12558. if (width != null && (overflow === 'break' || overflow === 'breakAll')) {
  12559. lines = text ? wrapText(text, style.font, width, overflow === 'breakAll', 0).lines : [];
  12560. }
  12561. else {
  12562. lines = text ? text.split('\n') : [];
  12563. }
  12564. var contentHeight = lines.length * lineHeight;
  12565. var height = retrieve2(style.height, contentHeight);
  12566. if (contentHeight > height && truncateLineOverflow) {
  12567. var lineCount = Math.floor(height / lineHeight);
  12568. lines = lines.slice(0, lineCount);
  12569. }
  12570. if (text && truncate && width != null) {
  12571. var options = prepareTruncateOptions(width, font, style.ellipsis, {
  12572. minChar: style.truncateMinChar,
  12573. placeholder: style.placeholder
  12574. });
  12575. for (var i = 0; i < lines.length; i++) {
  12576. lines[i] = truncateSingleLine(lines[i], options);
  12577. }
  12578. }
  12579. var outerHeight = height;
  12580. var contentWidth = 0;
  12581. for (var i = 0; i < lines.length; i++) {
  12582. contentWidth = Math.max(getWidth(lines[i], font), contentWidth);
  12583. }
  12584. if (width == null) {
  12585. width = contentWidth;
  12586. }
  12587. var outerWidth = contentWidth;
  12588. if (padding) {
  12589. outerHeight += padding[0] + padding[2];
  12590. outerWidth += padding[1] + padding[3];
  12591. width += padding[1] + padding[3];
  12592. }
  12593. if (bgColorDrawn) {
  12594. outerWidth = width;
  12595. }
  12596. return {
  12597. lines: lines,
  12598. height: height,
  12599. outerWidth: outerWidth,
  12600. outerHeight: outerHeight,
  12601. lineHeight: lineHeight,
  12602. calculatedLineHeight: calculatedLineHeight,
  12603. contentWidth: contentWidth,
  12604. contentHeight: contentHeight,
  12605. width: width
  12606. };
  12607. }
  12608. var RichTextToken = (function () {
  12609. function RichTextToken() {
  12610. }
  12611. return RichTextToken;
  12612. }());
  12613. var RichTextLine = (function () {
  12614. function RichTextLine(tokens) {
  12615. this.tokens = [];
  12616. if (tokens) {
  12617. this.tokens = tokens;
  12618. }
  12619. }
  12620. return RichTextLine;
  12621. }());
  12622. var RichTextContentBlock = (function () {
  12623. function RichTextContentBlock() {
  12624. this.width = 0;
  12625. this.height = 0;
  12626. this.contentWidth = 0;
  12627. this.contentHeight = 0;
  12628. this.outerWidth = 0;
  12629. this.outerHeight = 0;
  12630. this.lines = [];
  12631. }
  12632. return RichTextContentBlock;
  12633. }());
  12634. function parseRichText(text, style) {
  12635. var contentBlock = new RichTextContentBlock();
  12636. text != null && (text += '');
  12637. if (!text) {
  12638. return contentBlock;
  12639. }
  12640. var topWidth = style.width;
  12641. var topHeight = style.height;
  12642. var overflow = style.overflow;
  12643. var wrapInfo = (overflow === 'break' || overflow === 'breakAll') && topWidth != null
  12644. ? { width: topWidth, accumWidth: 0, breakAll: overflow === 'breakAll' }
  12645. : null;
  12646. var lastIndex = STYLE_REG.lastIndex = 0;
  12647. var result;
  12648. while ((result = STYLE_REG.exec(text)) != null) {
  12649. var matchedIndex = result.index;
  12650. if (matchedIndex > lastIndex) {
  12651. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex), style, wrapInfo);
  12652. }
  12653. pushTokens(contentBlock, result[2], style, wrapInfo, result[1]);
  12654. lastIndex = STYLE_REG.lastIndex;
  12655. }
  12656. if (lastIndex < text.length) {
  12657. pushTokens(contentBlock, text.substring(lastIndex, text.length), style, wrapInfo);
  12658. }
  12659. var pendingList = [];
  12660. var calculatedHeight = 0;
  12661. var calculatedWidth = 0;
  12662. var stlPadding = style.padding;
  12663. var truncate = overflow === 'truncate';
  12664. var truncateLine = style.lineOverflow === 'truncate';
  12665. function finishLine(line, lineWidth, lineHeight) {
  12666. line.width = lineWidth;
  12667. line.lineHeight = lineHeight;
  12668. calculatedHeight += lineHeight;
  12669. calculatedWidth = Math.max(calculatedWidth, lineWidth);
  12670. }
  12671. outer: for (var i = 0; i < contentBlock.lines.length; i++) {
  12672. var line = contentBlock.lines[i];
  12673. var lineHeight = 0;
  12674. var lineWidth = 0;
  12675. for (var j = 0; j < line.tokens.length; j++) {
  12676. var token = line.tokens[j];
  12677. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  12678. var textPadding = token.textPadding = tokenStyle.padding;
  12679. var paddingH = textPadding ? textPadding[1] + textPadding[3] : 0;
  12680. var font = token.font = tokenStyle.font || style.font;
  12681. token.contentHeight = getLineHeight(font);
  12682. var tokenHeight = retrieve2(tokenStyle.height, token.contentHeight);
  12683. token.innerHeight = tokenHeight;
  12684. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  12685. token.height = tokenHeight;
  12686. token.lineHeight = retrieve3(tokenStyle.lineHeight, style.lineHeight, tokenHeight);
  12687. token.align = tokenStyle && tokenStyle.align || style.align;
  12688. token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
  12689. if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
  12690. if (j > 0) {
  12691. line.tokens = line.tokens.slice(0, j);
  12692. finishLine(line, lineWidth, lineHeight);
  12693. contentBlock.lines = contentBlock.lines.slice(0, i + 1);
  12694. }
  12695. else {
  12696. contentBlock.lines = contentBlock.lines.slice(0, i);
  12697. }
  12698. break outer;
  12699. }
  12700. var styleTokenWidth = tokenStyle.width;
  12701. var tokenWidthNotSpecified = styleTokenWidth == null || styleTokenWidth === 'auto';
  12702. if (typeof styleTokenWidth === 'string' && styleTokenWidth.charAt(styleTokenWidth.length - 1) === '%') {
  12703. token.percentWidth = styleTokenWidth;
  12704. pendingList.push(token);
  12705. token.contentWidth = getWidth(token.text, font);
  12706. }
  12707. else {
  12708. if (tokenWidthNotSpecified) {
  12709. var textBackgroundColor = tokenStyle.backgroundColor;
  12710. var bgImg = textBackgroundColor && textBackgroundColor.image;
  12711. if (bgImg) {
  12712. bgImg = findExistImage(bgImg);
  12713. if (isImageReady(bgImg)) {
  12714. token.width = Math.max(token.width, bgImg.width * tokenHeight / bgImg.height);
  12715. }
  12716. }
  12717. }
  12718. var remainTruncWidth = truncate && topWidth != null
  12719. ? topWidth - lineWidth : null;
  12720. if (remainTruncWidth != null && remainTruncWidth < token.width) {
  12721. if (!tokenWidthNotSpecified || remainTruncWidth < paddingH) {
  12722. token.text = '';
  12723. token.width = token.contentWidth = 0;
  12724. }
  12725. else {
  12726. token.text = truncateText(token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
  12727. token.width = token.contentWidth = getWidth(token.text, font);
  12728. }
  12729. }
  12730. else {
  12731. token.contentWidth = getWidth(token.text, font);
  12732. }
  12733. }
  12734. token.width += paddingH;
  12735. lineWidth += token.width;
  12736. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  12737. }
  12738. finishLine(line, lineWidth, lineHeight);
  12739. }
  12740. contentBlock.outerWidth = contentBlock.width = retrieve2(topWidth, calculatedWidth);
  12741. contentBlock.outerHeight = contentBlock.height = retrieve2(topHeight, calculatedHeight);
  12742. contentBlock.contentHeight = calculatedHeight;
  12743. contentBlock.contentWidth = calculatedWidth;
  12744. if (stlPadding) {
  12745. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  12746. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  12747. }
  12748. for (var i = 0; i < pendingList.length; i++) {
  12749. var token = pendingList[i];
  12750. var percentWidth = token.percentWidth;
  12751. token.width = parseInt(percentWidth, 10) / 100 * contentBlock.width;
  12752. }
  12753. return contentBlock;
  12754. }
  12755. function pushTokens(block, str, style, wrapInfo, styleName) {
  12756. var isEmptyStr = str === '';
  12757. var tokenStyle = styleName && style.rich[styleName] || {};
  12758. var lines = block.lines;
  12759. var font = tokenStyle.font || style.font;
  12760. var newLine = false;
  12761. var strLines;
  12762. var linesWidths;
  12763. if (wrapInfo) {
  12764. var tokenPadding = tokenStyle.padding;
  12765. var tokenPaddingH = tokenPadding ? tokenPadding[1] + tokenPadding[3] : 0;
  12766. if (tokenStyle.width != null && tokenStyle.width !== 'auto') {
  12767. var outerWidth_1 = parsePercent(tokenStyle.width, wrapInfo.width) + tokenPaddingH;
  12768. if (lines.length > 0) {
  12769. if (outerWidth_1 + wrapInfo.accumWidth > wrapInfo.width) {
  12770. strLines = str.split('\n');
  12771. newLine = true;
  12772. }
  12773. }
  12774. wrapInfo.accumWidth = outerWidth_1;
  12775. }
  12776. else {
  12777. var res = wrapText(str, font, wrapInfo.width, wrapInfo.breakAll, wrapInfo.accumWidth);
  12778. wrapInfo.accumWidth = res.accumWidth + tokenPaddingH;
  12779. linesWidths = res.linesWidths;
  12780. strLines = res.lines;
  12781. }
  12782. }
  12783. else {
  12784. strLines = str.split('\n');
  12785. }
  12786. for (var i = 0; i < strLines.length; i++) {
  12787. var text = strLines[i];
  12788. var token = new RichTextToken();
  12789. token.styleName = styleName;
  12790. token.text = text;
  12791. token.isLineHolder = !text && !isEmptyStr;
  12792. if (typeof tokenStyle.width === 'number') {
  12793. token.width = tokenStyle.width;
  12794. }
  12795. else {
  12796. token.width = linesWidths
  12797. ? linesWidths[i]
  12798. : getWidth(text, font);
  12799. }
  12800. if (!i && !newLine) {
  12801. var tokens = (lines[lines.length - 1] || (lines[0] = new RichTextLine())).tokens;
  12802. var tokensLen = tokens.length;
  12803. (tokensLen === 1 && tokens[0].isLineHolder)
  12804. ? (tokens[0] = token)
  12805. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  12806. }
  12807. else {
  12808. lines.push(new RichTextLine([token]));
  12809. }
  12810. }
  12811. }
  12812. function isAlphabeticLetter(ch) {
  12813. var code = ch.charCodeAt(0);
  12814. return code >= 0x20 && code <= 0x24F
  12815. || code >= 0x370 && code <= 0x10FF
  12816. || code >= 0x1200 && code <= 0x13FF
  12817. || code >= 0x1E00 && code <= 0x206F;
  12818. }
  12819. var breakCharMap = reduce(',&?/;] '.split(''), function (obj, ch) {
  12820. obj[ch] = true;
  12821. return obj;
  12822. }, {});
  12823. function isWordBreakChar(ch) {
  12824. if (isAlphabeticLetter(ch)) {
  12825. if (breakCharMap[ch]) {
  12826. return true;
  12827. }
  12828. return false;
  12829. }
  12830. return true;
  12831. }
  12832. function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
  12833. var lines = [];
  12834. var linesWidths = [];
  12835. var line = '';
  12836. var currentWord = '';
  12837. var currentWordWidth = 0;
  12838. var accumWidth = 0;
  12839. for (var i = 0; i < text.length; i++) {
  12840. var ch = text.charAt(i);
  12841. if (ch === '\n') {
  12842. if (currentWord) {
  12843. line += currentWord;
  12844. accumWidth += currentWordWidth;
  12845. }
  12846. lines.push(line);
  12847. linesWidths.push(accumWidth);
  12848. line = '';
  12849. currentWord = '';
  12850. currentWordWidth = 0;
  12851. accumWidth = 0;
  12852. continue;
  12853. }
  12854. var chWidth = getWidth(ch, font);
  12855. var inWord = isBreakAll ? false : !isWordBreakChar(ch);
  12856. if (!lines.length
  12857. ? lastAccumWidth + accumWidth + chWidth > lineWidth
  12858. : accumWidth + chWidth > lineWidth) {
  12859. if (!accumWidth) {
  12860. if (inWord) {
  12861. lines.push(currentWord);
  12862. linesWidths.push(currentWordWidth);
  12863. currentWord = ch;
  12864. currentWordWidth = chWidth;
  12865. }
  12866. else {
  12867. lines.push(ch);
  12868. linesWidths.push(chWidth);
  12869. }
  12870. }
  12871. else if (line || currentWord) {
  12872. if (inWord) {
  12873. if (!line) {
  12874. line = currentWord;
  12875. currentWord = '';
  12876. currentWordWidth = 0;
  12877. accumWidth = currentWordWidth;
  12878. }
  12879. lines.push(line);
  12880. linesWidths.push(accumWidth - currentWordWidth);
  12881. currentWord += ch;
  12882. currentWordWidth += chWidth;
  12883. line = '';
  12884. accumWidth = currentWordWidth;
  12885. }
  12886. else {
  12887. if (currentWord) {
  12888. line += currentWord;
  12889. currentWord = '';
  12890. currentWordWidth = 0;
  12891. }
  12892. lines.push(line);
  12893. linesWidths.push(accumWidth);
  12894. line = ch;
  12895. accumWidth = chWidth;
  12896. }
  12897. }
  12898. continue;
  12899. }
  12900. accumWidth += chWidth;
  12901. if (inWord) {
  12902. currentWord += ch;
  12903. currentWordWidth += chWidth;
  12904. }
  12905. else {
  12906. if (currentWord) {
  12907. line += currentWord;
  12908. currentWord = '';
  12909. currentWordWidth = 0;
  12910. }
  12911. line += ch;
  12912. }
  12913. }
  12914. if (!lines.length && !line) {
  12915. line = text;
  12916. currentWord = '';
  12917. currentWordWidth = 0;
  12918. }
  12919. if (currentWord) {
  12920. line += currentWord;
  12921. }
  12922. if (line) {
  12923. lines.push(line);
  12924. linesWidths.push(accumWidth);
  12925. }
  12926. if (lines.length === 1) {
  12927. accumWidth += lastAccumWidth;
  12928. }
  12929. return {
  12930. accumWidth: accumWidth,
  12931. lines: lines,
  12932. linesWidths: linesWidths
  12933. };
  12934. }
  12935. var DEFAULT_RICH_TEXT_COLOR = {
  12936. fill: '#000'
  12937. };
  12938. var DEFAULT_STROKE_LINE_WIDTH = 2;
  12939. var DEFAULT_TEXT_ANIMATION_PROPS = {
  12940. style: defaults({
  12941. fill: true,
  12942. stroke: true,
  12943. fillOpacity: true,
  12944. strokeOpacity: true,
  12945. lineWidth: true,
  12946. fontSize: true,
  12947. lineHeight: true,
  12948. width: true,
  12949. height: true,
  12950. textShadowColor: true,
  12951. textShadowBlur: true,
  12952. textShadowOffsetX: true,
  12953. textShadowOffsetY: true,
  12954. backgroundColor: true,
  12955. padding: true,
  12956. borderColor: true,
  12957. borderWidth: true,
  12958. borderRadius: true
  12959. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  12960. };
  12961. var ZRText = (function (_super) {
  12962. __extends(ZRText, _super);
  12963. function ZRText(opts) {
  12964. var _this = _super.call(this) || this;
  12965. _this.type = 'text';
  12966. _this._children = [];
  12967. _this._defaultStyle = DEFAULT_RICH_TEXT_COLOR;
  12968. _this.attr(opts);
  12969. return _this;
  12970. }
  12971. ZRText.prototype.childrenRef = function () {
  12972. return this._children;
  12973. };
  12974. ZRText.prototype.update = function () {
  12975. _super.prototype.update.call(this);
  12976. if (this.styleChanged()) {
  12977. this._updateSubTexts();
  12978. }
  12979. for (var i = 0; i < this._children.length; i++) {
  12980. var child = this._children[i];
  12981. child.zlevel = this.zlevel;
  12982. child.z = this.z;
  12983. child.z2 = this.z2;
  12984. child.culling = this.culling;
  12985. child.cursor = this.cursor;
  12986. child.invisible = this.invisible;
  12987. }
  12988. };
  12989. ZRText.prototype.updateTransform = function () {
  12990. var innerTransformable = this.innerTransformable;
  12991. if (innerTransformable) {
  12992. innerTransformable.updateTransform();
  12993. if (innerTransformable.transform) {
  12994. this.transform = innerTransformable.transform;
  12995. }
  12996. }
  12997. else {
  12998. _super.prototype.updateTransform.call(this);
  12999. }
  13000. };
  13001. ZRText.prototype.getLocalTransform = function (m) {
  13002. var innerTransformable = this.innerTransformable;
  13003. return innerTransformable
  13004. ? innerTransformable.getLocalTransform(m)
  13005. : _super.prototype.getLocalTransform.call(this, m);
  13006. };
  13007. ZRText.prototype.getComputedTransform = function () {
  13008. if (this.__hostTarget) {
  13009. this.__hostTarget.getComputedTransform();
  13010. this.__hostTarget.updateInnerText(true);
  13011. }
  13012. return _super.prototype.getComputedTransform.call(this);
  13013. };
  13014. ZRText.prototype._updateSubTexts = function () {
  13015. this._childCursor = 0;
  13016. normalizeTextStyle(this.style);
  13017. this.style.rich
  13018. ? this._updateRichTexts()
  13019. : this._updatePlainTexts();
  13020. this._children.length = this._childCursor;
  13021. this.styleUpdated();
  13022. };
  13023. ZRText.prototype.addSelfToZr = function (zr) {
  13024. _super.prototype.addSelfToZr.call(this, zr);
  13025. for (var i = 0; i < this._children.length; i++) {
  13026. this._children[i].__zr = zr;
  13027. }
  13028. };
  13029. ZRText.prototype.removeSelfFromZr = function (zr) {
  13030. _super.prototype.removeSelfFromZr.call(this, zr);
  13031. for (var i = 0; i < this._children.length; i++) {
  13032. this._children[i].__zr = null;
  13033. }
  13034. };
  13035. ZRText.prototype.getBoundingRect = function () {
  13036. if (this.styleChanged()) {
  13037. this._updateSubTexts();
  13038. }
  13039. if (!this._rect) {
  13040. var tmpRect = new BoundingRect(0, 0, 0, 0);
  13041. var children = this._children;
  13042. var tmpMat = [];
  13043. var rect = null;
  13044. for (var i = 0; i < children.length; i++) {
  13045. var child = children[i];
  13046. var childRect = child.getBoundingRect();
  13047. var transform = child.getLocalTransform(tmpMat);
  13048. if (transform) {
  13049. tmpRect.copy(childRect);
  13050. tmpRect.applyTransform(transform);
  13051. rect = rect || tmpRect.clone();
  13052. rect.union(tmpRect);
  13053. }
  13054. else {
  13055. rect = rect || childRect.clone();
  13056. rect.union(childRect);
  13057. }
  13058. }
  13059. this._rect = rect || tmpRect;
  13060. }
  13061. return this._rect;
  13062. };
  13063. ZRText.prototype.setDefaultTextStyle = function (defaultTextStyle) {
  13064. this._defaultStyle = defaultTextStyle || DEFAULT_RICH_TEXT_COLOR;
  13065. };
  13066. ZRText.prototype.setTextContent = function (textContent) {
  13067. {
  13068. throw new Error('Can\'t attach text on another text');
  13069. }
  13070. };
  13071. ZRText.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  13072. if (!sourceStyle) {
  13073. return targetStyle;
  13074. }
  13075. var sourceRich = sourceStyle.rich;
  13076. var targetRich = targetStyle.rich || (sourceRich && {});
  13077. extend(targetStyle, sourceStyle);
  13078. if (sourceRich && targetRich) {
  13079. this._mergeRich(targetRich, sourceRich);
  13080. targetStyle.rich = targetRich;
  13081. }
  13082. else if (targetRich) {
  13083. targetStyle.rich = targetRich;
  13084. }
  13085. return targetStyle;
  13086. };
  13087. ZRText.prototype._mergeRich = function (targetRich, sourceRich) {
  13088. var richNames = keys(sourceRich);
  13089. for (var i = 0; i < richNames.length; i++) {
  13090. var richName = richNames[i];
  13091. targetRich[richName] = targetRich[richName] || {};
  13092. extend(targetRich[richName], sourceRich[richName]);
  13093. }
  13094. };
  13095. ZRText.prototype.getAnimationStyleProps = function () {
  13096. return DEFAULT_TEXT_ANIMATION_PROPS;
  13097. };
  13098. ZRText.prototype._getOrCreateChild = function (Ctor) {
  13099. var child = this._children[this._childCursor];
  13100. if (!child || !(child instanceof Ctor)) {
  13101. child = new Ctor();
  13102. }
  13103. this._children[this._childCursor++] = child;
  13104. child.__zr = this.__zr;
  13105. child.parent = this;
  13106. return child;
  13107. };
  13108. ZRText.prototype._updatePlainTexts = function () {
  13109. var style = this.style;
  13110. var textFont = style.font || DEFAULT_FONT;
  13111. var textPadding = style.padding;
  13112. var text = getStyleText(style);
  13113. var contentBlock = parsePlainText(text, style);
  13114. var needDrawBg = needDrawBackground(style);
  13115. var bgColorDrawn = !!(style.backgroundColor);
  13116. var outerHeight = contentBlock.outerHeight;
  13117. var outerWidth = contentBlock.outerWidth;
  13118. var contentWidth = contentBlock.contentWidth;
  13119. var textLines = contentBlock.lines;
  13120. var lineHeight = contentBlock.lineHeight;
  13121. var defaultStyle = this._defaultStyle;
  13122. var baseX = style.x || 0;
  13123. var baseY = style.y || 0;
  13124. var textAlign = style.align || defaultStyle.align || 'left';
  13125. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
  13126. var textX = baseX;
  13127. var textY = adjustTextY$1(baseY, contentBlock.contentHeight, verticalAlign);
  13128. if (needDrawBg || textPadding) {
  13129. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  13130. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  13131. needDrawBg && this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  13132. }
  13133. textY += lineHeight / 2;
  13134. if (textPadding) {
  13135. textX = getTextXForPadding(baseX, textAlign, textPadding);
  13136. if (verticalAlign === 'top') {
  13137. textY += textPadding[0];
  13138. }
  13139. else if (verticalAlign === 'bottom') {
  13140. textY -= textPadding[2];
  13141. }
  13142. }
  13143. var defaultLineWidth = 0;
  13144. var useDefaultFill = false;
  13145. var textFill = getFill('fill' in style
  13146. ? style.fill
  13147. : (useDefaultFill = true, defaultStyle.fill));
  13148. var textStroke = getStroke('stroke' in style
  13149. ? style.stroke
  13150. : (!bgColorDrawn
  13151. && (!defaultStyle.autoStroke || useDefaultFill))
  13152. ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  13153. : null);
  13154. var hasShadow = style.textShadowBlur > 0;
  13155. var fixedBoundingRect = style.width != null
  13156. && (style.overflow === 'truncate' || style.overflow === 'break' || style.overflow === 'breakAll');
  13157. var calculatedLineHeight = contentBlock.calculatedLineHeight;
  13158. for (var i = 0; i < textLines.length; i++) {
  13159. var el = this._getOrCreateChild(TSpan);
  13160. var subElStyle = el.createStyle();
  13161. el.useStyle(subElStyle);
  13162. subElStyle.text = textLines[i];
  13163. subElStyle.x = textX;
  13164. subElStyle.y = textY;
  13165. if (textAlign) {
  13166. subElStyle.textAlign = textAlign;
  13167. }
  13168. subElStyle.textBaseline = 'middle';
  13169. subElStyle.opacity = style.opacity;
  13170. subElStyle.strokeFirst = true;
  13171. if (hasShadow) {
  13172. subElStyle.shadowBlur = style.textShadowBlur || 0;
  13173. subElStyle.shadowColor = style.textShadowColor || 'transparent';
  13174. subElStyle.shadowOffsetX = style.textShadowOffsetX || 0;
  13175. subElStyle.shadowOffsetY = style.textShadowOffsetY || 0;
  13176. }
  13177. subElStyle.stroke = textStroke;
  13178. subElStyle.fill = textFill;
  13179. if (textStroke) {
  13180. subElStyle.lineWidth = style.lineWidth || defaultLineWidth;
  13181. subElStyle.lineDash = style.lineDash;
  13182. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13183. }
  13184. subElStyle.font = textFont;
  13185. setSeparateFont(subElStyle, style);
  13186. textY += lineHeight;
  13187. if (fixedBoundingRect) {
  13188. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, style.width, subElStyle.textAlign), adjustTextY$1(subElStyle.y, calculatedLineHeight, subElStyle.textBaseline), contentWidth, calculatedLineHeight));
  13189. }
  13190. }
  13191. };
  13192. ZRText.prototype._updateRichTexts = function () {
  13193. var style = this.style;
  13194. var text = getStyleText(style);
  13195. var contentBlock = parseRichText(text, style);
  13196. var contentWidth = contentBlock.width;
  13197. var outerWidth = contentBlock.outerWidth;
  13198. var outerHeight = contentBlock.outerHeight;
  13199. var textPadding = style.padding;
  13200. var baseX = style.x || 0;
  13201. var baseY = style.y || 0;
  13202. var defaultStyle = this._defaultStyle;
  13203. var textAlign = style.align || defaultStyle.align;
  13204. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
  13205. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  13206. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  13207. var xLeft = boxX;
  13208. var lineTop = boxY;
  13209. if (textPadding) {
  13210. xLeft += textPadding[3];
  13211. lineTop += textPadding[0];
  13212. }
  13213. var xRight = xLeft + contentWidth;
  13214. if (needDrawBackground(style)) {
  13215. this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  13216. }
  13217. var bgColorDrawn = !!(style.backgroundColor);
  13218. for (var i = 0; i < contentBlock.lines.length; i++) {
  13219. var line = contentBlock.lines[i];
  13220. var tokens = line.tokens;
  13221. var tokenCount = tokens.length;
  13222. var lineHeight = line.lineHeight;
  13223. var remainedWidth = line.width;
  13224. var leftIndex = 0;
  13225. var lineXLeft = xLeft;
  13226. var lineXRight = xRight;
  13227. var rightIndex = tokenCount - 1;
  13228. var token = void 0;
  13229. while (leftIndex < tokenCount
  13230. && (token = tokens[leftIndex], !token.align || token.align === 'left')) {
  13231. this._placeToken(token, style, lineHeight, lineTop, lineXLeft, 'left', bgColorDrawn);
  13232. remainedWidth -= token.width;
  13233. lineXLeft += token.width;
  13234. leftIndex++;
  13235. }
  13236. while (rightIndex >= 0
  13237. && (token = tokens[rightIndex], token.align === 'right')) {
  13238. this._placeToken(token, style, lineHeight, lineTop, lineXRight, 'right', bgColorDrawn);
  13239. remainedWidth -= token.width;
  13240. lineXRight -= token.width;
  13241. rightIndex--;
  13242. }
  13243. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - remainedWidth) / 2;
  13244. while (leftIndex <= rightIndex) {
  13245. token = tokens[leftIndex];
  13246. this._placeToken(token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center', bgColorDrawn);
  13247. lineXLeft += token.width;
  13248. leftIndex++;
  13249. }
  13250. lineTop += lineHeight;
  13251. }
  13252. };
  13253. ZRText.prototype._placeToken = function (token, style, lineHeight, lineTop, x, textAlign, parentBgColorDrawn) {
  13254. var tokenStyle = style.rich[token.styleName] || {};
  13255. tokenStyle.text = token.text;
  13256. var verticalAlign = token.verticalAlign;
  13257. var y = lineTop + lineHeight / 2;
  13258. if (verticalAlign === 'top') {
  13259. y = lineTop + token.height / 2;
  13260. }
  13261. else if (verticalAlign === 'bottom') {
  13262. y = lineTop + lineHeight - token.height / 2;
  13263. }
  13264. var needDrawBg = !token.isLineHolder && needDrawBackground(tokenStyle);
  13265. needDrawBg && this._renderBackground(tokenStyle, style, textAlign === 'right'
  13266. ? x - token.width
  13267. : textAlign === 'center'
  13268. ? x - token.width / 2
  13269. : x, y - token.height / 2, token.width, token.height);
  13270. var bgColorDrawn = !!tokenStyle.backgroundColor;
  13271. var textPadding = token.textPadding;
  13272. if (textPadding) {
  13273. x = getTextXForPadding(x, textAlign, textPadding);
  13274. y -= token.height / 2 - textPadding[0] - token.innerHeight / 2;
  13275. }
  13276. var el = this._getOrCreateChild(TSpan);
  13277. var subElStyle = el.createStyle();
  13278. el.useStyle(subElStyle);
  13279. var defaultStyle = this._defaultStyle;
  13280. var useDefaultFill = false;
  13281. var defaultLineWidth = 0;
  13282. var textFill = getFill('fill' in tokenStyle ? tokenStyle.fill
  13283. : 'fill' in style ? style.fill
  13284. : (useDefaultFill = true, defaultStyle.fill));
  13285. var textStroke = getStroke('stroke' in tokenStyle ? tokenStyle.stroke
  13286. : 'stroke' in style ? style.stroke
  13287. : (!bgColorDrawn
  13288. && !parentBgColorDrawn
  13289. && (!defaultStyle.autoStroke || useDefaultFill)) ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  13290. : null);
  13291. var hasShadow = tokenStyle.textShadowBlur > 0
  13292. || style.textShadowBlur > 0;
  13293. subElStyle.text = token.text;
  13294. subElStyle.x = x;
  13295. subElStyle.y = y;
  13296. if (hasShadow) {
  13297. subElStyle.shadowBlur = tokenStyle.textShadowBlur || style.textShadowBlur || 0;
  13298. subElStyle.shadowColor = tokenStyle.textShadowColor || style.textShadowColor || 'transparent';
  13299. subElStyle.shadowOffsetX = tokenStyle.textShadowOffsetX || style.textShadowOffsetX || 0;
  13300. subElStyle.shadowOffsetY = tokenStyle.textShadowOffsetY || style.textShadowOffsetY || 0;
  13301. }
  13302. subElStyle.textAlign = textAlign;
  13303. subElStyle.textBaseline = 'middle';
  13304. subElStyle.font = token.font || DEFAULT_FONT;
  13305. subElStyle.opacity = retrieve3(tokenStyle.opacity, style.opacity, 1);
  13306. setSeparateFont(subElStyle, tokenStyle);
  13307. if (textStroke) {
  13308. subElStyle.lineWidth = retrieve3(tokenStyle.lineWidth, style.lineWidth, defaultLineWidth);
  13309. subElStyle.lineDash = retrieve2(tokenStyle.lineDash, style.lineDash);
  13310. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13311. subElStyle.stroke = textStroke;
  13312. }
  13313. if (textFill) {
  13314. subElStyle.fill = textFill;
  13315. }
  13316. var textWidth = token.contentWidth;
  13317. var textHeight = token.contentHeight;
  13318. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, textWidth, subElStyle.textAlign), adjustTextY$1(subElStyle.y, textHeight, subElStyle.textBaseline), textWidth, textHeight));
  13319. };
  13320. ZRText.prototype._renderBackground = function (style, topStyle, x, y, width, height) {
  13321. var textBackgroundColor = style.backgroundColor;
  13322. var textBorderWidth = style.borderWidth;
  13323. var textBorderColor = style.borderColor;
  13324. var isImageBg = textBackgroundColor && textBackgroundColor.image;
  13325. var isPlainOrGradientBg = textBackgroundColor && !isImageBg;
  13326. var textBorderRadius = style.borderRadius;
  13327. var self = this;
  13328. var rectEl;
  13329. var imgEl;
  13330. if (isPlainOrGradientBg || style.lineHeight || (textBorderWidth && textBorderColor)) {
  13331. rectEl = this._getOrCreateChild(Rect);
  13332. rectEl.useStyle(rectEl.createStyle());
  13333. rectEl.style.fill = null;
  13334. var rectShape = rectEl.shape;
  13335. rectShape.x = x;
  13336. rectShape.y = y;
  13337. rectShape.width = width;
  13338. rectShape.height = height;
  13339. rectShape.r = textBorderRadius;
  13340. rectEl.dirtyShape();
  13341. }
  13342. if (isPlainOrGradientBg) {
  13343. var rectStyle = rectEl.style;
  13344. rectStyle.fill = textBackgroundColor || null;
  13345. rectStyle.fillOpacity = retrieve2(style.fillOpacity, 1);
  13346. }
  13347. else if (isImageBg) {
  13348. imgEl = this._getOrCreateChild(ZRImage);
  13349. imgEl.onload = function () {
  13350. self.dirtyStyle();
  13351. };
  13352. var imgStyle = imgEl.style;
  13353. imgStyle.image = textBackgroundColor.image;
  13354. imgStyle.x = x;
  13355. imgStyle.y = y;
  13356. imgStyle.width = width;
  13357. imgStyle.height = height;
  13358. }
  13359. if (textBorderWidth && textBorderColor) {
  13360. var rectStyle = rectEl.style;
  13361. rectStyle.lineWidth = textBorderWidth;
  13362. rectStyle.stroke = textBorderColor;
  13363. rectStyle.strokeOpacity = retrieve2(style.strokeOpacity, 1);
  13364. rectStyle.lineDash = style.borderDash;
  13365. rectStyle.lineDashOffset = style.borderDashOffset || 0;
  13366. rectEl.strokeContainThreshold = 0;
  13367. if (rectEl.hasFill() && rectEl.hasStroke()) {
  13368. rectStyle.strokeFirst = true;
  13369. rectStyle.lineWidth *= 2;
  13370. }
  13371. }
  13372. var commonStyle = (rectEl || imgEl).style;
  13373. commonStyle.shadowBlur = style.shadowBlur || 0;
  13374. commonStyle.shadowColor = style.shadowColor || 'transparent';
  13375. commonStyle.shadowOffsetX = style.shadowOffsetX || 0;
  13376. commonStyle.shadowOffsetY = style.shadowOffsetY || 0;
  13377. commonStyle.opacity = retrieve3(style.opacity, topStyle.opacity, 1);
  13378. };
  13379. ZRText.makeFont = function (style) {
  13380. var font = '';
  13381. if (hasSeparateFont(style)) {
  13382. font = [
  13383. style.fontStyle,
  13384. style.fontWeight,
  13385. parseFontSize(style.fontSize),
  13386. style.fontFamily || 'sans-serif'
  13387. ].join(' ');
  13388. }
  13389. return font && trim(font) || style.textFont || style.font;
  13390. };
  13391. return ZRText;
  13392. }(Displayable));
  13393. var VALID_TEXT_ALIGN = { left: true, right: 1, center: 1 };
  13394. var VALID_TEXT_VERTICAL_ALIGN = { top: 1, bottom: 1, middle: 1 };
  13395. var FONT_PARTS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily'];
  13396. function parseFontSize(fontSize) {
  13397. if (typeof fontSize === 'string'
  13398. && (fontSize.indexOf('px') !== -1
  13399. || fontSize.indexOf('rem') !== -1
  13400. || fontSize.indexOf('em') !== -1)) {
  13401. return fontSize;
  13402. }
  13403. else if (!isNaN(+fontSize)) {
  13404. return fontSize + 'px';
  13405. }
  13406. else {
  13407. return DEFAULT_FONT_SIZE + 'px';
  13408. }
  13409. }
  13410. function setSeparateFont(targetStyle, sourceStyle) {
  13411. for (var i = 0; i < FONT_PARTS.length; i++) {
  13412. var fontProp = FONT_PARTS[i];
  13413. var val = sourceStyle[fontProp];
  13414. if (val != null) {
  13415. targetStyle[fontProp] = val;
  13416. }
  13417. }
  13418. }
  13419. function hasSeparateFont(style) {
  13420. return style.fontSize != null || style.fontFamily || style.fontWeight;
  13421. }
  13422. function normalizeTextStyle(style) {
  13423. normalizeStyle(style);
  13424. each(style.rich, normalizeStyle);
  13425. return style;
  13426. }
  13427. function normalizeStyle(style) {
  13428. if (style) {
  13429. style.font = ZRText.makeFont(style);
  13430. var textAlign = style.align;
  13431. textAlign === 'middle' && (textAlign = 'center');
  13432. style.align = (textAlign == null || VALID_TEXT_ALIGN[textAlign]) ? textAlign : 'left';
  13433. var verticalAlign = style.verticalAlign;
  13434. verticalAlign === 'center' && (verticalAlign = 'middle');
  13435. style.verticalAlign = (verticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[verticalAlign]) ? verticalAlign : 'top';
  13436. var textPadding = style.padding;
  13437. if (textPadding) {
  13438. style.padding = normalizeCssArray(style.padding);
  13439. }
  13440. }
  13441. }
  13442. function getStroke(stroke, lineWidth) {
  13443. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  13444. ? null
  13445. : (stroke.image || stroke.colorStops)
  13446. ? '#000'
  13447. : stroke;
  13448. }
  13449. function getFill(fill) {
  13450. return (fill == null || fill === 'none')
  13451. ? null
  13452. : (fill.image || fill.colorStops)
  13453. ? '#000'
  13454. : fill;
  13455. }
  13456. function getTextXForPadding(x, textAlign, textPadding) {
  13457. return textAlign === 'right'
  13458. ? (x - textPadding[1])
  13459. : textAlign === 'center'
  13460. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  13461. : (x + textPadding[3]);
  13462. }
  13463. function getStyleText(style) {
  13464. var text = style.text;
  13465. text != null && (text += '');
  13466. return text;
  13467. }
  13468. function needDrawBackground(style) {
  13469. return !!(style.backgroundColor
  13470. || style.lineHeight
  13471. || (style.borderWidth && style.borderColor));
  13472. }
  13473. var ArcShape = (function () {
  13474. function ArcShape() {
  13475. this.cx = 0;
  13476. this.cy = 0;
  13477. this.r = 0;
  13478. this.startAngle = 0;
  13479. this.endAngle = Math.PI * 2;
  13480. this.clockwise = true;
  13481. }
  13482. return ArcShape;
  13483. }());
  13484. var Arc = (function (_super) {
  13485. __extends(Arc, _super);
  13486. function Arc(opts) {
  13487. return _super.call(this, opts) || this;
  13488. }
  13489. Arc.prototype.getDefaultStyle = function () {
  13490. return {
  13491. stroke: '#000',
  13492. fill: null
  13493. };
  13494. };
  13495. Arc.prototype.getDefaultShape = function () {
  13496. return new ArcShape();
  13497. };
  13498. Arc.prototype.buildPath = function (ctx, shape) {
  13499. var x = shape.cx;
  13500. var y = shape.cy;
  13501. var r = Math.max(shape.r, 0);
  13502. var startAngle = shape.startAngle;
  13503. var endAngle = shape.endAngle;
  13504. var clockwise = shape.clockwise;
  13505. var unitX = Math.cos(startAngle);
  13506. var unitY = Math.sin(startAngle);
  13507. ctx.moveTo(unitX * r + x, unitY * r + y);
  13508. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13509. };
  13510. return Arc;
  13511. }(Path));
  13512. Arc.prototype.type = 'arc';
  13513. var out = [];
  13514. var BezierCurveShape = (function () {
  13515. function BezierCurveShape() {
  13516. this.x1 = 0;
  13517. this.y1 = 0;
  13518. this.x2 = 0;
  13519. this.y2 = 0;
  13520. this.cpx1 = 0;
  13521. this.cpy1 = 0;
  13522. this.percent = 1;
  13523. }
  13524. return BezierCurveShape;
  13525. }());
  13526. function someVectorAt(shape, t, isTangent) {
  13527. var cpx2 = shape.cpx2;
  13528. var cpy2 = shape.cpy2;
  13529. if (cpx2 != null || cpy2 != null) {
  13530. return [
  13531. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  13532. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  13533. ];
  13534. }
  13535. else {
  13536. return [
  13537. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  13538. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  13539. ];
  13540. }
  13541. }
  13542. var BezierCurve = (function (_super) {
  13543. __extends(BezierCurve, _super);
  13544. function BezierCurve(opts) {
  13545. return _super.call(this, opts) || this;
  13546. }
  13547. BezierCurve.prototype.getDefaultStyle = function () {
  13548. return {
  13549. stroke: '#000',
  13550. fill: null
  13551. };
  13552. };
  13553. BezierCurve.prototype.getDefaultShape = function () {
  13554. return new BezierCurveShape();
  13555. };
  13556. BezierCurve.prototype.buildPath = function (ctx, shape) {
  13557. var x1 = shape.x1;
  13558. var y1 = shape.y1;
  13559. var x2 = shape.x2;
  13560. var y2 = shape.y2;
  13561. var cpx1 = shape.cpx1;
  13562. var cpy1 = shape.cpy1;
  13563. var cpx2 = shape.cpx2;
  13564. var cpy2 = shape.cpy2;
  13565. var percent = shape.percent;
  13566. if (percent === 0) {
  13567. return;
  13568. }
  13569. ctx.moveTo(x1, y1);
  13570. if (cpx2 == null || cpy2 == null) {
  13571. if (percent < 1) {
  13572. quadraticSubdivide(x1, cpx1, x2, percent, out);
  13573. cpx1 = out[1];
  13574. x2 = out[2];
  13575. quadraticSubdivide(y1, cpy1, y2, percent, out);
  13576. cpy1 = out[1];
  13577. y2 = out[2];
  13578. }
  13579. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  13580. }
  13581. else {
  13582. if (percent < 1) {
  13583. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  13584. cpx1 = out[1];
  13585. cpx2 = out[2];
  13586. x2 = out[3];
  13587. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  13588. cpy1 = out[1];
  13589. cpy2 = out[2];
  13590. y2 = out[3];
  13591. }
  13592. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  13593. }
  13594. };
  13595. BezierCurve.prototype.pointAt = function (t) {
  13596. return someVectorAt(this.shape, t, false);
  13597. };
  13598. BezierCurve.prototype.tangentAt = function (t) {
  13599. var p = someVectorAt(this.shape, t, true);
  13600. return normalize(p, p);
  13601. };
  13602. return BezierCurve;
  13603. }(Path));
  13604. BezierCurve.prototype.type = 'bezier-curve';
  13605. var DropletShape = (function () {
  13606. function DropletShape() {
  13607. this.cx = 0;
  13608. this.cy = 0;
  13609. this.width = 0;
  13610. this.height = 0;
  13611. }
  13612. return DropletShape;
  13613. }());
  13614. var Droplet = (function (_super) {
  13615. __extends(Droplet, _super);
  13616. function Droplet(opts) {
  13617. return _super.call(this, opts) || this;
  13618. }
  13619. Droplet.prototype.getDefaultShape = function () {
  13620. return new DropletShape();
  13621. };
  13622. Droplet.prototype.buildPath = function (ctx, shape) {
  13623. var x = shape.cx;
  13624. var y = shape.cy;
  13625. var a = shape.width;
  13626. var b = shape.height;
  13627. ctx.moveTo(x, y + a);
  13628. ctx.bezierCurveTo(x + a, y + a, x + a * 3 / 2, y - a / 3, x, y - b);
  13629. ctx.bezierCurveTo(x - a * 3 / 2, y - a / 3, x - a, y + a, x, y + a);
  13630. ctx.closePath();
  13631. };
  13632. return Droplet;
  13633. }(Path));
  13634. Droplet.prototype.type = 'droplet';
  13635. var HeartShape = (function () {
  13636. function HeartShape() {
  13637. this.cx = 0;
  13638. this.cy = 0;
  13639. this.width = 0;
  13640. this.height = 0;
  13641. }
  13642. return HeartShape;
  13643. }());
  13644. var Heart = (function (_super) {
  13645. __extends(Heart, _super);
  13646. function Heart(opts) {
  13647. return _super.call(this, opts) || this;
  13648. }
  13649. Heart.prototype.getDefaultShape = function () {
  13650. return new HeartShape();
  13651. };
  13652. Heart.prototype.buildPath = function (ctx, shape) {
  13653. var x = shape.cx;
  13654. var y = shape.cy;
  13655. var a = shape.width;
  13656. var b = shape.height;
  13657. ctx.moveTo(x, y);
  13658. ctx.bezierCurveTo(x + a / 2, y - b * 2 / 3, x + a * 2, y + b / 3, x, y + b);
  13659. ctx.bezierCurveTo(x - a * 2, y + b / 3, x - a / 2, y - b * 2 / 3, x, y);
  13660. };
  13661. return Heart;
  13662. }(Path));
  13663. Heart.prototype.type = 'heart';
  13664. var PI$3 = Math.PI;
  13665. var sin = Math.sin;
  13666. var cos = Math.cos;
  13667. var IsogonShape = (function () {
  13668. function IsogonShape() {
  13669. this.x = 0;
  13670. this.y = 0;
  13671. this.r = 0;
  13672. this.n = 0;
  13673. }
  13674. return IsogonShape;
  13675. }());
  13676. var Isogon = (function (_super) {
  13677. __extends(Isogon, _super);
  13678. function Isogon(opts) {
  13679. return _super.call(this, opts) || this;
  13680. }
  13681. Isogon.prototype.getDefaultShape = function () {
  13682. return new IsogonShape();
  13683. };
  13684. Isogon.prototype.buildPath = function (ctx, shape) {
  13685. var n = shape.n;
  13686. if (!n || n < 2) {
  13687. return;
  13688. }
  13689. var x = shape.x;
  13690. var y = shape.y;
  13691. var r = shape.r;
  13692. var dStep = 2 * PI$3 / n;
  13693. var deg = -PI$3 / 2;
  13694. ctx.moveTo(x + r * cos(deg), y + r * sin(deg));
  13695. for (var i = 0, end = n - 1; i < end; i++) {
  13696. deg += dStep;
  13697. ctx.lineTo(x + r * cos(deg), y + r * sin(deg));
  13698. }
  13699. ctx.closePath();
  13700. return;
  13701. };
  13702. return Isogon;
  13703. }(Path));
  13704. Isogon.prototype.type = 'isogon';
  13705. var RingShape = (function () {
  13706. function RingShape() {
  13707. this.cx = 0;
  13708. this.cy = 0;
  13709. this.r = 0;
  13710. this.r0 = 0;
  13711. }
  13712. return RingShape;
  13713. }());
  13714. var Ring = (function (_super) {
  13715. __extends(Ring, _super);
  13716. function Ring(opts) {
  13717. return _super.call(this, opts) || this;
  13718. }
  13719. Ring.prototype.getDefaultShape = function () {
  13720. return new RingShape();
  13721. };
  13722. Ring.prototype.buildPath = function (ctx, shape) {
  13723. var x = shape.cx;
  13724. var y = shape.cy;
  13725. var PI2 = Math.PI * 2;
  13726. ctx.moveTo(x + shape.r, y);
  13727. ctx.arc(x, y, shape.r, 0, PI2, false);
  13728. ctx.moveTo(x + shape.r0, y);
  13729. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13730. };
  13731. return Ring;
  13732. }(Path));
  13733. Ring.prototype.type = 'ring';
  13734. var sin$1 = Math.sin;
  13735. var cos$1 = Math.cos;
  13736. var radian = Math.PI / 180;
  13737. var RoseShape = (function () {
  13738. function RoseShape() {
  13739. this.cx = 0;
  13740. this.cy = 0;
  13741. this.r = [];
  13742. this.k = 0;
  13743. this.n = 1;
  13744. }
  13745. return RoseShape;
  13746. }());
  13747. var Rose = (function (_super) {
  13748. __extends(Rose, _super);
  13749. function Rose(opts) {
  13750. return _super.call(this, opts) || this;
  13751. }
  13752. Rose.prototype.getDefaultStyle = function () {
  13753. return {
  13754. stroke: '#000',
  13755. fill: null
  13756. };
  13757. };
  13758. Rose.prototype.getDefaultShape = function () {
  13759. return new RoseShape();
  13760. };
  13761. Rose.prototype.buildPath = function (ctx, shape) {
  13762. var R = shape.r;
  13763. var k = shape.k;
  13764. var n = shape.n;
  13765. var x0 = shape.cx;
  13766. var y0 = shape.cy;
  13767. var x;
  13768. var y;
  13769. var r;
  13770. ctx.moveTo(x0, y0);
  13771. for (var i = 0, len = R.length; i < len; i++) {
  13772. r = R[i];
  13773. for (var j = 0; j <= 360 * n; j++) {
  13774. x = r
  13775. * sin$1(k / n * j % 360 * radian)
  13776. * cos$1(j * radian)
  13777. + x0;
  13778. y = r
  13779. * sin$1(k / n * j % 360 * radian)
  13780. * sin$1(j * radian)
  13781. + y0;
  13782. ctx.lineTo(x, y);
  13783. }
  13784. }
  13785. };
  13786. return Rose;
  13787. }(Path));
  13788. Rose.prototype.type = 'rose';
  13789. var PI$4 = Math.PI;
  13790. var cos$2 = Math.cos;
  13791. var sin$2 = Math.sin;
  13792. var StarShape = (function () {
  13793. function StarShape() {
  13794. this.cx = 0;
  13795. this.cy = 0;
  13796. this.n = 3;
  13797. this.r = 0;
  13798. }
  13799. return StarShape;
  13800. }());
  13801. var Star = (function (_super) {
  13802. __extends(Star, _super);
  13803. function Star(opts) {
  13804. return _super.call(this, opts) || this;
  13805. }
  13806. Star.prototype.getDefaultShape = function () {
  13807. return new StarShape();
  13808. };
  13809. Star.prototype.buildPath = function (ctx, shape) {
  13810. var n = shape.n;
  13811. if (!n || n < 2) {
  13812. return;
  13813. }
  13814. var x = shape.cx;
  13815. var y = shape.cy;
  13816. var r = shape.r;
  13817. var r0 = shape.r0;
  13818. if (r0 == null) {
  13819. r0 = n > 4
  13820. ? r * cos$2(2 * PI$4 / n) / cos$2(PI$4 / n)
  13821. : r / 3;
  13822. }
  13823. var dStep = PI$4 / n;
  13824. var deg = -PI$4 / 2;
  13825. var xStart = x + r * cos$2(deg);
  13826. var yStart = y + r * sin$2(deg);
  13827. deg += dStep;
  13828. ctx.moveTo(xStart, yStart);
  13829. for (var i = 0, end = n * 2 - 1, ri = void 0; i < end; i++) {
  13830. ri = i % 2 === 0 ? r0 : r;
  13831. ctx.lineTo(x + ri * cos$2(deg), y + ri * sin$2(deg));
  13832. deg += dStep;
  13833. }
  13834. ctx.closePath();
  13835. };
  13836. return Star;
  13837. }(Path));
  13838. Star.prototype.type = 'star';
  13839. var cos$3 = Math.cos;
  13840. var sin$3 = Math.sin;
  13841. var TrochoidShape = (function () {
  13842. function TrochoidShape() {
  13843. this.cx = 0;
  13844. this.cy = 0;
  13845. this.r = 0;
  13846. this.r0 = 0;
  13847. this.d = 0;
  13848. this.location = 'out';
  13849. }
  13850. return TrochoidShape;
  13851. }());
  13852. var Trochoid = (function (_super) {
  13853. __extends(Trochoid, _super);
  13854. function Trochoid(opts) {
  13855. return _super.call(this, opts) || this;
  13856. }
  13857. Trochoid.prototype.getDefaultStyle = function () {
  13858. return {
  13859. stroke: '#000',
  13860. fill: null
  13861. };
  13862. };
  13863. Trochoid.prototype.getDefaultShape = function () {
  13864. return new TrochoidShape();
  13865. };
  13866. Trochoid.prototype.buildPath = function (ctx, shape) {
  13867. var R = shape.r;
  13868. var r = shape.r0;
  13869. var d = shape.d;
  13870. var offsetX = shape.cx;
  13871. var offsetY = shape.cy;
  13872. var delta = shape.location === 'out' ? 1 : -1;
  13873. var x1;
  13874. var y1;
  13875. var x2;
  13876. var y2;
  13877. if (shape.location && R <= r) {
  13878. return;
  13879. }
  13880. var num = 0;
  13881. var i = 1;
  13882. var theta;
  13883. x1 = (R + delta * r) * cos$3(0)
  13884. - delta * d * cos$3(0) + offsetX;
  13885. y1 = (R + delta * r) * sin$3(0)
  13886. - d * sin$3(0) + offsetY;
  13887. ctx.moveTo(x1, y1);
  13888. do {
  13889. num++;
  13890. } while ((r * num) % (R + delta * r) !== 0);
  13891. do {
  13892. theta = Math.PI / 180 * i;
  13893. x2 = (R + delta * r) * cos$3(theta)
  13894. - delta * d * cos$3((R / r + delta) * theta)
  13895. + offsetX;
  13896. y2 = (R + delta * r) * sin$3(theta)
  13897. - d * sin$3((R / r + delta) * theta)
  13898. + offsetY;
  13899. ctx.lineTo(x2, y2);
  13900. i++;
  13901. } while (i <= (r * num) / (R + delta * r) * 360);
  13902. };
  13903. return Trochoid;
  13904. }(Path));
  13905. Trochoid.prototype.type = 'trochoid';
  13906. var Pattern = (function () {
  13907. function Pattern(image, repeat) {
  13908. this.image = image;
  13909. this.repeat = repeat;
  13910. this.x = 0;
  13911. this.y = 0;
  13912. this.rotation = 0;
  13913. this.scaleX = 1;
  13914. this.scaleY = 1;
  13915. }
  13916. return Pattern;
  13917. }());
  13918. var extent = [0, 0];
  13919. var extent2 = [0, 0];
  13920. var minTv$1 = new Point();
  13921. var maxTv$1 = new Point();
  13922. var OrientedBoundingRect = (function () {
  13923. function OrientedBoundingRect(rect, transform) {
  13924. this._corners = [];
  13925. this._axes = [];
  13926. this._origin = [0, 0];
  13927. for (var i = 0; i < 4; i++) {
  13928. this._corners[i] = new Point();
  13929. }
  13930. for (var i = 0; i < 2; i++) {
  13931. this._axes[i] = new Point();
  13932. }
  13933. if (rect) {
  13934. this.fromBoundingRect(rect, transform);
  13935. }
  13936. }
  13937. OrientedBoundingRect.prototype.fromBoundingRect = function (rect, transform) {
  13938. var corners = this._corners;
  13939. var axes = this._axes;
  13940. var x = rect.x;
  13941. var y = rect.y;
  13942. var x2 = x + rect.width;
  13943. var y2 = y + rect.height;
  13944. corners[0].set(x, y);
  13945. corners[1].set(x2, y);
  13946. corners[2].set(x2, y2);
  13947. corners[3].set(x, y2);
  13948. if (transform) {
  13949. for (var i = 0; i < 4; i++) {
  13950. corners[i].transform(transform);
  13951. }
  13952. }
  13953. Point.sub(axes[0], corners[1], corners[0]);
  13954. Point.sub(axes[1], corners[3], corners[0]);
  13955. axes[0].normalize();
  13956. axes[1].normalize();
  13957. for (var i = 0; i < 2; i++) {
  13958. this._origin[i] = axes[i].dot(corners[0]);
  13959. }
  13960. };
  13961. OrientedBoundingRect.prototype.intersect = function (other, mtv) {
  13962. var overlapped = true;
  13963. var noMtv = !mtv;
  13964. minTv$1.set(Infinity, Infinity);
  13965. maxTv$1.set(0, 0);
  13966. if (!this._intersectCheckOneSide(this, other, minTv$1, maxTv$1, noMtv, 1)) {
  13967. overlapped = false;
  13968. if (noMtv) {
  13969. return overlapped;
  13970. }
  13971. }
  13972. if (!this._intersectCheckOneSide(other, this, minTv$1, maxTv$1, noMtv, -1)) {
  13973. overlapped = false;
  13974. if (noMtv) {
  13975. return overlapped;
  13976. }
  13977. }
  13978. if (!noMtv) {
  13979. Point.copy(mtv, overlapped ? minTv$1 : maxTv$1);
  13980. }
  13981. return overlapped;
  13982. };
  13983. OrientedBoundingRect.prototype._intersectCheckOneSide = function (self, other, minTv, maxTv, noMtv, inverse) {
  13984. var overlapped = true;
  13985. for (var i = 0; i < 2; i++) {
  13986. var axis = this._axes[i];
  13987. this._getProjMinMaxOnAxis(i, self._corners, extent);
  13988. this._getProjMinMaxOnAxis(i, other._corners, extent2);
  13989. if (extent[1] < extent2[0] || extent[0] > extent2[1]) {
  13990. overlapped = false;
  13991. if (noMtv) {
  13992. return overlapped;
  13993. }
  13994. var dist0 = Math.abs(extent2[0] - extent[1]);
  13995. var dist1 = Math.abs(extent[0] - extent2[1]);
  13996. if (Math.min(dist0, dist1) > maxTv.len()) {
  13997. if (dist0 < dist1) {
  13998. Point.scale(maxTv, axis, -dist0 * inverse);
  13999. }
  14000. else {
  14001. Point.scale(maxTv, axis, dist1 * inverse);
  14002. }
  14003. }
  14004. }
  14005. else if (minTv) {
  14006. var dist0 = Math.abs(extent2[0] - extent[1]);
  14007. var dist1 = Math.abs(extent[0] - extent2[1]);
  14008. if (Math.min(dist0, dist1) < minTv.len()) {
  14009. if (dist0 < dist1) {
  14010. Point.scale(minTv, axis, dist0 * inverse);
  14011. }
  14012. else {
  14013. Point.scale(minTv, axis, -dist1 * inverse);
  14014. }
  14015. }
  14016. }
  14017. }
  14018. return overlapped;
  14019. };
  14020. OrientedBoundingRect.prototype._getProjMinMaxOnAxis = function (dim, corners, out) {
  14021. var axis = this._axes[dim];
  14022. var origin = this._origin;
  14023. var proj = corners[0].dot(axis) + origin[dim];
  14024. var min = proj;
  14025. var max = proj;
  14026. for (var i = 1; i < corners.length; i++) {
  14027. var proj_1 = corners[i].dot(axis) + origin[dim];
  14028. min = Math.min(proj_1, min);
  14029. max = Math.max(proj_1, max);
  14030. }
  14031. out[0] = min;
  14032. out[1] = max;
  14033. };
  14034. return OrientedBoundingRect;
  14035. }());
  14036. var DebugRect = (function () {
  14037. function DebugRect(style) {
  14038. var dom = this.dom = document.createElement('div');
  14039. dom.className = 'ec-debug-dirty-rect';
  14040. style = extend({}, style);
  14041. extend(style, {
  14042. backgroundColor: 'rgba(0, 0, 255, 0.2)',
  14043. border: '1px solid #00f'
  14044. });
  14045. dom.style.cssText = "\nposition: absolute;\nopacity: 0;\ntransition: opacity 0.5s linear;\npointer-events: none;\n";
  14046. for (var key in style) {
  14047. if (style.hasOwnProperty(key)) {
  14048. dom.style[key] = style[key];
  14049. }
  14050. }
  14051. }
  14052. DebugRect.prototype.update = function (rect) {
  14053. var domStyle = this.dom.style;
  14054. domStyle.width = rect.width + 'px';
  14055. domStyle.height = rect.height + 'px';
  14056. domStyle.left = rect.x + 'px';
  14057. domStyle.top = rect.y + 'px';
  14058. };
  14059. DebugRect.prototype.hide = function () {
  14060. this.dom.style.opacity = '0';
  14061. };
  14062. DebugRect.prototype.show = function (autoHideDelay) {
  14063. var _this = this;
  14064. clearTimeout(this._hideTimeout);
  14065. this.dom.style.opacity = '1';
  14066. this._hideTimeout = setTimeout(function () {
  14067. _this.hide();
  14068. }, autoHideDelay || 1000);
  14069. };
  14070. return DebugRect;
  14071. }());
  14072. function showDebugDirtyRect(zr, opts) {
  14073. opts = opts || {};
  14074. var painter = zr.painter;
  14075. if (!painter.getLayers) {
  14076. throw new Error('Debug dirty rect can only been used on canvas renderer.');
  14077. }
  14078. if (painter.isSingleCanvas()) {
  14079. throw new Error('Debug dirty rect can only been used on zrender inited with container.');
  14080. }
  14081. var debugViewRoot = document.createElement('div');
  14082. debugViewRoot.style.cssText = "\nposition:absolute;\nleft:0;\ntop:0;\nright:0;\nbottom:0;\npointer-events:none;\n";
  14083. debugViewRoot.className = 'ec-debug-dirty-rect-container';
  14084. var debugRects = [];
  14085. var dom = zr.dom;
  14086. dom.appendChild(debugViewRoot);
  14087. var computedStyle = getComputedStyle(dom);
  14088. if (computedStyle.position === 'static') {
  14089. dom.style.position = 'relative';
  14090. }
  14091. zr.on('rendered', function () {
  14092. if (painter.getLayers) {
  14093. var idx_1 = 0;
  14094. painter.eachBuiltinLayer(function (layer) {
  14095. if (!layer.debugGetPaintRects) {
  14096. return;
  14097. }
  14098. var paintRects = layer.debugGetPaintRects();
  14099. for (var i = 0; i < paintRects.length; i++) {
  14100. if (!paintRects[i].width || !paintRects[i].height) {
  14101. continue;
  14102. }
  14103. if (!debugRects[idx_1]) {
  14104. debugRects[idx_1] = new DebugRect(opts.style);
  14105. debugViewRoot.appendChild(debugRects[idx_1].dom);
  14106. }
  14107. debugRects[idx_1].show(opts.autoHideDelay);
  14108. debugRects[idx_1].update(paintRects[i]);
  14109. idx_1++;
  14110. }
  14111. });
  14112. for (var i = idx_1; i < debugRects.length; i++) {
  14113. debugRects[i].hide();
  14114. }
  14115. }
  14116. });
  14117. }
  14118. function isSafeNum(num) {
  14119. return isFinite(num);
  14120. }
  14121. function createLinearGradient(ctx, obj, rect) {
  14122. var x = obj.x == null ? 0 : obj.x;
  14123. var x2 = obj.x2 == null ? 1 : obj.x2;
  14124. var y = obj.y == null ? 0 : obj.y;
  14125. var y2 = obj.y2 == null ? 0 : obj.y2;
  14126. if (!obj.global) {
  14127. x = x * rect.width + rect.x;
  14128. x2 = x2 * rect.width + rect.x;
  14129. y = y * rect.height + rect.y;
  14130. y2 = y2 * rect.height + rect.y;
  14131. }
  14132. x = isSafeNum(x) ? x : 0;
  14133. x2 = isSafeNum(x2) ? x2 : 1;
  14134. y = isSafeNum(y) ? y : 0;
  14135. y2 = isSafeNum(y2) ? y2 : 0;
  14136. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  14137. return canvasGradient;
  14138. }
  14139. function createRadialGradient(ctx, obj, rect) {
  14140. var width = rect.width;
  14141. var height = rect.height;
  14142. var min = Math.min(width, height);
  14143. var x = obj.x == null ? 0.5 : obj.x;
  14144. var y = obj.y == null ? 0.5 : obj.y;
  14145. var r = obj.r == null ? 0.5 : obj.r;
  14146. if (!obj.global) {
  14147. x = x * width + rect.x;
  14148. y = y * height + rect.y;
  14149. r = r * min;
  14150. }
  14151. x = isSafeNum(x) ? x : 0.5;
  14152. y = isSafeNum(y) ? y : 0.5;
  14153. r = r >= 0 && isSafeNum(r) ? r : 0.5;
  14154. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  14155. return canvasGradient;
  14156. }
  14157. function getCanvasGradient(ctx, obj, rect) {
  14158. var canvasGradient = obj.type === 'radial'
  14159. ? createRadialGradient(ctx, obj, rect)
  14160. : createLinearGradient(ctx, obj, rect);
  14161. var colorStops = obj.colorStops;
  14162. for (var i = 0; i < colorStops.length; i++) {
  14163. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  14164. }
  14165. return canvasGradient;
  14166. }
  14167. function isClipPathChanged(clipPaths, prevClipPaths) {
  14168. if (clipPaths === prevClipPaths || (!clipPaths && !prevClipPaths)) {
  14169. return false;
  14170. }
  14171. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  14172. return true;
  14173. }
  14174. for (var i = 0; i < clipPaths.length; i++) {
  14175. if (clipPaths[i] !== prevClipPaths[i]) {
  14176. return true;
  14177. }
  14178. }
  14179. return false;
  14180. }
  14181. function parseInt10(val) {
  14182. return parseInt(val, 10);
  14183. }
  14184. function getSize(root, whIdx, opts) {
  14185. var wh = ['width', 'height'][whIdx];
  14186. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  14187. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  14188. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  14189. if (opts[wh] != null && opts[wh] !== 'auto') {
  14190. return parseFloat(opts[wh]);
  14191. }
  14192. var stl = document.defaultView.getComputedStyle(root);
  14193. return ((root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  14194. - (parseInt10(stl[plt]) || 0)
  14195. - (parseInt10(stl[prb]) || 0)) | 0;
  14196. }
  14197. function normalizeLineDash(lineType, lineWidth) {
  14198. if (!lineType || lineType === 'solid' || !(lineWidth > 0)) {
  14199. return null;
  14200. }
  14201. return lineType === 'dashed'
  14202. ? [4 * lineWidth, 2 * lineWidth]
  14203. : lineType === 'dotted'
  14204. ? [lineWidth]
  14205. : isNumber(lineType)
  14206. ? [lineType] : isArray(lineType) ? lineType : null;
  14207. }
  14208. function getLineDash(el) {
  14209. var style = el.style;
  14210. var lineDash = style.lineDash && style.lineWidth > 0 && normalizeLineDash(style.lineDash, style.lineWidth);
  14211. var lineDashOffset = style.lineDashOffset;
  14212. if (lineDash) {
  14213. var lineScale_1 = (style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1;
  14214. if (lineScale_1 && lineScale_1 !== 1) {
  14215. lineDash = map(lineDash, function (rawVal) {
  14216. return rawVal / lineScale_1;
  14217. });
  14218. lineDashOffset /= lineScale_1;
  14219. }
  14220. }
  14221. return [lineDash, lineDashOffset];
  14222. }
  14223. var pathProxyForDraw = new PathProxy(true);
  14224. function styleHasStroke(style) {
  14225. var stroke = style.stroke;
  14226. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  14227. }
  14228. function isValidStrokeFillStyle(strokeOrFill) {
  14229. return typeof strokeOrFill === 'string' && strokeOrFill !== 'none';
  14230. }
  14231. function styleHasFill(style) {
  14232. var fill = style.fill;
  14233. return fill != null && fill !== 'none';
  14234. }
  14235. function doFillPath(ctx, style) {
  14236. if (style.fillOpacity != null && style.fillOpacity !== 1) {
  14237. var originalGlobalAlpha = ctx.globalAlpha;
  14238. ctx.globalAlpha = style.fillOpacity * style.opacity;
  14239. ctx.fill();
  14240. ctx.globalAlpha = originalGlobalAlpha;
  14241. }
  14242. else {
  14243. ctx.fill();
  14244. }
  14245. }
  14246. function doStrokePath(ctx, style) {
  14247. if (style.strokeOpacity != null && style.strokeOpacity !== 1) {
  14248. var originalGlobalAlpha = ctx.globalAlpha;
  14249. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  14250. ctx.stroke();
  14251. ctx.globalAlpha = originalGlobalAlpha;
  14252. }
  14253. else {
  14254. ctx.stroke();
  14255. }
  14256. }
  14257. function createCanvasPattern(ctx, pattern, el) {
  14258. var image = createOrUpdateImage(pattern.image, pattern.__image, el);
  14259. if (isImageReady(image)) {
  14260. var canvasPattern = ctx.createPattern(image, pattern.repeat || 'repeat');
  14261. if (typeof DOMMatrix === 'function'
  14262. && canvasPattern
  14263. && canvasPattern.setTransform) {
  14264. var matrix = new DOMMatrix();
  14265. matrix.translateSelf((pattern.x || 0), (pattern.y || 0));
  14266. matrix.rotateSelf(0, 0, (pattern.rotation || 0) * RADIAN_TO_DEGREE);
  14267. matrix.scaleSelf((pattern.scaleX || 1), (pattern.scaleY || 1));
  14268. canvasPattern.setTransform(matrix);
  14269. }
  14270. return canvasPattern;
  14271. }
  14272. }
  14273. function brushPath(ctx, el, style, inBatch) {
  14274. var _a;
  14275. var hasStroke = styleHasStroke(style);
  14276. var hasFill = styleHasFill(style);
  14277. var strokePercent = style.strokePercent;
  14278. var strokePart = strokePercent < 1;
  14279. var firstDraw = !el.path;
  14280. if ((!el.silent || strokePart) && firstDraw) {
  14281. el.createPathProxy();
  14282. }
  14283. var path = el.path || pathProxyForDraw;
  14284. var dirtyFlag = el.__dirty;
  14285. if (!inBatch) {
  14286. var fill = style.fill;
  14287. var stroke = style.stroke;
  14288. var hasFillGradient = hasFill && !!fill.colorStops;
  14289. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  14290. var hasFillPattern = hasFill && !!fill.image;
  14291. var hasStrokePattern = hasStroke && !!stroke.image;
  14292. var fillGradient = void 0;
  14293. var strokeGradient = void 0;
  14294. var fillPattern = void 0;
  14295. var strokePattern = void 0;
  14296. var rect = void 0;
  14297. if (hasFillGradient || hasStrokeGradient) {
  14298. rect = el.getBoundingRect();
  14299. }
  14300. if (hasFillGradient) {
  14301. fillGradient = dirtyFlag
  14302. ? getCanvasGradient(ctx, fill, rect)
  14303. : el.__canvasFillGradient;
  14304. el.__canvasFillGradient = fillGradient;
  14305. }
  14306. if (hasStrokeGradient) {
  14307. strokeGradient = dirtyFlag
  14308. ? getCanvasGradient(ctx, stroke, rect)
  14309. : el.__canvasStrokeGradient;
  14310. el.__canvasStrokeGradient = strokeGradient;
  14311. }
  14312. if (hasFillPattern) {
  14313. fillPattern = (dirtyFlag || !el.__canvasFillPattern)
  14314. ? createCanvasPattern(ctx, fill, el)
  14315. : el.__canvasFillPattern;
  14316. el.__canvasFillPattern = fillPattern;
  14317. }
  14318. if (hasStrokePattern) {
  14319. strokePattern = (dirtyFlag || !el.__canvasStrokePattern)
  14320. ? createCanvasPattern(ctx, stroke, el)
  14321. : el.__canvasStrokePattern;
  14322. el.__canvasStrokePattern = fillPattern;
  14323. }
  14324. if (hasFillGradient) {
  14325. ctx.fillStyle = fillGradient;
  14326. }
  14327. else if (hasFillPattern) {
  14328. if (fillPattern) {
  14329. ctx.fillStyle = fillPattern;
  14330. }
  14331. else {
  14332. hasFill = false;
  14333. }
  14334. }
  14335. if (hasStrokeGradient) {
  14336. ctx.strokeStyle = strokeGradient;
  14337. }
  14338. else if (hasStrokePattern) {
  14339. if (strokePattern) {
  14340. ctx.strokeStyle = strokePattern;
  14341. }
  14342. else {
  14343. hasStroke = false;
  14344. }
  14345. }
  14346. }
  14347. var scale = el.getGlobalScale();
  14348. path.setScale(scale[0], scale[1], el.segmentIgnoreThreshold);
  14349. var lineDash;
  14350. var lineDashOffset;
  14351. if (ctx.setLineDash && style.lineDash) {
  14352. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14353. }
  14354. var needsRebuild = true;
  14355. if (firstDraw || (dirtyFlag & SHAPE_CHANGED_BIT)) {
  14356. path.setDPR(ctx.dpr);
  14357. if (strokePart) {
  14358. path.setContext(null);
  14359. }
  14360. else {
  14361. path.setContext(ctx);
  14362. needsRebuild = false;
  14363. }
  14364. path.reset();
  14365. el.buildPath(path, el.shape, inBatch);
  14366. path.toStatic();
  14367. el.pathUpdated();
  14368. }
  14369. if (needsRebuild) {
  14370. path.rebuildPath(ctx, strokePart ? strokePercent : 1);
  14371. }
  14372. if (lineDash) {
  14373. ctx.setLineDash(lineDash);
  14374. ctx.lineDashOffset = lineDashOffset;
  14375. }
  14376. if (!inBatch) {
  14377. if (style.strokeFirst) {
  14378. if (hasStroke) {
  14379. doStrokePath(ctx, style);
  14380. }
  14381. if (hasFill) {
  14382. doFillPath(ctx, style);
  14383. }
  14384. }
  14385. else {
  14386. if (hasFill) {
  14387. doFillPath(ctx, style);
  14388. }
  14389. if (hasStroke) {
  14390. doStrokePath(ctx, style);
  14391. }
  14392. }
  14393. }
  14394. if (lineDash) {
  14395. ctx.setLineDash([]);
  14396. }
  14397. }
  14398. function brushImage(ctx, el, style) {
  14399. var image = el.__image = createOrUpdateImage(style.image, el.__image, el, el.onload);
  14400. if (!image || !isImageReady(image)) {
  14401. return;
  14402. }
  14403. var x = style.x || 0;
  14404. var y = style.y || 0;
  14405. var width = el.getWidth();
  14406. var height = el.getHeight();
  14407. var aspect = image.width / image.height;
  14408. if (width == null && height != null) {
  14409. width = height * aspect;
  14410. }
  14411. else if (height == null && width != null) {
  14412. height = width / aspect;
  14413. }
  14414. else if (width == null && height == null) {
  14415. width = image.width;
  14416. height = image.height;
  14417. }
  14418. if (style.sWidth && style.sHeight) {
  14419. var sx = style.sx || 0;
  14420. var sy = style.sy || 0;
  14421. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  14422. }
  14423. else if (style.sx && style.sy) {
  14424. var sx = style.sx;
  14425. var sy = style.sy;
  14426. var sWidth = width - sx;
  14427. var sHeight = height - sy;
  14428. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  14429. }
  14430. else {
  14431. ctx.drawImage(image, x, y, width, height);
  14432. }
  14433. }
  14434. function brushText(ctx, el, style) {
  14435. var _a;
  14436. var text = style.text;
  14437. text != null && (text += '');
  14438. if (text) {
  14439. ctx.font = style.font || DEFAULT_FONT;
  14440. ctx.textAlign = style.textAlign;
  14441. ctx.textBaseline = style.textBaseline;
  14442. var lineDash = void 0;
  14443. var lineDashOffset = void 0;
  14444. if (ctx.setLineDash && style.lineDash) {
  14445. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14446. }
  14447. if (lineDash) {
  14448. ctx.setLineDash(lineDash);
  14449. ctx.lineDashOffset = lineDashOffset;
  14450. }
  14451. if (style.strokeFirst) {
  14452. if (styleHasStroke(style)) {
  14453. ctx.strokeText(text, style.x, style.y);
  14454. }
  14455. if (styleHasFill(style)) {
  14456. ctx.fillText(text, style.x, style.y);
  14457. }
  14458. }
  14459. else {
  14460. if (styleHasFill(style)) {
  14461. ctx.fillText(text, style.x, style.y);
  14462. }
  14463. if (styleHasStroke(style)) {
  14464. ctx.strokeText(text, style.x, style.y);
  14465. }
  14466. }
  14467. if (lineDash) {
  14468. ctx.setLineDash([]);
  14469. }
  14470. }
  14471. }
  14472. var SHADOW_NUMBER_PROPS = ['shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  14473. var STROKE_PROPS = [
  14474. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  14475. ];
  14476. function bindCommonProps(ctx, style, prevStyle, forceSetAll, scope) {
  14477. var styleChanged = false;
  14478. if (!forceSetAll) {
  14479. prevStyle = prevStyle || {};
  14480. if (style === prevStyle) {
  14481. return false;
  14482. }
  14483. }
  14484. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14485. flushPathDrawn(ctx, scope);
  14486. styleChanged = true;
  14487. var opacity = Math.max(Math.min(style.opacity, 1), 0);
  14488. ctx.globalAlpha = isNaN(opacity) ? DEFAULT_COMMON_STYLE.opacity : opacity;
  14489. }
  14490. if (forceSetAll || style.blend !== prevStyle.blend) {
  14491. if (!styleChanged) {
  14492. flushPathDrawn(ctx, scope);
  14493. styleChanged = true;
  14494. }
  14495. ctx.globalCompositeOperation = style.blend || DEFAULT_COMMON_STYLE.blend;
  14496. }
  14497. for (var i = 0; i < SHADOW_NUMBER_PROPS.length; i++) {
  14498. var propName = SHADOW_NUMBER_PROPS[i];
  14499. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14500. if (!styleChanged) {
  14501. flushPathDrawn(ctx, scope);
  14502. styleChanged = true;
  14503. }
  14504. ctx[propName] = ctx.dpr * (style[propName] || 0);
  14505. }
  14506. }
  14507. if (forceSetAll || style.shadowColor !== prevStyle.shadowColor) {
  14508. if (!styleChanged) {
  14509. flushPathDrawn(ctx, scope);
  14510. styleChanged = true;
  14511. }
  14512. ctx.shadowColor = style.shadowColor || DEFAULT_COMMON_STYLE.shadowColor;
  14513. }
  14514. return styleChanged;
  14515. }
  14516. function bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetAll, scope) {
  14517. var style = getStyle(el, scope.inHover);
  14518. var prevStyle = forceSetAll
  14519. ? null
  14520. : (prevEl && getStyle(prevEl, scope.inHover) || {});
  14521. if (style === prevStyle) {
  14522. return false;
  14523. }
  14524. var styleChanged = bindCommonProps(ctx, style, prevStyle, forceSetAll, scope);
  14525. if (forceSetAll || style.fill !== prevStyle.fill) {
  14526. if (!styleChanged) {
  14527. flushPathDrawn(ctx, scope);
  14528. styleChanged = true;
  14529. }
  14530. isValidStrokeFillStyle(style.fill) && (ctx.fillStyle = style.fill);
  14531. }
  14532. if (forceSetAll || style.stroke !== prevStyle.stroke) {
  14533. if (!styleChanged) {
  14534. flushPathDrawn(ctx, scope);
  14535. styleChanged = true;
  14536. }
  14537. isValidStrokeFillStyle(style.stroke) && (ctx.strokeStyle = style.stroke);
  14538. }
  14539. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14540. if (!styleChanged) {
  14541. flushPathDrawn(ctx, scope);
  14542. styleChanged = true;
  14543. }
  14544. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  14545. }
  14546. if (el.hasStroke()) {
  14547. var lineWidth = style.lineWidth;
  14548. var newLineWidth = lineWidth / ((style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1);
  14549. if (ctx.lineWidth !== newLineWidth) {
  14550. if (!styleChanged) {
  14551. flushPathDrawn(ctx, scope);
  14552. styleChanged = true;
  14553. }
  14554. ctx.lineWidth = newLineWidth;
  14555. }
  14556. }
  14557. for (var i = 0; i < STROKE_PROPS.length; i++) {
  14558. var prop = STROKE_PROPS[i];
  14559. var propName = prop[0];
  14560. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14561. if (!styleChanged) {
  14562. flushPathDrawn(ctx, scope);
  14563. styleChanged = true;
  14564. }
  14565. ctx[propName] = style[propName] || prop[1];
  14566. }
  14567. }
  14568. return styleChanged;
  14569. }
  14570. function bindImageStyle(ctx, el, prevEl, forceSetAll, scope) {
  14571. return bindCommonProps(ctx, getStyle(el, scope.inHover), prevEl && getStyle(prevEl, scope.inHover), forceSetAll, scope);
  14572. }
  14573. function setContextTransform(ctx, el) {
  14574. var m = el.transform;
  14575. var dpr = ctx.dpr || 1;
  14576. if (m) {
  14577. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  14578. }
  14579. else {
  14580. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  14581. }
  14582. }
  14583. function updateClipStatus(clipPaths, ctx, scope) {
  14584. var allClipped = false;
  14585. for (var i = 0; i < clipPaths.length; i++) {
  14586. var clipPath = clipPaths[i];
  14587. allClipped = allClipped || clipPath.isZeroArea();
  14588. setContextTransform(ctx, clipPath);
  14589. ctx.beginPath();
  14590. clipPath.buildPath(ctx, clipPath.shape);
  14591. ctx.clip();
  14592. }
  14593. scope.allClipped = allClipped;
  14594. }
  14595. function isTransformChanged(m0, m1) {
  14596. if (m0 && m1) {
  14597. return m0[0] !== m1[0]
  14598. || m0[1] !== m1[1]
  14599. || m0[2] !== m1[2]
  14600. || m0[3] !== m1[3]
  14601. || m0[4] !== m1[4]
  14602. || m0[5] !== m1[5];
  14603. }
  14604. else if (!m0 && !m1) {
  14605. return false;
  14606. }
  14607. return true;
  14608. }
  14609. var DRAW_TYPE_PATH = 1;
  14610. var DRAW_TYPE_IMAGE = 2;
  14611. var DRAW_TYPE_TEXT = 3;
  14612. var DRAW_TYPE_INCREMENTAL = 4;
  14613. function canPathBatch(style) {
  14614. var hasFill = styleHasFill(style);
  14615. var hasStroke = styleHasStroke(style);
  14616. return !(style.lineDash
  14617. || !(+hasFill ^ +hasStroke)
  14618. || (hasFill && typeof style.fill !== 'string')
  14619. || (hasStroke && typeof style.stroke !== 'string')
  14620. || style.strokePercent < 1
  14621. || style.strokeOpacity < 1
  14622. || style.fillOpacity < 1);
  14623. }
  14624. function flushPathDrawn(ctx, scope) {
  14625. scope.batchFill && ctx.fill();
  14626. scope.batchStroke && ctx.stroke();
  14627. scope.batchFill = '';
  14628. scope.batchStroke = '';
  14629. }
  14630. function getStyle(el, inHover) {
  14631. return inHover ? (el.__hoverStyle || el.style) : el.style;
  14632. }
  14633. function brushSingle(ctx, el) {
  14634. brush(ctx, el, { inHover: false, viewWidth: 0, viewHeight: 0 }, true);
  14635. }
  14636. function brush(ctx, el, scope, isLast) {
  14637. var m = el.transform;
  14638. if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false)) {
  14639. el.__dirty &= ~REDRAW_BIT;
  14640. el.__isRendered = false;
  14641. return;
  14642. }
  14643. var clipPaths = el.__clipPaths;
  14644. var prevElClipPaths = scope.prevElClipPaths;
  14645. var forceSetTransform = false;
  14646. var forceSetStyle = false;
  14647. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  14648. if (prevElClipPaths && prevElClipPaths.length) {
  14649. flushPathDrawn(ctx, scope);
  14650. ctx.restore();
  14651. forceSetStyle = forceSetTransform = true;
  14652. scope.prevElClipPaths = null;
  14653. scope.allClipped = false;
  14654. scope.prevEl = null;
  14655. }
  14656. if (clipPaths && clipPaths.length) {
  14657. flushPathDrawn(ctx, scope);
  14658. ctx.save();
  14659. updateClipStatus(clipPaths, ctx, scope);
  14660. forceSetTransform = true;
  14661. }
  14662. scope.prevElClipPaths = clipPaths;
  14663. }
  14664. if (scope.allClipped) {
  14665. el.__isRendered = false;
  14666. return;
  14667. }
  14668. el.beforeBrush && el.beforeBrush();
  14669. el.innerBeforeBrush();
  14670. var prevEl = scope.prevEl;
  14671. if (!prevEl) {
  14672. forceSetStyle = forceSetTransform = true;
  14673. }
  14674. var canBatchPath = el instanceof Path
  14675. && el.autoBatch
  14676. && canPathBatch(el.style);
  14677. if (forceSetTransform || isTransformChanged(m, prevEl.transform)) {
  14678. flushPathDrawn(ctx, scope);
  14679. setContextTransform(ctx, el);
  14680. }
  14681. else if (!canBatchPath) {
  14682. flushPathDrawn(ctx, scope);
  14683. }
  14684. var style = getStyle(el, scope.inHover);
  14685. if (el instanceof Path) {
  14686. if (scope.lastDrawType !== DRAW_TYPE_PATH) {
  14687. forceSetStyle = true;
  14688. scope.lastDrawType = DRAW_TYPE_PATH;
  14689. }
  14690. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14691. if (!canBatchPath || (!scope.batchFill && !scope.batchStroke)) {
  14692. ctx.beginPath();
  14693. }
  14694. brushPath(ctx, el, style, canBatchPath);
  14695. if (canBatchPath) {
  14696. scope.batchFill = style.fill || '';
  14697. scope.batchStroke = style.stroke || '';
  14698. }
  14699. }
  14700. else {
  14701. if (el instanceof TSpan) {
  14702. if (scope.lastDrawType !== DRAW_TYPE_TEXT) {
  14703. forceSetStyle = true;
  14704. scope.lastDrawType = DRAW_TYPE_TEXT;
  14705. }
  14706. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14707. brushText(ctx, el, style);
  14708. }
  14709. else if (el instanceof ZRImage) {
  14710. if (scope.lastDrawType !== DRAW_TYPE_IMAGE) {
  14711. forceSetStyle = true;
  14712. scope.lastDrawType = DRAW_TYPE_IMAGE;
  14713. }
  14714. bindImageStyle(ctx, el, prevEl, forceSetStyle, scope);
  14715. brushImage(ctx, el, style);
  14716. }
  14717. else if (el.getTemporalDisplayables) {
  14718. if (scope.lastDrawType !== DRAW_TYPE_INCREMENTAL) {
  14719. forceSetStyle = true;
  14720. scope.lastDrawType = DRAW_TYPE_INCREMENTAL;
  14721. }
  14722. brushIncremental(ctx, el, scope);
  14723. }
  14724. }
  14725. if (canBatchPath && isLast) {
  14726. flushPathDrawn(ctx, scope);
  14727. }
  14728. el.innerAfterBrush();
  14729. el.afterBrush && el.afterBrush();
  14730. scope.prevEl = el;
  14731. el.__dirty = 0;
  14732. el.__isRendered = true;
  14733. }
  14734. function brushIncremental(ctx, el, scope) {
  14735. var displayables = el.getDisplayables();
  14736. var temporalDisplayables = el.getTemporalDisplayables();
  14737. ctx.save();
  14738. var innerScope = {
  14739. prevElClipPaths: null,
  14740. prevEl: null,
  14741. allClipped: false,
  14742. viewWidth: scope.viewWidth,
  14743. viewHeight: scope.viewHeight,
  14744. inHover: scope.inHover
  14745. };
  14746. var i;
  14747. var len;
  14748. for (i = el.getCursor(), len = displayables.length; i < len; i++) {
  14749. var displayable = displayables[i];
  14750. displayable.beforeBrush && displayable.beforeBrush();
  14751. displayable.innerBeforeBrush();
  14752. brush(ctx, displayable, innerScope, i === len - 1);
  14753. displayable.innerAfterBrush();
  14754. displayable.afterBrush && displayable.afterBrush();
  14755. innerScope.prevEl = displayable;
  14756. }
  14757. for (var i_1 = 0, len_1 = temporalDisplayables.length; i_1 < len_1; i_1++) {
  14758. var displayable = temporalDisplayables[i_1];
  14759. displayable.beforeBrush && displayable.beforeBrush();
  14760. displayable.innerBeforeBrush();
  14761. brush(ctx, displayable, innerScope, i_1 === len_1 - 1);
  14762. displayable.innerAfterBrush();
  14763. displayable.afterBrush && displayable.afterBrush();
  14764. innerScope.prevEl = displayable;
  14765. }
  14766. el.clearTemporalDisplayables();
  14767. el.notClear = true;
  14768. ctx.restore();
  14769. }
  14770. function createDom(id, painter, dpr) {
  14771. var newDom = platformApi.createCanvas();
  14772. var width = painter.getWidth();
  14773. var height = painter.getHeight();
  14774. var newDomStyle = newDom.style;
  14775. if (newDomStyle) {
  14776. newDomStyle.position = 'absolute';
  14777. newDomStyle.left = '0';
  14778. newDomStyle.top = '0';
  14779. newDomStyle.width = width + 'px';
  14780. newDomStyle.height = height + 'px';
  14781. newDom.setAttribute('data-zr-dom-id', id);
  14782. }
  14783. newDom.width = width * dpr;
  14784. newDom.height = height * dpr;
  14785. return newDom;
  14786. }
  14787. var Layer = (function (_super) {
  14788. __extends(Layer, _super);
  14789. function Layer(id, painter, dpr) {
  14790. var _this = _super.call(this) || this;
  14791. _this.motionBlur = false;
  14792. _this.lastFrameAlpha = 0.7;
  14793. _this.dpr = 1;
  14794. _this.virtual = false;
  14795. _this.config = {};
  14796. _this.incremental = false;
  14797. _this.zlevel = 0;
  14798. _this.maxRepaintRectCount = 5;
  14799. _this.__dirty = true;
  14800. _this.__firstTimePaint = true;
  14801. _this.__used = false;
  14802. _this.__drawIndex = 0;
  14803. _this.__startIndex = 0;
  14804. _this.__endIndex = 0;
  14805. _this.__prevStartIndex = null;
  14806. _this.__prevEndIndex = null;
  14807. var dom;
  14808. dpr = dpr || devicePixelRatio;
  14809. if (typeof id === 'string') {
  14810. dom = createDom(id, painter, dpr);
  14811. }
  14812. else if (isObject(id)) {
  14813. dom = id;
  14814. id = dom.id;
  14815. }
  14816. _this.id = id;
  14817. _this.dom = dom;
  14818. var domStyle = dom.style;
  14819. if (domStyle) {
  14820. disableUserSelect(dom);
  14821. dom.onselectstart = function () { return false; };
  14822. domStyle.padding = '0';
  14823. domStyle.margin = '0';
  14824. domStyle.borderWidth = '0';
  14825. }
  14826. _this.painter = painter;
  14827. _this.dpr = dpr;
  14828. return _this;
  14829. }
  14830. Layer.prototype.getElementCount = function () {
  14831. return this.__endIndex - this.__startIndex;
  14832. };
  14833. Layer.prototype.afterBrush = function () {
  14834. this.__prevStartIndex = this.__startIndex;
  14835. this.__prevEndIndex = this.__endIndex;
  14836. };
  14837. Layer.prototype.initContext = function () {
  14838. this.ctx = this.dom.getContext('2d');
  14839. this.ctx.dpr = this.dpr;
  14840. };
  14841. Layer.prototype.setUnpainted = function () {
  14842. this.__firstTimePaint = true;
  14843. };
  14844. Layer.prototype.createBackBuffer = function () {
  14845. var dpr = this.dpr;
  14846. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  14847. this.ctxBack = this.domBack.getContext('2d');
  14848. if (dpr !== 1) {
  14849. this.ctxBack.scale(dpr, dpr);
  14850. }
  14851. };
  14852. Layer.prototype.createRepaintRects = function (displayList, prevList, viewWidth, viewHeight) {
  14853. if (this.__firstTimePaint) {
  14854. this.__firstTimePaint = false;
  14855. return null;
  14856. }
  14857. var mergedRepaintRects = [];
  14858. var maxRepaintRectCount = this.maxRepaintRectCount;
  14859. var full = false;
  14860. var pendingRect = new BoundingRect(0, 0, 0, 0);
  14861. function addRectToMergePool(rect) {
  14862. if (!rect.isFinite() || rect.isZero()) {
  14863. return;
  14864. }
  14865. if (mergedRepaintRects.length === 0) {
  14866. var boundingRect = new BoundingRect(0, 0, 0, 0);
  14867. boundingRect.copy(rect);
  14868. mergedRepaintRects.push(boundingRect);
  14869. }
  14870. else {
  14871. var isMerged = false;
  14872. var minDeltaArea = Infinity;
  14873. var bestRectToMergeIdx = 0;
  14874. for (var i = 0; i < mergedRepaintRects.length; ++i) {
  14875. var mergedRect = mergedRepaintRects[i];
  14876. if (mergedRect.intersect(rect)) {
  14877. var pendingRect_1 = new BoundingRect(0, 0, 0, 0);
  14878. pendingRect_1.copy(mergedRect);
  14879. pendingRect_1.union(rect);
  14880. mergedRepaintRects[i] = pendingRect_1;
  14881. isMerged = true;
  14882. break;
  14883. }
  14884. else if (full) {
  14885. pendingRect.copy(rect);
  14886. pendingRect.union(mergedRect);
  14887. var aArea = rect.width * rect.height;
  14888. var bArea = mergedRect.width * mergedRect.height;
  14889. var pendingArea = pendingRect.width * pendingRect.height;
  14890. var deltaArea = pendingArea - aArea - bArea;
  14891. if (deltaArea < minDeltaArea) {
  14892. minDeltaArea = deltaArea;
  14893. bestRectToMergeIdx = i;
  14894. }
  14895. }
  14896. }
  14897. if (full) {
  14898. mergedRepaintRects[bestRectToMergeIdx].union(rect);
  14899. isMerged = true;
  14900. }
  14901. if (!isMerged) {
  14902. var boundingRect = new BoundingRect(0, 0, 0, 0);
  14903. boundingRect.copy(rect);
  14904. mergedRepaintRects.push(boundingRect);
  14905. }
  14906. if (!full) {
  14907. full = mergedRepaintRects.length >= maxRepaintRectCount;
  14908. }
  14909. }
  14910. }
  14911. for (var i = this.__startIndex; i < this.__endIndex; ++i) {
  14912. var el = displayList[i];
  14913. if (el) {
  14914. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  14915. var prevRect = el.__isRendered && ((el.__dirty & REDRAW_BIT) || !shouldPaint)
  14916. ? el.getPrevPaintRect()
  14917. : null;
  14918. if (prevRect) {
  14919. addRectToMergePool(prevRect);
  14920. }
  14921. var curRect = shouldPaint && ((el.__dirty & REDRAW_BIT) || !el.__isRendered)
  14922. ? el.getPaintRect()
  14923. : null;
  14924. if (curRect) {
  14925. addRectToMergePool(curRect);
  14926. }
  14927. }
  14928. }
  14929. for (var i = this.__prevStartIndex; i < this.__prevEndIndex; ++i) {
  14930. var el = prevList[i];
  14931. var shouldPaint = el && el.shouldBePainted(viewWidth, viewHeight, true, true);
  14932. if (el && (!shouldPaint || !el.__zr) && el.__isRendered) {
  14933. var prevRect = el.getPrevPaintRect();
  14934. if (prevRect) {
  14935. addRectToMergePool(prevRect);
  14936. }
  14937. }
  14938. }
  14939. var hasIntersections;
  14940. do {
  14941. hasIntersections = false;
  14942. for (var i = 0; i < mergedRepaintRects.length;) {
  14943. if (mergedRepaintRects[i].isZero()) {
  14944. mergedRepaintRects.splice(i, 1);
  14945. continue;
  14946. }
  14947. for (var j = i + 1; j < mergedRepaintRects.length;) {
  14948. if (mergedRepaintRects[i].intersect(mergedRepaintRects[j])) {
  14949. hasIntersections = true;
  14950. mergedRepaintRects[i].union(mergedRepaintRects[j]);
  14951. mergedRepaintRects.splice(j, 1);
  14952. }
  14953. else {
  14954. j++;
  14955. }
  14956. }
  14957. i++;
  14958. }
  14959. } while (hasIntersections);
  14960. this._paintRects = mergedRepaintRects;
  14961. return mergedRepaintRects;
  14962. };
  14963. Layer.prototype.debugGetPaintRects = function () {
  14964. return (this._paintRects || []).slice();
  14965. };
  14966. Layer.prototype.resize = function (width, height) {
  14967. var dpr = this.dpr;
  14968. var dom = this.dom;
  14969. var domStyle = dom.style;
  14970. var domBack = this.domBack;
  14971. if (domStyle) {
  14972. domStyle.width = width + 'px';
  14973. domStyle.height = height + 'px';
  14974. }
  14975. dom.width = width * dpr;
  14976. dom.height = height * dpr;
  14977. if (domBack) {
  14978. domBack.width = width * dpr;
  14979. domBack.height = height * dpr;
  14980. if (dpr !== 1) {
  14981. this.ctxBack.scale(dpr, dpr);
  14982. }
  14983. }
  14984. };
  14985. Layer.prototype.clear = function (clearAll, clearColor, repaintRects) {
  14986. var dom = this.dom;
  14987. var ctx = this.ctx;
  14988. var width = dom.width;
  14989. var height = dom.height;
  14990. clearColor = clearColor || this.clearColor;
  14991. var haveMotionBLur = this.motionBlur && !clearAll;
  14992. var lastFrameAlpha = this.lastFrameAlpha;
  14993. var dpr = this.dpr;
  14994. var self = this;
  14995. if (haveMotionBLur) {
  14996. if (!this.domBack) {
  14997. this.createBackBuffer();
  14998. }
  14999. this.ctxBack.globalCompositeOperation = 'copy';
  15000. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  15001. }
  15002. var domBack = this.domBack;
  15003. function doClear(x, y, width, height) {
  15004. ctx.clearRect(x, y, width, height);
  15005. if (clearColor && clearColor !== 'transparent') {
  15006. var clearColorGradientOrPattern = void 0;
  15007. if (isGradientObject(clearColor)) {
  15008. var shouldCache = clearColor.global || (clearColor.__width === width
  15009. && clearColor.__height === height);
  15010. clearColorGradientOrPattern = shouldCache
  15011. && clearColor.__canvasGradient
  15012. || getCanvasGradient(ctx, clearColor, {
  15013. x: 0,
  15014. y: 0,
  15015. width: width,
  15016. height: height
  15017. });
  15018. clearColor.__canvasGradient = clearColorGradientOrPattern;
  15019. clearColor.__width = width;
  15020. clearColor.__height = height;
  15021. }
  15022. else if (isImagePatternObject(clearColor)) {
  15023. clearColor.scaleX = clearColor.scaleX || dpr;
  15024. clearColor.scaleY = clearColor.scaleY || dpr;
  15025. clearColorGradientOrPattern = createCanvasPattern(ctx, clearColor, {
  15026. dirty: function () {
  15027. self.setUnpainted();
  15028. self.painter.refresh();
  15029. }
  15030. });
  15031. }
  15032. ctx.save();
  15033. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  15034. ctx.fillRect(x, y, width, height);
  15035. ctx.restore();
  15036. }
  15037. if (haveMotionBLur) {
  15038. ctx.save();
  15039. ctx.globalAlpha = lastFrameAlpha;
  15040. ctx.drawImage(domBack, x, y, width, height);
  15041. ctx.restore();
  15042. }
  15043. }
  15044. if (!repaintRects || haveMotionBLur) {
  15045. doClear(0, 0, width, height);
  15046. }
  15047. else if (repaintRects.length) {
  15048. each(repaintRects, function (rect) {
  15049. doClear(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  15050. });
  15051. }
  15052. };
  15053. return Layer;
  15054. }(Eventful));
  15055. var HOVER_LAYER_ZLEVEL = 1e5;
  15056. var CANVAS_ZLEVEL = 314159;
  15057. var EL_AFTER_INCREMENTAL_INC = 0.01;
  15058. var INCREMENTAL_INC = 0.001;
  15059. function isLayerValid(layer) {
  15060. if (!layer) {
  15061. return false;
  15062. }
  15063. if (layer.__builtin__) {
  15064. return true;
  15065. }
  15066. if (typeof (layer.resize) !== 'function'
  15067. || typeof (layer.refresh) !== 'function') {
  15068. return false;
  15069. }
  15070. return true;
  15071. }
  15072. function createRoot(width, height) {
  15073. var domRoot = document.createElement('div');
  15074. domRoot.style.cssText = [
  15075. 'position:relative',
  15076. 'width:' + width + 'px',
  15077. 'height:' + height + 'px',
  15078. 'padding:0',
  15079. 'margin:0',
  15080. 'border-width:0'
  15081. ].join(';') + ';';
  15082. return domRoot;
  15083. }
  15084. var CanvasPainter = (function () {
  15085. function CanvasPainter(root, storage, opts, id) {
  15086. this.type = 'canvas';
  15087. this._zlevelList = [];
  15088. this._prevDisplayList = [];
  15089. this._layers = {};
  15090. this._layerConfig = {};
  15091. this._needsManuallyCompositing = false;
  15092. this.type = 'canvas';
  15093. var singleCanvas = !root.nodeName
  15094. || root.nodeName.toUpperCase() === 'CANVAS';
  15095. this._opts = opts = extend({}, opts || {});
  15096. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  15097. this._singleCanvas = singleCanvas;
  15098. this.root = root;
  15099. var rootStyle = root.style;
  15100. if (rootStyle) {
  15101. disableUserSelect(root);
  15102. root.innerHTML = '';
  15103. }
  15104. this.storage = storage;
  15105. var zlevelList = this._zlevelList;
  15106. this._prevDisplayList = [];
  15107. var layers = this._layers;
  15108. if (!singleCanvas) {
  15109. this._width = getSize(root, 0, opts);
  15110. this._height = getSize(root, 1, opts);
  15111. var domRoot = this._domRoot = createRoot(this._width, this._height);
  15112. root.appendChild(domRoot);
  15113. }
  15114. else {
  15115. var rootCanvas = root;
  15116. var width = rootCanvas.width;
  15117. var height = rootCanvas.height;
  15118. if (opts.width != null) {
  15119. width = opts.width;
  15120. }
  15121. if (opts.height != null) {
  15122. height = opts.height;
  15123. }
  15124. this.dpr = opts.devicePixelRatio || 1;
  15125. rootCanvas.width = width * this.dpr;
  15126. rootCanvas.height = height * this.dpr;
  15127. this._width = width;
  15128. this._height = height;
  15129. var mainLayer = new Layer(rootCanvas, this, this.dpr);
  15130. mainLayer.__builtin__ = true;
  15131. mainLayer.initContext();
  15132. layers[CANVAS_ZLEVEL] = mainLayer;
  15133. mainLayer.zlevel = CANVAS_ZLEVEL;
  15134. zlevelList.push(CANVAS_ZLEVEL);
  15135. this._domRoot = root;
  15136. }
  15137. }
  15138. CanvasPainter.prototype.getType = function () {
  15139. return 'canvas';
  15140. };
  15141. CanvasPainter.prototype.isSingleCanvas = function () {
  15142. return this._singleCanvas;
  15143. };
  15144. CanvasPainter.prototype.getViewportRoot = function () {
  15145. return this._domRoot;
  15146. };
  15147. CanvasPainter.prototype.getViewportRootOffset = function () {
  15148. var viewportRoot = this.getViewportRoot();
  15149. if (viewportRoot) {
  15150. return {
  15151. offsetLeft: viewportRoot.offsetLeft || 0,
  15152. offsetTop: viewportRoot.offsetTop || 0
  15153. };
  15154. }
  15155. };
  15156. CanvasPainter.prototype.refresh = function (paintAll) {
  15157. var list = this.storage.getDisplayList(true);
  15158. var prevList = this._prevDisplayList;
  15159. var zlevelList = this._zlevelList;
  15160. this._redrawId = Math.random();
  15161. this._paintList(list, prevList, paintAll, this._redrawId);
  15162. for (var i = 0; i < zlevelList.length; i++) {
  15163. var z = zlevelList[i];
  15164. var layer = this._layers[z];
  15165. if (!layer.__builtin__ && layer.refresh) {
  15166. var clearColor = i === 0 ? this._backgroundColor : null;
  15167. layer.refresh(clearColor);
  15168. }
  15169. }
  15170. if (this._opts.useDirtyRect) {
  15171. this._prevDisplayList = list.slice();
  15172. }
  15173. return this;
  15174. };
  15175. CanvasPainter.prototype.refreshHover = function () {
  15176. this._paintHoverList(this.storage.getDisplayList(false));
  15177. };
  15178. CanvasPainter.prototype._paintHoverList = function (list) {
  15179. var len = list.length;
  15180. var hoverLayer = this._hoverlayer;
  15181. hoverLayer && hoverLayer.clear();
  15182. if (!len) {
  15183. return;
  15184. }
  15185. var scope = {
  15186. inHover: true,
  15187. viewWidth: this._width,
  15188. viewHeight: this._height
  15189. };
  15190. var ctx;
  15191. for (var i = 0; i < len; i++) {
  15192. var el = list[i];
  15193. if (el.__inHover) {
  15194. if (!hoverLayer) {
  15195. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  15196. }
  15197. if (!ctx) {
  15198. ctx = hoverLayer.ctx;
  15199. ctx.save();
  15200. }
  15201. brush(ctx, el, scope, i === len - 1);
  15202. }
  15203. }
  15204. if (ctx) {
  15205. ctx.restore();
  15206. }
  15207. };
  15208. CanvasPainter.prototype.getHoverLayer = function () {
  15209. return this.getLayer(HOVER_LAYER_ZLEVEL);
  15210. };
  15211. CanvasPainter.prototype.paintOne = function (ctx, el) {
  15212. brushSingle(ctx, el);
  15213. };
  15214. CanvasPainter.prototype._paintList = function (list, prevList, paintAll, redrawId) {
  15215. if (this._redrawId !== redrawId) {
  15216. return;
  15217. }
  15218. paintAll = paintAll || false;
  15219. this._updateLayerStatus(list);
  15220. var _a = this._doPaintList(list, prevList, paintAll), finished = _a.finished, needsRefreshHover = _a.needsRefreshHover;
  15221. if (this._needsManuallyCompositing) {
  15222. this._compositeManually();
  15223. }
  15224. if (needsRefreshHover) {
  15225. this._paintHoverList(list);
  15226. }
  15227. if (!finished) {
  15228. var self_1 = this;
  15229. requestAnimationFrame$1(function () {
  15230. self_1._paintList(list, prevList, paintAll, redrawId);
  15231. });
  15232. }
  15233. else {
  15234. this.eachLayer(function (layer) {
  15235. layer.afterBrush && layer.afterBrush();
  15236. });
  15237. }
  15238. };
  15239. CanvasPainter.prototype._compositeManually = function () {
  15240. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  15241. var width = this._domRoot.width;
  15242. var height = this._domRoot.height;
  15243. ctx.clearRect(0, 0, width, height);
  15244. this.eachBuiltinLayer(function (layer) {
  15245. if (layer.virtual) {
  15246. ctx.drawImage(layer.dom, 0, 0, width, height);
  15247. }
  15248. });
  15249. };
  15250. CanvasPainter.prototype._doPaintList = function (list, prevList, paintAll) {
  15251. var _this = this;
  15252. var layerList = [];
  15253. var useDirtyRect = this._opts.useDirtyRect;
  15254. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  15255. var zlevel = this._zlevelList[zi];
  15256. var layer = this._layers[zlevel];
  15257. if (layer.__builtin__
  15258. && layer !== this._hoverlayer
  15259. && (layer.__dirty || paintAll)) {
  15260. layerList.push(layer);
  15261. }
  15262. }
  15263. var finished = true;
  15264. var needsRefreshHover = false;
  15265. var _loop_1 = function (k) {
  15266. var layer = layerList[k];
  15267. var ctx = layer.ctx;
  15268. var repaintRects = useDirtyRect
  15269. && layer.createRepaintRects(list, prevList, this_1._width, this_1._height);
  15270. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  15271. var useTimer = !paintAll && layer.incremental && Date.now;
  15272. var startTime = useTimer && Date.now();
  15273. var clearColor = layer.zlevel === this_1._zlevelList[0]
  15274. ? this_1._backgroundColor : null;
  15275. if (layer.__startIndex === layer.__endIndex) {
  15276. layer.clear(false, clearColor, repaintRects);
  15277. }
  15278. else if (start === layer.__startIndex) {
  15279. var firstEl = list[start];
  15280. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  15281. layer.clear(false, clearColor, repaintRects);
  15282. }
  15283. }
  15284. if (start === -1) {
  15285. console.error('For some unknown reason. drawIndex is -1');
  15286. start = layer.__startIndex;
  15287. }
  15288. var i;
  15289. var repaint = function (repaintRect) {
  15290. var scope = {
  15291. inHover: false,
  15292. allClipped: false,
  15293. prevEl: null,
  15294. viewWidth: _this._width,
  15295. viewHeight: _this._height
  15296. };
  15297. for (i = start; i < layer.__endIndex; i++) {
  15298. var el = list[i];
  15299. if (el.__inHover) {
  15300. needsRefreshHover = true;
  15301. }
  15302. _this._doPaintEl(el, layer, useDirtyRect, repaintRect, scope, i === layer.__endIndex - 1);
  15303. if (useTimer) {
  15304. var dTime = Date.now() - startTime;
  15305. if (dTime > 15) {
  15306. break;
  15307. }
  15308. }
  15309. }
  15310. if (scope.prevElClipPaths) {
  15311. ctx.restore();
  15312. }
  15313. };
  15314. if (repaintRects) {
  15315. if (repaintRects.length === 0) {
  15316. i = layer.__endIndex;
  15317. }
  15318. else {
  15319. var dpr = this_1.dpr;
  15320. for (var r = 0; r < repaintRects.length; ++r) {
  15321. var rect = repaintRects[r];
  15322. ctx.save();
  15323. ctx.beginPath();
  15324. ctx.rect(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  15325. ctx.clip();
  15326. repaint(rect);
  15327. ctx.restore();
  15328. }
  15329. }
  15330. }
  15331. else {
  15332. ctx.save();
  15333. repaint();
  15334. ctx.restore();
  15335. }
  15336. layer.__drawIndex = i;
  15337. if (layer.__drawIndex < layer.__endIndex) {
  15338. finished = false;
  15339. }
  15340. };
  15341. var this_1 = this;
  15342. for (var k = 0; k < layerList.length; k++) {
  15343. _loop_1(k);
  15344. }
  15345. if (env.wxa) {
  15346. each(this._layers, function (layer) {
  15347. if (layer && layer.ctx && layer.ctx.draw) {
  15348. layer.ctx.draw();
  15349. }
  15350. });
  15351. }
  15352. return {
  15353. finished: finished,
  15354. needsRefreshHover: needsRefreshHover
  15355. };
  15356. };
  15357. CanvasPainter.prototype._doPaintEl = function (el, currentLayer, useDirtyRect, repaintRect, scope, isLast) {
  15358. var ctx = currentLayer.ctx;
  15359. if (useDirtyRect) {
  15360. var paintRect = el.getPaintRect();
  15361. if (!repaintRect || paintRect && paintRect.intersect(repaintRect)) {
  15362. brush(ctx, el, scope, isLast);
  15363. el.setPrevPaintRect(paintRect);
  15364. }
  15365. }
  15366. else {
  15367. brush(ctx, el, scope, isLast);
  15368. }
  15369. };
  15370. CanvasPainter.prototype.getLayer = function (zlevel, virtual) {
  15371. if (this._singleCanvas && !this._needsManuallyCompositing) {
  15372. zlevel = CANVAS_ZLEVEL;
  15373. }
  15374. var layer = this._layers[zlevel];
  15375. if (!layer) {
  15376. layer = new Layer('zr_' + zlevel, this, this.dpr);
  15377. layer.zlevel = zlevel;
  15378. layer.__builtin__ = true;
  15379. if (this._layerConfig[zlevel]) {
  15380. merge(layer, this._layerConfig[zlevel], true);
  15381. }
  15382. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  15383. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  15384. }
  15385. if (virtual) {
  15386. layer.virtual = virtual;
  15387. }
  15388. this.insertLayer(zlevel, layer);
  15389. layer.initContext();
  15390. }
  15391. return layer;
  15392. };
  15393. CanvasPainter.prototype.insertLayer = function (zlevel, layer) {
  15394. var layersMap = this._layers;
  15395. var zlevelList = this._zlevelList;
  15396. var len = zlevelList.length;
  15397. var domRoot = this._domRoot;
  15398. var prevLayer = null;
  15399. var i = -1;
  15400. if (layersMap[zlevel]) {
  15401. {
  15402. logError('ZLevel ' + zlevel + ' has been used already');
  15403. }
  15404. return;
  15405. }
  15406. if (!isLayerValid(layer)) {
  15407. {
  15408. logError('Layer of zlevel ' + zlevel + ' is not valid');
  15409. }
  15410. return;
  15411. }
  15412. if (len > 0 && zlevel > zlevelList[0]) {
  15413. for (i = 0; i < len - 1; i++) {
  15414. if (zlevelList[i] < zlevel
  15415. && zlevelList[i + 1] > zlevel) {
  15416. break;
  15417. }
  15418. }
  15419. prevLayer = layersMap[zlevelList[i]];
  15420. }
  15421. zlevelList.splice(i + 1, 0, zlevel);
  15422. layersMap[zlevel] = layer;
  15423. if (!layer.virtual) {
  15424. if (prevLayer) {
  15425. var prevDom = prevLayer.dom;
  15426. if (prevDom.nextSibling) {
  15427. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  15428. }
  15429. else {
  15430. domRoot.appendChild(layer.dom);
  15431. }
  15432. }
  15433. else {
  15434. if (domRoot.firstChild) {
  15435. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  15436. }
  15437. else {
  15438. domRoot.appendChild(layer.dom);
  15439. }
  15440. }
  15441. }
  15442. layer.painter || (layer.painter = this);
  15443. };
  15444. CanvasPainter.prototype.eachLayer = function (cb, context) {
  15445. var zlevelList = this._zlevelList;
  15446. for (var i = 0; i < zlevelList.length; i++) {
  15447. var z = zlevelList[i];
  15448. cb.call(context, this._layers[z], z);
  15449. }
  15450. };
  15451. CanvasPainter.prototype.eachBuiltinLayer = function (cb, context) {
  15452. var zlevelList = this._zlevelList;
  15453. for (var i = 0; i < zlevelList.length; i++) {
  15454. var z = zlevelList[i];
  15455. var layer = this._layers[z];
  15456. if (layer.__builtin__) {
  15457. cb.call(context, layer, z);
  15458. }
  15459. }
  15460. };
  15461. CanvasPainter.prototype.eachOtherLayer = function (cb, context) {
  15462. var zlevelList = this._zlevelList;
  15463. for (var i = 0; i < zlevelList.length; i++) {
  15464. var z = zlevelList[i];
  15465. var layer = this._layers[z];
  15466. if (!layer.__builtin__) {
  15467. cb.call(context, layer, z);
  15468. }
  15469. }
  15470. };
  15471. CanvasPainter.prototype.getLayers = function () {
  15472. return this._layers;
  15473. };
  15474. CanvasPainter.prototype._updateLayerStatus = function (list) {
  15475. this.eachBuiltinLayer(function (layer, z) {
  15476. layer.__dirty = layer.__used = false;
  15477. });
  15478. function updatePrevLayer(idx) {
  15479. if (prevLayer) {
  15480. if (prevLayer.__endIndex !== idx) {
  15481. prevLayer.__dirty = true;
  15482. }
  15483. prevLayer.__endIndex = idx;
  15484. }
  15485. }
  15486. if (this._singleCanvas) {
  15487. for (var i_1 = 1; i_1 < list.length; i_1++) {
  15488. var el = list[i_1];
  15489. if (el.zlevel !== list[i_1 - 1].zlevel || el.incremental) {
  15490. this._needsManuallyCompositing = true;
  15491. break;
  15492. }
  15493. }
  15494. }
  15495. var prevLayer = null;
  15496. var incrementalLayerCount = 0;
  15497. var prevZlevel;
  15498. var i;
  15499. for (i = 0; i < list.length; i++) {
  15500. var el = list[i];
  15501. var zlevel = el.zlevel;
  15502. var layer = void 0;
  15503. if (prevZlevel !== zlevel) {
  15504. prevZlevel = zlevel;
  15505. incrementalLayerCount = 0;
  15506. }
  15507. if (el.incremental) {
  15508. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  15509. layer.incremental = true;
  15510. incrementalLayerCount = 1;
  15511. }
  15512. else {
  15513. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  15514. }
  15515. if (!layer.__builtin__) {
  15516. logError('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  15517. }
  15518. if (layer !== prevLayer) {
  15519. layer.__used = true;
  15520. if (layer.__startIndex !== i) {
  15521. layer.__dirty = true;
  15522. }
  15523. layer.__startIndex = i;
  15524. if (!layer.incremental) {
  15525. layer.__drawIndex = i;
  15526. }
  15527. else {
  15528. layer.__drawIndex = -1;
  15529. }
  15530. updatePrevLayer(i);
  15531. prevLayer = layer;
  15532. }
  15533. if ((el.__dirty & REDRAW_BIT) && !el.__inHover) {
  15534. layer.__dirty = true;
  15535. if (layer.incremental && layer.__drawIndex < 0) {
  15536. layer.__drawIndex = i;
  15537. }
  15538. }
  15539. }
  15540. updatePrevLayer(i);
  15541. this.eachBuiltinLayer(function (layer, z) {
  15542. if (!layer.__used && layer.getElementCount() > 0) {
  15543. layer.__dirty = true;
  15544. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  15545. }
  15546. if (layer.__dirty && layer.__drawIndex < 0) {
  15547. layer.__drawIndex = layer.__startIndex;
  15548. }
  15549. });
  15550. };
  15551. CanvasPainter.prototype.clear = function () {
  15552. this.eachBuiltinLayer(this._clearLayer);
  15553. return this;
  15554. };
  15555. CanvasPainter.prototype._clearLayer = function (layer) {
  15556. layer.clear();
  15557. };
  15558. CanvasPainter.prototype.setBackgroundColor = function (backgroundColor) {
  15559. this._backgroundColor = backgroundColor;
  15560. each(this._layers, function (layer) {
  15561. layer.setUnpainted();
  15562. });
  15563. };
  15564. CanvasPainter.prototype.configLayer = function (zlevel, config) {
  15565. if (config) {
  15566. var layerConfig = this._layerConfig;
  15567. if (!layerConfig[zlevel]) {
  15568. layerConfig[zlevel] = config;
  15569. }
  15570. else {
  15571. merge(layerConfig[zlevel], config, true);
  15572. }
  15573. for (var i = 0; i < this._zlevelList.length; i++) {
  15574. var _zlevel = this._zlevelList[i];
  15575. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  15576. var layer = this._layers[_zlevel];
  15577. merge(layer, layerConfig[zlevel], true);
  15578. }
  15579. }
  15580. }
  15581. };
  15582. CanvasPainter.prototype.delLayer = function (zlevel) {
  15583. var layers = this._layers;
  15584. var zlevelList = this._zlevelList;
  15585. var layer = layers[zlevel];
  15586. if (!layer) {
  15587. return;
  15588. }
  15589. layer.dom.parentNode.removeChild(layer.dom);
  15590. delete layers[zlevel];
  15591. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  15592. };
  15593. CanvasPainter.prototype.resize = function (width, height) {
  15594. if (!this._domRoot.style) {
  15595. if (width == null || height == null) {
  15596. return;
  15597. }
  15598. this._width = width;
  15599. this._height = height;
  15600. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  15601. }
  15602. else {
  15603. var domRoot = this._domRoot;
  15604. domRoot.style.display = 'none';
  15605. var opts = this._opts;
  15606. var root = this.root;
  15607. width != null && (opts.width = width);
  15608. height != null && (opts.height = height);
  15609. width = getSize(root, 0, opts);
  15610. height = getSize(root, 1, opts);
  15611. domRoot.style.display = '';
  15612. if (this._width !== width || height !== this._height) {
  15613. domRoot.style.width = width + 'px';
  15614. domRoot.style.height = height + 'px';
  15615. for (var id in this._layers) {
  15616. if (this._layers.hasOwnProperty(id)) {
  15617. this._layers[id].resize(width, height);
  15618. }
  15619. }
  15620. this.refresh(true);
  15621. }
  15622. this._width = width;
  15623. this._height = height;
  15624. }
  15625. return this;
  15626. };
  15627. CanvasPainter.prototype.clearLayer = function (zlevel) {
  15628. var layer = this._layers[zlevel];
  15629. if (layer) {
  15630. layer.clear();
  15631. }
  15632. };
  15633. CanvasPainter.prototype.dispose = function () {
  15634. this.root.innerHTML = '';
  15635. this.root =
  15636. this.storage =
  15637. this._domRoot =
  15638. this._layers = null;
  15639. };
  15640. CanvasPainter.prototype.getRenderedCanvas = function (opts) {
  15641. opts = opts || {};
  15642. if (this._singleCanvas && !this._compositeManually) {
  15643. return this._layers[CANVAS_ZLEVEL].dom;
  15644. }
  15645. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  15646. imageLayer.initContext();
  15647. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  15648. var ctx = imageLayer.ctx;
  15649. if (opts.pixelRatio <= this.dpr) {
  15650. this.refresh();
  15651. var width_1 = imageLayer.dom.width;
  15652. var height_1 = imageLayer.dom.height;
  15653. this.eachLayer(function (layer) {
  15654. if (layer.__builtin__) {
  15655. ctx.drawImage(layer.dom, 0, 0, width_1, height_1);
  15656. }
  15657. else if (layer.renderToCanvas) {
  15658. ctx.save();
  15659. layer.renderToCanvas(ctx);
  15660. ctx.restore();
  15661. }
  15662. });
  15663. }
  15664. else {
  15665. var scope = {
  15666. inHover: false,
  15667. viewWidth: this._width,
  15668. viewHeight: this._height
  15669. };
  15670. var displayList = this.storage.getDisplayList(true);
  15671. for (var i = 0, len = displayList.length; i < len; i++) {
  15672. var el = displayList[i];
  15673. brush(ctx, el, scope, i === len - 1);
  15674. }
  15675. }
  15676. return imageLayer.dom;
  15677. };
  15678. CanvasPainter.prototype.getWidth = function () {
  15679. return this._width;
  15680. };
  15681. CanvasPainter.prototype.getHeight = function () {
  15682. return this._height;
  15683. };
  15684. return CanvasPainter;
  15685. }());
  15686. var mathSin$4 = Math.sin;
  15687. var mathCos$4 = Math.cos;
  15688. var PI$5 = Math.PI;
  15689. var PI2$6 = Math.PI * 2;
  15690. var degree = 180 / PI$5;
  15691. var SVGPathRebuilder = (function () {
  15692. function SVGPathRebuilder() {
  15693. }
  15694. SVGPathRebuilder.prototype.reset = function (precision) {
  15695. this._start = true;
  15696. this._d = [];
  15697. this._str = '';
  15698. this._p = Math.pow(10, precision || 4);
  15699. };
  15700. SVGPathRebuilder.prototype.moveTo = function (x, y) {
  15701. this._add('M', x, y);
  15702. };
  15703. SVGPathRebuilder.prototype.lineTo = function (x, y) {
  15704. this._add('L', x, y);
  15705. };
  15706. SVGPathRebuilder.prototype.bezierCurveTo = function (x, y, x2, y2, x3, y3) {
  15707. this._add('C', x, y, x2, y2, x3, y3);
  15708. };
  15709. SVGPathRebuilder.prototype.quadraticCurveTo = function (x, y, x2, y2) {
  15710. this._add('Q', x, y, x2, y2);
  15711. };
  15712. SVGPathRebuilder.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  15713. this.ellipse(cx, cy, r, r, 0, startAngle, endAngle, anticlockwise);
  15714. };
  15715. SVGPathRebuilder.prototype.ellipse = function (cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise) {
  15716. var dTheta = endAngle - startAngle;
  15717. var clockwise = !anticlockwise;
  15718. var dThetaPositive = Math.abs(dTheta);
  15719. var isCircle = isAroundZero$1(dThetaPositive - PI2$6)
  15720. || (clockwise ? dTheta >= PI2$6 : -dTheta >= PI2$6);
  15721. var unifiedTheta = dTheta > 0 ? dTheta % PI2$6 : (dTheta % PI2$6 + PI2$6);
  15722. var large = false;
  15723. if (isCircle) {
  15724. large = true;
  15725. }
  15726. else if (isAroundZero$1(dThetaPositive)) {
  15727. large = false;
  15728. }
  15729. else {
  15730. large = (unifiedTheta >= PI$5) === !!clockwise;
  15731. }
  15732. var x0 = cx + rx * mathCos$4(startAngle);
  15733. var y0 = cy + ry * mathSin$4(startAngle);
  15734. if (this._start) {
  15735. this._add('M', x0, y0);
  15736. }
  15737. var xRot = Math.round(psi * degree);
  15738. if (isCircle) {
  15739. var p = 1 / this._p;
  15740. var dTheta_1 = (clockwise ? 1 : -1) * (PI2$6 - p);
  15741. this._add('A', rx, ry, xRot, 1, +clockwise, cx + rx * mathCos$4(startAngle + dTheta_1), cy + ry * mathSin$4(startAngle + dTheta_1));
  15742. if (p > 1e-2) {
  15743. this._add('A', rx, ry, xRot, 0, +clockwise, x0, y0);
  15744. }
  15745. }
  15746. else {
  15747. var x = cx + rx * mathCos$4(endAngle);
  15748. var y = cy + ry * mathSin$4(endAngle);
  15749. this._add('A', rx, ry, xRot, +large, +clockwise, x, y);
  15750. }
  15751. };
  15752. SVGPathRebuilder.prototype.rect = function (x, y, w, h) {
  15753. this._add('M', x, y);
  15754. this._add('l', w, 0);
  15755. this._add('l', 0, h);
  15756. this._add('l', -w, 0);
  15757. this._add('Z');
  15758. };
  15759. SVGPathRebuilder.prototype.closePath = function () {
  15760. if (this._d.length > 0) {
  15761. this._add('Z');
  15762. }
  15763. };
  15764. SVGPathRebuilder.prototype._add = function (cmd, a, b, c, d, e, f, g, h) {
  15765. var vals = [];
  15766. var p = this._p;
  15767. for (var i = 1; i < arguments.length; i++) {
  15768. var val = arguments[i];
  15769. if (isNaN(val)) {
  15770. this._invalid = true;
  15771. return;
  15772. }
  15773. vals.push(Math.round(val * p) / p);
  15774. }
  15775. this._d.push(cmd + vals.join(' '));
  15776. this._start = cmd === 'Z';
  15777. };
  15778. SVGPathRebuilder.prototype.generateStr = function () {
  15779. this._str = this._invalid ? '' : this._d.join('');
  15780. this._d = [];
  15781. };
  15782. SVGPathRebuilder.prototype.getStr = function () {
  15783. return this._str;
  15784. };
  15785. return SVGPathRebuilder;
  15786. }());
  15787. var NONE = 'none';
  15788. var mathRound$1 = Math.round;
  15789. function pathHasFill(style) {
  15790. var fill = style.fill;
  15791. return fill != null && fill !== NONE;
  15792. }
  15793. function pathHasStroke(style) {
  15794. var stroke = style.stroke;
  15795. return stroke != null && stroke !== NONE;
  15796. }
  15797. var strokeProps = ['lineCap', 'miterLimit', 'lineJoin'];
  15798. var svgStrokeProps = map(strokeProps, function (prop) { return "stroke-" + prop.toLowerCase(); });
  15799. function mapStyleToAttrs(updateAttr, style, el, forceUpdate) {
  15800. var opacity = style.opacity == null ? 1 : style.opacity;
  15801. if (el instanceof ZRImage) {
  15802. updateAttr('opacity', opacity);
  15803. return;
  15804. }
  15805. if (pathHasFill(style)) {
  15806. var fill = normalizeColor(style.fill);
  15807. updateAttr('fill', fill.color);
  15808. var fillOpacity = style.fillOpacity != null
  15809. ? style.fillOpacity * fill.opacity * opacity
  15810. : fill.opacity * opacity;
  15811. if (forceUpdate || fillOpacity < 1) {
  15812. updateAttr('fill-opacity', fillOpacity);
  15813. }
  15814. }
  15815. else {
  15816. updateAttr('fill', NONE);
  15817. }
  15818. if (pathHasStroke(style)) {
  15819. var stroke = normalizeColor(style.stroke);
  15820. updateAttr('stroke', stroke.color);
  15821. var strokeScale = style.strokeNoScale
  15822. ? el.getLineScale()
  15823. : 1;
  15824. var strokeWidth = (strokeScale ? (style.lineWidth || 0) / strokeScale : 0);
  15825. var strokeOpacity = style.strokeOpacity != null
  15826. ? style.strokeOpacity * stroke.opacity * opacity
  15827. : stroke.opacity * opacity;
  15828. var strokeFirst = style.strokeFirst;
  15829. if (forceUpdate || strokeWidth !== 1) {
  15830. updateAttr('stroke-width', strokeWidth);
  15831. }
  15832. if (forceUpdate || strokeFirst) {
  15833. updateAttr('paint-order', strokeFirst ? 'stroke' : 'fill');
  15834. }
  15835. if (forceUpdate || strokeOpacity < 1) {
  15836. updateAttr('stroke-opacity', strokeOpacity);
  15837. }
  15838. if (style.lineDash) {
  15839. var _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  15840. if (lineDash) {
  15841. lineDashOffset = mathRound$1(lineDashOffset || 0);
  15842. updateAttr('stroke-dasharray', lineDash.join(','));
  15843. if (lineDashOffset || forceUpdate) {
  15844. updateAttr('stroke-dashoffset', lineDashOffset);
  15845. }
  15846. }
  15847. }
  15848. else if (forceUpdate) {
  15849. updateAttr('stroke-dasharray', NONE);
  15850. }
  15851. for (var i = 0; i < strokeProps.length; i++) {
  15852. var propName = strokeProps[i];
  15853. if (forceUpdate || style[propName] !== DEFAULT_PATH_STYLE[propName]) {
  15854. var val = style[propName] || DEFAULT_PATH_STYLE[propName];
  15855. val && updateAttr(svgStrokeProps[i], val);
  15856. }
  15857. }
  15858. }
  15859. else if (forceUpdate) {
  15860. updateAttr('stroke', NONE);
  15861. }
  15862. }
  15863. var SVGNS = 'http://www.w3.org/2000/svg';
  15864. var XLINKNS = 'http://www.w3.org/1999/xlink';
  15865. var XMLNS = 'http://www.w3.org/2000/xmlns/';
  15866. var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
  15867. var META_DATA_PREFIX = 'ecmeta_';
  15868. function createElement(name) {
  15869. return document.createElementNS(SVGNS, name);
  15870. }
  15871. function createVNode(tag, key, attrs, children, text) {
  15872. return {
  15873. tag: tag,
  15874. attrs: attrs || {},
  15875. children: children,
  15876. text: text,
  15877. key: key
  15878. };
  15879. }
  15880. function createElementOpen(name, attrs) {
  15881. var attrsStr = [];
  15882. if (attrs) {
  15883. for (var key in attrs) {
  15884. var val = attrs[key];
  15885. var part = key;
  15886. if (val === false) {
  15887. continue;
  15888. }
  15889. else if (val !== true && val != null) {
  15890. part += "=\"" + val + "\"";
  15891. }
  15892. attrsStr.push(part);
  15893. }
  15894. }
  15895. return "<" + name + " " + attrsStr.join(' ') + ">";
  15896. }
  15897. function createElementClose(name) {
  15898. return "</" + name + ">";
  15899. }
  15900. function vNodeToString(el, opts) {
  15901. opts = opts || {};
  15902. var S = opts.newline ? '\n' : '';
  15903. function convertElToString(el) {
  15904. var children = el.children, tag = el.tag, attrs = el.attrs, text = el.text;
  15905. return createElementOpen(tag, attrs)
  15906. + (tag !== 'style' ? encodeHTML(text) : text || '')
  15907. + (children ? "" + S + map(children, function (child) { return convertElToString(child); }).join(S) + S : '')
  15908. + createElementClose(tag);
  15909. }
  15910. return convertElToString(el);
  15911. }
  15912. function getCssString(selectorNodes, animationNodes, opts) {
  15913. opts = opts || {};
  15914. var S = opts.newline ? '\n' : '';
  15915. var bracketBegin = " {" + S;
  15916. var bracketEnd = S + "}";
  15917. var selectors = map(keys(selectorNodes), function (className) {
  15918. return className + bracketBegin + map(keys(selectorNodes[className]), function (attrName) {
  15919. return attrName + ":" + selectorNodes[className][attrName] + ";";
  15920. }).join(S) + bracketEnd;
  15921. }).join(S);
  15922. var animations = map(keys(animationNodes), function (animationName) {
  15923. return "@keyframes " + animationName + bracketBegin + map(keys(animationNodes[animationName]), function (percent) {
  15924. return percent + bracketBegin + map(keys(animationNodes[animationName][percent]), function (attrName) {
  15925. var val = animationNodes[animationName][percent][attrName];
  15926. if (attrName === 'd') {
  15927. val = "path(\"" + val + "\")";
  15928. }
  15929. return attrName + ":" + val + ";";
  15930. }).join(S) + bracketEnd;
  15931. }).join(S) + bracketEnd;
  15932. }).join(S);
  15933. if (!selectors && !animations) {
  15934. return '';
  15935. }
  15936. return ['<![CDATA[', selectors, animations, ']]>'].join(S);
  15937. }
  15938. function createBrushScope(zrId) {
  15939. return {
  15940. zrId: zrId,
  15941. shadowCache: {},
  15942. patternCache: {},
  15943. gradientCache: {},
  15944. clipPathCache: {},
  15945. defs: {},
  15946. cssNodes: {},
  15947. cssAnims: {},
  15948. cssStyleCache: {},
  15949. cssAnimIdx: 0,
  15950. shadowIdx: 0,
  15951. gradientIdx: 0,
  15952. patternIdx: 0,
  15953. clipPathIdx: 0
  15954. };
  15955. }
  15956. function createSVGVNode(width, height, children, useViewBox) {
  15957. return createVNode('svg', 'root', {
  15958. 'width': width,
  15959. 'height': height,
  15960. 'xmlns': SVGNS,
  15961. 'xmlns:xlink': XLINKNS,
  15962. 'version': '1.1',
  15963. 'baseProfile': 'full',
  15964. 'viewBox': useViewBox ? "0 0 " + width + " " + height : false
  15965. }, children);
  15966. }
  15967. var cssClassIdx = 0;
  15968. function getClassId() {
  15969. return cssClassIdx++;
  15970. }
  15971. var EASING_MAP = {
  15972. cubicIn: '0.32,0,0.67,0',
  15973. cubicOut: '0.33,1,0.68,1',
  15974. cubicInOut: '0.65,0,0.35,1',
  15975. quadraticIn: '0.11,0,0.5,0',
  15976. quadraticOut: '0.5,1,0.89,1',
  15977. quadraticInOut: '0.45,0,0.55,1',
  15978. quarticIn: '0.5,0,0.75,0',
  15979. quarticOut: '0.25,1,0.5,1',
  15980. quarticInOut: '0.76,0,0.24,1',
  15981. quinticIn: '0.64,0,0.78,0',
  15982. quinticOut: '0.22,1,0.36,1',
  15983. quinticInOut: '0.83,0,0.17,1',
  15984. sinusoidalIn: '0.12,0,0.39,0',
  15985. sinusoidalOut: '0.61,1,0.88,1',
  15986. sinusoidalInOut: '0.37,0,0.63,1',
  15987. exponentialIn: '0.7,0,0.84,0',
  15988. exponentialOut: '0.16,1,0.3,1',
  15989. exponentialInOut: '0.87,0,0.13,1',
  15990. circularIn: '0.55,0,1,0.45',
  15991. circularOut: '0,0.55,0.45,1',
  15992. circularInOut: '0.85,0,0.15,1'
  15993. };
  15994. var transformOriginKey = 'transform-origin';
  15995. function buildPathString(el, kfShape, path) {
  15996. var shape = extend({}, el.shape);
  15997. extend(shape, kfShape);
  15998. el.buildPath(path, shape);
  15999. var svgPathBuilder = new SVGPathRebuilder();
  16000. svgPathBuilder.reset(getPathPrecision(el));
  16001. path.rebuildPath(svgPathBuilder, 1);
  16002. svgPathBuilder.generateStr();
  16003. return svgPathBuilder.getStr();
  16004. }
  16005. function setTransformOrigin(target, transform) {
  16006. var originX = transform.originX, originY = transform.originY;
  16007. if (originX || originY) {
  16008. target[transformOriginKey] = originX + "px " + originY + "px";
  16009. }
  16010. }
  16011. var ANIMATE_STYLE_MAP = {
  16012. fill: 'fill',
  16013. opacity: 'opacity',
  16014. lineWidth: 'stroke-width',
  16015. lineDashOffset: 'stroke-dashoffset'
  16016. };
  16017. function addAnimation(cssAnim, scope) {
  16018. var animationName = scope.zrId + '-ani-' + scope.cssAnimIdx++;
  16019. scope.cssAnims[animationName] = cssAnim;
  16020. return animationName;
  16021. }
  16022. function createCompoundPathCSSAnimation(el, attrs, scope) {
  16023. var paths = el.shape.paths;
  16024. var composedAnim = {};
  16025. var cssAnimationCfg;
  16026. var cssAnimationName;
  16027. each(paths, function (path) {
  16028. var subScope = createBrushScope(scope.zrId);
  16029. subScope.animation = true;
  16030. createCSSAnimation(path, {}, subScope, true);
  16031. var cssAnims = subScope.cssAnims;
  16032. var cssNodes = subScope.cssNodes;
  16033. var animNames = keys(cssAnims);
  16034. var len = animNames.length;
  16035. if (!len) {
  16036. return;
  16037. }
  16038. cssAnimationName = animNames[len - 1];
  16039. var lastAnim = cssAnims[cssAnimationName];
  16040. for (var percent in lastAnim) {
  16041. var kf = lastAnim[percent];
  16042. composedAnim[percent] = composedAnim[percent] || { d: '' };
  16043. composedAnim[percent].d += kf.d || '';
  16044. }
  16045. for (var className in cssNodes) {
  16046. var val = cssNodes[className].animation;
  16047. if (val.indexOf(cssAnimationName) >= 0) {
  16048. cssAnimationCfg = val;
  16049. }
  16050. }
  16051. });
  16052. if (!cssAnimationCfg) {
  16053. return;
  16054. }
  16055. attrs.d = false;
  16056. var animationName = addAnimation(composedAnim, scope);
  16057. return cssAnimationCfg.replace(cssAnimationName, animationName);
  16058. }
  16059. function getEasingFunc(easing) {
  16060. return isString(easing)
  16061. ? EASING_MAP[easing]
  16062. ? "cubic-bezier(" + EASING_MAP[easing] + ")"
  16063. : createCubicEasingFunc(easing) ? easing : ''
  16064. : '';
  16065. }
  16066. function createCSSAnimation(el, attrs, scope, onlyShape) {
  16067. var animators = el.animators;
  16068. var len = animators.length;
  16069. var cssAnimations = [];
  16070. if (el instanceof CompoundPath) {
  16071. var animationCfg = createCompoundPathCSSAnimation(el, attrs, scope);
  16072. if (animationCfg) {
  16073. cssAnimations.push(animationCfg);
  16074. }
  16075. else if (!len) {
  16076. return;
  16077. }
  16078. }
  16079. else if (!len) {
  16080. return;
  16081. }
  16082. var groupAnimators = {};
  16083. for (var i = 0; i < len; i++) {
  16084. var animator = animators[i];
  16085. var cfgArr = [animator.getMaxTime() / 1000 + 's'];
  16086. var easing = getEasingFunc(animator.getClip().easing);
  16087. var delay = animator.getDelay();
  16088. if (easing) {
  16089. cfgArr.push(easing);
  16090. }
  16091. else {
  16092. cfgArr.push('linear');
  16093. }
  16094. if (delay) {
  16095. cfgArr.push(delay / 1000 + 's');
  16096. }
  16097. if (animator.getLoop()) {
  16098. cfgArr.push('infinite');
  16099. }
  16100. var cfg = cfgArr.join(' ');
  16101. groupAnimators[cfg] = groupAnimators[cfg] || [cfg, []];
  16102. groupAnimators[cfg][1].push(animator);
  16103. }
  16104. function createSingleCSSAnimation(groupAnimator) {
  16105. var animators = groupAnimator[1];
  16106. var len = animators.length;
  16107. var transformKfs = {};
  16108. var shapeKfs = {};
  16109. var finalKfs = {};
  16110. var animationTimingFunctionAttrName = 'animation-timing-function';
  16111. function saveAnimatorTrackToCssKfs(animator, cssKfs, toCssAttrName) {
  16112. var tracks = animator.getTracks();
  16113. var maxTime = animator.getMaxTime();
  16114. for (var k = 0; k < tracks.length; k++) {
  16115. var track = tracks[k];
  16116. if (track.needsAnimate()) {
  16117. var kfs = track.keyframes;
  16118. var attrName = track.propName;
  16119. toCssAttrName && (attrName = toCssAttrName(attrName));
  16120. if (attrName) {
  16121. for (var i = 0; i < kfs.length; i++) {
  16122. var kf = kfs[i];
  16123. var percent = Math.round(kf.time / maxTime * 100) + '%';
  16124. var kfEasing = getEasingFunc(kf.easing);
  16125. var rawValue = kf.rawValue;
  16126. if (isString(rawValue) || isNumber(rawValue)) {
  16127. cssKfs[percent] = cssKfs[percent] || {};
  16128. cssKfs[percent][attrName] = kf.rawValue;
  16129. if (kfEasing) {
  16130. cssKfs[percent][animationTimingFunctionAttrName] = kfEasing;
  16131. }
  16132. }
  16133. }
  16134. }
  16135. }
  16136. }
  16137. }
  16138. for (var i = 0; i < len; i++) {
  16139. var animator = animators[i];
  16140. var targetProp = animator.targetName;
  16141. if (!targetProp) {
  16142. !onlyShape && saveAnimatorTrackToCssKfs(animator, transformKfs);
  16143. }
  16144. else if (targetProp === 'shape') {
  16145. saveAnimatorTrackToCssKfs(animator, shapeKfs);
  16146. }
  16147. }
  16148. for (var percent in transformKfs) {
  16149. var transform = {};
  16150. copyTransform(transform, el);
  16151. extend(transform, transformKfs[percent]);
  16152. var str = getSRTTransformString(transform);
  16153. var timingFunction = transformKfs[percent][animationTimingFunctionAttrName];
  16154. finalKfs[percent] = str ? {
  16155. transform: str
  16156. } : {};
  16157. setTransformOrigin(finalKfs[percent], transform);
  16158. if (timingFunction) {
  16159. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16160. }
  16161. }
  16162. var path;
  16163. var canAnimateShape = true;
  16164. for (var percent in shapeKfs) {
  16165. finalKfs[percent] = finalKfs[percent] || {};
  16166. var isFirst = !path;
  16167. var timingFunction = shapeKfs[percent][animationTimingFunctionAttrName];
  16168. if (isFirst) {
  16169. path = new PathProxy();
  16170. }
  16171. var len_1 = path.len();
  16172. path.reset();
  16173. finalKfs[percent].d = buildPathString(el, shapeKfs[percent], path);
  16174. var newLen = path.len();
  16175. if (!isFirst && len_1 !== newLen) {
  16176. canAnimateShape = false;
  16177. break;
  16178. }
  16179. if (timingFunction) {
  16180. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16181. }
  16182. }
  16183. if (!canAnimateShape) {
  16184. for (var percent in finalKfs) {
  16185. delete finalKfs[percent].d;
  16186. }
  16187. }
  16188. if (!onlyShape) {
  16189. for (var i = 0; i < len; i++) {
  16190. var animator = animators[i];
  16191. var targetProp = animator.targetName;
  16192. if (targetProp === 'style') {
  16193. saveAnimatorTrackToCssKfs(animator, finalKfs, function (propName) { return ANIMATE_STYLE_MAP[propName]; });
  16194. }
  16195. }
  16196. }
  16197. var percents = keys(finalKfs);
  16198. var allTransformOriginSame = true;
  16199. var transformOrigin;
  16200. for (var i = 1; i < percents.length; i++) {
  16201. var p0 = percents[i - 1];
  16202. var p1 = percents[i];
  16203. if (finalKfs[p0][transformOriginKey] !== finalKfs[p1][transformOriginKey]) {
  16204. allTransformOriginSame = false;
  16205. break;
  16206. }
  16207. transformOrigin = finalKfs[p0][transformOriginKey];
  16208. }
  16209. if (allTransformOriginSame && transformOrigin) {
  16210. for (var percent in finalKfs) {
  16211. if (finalKfs[percent][transformOriginKey]) {
  16212. delete finalKfs[percent][transformOriginKey];
  16213. }
  16214. }
  16215. attrs[transformOriginKey] = transformOrigin;
  16216. }
  16217. if (filter(percents, function (percent) { return keys(finalKfs[percent]).length > 0; }).length) {
  16218. var animationName = addAnimation(finalKfs, scope);
  16219. return animationName + " " + groupAnimator[0] + " both";
  16220. }
  16221. }
  16222. for (var key in groupAnimators) {
  16223. var animationCfg = createSingleCSSAnimation(groupAnimators[key]);
  16224. if (animationCfg) {
  16225. cssAnimations.push(animationCfg);
  16226. }
  16227. }
  16228. if (cssAnimations.length) {
  16229. var className = scope.zrId + '-cls-' + getClassId();
  16230. scope.cssNodes['.' + className] = {
  16231. animation: cssAnimations.join(',')
  16232. };
  16233. attrs["class"] = className;
  16234. }
  16235. }
  16236. function createCSSEmphasis(el, attrs, scope) {
  16237. if (!el.ignore) {
  16238. if (el.isSilent()) {
  16239. var style = {
  16240. 'pointer-events': 'none'
  16241. };
  16242. setClassAttribute(style, attrs, scope, true);
  16243. }
  16244. else {
  16245. var emphasisStyle = el.states.emphasis && el.states.emphasis.style
  16246. ? el.states.emphasis.style
  16247. : {};
  16248. var fill = emphasisStyle.fill;
  16249. if (!fill) {
  16250. var normalFill = el.style && el.style.fill;
  16251. var selectFill = el.states.select
  16252. && el.states.select.style
  16253. && el.states.select.style.fill;
  16254. var fromFill = el.currentStates.indexOf('select') >= 0
  16255. ? (selectFill || normalFill)
  16256. : normalFill;
  16257. if (fromFill) {
  16258. fill = liftColor(fromFill);
  16259. }
  16260. }
  16261. var lineWidth = emphasisStyle.lineWidth;
  16262. if (lineWidth) {
  16263. var scaleX = (!emphasisStyle.strokeNoScale && el.transform)
  16264. ? el.transform[0]
  16265. : 1;
  16266. lineWidth = lineWidth / scaleX;
  16267. }
  16268. var style = {
  16269. cursor: 'pointer',
  16270. };
  16271. if (fill) {
  16272. style.fill = fill;
  16273. }
  16274. if (emphasisStyle.stroke) {
  16275. style.stroke = emphasisStyle.stroke;
  16276. }
  16277. if (lineWidth) {
  16278. style['stroke-width'] = lineWidth;
  16279. }
  16280. setClassAttribute(style, attrs, scope, true);
  16281. }
  16282. }
  16283. }
  16284. function setClassAttribute(style, attrs, scope, withHover) {
  16285. var styleKey = JSON.stringify(style);
  16286. var className = scope.cssStyleCache[styleKey];
  16287. if (!className) {
  16288. className = scope.zrId + '-cls-' + getClassId();
  16289. scope.cssStyleCache[styleKey] = className;
  16290. scope.cssNodes['.' + className + (withHover ? ':hover' : '')] = style;
  16291. }
  16292. attrs["class"] = attrs["class"] ? (attrs["class"] + ' ' + className) : className;
  16293. }
  16294. var round$1 = Math.round;
  16295. function isImageLike$1(val) {
  16296. return val && isString(val.src);
  16297. }
  16298. function isCanvasLike(val) {
  16299. return val && isFunction(val.toDataURL);
  16300. }
  16301. function setStyleAttrs(attrs, style, el, scope) {
  16302. mapStyleToAttrs(function (key, val) {
  16303. var isFillStroke = key === 'fill' || key === 'stroke';
  16304. if (isFillStroke && isGradient(val)) {
  16305. setGradient(style, attrs, key, scope);
  16306. }
  16307. else if (isFillStroke && isPattern(val)) {
  16308. setPattern(el, attrs, key, scope);
  16309. }
  16310. else if (isFillStroke && val === 'none') {
  16311. attrs[key] = 'transparent';
  16312. }
  16313. else {
  16314. attrs[key] = val;
  16315. }
  16316. }, style, el, false);
  16317. setShadow(el, attrs, scope);
  16318. }
  16319. function setMetaData(attrs, el) {
  16320. var metaData = getElementSSRData(el);
  16321. if (metaData) {
  16322. metaData.each(function (val, key) {
  16323. val != null && (attrs[(META_DATA_PREFIX + key).toLowerCase()] = val + '');
  16324. });
  16325. if (el.isSilent()) {
  16326. attrs[META_DATA_PREFIX + 'silent'] = 'true';
  16327. }
  16328. }
  16329. }
  16330. function noRotateScale(m) {
  16331. return isAroundZero$1(m[0] - 1)
  16332. && isAroundZero$1(m[1])
  16333. && isAroundZero$1(m[2])
  16334. && isAroundZero$1(m[3] - 1);
  16335. }
  16336. function noTranslate(m) {
  16337. return isAroundZero$1(m[4]) && isAroundZero$1(m[5]);
  16338. }
  16339. function setTransform(attrs, m, compress) {
  16340. if (m && !(noTranslate(m) && noRotateScale(m))) {
  16341. var mul = compress ? 10 : 1e4;
  16342. attrs.transform = noRotateScale(m)
  16343. ? "translate(" + round$1(m[4] * mul) / mul + " " + round$1(m[5] * mul) / mul + ")" : getMatrixStr(m);
  16344. }
  16345. }
  16346. function convertPolyShape(shape, attrs, mul) {
  16347. var points = shape.points;
  16348. var strArr = [];
  16349. for (var i = 0; i < points.length; i++) {
  16350. strArr.push(round$1(points[i][0] * mul) / mul);
  16351. strArr.push(round$1(points[i][1] * mul) / mul);
  16352. }
  16353. attrs.points = strArr.join(' ');
  16354. }
  16355. function validatePolyShape(shape) {
  16356. return !shape.smooth;
  16357. }
  16358. function createAttrsConvert(desc) {
  16359. var normalizedDesc = map(desc, function (item) {
  16360. return (typeof item === 'string' ? [item, item] : item);
  16361. });
  16362. return function (shape, attrs, mul) {
  16363. for (var i = 0; i < normalizedDesc.length; i++) {
  16364. var item = normalizedDesc[i];
  16365. var val = shape[item[0]];
  16366. if (val != null) {
  16367. attrs[item[1]] = round$1(val * mul) / mul;
  16368. }
  16369. }
  16370. };
  16371. }
  16372. var builtinShapesDef = {
  16373. circle: [createAttrsConvert(['cx', 'cy', 'r'])],
  16374. polyline: [convertPolyShape, validatePolyShape],
  16375. polygon: [convertPolyShape, validatePolyShape]
  16376. };
  16377. function hasShapeAnimation(el) {
  16378. var animators = el.animators;
  16379. for (var i = 0; i < animators.length; i++) {
  16380. if (animators[i].targetName === 'shape') {
  16381. return true;
  16382. }
  16383. }
  16384. return false;
  16385. }
  16386. function brushSVGPath(el, scope) {
  16387. var style = el.style;
  16388. var shape = el.shape;
  16389. var builtinShpDef = builtinShapesDef[el.type];
  16390. var attrs = {};
  16391. var needsAnimate = scope.animation;
  16392. var svgElType = 'path';
  16393. var strokePercent = el.style.strokePercent;
  16394. var precision = (scope.compress && getPathPrecision(el)) || 4;
  16395. if (builtinShpDef
  16396. && !scope.willUpdate
  16397. && !(builtinShpDef[1] && !builtinShpDef[1](shape))
  16398. && !(needsAnimate && hasShapeAnimation(el))
  16399. && !(strokePercent < 1)) {
  16400. svgElType = el.type;
  16401. var mul = Math.pow(10, precision);
  16402. builtinShpDef[0](shape, attrs, mul);
  16403. }
  16404. else {
  16405. var needBuildPath = !el.path || el.shapeChanged();
  16406. if (!el.path) {
  16407. el.createPathProxy();
  16408. }
  16409. var path = el.path;
  16410. if (needBuildPath) {
  16411. path.beginPath();
  16412. el.buildPath(path, el.shape);
  16413. el.pathUpdated();
  16414. }
  16415. var pathVersion = path.getVersion();
  16416. var elExt = el;
  16417. var svgPathBuilder = elExt.__svgPathBuilder;
  16418. if (elExt.__svgPathVersion !== pathVersion
  16419. || !svgPathBuilder
  16420. || strokePercent !== elExt.__svgPathStrokePercent) {
  16421. if (!svgPathBuilder) {
  16422. svgPathBuilder = elExt.__svgPathBuilder = new SVGPathRebuilder();
  16423. }
  16424. svgPathBuilder.reset(precision);
  16425. path.rebuildPath(svgPathBuilder, strokePercent);
  16426. svgPathBuilder.generateStr();
  16427. elExt.__svgPathVersion = pathVersion;
  16428. elExt.__svgPathStrokePercent = strokePercent;
  16429. }
  16430. attrs.d = svgPathBuilder.getStr();
  16431. }
  16432. setTransform(attrs, el.transform);
  16433. setStyleAttrs(attrs, style, el, scope);
  16434. setMetaData(attrs, el);
  16435. scope.animation && createCSSAnimation(el, attrs, scope);
  16436. scope.emphasis && createCSSEmphasis(el, attrs, scope);
  16437. return createVNode(svgElType, el.id + '', attrs);
  16438. }
  16439. function brushSVGImage(el, scope) {
  16440. var style = el.style;
  16441. var image = style.image;
  16442. if (image && !isString(image)) {
  16443. if (isImageLike$1(image)) {
  16444. image = image.src;
  16445. }
  16446. else if (isCanvasLike(image)) {
  16447. image = image.toDataURL();
  16448. }
  16449. }
  16450. if (!image) {
  16451. return;
  16452. }
  16453. var x = style.x || 0;
  16454. var y = style.y || 0;
  16455. var dw = style.width;
  16456. var dh = style.height;
  16457. var attrs = {
  16458. href: image,
  16459. width: dw,
  16460. height: dh
  16461. };
  16462. if (x) {
  16463. attrs.x = x;
  16464. }
  16465. if (y) {
  16466. attrs.y = y;
  16467. }
  16468. setTransform(attrs, el.transform);
  16469. setStyleAttrs(attrs, style, el, scope);
  16470. setMetaData(attrs, el);
  16471. scope.animation && createCSSAnimation(el, attrs, scope);
  16472. return createVNode('image', el.id + '', attrs);
  16473. }
  16474. function brushSVGTSpan(el, scope) {
  16475. var style = el.style;
  16476. var text = style.text;
  16477. text != null && (text += '');
  16478. if (!text || isNaN(style.x) || isNaN(style.y)) {
  16479. return;
  16480. }
  16481. var font = style.font || DEFAULT_FONT;
  16482. var x = style.x || 0;
  16483. var y = adjustTextY(style.y || 0, getLineHeight(font), style.textBaseline);
  16484. var textAlign = TEXT_ALIGN_TO_ANCHOR[style.textAlign]
  16485. || style.textAlign;
  16486. var attrs = {
  16487. 'dominant-baseline': 'central',
  16488. 'text-anchor': textAlign
  16489. };
  16490. if (hasSeparateFont(style)) {
  16491. var separatedFontStr = '';
  16492. var fontStyle = style.fontStyle;
  16493. var fontSize = parseFontSize(style.fontSize);
  16494. if (!parseFloat(fontSize)) {
  16495. return;
  16496. }
  16497. var fontFamily = style.fontFamily || DEFAULT_FONT_FAMILY;
  16498. var fontWeight = style.fontWeight;
  16499. separatedFontStr += "font-size:" + fontSize + ";font-family:" + fontFamily + ";";
  16500. if (fontStyle && fontStyle !== 'normal') {
  16501. separatedFontStr += "font-style:" + fontStyle + ";";
  16502. }
  16503. if (fontWeight && fontWeight !== 'normal') {
  16504. separatedFontStr += "font-weight:" + fontWeight + ";";
  16505. }
  16506. attrs.style = separatedFontStr;
  16507. }
  16508. else {
  16509. attrs.style = "font: " + font;
  16510. }
  16511. if (text.match(/\s/)) {
  16512. attrs['xml:space'] = 'preserve';
  16513. }
  16514. if (x) {
  16515. attrs.x = x;
  16516. }
  16517. if (y) {
  16518. attrs.y = y;
  16519. }
  16520. setTransform(attrs, el.transform);
  16521. setStyleAttrs(attrs, style, el, scope);
  16522. setMetaData(attrs, el);
  16523. scope.animation && createCSSAnimation(el, attrs, scope);
  16524. return createVNode('text', el.id + '', attrs, undefined, text);
  16525. }
  16526. function brush$1(el, scope) {
  16527. if (el instanceof Path) {
  16528. return brushSVGPath(el, scope);
  16529. }
  16530. else if (el instanceof ZRImage) {
  16531. return brushSVGImage(el, scope);
  16532. }
  16533. else if (el instanceof TSpan) {
  16534. return brushSVGTSpan(el, scope);
  16535. }
  16536. }
  16537. function setShadow(el, attrs, scope) {
  16538. var style = el.style;
  16539. if (hasShadow(style)) {
  16540. var shadowKey = getShadowKey(el);
  16541. var shadowCache = scope.shadowCache;
  16542. var shadowId = shadowCache[shadowKey];
  16543. if (!shadowId) {
  16544. var globalScale = el.getGlobalScale();
  16545. var scaleX = globalScale[0];
  16546. var scaleY = globalScale[1];
  16547. if (!scaleX || !scaleY) {
  16548. return;
  16549. }
  16550. var offsetX = style.shadowOffsetX || 0;
  16551. var offsetY = style.shadowOffsetY || 0;
  16552. var blur_1 = style.shadowBlur;
  16553. var _a = normalizeColor(style.shadowColor), opacity = _a.opacity, color = _a.color;
  16554. var stdDx = blur_1 / 2 / scaleX;
  16555. var stdDy = blur_1 / 2 / scaleY;
  16556. var stdDeviation = stdDx + ' ' + stdDy;
  16557. shadowId = scope.zrId + '-s' + scope.shadowIdx++;
  16558. scope.defs[shadowId] = createVNode('filter', shadowId, {
  16559. 'id': shadowId,
  16560. 'x': '-100%',
  16561. 'y': '-100%',
  16562. 'width': '300%',
  16563. 'height': '300%'
  16564. }, [
  16565. createVNode('feDropShadow', '', {
  16566. 'dx': offsetX / scaleX,
  16567. 'dy': offsetY / scaleY,
  16568. 'stdDeviation': stdDeviation,
  16569. 'flood-color': color,
  16570. 'flood-opacity': opacity
  16571. })
  16572. ]);
  16573. shadowCache[shadowKey] = shadowId;
  16574. }
  16575. attrs.filter = getIdURL(shadowId);
  16576. }
  16577. }
  16578. function setGradient(style, attrs, target, scope) {
  16579. var val = style[target];
  16580. var gradientTag;
  16581. var gradientAttrs = {
  16582. 'gradientUnits': val.global
  16583. ? 'userSpaceOnUse'
  16584. : 'objectBoundingBox'
  16585. };
  16586. if (isLinearGradient(val)) {
  16587. gradientTag = 'linearGradient';
  16588. gradientAttrs.x1 = val.x;
  16589. gradientAttrs.y1 = val.y;
  16590. gradientAttrs.x2 = val.x2;
  16591. gradientAttrs.y2 = val.y2;
  16592. }
  16593. else if (isRadialGradient(val)) {
  16594. gradientTag = 'radialGradient';
  16595. gradientAttrs.cx = retrieve2(val.x, 0.5);
  16596. gradientAttrs.cy = retrieve2(val.y, 0.5);
  16597. gradientAttrs.r = retrieve2(val.r, 0.5);
  16598. }
  16599. else {
  16600. {
  16601. logError('Illegal gradient type.');
  16602. }
  16603. return;
  16604. }
  16605. var colors = val.colorStops;
  16606. var colorStops = [];
  16607. for (var i = 0, len = colors.length; i < len; ++i) {
  16608. var offset = round4(colors[i].offset) * 100 + '%';
  16609. var stopColor = colors[i].color;
  16610. var _a = normalizeColor(stopColor), color = _a.color, opacity = _a.opacity;
  16611. var stopsAttrs = {
  16612. 'offset': offset
  16613. };
  16614. stopsAttrs['stop-color'] = color;
  16615. if (opacity < 1) {
  16616. stopsAttrs['stop-opacity'] = opacity;
  16617. }
  16618. colorStops.push(createVNode('stop', i + '', stopsAttrs));
  16619. }
  16620. var gradientVNode = createVNode(gradientTag, '', gradientAttrs, colorStops);
  16621. var gradientKey = vNodeToString(gradientVNode);
  16622. var gradientCache = scope.gradientCache;
  16623. var gradientId = gradientCache[gradientKey];
  16624. if (!gradientId) {
  16625. gradientId = scope.zrId + '-g' + scope.gradientIdx++;
  16626. gradientCache[gradientKey] = gradientId;
  16627. gradientAttrs.id = gradientId;
  16628. scope.defs[gradientId] = createVNode(gradientTag, gradientId, gradientAttrs, colorStops);
  16629. }
  16630. attrs[target] = getIdURL(gradientId);
  16631. }
  16632. function setPattern(el, attrs, target, scope) {
  16633. var val = el.style[target];
  16634. var boundingRect = el.getBoundingRect();
  16635. var patternAttrs = {};
  16636. var repeat = val.repeat;
  16637. var noRepeat = repeat === 'no-repeat';
  16638. var repeatX = repeat === 'repeat-x';
  16639. var repeatY = repeat === 'repeat-y';
  16640. var child;
  16641. if (isImagePattern(val)) {
  16642. var imageWidth_1 = val.imageWidth;
  16643. var imageHeight_1 = val.imageHeight;
  16644. var imageSrc = void 0;
  16645. var patternImage = val.image;
  16646. if (isString(patternImage)) {
  16647. imageSrc = patternImage;
  16648. }
  16649. else if (isImageLike$1(patternImage)) {
  16650. imageSrc = patternImage.src;
  16651. }
  16652. else if (isCanvasLike(patternImage)) {
  16653. imageSrc = patternImage.toDataURL();
  16654. }
  16655. if (typeof Image === 'undefined') {
  16656. var errMsg = 'Image width/height must been given explictly in svg-ssr renderer.';
  16657. assert(imageWidth_1, errMsg);
  16658. assert(imageHeight_1, errMsg);
  16659. }
  16660. else if (imageWidth_1 == null || imageHeight_1 == null) {
  16661. var setSizeToVNode_1 = function (vNode, img) {
  16662. if (vNode) {
  16663. var svgEl = vNode.elm;
  16664. var width = imageWidth_1 || img.width;
  16665. var height = imageHeight_1 || img.height;
  16666. if (vNode.tag === 'pattern') {
  16667. if (repeatX) {
  16668. height = 1;
  16669. width /= boundingRect.width;
  16670. }
  16671. else if (repeatY) {
  16672. width = 1;
  16673. height /= boundingRect.height;
  16674. }
  16675. }
  16676. vNode.attrs.width = width;
  16677. vNode.attrs.height = height;
  16678. if (svgEl) {
  16679. svgEl.setAttribute('width', width);
  16680. svgEl.setAttribute('height', height);
  16681. }
  16682. }
  16683. };
  16684. var createdImage = createOrUpdateImage(imageSrc, null, el, function (img) {
  16685. noRepeat || setSizeToVNode_1(patternVNode, img);
  16686. setSizeToVNode_1(child, img);
  16687. });
  16688. if (createdImage && createdImage.width && createdImage.height) {
  16689. imageWidth_1 = imageWidth_1 || createdImage.width;
  16690. imageHeight_1 = imageHeight_1 || createdImage.height;
  16691. }
  16692. }
  16693. child = createVNode('image', 'img', {
  16694. href: imageSrc,
  16695. width: imageWidth_1,
  16696. height: imageHeight_1
  16697. });
  16698. patternAttrs.width = imageWidth_1;
  16699. patternAttrs.height = imageHeight_1;
  16700. }
  16701. else if (val.svgElement) {
  16702. child = clone(val.svgElement);
  16703. patternAttrs.width = val.svgWidth;
  16704. patternAttrs.height = val.svgHeight;
  16705. }
  16706. if (!child) {
  16707. return;
  16708. }
  16709. var patternWidth;
  16710. var patternHeight;
  16711. if (noRepeat) {
  16712. patternWidth = patternHeight = 1;
  16713. }
  16714. else if (repeatX) {
  16715. patternHeight = 1;
  16716. patternWidth = patternAttrs.width / boundingRect.width;
  16717. }
  16718. else if (repeatY) {
  16719. patternWidth = 1;
  16720. patternHeight = patternAttrs.height / boundingRect.height;
  16721. }
  16722. else {
  16723. patternAttrs.patternUnits = 'userSpaceOnUse';
  16724. }
  16725. if (patternWidth != null && !isNaN(patternWidth)) {
  16726. patternAttrs.width = patternWidth;
  16727. }
  16728. if (patternHeight != null && !isNaN(patternHeight)) {
  16729. patternAttrs.height = patternHeight;
  16730. }
  16731. var patternTransform = getSRTTransformString(val);
  16732. patternTransform && (patternAttrs.patternTransform = patternTransform);
  16733. var patternVNode = createVNode('pattern', '', patternAttrs, [child]);
  16734. var patternKey = vNodeToString(patternVNode);
  16735. var patternCache = scope.patternCache;
  16736. var patternId = patternCache[patternKey];
  16737. if (!patternId) {
  16738. patternId = scope.zrId + '-p' + scope.patternIdx++;
  16739. patternCache[patternKey] = patternId;
  16740. patternAttrs.id = patternId;
  16741. patternVNode = scope.defs[patternId] = createVNode('pattern', patternId, patternAttrs, [child]);
  16742. }
  16743. attrs[target] = getIdURL(patternId);
  16744. }
  16745. function setClipPath(clipPath, attrs, scope) {
  16746. var clipPathCache = scope.clipPathCache, defs = scope.defs;
  16747. var clipPathId = clipPathCache[clipPath.id];
  16748. if (!clipPathId) {
  16749. clipPathId = scope.zrId + '-c' + scope.clipPathIdx++;
  16750. var clipPathAttrs = {
  16751. id: clipPathId
  16752. };
  16753. clipPathCache[clipPath.id] = clipPathId;
  16754. defs[clipPathId] = createVNode('clipPath', clipPathId, clipPathAttrs, [brushSVGPath(clipPath, scope)]);
  16755. }
  16756. attrs['clip-path'] = getIdURL(clipPathId);
  16757. }
  16758. function createTextNode(text) {
  16759. return document.createTextNode(text);
  16760. }
  16761. function insertBefore(parentNode, newNode, referenceNode) {
  16762. parentNode.insertBefore(newNode, referenceNode);
  16763. }
  16764. function removeChild(node, child) {
  16765. node.removeChild(child);
  16766. }
  16767. function appendChild(node, child) {
  16768. node.appendChild(child);
  16769. }
  16770. function parentNode(node) {
  16771. return node.parentNode;
  16772. }
  16773. function nextSibling(node) {
  16774. return node.nextSibling;
  16775. }
  16776. function setTextContent(node, text) {
  16777. node.textContent = text;
  16778. }
  16779. var colonChar = 58;
  16780. var xChar = 120;
  16781. var emptyNode = createVNode('', '');
  16782. function isUndef(s) {
  16783. return s === undefined;
  16784. }
  16785. function isDef(s) {
  16786. return s !== undefined;
  16787. }
  16788. function createKeyToOldIdx(children, beginIdx, endIdx) {
  16789. var map = {};
  16790. for (var i = beginIdx; i <= endIdx; ++i) {
  16791. var key = children[i].key;
  16792. if (key !== undefined) {
  16793. {
  16794. if (map[key] != null) {
  16795. console.error("Duplicate key " + key);
  16796. }
  16797. }
  16798. map[key] = i;
  16799. }
  16800. }
  16801. return map;
  16802. }
  16803. function sameVnode(vnode1, vnode2) {
  16804. var isSameKey = vnode1.key === vnode2.key;
  16805. var isSameTag = vnode1.tag === vnode2.tag;
  16806. return isSameTag && isSameKey;
  16807. }
  16808. function createElm(vnode) {
  16809. var i;
  16810. var children = vnode.children;
  16811. var tag = vnode.tag;
  16812. if (isDef(tag)) {
  16813. var elm = (vnode.elm = createElement(tag));
  16814. updateAttrs(emptyNode, vnode);
  16815. if (isArray(children)) {
  16816. for (i = 0; i < children.length; ++i) {
  16817. var ch = children[i];
  16818. if (ch != null) {
  16819. appendChild(elm, createElm(ch));
  16820. }
  16821. }
  16822. }
  16823. else if (isDef(vnode.text) && !isObject(vnode.text)) {
  16824. appendChild(elm, createTextNode(vnode.text));
  16825. }
  16826. }
  16827. else {
  16828. vnode.elm = createTextNode(vnode.text);
  16829. }
  16830. return vnode.elm;
  16831. }
  16832. function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
  16833. for (; startIdx <= endIdx; ++startIdx) {
  16834. var ch = vnodes[startIdx];
  16835. if (ch != null) {
  16836. insertBefore(parentElm, createElm(ch), before);
  16837. }
  16838. }
  16839. }
  16840. function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
  16841. for (; startIdx <= endIdx; ++startIdx) {
  16842. var ch = vnodes[startIdx];
  16843. if (ch != null) {
  16844. if (isDef(ch.tag)) {
  16845. var parent_1 = parentNode(ch.elm);
  16846. removeChild(parent_1, ch.elm);
  16847. }
  16848. else {
  16849. removeChild(parentElm, ch.elm);
  16850. }
  16851. }
  16852. }
  16853. }
  16854. function updateAttrs(oldVnode, vnode) {
  16855. var key;
  16856. var elm = vnode.elm;
  16857. var oldAttrs = oldVnode && oldVnode.attrs || {};
  16858. var attrs = vnode.attrs || {};
  16859. if (oldAttrs === attrs) {
  16860. return;
  16861. }
  16862. for (key in attrs) {
  16863. var cur = attrs[key];
  16864. var old = oldAttrs[key];
  16865. if (old !== cur) {
  16866. if (cur === true) {
  16867. elm.setAttribute(key, '');
  16868. }
  16869. else if (cur === false) {
  16870. elm.removeAttribute(key);
  16871. }
  16872. else {
  16873. if (key === 'style') {
  16874. elm.style.cssText = cur;
  16875. }
  16876. else if (key.charCodeAt(0) !== xChar) {
  16877. elm.setAttribute(key, cur);
  16878. }
  16879. else if (key === 'xmlns:xlink' || key === 'xmlns') {
  16880. elm.setAttributeNS(XMLNS, key, cur);
  16881. }
  16882. else if (key.charCodeAt(3) === colonChar) {
  16883. elm.setAttributeNS(XML_NAMESPACE, key, cur);
  16884. }
  16885. else if (key.charCodeAt(5) === colonChar) {
  16886. elm.setAttributeNS(XLINKNS, key, cur);
  16887. }
  16888. else {
  16889. elm.setAttribute(key, cur);
  16890. }
  16891. }
  16892. }
  16893. }
  16894. for (key in oldAttrs) {
  16895. if (!(key in attrs)) {
  16896. elm.removeAttribute(key);
  16897. }
  16898. }
  16899. }
  16900. function updateChildren(parentElm, oldCh, newCh) {
  16901. var oldStartIdx = 0;
  16902. var newStartIdx = 0;
  16903. var oldEndIdx = oldCh.length - 1;
  16904. var oldStartVnode = oldCh[0];
  16905. var oldEndVnode = oldCh[oldEndIdx];
  16906. var newEndIdx = newCh.length - 1;
  16907. var newStartVnode = newCh[0];
  16908. var newEndVnode = newCh[newEndIdx];
  16909. var oldKeyToIdx;
  16910. var idxInOld;
  16911. var elmToMove;
  16912. var before;
  16913. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  16914. if (oldStartVnode == null) {
  16915. oldStartVnode = oldCh[++oldStartIdx];
  16916. }
  16917. else if (oldEndVnode == null) {
  16918. oldEndVnode = oldCh[--oldEndIdx];
  16919. }
  16920. else if (newStartVnode == null) {
  16921. newStartVnode = newCh[++newStartIdx];
  16922. }
  16923. else if (newEndVnode == null) {
  16924. newEndVnode = newCh[--newEndIdx];
  16925. }
  16926. else if (sameVnode(oldStartVnode, newStartVnode)) {
  16927. patchVnode(oldStartVnode, newStartVnode);
  16928. oldStartVnode = oldCh[++oldStartIdx];
  16929. newStartVnode = newCh[++newStartIdx];
  16930. }
  16931. else if (sameVnode(oldEndVnode, newEndVnode)) {
  16932. patchVnode(oldEndVnode, newEndVnode);
  16933. oldEndVnode = oldCh[--oldEndIdx];
  16934. newEndVnode = newCh[--newEndIdx];
  16935. }
  16936. else if (sameVnode(oldStartVnode, newEndVnode)) {
  16937. patchVnode(oldStartVnode, newEndVnode);
  16938. insertBefore(parentElm, oldStartVnode.elm, nextSibling(oldEndVnode.elm));
  16939. oldStartVnode = oldCh[++oldStartIdx];
  16940. newEndVnode = newCh[--newEndIdx];
  16941. }
  16942. else if (sameVnode(oldEndVnode, newStartVnode)) {
  16943. patchVnode(oldEndVnode, newStartVnode);
  16944. insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
  16945. oldEndVnode = oldCh[--oldEndIdx];
  16946. newStartVnode = newCh[++newStartIdx];
  16947. }
  16948. else {
  16949. if (isUndef(oldKeyToIdx)) {
  16950. oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
  16951. }
  16952. idxInOld = oldKeyToIdx[newStartVnode.key];
  16953. if (isUndef(idxInOld)) {
  16954. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  16955. }
  16956. else {
  16957. elmToMove = oldCh[idxInOld];
  16958. if (elmToMove.tag !== newStartVnode.tag) {
  16959. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  16960. }
  16961. else {
  16962. patchVnode(elmToMove, newStartVnode);
  16963. oldCh[idxInOld] = undefined;
  16964. insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
  16965. }
  16966. }
  16967. newStartVnode = newCh[++newStartIdx];
  16968. }
  16969. }
  16970. if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
  16971. if (oldStartIdx > oldEndIdx) {
  16972. before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm;
  16973. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
  16974. }
  16975. else {
  16976. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
  16977. }
  16978. }
  16979. }
  16980. function patchVnode(oldVnode, vnode) {
  16981. var elm = (vnode.elm = oldVnode.elm);
  16982. var oldCh = oldVnode.children;
  16983. var ch = vnode.children;
  16984. if (oldVnode === vnode) {
  16985. return;
  16986. }
  16987. updateAttrs(oldVnode, vnode);
  16988. if (isUndef(vnode.text)) {
  16989. if (isDef(oldCh) && isDef(ch)) {
  16990. if (oldCh !== ch) {
  16991. updateChildren(elm, oldCh, ch);
  16992. }
  16993. }
  16994. else if (isDef(ch)) {
  16995. if (isDef(oldVnode.text)) {
  16996. setTextContent(elm, '');
  16997. }
  16998. addVnodes(elm, null, ch, 0, ch.length - 1);
  16999. }
  17000. else if (isDef(oldCh)) {
  17001. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  17002. }
  17003. else if (isDef(oldVnode.text)) {
  17004. setTextContent(elm, '');
  17005. }
  17006. }
  17007. else if (oldVnode.text !== vnode.text) {
  17008. if (isDef(oldCh)) {
  17009. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  17010. }
  17011. setTextContent(elm, vnode.text);
  17012. }
  17013. }
  17014. function patch(oldVnode, vnode) {
  17015. if (sameVnode(oldVnode, vnode)) {
  17016. patchVnode(oldVnode, vnode);
  17017. }
  17018. else {
  17019. var elm = oldVnode.elm;
  17020. var parent_2 = parentNode(elm);
  17021. createElm(vnode);
  17022. if (parent_2 !== null) {
  17023. insertBefore(parent_2, vnode.elm, nextSibling(elm));
  17024. removeVnodes(parent_2, [oldVnode], 0, 0);
  17025. }
  17026. }
  17027. return vnode;
  17028. }
  17029. var svgId = 0;
  17030. var SVGPainter = (function () {
  17031. function SVGPainter(root, storage, opts) {
  17032. this.type = 'svg';
  17033. this.refreshHover = createMethodNotSupport('refreshHover');
  17034. this.configLayer = createMethodNotSupport('configLayer');
  17035. this.storage = storage;
  17036. this._opts = opts = extend({}, opts);
  17037. this.root = root;
  17038. this._id = 'zr' + svgId++;
  17039. this._oldVNode = createSVGVNode(opts.width, opts.height);
  17040. if (root && !opts.ssr) {
  17041. var viewport = this._viewport = document.createElement('div');
  17042. viewport.style.cssText = 'position:relative;overflow:hidden';
  17043. var svgDom = this._svgDom = this._oldVNode.elm = createElement('svg');
  17044. updateAttrs(null, this._oldVNode);
  17045. viewport.appendChild(svgDom);
  17046. root.appendChild(viewport);
  17047. }
  17048. this.resize(opts.width, opts.height);
  17049. }
  17050. SVGPainter.prototype.getType = function () {
  17051. return this.type;
  17052. };
  17053. SVGPainter.prototype.getViewportRoot = function () {
  17054. return this._viewport;
  17055. };
  17056. SVGPainter.prototype.getViewportRootOffset = function () {
  17057. var viewportRoot = this.getViewportRoot();
  17058. if (viewportRoot) {
  17059. return {
  17060. offsetLeft: viewportRoot.offsetLeft || 0,
  17061. offsetTop: viewportRoot.offsetTop || 0
  17062. };
  17063. }
  17064. };
  17065. SVGPainter.prototype.getSvgDom = function () {
  17066. return this._svgDom;
  17067. };
  17068. SVGPainter.prototype.refresh = function () {
  17069. if (this.root) {
  17070. var vnode = this.renderToVNode({
  17071. willUpdate: true
  17072. });
  17073. vnode.attrs.style = 'position:absolute;left:0;top:0;user-select:none';
  17074. patch(this._oldVNode, vnode);
  17075. this._oldVNode = vnode;
  17076. }
  17077. };
  17078. SVGPainter.prototype.renderOneToVNode = function (el) {
  17079. return brush$1(el, createBrushScope(this._id));
  17080. };
  17081. SVGPainter.prototype.renderToVNode = function (opts) {
  17082. opts = opts || {};
  17083. var list = this.storage.getDisplayList(true);
  17084. var width = this._width;
  17085. var height = this._height;
  17086. var scope = createBrushScope(this._id);
  17087. scope.animation = opts.animation;
  17088. scope.willUpdate = opts.willUpdate;
  17089. scope.compress = opts.compress;
  17090. scope.emphasis = opts.emphasis;
  17091. var children = [];
  17092. var bgVNode = this._bgVNode = createBackgroundVNode(width, height, this._backgroundColor, scope);
  17093. bgVNode && children.push(bgVNode);
  17094. var mainVNode = !opts.compress
  17095. ? (this._mainVNode = createVNode('g', 'main', {}, [])) : null;
  17096. this._paintList(list, scope, mainVNode ? mainVNode.children : children);
  17097. mainVNode && children.push(mainVNode);
  17098. var defs = map(keys(scope.defs), function (id) { return scope.defs[id]; });
  17099. if (defs.length) {
  17100. children.push(createVNode('defs', 'defs', {}, defs));
  17101. }
  17102. if (opts.animation) {
  17103. var animationCssStr = getCssString(scope.cssNodes, scope.cssAnims, { newline: true });
  17104. if (animationCssStr) {
  17105. var styleNode = createVNode('style', 'stl', {}, [], animationCssStr);
  17106. children.push(styleNode);
  17107. }
  17108. }
  17109. return createSVGVNode(width, height, children, opts.useViewBox);
  17110. };
  17111. SVGPainter.prototype.renderToString = function (opts) {
  17112. opts = opts || {};
  17113. return vNodeToString(this.renderToVNode({
  17114. animation: retrieve2(opts.cssAnimation, true),
  17115. emphasis: retrieve2(opts.cssEmphasis, true),
  17116. willUpdate: false,
  17117. compress: true,
  17118. useViewBox: retrieve2(opts.useViewBox, true)
  17119. }), { newline: true });
  17120. };
  17121. SVGPainter.prototype.setBackgroundColor = function (backgroundColor) {
  17122. this._backgroundColor = backgroundColor;
  17123. };
  17124. SVGPainter.prototype.getSvgRoot = function () {
  17125. return this._mainVNode && this._mainVNode.elm;
  17126. };
  17127. SVGPainter.prototype._paintList = function (list, scope, out) {
  17128. var listLen = list.length;
  17129. var clipPathsGroupsStack = [];
  17130. var clipPathsGroupsStackDepth = 0;
  17131. var currentClipPathGroup;
  17132. var prevClipPaths;
  17133. var clipGroupNodeIdx = 0;
  17134. for (var i = 0; i < listLen; i++) {
  17135. var displayable = list[i];
  17136. if (!displayable.invisible) {
  17137. var clipPaths = displayable.__clipPaths;
  17138. var len = clipPaths && clipPaths.length || 0;
  17139. var prevLen = prevClipPaths && prevClipPaths.length || 0;
  17140. var lca = void 0;
  17141. for (lca = Math.max(len - 1, prevLen - 1); lca >= 0; lca--) {
  17142. if (clipPaths && prevClipPaths
  17143. && clipPaths[lca] === prevClipPaths[lca]) {
  17144. break;
  17145. }
  17146. }
  17147. for (var i_1 = prevLen - 1; i_1 > lca; i_1--) {
  17148. clipPathsGroupsStackDepth--;
  17149. currentClipPathGroup = clipPathsGroupsStack[clipPathsGroupsStackDepth - 1];
  17150. }
  17151. for (var i_2 = lca + 1; i_2 < len; i_2++) {
  17152. var groupAttrs = {};
  17153. setClipPath(clipPaths[i_2], groupAttrs, scope);
  17154. var g = createVNode('g', 'clip-g-' + clipGroupNodeIdx++, groupAttrs, []);
  17155. (currentClipPathGroup ? currentClipPathGroup.children : out).push(g);
  17156. clipPathsGroupsStack[clipPathsGroupsStackDepth++] = g;
  17157. currentClipPathGroup = g;
  17158. }
  17159. prevClipPaths = clipPaths;
  17160. var ret = brush$1(displayable, scope);
  17161. if (ret) {
  17162. (currentClipPathGroup ? currentClipPathGroup.children : out).push(ret);
  17163. }
  17164. }
  17165. }
  17166. };
  17167. SVGPainter.prototype.resize = function (width, height) {
  17168. var opts = this._opts;
  17169. var root = this.root;
  17170. var viewport = this._viewport;
  17171. width != null && (opts.width = width);
  17172. height != null && (opts.height = height);
  17173. if (root && viewport) {
  17174. viewport.style.display = 'none';
  17175. width = getSize(root, 0, opts);
  17176. height = getSize(root, 1, opts);
  17177. viewport.style.display = '';
  17178. }
  17179. if (this._width !== width || this._height !== height) {
  17180. this._width = width;
  17181. this._height = height;
  17182. if (viewport) {
  17183. var viewportStyle = viewport.style;
  17184. viewportStyle.width = width + 'px';
  17185. viewportStyle.height = height + 'px';
  17186. }
  17187. if (!isPattern(this._backgroundColor)) {
  17188. var svgDom = this._svgDom;
  17189. if (svgDom) {
  17190. svgDom.setAttribute('width', width);
  17191. svgDom.setAttribute('height', height);
  17192. }
  17193. var bgEl = this._bgVNode && this._bgVNode.elm;
  17194. if (bgEl) {
  17195. bgEl.setAttribute('width', width);
  17196. bgEl.setAttribute('height', height);
  17197. }
  17198. }
  17199. else {
  17200. this.refresh();
  17201. }
  17202. }
  17203. };
  17204. SVGPainter.prototype.getWidth = function () {
  17205. return this._width;
  17206. };
  17207. SVGPainter.prototype.getHeight = function () {
  17208. return this._height;
  17209. };
  17210. SVGPainter.prototype.dispose = function () {
  17211. if (this.root) {
  17212. this.root.innerHTML = '';
  17213. }
  17214. this._svgDom =
  17215. this._viewport =
  17216. this.storage =
  17217. this._oldVNode =
  17218. this._bgVNode =
  17219. this._mainVNode = null;
  17220. };
  17221. SVGPainter.prototype.clear = function () {
  17222. if (this._svgDom) {
  17223. this._svgDom.innerHTML = null;
  17224. }
  17225. this._oldVNode = null;
  17226. };
  17227. SVGPainter.prototype.toDataURL = function (base64) {
  17228. var str = this.renderToString();
  17229. var prefix = 'data:image/svg+xml;';
  17230. if (base64) {
  17231. str = encodeBase64(str);
  17232. return str && prefix + 'base64,' + str;
  17233. }
  17234. return prefix + 'charset=UTF-8,' + encodeURIComponent(str);
  17235. };
  17236. return SVGPainter;
  17237. }());
  17238. function createMethodNotSupport(method) {
  17239. return function () {
  17240. {
  17241. logError('In SVG mode painter not support method "' + method + '"');
  17242. }
  17243. };
  17244. }
  17245. function createBackgroundVNode(width, height, backgroundColor, scope) {
  17246. var bgVNode;
  17247. if (backgroundColor && backgroundColor !== 'none') {
  17248. bgVNode = createVNode('rect', 'bg', {
  17249. width: width,
  17250. height: height,
  17251. x: '0',
  17252. y: '0'
  17253. });
  17254. if (isGradient(backgroundColor)) {
  17255. setGradient({ fill: backgroundColor }, bgVNode.attrs, 'fill', scope);
  17256. }
  17257. else if (isPattern(backgroundColor)) {
  17258. setPattern({
  17259. style: {
  17260. fill: backgroundColor
  17261. },
  17262. dirty: noop,
  17263. getBoundingRect: function () { return ({ width: width, height: height }); }
  17264. }, bgVNode.attrs, 'fill', scope);
  17265. }
  17266. else {
  17267. var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
  17268. bgVNode.attrs.fill = color;
  17269. opacity < 1 && (bgVNode.attrs['fill-opacity'] = opacity);
  17270. }
  17271. }
  17272. return bgVNode;
  17273. }
  17274. registerPainter('canvas', CanvasPainter);
  17275. registerPainter('svg', SVGPainter);
  17276. exports.Arc = Arc;
  17277. exports.ArcShape = ArcShape;
  17278. exports.BezierCurve = BezierCurve;
  17279. exports.BezierCurveShape = BezierCurveShape;
  17280. exports.BoundingRect = BoundingRect;
  17281. exports.Circle = Circle;
  17282. exports.CircleShape = CircleShape;
  17283. exports.CompoundPath = CompoundPath;
  17284. exports.Displayable = Displayable;
  17285. exports.Droplet = Droplet;
  17286. exports.DropletShape = DropletShape;
  17287. exports.Element = Element;
  17288. exports.Ellipse = Ellipse;
  17289. exports.EllipseShape = EllipseShape;
  17290. exports.Group = Group;
  17291. exports.Heart = Heart;
  17292. exports.HeartShape = HeartShape;
  17293. exports.Image = ZRImage;
  17294. exports.IncrementalDisplayable = IncrementalDisplayable;
  17295. exports.Isogon = Isogon;
  17296. exports.IsogonShape = IsogonShape;
  17297. exports.Line = Line;
  17298. exports.LineShape = LineShape;
  17299. exports.LinearGradient = LinearGradient;
  17300. exports.OrientedBoundingRect = OrientedBoundingRect;
  17301. exports.Path = Path;
  17302. exports.Pattern = Pattern;
  17303. exports.Point = Point;
  17304. exports.Polygon = Polygon;
  17305. exports.PolygonShape = PolygonShape;
  17306. exports.Polyline = Polyline;
  17307. exports.PolylineShape = PolylineShape;
  17308. exports.RadialGradient = RadialGradient;
  17309. exports.Rect = Rect;
  17310. exports.RectShape = RectShape;
  17311. exports.Ring = Ring;
  17312. exports.RingShape = RingShape;
  17313. exports.Rose = Rose;
  17314. exports.RoseShape = RoseShape;
  17315. exports.Sector = Sector;
  17316. exports.SectorShape = SectorShape;
  17317. exports.Star = Star;
  17318. exports.StarShape = StarShape;
  17319. exports.TSpan = TSpan;
  17320. exports.Text = ZRText;
  17321. exports.Trochoid = Trochoid;
  17322. exports.TrochoidShape = TrochoidShape;
  17323. exports.color = color;
  17324. exports.dispose = dispose;
  17325. exports.disposeAll = disposeAll;
  17326. exports.getElementSSRData = getElementSSRData;
  17327. exports.getInstance = getInstance;
  17328. exports.init = init;
  17329. exports.matrix = matrix;
  17330. exports.morph = morphPath$1;
  17331. exports.parseSVG = parseSVG;
  17332. exports.path = path;
  17333. exports.registerPainter = registerPainter;
  17334. exports.registerSSRDataGetter = registerSSRDataGetter;
  17335. exports.setPlatformAPI = setPlatformAPI;
  17336. exports.showDebugDirtyRect = showDebugDirtyRect;
  17337. exports.util = util;
  17338. exports.vector = vector;
  17339. exports.version = version;
  17340. Object.defineProperty(exports, '__esModule', { value: true });
  17341. })));
  17342. //# sourceMappingURL=zrender.js.map