zrender.js 641 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484
  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 (!env.hasGlobalWindow || 'Deno' in window) {
  41. env.node = true;
  42. env.svgSupported = true;
  43. }
  44. else {
  45. detect(navigator.userAgent, env);
  46. }
  47. function detect(ua, env) {
  48. var browser = env.browser;
  49. var firefox = ua.match(/Firefox\/([\d.]+)/);
  50. var ie = ua.match(/MSIE\s([\d.]+)/)
  51. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  52. var edge = ua.match(/Edge?\/([\d.]+)/);
  53. var weChat = (/micromessenger/i).test(ua);
  54. if (firefox) {
  55. browser.firefox = true;
  56. browser.version = firefox[1];
  57. }
  58. if (ie) {
  59. browser.ie = true;
  60. browser.version = ie[1];
  61. }
  62. if (edge) {
  63. browser.edge = true;
  64. browser.version = edge[1];
  65. browser.newEdge = +edge[1].split('.')[0] > 18;
  66. }
  67. if (weChat) {
  68. browser.weChat = true;
  69. }
  70. env.svgSupported = typeof SVGRect !== 'undefined';
  71. env.touchEventsSupported = 'ontouchstart' in window && !browser.ie && !browser.edge;
  72. env.pointerEventsSupported = 'onpointerdown' in window
  73. && (browser.edge || (browser.ie && +browser.version >= 11));
  74. env.domSupported = typeof document !== 'undefined';
  75. var style = document.documentElement.style;
  76. env.transform3dSupported = ((browser.ie && 'transition' in style)
  77. || browser.edge
  78. || (('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()))
  79. || 'MozPerspective' in style)
  80. && !('OTransition' in style);
  81. env.transformSupported = env.transform3dSupported
  82. || (browser.ie && +browser.version >= 9);
  83. }
  84. var DEFAULT_FONT_SIZE = 12;
  85. var DEFAULT_FONT_FAMILY = 'sans-serif';
  86. var DEFAULT_FONT = DEFAULT_FONT_SIZE + "px " + DEFAULT_FONT_FAMILY;
  87. var OFFSET = 20;
  88. var SCALE = 100;
  89. var defaultWidthMapStr = "007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N";
  90. function getTextWidthMap(mapStr) {
  91. var map = {};
  92. if (typeof JSON === 'undefined') {
  93. return map;
  94. }
  95. for (var i = 0; i < mapStr.length; i++) {
  96. var char = String.fromCharCode(i + 32);
  97. var size = (mapStr.charCodeAt(i) - OFFSET) / SCALE;
  98. map[char] = size;
  99. }
  100. return map;
  101. }
  102. var DEFAULT_TEXT_WIDTH_MAP = getTextWidthMap(defaultWidthMapStr);
  103. var platformApi = {
  104. createCanvas: function () {
  105. return typeof document !== 'undefined'
  106. && document.createElement('canvas');
  107. },
  108. measureText: (function () {
  109. var _ctx;
  110. var _cachedFont;
  111. return function (text, font) {
  112. if (!_ctx) {
  113. var canvas = platformApi.createCanvas();
  114. _ctx = canvas && canvas.getContext('2d');
  115. }
  116. if (_ctx) {
  117. if (_cachedFont !== font) {
  118. _cachedFont = _ctx.font = font || DEFAULT_FONT;
  119. }
  120. return _ctx.measureText(text);
  121. }
  122. else {
  123. text = text || '';
  124. font = font || DEFAULT_FONT;
  125. var res = /((?:\d+)?\.?\d*)px/.exec(font);
  126. var fontSize = res && +res[1] || DEFAULT_FONT_SIZE;
  127. var width = 0;
  128. if (font.indexOf('mono') >= 0) {
  129. width = fontSize * text.length;
  130. }
  131. else {
  132. for (var i = 0; i < text.length; i++) {
  133. var preCalcWidth = DEFAULT_TEXT_WIDTH_MAP[text[i]];
  134. width += preCalcWidth == null ? fontSize : (preCalcWidth * fontSize);
  135. }
  136. }
  137. return { width: width };
  138. }
  139. };
  140. })(),
  141. loadImage: function (src, onload, onerror) {
  142. var image = new Image();
  143. image.onload = onload;
  144. image.onerror = onerror;
  145. image.src = src;
  146. return image;
  147. }
  148. };
  149. function setPlatformAPI(newPlatformApis) {
  150. for (var key in platformApi) {
  151. if (newPlatformApis[key]) {
  152. platformApi[key] = newPlatformApis[key];
  153. }
  154. }
  155. }
  156. var BUILTIN_OBJECT = reduce([
  157. 'Function',
  158. 'RegExp',
  159. 'Date',
  160. 'Error',
  161. 'CanvasGradient',
  162. 'CanvasPattern',
  163. 'Image',
  164. 'Canvas'
  165. ], function (obj, val) {
  166. obj['[object ' + val + ']'] = true;
  167. return obj;
  168. }, {});
  169. var TYPED_ARRAY = reduce([
  170. 'Int8',
  171. 'Uint8',
  172. 'Uint8Clamped',
  173. 'Int16',
  174. 'Uint16',
  175. 'Int32',
  176. 'Uint32',
  177. 'Float32',
  178. 'Float64'
  179. ], function (obj, val) {
  180. obj['[object ' + val + 'Array]'] = true;
  181. return obj;
  182. }, {});
  183. var objToString = Object.prototype.toString;
  184. var arrayProto = Array.prototype;
  185. var nativeForEach = arrayProto.forEach;
  186. var nativeFilter = arrayProto.filter;
  187. var nativeSlice = arrayProto.slice;
  188. var nativeMap = arrayProto.map;
  189. var ctorFunction = function () { }.constructor;
  190. var protoFunction = ctorFunction ? ctorFunction.prototype : null;
  191. var protoKey = '__proto__';
  192. var idStart = 0x0907;
  193. function guid() {
  194. return idStart++;
  195. }
  196. function logError() {
  197. var args = [];
  198. for (var _i = 0; _i < arguments.length; _i++) {
  199. args[_i] = arguments[_i];
  200. }
  201. if (typeof console !== 'undefined') {
  202. console.error.apply(console, args);
  203. }
  204. }
  205. function clone(source) {
  206. if (source == null || typeof source !== 'object') {
  207. return source;
  208. }
  209. var result = source;
  210. var typeStr = objToString.call(source);
  211. if (typeStr === '[object Array]') {
  212. if (!isPrimitive(source)) {
  213. result = [];
  214. for (var i = 0, len = source.length; i < len; i++) {
  215. result[i] = clone(source[i]);
  216. }
  217. }
  218. }
  219. else if (TYPED_ARRAY[typeStr]) {
  220. if (!isPrimitive(source)) {
  221. var Ctor = source.constructor;
  222. if (Ctor.from) {
  223. result = Ctor.from(source);
  224. }
  225. else {
  226. result = new Ctor(source.length);
  227. for (var i = 0, len = source.length; i < len; i++) {
  228. result[i] = source[i];
  229. }
  230. }
  231. }
  232. }
  233. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  234. result = {};
  235. for (var key in source) {
  236. if (source.hasOwnProperty(key) && key !== protoKey) {
  237. result[key] = clone(source[key]);
  238. }
  239. }
  240. }
  241. return result;
  242. }
  243. function merge(target, source, overwrite) {
  244. if (!isObject(source) || !isObject(target)) {
  245. return overwrite ? clone(source) : target;
  246. }
  247. for (var key in source) {
  248. if (source.hasOwnProperty(key) && key !== protoKey) {
  249. var targetProp = target[key];
  250. var sourceProp = source[key];
  251. if (isObject(sourceProp)
  252. && isObject(targetProp)
  253. && !isArray(sourceProp)
  254. && !isArray(targetProp)
  255. && !isDom(sourceProp)
  256. && !isDom(targetProp)
  257. && !isBuiltInObject(sourceProp)
  258. && !isBuiltInObject(targetProp)
  259. && !isPrimitive(sourceProp)
  260. && !isPrimitive(targetProp)) {
  261. merge(targetProp, sourceProp, overwrite);
  262. }
  263. else if (overwrite || !(key in target)) {
  264. target[key] = clone(source[key]);
  265. }
  266. }
  267. }
  268. return target;
  269. }
  270. function mergeAll(targetAndSources, overwrite) {
  271. var result = targetAndSources[0];
  272. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  273. result = merge(result, targetAndSources[i], overwrite);
  274. }
  275. return result;
  276. }
  277. function extend(target, source) {
  278. if (Object.assign) {
  279. Object.assign(target, source);
  280. }
  281. else {
  282. for (var key in source) {
  283. if (source.hasOwnProperty(key) && key !== protoKey) {
  284. target[key] = source[key];
  285. }
  286. }
  287. }
  288. return target;
  289. }
  290. function defaults(target, source, overlay) {
  291. var keysArr = keys(source);
  292. for (var i = 0, len = keysArr.length; i < len; i++) {
  293. var key = keysArr[i];
  294. if ((overlay ? source[key] != null : target[key] == null)) {
  295. target[key] = source[key];
  296. }
  297. }
  298. return target;
  299. }
  300. var createCanvas = platformApi.createCanvas;
  301. function indexOf(array, value) {
  302. if (array) {
  303. if (array.indexOf) {
  304. return array.indexOf(value);
  305. }
  306. for (var i = 0, len = array.length; i < len; i++) {
  307. if (array[i] === value) {
  308. return i;
  309. }
  310. }
  311. }
  312. return -1;
  313. }
  314. function inherits(clazz, baseClazz) {
  315. var clazzPrototype = clazz.prototype;
  316. function F() { }
  317. F.prototype = baseClazz.prototype;
  318. clazz.prototype = new F();
  319. for (var prop in clazzPrototype) {
  320. if (clazzPrototype.hasOwnProperty(prop)) {
  321. clazz.prototype[prop] = clazzPrototype[prop];
  322. }
  323. }
  324. clazz.prototype.constructor = clazz;
  325. clazz.superClass = baseClazz;
  326. }
  327. function mixin(target, source, override) {
  328. target = 'prototype' in target ? target.prototype : target;
  329. source = 'prototype' in source ? source.prototype : source;
  330. if (Object.getOwnPropertyNames) {
  331. var keyList = Object.getOwnPropertyNames(source);
  332. for (var i = 0; i < keyList.length; i++) {
  333. var key = keyList[i];
  334. if (key !== 'constructor') {
  335. if ((override ? source[key] != null : target[key] == null)) {
  336. target[key] = source[key];
  337. }
  338. }
  339. }
  340. }
  341. else {
  342. defaults(target, source, override);
  343. }
  344. }
  345. function isArrayLike(data) {
  346. if (!data) {
  347. return false;
  348. }
  349. if (typeof data === 'string') {
  350. return false;
  351. }
  352. return typeof data.length === 'number';
  353. }
  354. function each(arr, cb, context) {
  355. if (!(arr && cb)) {
  356. return;
  357. }
  358. if (arr.forEach && arr.forEach === nativeForEach) {
  359. arr.forEach(cb, context);
  360. }
  361. else if (arr.length === +arr.length) {
  362. for (var i = 0, len = arr.length; i < len; i++) {
  363. cb.call(context, arr[i], i, arr);
  364. }
  365. }
  366. else {
  367. for (var key in arr) {
  368. if (arr.hasOwnProperty(key)) {
  369. cb.call(context, arr[key], key, arr);
  370. }
  371. }
  372. }
  373. }
  374. function map(arr, cb, context) {
  375. if (!arr) {
  376. return [];
  377. }
  378. if (!cb) {
  379. return slice(arr);
  380. }
  381. if (arr.map && arr.map === nativeMap) {
  382. return arr.map(cb, context);
  383. }
  384. else {
  385. var result = [];
  386. for (var i = 0, len = arr.length; i < len; i++) {
  387. result.push(cb.call(context, arr[i], i, arr));
  388. }
  389. return result;
  390. }
  391. }
  392. function reduce(arr, cb, memo, context) {
  393. if (!(arr && cb)) {
  394. return;
  395. }
  396. for (var i = 0, len = arr.length; i < len; i++) {
  397. memo = cb.call(context, memo, arr[i], i, arr);
  398. }
  399. return memo;
  400. }
  401. function filter(arr, cb, context) {
  402. if (!arr) {
  403. return [];
  404. }
  405. if (!cb) {
  406. return slice(arr);
  407. }
  408. if (arr.filter && arr.filter === nativeFilter) {
  409. return arr.filter(cb, context);
  410. }
  411. else {
  412. var result = [];
  413. for (var i = 0, len = arr.length; i < len; i++) {
  414. if (cb.call(context, arr[i], i, arr)) {
  415. result.push(arr[i]);
  416. }
  417. }
  418. return result;
  419. }
  420. }
  421. function find(arr, cb, context) {
  422. if (!(arr && cb)) {
  423. return;
  424. }
  425. for (var i = 0, len = arr.length; i < len; i++) {
  426. if (cb.call(context, arr[i], i, arr)) {
  427. return arr[i];
  428. }
  429. }
  430. }
  431. function keys(obj) {
  432. if (!obj) {
  433. return [];
  434. }
  435. if (Object.keys) {
  436. return Object.keys(obj);
  437. }
  438. var keyList = [];
  439. for (var key in obj) {
  440. if (obj.hasOwnProperty(key)) {
  441. keyList.push(key);
  442. }
  443. }
  444. return keyList;
  445. }
  446. function bindPolyfill(func, context) {
  447. var args = [];
  448. for (var _i = 2; _i < arguments.length; _i++) {
  449. args[_i - 2] = arguments[_i];
  450. }
  451. return function () {
  452. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  453. };
  454. }
  455. var bind = (protoFunction && isFunction(protoFunction.bind))
  456. ? protoFunction.call.bind(protoFunction.bind)
  457. : bindPolyfill;
  458. function curry(func) {
  459. var args = [];
  460. for (var _i = 1; _i < arguments.length; _i++) {
  461. args[_i - 1] = arguments[_i];
  462. }
  463. return function () {
  464. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  465. };
  466. }
  467. function isArray(value) {
  468. if (Array.isArray) {
  469. return Array.isArray(value);
  470. }
  471. return objToString.call(value) === '[object Array]';
  472. }
  473. function isFunction(value) {
  474. return typeof value === 'function';
  475. }
  476. function isString(value) {
  477. return typeof value === 'string';
  478. }
  479. function isStringSafe(value) {
  480. return objToString.call(value) === '[object String]';
  481. }
  482. function isNumber(value) {
  483. return typeof value === 'number';
  484. }
  485. function isObject(value) {
  486. var type = typeof value;
  487. return type === 'function' || (!!value && type === 'object');
  488. }
  489. function isBuiltInObject(value) {
  490. return !!BUILTIN_OBJECT[objToString.call(value)];
  491. }
  492. function isTypedArray(value) {
  493. return !!TYPED_ARRAY[objToString.call(value)];
  494. }
  495. function isDom(value) {
  496. return typeof value === 'object'
  497. && typeof value.nodeType === 'number'
  498. && typeof value.ownerDocument === 'object';
  499. }
  500. function isGradientObject(value) {
  501. return value.colorStops != null;
  502. }
  503. function isImagePatternObject(value) {
  504. return value.image != null;
  505. }
  506. function isRegExp(value) {
  507. return objToString.call(value) === '[object RegExp]';
  508. }
  509. function eqNaN(value) {
  510. return value !== value;
  511. }
  512. function retrieve() {
  513. var args = [];
  514. for (var _i = 0; _i < arguments.length; _i++) {
  515. args[_i] = arguments[_i];
  516. }
  517. for (var i = 0, len = args.length; i < len; i++) {
  518. if (args[i] != null) {
  519. return args[i];
  520. }
  521. }
  522. }
  523. function retrieve2(value0, value1) {
  524. return value0 != null
  525. ? value0
  526. : value1;
  527. }
  528. function retrieve3(value0, value1, value2) {
  529. return value0 != null
  530. ? value0
  531. : value1 != null
  532. ? value1
  533. : value2;
  534. }
  535. function slice(arr) {
  536. var args = [];
  537. for (var _i = 1; _i < arguments.length; _i++) {
  538. args[_i - 1] = arguments[_i];
  539. }
  540. return nativeSlice.apply(arr, args);
  541. }
  542. function normalizeCssArray(val) {
  543. if (typeof (val) === 'number') {
  544. return [val, val, val, val];
  545. }
  546. var len = val.length;
  547. if (len === 2) {
  548. return [val[0], val[1], val[0], val[1]];
  549. }
  550. else if (len === 3) {
  551. return [val[0], val[1], val[2], val[1]];
  552. }
  553. return val;
  554. }
  555. function assert(condition, message) {
  556. if (!condition) {
  557. throw new Error(message);
  558. }
  559. }
  560. function trim(str) {
  561. if (str == null) {
  562. return null;
  563. }
  564. else if (typeof str.trim === 'function') {
  565. return str.trim();
  566. }
  567. else {
  568. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  569. }
  570. }
  571. var primitiveKey = '__ec_primitive__';
  572. function setAsPrimitive(obj) {
  573. obj[primitiveKey] = true;
  574. }
  575. function isPrimitive(obj) {
  576. return obj[primitiveKey];
  577. }
  578. var MapPolyfill = (function () {
  579. function MapPolyfill() {
  580. this.data = {};
  581. }
  582. MapPolyfill.prototype["delete"] = function (key) {
  583. var existed = this.has(key);
  584. if (existed) {
  585. delete this.data[key];
  586. }
  587. return existed;
  588. };
  589. MapPolyfill.prototype.has = function (key) {
  590. return this.data.hasOwnProperty(key);
  591. };
  592. MapPolyfill.prototype.get = function (key) {
  593. return this.data[key];
  594. };
  595. MapPolyfill.prototype.set = function (key, value) {
  596. this.data[key] = value;
  597. return this;
  598. };
  599. MapPolyfill.prototype.keys = function () {
  600. return keys(this.data);
  601. };
  602. MapPolyfill.prototype.forEach = function (callback) {
  603. var data = this.data;
  604. for (var key in data) {
  605. if (data.hasOwnProperty(key)) {
  606. callback(data[key], key);
  607. }
  608. }
  609. };
  610. return MapPolyfill;
  611. }());
  612. var isNativeMapSupported = typeof Map === 'function';
  613. function maybeNativeMap() {
  614. return (isNativeMapSupported ? new Map() : new MapPolyfill());
  615. }
  616. var HashMap = (function () {
  617. function HashMap(obj) {
  618. var isArr = isArray(obj);
  619. this.data = maybeNativeMap();
  620. var thisMap = this;
  621. (obj instanceof HashMap)
  622. ? obj.each(visit)
  623. : (obj && each(obj, visit));
  624. function visit(value, key) {
  625. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  626. }
  627. }
  628. HashMap.prototype.hasKey = function (key) {
  629. return this.data.has(key);
  630. };
  631. HashMap.prototype.get = function (key) {
  632. return this.data.get(key);
  633. };
  634. HashMap.prototype.set = function (key, value) {
  635. this.data.set(key, value);
  636. return value;
  637. };
  638. HashMap.prototype.each = function (cb, context) {
  639. this.data.forEach(function (value, key) {
  640. cb.call(context, value, key);
  641. });
  642. };
  643. HashMap.prototype.keys = function () {
  644. var keys = this.data.keys();
  645. return isNativeMapSupported
  646. ? Array.from(keys)
  647. : keys;
  648. };
  649. HashMap.prototype.removeKey = function (key) {
  650. this.data["delete"](key);
  651. };
  652. return HashMap;
  653. }());
  654. function createHashMap(obj) {
  655. return new HashMap(obj);
  656. }
  657. function concatArray(a, b) {
  658. var newArray = new a.constructor(a.length + b.length);
  659. for (var i = 0; i < a.length; i++) {
  660. newArray[i] = a[i];
  661. }
  662. var offset = a.length;
  663. for (var i = 0; i < b.length; i++) {
  664. newArray[i + offset] = b[i];
  665. }
  666. return newArray;
  667. }
  668. function createObject(proto, properties) {
  669. var obj;
  670. if (Object.create) {
  671. obj = Object.create(proto);
  672. }
  673. else {
  674. var StyleCtor = function () { };
  675. StyleCtor.prototype = proto;
  676. obj = new StyleCtor();
  677. }
  678. if (properties) {
  679. extend(obj, properties);
  680. }
  681. return obj;
  682. }
  683. function disableUserSelect(dom) {
  684. var domStyle = dom.style;
  685. domStyle.webkitUserSelect = 'none';
  686. domStyle.userSelect = 'none';
  687. domStyle.webkitTapHighlightColor = 'rgba(0,0,0,0)';
  688. domStyle['-webkit-touch-callout'] = 'none';
  689. }
  690. function hasOwn(own, prop) {
  691. return own.hasOwnProperty(prop);
  692. }
  693. function noop() { }
  694. var RADIAN_TO_DEGREE = 180 / Math.PI;
  695. var util = /*#__PURE__*/Object.freeze({
  696. __proto__: null,
  697. guid: guid,
  698. logError: logError,
  699. clone: clone,
  700. merge: merge,
  701. mergeAll: mergeAll,
  702. extend: extend,
  703. defaults: defaults,
  704. createCanvas: createCanvas,
  705. indexOf: indexOf,
  706. inherits: inherits,
  707. mixin: mixin,
  708. isArrayLike: isArrayLike,
  709. each: each,
  710. map: map,
  711. reduce: reduce,
  712. filter: filter,
  713. find: find,
  714. keys: keys,
  715. bind: bind,
  716. curry: curry,
  717. isArray: isArray,
  718. isFunction: isFunction,
  719. isString: isString,
  720. isStringSafe: isStringSafe,
  721. isNumber: isNumber,
  722. isObject: isObject,
  723. isBuiltInObject: isBuiltInObject,
  724. isTypedArray: isTypedArray,
  725. isDom: isDom,
  726. isGradientObject: isGradientObject,
  727. isImagePatternObject: isImagePatternObject,
  728. isRegExp: isRegExp,
  729. eqNaN: eqNaN,
  730. retrieve: retrieve,
  731. retrieve2: retrieve2,
  732. retrieve3: retrieve3,
  733. slice: slice,
  734. normalizeCssArray: normalizeCssArray,
  735. assert: assert,
  736. trim: trim,
  737. setAsPrimitive: setAsPrimitive,
  738. isPrimitive: isPrimitive,
  739. HashMap: HashMap,
  740. createHashMap: createHashMap,
  741. concatArray: concatArray,
  742. createObject: createObject,
  743. disableUserSelect: disableUserSelect,
  744. hasOwn: hasOwn,
  745. noop: noop,
  746. RADIAN_TO_DEGREE: RADIAN_TO_DEGREE
  747. });
  748. /*! *****************************************************************************
  749. Copyright (c) Microsoft Corporation. All rights reserved.
  750. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  751. this file except in compliance with the License. You may obtain a copy of the
  752. License at http://www.apache.org/licenses/LICENSE-2.0
  753. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  754. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  755. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  756. MERCHANTABLITY OR NON-INFRINGEMENT.
  757. See the Apache Version 2.0 License for specific language governing permissions
  758. and limitations under the License.
  759. ***************************************************************************** */
  760. /* global Reflect, Promise */
  761. var extendStatics = function(d, b) {
  762. extendStatics = Object.setPrototypeOf ||
  763. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  764. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  765. return extendStatics(d, b);
  766. };
  767. function __extends(d, b) {
  768. extendStatics(d, b);
  769. function __() { this.constructor = d; }
  770. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  771. }
  772. function create(x, y) {
  773. if (x == null) {
  774. x = 0;
  775. }
  776. if (y == null) {
  777. y = 0;
  778. }
  779. return [x, y];
  780. }
  781. function copy(out, v) {
  782. out[0] = v[0];
  783. out[1] = v[1];
  784. return out;
  785. }
  786. function clone$1(v) {
  787. return [v[0], v[1]];
  788. }
  789. function set(out, a, b) {
  790. out[0] = a;
  791. out[1] = b;
  792. return out;
  793. }
  794. function add(out, v1, v2) {
  795. out[0] = v1[0] + v2[0];
  796. out[1] = v1[1] + v2[1];
  797. return out;
  798. }
  799. function scaleAndAdd(out, v1, v2, a) {
  800. out[0] = v1[0] + v2[0] * a;
  801. out[1] = v1[1] + v2[1] * a;
  802. return out;
  803. }
  804. function sub(out, v1, v2) {
  805. out[0] = v1[0] - v2[0];
  806. out[1] = v1[1] - v2[1];
  807. return out;
  808. }
  809. function len(v) {
  810. return Math.sqrt(lenSquare(v));
  811. }
  812. var length = len;
  813. function lenSquare(v) {
  814. return v[0] * v[0] + v[1] * v[1];
  815. }
  816. var lengthSquare = lenSquare;
  817. function mul(out, v1, v2) {
  818. out[0] = v1[0] * v2[0];
  819. out[1] = v1[1] * v2[1];
  820. return out;
  821. }
  822. function div(out, v1, v2) {
  823. out[0] = v1[0] / v2[0];
  824. out[1] = v1[1] / v2[1];
  825. return out;
  826. }
  827. function dot(v1, v2) {
  828. return v1[0] * v2[0] + v1[1] * v2[1];
  829. }
  830. function scale(out, v, s) {
  831. out[0] = v[0] * s;
  832. out[1] = v[1] * s;
  833. return out;
  834. }
  835. function normalize(out, v) {
  836. var d = len(v);
  837. if (d === 0) {
  838. out[0] = 0;
  839. out[1] = 0;
  840. }
  841. else {
  842. out[0] = v[0] / d;
  843. out[1] = v[1] / d;
  844. }
  845. return out;
  846. }
  847. function distance(v1, v2) {
  848. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0])
  849. + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  850. }
  851. var dist = distance;
  852. function distanceSquare(v1, v2) {
  853. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  854. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  855. }
  856. var distSquare = distanceSquare;
  857. function negate(out, v) {
  858. out[0] = -v[0];
  859. out[1] = -v[1];
  860. return out;
  861. }
  862. function lerp(out, v1, v2, t) {
  863. out[0] = v1[0] + t * (v2[0] - v1[0]);
  864. out[1] = v1[1] + t * (v2[1] - v1[1]);
  865. return out;
  866. }
  867. function applyTransform(out, v, m) {
  868. var x = v[0];
  869. var y = v[1];
  870. out[0] = m[0] * x + m[2] * y + m[4];
  871. out[1] = m[1] * x + m[3] * y + m[5];
  872. return out;
  873. }
  874. function min(out, v1, v2) {
  875. out[0] = Math.min(v1[0], v2[0]);
  876. out[1] = Math.min(v1[1], v2[1]);
  877. return out;
  878. }
  879. function max(out, v1, v2) {
  880. out[0] = Math.max(v1[0], v2[0]);
  881. out[1] = Math.max(v1[1], v2[1]);
  882. return out;
  883. }
  884. var vector = /*#__PURE__*/Object.freeze({
  885. __proto__: null,
  886. create: create,
  887. copy: copy,
  888. clone: clone$1,
  889. set: set,
  890. add: add,
  891. scaleAndAdd: scaleAndAdd,
  892. sub: sub,
  893. len: len,
  894. length: length,
  895. lenSquare: lenSquare,
  896. lengthSquare: lengthSquare,
  897. mul: mul,
  898. div: div,
  899. dot: dot,
  900. scale: scale,
  901. normalize: normalize,
  902. distance: distance,
  903. dist: dist,
  904. distanceSquare: distanceSquare,
  905. distSquare: distSquare,
  906. negate: negate,
  907. lerp: lerp,
  908. applyTransform: applyTransform,
  909. min: min,
  910. max: max
  911. });
  912. var Param = (function () {
  913. function Param(target, e) {
  914. this.target = target;
  915. this.topTarget = e && e.topTarget;
  916. }
  917. return Param;
  918. }());
  919. var Draggable = (function () {
  920. function Draggable(handler) {
  921. this.handler = handler;
  922. handler.on('mousedown', this._dragStart, this);
  923. handler.on('mousemove', this._drag, this);
  924. handler.on('mouseup', this._dragEnd, this);
  925. }
  926. Draggable.prototype._dragStart = function (e) {
  927. var draggingTarget = e.target;
  928. while (draggingTarget && !draggingTarget.draggable) {
  929. draggingTarget = draggingTarget.parent || draggingTarget.__hostTarget;
  930. }
  931. if (draggingTarget) {
  932. this._draggingTarget = draggingTarget;
  933. draggingTarget.dragging = true;
  934. this._x = e.offsetX;
  935. this._y = e.offsetY;
  936. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragstart', e.event);
  937. }
  938. };
  939. Draggable.prototype._drag = function (e) {
  940. var draggingTarget = this._draggingTarget;
  941. if (draggingTarget) {
  942. var x = e.offsetX;
  943. var y = e.offsetY;
  944. var dx = x - this._x;
  945. var dy = y - this._y;
  946. this._x = x;
  947. this._y = y;
  948. draggingTarget.drift(dx, dy, e);
  949. this.handler.dispatchToElement(new Param(draggingTarget, e), 'drag', e.event);
  950. var dropTarget = this.handler.findHover(x, y, draggingTarget).target;
  951. var lastDropTarget = this._dropTarget;
  952. this._dropTarget = dropTarget;
  953. if (draggingTarget !== dropTarget) {
  954. if (lastDropTarget && dropTarget !== lastDropTarget) {
  955. this.handler.dispatchToElement(new Param(lastDropTarget, e), 'dragleave', e.event);
  956. }
  957. if (dropTarget && dropTarget !== lastDropTarget) {
  958. this.handler.dispatchToElement(new Param(dropTarget, e), 'dragenter', e.event);
  959. }
  960. }
  961. }
  962. };
  963. Draggable.prototype._dragEnd = function (e) {
  964. var draggingTarget = this._draggingTarget;
  965. if (draggingTarget) {
  966. draggingTarget.dragging = false;
  967. }
  968. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragend', e.event);
  969. if (this._dropTarget) {
  970. this.handler.dispatchToElement(new Param(this._dropTarget, e), 'drop', e.event);
  971. }
  972. this._draggingTarget = null;
  973. this._dropTarget = null;
  974. };
  975. return Draggable;
  976. }());
  977. var Eventful = (function () {
  978. function Eventful(eventProcessors) {
  979. if (eventProcessors) {
  980. this._$eventProcessor = eventProcessors;
  981. }
  982. }
  983. Eventful.prototype.on = function (event, query, handler, context) {
  984. if (!this._$handlers) {
  985. this._$handlers = {};
  986. }
  987. var _h = this._$handlers;
  988. if (typeof query === 'function') {
  989. context = handler;
  990. handler = query;
  991. query = null;
  992. }
  993. if (!handler || !event) {
  994. return this;
  995. }
  996. var eventProcessor = this._$eventProcessor;
  997. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  998. query = eventProcessor.normalizeQuery(query);
  999. }
  1000. if (!_h[event]) {
  1001. _h[event] = [];
  1002. }
  1003. for (var i = 0; i < _h[event].length; i++) {
  1004. if (_h[event][i].h === handler) {
  1005. return this;
  1006. }
  1007. }
  1008. var wrap = {
  1009. h: handler,
  1010. query: query,
  1011. ctx: (context || this),
  1012. callAtLast: handler.zrEventfulCallAtLast
  1013. };
  1014. var lastIndex = _h[event].length - 1;
  1015. var lastWrap = _h[event][lastIndex];
  1016. (lastWrap && lastWrap.callAtLast)
  1017. ? _h[event].splice(lastIndex, 0, wrap)
  1018. : _h[event].push(wrap);
  1019. return this;
  1020. };
  1021. Eventful.prototype.isSilent = function (eventName) {
  1022. var _h = this._$handlers;
  1023. return !_h || !_h[eventName] || !_h[eventName].length;
  1024. };
  1025. Eventful.prototype.off = function (eventType, handler) {
  1026. var _h = this._$handlers;
  1027. if (!_h) {
  1028. return this;
  1029. }
  1030. if (!eventType) {
  1031. this._$handlers = {};
  1032. return this;
  1033. }
  1034. if (handler) {
  1035. if (_h[eventType]) {
  1036. var newList = [];
  1037. for (var i = 0, l = _h[eventType].length; i < l; i++) {
  1038. if (_h[eventType][i].h !== handler) {
  1039. newList.push(_h[eventType][i]);
  1040. }
  1041. }
  1042. _h[eventType] = newList;
  1043. }
  1044. if (_h[eventType] && _h[eventType].length === 0) {
  1045. delete _h[eventType];
  1046. }
  1047. }
  1048. else {
  1049. delete _h[eventType];
  1050. }
  1051. return this;
  1052. };
  1053. Eventful.prototype.trigger = function (eventType) {
  1054. var args = [];
  1055. for (var _i = 1; _i < arguments.length; _i++) {
  1056. args[_i - 1] = arguments[_i];
  1057. }
  1058. if (!this._$handlers) {
  1059. return this;
  1060. }
  1061. var _h = this._$handlers[eventType];
  1062. var eventProcessor = this._$eventProcessor;
  1063. if (_h) {
  1064. var argLen = args.length;
  1065. var len = _h.length;
  1066. for (var i = 0; i < len; i++) {
  1067. var hItem = _h[i];
  1068. if (eventProcessor
  1069. && eventProcessor.filter
  1070. && hItem.query != null
  1071. && !eventProcessor.filter(eventType, hItem.query)) {
  1072. continue;
  1073. }
  1074. switch (argLen) {
  1075. case 0:
  1076. hItem.h.call(hItem.ctx);
  1077. break;
  1078. case 1:
  1079. hItem.h.call(hItem.ctx, args[0]);
  1080. break;
  1081. case 2:
  1082. hItem.h.call(hItem.ctx, args[0], args[1]);
  1083. break;
  1084. default:
  1085. hItem.h.apply(hItem.ctx, args);
  1086. break;
  1087. }
  1088. }
  1089. }
  1090. eventProcessor && eventProcessor.afterTrigger
  1091. && eventProcessor.afterTrigger(eventType);
  1092. return this;
  1093. };
  1094. Eventful.prototype.triggerWithContext = function (type) {
  1095. var args = [];
  1096. for (var _i = 1; _i < arguments.length; _i++) {
  1097. args[_i - 1] = arguments[_i];
  1098. }
  1099. if (!this._$handlers) {
  1100. return this;
  1101. }
  1102. var _h = this._$handlers[type];
  1103. var eventProcessor = this._$eventProcessor;
  1104. if (_h) {
  1105. var argLen = args.length;
  1106. var ctx = args[argLen - 1];
  1107. var len = _h.length;
  1108. for (var i = 0; i < len; i++) {
  1109. var hItem = _h[i];
  1110. if (eventProcessor
  1111. && eventProcessor.filter
  1112. && hItem.query != null
  1113. && !eventProcessor.filter(type, hItem.query)) {
  1114. continue;
  1115. }
  1116. switch (argLen) {
  1117. case 0:
  1118. hItem.h.call(ctx);
  1119. break;
  1120. case 1:
  1121. hItem.h.call(ctx, args[0]);
  1122. break;
  1123. case 2:
  1124. hItem.h.call(ctx, args[0], args[1]);
  1125. break;
  1126. default:
  1127. hItem.h.apply(ctx, args.slice(1, argLen - 1));
  1128. break;
  1129. }
  1130. }
  1131. }
  1132. eventProcessor && eventProcessor.afterTrigger
  1133. && eventProcessor.afterTrigger(type);
  1134. return this;
  1135. };
  1136. return Eventful;
  1137. }());
  1138. var LN2 = Math.log(2);
  1139. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1140. var cacheKey = rowMask + '-' + colMask;
  1141. var fullRank = rows.length;
  1142. if (detCache.hasOwnProperty(cacheKey)) {
  1143. return detCache[cacheKey];
  1144. }
  1145. if (rank === 1) {
  1146. var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);
  1147. return rows[rowStart][colStart];
  1148. }
  1149. var subRowMask = rowMask | (1 << rowStart);
  1150. var subRowStart = rowStart + 1;
  1151. while (rowMask & (1 << subRowStart)) {
  1152. subRowStart++;
  1153. }
  1154. var sum = 0;
  1155. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1156. var colTag = 1 << j;
  1157. if (!(colTag & colMask)) {
  1158. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]
  1159. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1160. colLocalIdx++;
  1161. }
  1162. }
  1163. detCache[cacheKey] = sum;
  1164. return sum;
  1165. }
  1166. function buildTransformer(src, dest) {
  1167. var mA = [
  1168. [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],
  1169. [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],
  1170. [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],
  1171. [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],
  1172. [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],
  1173. [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],
  1174. [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],
  1175. [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]
  1176. ];
  1177. var detCache = {};
  1178. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1179. if (det === 0) {
  1180. return;
  1181. }
  1182. var vh = [];
  1183. for (var i = 0; i < 8; i++) {
  1184. for (var j = 0; j < 8; j++) {
  1185. vh[j] == null && (vh[j] = 0);
  1186. vh[j] += ((i + j) % 2 ? -1 : 1)
  1187. * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)
  1188. / det * dest[i];
  1189. }
  1190. }
  1191. return function (out, srcPointX, srcPointY) {
  1192. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1193. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1194. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1195. };
  1196. }
  1197. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1198. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1199. if (el.getBoundingClientRect && env.domSupported && !isCanvasEl(el)) {
  1200. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1201. var markers = prepareCoordMarkers(el, saved);
  1202. var transformer = preparePointerTransformer(markers, saved, inverse);
  1203. if (transformer) {
  1204. transformer(out, inX, inY);
  1205. return true;
  1206. }
  1207. }
  1208. return false;
  1209. }
  1210. function prepareCoordMarkers(el, saved) {
  1211. var markers = saved.markers;
  1212. if (markers) {
  1213. return markers;
  1214. }
  1215. markers = saved.markers = [];
  1216. var propLR = ['left', 'right'];
  1217. var propTB = ['top', 'bottom'];
  1218. for (var i = 0; i < 4; i++) {
  1219. var marker = document.createElement('div');
  1220. var stl = marker.style;
  1221. var idxLR = i % 2;
  1222. var idxTB = (i >> 1) % 2;
  1223. stl.cssText = [
  1224. 'position: absolute',
  1225. 'visibility: hidden',
  1226. 'padding: 0',
  1227. 'margin: 0',
  1228. 'border-width: 0',
  1229. 'user-select: none',
  1230. 'width:0',
  1231. 'height:0',
  1232. propLR[idxLR] + ':0',
  1233. propTB[idxTB] + ':0',
  1234. propLR[1 - idxLR] + ':auto',
  1235. propTB[1 - idxTB] + ':auto',
  1236. ''
  1237. ].join('!important;');
  1238. el.appendChild(marker);
  1239. markers.push(marker);
  1240. }
  1241. return markers;
  1242. }
  1243. function preparePointerTransformer(markers, saved, inverse) {
  1244. var transformerName = inverse ? 'invTrans' : 'trans';
  1245. var transformer = saved[transformerName];
  1246. var oldSrcCoords = saved.srcCoords;
  1247. var srcCoords = [];
  1248. var destCoords = [];
  1249. var oldCoordTheSame = true;
  1250. for (var i = 0; i < 4; i++) {
  1251. var rect = markers[i].getBoundingClientRect();
  1252. var ii = 2 * i;
  1253. var x = rect.left;
  1254. var y = rect.top;
  1255. srcCoords.push(x, y);
  1256. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1257. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1258. }
  1259. return (oldCoordTheSame && transformer)
  1260. ? transformer
  1261. : (saved.srcCoords = srcCoords,
  1262. saved[transformerName] = inverse
  1263. ? buildTransformer(destCoords, srcCoords)
  1264. : buildTransformer(srcCoords, destCoords));
  1265. }
  1266. function isCanvasEl(el) {
  1267. return el.nodeName.toUpperCase() === 'CANVAS';
  1268. }
  1269. var replaceReg = /([&<>"'])/g;
  1270. var replaceMap = {
  1271. '&': '&amp;',
  1272. '<': '&lt;',
  1273. '>': '&gt;',
  1274. '"': '&quot;',
  1275. '\'': '&#39;'
  1276. };
  1277. function encodeHTML(source) {
  1278. return source == null
  1279. ? ''
  1280. : (source + '').replace(replaceReg, function (str, c) {
  1281. return replaceMap[c];
  1282. });
  1283. }
  1284. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1285. var _calcOut = [];
  1286. var firefoxNotSupportOffsetXY = env.browser.firefox
  1287. && +env.browser.version.split('.')[0] < 39;
  1288. function clientToLocal(el, e, out, calculate) {
  1289. out = out || {};
  1290. if (calculate) {
  1291. calculateZrXY(el, e, out);
  1292. }
  1293. else if (firefoxNotSupportOffsetXY
  1294. && e.layerX != null
  1295. && e.layerX !== e.offsetX) {
  1296. out.zrX = e.layerX;
  1297. out.zrY = e.layerY;
  1298. }
  1299. else if (e.offsetX != null) {
  1300. out.zrX = e.offsetX;
  1301. out.zrY = e.offsetY;
  1302. }
  1303. else {
  1304. calculateZrXY(el, e, out);
  1305. }
  1306. return out;
  1307. }
  1308. function calculateZrXY(el, e, out) {
  1309. if (env.domSupported && el.getBoundingClientRect) {
  1310. var ex = e.clientX;
  1311. var ey = e.clientY;
  1312. if (isCanvasEl(el)) {
  1313. var box = el.getBoundingClientRect();
  1314. out.zrX = ex - box.left;
  1315. out.zrY = ey - box.top;
  1316. return;
  1317. }
  1318. else {
  1319. if (transformCoordWithViewport(_calcOut, el, ex, ey)) {
  1320. out.zrX = _calcOut[0];
  1321. out.zrY = _calcOut[1];
  1322. return;
  1323. }
  1324. }
  1325. }
  1326. out.zrX = out.zrY = 0;
  1327. }
  1328. function getNativeEvent(e) {
  1329. return e
  1330. || window.event;
  1331. }
  1332. function normalizeEvent(el, e, calculate) {
  1333. e = getNativeEvent(e);
  1334. if (e.zrX != null) {
  1335. return e;
  1336. }
  1337. var eventType = e.type;
  1338. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1339. if (!isTouch) {
  1340. clientToLocal(el, e, e, calculate);
  1341. var wheelDelta = getWheelDeltaMayPolyfill(e);
  1342. e.zrDelta = wheelDelta ? wheelDelta / 120 : -(e.detail || 0) / 3;
  1343. }
  1344. else {
  1345. var touch = eventType !== 'touchend'
  1346. ? e.targetTouches[0]
  1347. : e.changedTouches[0];
  1348. touch && clientToLocal(el, touch, e, calculate);
  1349. }
  1350. var button = e.button;
  1351. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1352. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1353. }
  1354. return e;
  1355. }
  1356. function getWheelDeltaMayPolyfill(e) {
  1357. var rawWheelDelta = e.wheelDelta;
  1358. if (rawWheelDelta) {
  1359. return rawWheelDelta;
  1360. }
  1361. var deltaX = e.deltaX;
  1362. var deltaY = e.deltaY;
  1363. if (deltaX == null || deltaY == null) {
  1364. return rawWheelDelta;
  1365. }
  1366. var delta = deltaY !== 0 ? Math.abs(deltaY) : Math.abs(deltaX);
  1367. var sign = deltaY > 0 ? -1
  1368. : deltaY < 0 ? 1
  1369. : deltaX > 0 ? -1
  1370. : 1;
  1371. return 3 * delta * sign;
  1372. }
  1373. function addEventListener(el, name, handler, opt) {
  1374. el.addEventListener(name, handler, opt);
  1375. }
  1376. function removeEventListener(el, name, handler, opt) {
  1377. el.removeEventListener(name, handler, opt);
  1378. }
  1379. var stop = function (e) {
  1380. e.preventDefault();
  1381. e.stopPropagation();
  1382. e.cancelBubble = true;
  1383. };
  1384. var GestureMgr = (function () {
  1385. function GestureMgr() {
  1386. this._track = [];
  1387. }
  1388. GestureMgr.prototype.recognize = function (event, target, root) {
  1389. this._doTrack(event, target, root);
  1390. return this._recognize(event);
  1391. };
  1392. GestureMgr.prototype.clear = function () {
  1393. this._track.length = 0;
  1394. return this;
  1395. };
  1396. GestureMgr.prototype._doTrack = function (event, target, root) {
  1397. var touches = event.touches;
  1398. if (!touches) {
  1399. return;
  1400. }
  1401. var trackItem = {
  1402. points: [],
  1403. touches: [],
  1404. target: target,
  1405. event: event
  1406. };
  1407. for (var i = 0, len = touches.length; i < len; i++) {
  1408. var touch = touches[i];
  1409. var pos = clientToLocal(root, touch, {});
  1410. trackItem.points.push([pos.zrX, pos.zrY]);
  1411. trackItem.touches.push(touch);
  1412. }
  1413. this._track.push(trackItem);
  1414. };
  1415. GestureMgr.prototype._recognize = function (event) {
  1416. for (var eventName in recognizers) {
  1417. if (recognizers.hasOwnProperty(eventName)) {
  1418. var gestureInfo = recognizers[eventName](this._track, event);
  1419. if (gestureInfo) {
  1420. return gestureInfo;
  1421. }
  1422. }
  1423. }
  1424. };
  1425. return GestureMgr;
  1426. }());
  1427. function dist$1(pointPair) {
  1428. var dx = pointPair[1][0] - pointPair[0][0];
  1429. var dy = pointPair[1][1] - pointPair[0][1];
  1430. return Math.sqrt(dx * dx + dy * dy);
  1431. }
  1432. function center(pointPair) {
  1433. return [
  1434. (pointPair[0][0] + pointPair[1][0]) / 2,
  1435. (pointPair[0][1] + pointPair[1][1]) / 2
  1436. ];
  1437. }
  1438. var recognizers = {
  1439. pinch: function (tracks, event) {
  1440. var trackLen = tracks.length;
  1441. if (!trackLen) {
  1442. return;
  1443. }
  1444. var pinchEnd = (tracks[trackLen - 1] || {}).points;
  1445. var pinchPre = (tracks[trackLen - 2] || {}).points || pinchEnd;
  1446. if (pinchPre
  1447. && pinchPre.length > 1
  1448. && pinchEnd
  1449. && pinchEnd.length > 1) {
  1450. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1451. !isFinite(pinchScale) && (pinchScale = 1);
  1452. event.pinchScale = pinchScale;
  1453. var pinchCenter = center(pinchEnd);
  1454. event.pinchX = pinchCenter[0];
  1455. event.pinchY = pinchCenter[1];
  1456. return {
  1457. type: 'pinch',
  1458. target: tracks[0].target,
  1459. event: event
  1460. };
  1461. }
  1462. }
  1463. };
  1464. function create$1() {
  1465. return [1, 0, 0, 1, 0, 0];
  1466. }
  1467. function identity(out) {
  1468. out[0] = 1;
  1469. out[1] = 0;
  1470. out[2] = 0;
  1471. out[3] = 1;
  1472. out[4] = 0;
  1473. out[5] = 0;
  1474. return out;
  1475. }
  1476. function copy$1(out, m) {
  1477. out[0] = m[0];
  1478. out[1] = m[1];
  1479. out[2] = m[2];
  1480. out[3] = m[3];
  1481. out[4] = m[4];
  1482. out[5] = m[5];
  1483. return out;
  1484. }
  1485. function mul$1(out, m1, m2) {
  1486. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  1487. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  1488. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  1489. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  1490. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1491. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1492. out[0] = out0;
  1493. out[1] = out1;
  1494. out[2] = out2;
  1495. out[3] = out3;
  1496. out[4] = out4;
  1497. out[5] = out5;
  1498. return out;
  1499. }
  1500. function translate(out, a, v) {
  1501. out[0] = a[0];
  1502. out[1] = a[1];
  1503. out[2] = a[2];
  1504. out[3] = a[3];
  1505. out[4] = a[4] + v[0];
  1506. out[5] = a[5] + v[1];
  1507. return out;
  1508. }
  1509. function rotate(out, a, rad, pivot) {
  1510. if (pivot === void 0) { pivot = [0, 0]; }
  1511. var aa = a[0];
  1512. var ac = a[2];
  1513. var atx = a[4];
  1514. var ab = a[1];
  1515. var ad = a[3];
  1516. var aty = a[5];
  1517. var st = Math.sin(rad);
  1518. var ct = Math.cos(rad);
  1519. out[0] = aa * ct + ab * st;
  1520. out[1] = -aa * st + ab * ct;
  1521. out[2] = ac * ct + ad * st;
  1522. out[3] = -ac * st + ct * ad;
  1523. out[4] = ct * (atx - pivot[0]) + st * (aty - pivot[1]) + pivot[0];
  1524. out[5] = ct * (aty - pivot[1]) - st * (atx - pivot[0]) + pivot[1];
  1525. return out;
  1526. }
  1527. function scale$1(out, a, v) {
  1528. var vx = v[0];
  1529. var vy = v[1];
  1530. out[0] = a[0] * vx;
  1531. out[1] = a[1] * vy;
  1532. out[2] = a[2] * vx;
  1533. out[3] = a[3] * vy;
  1534. out[4] = a[4] * vx;
  1535. out[5] = a[5] * vy;
  1536. return out;
  1537. }
  1538. function invert(out, a) {
  1539. var aa = a[0];
  1540. var ac = a[2];
  1541. var atx = a[4];
  1542. var ab = a[1];
  1543. var ad = a[3];
  1544. var aty = a[5];
  1545. var det = aa * ad - ab * ac;
  1546. if (!det) {
  1547. return null;
  1548. }
  1549. det = 1.0 / det;
  1550. out[0] = ad * det;
  1551. out[1] = -ab * det;
  1552. out[2] = -ac * det;
  1553. out[3] = aa * det;
  1554. out[4] = (ac * aty - ad * atx) * det;
  1555. out[5] = (ab * atx - aa * aty) * det;
  1556. return out;
  1557. }
  1558. function clone$2(a) {
  1559. var b = create$1();
  1560. copy$1(b, a);
  1561. return b;
  1562. }
  1563. var matrix = /*#__PURE__*/Object.freeze({
  1564. __proto__: null,
  1565. create: create$1,
  1566. identity: identity,
  1567. copy: copy$1,
  1568. mul: mul$1,
  1569. translate: translate,
  1570. rotate: rotate,
  1571. scale: scale$1,
  1572. invert: invert,
  1573. clone: clone$2
  1574. });
  1575. var Point = (function () {
  1576. function Point(x, y) {
  1577. this.x = x || 0;
  1578. this.y = y || 0;
  1579. }
  1580. Point.prototype.copy = function (other) {
  1581. this.x = other.x;
  1582. this.y = other.y;
  1583. return this;
  1584. };
  1585. Point.prototype.clone = function () {
  1586. return new Point(this.x, this.y);
  1587. };
  1588. Point.prototype.set = function (x, y) {
  1589. this.x = x;
  1590. this.y = y;
  1591. return this;
  1592. };
  1593. Point.prototype.equal = function (other) {
  1594. return other.x === this.x && other.y === this.y;
  1595. };
  1596. Point.prototype.add = function (other) {
  1597. this.x += other.x;
  1598. this.y += other.y;
  1599. return this;
  1600. };
  1601. Point.prototype.scale = function (scalar) {
  1602. this.x *= scalar;
  1603. this.y *= scalar;
  1604. };
  1605. Point.prototype.scaleAndAdd = function (other, scalar) {
  1606. this.x += other.x * scalar;
  1607. this.y += other.y * scalar;
  1608. };
  1609. Point.prototype.sub = function (other) {
  1610. this.x -= other.x;
  1611. this.y -= other.y;
  1612. return this;
  1613. };
  1614. Point.prototype.dot = function (other) {
  1615. return this.x * other.x + this.y * other.y;
  1616. };
  1617. Point.prototype.len = function () {
  1618. return Math.sqrt(this.x * this.x + this.y * this.y);
  1619. };
  1620. Point.prototype.lenSquare = function () {
  1621. return this.x * this.x + this.y * this.y;
  1622. };
  1623. Point.prototype.normalize = function () {
  1624. var len = this.len();
  1625. this.x /= len;
  1626. this.y /= len;
  1627. return this;
  1628. };
  1629. Point.prototype.distance = function (other) {
  1630. var dx = this.x - other.x;
  1631. var dy = this.y - other.y;
  1632. return Math.sqrt(dx * dx + dy * dy);
  1633. };
  1634. Point.prototype.distanceSquare = function (other) {
  1635. var dx = this.x - other.x;
  1636. var dy = this.y - other.y;
  1637. return dx * dx + dy * dy;
  1638. };
  1639. Point.prototype.negate = function () {
  1640. this.x = -this.x;
  1641. this.y = -this.y;
  1642. return this;
  1643. };
  1644. Point.prototype.transform = function (m) {
  1645. if (!m) {
  1646. return;
  1647. }
  1648. var x = this.x;
  1649. var y = this.y;
  1650. this.x = m[0] * x + m[2] * y + m[4];
  1651. this.y = m[1] * x + m[3] * y + m[5];
  1652. return this;
  1653. };
  1654. Point.prototype.toArray = function (out) {
  1655. out[0] = this.x;
  1656. out[1] = this.y;
  1657. return out;
  1658. };
  1659. Point.prototype.fromArray = function (input) {
  1660. this.x = input[0];
  1661. this.y = input[1];
  1662. };
  1663. Point.set = function (p, x, y) {
  1664. p.x = x;
  1665. p.y = y;
  1666. };
  1667. Point.copy = function (p, p2) {
  1668. p.x = p2.x;
  1669. p.y = p2.y;
  1670. };
  1671. Point.len = function (p) {
  1672. return Math.sqrt(p.x * p.x + p.y * p.y);
  1673. };
  1674. Point.lenSquare = function (p) {
  1675. return p.x * p.x + p.y * p.y;
  1676. };
  1677. Point.dot = function (p0, p1) {
  1678. return p0.x * p1.x + p0.y * p1.y;
  1679. };
  1680. Point.add = function (out, p0, p1) {
  1681. out.x = p0.x + p1.x;
  1682. out.y = p0.y + p1.y;
  1683. };
  1684. Point.sub = function (out, p0, p1) {
  1685. out.x = p0.x - p1.x;
  1686. out.y = p0.y - p1.y;
  1687. };
  1688. Point.scale = function (out, p0, scalar) {
  1689. out.x = p0.x * scalar;
  1690. out.y = p0.y * scalar;
  1691. };
  1692. Point.scaleAndAdd = function (out, p0, p1, scalar) {
  1693. out.x = p0.x + p1.x * scalar;
  1694. out.y = p0.y + p1.y * scalar;
  1695. };
  1696. Point.lerp = function (out, p0, p1, t) {
  1697. var onet = 1 - t;
  1698. out.x = onet * p0.x + t * p1.x;
  1699. out.y = onet * p0.y + t * p1.y;
  1700. };
  1701. return Point;
  1702. }());
  1703. var mathMin = Math.min;
  1704. var mathMax = Math.max;
  1705. var lt = new Point();
  1706. var rb = new Point();
  1707. var lb = new Point();
  1708. var rt = new Point();
  1709. var minTv = new Point();
  1710. var maxTv = new Point();
  1711. var BoundingRect = (function () {
  1712. function BoundingRect(x, y, width, height) {
  1713. if (width < 0) {
  1714. x = x + width;
  1715. width = -width;
  1716. }
  1717. if (height < 0) {
  1718. y = y + height;
  1719. height = -height;
  1720. }
  1721. this.x = x;
  1722. this.y = y;
  1723. this.width = width;
  1724. this.height = height;
  1725. }
  1726. BoundingRect.prototype.union = function (other) {
  1727. var x = mathMin(other.x, this.x);
  1728. var y = mathMin(other.y, this.y);
  1729. if (isFinite(this.x) && isFinite(this.width)) {
  1730. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  1731. }
  1732. else {
  1733. this.width = other.width;
  1734. }
  1735. if (isFinite(this.y) && isFinite(this.height)) {
  1736. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  1737. }
  1738. else {
  1739. this.height = other.height;
  1740. }
  1741. this.x = x;
  1742. this.y = y;
  1743. };
  1744. BoundingRect.prototype.applyTransform = function (m) {
  1745. BoundingRect.applyTransform(this, this, m);
  1746. };
  1747. BoundingRect.prototype.calculateTransform = function (b) {
  1748. var a = this;
  1749. var sx = b.width / a.width;
  1750. var sy = b.height / a.height;
  1751. var m = create$1();
  1752. translate(m, m, [-a.x, -a.y]);
  1753. scale$1(m, m, [sx, sy]);
  1754. translate(m, m, [b.x, b.y]);
  1755. return m;
  1756. };
  1757. BoundingRect.prototype.intersect = function (b, mtv) {
  1758. if (!b) {
  1759. return false;
  1760. }
  1761. if (!(b instanceof BoundingRect)) {
  1762. b = BoundingRect.create(b);
  1763. }
  1764. var a = this;
  1765. var ax0 = a.x;
  1766. var ax1 = a.x + a.width;
  1767. var ay0 = a.y;
  1768. var ay1 = a.y + a.height;
  1769. var bx0 = b.x;
  1770. var bx1 = b.x + b.width;
  1771. var by0 = b.y;
  1772. var by1 = b.y + b.height;
  1773. var overlap = !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  1774. if (mtv) {
  1775. var dMin = Infinity;
  1776. var dMax = 0;
  1777. var d0 = Math.abs(ax1 - bx0);
  1778. var d1 = Math.abs(bx1 - ax0);
  1779. var d2 = Math.abs(ay1 - by0);
  1780. var d3 = Math.abs(by1 - ay0);
  1781. var dx = Math.min(d0, d1);
  1782. var dy = Math.min(d2, d3);
  1783. if (ax1 < bx0 || bx1 < ax0) {
  1784. if (dx > dMax) {
  1785. dMax = dx;
  1786. if (d0 < d1) {
  1787. Point.set(maxTv, -d0, 0);
  1788. }
  1789. else {
  1790. Point.set(maxTv, d1, 0);
  1791. }
  1792. }
  1793. }
  1794. else {
  1795. if (dx < dMin) {
  1796. dMin = dx;
  1797. if (d0 < d1) {
  1798. Point.set(minTv, d0, 0);
  1799. }
  1800. else {
  1801. Point.set(minTv, -d1, 0);
  1802. }
  1803. }
  1804. }
  1805. if (ay1 < by0 || by1 < ay0) {
  1806. if (dy > dMax) {
  1807. dMax = dy;
  1808. if (d2 < d3) {
  1809. Point.set(maxTv, 0, -d2);
  1810. }
  1811. else {
  1812. Point.set(maxTv, 0, d3);
  1813. }
  1814. }
  1815. }
  1816. else {
  1817. if (dx < dMin) {
  1818. dMin = dx;
  1819. if (d2 < d3) {
  1820. Point.set(minTv, 0, d2);
  1821. }
  1822. else {
  1823. Point.set(minTv, 0, -d3);
  1824. }
  1825. }
  1826. }
  1827. }
  1828. if (mtv) {
  1829. Point.copy(mtv, overlap ? minTv : maxTv);
  1830. }
  1831. return overlap;
  1832. };
  1833. BoundingRect.prototype.contain = function (x, y) {
  1834. var rect = this;
  1835. return x >= rect.x
  1836. && x <= (rect.x + rect.width)
  1837. && y >= rect.y
  1838. && y <= (rect.y + rect.height);
  1839. };
  1840. BoundingRect.prototype.clone = function () {
  1841. return new BoundingRect(this.x, this.y, this.width, this.height);
  1842. };
  1843. BoundingRect.prototype.copy = function (other) {
  1844. BoundingRect.copy(this, other);
  1845. };
  1846. BoundingRect.prototype.plain = function () {
  1847. return {
  1848. x: this.x,
  1849. y: this.y,
  1850. width: this.width,
  1851. height: this.height
  1852. };
  1853. };
  1854. BoundingRect.prototype.isFinite = function () {
  1855. return isFinite(this.x)
  1856. && isFinite(this.y)
  1857. && isFinite(this.width)
  1858. && isFinite(this.height);
  1859. };
  1860. BoundingRect.prototype.isZero = function () {
  1861. return this.width === 0 || this.height === 0;
  1862. };
  1863. BoundingRect.create = function (rect) {
  1864. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  1865. };
  1866. BoundingRect.copy = function (target, source) {
  1867. target.x = source.x;
  1868. target.y = source.y;
  1869. target.width = source.width;
  1870. target.height = source.height;
  1871. };
  1872. BoundingRect.applyTransform = function (target, source, m) {
  1873. if (!m) {
  1874. if (target !== source) {
  1875. BoundingRect.copy(target, source);
  1876. }
  1877. return;
  1878. }
  1879. if (m[1] < 1e-5 && m[1] > -1e-5 && m[2] < 1e-5 && m[2] > -1e-5) {
  1880. var sx = m[0];
  1881. var sy = m[3];
  1882. var tx = m[4];
  1883. var ty = m[5];
  1884. target.x = source.x * sx + tx;
  1885. target.y = source.y * sy + ty;
  1886. target.width = source.width * sx;
  1887. target.height = source.height * sy;
  1888. if (target.width < 0) {
  1889. target.x += target.width;
  1890. target.width = -target.width;
  1891. }
  1892. if (target.height < 0) {
  1893. target.y += target.height;
  1894. target.height = -target.height;
  1895. }
  1896. return;
  1897. }
  1898. lt.x = lb.x = source.x;
  1899. lt.y = rt.y = source.y;
  1900. rb.x = rt.x = source.x + source.width;
  1901. rb.y = lb.y = source.y + source.height;
  1902. lt.transform(m);
  1903. rt.transform(m);
  1904. rb.transform(m);
  1905. lb.transform(m);
  1906. target.x = mathMin(lt.x, rb.x, lb.x, rt.x);
  1907. target.y = mathMin(lt.y, rb.y, lb.y, rt.y);
  1908. var maxX = mathMax(lt.x, rb.x, lb.x, rt.x);
  1909. var maxY = mathMax(lt.y, rb.y, lb.y, rt.y);
  1910. target.width = maxX - target.x;
  1911. target.height = maxY - target.y;
  1912. };
  1913. return BoundingRect;
  1914. }());
  1915. var SILENT = 'silent';
  1916. function makeEventPacket(eveType, targetInfo, event) {
  1917. return {
  1918. type: eveType,
  1919. event: event,
  1920. target: targetInfo.target,
  1921. topTarget: targetInfo.topTarget,
  1922. cancelBubble: false,
  1923. offsetX: event.zrX,
  1924. offsetY: event.zrY,
  1925. gestureEvent: event.gestureEvent,
  1926. pinchX: event.pinchX,
  1927. pinchY: event.pinchY,
  1928. pinchScale: event.pinchScale,
  1929. wheelDelta: event.zrDelta,
  1930. zrByTouch: event.zrByTouch,
  1931. which: event.which,
  1932. stop: stopEvent
  1933. };
  1934. }
  1935. function stopEvent() {
  1936. stop(this.event);
  1937. }
  1938. var EmptyProxy = (function (_super) {
  1939. __extends(EmptyProxy, _super);
  1940. function EmptyProxy() {
  1941. var _this = _super !== null && _super.apply(this, arguments) || this;
  1942. _this.handler = null;
  1943. return _this;
  1944. }
  1945. EmptyProxy.prototype.dispose = function () { };
  1946. EmptyProxy.prototype.setCursor = function () { };
  1947. return EmptyProxy;
  1948. }(Eventful));
  1949. var HoveredResult = (function () {
  1950. function HoveredResult(x, y) {
  1951. this.x = x;
  1952. this.y = y;
  1953. }
  1954. return HoveredResult;
  1955. }());
  1956. var handlerNames = [
  1957. 'click', 'dblclick', 'mousewheel', 'mouseout',
  1958. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  1959. ];
  1960. var tmpRect = new BoundingRect(0, 0, 0, 0);
  1961. var Handler = (function (_super) {
  1962. __extends(Handler, _super);
  1963. function Handler(storage, painter, proxy, painterRoot, pointerSize) {
  1964. var _this = _super.call(this) || this;
  1965. _this._hovered = new HoveredResult(0, 0);
  1966. _this.storage = storage;
  1967. _this.painter = painter;
  1968. _this.painterRoot = painterRoot;
  1969. _this._pointerSize = pointerSize;
  1970. proxy = proxy || new EmptyProxy();
  1971. _this.proxy = null;
  1972. _this.setHandlerProxy(proxy);
  1973. _this._draggingMgr = new Draggable(_this);
  1974. return _this;
  1975. }
  1976. Handler.prototype.setHandlerProxy = function (proxy) {
  1977. if (this.proxy) {
  1978. this.proxy.dispose();
  1979. }
  1980. if (proxy) {
  1981. each(handlerNames, function (name) {
  1982. proxy.on && proxy.on(name, this[name], this);
  1983. }, this);
  1984. proxy.handler = this;
  1985. }
  1986. this.proxy = proxy;
  1987. };
  1988. Handler.prototype.mousemove = function (event) {
  1989. var x = event.zrX;
  1990. var y = event.zrY;
  1991. var isOutside = isOutsideBoundary(this, x, y);
  1992. var lastHovered = this._hovered;
  1993. var lastHoveredTarget = lastHovered.target;
  1994. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  1995. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  1996. lastHoveredTarget = lastHovered.target;
  1997. }
  1998. var hovered = this._hovered = isOutside ? new HoveredResult(x, y) : this.findHover(x, y);
  1999. var hoveredTarget = hovered.target;
  2000. var proxy = this.proxy;
  2001. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  2002. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2003. this.dispatchToElement(lastHovered, 'mouseout', event);
  2004. }
  2005. this.dispatchToElement(hovered, 'mousemove', event);
  2006. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2007. this.dispatchToElement(hovered, 'mouseover', event);
  2008. }
  2009. };
  2010. Handler.prototype.mouseout = function (event) {
  2011. var eventControl = event.zrEventControl;
  2012. if (eventControl !== 'only_globalout') {
  2013. this.dispatchToElement(this._hovered, 'mouseout', event);
  2014. }
  2015. if (eventControl !== 'no_globalout') {
  2016. this.trigger('globalout', { type: 'globalout', event: event });
  2017. }
  2018. };
  2019. Handler.prototype.resize = function () {
  2020. this._hovered = new HoveredResult(0, 0);
  2021. };
  2022. Handler.prototype.dispatch = function (eventName, eventArgs) {
  2023. var handler = this[eventName];
  2024. handler && handler.call(this, eventArgs);
  2025. };
  2026. Handler.prototype.dispose = function () {
  2027. this.proxy.dispose();
  2028. this.storage = null;
  2029. this.proxy = null;
  2030. this.painter = null;
  2031. };
  2032. Handler.prototype.setCursorStyle = function (cursorStyle) {
  2033. var proxy = this.proxy;
  2034. proxy.setCursor && proxy.setCursor(cursorStyle);
  2035. };
  2036. Handler.prototype.dispatchToElement = function (targetInfo, eventName, event) {
  2037. targetInfo = targetInfo || {};
  2038. var el = targetInfo.target;
  2039. if (el && el.silent) {
  2040. return;
  2041. }
  2042. var eventKey = ('on' + eventName);
  2043. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2044. while (el) {
  2045. el[eventKey]
  2046. && (eventPacket.cancelBubble = !!el[eventKey].call(el, eventPacket));
  2047. el.trigger(eventName, eventPacket);
  2048. el = el.__hostTarget ? el.__hostTarget : el.parent;
  2049. if (eventPacket.cancelBubble) {
  2050. break;
  2051. }
  2052. }
  2053. if (!eventPacket.cancelBubble) {
  2054. this.trigger(eventName, eventPacket);
  2055. if (this.painter && this.painter.eachOtherLayer) {
  2056. this.painter.eachOtherLayer(function (layer) {
  2057. if (typeof (layer[eventKey]) === 'function') {
  2058. layer[eventKey].call(layer, eventPacket);
  2059. }
  2060. if (layer.trigger) {
  2061. layer.trigger(eventName, eventPacket);
  2062. }
  2063. });
  2064. }
  2065. }
  2066. };
  2067. Handler.prototype.findHover = function (x, y, exclude) {
  2068. var list = this.storage.getDisplayList();
  2069. var out = new HoveredResult(x, y);
  2070. setHoverTarget(list, out, x, y, exclude);
  2071. if (this._pointerSize && !out.target) {
  2072. var candidates = [];
  2073. var pointerSize = this._pointerSize;
  2074. var targetSizeHalf = pointerSize / 2;
  2075. var pointerRect = new BoundingRect(x - targetSizeHalf, y - targetSizeHalf, pointerSize, pointerSize);
  2076. for (var i = list.length - 1; i >= 0; i--) {
  2077. var el = list[i];
  2078. if (el !== exclude
  2079. && !el.ignore
  2080. && !el.ignoreCoarsePointer
  2081. && (!el.parent || !el.parent.ignoreCoarsePointer)) {
  2082. tmpRect.copy(el.getBoundingRect());
  2083. if (el.transform) {
  2084. tmpRect.applyTransform(el.transform);
  2085. }
  2086. if (tmpRect.intersect(pointerRect)) {
  2087. candidates.push(el);
  2088. }
  2089. }
  2090. }
  2091. if (candidates.length) {
  2092. var rStep = 4;
  2093. var thetaStep = Math.PI / 12;
  2094. var PI2 = Math.PI * 2;
  2095. for (var r = 0; r < targetSizeHalf; r += rStep) {
  2096. for (var theta = 0; theta < PI2; theta += thetaStep) {
  2097. var x1 = x + r * Math.cos(theta);
  2098. var y1 = y + r * Math.sin(theta);
  2099. setHoverTarget(candidates, out, x1, y1, exclude);
  2100. if (out.target) {
  2101. return out;
  2102. }
  2103. }
  2104. }
  2105. }
  2106. }
  2107. return out;
  2108. };
  2109. Handler.prototype.processGesture = function (event, stage) {
  2110. if (!this._gestureMgr) {
  2111. this._gestureMgr = new GestureMgr();
  2112. }
  2113. var gestureMgr = this._gestureMgr;
  2114. stage === 'start' && gestureMgr.clear();
  2115. var gestureInfo = gestureMgr.recognize(event, this.findHover(event.zrX, event.zrY, null).target, this.proxy.dom);
  2116. stage === 'end' && gestureMgr.clear();
  2117. if (gestureInfo) {
  2118. var type = gestureInfo.type;
  2119. event.gestureEvent = type;
  2120. var res = new HoveredResult();
  2121. res.target = gestureInfo.target;
  2122. this.dispatchToElement(res, type, gestureInfo.event);
  2123. }
  2124. };
  2125. return Handler;
  2126. }(Eventful));
  2127. each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2128. Handler.prototype[name] = function (event) {
  2129. var x = event.zrX;
  2130. var y = event.zrY;
  2131. var isOutside = isOutsideBoundary(this, x, y);
  2132. var hovered;
  2133. var hoveredTarget;
  2134. if (name !== 'mouseup' || !isOutside) {
  2135. hovered = this.findHover(x, y);
  2136. hoveredTarget = hovered.target;
  2137. }
  2138. if (name === 'mousedown') {
  2139. this._downEl = hoveredTarget;
  2140. this._downPoint = [event.zrX, event.zrY];
  2141. this._upEl = hoveredTarget;
  2142. }
  2143. else if (name === 'mouseup') {
  2144. this._upEl = hoveredTarget;
  2145. }
  2146. else if (name === 'click') {
  2147. if (this._downEl !== this._upEl
  2148. || !this._downPoint
  2149. || dist(this._downPoint, [event.zrX, event.zrY]) > 4) {
  2150. return;
  2151. }
  2152. this._downPoint = null;
  2153. }
  2154. this.dispatchToElement(hovered, name, event);
  2155. };
  2156. });
  2157. function isHover(displayable, x, y) {
  2158. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2159. var el = displayable;
  2160. var isSilent = void 0;
  2161. var ignoreClip = false;
  2162. while (el) {
  2163. if (el.ignoreClip) {
  2164. ignoreClip = true;
  2165. }
  2166. if (!ignoreClip) {
  2167. var clipPath = el.getClipPath();
  2168. if (clipPath && !clipPath.contain(x, y)) {
  2169. return false;
  2170. }
  2171. }
  2172. if (el.silent) {
  2173. isSilent = true;
  2174. }
  2175. var hostEl = el.__hostTarget;
  2176. el = hostEl ? hostEl : el.parent;
  2177. }
  2178. return isSilent ? SILENT : true;
  2179. }
  2180. return false;
  2181. }
  2182. function setHoverTarget(list, out, x, y, exclude) {
  2183. for (var i = list.length - 1; i >= 0; i--) {
  2184. var el = list[i];
  2185. var hoverCheckResult = void 0;
  2186. if (el !== exclude
  2187. && !el.ignore
  2188. && (hoverCheckResult = isHover(el, x, y))) {
  2189. !out.topTarget && (out.topTarget = el);
  2190. if (hoverCheckResult !== SILENT) {
  2191. out.target = el;
  2192. break;
  2193. }
  2194. }
  2195. }
  2196. }
  2197. function isOutsideBoundary(handlerInstance, x, y) {
  2198. var painter = handlerInstance.painter;
  2199. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  2200. }
  2201. var DEFAULT_MIN_MERGE = 32;
  2202. var DEFAULT_MIN_GALLOPING = 7;
  2203. function minRunLength(n) {
  2204. var r = 0;
  2205. while (n >= DEFAULT_MIN_MERGE) {
  2206. r |= n & 1;
  2207. n >>= 1;
  2208. }
  2209. return n + r;
  2210. }
  2211. function makeAscendingRun(array, lo, hi, compare) {
  2212. var runHi = lo + 1;
  2213. if (runHi === hi) {
  2214. return 1;
  2215. }
  2216. if (compare(array[runHi++], array[lo]) < 0) {
  2217. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  2218. runHi++;
  2219. }
  2220. reverseRun(array, lo, runHi);
  2221. }
  2222. else {
  2223. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  2224. runHi++;
  2225. }
  2226. }
  2227. return runHi - lo;
  2228. }
  2229. function reverseRun(array, lo, hi) {
  2230. hi--;
  2231. while (lo < hi) {
  2232. var t = array[lo];
  2233. array[lo++] = array[hi];
  2234. array[hi--] = t;
  2235. }
  2236. }
  2237. function binaryInsertionSort(array, lo, hi, start, compare) {
  2238. if (start === lo) {
  2239. start++;
  2240. }
  2241. for (; start < hi; start++) {
  2242. var pivot = array[start];
  2243. var left = lo;
  2244. var right = start;
  2245. var mid;
  2246. while (left < right) {
  2247. mid = left + right >>> 1;
  2248. if (compare(pivot, array[mid]) < 0) {
  2249. right = mid;
  2250. }
  2251. else {
  2252. left = mid + 1;
  2253. }
  2254. }
  2255. var n = start - left;
  2256. switch (n) {
  2257. case 3:
  2258. array[left + 3] = array[left + 2];
  2259. case 2:
  2260. array[left + 2] = array[left + 1];
  2261. case 1:
  2262. array[left + 1] = array[left];
  2263. break;
  2264. default:
  2265. while (n > 0) {
  2266. array[left + n] = array[left + n - 1];
  2267. n--;
  2268. }
  2269. }
  2270. array[left] = pivot;
  2271. }
  2272. }
  2273. function gallopLeft(value, array, start, length, hint, compare) {
  2274. var lastOffset = 0;
  2275. var maxOffset = 0;
  2276. var offset = 1;
  2277. if (compare(value, array[start + hint]) > 0) {
  2278. maxOffset = length - hint;
  2279. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  2280. lastOffset = offset;
  2281. offset = (offset << 1) + 1;
  2282. if (offset <= 0) {
  2283. offset = maxOffset;
  2284. }
  2285. }
  2286. if (offset > maxOffset) {
  2287. offset = maxOffset;
  2288. }
  2289. lastOffset += hint;
  2290. offset += hint;
  2291. }
  2292. else {
  2293. maxOffset = hint + 1;
  2294. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  2295. lastOffset = offset;
  2296. offset = (offset << 1) + 1;
  2297. if (offset <= 0) {
  2298. offset = maxOffset;
  2299. }
  2300. }
  2301. if (offset > maxOffset) {
  2302. offset = maxOffset;
  2303. }
  2304. var tmp = lastOffset;
  2305. lastOffset = hint - offset;
  2306. offset = hint - tmp;
  2307. }
  2308. lastOffset++;
  2309. while (lastOffset < offset) {
  2310. var m = lastOffset + (offset - lastOffset >>> 1);
  2311. if (compare(value, array[start + m]) > 0) {
  2312. lastOffset = m + 1;
  2313. }
  2314. else {
  2315. offset = m;
  2316. }
  2317. }
  2318. return offset;
  2319. }
  2320. function gallopRight(value, array, start, length, hint, compare) {
  2321. var lastOffset = 0;
  2322. var maxOffset = 0;
  2323. var offset = 1;
  2324. if (compare(value, array[start + hint]) < 0) {
  2325. maxOffset = hint + 1;
  2326. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  2327. lastOffset = offset;
  2328. offset = (offset << 1) + 1;
  2329. if (offset <= 0) {
  2330. offset = maxOffset;
  2331. }
  2332. }
  2333. if (offset > maxOffset) {
  2334. offset = maxOffset;
  2335. }
  2336. var tmp = lastOffset;
  2337. lastOffset = hint - offset;
  2338. offset = hint - tmp;
  2339. }
  2340. else {
  2341. maxOffset = length - hint;
  2342. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  2343. lastOffset = offset;
  2344. offset = (offset << 1) + 1;
  2345. if (offset <= 0) {
  2346. offset = maxOffset;
  2347. }
  2348. }
  2349. if (offset > maxOffset) {
  2350. offset = maxOffset;
  2351. }
  2352. lastOffset += hint;
  2353. offset += hint;
  2354. }
  2355. lastOffset++;
  2356. while (lastOffset < offset) {
  2357. var m = lastOffset + (offset - lastOffset >>> 1);
  2358. if (compare(value, array[start + m]) < 0) {
  2359. offset = m;
  2360. }
  2361. else {
  2362. lastOffset = m + 1;
  2363. }
  2364. }
  2365. return offset;
  2366. }
  2367. function TimSort(array, compare) {
  2368. var minGallop = DEFAULT_MIN_GALLOPING;
  2369. var runStart;
  2370. var runLength;
  2371. var stackSize = 0;
  2372. var tmp = [];
  2373. runStart = [];
  2374. runLength = [];
  2375. function pushRun(_runStart, _runLength) {
  2376. runStart[stackSize] = _runStart;
  2377. runLength[stackSize] = _runLength;
  2378. stackSize += 1;
  2379. }
  2380. function mergeRuns() {
  2381. while (stackSize > 1) {
  2382. var n = stackSize - 2;
  2383. if ((n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1])
  2384. || (n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1])) {
  2385. if (runLength[n - 1] < runLength[n + 1]) {
  2386. n--;
  2387. }
  2388. }
  2389. else if (runLength[n] > runLength[n + 1]) {
  2390. break;
  2391. }
  2392. mergeAt(n);
  2393. }
  2394. }
  2395. function forceMergeRuns() {
  2396. while (stackSize > 1) {
  2397. var n = stackSize - 2;
  2398. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  2399. n--;
  2400. }
  2401. mergeAt(n);
  2402. }
  2403. }
  2404. function mergeAt(i) {
  2405. var start1 = runStart[i];
  2406. var length1 = runLength[i];
  2407. var start2 = runStart[i + 1];
  2408. var length2 = runLength[i + 1];
  2409. runLength[i] = length1 + length2;
  2410. if (i === stackSize - 3) {
  2411. runStart[i + 1] = runStart[i + 2];
  2412. runLength[i + 1] = runLength[i + 2];
  2413. }
  2414. stackSize--;
  2415. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  2416. start1 += k;
  2417. length1 -= k;
  2418. if (length1 === 0) {
  2419. return;
  2420. }
  2421. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  2422. if (length2 === 0) {
  2423. return;
  2424. }
  2425. if (length1 <= length2) {
  2426. mergeLow(start1, length1, start2, length2);
  2427. }
  2428. else {
  2429. mergeHigh(start1, length1, start2, length2);
  2430. }
  2431. }
  2432. function mergeLow(start1, length1, start2, length2) {
  2433. var i = 0;
  2434. for (i = 0; i < length1; i++) {
  2435. tmp[i] = array[start1 + i];
  2436. }
  2437. var cursor1 = 0;
  2438. var cursor2 = start2;
  2439. var dest = start1;
  2440. array[dest++] = array[cursor2++];
  2441. if (--length2 === 0) {
  2442. for (i = 0; i < length1; i++) {
  2443. array[dest + i] = tmp[cursor1 + i];
  2444. }
  2445. return;
  2446. }
  2447. if (length1 === 1) {
  2448. for (i = 0; i < length2; i++) {
  2449. array[dest + i] = array[cursor2 + i];
  2450. }
  2451. array[dest + length2] = tmp[cursor1];
  2452. return;
  2453. }
  2454. var _minGallop = minGallop;
  2455. var count1;
  2456. var count2;
  2457. var exit;
  2458. while (1) {
  2459. count1 = 0;
  2460. count2 = 0;
  2461. exit = false;
  2462. do {
  2463. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  2464. array[dest++] = array[cursor2++];
  2465. count2++;
  2466. count1 = 0;
  2467. if (--length2 === 0) {
  2468. exit = true;
  2469. break;
  2470. }
  2471. }
  2472. else {
  2473. array[dest++] = tmp[cursor1++];
  2474. count1++;
  2475. count2 = 0;
  2476. if (--length1 === 1) {
  2477. exit = true;
  2478. break;
  2479. }
  2480. }
  2481. } while ((count1 | count2) < _minGallop);
  2482. if (exit) {
  2483. break;
  2484. }
  2485. do {
  2486. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  2487. if (count1 !== 0) {
  2488. for (i = 0; i < count1; i++) {
  2489. array[dest + i] = tmp[cursor1 + i];
  2490. }
  2491. dest += count1;
  2492. cursor1 += count1;
  2493. length1 -= count1;
  2494. if (length1 <= 1) {
  2495. exit = true;
  2496. break;
  2497. }
  2498. }
  2499. array[dest++] = array[cursor2++];
  2500. if (--length2 === 0) {
  2501. exit = true;
  2502. break;
  2503. }
  2504. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  2505. if (count2 !== 0) {
  2506. for (i = 0; i < count2; i++) {
  2507. array[dest + i] = array[cursor2 + i];
  2508. }
  2509. dest += count2;
  2510. cursor2 += count2;
  2511. length2 -= count2;
  2512. if (length2 === 0) {
  2513. exit = true;
  2514. break;
  2515. }
  2516. }
  2517. array[dest++] = tmp[cursor1++];
  2518. if (--length1 === 1) {
  2519. exit = true;
  2520. break;
  2521. }
  2522. _minGallop--;
  2523. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2524. if (exit) {
  2525. break;
  2526. }
  2527. if (_minGallop < 0) {
  2528. _minGallop = 0;
  2529. }
  2530. _minGallop += 2;
  2531. }
  2532. minGallop = _minGallop;
  2533. minGallop < 1 && (minGallop = 1);
  2534. if (length1 === 1) {
  2535. for (i = 0; i < length2; i++) {
  2536. array[dest + i] = array[cursor2 + i];
  2537. }
  2538. array[dest + length2] = tmp[cursor1];
  2539. }
  2540. else if (length1 === 0) {
  2541. throw new Error();
  2542. }
  2543. else {
  2544. for (i = 0; i < length1; i++) {
  2545. array[dest + i] = tmp[cursor1 + i];
  2546. }
  2547. }
  2548. }
  2549. function mergeHigh(start1, length1, start2, length2) {
  2550. var i = 0;
  2551. for (i = 0; i < length2; i++) {
  2552. tmp[i] = array[start2 + i];
  2553. }
  2554. var cursor1 = start1 + length1 - 1;
  2555. var cursor2 = length2 - 1;
  2556. var dest = start2 + length2 - 1;
  2557. var customCursor = 0;
  2558. var customDest = 0;
  2559. array[dest--] = array[cursor1--];
  2560. if (--length1 === 0) {
  2561. customCursor = dest - (length2 - 1);
  2562. for (i = 0; i < length2; i++) {
  2563. array[customCursor + i] = tmp[i];
  2564. }
  2565. return;
  2566. }
  2567. if (length2 === 1) {
  2568. dest -= length1;
  2569. cursor1 -= length1;
  2570. customDest = dest + 1;
  2571. customCursor = cursor1 + 1;
  2572. for (i = length1 - 1; i >= 0; i--) {
  2573. array[customDest + i] = array[customCursor + i];
  2574. }
  2575. array[dest] = tmp[cursor2];
  2576. return;
  2577. }
  2578. var _minGallop = minGallop;
  2579. while (true) {
  2580. var count1 = 0;
  2581. var count2 = 0;
  2582. var exit = false;
  2583. do {
  2584. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  2585. array[dest--] = array[cursor1--];
  2586. count1++;
  2587. count2 = 0;
  2588. if (--length1 === 0) {
  2589. exit = true;
  2590. break;
  2591. }
  2592. }
  2593. else {
  2594. array[dest--] = tmp[cursor2--];
  2595. count2++;
  2596. count1 = 0;
  2597. if (--length2 === 1) {
  2598. exit = true;
  2599. break;
  2600. }
  2601. }
  2602. } while ((count1 | count2) < _minGallop);
  2603. if (exit) {
  2604. break;
  2605. }
  2606. do {
  2607. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  2608. if (count1 !== 0) {
  2609. dest -= count1;
  2610. cursor1 -= count1;
  2611. length1 -= count1;
  2612. customDest = dest + 1;
  2613. customCursor = cursor1 + 1;
  2614. for (i = count1 - 1; i >= 0; i--) {
  2615. array[customDest + i] = array[customCursor + i];
  2616. }
  2617. if (length1 === 0) {
  2618. exit = true;
  2619. break;
  2620. }
  2621. }
  2622. array[dest--] = tmp[cursor2--];
  2623. if (--length2 === 1) {
  2624. exit = true;
  2625. break;
  2626. }
  2627. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  2628. if (count2 !== 0) {
  2629. dest -= count2;
  2630. cursor2 -= count2;
  2631. length2 -= count2;
  2632. customDest = dest + 1;
  2633. customCursor = cursor2 + 1;
  2634. for (i = 0; i < count2; i++) {
  2635. array[customDest + i] = tmp[customCursor + i];
  2636. }
  2637. if (length2 <= 1) {
  2638. exit = true;
  2639. break;
  2640. }
  2641. }
  2642. array[dest--] = array[cursor1--];
  2643. if (--length1 === 0) {
  2644. exit = true;
  2645. break;
  2646. }
  2647. _minGallop--;
  2648. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2649. if (exit) {
  2650. break;
  2651. }
  2652. if (_minGallop < 0) {
  2653. _minGallop = 0;
  2654. }
  2655. _minGallop += 2;
  2656. }
  2657. minGallop = _minGallop;
  2658. if (minGallop < 1) {
  2659. minGallop = 1;
  2660. }
  2661. if (length2 === 1) {
  2662. dest -= length1;
  2663. cursor1 -= length1;
  2664. customDest = dest + 1;
  2665. customCursor = cursor1 + 1;
  2666. for (i = length1 - 1; i >= 0; i--) {
  2667. array[customDest + i] = array[customCursor + i];
  2668. }
  2669. array[dest] = tmp[cursor2];
  2670. }
  2671. else if (length2 === 0) {
  2672. throw new Error();
  2673. }
  2674. else {
  2675. customCursor = dest - (length2 - 1);
  2676. for (i = 0; i < length2; i++) {
  2677. array[customCursor + i] = tmp[i];
  2678. }
  2679. }
  2680. }
  2681. return {
  2682. mergeRuns: mergeRuns,
  2683. forceMergeRuns: forceMergeRuns,
  2684. pushRun: pushRun
  2685. };
  2686. }
  2687. function sort(array, compare, lo, hi) {
  2688. if (!lo) {
  2689. lo = 0;
  2690. }
  2691. if (!hi) {
  2692. hi = array.length;
  2693. }
  2694. var remaining = hi - lo;
  2695. if (remaining < 2) {
  2696. return;
  2697. }
  2698. var runLength = 0;
  2699. if (remaining < DEFAULT_MIN_MERGE) {
  2700. runLength = makeAscendingRun(array, lo, hi, compare);
  2701. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  2702. return;
  2703. }
  2704. var ts = TimSort(array, compare);
  2705. var minRun = minRunLength(remaining);
  2706. do {
  2707. runLength = makeAscendingRun(array, lo, hi, compare);
  2708. if (runLength < minRun) {
  2709. var force = remaining;
  2710. if (force > minRun) {
  2711. force = minRun;
  2712. }
  2713. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  2714. runLength = force;
  2715. }
  2716. ts.pushRun(lo, runLength);
  2717. ts.mergeRuns();
  2718. remaining -= runLength;
  2719. lo += runLength;
  2720. } while (remaining !== 0);
  2721. ts.forceMergeRuns();
  2722. }
  2723. var REDRAW_BIT = 1;
  2724. var STYLE_CHANGED_BIT = 2;
  2725. var SHAPE_CHANGED_BIT = 4;
  2726. var invalidZErrorLogged = false;
  2727. function logInvalidZError() {
  2728. if (invalidZErrorLogged) {
  2729. return;
  2730. }
  2731. invalidZErrorLogged = true;
  2732. console.warn('z / z2 / zlevel of displayable is invalid, which may cause unexpected errors');
  2733. }
  2734. function shapeCompareFunc(a, b) {
  2735. if (a.zlevel === b.zlevel) {
  2736. if (a.z === b.z) {
  2737. return a.z2 - b.z2;
  2738. }
  2739. return a.z - b.z;
  2740. }
  2741. return a.zlevel - b.zlevel;
  2742. }
  2743. var Storage = (function () {
  2744. function Storage() {
  2745. this._roots = [];
  2746. this._displayList = [];
  2747. this._displayListLen = 0;
  2748. this.displayableSortFunc = shapeCompareFunc;
  2749. }
  2750. Storage.prototype.traverse = function (cb, context) {
  2751. for (var i = 0; i < this._roots.length; i++) {
  2752. this._roots[i].traverse(cb, context);
  2753. }
  2754. };
  2755. Storage.prototype.getDisplayList = function (update, includeIgnore) {
  2756. includeIgnore = includeIgnore || false;
  2757. var displayList = this._displayList;
  2758. if (update || !displayList.length) {
  2759. this.updateDisplayList(includeIgnore);
  2760. }
  2761. return displayList;
  2762. };
  2763. Storage.prototype.updateDisplayList = function (includeIgnore) {
  2764. this._displayListLen = 0;
  2765. var roots = this._roots;
  2766. var displayList = this._displayList;
  2767. for (var i = 0, len = roots.length; i < len; i++) {
  2768. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  2769. }
  2770. displayList.length = this._displayListLen;
  2771. sort(displayList, shapeCompareFunc);
  2772. };
  2773. Storage.prototype._updateAndAddDisplayable = function (el, clipPaths, includeIgnore) {
  2774. if (el.ignore && !includeIgnore) {
  2775. return;
  2776. }
  2777. el.beforeUpdate();
  2778. el.update();
  2779. el.afterUpdate();
  2780. var userSetClipPath = el.getClipPath();
  2781. if (el.ignoreClip) {
  2782. clipPaths = null;
  2783. }
  2784. else if (userSetClipPath) {
  2785. if (clipPaths) {
  2786. clipPaths = clipPaths.slice();
  2787. }
  2788. else {
  2789. clipPaths = [];
  2790. }
  2791. var currentClipPath = userSetClipPath;
  2792. var parentClipPath = el;
  2793. while (currentClipPath) {
  2794. currentClipPath.parent = parentClipPath;
  2795. currentClipPath.updateTransform();
  2796. clipPaths.push(currentClipPath);
  2797. parentClipPath = currentClipPath;
  2798. currentClipPath = currentClipPath.getClipPath();
  2799. }
  2800. }
  2801. if (el.childrenRef) {
  2802. var children = el.childrenRef();
  2803. for (var i = 0; i < children.length; i++) {
  2804. var child = children[i];
  2805. if (el.__dirty) {
  2806. child.__dirty |= REDRAW_BIT;
  2807. }
  2808. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  2809. }
  2810. el.__dirty = 0;
  2811. }
  2812. else {
  2813. var disp = el;
  2814. if (clipPaths && clipPaths.length) {
  2815. disp.__clipPaths = clipPaths;
  2816. }
  2817. else if (disp.__clipPaths && disp.__clipPaths.length > 0) {
  2818. disp.__clipPaths = [];
  2819. }
  2820. if (isNaN(disp.z)) {
  2821. logInvalidZError();
  2822. disp.z = 0;
  2823. }
  2824. if (isNaN(disp.z2)) {
  2825. logInvalidZError();
  2826. disp.z2 = 0;
  2827. }
  2828. if (isNaN(disp.zlevel)) {
  2829. logInvalidZError();
  2830. disp.zlevel = 0;
  2831. }
  2832. this._displayList[this._displayListLen++] = disp;
  2833. }
  2834. var decalEl = el.getDecalElement && el.getDecalElement();
  2835. if (decalEl) {
  2836. this._updateAndAddDisplayable(decalEl, clipPaths, includeIgnore);
  2837. }
  2838. var textGuide = el.getTextGuideLine();
  2839. if (textGuide) {
  2840. this._updateAndAddDisplayable(textGuide, clipPaths, includeIgnore);
  2841. }
  2842. var textEl = el.getTextContent();
  2843. if (textEl) {
  2844. this._updateAndAddDisplayable(textEl, clipPaths, includeIgnore);
  2845. }
  2846. };
  2847. Storage.prototype.addRoot = function (el) {
  2848. if (el.__zr && el.__zr.storage === this) {
  2849. return;
  2850. }
  2851. this._roots.push(el);
  2852. };
  2853. Storage.prototype.delRoot = function (el) {
  2854. if (el instanceof Array) {
  2855. for (var i = 0, l = el.length; i < l; i++) {
  2856. this.delRoot(el[i]);
  2857. }
  2858. return;
  2859. }
  2860. var idx = indexOf(this._roots, el);
  2861. if (idx >= 0) {
  2862. this._roots.splice(idx, 1);
  2863. }
  2864. };
  2865. Storage.prototype.delAllRoots = function () {
  2866. this._roots = [];
  2867. this._displayList = [];
  2868. this._displayListLen = 0;
  2869. return;
  2870. };
  2871. Storage.prototype.getRoots = function () {
  2872. return this._roots;
  2873. };
  2874. Storage.prototype.dispose = function () {
  2875. this._displayList = null;
  2876. this._roots = null;
  2877. };
  2878. return Storage;
  2879. }());
  2880. var requestAnimationFrame;
  2881. requestAnimationFrame = (env.hasGlobalWindow
  2882. && ((window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  2883. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  2884. || window.mozRequestAnimationFrame
  2885. || window.webkitRequestAnimationFrame)) || function (func) {
  2886. return setTimeout(func, 16);
  2887. };
  2888. var requestAnimationFrame$1 = requestAnimationFrame;
  2889. var easingFuncs = {
  2890. linear: function (k) {
  2891. return k;
  2892. },
  2893. quadraticIn: function (k) {
  2894. return k * k;
  2895. },
  2896. quadraticOut: function (k) {
  2897. return k * (2 - k);
  2898. },
  2899. quadraticInOut: function (k) {
  2900. if ((k *= 2) < 1) {
  2901. return 0.5 * k * k;
  2902. }
  2903. return -0.5 * (--k * (k - 2) - 1);
  2904. },
  2905. cubicIn: function (k) {
  2906. return k * k * k;
  2907. },
  2908. cubicOut: function (k) {
  2909. return --k * k * k + 1;
  2910. },
  2911. cubicInOut: function (k) {
  2912. if ((k *= 2) < 1) {
  2913. return 0.5 * k * k * k;
  2914. }
  2915. return 0.5 * ((k -= 2) * k * k + 2);
  2916. },
  2917. quarticIn: function (k) {
  2918. return k * k * k * k;
  2919. },
  2920. quarticOut: function (k) {
  2921. return 1 - (--k * k * k * k);
  2922. },
  2923. quarticInOut: function (k) {
  2924. if ((k *= 2) < 1) {
  2925. return 0.5 * k * k * k * k;
  2926. }
  2927. return -0.5 * ((k -= 2) * k * k * k - 2);
  2928. },
  2929. quinticIn: function (k) {
  2930. return k * k * k * k * k;
  2931. },
  2932. quinticOut: function (k) {
  2933. return --k * k * k * k * k + 1;
  2934. },
  2935. quinticInOut: function (k) {
  2936. if ((k *= 2) < 1) {
  2937. return 0.5 * k * k * k * k * k;
  2938. }
  2939. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2940. },
  2941. sinusoidalIn: function (k) {
  2942. return 1 - Math.cos(k * Math.PI / 2);
  2943. },
  2944. sinusoidalOut: function (k) {
  2945. return Math.sin(k * Math.PI / 2);
  2946. },
  2947. sinusoidalInOut: function (k) {
  2948. return 0.5 * (1 - Math.cos(Math.PI * k));
  2949. },
  2950. exponentialIn: function (k) {
  2951. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2952. },
  2953. exponentialOut: function (k) {
  2954. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2955. },
  2956. exponentialInOut: function (k) {
  2957. if (k === 0) {
  2958. return 0;
  2959. }
  2960. if (k === 1) {
  2961. return 1;
  2962. }
  2963. if ((k *= 2) < 1) {
  2964. return 0.5 * Math.pow(1024, k - 1);
  2965. }
  2966. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2967. },
  2968. circularIn: function (k) {
  2969. return 1 - Math.sqrt(1 - k * k);
  2970. },
  2971. circularOut: function (k) {
  2972. return Math.sqrt(1 - (--k * k));
  2973. },
  2974. circularInOut: function (k) {
  2975. if ((k *= 2) < 1) {
  2976. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2977. }
  2978. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2979. },
  2980. elasticIn: function (k) {
  2981. var s;
  2982. var a = 0.1;
  2983. var p = 0.4;
  2984. if (k === 0) {
  2985. return 0;
  2986. }
  2987. if (k === 1) {
  2988. return 1;
  2989. }
  2990. if (!a || a < 1) {
  2991. a = 1;
  2992. s = p / 4;
  2993. }
  2994. else {
  2995. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2996. }
  2997. return -(a * Math.pow(2, 10 * (k -= 1))
  2998. * Math.sin((k - s) * (2 * Math.PI) / p));
  2999. },
  3000. elasticOut: function (k) {
  3001. var s;
  3002. var a = 0.1;
  3003. var p = 0.4;
  3004. if (k === 0) {
  3005. return 0;
  3006. }
  3007. if (k === 1) {
  3008. return 1;
  3009. }
  3010. if (!a || a < 1) {
  3011. a = 1;
  3012. s = p / 4;
  3013. }
  3014. else {
  3015. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3016. }
  3017. return (a * Math.pow(2, -10 * k)
  3018. * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  3019. },
  3020. elasticInOut: function (k) {
  3021. var s;
  3022. var a = 0.1;
  3023. var p = 0.4;
  3024. if (k === 0) {
  3025. return 0;
  3026. }
  3027. if (k === 1) {
  3028. return 1;
  3029. }
  3030. if (!a || a < 1) {
  3031. a = 1;
  3032. s = p / 4;
  3033. }
  3034. else {
  3035. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3036. }
  3037. if ((k *= 2) < 1) {
  3038. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  3039. * Math.sin((k - s) * (2 * Math.PI) / p));
  3040. }
  3041. return a * Math.pow(2, -10 * (k -= 1))
  3042. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  3043. },
  3044. backIn: function (k) {
  3045. var s = 1.70158;
  3046. return k * k * ((s + 1) * k - s);
  3047. },
  3048. backOut: function (k) {
  3049. var s = 1.70158;
  3050. return --k * k * ((s + 1) * k + s) + 1;
  3051. },
  3052. backInOut: function (k) {
  3053. var s = 1.70158 * 1.525;
  3054. if ((k *= 2) < 1) {
  3055. return 0.5 * (k * k * ((s + 1) * k - s));
  3056. }
  3057. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  3058. },
  3059. bounceIn: function (k) {
  3060. return 1 - easingFuncs.bounceOut(1 - k);
  3061. },
  3062. bounceOut: function (k) {
  3063. if (k < (1 / 2.75)) {
  3064. return 7.5625 * k * k;
  3065. }
  3066. else if (k < (2 / 2.75)) {
  3067. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  3068. }
  3069. else if (k < (2.5 / 2.75)) {
  3070. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  3071. }
  3072. else {
  3073. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  3074. }
  3075. },
  3076. bounceInOut: function (k) {
  3077. if (k < 0.5) {
  3078. return easingFuncs.bounceIn(k * 2) * 0.5;
  3079. }
  3080. return easingFuncs.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  3081. }
  3082. };
  3083. var mathPow = Math.pow;
  3084. var mathSqrt = Math.sqrt;
  3085. var EPSILON = 1e-8;
  3086. var EPSILON_NUMERIC = 1e-4;
  3087. var THREE_SQRT = mathSqrt(3);
  3088. var ONE_THIRD = 1 / 3;
  3089. var _v0 = create();
  3090. var _v1 = create();
  3091. var _v2 = create();
  3092. function isAroundZero(val) {
  3093. return val > -EPSILON && val < EPSILON;
  3094. }
  3095. function isNotAroundZero(val) {
  3096. return val > EPSILON || val < -EPSILON;
  3097. }
  3098. function cubicAt(p0, p1, p2, p3, t) {
  3099. var onet = 1 - t;
  3100. return onet * onet * (onet * p0 + 3 * t * p1)
  3101. + t * t * (t * p3 + 3 * onet * p2);
  3102. }
  3103. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  3104. var onet = 1 - t;
  3105. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  3106. + (p3 - p2) * t * t);
  3107. }
  3108. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  3109. var a = p3 + 3 * (p1 - p2) - p0;
  3110. var b = 3 * (p2 - p1 * 2 + p0);
  3111. var c = 3 * (p1 - p0);
  3112. var d = p0 - val;
  3113. var A = b * b - 3 * a * c;
  3114. var B = b * c - 9 * a * d;
  3115. var C = c * c - 3 * b * d;
  3116. var n = 0;
  3117. if (isAroundZero(A) && isAroundZero(B)) {
  3118. if (isAroundZero(b)) {
  3119. roots[0] = 0;
  3120. }
  3121. else {
  3122. var t1 = -c / b;
  3123. if (t1 >= 0 && t1 <= 1) {
  3124. roots[n++] = t1;
  3125. }
  3126. }
  3127. }
  3128. else {
  3129. var disc = B * B - 4 * A * C;
  3130. if (isAroundZero(disc)) {
  3131. var K = B / A;
  3132. var t1 = -b / a + K;
  3133. var t2 = -K / 2;
  3134. if (t1 >= 0 && t1 <= 1) {
  3135. roots[n++] = t1;
  3136. }
  3137. if (t2 >= 0 && t2 <= 1) {
  3138. roots[n++] = t2;
  3139. }
  3140. }
  3141. else if (disc > 0) {
  3142. var discSqrt = mathSqrt(disc);
  3143. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  3144. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  3145. if (Y1 < 0) {
  3146. Y1 = -mathPow(-Y1, ONE_THIRD);
  3147. }
  3148. else {
  3149. Y1 = mathPow(Y1, ONE_THIRD);
  3150. }
  3151. if (Y2 < 0) {
  3152. Y2 = -mathPow(-Y2, ONE_THIRD);
  3153. }
  3154. else {
  3155. Y2 = mathPow(Y2, ONE_THIRD);
  3156. }
  3157. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  3158. if (t1 >= 0 && t1 <= 1) {
  3159. roots[n++] = t1;
  3160. }
  3161. }
  3162. else {
  3163. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  3164. var theta = Math.acos(T) / 3;
  3165. var ASqrt = mathSqrt(A);
  3166. var tmp = Math.cos(theta);
  3167. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  3168. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  3169. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  3170. if (t1 >= 0 && t1 <= 1) {
  3171. roots[n++] = t1;
  3172. }
  3173. if (t2 >= 0 && t2 <= 1) {
  3174. roots[n++] = t2;
  3175. }
  3176. if (t3 >= 0 && t3 <= 1) {
  3177. roots[n++] = t3;
  3178. }
  3179. }
  3180. }
  3181. return n;
  3182. }
  3183. function cubicExtrema(p0, p1, p2, p3, extrema) {
  3184. var b = 6 * p2 - 12 * p1 + 6 * p0;
  3185. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  3186. var c = 3 * p1 - 3 * p0;
  3187. var n = 0;
  3188. if (isAroundZero(a)) {
  3189. if (isNotAroundZero(b)) {
  3190. var t1 = -c / b;
  3191. if (t1 >= 0 && t1 <= 1) {
  3192. extrema[n++] = t1;
  3193. }
  3194. }
  3195. }
  3196. else {
  3197. var disc = b * b - 4 * a * c;
  3198. if (isAroundZero(disc)) {
  3199. extrema[0] = -b / (2 * a);
  3200. }
  3201. else if (disc > 0) {
  3202. var discSqrt = mathSqrt(disc);
  3203. var t1 = (-b + discSqrt) / (2 * a);
  3204. var t2 = (-b - discSqrt) / (2 * a);
  3205. if (t1 >= 0 && t1 <= 1) {
  3206. extrema[n++] = t1;
  3207. }
  3208. if (t2 >= 0 && t2 <= 1) {
  3209. extrema[n++] = t2;
  3210. }
  3211. }
  3212. }
  3213. return n;
  3214. }
  3215. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  3216. var p01 = (p1 - p0) * t + p0;
  3217. var p12 = (p2 - p1) * t + p1;
  3218. var p23 = (p3 - p2) * t + p2;
  3219. var p012 = (p12 - p01) * t + p01;
  3220. var p123 = (p23 - p12) * t + p12;
  3221. var p0123 = (p123 - p012) * t + p012;
  3222. out[0] = p0;
  3223. out[1] = p01;
  3224. out[2] = p012;
  3225. out[3] = p0123;
  3226. out[4] = p0123;
  3227. out[5] = p123;
  3228. out[6] = p23;
  3229. out[7] = p3;
  3230. }
  3231. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  3232. var t;
  3233. var interval = 0.005;
  3234. var d = Infinity;
  3235. var prev;
  3236. var next;
  3237. var d1;
  3238. var d2;
  3239. _v0[0] = x;
  3240. _v0[1] = y;
  3241. for (var _t = 0; _t < 1; _t += 0.05) {
  3242. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  3243. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  3244. d1 = distSquare(_v0, _v1);
  3245. if (d1 < d) {
  3246. t = _t;
  3247. d = d1;
  3248. }
  3249. }
  3250. d = Infinity;
  3251. for (var i = 0; i < 32; i++) {
  3252. if (interval < EPSILON_NUMERIC) {
  3253. break;
  3254. }
  3255. prev = t - interval;
  3256. next = t + interval;
  3257. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  3258. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  3259. d1 = distSquare(_v1, _v0);
  3260. if (prev >= 0 && d1 < d) {
  3261. t = prev;
  3262. d = d1;
  3263. }
  3264. else {
  3265. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  3266. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  3267. d2 = distSquare(_v2, _v0);
  3268. if (next <= 1 && d2 < d) {
  3269. t = next;
  3270. d = d2;
  3271. }
  3272. else {
  3273. interval *= 0.5;
  3274. }
  3275. }
  3276. }
  3277. if (out) {
  3278. out[0] = cubicAt(x0, x1, x2, x3, t);
  3279. out[1] = cubicAt(y0, y1, y2, y3, t);
  3280. }
  3281. return mathSqrt(d);
  3282. }
  3283. function cubicLength(x0, y0, x1, y1, x2, y2, x3, y3, iteration) {
  3284. var px = x0;
  3285. var py = y0;
  3286. var d = 0;
  3287. var step = 1 / iteration;
  3288. for (var i = 1; i <= iteration; i++) {
  3289. var t = i * step;
  3290. var x = cubicAt(x0, x1, x2, x3, t);
  3291. var y = cubicAt(y0, y1, y2, y3, t);
  3292. var dx = x - px;
  3293. var dy = y - py;
  3294. d += Math.sqrt(dx * dx + dy * dy);
  3295. px = x;
  3296. py = y;
  3297. }
  3298. return d;
  3299. }
  3300. function quadraticAt(p0, p1, p2, t) {
  3301. var onet = 1 - t;
  3302. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  3303. }
  3304. function quadraticDerivativeAt(p0, p1, p2, t) {
  3305. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  3306. }
  3307. function quadraticRootAt(p0, p1, p2, val, roots) {
  3308. var a = p0 - 2 * p1 + p2;
  3309. var b = 2 * (p1 - p0);
  3310. var c = p0 - val;
  3311. var n = 0;
  3312. if (isAroundZero(a)) {
  3313. if (isNotAroundZero(b)) {
  3314. var t1 = -c / b;
  3315. if (t1 >= 0 && t1 <= 1) {
  3316. roots[n++] = t1;
  3317. }
  3318. }
  3319. }
  3320. else {
  3321. var disc = b * b - 4 * a * c;
  3322. if (isAroundZero(disc)) {
  3323. var t1 = -b / (2 * a);
  3324. if (t1 >= 0 && t1 <= 1) {
  3325. roots[n++] = t1;
  3326. }
  3327. }
  3328. else if (disc > 0) {
  3329. var discSqrt = mathSqrt(disc);
  3330. var t1 = (-b + discSqrt) / (2 * a);
  3331. var t2 = (-b - discSqrt) / (2 * a);
  3332. if (t1 >= 0 && t1 <= 1) {
  3333. roots[n++] = t1;
  3334. }
  3335. if (t2 >= 0 && t2 <= 1) {
  3336. roots[n++] = t2;
  3337. }
  3338. }
  3339. }
  3340. return n;
  3341. }
  3342. function quadraticExtremum(p0, p1, p2) {
  3343. var divider = p0 + p2 - 2 * p1;
  3344. if (divider === 0) {
  3345. return 0.5;
  3346. }
  3347. else {
  3348. return (p0 - p1) / divider;
  3349. }
  3350. }
  3351. function quadraticSubdivide(p0, p1, p2, t, out) {
  3352. var p01 = (p1 - p0) * t + p0;
  3353. var p12 = (p2 - p1) * t + p1;
  3354. var p012 = (p12 - p01) * t + p01;
  3355. out[0] = p0;
  3356. out[1] = p01;
  3357. out[2] = p012;
  3358. out[3] = p012;
  3359. out[4] = p12;
  3360. out[5] = p2;
  3361. }
  3362. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  3363. var t;
  3364. var interval = 0.005;
  3365. var d = Infinity;
  3366. _v0[0] = x;
  3367. _v0[1] = y;
  3368. for (var _t = 0; _t < 1; _t += 0.05) {
  3369. _v1[0] = quadraticAt(x0, x1, x2, _t);
  3370. _v1[1] = quadraticAt(y0, y1, y2, _t);
  3371. var d1 = distSquare(_v0, _v1);
  3372. if (d1 < d) {
  3373. t = _t;
  3374. d = d1;
  3375. }
  3376. }
  3377. d = Infinity;
  3378. for (var i = 0; i < 32; i++) {
  3379. if (interval < EPSILON_NUMERIC) {
  3380. break;
  3381. }
  3382. var prev = t - interval;
  3383. var next = t + interval;
  3384. _v1[0] = quadraticAt(x0, x1, x2, prev);
  3385. _v1[1] = quadraticAt(y0, y1, y2, prev);
  3386. var d1 = distSquare(_v1, _v0);
  3387. if (prev >= 0 && d1 < d) {
  3388. t = prev;
  3389. d = d1;
  3390. }
  3391. else {
  3392. _v2[0] = quadraticAt(x0, x1, x2, next);
  3393. _v2[1] = quadraticAt(y0, y1, y2, next);
  3394. var d2 = distSquare(_v2, _v0);
  3395. if (next <= 1 && d2 < d) {
  3396. t = next;
  3397. d = d2;
  3398. }
  3399. else {
  3400. interval *= 0.5;
  3401. }
  3402. }
  3403. }
  3404. if (out) {
  3405. out[0] = quadraticAt(x0, x1, x2, t);
  3406. out[1] = quadraticAt(y0, y1, y2, t);
  3407. }
  3408. return mathSqrt(d);
  3409. }
  3410. function quadraticLength(x0, y0, x1, y1, x2, y2, iteration) {
  3411. var px = x0;
  3412. var py = y0;
  3413. var d = 0;
  3414. var step = 1 / iteration;
  3415. for (var i = 1; i <= iteration; i++) {
  3416. var t = i * step;
  3417. var x = quadraticAt(x0, x1, x2, t);
  3418. var y = quadraticAt(y0, y1, y2, t);
  3419. var dx = x - px;
  3420. var dy = y - py;
  3421. d += Math.sqrt(dx * dx + dy * dy);
  3422. px = x;
  3423. py = y;
  3424. }
  3425. return d;
  3426. }
  3427. var regexp = /cubic-bezier\(([0-9,\.e ]+)\)/;
  3428. function createCubicEasingFunc(cubicEasingStr) {
  3429. var cubic = cubicEasingStr && regexp.exec(cubicEasingStr);
  3430. if (cubic) {
  3431. var points = cubic[1].split(',');
  3432. var a_1 = +trim(points[0]);
  3433. var b_1 = +trim(points[1]);
  3434. var c_1 = +trim(points[2]);
  3435. var d_1 = +trim(points[3]);
  3436. if (isNaN(a_1 + b_1 + c_1 + d_1)) {
  3437. return;
  3438. }
  3439. var roots_1 = [];
  3440. return function (p) {
  3441. return p <= 0
  3442. ? 0 : p >= 1
  3443. ? 1
  3444. : cubicRootAt(0, a_1, c_1, 1, p, roots_1) && cubicAt(0, b_1, d_1, 1, roots_1[0]);
  3445. };
  3446. }
  3447. }
  3448. var Clip = (function () {
  3449. function Clip(opts) {
  3450. this._inited = false;
  3451. this._startTime = 0;
  3452. this._pausedTime = 0;
  3453. this._paused = false;
  3454. this._life = opts.life || 1000;
  3455. this._delay = opts.delay || 0;
  3456. this.loop = opts.loop || false;
  3457. this.onframe = opts.onframe || noop;
  3458. this.ondestroy = opts.ondestroy || noop;
  3459. this.onrestart = opts.onrestart || noop;
  3460. opts.easing && this.setEasing(opts.easing);
  3461. }
  3462. Clip.prototype.step = function (globalTime, deltaTime) {
  3463. if (!this._inited) {
  3464. this._startTime = globalTime + this._delay;
  3465. this._inited = true;
  3466. }
  3467. if (this._paused) {
  3468. this._pausedTime += deltaTime;
  3469. return;
  3470. }
  3471. var life = this._life;
  3472. var elapsedTime = globalTime - this._startTime - this._pausedTime;
  3473. var percent = elapsedTime / life;
  3474. if (percent < 0) {
  3475. percent = 0;
  3476. }
  3477. percent = Math.min(percent, 1);
  3478. var easingFunc = this.easingFunc;
  3479. var schedule = easingFunc ? easingFunc(percent) : percent;
  3480. this.onframe(schedule);
  3481. if (percent === 1) {
  3482. if (this.loop) {
  3483. var remainder = elapsedTime % life;
  3484. this._startTime = globalTime - remainder;
  3485. this._pausedTime = 0;
  3486. this.onrestart();
  3487. }
  3488. else {
  3489. return true;
  3490. }
  3491. }
  3492. return false;
  3493. };
  3494. Clip.prototype.pause = function () {
  3495. this._paused = true;
  3496. };
  3497. Clip.prototype.resume = function () {
  3498. this._paused = false;
  3499. };
  3500. Clip.prototype.setEasing = function (easing) {
  3501. this.easing = easing;
  3502. this.easingFunc = isFunction(easing)
  3503. ? easing
  3504. : easingFuncs[easing] || createCubicEasingFunc(easing);
  3505. };
  3506. return Clip;
  3507. }());
  3508. var Entry = (function () {
  3509. function Entry(val) {
  3510. this.value = val;
  3511. }
  3512. return Entry;
  3513. }());
  3514. var LinkedList = (function () {
  3515. function LinkedList() {
  3516. this._len = 0;
  3517. }
  3518. LinkedList.prototype.insert = function (val) {
  3519. var entry = new Entry(val);
  3520. this.insertEntry(entry);
  3521. return entry;
  3522. };
  3523. LinkedList.prototype.insertEntry = function (entry) {
  3524. if (!this.head) {
  3525. this.head = this.tail = entry;
  3526. }
  3527. else {
  3528. this.tail.next = entry;
  3529. entry.prev = this.tail;
  3530. entry.next = null;
  3531. this.tail = entry;
  3532. }
  3533. this._len++;
  3534. };
  3535. LinkedList.prototype.remove = function (entry) {
  3536. var prev = entry.prev;
  3537. var next = entry.next;
  3538. if (prev) {
  3539. prev.next = next;
  3540. }
  3541. else {
  3542. this.head = next;
  3543. }
  3544. if (next) {
  3545. next.prev = prev;
  3546. }
  3547. else {
  3548. this.tail = prev;
  3549. }
  3550. entry.next = entry.prev = null;
  3551. this._len--;
  3552. };
  3553. LinkedList.prototype.len = function () {
  3554. return this._len;
  3555. };
  3556. LinkedList.prototype.clear = function () {
  3557. this.head = this.tail = null;
  3558. this._len = 0;
  3559. };
  3560. return LinkedList;
  3561. }());
  3562. var LRU = (function () {
  3563. function LRU(maxSize) {
  3564. this._list = new LinkedList();
  3565. this._maxSize = 10;
  3566. this._map = {};
  3567. this._maxSize = maxSize;
  3568. }
  3569. LRU.prototype.put = function (key, value) {
  3570. var list = this._list;
  3571. var map = this._map;
  3572. var removed = null;
  3573. if (map[key] == null) {
  3574. var len = list.len();
  3575. var entry = this._lastRemovedEntry;
  3576. if (len >= this._maxSize && len > 0) {
  3577. var leastUsedEntry = list.head;
  3578. list.remove(leastUsedEntry);
  3579. delete map[leastUsedEntry.key];
  3580. removed = leastUsedEntry.value;
  3581. this._lastRemovedEntry = leastUsedEntry;
  3582. }
  3583. if (entry) {
  3584. entry.value = value;
  3585. }
  3586. else {
  3587. entry = new Entry(value);
  3588. }
  3589. entry.key = key;
  3590. list.insertEntry(entry);
  3591. map[key] = entry;
  3592. }
  3593. return removed;
  3594. };
  3595. LRU.prototype.get = function (key) {
  3596. var entry = this._map[key];
  3597. var list = this._list;
  3598. if (entry != null) {
  3599. if (entry !== list.tail) {
  3600. list.remove(entry);
  3601. list.insertEntry(entry);
  3602. }
  3603. return entry.value;
  3604. }
  3605. };
  3606. LRU.prototype.clear = function () {
  3607. this._list.clear();
  3608. this._map = {};
  3609. };
  3610. LRU.prototype.len = function () {
  3611. return this._list.len();
  3612. };
  3613. return LRU;
  3614. }());
  3615. var kCSSColorTable = {
  3616. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  3617. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  3618. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  3619. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  3620. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  3621. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  3622. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  3623. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  3624. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  3625. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  3626. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  3627. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  3628. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  3629. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  3630. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  3631. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  3632. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  3633. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  3634. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  3635. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  3636. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  3637. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  3638. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  3639. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  3640. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  3641. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  3642. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  3643. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  3644. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  3645. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  3646. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  3647. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  3648. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  3649. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  3650. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  3651. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  3652. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  3653. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  3654. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  3655. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  3656. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  3657. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  3658. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  3659. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  3660. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  3661. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  3662. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  3663. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  3664. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  3665. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  3666. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  3667. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  3668. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  3669. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  3670. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  3671. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  3672. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  3673. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  3674. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  3675. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  3676. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  3677. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  3678. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  3679. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  3680. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  3681. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  3682. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  3683. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  3684. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  3685. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  3686. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  3687. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  3688. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  3689. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  3690. };
  3691. function clampCssByte(i) {
  3692. i = Math.round(i);
  3693. return i < 0 ? 0 : i > 255 ? 255 : i;
  3694. }
  3695. function clampCssAngle(i) {
  3696. i = Math.round(i);
  3697. return i < 0 ? 0 : i > 360 ? 360 : i;
  3698. }
  3699. function clampCssFloat(f) {
  3700. return f < 0 ? 0 : f > 1 ? 1 : f;
  3701. }
  3702. function parseCssInt(val) {
  3703. var str = val;
  3704. if (str.length && str.charAt(str.length - 1) === '%') {
  3705. return clampCssByte(parseFloat(str) / 100 * 255);
  3706. }
  3707. return clampCssByte(parseInt(str, 10));
  3708. }
  3709. function parseCssFloat(val) {
  3710. var str = val;
  3711. if (str.length && str.charAt(str.length - 1) === '%') {
  3712. return clampCssFloat(parseFloat(str) / 100);
  3713. }
  3714. return clampCssFloat(parseFloat(str));
  3715. }
  3716. function cssHueToRgb(m1, m2, h) {
  3717. if (h < 0) {
  3718. h += 1;
  3719. }
  3720. else if (h > 1) {
  3721. h -= 1;
  3722. }
  3723. if (h * 6 < 1) {
  3724. return m1 + (m2 - m1) * h * 6;
  3725. }
  3726. if (h * 2 < 1) {
  3727. return m2;
  3728. }
  3729. if (h * 3 < 2) {
  3730. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3731. }
  3732. return m1;
  3733. }
  3734. function lerpNumber(a, b, p) {
  3735. return a + (b - a) * p;
  3736. }
  3737. function setRgba(out, r, g, b, a) {
  3738. out[0] = r;
  3739. out[1] = g;
  3740. out[2] = b;
  3741. out[3] = a;
  3742. return out;
  3743. }
  3744. function copyRgba(out, a) {
  3745. out[0] = a[0];
  3746. out[1] = a[1];
  3747. out[2] = a[2];
  3748. out[3] = a[3];
  3749. return out;
  3750. }
  3751. var colorCache = new LRU(20);
  3752. var lastRemovedArr = null;
  3753. function putToCache(colorStr, rgbaArr) {
  3754. if (lastRemovedArr) {
  3755. copyRgba(lastRemovedArr, rgbaArr);
  3756. }
  3757. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  3758. }
  3759. function parse(colorStr, rgbaArr) {
  3760. if (!colorStr) {
  3761. return;
  3762. }
  3763. rgbaArr = rgbaArr || [];
  3764. var cached = colorCache.get(colorStr);
  3765. if (cached) {
  3766. return copyRgba(rgbaArr, cached);
  3767. }
  3768. colorStr = colorStr + '';
  3769. var str = colorStr.replace(/ /g, '').toLowerCase();
  3770. if (str in kCSSColorTable) {
  3771. copyRgba(rgbaArr, kCSSColorTable[str]);
  3772. putToCache(colorStr, rgbaArr);
  3773. return rgbaArr;
  3774. }
  3775. var strLen = str.length;
  3776. if (str.charAt(0) === '#') {
  3777. if (strLen === 4 || strLen === 5) {
  3778. var iv = parseInt(str.slice(1, 4), 16);
  3779. if (!(iv >= 0 && iv <= 0xfff)) {
  3780. setRgba(rgbaArr, 0, 0, 0, 1);
  3781. return;
  3782. }
  3783. 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);
  3784. putToCache(colorStr, rgbaArr);
  3785. return rgbaArr;
  3786. }
  3787. else if (strLen === 7 || strLen === 9) {
  3788. var iv = parseInt(str.slice(1, 7), 16);
  3789. if (!(iv >= 0 && iv <= 0xffffff)) {
  3790. setRgba(rgbaArr, 0, 0, 0, 1);
  3791. return;
  3792. }
  3793. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, strLen === 9 ? parseInt(str.slice(7), 16) / 0xff : 1);
  3794. putToCache(colorStr, rgbaArr);
  3795. return rgbaArr;
  3796. }
  3797. return;
  3798. }
  3799. var op = str.indexOf('(');
  3800. var ep = str.indexOf(')');
  3801. if (op !== -1 && ep + 1 === strLen) {
  3802. var fname = str.substr(0, op);
  3803. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3804. var alpha = 1;
  3805. switch (fname) {
  3806. case 'rgba':
  3807. if (params.length !== 4) {
  3808. return params.length === 3
  3809. ? setRgba(rgbaArr, +params[0], +params[1], +params[2], 1)
  3810. : setRgba(rgbaArr, 0, 0, 0, 1);
  3811. }
  3812. alpha = parseCssFloat(params.pop());
  3813. case 'rgb':
  3814. if (params.length >= 3) {
  3815. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), params.length === 3 ? alpha : parseCssFloat(params[3]));
  3816. putToCache(colorStr, rgbaArr);
  3817. return rgbaArr;
  3818. }
  3819. else {
  3820. setRgba(rgbaArr, 0, 0, 0, 1);
  3821. return;
  3822. }
  3823. case 'hsla':
  3824. if (params.length !== 4) {
  3825. setRgba(rgbaArr, 0, 0, 0, 1);
  3826. return;
  3827. }
  3828. params[3] = parseCssFloat(params[3]);
  3829. hsla2rgba(params, rgbaArr);
  3830. putToCache(colorStr, rgbaArr);
  3831. return rgbaArr;
  3832. case 'hsl':
  3833. if (params.length !== 3) {
  3834. setRgba(rgbaArr, 0, 0, 0, 1);
  3835. return;
  3836. }
  3837. hsla2rgba(params, rgbaArr);
  3838. putToCache(colorStr, rgbaArr);
  3839. return rgbaArr;
  3840. default:
  3841. return;
  3842. }
  3843. }
  3844. setRgba(rgbaArr, 0, 0, 0, 1);
  3845. return;
  3846. }
  3847. function hsla2rgba(hsla, rgba) {
  3848. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360;
  3849. var s = parseCssFloat(hsla[1]);
  3850. var l = parseCssFloat(hsla[2]);
  3851. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  3852. var m1 = l * 2 - m2;
  3853. rgba = rgba || [];
  3854. 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);
  3855. if (hsla.length === 4) {
  3856. rgba[3] = hsla[3];
  3857. }
  3858. return rgba;
  3859. }
  3860. function rgba2hsla(rgba) {
  3861. if (!rgba) {
  3862. return;
  3863. }
  3864. var R = rgba[0] / 255;
  3865. var G = rgba[1] / 255;
  3866. var B = rgba[2] / 255;
  3867. var vMin = Math.min(R, G, B);
  3868. var vMax = Math.max(R, G, B);
  3869. var delta = vMax - vMin;
  3870. var L = (vMax + vMin) / 2;
  3871. var H;
  3872. var S;
  3873. if (delta === 0) {
  3874. H = 0;
  3875. S = 0;
  3876. }
  3877. else {
  3878. if (L < 0.5) {
  3879. S = delta / (vMax + vMin);
  3880. }
  3881. else {
  3882. S = delta / (2 - vMax - vMin);
  3883. }
  3884. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  3885. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  3886. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  3887. if (R === vMax) {
  3888. H = deltaB - deltaG;
  3889. }
  3890. else if (G === vMax) {
  3891. H = (1 / 3) + deltaR - deltaB;
  3892. }
  3893. else if (B === vMax) {
  3894. H = (2 / 3) + deltaG - deltaR;
  3895. }
  3896. if (H < 0) {
  3897. H += 1;
  3898. }
  3899. if (H > 1) {
  3900. H -= 1;
  3901. }
  3902. }
  3903. var hsla = [H * 360, S, L];
  3904. if (rgba[3] != null) {
  3905. hsla.push(rgba[3]);
  3906. }
  3907. return hsla;
  3908. }
  3909. function lift(color, level) {
  3910. var colorArr = parse(color);
  3911. if (colorArr) {
  3912. for (var i = 0; i < 3; i++) {
  3913. if (level < 0) {
  3914. colorArr[i] = colorArr[i] * (1 - level) | 0;
  3915. }
  3916. else {
  3917. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  3918. }
  3919. if (colorArr[i] > 255) {
  3920. colorArr[i] = 255;
  3921. }
  3922. else if (colorArr[i] < 0) {
  3923. colorArr[i] = 0;
  3924. }
  3925. }
  3926. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  3927. }
  3928. }
  3929. function toHex(color) {
  3930. var colorArr = parse(color);
  3931. if (colorArr) {
  3932. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  3933. }
  3934. }
  3935. function fastLerp(normalizedValue, colors, out) {
  3936. if (!(colors && colors.length)
  3937. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3938. return;
  3939. }
  3940. out = out || [];
  3941. var value = normalizedValue * (colors.length - 1);
  3942. var leftIndex = Math.floor(value);
  3943. var rightIndex = Math.ceil(value);
  3944. var leftColor = colors[leftIndex];
  3945. var rightColor = colors[rightIndex];
  3946. var dv = value - leftIndex;
  3947. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  3948. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  3949. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  3950. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  3951. return out;
  3952. }
  3953. var fastMapToColor = fastLerp;
  3954. function lerp$1(normalizedValue, colors, fullOutput) {
  3955. if (!(colors && colors.length)
  3956. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3957. return;
  3958. }
  3959. var value = normalizedValue * (colors.length - 1);
  3960. var leftIndex = Math.floor(value);
  3961. var rightIndex = Math.ceil(value);
  3962. var leftColor = parse(colors[leftIndex]);
  3963. var rightColor = parse(colors[rightIndex]);
  3964. var dv = value - leftIndex;
  3965. var color = stringify([
  3966. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  3967. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  3968. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  3969. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  3970. ], 'rgba');
  3971. return fullOutput
  3972. ? {
  3973. color: color,
  3974. leftIndex: leftIndex,
  3975. rightIndex: rightIndex,
  3976. value: value
  3977. }
  3978. : color;
  3979. }
  3980. var mapToColor = lerp$1;
  3981. function modifyHSL(color, h, s, l) {
  3982. var colorArr = parse(color);
  3983. if (color) {
  3984. colorArr = rgba2hsla(colorArr);
  3985. h != null && (colorArr[0] = clampCssAngle(h));
  3986. s != null && (colorArr[1] = parseCssFloat(s));
  3987. l != null && (colorArr[2] = parseCssFloat(l));
  3988. return stringify(hsla2rgba(colorArr), 'rgba');
  3989. }
  3990. }
  3991. function modifyAlpha(color, alpha) {
  3992. var colorArr = parse(color);
  3993. if (colorArr && alpha != null) {
  3994. colorArr[3] = clampCssFloat(alpha);
  3995. return stringify(colorArr, 'rgba');
  3996. }
  3997. }
  3998. function stringify(arrColor, type) {
  3999. if (!arrColor || !arrColor.length) {
  4000. return;
  4001. }
  4002. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  4003. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  4004. colorStr += ',' + arrColor[3];
  4005. }
  4006. return type + '(' + colorStr + ')';
  4007. }
  4008. function lum(color, backgroundLum) {
  4009. var arr = parse(color);
  4010. return arr
  4011. ? (0.299 * arr[0] + 0.587 * arr[1] + 0.114 * arr[2]) * arr[3] / 255
  4012. + (1 - arr[3]) * backgroundLum
  4013. : 0;
  4014. }
  4015. function random() {
  4016. return stringify([
  4017. Math.round(Math.random() * 255),
  4018. Math.round(Math.random() * 255),
  4019. Math.round(Math.random() * 255)
  4020. ], 'rgb');
  4021. }
  4022. var liftedColorCache = new LRU(100);
  4023. function liftColor(color) {
  4024. if (isString(color)) {
  4025. var liftedColor = liftedColorCache.get(color);
  4026. if (!liftedColor) {
  4027. liftedColor = lift(color, -0.1);
  4028. liftedColorCache.put(color, liftedColor);
  4029. }
  4030. return liftedColor;
  4031. }
  4032. else if (isGradientObject(color)) {
  4033. var ret = extend({}, color);
  4034. ret.colorStops = map(color.colorStops, function (stop) { return ({
  4035. offset: stop.offset,
  4036. color: lift(stop.color, -0.1)
  4037. }); });
  4038. return ret;
  4039. }
  4040. return color;
  4041. }
  4042. var color = /*#__PURE__*/Object.freeze({
  4043. __proto__: null,
  4044. parse: parse,
  4045. lift: lift,
  4046. toHex: toHex,
  4047. fastLerp: fastLerp,
  4048. fastMapToColor: fastMapToColor,
  4049. lerp: lerp$1,
  4050. mapToColor: mapToColor,
  4051. modifyHSL: modifyHSL,
  4052. modifyAlpha: modifyAlpha,
  4053. stringify: stringify,
  4054. lum: lum,
  4055. random: random,
  4056. liftColor: liftColor
  4057. });
  4058. var mathRound = Math.round;
  4059. function normalizeColor(color) {
  4060. var opacity;
  4061. if (!color || color === 'transparent') {
  4062. color = 'none';
  4063. }
  4064. else if (typeof color === 'string' && color.indexOf('rgba') > -1) {
  4065. var arr = parse(color);
  4066. if (arr) {
  4067. color = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')';
  4068. opacity = arr[3];
  4069. }
  4070. }
  4071. return {
  4072. color: color,
  4073. opacity: opacity == null ? 1 : opacity
  4074. };
  4075. }
  4076. var EPSILON$1 = 1e-4;
  4077. function isAroundZero$1(transform) {
  4078. return transform < EPSILON$1 && transform > -EPSILON$1;
  4079. }
  4080. function round3(transform) {
  4081. return mathRound(transform * 1e3) / 1e3;
  4082. }
  4083. function round4(transform) {
  4084. return mathRound(transform * 1e4) / 1e4;
  4085. }
  4086. function getMatrixStr(m) {
  4087. return 'matrix('
  4088. + round3(m[0]) + ','
  4089. + round3(m[1]) + ','
  4090. + round3(m[2]) + ','
  4091. + round3(m[3]) + ','
  4092. + round4(m[4]) + ','
  4093. + round4(m[5])
  4094. + ')';
  4095. }
  4096. var TEXT_ALIGN_TO_ANCHOR = {
  4097. left: 'start',
  4098. right: 'end',
  4099. center: 'middle',
  4100. middle: 'middle'
  4101. };
  4102. function adjustTextY(y, lineHeight, textBaseline) {
  4103. if (textBaseline === 'top') {
  4104. y += lineHeight / 2;
  4105. }
  4106. else if (textBaseline === 'bottom') {
  4107. y -= lineHeight / 2;
  4108. }
  4109. return y;
  4110. }
  4111. function hasShadow(style) {
  4112. return style
  4113. && (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY);
  4114. }
  4115. function getShadowKey(displayable) {
  4116. var style = displayable.style;
  4117. var globalScale = displayable.getGlobalScale();
  4118. return [
  4119. style.shadowColor,
  4120. (style.shadowBlur || 0).toFixed(2),
  4121. (style.shadowOffsetX || 0).toFixed(2),
  4122. (style.shadowOffsetY || 0).toFixed(2),
  4123. globalScale[0],
  4124. globalScale[1]
  4125. ].join(',');
  4126. }
  4127. function isImagePattern(val) {
  4128. return val && (!!val.image);
  4129. }
  4130. function isSVGPattern(val) {
  4131. return val && (!!val.svgElement);
  4132. }
  4133. function isPattern(val) {
  4134. return isImagePattern(val) || isSVGPattern(val);
  4135. }
  4136. function isLinearGradient(val) {
  4137. return val.type === 'linear';
  4138. }
  4139. function isRadialGradient(val) {
  4140. return val.type === 'radial';
  4141. }
  4142. function isGradient(val) {
  4143. return val && (val.type === 'linear'
  4144. || val.type === 'radial');
  4145. }
  4146. function getIdURL(id) {
  4147. return "url(#" + id + ")";
  4148. }
  4149. function getPathPrecision(el) {
  4150. var scale = el.getGlobalScale();
  4151. var size = Math.max(scale[0], scale[1]);
  4152. return Math.max(Math.ceil(Math.log(size) / Math.log(10)), 1);
  4153. }
  4154. function getSRTTransformString(transform) {
  4155. var x = transform.x || 0;
  4156. var y = transform.y || 0;
  4157. var rotation = (transform.rotation || 0) * RADIAN_TO_DEGREE;
  4158. var scaleX = retrieve2(transform.scaleX, 1);
  4159. var scaleY = retrieve2(transform.scaleY, 1);
  4160. var skewX = transform.skewX || 0;
  4161. var skewY = transform.skewY || 0;
  4162. var res = [];
  4163. if (x || y) {
  4164. res.push("translate(" + x + "px," + y + "px)");
  4165. }
  4166. if (rotation) {
  4167. res.push("rotate(" + rotation + ")");
  4168. }
  4169. if (scaleX !== 1 || scaleY !== 1) {
  4170. res.push("scale(" + scaleX + "," + scaleY + ")");
  4171. }
  4172. if (skewX || skewY) {
  4173. res.push("skew(" + mathRound(skewX * RADIAN_TO_DEGREE) + "deg, " + mathRound(skewY * RADIAN_TO_DEGREE) + "deg)");
  4174. }
  4175. return res.join(' ');
  4176. }
  4177. var encodeBase64 = (function () {
  4178. if (env.hasGlobalWindow && isFunction(window.btoa)) {
  4179. return function (str) {
  4180. return window.btoa(unescape(encodeURIComponent(str)));
  4181. };
  4182. }
  4183. if (typeof Buffer !== 'undefined') {
  4184. return function (str) {
  4185. return Buffer.from(str).toString('base64');
  4186. };
  4187. }
  4188. return function (str) {
  4189. {
  4190. logError('Base64 isn\'t natively supported in the current environment.');
  4191. }
  4192. return null;
  4193. };
  4194. })();
  4195. var arraySlice = Array.prototype.slice;
  4196. function interpolateNumber(p0, p1, percent) {
  4197. return (p1 - p0) * percent + p0;
  4198. }
  4199. function interpolate1DArray(out, p0, p1, percent) {
  4200. var len = p0.length;
  4201. for (var i = 0; i < len; i++) {
  4202. out[i] = interpolateNumber(p0[i], p1[i], percent);
  4203. }
  4204. return out;
  4205. }
  4206. function interpolate2DArray(out, p0, p1, percent) {
  4207. var len = p0.length;
  4208. var len2 = len && p0[0].length;
  4209. for (var i = 0; i < len; i++) {
  4210. if (!out[i]) {
  4211. out[i] = [];
  4212. }
  4213. for (var j = 0; j < len2; j++) {
  4214. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  4215. }
  4216. }
  4217. return out;
  4218. }
  4219. function add1DArray(out, p0, p1, sign) {
  4220. var len = p0.length;
  4221. for (var i = 0; i < len; i++) {
  4222. out[i] = p0[i] + p1[i] * sign;
  4223. }
  4224. return out;
  4225. }
  4226. function add2DArray(out, p0, p1, sign) {
  4227. var len = p0.length;
  4228. var len2 = len && p0[0].length;
  4229. for (var i = 0; i < len; i++) {
  4230. if (!out[i]) {
  4231. out[i] = [];
  4232. }
  4233. for (var j = 0; j < len2; j++) {
  4234. out[i][j] = p0[i][j] + p1[i][j] * sign;
  4235. }
  4236. }
  4237. return out;
  4238. }
  4239. function fillColorStops(val0, val1) {
  4240. var len0 = val0.length;
  4241. var len1 = val1.length;
  4242. var shorterArr = len0 > len1 ? val1 : val0;
  4243. var shorterLen = Math.min(len0, len1);
  4244. var last = shorterArr[shorterLen - 1] || { color: [0, 0, 0, 0], offset: 0 };
  4245. for (var i = shorterLen; i < Math.max(len0, len1); i++) {
  4246. shorterArr.push({
  4247. offset: last.offset,
  4248. color: last.color.slice()
  4249. });
  4250. }
  4251. }
  4252. function fillArray(val0, val1, arrDim) {
  4253. var arr0 = val0;
  4254. var arr1 = val1;
  4255. if (!arr0.push || !arr1.push) {
  4256. return;
  4257. }
  4258. var arr0Len = arr0.length;
  4259. var arr1Len = arr1.length;
  4260. if (arr0Len !== arr1Len) {
  4261. var isPreviousLarger = arr0Len > arr1Len;
  4262. if (isPreviousLarger) {
  4263. arr0.length = arr1Len;
  4264. }
  4265. else {
  4266. for (var i = arr0Len; i < arr1Len; i++) {
  4267. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  4268. }
  4269. }
  4270. }
  4271. var len2 = arr0[0] && arr0[0].length;
  4272. for (var i = 0; i < arr0.length; i++) {
  4273. if (arrDim === 1) {
  4274. if (isNaN(arr0[i])) {
  4275. arr0[i] = arr1[i];
  4276. }
  4277. }
  4278. else {
  4279. for (var j = 0; j < len2; j++) {
  4280. if (isNaN(arr0[i][j])) {
  4281. arr0[i][j] = arr1[i][j];
  4282. }
  4283. }
  4284. }
  4285. }
  4286. }
  4287. function cloneValue(value) {
  4288. if (isArrayLike(value)) {
  4289. var len = value.length;
  4290. if (isArrayLike(value[0])) {
  4291. var ret = [];
  4292. for (var i = 0; i < len; i++) {
  4293. ret.push(arraySlice.call(value[i]));
  4294. }
  4295. return ret;
  4296. }
  4297. return arraySlice.call(value);
  4298. }
  4299. return value;
  4300. }
  4301. function rgba2String(rgba) {
  4302. rgba[0] = Math.floor(rgba[0]) || 0;
  4303. rgba[1] = Math.floor(rgba[1]) || 0;
  4304. rgba[2] = Math.floor(rgba[2]) || 0;
  4305. rgba[3] = rgba[3] == null ? 1 : rgba[3];
  4306. return 'rgba(' + rgba.join(',') + ')';
  4307. }
  4308. function guessArrayDim(value) {
  4309. return isArrayLike(value && value[0]) ? 2 : 1;
  4310. }
  4311. var VALUE_TYPE_NUMBER = 0;
  4312. var VALUE_TYPE_1D_ARRAY = 1;
  4313. var VALUE_TYPE_2D_ARRAY = 2;
  4314. var VALUE_TYPE_COLOR = 3;
  4315. var VALUE_TYPE_LINEAR_GRADIENT = 4;
  4316. var VALUE_TYPE_RADIAL_GRADIENT = 5;
  4317. var VALUE_TYPE_UNKOWN = 6;
  4318. function isGradientValueType(valType) {
  4319. return valType === VALUE_TYPE_LINEAR_GRADIENT || valType === VALUE_TYPE_RADIAL_GRADIENT;
  4320. }
  4321. function isArrayValueType(valType) {
  4322. return valType === VALUE_TYPE_1D_ARRAY || valType === VALUE_TYPE_2D_ARRAY;
  4323. }
  4324. var tmpRgba = [0, 0, 0, 0];
  4325. var Track = (function () {
  4326. function Track(propName) {
  4327. this.keyframes = [];
  4328. this.discrete = false;
  4329. this._invalid = false;
  4330. this._needsSort = false;
  4331. this._lastFr = 0;
  4332. this._lastFrP = 0;
  4333. this.propName = propName;
  4334. }
  4335. Track.prototype.isFinished = function () {
  4336. return this._finished;
  4337. };
  4338. Track.prototype.setFinished = function () {
  4339. this._finished = true;
  4340. if (this._additiveTrack) {
  4341. this._additiveTrack.setFinished();
  4342. }
  4343. };
  4344. Track.prototype.needsAnimate = function () {
  4345. return this.keyframes.length >= 1;
  4346. };
  4347. Track.prototype.getAdditiveTrack = function () {
  4348. return this._additiveTrack;
  4349. };
  4350. Track.prototype.addKeyframe = function (time, rawValue, easing) {
  4351. this._needsSort = true;
  4352. var keyframes = this.keyframes;
  4353. var len = keyframes.length;
  4354. var discrete = false;
  4355. var valType = VALUE_TYPE_UNKOWN;
  4356. var value = rawValue;
  4357. if (isArrayLike(rawValue)) {
  4358. var arrayDim = guessArrayDim(rawValue);
  4359. valType = arrayDim;
  4360. if (arrayDim === 1 && !isNumber(rawValue[0])
  4361. || arrayDim === 2 && !isNumber(rawValue[0][0])) {
  4362. discrete = true;
  4363. }
  4364. }
  4365. else {
  4366. if (isNumber(rawValue) && !eqNaN(rawValue)) {
  4367. valType = VALUE_TYPE_NUMBER;
  4368. }
  4369. else if (isString(rawValue)) {
  4370. if (!isNaN(+rawValue)) {
  4371. valType = VALUE_TYPE_NUMBER;
  4372. }
  4373. else {
  4374. var colorArray = parse(rawValue);
  4375. if (colorArray) {
  4376. value = colorArray;
  4377. valType = VALUE_TYPE_COLOR;
  4378. }
  4379. }
  4380. }
  4381. else if (isGradientObject(rawValue)) {
  4382. var parsedGradient = extend({}, value);
  4383. parsedGradient.colorStops = map(rawValue.colorStops, function (colorStop) { return ({
  4384. offset: colorStop.offset,
  4385. color: parse(colorStop.color)
  4386. }); });
  4387. if (isLinearGradient(rawValue)) {
  4388. valType = VALUE_TYPE_LINEAR_GRADIENT;
  4389. }
  4390. else if (isRadialGradient(rawValue)) {
  4391. valType = VALUE_TYPE_RADIAL_GRADIENT;
  4392. }
  4393. value = parsedGradient;
  4394. }
  4395. }
  4396. if (len === 0) {
  4397. this.valType = valType;
  4398. }
  4399. else if (valType !== this.valType || valType === VALUE_TYPE_UNKOWN) {
  4400. discrete = true;
  4401. }
  4402. this.discrete = this.discrete || discrete;
  4403. var kf = {
  4404. time: time,
  4405. value: value,
  4406. rawValue: rawValue,
  4407. percent: 0
  4408. };
  4409. if (easing) {
  4410. kf.easing = easing;
  4411. kf.easingFunc = isFunction(easing)
  4412. ? easing
  4413. : easingFuncs[easing] || createCubicEasingFunc(easing);
  4414. }
  4415. keyframes.push(kf);
  4416. return kf;
  4417. };
  4418. Track.prototype.prepare = function (maxTime, additiveTrack) {
  4419. var kfs = this.keyframes;
  4420. if (this._needsSort) {
  4421. kfs.sort(function (a, b) {
  4422. return a.time - b.time;
  4423. });
  4424. }
  4425. var valType = this.valType;
  4426. var kfsLen = kfs.length;
  4427. var lastKf = kfs[kfsLen - 1];
  4428. var isDiscrete = this.discrete;
  4429. var isArr = isArrayValueType(valType);
  4430. var isGradient = isGradientValueType(valType);
  4431. for (var i = 0; i < kfsLen; i++) {
  4432. var kf = kfs[i];
  4433. var value = kf.value;
  4434. var lastValue = lastKf.value;
  4435. kf.percent = kf.time / maxTime;
  4436. if (!isDiscrete) {
  4437. if (isArr && i !== kfsLen - 1) {
  4438. fillArray(value, lastValue, valType);
  4439. }
  4440. else if (isGradient) {
  4441. fillColorStops(value.colorStops, lastValue.colorStops);
  4442. }
  4443. }
  4444. }
  4445. if (!isDiscrete
  4446. && valType !== VALUE_TYPE_RADIAL_GRADIENT
  4447. && additiveTrack
  4448. && this.needsAnimate()
  4449. && additiveTrack.needsAnimate()
  4450. && valType === additiveTrack.valType
  4451. && !additiveTrack._finished) {
  4452. this._additiveTrack = additiveTrack;
  4453. var startValue = kfs[0].value;
  4454. for (var i = 0; i < kfsLen; i++) {
  4455. if (valType === VALUE_TYPE_NUMBER) {
  4456. kfs[i].additiveValue = kfs[i].value - startValue;
  4457. }
  4458. else if (valType === VALUE_TYPE_COLOR) {
  4459. kfs[i].additiveValue =
  4460. add1DArray([], kfs[i].value, startValue, -1);
  4461. }
  4462. else if (isArrayValueType(valType)) {
  4463. kfs[i].additiveValue = valType === VALUE_TYPE_1D_ARRAY
  4464. ? add1DArray([], kfs[i].value, startValue, -1)
  4465. : add2DArray([], kfs[i].value, startValue, -1);
  4466. }
  4467. }
  4468. }
  4469. };
  4470. Track.prototype.step = function (target, percent) {
  4471. if (this._finished) {
  4472. return;
  4473. }
  4474. if (this._additiveTrack && this._additiveTrack._finished) {
  4475. this._additiveTrack = null;
  4476. }
  4477. var isAdditive = this._additiveTrack != null;
  4478. var valueKey = isAdditive ? 'additiveValue' : 'value';
  4479. var valType = this.valType;
  4480. var keyframes = this.keyframes;
  4481. var kfsNum = keyframes.length;
  4482. var propName = this.propName;
  4483. var isValueColor = valType === VALUE_TYPE_COLOR;
  4484. var frameIdx;
  4485. var lastFrame = this._lastFr;
  4486. var mathMin = Math.min;
  4487. var frame;
  4488. var nextFrame;
  4489. if (kfsNum === 1) {
  4490. frame = nextFrame = keyframes[0];
  4491. }
  4492. else {
  4493. if (percent < 0) {
  4494. frameIdx = 0;
  4495. }
  4496. else if (percent < this._lastFrP) {
  4497. var start = mathMin(lastFrame + 1, kfsNum - 1);
  4498. for (frameIdx = start; frameIdx >= 0; frameIdx--) {
  4499. if (keyframes[frameIdx].percent <= percent) {
  4500. break;
  4501. }
  4502. }
  4503. frameIdx = mathMin(frameIdx, kfsNum - 2);
  4504. }
  4505. else {
  4506. for (frameIdx = lastFrame; frameIdx < kfsNum; frameIdx++) {
  4507. if (keyframes[frameIdx].percent > percent) {
  4508. break;
  4509. }
  4510. }
  4511. frameIdx = mathMin(frameIdx - 1, kfsNum - 2);
  4512. }
  4513. nextFrame = keyframes[frameIdx + 1];
  4514. frame = keyframes[frameIdx];
  4515. }
  4516. if (!(frame && nextFrame)) {
  4517. return;
  4518. }
  4519. this._lastFr = frameIdx;
  4520. this._lastFrP = percent;
  4521. var interval = (nextFrame.percent - frame.percent);
  4522. var w = interval === 0 ? 1 : mathMin((percent - frame.percent) / interval, 1);
  4523. if (nextFrame.easingFunc) {
  4524. w = nextFrame.easingFunc(w);
  4525. }
  4526. var targetArr = isAdditive ? this._additiveValue
  4527. : (isValueColor ? tmpRgba : target[propName]);
  4528. if ((isArrayValueType(valType) || isValueColor) && !targetArr) {
  4529. targetArr = this._additiveValue = [];
  4530. }
  4531. if (this.discrete) {
  4532. target[propName] = w < 1 ? frame.rawValue : nextFrame.rawValue;
  4533. }
  4534. else if (isArrayValueType(valType)) {
  4535. valType === VALUE_TYPE_1D_ARRAY
  4536. ? interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w)
  4537. : interpolate2DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4538. }
  4539. else if (isGradientValueType(valType)) {
  4540. var val = frame[valueKey];
  4541. var nextVal_1 = nextFrame[valueKey];
  4542. var isLinearGradient_1 = valType === VALUE_TYPE_LINEAR_GRADIENT;
  4543. target[propName] = {
  4544. type: isLinearGradient_1 ? 'linear' : 'radial',
  4545. x: interpolateNumber(val.x, nextVal_1.x, w),
  4546. y: interpolateNumber(val.y, nextVal_1.y, w),
  4547. colorStops: map(val.colorStops, function (colorStop, idx) {
  4548. var nextColorStop = nextVal_1.colorStops[idx];
  4549. return {
  4550. offset: interpolateNumber(colorStop.offset, nextColorStop.offset, w),
  4551. color: rgba2String(interpolate1DArray([], colorStop.color, nextColorStop.color, w))
  4552. };
  4553. }),
  4554. global: nextVal_1.global
  4555. };
  4556. if (isLinearGradient_1) {
  4557. target[propName].x2 = interpolateNumber(val.x2, nextVal_1.x2, w);
  4558. target[propName].y2 = interpolateNumber(val.y2, nextVal_1.y2, w);
  4559. }
  4560. else {
  4561. target[propName].r = interpolateNumber(val.r, nextVal_1.r, w);
  4562. }
  4563. }
  4564. else if (isValueColor) {
  4565. interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4566. if (!isAdditive) {
  4567. target[propName] = rgba2String(targetArr);
  4568. }
  4569. }
  4570. else {
  4571. var value = interpolateNumber(frame[valueKey], nextFrame[valueKey], w);
  4572. if (isAdditive) {
  4573. this._additiveValue = value;
  4574. }
  4575. else {
  4576. target[propName] = value;
  4577. }
  4578. }
  4579. if (isAdditive) {
  4580. this._addToTarget(target);
  4581. }
  4582. };
  4583. Track.prototype._addToTarget = function (target) {
  4584. var valType = this.valType;
  4585. var propName = this.propName;
  4586. var additiveValue = this._additiveValue;
  4587. if (valType === VALUE_TYPE_NUMBER) {
  4588. target[propName] = target[propName] + additiveValue;
  4589. }
  4590. else if (valType === VALUE_TYPE_COLOR) {
  4591. parse(target[propName], tmpRgba);
  4592. add1DArray(tmpRgba, tmpRgba, additiveValue, 1);
  4593. target[propName] = rgba2String(tmpRgba);
  4594. }
  4595. else if (valType === VALUE_TYPE_1D_ARRAY) {
  4596. add1DArray(target[propName], target[propName], additiveValue, 1);
  4597. }
  4598. else if (valType === VALUE_TYPE_2D_ARRAY) {
  4599. add2DArray(target[propName], target[propName], additiveValue, 1);
  4600. }
  4601. };
  4602. return Track;
  4603. }());
  4604. var Animator = (function () {
  4605. function Animator(target, loop, allowDiscreteAnimation, additiveTo) {
  4606. this._tracks = {};
  4607. this._trackKeys = [];
  4608. this._maxTime = 0;
  4609. this._started = 0;
  4610. this._clip = null;
  4611. this._target = target;
  4612. this._loop = loop;
  4613. if (loop && additiveTo) {
  4614. logError('Can\' use additive animation on looped animation.');
  4615. return;
  4616. }
  4617. this._additiveAnimators = additiveTo;
  4618. this._allowDiscrete = allowDiscreteAnimation;
  4619. }
  4620. Animator.prototype.getMaxTime = function () {
  4621. return this._maxTime;
  4622. };
  4623. Animator.prototype.getDelay = function () {
  4624. return this._delay;
  4625. };
  4626. Animator.prototype.getLoop = function () {
  4627. return this._loop;
  4628. };
  4629. Animator.prototype.getTarget = function () {
  4630. return this._target;
  4631. };
  4632. Animator.prototype.changeTarget = function (target) {
  4633. this._target = target;
  4634. };
  4635. Animator.prototype.when = function (time, props, easing) {
  4636. return this.whenWithKeys(time, props, keys(props), easing);
  4637. };
  4638. Animator.prototype.whenWithKeys = function (time, props, propNames, easing) {
  4639. var tracks = this._tracks;
  4640. for (var i = 0; i < propNames.length; i++) {
  4641. var propName = propNames[i];
  4642. var track = tracks[propName];
  4643. if (!track) {
  4644. track = tracks[propName] = new Track(propName);
  4645. var initialValue = void 0;
  4646. var additiveTrack = this._getAdditiveTrack(propName);
  4647. if (additiveTrack) {
  4648. var addtiveTrackKfs = additiveTrack.keyframes;
  4649. var lastFinalKf = addtiveTrackKfs[addtiveTrackKfs.length - 1];
  4650. initialValue = lastFinalKf && lastFinalKf.value;
  4651. if (additiveTrack.valType === VALUE_TYPE_COLOR && initialValue) {
  4652. initialValue = rgba2String(initialValue);
  4653. }
  4654. }
  4655. else {
  4656. initialValue = this._target[propName];
  4657. }
  4658. if (initialValue == null) {
  4659. continue;
  4660. }
  4661. if (time > 0) {
  4662. track.addKeyframe(0, cloneValue(initialValue), easing);
  4663. }
  4664. this._trackKeys.push(propName);
  4665. }
  4666. track.addKeyframe(time, cloneValue(props[propName]), easing);
  4667. }
  4668. this._maxTime = Math.max(this._maxTime, time);
  4669. return this;
  4670. };
  4671. Animator.prototype.pause = function () {
  4672. this._clip.pause();
  4673. this._paused = true;
  4674. };
  4675. Animator.prototype.resume = function () {
  4676. this._clip.resume();
  4677. this._paused = false;
  4678. };
  4679. Animator.prototype.isPaused = function () {
  4680. return !!this._paused;
  4681. };
  4682. Animator.prototype.duration = function (duration) {
  4683. this._maxTime = duration;
  4684. this._force = true;
  4685. return this;
  4686. };
  4687. Animator.prototype._doneCallback = function () {
  4688. this._setTracksFinished();
  4689. this._clip = null;
  4690. var doneList = this._doneCbs;
  4691. if (doneList) {
  4692. var len = doneList.length;
  4693. for (var i = 0; i < len; i++) {
  4694. doneList[i].call(this);
  4695. }
  4696. }
  4697. };
  4698. Animator.prototype._abortedCallback = function () {
  4699. this._setTracksFinished();
  4700. var animation = this.animation;
  4701. var abortedList = this._abortedCbs;
  4702. if (animation) {
  4703. animation.removeClip(this._clip);
  4704. }
  4705. this._clip = null;
  4706. if (abortedList) {
  4707. for (var i = 0; i < abortedList.length; i++) {
  4708. abortedList[i].call(this);
  4709. }
  4710. }
  4711. };
  4712. Animator.prototype._setTracksFinished = function () {
  4713. var tracks = this._tracks;
  4714. var tracksKeys = this._trackKeys;
  4715. for (var i = 0; i < tracksKeys.length; i++) {
  4716. tracks[tracksKeys[i]].setFinished();
  4717. }
  4718. };
  4719. Animator.prototype._getAdditiveTrack = function (trackName) {
  4720. var additiveTrack;
  4721. var additiveAnimators = this._additiveAnimators;
  4722. if (additiveAnimators) {
  4723. for (var i = 0; i < additiveAnimators.length; i++) {
  4724. var track = additiveAnimators[i].getTrack(trackName);
  4725. if (track) {
  4726. additiveTrack = track;
  4727. }
  4728. }
  4729. }
  4730. return additiveTrack;
  4731. };
  4732. Animator.prototype.start = function (easing) {
  4733. if (this._started > 0) {
  4734. return;
  4735. }
  4736. this._started = 1;
  4737. var self = this;
  4738. var tracks = [];
  4739. var maxTime = this._maxTime || 0;
  4740. for (var i = 0; i < this._trackKeys.length; i++) {
  4741. var propName = this._trackKeys[i];
  4742. var track = this._tracks[propName];
  4743. var additiveTrack = this._getAdditiveTrack(propName);
  4744. var kfs = track.keyframes;
  4745. var kfsNum = kfs.length;
  4746. track.prepare(maxTime, additiveTrack);
  4747. if (track.needsAnimate()) {
  4748. if (!this._allowDiscrete && track.discrete) {
  4749. var lastKf = kfs[kfsNum - 1];
  4750. if (lastKf) {
  4751. self._target[track.propName] = lastKf.rawValue;
  4752. }
  4753. track.setFinished();
  4754. }
  4755. else {
  4756. tracks.push(track);
  4757. }
  4758. }
  4759. }
  4760. if (tracks.length || this._force) {
  4761. var clip = new Clip({
  4762. life: maxTime,
  4763. loop: this._loop,
  4764. delay: this._delay || 0,
  4765. onframe: function (percent) {
  4766. self._started = 2;
  4767. var additiveAnimators = self._additiveAnimators;
  4768. if (additiveAnimators) {
  4769. var stillHasAdditiveAnimator = false;
  4770. for (var i = 0; i < additiveAnimators.length; i++) {
  4771. if (additiveAnimators[i]._clip) {
  4772. stillHasAdditiveAnimator = true;
  4773. break;
  4774. }
  4775. }
  4776. if (!stillHasAdditiveAnimator) {
  4777. self._additiveAnimators = null;
  4778. }
  4779. }
  4780. for (var i = 0; i < tracks.length; i++) {
  4781. tracks[i].step(self._target, percent);
  4782. }
  4783. var onframeList = self._onframeCbs;
  4784. if (onframeList) {
  4785. for (var i = 0; i < onframeList.length; i++) {
  4786. onframeList[i](self._target, percent);
  4787. }
  4788. }
  4789. },
  4790. ondestroy: function () {
  4791. self._doneCallback();
  4792. }
  4793. });
  4794. this._clip = clip;
  4795. if (this.animation) {
  4796. this.animation.addClip(clip);
  4797. }
  4798. if (easing) {
  4799. clip.setEasing(easing);
  4800. }
  4801. }
  4802. else {
  4803. this._doneCallback();
  4804. }
  4805. return this;
  4806. };
  4807. Animator.prototype.stop = function (forwardToLast) {
  4808. if (!this._clip) {
  4809. return;
  4810. }
  4811. var clip = this._clip;
  4812. if (forwardToLast) {
  4813. clip.onframe(1);
  4814. }
  4815. this._abortedCallback();
  4816. };
  4817. Animator.prototype.delay = function (time) {
  4818. this._delay = time;
  4819. return this;
  4820. };
  4821. Animator.prototype.during = function (cb) {
  4822. if (cb) {
  4823. if (!this._onframeCbs) {
  4824. this._onframeCbs = [];
  4825. }
  4826. this._onframeCbs.push(cb);
  4827. }
  4828. return this;
  4829. };
  4830. Animator.prototype.done = function (cb) {
  4831. if (cb) {
  4832. if (!this._doneCbs) {
  4833. this._doneCbs = [];
  4834. }
  4835. this._doneCbs.push(cb);
  4836. }
  4837. return this;
  4838. };
  4839. Animator.prototype.aborted = function (cb) {
  4840. if (cb) {
  4841. if (!this._abortedCbs) {
  4842. this._abortedCbs = [];
  4843. }
  4844. this._abortedCbs.push(cb);
  4845. }
  4846. return this;
  4847. };
  4848. Animator.prototype.getClip = function () {
  4849. return this._clip;
  4850. };
  4851. Animator.prototype.getTrack = function (propName) {
  4852. return this._tracks[propName];
  4853. };
  4854. Animator.prototype.getTracks = function () {
  4855. var _this = this;
  4856. return map(this._trackKeys, function (key) { return _this._tracks[key]; });
  4857. };
  4858. Animator.prototype.stopTracks = function (propNames, forwardToLast) {
  4859. if (!propNames.length || !this._clip) {
  4860. return true;
  4861. }
  4862. var tracks = this._tracks;
  4863. var tracksKeys = this._trackKeys;
  4864. for (var i = 0; i < propNames.length; i++) {
  4865. var track = tracks[propNames[i]];
  4866. if (track && !track.isFinished()) {
  4867. if (forwardToLast) {
  4868. track.step(this._target, 1);
  4869. }
  4870. else if (this._started === 1) {
  4871. track.step(this._target, 0);
  4872. }
  4873. track.setFinished();
  4874. }
  4875. }
  4876. var allAborted = true;
  4877. for (var i = 0; i < tracksKeys.length; i++) {
  4878. if (!tracks[tracksKeys[i]].isFinished()) {
  4879. allAborted = false;
  4880. break;
  4881. }
  4882. }
  4883. if (allAborted) {
  4884. this._abortedCallback();
  4885. }
  4886. return allAborted;
  4887. };
  4888. Animator.prototype.saveTo = function (target, trackKeys, firstOrLast) {
  4889. if (!target) {
  4890. return;
  4891. }
  4892. trackKeys = trackKeys || this._trackKeys;
  4893. for (var i = 0; i < trackKeys.length; i++) {
  4894. var propName = trackKeys[i];
  4895. var track = this._tracks[propName];
  4896. if (!track || track.isFinished()) {
  4897. continue;
  4898. }
  4899. var kfs = track.keyframes;
  4900. var kf = kfs[firstOrLast ? 0 : kfs.length - 1];
  4901. if (kf) {
  4902. target[propName] = cloneValue(kf.rawValue);
  4903. }
  4904. }
  4905. };
  4906. Animator.prototype.__changeFinalValue = function (finalProps, trackKeys) {
  4907. trackKeys = trackKeys || keys(finalProps);
  4908. for (var i = 0; i < trackKeys.length; i++) {
  4909. var propName = trackKeys[i];
  4910. var track = this._tracks[propName];
  4911. if (!track) {
  4912. continue;
  4913. }
  4914. var kfs = track.keyframes;
  4915. if (kfs.length > 1) {
  4916. var lastKf = kfs.pop();
  4917. track.addKeyframe(lastKf.time, finalProps[propName]);
  4918. track.prepare(this._maxTime, track.getAdditiveTrack());
  4919. }
  4920. }
  4921. };
  4922. return Animator;
  4923. }());
  4924. function getTime() {
  4925. return new Date().getTime();
  4926. }
  4927. var Animation = (function (_super) {
  4928. __extends(Animation, _super);
  4929. function Animation(opts) {
  4930. var _this = _super.call(this) || this;
  4931. _this._running = false;
  4932. _this._time = 0;
  4933. _this._pausedTime = 0;
  4934. _this._pauseStart = 0;
  4935. _this._paused = false;
  4936. opts = opts || {};
  4937. _this.stage = opts.stage || {};
  4938. return _this;
  4939. }
  4940. Animation.prototype.addClip = function (clip) {
  4941. if (clip.animation) {
  4942. this.removeClip(clip);
  4943. }
  4944. if (!this._head) {
  4945. this._head = this._tail = clip;
  4946. }
  4947. else {
  4948. this._tail.next = clip;
  4949. clip.prev = this._tail;
  4950. clip.next = null;
  4951. this._tail = clip;
  4952. }
  4953. clip.animation = this;
  4954. };
  4955. Animation.prototype.addAnimator = function (animator) {
  4956. animator.animation = this;
  4957. var clip = animator.getClip();
  4958. if (clip) {
  4959. this.addClip(clip);
  4960. }
  4961. };
  4962. Animation.prototype.removeClip = function (clip) {
  4963. if (!clip.animation) {
  4964. return;
  4965. }
  4966. var prev = clip.prev;
  4967. var next = clip.next;
  4968. if (prev) {
  4969. prev.next = next;
  4970. }
  4971. else {
  4972. this._head = next;
  4973. }
  4974. if (next) {
  4975. next.prev = prev;
  4976. }
  4977. else {
  4978. this._tail = prev;
  4979. }
  4980. clip.next = clip.prev = clip.animation = null;
  4981. };
  4982. Animation.prototype.removeAnimator = function (animator) {
  4983. var clip = animator.getClip();
  4984. if (clip) {
  4985. this.removeClip(clip);
  4986. }
  4987. animator.animation = null;
  4988. };
  4989. Animation.prototype.update = function (notTriggerFrameAndStageUpdate) {
  4990. var time = getTime() - this._pausedTime;
  4991. var delta = time - this._time;
  4992. var clip = this._head;
  4993. while (clip) {
  4994. var nextClip = clip.next;
  4995. var finished = clip.step(time, delta);
  4996. if (finished) {
  4997. clip.ondestroy();
  4998. this.removeClip(clip);
  4999. clip = nextClip;
  5000. }
  5001. else {
  5002. clip = nextClip;
  5003. }
  5004. }
  5005. this._time = time;
  5006. if (!notTriggerFrameAndStageUpdate) {
  5007. this.trigger('frame', delta);
  5008. this.stage.update && this.stage.update();
  5009. }
  5010. };
  5011. Animation.prototype._startLoop = function () {
  5012. var self = this;
  5013. this._running = true;
  5014. function step() {
  5015. if (self._running) {
  5016. requestAnimationFrame$1(step);
  5017. !self._paused && self.update();
  5018. }
  5019. }
  5020. requestAnimationFrame$1(step);
  5021. };
  5022. Animation.prototype.start = function () {
  5023. if (this._running) {
  5024. return;
  5025. }
  5026. this._time = getTime();
  5027. this._pausedTime = 0;
  5028. this._startLoop();
  5029. };
  5030. Animation.prototype.stop = function () {
  5031. this._running = false;
  5032. };
  5033. Animation.prototype.pause = function () {
  5034. if (!this._paused) {
  5035. this._pauseStart = getTime();
  5036. this._paused = true;
  5037. }
  5038. };
  5039. Animation.prototype.resume = function () {
  5040. if (this._paused) {
  5041. this._pausedTime += getTime() - this._pauseStart;
  5042. this._paused = false;
  5043. }
  5044. };
  5045. Animation.prototype.clear = function () {
  5046. var clip = this._head;
  5047. while (clip) {
  5048. var nextClip = clip.next;
  5049. clip.prev = clip.next = clip.animation = null;
  5050. clip = nextClip;
  5051. }
  5052. this._head = this._tail = null;
  5053. };
  5054. Animation.prototype.isFinished = function () {
  5055. return this._head == null;
  5056. };
  5057. Animation.prototype.animate = function (target, options) {
  5058. options = options || {};
  5059. this.start();
  5060. var animator = new Animator(target, options.loop);
  5061. this.addAnimator(animator);
  5062. return animator;
  5063. };
  5064. return Animation;
  5065. }(Eventful));
  5066. var TOUCH_CLICK_DELAY = 300;
  5067. var globalEventSupported = env.domSupported;
  5068. var localNativeListenerNames = (function () {
  5069. var mouseHandlerNames = [
  5070. 'click', 'dblclick', 'mousewheel', 'wheel', 'mouseout',
  5071. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  5072. ];
  5073. var touchHandlerNames = [
  5074. 'touchstart', 'touchend', 'touchmove'
  5075. ];
  5076. var pointerEventNameMap = {
  5077. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  5078. };
  5079. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  5080. var nm = name.replace('mouse', 'pointer');
  5081. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  5082. });
  5083. return {
  5084. mouse: mouseHandlerNames,
  5085. touch: touchHandlerNames,
  5086. pointer: pointerHandlerNames
  5087. };
  5088. })();
  5089. var globalNativeListenerNames = {
  5090. mouse: ['mousemove', 'mouseup'],
  5091. pointer: ['pointermove', 'pointerup']
  5092. };
  5093. var wheelEventSupported = false;
  5094. function isPointerFromTouch(event) {
  5095. var pointerType = event.pointerType;
  5096. return pointerType === 'pen' || pointerType === 'touch';
  5097. }
  5098. function setTouchTimer(scope) {
  5099. scope.touching = true;
  5100. if (scope.touchTimer != null) {
  5101. clearTimeout(scope.touchTimer);
  5102. scope.touchTimer = null;
  5103. }
  5104. scope.touchTimer = setTimeout(function () {
  5105. scope.touching = false;
  5106. scope.touchTimer = null;
  5107. }, 700);
  5108. }
  5109. function markTouch(event) {
  5110. event && (event.zrByTouch = true);
  5111. }
  5112. function normalizeGlobalEvent(instance, event) {
  5113. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  5114. }
  5115. function isLocalEl(instance, el) {
  5116. var elTmp = el;
  5117. var isLocal = false;
  5118. while (elTmp && elTmp.nodeType !== 9
  5119. && !(isLocal = elTmp.domBelongToZr
  5120. || (elTmp !== el && elTmp === instance.painterRoot))) {
  5121. elTmp = elTmp.parentNode;
  5122. }
  5123. return isLocal;
  5124. }
  5125. var FakeGlobalEvent = (function () {
  5126. function FakeGlobalEvent(instance, event) {
  5127. this.stopPropagation = noop;
  5128. this.stopImmediatePropagation = noop;
  5129. this.preventDefault = noop;
  5130. this.type = event.type;
  5131. this.target = this.currentTarget = instance.dom;
  5132. this.pointerType = event.pointerType;
  5133. this.clientX = event.clientX;
  5134. this.clientY = event.clientY;
  5135. }
  5136. return FakeGlobalEvent;
  5137. }());
  5138. var localDOMHandlers = {
  5139. mousedown: function (event) {
  5140. event = normalizeEvent(this.dom, event);
  5141. this.__mayPointerCapture = [event.zrX, event.zrY];
  5142. this.trigger('mousedown', event);
  5143. },
  5144. mousemove: function (event) {
  5145. event = normalizeEvent(this.dom, event);
  5146. var downPoint = this.__mayPointerCapture;
  5147. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  5148. this.__togglePointerCapture(true);
  5149. }
  5150. this.trigger('mousemove', event);
  5151. },
  5152. mouseup: function (event) {
  5153. event = normalizeEvent(this.dom, event);
  5154. this.__togglePointerCapture(false);
  5155. this.trigger('mouseup', event);
  5156. },
  5157. mouseout: function (event) {
  5158. event = normalizeEvent(this.dom, event);
  5159. var element = event.toElement || event.relatedTarget;
  5160. if (!isLocalEl(this, element)) {
  5161. if (this.__pointerCapturing) {
  5162. event.zrEventControl = 'no_globalout';
  5163. }
  5164. this.trigger('mouseout', event);
  5165. }
  5166. },
  5167. wheel: function (event) {
  5168. wheelEventSupported = true;
  5169. event = normalizeEvent(this.dom, event);
  5170. this.trigger('mousewheel', event);
  5171. },
  5172. mousewheel: function (event) {
  5173. if (wheelEventSupported) {
  5174. return;
  5175. }
  5176. event = normalizeEvent(this.dom, event);
  5177. this.trigger('mousewheel', event);
  5178. },
  5179. touchstart: function (event) {
  5180. event = normalizeEvent(this.dom, event);
  5181. markTouch(event);
  5182. this.__lastTouchMoment = new Date();
  5183. this.handler.processGesture(event, 'start');
  5184. localDOMHandlers.mousemove.call(this, event);
  5185. localDOMHandlers.mousedown.call(this, event);
  5186. },
  5187. touchmove: function (event) {
  5188. event = normalizeEvent(this.dom, event);
  5189. markTouch(event);
  5190. this.handler.processGesture(event, 'change');
  5191. localDOMHandlers.mousemove.call(this, event);
  5192. },
  5193. touchend: function (event) {
  5194. event = normalizeEvent(this.dom, event);
  5195. markTouch(event);
  5196. this.handler.processGesture(event, 'end');
  5197. localDOMHandlers.mouseup.call(this, event);
  5198. if (+new Date() - (+this.__lastTouchMoment) < TOUCH_CLICK_DELAY) {
  5199. localDOMHandlers.click.call(this, event);
  5200. }
  5201. },
  5202. pointerdown: function (event) {
  5203. localDOMHandlers.mousedown.call(this, event);
  5204. },
  5205. pointermove: function (event) {
  5206. if (!isPointerFromTouch(event)) {
  5207. localDOMHandlers.mousemove.call(this, event);
  5208. }
  5209. },
  5210. pointerup: function (event) {
  5211. localDOMHandlers.mouseup.call(this, event);
  5212. },
  5213. pointerout: function (event) {
  5214. if (!isPointerFromTouch(event)) {
  5215. localDOMHandlers.mouseout.call(this, event);
  5216. }
  5217. }
  5218. };
  5219. each(['click', 'dblclick', 'contextmenu'], function (name) {
  5220. localDOMHandlers[name] = function (event) {
  5221. event = normalizeEvent(this.dom, event);
  5222. this.trigger(name, event);
  5223. };
  5224. });
  5225. var globalDOMHandlers = {
  5226. pointermove: function (event) {
  5227. if (!isPointerFromTouch(event)) {
  5228. globalDOMHandlers.mousemove.call(this, event);
  5229. }
  5230. },
  5231. pointerup: function (event) {
  5232. globalDOMHandlers.mouseup.call(this, event);
  5233. },
  5234. mousemove: function (event) {
  5235. this.trigger('mousemove', event);
  5236. },
  5237. mouseup: function (event) {
  5238. var pointerCaptureReleasing = this.__pointerCapturing;
  5239. this.__togglePointerCapture(false);
  5240. this.trigger('mouseup', event);
  5241. if (pointerCaptureReleasing) {
  5242. event.zrEventControl = 'only_globalout';
  5243. this.trigger('mouseout', event);
  5244. }
  5245. }
  5246. };
  5247. function mountLocalDOMEventListeners(instance, scope) {
  5248. var domHandlers = scope.domHandlers;
  5249. if (env.pointerEventsSupported) {
  5250. each(localNativeListenerNames.pointer, function (nativeEventName) {
  5251. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5252. domHandlers[nativeEventName].call(instance, event);
  5253. });
  5254. });
  5255. }
  5256. else {
  5257. if (env.touchEventsSupported) {
  5258. each(localNativeListenerNames.touch, function (nativeEventName) {
  5259. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5260. domHandlers[nativeEventName].call(instance, event);
  5261. setTouchTimer(scope);
  5262. });
  5263. });
  5264. }
  5265. each(localNativeListenerNames.mouse, function (nativeEventName) {
  5266. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5267. event = getNativeEvent(event);
  5268. if (!scope.touching) {
  5269. domHandlers[nativeEventName].call(instance, event);
  5270. }
  5271. });
  5272. });
  5273. }
  5274. }
  5275. function mountGlobalDOMEventListeners(instance, scope) {
  5276. if (env.pointerEventsSupported) {
  5277. each(globalNativeListenerNames.pointer, mount);
  5278. }
  5279. else if (!env.touchEventsSupported) {
  5280. each(globalNativeListenerNames.mouse, mount);
  5281. }
  5282. function mount(nativeEventName) {
  5283. function nativeEventListener(event) {
  5284. event = getNativeEvent(event);
  5285. if (!isLocalEl(instance, event.target)) {
  5286. event = normalizeGlobalEvent(instance, event);
  5287. scope.domHandlers[nativeEventName].call(instance, event);
  5288. }
  5289. }
  5290. mountSingleDOMEventListener(scope, nativeEventName, nativeEventListener, { capture: true });
  5291. }
  5292. }
  5293. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  5294. scope.mounted[nativeEventName] = listener;
  5295. scope.listenerOpts[nativeEventName] = opt;
  5296. addEventListener(scope.domTarget, nativeEventName, listener, opt);
  5297. }
  5298. function unmountDOMEventListeners(scope) {
  5299. var mounted = scope.mounted;
  5300. for (var nativeEventName in mounted) {
  5301. if (mounted.hasOwnProperty(nativeEventName)) {
  5302. removeEventListener(scope.domTarget, nativeEventName, mounted[nativeEventName], scope.listenerOpts[nativeEventName]);
  5303. }
  5304. }
  5305. scope.mounted = {};
  5306. }
  5307. var DOMHandlerScope = (function () {
  5308. function DOMHandlerScope(domTarget, domHandlers) {
  5309. this.mounted = {};
  5310. this.listenerOpts = {};
  5311. this.touching = false;
  5312. this.domTarget = domTarget;
  5313. this.domHandlers = domHandlers;
  5314. }
  5315. return DOMHandlerScope;
  5316. }());
  5317. var HandlerDomProxy = (function (_super) {
  5318. __extends(HandlerDomProxy, _super);
  5319. function HandlerDomProxy(dom, painterRoot) {
  5320. var _this = _super.call(this) || this;
  5321. _this.__pointerCapturing = false;
  5322. _this.dom = dom;
  5323. _this.painterRoot = painterRoot;
  5324. _this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  5325. if (globalEventSupported) {
  5326. _this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  5327. }
  5328. mountLocalDOMEventListeners(_this, _this._localHandlerScope);
  5329. return _this;
  5330. }
  5331. HandlerDomProxy.prototype.dispose = function () {
  5332. unmountDOMEventListeners(this._localHandlerScope);
  5333. if (globalEventSupported) {
  5334. unmountDOMEventListeners(this._globalHandlerScope);
  5335. }
  5336. };
  5337. HandlerDomProxy.prototype.setCursor = function (cursorStyle) {
  5338. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  5339. };
  5340. HandlerDomProxy.prototype.__togglePointerCapture = function (isPointerCapturing) {
  5341. this.__mayPointerCapture = null;
  5342. if (globalEventSupported
  5343. && ((+this.__pointerCapturing) ^ (+isPointerCapturing))) {
  5344. this.__pointerCapturing = isPointerCapturing;
  5345. var globalHandlerScope = this._globalHandlerScope;
  5346. isPointerCapturing
  5347. ? mountGlobalDOMEventListeners(this, globalHandlerScope)
  5348. : unmountDOMEventListeners(globalHandlerScope);
  5349. }
  5350. };
  5351. return HandlerDomProxy;
  5352. }(Eventful));
  5353. var dpr = 1;
  5354. if (env.hasGlobalWindow) {
  5355. dpr = Math.max(window.devicePixelRatio
  5356. || (window.screen && window.screen.deviceXDPI / window.screen.logicalXDPI)
  5357. || 1, 1);
  5358. }
  5359. var devicePixelRatio = dpr;
  5360. var DARK_MODE_THRESHOLD = 0.4;
  5361. var DARK_LABEL_COLOR = '#333';
  5362. var LIGHT_LABEL_COLOR = '#ccc';
  5363. var LIGHTER_LABEL_COLOR = '#eee';
  5364. var mIdentity = identity;
  5365. var EPSILON$2 = 5e-5;
  5366. function isNotAroundZero$1(val) {
  5367. return val > EPSILON$2 || val < -EPSILON$2;
  5368. }
  5369. var scaleTmp = [];
  5370. var tmpTransform = [];
  5371. var originTransform = create$1();
  5372. var abs = Math.abs;
  5373. var Transformable = (function () {
  5374. function Transformable() {
  5375. }
  5376. Transformable.prototype.getLocalTransform = function (m) {
  5377. return Transformable.getLocalTransform(this, m);
  5378. };
  5379. Transformable.prototype.setPosition = function (arr) {
  5380. this.x = arr[0];
  5381. this.y = arr[1];
  5382. };
  5383. Transformable.prototype.setScale = function (arr) {
  5384. this.scaleX = arr[0];
  5385. this.scaleY = arr[1];
  5386. };
  5387. Transformable.prototype.setSkew = function (arr) {
  5388. this.skewX = arr[0];
  5389. this.skewY = arr[1];
  5390. };
  5391. Transformable.prototype.setOrigin = function (arr) {
  5392. this.originX = arr[0];
  5393. this.originY = arr[1];
  5394. };
  5395. Transformable.prototype.needLocalTransform = function () {
  5396. return isNotAroundZero$1(this.rotation)
  5397. || isNotAroundZero$1(this.x)
  5398. || isNotAroundZero$1(this.y)
  5399. || isNotAroundZero$1(this.scaleX - 1)
  5400. || isNotAroundZero$1(this.scaleY - 1)
  5401. || isNotAroundZero$1(this.skewX)
  5402. || isNotAroundZero$1(this.skewY);
  5403. };
  5404. Transformable.prototype.updateTransform = function () {
  5405. var parentTransform = this.parent && this.parent.transform;
  5406. var needLocalTransform = this.needLocalTransform();
  5407. var m = this.transform;
  5408. if (!(needLocalTransform || parentTransform)) {
  5409. if (m) {
  5410. mIdentity(m);
  5411. this.invTransform = null;
  5412. }
  5413. return;
  5414. }
  5415. m = m || create$1();
  5416. if (needLocalTransform) {
  5417. this.getLocalTransform(m);
  5418. }
  5419. else {
  5420. mIdentity(m);
  5421. }
  5422. if (parentTransform) {
  5423. if (needLocalTransform) {
  5424. mul$1(m, parentTransform, m);
  5425. }
  5426. else {
  5427. copy$1(m, parentTransform);
  5428. }
  5429. }
  5430. this.transform = m;
  5431. this._resolveGlobalScaleRatio(m);
  5432. };
  5433. Transformable.prototype._resolveGlobalScaleRatio = function (m) {
  5434. var globalScaleRatio = this.globalScaleRatio;
  5435. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  5436. this.getGlobalScale(scaleTmp);
  5437. var relX = scaleTmp[0] < 0 ? -1 : 1;
  5438. var relY = scaleTmp[1] < 0 ? -1 : 1;
  5439. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  5440. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  5441. m[0] *= sx;
  5442. m[1] *= sx;
  5443. m[2] *= sy;
  5444. m[3] *= sy;
  5445. }
  5446. this.invTransform = this.invTransform || create$1();
  5447. invert(this.invTransform, m);
  5448. };
  5449. Transformable.prototype.getComputedTransform = function () {
  5450. var transformNode = this;
  5451. var ancestors = [];
  5452. while (transformNode) {
  5453. ancestors.push(transformNode);
  5454. transformNode = transformNode.parent;
  5455. }
  5456. while (transformNode = ancestors.pop()) {
  5457. transformNode.updateTransform();
  5458. }
  5459. return this.transform;
  5460. };
  5461. Transformable.prototype.setLocalTransform = function (m) {
  5462. if (!m) {
  5463. return;
  5464. }
  5465. var sx = m[0] * m[0] + m[1] * m[1];
  5466. var sy = m[2] * m[2] + m[3] * m[3];
  5467. var rotation = Math.atan2(m[1], m[0]);
  5468. var shearX = Math.PI / 2 + rotation - Math.atan2(m[3], m[2]);
  5469. sy = Math.sqrt(sy) * Math.cos(shearX);
  5470. sx = Math.sqrt(sx);
  5471. this.skewX = shearX;
  5472. this.skewY = 0;
  5473. this.rotation = -rotation;
  5474. this.x = +m[4];
  5475. this.y = +m[5];
  5476. this.scaleX = sx;
  5477. this.scaleY = sy;
  5478. this.originX = 0;
  5479. this.originY = 0;
  5480. };
  5481. Transformable.prototype.decomposeTransform = function () {
  5482. if (!this.transform) {
  5483. return;
  5484. }
  5485. var parent = this.parent;
  5486. var m = this.transform;
  5487. if (parent && parent.transform) {
  5488. parent.invTransform = parent.invTransform || create$1();
  5489. mul$1(tmpTransform, parent.invTransform, m);
  5490. m = tmpTransform;
  5491. }
  5492. var ox = this.originX;
  5493. var oy = this.originY;
  5494. if (ox || oy) {
  5495. originTransform[4] = ox;
  5496. originTransform[5] = oy;
  5497. mul$1(tmpTransform, m, originTransform);
  5498. tmpTransform[4] -= ox;
  5499. tmpTransform[5] -= oy;
  5500. m = tmpTransform;
  5501. }
  5502. this.setLocalTransform(m);
  5503. };
  5504. Transformable.prototype.getGlobalScale = function (out) {
  5505. var m = this.transform;
  5506. out = out || [];
  5507. if (!m) {
  5508. out[0] = 1;
  5509. out[1] = 1;
  5510. return out;
  5511. }
  5512. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  5513. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  5514. if (m[0] < 0) {
  5515. out[0] = -out[0];
  5516. }
  5517. if (m[3] < 0) {
  5518. out[1] = -out[1];
  5519. }
  5520. return out;
  5521. };
  5522. Transformable.prototype.transformCoordToLocal = function (x, y) {
  5523. var v2 = [x, y];
  5524. var invTransform = this.invTransform;
  5525. if (invTransform) {
  5526. applyTransform(v2, v2, invTransform);
  5527. }
  5528. return v2;
  5529. };
  5530. Transformable.prototype.transformCoordToGlobal = function (x, y) {
  5531. var v2 = [x, y];
  5532. var transform = this.transform;
  5533. if (transform) {
  5534. applyTransform(v2, v2, transform);
  5535. }
  5536. return v2;
  5537. };
  5538. Transformable.prototype.getLineScale = function () {
  5539. var m = this.transform;
  5540. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  5541. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  5542. : 1;
  5543. };
  5544. Transformable.prototype.copyTransform = function (source) {
  5545. copyTransform(this, source);
  5546. };
  5547. Transformable.getLocalTransform = function (target, m) {
  5548. m = m || [];
  5549. var ox = target.originX || 0;
  5550. var oy = target.originY || 0;
  5551. var sx = target.scaleX;
  5552. var sy = target.scaleY;
  5553. var ax = target.anchorX;
  5554. var ay = target.anchorY;
  5555. var rotation = target.rotation || 0;
  5556. var x = target.x;
  5557. var y = target.y;
  5558. var skewX = target.skewX ? Math.tan(target.skewX) : 0;
  5559. var skewY = target.skewY ? Math.tan(-target.skewY) : 0;
  5560. if (ox || oy || ax || ay) {
  5561. var dx = ox + ax;
  5562. var dy = oy + ay;
  5563. m[4] = -dx * sx - skewX * dy * sy;
  5564. m[5] = -dy * sy - skewY * dx * sx;
  5565. }
  5566. else {
  5567. m[4] = m[5] = 0;
  5568. }
  5569. m[0] = sx;
  5570. m[3] = sy;
  5571. m[1] = skewY * sx;
  5572. m[2] = skewX * sy;
  5573. rotation && rotate(m, m, rotation);
  5574. m[4] += ox + x;
  5575. m[5] += oy + y;
  5576. return m;
  5577. };
  5578. Transformable.initDefaultProps = (function () {
  5579. var proto = Transformable.prototype;
  5580. proto.scaleX =
  5581. proto.scaleY =
  5582. proto.globalScaleRatio = 1;
  5583. proto.x =
  5584. proto.y =
  5585. proto.originX =
  5586. proto.originY =
  5587. proto.skewX =
  5588. proto.skewY =
  5589. proto.rotation =
  5590. proto.anchorX =
  5591. proto.anchorY = 0;
  5592. })();
  5593. return Transformable;
  5594. }());
  5595. var TRANSFORMABLE_PROPS = [
  5596. 'x', 'y', 'originX', 'originY', 'anchorX', 'anchorY', 'rotation', 'scaleX', 'scaleY', 'skewX', 'skewY'
  5597. ];
  5598. function copyTransform(target, source) {
  5599. for (var i = 0; i < TRANSFORMABLE_PROPS.length; i++) {
  5600. var propName = TRANSFORMABLE_PROPS[i];
  5601. target[propName] = source[propName];
  5602. }
  5603. }
  5604. var textWidthCache = {};
  5605. function getWidth(text, font) {
  5606. font = font || DEFAULT_FONT;
  5607. var cacheOfFont = textWidthCache[font];
  5608. if (!cacheOfFont) {
  5609. cacheOfFont = textWidthCache[font] = new LRU(500);
  5610. }
  5611. var width = cacheOfFont.get(text);
  5612. if (width == null) {
  5613. width = platformApi.measureText(text, font).width;
  5614. cacheOfFont.put(text, width);
  5615. }
  5616. return width;
  5617. }
  5618. function innerGetBoundingRect(text, font, textAlign, textBaseline) {
  5619. var width = getWidth(text, font);
  5620. var height = getLineHeight(font);
  5621. var x = adjustTextX(0, width, textAlign);
  5622. var y = adjustTextY$1(0, height, textBaseline);
  5623. var rect = new BoundingRect(x, y, width, height);
  5624. return rect;
  5625. }
  5626. function getBoundingRect(text, font, textAlign, textBaseline) {
  5627. var textLines = ((text || '') + '').split('\n');
  5628. var len = textLines.length;
  5629. if (len === 1) {
  5630. return innerGetBoundingRect(textLines[0], font, textAlign, textBaseline);
  5631. }
  5632. else {
  5633. var uniondRect = new BoundingRect(0, 0, 0, 0);
  5634. for (var i = 0; i < textLines.length; i++) {
  5635. var rect = innerGetBoundingRect(textLines[i], font, textAlign, textBaseline);
  5636. i === 0 ? uniondRect.copy(rect) : uniondRect.union(rect);
  5637. }
  5638. return uniondRect;
  5639. }
  5640. }
  5641. function adjustTextX(x, width, textAlign) {
  5642. if (textAlign === 'right') {
  5643. x -= width;
  5644. }
  5645. else if (textAlign === 'center') {
  5646. x -= width / 2;
  5647. }
  5648. return x;
  5649. }
  5650. function adjustTextY$1(y, height, verticalAlign) {
  5651. if (verticalAlign === 'middle') {
  5652. y -= height / 2;
  5653. }
  5654. else if (verticalAlign === 'bottom') {
  5655. y -= height;
  5656. }
  5657. return y;
  5658. }
  5659. function getLineHeight(font) {
  5660. return getWidth('国', font);
  5661. }
  5662. function parsePercent(value, maxValue) {
  5663. if (typeof value === 'string') {
  5664. if (value.lastIndexOf('%') >= 0) {
  5665. return parseFloat(value) / 100 * maxValue;
  5666. }
  5667. return parseFloat(value);
  5668. }
  5669. return value;
  5670. }
  5671. function calculateTextPosition(out, opts, rect) {
  5672. var textPosition = opts.position || 'inside';
  5673. var distance = opts.distance != null ? opts.distance : 5;
  5674. var height = rect.height;
  5675. var width = rect.width;
  5676. var halfHeight = height / 2;
  5677. var x = rect.x;
  5678. var y = rect.y;
  5679. var textAlign = 'left';
  5680. var textVerticalAlign = 'top';
  5681. if (textPosition instanceof Array) {
  5682. x += parsePercent(textPosition[0], rect.width);
  5683. y += parsePercent(textPosition[1], rect.height);
  5684. textAlign = null;
  5685. textVerticalAlign = null;
  5686. }
  5687. else {
  5688. switch (textPosition) {
  5689. case 'left':
  5690. x -= distance;
  5691. y += halfHeight;
  5692. textAlign = 'right';
  5693. textVerticalAlign = 'middle';
  5694. break;
  5695. case 'right':
  5696. x += distance + width;
  5697. y += halfHeight;
  5698. textVerticalAlign = 'middle';
  5699. break;
  5700. case 'top':
  5701. x += width / 2;
  5702. y -= distance;
  5703. textAlign = 'center';
  5704. textVerticalAlign = 'bottom';
  5705. break;
  5706. case 'bottom':
  5707. x += width / 2;
  5708. y += height + distance;
  5709. textAlign = 'center';
  5710. break;
  5711. case 'inside':
  5712. x += width / 2;
  5713. y += halfHeight;
  5714. textAlign = 'center';
  5715. textVerticalAlign = 'middle';
  5716. break;
  5717. case 'insideLeft':
  5718. x += distance;
  5719. y += halfHeight;
  5720. textVerticalAlign = 'middle';
  5721. break;
  5722. case 'insideRight':
  5723. x += width - distance;
  5724. y += halfHeight;
  5725. textAlign = 'right';
  5726. textVerticalAlign = 'middle';
  5727. break;
  5728. case 'insideTop':
  5729. x += width / 2;
  5730. y += distance;
  5731. textAlign = 'center';
  5732. break;
  5733. case 'insideBottom':
  5734. x += width / 2;
  5735. y += height - distance;
  5736. textAlign = 'center';
  5737. textVerticalAlign = 'bottom';
  5738. break;
  5739. case 'insideTopLeft':
  5740. x += distance;
  5741. y += distance;
  5742. break;
  5743. case 'insideTopRight':
  5744. x += width - distance;
  5745. y += distance;
  5746. textAlign = 'right';
  5747. break;
  5748. case 'insideBottomLeft':
  5749. x += distance;
  5750. y += height - distance;
  5751. textVerticalAlign = 'bottom';
  5752. break;
  5753. case 'insideBottomRight':
  5754. x += width - distance;
  5755. y += height - distance;
  5756. textAlign = 'right';
  5757. textVerticalAlign = 'bottom';
  5758. break;
  5759. }
  5760. }
  5761. out = out || {};
  5762. out.x = x;
  5763. out.y = y;
  5764. out.align = textAlign;
  5765. out.verticalAlign = textVerticalAlign;
  5766. return out;
  5767. }
  5768. var PRESERVED_NORMAL_STATE = '__zr_normal__';
  5769. var PRIMARY_STATES_KEYS = TRANSFORMABLE_PROPS.concat(['ignore']);
  5770. var DEFAULT_ANIMATABLE_MAP = reduce(TRANSFORMABLE_PROPS, function (obj, key) {
  5771. obj[key] = true;
  5772. return obj;
  5773. }, { ignore: false });
  5774. var tmpTextPosCalcRes = {};
  5775. var tmpBoundingRect = new BoundingRect(0, 0, 0, 0);
  5776. var Element = (function () {
  5777. function Element(props) {
  5778. this.id = guid();
  5779. this.animators = [];
  5780. this.currentStates = [];
  5781. this.states = {};
  5782. this._init(props);
  5783. }
  5784. Element.prototype._init = function (props) {
  5785. this.attr(props);
  5786. };
  5787. Element.prototype.drift = function (dx, dy, e) {
  5788. switch (this.draggable) {
  5789. case 'horizontal':
  5790. dy = 0;
  5791. break;
  5792. case 'vertical':
  5793. dx = 0;
  5794. break;
  5795. }
  5796. var m = this.transform;
  5797. if (!m) {
  5798. m = this.transform = [1, 0, 0, 1, 0, 0];
  5799. }
  5800. m[4] += dx;
  5801. m[5] += dy;
  5802. this.decomposeTransform();
  5803. this.markRedraw();
  5804. };
  5805. Element.prototype.beforeUpdate = function () { };
  5806. Element.prototype.afterUpdate = function () { };
  5807. Element.prototype.update = function () {
  5808. this.updateTransform();
  5809. if (this.__dirty) {
  5810. this.updateInnerText();
  5811. }
  5812. };
  5813. Element.prototype.updateInnerText = function (forceUpdate) {
  5814. var textEl = this._textContent;
  5815. if (textEl && (!textEl.ignore || forceUpdate)) {
  5816. if (!this.textConfig) {
  5817. this.textConfig = {};
  5818. }
  5819. var textConfig = this.textConfig;
  5820. var isLocal = textConfig.local;
  5821. var innerTransformable = textEl.innerTransformable;
  5822. var textAlign = void 0;
  5823. var textVerticalAlign = void 0;
  5824. var textStyleChanged = false;
  5825. innerTransformable.parent = isLocal ? this : null;
  5826. var innerOrigin = false;
  5827. innerTransformable.copyTransform(textEl);
  5828. if (textConfig.position != null) {
  5829. var layoutRect = tmpBoundingRect;
  5830. if (textConfig.layoutRect) {
  5831. layoutRect.copy(textConfig.layoutRect);
  5832. }
  5833. else {
  5834. layoutRect.copy(this.getBoundingRect());
  5835. }
  5836. if (!isLocal) {
  5837. layoutRect.applyTransform(this.transform);
  5838. }
  5839. if (this.calculateTextPosition) {
  5840. this.calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5841. }
  5842. else {
  5843. calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5844. }
  5845. innerTransformable.x = tmpTextPosCalcRes.x;
  5846. innerTransformable.y = tmpTextPosCalcRes.y;
  5847. textAlign = tmpTextPosCalcRes.align;
  5848. textVerticalAlign = tmpTextPosCalcRes.verticalAlign;
  5849. var textOrigin = textConfig.origin;
  5850. if (textOrigin && textConfig.rotation != null) {
  5851. var relOriginX = void 0;
  5852. var relOriginY = void 0;
  5853. if (textOrigin === 'center') {
  5854. relOriginX = layoutRect.width * 0.5;
  5855. relOriginY = layoutRect.height * 0.5;
  5856. }
  5857. else {
  5858. relOriginX = parsePercent(textOrigin[0], layoutRect.width);
  5859. relOriginY = parsePercent(textOrigin[1], layoutRect.height);
  5860. }
  5861. innerOrigin = true;
  5862. innerTransformable.originX = -innerTransformable.x + relOriginX + (isLocal ? 0 : layoutRect.x);
  5863. innerTransformable.originY = -innerTransformable.y + relOriginY + (isLocal ? 0 : layoutRect.y);
  5864. }
  5865. }
  5866. if (textConfig.rotation != null) {
  5867. innerTransformable.rotation = textConfig.rotation;
  5868. }
  5869. var textOffset = textConfig.offset;
  5870. if (textOffset) {
  5871. innerTransformable.x += textOffset[0];
  5872. innerTransformable.y += textOffset[1];
  5873. if (!innerOrigin) {
  5874. innerTransformable.originX = -textOffset[0];
  5875. innerTransformable.originY = -textOffset[1];
  5876. }
  5877. }
  5878. var isInside = textConfig.inside == null
  5879. ? (typeof textConfig.position === 'string' && textConfig.position.indexOf('inside') >= 0)
  5880. : textConfig.inside;
  5881. var innerTextDefaultStyle = this._innerTextDefaultStyle || (this._innerTextDefaultStyle = {});
  5882. var textFill = void 0;
  5883. var textStroke = void 0;
  5884. var autoStroke = void 0;
  5885. if (isInside && this.canBeInsideText()) {
  5886. textFill = textConfig.insideFill;
  5887. textStroke = textConfig.insideStroke;
  5888. if (textFill == null || textFill === 'auto') {
  5889. textFill = this.getInsideTextFill();
  5890. }
  5891. if (textStroke == null || textStroke === 'auto') {
  5892. textStroke = this.getInsideTextStroke(textFill);
  5893. autoStroke = true;
  5894. }
  5895. }
  5896. else {
  5897. textFill = textConfig.outsideFill;
  5898. textStroke = textConfig.outsideStroke;
  5899. if (textFill == null || textFill === 'auto') {
  5900. textFill = this.getOutsideFill();
  5901. }
  5902. if (textStroke == null || textStroke === 'auto') {
  5903. textStroke = this.getOutsideStroke(textFill);
  5904. autoStroke = true;
  5905. }
  5906. }
  5907. textFill = textFill || '#000';
  5908. if (textFill !== innerTextDefaultStyle.fill
  5909. || textStroke !== innerTextDefaultStyle.stroke
  5910. || autoStroke !== innerTextDefaultStyle.autoStroke
  5911. || textAlign !== innerTextDefaultStyle.align
  5912. || textVerticalAlign !== innerTextDefaultStyle.verticalAlign) {
  5913. textStyleChanged = true;
  5914. innerTextDefaultStyle.fill = textFill;
  5915. innerTextDefaultStyle.stroke = textStroke;
  5916. innerTextDefaultStyle.autoStroke = autoStroke;
  5917. innerTextDefaultStyle.align = textAlign;
  5918. innerTextDefaultStyle.verticalAlign = textVerticalAlign;
  5919. textEl.setDefaultTextStyle(innerTextDefaultStyle);
  5920. }
  5921. textEl.__dirty |= REDRAW_BIT;
  5922. if (textStyleChanged) {
  5923. textEl.dirtyStyle(true);
  5924. }
  5925. }
  5926. };
  5927. Element.prototype.canBeInsideText = function () {
  5928. return true;
  5929. };
  5930. Element.prototype.getInsideTextFill = function () {
  5931. return '#fff';
  5932. };
  5933. Element.prototype.getInsideTextStroke = function (textFill) {
  5934. return '#000';
  5935. };
  5936. Element.prototype.getOutsideFill = function () {
  5937. return this.__zr && this.__zr.isDarkMode() ? LIGHT_LABEL_COLOR : DARK_LABEL_COLOR;
  5938. };
  5939. Element.prototype.getOutsideStroke = function (textFill) {
  5940. var backgroundColor = this.__zr && this.__zr.getBackgroundColor();
  5941. var colorArr = typeof backgroundColor === 'string' && parse(backgroundColor);
  5942. if (!colorArr) {
  5943. colorArr = [255, 255, 255, 1];
  5944. }
  5945. var alpha = colorArr[3];
  5946. var isDark = this.__zr.isDarkMode();
  5947. for (var i = 0; i < 3; i++) {
  5948. colorArr[i] = colorArr[i] * alpha + (isDark ? 0 : 255) * (1 - alpha);
  5949. }
  5950. colorArr[3] = 1;
  5951. return stringify(colorArr, 'rgba');
  5952. };
  5953. Element.prototype.traverse = function (cb, context) { };
  5954. Element.prototype.attrKV = function (key, value) {
  5955. if (key === 'textConfig') {
  5956. this.setTextConfig(value);
  5957. }
  5958. else if (key === 'textContent') {
  5959. this.setTextContent(value);
  5960. }
  5961. else if (key === 'clipPath') {
  5962. this.setClipPath(value);
  5963. }
  5964. else if (key === 'extra') {
  5965. this.extra = this.extra || {};
  5966. extend(this.extra, value);
  5967. }
  5968. else {
  5969. this[key] = value;
  5970. }
  5971. };
  5972. Element.prototype.hide = function () {
  5973. this.ignore = true;
  5974. this.markRedraw();
  5975. };
  5976. Element.prototype.show = function () {
  5977. this.ignore = false;
  5978. this.markRedraw();
  5979. };
  5980. Element.prototype.attr = function (keyOrObj, value) {
  5981. if (typeof keyOrObj === 'string') {
  5982. this.attrKV(keyOrObj, value);
  5983. }
  5984. else if (isObject(keyOrObj)) {
  5985. var obj = keyOrObj;
  5986. var keysArr = keys(obj);
  5987. for (var i = 0; i < keysArr.length; i++) {
  5988. var key = keysArr[i];
  5989. this.attrKV(key, keyOrObj[key]);
  5990. }
  5991. }
  5992. this.markRedraw();
  5993. return this;
  5994. };
  5995. Element.prototype.saveCurrentToNormalState = function (toState) {
  5996. this._innerSaveToNormal(toState);
  5997. var normalState = this._normalState;
  5998. for (var i = 0; i < this.animators.length; i++) {
  5999. var animator = this.animators[i];
  6000. var fromStateTransition = animator.__fromStateTransition;
  6001. if (animator.getLoop() || fromStateTransition && fromStateTransition !== PRESERVED_NORMAL_STATE) {
  6002. continue;
  6003. }
  6004. var targetName = animator.targetName;
  6005. var target = targetName
  6006. ? normalState[targetName] : normalState;
  6007. animator.saveTo(target);
  6008. }
  6009. };
  6010. Element.prototype._innerSaveToNormal = function (toState) {
  6011. var normalState = this._normalState;
  6012. if (!normalState) {
  6013. normalState = this._normalState = {};
  6014. }
  6015. if (toState.textConfig && !normalState.textConfig) {
  6016. normalState.textConfig = this.textConfig;
  6017. }
  6018. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS);
  6019. };
  6020. Element.prototype._savePrimaryToNormal = function (toState, normalState, primaryKeys) {
  6021. for (var i = 0; i < primaryKeys.length; i++) {
  6022. var key = primaryKeys[i];
  6023. if (toState[key] != null && !(key in normalState)) {
  6024. normalState[key] = this[key];
  6025. }
  6026. }
  6027. };
  6028. Element.prototype.hasState = function () {
  6029. return this.currentStates.length > 0;
  6030. };
  6031. Element.prototype.getState = function (name) {
  6032. return this.states[name];
  6033. };
  6034. Element.prototype.ensureState = function (name) {
  6035. var states = this.states;
  6036. if (!states[name]) {
  6037. states[name] = {};
  6038. }
  6039. return states[name];
  6040. };
  6041. Element.prototype.clearStates = function (noAnimation) {
  6042. this.useState(PRESERVED_NORMAL_STATE, false, noAnimation);
  6043. };
  6044. Element.prototype.useState = function (stateName, keepCurrentStates, noAnimation, forceUseHoverLayer) {
  6045. var toNormalState = stateName === PRESERVED_NORMAL_STATE;
  6046. var hasStates = this.hasState();
  6047. if (!hasStates && toNormalState) {
  6048. return;
  6049. }
  6050. var currentStates = this.currentStates;
  6051. var animationCfg = this.stateTransition;
  6052. if (indexOf(currentStates, stateName) >= 0 && (keepCurrentStates || currentStates.length === 1)) {
  6053. return;
  6054. }
  6055. var state;
  6056. if (this.stateProxy && !toNormalState) {
  6057. state = this.stateProxy(stateName);
  6058. }
  6059. if (!state) {
  6060. state = (this.states && this.states[stateName]);
  6061. }
  6062. if (!state && !toNormalState) {
  6063. logError("State " + stateName + " not exists.");
  6064. return;
  6065. }
  6066. if (!toNormalState) {
  6067. this.saveCurrentToNormalState(state);
  6068. }
  6069. var useHoverLayer = !!((state && state.hoverLayer) || forceUseHoverLayer);
  6070. if (useHoverLayer) {
  6071. this._toggleHoverLayerFlag(true);
  6072. }
  6073. this._applyStateObj(stateName, state, this._normalState, keepCurrentStates, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6074. var textContent = this._textContent;
  6075. var textGuide = this._textGuide;
  6076. if (textContent) {
  6077. textContent.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6078. }
  6079. if (textGuide) {
  6080. textGuide.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6081. }
  6082. if (toNormalState) {
  6083. this.currentStates = [];
  6084. this._normalState = {};
  6085. }
  6086. else {
  6087. if (!keepCurrentStates) {
  6088. this.currentStates = [stateName];
  6089. }
  6090. else {
  6091. this.currentStates.push(stateName);
  6092. }
  6093. }
  6094. this._updateAnimationTargets();
  6095. this.markRedraw();
  6096. if (!useHoverLayer && this.__inHover) {
  6097. this._toggleHoverLayerFlag(false);
  6098. this.__dirty &= ~REDRAW_BIT;
  6099. }
  6100. return state;
  6101. };
  6102. Element.prototype.useStates = function (states, noAnimation, forceUseHoverLayer) {
  6103. if (!states.length) {
  6104. this.clearStates();
  6105. }
  6106. else {
  6107. var stateObjects = [];
  6108. var currentStates = this.currentStates;
  6109. var len = states.length;
  6110. var notChange = len === currentStates.length;
  6111. if (notChange) {
  6112. for (var i = 0; i < len; i++) {
  6113. if (states[i] !== currentStates[i]) {
  6114. notChange = false;
  6115. break;
  6116. }
  6117. }
  6118. }
  6119. if (notChange) {
  6120. return;
  6121. }
  6122. for (var i = 0; i < len; i++) {
  6123. var stateName = states[i];
  6124. var stateObj = void 0;
  6125. if (this.stateProxy) {
  6126. stateObj = this.stateProxy(stateName, states);
  6127. }
  6128. if (!stateObj) {
  6129. stateObj = this.states[stateName];
  6130. }
  6131. if (stateObj) {
  6132. stateObjects.push(stateObj);
  6133. }
  6134. }
  6135. var lastStateObj = stateObjects[len - 1];
  6136. var useHoverLayer = !!((lastStateObj && lastStateObj.hoverLayer) || forceUseHoverLayer);
  6137. if (useHoverLayer) {
  6138. this._toggleHoverLayerFlag(true);
  6139. }
  6140. var mergedState = this._mergeStates(stateObjects);
  6141. var animationCfg = this.stateTransition;
  6142. this.saveCurrentToNormalState(mergedState);
  6143. this._applyStateObj(states.join(','), mergedState, this._normalState, false, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6144. var textContent = this._textContent;
  6145. var textGuide = this._textGuide;
  6146. if (textContent) {
  6147. textContent.useStates(states, noAnimation, useHoverLayer);
  6148. }
  6149. if (textGuide) {
  6150. textGuide.useStates(states, noAnimation, useHoverLayer);
  6151. }
  6152. this._updateAnimationTargets();
  6153. this.currentStates = states.slice();
  6154. this.markRedraw();
  6155. if (!useHoverLayer && this.__inHover) {
  6156. this._toggleHoverLayerFlag(false);
  6157. this.__dirty &= ~REDRAW_BIT;
  6158. }
  6159. }
  6160. };
  6161. Element.prototype.isSilent = function () {
  6162. var isSilent = this.silent;
  6163. var ancestor = this.parent;
  6164. while (!isSilent && ancestor) {
  6165. if (ancestor.silent) {
  6166. isSilent = true;
  6167. break;
  6168. }
  6169. ancestor = ancestor.parent;
  6170. }
  6171. return isSilent;
  6172. };
  6173. Element.prototype._updateAnimationTargets = function () {
  6174. for (var i = 0; i < this.animators.length; i++) {
  6175. var animator = this.animators[i];
  6176. if (animator.targetName) {
  6177. animator.changeTarget(this[animator.targetName]);
  6178. }
  6179. }
  6180. };
  6181. Element.prototype.removeState = function (state) {
  6182. var idx = indexOf(this.currentStates, state);
  6183. if (idx >= 0) {
  6184. var currentStates = this.currentStates.slice();
  6185. currentStates.splice(idx, 1);
  6186. this.useStates(currentStates);
  6187. }
  6188. };
  6189. Element.prototype.replaceState = function (oldState, newState, forceAdd) {
  6190. var currentStates = this.currentStates.slice();
  6191. var idx = indexOf(currentStates, oldState);
  6192. var newStateExists = indexOf(currentStates, newState) >= 0;
  6193. if (idx >= 0) {
  6194. if (!newStateExists) {
  6195. currentStates[idx] = newState;
  6196. }
  6197. else {
  6198. currentStates.splice(idx, 1);
  6199. }
  6200. }
  6201. else if (forceAdd && !newStateExists) {
  6202. currentStates.push(newState);
  6203. }
  6204. this.useStates(currentStates);
  6205. };
  6206. Element.prototype.toggleState = function (state, enable) {
  6207. if (enable) {
  6208. this.useState(state, true);
  6209. }
  6210. else {
  6211. this.removeState(state);
  6212. }
  6213. };
  6214. Element.prototype._mergeStates = function (states) {
  6215. var mergedState = {};
  6216. var mergedTextConfig;
  6217. for (var i = 0; i < states.length; i++) {
  6218. var state = states[i];
  6219. extend(mergedState, state);
  6220. if (state.textConfig) {
  6221. mergedTextConfig = mergedTextConfig || {};
  6222. extend(mergedTextConfig, state.textConfig);
  6223. }
  6224. }
  6225. if (mergedTextConfig) {
  6226. mergedState.textConfig = mergedTextConfig;
  6227. }
  6228. return mergedState;
  6229. };
  6230. Element.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  6231. var needsRestoreToNormal = !(state && keepCurrentStates);
  6232. if (state && state.textConfig) {
  6233. this.textConfig = extend({}, keepCurrentStates ? this.textConfig : normalState.textConfig);
  6234. extend(this.textConfig, state.textConfig);
  6235. }
  6236. else if (needsRestoreToNormal) {
  6237. if (normalState.textConfig) {
  6238. this.textConfig = normalState.textConfig;
  6239. }
  6240. }
  6241. var transitionTarget = {};
  6242. var hasTransition = false;
  6243. for (var i = 0; i < PRIMARY_STATES_KEYS.length; i++) {
  6244. var key = PRIMARY_STATES_KEYS[i];
  6245. var propNeedsTransition = transition && DEFAULT_ANIMATABLE_MAP[key];
  6246. if (state && state[key] != null) {
  6247. if (propNeedsTransition) {
  6248. hasTransition = true;
  6249. transitionTarget[key] = state[key];
  6250. }
  6251. else {
  6252. this[key] = state[key];
  6253. }
  6254. }
  6255. else if (needsRestoreToNormal) {
  6256. if (normalState[key] != null) {
  6257. if (propNeedsTransition) {
  6258. hasTransition = true;
  6259. transitionTarget[key] = normalState[key];
  6260. }
  6261. else {
  6262. this[key] = normalState[key];
  6263. }
  6264. }
  6265. }
  6266. }
  6267. if (!transition) {
  6268. for (var i = 0; i < this.animators.length; i++) {
  6269. var animator = this.animators[i];
  6270. var targetName = animator.targetName;
  6271. if (!animator.getLoop()) {
  6272. animator.__changeFinalValue(targetName
  6273. ? (state || normalState)[targetName]
  6274. : (state || normalState));
  6275. }
  6276. }
  6277. }
  6278. if (hasTransition) {
  6279. this._transitionState(stateName, transitionTarget, animationCfg);
  6280. }
  6281. };
  6282. Element.prototype._attachComponent = function (componentEl) {
  6283. if (componentEl.__zr && !componentEl.__hostTarget) {
  6284. {
  6285. throw new Error('Text element has been added to zrender.');
  6286. }
  6287. }
  6288. if (componentEl === this) {
  6289. {
  6290. throw new Error('Recursive component attachment.');
  6291. }
  6292. }
  6293. var zr = this.__zr;
  6294. if (zr) {
  6295. componentEl.addSelfToZr(zr);
  6296. }
  6297. componentEl.__zr = zr;
  6298. componentEl.__hostTarget = this;
  6299. };
  6300. Element.prototype._detachComponent = function (componentEl) {
  6301. if (componentEl.__zr) {
  6302. componentEl.removeSelfFromZr(componentEl.__zr);
  6303. }
  6304. componentEl.__zr = null;
  6305. componentEl.__hostTarget = null;
  6306. };
  6307. Element.prototype.getClipPath = function () {
  6308. return this._clipPath;
  6309. };
  6310. Element.prototype.setClipPath = function (clipPath) {
  6311. if (this._clipPath && this._clipPath !== clipPath) {
  6312. this.removeClipPath();
  6313. }
  6314. this._attachComponent(clipPath);
  6315. this._clipPath = clipPath;
  6316. this.markRedraw();
  6317. };
  6318. Element.prototype.removeClipPath = function () {
  6319. var clipPath = this._clipPath;
  6320. if (clipPath) {
  6321. this._detachComponent(clipPath);
  6322. this._clipPath = null;
  6323. this.markRedraw();
  6324. }
  6325. };
  6326. Element.prototype.getTextContent = function () {
  6327. return this._textContent;
  6328. };
  6329. Element.prototype.setTextContent = function (textEl) {
  6330. var previousTextContent = this._textContent;
  6331. if (previousTextContent === textEl) {
  6332. return;
  6333. }
  6334. if (previousTextContent && previousTextContent !== textEl) {
  6335. this.removeTextContent();
  6336. }
  6337. {
  6338. if (textEl.__zr && !textEl.__hostTarget) {
  6339. throw new Error('Text element has been added to zrender.');
  6340. }
  6341. }
  6342. textEl.innerTransformable = new Transformable();
  6343. this._attachComponent(textEl);
  6344. this._textContent = textEl;
  6345. this.markRedraw();
  6346. };
  6347. Element.prototype.setTextConfig = function (cfg) {
  6348. if (!this.textConfig) {
  6349. this.textConfig = {};
  6350. }
  6351. extend(this.textConfig, cfg);
  6352. this.markRedraw();
  6353. };
  6354. Element.prototype.removeTextConfig = function () {
  6355. this.textConfig = null;
  6356. this.markRedraw();
  6357. };
  6358. Element.prototype.removeTextContent = function () {
  6359. var textEl = this._textContent;
  6360. if (textEl) {
  6361. textEl.innerTransformable = null;
  6362. this._detachComponent(textEl);
  6363. this._textContent = null;
  6364. this._innerTextDefaultStyle = null;
  6365. this.markRedraw();
  6366. }
  6367. };
  6368. Element.prototype.getTextGuideLine = function () {
  6369. return this._textGuide;
  6370. };
  6371. Element.prototype.setTextGuideLine = function (guideLine) {
  6372. if (this._textGuide && this._textGuide !== guideLine) {
  6373. this.removeTextGuideLine();
  6374. }
  6375. this._attachComponent(guideLine);
  6376. this._textGuide = guideLine;
  6377. this.markRedraw();
  6378. };
  6379. Element.prototype.removeTextGuideLine = function () {
  6380. var textGuide = this._textGuide;
  6381. if (textGuide) {
  6382. this._detachComponent(textGuide);
  6383. this._textGuide = null;
  6384. this.markRedraw();
  6385. }
  6386. };
  6387. Element.prototype.markRedraw = function () {
  6388. this.__dirty |= REDRAW_BIT;
  6389. var zr = this.__zr;
  6390. if (zr) {
  6391. if (this.__inHover) {
  6392. zr.refreshHover();
  6393. }
  6394. else {
  6395. zr.refresh();
  6396. }
  6397. }
  6398. if (this.__hostTarget) {
  6399. this.__hostTarget.markRedraw();
  6400. }
  6401. };
  6402. Element.prototype.dirty = function () {
  6403. this.markRedraw();
  6404. };
  6405. Element.prototype._toggleHoverLayerFlag = function (inHover) {
  6406. this.__inHover = inHover;
  6407. var textContent = this._textContent;
  6408. var textGuide = this._textGuide;
  6409. if (textContent) {
  6410. textContent.__inHover = inHover;
  6411. }
  6412. if (textGuide) {
  6413. textGuide.__inHover = inHover;
  6414. }
  6415. };
  6416. Element.prototype.addSelfToZr = function (zr) {
  6417. if (this.__zr === zr) {
  6418. return;
  6419. }
  6420. this.__zr = zr;
  6421. var animators = this.animators;
  6422. if (animators) {
  6423. for (var i = 0; i < animators.length; i++) {
  6424. zr.animation.addAnimator(animators[i]);
  6425. }
  6426. }
  6427. if (this._clipPath) {
  6428. this._clipPath.addSelfToZr(zr);
  6429. }
  6430. if (this._textContent) {
  6431. this._textContent.addSelfToZr(zr);
  6432. }
  6433. if (this._textGuide) {
  6434. this._textGuide.addSelfToZr(zr);
  6435. }
  6436. };
  6437. Element.prototype.removeSelfFromZr = function (zr) {
  6438. if (!this.__zr) {
  6439. return;
  6440. }
  6441. this.__zr = null;
  6442. var animators = this.animators;
  6443. if (animators) {
  6444. for (var i = 0; i < animators.length; i++) {
  6445. zr.animation.removeAnimator(animators[i]);
  6446. }
  6447. }
  6448. if (this._clipPath) {
  6449. this._clipPath.removeSelfFromZr(zr);
  6450. }
  6451. if (this._textContent) {
  6452. this._textContent.removeSelfFromZr(zr);
  6453. }
  6454. if (this._textGuide) {
  6455. this._textGuide.removeSelfFromZr(zr);
  6456. }
  6457. };
  6458. Element.prototype.animate = function (key, loop, allowDiscreteAnimation) {
  6459. var target = key ? this[key] : this;
  6460. {
  6461. if (!target) {
  6462. logError('Property "'
  6463. + key
  6464. + '" is not existed in element '
  6465. + this.id);
  6466. return;
  6467. }
  6468. }
  6469. var animator = new Animator(target, loop, allowDiscreteAnimation);
  6470. key && (animator.targetName = key);
  6471. this.addAnimator(animator, key);
  6472. return animator;
  6473. };
  6474. Element.prototype.addAnimator = function (animator, key) {
  6475. var zr = this.__zr;
  6476. var el = this;
  6477. animator.during(function () {
  6478. el.updateDuringAnimation(key);
  6479. }).done(function () {
  6480. var animators = el.animators;
  6481. var idx = indexOf(animators, animator);
  6482. if (idx >= 0) {
  6483. animators.splice(idx, 1);
  6484. }
  6485. });
  6486. this.animators.push(animator);
  6487. if (zr) {
  6488. zr.animation.addAnimator(animator);
  6489. }
  6490. zr && zr.wakeUp();
  6491. };
  6492. Element.prototype.updateDuringAnimation = function (key) {
  6493. this.markRedraw();
  6494. };
  6495. Element.prototype.stopAnimation = function (scope, forwardToLast) {
  6496. var animators = this.animators;
  6497. var len = animators.length;
  6498. var leftAnimators = [];
  6499. for (var i = 0; i < len; i++) {
  6500. var animator = animators[i];
  6501. if (!scope || scope === animator.scope) {
  6502. animator.stop(forwardToLast);
  6503. }
  6504. else {
  6505. leftAnimators.push(animator);
  6506. }
  6507. }
  6508. this.animators = leftAnimators;
  6509. return this;
  6510. };
  6511. Element.prototype.animateTo = function (target, cfg, animationProps) {
  6512. animateTo(this, target, cfg, animationProps);
  6513. };
  6514. Element.prototype.animateFrom = function (target, cfg, animationProps) {
  6515. animateTo(this, target, cfg, animationProps, true);
  6516. };
  6517. Element.prototype._transitionState = function (stateName, target, cfg, animationProps) {
  6518. var animators = animateTo(this, target, cfg, animationProps);
  6519. for (var i = 0; i < animators.length; i++) {
  6520. animators[i].__fromStateTransition = stateName;
  6521. }
  6522. };
  6523. Element.prototype.getBoundingRect = function () {
  6524. return null;
  6525. };
  6526. Element.prototype.getPaintRect = function () {
  6527. return null;
  6528. };
  6529. Element.initDefaultProps = (function () {
  6530. var elProto = Element.prototype;
  6531. elProto.type = 'element';
  6532. elProto.name = '';
  6533. elProto.ignore =
  6534. elProto.silent =
  6535. elProto.isGroup =
  6536. elProto.draggable =
  6537. elProto.dragging =
  6538. elProto.ignoreClip =
  6539. elProto.__inHover = false;
  6540. elProto.__dirty = REDRAW_BIT;
  6541. var logs = {};
  6542. function logDeprecatedError(key, xKey, yKey) {
  6543. if (!logs[key + xKey + yKey]) {
  6544. console.warn("DEPRECATED: '" + key + "' has been deprecated. use '" + xKey + "', '" + yKey + "' instead");
  6545. logs[key + xKey + yKey] = true;
  6546. }
  6547. }
  6548. function createLegacyProperty(key, privateKey, xKey, yKey) {
  6549. Object.defineProperty(elProto, key, {
  6550. get: function () {
  6551. {
  6552. logDeprecatedError(key, xKey, yKey);
  6553. }
  6554. if (!this[privateKey]) {
  6555. var pos = this[privateKey] = [];
  6556. enhanceArray(this, pos);
  6557. }
  6558. return this[privateKey];
  6559. },
  6560. set: function (pos) {
  6561. {
  6562. logDeprecatedError(key, xKey, yKey);
  6563. }
  6564. this[xKey] = pos[0];
  6565. this[yKey] = pos[1];
  6566. this[privateKey] = pos;
  6567. enhanceArray(this, pos);
  6568. }
  6569. });
  6570. function enhanceArray(self, pos) {
  6571. Object.defineProperty(pos, 0, {
  6572. get: function () {
  6573. return self[xKey];
  6574. },
  6575. set: function (val) {
  6576. self[xKey] = val;
  6577. }
  6578. });
  6579. Object.defineProperty(pos, 1, {
  6580. get: function () {
  6581. return self[yKey];
  6582. },
  6583. set: function (val) {
  6584. self[yKey] = val;
  6585. }
  6586. });
  6587. }
  6588. }
  6589. if (Object.defineProperty) {
  6590. createLegacyProperty('position', '_legacyPos', 'x', 'y');
  6591. createLegacyProperty('scale', '_legacyScale', 'scaleX', 'scaleY');
  6592. createLegacyProperty('origin', '_legacyOrigin', 'originX', 'originY');
  6593. }
  6594. })();
  6595. return Element;
  6596. }());
  6597. mixin(Element, Eventful);
  6598. mixin(Element, Transformable);
  6599. function animateTo(animatable, target, cfg, animationProps, reverse) {
  6600. cfg = cfg || {};
  6601. var animators = [];
  6602. animateToShallow(animatable, '', animatable, target, cfg, animationProps, animators, reverse);
  6603. var finishCount = animators.length;
  6604. var doneHappened = false;
  6605. var cfgDone = cfg.done;
  6606. var cfgAborted = cfg.aborted;
  6607. var doneCb = function () {
  6608. doneHappened = true;
  6609. finishCount--;
  6610. if (finishCount <= 0) {
  6611. doneHappened
  6612. ? (cfgDone && cfgDone())
  6613. : (cfgAborted && cfgAborted());
  6614. }
  6615. };
  6616. var abortedCb = function () {
  6617. finishCount--;
  6618. if (finishCount <= 0) {
  6619. doneHappened
  6620. ? (cfgDone && cfgDone())
  6621. : (cfgAborted && cfgAborted());
  6622. }
  6623. };
  6624. if (!finishCount) {
  6625. cfgDone && cfgDone();
  6626. }
  6627. if (animators.length > 0 && cfg.during) {
  6628. animators[0].during(function (target, percent) {
  6629. cfg.during(percent);
  6630. });
  6631. }
  6632. for (var i = 0; i < animators.length; i++) {
  6633. var animator = animators[i];
  6634. if (doneCb) {
  6635. animator.done(doneCb);
  6636. }
  6637. if (abortedCb) {
  6638. animator.aborted(abortedCb);
  6639. }
  6640. if (cfg.force) {
  6641. animator.duration(cfg.duration);
  6642. }
  6643. animator.start(cfg.easing);
  6644. }
  6645. return animators;
  6646. }
  6647. function copyArrShallow(source, target, len) {
  6648. for (var i = 0; i < len; i++) {
  6649. source[i] = target[i];
  6650. }
  6651. }
  6652. function is2DArray(value) {
  6653. return isArrayLike(value[0]);
  6654. }
  6655. function copyValue(target, source, key) {
  6656. if (isArrayLike(source[key])) {
  6657. if (!isArrayLike(target[key])) {
  6658. target[key] = [];
  6659. }
  6660. if (isTypedArray(source[key])) {
  6661. var len = source[key].length;
  6662. if (target[key].length !== len) {
  6663. target[key] = new (source[key].constructor)(len);
  6664. copyArrShallow(target[key], source[key], len);
  6665. }
  6666. }
  6667. else {
  6668. var sourceArr = source[key];
  6669. var targetArr = target[key];
  6670. var len0 = sourceArr.length;
  6671. if (is2DArray(sourceArr)) {
  6672. var len1 = sourceArr[0].length;
  6673. for (var i = 0; i < len0; i++) {
  6674. if (!targetArr[i]) {
  6675. targetArr[i] = Array.prototype.slice.call(sourceArr[i]);
  6676. }
  6677. else {
  6678. copyArrShallow(targetArr[i], sourceArr[i], len1);
  6679. }
  6680. }
  6681. }
  6682. else {
  6683. copyArrShallow(targetArr, sourceArr, len0);
  6684. }
  6685. targetArr.length = sourceArr.length;
  6686. }
  6687. }
  6688. else {
  6689. target[key] = source[key];
  6690. }
  6691. }
  6692. function isValueSame(val1, val2) {
  6693. return val1 === val2
  6694. || isArrayLike(val1) && isArrayLike(val2) && is1DArraySame(val1, val2);
  6695. }
  6696. function is1DArraySame(arr0, arr1) {
  6697. var len = arr0.length;
  6698. if (len !== arr1.length) {
  6699. return false;
  6700. }
  6701. for (var i = 0; i < len; i++) {
  6702. if (arr0[i] !== arr1[i]) {
  6703. return false;
  6704. }
  6705. }
  6706. return true;
  6707. }
  6708. function animateToShallow(animatable, topKey, animateObj, target, cfg, animationProps, animators, reverse) {
  6709. var targetKeys = keys(target);
  6710. var duration = cfg.duration;
  6711. var delay = cfg.delay;
  6712. var additive = cfg.additive;
  6713. var setToFinal = cfg.setToFinal;
  6714. var animateAll = !isObject(animationProps);
  6715. var existsAnimators = animatable.animators;
  6716. var animationKeys = [];
  6717. for (var k = 0; k < targetKeys.length; k++) {
  6718. var innerKey = targetKeys[k];
  6719. var targetVal = target[innerKey];
  6720. if (targetVal != null && animateObj[innerKey] != null
  6721. && (animateAll || animationProps[innerKey])) {
  6722. if (isObject(targetVal)
  6723. && !isArrayLike(targetVal)
  6724. && !isGradientObject(targetVal)) {
  6725. if (topKey) {
  6726. if (!reverse) {
  6727. animateObj[innerKey] = targetVal;
  6728. animatable.updateDuringAnimation(topKey);
  6729. }
  6730. continue;
  6731. }
  6732. animateToShallow(animatable, innerKey, animateObj[innerKey], targetVal, cfg, animationProps && animationProps[innerKey], animators, reverse);
  6733. }
  6734. else {
  6735. animationKeys.push(innerKey);
  6736. }
  6737. }
  6738. else if (!reverse) {
  6739. animateObj[innerKey] = targetVal;
  6740. animatable.updateDuringAnimation(topKey);
  6741. animationKeys.push(innerKey);
  6742. }
  6743. }
  6744. var keyLen = animationKeys.length;
  6745. if (!additive && keyLen) {
  6746. for (var i = 0; i < existsAnimators.length; i++) {
  6747. var animator = existsAnimators[i];
  6748. if (animator.targetName === topKey) {
  6749. var allAborted = animator.stopTracks(animationKeys);
  6750. if (allAborted) {
  6751. var idx = indexOf(existsAnimators, animator);
  6752. existsAnimators.splice(idx, 1);
  6753. }
  6754. }
  6755. }
  6756. }
  6757. if (!cfg.force) {
  6758. animationKeys = filter(animationKeys, function (key) { return !isValueSame(target[key], animateObj[key]); });
  6759. keyLen = animationKeys.length;
  6760. }
  6761. if (keyLen > 0
  6762. || (cfg.force && !animators.length)) {
  6763. var revertedSource = void 0;
  6764. var reversedTarget = void 0;
  6765. var sourceClone = void 0;
  6766. if (reverse) {
  6767. reversedTarget = {};
  6768. if (setToFinal) {
  6769. revertedSource = {};
  6770. }
  6771. for (var i = 0; i < keyLen; i++) {
  6772. var innerKey = animationKeys[i];
  6773. reversedTarget[innerKey] = animateObj[innerKey];
  6774. if (setToFinal) {
  6775. revertedSource[innerKey] = target[innerKey];
  6776. }
  6777. else {
  6778. animateObj[innerKey] = target[innerKey];
  6779. }
  6780. }
  6781. }
  6782. else if (setToFinal) {
  6783. sourceClone = {};
  6784. for (var i = 0; i < keyLen; i++) {
  6785. var innerKey = animationKeys[i];
  6786. sourceClone[innerKey] = cloneValue(animateObj[innerKey]);
  6787. copyValue(animateObj, target, innerKey);
  6788. }
  6789. }
  6790. var animator = new Animator(animateObj, false, false, additive ? filter(existsAnimators, function (animator) { return animator.targetName === topKey; }) : null);
  6791. animator.targetName = topKey;
  6792. if (cfg.scope) {
  6793. animator.scope = cfg.scope;
  6794. }
  6795. if (setToFinal && revertedSource) {
  6796. animator.whenWithKeys(0, revertedSource, animationKeys);
  6797. }
  6798. if (sourceClone) {
  6799. animator.whenWithKeys(0, sourceClone, animationKeys);
  6800. }
  6801. animator.whenWithKeys(duration == null ? 500 : duration, reverse ? reversedTarget : target, animationKeys).delay(delay || 0);
  6802. animatable.addAnimator(animator, topKey);
  6803. animators.push(animator);
  6804. }
  6805. }
  6806. var Group = (function (_super) {
  6807. __extends(Group, _super);
  6808. function Group(opts) {
  6809. var _this = _super.call(this) || this;
  6810. _this.isGroup = true;
  6811. _this._children = [];
  6812. _this.attr(opts);
  6813. return _this;
  6814. }
  6815. Group.prototype.childrenRef = function () {
  6816. return this._children;
  6817. };
  6818. Group.prototype.children = function () {
  6819. return this._children.slice();
  6820. };
  6821. Group.prototype.childAt = function (idx) {
  6822. return this._children[idx];
  6823. };
  6824. Group.prototype.childOfName = function (name) {
  6825. var children = this._children;
  6826. for (var i = 0; i < children.length; i++) {
  6827. if (children[i].name === name) {
  6828. return children[i];
  6829. }
  6830. }
  6831. };
  6832. Group.prototype.childCount = function () {
  6833. return this._children.length;
  6834. };
  6835. Group.prototype.add = function (child) {
  6836. if (child) {
  6837. if (child !== this && child.parent !== this) {
  6838. this._children.push(child);
  6839. this._doAdd(child);
  6840. }
  6841. {
  6842. if (child.__hostTarget) {
  6843. throw 'This elemenet has been used as an attachment';
  6844. }
  6845. }
  6846. }
  6847. return this;
  6848. };
  6849. Group.prototype.addBefore = function (child, nextSibling) {
  6850. if (child && child !== this && child.parent !== this
  6851. && nextSibling && nextSibling.parent === this) {
  6852. var children = this._children;
  6853. var idx = children.indexOf(nextSibling);
  6854. if (idx >= 0) {
  6855. children.splice(idx, 0, child);
  6856. this._doAdd(child);
  6857. }
  6858. }
  6859. return this;
  6860. };
  6861. Group.prototype.replace = function (oldChild, newChild) {
  6862. var idx = indexOf(this._children, oldChild);
  6863. if (idx >= 0) {
  6864. this.replaceAt(newChild, idx);
  6865. }
  6866. return this;
  6867. };
  6868. Group.prototype.replaceAt = function (child, index) {
  6869. var children = this._children;
  6870. var old = children[index];
  6871. if (child && child !== this && child.parent !== this && child !== old) {
  6872. children[index] = child;
  6873. old.parent = null;
  6874. var zr = this.__zr;
  6875. if (zr) {
  6876. old.removeSelfFromZr(zr);
  6877. }
  6878. this._doAdd(child);
  6879. }
  6880. return this;
  6881. };
  6882. Group.prototype._doAdd = function (child) {
  6883. if (child.parent) {
  6884. child.parent.remove(child);
  6885. }
  6886. child.parent = this;
  6887. var zr = this.__zr;
  6888. if (zr && zr !== child.__zr) {
  6889. child.addSelfToZr(zr);
  6890. }
  6891. zr && zr.refresh();
  6892. };
  6893. Group.prototype.remove = function (child) {
  6894. var zr = this.__zr;
  6895. var children = this._children;
  6896. var idx = indexOf(children, child);
  6897. if (idx < 0) {
  6898. return this;
  6899. }
  6900. children.splice(idx, 1);
  6901. child.parent = null;
  6902. if (zr) {
  6903. child.removeSelfFromZr(zr);
  6904. }
  6905. zr && zr.refresh();
  6906. return this;
  6907. };
  6908. Group.prototype.removeAll = function () {
  6909. var children = this._children;
  6910. var zr = this.__zr;
  6911. for (var i = 0; i < children.length; i++) {
  6912. var child = children[i];
  6913. if (zr) {
  6914. child.removeSelfFromZr(zr);
  6915. }
  6916. child.parent = null;
  6917. }
  6918. children.length = 0;
  6919. return this;
  6920. };
  6921. Group.prototype.eachChild = function (cb, context) {
  6922. var children = this._children;
  6923. for (var i = 0; i < children.length; i++) {
  6924. var child = children[i];
  6925. cb.call(context, child, i);
  6926. }
  6927. return this;
  6928. };
  6929. Group.prototype.traverse = function (cb, context) {
  6930. for (var i = 0; i < this._children.length; i++) {
  6931. var child = this._children[i];
  6932. var stopped = cb.call(context, child);
  6933. if (child.isGroup && !stopped) {
  6934. child.traverse(cb, context);
  6935. }
  6936. }
  6937. return this;
  6938. };
  6939. Group.prototype.addSelfToZr = function (zr) {
  6940. _super.prototype.addSelfToZr.call(this, zr);
  6941. for (var i = 0; i < this._children.length; i++) {
  6942. var child = this._children[i];
  6943. child.addSelfToZr(zr);
  6944. }
  6945. };
  6946. Group.prototype.removeSelfFromZr = function (zr) {
  6947. _super.prototype.removeSelfFromZr.call(this, zr);
  6948. for (var i = 0; i < this._children.length; i++) {
  6949. var child = this._children[i];
  6950. child.removeSelfFromZr(zr);
  6951. }
  6952. };
  6953. Group.prototype.getBoundingRect = function (includeChildren) {
  6954. var tmpRect = new BoundingRect(0, 0, 0, 0);
  6955. var children = includeChildren || this._children;
  6956. var tmpMat = [];
  6957. var rect = null;
  6958. for (var i = 0; i < children.length; i++) {
  6959. var child = children[i];
  6960. if (child.ignore || child.invisible) {
  6961. continue;
  6962. }
  6963. var childRect = child.getBoundingRect();
  6964. var transform = child.getLocalTransform(tmpMat);
  6965. if (transform) {
  6966. BoundingRect.applyTransform(tmpRect, childRect, transform);
  6967. rect = rect || tmpRect.clone();
  6968. rect.union(tmpRect);
  6969. }
  6970. else {
  6971. rect = rect || childRect.clone();
  6972. rect.union(childRect);
  6973. }
  6974. }
  6975. return rect || tmpRect;
  6976. };
  6977. return Group;
  6978. }(Element));
  6979. Group.prototype.type = 'group';
  6980. /*!
  6981. * ZRender, a high performance 2d drawing library.
  6982. *
  6983. * Copyright (c) 2013, Baidu Inc.
  6984. * All rights reserved.
  6985. *
  6986. * LICENSE
  6987. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  6988. */
  6989. var painterCtors = {};
  6990. var instances = {};
  6991. function delInstance(id) {
  6992. delete instances[id];
  6993. }
  6994. function isDarkMode(backgroundColor) {
  6995. if (!backgroundColor) {
  6996. return false;
  6997. }
  6998. if (typeof backgroundColor === 'string') {
  6999. return lum(backgroundColor, 1) < DARK_MODE_THRESHOLD;
  7000. }
  7001. else if (backgroundColor.colorStops) {
  7002. var colorStops = backgroundColor.colorStops;
  7003. var totalLum = 0;
  7004. var len = colorStops.length;
  7005. for (var i = 0; i < len; i++) {
  7006. totalLum += lum(colorStops[i].color, 1);
  7007. }
  7008. totalLum /= len;
  7009. return totalLum < DARK_MODE_THRESHOLD;
  7010. }
  7011. return false;
  7012. }
  7013. var ZRender = (function () {
  7014. function ZRender(id, dom, opts) {
  7015. var _this = this;
  7016. this._sleepAfterStill = 10;
  7017. this._stillFrameAccum = 0;
  7018. this._needsRefresh = true;
  7019. this._needsRefreshHover = true;
  7020. this._darkMode = false;
  7021. opts = opts || {};
  7022. this.dom = dom;
  7023. this.id = id;
  7024. var storage = new Storage();
  7025. var rendererType = opts.renderer || 'canvas';
  7026. if (!painterCtors[rendererType]) {
  7027. rendererType = keys(painterCtors)[0];
  7028. }
  7029. {
  7030. if (!painterCtors[rendererType]) {
  7031. throw new Error("Renderer '" + rendererType + "' is not imported. Please import it first.");
  7032. }
  7033. }
  7034. opts.useDirtyRect = opts.useDirtyRect == null
  7035. ? false
  7036. : opts.useDirtyRect;
  7037. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  7038. var ssrMode = opts.ssr || painter.ssrOnly;
  7039. this.storage = storage;
  7040. this.painter = painter;
  7041. var handlerProxy = (!env.node && !env.worker && !ssrMode)
  7042. ? new HandlerDomProxy(painter.getViewportRoot(), painter.root)
  7043. : null;
  7044. var useCoarsePointer = opts.useCoarsePointer;
  7045. var usePointerSize = (useCoarsePointer == null || useCoarsePointer === 'auto')
  7046. ? env.touchEventsSupported
  7047. : !!useCoarsePointer;
  7048. var defaultPointerSize = 44;
  7049. var pointerSize;
  7050. if (usePointerSize) {
  7051. pointerSize = retrieve2(opts.pointerSize, defaultPointerSize);
  7052. }
  7053. this.handler = new Handler(storage, painter, handlerProxy, painter.root, pointerSize);
  7054. this.animation = new Animation({
  7055. stage: {
  7056. update: ssrMode ? null : function () { return _this._flush(true); }
  7057. }
  7058. });
  7059. if (!ssrMode) {
  7060. this.animation.start();
  7061. }
  7062. }
  7063. ZRender.prototype.add = function (el) {
  7064. if (this._disposed || !el) {
  7065. return;
  7066. }
  7067. this.storage.addRoot(el);
  7068. el.addSelfToZr(this);
  7069. this.refresh();
  7070. };
  7071. ZRender.prototype.remove = function (el) {
  7072. if (this._disposed || !el) {
  7073. return;
  7074. }
  7075. this.storage.delRoot(el);
  7076. el.removeSelfFromZr(this);
  7077. this.refresh();
  7078. };
  7079. ZRender.prototype.configLayer = function (zLevel, config) {
  7080. if (this._disposed) {
  7081. return;
  7082. }
  7083. if (this.painter.configLayer) {
  7084. this.painter.configLayer(zLevel, config);
  7085. }
  7086. this.refresh();
  7087. };
  7088. ZRender.prototype.setBackgroundColor = function (backgroundColor) {
  7089. if (this._disposed) {
  7090. return;
  7091. }
  7092. if (this.painter.setBackgroundColor) {
  7093. this.painter.setBackgroundColor(backgroundColor);
  7094. }
  7095. this.refresh();
  7096. this._backgroundColor = backgroundColor;
  7097. this._darkMode = isDarkMode(backgroundColor);
  7098. };
  7099. ZRender.prototype.getBackgroundColor = function () {
  7100. return this._backgroundColor;
  7101. };
  7102. ZRender.prototype.setDarkMode = function (darkMode) {
  7103. this._darkMode = darkMode;
  7104. };
  7105. ZRender.prototype.isDarkMode = function () {
  7106. return this._darkMode;
  7107. };
  7108. ZRender.prototype.refreshImmediately = function (fromInside) {
  7109. if (this._disposed) {
  7110. return;
  7111. }
  7112. if (!fromInside) {
  7113. this.animation.update(true);
  7114. }
  7115. this._needsRefresh = false;
  7116. this.painter.refresh();
  7117. this._needsRefresh = false;
  7118. };
  7119. ZRender.prototype.refresh = function () {
  7120. if (this._disposed) {
  7121. return;
  7122. }
  7123. this._needsRefresh = true;
  7124. this.animation.start();
  7125. };
  7126. ZRender.prototype.flush = function () {
  7127. if (this._disposed) {
  7128. return;
  7129. }
  7130. this._flush(false);
  7131. };
  7132. ZRender.prototype._flush = function (fromInside) {
  7133. var triggerRendered;
  7134. var start = getTime();
  7135. if (this._needsRefresh) {
  7136. triggerRendered = true;
  7137. this.refreshImmediately(fromInside);
  7138. }
  7139. if (this._needsRefreshHover) {
  7140. triggerRendered = true;
  7141. this.refreshHoverImmediately();
  7142. }
  7143. var end = getTime();
  7144. if (triggerRendered) {
  7145. this._stillFrameAccum = 0;
  7146. this.trigger('rendered', {
  7147. elapsedTime: end - start
  7148. });
  7149. }
  7150. else if (this._sleepAfterStill > 0) {
  7151. this._stillFrameAccum++;
  7152. if (this._stillFrameAccum > this._sleepAfterStill) {
  7153. this.animation.stop();
  7154. }
  7155. }
  7156. };
  7157. ZRender.prototype.setSleepAfterStill = function (stillFramesCount) {
  7158. this._sleepAfterStill = stillFramesCount;
  7159. };
  7160. ZRender.prototype.wakeUp = function () {
  7161. if (this._disposed) {
  7162. return;
  7163. }
  7164. this.animation.start();
  7165. this._stillFrameAccum = 0;
  7166. };
  7167. ZRender.prototype.refreshHover = function () {
  7168. this._needsRefreshHover = true;
  7169. };
  7170. ZRender.prototype.refreshHoverImmediately = function () {
  7171. if (this._disposed) {
  7172. return;
  7173. }
  7174. this._needsRefreshHover = false;
  7175. if (this.painter.refreshHover && this.painter.getType() === 'canvas') {
  7176. this.painter.refreshHover();
  7177. }
  7178. };
  7179. ZRender.prototype.resize = function (opts) {
  7180. if (this._disposed) {
  7181. return;
  7182. }
  7183. opts = opts || {};
  7184. this.painter.resize(opts.width, opts.height);
  7185. this.handler.resize();
  7186. };
  7187. ZRender.prototype.clearAnimation = function () {
  7188. if (this._disposed) {
  7189. return;
  7190. }
  7191. this.animation.clear();
  7192. };
  7193. ZRender.prototype.getWidth = function () {
  7194. if (this._disposed) {
  7195. return;
  7196. }
  7197. return this.painter.getWidth();
  7198. };
  7199. ZRender.prototype.getHeight = function () {
  7200. if (this._disposed) {
  7201. return;
  7202. }
  7203. return this.painter.getHeight();
  7204. };
  7205. ZRender.prototype.setCursorStyle = function (cursorStyle) {
  7206. if (this._disposed) {
  7207. return;
  7208. }
  7209. this.handler.setCursorStyle(cursorStyle);
  7210. };
  7211. ZRender.prototype.findHover = function (x, y) {
  7212. if (this._disposed) {
  7213. return;
  7214. }
  7215. return this.handler.findHover(x, y);
  7216. };
  7217. ZRender.prototype.on = function (eventName, eventHandler, context) {
  7218. if (!this._disposed) {
  7219. this.handler.on(eventName, eventHandler, context);
  7220. }
  7221. return this;
  7222. };
  7223. ZRender.prototype.off = function (eventName, eventHandler) {
  7224. if (this._disposed) {
  7225. return;
  7226. }
  7227. this.handler.off(eventName, eventHandler);
  7228. };
  7229. ZRender.prototype.trigger = function (eventName, event) {
  7230. if (this._disposed) {
  7231. return;
  7232. }
  7233. this.handler.trigger(eventName, event);
  7234. };
  7235. ZRender.prototype.clear = function () {
  7236. if (this._disposed) {
  7237. return;
  7238. }
  7239. var roots = this.storage.getRoots();
  7240. for (var i = 0; i < roots.length; i++) {
  7241. if (roots[i] instanceof Group) {
  7242. roots[i].removeSelfFromZr(this);
  7243. }
  7244. }
  7245. this.storage.delAllRoots();
  7246. this.painter.clear();
  7247. };
  7248. ZRender.prototype.dispose = function () {
  7249. if (this._disposed) {
  7250. return;
  7251. }
  7252. this.animation.stop();
  7253. this.clear();
  7254. this.storage.dispose();
  7255. this.painter.dispose();
  7256. this.handler.dispose();
  7257. this.animation =
  7258. this.storage =
  7259. this.painter =
  7260. this.handler = null;
  7261. this._disposed = true;
  7262. delInstance(this.id);
  7263. };
  7264. return ZRender;
  7265. }());
  7266. function init(dom, opts) {
  7267. var zr = new ZRender(guid(), dom, opts);
  7268. instances[zr.id] = zr;
  7269. return zr;
  7270. }
  7271. function dispose(zr) {
  7272. zr.dispose();
  7273. }
  7274. function disposeAll() {
  7275. for (var key in instances) {
  7276. if (instances.hasOwnProperty(key)) {
  7277. instances[key].dispose();
  7278. }
  7279. }
  7280. instances = {};
  7281. }
  7282. function getInstance(id) {
  7283. return instances[id];
  7284. }
  7285. function registerPainter(name, Ctor) {
  7286. painterCtors[name] = Ctor;
  7287. }
  7288. var ssrDataGetter;
  7289. function getElementSSRData(el) {
  7290. if (typeof ssrDataGetter === 'function') {
  7291. return ssrDataGetter(el);
  7292. }
  7293. }
  7294. function registerSSRDataGetter(getter) {
  7295. ssrDataGetter = getter;
  7296. }
  7297. var version = '5.6.1';
  7298. var STYLE_MAGIC_KEY = '__zr_style_' + Math.round((Math.random() * 10));
  7299. var DEFAULT_COMMON_STYLE = {
  7300. shadowBlur: 0,
  7301. shadowOffsetX: 0,
  7302. shadowOffsetY: 0,
  7303. shadowColor: '#000',
  7304. opacity: 1,
  7305. blend: 'source-over'
  7306. };
  7307. var DEFAULT_COMMON_ANIMATION_PROPS = {
  7308. style: {
  7309. shadowBlur: true,
  7310. shadowOffsetX: true,
  7311. shadowOffsetY: true,
  7312. shadowColor: true,
  7313. opacity: true
  7314. }
  7315. };
  7316. DEFAULT_COMMON_STYLE[STYLE_MAGIC_KEY] = true;
  7317. var PRIMARY_STATES_KEYS$1 = ['z', 'z2', 'invisible'];
  7318. var PRIMARY_STATES_KEYS_IN_HOVER_LAYER = ['invisible'];
  7319. var Displayable = (function (_super) {
  7320. __extends(Displayable, _super);
  7321. function Displayable(props) {
  7322. return _super.call(this, props) || this;
  7323. }
  7324. Displayable.prototype._init = function (props) {
  7325. var keysArr = keys(props);
  7326. for (var i = 0; i < keysArr.length; i++) {
  7327. var key = keysArr[i];
  7328. if (key === 'style') {
  7329. this.useStyle(props[key]);
  7330. }
  7331. else {
  7332. _super.prototype.attrKV.call(this, key, props[key]);
  7333. }
  7334. }
  7335. if (!this.style) {
  7336. this.useStyle({});
  7337. }
  7338. };
  7339. Displayable.prototype.beforeBrush = function () { };
  7340. Displayable.prototype.afterBrush = function () { };
  7341. Displayable.prototype.innerBeforeBrush = function () { };
  7342. Displayable.prototype.innerAfterBrush = function () { };
  7343. Displayable.prototype.shouldBePainted = function (viewWidth, viewHeight, considerClipPath, considerAncestors) {
  7344. var m = this.transform;
  7345. if (this.ignore
  7346. || this.invisible
  7347. || this.style.opacity === 0
  7348. || (this.culling
  7349. && isDisplayableCulled(this, viewWidth, viewHeight))
  7350. || (m && !m[0] && !m[3])) {
  7351. return false;
  7352. }
  7353. if (considerClipPath && this.__clipPaths) {
  7354. for (var i = 0; i < this.__clipPaths.length; ++i) {
  7355. if (this.__clipPaths[i].isZeroArea()) {
  7356. return false;
  7357. }
  7358. }
  7359. }
  7360. if (considerAncestors && this.parent) {
  7361. var parent_1 = this.parent;
  7362. while (parent_1) {
  7363. if (parent_1.ignore) {
  7364. return false;
  7365. }
  7366. parent_1 = parent_1.parent;
  7367. }
  7368. }
  7369. return true;
  7370. };
  7371. Displayable.prototype.contain = function (x, y) {
  7372. return this.rectContain(x, y);
  7373. };
  7374. Displayable.prototype.traverse = function (cb, context) {
  7375. cb.call(context, this);
  7376. };
  7377. Displayable.prototype.rectContain = function (x, y) {
  7378. var coord = this.transformCoordToLocal(x, y);
  7379. var rect = this.getBoundingRect();
  7380. return rect.contain(coord[0], coord[1]);
  7381. };
  7382. Displayable.prototype.getPaintRect = function () {
  7383. var rect = this._paintRect;
  7384. if (!this._paintRect || this.__dirty) {
  7385. var transform = this.transform;
  7386. var elRect = this.getBoundingRect();
  7387. var style = this.style;
  7388. var shadowSize = style.shadowBlur || 0;
  7389. var shadowOffsetX = style.shadowOffsetX || 0;
  7390. var shadowOffsetY = style.shadowOffsetY || 0;
  7391. rect = this._paintRect || (this._paintRect = new BoundingRect(0, 0, 0, 0));
  7392. if (transform) {
  7393. BoundingRect.applyTransform(rect, elRect, transform);
  7394. }
  7395. else {
  7396. rect.copy(elRect);
  7397. }
  7398. if (shadowSize || shadowOffsetX || shadowOffsetY) {
  7399. rect.width += shadowSize * 2 + Math.abs(shadowOffsetX);
  7400. rect.height += shadowSize * 2 + Math.abs(shadowOffsetY);
  7401. rect.x = Math.min(rect.x, rect.x + shadowOffsetX - shadowSize);
  7402. rect.y = Math.min(rect.y, rect.y + shadowOffsetY - shadowSize);
  7403. }
  7404. var tolerance = this.dirtyRectTolerance;
  7405. if (!rect.isZero()) {
  7406. rect.x = Math.floor(rect.x - tolerance);
  7407. rect.y = Math.floor(rect.y - tolerance);
  7408. rect.width = Math.ceil(rect.width + 1 + tolerance * 2);
  7409. rect.height = Math.ceil(rect.height + 1 + tolerance * 2);
  7410. }
  7411. }
  7412. return rect;
  7413. };
  7414. Displayable.prototype.setPrevPaintRect = function (paintRect) {
  7415. if (paintRect) {
  7416. this._prevPaintRect = this._prevPaintRect || new BoundingRect(0, 0, 0, 0);
  7417. this._prevPaintRect.copy(paintRect);
  7418. }
  7419. else {
  7420. this._prevPaintRect = null;
  7421. }
  7422. };
  7423. Displayable.prototype.getPrevPaintRect = function () {
  7424. return this._prevPaintRect;
  7425. };
  7426. Displayable.prototype.animateStyle = function (loop) {
  7427. return this.animate('style', loop);
  7428. };
  7429. Displayable.prototype.updateDuringAnimation = function (targetKey) {
  7430. if (targetKey === 'style') {
  7431. this.dirtyStyle();
  7432. }
  7433. else {
  7434. this.markRedraw();
  7435. }
  7436. };
  7437. Displayable.prototype.attrKV = function (key, value) {
  7438. if (key !== 'style') {
  7439. _super.prototype.attrKV.call(this, key, value);
  7440. }
  7441. else {
  7442. if (!this.style) {
  7443. this.useStyle(value);
  7444. }
  7445. else {
  7446. this.setStyle(value);
  7447. }
  7448. }
  7449. };
  7450. Displayable.prototype.setStyle = function (keyOrObj, value) {
  7451. if (typeof keyOrObj === 'string') {
  7452. this.style[keyOrObj] = value;
  7453. }
  7454. else {
  7455. extend(this.style, keyOrObj);
  7456. }
  7457. this.dirtyStyle();
  7458. return this;
  7459. };
  7460. Displayable.prototype.dirtyStyle = function (notRedraw) {
  7461. if (!notRedraw) {
  7462. this.markRedraw();
  7463. }
  7464. this.__dirty |= STYLE_CHANGED_BIT;
  7465. if (this._rect) {
  7466. this._rect = null;
  7467. }
  7468. };
  7469. Displayable.prototype.dirty = function () {
  7470. this.dirtyStyle();
  7471. };
  7472. Displayable.prototype.styleChanged = function () {
  7473. return !!(this.__dirty & STYLE_CHANGED_BIT);
  7474. };
  7475. Displayable.prototype.styleUpdated = function () {
  7476. this.__dirty &= ~STYLE_CHANGED_BIT;
  7477. };
  7478. Displayable.prototype.createStyle = function (obj) {
  7479. return createObject(DEFAULT_COMMON_STYLE, obj);
  7480. };
  7481. Displayable.prototype.useStyle = function (obj) {
  7482. if (!obj[STYLE_MAGIC_KEY]) {
  7483. obj = this.createStyle(obj);
  7484. }
  7485. if (this.__inHover) {
  7486. this.__hoverStyle = obj;
  7487. }
  7488. else {
  7489. this.style = obj;
  7490. }
  7491. this.dirtyStyle();
  7492. };
  7493. Displayable.prototype.isStyleObject = function (obj) {
  7494. return obj[STYLE_MAGIC_KEY];
  7495. };
  7496. Displayable.prototype._innerSaveToNormal = function (toState) {
  7497. _super.prototype._innerSaveToNormal.call(this, toState);
  7498. var normalState = this._normalState;
  7499. if (toState.style && !normalState.style) {
  7500. normalState.style = this._mergeStyle(this.createStyle(), this.style);
  7501. }
  7502. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS$1);
  7503. };
  7504. Displayable.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  7505. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  7506. var needsRestoreToNormal = !(state && keepCurrentStates);
  7507. var targetStyle;
  7508. if (state && state.style) {
  7509. if (transition) {
  7510. if (keepCurrentStates) {
  7511. targetStyle = state.style;
  7512. }
  7513. else {
  7514. targetStyle = this._mergeStyle(this.createStyle(), normalState.style);
  7515. this._mergeStyle(targetStyle, state.style);
  7516. }
  7517. }
  7518. else {
  7519. targetStyle = this._mergeStyle(this.createStyle(), keepCurrentStates ? this.style : normalState.style);
  7520. this._mergeStyle(targetStyle, state.style);
  7521. }
  7522. }
  7523. else if (needsRestoreToNormal) {
  7524. targetStyle = normalState.style;
  7525. }
  7526. if (targetStyle) {
  7527. if (transition) {
  7528. var sourceStyle = this.style;
  7529. this.style = this.createStyle(needsRestoreToNormal ? {} : sourceStyle);
  7530. if (needsRestoreToNormal) {
  7531. var changedKeys = keys(sourceStyle);
  7532. for (var i = 0; i < changedKeys.length; i++) {
  7533. var key = changedKeys[i];
  7534. if (key in targetStyle) {
  7535. targetStyle[key] = targetStyle[key];
  7536. this.style[key] = sourceStyle[key];
  7537. }
  7538. }
  7539. }
  7540. var targetKeys = keys(targetStyle);
  7541. for (var i = 0; i < targetKeys.length; i++) {
  7542. var key = targetKeys[i];
  7543. this.style[key] = this.style[key];
  7544. }
  7545. this._transitionState(stateName, {
  7546. style: targetStyle
  7547. }, animationCfg, this.getAnimationStyleProps());
  7548. }
  7549. else {
  7550. this.useStyle(targetStyle);
  7551. }
  7552. }
  7553. var statesKeys = this.__inHover ? PRIMARY_STATES_KEYS_IN_HOVER_LAYER : PRIMARY_STATES_KEYS$1;
  7554. for (var i = 0; i < statesKeys.length; i++) {
  7555. var key = statesKeys[i];
  7556. if (state && state[key] != null) {
  7557. this[key] = state[key];
  7558. }
  7559. else if (needsRestoreToNormal) {
  7560. if (normalState[key] != null) {
  7561. this[key] = normalState[key];
  7562. }
  7563. }
  7564. }
  7565. };
  7566. Displayable.prototype._mergeStates = function (states) {
  7567. var mergedState = _super.prototype._mergeStates.call(this, states);
  7568. var mergedStyle;
  7569. for (var i = 0; i < states.length; i++) {
  7570. var state = states[i];
  7571. if (state.style) {
  7572. mergedStyle = mergedStyle || {};
  7573. this._mergeStyle(mergedStyle, state.style);
  7574. }
  7575. }
  7576. if (mergedStyle) {
  7577. mergedState.style = mergedStyle;
  7578. }
  7579. return mergedState;
  7580. };
  7581. Displayable.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  7582. extend(targetStyle, sourceStyle);
  7583. return targetStyle;
  7584. };
  7585. Displayable.prototype.getAnimationStyleProps = function () {
  7586. return DEFAULT_COMMON_ANIMATION_PROPS;
  7587. };
  7588. Displayable.initDefaultProps = (function () {
  7589. var dispProto = Displayable.prototype;
  7590. dispProto.type = 'displayable';
  7591. dispProto.invisible = false;
  7592. dispProto.z = 0;
  7593. dispProto.z2 = 0;
  7594. dispProto.zlevel = 0;
  7595. dispProto.culling = false;
  7596. dispProto.cursor = 'pointer';
  7597. dispProto.rectHover = false;
  7598. dispProto.incremental = false;
  7599. dispProto._rect = null;
  7600. dispProto.dirtyRectTolerance = 0;
  7601. dispProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT;
  7602. })();
  7603. return Displayable;
  7604. }(Element));
  7605. var tmpRect$1 = new BoundingRect(0, 0, 0, 0);
  7606. var viewRect = new BoundingRect(0, 0, 0, 0);
  7607. function isDisplayableCulled(el, width, height) {
  7608. tmpRect$1.copy(el.getBoundingRect());
  7609. if (el.transform) {
  7610. tmpRect$1.applyTransform(el.transform);
  7611. }
  7612. viewRect.width = width;
  7613. viewRect.height = height;
  7614. return !tmpRect$1.intersect(viewRect);
  7615. }
  7616. var mathMin$1 = Math.min;
  7617. var mathMax$1 = Math.max;
  7618. var mathSin = Math.sin;
  7619. var mathCos = Math.cos;
  7620. var PI2 = Math.PI * 2;
  7621. var start = create();
  7622. var end = create();
  7623. var extremity = create();
  7624. function fromPoints(points, min, max) {
  7625. if (points.length === 0) {
  7626. return;
  7627. }
  7628. var p = points[0];
  7629. var left = p[0];
  7630. var right = p[0];
  7631. var top = p[1];
  7632. var bottom = p[1];
  7633. for (var i = 1; i < points.length; i++) {
  7634. p = points[i];
  7635. left = mathMin$1(left, p[0]);
  7636. right = mathMax$1(right, p[0]);
  7637. top = mathMin$1(top, p[1]);
  7638. bottom = mathMax$1(bottom, p[1]);
  7639. }
  7640. min[0] = left;
  7641. min[1] = top;
  7642. max[0] = right;
  7643. max[1] = bottom;
  7644. }
  7645. function fromLine(x0, y0, x1, y1, min, max) {
  7646. min[0] = mathMin$1(x0, x1);
  7647. min[1] = mathMin$1(y0, y1);
  7648. max[0] = mathMax$1(x0, x1);
  7649. max[1] = mathMax$1(y0, y1);
  7650. }
  7651. var xDim = [];
  7652. var yDim = [];
  7653. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min, max) {
  7654. var cubicExtrema$1 = cubicExtrema;
  7655. var cubicAt$1 = cubicAt;
  7656. var n = cubicExtrema$1(x0, x1, x2, x3, xDim);
  7657. min[0] = Infinity;
  7658. min[1] = Infinity;
  7659. max[0] = -Infinity;
  7660. max[1] = -Infinity;
  7661. for (var i = 0; i < n; i++) {
  7662. var x = cubicAt$1(x0, x1, x2, x3, xDim[i]);
  7663. min[0] = mathMin$1(x, min[0]);
  7664. max[0] = mathMax$1(x, max[0]);
  7665. }
  7666. n = cubicExtrema$1(y0, y1, y2, y3, yDim);
  7667. for (var i = 0; i < n; i++) {
  7668. var y = cubicAt$1(y0, y1, y2, y3, yDim[i]);
  7669. min[1] = mathMin$1(y, min[1]);
  7670. max[1] = mathMax$1(y, max[1]);
  7671. }
  7672. min[0] = mathMin$1(x0, min[0]);
  7673. max[0] = mathMax$1(x0, max[0]);
  7674. min[0] = mathMin$1(x3, min[0]);
  7675. max[0] = mathMax$1(x3, max[0]);
  7676. min[1] = mathMin$1(y0, min[1]);
  7677. max[1] = mathMax$1(y0, max[1]);
  7678. min[1] = mathMin$1(y3, min[1]);
  7679. max[1] = mathMax$1(y3, max[1]);
  7680. }
  7681. function fromQuadratic(x0, y0, x1, y1, x2, y2, min, max) {
  7682. var quadraticExtremum$1 = quadraticExtremum;
  7683. var quadraticAt$1 = quadraticAt;
  7684. var tx = mathMax$1(mathMin$1(quadraticExtremum$1(x0, x1, x2), 1), 0);
  7685. var ty = mathMax$1(mathMin$1(quadraticExtremum$1(y0, y1, y2), 1), 0);
  7686. var x = quadraticAt$1(x0, x1, x2, tx);
  7687. var y = quadraticAt$1(y0, y1, y2, ty);
  7688. min[0] = mathMin$1(x0, x2, x);
  7689. min[1] = mathMin$1(y0, y2, y);
  7690. max[0] = mathMax$1(x0, x2, x);
  7691. max[1] = mathMax$1(y0, y2, y);
  7692. }
  7693. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min$1, max$1) {
  7694. var vec2Min = min;
  7695. var vec2Max = max;
  7696. var diff = Math.abs(startAngle - endAngle);
  7697. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  7698. min$1[0] = x - rx;
  7699. min$1[1] = y - ry;
  7700. max$1[0] = x + rx;
  7701. max$1[1] = y + ry;
  7702. return;
  7703. }
  7704. start[0] = mathCos(startAngle) * rx + x;
  7705. start[1] = mathSin(startAngle) * ry + y;
  7706. end[0] = mathCos(endAngle) * rx + x;
  7707. end[1] = mathSin(endAngle) * ry + y;
  7708. vec2Min(min$1, start, end);
  7709. vec2Max(max$1, start, end);
  7710. startAngle = startAngle % (PI2);
  7711. if (startAngle < 0) {
  7712. startAngle = startAngle + PI2;
  7713. }
  7714. endAngle = endAngle % (PI2);
  7715. if (endAngle < 0) {
  7716. endAngle = endAngle + PI2;
  7717. }
  7718. if (startAngle > endAngle && !anticlockwise) {
  7719. endAngle += PI2;
  7720. }
  7721. else if (startAngle < endAngle && anticlockwise) {
  7722. startAngle += PI2;
  7723. }
  7724. if (anticlockwise) {
  7725. var tmp = endAngle;
  7726. endAngle = startAngle;
  7727. startAngle = tmp;
  7728. }
  7729. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  7730. if (angle > startAngle) {
  7731. extremity[0] = mathCos(angle) * rx + x;
  7732. extremity[1] = mathSin(angle) * ry + y;
  7733. vec2Min(min$1, extremity, min$1);
  7734. vec2Max(max$1, extremity, max$1);
  7735. }
  7736. }
  7737. }
  7738. var CMD = {
  7739. M: 1,
  7740. L: 2,
  7741. C: 3,
  7742. Q: 4,
  7743. A: 5,
  7744. Z: 6,
  7745. R: 7
  7746. };
  7747. var tmpOutX = [];
  7748. var tmpOutY = [];
  7749. var min$1 = [];
  7750. var max$1 = [];
  7751. var min2 = [];
  7752. var max2 = [];
  7753. var mathMin$2 = Math.min;
  7754. var mathMax$2 = Math.max;
  7755. var mathCos$1 = Math.cos;
  7756. var mathSin$1 = Math.sin;
  7757. var mathAbs = Math.abs;
  7758. var PI = Math.PI;
  7759. var PI2$1 = PI * 2;
  7760. var hasTypedArray = typeof Float32Array !== 'undefined';
  7761. var tmpAngles = [];
  7762. function modPI2(radian) {
  7763. var n = Math.round(radian / PI * 1e8) / 1e8;
  7764. return (n % 2) * PI;
  7765. }
  7766. function normalizeArcAngles(angles, anticlockwise) {
  7767. var newStartAngle = modPI2(angles[0]);
  7768. if (newStartAngle < 0) {
  7769. newStartAngle += PI2$1;
  7770. }
  7771. var delta = newStartAngle - angles[0];
  7772. var newEndAngle = angles[1];
  7773. newEndAngle += delta;
  7774. if (!anticlockwise && newEndAngle - newStartAngle >= PI2$1) {
  7775. newEndAngle = newStartAngle + PI2$1;
  7776. }
  7777. else if (anticlockwise && newStartAngle - newEndAngle >= PI2$1) {
  7778. newEndAngle = newStartAngle - PI2$1;
  7779. }
  7780. else if (!anticlockwise && newStartAngle > newEndAngle) {
  7781. newEndAngle = newStartAngle + (PI2$1 - modPI2(newStartAngle - newEndAngle));
  7782. }
  7783. else if (anticlockwise && newStartAngle < newEndAngle) {
  7784. newEndAngle = newStartAngle - (PI2$1 - modPI2(newEndAngle - newStartAngle));
  7785. }
  7786. angles[0] = newStartAngle;
  7787. angles[1] = newEndAngle;
  7788. }
  7789. var PathProxy = (function () {
  7790. function PathProxy(notSaveData) {
  7791. this.dpr = 1;
  7792. this._xi = 0;
  7793. this._yi = 0;
  7794. this._x0 = 0;
  7795. this._y0 = 0;
  7796. this._len = 0;
  7797. if (notSaveData) {
  7798. this._saveData = false;
  7799. }
  7800. if (this._saveData) {
  7801. this.data = [];
  7802. }
  7803. }
  7804. PathProxy.prototype.increaseVersion = function () {
  7805. this._version++;
  7806. };
  7807. PathProxy.prototype.getVersion = function () {
  7808. return this._version;
  7809. };
  7810. PathProxy.prototype.setScale = function (sx, sy, segmentIgnoreThreshold) {
  7811. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  7812. if (segmentIgnoreThreshold > 0) {
  7813. this._ux = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  7814. this._uy = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  7815. }
  7816. };
  7817. PathProxy.prototype.setDPR = function (dpr) {
  7818. this.dpr = dpr;
  7819. };
  7820. PathProxy.prototype.setContext = function (ctx) {
  7821. this._ctx = ctx;
  7822. };
  7823. PathProxy.prototype.getContext = function () {
  7824. return this._ctx;
  7825. };
  7826. PathProxy.prototype.beginPath = function () {
  7827. this._ctx && this._ctx.beginPath();
  7828. this.reset();
  7829. return this;
  7830. };
  7831. PathProxy.prototype.reset = function () {
  7832. if (this._saveData) {
  7833. this._len = 0;
  7834. }
  7835. if (this._pathSegLen) {
  7836. this._pathSegLen = null;
  7837. this._pathLen = 0;
  7838. }
  7839. this._version++;
  7840. };
  7841. PathProxy.prototype.moveTo = function (x, y) {
  7842. this._drawPendingPt();
  7843. this.addData(CMD.M, x, y);
  7844. this._ctx && this._ctx.moveTo(x, y);
  7845. this._x0 = x;
  7846. this._y0 = y;
  7847. this._xi = x;
  7848. this._yi = y;
  7849. return this;
  7850. };
  7851. PathProxy.prototype.lineTo = function (x, y) {
  7852. var dx = mathAbs(x - this._xi);
  7853. var dy = mathAbs(y - this._yi);
  7854. var exceedUnit = dx > this._ux || dy > this._uy;
  7855. this.addData(CMD.L, x, y);
  7856. if (this._ctx && exceedUnit) {
  7857. this._ctx.lineTo(x, y);
  7858. }
  7859. if (exceedUnit) {
  7860. this._xi = x;
  7861. this._yi = y;
  7862. this._pendingPtDist = 0;
  7863. }
  7864. else {
  7865. var d2 = dx * dx + dy * dy;
  7866. if (d2 > this._pendingPtDist) {
  7867. this._pendingPtX = x;
  7868. this._pendingPtY = y;
  7869. this._pendingPtDist = d2;
  7870. }
  7871. }
  7872. return this;
  7873. };
  7874. PathProxy.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
  7875. this._drawPendingPt();
  7876. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  7877. if (this._ctx) {
  7878. this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  7879. }
  7880. this._xi = x3;
  7881. this._yi = y3;
  7882. return this;
  7883. };
  7884. PathProxy.prototype.quadraticCurveTo = function (x1, y1, x2, y2) {
  7885. this._drawPendingPt();
  7886. this.addData(CMD.Q, x1, y1, x2, y2);
  7887. if (this._ctx) {
  7888. this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  7889. }
  7890. this._xi = x2;
  7891. this._yi = y2;
  7892. return this;
  7893. };
  7894. PathProxy.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  7895. this._drawPendingPt();
  7896. tmpAngles[0] = startAngle;
  7897. tmpAngles[1] = endAngle;
  7898. normalizeArcAngles(tmpAngles, anticlockwise);
  7899. startAngle = tmpAngles[0];
  7900. endAngle = tmpAngles[1];
  7901. var delta = endAngle - startAngle;
  7902. this.addData(CMD.A, cx, cy, r, r, startAngle, delta, 0, anticlockwise ? 0 : 1);
  7903. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  7904. this._xi = mathCos$1(endAngle) * r + cx;
  7905. this._yi = mathSin$1(endAngle) * r + cy;
  7906. return this;
  7907. };
  7908. PathProxy.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  7909. this._drawPendingPt();
  7910. if (this._ctx) {
  7911. this._ctx.arcTo(x1, y1, x2, y2, radius);
  7912. }
  7913. return this;
  7914. };
  7915. PathProxy.prototype.rect = function (x, y, w, h) {
  7916. this._drawPendingPt();
  7917. this._ctx && this._ctx.rect(x, y, w, h);
  7918. this.addData(CMD.R, x, y, w, h);
  7919. return this;
  7920. };
  7921. PathProxy.prototype.closePath = function () {
  7922. this._drawPendingPt();
  7923. this.addData(CMD.Z);
  7924. var ctx = this._ctx;
  7925. var x0 = this._x0;
  7926. var y0 = this._y0;
  7927. if (ctx) {
  7928. ctx.closePath();
  7929. }
  7930. this._xi = x0;
  7931. this._yi = y0;
  7932. return this;
  7933. };
  7934. PathProxy.prototype.fill = function (ctx) {
  7935. ctx && ctx.fill();
  7936. this.toStatic();
  7937. };
  7938. PathProxy.prototype.stroke = function (ctx) {
  7939. ctx && ctx.stroke();
  7940. this.toStatic();
  7941. };
  7942. PathProxy.prototype.len = function () {
  7943. return this._len;
  7944. };
  7945. PathProxy.prototype.setData = function (data) {
  7946. var len = data.length;
  7947. if (!(this.data && this.data.length === len) && hasTypedArray) {
  7948. this.data = new Float32Array(len);
  7949. }
  7950. for (var i = 0; i < len; i++) {
  7951. this.data[i] = data[i];
  7952. }
  7953. this._len = len;
  7954. };
  7955. PathProxy.prototype.appendPath = function (path) {
  7956. if (!(path instanceof Array)) {
  7957. path = [path];
  7958. }
  7959. var len = path.length;
  7960. var appendSize = 0;
  7961. var offset = this._len;
  7962. for (var i = 0; i < len; i++) {
  7963. appendSize += path[i].len();
  7964. }
  7965. if (hasTypedArray && (this.data instanceof Float32Array)) {
  7966. this.data = new Float32Array(offset + appendSize);
  7967. }
  7968. for (var i = 0; i < len; i++) {
  7969. var appendPathData = path[i].data;
  7970. for (var k = 0; k < appendPathData.length; k++) {
  7971. this.data[offset++] = appendPathData[k];
  7972. }
  7973. }
  7974. this._len = offset;
  7975. };
  7976. PathProxy.prototype.addData = function (cmd, a, b, c, d, e, f, g, h) {
  7977. if (!this._saveData) {
  7978. return;
  7979. }
  7980. var data = this.data;
  7981. if (this._len + arguments.length > data.length) {
  7982. this._expandData();
  7983. data = this.data;
  7984. }
  7985. for (var i = 0; i < arguments.length; i++) {
  7986. data[this._len++] = arguments[i];
  7987. }
  7988. };
  7989. PathProxy.prototype._drawPendingPt = function () {
  7990. if (this._pendingPtDist > 0) {
  7991. this._ctx && this._ctx.lineTo(this._pendingPtX, this._pendingPtY);
  7992. this._pendingPtDist = 0;
  7993. }
  7994. };
  7995. PathProxy.prototype._expandData = function () {
  7996. if (!(this.data instanceof Array)) {
  7997. var newData = [];
  7998. for (var i = 0; i < this._len; i++) {
  7999. newData[i] = this.data[i];
  8000. }
  8001. this.data = newData;
  8002. }
  8003. };
  8004. PathProxy.prototype.toStatic = function () {
  8005. if (!this._saveData) {
  8006. return;
  8007. }
  8008. this._drawPendingPt();
  8009. var data = this.data;
  8010. if (data instanceof Array) {
  8011. data.length = this._len;
  8012. if (hasTypedArray && this._len > 11) {
  8013. this.data = new Float32Array(data);
  8014. }
  8015. }
  8016. };
  8017. PathProxy.prototype.getBoundingRect = function () {
  8018. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  8019. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  8020. var data = this.data;
  8021. var xi = 0;
  8022. var yi = 0;
  8023. var x0 = 0;
  8024. var y0 = 0;
  8025. var i;
  8026. for (i = 0; i < this._len;) {
  8027. var cmd = data[i++];
  8028. var isFirst = i === 1;
  8029. if (isFirst) {
  8030. xi = data[i];
  8031. yi = data[i + 1];
  8032. x0 = xi;
  8033. y0 = yi;
  8034. }
  8035. switch (cmd) {
  8036. case CMD.M:
  8037. xi = x0 = data[i++];
  8038. yi = y0 = data[i++];
  8039. min2[0] = x0;
  8040. min2[1] = y0;
  8041. max2[0] = x0;
  8042. max2[1] = y0;
  8043. break;
  8044. case CMD.L:
  8045. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  8046. xi = data[i++];
  8047. yi = data[i++];
  8048. break;
  8049. case CMD.C:
  8050. fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  8051. xi = data[i++];
  8052. yi = data[i++];
  8053. break;
  8054. case CMD.Q:
  8055. fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  8056. xi = data[i++];
  8057. yi = data[i++];
  8058. break;
  8059. case CMD.A:
  8060. var cx = data[i++];
  8061. var cy = data[i++];
  8062. var rx = data[i++];
  8063. var ry = data[i++];
  8064. var startAngle = data[i++];
  8065. var endAngle = data[i++] + startAngle;
  8066. i += 1;
  8067. var anticlockwise = !data[i++];
  8068. if (isFirst) {
  8069. x0 = mathCos$1(startAngle) * rx + cx;
  8070. y0 = mathSin$1(startAngle) * ry + cy;
  8071. }
  8072. fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  8073. xi = mathCos$1(endAngle) * rx + cx;
  8074. yi = mathSin$1(endAngle) * ry + cy;
  8075. break;
  8076. case CMD.R:
  8077. x0 = xi = data[i++];
  8078. y0 = yi = data[i++];
  8079. var width = data[i++];
  8080. var height = data[i++];
  8081. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  8082. break;
  8083. case CMD.Z:
  8084. xi = x0;
  8085. yi = y0;
  8086. break;
  8087. }
  8088. min(min$1, min$1, min2);
  8089. max(max$1, max$1, max2);
  8090. }
  8091. if (i === 0) {
  8092. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  8093. }
  8094. return new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  8095. };
  8096. PathProxy.prototype._calculateLength = function () {
  8097. var data = this.data;
  8098. var len = this._len;
  8099. var ux = this._ux;
  8100. var uy = this._uy;
  8101. var xi = 0;
  8102. var yi = 0;
  8103. var x0 = 0;
  8104. var y0 = 0;
  8105. if (!this._pathSegLen) {
  8106. this._pathSegLen = [];
  8107. }
  8108. var pathSegLen = this._pathSegLen;
  8109. var pathTotalLen = 0;
  8110. var segCount = 0;
  8111. for (var i = 0; i < len;) {
  8112. var cmd = data[i++];
  8113. var isFirst = i === 1;
  8114. if (isFirst) {
  8115. xi = data[i];
  8116. yi = data[i + 1];
  8117. x0 = xi;
  8118. y0 = yi;
  8119. }
  8120. var l = -1;
  8121. switch (cmd) {
  8122. case CMD.M:
  8123. xi = x0 = data[i++];
  8124. yi = y0 = data[i++];
  8125. break;
  8126. case CMD.L: {
  8127. var x2 = data[i++];
  8128. var y2 = data[i++];
  8129. var dx = x2 - xi;
  8130. var dy = y2 - yi;
  8131. if (mathAbs(dx) > ux || mathAbs(dy) > uy || i === len - 1) {
  8132. l = Math.sqrt(dx * dx + dy * dy);
  8133. xi = x2;
  8134. yi = y2;
  8135. }
  8136. break;
  8137. }
  8138. case CMD.C: {
  8139. var x1 = data[i++];
  8140. var y1 = data[i++];
  8141. var x2 = data[i++];
  8142. var y2 = data[i++];
  8143. var x3 = data[i++];
  8144. var y3 = data[i++];
  8145. l = cubicLength(xi, yi, x1, y1, x2, y2, x3, y3, 10);
  8146. xi = x3;
  8147. yi = y3;
  8148. break;
  8149. }
  8150. case CMD.Q: {
  8151. var x1 = data[i++];
  8152. var y1 = data[i++];
  8153. var x2 = data[i++];
  8154. var y2 = data[i++];
  8155. l = quadraticLength(xi, yi, x1, y1, x2, y2, 10);
  8156. xi = x2;
  8157. yi = y2;
  8158. break;
  8159. }
  8160. case CMD.A:
  8161. var cx = data[i++];
  8162. var cy = data[i++];
  8163. var rx = data[i++];
  8164. var ry = data[i++];
  8165. var startAngle = data[i++];
  8166. var delta = data[i++];
  8167. var endAngle = delta + startAngle;
  8168. i += 1;
  8169. if (isFirst) {
  8170. x0 = mathCos$1(startAngle) * rx + cx;
  8171. y0 = mathSin$1(startAngle) * ry + cy;
  8172. }
  8173. l = mathMax$2(rx, ry) * mathMin$2(PI2$1, Math.abs(delta));
  8174. xi = mathCos$1(endAngle) * rx + cx;
  8175. yi = mathSin$1(endAngle) * ry + cy;
  8176. break;
  8177. case CMD.R: {
  8178. x0 = xi = data[i++];
  8179. y0 = yi = data[i++];
  8180. var width = data[i++];
  8181. var height = data[i++];
  8182. l = width * 2 + height * 2;
  8183. break;
  8184. }
  8185. case CMD.Z: {
  8186. var dx = x0 - xi;
  8187. var dy = y0 - yi;
  8188. l = Math.sqrt(dx * dx + dy * dy);
  8189. xi = x0;
  8190. yi = y0;
  8191. break;
  8192. }
  8193. }
  8194. if (l >= 0) {
  8195. pathSegLen[segCount++] = l;
  8196. pathTotalLen += l;
  8197. }
  8198. }
  8199. this._pathLen = pathTotalLen;
  8200. return pathTotalLen;
  8201. };
  8202. PathProxy.prototype.rebuildPath = function (ctx, percent) {
  8203. var d = this.data;
  8204. var ux = this._ux;
  8205. var uy = this._uy;
  8206. var len = this._len;
  8207. var x0;
  8208. var y0;
  8209. var xi;
  8210. var yi;
  8211. var x;
  8212. var y;
  8213. var drawPart = percent < 1;
  8214. var pathSegLen;
  8215. var pathTotalLen;
  8216. var accumLength = 0;
  8217. var segCount = 0;
  8218. var displayedLength;
  8219. var pendingPtDist = 0;
  8220. var pendingPtX;
  8221. var pendingPtY;
  8222. if (drawPart) {
  8223. if (!this._pathSegLen) {
  8224. this._calculateLength();
  8225. }
  8226. pathSegLen = this._pathSegLen;
  8227. pathTotalLen = this._pathLen;
  8228. displayedLength = percent * pathTotalLen;
  8229. if (!displayedLength) {
  8230. return;
  8231. }
  8232. }
  8233. lo: for (var i = 0; i < len;) {
  8234. var cmd = d[i++];
  8235. var isFirst = i === 1;
  8236. if (isFirst) {
  8237. xi = d[i];
  8238. yi = d[i + 1];
  8239. x0 = xi;
  8240. y0 = yi;
  8241. }
  8242. if (cmd !== CMD.L && pendingPtDist > 0) {
  8243. ctx.lineTo(pendingPtX, pendingPtY);
  8244. pendingPtDist = 0;
  8245. }
  8246. switch (cmd) {
  8247. case CMD.M:
  8248. x0 = xi = d[i++];
  8249. y0 = yi = d[i++];
  8250. ctx.moveTo(xi, yi);
  8251. break;
  8252. case CMD.L: {
  8253. x = d[i++];
  8254. y = d[i++];
  8255. var dx = mathAbs(x - xi);
  8256. var dy = mathAbs(y - yi);
  8257. if (dx > ux || dy > uy) {
  8258. if (drawPart) {
  8259. var l = pathSegLen[segCount++];
  8260. if (accumLength + l > displayedLength) {
  8261. var t = (displayedLength - accumLength) / l;
  8262. ctx.lineTo(xi * (1 - t) + x * t, yi * (1 - t) + y * t);
  8263. break lo;
  8264. }
  8265. accumLength += l;
  8266. }
  8267. ctx.lineTo(x, y);
  8268. xi = x;
  8269. yi = y;
  8270. pendingPtDist = 0;
  8271. }
  8272. else {
  8273. var d2 = dx * dx + dy * dy;
  8274. if (d2 > pendingPtDist) {
  8275. pendingPtX = x;
  8276. pendingPtY = y;
  8277. pendingPtDist = d2;
  8278. }
  8279. }
  8280. break;
  8281. }
  8282. case CMD.C: {
  8283. var x1 = d[i++];
  8284. var y1 = d[i++];
  8285. var x2 = d[i++];
  8286. var y2 = d[i++];
  8287. var x3 = d[i++];
  8288. var y3 = d[i++];
  8289. if (drawPart) {
  8290. var l = pathSegLen[segCount++];
  8291. if (accumLength + l > displayedLength) {
  8292. var t = (displayedLength - accumLength) / l;
  8293. cubicSubdivide(xi, x1, x2, x3, t, tmpOutX);
  8294. cubicSubdivide(yi, y1, y2, y3, t, tmpOutY);
  8295. ctx.bezierCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2], tmpOutX[3], tmpOutY[3]);
  8296. break lo;
  8297. }
  8298. accumLength += l;
  8299. }
  8300. ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  8301. xi = x3;
  8302. yi = y3;
  8303. break;
  8304. }
  8305. case CMD.Q: {
  8306. var x1 = d[i++];
  8307. var y1 = d[i++];
  8308. var x2 = d[i++];
  8309. var y2 = d[i++];
  8310. if (drawPart) {
  8311. var l = pathSegLen[segCount++];
  8312. if (accumLength + l > displayedLength) {
  8313. var t = (displayedLength - accumLength) / l;
  8314. quadraticSubdivide(xi, x1, x2, t, tmpOutX);
  8315. quadraticSubdivide(yi, y1, y2, t, tmpOutY);
  8316. ctx.quadraticCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2]);
  8317. break lo;
  8318. }
  8319. accumLength += l;
  8320. }
  8321. ctx.quadraticCurveTo(x1, y1, x2, y2);
  8322. xi = x2;
  8323. yi = y2;
  8324. break;
  8325. }
  8326. case CMD.A:
  8327. var cx = d[i++];
  8328. var cy = d[i++];
  8329. var rx = d[i++];
  8330. var ry = d[i++];
  8331. var startAngle = d[i++];
  8332. var delta = d[i++];
  8333. var psi = d[i++];
  8334. var anticlockwise = !d[i++];
  8335. var r = (rx > ry) ? rx : ry;
  8336. var isEllipse = mathAbs(rx - ry) > 1e-3;
  8337. var endAngle = startAngle + delta;
  8338. var breakBuild = false;
  8339. if (drawPart) {
  8340. var l = pathSegLen[segCount++];
  8341. if (accumLength + l > displayedLength) {
  8342. endAngle = startAngle + delta * (displayedLength - accumLength) / l;
  8343. breakBuild = true;
  8344. }
  8345. accumLength += l;
  8346. }
  8347. if (isEllipse && ctx.ellipse) {
  8348. ctx.ellipse(cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise);
  8349. }
  8350. else {
  8351. ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  8352. }
  8353. if (breakBuild) {
  8354. break lo;
  8355. }
  8356. if (isFirst) {
  8357. x0 = mathCos$1(startAngle) * rx + cx;
  8358. y0 = mathSin$1(startAngle) * ry + cy;
  8359. }
  8360. xi = mathCos$1(endAngle) * rx + cx;
  8361. yi = mathSin$1(endAngle) * ry + cy;
  8362. break;
  8363. case CMD.R:
  8364. x0 = xi = d[i];
  8365. y0 = yi = d[i + 1];
  8366. x = d[i++];
  8367. y = d[i++];
  8368. var width = d[i++];
  8369. var height = d[i++];
  8370. if (drawPart) {
  8371. var l = pathSegLen[segCount++];
  8372. if (accumLength + l > displayedLength) {
  8373. var d_1 = displayedLength - accumLength;
  8374. ctx.moveTo(x, y);
  8375. ctx.lineTo(x + mathMin$2(d_1, width), y);
  8376. d_1 -= width;
  8377. if (d_1 > 0) {
  8378. ctx.lineTo(x + width, y + mathMin$2(d_1, height));
  8379. }
  8380. d_1 -= height;
  8381. if (d_1 > 0) {
  8382. ctx.lineTo(x + mathMax$2(width - d_1, 0), y + height);
  8383. }
  8384. d_1 -= width;
  8385. if (d_1 > 0) {
  8386. ctx.lineTo(x, y + mathMax$2(height - d_1, 0));
  8387. }
  8388. break lo;
  8389. }
  8390. accumLength += l;
  8391. }
  8392. ctx.rect(x, y, width, height);
  8393. break;
  8394. case CMD.Z:
  8395. if (drawPart) {
  8396. var l = pathSegLen[segCount++];
  8397. if (accumLength + l > displayedLength) {
  8398. var t = (displayedLength - accumLength) / l;
  8399. ctx.lineTo(xi * (1 - t) + x0 * t, yi * (1 - t) + y0 * t);
  8400. break lo;
  8401. }
  8402. accumLength += l;
  8403. }
  8404. ctx.closePath();
  8405. xi = x0;
  8406. yi = y0;
  8407. }
  8408. }
  8409. };
  8410. PathProxy.prototype.clone = function () {
  8411. var newProxy = new PathProxy();
  8412. var data = this.data;
  8413. newProxy.data = data.slice ? data.slice()
  8414. : Array.prototype.slice.call(data);
  8415. newProxy._len = this._len;
  8416. return newProxy;
  8417. };
  8418. PathProxy.CMD = CMD;
  8419. PathProxy.initDefaultProps = (function () {
  8420. var proto = PathProxy.prototype;
  8421. proto._saveData = true;
  8422. proto._ux = 0;
  8423. proto._uy = 0;
  8424. proto._pendingPtDist = 0;
  8425. proto._version = 0;
  8426. })();
  8427. return PathProxy;
  8428. }());
  8429. function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
  8430. if (lineWidth === 0) {
  8431. return false;
  8432. }
  8433. var _l = lineWidth;
  8434. var _a = 0;
  8435. var _b = x0;
  8436. if ((y > y0 + _l && y > y1 + _l)
  8437. || (y < y0 - _l && y < y1 - _l)
  8438. || (x > x0 + _l && x > x1 + _l)
  8439. || (x < x0 - _l && x < x1 - _l)) {
  8440. return false;
  8441. }
  8442. if (x0 !== x1) {
  8443. _a = (y0 - y1) / (x0 - x1);
  8444. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  8445. }
  8446. else {
  8447. return Math.abs(x - x0) <= _l / 2;
  8448. }
  8449. var tmp = _a * x - y + _b;
  8450. var _s = tmp * tmp / (_a * _a + 1);
  8451. return _s <= _l / 2 * _l / 2;
  8452. }
  8453. function containStroke$1(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  8454. if (lineWidth === 0) {
  8455. return false;
  8456. }
  8457. var _l = lineWidth;
  8458. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  8459. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  8460. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  8461. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)) {
  8462. return false;
  8463. }
  8464. var d = cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  8465. return d <= _l / 2;
  8466. }
  8467. function containStroke$2(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  8468. if (lineWidth === 0) {
  8469. return false;
  8470. }
  8471. var _l = lineWidth;
  8472. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l)
  8473. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  8474. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  8475. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)) {
  8476. return false;
  8477. }
  8478. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  8479. return d <= _l / 2;
  8480. }
  8481. var PI2$2 = Math.PI * 2;
  8482. function normalizeRadian(angle) {
  8483. angle %= PI2$2;
  8484. if (angle < 0) {
  8485. angle += PI2$2;
  8486. }
  8487. return angle;
  8488. }
  8489. var PI2$3 = Math.PI * 2;
  8490. function containStroke$3(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  8491. if (lineWidth === 0) {
  8492. return false;
  8493. }
  8494. var _l = lineWidth;
  8495. x -= cx;
  8496. y -= cy;
  8497. var d = Math.sqrt(x * x + y * y);
  8498. if ((d - _l > r) || (d + _l < r)) {
  8499. return false;
  8500. }
  8501. if (Math.abs(startAngle - endAngle) % PI2$3 < 1e-4) {
  8502. return true;
  8503. }
  8504. if (anticlockwise) {
  8505. var tmp = startAngle;
  8506. startAngle = normalizeRadian(endAngle);
  8507. endAngle = normalizeRadian(tmp);
  8508. }
  8509. else {
  8510. startAngle = normalizeRadian(startAngle);
  8511. endAngle = normalizeRadian(endAngle);
  8512. }
  8513. if (startAngle > endAngle) {
  8514. endAngle += PI2$3;
  8515. }
  8516. var angle = Math.atan2(y, x);
  8517. if (angle < 0) {
  8518. angle += PI2$3;
  8519. }
  8520. return (angle >= startAngle && angle <= endAngle)
  8521. || (angle + PI2$3 >= startAngle && angle + PI2$3 <= endAngle);
  8522. }
  8523. function windingLine(x0, y0, x1, y1, x, y) {
  8524. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  8525. return 0;
  8526. }
  8527. if (y1 === y0) {
  8528. return 0;
  8529. }
  8530. var t = (y - y0) / (y1 - y0);
  8531. var dir = y1 < y0 ? 1 : -1;
  8532. if (t === 1 || t === 0) {
  8533. dir = y1 < y0 ? 0.5 : -0.5;
  8534. }
  8535. var x_ = t * (x1 - x0) + x0;
  8536. return x_ === x ? Infinity : x_ > x ? dir : 0;
  8537. }
  8538. var CMD$1 = PathProxy.CMD;
  8539. var PI2$4 = Math.PI * 2;
  8540. var EPSILON$3 = 1e-4;
  8541. function isAroundEqual(a, b) {
  8542. return Math.abs(a - b) < EPSILON$3;
  8543. }
  8544. var roots = [-1, -1, -1];
  8545. var extrema = [-1, -1];
  8546. function swapExtrema() {
  8547. var tmp = extrema[0];
  8548. extrema[0] = extrema[1];
  8549. extrema[1] = tmp;
  8550. }
  8551. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  8552. if ((y > y0 && y > y1 && y > y2 && y > y3)
  8553. || (y < y0 && y < y1 && y < y2 && y < y3)) {
  8554. return 0;
  8555. }
  8556. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  8557. if (nRoots === 0) {
  8558. return 0;
  8559. }
  8560. else {
  8561. var w = 0;
  8562. var nExtrema = -1;
  8563. var y0_ = void 0;
  8564. var y1_ = void 0;
  8565. for (var i = 0; i < nRoots; i++) {
  8566. var t = roots[i];
  8567. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  8568. var x_ = cubicAt(x0, x1, x2, x3, t);
  8569. if (x_ < x) {
  8570. continue;
  8571. }
  8572. if (nExtrema < 0) {
  8573. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  8574. if (extrema[1] < extrema[0] && nExtrema > 1) {
  8575. swapExtrema();
  8576. }
  8577. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  8578. if (nExtrema > 1) {
  8579. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  8580. }
  8581. }
  8582. if (nExtrema === 2) {
  8583. if (t < extrema[0]) {
  8584. w += y0_ < y0 ? unit : -unit;
  8585. }
  8586. else if (t < extrema[1]) {
  8587. w += y1_ < y0_ ? unit : -unit;
  8588. }
  8589. else {
  8590. w += y3 < y1_ ? unit : -unit;
  8591. }
  8592. }
  8593. else {
  8594. if (t < extrema[0]) {
  8595. w += y0_ < y0 ? unit : -unit;
  8596. }
  8597. else {
  8598. w += y3 < y0_ ? unit : -unit;
  8599. }
  8600. }
  8601. }
  8602. return w;
  8603. }
  8604. }
  8605. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  8606. if ((y > y0 && y > y1 && y > y2)
  8607. || (y < y0 && y < y1 && y < y2)) {
  8608. return 0;
  8609. }
  8610. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  8611. if (nRoots === 0) {
  8612. return 0;
  8613. }
  8614. else {
  8615. var t = quadraticExtremum(y0, y1, y2);
  8616. if (t >= 0 && t <= 1) {
  8617. var w = 0;
  8618. var y_ = quadraticAt(y0, y1, y2, t);
  8619. for (var i = 0; i < nRoots; i++) {
  8620. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  8621. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  8622. if (x_ < x) {
  8623. continue;
  8624. }
  8625. if (roots[i] < t) {
  8626. w += y_ < y0 ? unit : -unit;
  8627. }
  8628. else {
  8629. w += y2 < y_ ? unit : -unit;
  8630. }
  8631. }
  8632. return w;
  8633. }
  8634. else {
  8635. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  8636. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  8637. if (x_ < x) {
  8638. return 0;
  8639. }
  8640. return y2 < y0 ? unit : -unit;
  8641. }
  8642. }
  8643. }
  8644. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  8645. y -= cy;
  8646. if (y > r || y < -r) {
  8647. return 0;
  8648. }
  8649. var tmp = Math.sqrt(r * r - y * y);
  8650. roots[0] = -tmp;
  8651. roots[1] = tmp;
  8652. var dTheta = Math.abs(startAngle - endAngle);
  8653. if (dTheta < 1e-4) {
  8654. return 0;
  8655. }
  8656. if (dTheta >= PI2$4 - 1e-4) {
  8657. startAngle = 0;
  8658. endAngle = PI2$4;
  8659. var dir = anticlockwise ? 1 : -1;
  8660. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  8661. return dir;
  8662. }
  8663. else {
  8664. return 0;
  8665. }
  8666. }
  8667. if (startAngle > endAngle) {
  8668. var tmp_1 = startAngle;
  8669. startAngle = endAngle;
  8670. endAngle = tmp_1;
  8671. }
  8672. if (startAngle < 0) {
  8673. startAngle += PI2$4;
  8674. endAngle += PI2$4;
  8675. }
  8676. var w = 0;
  8677. for (var i = 0; i < 2; i++) {
  8678. var x_ = roots[i];
  8679. if (x_ + cx > x) {
  8680. var angle = Math.atan2(y, x_);
  8681. var dir = anticlockwise ? 1 : -1;
  8682. if (angle < 0) {
  8683. angle = PI2$4 + angle;
  8684. }
  8685. if ((angle >= startAngle && angle <= endAngle)
  8686. || (angle + PI2$4 >= startAngle && angle + PI2$4 <= endAngle)) {
  8687. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  8688. dir = -dir;
  8689. }
  8690. w += dir;
  8691. }
  8692. }
  8693. }
  8694. return w;
  8695. }
  8696. function containPath(path, lineWidth, isStroke, x, y) {
  8697. var data = path.data;
  8698. var len = path.len();
  8699. var w = 0;
  8700. var xi = 0;
  8701. var yi = 0;
  8702. var x0 = 0;
  8703. var y0 = 0;
  8704. var x1;
  8705. var y1;
  8706. for (var i = 0; i < len;) {
  8707. var cmd = data[i++];
  8708. var isFirst = i === 1;
  8709. if (cmd === CMD$1.M && i > 1) {
  8710. if (!isStroke) {
  8711. w += windingLine(xi, yi, x0, y0, x, y);
  8712. }
  8713. }
  8714. if (isFirst) {
  8715. xi = data[i];
  8716. yi = data[i + 1];
  8717. x0 = xi;
  8718. y0 = yi;
  8719. }
  8720. switch (cmd) {
  8721. case CMD$1.M:
  8722. x0 = data[i++];
  8723. y0 = data[i++];
  8724. xi = x0;
  8725. yi = y0;
  8726. break;
  8727. case CMD$1.L:
  8728. if (isStroke) {
  8729. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  8730. return true;
  8731. }
  8732. }
  8733. else {
  8734. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  8735. }
  8736. xi = data[i++];
  8737. yi = data[i++];
  8738. break;
  8739. case CMD$1.C:
  8740. if (isStroke) {
  8741. if (containStroke$1(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8742. return true;
  8743. }
  8744. }
  8745. else {
  8746. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8747. }
  8748. xi = data[i++];
  8749. yi = data[i++];
  8750. break;
  8751. case CMD$1.Q:
  8752. if (isStroke) {
  8753. if (containStroke$2(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8754. return true;
  8755. }
  8756. }
  8757. else {
  8758. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8759. }
  8760. xi = data[i++];
  8761. yi = data[i++];
  8762. break;
  8763. case CMD$1.A:
  8764. var cx = data[i++];
  8765. var cy = data[i++];
  8766. var rx = data[i++];
  8767. var ry = data[i++];
  8768. var theta = data[i++];
  8769. var dTheta = data[i++];
  8770. i += 1;
  8771. var anticlockwise = !!(1 - data[i++]);
  8772. x1 = Math.cos(theta) * rx + cx;
  8773. y1 = Math.sin(theta) * ry + cy;
  8774. if (!isFirst) {
  8775. w += windingLine(xi, yi, x1, y1, x, y);
  8776. }
  8777. else {
  8778. x0 = x1;
  8779. y0 = y1;
  8780. }
  8781. var _x = (x - cx) * ry / rx + cx;
  8782. if (isStroke) {
  8783. if (containStroke$3(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  8784. return true;
  8785. }
  8786. }
  8787. else {
  8788. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  8789. }
  8790. xi = Math.cos(theta + dTheta) * rx + cx;
  8791. yi = Math.sin(theta + dTheta) * ry + cy;
  8792. break;
  8793. case CMD$1.R:
  8794. x0 = xi = data[i++];
  8795. y0 = yi = data[i++];
  8796. var width = data[i++];
  8797. var height = data[i++];
  8798. x1 = x0 + width;
  8799. y1 = y0 + height;
  8800. if (isStroke) {
  8801. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  8802. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  8803. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  8804. || containStroke(x0, y1, x0, y0, lineWidth, x, y)) {
  8805. return true;
  8806. }
  8807. }
  8808. else {
  8809. w += windingLine(x1, y0, x1, y1, x, y);
  8810. w += windingLine(x0, y1, x0, y0, x, y);
  8811. }
  8812. break;
  8813. case CMD$1.Z:
  8814. if (isStroke) {
  8815. if (containStroke(xi, yi, x0, y0, lineWidth, x, y)) {
  8816. return true;
  8817. }
  8818. }
  8819. else {
  8820. w += windingLine(xi, yi, x0, y0, x, y);
  8821. }
  8822. xi = x0;
  8823. yi = y0;
  8824. break;
  8825. }
  8826. }
  8827. if (!isStroke && !isAroundEqual(yi, y0)) {
  8828. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  8829. }
  8830. return w !== 0;
  8831. }
  8832. function contain(pathProxy, x, y) {
  8833. return containPath(pathProxy, 0, false, x, y);
  8834. }
  8835. function containStroke$4(pathProxy, lineWidth, x, y) {
  8836. return containPath(pathProxy, lineWidth, true, x, y);
  8837. }
  8838. var DEFAULT_PATH_STYLE = defaults({
  8839. fill: '#000',
  8840. stroke: null,
  8841. strokePercent: 1,
  8842. fillOpacity: 1,
  8843. strokeOpacity: 1,
  8844. lineDashOffset: 0,
  8845. lineWidth: 1,
  8846. lineCap: 'butt',
  8847. miterLimit: 10,
  8848. strokeNoScale: false,
  8849. strokeFirst: false
  8850. }, DEFAULT_COMMON_STYLE);
  8851. var DEFAULT_PATH_ANIMATION_PROPS = {
  8852. style: defaults({
  8853. fill: true,
  8854. stroke: true,
  8855. strokePercent: true,
  8856. fillOpacity: true,
  8857. strokeOpacity: true,
  8858. lineDashOffset: true,
  8859. lineWidth: true,
  8860. miterLimit: true
  8861. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  8862. };
  8863. var pathCopyParams = TRANSFORMABLE_PROPS.concat(['invisible',
  8864. 'culling', 'z', 'z2', 'zlevel', 'parent'
  8865. ]);
  8866. var Path = (function (_super) {
  8867. __extends(Path, _super);
  8868. function Path(opts) {
  8869. return _super.call(this, opts) || this;
  8870. }
  8871. Path.prototype.update = function () {
  8872. var _this = this;
  8873. _super.prototype.update.call(this);
  8874. var style = this.style;
  8875. if (style.decal) {
  8876. var decalEl = this._decalEl = this._decalEl || new Path();
  8877. if (decalEl.buildPath === Path.prototype.buildPath) {
  8878. decalEl.buildPath = function (ctx) {
  8879. _this.buildPath(ctx, _this.shape);
  8880. };
  8881. }
  8882. decalEl.silent = true;
  8883. var decalElStyle = decalEl.style;
  8884. for (var key in style) {
  8885. if (decalElStyle[key] !== style[key]) {
  8886. decalElStyle[key] = style[key];
  8887. }
  8888. }
  8889. decalElStyle.fill = style.fill ? style.decal : null;
  8890. decalElStyle.decal = null;
  8891. decalElStyle.shadowColor = null;
  8892. style.strokeFirst && (decalElStyle.stroke = null);
  8893. for (var i = 0; i < pathCopyParams.length; ++i) {
  8894. decalEl[pathCopyParams[i]] = this[pathCopyParams[i]];
  8895. }
  8896. decalEl.__dirty |= REDRAW_BIT;
  8897. }
  8898. else if (this._decalEl) {
  8899. this._decalEl = null;
  8900. }
  8901. };
  8902. Path.prototype.getDecalElement = function () {
  8903. return this._decalEl;
  8904. };
  8905. Path.prototype._init = function (props) {
  8906. var keysArr = keys(props);
  8907. this.shape = this.getDefaultShape();
  8908. var defaultStyle = this.getDefaultStyle();
  8909. if (defaultStyle) {
  8910. this.useStyle(defaultStyle);
  8911. }
  8912. for (var i = 0; i < keysArr.length; i++) {
  8913. var key = keysArr[i];
  8914. var value = props[key];
  8915. if (key === 'style') {
  8916. if (!this.style) {
  8917. this.useStyle(value);
  8918. }
  8919. else {
  8920. extend(this.style, value);
  8921. }
  8922. }
  8923. else if (key === 'shape') {
  8924. extend(this.shape, value);
  8925. }
  8926. else {
  8927. _super.prototype.attrKV.call(this, key, value);
  8928. }
  8929. }
  8930. if (!this.style) {
  8931. this.useStyle({});
  8932. }
  8933. };
  8934. Path.prototype.getDefaultStyle = function () {
  8935. return null;
  8936. };
  8937. Path.prototype.getDefaultShape = function () {
  8938. return {};
  8939. };
  8940. Path.prototype.canBeInsideText = function () {
  8941. return this.hasFill();
  8942. };
  8943. Path.prototype.getInsideTextFill = function () {
  8944. var pathFill = this.style.fill;
  8945. if (pathFill !== 'none') {
  8946. if (isString(pathFill)) {
  8947. var fillLum = lum(pathFill, 0);
  8948. if (fillLum > 0.5) {
  8949. return DARK_LABEL_COLOR;
  8950. }
  8951. else if (fillLum > 0.2) {
  8952. return LIGHTER_LABEL_COLOR;
  8953. }
  8954. return LIGHT_LABEL_COLOR;
  8955. }
  8956. else if (pathFill) {
  8957. return LIGHT_LABEL_COLOR;
  8958. }
  8959. }
  8960. return DARK_LABEL_COLOR;
  8961. };
  8962. Path.prototype.getInsideTextStroke = function (textFill) {
  8963. var pathFill = this.style.fill;
  8964. if (isString(pathFill)) {
  8965. var zr = this.__zr;
  8966. var isDarkMode = !!(zr && zr.isDarkMode());
  8967. var isDarkLabel = lum(textFill, 0) < DARK_MODE_THRESHOLD;
  8968. if (isDarkMode === isDarkLabel) {
  8969. return pathFill;
  8970. }
  8971. }
  8972. };
  8973. Path.prototype.buildPath = function (ctx, shapeCfg, inBatch) { };
  8974. Path.prototype.pathUpdated = function () {
  8975. this.__dirty &= ~SHAPE_CHANGED_BIT;
  8976. };
  8977. Path.prototype.getUpdatedPathProxy = function (inBatch) {
  8978. !this.path && this.createPathProxy();
  8979. this.path.beginPath();
  8980. this.buildPath(this.path, this.shape, inBatch);
  8981. return this.path;
  8982. };
  8983. Path.prototype.createPathProxy = function () {
  8984. this.path = new PathProxy(false);
  8985. };
  8986. Path.prototype.hasStroke = function () {
  8987. var style = this.style;
  8988. var stroke = style.stroke;
  8989. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  8990. };
  8991. Path.prototype.hasFill = function () {
  8992. var style = this.style;
  8993. var fill = style.fill;
  8994. return fill != null && fill !== 'none';
  8995. };
  8996. Path.prototype.getBoundingRect = function () {
  8997. var rect = this._rect;
  8998. var style = this.style;
  8999. var needsUpdateRect = !rect;
  9000. if (needsUpdateRect) {
  9001. var firstInvoke = false;
  9002. if (!this.path) {
  9003. firstInvoke = true;
  9004. this.createPathProxy();
  9005. }
  9006. var path = this.path;
  9007. if (firstInvoke || (this.__dirty & SHAPE_CHANGED_BIT)) {
  9008. path.beginPath();
  9009. this.buildPath(path, this.shape, false);
  9010. this.pathUpdated();
  9011. }
  9012. rect = path.getBoundingRect();
  9013. }
  9014. this._rect = rect;
  9015. if (this.hasStroke() && this.path && this.path.len() > 0) {
  9016. var rectStroke = this._rectStroke || (this._rectStroke = rect.clone());
  9017. if (this.__dirty || needsUpdateRect) {
  9018. rectStroke.copy(rect);
  9019. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  9020. var w = style.lineWidth;
  9021. if (!this.hasFill()) {
  9022. var strokeContainThreshold = this.strokeContainThreshold;
  9023. w = Math.max(w, strokeContainThreshold == null ? 4 : strokeContainThreshold);
  9024. }
  9025. if (lineScale > 1e-10) {
  9026. rectStroke.width += w / lineScale;
  9027. rectStroke.height += w / lineScale;
  9028. rectStroke.x -= w / lineScale / 2;
  9029. rectStroke.y -= w / lineScale / 2;
  9030. }
  9031. }
  9032. return rectStroke;
  9033. }
  9034. return rect;
  9035. };
  9036. Path.prototype.contain = function (x, y) {
  9037. var localPos = this.transformCoordToLocal(x, y);
  9038. var rect = this.getBoundingRect();
  9039. var style = this.style;
  9040. x = localPos[0];
  9041. y = localPos[1];
  9042. if (rect.contain(x, y)) {
  9043. var pathProxy = this.path;
  9044. if (this.hasStroke()) {
  9045. var lineWidth = style.lineWidth;
  9046. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  9047. if (lineScale > 1e-10) {
  9048. if (!this.hasFill()) {
  9049. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  9050. }
  9051. if (containStroke$4(pathProxy, lineWidth / lineScale, x, y)) {
  9052. return true;
  9053. }
  9054. }
  9055. }
  9056. if (this.hasFill()) {
  9057. return contain(pathProxy, x, y);
  9058. }
  9059. }
  9060. return false;
  9061. };
  9062. Path.prototype.dirtyShape = function () {
  9063. this.__dirty |= SHAPE_CHANGED_BIT;
  9064. if (this._rect) {
  9065. this._rect = null;
  9066. }
  9067. if (this._decalEl) {
  9068. this._decalEl.dirtyShape();
  9069. }
  9070. this.markRedraw();
  9071. };
  9072. Path.prototype.dirty = function () {
  9073. this.dirtyStyle();
  9074. this.dirtyShape();
  9075. };
  9076. Path.prototype.animateShape = function (loop) {
  9077. return this.animate('shape', loop);
  9078. };
  9079. Path.prototype.updateDuringAnimation = function (targetKey) {
  9080. if (targetKey === 'style') {
  9081. this.dirtyStyle();
  9082. }
  9083. else if (targetKey === 'shape') {
  9084. this.dirtyShape();
  9085. }
  9086. else {
  9087. this.markRedraw();
  9088. }
  9089. };
  9090. Path.prototype.attrKV = function (key, value) {
  9091. if (key === 'shape') {
  9092. this.setShape(value);
  9093. }
  9094. else {
  9095. _super.prototype.attrKV.call(this, key, value);
  9096. }
  9097. };
  9098. Path.prototype.setShape = function (keyOrObj, value) {
  9099. var shape = this.shape;
  9100. if (!shape) {
  9101. shape = this.shape = {};
  9102. }
  9103. if (typeof keyOrObj === 'string') {
  9104. shape[keyOrObj] = value;
  9105. }
  9106. else {
  9107. extend(shape, keyOrObj);
  9108. }
  9109. this.dirtyShape();
  9110. return this;
  9111. };
  9112. Path.prototype.shapeChanged = function () {
  9113. return !!(this.__dirty & SHAPE_CHANGED_BIT);
  9114. };
  9115. Path.prototype.createStyle = function (obj) {
  9116. return createObject(DEFAULT_PATH_STYLE, obj);
  9117. };
  9118. Path.prototype._innerSaveToNormal = function (toState) {
  9119. _super.prototype._innerSaveToNormal.call(this, toState);
  9120. var normalState = this._normalState;
  9121. if (toState.shape && !normalState.shape) {
  9122. normalState.shape = extend({}, this.shape);
  9123. }
  9124. };
  9125. Path.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  9126. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  9127. var needsRestoreToNormal = !(state && keepCurrentStates);
  9128. var targetShape;
  9129. if (state && state.shape) {
  9130. if (transition) {
  9131. if (keepCurrentStates) {
  9132. targetShape = state.shape;
  9133. }
  9134. else {
  9135. targetShape = extend({}, normalState.shape);
  9136. extend(targetShape, state.shape);
  9137. }
  9138. }
  9139. else {
  9140. targetShape = extend({}, keepCurrentStates ? this.shape : normalState.shape);
  9141. extend(targetShape, state.shape);
  9142. }
  9143. }
  9144. else if (needsRestoreToNormal) {
  9145. targetShape = normalState.shape;
  9146. }
  9147. if (targetShape) {
  9148. if (transition) {
  9149. this.shape = extend({}, this.shape);
  9150. var targetShapePrimaryProps = {};
  9151. var shapeKeys = keys(targetShape);
  9152. for (var i = 0; i < shapeKeys.length; i++) {
  9153. var key = shapeKeys[i];
  9154. if (typeof targetShape[key] === 'object') {
  9155. this.shape[key] = targetShape[key];
  9156. }
  9157. else {
  9158. targetShapePrimaryProps[key] = targetShape[key];
  9159. }
  9160. }
  9161. this._transitionState(stateName, {
  9162. shape: targetShapePrimaryProps
  9163. }, animationCfg);
  9164. }
  9165. else {
  9166. this.shape = targetShape;
  9167. this.dirtyShape();
  9168. }
  9169. }
  9170. };
  9171. Path.prototype._mergeStates = function (states) {
  9172. var mergedState = _super.prototype._mergeStates.call(this, states);
  9173. var mergedShape;
  9174. for (var i = 0; i < states.length; i++) {
  9175. var state = states[i];
  9176. if (state.shape) {
  9177. mergedShape = mergedShape || {};
  9178. this._mergeStyle(mergedShape, state.shape);
  9179. }
  9180. }
  9181. if (mergedShape) {
  9182. mergedState.shape = mergedShape;
  9183. }
  9184. return mergedState;
  9185. };
  9186. Path.prototype.getAnimationStyleProps = function () {
  9187. return DEFAULT_PATH_ANIMATION_PROPS;
  9188. };
  9189. Path.prototype.isZeroArea = function () {
  9190. return false;
  9191. };
  9192. Path.extend = function (defaultProps) {
  9193. var Sub = (function (_super) {
  9194. __extends(Sub, _super);
  9195. function Sub(opts) {
  9196. var _this = _super.call(this, opts) || this;
  9197. defaultProps.init && defaultProps.init.call(_this, opts);
  9198. return _this;
  9199. }
  9200. Sub.prototype.getDefaultStyle = function () {
  9201. return clone(defaultProps.style);
  9202. };
  9203. Sub.prototype.getDefaultShape = function () {
  9204. return clone(defaultProps.shape);
  9205. };
  9206. return Sub;
  9207. }(Path));
  9208. for (var key in defaultProps) {
  9209. if (typeof defaultProps[key] === 'function') {
  9210. Sub.prototype[key] = defaultProps[key];
  9211. }
  9212. }
  9213. return Sub;
  9214. };
  9215. Path.initDefaultProps = (function () {
  9216. var pathProto = Path.prototype;
  9217. pathProto.type = 'path';
  9218. pathProto.strokeContainThreshold = 5;
  9219. pathProto.segmentIgnoreThreshold = 0;
  9220. pathProto.subPixelOptimize = false;
  9221. pathProto.autoBatch = false;
  9222. pathProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT | SHAPE_CHANGED_BIT;
  9223. })();
  9224. return Path;
  9225. }(Displayable));
  9226. var CMD$2 = PathProxy.CMD;
  9227. var points = [[], [], []];
  9228. var mathSqrt$1 = Math.sqrt;
  9229. var mathAtan2 = Math.atan2;
  9230. function transformPath(path, m) {
  9231. if (!m) {
  9232. return;
  9233. }
  9234. var data = path.data;
  9235. var len = path.len();
  9236. var cmd;
  9237. var nPoint;
  9238. var i;
  9239. var j;
  9240. var k;
  9241. var p;
  9242. var M = CMD$2.M;
  9243. var C = CMD$2.C;
  9244. var L = CMD$2.L;
  9245. var R = CMD$2.R;
  9246. var A = CMD$2.A;
  9247. var Q = CMD$2.Q;
  9248. for (i = 0, j = 0; i < len;) {
  9249. cmd = data[i++];
  9250. j = i;
  9251. nPoint = 0;
  9252. switch (cmd) {
  9253. case M:
  9254. nPoint = 1;
  9255. break;
  9256. case L:
  9257. nPoint = 1;
  9258. break;
  9259. case C:
  9260. nPoint = 3;
  9261. break;
  9262. case Q:
  9263. nPoint = 2;
  9264. break;
  9265. case A:
  9266. var x = m[4];
  9267. var y = m[5];
  9268. var sx = mathSqrt$1(m[0] * m[0] + m[1] * m[1]);
  9269. var sy = mathSqrt$1(m[2] * m[2] + m[3] * m[3]);
  9270. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  9271. data[i] *= sx;
  9272. data[i++] += x;
  9273. data[i] *= sy;
  9274. data[i++] += y;
  9275. data[i++] *= sx;
  9276. data[i++] *= sy;
  9277. data[i++] += angle;
  9278. data[i++] += angle;
  9279. i += 2;
  9280. j = i;
  9281. break;
  9282. case R:
  9283. p[0] = data[i++];
  9284. p[1] = data[i++];
  9285. applyTransform(p, p, m);
  9286. data[j++] = p[0];
  9287. data[j++] = p[1];
  9288. p[0] += data[i++];
  9289. p[1] += data[i++];
  9290. applyTransform(p, p, m);
  9291. data[j++] = p[0];
  9292. data[j++] = p[1];
  9293. }
  9294. for (k = 0; k < nPoint; k++) {
  9295. var p_1 = points[k];
  9296. p_1[0] = data[i++];
  9297. p_1[1] = data[i++];
  9298. applyTransform(p_1, p_1, m);
  9299. data[j++] = p_1[0];
  9300. data[j++] = p_1[1];
  9301. }
  9302. }
  9303. path.increaseVersion();
  9304. }
  9305. var mathSqrt$2 = Math.sqrt;
  9306. var mathSin$2 = Math.sin;
  9307. var mathCos$2 = Math.cos;
  9308. var PI$1 = Math.PI;
  9309. function vMag(v) {
  9310. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  9311. }
  9312. function vRatio(u, v) {
  9313. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  9314. }
  9315. function vAngle(u, v) {
  9316. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  9317. * Math.acos(vRatio(u, v));
  9318. }
  9319. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  9320. var psi = psiDeg * (PI$1 / 180.0);
  9321. var xp = mathCos$2(psi) * (x1 - x2) / 2.0
  9322. + mathSin$2(psi) * (y1 - y2) / 2.0;
  9323. var yp = -1 * mathSin$2(psi) * (x1 - x2) / 2.0
  9324. + mathCos$2(psi) * (y1 - y2) / 2.0;
  9325. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  9326. if (lambda > 1) {
  9327. rx *= mathSqrt$2(lambda);
  9328. ry *= mathSqrt$2(lambda);
  9329. }
  9330. var f = (fa === fs ? -1 : 1)
  9331. * mathSqrt$2((((rx * rx) * (ry * ry))
  9332. - ((rx * rx) * (yp * yp))
  9333. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  9334. + (ry * ry) * (xp * xp))) || 0;
  9335. var cxp = f * rx * yp / ry;
  9336. var cyp = f * -ry * xp / rx;
  9337. var cx = (x1 + x2) / 2.0
  9338. + mathCos$2(psi) * cxp
  9339. - mathSin$2(psi) * cyp;
  9340. var cy = (y1 + y2) / 2.0
  9341. + mathSin$2(psi) * cxp
  9342. + mathCos$2(psi) * cyp;
  9343. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  9344. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  9345. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  9346. var dTheta = vAngle(u, v);
  9347. if (vRatio(u, v) <= -1) {
  9348. dTheta = PI$1;
  9349. }
  9350. if (vRatio(u, v) >= 1) {
  9351. dTheta = 0;
  9352. }
  9353. if (dTheta < 0) {
  9354. var n = Math.round(dTheta / PI$1 * 1e6) / 1e6;
  9355. dTheta = PI$1 * 2 + (n % 2) * PI$1;
  9356. }
  9357. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  9358. }
  9359. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  9360. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  9361. function createPathProxyFromString(data) {
  9362. var path = new PathProxy();
  9363. if (!data) {
  9364. return path;
  9365. }
  9366. var cpx = 0;
  9367. var cpy = 0;
  9368. var subpathX = cpx;
  9369. var subpathY = cpy;
  9370. var prevCmd;
  9371. var CMD = PathProxy.CMD;
  9372. var cmdList = data.match(commandReg);
  9373. if (!cmdList) {
  9374. return path;
  9375. }
  9376. for (var l = 0; l < cmdList.length; l++) {
  9377. var cmdText = cmdList[l];
  9378. var cmdStr = cmdText.charAt(0);
  9379. var cmd = void 0;
  9380. var p = cmdText.match(numberReg) || [];
  9381. var pLen = p.length;
  9382. for (var i = 0; i < pLen; i++) {
  9383. p[i] = parseFloat(p[i]);
  9384. }
  9385. var off = 0;
  9386. while (off < pLen) {
  9387. var ctlPtx = void 0;
  9388. var ctlPty = void 0;
  9389. var rx = void 0;
  9390. var ry = void 0;
  9391. var psi = void 0;
  9392. var fa = void 0;
  9393. var fs = void 0;
  9394. var x1 = cpx;
  9395. var y1 = cpy;
  9396. var len = void 0;
  9397. var pathData = void 0;
  9398. switch (cmdStr) {
  9399. case 'l':
  9400. cpx += p[off++];
  9401. cpy += p[off++];
  9402. cmd = CMD.L;
  9403. path.addData(cmd, cpx, cpy);
  9404. break;
  9405. case 'L':
  9406. cpx = p[off++];
  9407. cpy = p[off++];
  9408. cmd = CMD.L;
  9409. path.addData(cmd, cpx, cpy);
  9410. break;
  9411. case 'm':
  9412. cpx += p[off++];
  9413. cpy += p[off++];
  9414. cmd = CMD.M;
  9415. path.addData(cmd, cpx, cpy);
  9416. subpathX = cpx;
  9417. subpathY = cpy;
  9418. cmdStr = 'l';
  9419. break;
  9420. case 'M':
  9421. cpx = p[off++];
  9422. cpy = p[off++];
  9423. cmd = CMD.M;
  9424. path.addData(cmd, cpx, cpy);
  9425. subpathX = cpx;
  9426. subpathY = cpy;
  9427. cmdStr = 'L';
  9428. break;
  9429. case 'h':
  9430. cpx += p[off++];
  9431. cmd = CMD.L;
  9432. path.addData(cmd, cpx, cpy);
  9433. break;
  9434. case 'H':
  9435. cpx = p[off++];
  9436. cmd = CMD.L;
  9437. path.addData(cmd, cpx, cpy);
  9438. break;
  9439. case 'v':
  9440. cpy += p[off++];
  9441. cmd = CMD.L;
  9442. path.addData(cmd, cpx, cpy);
  9443. break;
  9444. case 'V':
  9445. cpy = p[off++];
  9446. cmd = CMD.L;
  9447. path.addData(cmd, cpx, cpy);
  9448. break;
  9449. case 'C':
  9450. cmd = CMD.C;
  9451. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  9452. cpx = p[off - 2];
  9453. cpy = p[off - 1];
  9454. break;
  9455. case 'c':
  9456. cmd = CMD.C;
  9457. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  9458. cpx += p[off - 2];
  9459. cpy += p[off - 1];
  9460. break;
  9461. case 'S':
  9462. ctlPtx = cpx;
  9463. ctlPty = cpy;
  9464. len = path.len();
  9465. pathData = path.data;
  9466. if (prevCmd === CMD.C) {
  9467. ctlPtx += cpx - pathData[len - 4];
  9468. ctlPty += cpy - pathData[len - 3];
  9469. }
  9470. cmd = CMD.C;
  9471. x1 = p[off++];
  9472. y1 = p[off++];
  9473. cpx = p[off++];
  9474. cpy = p[off++];
  9475. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9476. break;
  9477. case 's':
  9478. ctlPtx = cpx;
  9479. ctlPty = cpy;
  9480. len = path.len();
  9481. pathData = path.data;
  9482. if (prevCmd === CMD.C) {
  9483. ctlPtx += cpx - pathData[len - 4];
  9484. ctlPty += cpy - pathData[len - 3];
  9485. }
  9486. cmd = CMD.C;
  9487. x1 = cpx + p[off++];
  9488. y1 = cpy + p[off++];
  9489. cpx += p[off++];
  9490. cpy += p[off++];
  9491. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9492. break;
  9493. case 'Q':
  9494. x1 = p[off++];
  9495. y1 = p[off++];
  9496. cpx = p[off++];
  9497. cpy = p[off++];
  9498. cmd = CMD.Q;
  9499. path.addData(cmd, x1, y1, cpx, cpy);
  9500. break;
  9501. case 'q':
  9502. x1 = p[off++] + cpx;
  9503. y1 = p[off++] + cpy;
  9504. cpx += p[off++];
  9505. cpy += p[off++];
  9506. cmd = CMD.Q;
  9507. path.addData(cmd, x1, y1, cpx, cpy);
  9508. break;
  9509. case 'T':
  9510. ctlPtx = cpx;
  9511. ctlPty = cpy;
  9512. len = path.len();
  9513. pathData = path.data;
  9514. if (prevCmd === CMD.Q) {
  9515. ctlPtx += cpx - pathData[len - 4];
  9516. ctlPty += cpy - pathData[len - 3];
  9517. }
  9518. cpx = p[off++];
  9519. cpy = p[off++];
  9520. cmd = CMD.Q;
  9521. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9522. break;
  9523. case 't':
  9524. ctlPtx = cpx;
  9525. ctlPty = cpy;
  9526. len = path.len();
  9527. pathData = path.data;
  9528. if (prevCmd === CMD.Q) {
  9529. ctlPtx += cpx - pathData[len - 4];
  9530. ctlPty += cpy - pathData[len - 3];
  9531. }
  9532. cpx += p[off++];
  9533. cpy += p[off++];
  9534. cmd = CMD.Q;
  9535. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9536. break;
  9537. case 'A':
  9538. rx = p[off++];
  9539. ry = p[off++];
  9540. psi = p[off++];
  9541. fa = p[off++];
  9542. fs = p[off++];
  9543. x1 = cpx, y1 = cpy;
  9544. cpx = p[off++];
  9545. cpy = p[off++];
  9546. cmd = CMD.A;
  9547. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9548. break;
  9549. case 'a':
  9550. rx = p[off++];
  9551. ry = p[off++];
  9552. psi = p[off++];
  9553. fa = p[off++];
  9554. fs = p[off++];
  9555. x1 = cpx, y1 = cpy;
  9556. cpx += p[off++];
  9557. cpy += p[off++];
  9558. cmd = CMD.A;
  9559. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9560. break;
  9561. }
  9562. }
  9563. if (cmdStr === 'z' || cmdStr === 'Z') {
  9564. cmd = CMD.Z;
  9565. path.addData(cmd);
  9566. cpx = subpathX;
  9567. cpy = subpathY;
  9568. }
  9569. prevCmd = cmd;
  9570. }
  9571. path.toStatic();
  9572. return path;
  9573. }
  9574. var SVGPath = (function (_super) {
  9575. __extends(SVGPath, _super);
  9576. function SVGPath() {
  9577. return _super !== null && _super.apply(this, arguments) || this;
  9578. }
  9579. SVGPath.prototype.applyTransform = function (m) { };
  9580. return SVGPath;
  9581. }(Path));
  9582. function isPathProxy(path) {
  9583. return path.setData != null;
  9584. }
  9585. function createPathOptions(str, opts) {
  9586. var pathProxy = createPathProxyFromString(str);
  9587. var innerOpts = extend({}, opts);
  9588. innerOpts.buildPath = function (path) {
  9589. if (isPathProxy(path)) {
  9590. path.setData(pathProxy.data);
  9591. var ctx = path.getContext();
  9592. if (ctx) {
  9593. path.rebuildPath(ctx, 1);
  9594. }
  9595. }
  9596. else {
  9597. var ctx = path;
  9598. pathProxy.rebuildPath(ctx, 1);
  9599. }
  9600. };
  9601. innerOpts.applyTransform = function (m) {
  9602. transformPath(pathProxy, m);
  9603. this.dirtyShape();
  9604. };
  9605. return innerOpts;
  9606. }
  9607. function createFromString(str, opts) {
  9608. return new SVGPath(createPathOptions(str, opts));
  9609. }
  9610. function extendFromString(str, defaultOpts) {
  9611. var innerOpts = createPathOptions(str, defaultOpts);
  9612. var Sub = (function (_super) {
  9613. __extends(Sub, _super);
  9614. function Sub(opts) {
  9615. var _this = _super.call(this, opts) || this;
  9616. _this.applyTransform = innerOpts.applyTransform;
  9617. _this.buildPath = innerOpts.buildPath;
  9618. return _this;
  9619. }
  9620. return Sub;
  9621. }(SVGPath));
  9622. return Sub;
  9623. }
  9624. function mergePath(pathEls, opts) {
  9625. var pathList = [];
  9626. var len = pathEls.length;
  9627. for (var i = 0; i < len; i++) {
  9628. var pathEl = pathEls[i];
  9629. pathList.push(pathEl.getUpdatedPathProxy(true));
  9630. }
  9631. var pathBundle = new Path(opts);
  9632. pathBundle.createPathProxy();
  9633. pathBundle.buildPath = function (path) {
  9634. if (isPathProxy(path)) {
  9635. path.appendPath(pathList);
  9636. var ctx = path.getContext();
  9637. if (ctx) {
  9638. path.rebuildPath(ctx, 1);
  9639. }
  9640. }
  9641. };
  9642. return pathBundle;
  9643. }
  9644. function clonePath(sourcePath, opts) {
  9645. opts = opts || {};
  9646. var path = new Path();
  9647. if (sourcePath.shape) {
  9648. path.setShape(sourcePath.shape);
  9649. }
  9650. path.setStyle(sourcePath.style);
  9651. if (opts.bakeTransform) {
  9652. transformPath(path.path, sourcePath.getComputedTransform());
  9653. }
  9654. else {
  9655. if (opts.toLocal) {
  9656. path.setLocalTransform(sourcePath.getComputedTransform());
  9657. }
  9658. else {
  9659. path.copyTransform(sourcePath);
  9660. }
  9661. }
  9662. path.buildPath = sourcePath.buildPath;
  9663. path.applyTransform = path.applyTransform;
  9664. path.z = sourcePath.z;
  9665. path.z2 = sourcePath.z2;
  9666. path.zlevel = sourcePath.zlevel;
  9667. return path;
  9668. }
  9669. var path = /*#__PURE__*/Object.freeze({
  9670. __proto__: null,
  9671. createFromString: createFromString,
  9672. extendFromString: extendFromString,
  9673. mergePath: mergePath,
  9674. clonePath: clonePath
  9675. });
  9676. var DEFAULT_IMAGE_STYLE = defaults({
  9677. x: 0,
  9678. y: 0
  9679. }, DEFAULT_COMMON_STYLE);
  9680. var DEFAULT_IMAGE_ANIMATION_PROPS = {
  9681. style: defaults({
  9682. x: true,
  9683. y: true,
  9684. width: true,
  9685. height: true,
  9686. sx: true,
  9687. sy: true,
  9688. sWidth: true,
  9689. sHeight: true
  9690. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  9691. };
  9692. function isImageLike(source) {
  9693. return !!(source
  9694. && typeof source !== 'string'
  9695. && source.width && source.height);
  9696. }
  9697. var ZRImage = (function (_super) {
  9698. __extends(ZRImage, _super);
  9699. function ZRImage() {
  9700. return _super !== null && _super.apply(this, arguments) || this;
  9701. }
  9702. ZRImage.prototype.createStyle = function (obj) {
  9703. return createObject(DEFAULT_IMAGE_STYLE, obj);
  9704. };
  9705. ZRImage.prototype._getSize = function (dim) {
  9706. var style = this.style;
  9707. var size = style[dim];
  9708. if (size != null) {
  9709. return size;
  9710. }
  9711. var imageSource = isImageLike(style.image)
  9712. ? style.image : this.__image;
  9713. if (!imageSource) {
  9714. return 0;
  9715. }
  9716. var otherDim = dim === 'width' ? 'height' : 'width';
  9717. var otherDimSize = style[otherDim];
  9718. if (otherDimSize == null) {
  9719. return imageSource[dim];
  9720. }
  9721. else {
  9722. return imageSource[dim] / imageSource[otherDim] * otherDimSize;
  9723. }
  9724. };
  9725. ZRImage.prototype.getWidth = function () {
  9726. return this._getSize('width');
  9727. };
  9728. ZRImage.prototype.getHeight = function () {
  9729. return this._getSize('height');
  9730. };
  9731. ZRImage.prototype.getAnimationStyleProps = function () {
  9732. return DEFAULT_IMAGE_ANIMATION_PROPS;
  9733. };
  9734. ZRImage.prototype.getBoundingRect = function () {
  9735. var style = this.style;
  9736. if (!this._rect) {
  9737. this._rect = new BoundingRect(style.x || 0, style.y || 0, this.getWidth(), this.getHeight());
  9738. }
  9739. return this._rect;
  9740. };
  9741. return ZRImage;
  9742. }(Displayable));
  9743. ZRImage.prototype.type = 'image';
  9744. var CircleShape = (function () {
  9745. function CircleShape() {
  9746. this.cx = 0;
  9747. this.cy = 0;
  9748. this.r = 0;
  9749. }
  9750. return CircleShape;
  9751. }());
  9752. var Circle = (function (_super) {
  9753. __extends(Circle, _super);
  9754. function Circle(opts) {
  9755. return _super.call(this, opts) || this;
  9756. }
  9757. Circle.prototype.getDefaultShape = function () {
  9758. return new CircleShape();
  9759. };
  9760. Circle.prototype.buildPath = function (ctx, shape) {
  9761. ctx.moveTo(shape.cx + shape.r, shape.cy);
  9762. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2);
  9763. };
  9764. return Circle;
  9765. }(Path));
  9766. Circle.prototype.type = 'circle';
  9767. function buildPath(ctx, shape) {
  9768. var x = shape.x;
  9769. var y = shape.y;
  9770. var width = shape.width;
  9771. var height = shape.height;
  9772. var r = shape.r;
  9773. var r1;
  9774. var r2;
  9775. var r3;
  9776. var r4;
  9777. if (width < 0) {
  9778. x = x + width;
  9779. width = -width;
  9780. }
  9781. if (height < 0) {
  9782. y = y + height;
  9783. height = -height;
  9784. }
  9785. if (typeof r === 'number') {
  9786. r1 = r2 = r3 = r4 = r;
  9787. }
  9788. else if (r instanceof Array) {
  9789. if (r.length === 1) {
  9790. r1 = r2 = r3 = r4 = r[0];
  9791. }
  9792. else if (r.length === 2) {
  9793. r1 = r3 = r[0];
  9794. r2 = r4 = r[1];
  9795. }
  9796. else if (r.length === 3) {
  9797. r1 = r[0];
  9798. r2 = r4 = r[1];
  9799. r3 = r[2];
  9800. }
  9801. else {
  9802. r1 = r[0];
  9803. r2 = r[1];
  9804. r3 = r[2];
  9805. r4 = r[3];
  9806. }
  9807. }
  9808. else {
  9809. r1 = r2 = r3 = r4 = 0;
  9810. }
  9811. var total;
  9812. if (r1 + r2 > width) {
  9813. total = r1 + r2;
  9814. r1 *= width / total;
  9815. r2 *= width / total;
  9816. }
  9817. if (r3 + r4 > width) {
  9818. total = r3 + r4;
  9819. r3 *= width / total;
  9820. r4 *= width / total;
  9821. }
  9822. if (r2 + r3 > height) {
  9823. total = r2 + r3;
  9824. r2 *= height / total;
  9825. r3 *= height / total;
  9826. }
  9827. if (r1 + r4 > height) {
  9828. total = r1 + r4;
  9829. r1 *= height / total;
  9830. r4 *= height / total;
  9831. }
  9832. ctx.moveTo(x + r1, y);
  9833. ctx.lineTo(x + width - r2, y);
  9834. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  9835. ctx.lineTo(x + width, y + height - r3);
  9836. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  9837. ctx.lineTo(x + r4, y + height);
  9838. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  9839. ctx.lineTo(x, y + r1);
  9840. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  9841. }
  9842. var round = Math.round;
  9843. function subPixelOptimizeLine(outputShape, inputShape, style) {
  9844. if (!inputShape) {
  9845. return;
  9846. }
  9847. var x1 = inputShape.x1;
  9848. var x2 = inputShape.x2;
  9849. var y1 = inputShape.y1;
  9850. var y2 = inputShape.y2;
  9851. outputShape.x1 = x1;
  9852. outputShape.x2 = x2;
  9853. outputShape.y1 = y1;
  9854. outputShape.y2 = y2;
  9855. var lineWidth = style && style.lineWidth;
  9856. if (!lineWidth) {
  9857. return outputShape;
  9858. }
  9859. if (round(x1 * 2) === round(x2 * 2)) {
  9860. outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true);
  9861. }
  9862. if (round(y1 * 2) === round(y2 * 2)) {
  9863. outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true);
  9864. }
  9865. return outputShape;
  9866. }
  9867. function subPixelOptimizeRect(outputShape, inputShape, style) {
  9868. if (!inputShape) {
  9869. return;
  9870. }
  9871. var originX = inputShape.x;
  9872. var originY = inputShape.y;
  9873. var originWidth = inputShape.width;
  9874. var originHeight = inputShape.height;
  9875. outputShape.x = originX;
  9876. outputShape.y = originY;
  9877. outputShape.width = originWidth;
  9878. outputShape.height = originHeight;
  9879. var lineWidth = style && style.lineWidth;
  9880. if (!lineWidth) {
  9881. return outputShape;
  9882. }
  9883. outputShape.x = subPixelOptimize(originX, lineWidth, true);
  9884. outputShape.y = subPixelOptimize(originY, lineWidth, true);
  9885. outputShape.width = Math.max(subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
  9886. outputShape.height = Math.max(subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
  9887. return outputShape;
  9888. }
  9889. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  9890. if (!lineWidth) {
  9891. return position;
  9892. }
  9893. var doubledPosition = round(position * 2);
  9894. return (doubledPosition + round(lineWidth)) % 2 === 0
  9895. ? doubledPosition / 2
  9896. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  9897. }
  9898. var RectShape = (function () {
  9899. function RectShape() {
  9900. this.x = 0;
  9901. this.y = 0;
  9902. this.width = 0;
  9903. this.height = 0;
  9904. }
  9905. return RectShape;
  9906. }());
  9907. var subPixelOptimizeOutputShape = {};
  9908. var Rect = (function (_super) {
  9909. __extends(Rect, _super);
  9910. function Rect(opts) {
  9911. return _super.call(this, opts) || this;
  9912. }
  9913. Rect.prototype.getDefaultShape = function () {
  9914. return new RectShape();
  9915. };
  9916. Rect.prototype.buildPath = function (ctx, shape) {
  9917. var x;
  9918. var y;
  9919. var width;
  9920. var height;
  9921. if (this.subPixelOptimize) {
  9922. var optimizedShape = subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style);
  9923. x = optimizedShape.x;
  9924. y = optimizedShape.y;
  9925. width = optimizedShape.width;
  9926. height = optimizedShape.height;
  9927. optimizedShape.r = shape.r;
  9928. shape = optimizedShape;
  9929. }
  9930. else {
  9931. x = shape.x;
  9932. y = shape.y;
  9933. width = shape.width;
  9934. height = shape.height;
  9935. }
  9936. if (!shape.r) {
  9937. ctx.rect(x, y, width, height);
  9938. }
  9939. else {
  9940. buildPath(ctx, shape);
  9941. }
  9942. };
  9943. Rect.prototype.isZeroArea = function () {
  9944. return !this.shape.width || !this.shape.height;
  9945. };
  9946. return Rect;
  9947. }(Path));
  9948. Rect.prototype.type = 'rect';
  9949. var EllipseShape = (function () {
  9950. function EllipseShape() {
  9951. this.cx = 0;
  9952. this.cy = 0;
  9953. this.rx = 0;
  9954. this.ry = 0;
  9955. }
  9956. return EllipseShape;
  9957. }());
  9958. var Ellipse = (function (_super) {
  9959. __extends(Ellipse, _super);
  9960. function Ellipse(opts) {
  9961. return _super.call(this, opts) || this;
  9962. }
  9963. Ellipse.prototype.getDefaultShape = function () {
  9964. return new EllipseShape();
  9965. };
  9966. Ellipse.prototype.buildPath = function (ctx, shape) {
  9967. var k = 0.5522848;
  9968. var x = shape.cx;
  9969. var y = shape.cy;
  9970. var a = shape.rx;
  9971. var b = shape.ry;
  9972. var ox = a * k;
  9973. var oy = b * k;
  9974. ctx.moveTo(x - a, y);
  9975. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  9976. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  9977. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  9978. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  9979. ctx.closePath();
  9980. };
  9981. return Ellipse;
  9982. }(Path));
  9983. Ellipse.prototype.type = 'ellipse';
  9984. var subPixelOptimizeOutputShape$1 = {};
  9985. var LineShape = (function () {
  9986. function LineShape() {
  9987. this.x1 = 0;
  9988. this.y1 = 0;
  9989. this.x2 = 0;
  9990. this.y2 = 0;
  9991. this.percent = 1;
  9992. }
  9993. return LineShape;
  9994. }());
  9995. var Line = (function (_super) {
  9996. __extends(Line, _super);
  9997. function Line(opts) {
  9998. return _super.call(this, opts) || this;
  9999. }
  10000. Line.prototype.getDefaultStyle = function () {
  10001. return {
  10002. stroke: '#000',
  10003. fill: null
  10004. };
  10005. };
  10006. Line.prototype.getDefaultShape = function () {
  10007. return new LineShape();
  10008. };
  10009. Line.prototype.buildPath = function (ctx, shape) {
  10010. var x1;
  10011. var y1;
  10012. var x2;
  10013. var y2;
  10014. if (this.subPixelOptimize) {
  10015. var optimizedShape = subPixelOptimizeLine(subPixelOptimizeOutputShape$1, shape, this.style);
  10016. x1 = optimizedShape.x1;
  10017. y1 = optimizedShape.y1;
  10018. x2 = optimizedShape.x2;
  10019. y2 = optimizedShape.y2;
  10020. }
  10021. else {
  10022. x1 = shape.x1;
  10023. y1 = shape.y1;
  10024. x2 = shape.x2;
  10025. y2 = shape.y2;
  10026. }
  10027. var percent = shape.percent;
  10028. if (percent === 0) {
  10029. return;
  10030. }
  10031. ctx.moveTo(x1, y1);
  10032. if (percent < 1) {
  10033. x2 = x1 * (1 - percent) + x2 * percent;
  10034. y2 = y1 * (1 - percent) + y2 * percent;
  10035. }
  10036. ctx.lineTo(x2, y2);
  10037. };
  10038. Line.prototype.pointAt = function (p) {
  10039. var shape = this.shape;
  10040. return [
  10041. shape.x1 * (1 - p) + shape.x2 * p,
  10042. shape.y1 * (1 - p) + shape.y2 * p
  10043. ];
  10044. };
  10045. return Line;
  10046. }(Path));
  10047. Line.prototype.type = 'line';
  10048. function smoothBezier(points, smooth, isLoop, constraint) {
  10049. var cps = [];
  10050. var v = [];
  10051. var v1 = [];
  10052. var v2 = [];
  10053. var prevPoint;
  10054. var nextPoint;
  10055. var min$1;
  10056. var max$1;
  10057. if (constraint) {
  10058. min$1 = [Infinity, Infinity];
  10059. max$1 = [-Infinity, -Infinity];
  10060. for (var i = 0, len = points.length; i < len; i++) {
  10061. min(min$1, min$1, points[i]);
  10062. max(max$1, max$1, points[i]);
  10063. }
  10064. min(min$1, min$1, constraint[0]);
  10065. max(max$1, max$1, constraint[1]);
  10066. }
  10067. for (var i = 0, len = points.length; i < len; i++) {
  10068. var point = points[i];
  10069. if (isLoop) {
  10070. prevPoint = points[i ? i - 1 : len - 1];
  10071. nextPoint = points[(i + 1) % len];
  10072. }
  10073. else {
  10074. if (i === 0 || i === len - 1) {
  10075. cps.push(clone$1(points[i]));
  10076. continue;
  10077. }
  10078. else {
  10079. prevPoint = points[i - 1];
  10080. nextPoint = points[i + 1];
  10081. }
  10082. }
  10083. sub(v, nextPoint, prevPoint);
  10084. scale(v, v, smooth);
  10085. var d0 = distance(point, prevPoint);
  10086. var d1 = distance(point, nextPoint);
  10087. var sum = d0 + d1;
  10088. if (sum !== 0) {
  10089. d0 /= sum;
  10090. d1 /= sum;
  10091. }
  10092. scale(v1, v, -d0);
  10093. scale(v2, v, d1);
  10094. var cp0 = add([], point, v1);
  10095. var cp1 = add([], point, v2);
  10096. if (constraint) {
  10097. max(cp0, cp0, min$1);
  10098. min(cp0, cp0, max$1);
  10099. max(cp1, cp1, min$1);
  10100. min(cp1, cp1, max$1);
  10101. }
  10102. cps.push(cp0);
  10103. cps.push(cp1);
  10104. }
  10105. if (isLoop) {
  10106. cps.push(cps.shift());
  10107. }
  10108. return cps;
  10109. }
  10110. function buildPath$1(ctx, shape, closePath) {
  10111. var smooth = shape.smooth;
  10112. var points = shape.points;
  10113. if (points && points.length >= 2) {
  10114. if (smooth) {
  10115. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  10116. ctx.moveTo(points[0][0], points[0][1]);
  10117. var len = points.length;
  10118. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  10119. var cp1 = controlPoints[i * 2];
  10120. var cp2 = controlPoints[i * 2 + 1];
  10121. var p = points[(i + 1) % len];
  10122. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  10123. }
  10124. }
  10125. else {
  10126. ctx.moveTo(points[0][0], points[0][1]);
  10127. for (var i = 1, l = points.length; i < l; i++) {
  10128. ctx.lineTo(points[i][0], points[i][1]);
  10129. }
  10130. }
  10131. closePath && ctx.closePath();
  10132. }
  10133. }
  10134. var PolygonShape = (function () {
  10135. function PolygonShape() {
  10136. this.points = null;
  10137. this.smooth = 0;
  10138. this.smoothConstraint = null;
  10139. }
  10140. return PolygonShape;
  10141. }());
  10142. var Polygon = (function (_super) {
  10143. __extends(Polygon, _super);
  10144. function Polygon(opts) {
  10145. return _super.call(this, opts) || this;
  10146. }
  10147. Polygon.prototype.getDefaultShape = function () {
  10148. return new PolygonShape();
  10149. };
  10150. Polygon.prototype.buildPath = function (ctx, shape) {
  10151. buildPath$1(ctx, shape, true);
  10152. };
  10153. return Polygon;
  10154. }(Path));
  10155. Polygon.prototype.type = 'polygon';
  10156. var PolylineShape = (function () {
  10157. function PolylineShape() {
  10158. this.points = null;
  10159. this.percent = 1;
  10160. this.smooth = 0;
  10161. this.smoothConstraint = null;
  10162. }
  10163. return PolylineShape;
  10164. }());
  10165. var Polyline = (function (_super) {
  10166. __extends(Polyline, _super);
  10167. function Polyline(opts) {
  10168. return _super.call(this, opts) || this;
  10169. }
  10170. Polyline.prototype.getDefaultStyle = function () {
  10171. return {
  10172. stroke: '#000',
  10173. fill: null
  10174. };
  10175. };
  10176. Polyline.prototype.getDefaultShape = function () {
  10177. return new PolylineShape();
  10178. };
  10179. Polyline.prototype.buildPath = function (ctx, shape) {
  10180. buildPath$1(ctx, shape, false);
  10181. };
  10182. return Polyline;
  10183. }(Path));
  10184. Polyline.prototype.type = 'polyline';
  10185. var Gradient = (function () {
  10186. function Gradient(colorStops) {
  10187. this.colorStops = colorStops || [];
  10188. }
  10189. Gradient.prototype.addColorStop = function (offset, color) {
  10190. this.colorStops.push({
  10191. offset: offset,
  10192. color: color
  10193. });
  10194. };
  10195. return Gradient;
  10196. }());
  10197. var LinearGradient = (function (_super) {
  10198. __extends(LinearGradient, _super);
  10199. function LinearGradient(x, y, x2, y2, colorStops, globalCoord) {
  10200. var _this = _super.call(this, colorStops) || this;
  10201. _this.x = x == null ? 0 : x;
  10202. _this.y = y == null ? 0 : y;
  10203. _this.x2 = x2 == null ? 1 : x2;
  10204. _this.y2 = y2 == null ? 0 : y2;
  10205. _this.type = 'linear';
  10206. _this.global = globalCoord || false;
  10207. return _this;
  10208. }
  10209. return LinearGradient;
  10210. }(Gradient));
  10211. var RadialGradient = (function (_super) {
  10212. __extends(RadialGradient, _super);
  10213. function RadialGradient(x, y, r, colorStops, globalCoord) {
  10214. var _this = _super.call(this, colorStops) || this;
  10215. _this.x = x == null ? 0.5 : x;
  10216. _this.y = y == null ? 0.5 : y;
  10217. _this.r = r == null ? 0.5 : r;
  10218. _this.type = 'radial';
  10219. _this.global = globalCoord || false;
  10220. return _this;
  10221. }
  10222. return RadialGradient;
  10223. }(Gradient));
  10224. var DEFAULT_TSPAN_STYLE = defaults({
  10225. strokeFirst: true,
  10226. font: DEFAULT_FONT,
  10227. x: 0,
  10228. y: 0,
  10229. textAlign: 'left',
  10230. textBaseline: 'top',
  10231. miterLimit: 2
  10232. }, DEFAULT_PATH_STYLE);
  10233. var TSpan = (function (_super) {
  10234. __extends(TSpan, _super);
  10235. function TSpan() {
  10236. return _super !== null && _super.apply(this, arguments) || this;
  10237. }
  10238. TSpan.prototype.hasStroke = function () {
  10239. var style = this.style;
  10240. var stroke = style.stroke;
  10241. return stroke != null && stroke !== 'none' && style.lineWidth > 0;
  10242. };
  10243. TSpan.prototype.hasFill = function () {
  10244. var style = this.style;
  10245. var fill = style.fill;
  10246. return fill != null && fill !== 'none';
  10247. };
  10248. TSpan.prototype.createStyle = function (obj) {
  10249. return createObject(DEFAULT_TSPAN_STYLE, obj);
  10250. };
  10251. TSpan.prototype.setBoundingRect = function (rect) {
  10252. this._rect = rect;
  10253. };
  10254. TSpan.prototype.getBoundingRect = function () {
  10255. var style = this.style;
  10256. if (!this._rect) {
  10257. var text = style.text;
  10258. text != null ? (text += '') : (text = '');
  10259. var rect = getBoundingRect(text, style.font, style.textAlign, style.textBaseline);
  10260. rect.x += style.x || 0;
  10261. rect.y += style.y || 0;
  10262. if (this.hasStroke()) {
  10263. var w = style.lineWidth;
  10264. rect.x -= w / 2;
  10265. rect.y -= w / 2;
  10266. rect.width += w;
  10267. rect.height += w;
  10268. }
  10269. this._rect = rect;
  10270. }
  10271. return this._rect;
  10272. };
  10273. TSpan.initDefaultProps = (function () {
  10274. var tspanProto = TSpan.prototype;
  10275. tspanProto.dirtyRectTolerance = 10;
  10276. })();
  10277. return TSpan;
  10278. }(Displayable));
  10279. TSpan.prototype.type = 'tspan';
  10280. function parseXML(svg) {
  10281. if (isString(svg)) {
  10282. var parser = new DOMParser();
  10283. svg = parser.parseFromString(svg, 'text/xml');
  10284. }
  10285. var svgNode = svg;
  10286. if (svgNode.nodeType === 9) {
  10287. svgNode = svgNode.firstChild;
  10288. }
  10289. while (svgNode.nodeName.toLowerCase() !== 'svg' || svgNode.nodeType !== 1) {
  10290. svgNode = svgNode.nextSibling;
  10291. }
  10292. return svgNode;
  10293. }
  10294. var nodeParsers;
  10295. var INHERITABLE_STYLE_ATTRIBUTES_MAP = {
  10296. 'fill': 'fill',
  10297. 'stroke': 'stroke',
  10298. 'stroke-width': 'lineWidth',
  10299. 'opacity': 'opacity',
  10300. 'fill-opacity': 'fillOpacity',
  10301. 'stroke-opacity': 'strokeOpacity',
  10302. 'stroke-dasharray': 'lineDash',
  10303. 'stroke-dashoffset': 'lineDashOffset',
  10304. 'stroke-linecap': 'lineCap',
  10305. 'stroke-linejoin': 'lineJoin',
  10306. 'stroke-miterlimit': 'miterLimit',
  10307. 'font-family': 'fontFamily',
  10308. 'font-size': 'fontSize',
  10309. 'font-style': 'fontStyle',
  10310. 'font-weight': 'fontWeight',
  10311. 'text-anchor': 'textAlign',
  10312. 'visibility': 'visibility',
  10313. 'display': 'display'
  10314. };
  10315. var INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS = keys(INHERITABLE_STYLE_ATTRIBUTES_MAP);
  10316. var SELF_STYLE_ATTRIBUTES_MAP = {
  10317. 'alignment-baseline': 'textBaseline',
  10318. 'stop-color': 'stopColor'
  10319. };
  10320. var SELF_STYLE_ATTRIBUTES_MAP_KEYS = keys(SELF_STYLE_ATTRIBUTES_MAP);
  10321. var SVGParser = (function () {
  10322. function SVGParser() {
  10323. this._defs = {};
  10324. this._root = null;
  10325. }
  10326. SVGParser.prototype.parse = function (xml, opt) {
  10327. opt = opt || {};
  10328. var svg = parseXML(xml);
  10329. {
  10330. if (!svg) {
  10331. throw new Error('Illegal svg');
  10332. }
  10333. }
  10334. this._defsUsePending = [];
  10335. var root = new Group();
  10336. this._root = root;
  10337. var named = [];
  10338. var viewBox = svg.getAttribute('viewBox') || '';
  10339. var width = parseFloat((svg.getAttribute('width') || opt.width));
  10340. var height = parseFloat((svg.getAttribute('height') || opt.height));
  10341. isNaN(width) && (width = null);
  10342. isNaN(height) && (height = null);
  10343. parseAttributes(svg, root, null, true, false);
  10344. var child = svg.firstChild;
  10345. while (child) {
  10346. this._parseNode(child, root, named, null, false, false);
  10347. child = child.nextSibling;
  10348. }
  10349. applyDefs(this._defs, this._defsUsePending);
  10350. this._defsUsePending = [];
  10351. var viewBoxRect;
  10352. var viewBoxTransform;
  10353. if (viewBox) {
  10354. var viewBoxArr = splitNumberSequence(viewBox);
  10355. if (viewBoxArr.length >= 4) {
  10356. viewBoxRect = {
  10357. x: parseFloat((viewBoxArr[0] || 0)),
  10358. y: parseFloat((viewBoxArr[1] || 0)),
  10359. width: parseFloat(viewBoxArr[2]),
  10360. height: parseFloat(viewBoxArr[3])
  10361. };
  10362. }
  10363. }
  10364. if (viewBoxRect && width != null && height != null) {
  10365. viewBoxTransform = makeViewBoxTransform(viewBoxRect, { x: 0, y: 0, width: width, height: height });
  10366. if (!opt.ignoreViewBox) {
  10367. var elRoot = root;
  10368. root = new Group();
  10369. root.add(elRoot);
  10370. elRoot.scaleX = elRoot.scaleY = viewBoxTransform.scale;
  10371. elRoot.x = viewBoxTransform.x;
  10372. elRoot.y = viewBoxTransform.y;
  10373. }
  10374. }
  10375. if (!opt.ignoreRootClip && width != null && height != null) {
  10376. root.setClipPath(new Rect({
  10377. shape: { x: 0, y: 0, width: width, height: height }
  10378. }));
  10379. }
  10380. return {
  10381. root: root,
  10382. width: width,
  10383. height: height,
  10384. viewBoxRect: viewBoxRect,
  10385. viewBoxTransform: viewBoxTransform,
  10386. named: named
  10387. };
  10388. };
  10389. SVGParser.prototype._parseNode = function (xmlNode, parentGroup, named, namedFrom, isInDefs, isInText) {
  10390. var nodeName = xmlNode.nodeName.toLowerCase();
  10391. var el;
  10392. var namedFromForSub = namedFrom;
  10393. if (nodeName === 'defs') {
  10394. isInDefs = true;
  10395. }
  10396. if (nodeName === 'text') {
  10397. isInText = true;
  10398. }
  10399. if (nodeName === 'defs' || nodeName === 'switch') {
  10400. el = parentGroup;
  10401. }
  10402. else {
  10403. if (!isInDefs) {
  10404. var parser_1 = nodeParsers[nodeName];
  10405. if (parser_1 && hasOwn(nodeParsers, nodeName)) {
  10406. el = parser_1.call(this, xmlNode, parentGroup);
  10407. var nameAttr = xmlNode.getAttribute('name');
  10408. if (nameAttr) {
  10409. var newNamed = {
  10410. name: nameAttr,
  10411. namedFrom: null,
  10412. svgNodeTagLower: nodeName,
  10413. el: el
  10414. };
  10415. named.push(newNamed);
  10416. if (nodeName === 'g') {
  10417. namedFromForSub = newNamed;
  10418. }
  10419. }
  10420. else if (namedFrom) {
  10421. named.push({
  10422. name: namedFrom.name,
  10423. namedFrom: namedFrom,
  10424. svgNodeTagLower: nodeName,
  10425. el: el
  10426. });
  10427. }
  10428. parentGroup.add(el);
  10429. }
  10430. }
  10431. var parser = paintServerParsers[nodeName];
  10432. if (parser && hasOwn(paintServerParsers, nodeName)) {
  10433. var def = parser.call(this, xmlNode);
  10434. var id = xmlNode.getAttribute('id');
  10435. if (id) {
  10436. this._defs[id] = def;
  10437. }
  10438. }
  10439. }
  10440. if (el && el.isGroup) {
  10441. var child = xmlNode.firstChild;
  10442. while (child) {
  10443. if (child.nodeType === 1) {
  10444. this._parseNode(child, el, named, namedFromForSub, isInDefs, isInText);
  10445. }
  10446. else if (child.nodeType === 3 && isInText) {
  10447. this._parseText(child, el);
  10448. }
  10449. child = child.nextSibling;
  10450. }
  10451. }
  10452. };
  10453. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  10454. var text = new TSpan({
  10455. style: {
  10456. text: xmlNode.textContent
  10457. },
  10458. silent: true,
  10459. x: this._textX || 0,
  10460. y: this._textY || 0
  10461. });
  10462. inheritStyle(parentGroup, text);
  10463. parseAttributes(xmlNode, text, this._defsUsePending, false, false);
  10464. applyTextAlignment(text, parentGroup);
  10465. var textStyle = text.style;
  10466. var fontSize = textStyle.fontSize;
  10467. if (fontSize && fontSize < 9) {
  10468. textStyle.fontSize = 9;
  10469. text.scaleX *= fontSize / 9;
  10470. text.scaleY *= fontSize / 9;
  10471. }
  10472. var font = (textStyle.fontSize || textStyle.fontFamily) && [
  10473. textStyle.fontStyle,
  10474. textStyle.fontWeight,
  10475. (textStyle.fontSize || 12) + 'px',
  10476. textStyle.fontFamily || 'sans-serif'
  10477. ].join(' ');
  10478. textStyle.font = font;
  10479. var rect = text.getBoundingRect();
  10480. this._textX += rect.width;
  10481. parentGroup.add(text);
  10482. return text;
  10483. };
  10484. SVGParser.internalField = (function () {
  10485. nodeParsers = {
  10486. 'g': function (xmlNode, parentGroup) {
  10487. var g = new Group();
  10488. inheritStyle(parentGroup, g);
  10489. parseAttributes(xmlNode, g, this._defsUsePending, false, false);
  10490. return g;
  10491. },
  10492. 'rect': function (xmlNode, parentGroup) {
  10493. var rect = new Rect();
  10494. inheritStyle(parentGroup, rect);
  10495. parseAttributes(xmlNode, rect, this._defsUsePending, false, false);
  10496. rect.setShape({
  10497. x: parseFloat(xmlNode.getAttribute('x') || '0'),
  10498. y: parseFloat(xmlNode.getAttribute('y') || '0'),
  10499. width: parseFloat(xmlNode.getAttribute('width') || '0'),
  10500. height: parseFloat(xmlNode.getAttribute('height') || '0')
  10501. });
  10502. rect.silent = true;
  10503. return rect;
  10504. },
  10505. 'circle': function (xmlNode, parentGroup) {
  10506. var circle = new Circle();
  10507. inheritStyle(parentGroup, circle);
  10508. parseAttributes(xmlNode, circle, this._defsUsePending, false, false);
  10509. circle.setShape({
  10510. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  10511. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  10512. r: parseFloat(xmlNode.getAttribute('r') || '0')
  10513. });
  10514. circle.silent = true;
  10515. return circle;
  10516. },
  10517. 'line': function (xmlNode, parentGroup) {
  10518. var line = new Line();
  10519. inheritStyle(parentGroup, line);
  10520. parseAttributes(xmlNode, line, this._defsUsePending, false, false);
  10521. line.setShape({
  10522. x1: parseFloat(xmlNode.getAttribute('x1') || '0'),
  10523. y1: parseFloat(xmlNode.getAttribute('y1') || '0'),
  10524. x2: parseFloat(xmlNode.getAttribute('x2') || '0'),
  10525. y2: parseFloat(xmlNode.getAttribute('y2') || '0')
  10526. });
  10527. line.silent = true;
  10528. return line;
  10529. },
  10530. 'ellipse': function (xmlNode, parentGroup) {
  10531. var ellipse = new Ellipse();
  10532. inheritStyle(parentGroup, ellipse);
  10533. parseAttributes(xmlNode, ellipse, this._defsUsePending, false, false);
  10534. ellipse.setShape({
  10535. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  10536. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  10537. rx: parseFloat(xmlNode.getAttribute('rx') || '0'),
  10538. ry: parseFloat(xmlNode.getAttribute('ry') || '0')
  10539. });
  10540. ellipse.silent = true;
  10541. return ellipse;
  10542. },
  10543. 'polygon': function (xmlNode, parentGroup) {
  10544. var pointsStr = xmlNode.getAttribute('points');
  10545. var pointsArr;
  10546. if (pointsStr) {
  10547. pointsArr = parsePoints(pointsStr);
  10548. }
  10549. var polygon = new Polygon({
  10550. shape: {
  10551. points: pointsArr || []
  10552. },
  10553. silent: true
  10554. });
  10555. inheritStyle(parentGroup, polygon);
  10556. parseAttributes(xmlNode, polygon, this._defsUsePending, false, false);
  10557. return polygon;
  10558. },
  10559. 'polyline': function (xmlNode, parentGroup) {
  10560. var pointsStr = xmlNode.getAttribute('points');
  10561. var pointsArr;
  10562. if (pointsStr) {
  10563. pointsArr = parsePoints(pointsStr);
  10564. }
  10565. var polyline = new Polyline({
  10566. shape: {
  10567. points: pointsArr || []
  10568. },
  10569. silent: true
  10570. });
  10571. inheritStyle(parentGroup, polyline);
  10572. parseAttributes(xmlNode, polyline, this._defsUsePending, false, false);
  10573. return polyline;
  10574. },
  10575. 'image': function (xmlNode, parentGroup) {
  10576. var img = new ZRImage();
  10577. inheritStyle(parentGroup, img);
  10578. parseAttributes(xmlNode, img, this._defsUsePending, false, false);
  10579. img.setStyle({
  10580. image: xmlNode.getAttribute('xlink:href') || xmlNode.getAttribute('href'),
  10581. x: +xmlNode.getAttribute('x'),
  10582. y: +xmlNode.getAttribute('y'),
  10583. width: +xmlNode.getAttribute('width'),
  10584. height: +xmlNode.getAttribute('height')
  10585. });
  10586. img.silent = true;
  10587. return img;
  10588. },
  10589. 'text': function (xmlNode, parentGroup) {
  10590. var x = xmlNode.getAttribute('x') || '0';
  10591. var y = xmlNode.getAttribute('y') || '0';
  10592. var dx = xmlNode.getAttribute('dx') || '0';
  10593. var dy = xmlNode.getAttribute('dy') || '0';
  10594. this._textX = parseFloat(x) + parseFloat(dx);
  10595. this._textY = parseFloat(y) + parseFloat(dy);
  10596. var g = new Group();
  10597. inheritStyle(parentGroup, g);
  10598. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  10599. return g;
  10600. },
  10601. 'tspan': function (xmlNode, parentGroup) {
  10602. var x = xmlNode.getAttribute('x');
  10603. var y = xmlNode.getAttribute('y');
  10604. if (x != null) {
  10605. this._textX = parseFloat(x);
  10606. }
  10607. if (y != null) {
  10608. this._textY = parseFloat(y);
  10609. }
  10610. var dx = xmlNode.getAttribute('dx') || '0';
  10611. var dy = xmlNode.getAttribute('dy') || '0';
  10612. var g = new Group();
  10613. inheritStyle(parentGroup, g);
  10614. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  10615. this._textX += parseFloat(dx);
  10616. this._textY += parseFloat(dy);
  10617. return g;
  10618. },
  10619. 'path': function (xmlNode, parentGroup) {
  10620. var d = xmlNode.getAttribute('d') || '';
  10621. var path = createFromString(d);
  10622. inheritStyle(parentGroup, path);
  10623. parseAttributes(xmlNode, path, this._defsUsePending, false, false);
  10624. path.silent = true;
  10625. return path;
  10626. }
  10627. };
  10628. })();
  10629. return SVGParser;
  10630. }());
  10631. var paintServerParsers = {
  10632. 'lineargradient': function (xmlNode) {
  10633. var x1 = parseInt(xmlNode.getAttribute('x1') || '0', 10);
  10634. var y1 = parseInt(xmlNode.getAttribute('y1') || '0', 10);
  10635. var x2 = parseInt(xmlNode.getAttribute('x2') || '10', 10);
  10636. var y2 = parseInt(xmlNode.getAttribute('y2') || '0', 10);
  10637. var gradient = new LinearGradient(x1, y1, x2, y2);
  10638. parsePaintServerUnit(xmlNode, gradient);
  10639. parseGradientColorStops(xmlNode, gradient);
  10640. return gradient;
  10641. },
  10642. 'radialgradient': function (xmlNode) {
  10643. var cx = parseInt(xmlNode.getAttribute('cx') || '0', 10);
  10644. var cy = parseInt(xmlNode.getAttribute('cy') || '0', 10);
  10645. var r = parseInt(xmlNode.getAttribute('r') || '0', 10);
  10646. var gradient = new RadialGradient(cx, cy, r);
  10647. parsePaintServerUnit(xmlNode, gradient);
  10648. parseGradientColorStops(xmlNode, gradient);
  10649. return gradient;
  10650. }
  10651. };
  10652. function parsePaintServerUnit(xmlNode, gradient) {
  10653. var gradientUnits = xmlNode.getAttribute('gradientUnits');
  10654. if (gradientUnits === 'userSpaceOnUse') {
  10655. gradient.global = true;
  10656. }
  10657. }
  10658. function parseGradientColorStops(xmlNode, gradient) {
  10659. var stop = xmlNode.firstChild;
  10660. while (stop) {
  10661. if (stop.nodeType === 1
  10662. && stop.nodeName.toLocaleLowerCase() === 'stop') {
  10663. var offsetStr = stop.getAttribute('offset');
  10664. var offset = void 0;
  10665. if (offsetStr && offsetStr.indexOf('%') > 0) {
  10666. offset = parseInt(offsetStr, 10) / 100;
  10667. }
  10668. else if (offsetStr) {
  10669. offset = parseFloat(offsetStr);
  10670. }
  10671. else {
  10672. offset = 0;
  10673. }
  10674. var styleVals = {};
  10675. parseInlineStyle(stop, styleVals, styleVals);
  10676. var stopColor = styleVals.stopColor
  10677. || stop.getAttribute('stop-color')
  10678. || '#000000';
  10679. gradient.colorStops.push({
  10680. offset: offset,
  10681. color: stopColor
  10682. });
  10683. }
  10684. stop = stop.nextSibling;
  10685. }
  10686. }
  10687. function inheritStyle(parent, child) {
  10688. if (parent && parent.__inheritedStyle) {
  10689. if (!child.__inheritedStyle) {
  10690. child.__inheritedStyle = {};
  10691. }
  10692. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  10693. }
  10694. }
  10695. function parsePoints(pointsString) {
  10696. var list = splitNumberSequence(pointsString);
  10697. var points = [];
  10698. for (var i = 0; i < list.length; i += 2) {
  10699. var x = parseFloat(list[i]);
  10700. var y = parseFloat(list[i + 1]);
  10701. points.push([x, y]);
  10702. }
  10703. return points;
  10704. }
  10705. function parseAttributes(xmlNode, el, defsUsePending, onlyInlineStyle, isTextGroup) {
  10706. var disp = el;
  10707. var inheritedStyle = disp.__inheritedStyle = disp.__inheritedStyle || {};
  10708. var selfStyle = {};
  10709. if (xmlNode.nodeType === 1) {
  10710. parseTransformAttribute(xmlNode, el);
  10711. parseInlineStyle(xmlNode, inheritedStyle, selfStyle);
  10712. if (!onlyInlineStyle) {
  10713. parseAttributeStyle(xmlNode, inheritedStyle, selfStyle);
  10714. }
  10715. }
  10716. disp.style = disp.style || {};
  10717. if (inheritedStyle.fill != null) {
  10718. disp.style.fill = getFillStrokeStyle(disp, 'fill', inheritedStyle.fill, defsUsePending);
  10719. }
  10720. if (inheritedStyle.stroke != null) {
  10721. disp.style.stroke = getFillStrokeStyle(disp, 'stroke', inheritedStyle.stroke, defsUsePending);
  10722. }
  10723. each([
  10724. 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'
  10725. ], function (propName) {
  10726. if (inheritedStyle[propName] != null) {
  10727. disp.style[propName] = parseFloat(inheritedStyle[propName]);
  10728. }
  10729. });
  10730. each([
  10731. 'lineDashOffset', 'lineCap', 'lineJoin', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign'
  10732. ], function (propName) {
  10733. if (inheritedStyle[propName] != null) {
  10734. disp.style[propName] = inheritedStyle[propName];
  10735. }
  10736. });
  10737. if (isTextGroup) {
  10738. disp.__selfStyle = selfStyle;
  10739. }
  10740. if (inheritedStyle.lineDash) {
  10741. disp.style.lineDash = map(splitNumberSequence(inheritedStyle.lineDash), function (str) {
  10742. return parseFloat(str);
  10743. });
  10744. }
  10745. if (inheritedStyle.visibility === 'hidden' || inheritedStyle.visibility === 'collapse') {
  10746. disp.invisible = true;
  10747. }
  10748. if (inheritedStyle.display === 'none') {
  10749. disp.ignore = true;
  10750. }
  10751. }
  10752. function applyTextAlignment(text, parentGroup) {
  10753. var parentSelfStyle = parentGroup.__selfStyle;
  10754. if (parentSelfStyle) {
  10755. var textBaseline = parentSelfStyle.textBaseline;
  10756. var zrTextBaseline = textBaseline;
  10757. if (!textBaseline || textBaseline === 'auto') {
  10758. zrTextBaseline = 'alphabetic';
  10759. }
  10760. else if (textBaseline === 'baseline') {
  10761. zrTextBaseline = 'alphabetic';
  10762. }
  10763. else if (textBaseline === 'before-edge' || textBaseline === 'text-before-edge') {
  10764. zrTextBaseline = 'top';
  10765. }
  10766. else if (textBaseline === 'after-edge' || textBaseline === 'text-after-edge') {
  10767. zrTextBaseline = 'bottom';
  10768. }
  10769. else if (textBaseline === 'central' || textBaseline === 'mathematical') {
  10770. zrTextBaseline = 'middle';
  10771. }
  10772. text.style.textBaseline = zrTextBaseline;
  10773. }
  10774. var parentInheritedStyle = parentGroup.__inheritedStyle;
  10775. if (parentInheritedStyle) {
  10776. var textAlign = parentInheritedStyle.textAlign;
  10777. var zrTextAlign = textAlign;
  10778. if (textAlign) {
  10779. if (textAlign === 'middle') {
  10780. zrTextAlign = 'center';
  10781. }
  10782. text.style.textAlign = zrTextAlign;
  10783. }
  10784. }
  10785. }
  10786. var urlRegex = /^url\(\s*#(.*?)\)/;
  10787. function getFillStrokeStyle(el, method, str, defsUsePending) {
  10788. var urlMatch = str && str.match(urlRegex);
  10789. if (urlMatch) {
  10790. var url = trim(urlMatch[1]);
  10791. defsUsePending.push([el, method, url]);
  10792. return;
  10793. }
  10794. if (str === 'none') {
  10795. str = null;
  10796. }
  10797. return str;
  10798. }
  10799. function applyDefs(defs, defsUsePending) {
  10800. for (var i = 0; i < defsUsePending.length; i++) {
  10801. var item = defsUsePending[i];
  10802. item[0].style[item[1]] = defs[item[2]];
  10803. }
  10804. }
  10805. var numberReg$1 = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  10806. function splitNumberSequence(rawStr) {
  10807. return rawStr.match(numberReg$1) || [];
  10808. }
  10809. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.eE,]*)\)/g;
  10810. var DEGREE_TO_ANGLE = Math.PI / 180;
  10811. function parseTransformAttribute(xmlNode, node) {
  10812. var transform = xmlNode.getAttribute('transform');
  10813. if (transform) {
  10814. transform = transform.replace(/,/g, ' ');
  10815. var transformOps_1 = [];
  10816. var mt = null;
  10817. transform.replace(transformRegex, function (str, type, value) {
  10818. transformOps_1.push(type, value);
  10819. return '';
  10820. });
  10821. for (var i = transformOps_1.length - 1; i > 0; i -= 2) {
  10822. var value = transformOps_1[i];
  10823. var type = transformOps_1[i - 1];
  10824. var valueArr = splitNumberSequence(value);
  10825. mt = mt || create$1();
  10826. switch (type) {
  10827. case 'translate':
  10828. translate(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || '0')]);
  10829. break;
  10830. case 'scale':
  10831. scale$1(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || valueArr[0])]);
  10832. break;
  10833. case 'rotate':
  10834. rotate(mt, mt, -parseFloat(valueArr[0]) * DEGREE_TO_ANGLE, [
  10835. parseFloat(valueArr[1] || '0'),
  10836. parseFloat(valueArr[2] || '0')
  10837. ]);
  10838. break;
  10839. case 'skewX':
  10840. var sx = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10841. mul$1(mt, [1, 0, sx, 1, 0, 0], mt);
  10842. break;
  10843. case 'skewY':
  10844. var sy = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10845. mul$1(mt, [1, sy, 0, 1, 0, 0], mt);
  10846. break;
  10847. case 'matrix':
  10848. mt[0] = parseFloat(valueArr[0]);
  10849. mt[1] = parseFloat(valueArr[1]);
  10850. mt[2] = parseFloat(valueArr[2]);
  10851. mt[3] = parseFloat(valueArr[3]);
  10852. mt[4] = parseFloat(valueArr[4]);
  10853. mt[5] = parseFloat(valueArr[5]);
  10854. break;
  10855. }
  10856. }
  10857. node.setLocalTransform(mt);
  10858. }
  10859. }
  10860. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  10861. function parseInlineStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  10862. var style = xmlNode.getAttribute('style');
  10863. if (!style) {
  10864. return;
  10865. }
  10866. styleRegex.lastIndex = 0;
  10867. var styleRegResult;
  10868. while ((styleRegResult = styleRegex.exec(style)) != null) {
  10869. var svgStlAttr = styleRegResult[1];
  10870. var zrInheritableStlAttr = hasOwn(INHERITABLE_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  10871. ? INHERITABLE_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  10872. : null;
  10873. if (zrInheritableStlAttr) {
  10874. inheritableStyleResult[zrInheritableStlAttr] = styleRegResult[2];
  10875. }
  10876. var zrSelfStlAttr = hasOwn(SELF_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  10877. ? SELF_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  10878. : null;
  10879. if (zrSelfStlAttr) {
  10880. selfStyleResult[zrSelfStlAttr] = styleRegResult[2];
  10881. }
  10882. }
  10883. }
  10884. function parseAttributeStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  10885. for (var i = 0; i < INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  10886. var svgAttrName = INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS[i];
  10887. var attrValue = xmlNode.getAttribute(svgAttrName);
  10888. if (attrValue != null) {
  10889. inheritableStyleResult[INHERITABLE_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  10890. }
  10891. }
  10892. for (var i = 0; i < SELF_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  10893. var svgAttrName = SELF_STYLE_ATTRIBUTES_MAP_KEYS[i];
  10894. var attrValue = xmlNode.getAttribute(svgAttrName);
  10895. if (attrValue != null) {
  10896. selfStyleResult[SELF_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  10897. }
  10898. }
  10899. }
  10900. function makeViewBoxTransform(viewBoxRect, boundingRect) {
  10901. var scaleX = boundingRect.width / viewBoxRect.width;
  10902. var scaleY = boundingRect.height / viewBoxRect.height;
  10903. var scale = Math.min(scaleX, scaleY);
  10904. return {
  10905. scale: scale,
  10906. x: -(viewBoxRect.x + viewBoxRect.width / 2) * scale + (boundingRect.x + boundingRect.width / 2),
  10907. y: -(viewBoxRect.y + viewBoxRect.height / 2) * scale + (boundingRect.y + boundingRect.height / 2)
  10908. };
  10909. }
  10910. function parseSVG(xml, opt) {
  10911. var parser = new SVGParser();
  10912. return parser.parse(xml, opt);
  10913. }
  10914. var PI$2 = Math.PI;
  10915. var PI2$5 = PI$2 * 2;
  10916. var mathSin$3 = Math.sin;
  10917. var mathCos$3 = Math.cos;
  10918. var mathACos = Math.acos;
  10919. var mathATan2 = Math.atan2;
  10920. var mathAbs$1 = Math.abs;
  10921. var mathSqrt$3 = Math.sqrt;
  10922. var mathMax$3 = Math.max;
  10923. var mathMin$3 = Math.min;
  10924. var e = 1e-4;
  10925. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  10926. var dx10 = x1 - x0;
  10927. var dy10 = y1 - y0;
  10928. var dx32 = x3 - x2;
  10929. var dy32 = y3 - y2;
  10930. var t = dy32 * dx10 - dx32 * dy10;
  10931. if (t * t < e) {
  10932. return;
  10933. }
  10934. t = (dx32 * (y0 - y2) - dy32 * (x0 - x2)) / t;
  10935. return [x0 + t * dx10, y0 + t * dy10];
  10936. }
  10937. function computeCornerTangents(x0, y0, x1, y1, radius, cr, clockwise) {
  10938. var x01 = x0 - x1;
  10939. var y01 = y0 - y1;
  10940. var lo = (clockwise ? cr : -cr) / mathSqrt$3(x01 * x01 + y01 * y01);
  10941. var ox = lo * y01;
  10942. var oy = -lo * x01;
  10943. var x11 = x0 + ox;
  10944. var y11 = y0 + oy;
  10945. var x10 = x1 + ox;
  10946. var y10 = y1 + oy;
  10947. var x00 = (x11 + x10) / 2;
  10948. var y00 = (y11 + y10) / 2;
  10949. var dx = x10 - x11;
  10950. var dy = y10 - y11;
  10951. var d2 = dx * dx + dy * dy;
  10952. var r = radius - cr;
  10953. var s = x11 * y10 - x10 * y11;
  10954. var d = (dy < 0 ? -1 : 1) * mathSqrt$3(mathMax$3(0, r * r * d2 - s * s));
  10955. var cx0 = (s * dy - dx * d) / d2;
  10956. var cy0 = (-s * dx - dy * d) / d2;
  10957. var cx1 = (s * dy + dx * d) / d2;
  10958. var cy1 = (-s * dx + dy * d) / d2;
  10959. var dx0 = cx0 - x00;
  10960. var dy0 = cy0 - y00;
  10961. var dx1 = cx1 - x00;
  10962. var dy1 = cy1 - y00;
  10963. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
  10964. cx0 = cx1;
  10965. cy0 = cy1;
  10966. }
  10967. return {
  10968. cx: cx0,
  10969. cy: cy0,
  10970. x0: -ox,
  10971. y0: -oy,
  10972. x1: cx0 * (radius / r - 1),
  10973. y1: cy0 * (radius / r - 1)
  10974. };
  10975. }
  10976. function normalizeCornerRadius(cr) {
  10977. var arr;
  10978. if (isArray(cr)) {
  10979. var len = cr.length;
  10980. if (!len) {
  10981. return cr;
  10982. }
  10983. if (len === 1) {
  10984. arr = [cr[0], cr[0], 0, 0];
  10985. }
  10986. else if (len === 2) {
  10987. arr = [cr[0], cr[0], cr[1], cr[1]];
  10988. }
  10989. else if (len === 3) {
  10990. arr = cr.concat(cr[2]);
  10991. }
  10992. else {
  10993. arr = cr;
  10994. }
  10995. }
  10996. else {
  10997. arr = [cr, cr, cr, cr];
  10998. }
  10999. return arr;
  11000. }
  11001. function buildPath$2(ctx, shape) {
  11002. var _a;
  11003. var radius = mathMax$3(shape.r, 0);
  11004. var innerRadius = mathMax$3(shape.r0 || 0, 0);
  11005. var hasRadius = radius > 0;
  11006. var hasInnerRadius = innerRadius > 0;
  11007. if (!hasRadius && !hasInnerRadius) {
  11008. return;
  11009. }
  11010. if (!hasRadius) {
  11011. radius = innerRadius;
  11012. innerRadius = 0;
  11013. }
  11014. if (innerRadius > radius) {
  11015. var tmp = radius;
  11016. radius = innerRadius;
  11017. innerRadius = tmp;
  11018. }
  11019. var startAngle = shape.startAngle, endAngle = shape.endAngle;
  11020. if (isNaN(startAngle) || isNaN(endAngle)) {
  11021. return;
  11022. }
  11023. var cx = shape.cx, cy = shape.cy;
  11024. var clockwise = !!shape.clockwise;
  11025. var arc = mathAbs$1(endAngle - startAngle);
  11026. var mod = arc > PI2$5 && arc % PI2$5;
  11027. mod > e && (arc = mod);
  11028. if (!(radius > e)) {
  11029. ctx.moveTo(cx, cy);
  11030. }
  11031. else if (arc > PI2$5 - e) {
  11032. ctx.moveTo(cx + radius * mathCos$3(startAngle), cy + radius * mathSin$3(startAngle));
  11033. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  11034. if (innerRadius > e) {
  11035. ctx.moveTo(cx + innerRadius * mathCos$3(endAngle), cy + innerRadius * mathSin$3(endAngle));
  11036. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  11037. }
  11038. }
  11039. else {
  11040. var icrStart = void 0;
  11041. var icrEnd = void 0;
  11042. var ocrStart = void 0;
  11043. var ocrEnd = void 0;
  11044. var ocrs = void 0;
  11045. var ocre = void 0;
  11046. var icrs = void 0;
  11047. var icre = void 0;
  11048. var ocrMax = void 0;
  11049. var icrMax = void 0;
  11050. var limitedOcrMax = void 0;
  11051. var limitedIcrMax = void 0;
  11052. var xre = void 0;
  11053. var yre = void 0;
  11054. var xirs = void 0;
  11055. var yirs = void 0;
  11056. var xrs = radius * mathCos$3(startAngle);
  11057. var yrs = radius * mathSin$3(startAngle);
  11058. var xire = innerRadius * mathCos$3(endAngle);
  11059. var yire = innerRadius * mathSin$3(endAngle);
  11060. var hasArc = arc > e;
  11061. if (hasArc) {
  11062. var cornerRadius = shape.cornerRadius;
  11063. if (cornerRadius) {
  11064. _a = normalizeCornerRadius(cornerRadius), icrStart = _a[0], icrEnd = _a[1], ocrStart = _a[2], ocrEnd = _a[3];
  11065. }
  11066. var halfRd = mathAbs$1(radius - innerRadius) / 2;
  11067. ocrs = mathMin$3(halfRd, ocrStart);
  11068. ocre = mathMin$3(halfRd, ocrEnd);
  11069. icrs = mathMin$3(halfRd, icrStart);
  11070. icre = mathMin$3(halfRd, icrEnd);
  11071. limitedOcrMax = ocrMax = mathMax$3(ocrs, ocre);
  11072. limitedIcrMax = icrMax = mathMax$3(icrs, icre);
  11073. if (ocrMax > e || icrMax > e) {
  11074. xre = radius * mathCos$3(endAngle);
  11075. yre = radius * mathSin$3(endAngle);
  11076. xirs = innerRadius * mathCos$3(startAngle);
  11077. yirs = innerRadius * mathSin$3(startAngle);
  11078. if (arc < PI$2) {
  11079. var it_1 = intersect(xrs, yrs, xirs, yirs, xre, yre, xire, yire);
  11080. if (it_1) {
  11081. var x0 = xrs - it_1[0];
  11082. var y0 = yrs - it_1[1];
  11083. var x1 = xre - it_1[0];
  11084. var y1 = yre - it_1[1];
  11085. var a = 1 / mathSin$3(mathACos((x0 * x1 + y0 * y1) / (mathSqrt$3(x0 * x0 + y0 * y0) * mathSqrt$3(x1 * x1 + y1 * y1))) / 2);
  11086. var b = mathSqrt$3(it_1[0] * it_1[0] + it_1[1] * it_1[1]);
  11087. limitedOcrMax = mathMin$3(ocrMax, (radius - b) / (a + 1));
  11088. limitedIcrMax = mathMin$3(icrMax, (innerRadius - b) / (a - 1));
  11089. }
  11090. }
  11091. }
  11092. }
  11093. if (!hasArc) {
  11094. ctx.moveTo(cx + xrs, cy + yrs);
  11095. }
  11096. else if (limitedOcrMax > e) {
  11097. var crStart = mathMin$3(ocrStart, limitedOcrMax);
  11098. var crEnd = mathMin$3(ocrEnd, limitedOcrMax);
  11099. var ct0 = computeCornerTangents(xirs, yirs, xrs, yrs, radius, crStart, clockwise);
  11100. var ct1 = computeCornerTangents(xre, yre, xire, yire, radius, crEnd, clockwise);
  11101. ctx.moveTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  11102. if (limitedOcrMax < ocrMax && crStart === crEnd) {
  11103. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedOcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11104. }
  11105. else {
  11106. crStart > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crStart, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  11107. ctx.arc(cx, cy, radius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), !clockwise);
  11108. crEnd > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crEnd, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11109. }
  11110. }
  11111. else {
  11112. ctx.moveTo(cx + xrs, cy + yrs);
  11113. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  11114. }
  11115. if (!(innerRadius > e) || !hasArc) {
  11116. ctx.lineTo(cx + xire, cy + yire);
  11117. }
  11118. else if (limitedIcrMax > e) {
  11119. var crStart = mathMin$3(icrStart, limitedIcrMax);
  11120. var crEnd = mathMin$3(icrEnd, limitedIcrMax);
  11121. var ct0 = computeCornerTangents(xire, yire, xre, yre, innerRadius, -crEnd, clockwise);
  11122. var ct1 = computeCornerTangents(xrs, yrs, xirs, yirs, innerRadius, -crStart, clockwise);
  11123. ctx.lineTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  11124. if (limitedIcrMax < icrMax && crStart === crEnd) {
  11125. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedIcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11126. }
  11127. else {
  11128. crEnd > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crEnd, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  11129. ctx.arc(cx, cy, innerRadius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), clockwise);
  11130. crStart > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crStart, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11131. }
  11132. }
  11133. else {
  11134. ctx.lineTo(cx + xire, cy + yire);
  11135. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  11136. }
  11137. }
  11138. ctx.closePath();
  11139. }
  11140. var SectorShape = (function () {
  11141. function SectorShape() {
  11142. this.cx = 0;
  11143. this.cy = 0;
  11144. this.r0 = 0;
  11145. this.r = 0;
  11146. this.startAngle = 0;
  11147. this.endAngle = Math.PI * 2;
  11148. this.clockwise = true;
  11149. this.cornerRadius = 0;
  11150. }
  11151. return SectorShape;
  11152. }());
  11153. var Sector = (function (_super) {
  11154. __extends(Sector, _super);
  11155. function Sector(opts) {
  11156. return _super.call(this, opts) || this;
  11157. }
  11158. Sector.prototype.getDefaultShape = function () {
  11159. return new SectorShape();
  11160. };
  11161. Sector.prototype.buildPath = function (ctx, shape) {
  11162. buildPath$2(ctx, shape);
  11163. };
  11164. Sector.prototype.isZeroArea = function () {
  11165. return this.shape.startAngle === this.shape.endAngle
  11166. || this.shape.r === this.shape.r0;
  11167. };
  11168. return Sector;
  11169. }(Path));
  11170. Sector.prototype.type = 'sector';
  11171. var CMD$3 = PathProxy.CMD;
  11172. function aroundEqual(a, b) {
  11173. return Math.abs(a - b) < 1e-5;
  11174. }
  11175. function pathToBezierCurves(path) {
  11176. var data = path.data;
  11177. var len = path.len();
  11178. var bezierArrayGroups = [];
  11179. var currentSubpath;
  11180. var xi = 0;
  11181. var yi = 0;
  11182. var x0 = 0;
  11183. var y0 = 0;
  11184. function createNewSubpath(x, y) {
  11185. if (currentSubpath && currentSubpath.length > 2) {
  11186. bezierArrayGroups.push(currentSubpath);
  11187. }
  11188. currentSubpath = [x, y];
  11189. }
  11190. function addLine(x0, y0, x1, y1) {
  11191. if (!(aroundEqual(x0, x1) && aroundEqual(y0, y1))) {
  11192. currentSubpath.push(x0, y0, x1, y1, x1, y1);
  11193. }
  11194. }
  11195. function addArc(startAngle, endAngle, cx, cy, rx, ry) {
  11196. var delta = Math.abs(endAngle - startAngle);
  11197. var len = Math.tan(delta / 4) * 4 / 3;
  11198. var dir = endAngle < startAngle ? -1 : 1;
  11199. var c1 = Math.cos(startAngle);
  11200. var s1 = Math.sin(startAngle);
  11201. var c2 = Math.cos(endAngle);
  11202. var s2 = Math.sin(endAngle);
  11203. var x1 = c1 * rx + cx;
  11204. var y1 = s1 * ry + cy;
  11205. var x4 = c2 * rx + cx;
  11206. var y4 = s2 * ry + cy;
  11207. var hx = rx * len * dir;
  11208. var hy = ry * len * dir;
  11209. currentSubpath.push(x1 - hx * s1, y1 + hy * c1, x4 + hx * s2, y4 - hy * c2, x4, y4);
  11210. }
  11211. var x1;
  11212. var y1;
  11213. var x2;
  11214. var y2;
  11215. for (var i = 0; i < len;) {
  11216. var cmd = data[i++];
  11217. var isFirst = i === 1;
  11218. if (isFirst) {
  11219. xi = data[i];
  11220. yi = data[i + 1];
  11221. x0 = xi;
  11222. y0 = yi;
  11223. if (cmd === CMD$3.L || cmd === CMD$3.C || cmd === CMD$3.Q) {
  11224. currentSubpath = [x0, y0];
  11225. }
  11226. }
  11227. switch (cmd) {
  11228. case CMD$3.M:
  11229. xi = x0 = data[i++];
  11230. yi = y0 = data[i++];
  11231. createNewSubpath(x0, y0);
  11232. break;
  11233. case CMD$3.L:
  11234. x1 = data[i++];
  11235. y1 = data[i++];
  11236. addLine(xi, yi, x1, y1);
  11237. xi = x1;
  11238. yi = y1;
  11239. break;
  11240. case CMD$3.C:
  11241. currentSubpath.push(data[i++], data[i++], data[i++], data[i++], xi = data[i++], yi = data[i++]);
  11242. break;
  11243. case CMD$3.Q:
  11244. x1 = data[i++];
  11245. y1 = data[i++];
  11246. x2 = data[i++];
  11247. y2 = data[i++];
  11248. currentSubpath.push(xi + 2 / 3 * (x1 - xi), yi + 2 / 3 * (y1 - yi), x2 + 2 / 3 * (x1 - x2), y2 + 2 / 3 * (y1 - y2), x2, y2);
  11249. xi = x2;
  11250. yi = y2;
  11251. break;
  11252. case CMD$3.A:
  11253. var cx = data[i++];
  11254. var cy = data[i++];
  11255. var rx = data[i++];
  11256. var ry = data[i++];
  11257. var startAngle = data[i++];
  11258. var endAngle = data[i++] + startAngle;
  11259. i += 1;
  11260. var anticlockwise = !data[i++];
  11261. x1 = Math.cos(startAngle) * rx + cx;
  11262. y1 = Math.sin(startAngle) * ry + cy;
  11263. if (isFirst) {
  11264. x0 = x1;
  11265. y0 = y1;
  11266. createNewSubpath(x0, y0);
  11267. }
  11268. else {
  11269. addLine(xi, yi, x1, y1);
  11270. }
  11271. xi = Math.cos(endAngle) * rx + cx;
  11272. yi = Math.sin(endAngle) * ry + cy;
  11273. var step = (anticlockwise ? -1 : 1) * Math.PI / 2;
  11274. for (var angle = startAngle; anticlockwise ? angle > endAngle : angle < endAngle; angle += step) {
  11275. var nextAngle = anticlockwise ? Math.max(angle + step, endAngle)
  11276. : Math.min(angle + step, endAngle);
  11277. addArc(angle, nextAngle, cx, cy, rx, ry);
  11278. }
  11279. break;
  11280. case CMD$3.R:
  11281. x0 = xi = data[i++];
  11282. y0 = yi = data[i++];
  11283. x1 = x0 + data[i++];
  11284. y1 = y0 + data[i++];
  11285. createNewSubpath(x1, y0);
  11286. addLine(x1, y0, x1, y1);
  11287. addLine(x1, y1, x0, y1);
  11288. addLine(x0, y1, x0, y0);
  11289. addLine(x0, y0, x1, y0);
  11290. break;
  11291. case CMD$3.Z:
  11292. currentSubpath && addLine(xi, yi, x0, y0);
  11293. xi = x0;
  11294. yi = y0;
  11295. break;
  11296. }
  11297. }
  11298. if (currentSubpath && currentSubpath.length > 2) {
  11299. bezierArrayGroups.push(currentSubpath);
  11300. }
  11301. return bezierArrayGroups;
  11302. }
  11303. function adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, out, scale) {
  11304. if (aroundEqual(x0, x1) && aroundEqual(y0, y1) && aroundEqual(x2, x3) && aroundEqual(y2, y3)) {
  11305. out.push(x3, y3);
  11306. return;
  11307. }
  11308. var PIXEL_DISTANCE = 2 / scale;
  11309. var PIXEL_DISTANCE_SQR = PIXEL_DISTANCE * PIXEL_DISTANCE;
  11310. var dx = x3 - x0;
  11311. var dy = y3 - y0;
  11312. var d = Math.sqrt(dx * dx + dy * dy);
  11313. dx /= d;
  11314. dy /= d;
  11315. var dx1 = x1 - x0;
  11316. var dy1 = y1 - y0;
  11317. var dx2 = x2 - x3;
  11318. var dy2 = y2 - y3;
  11319. var cp1LenSqr = dx1 * dx1 + dy1 * dy1;
  11320. var cp2LenSqr = dx2 * dx2 + dy2 * dy2;
  11321. if (cp1LenSqr < PIXEL_DISTANCE_SQR && cp2LenSqr < PIXEL_DISTANCE_SQR) {
  11322. out.push(x3, y3);
  11323. return;
  11324. }
  11325. var projLen1 = dx * dx1 + dy * dy1;
  11326. var projLen2 = -dx * dx2 - dy * dy2;
  11327. var d1Sqr = cp1LenSqr - projLen1 * projLen1;
  11328. var d2Sqr = cp2LenSqr - projLen2 * projLen2;
  11329. if (d1Sqr < PIXEL_DISTANCE_SQR && projLen1 >= 0
  11330. && d2Sqr < PIXEL_DISTANCE_SQR && projLen2 >= 0) {
  11331. out.push(x3, y3);
  11332. return;
  11333. }
  11334. var tmpSegX = [];
  11335. var tmpSegY = [];
  11336. cubicSubdivide(x0, x1, x2, x3, 0.5, tmpSegX);
  11337. cubicSubdivide(y0, y1, y2, y3, 0.5, tmpSegY);
  11338. adpativeBezier(tmpSegX[0], tmpSegY[0], tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], tmpSegX[3], tmpSegY[3], out, scale);
  11339. adpativeBezier(tmpSegX[4], tmpSegY[4], tmpSegX[5], tmpSegY[5], tmpSegX[6], tmpSegY[6], tmpSegX[7], tmpSegY[7], out, scale);
  11340. }
  11341. function pathToPolygons(path, scale) {
  11342. var bezierArrayGroups = pathToBezierCurves(path);
  11343. var polygons = [];
  11344. scale = scale || 1;
  11345. for (var i = 0; i < bezierArrayGroups.length; i++) {
  11346. var beziers = bezierArrayGroups[i];
  11347. var polygon = [];
  11348. var x0 = beziers[0];
  11349. var y0 = beziers[1];
  11350. polygon.push(x0, y0);
  11351. for (var k = 2; k < beziers.length;) {
  11352. var x1 = beziers[k++];
  11353. var y1 = beziers[k++];
  11354. var x2 = beziers[k++];
  11355. var y2 = beziers[k++];
  11356. var x3 = beziers[k++];
  11357. var y3 = beziers[k++];
  11358. adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, polygon, scale);
  11359. x0 = x3;
  11360. y0 = y3;
  11361. }
  11362. polygons.push(polygon);
  11363. }
  11364. return polygons;
  11365. }
  11366. function getDividingGrids(dimSize, rowDim, count) {
  11367. var rowSize = dimSize[rowDim];
  11368. var columnSize = dimSize[1 - rowDim];
  11369. var ratio = Math.abs(rowSize / columnSize);
  11370. var rowCount = Math.ceil(Math.sqrt(ratio * count));
  11371. var columnCount = Math.floor(count / rowCount);
  11372. if (columnCount === 0) {
  11373. columnCount = 1;
  11374. rowCount = count;
  11375. }
  11376. var grids = [];
  11377. for (var i = 0; i < rowCount; i++) {
  11378. grids.push(columnCount);
  11379. }
  11380. var currentCount = rowCount * columnCount;
  11381. var remained = count - currentCount;
  11382. if (remained > 0) {
  11383. for (var i = 0; i < remained; i++) {
  11384. grids[i % rowCount] += 1;
  11385. }
  11386. }
  11387. return grids;
  11388. }
  11389. function divideSector(sectorShape, count, outShapes) {
  11390. var r0 = sectorShape.r0;
  11391. var r = sectorShape.r;
  11392. var startAngle = sectorShape.startAngle;
  11393. var endAngle = sectorShape.endAngle;
  11394. var angle = Math.abs(endAngle - startAngle);
  11395. var arcLen = angle * r;
  11396. var deltaR = r - r0;
  11397. var isAngleRow = arcLen > Math.abs(deltaR);
  11398. var grids = getDividingGrids([arcLen, deltaR], isAngleRow ? 0 : 1, count);
  11399. var rowSize = (isAngleRow ? angle : deltaR) / grids.length;
  11400. for (var row = 0; row < grids.length; row++) {
  11401. var columnSize = (isAngleRow ? deltaR : angle) / grids[row];
  11402. for (var column = 0; column < grids[row]; column++) {
  11403. var newShape = {};
  11404. if (isAngleRow) {
  11405. newShape.startAngle = startAngle + rowSize * row;
  11406. newShape.endAngle = startAngle + rowSize * (row + 1);
  11407. newShape.r0 = r0 + columnSize * column;
  11408. newShape.r = r0 + columnSize * (column + 1);
  11409. }
  11410. else {
  11411. newShape.startAngle = startAngle + columnSize * column;
  11412. newShape.endAngle = startAngle + columnSize * (column + 1);
  11413. newShape.r0 = r0 + rowSize * row;
  11414. newShape.r = r0 + rowSize * (row + 1);
  11415. }
  11416. newShape.clockwise = sectorShape.clockwise;
  11417. newShape.cx = sectorShape.cx;
  11418. newShape.cy = sectorShape.cy;
  11419. outShapes.push(newShape);
  11420. }
  11421. }
  11422. }
  11423. function divideRect(rectShape, count, outShapes) {
  11424. var width = rectShape.width;
  11425. var height = rectShape.height;
  11426. var isHorizontalRow = width > height;
  11427. var grids = getDividingGrids([width, height], isHorizontalRow ? 0 : 1, count);
  11428. var rowSizeDim = isHorizontalRow ? 'width' : 'height';
  11429. var columnSizeDim = isHorizontalRow ? 'height' : 'width';
  11430. var rowDim = isHorizontalRow ? 'x' : 'y';
  11431. var columnDim = isHorizontalRow ? 'y' : 'x';
  11432. var rowSize = rectShape[rowSizeDim] / grids.length;
  11433. for (var row = 0; row < grids.length; row++) {
  11434. var columnSize = rectShape[columnSizeDim] / grids[row];
  11435. for (var column = 0; column < grids[row]; column++) {
  11436. var newShape = {};
  11437. newShape[rowDim] = row * rowSize;
  11438. newShape[columnDim] = column * columnSize;
  11439. newShape[rowSizeDim] = rowSize;
  11440. newShape[columnSizeDim] = columnSize;
  11441. newShape.x += rectShape.x;
  11442. newShape.y += rectShape.y;
  11443. outShapes.push(newShape);
  11444. }
  11445. }
  11446. }
  11447. function crossProduct2d(x1, y1, x2, y2) {
  11448. return x1 * y2 - x2 * y1;
  11449. }
  11450. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  11451. var mx = a2x - a1x;
  11452. var my = a2y - a1y;
  11453. var nx = b2x - b1x;
  11454. var ny = b2y - b1y;
  11455. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  11456. if (Math.abs(nmCrossProduct) < 1e-6) {
  11457. return null;
  11458. }
  11459. var b1a1x = a1x - b1x;
  11460. var b1a1y = a1y - b1y;
  11461. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  11462. if (p < 0 || p > 1) {
  11463. return null;
  11464. }
  11465. return new Point(p * mx + a1x, p * my + a1y);
  11466. }
  11467. function projPtOnLine(pt, lineA, lineB) {
  11468. var dir = new Point();
  11469. Point.sub(dir, lineB, lineA);
  11470. dir.normalize();
  11471. var dir2 = new Point();
  11472. Point.sub(dir2, pt, lineA);
  11473. var len = dir2.dot(dir);
  11474. return len;
  11475. }
  11476. function addToPoly(poly, pt) {
  11477. var last = poly[poly.length - 1];
  11478. if (last && last[0] === pt[0] && last[1] === pt[1]) {
  11479. return;
  11480. }
  11481. poly.push(pt);
  11482. }
  11483. function splitPolygonByLine(points, lineA, lineB) {
  11484. var len = points.length;
  11485. var intersections = [];
  11486. for (var i = 0; i < len; i++) {
  11487. var p0 = points[i];
  11488. var p1 = points[(i + 1) % len];
  11489. var intersectionPt = lineLineIntersect(p0[0], p0[1], p1[0], p1[1], lineA.x, lineA.y, lineB.x, lineB.y);
  11490. if (intersectionPt) {
  11491. intersections.push({
  11492. projPt: projPtOnLine(intersectionPt, lineA, lineB),
  11493. pt: intersectionPt,
  11494. idx: i
  11495. });
  11496. }
  11497. }
  11498. if (intersections.length < 2) {
  11499. return [{ points: points }, { points: points }];
  11500. }
  11501. intersections.sort(function (a, b) {
  11502. return a.projPt - b.projPt;
  11503. });
  11504. var splitPt0 = intersections[0];
  11505. var splitPt1 = intersections[intersections.length - 1];
  11506. if (splitPt1.idx < splitPt0.idx) {
  11507. var tmp = splitPt0;
  11508. splitPt0 = splitPt1;
  11509. splitPt1 = tmp;
  11510. }
  11511. var splitPt0Arr = [splitPt0.pt.x, splitPt0.pt.y];
  11512. var splitPt1Arr = [splitPt1.pt.x, splitPt1.pt.y];
  11513. var newPolyA = [splitPt0Arr];
  11514. var newPolyB = [splitPt1Arr];
  11515. for (var i = splitPt0.idx + 1; i <= splitPt1.idx; i++) {
  11516. addToPoly(newPolyA, points[i].slice());
  11517. }
  11518. addToPoly(newPolyA, splitPt1Arr);
  11519. addToPoly(newPolyA, splitPt0Arr);
  11520. for (var i = splitPt1.idx + 1; i <= splitPt0.idx + len; i++) {
  11521. addToPoly(newPolyB, points[i % len].slice());
  11522. }
  11523. addToPoly(newPolyB, splitPt0Arr);
  11524. addToPoly(newPolyB, splitPt1Arr);
  11525. return [{
  11526. points: newPolyA
  11527. }, {
  11528. points: newPolyB
  11529. }];
  11530. }
  11531. function binaryDividePolygon(polygonShape) {
  11532. var points = polygonShape.points;
  11533. var min = [];
  11534. var max = [];
  11535. fromPoints(points, min, max);
  11536. var boundingRect = new BoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  11537. var width = boundingRect.width;
  11538. var height = boundingRect.height;
  11539. var x = boundingRect.x;
  11540. var y = boundingRect.y;
  11541. var pt0 = new Point();
  11542. var pt1 = new Point();
  11543. if (width > height) {
  11544. pt0.x = pt1.x = x + width / 2;
  11545. pt0.y = y;
  11546. pt1.y = y + height;
  11547. }
  11548. else {
  11549. pt0.y = pt1.y = y + height / 2;
  11550. pt0.x = x;
  11551. pt1.x = x + width;
  11552. }
  11553. return splitPolygonByLine(points, pt0, pt1);
  11554. }
  11555. function binaryDivideRecursive(divider, shape, count, out) {
  11556. if (count === 1) {
  11557. out.push(shape);
  11558. }
  11559. else {
  11560. var mid = Math.floor(count / 2);
  11561. var sub = divider(shape);
  11562. binaryDivideRecursive(divider, sub[0], mid, out);
  11563. binaryDivideRecursive(divider, sub[1], count - mid, out);
  11564. }
  11565. return out;
  11566. }
  11567. function clone$3(path, count) {
  11568. var paths = [];
  11569. for (var i = 0; i < count; i++) {
  11570. paths.push(clonePath(path));
  11571. }
  11572. return paths;
  11573. }
  11574. function copyPathProps(source, target) {
  11575. target.setStyle(source.style);
  11576. target.z = source.z;
  11577. target.z2 = source.z2;
  11578. target.zlevel = source.zlevel;
  11579. }
  11580. function polygonConvert(points) {
  11581. var out = [];
  11582. for (var i = 0; i < points.length;) {
  11583. out.push([points[i++], points[i++]]);
  11584. }
  11585. return out;
  11586. }
  11587. function split(path, count) {
  11588. var outShapes = [];
  11589. var shape = path.shape;
  11590. var OutShapeCtor;
  11591. switch (path.type) {
  11592. case 'rect':
  11593. divideRect(shape, count, outShapes);
  11594. OutShapeCtor = Rect;
  11595. break;
  11596. case 'sector':
  11597. divideSector(shape, count, outShapes);
  11598. OutShapeCtor = Sector;
  11599. break;
  11600. case 'circle':
  11601. divideSector({
  11602. r0: 0, r: shape.r, startAngle: 0, endAngle: Math.PI * 2,
  11603. cx: shape.cx, cy: shape.cy
  11604. }, count, outShapes);
  11605. OutShapeCtor = Sector;
  11606. break;
  11607. default:
  11608. var m = path.getComputedTransform();
  11609. var scale = m ? Math.sqrt(Math.max(m[0] * m[0] + m[1] * m[1], m[2] * m[2] + m[3] * m[3])) : 1;
  11610. var polygons = map(pathToPolygons(path.getUpdatedPathProxy(), scale), function (poly) { return polygonConvert(poly); });
  11611. var polygonCount = polygons.length;
  11612. if (polygonCount === 0) {
  11613. binaryDivideRecursive(binaryDividePolygon, {
  11614. points: polygons[0]
  11615. }, count, outShapes);
  11616. }
  11617. else if (polygonCount === count) {
  11618. for (var i = 0; i < polygonCount; i++) {
  11619. outShapes.push({
  11620. points: polygons[i]
  11621. });
  11622. }
  11623. }
  11624. else {
  11625. var totalArea_1 = 0;
  11626. var items = map(polygons, function (poly) {
  11627. var min = [];
  11628. var max = [];
  11629. fromPoints(poly, min, max);
  11630. var area = (max[1] - min[1]) * (max[0] - min[0]);
  11631. totalArea_1 += area;
  11632. return { poly: poly, area: area };
  11633. });
  11634. items.sort(function (a, b) { return b.area - a.area; });
  11635. var left = count;
  11636. for (var i = 0; i < polygonCount; i++) {
  11637. var item = items[i];
  11638. if (left <= 0) {
  11639. break;
  11640. }
  11641. var selfCount = i === polygonCount - 1
  11642. ? left
  11643. : Math.ceil(item.area / totalArea_1 * count);
  11644. if (selfCount < 0) {
  11645. continue;
  11646. }
  11647. binaryDivideRecursive(binaryDividePolygon, {
  11648. points: item.poly
  11649. }, selfCount, outShapes);
  11650. left -= selfCount;
  11651. }
  11652. }
  11653. OutShapeCtor = Polygon;
  11654. break;
  11655. }
  11656. if (!OutShapeCtor) {
  11657. return clone$3(path, count);
  11658. }
  11659. var out = [];
  11660. for (var i = 0; i < outShapes.length; i++) {
  11661. var subPath = new OutShapeCtor();
  11662. subPath.setShape(outShapes[i]);
  11663. copyPathProps(path, subPath);
  11664. out.push(subPath);
  11665. }
  11666. return out;
  11667. }
  11668. function alignSubpath(subpath1, subpath2) {
  11669. var len1 = subpath1.length;
  11670. var len2 = subpath2.length;
  11671. if (len1 === len2) {
  11672. return [subpath1, subpath2];
  11673. }
  11674. var tmpSegX = [];
  11675. var tmpSegY = [];
  11676. var shorterPath = len1 < len2 ? subpath1 : subpath2;
  11677. var shorterLen = Math.min(len1, len2);
  11678. var diff = Math.abs(len2 - len1) / 6;
  11679. var shorterBezierCount = (shorterLen - 2) / 6;
  11680. var eachCurveSubDivCount = Math.ceil(diff / shorterBezierCount) + 1;
  11681. var newSubpath = [shorterPath[0], shorterPath[1]];
  11682. var remained = diff;
  11683. for (var i = 2; i < shorterLen;) {
  11684. var x0 = shorterPath[i - 2];
  11685. var y0 = shorterPath[i - 1];
  11686. var x1 = shorterPath[i++];
  11687. var y1 = shorterPath[i++];
  11688. var x2 = shorterPath[i++];
  11689. var y2 = shorterPath[i++];
  11690. var x3 = shorterPath[i++];
  11691. var y3 = shorterPath[i++];
  11692. if (remained <= 0) {
  11693. newSubpath.push(x1, y1, x2, y2, x3, y3);
  11694. continue;
  11695. }
  11696. var actualSubDivCount = Math.min(remained, eachCurveSubDivCount - 1) + 1;
  11697. for (var k = 1; k <= actualSubDivCount; k++) {
  11698. var p = k / actualSubDivCount;
  11699. cubicSubdivide(x0, x1, x2, x3, p, tmpSegX);
  11700. cubicSubdivide(y0, y1, y2, y3, p, tmpSegY);
  11701. x0 = tmpSegX[3];
  11702. y0 = tmpSegY[3];
  11703. newSubpath.push(tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], x0, y0);
  11704. x1 = tmpSegX[5];
  11705. y1 = tmpSegY[5];
  11706. x2 = tmpSegX[6];
  11707. y2 = tmpSegY[6];
  11708. }
  11709. remained -= actualSubDivCount - 1;
  11710. }
  11711. return shorterPath === subpath1 ? [newSubpath, subpath2] : [subpath1, newSubpath];
  11712. }
  11713. function createSubpath(lastSubpathSubpath, otherSubpath) {
  11714. var len = lastSubpathSubpath.length;
  11715. var lastX = lastSubpathSubpath[len - 2];
  11716. var lastY = lastSubpathSubpath[len - 1];
  11717. var newSubpath = [];
  11718. for (var i = 0; i < otherSubpath.length;) {
  11719. newSubpath[i++] = lastX;
  11720. newSubpath[i++] = lastY;
  11721. }
  11722. return newSubpath;
  11723. }
  11724. function alignBezierCurves(array1, array2) {
  11725. var _a;
  11726. var lastSubpath1;
  11727. var lastSubpath2;
  11728. var newArray1 = [];
  11729. var newArray2 = [];
  11730. for (var i = 0; i < Math.max(array1.length, array2.length); i++) {
  11731. var subpath1 = array1[i];
  11732. var subpath2 = array2[i];
  11733. var newSubpath1 = void 0;
  11734. var newSubpath2 = void 0;
  11735. if (!subpath1) {
  11736. newSubpath1 = createSubpath(lastSubpath1 || subpath2, subpath2);
  11737. newSubpath2 = subpath2;
  11738. }
  11739. else if (!subpath2) {
  11740. newSubpath2 = createSubpath(lastSubpath2 || subpath1, subpath1);
  11741. newSubpath1 = subpath1;
  11742. }
  11743. else {
  11744. _a = alignSubpath(subpath1, subpath2), newSubpath1 = _a[0], newSubpath2 = _a[1];
  11745. lastSubpath1 = newSubpath1;
  11746. lastSubpath2 = newSubpath2;
  11747. }
  11748. newArray1.push(newSubpath1);
  11749. newArray2.push(newSubpath2);
  11750. }
  11751. return [newArray1, newArray2];
  11752. }
  11753. function centroid(array) {
  11754. var signedArea = 0;
  11755. var cx = 0;
  11756. var cy = 0;
  11757. var len = array.length;
  11758. for (var i = 0, j = len - 2; i < len; j = i, i += 2) {
  11759. var x0 = array[j];
  11760. var y0 = array[j + 1];
  11761. var x1 = array[i];
  11762. var y1 = array[i + 1];
  11763. var a = x0 * y1 - x1 * y0;
  11764. signedArea += a;
  11765. cx += (x0 + x1) * a;
  11766. cy += (y0 + y1) * a;
  11767. }
  11768. if (signedArea === 0) {
  11769. return [array[0] || 0, array[1] || 0];
  11770. }
  11771. return [cx / signedArea / 3, cy / signedArea / 3, signedArea];
  11772. }
  11773. function findBestRingOffset(fromSubBeziers, toSubBeziers, fromCp, toCp) {
  11774. var bezierCount = (fromSubBeziers.length - 2) / 6;
  11775. var bestScore = Infinity;
  11776. var bestOffset = 0;
  11777. var len = fromSubBeziers.length;
  11778. var len2 = len - 2;
  11779. for (var offset = 0; offset < bezierCount; offset++) {
  11780. var cursorOffset = offset * 6;
  11781. var score = 0;
  11782. for (var k = 0; k < len; k += 2) {
  11783. var idx = k === 0 ? cursorOffset : ((cursorOffset + k - 2) % len2 + 2);
  11784. var x0 = fromSubBeziers[idx] - fromCp[0];
  11785. var y0 = fromSubBeziers[idx + 1] - fromCp[1];
  11786. var x1 = toSubBeziers[k] - toCp[0];
  11787. var y1 = toSubBeziers[k + 1] - toCp[1];
  11788. var dx = x1 - x0;
  11789. var dy = y1 - y0;
  11790. score += dx * dx + dy * dy;
  11791. }
  11792. if (score < bestScore) {
  11793. bestScore = score;
  11794. bestOffset = offset;
  11795. }
  11796. }
  11797. return bestOffset;
  11798. }
  11799. function reverse(array) {
  11800. var newArr = [];
  11801. var len = array.length;
  11802. for (var i = 0; i < len; i += 2) {
  11803. newArr[i] = array[len - i - 2];
  11804. newArr[i + 1] = array[len - i - 1];
  11805. }
  11806. return newArr;
  11807. }
  11808. function findBestMorphingRotation(fromArr, toArr, searchAngleIteration, searchAngleRange) {
  11809. var result = [];
  11810. var fromNeedsReverse;
  11811. for (var i = 0; i < fromArr.length; i++) {
  11812. var fromSubpathBezier = fromArr[i];
  11813. var toSubpathBezier = toArr[i];
  11814. var fromCp = centroid(fromSubpathBezier);
  11815. var toCp = centroid(toSubpathBezier);
  11816. if (fromNeedsReverse == null) {
  11817. fromNeedsReverse = fromCp[2] < 0 !== toCp[2] < 0;
  11818. }
  11819. var newFromSubpathBezier = [];
  11820. var newToSubpathBezier = [];
  11821. var bestAngle = 0;
  11822. var bestScore = Infinity;
  11823. var tmpArr = [];
  11824. var len = fromSubpathBezier.length;
  11825. if (fromNeedsReverse) {
  11826. fromSubpathBezier = reverse(fromSubpathBezier);
  11827. }
  11828. var offset = findBestRingOffset(fromSubpathBezier, toSubpathBezier, fromCp, toCp) * 6;
  11829. var len2 = len - 2;
  11830. for (var k = 0; k < len2; k += 2) {
  11831. var idx = (offset + k) % len2 + 2;
  11832. newFromSubpathBezier[k + 2] = fromSubpathBezier[idx] - fromCp[0];
  11833. newFromSubpathBezier[k + 3] = fromSubpathBezier[idx + 1] - fromCp[1];
  11834. }
  11835. newFromSubpathBezier[0] = fromSubpathBezier[offset] - fromCp[0];
  11836. newFromSubpathBezier[1] = fromSubpathBezier[offset + 1] - fromCp[1];
  11837. if (searchAngleIteration > 0) {
  11838. var step = searchAngleRange / searchAngleIteration;
  11839. for (var angle = -searchAngleRange / 2; angle <= searchAngleRange / 2; angle += step) {
  11840. var sa = Math.sin(angle);
  11841. var ca = Math.cos(angle);
  11842. var score = 0;
  11843. for (var k = 0; k < fromSubpathBezier.length; k += 2) {
  11844. var x0 = newFromSubpathBezier[k];
  11845. var y0 = newFromSubpathBezier[k + 1];
  11846. var x1 = toSubpathBezier[k] - toCp[0];
  11847. var y1 = toSubpathBezier[k + 1] - toCp[1];
  11848. var newX1 = x1 * ca - y1 * sa;
  11849. var newY1 = x1 * sa + y1 * ca;
  11850. tmpArr[k] = newX1;
  11851. tmpArr[k + 1] = newY1;
  11852. var dx = newX1 - x0;
  11853. var dy = newY1 - y0;
  11854. score += dx * dx + dy * dy;
  11855. }
  11856. if (score < bestScore) {
  11857. bestScore = score;
  11858. bestAngle = angle;
  11859. for (var m = 0; m < tmpArr.length; m++) {
  11860. newToSubpathBezier[m] = tmpArr[m];
  11861. }
  11862. }
  11863. }
  11864. }
  11865. else {
  11866. for (var i_1 = 0; i_1 < len; i_1 += 2) {
  11867. newToSubpathBezier[i_1] = toSubpathBezier[i_1] - toCp[0];
  11868. newToSubpathBezier[i_1 + 1] = toSubpathBezier[i_1 + 1] - toCp[1];
  11869. }
  11870. }
  11871. result.push({
  11872. from: newFromSubpathBezier,
  11873. to: newToSubpathBezier,
  11874. fromCp: fromCp,
  11875. toCp: toCp,
  11876. rotation: -bestAngle
  11877. });
  11878. }
  11879. return result;
  11880. }
  11881. function isCombineMorphing(path) {
  11882. return path.__isCombineMorphing;
  11883. }
  11884. function isMorphing(el) {
  11885. return el.__morphT >= 0;
  11886. }
  11887. var SAVED_METHOD_PREFIX = '__mOriginal_';
  11888. function saveAndModifyMethod(obj, methodName, modifiers) {
  11889. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  11890. var originalMethod = obj[savedMethodName] || obj[methodName];
  11891. if (!obj[savedMethodName]) {
  11892. obj[savedMethodName] = obj[methodName];
  11893. }
  11894. var replace = modifiers.replace;
  11895. var after = modifiers.after;
  11896. var before = modifiers.before;
  11897. obj[methodName] = function () {
  11898. var args = arguments;
  11899. var res;
  11900. before && before.apply(this, args);
  11901. if (replace) {
  11902. res = replace.apply(this, args);
  11903. }
  11904. else {
  11905. res = originalMethod.apply(this, args);
  11906. }
  11907. after && after.apply(this, args);
  11908. return res;
  11909. };
  11910. }
  11911. function restoreMethod(obj, methodName) {
  11912. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  11913. if (obj[savedMethodName]) {
  11914. obj[methodName] = obj[savedMethodName];
  11915. obj[savedMethodName] = null;
  11916. }
  11917. }
  11918. function applyTransformOnBeziers(bezierCurves, mm) {
  11919. for (var i = 0; i < bezierCurves.length; i++) {
  11920. var subBeziers = bezierCurves[i];
  11921. for (var k = 0; k < subBeziers.length;) {
  11922. var x = subBeziers[k];
  11923. var y = subBeziers[k + 1];
  11924. subBeziers[k++] = mm[0] * x + mm[2] * y + mm[4];
  11925. subBeziers[k++] = mm[1] * x + mm[3] * y + mm[5];
  11926. }
  11927. }
  11928. }
  11929. function prepareMorphPath(fromPath, toPath) {
  11930. var fromPathProxy = fromPath.getUpdatedPathProxy();
  11931. var toPathProxy = toPath.getUpdatedPathProxy();
  11932. var _a = alignBezierCurves(pathToBezierCurves(fromPathProxy), pathToBezierCurves(toPathProxy)), fromBezierCurves = _a[0], toBezierCurves = _a[1];
  11933. var fromPathTransform = fromPath.getComputedTransform();
  11934. var toPathTransform = toPath.getComputedTransform();
  11935. function updateIdentityTransform() {
  11936. this.transform = null;
  11937. }
  11938. fromPathTransform && applyTransformOnBeziers(fromBezierCurves, fromPathTransform);
  11939. toPathTransform && applyTransformOnBeziers(toBezierCurves, toPathTransform);
  11940. saveAndModifyMethod(toPath, 'updateTransform', { replace: updateIdentityTransform });
  11941. toPath.transform = null;
  11942. var morphingData = findBestMorphingRotation(fromBezierCurves, toBezierCurves, 10, Math.PI);
  11943. var tmpArr = [];
  11944. saveAndModifyMethod(toPath, 'buildPath', { replace: function (path) {
  11945. var t = toPath.__morphT;
  11946. var onet = 1 - t;
  11947. var newCp = [];
  11948. for (var i = 0; i < morphingData.length; i++) {
  11949. var item = morphingData[i];
  11950. var from = item.from;
  11951. var to = item.to;
  11952. var angle = item.rotation * t;
  11953. var fromCp = item.fromCp;
  11954. var toCp = item.toCp;
  11955. var sa = Math.sin(angle);
  11956. var ca = Math.cos(angle);
  11957. lerp(newCp, fromCp, toCp, t);
  11958. for (var m = 0; m < from.length; m += 2) {
  11959. var x0_1 = from[m];
  11960. var y0_1 = from[m + 1];
  11961. var x1 = to[m];
  11962. var y1 = to[m + 1];
  11963. var x = x0_1 * onet + x1 * t;
  11964. var y = y0_1 * onet + y1 * t;
  11965. tmpArr[m] = (x * ca - y * sa) + newCp[0];
  11966. tmpArr[m + 1] = (x * sa + y * ca) + newCp[1];
  11967. }
  11968. var x0 = tmpArr[0];
  11969. var y0 = tmpArr[1];
  11970. path.moveTo(x0, y0);
  11971. for (var m = 2; m < from.length;) {
  11972. var x1 = tmpArr[m++];
  11973. var y1 = tmpArr[m++];
  11974. var x2 = tmpArr[m++];
  11975. var y2 = tmpArr[m++];
  11976. var x3 = tmpArr[m++];
  11977. var y3 = tmpArr[m++];
  11978. if (x0 === x1 && y0 === y1 && x2 === x3 && y2 === y3) {
  11979. path.lineTo(x3, y3);
  11980. }
  11981. else {
  11982. path.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11983. }
  11984. x0 = x3;
  11985. y0 = y3;
  11986. }
  11987. }
  11988. } });
  11989. }
  11990. function morphPath(fromPath, toPath, animationOpts) {
  11991. if (!fromPath || !toPath) {
  11992. return toPath;
  11993. }
  11994. var oldDone = animationOpts.done;
  11995. var oldDuring = animationOpts.during;
  11996. prepareMorphPath(fromPath, toPath);
  11997. toPath.__morphT = 0;
  11998. function restoreToPath() {
  11999. restoreMethod(toPath, 'buildPath');
  12000. restoreMethod(toPath, 'updateTransform');
  12001. toPath.__morphT = -1;
  12002. toPath.createPathProxy();
  12003. toPath.dirtyShape();
  12004. }
  12005. toPath.animateTo({
  12006. __morphT: 1
  12007. }, defaults({
  12008. during: function (p) {
  12009. toPath.dirtyShape();
  12010. oldDuring && oldDuring(p);
  12011. },
  12012. done: function () {
  12013. restoreToPath();
  12014. oldDone && oldDone();
  12015. }
  12016. }, animationOpts));
  12017. return toPath;
  12018. }
  12019. function hilbert(x, y, minX, minY, maxX, maxY) {
  12020. var bits = 16;
  12021. x = (maxX === minX) ? 0 : Math.round(32767 * (x - minX) / (maxX - minX));
  12022. y = (maxY === minY) ? 0 : Math.round(32767 * (y - minY) / (maxY - minY));
  12023. var d = 0;
  12024. var tmp;
  12025. for (var s = (1 << bits) / 2; s > 0; s /= 2) {
  12026. var rx = 0;
  12027. var ry = 0;
  12028. if ((x & s) > 0) {
  12029. rx = 1;
  12030. }
  12031. if ((y & s) > 0) {
  12032. ry = 1;
  12033. }
  12034. d += s * s * ((3 * rx) ^ ry);
  12035. if (ry === 0) {
  12036. if (rx === 1) {
  12037. x = s - 1 - x;
  12038. y = s - 1 - y;
  12039. }
  12040. tmp = x;
  12041. x = y;
  12042. y = tmp;
  12043. }
  12044. }
  12045. return d;
  12046. }
  12047. function sortPaths(pathList) {
  12048. var xMin = Infinity;
  12049. var yMin = Infinity;
  12050. var xMax = -Infinity;
  12051. var yMax = -Infinity;
  12052. var cps = map(pathList, function (path) {
  12053. var rect = path.getBoundingRect();
  12054. var m = path.getComputedTransform();
  12055. var x = rect.x + rect.width / 2 + (m ? m[4] : 0);
  12056. var y = rect.y + rect.height / 2 + (m ? m[5] : 0);
  12057. xMin = Math.min(x, xMin);
  12058. yMin = Math.min(y, yMin);
  12059. xMax = Math.max(x, xMax);
  12060. yMax = Math.max(y, yMax);
  12061. return [x, y];
  12062. });
  12063. var items = map(cps, function (cp, idx) {
  12064. return {
  12065. cp: cp,
  12066. z: hilbert(cp[0], cp[1], xMin, yMin, xMax, yMax),
  12067. path: pathList[idx]
  12068. };
  12069. });
  12070. return items.sort(function (a, b) { return a.z - b.z; }).map(function (item) { return item.path; });
  12071. }
  12072. function defaultDividePath(param) {
  12073. return split(param.path, param.count);
  12074. }
  12075. function createEmptyReturn() {
  12076. return {
  12077. fromIndividuals: [],
  12078. toIndividuals: [],
  12079. count: 0
  12080. };
  12081. }
  12082. function combineMorph(fromList, toPath, animationOpts) {
  12083. var fromPathList = [];
  12084. function addFromPath(fromList) {
  12085. for (var i = 0; i < fromList.length; i++) {
  12086. var from = fromList[i];
  12087. if (isCombineMorphing(from)) {
  12088. addFromPath(from.childrenRef());
  12089. }
  12090. else if (from instanceof Path) {
  12091. fromPathList.push(from);
  12092. }
  12093. }
  12094. }
  12095. addFromPath(fromList);
  12096. var separateCount = fromPathList.length;
  12097. if (!separateCount) {
  12098. return createEmptyReturn();
  12099. }
  12100. var dividePath = animationOpts.dividePath || defaultDividePath;
  12101. var toSubPathList = dividePath({
  12102. path: toPath, count: separateCount
  12103. });
  12104. if (toSubPathList.length !== separateCount) {
  12105. console.error('Invalid morphing: unmatched splitted path');
  12106. return createEmptyReturn();
  12107. }
  12108. fromPathList = sortPaths(fromPathList);
  12109. toSubPathList = sortPaths(toSubPathList);
  12110. var oldDone = animationOpts.done;
  12111. var oldDuring = animationOpts.during;
  12112. var individualDelay = animationOpts.individualDelay;
  12113. var identityTransform = new Transformable();
  12114. for (var i = 0; i < separateCount; i++) {
  12115. var from = fromPathList[i];
  12116. var to = toSubPathList[i];
  12117. to.parent = toPath;
  12118. to.copyTransform(identityTransform);
  12119. if (!individualDelay) {
  12120. prepareMorphPath(from, to);
  12121. }
  12122. }
  12123. toPath.__isCombineMorphing = true;
  12124. toPath.childrenRef = function () {
  12125. return toSubPathList;
  12126. };
  12127. function addToSubPathListToZr(zr) {
  12128. for (var i = 0; i < toSubPathList.length; i++) {
  12129. toSubPathList[i].addSelfToZr(zr);
  12130. }
  12131. }
  12132. saveAndModifyMethod(toPath, 'addSelfToZr', {
  12133. after: function (zr) {
  12134. addToSubPathListToZr(zr);
  12135. }
  12136. });
  12137. saveAndModifyMethod(toPath, 'removeSelfFromZr', {
  12138. after: function (zr) {
  12139. for (var i = 0; i < toSubPathList.length; i++) {
  12140. toSubPathList[i].removeSelfFromZr(zr);
  12141. }
  12142. }
  12143. });
  12144. function restoreToPath() {
  12145. toPath.__isCombineMorphing = false;
  12146. toPath.__morphT = -1;
  12147. toPath.childrenRef = null;
  12148. restoreMethod(toPath, 'addSelfToZr');
  12149. restoreMethod(toPath, 'removeSelfFromZr');
  12150. }
  12151. var toLen = toSubPathList.length;
  12152. if (individualDelay) {
  12153. var animating_1 = toLen;
  12154. var eachDone = function () {
  12155. animating_1--;
  12156. if (animating_1 === 0) {
  12157. restoreToPath();
  12158. oldDone && oldDone();
  12159. }
  12160. };
  12161. for (var i = 0; i < toLen; i++) {
  12162. var indivdualAnimationOpts = individualDelay ? defaults({
  12163. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toSubPathList[i]),
  12164. done: eachDone
  12165. }, animationOpts) : animationOpts;
  12166. morphPath(fromPathList[i], toSubPathList[i], indivdualAnimationOpts);
  12167. }
  12168. }
  12169. else {
  12170. toPath.__morphT = 0;
  12171. toPath.animateTo({
  12172. __morphT: 1
  12173. }, defaults({
  12174. during: function (p) {
  12175. for (var i = 0; i < toLen; i++) {
  12176. var child = toSubPathList[i];
  12177. child.__morphT = toPath.__morphT;
  12178. child.dirtyShape();
  12179. }
  12180. oldDuring && oldDuring(p);
  12181. },
  12182. done: function () {
  12183. restoreToPath();
  12184. for (var i = 0; i < fromList.length; i++) {
  12185. restoreMethod(fromList[i], 'updateTransform');
  12186. }
  12187. oldDone && oldDone();
  12188. }
  12189. }, animationOpts));
  12190. }
  12191. if (toPath.__zr) {
  12192. addToSubPathListToZr(toPath.__zr);
  12193. }
  12194. return {
  12195. fromIndividuals: fromPathList,
  12196. toIndividuals: toSubPathList,
  12197. count: toLen
  12198. };
  12199. }
  12200. function separateMorph(fromPath, toPathList, animationOpts) {
  12201. var toLen = toPathList.length;
  12202. var fromPathList = [];
  12203. var dividePath = animationOpts.dividePath || defaultDividePath;
  12204. function addFromPath(fromList) {
  12205. for (var i = 0; i < fromList.length; i++) {
  12206. var from = fromList[i];
  12207. if (isCombineMorphing(from)) {
  12208. addFromPath(from.childrenRef());
  12209. }
  12210. else if (from instanceof Path) {
  12211. fromPathList.push(from);
  12212. }
  12213. }
  12214. }
  12215. if (isCombineMorphing(fromPath)) {
  12216. addFromPath(fromPath.childrenRef());
  12217. var fromLen = fromPathList.length;
  12218. if (fromLen < toLen) {
  12219. var k = 0;
  12220. for (var i = fromLen; i < toLen; i++) {
  12221. fromPathList.push(clonePath(fromPathList[k++ % fromLen]));
  12222. }
  12223. }
  12224. fromPathList.length = toLen;
  12225. }
  12226. else {
  12227. fromPathList = dividePath({ path: fromPath, count: toLen });
  12228. var fromPathTransform = fromPath.getComputedTransform();
  12229. for (var i = 0; i < fromPathList.length; i++) {
  12230. fromPathList[i].setLocalTransform(fromPathTransform);
  12231. }
  12232. if (fromPathList.length !== toLen) {
  12233. console.error('Invalid morphing: unmatched splitted path');
  12234. return createEmptyReturn();
  12235. }
  12236. }
  12237. fromPathList = sortPaths(fromPathList);
  12238. toPathList = sortPaths(toPathList);
  12239. var individualDelay = animationOpts.individualDelay;
  12240. for (var i = 0; i < toLen; i++) {
  12241. var indivdualAnimationOpts = individualDelay ? defaults({
  12242. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toPathList[i])
  12243. }, animationOpts) : animationOpts;
  12244. morphPath(fromPathList[i], toPathList[i], indivdualAnimationOpts);
  12245. }
  12246. return {
  12247. fromIndividuals: fromPathList,
  12248. toIndividuals: toPathList,
  12249. count: toPathList.length
  12250. };
  12251. }
  12252. var morphPath$1 = /*#__PURE__*/Object.freeze({
  12253. __proto__: null,
  12254. alignBezierCurves: alignBezierCurves,
  12255. centroid: centroid,
  12256. isCombineMorphing: isCombineMorphing,
  12257. isMorphing: isMorphing,
  12258. morphPath: morphPath,
  12259. combineMorph: combineMorph,
  12260. separateMorph: separateMorph,
  12261. defaultDividePath: split
  12262. });
  12263. var CompoundPath = (function (_super) {
  12264. __extends(CompoundPath, _super);
  12265. function CompoundPath() {
  12266. var _this = _super !== null && _super.apply(this, arguments) || this;
  12267. _this.type = 'compound';
  12268. return _this;
  12269. }
  12270. CompoundPath.prototype._updatePathDirty = function () {
  12271. var paths = this.shape.paths;
  12272. var dirtyPath = this.shapeChanged();
  12273. for (var i = 0; i < paths.length; i++) {
  12274. dirtyPath = dirtyPath || paths[i].shapeChanged();
  12275. }
  12276. if (dirtyPath) {
  12277. this.dirtyShape();
  12278. }
  12279. };
  12280. CompoundPath.prototype.beforeBrush = function () {
  12281. this._updatePathDirty();
  12282. var paths = this.shape.paths || [];
  12283. var scale = this.getGlobalScale();
  12284. for (var i = 0; i < paths.length; i++) {
  12285. if (!paths[i].path) {
  12286. paths[i].createPathProxy();
  12287. }
  12288. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  12289. }
  12290. };
  12291. CompoundPath.prototype.buildPath = function (ctx, shape) {
  12292. var paths = shape.paths || [];
  12293. for (var i = 0; i < paths.length; i++) {
  12294. paths[i].buildPath(ctx, paths[i].shape, true);
  12295. }
  12296. };
  12297. CompoundPath.prototype.afterBrush = function () {
  12298. var paths = this.shape.paths || [];
  12299. for (var i = 0; i < paths.length; i++) {
  12300. paths[i].pathUpdated();
  12301. }
  12302. };
  12303. CompoundPath.prototype.getBoundingRect = function () {
  12304. this._updatePathDirty.call(this);
  12305. return Path.prototype.getBoundingRect.call(this);
  12306. };
  12307. return CompoundPath;
  12308. }(Path));
  12309. var m = [];
  12310. var IncrementalDisplayable = (function (_super) {
  12311. __extends(IncrementalDisplayable, _super);
  12312. function IncrementalDisplayable() {
  12313. var _this = _super !== null && _super.apply(this, arguments) || this;
  12314. _this.notClear = true;
  12315. _this.incremental = true;
  12316. _this._displayables = [];
  12317. _this._temporaryDisplayables = [];
  12318. _this._cursor = 0;
  12319. return _this;
  12320. }
  12321. IncrementalDisplayable.prototype.traverse = function (cb, context) {
  12322. cb.call(context, this);
  12323. };
  12324. IncrementalDisplayable.prototype.useStyle = function () {
  12325. this.style = {};
  12326. };
  12327. IncrementalDisplayable.prototype.getCursor = function () {
  12328. return this._cursor;
  12329. };
  12330. IncrementalDisplayable.prototype.innerAfterBrush = function () {
  12331. this._cursor = this._displayables.length;
  12332. };
  12333. IncrementalDisplayable.prototype.clearDisplaybles = function () {
  12334. this._displayables = [];
  12335. this._temporaryDisplayables = [];
  12336. this._cursor = 0;
  12337. this.markRedraw();
  12338. this.notClear = false;
  12339. };
  12340. IncrementalDisplayable.prototype.clearTemporalDisplayables = function () {
  12341. this._temporaryDisplayables = [];
  12342. };
  12343. IncrementalDisplayable.prototype.addDisplayable = function (displayable, notPersistent) {
  12344. if (notPersistent) {
  12345. this._temporaryDisplayables.push(displayable);
  12346. }
  12347. else {
  12348. this._displayables.push(displayable);
  12349. }
  12350. this.markRedraw();
  12351. };
  12352. IncrementalDisplayable.prototype.addDisplayables = function (displayables, notPersistent) {
  12353. notPersistent = notPersistent || false;
  12354. for (var i = 0; i < displayables.length; i++) {
  12355. this.addDisplayable(displayables[i], notPersistent);
  12356. }
  12357. };
  12358. IncrementalDisplayable.prototype.getDisplayables = function () {
  12359. return this._displayables;
  12360. };
  12361. IncrementalDisplayable.prototype.getTemporalDisplayables = function () {
  12362. return this._temporaryDisplayables;
  12363. };
  12364. IncrementalDisplayable.prototype.eachPendingDisplayable = function (cb) {
  12365. for (var i = this._cursor; i < this._displayables.length; i++) {
  12366. cb && cb(this._displayables[i]);
  12367. }
  12368. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  12369. cb && cb(this._temporaryDisplayables[i]);
  12370. }
  12371. };
  12372. IncrementalDisplayable.prototype.update = function () {
  12373. this.updateTransform();
  12374. for (var i = this._cursor; i < this._displayables.length; i++) {
  12375. var displayable = this._displayables[i];
  12376. displayable.parent = this;
  12377. displayable.update();
  12378. displayable.parent = null;
  12379. }
  12380. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  12381. var displayable = this._temporaryDisplayables[i];
  12382. displayable.parent = this;
  12383. displayable.update();
  12384. displayable.parent = null;
  12385. }
  12386. };
  12387. IncrementalDisplayable.prototype.getBoundingRect = function () {
  12388. if (!this._rect) {
  12389. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  12390. for (var i = 0; i < this._displayables.length; i++) {
  12391. var displayable = this._displayables[i];
  12392. var childRect = displayable.getBoundingRect().clone();
  12393. if (displayable.needLocalTransform()) {
  12394. childRect.applyTransform(displayable.getLocalTransform(m));
  12395. }
  12396. rect.union(childRect);
  12397. }
  12398. this._rect = rect;
  12399. }
  12400. return this._rect;
  12401. };
  12402. IncrementalDisplayable.prototype.contain = function (x, y) {
  12403. var localPos = this.transformCoordToLocal(x, y);
  12404. var rect = this.getBoundingRect();
  12405. if (rect.contain(localPos[0], localPos[1])) {
  12406. for (var i = 0; i < this._displayables.length; i++) {
  12407. var displayable = this._displayables[i];
  12408. if (displayable.contain(x, y)) {
  12409. return true;
  12410. }
  12411. }
  12412. }
  12413. return false;
  12414. };
  12415. return IncrementalDisplayable;
  12416. }(Displayable));
  12417. var globalImageCache = new LRU(50);
  12418. function findExistImage(newImageOrSrc) {
  12419. if (typeof newImageOrSrc === 'string') {
  12420. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  12421. return cachedImgObj && cachedImgObj.image;
  12422. }
  12423. else {
  12424. return newImageOrSrc;
  12425. }
  12426. }
  12427. function createOrUpdateImage(newImageOrSrc, image, hostEl, onload, cbPayload) {
  12428. if (!newImageOrSrc) {
  12429. return image;
  12430. }
  12431. else if (typeof newImageOrSrc === 'string') {
  12432. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  12433. return image;
  12434. }
  12435. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  12436. var pendingWrap = { hostEl: hostEl, cb: onload, cbPayload: cbPayload };
  12437. if (cachedImgObj) {
  12438. image = cachedImgObj.image;
  12439. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  12440. }
  12441. else {
  12442. image = platformApi.loadImage(newImageOrSrc, imageOnLoad, imageOnLoad);
  12443. image.__zrImageSrc = newImageOrSrc;
  12444. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  12445. image: image,
  12446. pending: [pendingWrap]
  12447. });
  12448. }
  12449. return image;
  12450. }
  12451. else {
  12452. return newImageOrSrc;
  12453. }
  12454. }
  12455. function imageOnLoad() {
  12456. var cachedImgObj = this.__cachedImgObj;
  12457. this.onload = this.onerror = this.__cachedImgObj = null;
  12458. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  12459. var pendingWrap = cachedImgObj.pending[i];
  12460. var cb = pendingWrap.cb;
  12461. cb && cb(this, pendingWrap.cbPayload);
  12462. pendingWrap.hostEl.dirty();
  12463. }
  12464. cachedImgObj.pending.length = 0;
  12465. }
  12466. function isImageReady(image) {
  12467. return image && image.width && image.height;
  12468. }
  12469. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  12470. function truncateText2(out, text, containerWidth, font, ellipsis, options) {
  12471. if (!containerWidth) {
  12472. out.text = '';
  12473. out.isTruncated = false;
  12474. return;
  12475. }
  12476. var textLines = (text + '').split('\n');
  12477. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  12478. var isTruncated = false;
  12479. var truncateOut = {};
  12480. for (var i = 0, len = textLines.length; i < len; i++) {
  12481. truncateSingleLine(truncateOut, textLines[i], options);
  12482. textLines[i] = truncateOut.textLine;
  12483. isTruncated = isTruncated || truncateOut.isTruncated;
  12484. }
  12485. out.text = textLines.join('\n');
  12486. out.isTruncated = isTruncated;
  12487. }
  12488. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  12489. options = options || {};
  12490. var preparedOpts = extend({}, options);
  12491. preparedOpts.font = font;
  12492. ellipsis = retrieve2(ellipsis, '...');
  12493. preparedOpts.maxIterations = retrieve2(options.maxIterations, 2);
  12494. var minChar = preparedOpts.minChar = retrieve2(options.minChar, 0);
  12495. preparedOpts.cnCharWidth = getWidth('国', font);
  12496. var ascCharWidth = preparedOpts.ascCharWidth = getWidth('a', font);
  12497. preparedOpts.placeholder = retrieve2(options.placeholder, '');
  12498. var contentWidth = containerWidth = Math.max(0, containerWidth - 1);
  12499. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  12500. contentWidth -= ascCharWidth;
  12501. }
  12502. var ellipsisWidth = getWidth(ellipsis, font);
  12503. if (ellipsisWidth > contentWidth) {
  12504. ellipsis = '';
  12505. ellipsisWidth = 0;
  12506. }
  12507. contentWidth = containerWidth - ellipsisWidth;
  12508. preparedOpts.ellipsis = ellipsis;
  12509. preparedOpts.ellipsisWidth = ellipsisWidth;
  12510. preparedOpts.contentWidth = contentWidth;
  12511. preparedOpts.containerWidth = containerWidth;
  12512. return preparedOpts;
  12513. }
  12514. function truncateSingleLine(out, textLine, options) {
  12515. var containerWidth = options.containerWidth;
  12516. var font = options.font;
  12517. var contentWidth = options.contentWidth;
  12518. if (!containerWidth) {
  12519. out.textLine = '';
  12520. out.isTruncated = false;
  12521. return;
  12522. }
  12523. var lineWidth = getWidth(textLine, font);
  12524. if (lineWidth <= containerWidth) {
  12525. out.textLine = textLine;
  12526. out.isTruncated = false;
  12527. return;
  12528. }
  12529. for (var j = 0;; j++) {
  12530. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  12531. textLine += options.ellipsis;
  12532. break;
  12533. }
  12534. var subLength = j === 0
  12535. ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
  12536. : lineWidth > 0
  12537. ? Math.floor(textLine.length * contentWidth / lineWidth)
  12538. : 0;
  12539. textLine = textLine.substr(0, subLength);
  12540. lineWidth = getWidth(textLine, font);
  12541. }
  12542. if (textLine === '') {
  12543. textLine = options.placeholder;
  12544. }
  12545. out.textLine = textLine;
  12546. out.isTruncated = true;
  12547. }
  12548. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  12549. var width = 0;
  12550. var i = 0;
  12551. for (var len = text.length; i < len && width < contentWidth; i++) {
  12552. var charCode = text.charCodeAt(i);
  12553. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  12554. }
  12555. return i;
  12556. }
  12557. function parsePlainText(text, style) {
  12558. text != null && (text += '');
  12559. var overflow = style.overflow;
  12560. var padding = style.padding;
  12561. var font = style.font;
  12562. var truncate = overflow === 'truncate';
  12563. var calculatedLineHeight = getLineHeight(font);
  12564. var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
  12565. var bgColorDrawn = !!(style.backgroundColor);
  12566. var truncateLineOverflow = style.lineOverflow === 'truncate';
  12567. var isTruncated = false;
  12568. var width = style.width;
  12569. var lines;
  12570. if (width != null && (overflow === 'break' || overflow === 'breakAll')) {
  12571. lines = text ? wrapText(text, style.font, width, overflow === 'breakAll', 0).lines : [];
  12572. }
  12573. else {
  12574. lines = text ? text.split('\n') : [];
  12575. }
  12576. var contentHeight = lines.length * lineHeight;
  12577. var height = retrieve2(style.height, contentHeight);
  12578. if (contentHeight > height && truncateLineOverflow) {
  12579. var lineCount = Math.floor(height / lineHeight);
  12580. isTruncated = isTruncated || (lines.length > lineCount);
  12581. lines = lines.slice(0, lineCount);
  12582. }
  12583. if (text && truncate && width != null) {
  12584. var options = prepareTruncateOptions(width, font, style.ellipsis, {
  12585. minChar: style.truncateMinChar,
  12586. placeholder: style.placeholder
  12587. });
  12588. var singleOut = {};
  12589. for (var i = 0; i < lines.length; i++) {
  12590. truncateSingleLine(singleOut, lines[i], options);
  12591. lines[i] = singleOut.textLine;
  12592. isTruncated = isTruncated || singleOut.isTruncated;
  12593. }
  12594. }
  12595. var outerHeight = height;
  12596. var contentWidth = 0;
  12597. for (var i = 0; i < lines.length; i++) {
  12598. contentWidth = Math.max(getWidth(lines[i], font), contentWidth);
  12599. }
  12600. if (width == null) {
  12601. width = contentWidth;
  12602. }
  12603. var outerWidth = contentWidth;
  12604. if (padding) {
  12605. outerHeight += padding[0] + padding[2];
  12606. outerWidth += padding[1] + padding[3];
  12607. width += padding[1] + padding[3];
  12608. }
  12609. if (bgColorDrawn) {
  12610. outerWidth = width;
  12611. }
  12612. return {
  12613. lines: lines,
  12614. height: height,
  12615. outerWidth: outerWidth,
  12616. outerHeight: outerHeight,
  12617. lineHeight: lineHeight,
  12618. calculatedLineHeight: calculatedLineHeight,
  12619. contentWidth: contentWidth,
  12620. contentHeight: contentHeight,
  12621. width: width,
  12622. isTruncated: isTruncated
  12623. };
  12624. }
  12625. var RichTextToken = (function () {
  12626. function RichTextToken() {
  12627. }
  12628. return RichTextToken;
  12629. }());
  12630. var RichTextLine = (function () {
  12631. function RichTextLine(tokens) {
  12632. this.tokens = [];
  12633. if (tokens) {
  12634. this.tokens = tokens;
  12635. }
  12636. }
  12637. return RichTextLine;
  12638. }());
  12639. var RichTextContentBlock = (function () {
  12640. function RichTextContentBlock() {
  12641. this.width = 0;
  12642. this.height = 0;
  12643. this.contentWidth = 0;
  12644. this.contentHeight = 0;
  12645. this.outerWidth = 0;
  12646. this.outerHeight = 0;
  12647. this.lines = [];
  12648. this.isTruncated = false;
  12649. }
  12650. return RichTextContentBlock;
  12651. }());
  12652. function parseRichText(text, style) {
  12653. var contentBlock = new RichTextContentBlock();
  12654. text != null && (text += '');
  12655. if (!text) {
  12656. return contentBlock;
  12657. }
  12658. var topWidth = style.width;
  12659. var topHeight = style.height;
  12660. var overflow = style.overflow;
  12661. var wrapInfo = (overflow === 'break' || overflow === 'breakAll') && topWidth != null
  12662. ? { width: topWidth, accumWidth: 0, breakAll: overflow === 'breakAll' }
  12663. : null;
  12664. var lastIndex = STYLE_REG.lastIndex = 0;
  12665. var result;
  12666. while ((result = STYLE_REG.exec(text)) != null) {
  12667. var matchedIndex = result.index;
  12668. if (matchedIndex > lastIndex) {
  12669. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex), style, wrapInfo);
  12670. }
  12671. pushTokens(contentBlock, result[2], style, wrapInfo, result[1]);
  12672. lastIndex = STYLE_REG.lastIndex;
  12673. }
  12674. if (lastIndex < text.length) {
  12675. pushTokens(contentBlock, text.substring(lastIndex, text.length), style, wrapInfo);
  12676. }
  12677. var pendingList = [];
  12678. var calculatedHeight = 0;
  12679. var calculatedWidth = 0;
  12680. var stlPadding = style.padding;
  12681. var truncate = overflow === 'truncate';
  12682. var truncateLine = style.lineOverflow === 'truncate';
  12683. var tmpTruncateOut = {};
  12684. function finishLine(line, lineWidth, lineHeight) {
  12685. line.width = lineWidth;
  12686. line.lineHeight = lineHeight;
  12687. calculatedHeight += lineHeight;
  12688. calculatedWidth = Math.max(calculatedWidth, lineWidth);
  12689. }
  12690. outer: for (var i = 0; i < contentBlock.lines.length; i++) {
  12691. var line = contentBlock.lines[i];
  12692. var lineHeight = 0;
  12693. var lineWidth = 0;
  12694. for (var j = 0; j < line.tokens.length; j++) {
  12695. var token = line.tokens[j];
  12696. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  12697. var textPadding = token.textPadding = tokenStyle.padding;
  12698. var paddingH = textPadding ? textPadding[1] + textPadding[3] : 0;
  12699. var font = token.font = tokenStyle.font || style.font;
  12700. token.contentHeight = getLineHeight(font);
  12701. var tokenHeight = retrieve2(tokenStyle.height, token.contentHeight);
  12702. token.innerHeight = tokenHeight;
  12703. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  12704. token.height = tokenHeight;
  12705. token.lineHeight = retrieve3(tokenStyle.lineHeight, style.lineHeight, tokenHeight);
  12706. token.align = tokenStyle && tokenStyle.align || style.align;
  12707. token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
  12708. if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
  12709. var originalLength = contentBlock.lines.length;
  12710. if (j > 0) {
  12711. line.tokens = line.tokens.slice(0, j);
  12712. finishLine(line, lineWidth, lineHeight);
  12713. contentBlock.lines = contentBlock.lines.slice(0, i + 1);
  12714. }
  12715. else {
  12716. contentBlock.lines = contentBlock.lines.slice(0, i);
  12717. }
  12718. contentBlock.isTruncated = contentBlock.isTruncated || (contentBlock.lines.length < originalLength);
  12719. break outer;
  12720. }
  12721. var styleTokenWidth = tokenStyle.width;
  12722. var tokenWidthNotSpecified = styleTokenWidth == null || styleTokenWidth === 'auto';
  12723. if (typeof styleTokenWidth === 'string' && styleTokenWidth.charAt(styleTokenWidth.length - 1) === '%') {
  12724. token.percentWidth = styleTokenWidth;
  12725. pendingList.push(token);
  12726. token.contentWidth = getWidth(token.text, font);
  12727. }
  12728. else {
  12729. if (tokenWidthNotSpecified) {
  12730. var textBackgroundColor = tokenStyle.backgroundColor;
  12731. var bgImg = textBackgroundColor && textBackgroundColor.image;
  12732. if (bgImg) {
  12733. bgImg = findExistImage(bgImg);
  12734. if (isImageReady(bgImg)) {
  12735. token.width = Math.max(token.width, bgImg.width * tokenHeight / bgImg.height);
  12736. }
  12737. }
  12738. }
  12739. var remainTruncWidth = truncate && topWidth != null
  12740. ? topWidth - lineWidth : null;
  12741. if (remainTruncWidth != null && remainTruncWidth < token.width) {
  12742. if (!tokenWidthNotSpecified || remainTruncWidth < paddingH) {
  12743. token.text = '';
  12744. token.width = token.contentWidth = 0;
  12745. }
  12746. else {
  12747. truncateText2(tmpTruncateOut, token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
  12748. token.text = tmpTruncateOut.text;
  12749. contentBlock.isTruncated = contentBlock.isTruncated || tmpTruncateOut.isTruncated;
  12750. token.width = token.contentWidth = getWidth(token.text, font);
  12751. }
  12752. }
  12753. else {
  12754. token.contentWidth = getWidth(token.text, font);
  12755. }
  12756. }
  12757. token.width += paddingH;
  12758. lineWidth += token.width;
  12759. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  12760. }
  12761. finishLine(line, lineWidth, lineHeight);
  12762. }
  12763. contentBlock.outerWidth = contentBlock.width = retrieve2(topWidth, calculatedWidth);
  12764. contentBlock.outerHeight = contentBlock.height = retrieve2(topHeight, calculatedHeight);
  12765. contentBlock.contentHeight = calculatedHeight;
  12766. contentBlock.contentWidth = calculatedWidth;
  12767. if (stlPadding) {
  12768. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  12769. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  12770. }
  12771. for (var i = 0; i < pendingList.length; i++) {
  12772. var token = pendingList[i];
  12773. var percentWidth = token.percentWidth;
  12774. token.width = parseInt(percentWidth, 10) / 100 * contentBlock.width;
  12775. }
  12776. return contentBlock;
  12777. }
  12778. function pushTokens(block, str, style, wrapInfo, styleName) {
  12779. var isEmptyStr = str === '';
  12780. var tokenStyle = styleName && style.rich[styleName] || {};
  12781. var lines = block.lines;
  12782. var font = tokenStyle.font || style.font;
  12783. var newLine = false;
  12784. var strLines;
  12785. var linesWidths;
  12786. if (wrapInfo) {
  12787. var tokenPadding = tokenStyle.padding;
  12788. var tokenPaddingH = tokenPadding ? tokenPadding[1] + tokenPadding[3] : 0;
  12789. if (tokenStyle.width != null && tokenStyle.width !== 'auto') {
  12790. var outerWidth_1 = parsePercent(tokenStyle.width, wrapInfo.width) + tokenPaddingH;
  12791. if (lines.length > 0) {
  12792. if (outerWidth_1 + wrapInfo.accumWidth > wrapInfo.width) {
  12793. strLines = str.split('\n');
  12794. newLine = true;
  12795. }
  12796. }
  12797. wrapInfo.accumWidth = outerWidth_1;
  12798. }
  12799. else {
  12800. var res = wrapText(str, font, wrapInfo.width, wrapInfo.breakAll, wrapInfo.accumWidth);
  12801. wrapInfo.accumWidth = res.accumWidth + tokenPaddingH;
  12802. linesWidths = res.linesWidths;
  12803. strLines = res.lines;
  12804. }
  12805. }
  12806. else {
  12807. strLines = str.split('\n');
  12808. }
  12809. for (var i = 0; i < strLines.length; i++) {
  12810. var text = strLines[i];
  12811. var token = new RichTextToken();
  12812. token.styleName = styleName;
  12813. token.text = text;
  12814. token.isLineHolder = !text && !isEmptyStr;
  12815. if (typeof tokenStyle.width === 'number') {
  12816. token.width = tokenStyle.width;
  12817. }
  12818. else {
  12819. token.width = linesWidths
  12820. ? linesWidths[i]
  12821. : getWidth(text, font);
  12822. }
  12823. if (!i && !newLine) {
  12824. var tokens = (lines[lines.length - 1] || (lines[0] = new RichTextLine())).tokens;
  12825. var tokensLen = tokens.length;
  12826. (tokensLen === 1 && tokens[0].isLineHolder)
  12827. ? (tokens[0] = token)
  12828. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  12829. }
  12830. else {
  12831. lines.push(new RichTextLine([token]));
  12832. }
  12833. }
  12834. }
  12835. function isAlphabeticLetter(ch) {
  12836. var code = ch.charCodeAt(0);
  12837. return code >= 0x20 && code <= 0x24F
  12838. || code >= 0x370 && code <= 0x10FF
  12839. || code >= 0x1200 && code <= 0x13FF
  12840. || code >= 0x1E00 && code <= 0x206F;
  12841. }
  12842. var breakCharMap = reduce(',&?/;] '.split(''), function (obj, ch) {
  12843. obj[ch] = true;
  12844. return obj;
  12845. }, {});
  12846. function isWordBreakChar(ch) {
  12847. if (isAlphabeticLetter(ch)) {
  12848. if (breakCharMap[ch]) {
  12849. return true;
  12850. }
  12851. return false;
  12852. }
  12853. return true;
  12854. }
  12855. function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
  12856. var lines = [];
  12857. var linesWidths = [];
  12858. var line = '';
  12859. var currentWord = '';
  12860. var currentWordWidth = 0;
  12861. var accumWidth = 0;
  12862. for (var i = 0; i < text.length; i++) {
  12863. var ch = text.charAt(i);
  12864. if (ch === '\n') {
  12865. if (currentWord) {
  12866. line += currentWord;
  12867. accumWidth += currentWordWidth;
  12868. }
  12869. lines.push(line);
  12870. linesWidths.push(accumWidth);
  12871. line = '';
  12872. currentWord = '';
  12873. currentWordWidth = 0;
  12874. accumWidth = 0;
  12875. continue;
  12876. }
  12877. var chWidth = getWidth(ch, font);
  12878. var inWord = isBreakAll ? false : !isWordBreakChar(ch);
  12879. if (!lines.length
  12880. ? lastAccumWidth + accumWidth + chWidth > lineWidth
  12881. : accumWidth + chWidth > lineWidth) {
  12882. if (!accumWidth) {
  12883. if (inWord) {
  12884. lines.push(currentWord);
  12885. linesWidths.push(currentWordWidth);
  12886. currentWord = ch;
  12887. currentWordWidth = chWidth;
  12888. }
  12889. else {
  12890. lines.push(ch);
  12891. linesWidths.push(chWidth);
  12892. }
  12893. }
  12894. else if (line || currentWord) {
  12895. if (inWord) {
  12896. if (!line) {
  12897. line = currentWord;
  12898. currentWord = '';
  12899. currentWordWidth = 0;
  12900. accumWidth = currentWordWidth;
  12901. }
  12902. lines.push(line);
  12903. linesWidths.push(accumWidth - currentWordWidth);
  12904. currentWord += ch;
  12905. currentWordWidth += chWidth;
  12906. line = '';
  12907. accumWidth = currentWordWidth;
  12908. }
  12909. else {
  12910. if (currentWord) {
  12911. line += currentWord;
  12912. currentWord = '';
  12913. currentWordWidth = 0;
  12914. }
  12915. lines.push(line);
  12916. linesWidths.push(accumWidth);
  12917. line = ch;
  12918. accumWidth = chWidth;
  12919. }
  12920. }
  12921. continue;
  12922. }
  12923. accumWidth += chWidth;
  12924. if (inWord) {
  12925. currentWord += ch;
  12926. currentWordWidth += chWidth;
  12927. }
  12928. else {
  12929. if (currentWord) {
  12930. line += currentWord;
  12931. currentWord = '';
  12932. currentWordWidth = 0;
  12933. }
  12934. line += ch;
  12935. }
  12936. }
  12937. if (!lines.length && !line) {
  12938. line = text;
  12939. currentWord = '';
  12940. currentWordWidth = 0;
  12941. }
  12942. if (currentWord) {
  12943. line += currentWord;
  12944. }
  12945. if (line) {
  12946. lines.push(line);
  12947. linesWidths.push(accumWidth);
  12948. }
  12949. if (lines.length === 1) {
  12950. accumWidth += lastAccumWidth;
  12951. }
  12952. return {
  12953. accumWidth: accumWidth,
  12954. lines: lines,
  12955. linesWidths: linesWidths
  12956. };
  12957. }
  12958. var DEFAULT_RICH_TEXT_COLOR = {
  12959. fill: '#000'
  12960. };
  12961. var DEFAULT_STROKE_LINE_WIDTH = 2;
  12962. var DEFAULT_TEXT_ANIMATION_PROPS = {
  12963. style: defaults({
  12964. fill: true,
  12965. stroke: true,
  12966. fillOpacity: true,
  12967. strokeOpacity: true,
  12968. lineWidth: true,
  12969. fontSize: true,
  12970. lineHeight: true,
  12971. width: true,
  12972. height: true,
  12973. textShadowColor: true,
  12974. textShadowBlur: true,
  12975. textShadowOffsetX: true,
  12976. textShadowOffsetY: true,
  12977. backgroundColor: true,
  12978. padding: true,
  12979. borderColor: true,
  12980. borderWidth: true,
  12981. borderRadius: true
  12982. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  12983. };
  12984. var ZRText = (function (_super) {
  12985. __extends(ZRText, _super);
  12986. function ZRText(opts) {
  12987. var _this = _super.call(this) || this;
  12988. _this.type = 'text';
  12989. _this._children = [];
  12990. _this._defaultStyle = DEFAULT_RICH_TEXT_COLOR;
  12991. _this.attr(opts);
  12992. return _this;
  12993. }
  12994. ZRText.prototype.childrenRef = function () {
  12995. return this._children;
  12996. };
  12997. ZRText.prototype.update = function () {
  12998. _super.prototype.update.call(this);
  12999. if (this.styleChanged()) {
  13000. this._updateSubTexts();
  13001. }
  13002. for (var i = 0; i < this._children.length; i++) {
  13003. var child = this._children[i];
  13004. child.zlevel = this.zlevel;
  13005. child.z = this.z;
  13006. child.z2 = this.z2;
  13007. child.culling = this.culling;
  13008. child.cursor = this.cursor;
  13009. child.invisible = this.invisible;
  13010. }
  13011. };
  13012. ZRText.prototype.updateTransform = function () {
  13013. var innerTransformable = this.innerTransformable;
  13014. if (innerTransformable) {
  13015. innerTransformable.updateTransform();
  13016. if (innerTransformable.transform) {
  13017. this.transform = innerTransformable.transform;
  13018. }
  13019. }
  13020. else {
  13021. _super.prototype.updateTransform.call(this);
  13022. }
  13023. };
  13024. ZRText.prototype.getLocalTransform = function (m) {
  13025. var innerTransformable = this.innerTransformable;
  13026. return innerTransformable
  13027. ? innerTransformable.getLocalTransform(m)
  13028. : _super.prototype.getLocalTransform.call(this, m);
  13029. };
  13030. ZRText.prototype.getComputedTransform = function () {
  13031. if (this.__hostTarget) {
  13032. this.__hostTarget.getComputedTransform();
  13033. this.__hostTarget.updateInnerText(true);
  13034. }
  13035. return _super.prototype.getComputedTransform.call(this);
  13036. };
  13037. ZRText.prototype._updateSubTexts = function () {
  13038. this._childCursor = 0;
  13039. normalizeTextStyle(this.style);
  13040. this.style.rich
  13041. ? this._updateRichTexts()
  13042. : this._updatePlainTexts();
  13043. this._children.length = this._childCursor;
  13044. this.styleUpdated();
  13045. };
  13046. ZRText.prototype.addSelfToZr = function (zr) {
  13047. _super.prototype.addSelfToZr.call(this, zr);
  13048. for (var i = 0; i < this._children.length; i++) {
  13049. this._children[i].__zr = zr;
  13050. }
  13051. };
  13052. ZRText.prototype.removeSelfFromZr = function (zr) {
  13053. _super.prototype.removeSelfFromZr.call(this, zr);
  13054. for (var i = 0; i < this._children.length; i++) {
  13055. this._children[i].__zr = null;
  13056. }
  13057. };
  13058. ZRText.prototype.getBoundingRect = function () {
  13059. if (this.styleChanged()) {
  13060. this._updateSubTexts();
  13061. }
  13062. if (!this._rect) {
  13063. var tmpRect = new BoundingRect(0, 0, 0, 0);
  13064. var children = this._children;
  13065. var tmpMat = [];
  13066. var rect = null;
  13067. for (var i = 0; i < children.length; i++) {
  13068. var child = children[i];
  13069. var childRect = child.getBoundingRect();
  13070. var transform = child.getLocalTransform(tmpMat);
  13071. if (transform) {
  13072. tmpRect.copy(childRect);
  13073. tmpRect.applyTransform(transform);
  13074. rect = rect || tmpRect.clone();
  13075. rect.union(tmpRect);
  13076. }
  13077. else {
  13078. rect = rect || childRect.clone();
  13079. rect.union(childRect);
  13080. }
  13081. }
  13082. this._rect = rect || tmpRect;
  13083. }
  13084. return this._rect;
  13085. };
  13086. ZRText.prototype.setDefaultTextStyle = function (defaultTextStyle) {
  13087. this._defaultStyle = defaultTextStyle || DEFAULT_RICH_TEXT_COLOR;
  13088. };
  13089. ZRText.prototype.setTextContent = function (textContent) {
  13090. {
  13091. throw new Error('Can\'t attach text on another text');
  13092. }
  13093. };
  13094. ZRText.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  13095. if (!sourceStyle) {
  13096. return targetStyle;
  13097. }
  13098. var sourceRich = sourceStyle.rich;
  13099. var targetRich = targetStyle.rich || (sourceRich && {});
  13100. extend(targetStyle, sourceStyle);
  13101. if (sourceRich && targetRich) {
  13102. this._mergeRich(targetRich, sourceRich);
  13103. targetStyle.rich = targetRich;
  13104. }
  13105. else if (targetRich) {
  13106. targetStyle.rich = targetRich;
  13107. }
  13108. return targetStyle;
  13109. };
  13110. ZRText.prototype._mergeRich = function (targetRich, sourceRich) {
  13111. var richNames = keys(sourceRich);
  13112. for (var i = 0; i < richNames.length; i++) {
  13113. var richName = richNames[i];
  13114. targetRich[richName] = targetRich[richName] || {};
  13115. extend(targetRich[richName], sourceRich[richName]);
  13116. }
  13117. };
  13118. ZRText.prototype.getAnimationStyleProps = function () {
  13119. return DEFAULT_TEXT_ANIMATION_PROPS;
  13120. };
  13121. ZRText.prototype._getOrCreateChild = function (Ctor) {
  13122. var child = this._children[this._childCursor];
  13123. if (!child || !(child instanceof Ctor)) {
  13124. child = new Ctor();
  13125. }
  13126. this._children[this._childCursor++] = child;
  13127. child.__zr = this.__zr;
  13128. child.parent = this;
  13129. return child;
  13130. };
  13131. ZRText.prototype._updatePlainTexts = function () {
  13132. var style = this.style;
  13133. var textFont = style.font || DEFAULT_FONT;
  13134. var textPadding = style.padding;
  13135. var text = getStyleText(style);
  13136. var contentBlock = parsePlainText(text, style);
  13137. var needDrawBg = needDrawBackground(style);
  13138. var bgColorDrawn = !!(style.backgroundColor);
  13139. var outerHeight = contentBlock.outerHeight;
  13140. var outerWidth = contentBlock.outerWidth;
  13141. var contentWidth = contentBlock.contentWidth;
  13142. var textLines = contentBlock.lines;
  13143. var lineHeight = contentBlock.lineHeight;
  13144. var defaultStyle = this._defaultStyle;
  13145. this.isTruncated = !!contentBlock.isTruncated;
  13146. var baseX = style.x || 0;
  13147. var baseY = style.y || 0;
  13148. var textAlign = style.align || defaultStyle.align || 'left';
  13149. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
  13150. var textX = baseX;
  13151. var textY = adjustTextY$1(baseY, contentBlock.contentHeight, verticalAlign);
  13152. if (needDrawBg || textPadding) {
  13153. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  13154. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  13155. needDrawBg && this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  13156. }
  13157. textY += lineHeight / 2;
  13158. if (textPadding) {
  13159. textX = getTextXForPadding(baseX, textAlign, textPadding);
  13160. if (verticalAlign === 'top') {
  13161. textY += textPadding[0];
  13162. }
  13163. else if (verticalAlign === 'bottom') {
  13164. textY -= textPadding[2];
  13165. }
  13166. }
  13167. var defaultLineWidth = 0;
  13168. var useDefaultFill = false;
  13169. var textFill = getFill('fill' in style
  13170. ? style.fill
  13171. : (useDefaultFill = true, defaultStyle.fill));
  13172. var textStroke = getStroke('stroke' in style
  13173. ? style.stroke
  13174. : (!bgColorDrawn
  13175. && (!defaultStyle.autoStroke || useDefaultFill))
  13176. ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  13177. : null);
  13178. var hasShadow = style.textShadowBlur > 0;
  13179. var fixedBoundingRect = style.width != null
  13180. && (style.overflow === 'truncate' || style.overflow === 'break' || style.overflow === 'breakAll');
  13181. var calculatedLineHeight = contentBlock.calculatedLineHeight;
  13182. for (var i = 0; i < textLines.length; i++) {
  13183. var el = this._getOrCreateChild(TSpan);
  13184. var subElStyle = el.createStyle();
  13185. el.useStyle(subElStyle);
  13186. subElStyle.text = textLines[i];
  13187. subElStyle.x = textX;
  13188. subElStyle.y = textY;
  13189. if (textAlign) {
  13190. subElStyle.textAlign = textAlign;
  13191. }
  13192. subElStyle.textBaseline = 'middle';
  13193. subElStyle.opacity = style.opacity;
  13194. subElStyle.strokeFirst = true;
  13195. if (hasShadow) {
  13196. subElStyle.shadowBlur = style.textShadowBlur || 0;
  13197. subElStyle.shadowColor = style.textShadowColor || 'transparent';
  13198. subElStyle.shadowOffsetX = style.textShadowOffsetX || 0;
  13199. subElStyle.shadowOffsetY = style.textShadowOffsetY || 0;
  13200. }
  13201. subElStyle.stroke = textStroke;
  13202. subElStyle.fill = textFill;
  13203. if (textStroke) {
  13204. subElStyle.lineWidth = style.lineWidth || defaultLineWidth;
  13205. subElStyle.lineDash = style.lineDash;
  13206. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13207. }
  13208. subElStyle.font = textFont;
  13209. setSeparateFont(subElStyle, style);
  13210. textY += lineHeight;
  13211. if (fixedBoundingRect) {
  13212. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, contentWidth, subElStyle.textAlign), adjustTextY$1(subElStyle.y, calculatedLineHeight, subElStyle.textBaseline), contentWidth, calculatedLineHeight));
  13213. }
  13214. }
  13215. };
  13216. ZRText.prototype._updateRichTexts = function () {
  13217. var style = this.style;
  13218. var text = getStyleText(style);
  13219. var contentBlock = parseRichText(text, style);
  13220. var contentWidth = contentBlock.width;
  13221. var outerWidth = contentBlock.outerWidth;
  13222. var outerHeight = contentBlock.outerHeight;
  13223. var textPadding = style.padding;
  13224. var baseX = style.x || 0;
  13225. var baseY = style.y || 0;
  13226. var defaultStyle = this._defaultStyle;
  13227. var textAlign = style.align || defaultStyle.align;
  13228. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
  13229. this.isTruncated = !!contentBlock.isTruncated;
  13230. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  13231. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  13232. var xLeft = boxX;
  13233. var lineTop = boxY;
  13234. if (textPadding) {
  13235. xLeft += textPadding[3];
  13236. lineTop += textPadding[0];
  13237. }
  13238. var xRight = xLeft + contentWidth;
  13239. if (needDrawBackground(style)) {
  13240. this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  13241. }
  13242. var bgColorDrawn = !!(style.backgroundColor);
  13243. for (var i = 0; i < contentBlock.lines.length; i++) {
  13244. var line = contentBlock.lines[i];
  13245. var tokens = line.tokens;
  13246. var tokenCount = tokens.length;
  13247. var lineHeight = line.lineHeight;
  13248. var remainedWidth = line.width;
  13249. var leftIndex = 0;
  13250. var lineXLeft = xLeft;
  13251. var lineXRight = xRight;
  13252. var rightIndex = tokenCount - 1;
  13253. var token = void 0;
  13254. while (leftIndex < tokenCount
  13255. && (token = tokens[leftIndex], !token.align || token.align === 'left')) {
  13256. this._placeToken(token, style, lineHeight, lineTop, lineXLeft, 'left', bgColorDrawn);
  13257. remainedWidth -= token.width;
  13258. lineXLeft += token.width;
  13259. leftIndex++;
  13260. }
  13261. while (rightIndex >= 0
  13262. && (token = tokens[rightIndex], token.align === 'right')) {
  13263. this._placeToken(token, style, lineHeight, lineTop, lineXRight, 'right', bgColorDrawn);
  13264. remainedWidth -= token.width;
  13265. lineXRight -= token.width;
  13266. rightIndex--;
  13267. }
  13268. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - remainedWidth) / 2;
  13269. while (leftIndex <= rightIndex) {
  13270. token = tokens[leftIndex];
  13271. this._placeToken(token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center', bgColorDrawn);
  13272. lineXLeft += token.width;
  13273. leftIndex++;
  13274. }
  13275. lineTop += lineHeight;
  13276. }
  13277. };
  13278. ZRText.prototype._placeToken = function (token, style, lineHeight, lineTop, x, textAlign, parentBgColorDrawn) {
  13279. var tokenStyle = style.rich[token.styleName] || {};
  13280. tokenStyle.text = token.text;
  13281. var verticalAlign = token.verticalAlign;
  13282. var y = lineTop + lineHeight / 2;
  13283. if (verticalAlign === 'top') {
  13284. y = lineTop + token.height / 2;
  13285. }
  13286. else if (verticalAlign === 'bottom') {
  13287. y = lineTop + lineHeight - token.height / 2;
  13288. }
  13289. var needDrawBg = !token.isLineHolder && needDrawBackground(tokenStyle);
  13290. needDrawBg && this._renderBackground(tokenStyle, style, textAlign === 'right'
  13291. ? x - token.width
  13292. : textAlign === 'center'
  13293. ? x - token.width / 2
  13294. : x, y - token.height / 2, token.width, token.height);
  13295. var bgColorDrawn = !!tokenStyle.backgroundColor;
  13296. var textPadding = token.textPadding;
  13297. if (textPadding) {
  13298. x = getTextXForPadding(x, textAlign, textPadding);
  13299. y -= token.height / 2 - textPadding[0] - token.innerHeight / 2;
  13300. }
  13301. var el = this._getOrCreateChild(TSpan);
  13302. var subElStyle = el.createStyle();
  13303. el.useStyle(subElStyle);
  13304. var defaultStyle = this._defaultStyle;
  13305. var useDefaultFill = false;
  13306. var defaultLineWidth = 0;
  13307. var textFill = getFill('fill' in tokenStyle ? tokenStyle.fill
  13308. : 'fill' in style ? style.fill
  13309. : (useDefaultFill = true, defaultStyle.fill));
  13310. var textStroke = getStroke('stroke' in tokenStyle ? tokenStyle.stroke
  13311. : 'stroke' in style ? style.stroke
  13312. : (!bgColorDrawn
  13313. && !parentBgColorDrawn
  13314. && (!defaultStyle.autoStroke || useDefaultFill)) ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  13315. : null);
  13316. var hasShadow = tokenStyle.textShadowBlur > 0
  13317. || style.textShadowBlur > 0;
  13318. subElStyle.text = token.text;
  13319. subElStyle.x = x;
  13320. subElStyle.y = y;
  13321. if (hasShadow) {
  13322. subElStyle.shadowBlur = tokenStyle.textShadowBlur || style.textShadowBlur || 0;
  13323. subElStyle.shadowColor = tokenStyle.textShadowColor || style.textShadowColor || 'transparent';
  13324. subElStyle.shadowOffsetX = tokenStyle.textShadowOffsetX || style.textShadowOffsetX || 0;
  13325. subElStyle.shadowOffsetY = tokenStyle.textShadowOffsetY || style.textShadowOffsetY || 0;
  13326. }
  13327. subElStyle.textAlign = textAlign;
  13328. subElStyle.textBaseline = 'middle';
  13329. subElStyle.font = token.font || DEFAULT_FONT;
  13330. subElStyle.opacity = retrieve3(tokenStyle.opacity, style.opacity, 1);
  13331. setSeparateFont(subElStyle, tokenStyle);
  13332. if (textStroke) {
  13333. subElStyle.lineWidth = retrieve3(tokenStyle.lineWidth, style.lineWidth, defaultLineWidth);
  13334. subElStyle.lineDash = retrieve2(tokenStyle.lineDash, style.lineDash);
  13335. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13336. subElStyle.stroke = textStroke;
  13337. }
  13338. if (textFill) {
  13339. subElStyle.fill = textFill;
  13340. }
  13341. var textWidth = token.contentWidth;
  13342. var textHeight = token.contentHeight;
  13343. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, textWidth, subElStyle.textAlign), adjustTextY$1(subElStyle.y, textHeight, subElStyle.textBaseline), textWidth, textHeight));
  13344. };
  13345. ZRText.prototype._renderBackground = function (style, topStyle, x, y, width, height) {
  13346. var textBackgroundColor = style.backgroundColor;
  13347. var textBorderWidth = style.borderWidth;
  13348. var textBorderColor = style.borderColor;
  13349. var isImageBg = textBackgroundColor && textBackgroundColor.image;
  13350. var isPlainOrGradientBg = textBackgroundColor && !isImageBg;
  13351. var textBorderRadius = style.borderRadius;
  13352. var self = this;
  13353. var rectEl;
  13354. var imgEl;
  13355. if (isPlainOrGradientBg || style.lineHeight || (textBorderWidth && textBorderColor)) {
  13356. rectEl = this._getOrCreateChild(Rect);
  13357. rectEl.useStyle(rectEl.createStyle());
  13358. rectEl.style.fill = null;
  13359. var rectShape = rectEl.shape;
  13360. rectShape.x = x;
  13361. rectShape.y = y;
  13362. rectShape.width = width;
  13363. rectShape.height = height;
  13364. rectShape.r = textBorderRadius;
  13365. rectEl.dirtyShape();
  13366. }
  13367. if (isPlainOrGradientBg) {
  13368. var rectStyle = rectEl.style;
  13369. rectStyle.fill = textBackgroundColor || null;
  13370. rectStyle.fillOpacity = retrieve2(style.fillOpacity, 1);
  13371. }
  13372. else if (isImageBg) {
  13373. imgEl = this._getOrCreateChild(ZRImage);
  13374. imgEl.onload = function () {
  13375. self.dirtyStyle();
  13376. };
  13377. var imgStyle = imgEl.style;
  13378. imgStyle.image = textBackgroundColor.image;
  13379. imgStyle.x = x;
  13380. imgStyle.y = y;
  13381. imgStyle.width = width;
  13382. imgStyle.height = height;
  13383. }
  13384. if (textBorderWidth && textBorderColor) {
  13385. var rectStyle = rectEl.style;
  13386. rectStyle.lineWidth = textBorderWidth;
  13387. rectStyle.stroke = textBorderColor;
  13388. rectStyle.strokeOpacity = retrieve2(style.strokeOpacity, 1);
  13389. rectStyle.lineDash = style.borderDash;
  13390. rectStyle.lineDashOffset = style.borderDashOffset || 0;
  13391. rectEl.strokeContainThreshold = 0;
  13392. if (rectEl.hasFill() && rectEl.hasStroke()) {
  13393. rectStyle.strokeFirst = true;
  13394. rectStyle.lineWidth *= 2;
  13395. }
  13396. }
  13397. var commonStyle = (rectEl || imgEl).style;
  13398. commonStyle.shadowBlur = style.shadowBlur || 0;
  13399. commonStyle.shadowColor = style.shadowColor || 'transparent';
  13400. commonStyle.shadowOffsetX = style.shadowOffsetX || 0;
  13401. commonStyle.shadowOffsetY = style.shadowOffsetY || 0;
  13402. commonStyle.opacity = retrieve3(style.opacity, topStyle.opacity, 1);
  13403. };
  13404. ZRText.makeFont = function (style) {
  13405. var font = '';
  13406. if (hasSeparateFont(style)) {
  13407. font = [
  13408. style.fontStyle,
  13409. style.fontWeight,
  13410. parseFontSize(style.fontSize),
  13411. style.fontFamily || 'sans-serif'
  13412. ].join(' ');
  13413. }
  13414. return font && trim(font) || style.textFont || style.font;
  13415. };
  13416. return ZRText;
  13417. }(Displayable));
  13418. var VALID_TEXT_ALIGN = { left: true, right: 1, center: 1 };
  13419. var VALID_TEXT_VERTICAL_ALIGN = { top: 1, bottom: 1, middle: 1 };
  13420. var FONT_PARTS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily'];
  13421. function parseFontSize(fontSize) {
  13422. if (typeof fontSize === 'string'
  13423. && (fontSize.indexOf('px') !== -1
  13424. || fontSize.indexOf('rem') !== -1
  13425. || fontSize.indexOf('em') !== -1)) {
  13426. return fontSize;
  13427. }
  13428. else if (!isNaN(+fontSize)) {
  13429. return fontSize + 'px';
  13430. }
  13431. else {
  13432. return DEFAULT_FONT_SIZE + 'px';
  13433. }
  13434. }
  13435. function setSeparateFont(targetStyle, sourceStyle) {
  13436. for (var i = 0; i < FONT_PARTS.length; i++) {
  13437. var fontProp = FONT_PARTS[i];
  13438. var val = sourceStyle[fontProp];
  13439. if (val != null) {
  13440. targetStyle[fontProp] = val;
  13441. }
  13442. }
  13443. }
  13444. function hasSeparateFont(style) {
  13445. return style.fontSize != null || style.fontFamily || style.fontWeight;
  13446. }
  13447. function normalizeTextStyle(style) {
  13448. normalizeStyle(style);
  13449. each(style.rich, normalizeStyle);
  13450. return style;
  13451. }
  13452. function normalizeStyle(style) {
  13453. if (style) {
  13454. style.font = ZRText.makeFont(style);
  13455. var textAlign = style.align;
  13456. textAlign === 'middle' && (textAlign = 'center');
  13457. style.align = (textAlign == null || VALID_TEXT_ALIGN[textAlign]) ? textAlign : 'left';
  13458. var verticalAlign = style.verticalAlign;
  13459. verticalAlign === 'center' && (verticalAlign = 'middle');
  13460. style.verticalAlign = (verticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[verticalAlign]) ? verticalAlign : 'top';
  13461. var textPadding = style.padding;
  13462. if (textPadding) {
  13463. style.padding = normalizeCssArray(style.padding);
  13464. }
  13465. }
  13466. }
  13467. function getStroke(stroke, lineWidth) {
  13468. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  13469. ? null
  13470. : (stroke.image || stroke.colorStops)
  13471. ? '#000'
  13472. : stroke;
  13473. }
  13474. function getFill(fill) {
  13475. return (fill == null || fill === 'none')
  13476. ? null
  13477. : (fill.image || fill.colorStops)
  13478. ? '#000'
  13479. : fill;
  13480. }
  13481. function getTextXForPadding(x, textAlign, textPadding) {
  13482. return textAlign === 'right'
  13483. ? (x - textPadding[1])
  13484. : textAlign === 'center'
  13485. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  13486. : (x + textPadding[3]);
  13487. }
  13488. function getStyleText(style) {
  13489. var text = style.text;
  13490. text != null && (text += '');
  13491. return text;
  13492. }
  13493. function needDrawBackground(style) {
  13494. return !!(style.backgroundColor
  13495. || style.lineHeight
  13496. || (style.borderWidth && style.borderColor));
  13497. }
  13498. var ArcShape = (function () {
  13499. function ArcShape() {
  13500. this.cx = 0;
  13501. this.cy = 0;
  13502. this.r = 0;
  13503. this.startAngle = 0;
  13504. this.endAngle = Math.PI * 2;
  13505. this.clockwise = true;
  13506. }
  13507. return ArcShape;
  13508. }());
  13509. var Arc = (function (_super) {
  13510. __extends(Arc, _super);
  13511. function Arc(opts) {
  13512. return _super.call(this, opts) || this;
  13513. }
  13514. Arc.prototype.getDefaultStyle = function () {
  13515. return {
  13516. stroke: '#000',
  13517. fill: null
  13518. };
  13519. };
  13520. Arc.prototype.getDefaultShape = function () {
  13521. return new ArcShape();
  13522. };
  13523. Arc.prototype.buildPath = function (ctx, shape) {
  13524. var x = shape.cx;
  13525. var y = shape.cy;
  13526. var r = Math.max(shape.r, 0);
  13527. var startAngle = shape.startAngle;
  13528. var endAngle = shape.endAngle;
  13529. var clockwise = shape.clockwise;
  13530. var unitX = Math.cos(startAngle);
  13531. var unitY = Math.sin(startAngle);
  13532. ctx.moveTo(unitX * r + x, unitY * r + y);
  13533. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13534. };
  13535. return Arc;
  13536. }(Path));
  13537. Arc.prototype.type = 'arc';
  13538. var out = [];
  13539. var BezierCurveShape = (function () {
  13540. function BezierCurveShape() {
  13541. this.x1 = 0;
  13542. this.y1 = 0;
  13543. this.x2 = 0;
  13544. this.y2 = 0;
  13545. this.cpx1 = 0;
  13546. this.cpy1 = 0;
  13547. this.percent = 1;
  13548. }
  13549. return BezierCurveShape;
  13550. }());
  13551. function someVectorAt(shape, t, isTangent) {
  13552. var cpx2 = shape.cpx2;
  13553. var cpy2 = shape.cpy2;
  13554. if (cpx2 != null || cpy2 != null) {
  13555. return [
  13556. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  13557. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  13558. ];
  13559. }
  13560. else {
  13561. return [
  13562. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  13563. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  13564. ];
  13565. }
  13566. }
  13567. var BezierCurve = (function (_super) {
  13568. __extends(BezierCurve, _super);
  13569. function BezierCurve(opts) {
  13570. return _super.call(this, opts) || this;
  13571. }
  13572. BezierCurve.prototype.getDefaultStyle = function () {
  13573. return {
  13574. stroke: '#000',
  13575. fill: null
  13576. };
  13577. };
  13578. BezierCurve.prototype.getDefaultShape = function () {
  13579. return new BezierCurveShape();
  13580. };
  13581. BezierCurve.prototype.buildPath = function (ctx, shape) {
  13582. var x1 = shape.x1;
  13583. var y1 = shape.y1;
  13584. var x2 = shape.x2;
  13585. var y2 = shape.y2;
  13586. var cpx1 = shape.cpx1;
  13587. var cpy1 = shape.cpy1;
  13588. var cpx2 = shape.cpx2;
  13589. var cpy2 = shape.cpy2;
  13590. var percent = shape.percent;
  13591. if (percent === 0) {
  13592. return;
  13593. }
  13594. ctx.moveTo(x1, y1);
  13595. if (cpx2 == null || cpy2 == null) {
  13596. if (percent < 1) {
  13597. quadraticSubdivide(x1, cpx1, x2, percent, out);
  13598. cpx1 = out[1];
  13599. x2 = out[2];
  13600. quadraticSubdivide(y1, cpy1, y2, percent, out);
  13601. cpy1 = out[1];
  13602. y2 = out[2];
  13603. }
  13604. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  13605. }
  13606. else {
  13607. if (percent < 1) {
  13608. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  13609. cpx1 = out[1];
  13610. cpx2 = out[2];
  13611. x2 = out[3];
  13612. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  13613. cpy1 = out[1];
  13614. cpy2 = out[2];
  13615. y2 = out[3];
  13616. }
  13617. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  13618. }
  13619. };
  13620. BezierCurve.prototype.pointAt = function (t) {
  13621. return someVectorAt(this.shape, t, false);
  13622. };
  13623. BezierCurve.prototype.tangentAt = function (t) {
  13624. var p = someVectorAt(this.shape, t, true);
  13625. return normalize(p, p);
  13626. };
  13627. return BezierCurve;
  13628. }(Path));
  13629. BezierCurve.prototype.type = 'bezier-curve';
  13630. var DropletShape = (function () {
  13631. function DropletShape() {
  13632. this.cx = 0;
  13633. this.cy = 0;
  13634. this.width = 0;
  13635. this.height = 0;
  13636. }
  13637. return DropletShape;
  13638. }());
  13639. var Droplet = (function (_super) {
  13640. __extends(Droplet, _super);
  13641. function Droplet(opts) {
  13642. return _super.call(this, opts) || this;
  13643. }
  13644. Droplet.prototype.getDefaultShape = function () {
  13645. return new DropletShape();
  13646. };
  13647. Droplet.prototype.buildPath = function (ctx, shape) {
  13648. var x = shape.cx;
  13649. var y = shape.cy;
  13650. var a = shape.width;
  13651. var b = shape.height;
  13652. ctx.moveTo(x, y + a);
  13653. ctx.bezierCurveTo(x + a, y + a, x + a * 3 / 2, y - a / 3, x, y - b);
  13654. ctx.bezierCurveTo(x - a * 3 / 2, y - a / 3, x - a, y + a, x, y + a);
  13655. ctx.closePath();
  13656. };
  13657. return Droplet;
  13658. }(Path));
  13659. Droplet.prototype.type = 'droplet';
  13660. var HeartShape = (function () {
  13661. function HeartShape() {
  13662. this.cx = 0;
  13663. this.cy = 0;
  13664. this.width = 0;
  13665. this.height = 0;
  13666. }
  13667. return HeartShape;
  13668. }());
  13669. var Heart = (function (_super) {
  13670. __extends(Heart, _super);
  13671. function Heart(opts) {
  13672. return _super.call(this, opts) || this;
  13673. }
  13674. Heart.prototype.getDefaultShape = function () {
  13675. return new HeartShape();
  13676. };
  13677. Heart.prototype.buildPath = function (ctx, shape) {
  13678. var x = shape.cx;
  13679. var y = shape.cy;
  13680. var a = shape.width;
  13681. var b = shape.height;
  13682. ctx.moveTo(x, y);
  13683. ctx.bezierCurveTo(x + a / 2, y - b * 2 / 3, x + a * 2, y + b / 3, x, y + b);
  13684. ctx.bezierCurveTo(x - a * 2, y + b / 3, x - a / 2, y - b * 2 / 3, x, y);
  13685. };
  13686. return Heart;
  13687. }(Path));
  13688. Heart.prototype.type = 'heart';
  13689. var PI$3 = Math.PI;
  13690. var sin = Math.sin;
  13691. var cos = Math.cos;
  13692. var IsogonShape = (function () {
  13693. function IsogonShape() {
  13694. this.x = 0;
  13695. this.y = 0;
  13696. this.r = 0;
  13697. this.n = 0;
  13698. }
  13699. return IsogonShape;
  13700. }());
  13701. var Isogon = (function (_super) {
  13702. __extends(Isogon, _super);
  13703. function Isogon(opts) {
  13704. return _super.call(this, opts) || this;
  13705. }
  13706. Isogon.prototype.getDefaultShape = function () {
  13707. return new IsogonShape();
  13708. };
  13709. Isogon.prototype.buildPath = function (ctx, shape) {
  13710. var n = shape.n;
  13711. if (!n || n < 2) {
  13712. return;
  13713. }
  13714. var x = shape.x;
  13715. var y = shape.y;
  13716. var r = shape.r;
  13717. var dStep = 2 * PI$3 / n;
  13718. var deg = -PI$3 / 2;
  13719. ctx.moveTo(x + r * cos(deg), y + r * sin(deg));
  13720. for (var i = 0, end = n - 1; i < end; i++) {
  13721. deg += dStep;
  13722. ctx.lineTo(x + r * cos(deg), y + r * sin(deg));
  13723. }
  13724. ctx.closePath();
  13725. return;
  13726. };
  13727. return Isogon;
  13728. }(Path));
  13729. Isogon.prototype.type = 'isogon';
  13730. var RingShape = (function () {
  13731. function RingShape() {
  13732. this.cx = 0;
  13733. this.cy = 0;
  13734. this.r = 0;
  13735. this.r0 = 0;
  13736. }
  13737. return RingShape;
  13738. }());
  13739. var Ring = (function (_super) {
  13740. __extends(Ring, _super);
  13741. function Ring(opts) {
  13742. return _super.call(this, opts) || this;
  13743. }
  13744. Ring.prototype.getDefaultShape = function () {
  13745. return new RingShape();
  13746. };
  13747. Ring.prototype.buildPath = function (ctx, shape) {
  13748. var x = shape.cx;
  13749. var y = shape.cy;
  13750. var PI2 = Math.PI * 2;
  13751. ctx.moveTo(x + shape.r, y);
  13752. ctx.arc(x, y, shape.r, 0, PI2, false);
  13753. ctx.moveTo(x + shape.r0, y);
  13754. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13755. };
  13756. return Ring;
  13757. }(Path));
  13758. Ring.prototype.type = 'ring';
  13759. var sin$1 = Math.sin;
  13760. var cos$1 = Math.cos;
  13761. var radian = Math.PI / 180;
  13762. var RoseShape = (function () {
  13763. function RoseShape() {
  13764. this.cx = 0;
  13765. this.cy = 0;
  13766. this.r = [];
  13767. this.k = 0;
  13768. this.n = 1;
  13769. }
  13770. return RoseShape;
  13771. }());
  13772. var Rose = (function (_super) {
  13773. __extends(Rose, _super);
  13774. function Rose(opts) {
  13775. return _super.call(this, opts) || this;
  13776. }
  13777. Rose.prototype.getDefaultStyle = function () {
  13778. return {
  13779. stroke: '#000',
  13780. fill: null
  13781. };
  13782. };
  13783. Rose.prototype.getDefaultShape = function () {
  13784. return new RoseShape();
  13785. };
  13786. Rose.prototype.buildPath = function (ctx, shape) {
  13787. var R = shape.r;
  13788. var k = shape.k;
  13789. var n = shape.n;
  13790. var x0 = shape.cx;
  13791. var y0 = shape.cy;
  13792. var x;
  13793. var y;
  13794. var r;
  13795. ctx.moveTo(x0, y0);
  13796. for (var i = 0, len = R.length; i < len; i++) {
  13797. r = R[i];
  13798. for (var j = 0; j <= 360 * n; j++) {
  13799. x = r
  13800. * sin$1(k / n * j % 360 * radian)
  13801. * cos$1(j * radian)
  13802. + x0;
  13803. y = r
  13804. * sin$1(k / n * j % 360 * radian)
  13805. * sin$1(j * radian)
  13806. + y0;
  13807. ctx.lineTo(x, y);
  13808. }
  13809. }
  13810. };
  13811. return Rose;
  13812. }(Path));
  13813. Rose.prototype.type = 'rose';
  13814. var PI$4 = Math.PI;
  13815. var cos$2 = Math.cos;
  13816. var sin$2 = Math.sin;
  13817. var StarShape = (function () {
  13818. function StarShape() {
  13819. this.cx = 0;
  13820. this.cy = 0;
  13821. this.n = 3;
  13822. this.r = 0;
  13823. }
  13824. return StarShape;
  13825. }());
  13826. var Star = (function (_super) {
  13827. __extends(Star, _super);
  13828. function Star(opts) {
  13829. return _super.call(this, opts) || this;
  13830. }
  13831. Star.prototype.getDefaultShape = function () {
  13832. return new StarShape();
  13833. };
  13834. Star.prototype.buildPath = function (ctx, shape) {
  13835. var n = shape.n;
  13836. if (!n || n < 2) {
  13837. return;
  13838. }
  13839. var x = shape.cx;
  13840. var y = shape.cy;
  13841. var r = shape.r;
  13842. var r0 = shape.r0;
  13843. if (r0 == null) {
  13844. r0 = n > 4
  13845. ? r * cos$2(2 * PI$4 / n) / cos$2(PI$4 / n)
  13846. : r / 3;
  13847. }
  13848. var dStep = PI$4 / n;
  13849. var deg = -PI$4 / 2;
  13850. var xStart = x + r * cos$2(deg);
  13851. var yStart = y + r * sin$2(deg);
  13852. deg += dStep;
  13853. ctx.moveTo(xStart, yStart);
  13854. for (var i = 0, end = n * 2 - 1, ri = void 0; i < end; i++) {
  13855. ri = i % 2 === 0 ? r0 : r;
  13856. ctx.lineTo(x + ri * cos$2(deg), y + ri * sin$2(deg));
  13857. deg += dStep;
  13858. }
  13859. ctx.closePath();
  13860. };
  13861. return Star;
  13862. }(Path));
  13863. Star.prototype.type = 'star';
  13864. var cos$3 = Math.cos;
  13865. var sin$3 = Math.sin;
  13866. var TrochoidShape = (function () {
  13867. function TrochoidShape() {
  13868. this.cx = 0;
  13869. this.cy = 0;
  13870. this.r = 0;
  13871. this.r0 = 0;
  13872. this.d = 0;
  13873. this.location = 'out';
  13874. }
  13875. return TrochoidShape;
  13876. }());
  13877. var Trochoid = (function (_super) {
  13878. __extends(Trochoid, _super);
  13879. function Trochoid(opts) {
  13880. return _super.call(this, opts) || this;
  13881. }
  13882. Trochoid.prototype.getDefaultStyle = function () {
  13883. return {
  13884. stroke: '#000',
  13885. fill: null
  13886. };
  13887. };
  13888. Trochoid.prototype.getDefaultShape = function () {
  13889. return new TrochoidShape();
  13890. };
  13891. Trochoid.prototype.buildPath = function (ctx, shape) {
  13892. var R = shape.r;
  13893. var r = shape.r0;
  13894. var d = shape.d;
  13895. var offsetX = shape.cx;
  13896. var offsetY = shape.cy;
  13897. var delta = shape.location === 'out' ? 1 : -1;
  13898. var x1;
  13899. var y1;
  13900. var x2;
  13901. var y2;
  13902. if (shape.location && R <= r) {
  13903. return;
  13904. }
  13905. var num = 0;
  13906. var i = 1;
  13907. var theta;
  13908. x1 = (R + delta * r) * cos$3(0)
  13909. - delta * d * cos$3(0) + offsetX;
  13910. y1 = (R + delta * r) * sin$3(0)
  13911. - d * sin$3(0) + offsetY;
  13912. ctx.moveTo(x1, y1);
  13913. do {
  13914. num++;
  13915. } while ((r * num) % (R + delta * r) !== 0);
  13916. do {
  13917. theta = Math.PI / 180 * i;
  13918. x2 = (R + delta * r) * cos$3(theta)
  13919. - delta * d * cos$3((R / r + delta) * theta)
  13920. + offsetX;
  13921. y2 = (R + delta * r) * sin$3(theta)
  13922. - d * sin$3((R / r + delta) * theta)
  13923. + offsetY;
  13924. ctx.lineTo(x2, y2);
  13925. i++;
  13926. } while (i <= (r * num) / (R + delta * r) * 360);
  13927. };
  13928. return Trochoid;
  13929. }(Path));
  13930. Trochoid.prototype.type = 'trochoid';
  13931. var Pattern = (function () {
  13932. function Pattern(image, repeat) {
  13933. this.image = image;
  13934. this.repeat = repeat;
  13935. this.x = 0;
  13936. this.y = 0;
  13937. this.rotation = 0;
  13938. this.scaleX = 1;
  13939. this.scaleY = 1;
  13940. }
  13941. return Pattern;
  13942. }());
  13943. var extent = [0, 0];
  13944. var extent2 = [0, 0];
  13945. var minTv$1 = new Point();
  13946. var maxTv$1 = new Point();
  13947. var OrientedBoundingRect = (function () {
  13948. function OrientedBoundingRect(rect, transform) {
  13949. this._corners = [];
  13950. this._axes = [];
  13951. this._origin = [0, 0];
  13952. for (var i = 0; i < 4; i++) {
  13953. this._corners[i] = new Point();
  13954. }
  13955. for (var i = 0; i < 2; i++) {
  13956. this._axes[i] = new Point();
  13957. }
  13958. if (rect) {
  13959. this.fromBoundingRect(rect, transform);
  13960. }
  13961. }
  13962. OrientedBoundingRect.prototype.fromBoundingRect = function (rect, transform) {
  13963. var corners = this._corners;
  13964. var axes = this._axes;
  13965. var x = rect.x;
  13966. var y = rect.y;
  13967. var x2 = x + rect.width;
  13968. var y2 = y + rect.height;
  13969. corners[0].set(x, y);
  13970. corners[1].set(x2, y);
  13971. corners[2].set(x2, y2);
  13972. corners[3].set(x, y2);
  13973. if (transform) {
  13974. for (var i = 0; i < 4; i++) {
  13975. corners[i].transform(transform);
  13976. }
  13977. }
  13978. Point.sub(axes[0], corners[1], corners[0]);
  13979. Point.sub(axes[1], corners[3], corners[0]);
  13980. axes[0].normalize();
  13981. axes[1].normalize();
  13982. for (var i = 0; i < 2; i++) {
  13983. this._origin[i] = axes[i].dot(corners[0]);
  13984. }
  13985. };
  13986. OrientedBoundingRect.prototype.intersect = function (other, mtv) {
  13987. var overlapped = true;
  13988. var noMtv = !mtv;
  13989. minTv$1.set(Infinity, Infinity);
  13990. maxTv$1.set(0, 0);
  13991. if (!this._intersectCheckOneSide(this, other, minTv$1, maxTv$1, noMtv, 1)) {
  13992. overlapped = false;
  13993. if (noMtv) {
  13994. return overlapped;
  13995. }
  13996. }
  13997. if (!this._intersectCheckOneSide(other, this, minTv$1, maxTv$1, noMtv, -1)) {
  13998. overlapped = false;
  13999. if (noMtv) {
  14000. return overlapped;
  14001. }
  14002. }
  14003. if (!noMtv) {
  14004. Point.copy(mtv, overlapped ? minTv$1 : maxTv$1);
  14005. }
  14006. return overlapped;
  14007. };
  14008. OrientedBoundingRect.prototype._intersectCheckOneSide = function (self, other, minTv, maxTv, noMtv, inverse) {
  14009. var overlapped = true;
  14010. for (var i = 0; i < 2; i++) {
  14011. var axis = this._axes[i];
  14012. this._getProjMinMaxOnAxis(i, self._corners, extent);
  14013. this._getProjMinMaxOnAxis(i, other._corners, extent2);
  14014. if (extent[1] < extent2[0] || extent[0] > extent2[1]) {
  14015. overlapped = false;
  14016. if (noMtv) {
  14017. return overlapped;
  14018. }
  14019. var dist0 = Math.abs(extent2[0] - extent[1]);
  14020. var dist1 = Math.abs(extent[0] - extent2[1]);
  14021. if (Math.min(dist0, dist1) > maxTv.len()) {
  14022. if (dist0 < dist1) {
  14023. Point.scale(maxTv, axis, -dist0 * inverse);
  14024. }
  14025. else {
  14026. Point.scale(maxTv, axis, dist1 * inverse);
  14027. }
  14028. }
  14029. }
  14030. else if (minTv) {
  14031. var dist0 = Math.abs(extent2[0] - extent[1]);
  14032. var dist1 = Math.abs(extent[0] - extent2[1]);
  14033. if (Math.min(dist0, dist1) < minTv.len()) {
  14034. if (dist0 < dist1) {
  14035. Point.scale(minTv, axis, dist0 * inverse);
  14036. }
  14037. else {
  14038. Point.scale(minTv, axis, -dist1 * inverse);
  14039. }
  14040. }
  14041. }
  14042. }
  14043. return overlapped;
  14044. };
  14045. OrientedBoundingRect.prototype._getProjMinMaxOnAxis = function (dim, corners, out) {
  14046. var axis = this._axes[dim];
  14047. var origin = this._origin;
  14048. var proj = corners[0].dot(axis) + origin[dim];
  14049. var min = proj;
  14050. var max = proj;
  14051. for (var i = 1; i < corners.length; i++) {
  14052. var proj_1 = corners[i].dot(axis) + origin[dim];
  14053. min = Math.min(proj_1, min);
  14054. max = Math.max(proj_1, max);
  14055. }
  14056. out[0] = min;
  14057. out[1] = max;
  14058. };
  14059. return OrientedBoundingRect;
  14060. }());
  14061. var DebugRect = (function () {
  14062. function DebugRect(style) {
  14063. var dom = this.dom = document.createElement('div');
  14064. dom.className = 'ec-debug-dirty-rect';
  14065. style = extend({}, style);
  14066. extend(style, {
  14067. backgroundColor: 'rgba(0, 0, 255, 0.2)',
  14068. border: '1px solid #00f'
  14069. });
  14070. dom.style.cssText = "\nposition: absolute;\nopacity: 0;\ntransition: opacity 0.5s linear;\npointer-events: none;\n";
  14071. for (var key in style) {
  14072. if (style.hasOwnProperty(key)) {
  14073. dom.style[key] = style[key];
  14074. }
  14075. }
  14076. }
  14077. DebugRect.prototype.update = function (rect) {
  14078. var domStyle = this.dom.style;
  14079. domStyle.width = rect.width + 'px';
  14080. domStyle.height = rect.height + 'px';
  14081. domStyle.left = rect.x + 'px';
  14082. domStyle.top = rect.y + 'px';
  14083. };
  14084. DebugRect.prototype.hide = function () {
  14085. this.dom.style.opacity = '0';
  14086. };
  14087. DebugRect.prototype.show = function (autoHideDelay) {
  14088. var _this = this;
  14089. clearTimeout(this._hideTimeout);
  14090. this.dom.style.opacity = '1';
  14091. this._hideTimeout = setTimeout(function () {
  14092. _this.hide();
  14093. }, autoHideDelay || 1000);
  14094. };
  14095. return DebugRect;
  14096. }());
  14097. function showDebugDirtyRect(zr, opts) {
  14098. opts = opts || {};
  14099. var painter = zr.painter;
  14100. if (!painter.getLayers) {
  14101. throw new Error('Debug dirty rect can only been used on canvas renderer.');
  14102. }
  14103. if (painter.isSingleCanvas()) {
  14104. throw new Error('Debug dirty rect can only been used on zrender inited with container.');
  14105. }
  14106. var debugViewRoot = document.createElement('div');
  14107. debugViewRoot.style.cssText = "\nposition:absolute;\nleft:0;\ntop:0;\nright:0;\nbottom:0;\npointer-events:none;\n";
  14108. debugViewRoot.className = 'ec-debug-dirty-rect-container';
  14109. var debugRects = [];
  14110. var dom = zr.dom;
  14111. dom.appendChild(debugViewRoot);
  14112. var computedStyle = getComputedStyle(dom);
  14113. if (computedStyle.position === 'static') {
  14114. dom.style.position = 'relative';
  14115. }
  14116. zr.on('rendered', function () {
  14117. if (painter.getLayers) {
  14118. var idx_1 = 0;
  14119. painter.eachBuiltinLayer(function (layer) {
  14120. if (!layer.debugGetPaintRects) {
  14121. return;
  14122. }
  14123. var paintRects = layer.debugGetPaintRects();
  14124. for (var i = 0; i < paintRects.length; i++) {
  14125. if (!paintRects[i].width || !paintRects[i].height) {
  14126. continue;
  14127. }
  14128. if (!debugRects[idx_1]) {
  14129. debugRects[idx_1] = new DebugRect(opts.style);
  14130. debugViewRoot.appendChild(debugRects[idx_1].dom);
  14131. }
  14132. debugRects[idx_1].show(opts.autoHideDelay);
  14133. debugRects[idx_1].update(paintRects[i]);
  14134. idx_1++;
  14135. }
  14136. });
  14137. for (var i = idx_1; i < debugRects.length; i++) {
  14138. debugRects[i].hide();
  14139. }
  14140. }
  14141. });
  14142. }
  14143. function isSafeNum(num) {
  14144. return isFinite(num);
  14145. }
  14146. function createLinearGradient(ctx, obj, rect) {
  14147. var x = obj.x == null ? 0 : obj.x;
  14148. var x2 = obj.x2 == null ? 1 : obj.x2;
  14149. var y = obj.y == null ? 0 : obj.y;
  14150. var y2 = obj.y2 == null ? 0 : obj.y2;
  14151. if (!obj.global) {
  14152. x = x * rect.width + rect.x;
  14153. x2 = x2 * rect.width + rect.x;
  14154. y = y * rect.height + rect.y;
  14155. y2 = y2 * rect.height + rect.y;
  14156. }
  14157. x = isSafeNum(x) ? x : 0;
  14158. x2 = isSafeNum(x2) ? x2 : 1;
  14159. y = isSafeNum(y) ? y : 0;
  14160. y2 = isSafeNum(y2) ? y2 : 0;
  14161. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  14162. return canvasGradient;
  14163. }
  14164. function createRadialGradient(ctx, obj, rect) {
  14165. var width = rect.width;
  14166. var height = rect.height;
  14167. var min = Math.min(width, height);
  14168. var x = obj.x == null ? 0.5 : obj.x;
  14169. var y = obj.y == null ? 0.5 : obj.y;
  14170. var r = obj.r == null ? 0.5 : obj.r;
  14171. if (!obj.global) {
  14172. x = x * width + rect.x;
  14173. y = y * height + rect.y;
  14174. r = r * min;
  14175. }
  14176. x = isSafeNum(x) ? x : 0.5;
  14177. y = isSafeNum(y) ? y : 0.5;
  14178. r = r >= 0 && isSafeNum(r) ? r : 0.5;
  14179. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  14180. return canvasGradient;
  14181. }
  14182. function getCanvasGradient(ctx, obj, rect) {
  14183. var canvasGradient = obj.type === 'radial'
  14184. ? createRadialGradient(ctx, obj, rect)
  14185. : createLinearGradient(ctx, obj, rect);
  14186. var colorStops = obj.colorStops;
  14187. for (var i = 0; i < colorStops.length; i++) {
  14188. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  14189. }
  14190. return canvasGradient;
  14191. }
  14192. function isClipPathChanged(clipPaths, prevClipPaths) {
  14193. if (clipPaths === prevClipPaths || (!clipPaths && !prevClipPaths)) {
  14194. return false;
  14195. }
  14196. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  14197. return true;
  14198. }
  14199. for (var i = 0; i < clipPaths.length; i++) {
  14200. if (clipPaths[i] !== prevClipPaths[i]) {
  14201. return true;
  14202. }
  14203. }
  14204. return false;
  14205. }
  14206. function parseInt10(val) {
  14207. return parseInt(val, 10);
  14208. }
  14209. function getSize(root, whIdx, opts) {
  14210. var wh = ['width', 'height'][whIdx];
  14211. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  14212. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  14213. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  14214. if (opts[wh] != null && opts[wh] !== 'auto') {
  14215. return parseFloat(opts[wh]);
  14216. }
  14217. var stl = document.defaultView.getComputedStyle(root);
  14218. return ((root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  14219. - (parseInt10(stl[plt]) || 0)
  14220. - (parseInt10(stl[prb]) || 0)) | 0;
  14221. }
  14222. function normalizeLineDash(lineType, lineWidth) {
  14223. if (!lineType || lineType === 'solid' || !(lineWidth > 0)) {
  14224. return null;
  14225. }
  14226. return lineType === 'dashed'
  14227. ? [4 * lineWidth, 2 * lineWidth]
  14228. : lineType === 'dotted'
  14229. ? [lineWidth]
  14230. : isNumber(lineType)
  14231. ? [lineType] : isArray(lineType) ? lineType : null;
  14232. }
  14233. function getLineDash(el) {
  14234. var style = el.style;
  14235. var lineDash = style.lineDash && style.lineWidth > 0 && normalizeLineDash(style.lineDash, style.lineWidth);
  14236. var lineDashOffset = style.lineDashOffset;
  14237. if (lineDash) {
  14238. var lineScale_1 = (style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1;
  14239. if (lineScale_1 && lineScale_1 !== 1) {
  14240. lineDash = map(lineDash, function (rawVal) {
  14241. return rawVal / lineScale_1;
  14242. });
  14243. lineDashOffset /= lineScale_1;
  14244. }
  14245. }
  14246. return [lineDash, lineDashOffset];
  14247. }
  14248. var pathProxyForDraw = new PathProxy(true);
  14249. function styleHasStroke(style) {
  14250. var stroke = style.stroke;
  14251. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  14252. }
  14253. function isValidStrokeFillStyle(strokeOrFill) {
  14254. return typeof strokeOrFill === 'string' && strokeOrFill !== 'none';
  14255. }
  14256. function styleHasFill(style) {
  14257. var fill = style.fill;
  14258. return fill != null && fill !== 'none';
  14259. }
  14260. function doFillPath(ctx, style) {
  14261. if (style.fillOpacity != null && style.fillOpacity !== 1) {
  14262. var originalGlobalAlpha = ctx.globalAlpha;
  14263. ctx.globalAlpha = style.fillOpacity * style.opacity;
  14264. ctx.fill();
  14265. ctx.globalAlpha = originalGlobalAlpha;
  14266. }
  14267. else {
  14268. ctx.fill();
  14269. }
  14270. }
  14271. function doStrokePath(ctx, style) {
  14272. if (style.strokeOpacity != null && style.strokeOpacity !== 1) {
  14273. var originalGlobalAlpha = ctx.globalAlpha;
  14274. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  14275. ctx.stroke();
  14276. ctx.globalAlpha = originalGlobalAlpha;
  14277. }
  14278. else {
  14279. ctx.stroke();
  14280. }
  14281. }
  14282. function createCanvasPattern(ctx, pattern, el) {
  14283. var image = createOrUpdateImage(pattern.image, pattern.__image, el);
  14284. if (isImageReady(image)) {
  14285. var canvasPattern = ctx.createPattern(image, pattern.repeat || 'repeat');
  14286. if (typeof DOMMatrix === 'function'
  14287. && canvasPattern
  14288. && canvasPattern.setTransform) {
  14289. var matrix = new DOMMatrix();
  14290. matrix.translateSelf((pattern.x || 0), (pattern.y || 0));
  14291. matrix.rotateSelf(0, 0, (pattern.rotation || 0) * RADIAN_TO_DEGREE);
  14292. matrix.scaleSelf((pattern.scaleX || 1), (pattern.scaleY || 1));
  14293. canvasPattern.setTransform(matrix);
  14294. }
  14295. return canvasPattern;
  14296. }
  14297. }
  14298. function brushPath(ctx, el, style, inBatch) {
  14299. var _a;
  14300. var hasStroke = styleHasStroke(style);
  14301. var hasFill = styleHasFill(style);
  14302. var strokePercent = style.strokePercent;
  14303. var strokePart = strokePercent < 1;
  14304. var firstDraw = !el.path;
  14305. if ((!el.silent || strokePart) && firstDraw) {
  14306. el.createPathProxy();
  14307. }
  14308. var path = el.path || pathProxyForDraw;
  14309. var dirtyFlag = el.__dirty;
  14310. if (!inBatch) {
  14311. var fill = style.fill;
  14312. var stroke = style.stroke;
  14313. var hasFillGradient = hasFill && !!fill.colorStops;
  14314. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  14315. var hasFillPattern = hasFill && !!fill.image;
  14316. var hasStrokePattern = hasStroke && !!stroke.image;
  14317. var fillGradient = void 0;
  14318. var strokeGradient = void 0;
  14319. var fillPattern = void 0;
  14320. var strokePattern = void 0;
  14321. var rect = void 0;
  14322. if (hasFillGradient || hasStrokeGradient) {
  14323. rect = el.getBoundingRect();
  14324. }
  14325. if (hasFillGradient) {
  14326. fillGradient = dirtyFlag
  14327. ? getCanvasGradient(ctx, fill, rect)
  14328. : el.__canvasFillGradient;
  14329. el.__canvasFillGradient = fillGradient;
  14330. }
  14331. if (hasStrokeGradient) {
  14332. strokeGradient = dirtyFlag
  14333. ? getCanvasGradient(ctx, stroke, rect)
  14334. : el.__canvasStrokeGradient;
  14335. el.__canvasStrokeGradient = strokeGradient;
  14336. }
  14337. if (hasFillPattern) {
  14338. fillPattern = (dirtyFlag || !el.__canvasFillPattern)
  14339. ? createCanvasPattern(ctx, fill, el)
  14340. : el.__canvasFillPattern;
  14341. el.__canvasFillPattern = fillPattern;
  14342. }
  14343. if (hasStrokePattern) {
  14344. strokePattern = (dirtyFlag || !el.__canvasStrokePattern)
  14345. ? createCanvasPattern(ctx, stroke, el)
  14346. : el.__canvasStrokePattern;
  14347. el.__canvasStrokePattern = fillPattern;
  14348. }
  14349. if (hasFillGradient) {
  14350. ctx.fillStyle = fillGradient;
  14351. }
  14352. else if (hasFillPattern) {
  14353. if (fillPattern) {
  14354. ctx.fillStyle = fillPattern;
  14355. }
  14356. else {
  14357. hasFill = false;
  14358. }
  14359. }
  14360. if (hasStrokeGradient) {
  14361. ctx.strokeStyle = strokeGradient;
  14362. }
  14363. else if (hasStrokePattern) {
  14364. if (strokePattern) {
  14365. ctx.strokeStyle = strokePattern;
  14366. }
  14367. else {
  14368. hasStroke = false;
  14369. }
  14370. }
  14371. }
  14372. var scale = el.getGlobalScale();
  14373. path.setScale(scale[0], scale[1], el.segmentIgnoreThreshold);
  14374. var lineDash;
  14375. var lineDashOffset;
  14376. if (ctx.setLineDash && style.lineDash) {
  14377. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14378. }
  14379. var needsRebuild = true;
  14380. if (firstDraw || (dirtyFlag & SHAPE_CHANGED_BIT)) {
  14381. path.setDPR(ctx.dpr);
  14382. if (strokePart) {
  14383. path.setContext(null);
  14384. }
  14385. else {
  14386. path.setContext(ctx);
  14387. needsRebuild = false;
  14388. }
  14389. path.reset();
  14390. el.buildPath(path, el.shape, inBatch);
  14391. path.toStatic();
  14392. el.pathUpdated();
  14393. }
  14394. if (needsRebuild) {
  14395. path.rebuildPath(ctx, strokePart ? strokePercent : 1);
  14396. }
  14397. if (lineDash) {
  14398. ctx.setLineDash(lineDash);
  14399. ctx.lineDashOffset = lineDashOffset;
  14400. }
  14401. if (!inBatch) {
  14402. if (style.strokeFirst) {
  14403. if (hasStroke) {
  14404. doStrokePath(ctx, style);
  14405. }
  14406. if (hasFill) {
  14407. doFillPath(ctx, style);
  14408. }
  14409. }
  14410. else {
  14411. if (hasFill) {
  14412. doFillPath(ctx, style);
  14413. }
  14414. if (hasStroke) {
  14415. doStrokePath(ctx, style);
  14416. }
  14417. }
  14418. }
  14419. if (lineDash) {
  14420. ctx.setLineDash([]);
  14421. }
  14422. }
  14423. function brushImage(ctx, el, style) {
  14424. var image = el.__image = createOrUpdateImage(style.image, el.__image, el, el.onload);
  14425. if (!image || !isImageReady(image)) {
  14426. return;
  14427. }
  14428. var x = style.x || 0;
  14429. var y = style.y || 0;
  14430. var width = el.getWidth();
  14431. var height = el.getHeight();
  14432. var aspect = image.width / image.height;
  14433. if (width == null && height != null) {
  14434. width = height * aspect;
  14435. }
  14436. else if (height == null && width != null) {
  14437. height = width / aspect;
  14438. }
  14439. else if (width == null && height == null) {
  14440. width = image.width;
  14441. height = image.height;
  14442. }
  14443. if (style.sWidth && style.sHeight) {
  14444. var sx = style.sx || 0;
  14445. var sy = style.sy || 0;
  14446. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  14447. }
  14448. else if (style.sx && style.sy) {
  14449. var sx = style.sx;
  14450. var sy = style.sy;
  14451. var sWidth = width - sx;
  14452. var sHeight = height - sy;
  14453. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  14454. }
  14455. else {
  14456. ctx.drawImage(image, x, y, width, height);
  14457. }
  14458. }
  14459. function brushText(ctx, el, style) {
  14460. var _a;
  14461. var text = style.text;
  14462. text != null && (text += '');
  14463. if (text) {
  14464. ctx.font = style.font || DEFAULT_FONT;
  14465. ctx.textAlign = style.textAlign;
  14466. ctx.textBaseline = style.textBaseline;
  14467. var lineDash = void 0;
  14468. var lineDashOffset = void 0;
  14469. if (ctx.setLineDash && style.lineDash) {
  14470. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14471. }
  14472. if (lineDash) {
  14473. ctx.setLineDash(lineDash);
  14474. ctx.lineDashOffset = lineDashOffset;
  14475. }
  14476. if (style.strokeFirst) {
  14477. if (styleHasStroke(style)) {
  14478. ctx.strokeText(text, style.x, style.y);
  14479. }
  14480. if (styleHasFill(style)) {
  14481. ctx.fillText(text, style.x, style.y);
  14482. }
  14483. }
  14484. else {
  14485. if (styleHasFill(style)) {
  14486. ctx.fillText(text, style.x, style.y);
  14487. }
  14488. if (styleHasStroke(style)) {
  14489. ctx.strokeText(text, style.x, style.y);
  14490. }
  14491. }
  14492. if (lineDash) {
  14493. ctx.setLineDash([]);
  14494. }
  14495. }
  14496. }
  14497. var SHADOW_NUMBER_PROPS = ['shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  14498. var STROKE_PROPS = [
  14499. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  14500. ];
  14501. function bindCommonProps(ctx, style, prevStyle, forceSetAll, scope) {
  14502. var styleChanged = false;
  14503. if (!forceSetAll) {
  14504. prevStyle = prevStyle || {};
  14505. if (style === prevStyle) {
  14506. return false;
  14507. }
  14508. }
  14509. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14510. flushPathDrawn(ctx, scope);
  14511. styleChanged = true;
  14512. var opacity = Math.max(Math.min(style.opacity, 1), 0);
  14513. ctx.globalAlpha = isNaN(opacity) ? DEFAULT_COMMON_STYLE.opacity : opacity;
  14514. }
  14515. if (forceSetAll || style.blend !== prevStyle.blend) {
  14516. if (!styleChanged) {
  14517. flushPathDrawn(ctx, scope);
  14518. styleChanged = true;
  14519. }
  14520. ctx.globalCompositeOperation = style.blend || DEFAULT_COMMON_STYLE.blend;
  14521. }
  14522. for (var i = 0; i < SHADOW_NUMBER_PROPS.length; i++) {
  14523. var propName = SHADOW_NUMBER_PROPS[i];
  14524. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14525. if (!styleChanged) {
  14526. flushPathDrawn(ctx, scope);
  14527. styleChanged = true;
  14528. }
  14529. ctx[propName] = ctx.dpr * (style[propName] || 0);
  14530. }
  14531. }
  14532. if (forceSetAll || style.shadowColor !== prevStyle.shadowColor) {
  14533. if (!styleChanged) {
  14534. flushPathDrawn(ctx, scope);
  14535. styleChanged = true;
  14536. }
  14537. ctx.shadowColor = style.shadowColor || DEFAULT_COMMON_STYLE.shadowColor;
  14538. }
  14539. return styleChanged;
  14540. }
  14541. function bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetAll, scope) {
  14542. var style = getStyle(el, scope.inHover);
  14543. var prevStyle = forceSetAll
  14544. ? null
  14545. : (prevEl && getStyle(prevEl, scope.inHover) || {});
  14546. if (style === prevStyle) {
  14547. return false;
  14548. }
  14549. var styleChanged = bindCommonProps(ctx, style, prevStyle, forceSetAll, scope);
  14550. if (forceSetAll || style.fill !== prevStyle.fill) {
  14551. if (!styleChanged) {
  14552. flushPathDrawn(ctx, scope);
  14553. styleChanged = true;
  14554. }
  14555. isValidStrokeFillStyle(style.fill) && (ctx.fillStyle = style.fill);
  14556. }
  14557. if (forceSetAll || style.stroke !== prevStyle.stroke) {
  14558. if (!styleChanged) {
  14559. flushPathDrawn(ctx, scope);
  14560. styleChanged = true;
  14561. }
  14562. isValidStrokeFillStyle(style.stroke) && (ctx.strokeStyle = style.stroke);
  14563. }
  14564. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14565. if (!styleChanged) {
  14566. flushPathDrawn(ctx, scope);
  14567. styleChanged = true;
  14568. }
  14569. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  14570. }
  14571. if (el.hasStroke()) {
  14572. var lineWidth = style.lineWidth;
  14573. var newLineWidth = lineWidth / ((style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1);
  14574. if (ctx.lineWidth !== newLineWidth) {
  14575. if (!styleChanged) {
  14576. flushPathDrawn(ctx, scope);
  14577. styleChanged = true;
  14578. }
  14579. ctx.lineWidth = newLineWidth;
  14580. }
  14581. }
  14582. for (var i = 0; i < STROKE_PROPS.length; i++) {
  14583. var prop = STROKE_PROPS[i];
  14584. var propName = prop[0];
  14585. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14586. if (!styleChanged) {
  14587. flushPathDrawn(ctx, scope);
  14588. styleChanged = true;
  14589. }
  14590. ctx[propName] = style[propName] || prop[1];
  14591. }
  14592. }
  14593. return styleChanged;
  14594. }
  14595. function bindImageStyle(ctx, el, prevEl, forceSetAll, scope) {
  14596. return bindCommonProps(ctx, getStyle(el, scope.inHover), prevEl && getStyle(prevEl, scope.inHover), forceSetAll, scope);
  14597. }
  14598. function setContextTransform(ctx, el) {
  14599. var m = el.transform;
  14600. var dpr = ctx.dpr || 1;
  14601. if (m) {
  14602. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  14603. }
  14604. else {
  14605. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  14606. }
  14607. }
  14608. function updateClipStatus(clipPaths, ctx, scope) {
  14609. var allClipped = false;
  14610. for (var i = 0; i < clipPaths.length; i++) {
  14611. var clipPath = clipPaths[i];
  14612. allClipped = allClipped || clipPath.isZeroArea();
  14613. setContextTransform(ctx, clipPath);
  14614. ctx.beginPath();
  14615. clipPath.buildPath(ctx, clipPath.shape);
  14616. ctx.clip();
  14617. }
  14618. scope.allClipped = allClipped;
  14619. }
  14620. function isTransformChanged(m0, m1) {
  14621. if (m0 && m1) {
  14622. return m0[0] !== m1[0]
  14623. || m0[1] !== m1[1]
  14624. || m0[2] !== m1[2]
  14625. || m0[3] !== m1[3]
  14626. || m0[4] !== m1[4]
  14627. || m0[5] !== m1[5];
  14628. }
  14629. else if (!m0 && !m1) {
  14630. return false;
  14631. }
  14632. return true;
  14633. }
  14634. var DRAW_TYPE_PATH = 1;
  14635. var DRAW_TYPE_IMAGE = 2;
  14636. var DRAW_TYPE_TEXT = 3;
  14637. var DRAW_TYPE_INCREMENTAL = 4;
  14638. function canPathBatch(style) {
  14639. var hasFill = styleHasFill(style);
  14640. var hasStroke = styleHasStroke(style);
  14641. return !(style.lineDash
  14642. || !(+hasFill ^ +hasStroke)
  14643. || (hasFill && typeof style.fill !== 'string')
  14644. || (hasStroke && typeof style.stroke !== 'string')
  14645. || style.strokePercent < 1
  14646. || style.strokeOpacity < 1
  14647. || style.fillOpacity < 1);
  14648. }
  14649. function flushPathDrawn(ctx, scope) {
  14650. scope.batchFill && ctx.fill();
  14651. scope.batchStroke && ctx.stroke();
  14652. scope.batchFill = '';
  14653. scope.batchStroke = '';
  14654. }
  14655. function getStyle(el, inHover) {
  14656. return inHover ? (el.__hoverStyle || el.style) : el.style;
  14657. }
  14658. function brushSingle(ctx, el) {
  14659. brush(ctx, el, { inHover: false, viewWidth: 0, viewHeight: 0 }, true);
  14660. }
  14661. function brush(ctx, el, scope, isLast) {
  14662. var m = el.transform;
  14663. if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false)) {
  14664. el.__dirty &= ~REDRAW_BIT;
  14665. el.__isRendered = false;
  14666. return;
  14667. }
  14668. var clipPaths = el.__clipPaths;
  14669. var prevElClipPaths = scope.prevElClipPaths;
  14670. var forceSetTransform = false;
  14671. var forceSetStyle = false;
  14672. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  14673. if (prevElClipPaths && prevElClipPaths.length) {
  14674. flushPathDrawn(ctx, scope);
  14675. ctx.restore();
  14676. forceSetStyle = forceSetTransform = true;
  14677. scope.prevElClipPaths = null;
  14678. scope.allClipped = false;
  14679. scope.prevEl = null;
  14680. }
  14681. if (clipPaths && clipPaths.length) {
  14682. flushPathDrawn(ctx, scope);
  14683. ctx.save();
  14684. updateClipStatus(clipPaths, ctx, scope);
  14685. forceSetTransform = true;
  14686. }
  14687. scope.prevElClipPaths = clipPaths;
  14688. }
  14689. if (scope.allClipped) {
  14690. el.__isRendered = false;
  14691. return;
  14692. }
  14693. el.beforeBrush && el.beforeBrush();
  14694. el.innerBeforeBrush();
  14695. var prevEl = scope.prevEl;
  14696. if (!prevEl) {
  14697. forceSetStyle = forceSetTransform = true;
  14698. }
  14699. var canBatchPath = el instanceof Path
  14700. && el.autoBatch
  14701. && canPathBatch(el.style);
  14702. if (forceSetTransform || isTransformChanged(m, prevEl.transform)) {
  14703. flushPathDrawn(ctx, scope);
  14704. setContextTransform(ctx, el);
  14705. }
  14706. else if (!canBatchPath) {
  14707. flushPathDrawn(ctx, scope);
  14708. }
  14709. var style = getStyle(el, scope.inHover);
  14710. if (el instanceof Path) {
  14711. if (scope.lastDrawType !== DRAW_TYPE_PATH) {
  14712. forceSetStyle = true;
  14713. scope.lastDrawType = DRAW_TYPE_PATH;
  14714. }
  14715. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14716. if (!canBatchPath || (!scope.batchFill && !scope.batchStroke)) {
  14717. ctx.beginPath();
  14718. }
  14719. brushPath(ctx, el, style, canBatchPath);
  14720. if (canBatchPath) {
  14721. scope.batchFill = style.fill || '';
  14722. scope.batchStroke = style.stroke || '';
  14723. }
  14724. }
  14725. else {
  14726. if (el instanceof TSpan) {
  14727. if (scope.lastDrawType !== DRAW_TYPE_TEXT) {
  14728. forceSetStyle = true;
  14729. scope.lastDrawType = DRAW_TYPE_TEXT;
  14730. }
  14731. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14732. brushText(ctx, el, style);
  14733. }
  14734. else if (el instanceof ZRImage) {
  14735. if (scope.lastDrawType !== DRAW_TYPE_IMAGE) {
  14736. forceSetStyle = true;
  14737. scope.lastDrawType = DRAW_TYPE_IMAGE;
  14738. }
  14739. bindImageStyle(ctx, el, prevEl, forceSetStyle, scope);
  14740. brushImage(ctx, el, style);
  14741. }
  14742. else if (el.getTemporalDisplayables) {
  14743. if (scope.lastDrawType !== DRAW_TYPE_INCREMENTAL) {
  14744. forceSetStyle = true;
  14745. scope.lastDrawType = DRAW_TYPE_INCREMENTAL;
  14746. }
  14747. brushIncremental(ctx, el, scope);
  14748. }
  14749. }
  14750. if (canBatchPath && isLast) {
  14751. flushPathDrawn(ctx, scope);
  14752. }
  14753. el.innerAfterBrush();
  14754. el.afterBrush && el.afterBrush();
  14755. scope.prevEl = el;
  14756. el.__dirty = 0;
  14757. el.__isRendered = true;
  14758. }
  14759. function brushIncremental(ctx, el, scope) {
  14760. var displayables = el.getDisplayables();
  14761. var temporalDisplayables = el.getTemporalDisplayables();
  14762. ctx.save();
  14763. var innerScope = {
  14764. prevElClipPaths: null,
  14765. prevEl: null,
  14766. allClipped: false,
  14767. viewWidth: scope.viewWidth,
  14768. viewHeight: scope.viewHeight,
  14769. inHover: scope.inHover
  14770. };
  14771. var i;
  14772. var len;
  14773. for (i = el.getCursor(), len = displayables.length; i < len; i++) {
  14774. var displayable = displayables[i];
  14775. displayable.beforeBrush && displayable.beforeBrush();
  14776. displayable.innerBeforeBrush();
  14777. brush(ctx, displayable, innerScope, i === len - 1);
  14778. displayable.innerAfterBrush();
  14779. displayable.afterBrush && displayable.afterBrush();
  14780. innerScope.prevEl = displayable;
  14781. }
  14782. for (var i_1 = 0, len_1 = temporalDisplayables.length; i_1 < len_1; i_1++) {
  14783. var displayable = temporalDisplayables[i_1];
  14784. displayable.beforeBrush && displayable.beforeBrush();
  14785. displayable.innerBeforeBrush();
  14786. brush(ctx, displayable, innerScope, i_1 === len_1 - 1);
  14787. displayable.innerAfterBrush();
  14788. displayable.afterBrush && displayable.afterBrush();
  14789. innerScope.prevEl = displayable;
  14790. }
  14791. el.clearTemporalDisplayables();
  14792. el.notClear = true;
  14793. ctx.restore();
  14794. }
  14795. function createDom(id, painter, dpr) {
  14796. var newDom = platformApi.createCanvas();
  14797. var width = painter.getWidth();
  14798. var height = painter.getHeight();
  14799. var newDomStyle = newDom.style;
  14800. if (newDomStyle) {
  14801. newDomStyle.position = 'absolute';
  14802. newDomStyle.left = '0';
  14803. newDomStyle.top = '0';
  14804. newDomStyle.width = width + 'px';
  14805. newDomStyle.height = height + 'px';
  14806. newDom.setAttribute('data-zr-dom-id', id);
  14807. }
  14808. newDom.width = width * dpr;
  14809. newDom.height = height * dpr;
  14810. return newDom;
  14811. }
  14812. var Layer = (function (_super) {
  14813. __extends(Layer, _super);
  14814. function Layer(id, painter, dpr) {
  14815. var _this = _super.call(this) || this;
  14816. _this.motionBlur = false;
  14817. _this.lastFrameAlpha = 0.7;
  14818. _this.dpr = 1;
  14819. _this.virtual = false;
  14820. _this.config = {};
  14821. _this.incremental = false;
  14822. _this.zlevel = 0;
  14823. _this.maxRepaintRectCount = 5;
  14824. _this.__dirty = true;
  14825. _this.__firstTimePaint = true;
  14826. _this.__used = false;
  14827. _this.__drawIndex = 0;
  14828. _this.__startIndex = 0;
  14829. _this.__endIndex = 0;
  14830. _this.__prevStartIndex = null;
  14831. _this.__prevEndIndex = null;
  14832. var dom;
  14833. dpr = dpr || devicePixelRatio;
  14834. if (typeof id === 'string') {
  14835. dom = createDom(id, painter, dpr);
  14836. }
  14837. else if (isObject(id)) {
  14838. dom = id;
  14839. id = dom.id;
  14840. }
  14841. _this.id = id;
  14842. _this.dom = dom;
  14843. var domStyle = dom.style;
  14844. if (domStyle) {
  14845. disableUserSelect(dom);
  14846. dom.onselectstart = function () { return false; };
  14847. domStyle.padding = '0';
  14848. domStyle.margin = '0';
  14849. domStyle.borderWidth = '0';
  14850. }
  14851. _this.painter = painter;
  14852. _this.dpr = dpr;
  14853. return _this;
  14854. }
  14855. Layer.prototype.getElementCount = function () {
  14856. return this.__endIndex - this.__startIndex;
  14857. };
  14858. Layer.prototype.afterBrush = function () {
  14859. this.__prevStartIndex = this.__startIndex;
  14860. this.__prevEndIndex = this.__endIndex;
  14861. };
  14862. Layer.prototype.initContext = function () {
  14863. this.ctx = this.dom.getContext('2d');
  14864. this.ctx.dpr = this.dpr;
  14865. };
  14866. Layer.prototype.setUnpainted = function () {
  14867. this.__firstTimePaint = true;
  14868. };
  14869. Layer.prototype.createBackBuffer = function () {
  14870. var dpr = this.dpr;
  14871. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  14872. this.ctxBack = this.domBack.getContext('2d');
  14873. if (dpr !== 1) {
  14874. this.ctxBack.scale(dpr, dpr);
  14875. }
  14876. };
  14877. Layer.prototype.createRepaintRects = function (displayList, prevList, viewWidth, viewHeight) {
  14878. if (this.__firstTimePaint) {
  14879. this.__firstTimePaint = false;
  14880. return null;
  14881. }
  14882. var mergedRepaintRects = [];
  14883. var maxRepaintRectCount = this.maxRepaintRectCount;
  14884. var full = false;
  14885. var pendingRect = new BoundingRect(0, 0, 0, 0);
  14886. function addRectToMergePool(rect) {
  14887. if (!rect.isFinite() || rect.isZero()) {
  14888. return;
  14889. }
  14890. if (mergedRepaintRects.length === 0) {
  14891. var boundingRect = new BoundingRect(0, 0, 0, 0);
  14892. boundingRect.copy(rect);
  14893. mergedRepaintRects.push(boundingRect);
  14894. }
  14895. else {
  14896. var isMerged = false;
  14897. var minDeltaArea = Infinity;
  14898. var bestRectToMergeIdx = 0;
  14899. for (var i = 0; i < mergedRepaintRects.length; ++i) {
  14900. var mergedRect = mergedRepaintRects[i];
  14901. if (mergedRect.intersect(rect)) {
  14902. var pendingRect_1 = new BoundingRect(0, 0, 0, 0);
  14903. pendingRect_1.copy(mergedRect);
  14904. pendingRect_1.union(rect);
  14905. mergedRepaintRects[i] = pendingRect_1;
  14906. isMerged = true;
  14907. break;
  14908. }
  14909. else if (full) {
  14910. pendingRect.copy(rect);
  14911. pendingRect.union(mergedRect);
  14912. var aArea = rect.width * rect.height;
  14913. var bArea = mergedRect.width * mergedRect.height;
  14914. var pendingArea = pendingRect.width * pendingRect.height;
  14915. var deltaArea = pendingArea - aArea - bArea;
  14916. if (deltaArea < minDeltaArea) {
  14917. minDeltaArea = deltaArea;
  14918. bestRectToMergeIdx = i;
  14919. }
  14920. }
  14921. }
  14922. if (full) {
  14923. mergedRepaintRects[bestRectToMergeIdx].union(rect);
  14924. isMerged = true;
  14925. }
  14926. if (!isMerged) {
  14927. var boundingRect = new BoundingRect(0, 0, 0, 0);
  14928. boundingRect.copy(rect);
  14929. mergedRepaintRects.push(boundingRect);
  14930. }
  14931. if (!full) {
  14932. full = mergedRepaintRects.length >= maxRepaintRectCount;
  14933. }
  14934. }
  14935. }
  14936. for (var i = this.__startIndex; i < this.__endIndex; ++i) {
  14937. var el = displayList[i];
  14938. if (el) {
  14939. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  14940. var prevRect = el.__isRendered && ((el.__dirty & REDRAW_BIT) || !shouldPaint)
  14941. ? el.getPrevPaintRect()
  14942. : null;
  14943. if (prevRect) {
  14944. addRectToMergePool(prevRect);
  14945. }
  14946. var curRect = shouldPaint && ((el.__dirty & REDRAW_BIT) || !el.__isRendered)
  14947. ? el.getPaintRect()
  14948. : null;
  14949. if (curRect) {
  14950. addRectToMergePool(curRect);
  14951. }
  14952. }
  14953. }
  14954. for (var i = this.__prevStartIndex; i < this.__prevEndIndex; ++i) {
  14955. var el = prevList[i];
  14956. var shouldPaint = el && el.shouldBePainted(viewWidth, viewHeight, true, true);
  14957. if (el && (!shouldPaint || !el.__zr) && el.__isRendered) {
  14958. var prevRect = el.getPrevPaintRect();
  14959. if (prevRect) {
  14960. addRectToMergePool(prevRect);
  14961. }
  14962. }
  14963. }
  14964. var hasIntersections;
  14965. do {
  14966. hasIntersections = false;
  14967. for (var i = 0; i < mergedRepaintRects.length;) {
  14968. if (mergedRepaintRects[i].isZero()) {
  14969. mergedRepaintRects.splice(i, 1);
  14970. continue;
  14971. }
  14972. for (var j = i + 1; j < mergedRepaintRects.length;) {
  14973. if (mergedRepaintRects[i].intersect(mergedRepaintRects[j])) {
  14974. hasIntersections = true;
  14975. mergedRepaintRects[i].union(mergedRepaintRects[j]);
  14976. mergedRepaintRects.splice(j, 1);
  14977. }
  14978. else {
  14979. j++;
  14980. }
  14981. }
  14982. i++;
  14983. }
  14984. } while (hasIntersections);
  14985. this._paintRects = mergedRepaintRects;
  14986. return mergedRepaintRects;
  14987. };
  14988. Layer.prototype.debugGetPaintRects = function () {
  14989. return (this._paintRects || []).slice();
  14990. };
  14991. Layer.prototype.resize = function (width, height) {
  14992. var dpr = this.dpr;
  14993. var dom = this.dom;
  14994. var domStyle = dom.style;
  14995. var domBack = this.domBack;
  14996. if (domStyle) {
  14997. domStyle.width = width + 'px';
  14998. domStyle.height = height + 'px';
  14999. }
  15000. dom.width = width * dpr;
  15001. dom.height = height * dpr;
  15002. if (domBack) {
  15003. domBack.width = width * dpr;
  15004. domBack.height = height * dpr;
  15005. if (dpr !== 1) {
  15006. this.ctxBack.scale(dpr, dpr);
  15007. }
  15008. }
  15009. };
  15010. Layer.prototype.clear = function (clearAll, clearColor, repaintRects) {
  15011. var dom = this.dom;
  15012. var ctx = this.ctx;
  15013. var width = dom.width;
  15014. var height = dom.height;
  15015. clearColor = clearColor || this.clearColor;
  15016. var haveMotionBLur = this.motionBlur && !clearAll;
  15017. var lastFrameAlpha = this.lastFrameAlpha;
  15018. var dpr = this.dpr;
  15019. var self = this;
  15020. if (haveMotionBLur) {
  15021. if (!this.domBack) {
  15022. this.createBackBuffer();
  15023. }
  15024. this.ctxBack.globalCompositeOperation = 'copy';
  15025. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  15026. }
  15027. var domBack = this.domBack;
  15028. function doClear(x, y, width, height) {
  15029. ctx.clearRect(x, y, width, height);
  15030. if (clearColor && clearColor !== 'transparent') {
  15031. var clearColorGradientOrPattern = void 0;
  15032. if (isGradientObject(clearColor)) {
  15033. var shouldCache = clearColor.global || (clearColor.__width === width
  15034. && clearColor.__height === height);
  15035. clearColorGradientOrPattern = shouldCache
  15036. && clearColor.__canvasGradient
  15037. || getCanvasGradient(ctx, clearColor, {
  15038. x: 0,
  15039. y: 0,
  15040. width: width,
  15041. height: height
  15042. });
  15043. clearColor.__canvasGradient = clearColorGradientOrPattern;
  15044. clearColor.__width = width;
  15045. clearColor.__height = height;
  15046. }
  15047. else if (isImagePatternObject(clearColor)) {
  15048. clearColor.scaleX = clearColor.scaleX || dpr;
  15049. clearColor.scaleY = clearColor.scaleY || dpr;
  15050. clearColorGradientOrPattern = createCanvasPattern(ctx, clearColor, {
  15051. dirty: function () {
  15052. self.setUnpainted();
  15053. self.painter.refresh();
  15054. }
  15055. });
  15056. }
  15057. ctx.save();
  15058. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  15059. ctx.fillRect(x, y, width, height);
  15060. ctx.restore();
  15061. }
  15062. if (haveMotionBLur) {
  15063. ctx.save();
  15064. ctx.globalAlpha = lastFrameAlpha;
  15065. ctx.drawImage(domBack, x, y, width, height);
  15066. ctx.restore();
  15067. }
  15068. }
  15069. if (!repaintRects || haveMotionBLur) {
  15070. doClear(0, 0, width, height);
  15071. }
  15072. else if (repaintRects.length) {
  15073. each(repaintRects, function (rect) {
  15074. doClear(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  15075. });
  15076. }
  15077. };
  15078. return Layer;
  15079. }(Eventful));
  15080. var HOVER_LAYER_ZLEVEL = 1e5;
  15081. var CANVAS_ZLEVEL = 314159;
  15082. var EL_AFTER_INCREMENTAL_INC = 0.01;
  15083. var INCREMENTAL_INC = 0.001;
  15084. function isLayerValid(layer) {
  15085. if (!layer) {
  15086. return false;
  15087. }
  15088. if (layer.__builtin__) {
  15089. return true;
  15090. }
  15091. if (typeof (layer.resize) !== 'function'
  15092. || typeof (layer.refresh) !== 'function') {
  15093. return false;
  15094. }
  15095. return true;
  15096. }
  15097. function createRoot(width, height) {
  15098. var domRoot = document.createElement('div');
  15099. domRoot.style.cssText = [
  15100. 'position:relative',
  15101. 'width:' + width + 'px',
  15102. 'height:' + height + 'px',
  15103. 'padding:0',
  15104. 'margin:0',
  15105. 'border-width:0'
  15106. ].join(';') + ';';
  15107. return domRoot;
  15108. }
  15109. var CanvasPainter = (function () {
  15110. function CanvasPainter(root, storage, opts, id) {
  15111. this.type = 'canvas';
  15112. this._zlevelList = [];
  15113. this._prevDisplayList = [];
  15114. this._layers = {};
  15115. this._layerConfig = {};
  15116. this._needsManuallyCompositing = false;
  15117. this.type = 'canvas';
  15118. var singleCanvas = !root.nodeName
  15119. || root.nodeName.toUpperCase() === 'CANVAS';
  15120. this._opts = opts = extend({}, opts || {});
  15121. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  15122. this._singleCanvas = singleCanvas;
  15123. this.root = root;
  15124. var rootStyle = root.style;
  15125. if (rootStyle) {
  15126. disableUserSelect(root);
  15127. root.innerHTML = '';
  15128. }
  15129. this.storage = storage;
  15130. var zlevelList = this._zlevelList;
  15131. this._prevDisplayList = [];
  15132. var layers = this._layers;
  15133. if (!singleCanvas) {
  15134. this._width = getSize(root, 0, opts);
  15135. this._height = getSize(root, 1, opts);
  15136. var domRoot = this._domRoot = createRoot(this._width, this._height);
  15137. root.appendChild(domRoot);
  15138. }
  15139. else {
  15140. var rootCanvas = root;
  15141. var width = rootCanvas.width;
  15142. var height = rootCanvas.height;
  15143. if (opts.width != null) {
  15144. width = opts.width;
  15145. }
  15146. if (opts.height != null) {
  15147. height = opts.height;
  15148. }
  15149. this.dpr = opts.devicePixelRatio || 1;
  15150. rootCanvas.width = width * this.dpr;
  15151. rootCanvas.height = height * this.dpr;
  15152. this._width = width;
  15153. this._height = height;
  15154. var mainLayer = new Layer(rootCanvas, this, this.dpr);
  15155. mainLayer.__builtin__ = true;
  15156. mainLayer.initContext();
  15157. layers[CANVAS_ZLEVEL] = mainLayer;
  15158. mainLayer.zlevel = CANVAS_ZLEVEL;
  15159. zlevelList.push(CANVAS_ZLEVEL);
  15160. this._domRoot = root;
  15161. }
  15162. }
  15163. CanvasPainter.prototype.getType = function () {
  15164. return 'canvas';
  15165. };
  15166. CanvasPainter.prototype.isSingleCanvas = function () {
  15167. return this._singleCanvas;
  15168. };
  15169. CanvasPainter.prototype.getViewportRoot = function () {
  15170. return this._domRoot;
  15171. };
  15172. CanvasPainter.prototype.getViewportRootOffset = function () {
  15173. var viewportRoot = this.getViewportRoot();
  15174. if (viewportRoot) {
  15175. return {
  15176. offsetLeft: viewportRoot.offsetLeft || 0,
  15177. offsetTop: viewportRoot.offsetTop || 0
  15178. };
  15179. }
  15180. };
  15181. CanvasPainter.prototype.refresh = function (paintAll) {
  15182. var list = this.storage.getDisplayList(true);
  15183. var prevList = this._prevDisplayList;
  15184. var zlevelList = this._zlevelList;
  15185. this._redrawId = Math.random();
  15186. this._paintList(list, prevList, paintAll, this._redrawId);
  15187. for (var i = 0; i < zlevelList.length; i++) {
  15188. var z = zlevelList[i];
  15189. var layer = this._layers[z];
  15190. if (!layer.__builtin__ && layer.refresh) {
  15191. var clearColor = i === 0 ? this._backgroundColor : null;
  15192. layer.refresh(clearColor);
  15193. }
  15194. }
  15195. if (this._opts.useDirtyRect) {
  15196. this._prevDisplayList = list.slice();
  15197. }
  15198. return this;
  15199. };
  15200. CanvasPainter.prototype.refreshHover = function () {
  15201. this._paintHoverList(this.storage.getDisplayList(false));
  15202. };
  15203. CanvasPainter.prototype._paintHoverList = function (list) {
  15204. var len = list.length;
  15205. var hoverLayer = this._hoverlayer;
  15206. hoverLayer && hoverLayer.clear();
  15207. if (!len) {
  15208. return;
  15209. }
  15210. var scope = {
  15211. inHover: true,
  15212. viewWidth: this._width,
  15213. viewHeight: this._height
  15214. };
  15215. var ctx;
  15216. for (var i = 0; i < len; i++) {
  15217. var el = list[i];
  15218. if (el.__inHover) {
  15219. if (!hoverLayer) {
  15220. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  15221. }
  15222. if (!ctx) {
  15223. ctx = hoverLayer.ctx;
  15224. ctx.save();
  15225. }
  15226. brush(ctx, el, scope, i === len - 1);
  15227. }
  15228. }
  15229. if (ctx) {
  15230. ctx.restore();
  15231. }
  15232. };
  15233. CanvasPainter.prototype.getHoverLayer = function () {
  15234. return this.getLayer(HOVER_LAYER_ZLEVEL);
  15235. };
  15236. CanvasPainter.prototype.paintOne = function (ctx, el) {
  15237. brushSingle(ctx, el);
  15238. };
  15239. CanvasPainter.prototype._paintList = function (list, prevList, paintAll, redrawId) {
  15240. if (this._redrawId !== redrawId) {
  15241. return;
  15242. }
  15243. paintAll = paintAll || false;
  15244. this._updateLayerStatus(list);
  15245. var _a = this._doPaintList(list, prevList, paintAll), finished = _a.finished, needsRefreshHover = _a.needsRefreshHover;
  15246. if (this._needsManuallyCompositing) {
  15247. this._compositeManually();
  15248. }
  15249. if (needsRefreshHover) {
  15250. this._paintHoverList(list);
  15251. }
  15252. if (!finished) {
  15253. var self_1 = this;
  15254. requestAnimationFrame$1(function () {
  15255. self_1._paintList(list, prevList, paintAll, redrawId);
  15256. });
  15257. }
  15258. else {
  15259. this.eachLayer(function (layer) {
  15260. layer.afterBrush && layer.afterBrush();
  15261. });
  15262. }
  15263. };
  15264. CanvasPainter.prototype._compositeManually = function () {
  15265. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  15266. var width = this._domRoot.width;
  15267. var height = this._domRoot.height;
  15268. ctx.clearRect(0, 0, width, height);
  15269. this.eachBuiltinLayer(function (layer) {
  15270. if (layer.virtual) {
  15271. ctx.drawImage(layer.dom, 0, 0, width, height);
  15272. }
  15273. });
  15274. };
  15275. CanvasPainter.prototype._doPaintList = function (list, prevList, paintAll) {
  15276. var _this = this;
  15277. var layerList = [];
  15278. var useDirtyRect = this._opts.useDirtyRect;
  15279. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  15280. var zlevel = this._zlevelList[zi];
  15281. var layer = this._layers[zlevel];
  15282. if (layer.__builtin__
  15283. && layer !== this._hoverlayer
  15284. && (layer.__dirty || paintAll)) {
  15285. layerList.push(layer);
  15286. }
  15287. }
  15288. var finished = true;
  15289. var needsRefreshHover = false;
  15290. var _loop_1 = function (k) {
  15291. var layer = layerList[k];
  15292. var ctx = layer.ctx;
  15293. var repaintRects = useDirtyRect
  15294. && layer.createRepaintRects(list, prevList, this_1._width, this_1._height);
  15295. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  15296. var useTimer = !paintAll && layer.incremental && Date.now;
  15297. var startTime = useTimer && Date.now();
  15298. var clearColor = layer.zlevel === this_1._zlevelList[0]
  15299. ? this_1._backgroundColor : null;
  15300. if (layer.__startIndex === layer.__endIndex) {
  15301. layer.clear(false, clearColor, repaintRects);
  15302. }
  15303. else if (start === layer.__startIndex) {
  15304. var firstEl = list[start];
  15305. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  15306. layer.clear(false, clearColor, repaintRects);
  15307. }
  15308. }
  15309. if (start === -1) {
  15310. console.error('For some unknown reason. drawIndex is -1');
  15311. start = layer.__startIndex;
  15312. }
  15313. var i;
  15314. var repaint = function (repaintRect) {
  15315. var scope = {
  15316. inHover: false,
  15317. allClipped: false,
  15318. prevEl: null,
  15319. viewWidth: _this._width,
  15320. viewHeight: _this._height
  15321. };
  15322. for (i = start; i < layer.__endIndex; i++) {
  15323. var el = list[i];
  15324. if (el.__inHover) {
  15325. needsRefreshHover = true;
  15326. }
  15327. _this._doPaintEl(el, layer, useDirtyRect, repaintRect, scope, i === layer.__endIndex - 1);
  15328. if (useTimer) {
  15329. var dTime = Date.now() - startTime;
  15330. if (dTime > 15) {
  15331. break;
  15332. }
  15333. }
  15334. }
  15335. if (scope.prevElClipPaths) {
  15336. ctx.restore();
  15337. }
  15338. };
  15339. if (repaintRects) {
  15340. if (repaintRects.length === 0) {
  15341. i = layer.__endIndex;
  15342. }
  15343. else {
  15344. var dpr = this_1.dpr;
  15345. for (var r = 0; r < repaintRects.length; ++r) {
  15346. var rect = repaintRects[r];
  15347. ctx.save();
  15348. ctx.beginPath();
  15349. ctx.rect(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  15350. ctx.clip();
  15351. repaint(rect);
  15352. ctx.restore();
  15353. }
  15354. }
  15355. }
  15356. else {
  15357. ctx.save();
  15358. repaint();
  15359. ctx.restore();
  15360. }
  15361. layer.__drawIndex = i;
  15362. if (layer.__drawIndex < layer.__endIndex) {
  15363. finished = false;
  15364. }
  15365. };
  15366. var this_1 = this;
  15367. for (var k = 0; k < layerList.length; k++) {
  15368. _loop_1(k);
  15369. }
  15370. if (env.wxa) {
  15371. each(this._layers, function (layer) {
  15372. if (layer && layer.ctx && layer.ctx.draw) {
  15373. layer.ctx.draw();
  15374. }
  15375. });
  15376. }
  15377. return {
  15378. finished: finished,
  15379. needsRefreshHover: needsRefreshHover
  15380. };
  15381. };
  15382. CanvasPainter.prototype._doPaintEl = function (el, currentLayer, useDirtyRect, repaintRect, scope, isLast) {
  15383. var ctx = currentLayer.ctx;
  15384. if (useDirtyRect) {
  15385. var paintRect = el.getPaintRect();
  15386. if (!repaintRect || paintRect && paintRect.intersect(repaintRect)) {
  15387. brush(ctx, el, scope, isLast);
  15388. el.setPrevPaintRect(paintRect);
  15389. }
  15390. }
  15391. else {
  15392. brush(ctx, el, scope, isLast);
  15393. }
  15394. };
  15395. CanvasPainter.prototype.getLayer = function (zlevel, virtual) {
  15396. if (this._singleCanvas && !this._needsManuallyCompositing) {
  15397. zlevel = CANVAS_ZLEVEL;
  15398. }
  15399. var layer = this._layers[zlevel];
  15400. if (!layer) {
  15401. layer = new Layer('zr_' + zlevel, this, this.dpr);
  15402. layer.zlevel = zlevel;
  15403. layer.__builtin__ = true;
  15404. if (this._layerConfig[zlevel]) {
  15405. merge(layer, this._layerConfig[zlevel], true);
  15406. }
  15407. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  15408. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  15409. }
  15410. if (virtual) {
  15411. layer.virtual = virtual;
  15412. }
  15413. this.insertLayer(zlevel, layer);
  15414. layer.initContext();
  15415. }
  15416. return layer;
  15417. };
  15418. CanvasPainter.prototype.insertLayer = function (zlevel, layer) {
  15419. var layersMap = this._layers;
  15420. var zlevelList = this._zlevelList;
  15421. var len = zlevelList.length;
  15422. var domRoot = this._domRoot;
  15423. var prevLayer = null;
  15424. var i = -1;
  15425. if (layersMap[zlevel]) {
  15426. {
  15427. logError('ZLevel ' + zlevel + ' has been used already');
  15428. }
  15429. return;
  15430. }
  15431. if (!isLayerValid(layer)) {
  15432. {
  15433. logError('Layer of zlevel ' + zlevel + ' is not valid');
  15434. }
  15435. return;
  15436. }
  15437. if (len > 0 && zlevel > zlevelList[0]) {
  15438. for (i = 0; i < len - 1; i++) {
  15439. if (zlevelList[i] < zlevel
  15440. && zlevelList[i + 1] > zlevel) {
  15441. break;
  15442. }
  15443. }
  15444. prevLayer = layersMap[zlevelList[i]];
  15445. }
  15446. zlevelList.splice(i + 1, 0, zlevel);
  15447. layersMap[zlevel] = layer;
  15448. if (!layer.virtual) {
  15449. if (prevLayer) {
  15450. var prevDom = prevLayer.dom;
  15451. if (prevDom.nextSibling) {
  15452. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  15453. }
  15454. else {
  15455. domRoot.appendChild(layer.dom);
  15456. }
  15457. }
  15458. else {
  15459. if (domRoot.firstChild) {
  15460. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  15461. }
  15462. else {
  15463. domRoot.appendChild(layer.dom);
  15464. }
  15465. }
  15466. }
  15467. layer.painter || (layer.painter = this);
  15468. };
  15469. CanvasPainter.prototype.eachLayer = function (cb, context) {
  15470. var zlevelList = this._zlevelList;
  15471. for (var i = 0; i < zlevelList.length; i++) {
  15472. var z = zlevelList[i];
  15473. cb.call(context, this._layers[z], z);
  15474. }
  15475. };
  15476. CanvasPainter.prototype.eachBuiltinLayer = function (cb, context) {
  15477. var zlevelList = this._zlevelList;
  15478. for (var i = 0; i < zlevelList.length; i++) {
  15479. var z = zlevelList[i];
  15480. var layer = this._layers[z];
  15481. if (layer.__builtin__) {
  15482. cb.call(context, layer, z);
  15483. }
  15484. }
  15485. };
  15486. CanvasPainter.prototype.eachOtherLayer = function (cb, context) {
  15487. var zlevelList = this._zlevelList;
  15488. for (var i = 0; i < zlevelList.length; i++) {
  15489. var z = zlevelList[i];
  15490. var layer = this._layers[z];
  15491. if (!layer.__builtin__) {
  15492. cb.call(context, layer, z);
  15493. }
  15494. }
  15495. };
  15496. CanvasPainter.prototype.getLayers = function () {
  15497. return this._layers;
  15498. };
  15499. CanvasPainter.prototype._updateLayerStatus = function (list) {
  15500. this.eachBuiltinLayer(function (layer, z) {
  15501. layer.__dirty = layer.__used = false;
  15502. });
  15503. function updatePrevLayer(idx) {
  15504. if (prevLayer) {
  15505. if (prevLayer.__endIndex !== idx) {
  15506. prevLayer.__dirty = true;
  15507. }
  15508. prevLayer.__endIndex = idx;
  15509. }
  15510. }
  15511. if (this._singleCanvas) {
  15512. for (var i_1 = 1; i_1 < list.length; i_1++) {
  15513. var el = list[i_1];
  15514. if (el.zlevel !== list[i_1 - 1].zlevel || el.incremental) {
  15515. this._needsManuallyCompositing = true;
  15516. break;
  15517. }
  15518. }
  15519. }
  15520. var prevLayer = null;
  15521. var incrementalLayerCount = 0;
  15522. var prevZlevel;
  15523. var i;
  15524. for (i = 0; i < list.length; i++) {
  15525. var el = list[i];
  15526. var zlevel = el.zlevel;
  15527. var layer = void 0;
  15528. if (prevZlevel !== zlevel) {
  15529. prevZlevel = zlevel;
  15530. incrementalLayerCount = 0;
  15531. }
  15532. if (el.incremental) {
  15533. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  15534. layer.incremental = true;
  15535. incrementalLayerCount = 1;
  15536. }
  15537. else {
  15538. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  15539. }
  15540. if (!layer.__builtin__) {
  15541. logError('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  15542. }
  15543. if (layer !== prevLayer) {
  15544. layer.__used = true;
  15545. if (layer.__startIndex !== i) {
  15546. layer.__dirty = true;
  15547. }
  15548. layer.__startIndex = i;
  15549. if (!layer.incremental) {
  15550. layer.__drawIndex = i;
  15551. }
  15552. else {
  15553. layer.__drawIndex = -1;
  15554. }
  15555. updatePrevLayer(i);
  15556. prevLayer = layer;
  15557. }
  15558. if ((el.__dirty & REDRAW_BIT) && !el.__inHover) {
  15559. layer.__dirty = true;
  15560. if (layer.incremental && layer.__drawIndex < 0) {
  15561. layer.__drawIndex = i;
  15562. }
  15563. }
  15564. }
  15565. updatePrevLayer(i);
  15566. this.eachBuiltinLayer(function (layer, z) {
  15567. if (!layer.__used && layer.getElementCount() > 0) {
  15568. layer.__dirty = true;
  15569. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  15570. }
  15571. if (layer.__dirty && layer.__drawIndex < 0) {
  15572. layer.__drawIndex = layer.__startIndex;
  15573. }
  15574. });
  15575. };
  15576. CanvasPainter.prototype.clear = function () {
  15577. this.eachBuiltinLayer(this._clearLayer);
  15578. return this;
  15579. };
  15580. CanvasPainter.prototype._clearLayer = function (layer) {
  15581. layer.clear();
  15582. };
  15583. CanvasPainter.prototype.setBackgroundColor = function (backgroundColor) {
  15584. this._backgroundColor = backgroundColor;
  15585. each(this._layers, function (layer) {
  15586. layer.setUnpainted();
  15587. });
  15588. };
  15589. CanvasPainter.prototype.configLayer = function (zlevel, config) {
  15590. if (config) {
  15591. var layerConfig = this._layerConfig;
  15592. if (!layerConfig[zlevel]) {
  15593. layerConfig[zlevel] = config;
  15594. }
  15595. else {
  15596. merge(layerConfig[zlevel], config, true);
  15597. }
  15598. for (var i = 0; i < this._zlevelList.length; i++) {
  15599. var _zlevel = this._zlevelList[i];
  15600. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  15601. var layer = this._layers[_zlevel];
  15602. merge(layer, layerConfig[zlevel], true);
  15603. }
  15604. }
  15605. }
  15606. };
  15607. CanvasPainter.prototype.delLayer = function (zlevel) {
  15608. var layers = this._layers;
  15609. var zlevelList = this._zlevelList;
  15610. var layer = layers[zlevel];
  15611. if (!layer) {
  15612. return;
  15613. }
  15614. layer.dom.parentNode.removeChild(layer.dom);
  15615. delete layers[zlevel];
  15616. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  15617. };
  15618. CanvasPainter.prototype.resize = function (width, height) {
  15619. if (!this._domRoot.style) {
  15620. if (width == null || height == null) {
  15621. return;
  15622. }
  15623. this._width = width;
  15624. this._height = height;
  15625. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  15626. }
  15627. else {
  15628. var domRoot = this._domRoot;
  15629. domRoot.style.display = 'none';
  15630. var opts = this._opts;
  15631. var root = this.root;
  15632. width != null && (opts.width = width);
  15633. height != null && (opts.height = height);
  15634. width = getSize(root, 0, opts);
  15635. height = getSize(root, 1, opts);
  15636. domRoot.style.display = '';
  15637. if (this._width !== width || height !== this._height) {
  15638. domRoot.style.width = width + 'px';
  15639. domRoot.style.height = height + 'px';
  15640. for (var id in this._layers) {
  15641. if (this._layers.hasOwnProperty(id)) {
  15642. this._layers[id].resize(width, height);
  15643. }
  15644. }
  15645. this.refresh(true);
  15646. }
  15647. this._width = width;
  15648. this._height = height;
  15649. }
  15650. return this;
  15651. };
  15652. CanvasPainter.prototype.clearLayer = function (zlevel) {
  15653. var layer = this._layers[zlevel];
  15654. if (layer) {
  15655. layer.clear();
  15656. }
  15657. };
  15658. CanvasPainter.prototype.dispose = function () {
  15659. this.root.innerHTML = '';
  15660. this.root =
  15661. this.storage =
  15662. this._domRoot =
  15663. this._layers = null;
  15664. };
  15665. CanvasPainter.prototype.getRenderedCanvas = function (opts) {
  15666. opts = opts || {};
  15667. if (this._singleCanvas && !this._compositeManually) {
  15668. return this._layers[CANVAS_ZLEVEL].dom;
  15669. }
  15670. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  15671. imageLayer.initContext();
  15672. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  15673. var ctx = imageLayer.ctx;
  15674. if (opts.pixelRatio <= this.dpr) {
  15675. this.refresh();
  15676. var width_1 = imageLayer.dom.width;
  15677. var height_1 = imageLayer.dom.height;
  15678. this.eachLayer(function (layer) {
  15679. if (layer.__builtin__) {
  15680. ctx.drawImage(layer.dom, 0, 0, width_1, height_1);
  15681. }
  15682. else if (layer.renderToCanvas) {
  15683. ctx.save();
  15684. layer.renderToCanvas(ctx);
  15685. ctx.restore();
  15686. }
  15687. });
  15688. }
  15689. else {
  15690. var scope = {
  15691. inHover: false,
  15692. viewWidth: this._width,
  15693. viewHeight: this._height
  15694. };
  15695. var displayList = this.storage.getDisplayList(true);
  15696. for (var i = 0, len = displayList.length; i < len; i++) {
  15697. var el = displayList[i];
  15698. brush(ctx, el, scope, i === len - 1);
  15699. }
  15700. }
  15701. return imageLayer.dom;
  15702. };
  15703. CanvasPainter.prototype.getWidth = function () {
  15704. return this._width;
  15705. };
  15706. CanvasPainter.prototype.getHeight = function () {
  15707. return this._height;
  15708. };
  15709. return CanvasPainter;
  15710. }());
  15711. var mathSin$4 = Math.sin;
  15712. var mathCos$4 = Math.cos;
  15713. var PI$5 = Math.PI;
  15714. var PI2$6 = Math.PI * 2;
  15715. var degree = 180 / PI$5;
  15716. var SVGPathRebuilder = (function () {
  15717. function SVGPathRebuilder() {
  15718. }
  15719. SVGPathRebuilder.prototype.reset = function (precision) {
  15720. this._start = true;
  15721. this._d = [];
  15722. this._str = '';
  15723. this._p = Math.pow(10, precision || 4);
  15724. };
  15725. SVGPathRebuilder.prototype.moveTo = function (x, y) {
  15726. this._add('M', x, y);
  15727. };
  15728. SVGPathRebuilder.prototype.lineTo = function (x, y) {
  15729. this._add('L', x, y);
  15730. };
  15731. SVGPathRebuilder.prototype.bezierCurveTo = function (x, y, x2, y2, x3, y3) {
  15732. this._add('C', x, y, x2, y2, x3, y3);
  15733. };
  15734. SVGPathRebuilder.prototype.quadraticCurveTo = function (x, y, x2, y2) {
  15735. this._add('Q', x, y, x2, y2);
  15736. };
  15737. SVGPathRebuilder.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  15738. this.ellipse(cx, cy, r, r, 0, startAngle, endAngle, anticlockwise);
  15739. };
  15740. SVGPathRebuilder.prototype.ellipse = function (cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise) {
  15741. var dTheta = endAngle - startAngle;
  15742. var clockwise = !anticlockwise;
  15743. var dThetaPositive = Math.abs(dTheta);
  15744. var isCircle = isAroundZero$1(dThetaPositive - PI2$6)
  15745. || (clockwise ? dTheta >= PI2$6 : -dTheta >= PI2$6);
  15746. var unifiedTheta = dTheta > 0 ? dTheta % PI2$6 : (dTheta % PI2$6 + PI2$6);
  15747. var large = false;
  15748. if (isCircle) {
  15749. large = true;
  15750. }
  15751. else if (isAroundZero$1(dThetaPositive)) {
  15752. large = false;
  15753. }
  15754. else {
  15755. large = (unifiedTheta >= PI$5) === !!clockwise;
  15756. }
  15757. var x0 = cx + rx * mathCos$4(startAngle);
  15758. var y0 = cy + ry * mathSin$4(startAngle);
  15759. if (this._start) {
  15760. this._add('M', x0, y0);
  15761. }
  15762. var xRot = Math.round(psi * degree);
  15763. if (isCircle) {
  15764. var p = 1 / this._p;
  15765. var dTheta_1 = (clockwise ? 1 : -1) * (PI2$6 - p);
  15766. this._add('A', rx, ry, xRot, 1, +clockwise, cx + rx * mathCos$4(startAngle + dTheta_1), cy + ry * mathSin$4(startAngle + dTheta_1));
  15767. if (p > 1e-2) {
  15768. this._add('A', rx, ry, xRot, 0, +clockwise, x0, y0);
  15769. }
  15770. }
  15771. else {
  15772. var x = cx + rx * mathCos$4(endAngle);
  15773. var y = cy + ry * mathSin$4(endAngle);
  15774. this._add('A', rx, ry, xRot, +large, +clockwise, x, y);
  15775. }
  15776. };
  15777. SVGPathRebuilder.prototype.rect = function (x, y, w, h) {
  15778. this._add('M', x, y);
  15779. this._add('l', w, 0);
  15780. this._add('l', 0, h);
  15781. this._add('l', -w, 0);
  15782. this._add('Z');
  15783. };
  15784. SVGPathRebuilder.prototype.closePath = function () {
  15785. if (this._d.length > 0) {
  15786. this._add('Z');
  15787. }
  15788. };
  15789. SVGPathRebuilder.prototype._add = function (cmd, a, b, c, d, e, f, g, h) {
  15790. var vals = [];
  15791. var p = this._p;
  15792. for (var i = 1; i < arguments.length; i++) {
  15793. var val = arguments[i];
  15794. if (isNaN(val)) {
  15795. this._invalid = true;
  15796. return;
  15797. }
  15798. vals.push(Math.round(val * p) / p);
  15799. }
  15800. this._d.push(cmd + vals.join(' '));
  15801. this._start = cmd === 'Z';
  15802. };
  15803. SVGPathRebuilder.prototype.generateStr = function () {
  15804. this._str = this._invalid ? '' : this._d.join('');
  15805. this._d = [];
  15806. };
  15807. SVGPathRebuilder.prototype.getStr = function () {
  15808. return this._str;
  15809. };
  15810. return SVGPathRebuilder;
  15811. }());
  15812. var NONE = 'none';
  15813. var mathRound$1 = Math.round;
  15814. function pathHasFill(style) {
  15815. var fill = style.fill;
  15816. return fill != null && fill !== NONE;
  15817. }
  15818. function pathHasStroke(style) {
  15819. var stroke = style.stroke;
  15820. return stroke != null && stroke !== NONE;
  15821. }
  15822. var strokeProps = ['lineCap', 'miterLimit', 'lineJoin'];
  15823. var svgStrokeProps = map(strokeProps, function (prop) { return "stroke-" + prop.toLowerCase(); });
  15824. function mapStyleToAttrs(updateAttr, style, el, forceUpdate) {
  15825. var opacity = style.opacity == null ? 1 : style.opacity;
  15826. if (el instanceof ZRImage) {
  15827. updateAttr('opacity', opacity);
  15828. return;
  15829. }
  15830. if (pathHasFill(style)) {
  15831. var fill = normalizeColor(style.fill);
  15832. updateAttr('fill', fill.color);
  15833. var fillOpacity = style.fillOpacity != null
  15834. ? style.fillOpacity * fill.opacity * opacity
  15835. : fill.opacity * opacity;
  15836. if (forceUpdate || fillOpacity < 1) {
  15837. updateAttr('fill-opacity', fillOpacity);
  15838. }
  15839. }
  15840. else {
  15841. updateAttr('fill', NONE);
  15842. }
  15843. if (pathHasStroke(style)) {
  15844. var stroke = normalizeColor(style.stroke);
  15845. updateAttr('stroke', stroke.color);
  15846. var strokeScale = style.strokeNoScale
  15847. ? el.getLineScale()
  15848. : 1;
  15849. var strokeWidth = (strokeScale ? (style.lineWidth || 0) / strokeScale : 0);
  15850. var strokeOpacity = style.strokeOpacity != null
  15851. ? style.strokeOpacity * stroke.opacity * opacity
  15852. : stroke.opacity * opacity;
  15853. var strokeFirst = style.strokeFirst;
  15854. if (forceUpdate || strokeWidth !== 1) {
  15855. updateAttr('stroke-width', strokeWidth);
  15856. }
  15857. if (forceUpdate || strokeFirst) {
  15858. updateAttr('paint-order', strokeFirst ? 'stroke' : 'fill');
  15859. }
  15860. if (forceUpdate || strokeOpacity < 1) {
  15861. updateAttr('stroke-opacity', strokeOpacity);
  15862. }
  15863. if (style.lineDash) {
  15864. var _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  15865. if (lineDash) {
  15866. lineDashOffset = mathRound$1(lineDashOffset || 0);
  15867. updateAttr('stroke-dasharray', lineDash.join(','));
  15868. if (lineDashOffset || forceUpdate) {
  15869. updateAttr('stroke-dashoffset', lineDashOffset);
  15870. }
  15871. }
  15872. }
  15873. else if (forceUpdate) {
  15874. updateAttr('stroke-dasharray', NONE);
  15875. }
  15876. for (var i = 0; i < strokeProps.length; i++) {
  15877. var propName = strokeProps[i];
  15878. if (forceUpdate || style[propName] !== DEFAULT_PATH_STYLE[propName]) {
  15879. var val = style[propName] || DEFAULT_PATH_STYLE[propName];
  15880. val && updateAttr(svgStrokeProps[i], val);
  15881. }
  15882. }
  15883. }
  15884. else if (forceUpdate) {
  15885. updateAttr('stroke', NONE);
  15886. }
  15887. }
  15888. var SVGNS = 'http://www.w3.org/2000/svg';
  15889. var XLINKNS = 'http://www.w3.org/1999/xlink';
  15890. var XMLNS = 'http://www.w3.org/2000/xmlns/';
  15891. var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
  15892. var META_DATA_PREFIX = 'ecmeta_';
  15893. function createElement(name) {
  15894. return document.createElementNS(SVGNS, name);
  15895. }
  15896. function createVNode(tag, key, attrs, children, text) {
  15897. return {
  15898. tag: tag,
  15899. attrs: attrs || {},
  15900. children: children,
  15901. text: text,
  15902. key: key
  15903. };
  15904. }
  15905. function createElementOpen(name, attrs) {
  15906. var attrsStr = [];
  15907. if (attrs) {
  15908. for (var key in attrs) {
  15909. var val = attrs[key];
  15910. var part = key;
  15911. if (val === false) {
  15912. continue;
  15913. }
  15914. else if (val !== true && val != null) {
  15915. part += "=\"" + val + "\"";
  15916. }
  15917. attrsStr.push(part);
  15918. }
  15919. }
  15920. return "<" + name + " " + attrsStr.join(' ') + ">";
  15921. }
  15922. function createElementClose(name) {
  15923. return "</" + name + ">";
  15924. }
  15925. function vNodeToString(el, opts) {
  15926. opts = opts || {};
  15927. var S = opts.newline ? '\n' : '';
  15928. function convertElToString(el) {
  15929. var children = el.children, tag = el.tag, attrs = el.attrs, text = el.text;
  15930. return createElementOpen(tag, attrs)
  15931. + (tag !== 'style' ? encodeHTML(text) : text || '')
  15932. + (children ? "" + S + map(children, function (child) { return convertElToString(child); }).join(S) + S : '')
  15933. + createElementClose(tag);
  15934. }
  15935. return convertElToString(el);
  15936. }
  15937. function getCssString(selectorNodes, animationNodes, opts) {
  15938. opts = opts || {};
  15939. var S = opts.newline ? '\n' : '';
  15940. var bracketBegin = " {" + S;
  15941. var bracketEnd = S + "}";
  15942. var selectors = map(keys(selectorNodes), function (className) {
  15943. return className + bracketBegin + map(keys(selectorNodes[className]), function (attrName) {
  15944. return attrName + ":" + selectorNodes[className][attrName] + ";";
  15945. }).join(S) + bracketEnd;
  15946. }).join(S);
  15947. var animations = map(keys(animationNodes), function (animationName) {
  15948. return "@keyframes " + animationName + bracketBegin + map(keys(animationNodes[animationName]), function (percent) {
  15949. return percent + bracketBegin + map(keys(animationNodes[animationName][percent]), function (attrName) {
  15950. var val = animationNodes[animationName][percent][attrName];
  15951. if (attrName === 'd') {
  15952. val = "path(\"" + val + "\")";
  15953. }
  15954. return attrName + ":" + val + ";";
  15955. }).join(S) + bracketEnd;
  15956. }).join(S) + bracketEnd;
  15957. }).join(S);
  15958. if (!selectors && !animations) {
  15959. return '';
  15960. }
  15961. return ['<![CDATA[', selectors, animations, ']]>'].join(S);
  15962. }
  15963. function createBrushScope(zrId) {
  15964. return {
  15965. zrId: zrId,
  15966. shadowCache: {},
  15967. patternCache: {},
  15968. gradientCache: {},
  15969. clipPathCache: {},
  15970. defs: {},
  15971. cssNodes: {},
  15972. cssAnims: {},
  15973. cssStyleCache: {},
  15974. cssAnimIdx: 0,
  15975. shadowIdx: 0,
  15976. gradientIdx: 0,
  15977. patternIdx: 0,
  15978. clipPathIdx: 0
  15979. };
  15980. }
  15981. function createSVGVNode(width, height, children, useViewBox) {
  15982. return createVNode('svg', 'root', {
  15983. 'width': width,
  15984. 'height': height,
  15985. 'xmlns': SVGNS,
  15986. 'xmlns:xlink': XLINKNS,
  15987. 'version': '1.1',
  15988. 'baseProfile': 'full',
  15989. 'viewBox': useViewBox ? "0 0 " + width + " " + height : false
  15990. }, children);
  15991. }
  15992. var cssClassIdx = 0;
  15993. function getClassId() {
  15994. return cssClassIdx++;
  15995. }
  15996. var EASING_MAP = {
  15997. cubicIn: '0.32,0,0.67,0',
  15998. cubicOut: '0.33,1,0.68,1',
  15999. cubicInOut: '0.65,0,0.35,1',
  16000. quadraticIn: '0.11,0,0.5,0',
  16001. quadraticOut: '0.5,1,0.89,1',
  16002. quadraticInOut: '0.45,0,0.55,1',
  16003. quarticIn: '0.5,0,0.75,0',
  16004. quarticOut: '0.25,1,0.5,1',
  16005. quarticInOut: '0.76,0,0.24,1',
  16006. quinticIn: '0.64,0,0.78,0',
  16007. quinticOut: '0.22,1,0.36,1',
  16008. quinticInOut: '0.83,0,0.17,1',
  16009. sinusoidalIn: '0.12,0,0.39,0',
  16010. sinusoidalOut: '0.61,1,0.88,1',
  16011. sinusoidalInOut: '0.37,0,0.63,1',
  16012. exponentialIn: '0.7,0,0.84,0',
  16013. exponentialOut: '0.16,1,0.3,1',
  16014. exponentialInOut: '0.87,0,0.13,1',
  16015. circularIn: '0.55,0,1,0.45',
  16016. circularOut: '0,0.55,0.45,1',
  16017. circularInOut: '0.85,0,0.15,1'
  16018. };
  16019. var transformOriginKey = 'transform-origin';
  16020. function buildPathString(el, kfShape, path) {
  16021. var shape = extend({}, el.shape);
  16022. extend(shape, kfShape);
  16023. el.buildPath(path, shape);
  16024. var svgPathBuilder = new SVGPathRebuilder();
  16025. svgPathBuilder.reset(getPathPrecision(el));
  16026. path.rebuildPath(svgPathBuilder, 1);
  16027. svgPathBuilder.generateStr();
  16028. return svgPathBuilder.getStr();
  16029. }
  16030. function setTransformOrigin(target, transform) {
  16031. var originX = transform.originX, originY = transform.originY;
  16032. if (originX || originY) {
  16033. target[transformOriginKey] = originX + "px " + originY + "px";
  16034. }
  16035. }
  16036. var ANIMATE_STYLE_MAP = {
  16037. fill: 'fill',
  16038. opacity: 'opacity',
  16039. lineWidth: 'stroke-width',
  16040. lineDashOffset: 'stroke-dashoffset'
  16041. };
  16042. function addAnimation(cssAnim, scope) {
  16043. var animationName = scope.zrId + '-ani-' + scope.cssAnimIdx++;
  16044. scope.cssAnims[animationName] = cssAnim;
  16045. return animationName;
  16046. }
  16047. function createCompoundPathCSSAnimation(el, attrs, scope) {
  16048. var paths = el.shape.paths;
  16049. var composedAnim = {};
  16050. var cssAnimationCfg;
  16051. var cssAnimationName;
  16052. each(paths, function (path) {
  16053. var subScope = createBrushScope(scope.zrId);
  16054. subScope.animation = true;
  16055. createCSSAnimation(path, {}, subScope, true);
  16056. var cssAnims = subScope.cssAnims;
  16057. var cssNodes = subScope.cssNodes;
  16058. var animNames = keys(cssAnims);
  16059. var len = animNames.length;
  16060. if (!len) {
  16061. return;
  16062. }
  16063. cssAnimationName = animNames[len - 1];
  16064. var lastAnim = cssAnims[cssAnimationName];
  16065. for (var percent in lastAnim) {
  16066. var kf = lastAnim[percent];
  16067. composedAnim[percent] = composedAnim[percent] || { d: '' };
  16068. composedAnim[percent].d += kf.d || '';
  16069. }
  16070. for (var className in cssNodes) {
  16071. var val = cssNodes[className].animation;
  16072. if (val.indexOf(cssAnimationName) >= 0) {
  16073. cssAnimationCfg = val;
  16074. }
  16075. }
  16076. });
  16077. if (!cssAnimationCfg) {
  16078. return;
  16079. }
  16080. attrs.d = false;
  16081. var animationName = addAnimation(composedAnim, scope);
  16082. return cssAnimationCfg.replace(cssAnimationName, animationName);
  16083. }
  16084. function getEasingFunc(easing) {
  16085. return isString(easing)
  16086. ? EASING_MAP[easing]
  16087. ? "cubic-bezier(" + EASING_MAP[easing] + ")"
  16088. : createCubicEasingFunc(easing) ? easing : ''
  16089. : '';
  16090. }
  16091. function createCSSAnimation(el, attrs, scope, onlyShape) {
  16092. var animators = el.animators;
  16093. var len = animators.length;
  16094. var cssAnimations = [];
  16095. if (el instanceof CompoundPath) {
  16096. var animationCfg = createCompoundPathCSSAnimation(el, attrs, scope);
  16097. if (animationCfg) {
  16098. cssAnimations.push(animationCfg);
  16099. }
  16100. else if (!len) {
  16101. return;
  16102. }
  16103. }
  16104. else if (!len) {
  16105. return;
  16106. }
  16107. var groupAnimators = {};
  16108. for (var i = 0; i < len; i++) {
  16109. var animator = animators[i];
  16110. var cfgArr = [animator.getMaxTime() / 1000 + 's'];
  16111. var easing = getEasingFunc(animator.getClip().easing);
  16112. var delay = animator.getDelay();
  16113. if (easing) {
  16114. cfgArr.push(easing);
  16115. }
  16116. else {
  16117. cfgArr.push('linear');
  16118. }
  16119. if (delay) {
  16120. cfgArr.push(delay / 1000 + 's');
  16121. }
  16122. if (animator.getLoop()) {
  16123. cfgArr.push('infinite');
  16124. }
  16125. var cfg = cfgArr.join(' ');
  16126. groupAnimators[cfg] = groupAnimators[cfg] || [cfg, []];
  16127. groupAnimators[cfg][1].push(animator);
  16128. }
  16129. function createSingleCSSAnimation(groupAnimator) {
  16130. var animators = groupAnimator[1];
  16131. var len = animators.length;
  16132. var transformKfs = {};
  16133. var shapeKfs = {};
  16134. var finalKfs = {};
  16135. var animationTimingFunctionAttrName = 'animation-timing-function';
  16136. function saveAnimatorTrackToCssKfs(animator, cssKfs, toCssAttrName) {
  16137. var tracks = animator.getTracks();
  16138. var maxTime = animator.getMaxTime();
  16139. for (var k = 0; k < tracks.length; k++) {
  16140. var track = tracks[k];
  16141. if (track.needsAnimate()) {
  16142. var kfs = track.keyframes;
  16143. var attrName = track.propName;
  16144. toCssAttrName && (attrName = toCssAttrName(attrName));
  16145. if (attrName) {
  16146. for (var i = 0; i < kfs.length; i++) {
  16147. var kf = kfs[i];
  16148. var percent = Math.round(kf.time / maxTime * 100) + '%';
  16149. var kfEasing = getEasingFunc(kf.easing);
  16150. var rawValue = kf.rawValue;
  16151. if (isString(rawValue) || isNumber(rawValue)) {
  16152. cssKfs[percent] = cssKfs[percent] || {};
  16153. cssKfs[percent][attrName] = kf.rawValue;
  16154. if (kfEasing) {
  16155. cssKfs[percent][animationTimingFunctionAttrName] = kfEasing;
  16156. }
  16157. }
  16158. }
  16159. }
  16160. }
  16161. }
  16162. }
  16163. for (var i = 0; i < len; i++) {
  16164. var animator = animators[i];
  16165. var targetProp = animator.targetName;
  16166. if (!targetProp) {
  16167. !onlyShape && saveAnimatorTrackToCssKfs(animator, transformKfs);
  16168. }
  16169. else if (targetProp === 'shape') {
  16170. saveAnimatorTrackToCssKfs(animator, shapeKfs);
  16171. }
  16172. }
  16173. for (var percent in transformKfs) {
  16174. var transform = {};
  16175. copyTransform(transform, el);
  16176. extend(transform, transformKfs[percent]);
  16177. var str = getSRTTransformString(transform);
  16178. var timingFunction = transformKfs[percent][animationTimingFunctionAttrName];
  16179. finalKfs[percent] = str ? {
  16180. transform: str
  16181. } : {};
  16182. setTransformOrigin(finalKfs[percent], transform);
  16183. if (timingFunction) {
  16184. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16185. }
  16186. }
  16187. var path;
  16188. var canAnimateShape = true;
  16189. for (var percent in shapeKfs) {
  16190. finalKfs[percent] = finalKfs[percent] || {};
  16191. var isFirst = !path;
  16192. var timingFunction = shapeKfs[percent][animationTimingFunctionAttrName];
  16193. if (isFirst) {
  16194. path = new PathProxy();
  16195. }
  16196. var len_1 = path.len();
  16197. path.reset();
  16198. finalKfs[percent].d = buildPathString(el, shapeKfs[percent], path);
  16199. var newLen = path.len();
  16200. if (!isFirst && len_1 !== newLen) {
  16201. canAnimateShape = false;
  16202. break;
  16203. }
  16204. if (timingFunction) {
  16205. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16206. }
  16207. }
  16208. if (!canAnimateShape) {
  16209. for (var percent in finalKfs) {
  16210. delete finalKfs[percent].d;
  16211. }
  16212. }
  16213. if (!onlyShape) {
  16214. for (var i = 0; i < len; i++) {
  16215. var animator = animators[i];
  16216. var targetProp = animator.targetName;
  16217. if (targetProp === 'style') {
  16218. saveAnimatorTrackToCssKfs(animator, finalKfs, function (propName) { return ANIMATE_STYLE_MAP[propName]; });
  16219. }
  16220. }
  16221. }
  16222. var percents = keys(finalKfs);
  16223. var allTransformOriginSame = true;
  16224. var transformOrigin;
  16225. for (var i = 1; i < percents.length; i++) {
  16226. var p0 = percents[i - 1];
  16227. var p1 = percents[i];
  16228. if (finalKfs[p0][transformOriginKey] !== finalKfs[p1][transformOriginKey]) {
  16229. allTransformOriginSame = false;
  16230. break;
  16231. }
  16232. transformOrigin = finalKfs[p0][transformOriginKey];
  16233. }
  16234. if (allTransformOriginSame && transformOrigin) {
  16235. for (var percent in finalKfs) {
  16236. if (finalKfs[percent][transformOriginKey]) {
  16237. delete finalKfs[percent][transformOriginKey];
  16238. }
  16239. }
  16240. attrs[transformOriginKey] = transformOrigin;
  16241. }
  16242. if (filter(percents, function (percent) { return keys(finalKfs[percent]).length > 0; }).length) {
  16243. var animationName = addAnimation(finalKfs, scope);
  16244. return animationName + " " + groupAnimator[0] + " both";
  16245. }
  16246. }
  16247. for (var key in groupAnimators) {
  16248. var animationCfg = createSingleCSSAnimation(groupAnimators[key]);
  16249. if (animationCfg) {
  16250. cssAnimations.push(animationCfg);
  16251. }
  16252. }
  16253. if (cssAnimations.length) {
  16254. var className = scope.zrId + '-cls-' + getClassId();
  16255. scope.cssNodes['.' + className] = {
  16256. animation: cssAnimations.join(',')
  16257. };
  16258. attrs["class"] = className;
  16259. }
  16260. }
  16261. function createCSSEmphasis(el, attrs, scope) {
  16262. if (!el.ignore) {
  16263. if (el.isSilent()) {
  16264. var style = {
  16265. 'pointer-events': 'none'
  16266. };
  16267. setClassAttribute(style, attrs, scope, true);
  16268. }
  16269. else {
  16270. var emphasisStyle = el.states.emphasis && el.states.emphasis.style
  16271. ? el.states.emphasis.style
  16272. : {};
  16273. var fill = emphasisStyle.fill;
  16274. if (!fill) {
  16275. var normalFill = el.style && el.style.fill;
  16276. var selectFill = el.states.select
  16277. && el.states.select.style
  16278. && el.states.select.style.fill;
  16279. var fromFill = el.currentStates.indexOf('select') >= 0
  16280. ? (selectFill || normalFill)
  16281. : normalFill;
  16282. if (fromFill) {
  16283. fill = liftColor(fromFill);
  16284. }
  16285. }
  16286. var lineWidth = emphasisStyle.lineWidth;
  16287. if (lineWidth) {
  16288. var scaleX = (!emphasisStyle.strokeNoScale && el.transform)
  16289. ? el.transform[0]
  16290. : 1;
  16291. lineWidth = lineWidth / scaleX;
  16292. }
  16293. var style = {
  16294. cursor: 'pointer',
  16295. };
  16296. if (fill) {
  16297. style.fill = fill;
  16298. }
  16299. if (emphasisStyle.stroke) {
  16300. style.stroke = emphasisStyle.stroke;
  16301. }
  16302. if (lineWidth) {
  16303. style['stroke-width'] = lineWidth;
  16304. }
  16305. setClassAttribute(style, attrs, scope, true);
  16306. }
  16307. }
  16308. }
  16309. function setClassAttribute(style, attrs, scope, withHover) {
  16310. var styleKey = JSON.stringify(style);
  16311. var className = scope.cssStyleCache[styleKey];
  16312. if (!className) {
  16313. className = scope.zrId + '-cls-' + getClassId();
  16314. scope.cssStyleCache[styleKey] = className;
  16315. scope.cssNodes['.' + className + (withHover ? ':hover' : '')] = style;
  16316. }
  16317. attrs["class"] = attrs["class"] ? (attrs["class"] + ' ' + className) : className;
  16318. }
  16319. var round$1 = Math.round;
  16320. function isImageLike$1(val) {
  16321. return val && isString(val.src);
  16322. }
  16323. function isCanvasLike(val) {
  16324. return val && isFunction(val.toDataURL);
  16325. }
  16326. function setStyleAttrs(attrs, style, el, scope) {
  16327. mapStyleToAttrs(function (key, val) {
  16328. var isFillStroke = key === 'fill' || key === 'stroke';
  16329. if (isFillStroke && isGradient(val)) {
  16330. setGradient(style, attrs, key, scope);
  16331. }
  16332. else if (isFillStroke && isPattern(val)) {
  16333. setPattern(el, attrs, key, scope);
  16334. }
  16335. else {
  16336. attrs[key] = val;
  16337. }
  16338. if (isFillStroke && scope.ssr && val === 'none') {
  16339. attrs['pointer-events'] = 'visible';
  16340. }
  16341. }, style, el, false);
  16342. setShadow(el, attrs, scope);
  16343. }
  16344. function setMetaData(attrs, el) {
  16345. var metaData = getElementSSRData(el);
  16346. if (metaData) {
  16347. metaData.each(function (val, key) {
  16348. val != null && (attrs[(META_DATA_PREFIX + key).toLowerCase()] = val + '');
  16349. });
  16350. if (el.isSilent()) {
  16351. attrs[META_DATA_PREFIX + 'silent'] = 'true';
  16352. }
  16353. }
  16354. }
  16355. function noRotateScale(m) {
  16356. return isAroundZero$1(m[0] - 1)
  16357. && isAroundZero$1(m[1])
  16358. && isAroundZero$1(m[2])
  16359. && isAroundZero$1(m[3] - 1);
  16360. }
  16361. function noTranslate(m) {
  16362. return isAroundZero$1(m[4]) && isAroundZero$1(m[5]);
  16363. }
  16364. function setTransform(attrs, m, compress) {
  16365. if (m && !(noTranslate(m) && noRotateScale(m))) {
  16366. var mul = compress ? 10 : 1e4;
  16367. attrs.transform = noRotateScale(m)
  16368. ? "translate(" + round$1(m[4] * mul) / mul + " " + round$1(m[5] * mul) / mul + ")" : getMatrixStr(m);
  16369. }
  16370. }
  16371. function convertPolyShape(shape, attrs, mul) {
  16372. var points = shape.points;
  16373. var strArr = [];
  16374. for (var i = 0; i < points.length; i++) {
  16375. strArr.push(round$1(points[i][0] * mul) / mul);
  16376. strArr.push(round$1(points[i][1] * mul) / mul);
  16377. }
  16378. attrs.points = strArr.join(' ');
  16379. }
  16380. function validatePolyShape(shape) {
  16381. return !shape.smooth;
  16382. }
  16383. function createAttrsConvert(desc) {
  16384. var normalizedDesc = map(desc, function (item) {
  16385. return (typeof item === 'string' ? [item, item] : item);
  16386. });
  16387. return function (shape, attrs, mul) {
  16388. for (var i = 0; i < normalizedDesc.length; i++) {
  16389. var item = normalizedDesc[i];
  16390. var val = shape[item[0]];
  16391. if (val != null) {
  16392. attrs[item[1]] = round$1(val * mul) / mul;
  16393. }
  16394. }
  16395. };
  16396. }
  16397. var builtinShapesDef = {
  16398. circle: [createAttrsConvert(['cx', 'cy', 'r'])],
  16399. polyline: [convertPolyShape, validatePolyShape],
  16400. polygon: [convertPolyShape, validatePolyShape]
  16401. };
  16402. function hasShapeAnimation(el) {
  16403. var animators = el.animators;
  16404. for (var i = 0; i < animators.length; i++) {
  16405. if (animators[i].targetName === 'shape') {
  16406. return true;
  16407. }
  16408. }
  16409. return false;
  16410. }
  16411. function brushSVGPath(el, scope) {
  16412. var style = el.style;
  16413. var shape = el.shape;
  16414. var builtinShpDef = builtinShapesDef[el.type];
  16415. var attrs = {};
  16416. var needsAnimate = scope.animation;
  16417. var svgElType = 'path';
  16418. var strokePercent = el.style.strokePercent;
  16419. var precision = (scope.compress && getPathPrecision(el)) || 4;
  16420. if (builtinShpDef
  16421. && !scope.willUpdate
  16422. && !(builtinShpDef[1] && !builtinShpDef[1](shape))
  16423. && !(needsAnimate && hasShapeAnimation(el))
  16424. && !(strokePercent < 1)) {
  16425. svgElType = el.type;
  16426. var mul = Math.pow(10, precision);
  16427. builtinShpDef[0](shape, attrs, mul);
  16428. }
  16429. else {
  16430. var needBuildPath = !el.path || el.shapeChanged();
  16431. if (!el.path) {
  16432. el.createPathProxy();
  16433. }
  16434. var path = el.path;
  16435. if (needBuildPath) {
  16436. path.beginPath();
  16437. el.buildPath(path, el.shape);
  16438. el.pathUpdated();
  16439. }
  16440. var pathVersion = path.getVersion();
  16441. var elExt = el;
  16442. var svgPathBuilder = elExt.__svgPathBuilder;
  16443. if (elExt.__svgPathVersion !== pathVersion
  16444. || !svgPathBuilder
  16445. || strokePercent !== elExt.__svgPathStrokePercent) {
  16446. if (!svgPathBuilder) {
  16447. svgPathBuilder = elExt.__svgPathBuilder = new SVGPathRebuilder();
  16448. }
  16449. svgPathBuilder.reset(precision);
  16450. path.rebuildPath(svgPathBuilder, strokePercent);
  16451. svgPathBuilder.generateStr();
  16452. elExt.__svgPathVersion = pathVersion;
  16453. elExt.__svgPathStrokePercent = strokePercent;
  16454. }
  16455. attrs.d = svgPathBuilder.getStr();
  16456. }
  16457. setTransform(attrs, el.transform);
  16458. setStyleAttrs(attrs, style, el, scope);
  16459. setMetaData(attrs, el);
  16460. scope.animation && createCSSAnimation(el, attrs, scope);
  16461. scope.emphasis && createCSSEmphasis(el, attrs, scope);
  16462. return createVNode(svgElType, el.id + '', attrs);
  16463. }
  16464. function brushSVGImage(el, scope) {
  16465. var style = el.style;
  16466. var image = style.image;
  16467. if (image && !isString(image)) {
  16468. if (isImageLike$1(image)) {
  16469. image = image.src;
  16470. }
  16471. else if (isCanvasLike(image)) {
  16472. image = image.toDataURL();
  16473. }
  16474. }
  16475. if (!image) {
  16476. return;
  16477. }
  16478. var x = style.x || 0;
  16479. var y = style.y || 0;
  16480. var dw = style.width;
  16481. var dh = style.height;
  16482. var attrs = {
  16483. href: image,
  16484. width: dw,
  16485. height: dh
  16486. };
  16487. if (x) {
  16488. attrs.x = x;
  16489. }
  16490. if (y) {
  16491. attrs.y = y;
  16492. }
  16493. setTransform(attrs, el.transform);
  16494. setStyleAttrs(attrs, style, el, scope);
  16495. setMetaData(attrs, el);
  16496. scope.animation && createCSSAnimation(el, attrs, scope);
  16497. return createVNode('image', el.id + '', attrs);
  16498. }
  16499. function brushSVGTSpan(el, scope) {
  16500. var style = el.style;
  16501. var text = style.text;
  16502. text != null && (text += '');
  16503. if (!text || isNaN(style.x) || isNaN(style.y)) {
  16504. return;
  16505. }
  16506. var font = style.font || DEFAULT_FONT;
  16507. var x = style.x || 0;
  16508. var y = adjustTextY(style.y || 0, getLineHeight(font), style.textBaseline);
  16509. var textAlign = TEXT_ALIGN_TO_ANCHOR[style.textAlign]
  16510. || style.textAlign;
  16511. var attrs = {
  16512. 'dominant-baseline': 'central',
  16513. 'text-anchor': textAlign
  16514. };
  16515. if (hasSeparateFont(style)) {
  16516. var separatedFontStr = '';
  16517. var fontStyle = style.fontStyle;
  16518. var fontSize = parseFontSize(style.fontSize);
  16519. if (!parseFloat(fontSize)) {
  16520. return;
  16521. }
  16522. var fontFamily = style.fontFamily || DEFAULT_FONT_FAMILY;
  16523. var fontWeight = style.fontWeight;
  16524. separatedFontStr += "font-size:" + fontSize + ";font-family:" + fontFamily + ";";
  16525. if (fontStyle && fontStyle !== 'normal') {
  16526. separatedFontStr += "font-style:" + fontStyle + ";";
  16527. }
  16528. if (fontWeight && fontWeight !== 'normal') {
  16529. separatedFontStr += "font-weight:" + fontWeight + ";";
  16530. }
  16531. attrs.style = separatedFontStr;
  16532. }
  16533. else {
  16534. attrs.style = "font: " + font;
  16535. }
  16536. if (text.match(/\s/)) {
  16537. attrs['xml:space'] = 'preserve';
  16538. }
  16539. if (x) {
  16540. attrs.x = x;
  16541. }
  16542. if (y) {
  16543. attrs.y = y;
  16544. }
  16545. setTransform(attrs, el.transform);
  16546. setStyleAttrs(attrs, style, el, scope);
  16547. setMetaData(attrs, el);
  16548. scope.animation && createCSSAnimation(el, attrs, scope);
  16549. return createVNode('text', el.id + '', attrs, undefined, text);
  16550. }
  16551. function brush$1(el, scope) {
  16552. if (el instanceof Path) {
  16553. return brushSVGPath(el, scope);
  16554. }
  16555. else if (el instanceof ZRImage) {
  16556. return brushSVGImage(el, scope);
  16557. }
  16558. else if (el instanceof TSpan) {
  16559. return brushSVGTSpan(el, scope);
  16560. }
  16561. }
  16562. function setShadow(el, attrs, scope) {
  16563. var style = el.style;
  16564. if (hasShadow(style)) {
  16565. var shadowKey = getShadowKey(el);
  16566. var shadowCache = scope.shadowCache;
  16567. var shadowId = shadowCache[shadowKey];
  16568. if (!shadowId) {
  16569. var globalScale = el.getGlobalScale();
  16570. var scaleX = globalScale[0];
  16571. var scaleY = globalScale[1];
  16572. if (!scaleX || !scaleY) {
  16573. return;
  16574. }
  16575. var offsetX = style.shadowOffsetX || 0;
  16576. var offsetY = style.shadowOffsetY || 0;
  16577. var blur_1 = style.shadowBlur;
  16578. var _a = normalizeColor(style.shadowColor), opacity = _a.opacity, color = _a.color;
  16579. var stdDx = blur_1 / 2 / scaleX;
  16580. var stdDy = blur_1 / 2 / scaleY;
  16581. var stdDeviation = stdDx + ' ' + stdDy;
  16582. shadowId = scope.zrId + '-s' + scope.shadowIdx++;
  16583. scope.defs[shadowId] = createVNode('filter', shadowId, {
  16584. 'id': shadowId,
  16585. 'x': '-100%',
  16586. 'y': '-100%',
  16587. 'width': '300%',
  16588. 'height': '300%'
  16589. }, [
  16590. createVNode('feDropShadow', '', {
  16591. 'dx': offsetX / scaleX,
  16592. 'dy': offsetY / scaleY,
  16593. 'stdDeviation': stdDeviation,
  16594. 'flood-color': color,
  16595. 'flood-opacity': opacity
  16596. })
  16597. ]);
  16598. shadowCache[shadowKey] = shadowId;
  16599. }
  16600. attrs.filter = getIdURL(shadowId);
  16601. }
  16602. }
  16603. function setGradient(style, attrs, target, scope) {
  16604. var val = style[target];
  16605. var gradientTag;
  16606. var gradientAttrs = {
  16607. 'gradientUnits': val.global
  16608. ? 'userSpaceOnUse'
  16609. : 'objectBoundingBox'
  16610. };
  16611. if (isLinearGradient(val)) {
  16612. gradientTag = 'linearGradient';
  16613. gradientAttrs.x1 = val.x;
  16614. gradientAttrs.y1 = val.y;
  16615. gradientAttrs.x2 = val.x2;
  16616. gradientAttrs.y2 = val.y2;
  16617. }
  16618. else if (isRadialGradient(val)) {
  16619. gradientTag = 'radialGradient';
  16620. gradientAttrs.cx = retrieve2(val.x, 0.5);
  16621. gradientAttrs.cy = retrieve2(val.y, 0.5);
  16622. gradientAttrs.r = retrieve2(val.r, 0.5);
  16623. }
  16624. else {
  16625. {
  16626. logError('Illegal gradient type.');
  16627. }
  16628. return;
  16629. }
  16630. var colors = val.colorStops;
  16631. var colorStops = [];
  16632. for (var i = 0, len = colors.length; i < len; ++i) {
  16633. var offset = round4(colors[i].offset) * 100 + '%';
  16634. var stopColor = colors[i].color;
  16635. var _a = normalizeColor(stopColor), color = _a.color, opacity = _a.opacity;
  16636. var stopsAttrs = {
  16637. 'offset': offset
  16638. };
  16639. stopsAttrs['stop-color'] = color;
  16640. if (opacity < 1) {
  16641. stopsAttrs['stop-opacity'] = opacity;
  16642. }
  16643. colorStops.push(createVNode('stop', i + '', stopsAttrs));
  16644. }
  16645. var gradientVNode = createVNode(gradientTag, '', gradientAttrs, colorStops);
  16646. var gradientKey = vNodeToString(gradientVNode);
  16647. var gradientCache = scope.gradientCache;
  16648. var gradientId = gradientCache[gradientKey];
  16649. if (!gradientId) {
  16650. gradientId = scope.zrId + '-g' + scope.gradientIdx++;
  16651. gradientCache[gradientKey] = gradientId;
  16652. gradientAttrs.id = gradientId;
  16653. scope.defs[gradientId] = createVNode(gradientTag, gradientId, gradientAttrs, colorStops);
  16654. }
  16655. attrs[target] = getIdURL(gradientId);
  16656. }
  16657. function setPattern(el, attrs, target, scope) {
  16658. var val = el.style[target];
  16659. var boundingRect = el.getBoundingRect();
  16660. var patternAttrs = {};
  16661. var repeat = val.repeat;
  16662. var noRepeat = repeat === 'no-repeat';
  16663. var repeatX = repeat === 'repeat-x';
  16664. var repeatY = repeat === 'repeat-y';
  16665. var child;
  16666. if (isImagePattern(val)) {
  16667. var imageWidth_1 = val.imageWidth;
  16668. var imageHeight_1 = val.imageHeight;
  16669. var imageSrc = void 0;
  16670. var patternImage = val.image;
  16671. if (isString(patternImage)) {
  16672. imageSrc = patternImage;
  16673. }
  16674. else if (isImageLike$1(patternImage)) {
  16675. imageSrc = patternImage.src;
  16676. }
  16677. else if (isCanvasLike(patternImage)) {
  16678. imageSrc = patternImage.toDataURL();
  16679. }
  16680. if (typeof Image === 'undefined') {
  16681. var errMsg = 'Image width/height must been given explictly in svg-ssr renderer.';
  16682. assert(imageWidth_1, errMsg);
  16683. assert(imageHeight_1, errMsg);
  16684. }
  16685. else if (imageWidth_1 == null || imageHeight_1 == null) {
  16686. var setSizeToVNode_1 = function (vNode, img) {
  16687. if (vNode) {
  16688. var svgEl = vNode.elm;
  16689. var width = imageWidth_1 || img.width;
  16690. var height = imageHeight_1 || img.height;
  16691. if (vNode.tag === 'pattern') {
  16692. if (repeatX) {
  16693. height = 1;
  16694. width /= boundingRect.width;
  16695. }
  16696. else if (repeatY) {
  16697. width = 1;
  16698. height /= boundingRect.height;
  16699. }
  16700. }
  16701. vNode.attrs.width = width;
  16702. vNode.attrs.height = height;
  16703. if (svgEl) {
  16704. svgEl.setAttribute('width', width);
  16705. svgEl.setAttribute('height', height);
  16706. }
  16707. }
  16708. };
  16709. var createdImage = createOrUpdateImage(imageSrc, null, el, function (img) {
  16710. noRepeat || setSizeToVNode_1(patternVNode, img);
  16711. setSizeToVNode_1(child, img);
  16712. });
  16713. if (createdImage && createdImage.width && createdImage.height) {
  16714. imageWidth_1 = imageWidth_1 || createdImage.width;
  16715. imageHeight_1 = imageHeight_1 || createdImage.height;
  16716. }
  16717. }
  16718. child = createVNode('image', 'img', {
  16719. href: imageSrc,
  16720. width: imageWidth_1,
  16721. height: imageHeight_1
  16722. });
  16723. patternAttrs.width = imageWidth_1;
  16724. patternAttrs.height = imageHeight_1;
  16725. }
  16726. else if (val.svgElement) {
  16727. child = clone(val.svgElement);
  16728. patternAttrs.width = val.svgWidth;
  16729. patternAttrs.height = val.svgHeight;
  16730. }
  16731. if (!child) {
  16732. return;
  16733. }
  16734. var patternWidth;
  16735. var patternHeight;
  16736. if (noRepeat) {
  16737. patternWidth = patternHeight = 1;
  16738. }
  16739. else if (repeatX) {
  16740. patternHeight = 1;
  16741. patternWidth = patternAttrs.width / boundingRect.width;
  16742. }
  16743. else if (repeatY) {
  16744. patternWidth = 1;
  16745. patternHeight = patternAttrs.height / boundingRect.height;
  16746. }
  16747. else {
  16748. patternAttrs.patternUnits = 'userSpaceOnUse';
  16749. }
  16750. if (patternWidth != null && !isNaN(patternWidth)) {
  16751. patternAttrs.width = patternWidth;
  16752. }
  16753. if (patternHeight != null && !isNaN(patternHeight)) {
  16754. patternAttrs.height = patternHeight;
  16755. }
  16756. var patternTransform = getSRTTransformString(val);
  16757. patternTransform && (patternAttrs.patternTransform = patternTransform);
  16758. var patternVNode = createVNode('pattern', '', patternAttrs, [child]);
  16759. var patternKey = vNodeToString(patternVNode);
  16760. var patternCache = scope.patternCache;
  16761. var patternId = patternCache[patternKey];
  16762. if (!patternId) {
  16763. patternId = scope.zrId + '-p' + scope.patternIdx++;
  16764. patternCache[patternKey] = patternId;
  16765. patternAttrs.id = patternId;
  16766. patternVNode = scope.defs[patternId] = createVNode('pattern', patternId, patternAttrs, [child]);
  16767. }
  16768. attrs[target] = getIdURL(patternId);
  16769. }
  16770. function setClipPath(clipPath, attrs, scope) {
  16771. var clipPathCache = scope.clipPathCache, defs = scope.defs;
  16772. var clipPathId = clipPathCache[clipPath.id];
  16773. if (!clipPathId) {
  16774. clipPathId = scope.zrId + '-c' + scope.clipPathIdx++;
  16775. var clipPathAttrs = {
  16776. id: clipPathId
  16777. };
  16778. clipPathCache[clipPath.id] = clipPathId;
  16779. defs[clipPathId] = createVNode('clipPath', clipPathId, clipPathAttrs, [brushSVGPath(clipPath, scope)]);
  16780. }
  16781. attrs['clip-path'] = getIdURL(clipPathId);
  16782. }
  16783. function createTextNode(text) {
  16784. return document.createTextNode(text);
  16785. }
  16786. function insertBefore(parentNode, newNode, referenceNode) {
  16787. parentNode.insertBefore(newNode, referenceNode);
  16788. }
  16789. function removeChild(node, child) {
  16790. node.removeChild(child);
  16791. }
  16792. function appendChild(node, child) {
  16793. node.appendChild(child);
  16794. }
  16795. function parentNode(node) {
  16796. return node.parentNode;
  16797. }
  16798. function nextSibling(node) {
  16799. return node.nextSibling;
  16800. }
  16801. function setTextContent(node, text) {
  16802. node.textContent = text;
  16803. }
  16804. var colonChar = 58;
  16805. var xChar = 120;
  16806. var emptyNode = createVNode('', '');
  16807. function isUndef(s) {
  16808. return s === undefined;
  16809. }
  16810. function isDef(s) {
  16811. return s !== undefined;
  16812. }
  16813. function createKeyToOldIdx(children, beginIdx, endIdx) {
  16814. var map = {};
  16815. for (var i = beginIdx; i <= endIdx; ++i) {
  16816. var key = children[i].key;
  16817. if (key !== undefined) {
  16818. {
  16819. if (map[key] != null) {
  16820. console.error("Duplicate key " + key);
  16821. }
  16822. }
  16823. map[key] = i;
  16824. }
  16825. }
  16826. return map;
  16827. }
  16828. function sameVnode(vnode1, vnode2) {
  16829. var isSameKey = vnode1.key === vnode2.key;
  16830. var isSameTag = vnode1.tag === vnode2.tag;
  16831. return isSameTag && isSameKey;
  16832. }
  16833. function createElm(vnode) {
  16834. var i;
  16835. var children = vnode.children;
  16836. var tag = vnode.tag;
  16837. if (isDef(tag)) {
  16838. var elm = (vnode.elm = createElement(tag));
  16839. updateAttrs(emptyNode, vnode);
  16840. if (isArray(children)) {
  16841. for (i = 0; i < children.length; ++i) {
  16842. var ch = children[i];
  16843. if (ch != null) {
  16844. appendChild(elm, createElm(ch));
  16845. }
  16846. }
  16847. }
  16848. else if (isDef(vnode.text) && !isObject(vnode.text)) {
  16849. appendChild(elm, createTextNode(vnode.text));
  16850. }
  16851. }
  16852. else {
  16853. vnode.elm = createTextNode(vnode.text);
  16854. }
  16855. return vnode.elm;
  16856. }
  16857. function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
  16858. for (; startIdx <= endIdx; ++startIdx) {
  16859. var ch = vnodes[startIdx];
  16860. if (ch != null) {
  16861. insertBefore(parentElm, createElm(ch), before);
  16862. }
  16863. }
  16864. }
  16865. function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
  16866. for (; startIdx <= endIdx; ++startIdx) {
  16867. var ch = vnodes[startIdx];
  16868. if (ch != null) {
  16869. if (isDef(ch.tag)) {
  16870. var parent_1 = parentNode(ch.elm);
  16871. removeChild(parent_1, ch.elm);
  16872. }
  16873. else {
  16874. removeChild(parentElm, ch.elm);
  16875. }
  16876. }
  16877. }
  16878. }
  16879. function updateAttrs(oldVnode, vnode) {
  16880. var key;
  16881. var elm = vnode.elm;
  16882. var oldAttrs = oldVnode && oldVnode.attrs || {};
  16883. var attrs = vnode.attrs || {};
  16884. if (oldAttrs === attrs) {
  16885. return;
  16886. }
  16887. for (key in attrs) {
  16888. var cur = attrs[key];
  16889. var old = oldAttrs[key];
  16890. if (old !== cur) {
  16891. if (cur === true) {
  16892. elm.setAttribute(key, '');
  16893. }
  16894. else if (cur === false) {
  16895. elm.removeAttribute(key);
  16896. }
  16897. else {
  16898. if (key === 'style') {
  16899. elm.style.cssText = cur;
  16900. }
  16901. else if (key.charCodeAt(0) !== xChar) {
  16902. elm.setAttribute(key, cur);
  16903. }
  16904. else if (key === 'xmlns:xlink' || key === 'xmlns') {
  16905. elm.setAttributeNS(XMLNS, key, cur);
  16906. }
  16907. else if (key.charCodeAt(3) === colonChar) {
  16908. elm.setAttributeNS(XML_NAMESPACE, key, cur);
  16909. }
  16910. else if (key.charCodeAt(5) === colonChar) {
  16911. elm.setAttributeNS(XLINKNS, key, cur);
  16912. }
  16913. else {
  16914. elm.setAttribute(key, cur);
  16915. }
  16916. }
  16917. }
  16918. }
  16919. for (key in oldAttrs) {
  16920. if (!(key in attrs)) {
  16921. elm.removeAttribute(key);
  16922. }
  16923. }
  16924. }
  16925. function updateChildren(parentElm, oldCh, newCh) {
  16926. var oldStartIdx = 0;
  16927. var newStartIdx = 0;
  16928. var oldEndIdx = oldCh.length - 1;
  16929. var oldStartVnode = oldCh[0];
  16930. var oldEndVnode = oldCh[oldEndIdx];
  16931. var newEndIdx = newCh.length - 1;
  16932. var newStartVnode = newCh[0];
  16933. var newEndVnode = newCh[newEndIdx];
  16934. var oldKeyToIdx;
  16935. var idxInOld;
  16936. var elmToMove;
  16937. var before;
  16938. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  16939. if (oldStartVnode == null) {
  16940. oldStartVnode = oldCh[++oldStartIdx];
  16941. }
  16942. else if (oldEndVnode == null) {
  16943. oldEndVnode = oldCh[--oldEndIdx];
  16944. }
  16945. else if (newStartVnode == null) {
  16946. newStartVnode = newCh[++newStartIdx];
  16947. }
  16948. else if (newEndVnode == null) {
  16949. newEndVnode = newCh[--newEndIdx];
  16950. }
  16951. else if (sameVnode(oldStartVnode, newStartVnode)) {
  16952. patchVnode(oldStartVnode, newStartVnode);
  16953. oldStartVnode = oldCh[++oldStartIdx];
  16954. newStartVnode = newCh[++newStartIdx];
  16955. }
  16956. else if (sameVnode(oldEndVnode, newEndVnode)) {
  16957. patchVnode(oldEndVnode, newEndVnode);
  16958. oldEndVnode = oldCh[--oldEndIdx];
  16959. newEndVnode = newCh[--newEndIdx];
  16960. }
  16961. else if (sameVnode(oldStartVnode, newEndVnode)) {
  16962. patchVnode(oldStartVnode, newEndVnode);
  16963. insertBefore(parentElm, oldStartVnode.elm, nextSibling(oldEndVnode.elm));
  16964. oldStartVnode = oldCh[++oldStartIdx];
  16965. newEndVnode = newCh[--newEndIdx];
  16966. }
  16967. else if (sameVnode(oldEndVnode, newStartVnode)) {
  16968. patchVnode(oldEndVnode, newStartVnode);
  16969. insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
  16970. oldEndVnode = oldCh[--oldEndIdx];
  16971. newStartVnode = newCh[++newStartIdx];
  16972. }
  16973. else {
  16974. if (isUndef(oldKeyToIdx)) {
  16975. oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
  16976. }
  16977. idxInOld = oldKeyToIdx[newStartVnode.key];
  16978. if (isUndef(idxInOld)) {
  16979. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  16980. }
  16981. else {
  16982. elmToMove = oldCh[idxInOld];
  16983. if (elmToMove.tag !== newStartVnode.tag) {
  16984. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  16985. }
  16986. else {
  16987. patchVnode(elmToMove, newStartVnode);
  16988. oldCh[idxInOld] = undefined;
  16989. insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
  16990. }
  16991. }
  16992. newStartVnode = newCh[++newStartIdx];
  16993. }
  16994. }
  16995. if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
  16996. if (oldStartIdx > oldEndIdx) {
  16997. before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm;
  16998. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
  16999. }
  17000. else {
  17001. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
  17002. }
  17003. }
  17004. }
  17005. function patchVnode(oldVnode, vnode) {
  17006. var elm = (vnode.elm = oldVnode.elm);
  17007. var oldCh = oldVnode.children;
  17008. var ch = vnode.children;
  17009. if (oldVnode === vnode) {
  17010. return;
  17011. }
  17012. updateAttrs(oldVnode, vnode);
  17013. if (isUndef(vnode.text)) {
  17014. if (isDef(oldCh) && isDef(ch)) {
  17015. if (oldCh !== ch) {
  17016. updateChildren(elm, oldCh, ch);
  17017. }
  17018. }
  17019. else if (isDef(ch)) {
  17020. if (isDef(oldVnode.text)) {
  17021. setTextContent(elm, '');
  17022. }
  17023. addVnodes(elm, null, ch, 0, ch.length - 1);
  17024. }
  17025. else if (isDef(oldCh)) {
  17026. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  17027. }
  17028. else if (isDef(oldVnode.text)) {
  17029. setTextContent(elm, '');
  17030. }
  17031. }
  17032. else if (oldVnode.text !== vnode.text) {
  17033. if (isDef(oldCh)) {
  17034. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  17035. }
  17036. setTextContent(elm, vnode.text);
  17037. }
  17038. }
  17039. function patch(oldVnode, vnode) {
  17040. if (sameVnode(oldVnode, vnode)) {
  17041. patchVnode(oldVnode, vnode);
  17042. }
  17043. else {
  17044. var elm = oldVnode.elm;
  17045. var parent_2 = parentNode(elm);
  17046. createElm(vnode);
  17047. if (parent_2 !== null) {
  17048. insertBefore(parent_2, vnode.elm, nextSibling(elm));
  17049. removeVnodes(parent_2, [oldVnode], 0, 0);
  17050. }
  17051. }
  17052. return vnode;
  17053. }
  17054. var svgId = 0;
  17055. var SVGPainter = (function () {
  17056. function SVGPainter(root, storage, opts) {
  17057. this.type = 'svg';
  17058. this.refreshHover = createMethodNotSupport('refreshHover');
  17059. this.configLayer = createMethodNotSupport('configLayer');
  17060. this.storage = storage;
  17061. this._opts = opts = extend({}, opts);
  17062. this.root = root;
  17063. this._id = 'zr' + svgId++;
  17064. this._oldVNode = createSVGVNode(opts.width, opts.height);
  17065. if (root && !opts.ssr) {
  17066. var viewport = this._viewport = document.createElement('div');
  17067. viewport.style.cssText = 'position:relative;overflow:hidden';
  17068. var svgDom = this._svgDom = this._oldVNode.elm = createElement('svg');
  17069. updateAttrs(null, this._oldVNode);
  17070. viewport.appendChild(svgDom);
  17071. root.appendChild(viewport);
  17072. }
  17073. this.resize(opts.width, opts.height);
  17074. }
  17075. SVGPainter.prototype.getType = function () {
  17076. return this.type;
  17077. };
  17078. SVGPainter.prototype.getViewportRoot = function () {
  17079. return this._viewport;
  17080. };
  17081. SVGPainter.prototype.getViewportRootOffset = function () {
  17082. var viewportRoot = this.getViewportRoot();
  17083. if (viewportRoot) {
  17084. return {
  17085. offsetLeft: viewportRoot.offsetLeft || 0,
  17086. offsetTop: viewportRoot.offsetTop || 0
  17087. };
  17088. }
  17089. };
  17090. SVGPainter.prototype.getSvgDom = function () {
  17091. return this._svgDom;
  17092. };
  17093. SVGPainter.prototype.refresh = function () {
  17094. if (this.root) {
  17095. var vnode = this.renderToVNode({
  17096. willUpdate: true
  17097. });
  17098. vnode.attrs.style = 'position:absolute;left:0;top:0;user-select:none';
  17099. patch(this._oldVNode, vnode);
  17100. this._oldVNode = vnode;
  17101. }
  17102. };
  17103. SVGPainter.prototype.renderOneToVNode = function (el) {
  17104. return brush$1(el, createBrushScope(this._id));
  17105. };
  17106. SVGPainter.prototype.renderToVNode = function (opts) {
  17107. opts = opts || {};
  17108. var list = this.storage.getDisplayList(true);
  17109. var width = this._width;
  17110. var height = this._height;
  17111. var scope = createBrushScope(this._id);
  17112. scope.animation = opts.animation;
  17113. scope.willUpdate = opts.willUpdate;
  17114. scope.compress = opts.compress;
  17115. scope.emphasis = opts.emphasis;
  17116. scope.ssr = this._opts.ssr;
  17117. var children = [];
  17118. var bgVNode = this._bgVNode = createBackgroundVNode(width, height, this._backgroundColor, scope);
  17119. bgVNode && children.push(bgVNode);
  17120. var mainVNode = !opts.compress
  17121. ? (this._mainVNode = createVNode('g', 'main', {}, [])) : null;
  17122. this._paintList(list, scope, mainVNode ? mainVNode.children : children);
  17123. mainVNode && children.push(mainVNode);
  17124. var defs = map(keys(scope.defs), function (id) { return scope.defs[id]; });
  17125. if (defs.length) {
  17126. children.push(createVNode('defs', 'defs', {}, defs));
  17127. }
  17128. if (opts.animation) {
  17129. var animationCssStr = getCssString(scope.cssNodes, scope.cssAnims, { newline: true });
  17130. if (animationCssStr) {
  17131. var styleNode = createVNode('style', 'stl', {}, [], animationCssStr);
  17132. children.push(styleNode);
  17133. }
  17134. }
  17135. return createSVGVNode(width, height, children, opts.useViewBox);
  17136. };
  17137. SVGPainter.prototype.renderToString = function (opts) {
  17138. opts = opts || {};
  17139. return vNodeToString(this.renderToVNode({
  17140. animation: retrieve2(opts.cssAnimation, true),
  17141. emphasis: retrieve2(opts.cssEmphasis, true),
  17142. willUpdate: false,
  17143. compress: true,
  17144. useViewBox: retrieve2(opts.useViewBox, true)
  17145. }), { newline: true });
  17146. };
  17147. SVGPainter.prototype.setBackgroundColor = function (backgroundColor) {
  17148. this._backgroundColor = backgroundColor;
  17149. };
  17150. SVGPainter.prototype.getSvgRoot = function () {
  17151. return this._mainVNode && this._mainVNode.elm;
  17152. };
  17153. SVGPainter.prototype._paintList = function (list, scope, out) {
  17154. var listLen = list.length;
  17155. var clipPathsGroupsStack = [];
  17156. var clipPathsGroupsStackDepth = 0;
  17157. var currentClipPathGroup;
  17158. var prevClipPaths;
  17159. var clipGroupNodeIdx = 0;
  17160. for (var i = 0; i < listLen; i++) {
  17161. var displayable = list[i];
  17162. if (!displayable.invisible) {
  17163. var clipPaths = displayable.__clipPaths;
  17164. var len = clipPaths && clipPaths.length || 0;
  17165. var prevLen = prevClipPaths && prevClipPaths.length || 0;
  17166. var lca = void 0;
  17167. for (lca = Math.max(len - 1, prevLen - 1); lca >= 0; lca--) {
  17168. if (clipPaths && prevClipPaths
  17169. && clipPaths[lca] === prevClipPaths[lca]) {
  17170. break;
  17171. }
  17172. }
  17173. for (var i_1 = prevLen - 1; i_1 > lca; i_1--) {
  17174. clipPathsGroupsStackDepth--;
  17175. currentClipPathGroup = clipPathsGroupsStack[clipPathsGroupsStackDepth - 1];
  17176. }
  17177. for (var i_2 = lca + 1; i_2 < len; i_2++) {
  17178. var groupAttrs = {};
  17179. setClipPath(clipPaths[i_2], groupAttrs, scope);
  17180. var g = createVNode('g', 'clip-g-' + clipGroupNodeIdx++, groupAttrs, []);
  17181. (currentClipPathGroup ? currentClipPathGroup.children : out).push(g);
  17182. clipPathsGroupsStack[clipPathsGroupsStackDepth++] = g;
  17183. currentClipPathGroup = g;
  17184. }
  17185. prevClipPaths = clipPaths;
  17186. var ret = brush$1(displayable, scope);
  17187. if (ret) {
  17188. (currentClipPathGroup ? currentClipPathGroup.children : out).push(ret);
  17189. }
  17190. }
  17191. }
  17192. };
  17193. SVGPainter.prototype.resize = function (width, height) {
  17194. var opts = this._opts;
  17195. var root = this.root;
  17196. var viewport = this._viewport;
  17197. width != null && (opts.width = width);
  17198. height != null && (opts.height = height);
  17199. if (root && viewport) {
  17200. viewport.style.display = 'none';
  17201. width = getSize(root, 0, opts);
  17202. height = getSize(root, 1, opts);
  17203. viewport.style.display = '';
  17204. }
  17205. if (this._width !== width || this._height !== height) {
  17206. this._width = width;
  17207. this._height = height;
  17208. if (viewport) {
  17209. var viewportStyle = viewport.style;
  17210. viewportStyle.width = width + 'px';
  17211. viewportStyle.height = height + 'px';
  17212. }
  17213. if (!isPattern(this._backgroundColor)) {
  17214. var svgDom = this._svgDom;
  17215. if (svgDom) {
  17216. svgDom.setAttribute('width', width);
  17217. svgDom.setAttribute('height', height);
  17218. }
  17219. var bgEl = this._bgVNode && this._bgVNode.elm;
  17220. if (bgEl) {
  17221. bgEl.setAttribute('width', width);
  17222. bgEl.setAttribute('height', height);
  17223. }
  17224. }
  17225. else {
  17226. this.refresh();
  17227. }
  17228. }
  17229. };
  17230. SVGPainter.prototype.getWidth = function () {
  17231. return this._width;
  17232. };
  17233. SVGPainter.prototype.getHeight = function () {
  17234. return this._height;
  17235. };
  17236. SVGPainter.prototype.dispose = function () {
  17237. if (this.root) {
  17238. this.root.innerHTML = '';
  17239. }
  17240. this._svgDom =
  17241. this._viewport =
  17242. this.storage =
  17243. this._oldVNode =
  17244. this._bgVNode =
  17245. this._mainVNode = null;
  17246. };
  17247. SVGPainter.prototype.clear = function () {
  17248. if (this._svgDom) {
  17249. this._svgDom.innerHTML = null;
  17250. }
  17251. this._oldVNode = null;
  17252. };
  17253. SVGPainter.prototype.toDataURL = function (base64) {
  17254. var str = this.renderToString();
  17255. var prefix = 'data:image/svg+xml;';
  17256. if (base64) {
  17257. str = encodeBase64(str);
  17258. return str && prefix + 'base64,' + str;
  17259. }
  17260. return prefix + 'charset=UTF-8,' + encodeURIComponent(str);
  17261. };
  17262. return SVGPainter;
  17263. }());
  17264. function createMethodNotSupport(method) {
  17265. return function () {
  17266. {
  17267. logError('In SVG mode painter not support method "' + method + '"');
  17268. }
  17269. };
  17270. }
  17271. function createBackgroundVNode(width, height, backgroundColor, scope) {
  17272. var bgVNode;
  17273. if (backgroundColor && backgroundColor !== 'none') {
  17274. bgVNode = createVNode('rect', 'bg', {
  17275. width: width,
  17276. height: height,
  17277. x: '0',
  17278. y: '0'
  17279. });
  17280. if (isGradient(backgroundColor)) {
  17281. setGradient({ fill: backgroundColor }, bgVNode.attrs, 'fill', scope);
  17282. }
  17283. else if (isPattern(backgroundColor)) {
  17284. setPattern({
  17285. style: {
  17286. fill: backgroundColor
  17287. },
  17288. dirty: noop,
  17289. getBoundingRect: function () { return ({ width: width, height: height }); }
  17290. }, bgVNode.attrs, 'fill', scope);
  17291. }
  17292. else {
  17293. var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
  17294. bgVNode.attrs.fill = color;
  17295. opacity < 1 && (bgVNode.attrs['fill-opacity'] = opacity);
  17296. }
  17297. }
  17298. return bgVNode;
  17299. }
  17300. registerPainter('canvas', CanvasPainter);
  17301. registerPainter('svg', SVGPainter);
  17302. exports.Arc = Arc;
  17303. exports.ArcShape = ArcShape;
  17304. exports.BezierCurve = BezierCurve;
  17305. exports.BezierCurveShape = BezierCurveShape;
  17306. exports.BoundingRect = BoundingRect;
  17307. exports.Circle = Circle;
  17308. exports.CircleShape = CircleShape;
  17309. exports.CompoundPath = CompoundPath;
  17310. exports.Displayable = Displayable;
  17311. exports.Droplet = Droplet;
  17312. exports.DropletShape = DropletShape;
  17313. exports.Element = Element;
  17314. exports.Ellipse = Ellipse;
  17315. exports.EllipseShape = EllipseShape;
  17316. exports.Group = Group;
  17317. exports.Heart = Heart;
  17318. exports.HeartShape = HeartShape;
  17319. exports.Image = ZRImage;
  17320. exports.IncrementalDisplayable = IncrementalDisplayable;
  17321. exports.Isogon = Isogon;
  17322. exports.IsogonShape = IsogonShape;
  17323. exports.Line = Line;
  17324. exports.LineShape = LineShape;
  17325. exports.LinearGradient = LinearGradient;
  17326. exports.OrientedBoundingRect = OrientedBoundingRect;
  17327. exports.Path = Path;
  17328. exports.Pattern = Pattern;
  17329. exports.Point = Point;
  17330. exports.Polygon = Polygon;
  17331. exports.PolygonShape = PolygonShape;
  17332. exports.Polyline = Polyline;
  17333. exports.PolylineShape = PolylineShape;
  17334. exports.RadialGradient = RadialGradient;
  17335. exports.Rect = Rect;
  17336. exports.RectShape = RectShape;
  17337. exports.Ring = Ring;
  17338. exports.RingShape = RingShape;
  17339. exports.Rose = Rose;
  17340. exports.RoseShape = RoseShape;
  17341. exports.Sector = Sector;
  17342. exports.SectorShape = SectorShape;
  17343. exports.Star = Star;
  17344. exports.StarShape = StarShape;
  17345. exports.TSpan = TSpan;
  17346. exports.Text = ZRText;
  17347. exports.Trochoid = Trochoid;
  17348. exports.TrochoidShape = TrochoidShape;
  17349. exports.color = color;
  17350. exports.dispose = dispose;
  17351. exports.disposeAll = disposeAll;
  17352. exports.getElementSSRData = getElementSSRData;
  17353. exports.getInstance = getInstance;
  17354. exports.init = init;
  17355. exports.matrix = matrix;
  17356. exports.morph = morphPath$1;
  17357. exports.parseSVG = parseSVG;
  17358. exports.path = path;
  17359. exports.registerPainter = registerPainter;
  17360. exports.registerSSRDataGetter = registerSSRDataGetter;
  17361. exports.setPlatformAPI = setPlatformAPI;
  17362. exports.showDebugDirtyRect = showDebugDirtyRect;
  17363. exports.util = util;
  17364. exports.vector = vector;
  17365. exports.version = version;
  17366. Object.defineProperty(exports, '__esModule', { value: true });
  17367. })));
  17368. //# sourceMappingURL=zrender.js.map