zrender.js 629 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.zrender = {}));
  5. }(this, (function (exports) { 'use strict';
  6. var Browser = (function () {
  7. function Browser() {
  8. this.firefox = false;
  9. this.ie = false;
  10. this.edge = false;
  11. this.newEdge = false;
  12. this.weChat = false;
  13. }
  14. return Browser;
  15. }());
  16. var Env = (function () {
  17. function Env() {
  18. this.browser = new Browser();
  19. this.node = false;
  20. this.wxa = false;
  21. this.worker = false;
  22. this.svgSupported = false;
  23. this.touchEventsSupported = false;
  24. this.pointerEventsSupported = false;
  25. this.domSupported = false;
  26. this.transformSupported = false;
  27. this.transform3dSupported = false;
  28. this.hasGlobalWindow = typeof window !== 'undefined';
  29. }
  30. return Env;
  31. }());
  32. var env = new Env();
  33. if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
  34. env.wxa = true;
  35. env.touchEventsSupported = true;
  36. }
  37. else if (typeof document === 'undefined' && typeof self !== 'undefined') {
  38. env.worker = true;
  39. }
  40. else if (typeof navigator === 'undefined') {
  41. env.node = true;
  42. env.svgSupported = true;
  43. }
  44. else {
  45. detect(navigator.userAgent, env);
  46. }
  47. function detect(ua, env) {
  48. var browser = env.browser;
  49. var firefox = ua.match(/Firefox\/([\d.]+)/);
  50. var ie = ua.match(/MSIE\s([\d.]+)/)
  51. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  52. var edge = ua.match(/Edge?\/([\d.]+)/);
  53. var weChat = (/micromessenger/i).test(ua);
  54. if (firefox) {
  55. browser.firefox = true;
  56. browser.version = firefox[1];
  57. }
  58. if (ie) {
  59. browser.ie = true;
  60. browser.version = ie[1];
  61. }
  62. if (edge) {
  63. browser.edge = true;
  64. browser.version = edge[1];
  65. browser.newEdge = +edge[1].split('.')[0] > 18;
  66. }
  67. if (weChat) {
  68. browser.weChat = true;
  69. }
  70. env.svgSupported = typeof SVGRect !== 'undefined';
  71. env.touchEventsSupported = 'ontouchstart' in window && !browser.ie && !browser.edge;
  72. env.pointerEventsSupported = 'onpointerdown' in window
  73. && (browser.edge || (browser.ie && +browser.version >= 11));
  74. env.domSupported = typeof document !== 'undefined';
  75. var style = document.documentElement.style;
  76. env.transform3dSupported = ((browser.ie && 'transition' in style)
  77. || browser.edge
  78. || (('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()))
  79. || 'MozPerspective' in style)
  80. && !('OTransition' in style);
  81. env.transformSupported = env.transform3dSupported
  82. || (browser.ie && +browser.version >= 9);
  83. }
  84. var DEFAULT_FONT_SIZE = 12;
  85. var DEFAULT_FONT_FAMILY = 'sans-serif';
  86. var DEFAULT_FONT = DEFAULT_FONT_SIZE + "px " + DEFAULT_FONT_FAMILY;
  87. var OFFSET = 20;
  88. var SCALE = 100;
  89. var defaultWidthMapStr = "007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N";
  90. function getTextWidthMap(mapStr) {
  91. var map = {};
  92. if (typeof JSON === 'undefined') {
  93. return map;
  94. }
  95. for (var i = 0; i < mapStr.length; i++) {
  96. var char = String.fromCharCode(i + 32);
  97. var size = (mapStr.charCodeAt(i) - OFFSET) / SCALE;
  98. map[char] = size;
  99. }
  100. return map;
  101. }
  102. var DEFAULT_TEXT_WIDTH_MAP = getTextWidthMap(defaultWidthMapStr);
  103. var platformApi = {
  104. createCanvas: function () {
  105. return typeof document !== 'undefined'
  106. && document.createElement('canvas');
  107. },
  108. measureText: (function () {
  109. var _ctx;
  110. var _cachedFont;
  111. return function (text, font) {
  112. if (!_ctx) {
  113. var canvas = platformApi.createCanvas();
  114. _ctx = canvas && canvas.getContext('2d');
  115. }
  116. if (_ctx) {
  117. if (_cachedFont !== font) {
  118. _cachedFont = _ctx.font = font || DEFAULT_FONT;
  119. }
  120. return _ctx.measureText(text);
  121. }
  122. else {
  123. text = text || '';
  124. font = font || DEFAULT_FONT;
  125. var res = /^([0-9]*?)px$/.exec(font);
  126. var fontSize = +(res && res[1]) || DEFAULT_FONT_SIZE;
  127. var width = 0;
  128. if (font.indexOf('mono') >= 0) {
  129. width = fontSize * text.length;
  130. }
  131. else {
  132. for (var i = 0; i < text.length; i++) {
  133. var preCalcWidth = DEFAULT_TEXT_WIDTH_MAP[text[i]];
  134. width += preCalcWidth == null ? fontSize : (preCalcWidth * fontSize);
  135. }
  136. }
  137. return { width: width };
  138. }
  139. };
  140. })(),
  141. loadImage: function (src, onload, onerror) {
  142. var image = new Image();
  143. image.onload = onload;
  144. image.onerror = onerror;
  145. image.src = src;
  146. return image;
  147. }
  148. };
  149. function setPlatformAPI(newPlatformApis) {
  150. for (var key in platformApi) {
  151. if (newPlatformApis[key]) {
  152. platformApi[key] = newPlatformApis[key];
  153. }
  154. }
  155. }
  156. var BUILTIN_OBJECT = reduce([
  157. 'Function',
  158. 'RegExp',
  159. 'Date',
  160. 'Error',
  161. 'CanvasGradient',
  162. 'CanvasPattern',
  163. 'Image',
  164. 'Canvas'
  165. ], function (obj, val) {
  166. obj['[object ' + val + ']'] = true;
  167. return obj;
  168. }, {});
  169. var TYPED_ARRAY = reduce([
  170. 'Int8',
  171. 'Uint8',
  172. 'Uint8Clamped',
  173. 'Int16',
  174. 'Uint16',
  175. 'Int32',
  176. 'Uint32',
  177. 'Float32',
  178. 'Float64'
  179. ], function (obj, val) {
  180. obj['[object ' + val + 'Array]'] = true;
  181. return obj;
  182. }, {});
  183. var objToString = Object.prototype.toString;
  184. var arrayProto = Array.prototype;
  185. var nativeForEach = arrayProto.forEach;
  186. var nativeFilter = arrayProto.filter;
  187. var nativeSlice = arrayProto.slice;
  188. var nativeMap = arrayProto.map;
  189. var ctorFunction = function () { }.constructor;
  190. var protoFunction = ctorFunction ? ctorFunction.prototype : null;
  191. var protoKey = '__proto__';
  192. var idStart = 0x0907;
  193. function guid() {
  194. return idStart++;
  195. }
  196. function logError() {
  197. var args = [];
  198. for (var _i = 0; _i < arguments.length; _i++) {
  199. args[_i] = arguments[_i];
  200. }
  201. if (typeof console !== 'undefined') {
  202. console.error.apply(console, args);
  203. }
  204. }
  205. function clone(source) {
  206. if (source == null || typeof source !== 'object') {
  207. return source;
  208. }
  209. var result = source;
  210. var typeStr = objToString.call(source);
  211. if (typeStr === '[object Array]') {
  212. if (!isPrimitive(source)) {
  213. result = [];
  214. for (var i = 0, len = source.length; i < len; i++) {
  215. result[i] = clone(source[i]);
  216. }
  217. }
  218. }
  219. else if (TYPED_ARRAY[typeStr]) {
  220. if (!isPrimitive(source)) {
  221. var Ctor = source.constructor;
  222. if (Ctor.from) {
  223. result = Ctor.from(source);
  224. }
  225. else {
  226. result = new Ctor(source.length);
  227. for (var i = 0, len = source.length; i < len; i++) {
  228. result[i] = source[i];
  229. }
  230. }
  231. }
  232. }
  233. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  234. result = {};
  235. for (var key in source) {
  236. if (source.hasOwnProperty(key) && key !== protoKey) {
  237. result[key] = clone(source[key]);
  238. }
  239. }
  240. }
  241. return result;
  242. }
  243. function merge(target, source, overwrite) {
  244. if (!isObject(source) || !isObject(target)) {
  245. return overwrite ? clone(source) : target;
  246. }
  247. for (var key in source) {
  248. if (source.hasOwnProperty(key) && key !== protoKey) {
  249. var targetProp = target[key];
  250. var sourceProp = source[key];
  251. if (isObject(sourceProp)
  252. && isObject(targetProp)
  253. && !isArray(sourceProp)
  254. && !isArray(targetProp)
  255. && !isDom(sourceProp)
  256. && !isDom(targetProp)
  257. && !isBuiltInObject(sourceProp)
  258. && !isBuiltInObject(targetProp)
  259. && !isPrimitive(sourceProp)
  260. && !isPrimitive(targetProp)) {
  261. merge(targetProp, sourceProp, overwrite);
  262. }
  263. else if (overwrite || !(key in target)) {
  264. target[key] = clone(source[key]);
  265. }
  266. }
  267. }
  268. return target;
  269. }
  270. function mergeAll(targetAndSources, overwrite) {
  271. var result = targetAndSources[0];
  272. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  273. result = merge(result, targetAndSources[i], overwrite);
  274. }
  275. return result;
  276. }
  277. function extend(target, source) {
  278. if (Object.assign) {
  279. Object.assign(target, source);
  280. }
  281. else {
  282. for (var key in source) {
  283. if (source.hasOwnProperty(key) && key !== protoKey) {
  284. target[key] = source[key];
  285. }
  286. }
  287. }
  288. return target;
  289. }
  290. function defaults(target, source, overlay) {
  291. var keysArr = keys(source);
  292. for (var i = 0; i < keysArr.length; i++) {
  293. var key = keysArr[i];
  294. if ((overlay ? source[key] != null : target[key] == null)) {
  295. target[key] = source[key];
  296. }
  297. }
  298. return target;
  299. }
  300. var createCanvas = platformApi.createCanvas;
  301. function indexOf(array, value) {
  302. if (array) {
  303. if (array.indexOf) {
  304. return array.indexOf(value);
  305. }
  306. for (var i = 0, len = array.length; i < len; i++) {
  307. if (array[i] === value) {
  308. return i;
  309. }
  310. }
  311. }
  312. return -1;
  313. }
  314. function inherits(clazz, baseClazz) {
  315. var clazzPrototype = clazz.prototype;
  316. function F() { }
  317. F.prototype = baseClazz.prototype;
  318. clazz.prototype = new F();
  319. for (var prop in clazzPrototype) {
  320. if (clazzPrototype.hasOwnProperty(prop)) {
  321. clazz.prototype[prop] = clazzPrototype[prop];
  322. }
  323. }
  324. clazz.prototype.constructor = clazz;
  325. clazz.superClass = baseClazz;
  326. }
  327. function mixin(target, source, override) {
  328. target = 'prototype' in target ? target.prototype : target;
  329. source = 'prototype' in source ? source.prototype : source;
  330. if (Object.getOwnPropertyNames) {
  331. var keyList = Object.getOwnPropertyNames(source);
  332. for (var i = 0; i < keyList.length; i++) {
  333. var key = keyList[i];
  334. if (key !== 'constructor') {
  335. if ((override ? source[key] != null : target[key] == null)) {
  336. target[key] = source[key];
  337. }
  338. }
  339. }
  340. }
  341. else {
  342. defaults(target, source, override);
  343. }
  344. }
  345. function isArrayLike(data) {
  346. if (!data) {
  347. return false;
  348. }
  349. if (typeof data === 'string') {
  350. return false;
  351. }
  352. return typeof data.length === 'number';
  353. }
  354. function each(arr, cb, context) {
  355. if (!(arr && cb)) {
  356. return;
  357. }
  358. if (arr.forEach && arr.forEach === nativeForEach) {
  359. arr.forEach(cb, context);
  360. }
  361. else if (arr.length === +arr.length) {
  362. for (var i = 0, len = arr.length; i < len; i++) {
  363. cb.call(context, arr[i], i, arr);
  364. }
  365. }
  366. else {
  367. for (var key in arr) {
  368. if (arr.hasOwnProperty(key)) {
  369. cb.call(context, arr[key], key, arr);
  370. }
  371. }
  372. }
  373. }
  374. function map(arr, cb, context) {
  375. if (!arr) {
  376. return [];
  377. }
  378. if (!cb) {
  379. return slice(arr);
  380. }
  381. if (arr.map && arr.map === nativeMap) {
  382. return arr.map(cb, context);
  383. }
  384. else {
  385. var result = [];
  386. for (var i = 0, len = arr.length; i < len; i++) {
  387. result.push(cb.call(context, arr[i], i, arr));
  388. }
  389. return result;
  390. }
  391. }
  392. function reduce(arr, cb, memo, context) {
  393. if (!(arr && cb)) {
  394. return;
  395. }
  396. for (var i = 0, len = arr.length; i < len; i++) {
  397. memo = cb.call(context, memo, arr[i], i, arr);
  398. }
  399. return memo;
  400. }
  401. function filter(arr, cb, context) {
  402. if (!arr) {
  403. return [];
  404. }
  405. if (!cb) {
  406. return slice(arr);
  407. }
  408. if (arr.filter && arr.filter === nativeFilter) {
  409. return arr.filter(cb, context);
  410. }
  411. else {
  412. var result = [];
  413. for (var i = 0, len = arr.length; i < len; i++) {
  414. if (cb.call(context, arr[i], i, arr)) {
  415. result.push(arr[i]);
  416. }
  417. }
  418. return result;
  419. }
  420. }
  421. function find(arr, cb, context) {
  422. if (!(arr && cb)) {
  423. return;
  424. }
  425. for (var i = 0, len = arr.length; i < len; i++) {
  426. if (cb.call(context, arr[i], i, arr)) {
  427. return arr[i];
  428. }
  429. }
  430. }
  431. function keys(obj) {
  432. if (!obj) {
  433. return [];
  434. }
  435. if (Object.keys) {
  436. return Object.keys(obj);
  437. }
  438. var keyList = [];
  439. for (var key in obj) {
  440. if (obj.hasOwnProperty(key)) {
  441. keyList.push(key);
  442. }
  443. }
  444. return keyList;
  445. }
  446. function bindPolyfill(func, context) {
  447. var args = [];
  448. for (var _i = 2; _i < arguments.length; _i++) {
  449. args[_i - 2] = arguments[_i];
  450. }
  451. return function () {
  452. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  453. };
  454. }
  455. var bind = (protoFunction && isFunction(protoFunction.bind))
  456. ? protoFunction.call.bind(protoFunction.bind)
  457. : bindPolyfill;
  458. function curry(func) {
  459. var args = [];
  460. for (var _i = 1; _i < arguments.length; _i++) {
  461. args[_i - 1] = arguments[_i];
  462. }
  463. return function () {
  464. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  465. };
  466. }
  467. function isArray(value) {
  468. if (Array.isArray) {
  469. return Array.isArray(value);
  470. }
  471. return objToString.call(value) === '[object Array]';
  472. }
  473. function isFunction(value) {
  474. return typeof value === 'function';
  475. }
  476. function isString(value) {
  477. return typeof value === 'string';
  478. }
  479. function isStringSafe(value) {
  480. return objToString.call(value) === '[object String]';
  481. }
  482. function isNumber(value) {
  483. return typeof value === 'number';
  484. }
  485. function isObject(value) {
  486. var type = typeof value;
  487. return type === 'function' || (!!value && type === 'object');
  488. }
  489. function isBuiltInObject(value) {
  490. return !!BUILTIN_OBJECT[objToString.call(value)];
  491. }
  492. function isTypedArray(value) {
  493. return !!TYPED_ARRAY[objToString.call(value)];
  494. }
  495. function isDom(value) {
  496. return typeof value === 'object'
  497. && typeof value.nodeType === 'number'
  498. && typeof value.ownerDocument === 'object';
  499. }
  500. function isGradientObject(value) {
  501. return value.colorStops != null;
  502. }
  503. function isImagePatternObject(value) {
  504. return value.image != null;
  505. }
  506. function isRegExp(value) {
  507. return objToString.call(value) === '[object RegExp]';
  508. }
  509. function eqNaN(value) {
  510. return value !== value;
  511. }
  512. function retrieve() {
  513. var args = [];
  514. for (var _i = 0; _i < arguments.length; _i++) {
  515. args[_i] = arguments[_i];
  516. }
  517. for (var i = 0, len = args.length; i < len; i++) {
  518. if (args[i] != null) {
  519. return args[i];
  520. }
  521. }
  522. }
  523. function retrieve2(value0, value1) {
  524. return value0 != null
  525. ? value0
  526. : value1;
  527. }
  528. function retrieve3(value0, value1, value2) {
  529. return value0 != null
  530. ? value0
  531. : value1 != null
  532. ? value1
  533. : value2;
  534. }
  535. function slice(arr) {
  536. var args = [];
  537. for (var _i = 1; _i < arguments.length; _i++) {
  538. args[_i - 1] = arguments[_i];
  539. }
  540. return nativeSlice.apply(arr, args);
  541. }
  542. function normalizeCssArray(val) {
  543. if (typeof (val) === 'number') {
  544. return [val, val, val, val];
  545. }
  546. var len = val.length;
  547. if (len === 2) {
  548. return [val[0], val[1], val[0], val[1]];
  549. }
  550. else if (len === 3) {
  551. return [val[0], val[1], val[2], val[1]];
  552. }
  553. return val;
  554. }
  555. function assert(condition, message) {
  556. if (!condition) {
  557. throw new Error(message);
  558. }
  559. }
  560. function trim(str) {
  561. if (str == null) {
  562. return null;
  563. }
  564. else if (typeof str.trim === 'function') {
  565. return str.trim();
  566. }
  567. else {
  568. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  569. }
  570. }
  571. var primitiveKey = '__ec_primitive__';
  572. function setAsPrimitive(obj) {
  573. obj[primitiveKey] = true;
  574. }
  575. function isPrimitive(obj) {
  576. return obj[primitiveKey];
  577. }
  578. var HashMap = (function () {
  579. function HashMap(obj) {
  580. this.data = {};
  581. var isArr = isArray(obj);
  582. this.data = {};
  583. var thisMap = this;
  584. (obj instanceof HashMap)
  585. ? obj.each(visit)
  586. : (obj && each(obj, visit));
  587. function visit(value, key) {
  588. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  589. }
  590. }
  591. HashMap.prototype.get = function (key) {
  592. return this.data.hasOwnProperty(key) ? this.data[key] : null;
  593. };
  594. HashMap.prototype.set = function (key, value) {
  595. return (this.data[key] = value);
  596. };
  597. HashMap.prototype.each = function (cb, context) {
  598. for (var key in this.data) {
  599. if (this.data.hasOwnProperty(key)) {
  600. cb.call(context, this.data[key], key);
  601. }
  602. }
  603. };
  604. HashMap.prototype.keys = function () {
  605. return keys(this.data);
  606. };
  607. HashMap.prototype.removeKey = function (key) {
  608. delete this.data[key];
  609. };
  610. return HashMap;
  611. }());
  612. function createHashMap(obj) {
  613. return new HashMap(obj);
  614. }
  615. function concatArray(a, b) {
  616. var newArray = new a.constructor(a.length + b.length);
  617. for (var i = 0; i < a.length; i++) {
  618. newArray[i] = a[i];
  619. }
  620. var offset = a.length;
  621. for (var i = 0; i < b.length; i++) {
  622. newArray[i + offset] = b[i];
  623. }
  624. return newArray;
  625. }
  626. function createObject(proto, properties) {
  627. var obj;
  628. if (Object.create) {
  629. obj = Object.create(proto);
  630. }
  631. else {
  632. var StyleCtor = function () { };
  633. StyleCtor.prototype = proto;
  634. obj = new StyleCtor();
  635. }
  636. if (properties) {
  637. extend(obj, properties);
  638. }
  639. return obj;
  640. }
  641. function disableUserSelect(dom) {
  642. var domStyle = dom.style;
  643. domStyle.webkitUserSelect = 'none';
  644. domStyle.userSelect = 'none';
  645. domStyle.webkitTapHighlightColor = 'rgba(0,0,0,0)';
  646. domStyle['-webkit-touch-callout'] = 'none';
  647. }
  648. function hasOwn(own, prop) {
  649. return own.hasOwnProperty(prop);
  650. }
  651. function noop() { }
  652. var RADIAN_TO_DEGREE = 180 / Math.PI;
  653. var util = /*#__PURE__*/Object.freeze({
  654. __proto__: null,
  655. guid: guid,
  656. logError: logError,
  657. clone: clone,
  658. merge: merge,
  659. mergeAll: mergeAll,
  660. extend: extend,
  661. defaults: defaults,
  662. createCanvas: createCanvas,
  663. indexOf: indexOf,
  664. inherits: inherits,
  665. mixin: mixin,
  666. isArrayLike: isArrayLike,
  667. each: each,
  668. map: map,
  669. reduce: reduce,
  670. filter: filter,
  671. find: find,
  672. keys: keys,
  673. bind: bind,
  674. curry: curry,
  675. isArray: isArray,
  676. isFunction: isFunction,
  677. isString: isString,
  678. isStringSafe: isStringSafe,
  679. isNumber: isNumber,
  680. isObject: isObject,
  681. isBuiltInObject: isBuiltInObject,
  682. isTypedArray: isTypedArray,
  683. isDom: isDom,
  684. isGradientObject: isGradientObject,
  685. isImagePatternObject: isImagePatternObject,
  686. isRegExp: isRegExp,
  687. eqNaN: eqNaN,
  688. retrieve: retrieve,
  689. retrieve2: retrieve2,
  690. retrieve3: retrieve3,
  691. slice: slice,
  692. normalizeCssArray: normalizeCssArray,
  693. assert: assert,
  694. trim: trim,
  695. setAsPrimitive: setAsPrimitive,
  696. isPrimitive: isPrimitive,
  697. HashMap: HashMap,
  698. createHashMap: createHashMap,
  699. concatArray: concatArray,
  700. createObject: createObject,
  701. disableUserSelect: disableUserSelect,
  702. hasOwn: hasOwn,
  703. noop: noop,
  704. RADIAN_TO_DEGREE: RADIAN_TO_DEGREE
  705. });
  706. /*! *****************************************************************************
  707. Copyright (c) Microsoft Corporation. All rights reserved.
  708. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  709. this file except in compliance with the License. You may obtain a copy of the
  710. License at http://www.apache.org/licenses/LICENSE-2.0
  711. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  712. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  713. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  714. MERCHANTABLITY OR NON-INFRINGEMENT.
  715. See the Apache Version 2.0 License for specific language governing permissions
  716. and limitations under the License.
  717. ***************************************************************************** */
  718. /* global Reflect, Promise */
  719. var extendStatics = function(d, b) {
  720. extendStatics = Object.setPrototypeOf ||
  721. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  722. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  723. return extendStatics(d, b);
  724. };
  725. function __extends(d, b) {
  726. extendStatics(d, b);
  727. function __() { this.constructor = d; }
  728. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  729. }
  730. function create(x, y) {
  731. if (x == null) {
  732. x = 0;
  733. }
  734. if (y == null) {
  735. y = 0;
  736. }
  737. return [x, y];
  738. }
  739. function copy(out, v) {
  740. out[0] = v[0];
  741. out[1] = v[1];
  742. return out;
  743. }
  744. function clone$1(v) {
  745. return [v[0], v[1]];
  746. }
  747. function set(out, a, b) {
  748. out[0] = a;
  749. out[1] = b;
  750. return out;
  751. }
  752. function add(out, v1, v2) {
  753. out[0] = v1[0] + v2[0];
  754. out[1] = v1[1] + v2[1];
  755. return out;
  756. }
  757. function scaleAndAdd(out, v1, v2, a) {
  758. out[0] = v1[0] + v2[0] * a;
  759. out[1] = v1[1] + v2[1] * a;
  760. return out;
  761. }
  762. function sub(out, v1, v2) {
  763. out[0] = v1[0] - v2[0];
  764. out[1] = v1[1] - v2[1];
  765. return out;
  766. }
  767. function len(v) {
  768. return Math.sqrt(lenSquare(v));
  769. }
  770. var length = len;
  771. function lenSquare(v) {
  772. return v[0] * v[0] + v[1] * v[1];
  773. }
  774. var lengthSquare = lenSquare;
  775. function mul(out, v1, v2) {
  776. out[0] = v1[0] * v2[0];
  777. out[1] = v1[1] * v2[1];
  778. return out;
  779. }
  780. function div(out, v1, v2) {
  781. out[0] = v1[0] / v2[0];
  782. out[1] = v1[1] / v2[1];
  783. return out;
  784. }
  785. function dot(v1, v2) {
  786. return v1[0] * v2[0] + v1[1] * v2[1];
  787. }
  788. function scale(out, v, s) {
  789. out[0] = v[0] * s;
  790. out[1] = v[1] * s;
  791. return out;
  792. }
  793. function normalize(out, v) {
  794. var d = len(v);
  795. if (d === 0) {
  796. out[0] = 0;
  797. out[1] = 0;
  798. }
  799. else {
  800. out[0] = v[0] / d;
  801. out[1] = v[1] / d;
  802. }
  803. return out;
  804. }
  805. function distance(v1, v2) {
  806. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0])
  807. + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  808. }
  809. var dist = distance;
  810. function distanceSquare(v1, v2) {
  811. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  812. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  813. }
  814. var distSquare = distanceSquare;
  815. function negate(out, v) {
  816. out[0] = -v[0];
  817. out[1] = -v[1];
  818. return out;
  819. }
  820. function lerp(out, v1, v2, t) {
  821. out[0] = v1[0] + t * (v2[0] - v1[0]);
  822. out[1] = v1[1] + t * (v2[1] - v1[1]);
  823. return out;
  824. }
  825. function applyTransform(out, v, m) {
  826. var x = v[0];
  827. var y = v[1];
  828. out[0] = m[0] * x + m[2] * y + m[4];
  829. out[1] = m[1] * x + m[3] * y + m[5];
  830. return out;
  831. }
  832. function min(out, v1, v2) {
  833. out[0] = Math.min(v1[0], v2[0]);
  834. out[1] = Math.min(v1[1], v2[1]);
  835. return out;
  836. }
  837. function max(out, v1, v2) {
  838. out[0] = Math.max(v1[0], v2[0]);
  839. out[1] = Math.max(v1[1], v2[1]);
  840. return out;
  841. }
  842. var vector = /*#__PURE__*/Object.freeze({
  843. __proto__: null,
  844. create: create,
  845. copy: copy,
  846. clone: clone$1,
  847. set: set,
  848. add: add,
  849. scaleAndAdd: scaleAndAdd,
  850. sub: sub,
  851. len: len,
  852. length: length,
  853. lenSquare: lenSquare,
  854. lengthSquare: lengthSquare,
  855. mul: mul,
  856. div: div,
  857. dot: dot,
  858. scale: scale,
  859. normalize: normalize,
  860. distance: distance,
  861. dist: dist,
  862. distanceSquare: distanceSquare,
  863. distSquare: distSquare,
  864. negate: negate,
  865. lerp: lerp,
  866. applyTransform: applyTransform,
  867. min: min,
  868. max: max
  869. });
  870. var Param = (function () {
  871. function Param(target, e) {
  872. this.target = target;
  873. this.topTarget = e && e.topTarget;
  874. }
  875. return Param;
  876. }());
  877. var Draggable = (function () {
  878. function Draggable(handler) {
  879. this.handler = handler;
  880. handler.on('mousedown', this._dragStart, this);
  881. handler.on('mousemove', this._drag, this);
  882. handler.on('mouseup', this._dragEnd, this);
  883. }
  884. Draggable.prototype._dragStart = function (e) {
  885. var draggingTarget = e.target;
  886. while (draggingTarget && !draggingTarget.draggable) {
  887. draggingTarget = draggingTarget.parent || draggingTarget.__hostTarget;
  888. }
  889. if (draggingTarget) {
  890. this._draggingTarget = draggingTarget;
  891. draggingTarget.dragging = true;
  892. this._x = e.offsetX;
  893. this._y = e.offsetY;
  894. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragstart', e.event);
  895. }
  896. };
  897. Draggable.prototype._drag = function (e) {
  898. var draggingTarget = this._draggingTarget;
  899. if (draggingTarget) {
  900. var x = e.offsetX;
  901. var y = e.offsetY;
  902. var dx = x - this._x;
  903. var dy = y - this._y;
  904. this._x = x;
  905. this._y = y;
  906. draggingTarget.drift(dx, dy, e);
  907. this.handler.dispatchToElement(new Param(draggingTarget, e), 'drag', e.event);
  908. var dropTarget = this.handler.findHover(x, y, draggingTarget).target;
  909. var lastDropTarget = this._dropTarget;
  910. this._dropTarget = dropTarget;
  911. if (draggingTarget !== dropTarget) {
  912. if (lastDropTarget && dropTarget !== lastDropTarget) {
  913. this.handler.dispatchToElement(new Param(lastDropTarget, e), 'dragleave', e.event);
  914. }
  915. if (dropTarget && dropTarget !== lastDropTarget) {
  916. this.handler.dispatchToElement(new Param(dropTarget, e), 'dragenter', e.event);
  917. }
  918. }
  919. }
  920. };
  921. Draggable.prototype._dragEnd = function (e) {
  922. var draggingTarget = this._draggingTarget;
  923. if (draggingTarget) {
  924. draggingTarget.dragging = false;
  925. }
  926. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragend', e.event);
  927. if (this._dropTarget) {
  928. this.handler.dispatchToElement(new Param(this._dropTarget, e), 'drop', e.event);
  929. }
  930. this._draggingTarget = null;
  931. this._dropTarget = null;
  932. };
  933. return Draggable;
  934. }());
  935. var Eventful = (function () {
  936. function Eventful(eventProcessors) {
  937. if (eventProcessors) {
  938. this._$eventProcessor = eventProcessors;
  939. }
  940. }
  941. Eventful.prototype.on = function (event, query, handler, context) {
  942. if (!this._$handlers) {
  943. this._$handlers = {};
  944. }
  945. var _h = this._$handlers;
  946. if (typeof query === 'function') {
  947. context = handler;
  948. handler = query;
  949. query = null;
  950. }
  951. if (!handler || !event) {
  952. return this;
  953. }
  954. var eventProcessor = this._$eventProcessor;
  955. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  956. query = eventProcessor.normalizeQuery(query);
  957. }
  958. if (!_h[event]) {
  959. _h[event] = [];
  960. }
  961. for (var i = 0; i < _h[event].length; i++) {
  962. if (_h[event][i].h === handler) {
  963. return this;
  964. }
  965. }
  966. var wrap = {
  967. h: handler,
  968. query: query,
  969. ctx: (context || this),
  970. callAtLast: handler.zrEventfulCallAtLast
  971. };
  972. var lastIndex = _h[event].length - 1;
  973. var lastWrap = _h[event][lastIndex];
  974. (lastWrap && lastWrap.callAtLast)
  975. ? _h[event].splice(lastIndex, 0, wrap)
  976. : _h[event].push(wrap);
  977. return this;
  978. };
  979. Eventful.prototype.isSilent = function (eventName) {
  980. var _h = this._$handlers;
  981. return !_h || !_h[eventName] || !_h[eventName].length;
  982. };
  983. Eventful.prototype.off = function (eventType, handler) {
  984. var _h = this._$handlers;
  985. if (!_h) {
  986. return this;
  987. }
  988. if (!eventType) {
  989. this._$handlers = {};
  990. return this;
  991. }
  992. if (handler) {
  993. if (_h[eventType]) {
  994. var newList = [];
  995. for (var i = 0, l = _h[eventType].length; i < l; i++) {
  996. if (_h[eventType][i].h !== handler) {
  997. newList.push(_h[eventType][i]);
  998. }
  999. }
  1000. _h[eventType] = newList;
  1001. }
  1002. if (_h[eventType] && _h[eventType].length === 0) {
  1003. delete _h[eventType];
  1004. }
  1005. }
  1006. else {
  1007. delete _h[eventType];
  1008. }
  1009. return this;
  1010. };
  1011. Eventful.prototype.trigger = function (eventType) {
  1012. var args = [];
  1013. for (var _i = 1; _i < arguments.length; _i++) {
  1014. args[_i - 1] = arguments[_i];
  1015. }
  1016. if (!this._$handlers) {
  1017. return this;
  1018. }
  1019. var _h = this._$handlers[eventType];
  1020. var eventProcessor = this._$eventProcessor;
  1021. if (_h) {
  1022. var argLen = args.length;
  1023. var len = _h.length;
  1024. for (var i = 0; i < len; i++) {
  1025. var hItem = _h[i];
  1026. if (eventProcessor
  1027. && eventProcessor.filter
  1028. && hItem.query != null
  1029. && !eventProcessor.filter(eventType, hItem.query)) {
  1030. continue;
  1031. }
  1032. switch (argLen) {
  1033. case 0:
  1034. hItem.h.call(hItem.ctx);
  1035. break;
  1036. case 1:
  1037. hItem.h.call(hItem.ctx, args[0]);
  1038. break;
  1039. case 2:
  1040. hItem.h.call(hItem.ctx, args[0], args[1]);
  1041. break;
  1042. default:
  1043. hItem.h.apply(hItem.ctx, args);
  1044. break;
  1045. }
  1046. }
  1047. }
  1048. eventProcessor && eventProcessor.afterTrigger
  1049. && eventProcessor.afterTrigger(eventType);
  1050. return this;
  1051. };
  1052. Eventful.prototype.triggerWithContext = function (type) {
  1053. var args = [];
  1054. for (var _i = 1; _i < arguments.length; _i++) {
  1055. args[_i - 1] = arguments[_i];
  1056. }
  1057. if (!this._$handlers) {
  1058. return this;
  1059. }
  1060. var _h = this._$handlers[type];
  1061. var eventProcessor = this._$eventProcessor;
  1062. if (_h) {
  1063. var argLen = args.length;
  1064. var ctx = args[argLen - 1];
  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(type, hItem.query)) {
  1072. continue;
  1073. }
  1074. switch (argLen) {
  1075. case 0:
  1076. hItem.h.call(ctx);
  1077. break;
  1078. case 1:
  1079. hItem.h.call(ctx, args[0]);
  1080. break;
  1081. case 2:
  1082. hItem.h.call(ctx, args[0], args[1]);
  1083. break;
  1084. default:
  1085. hItem.h.apply(ctx, args.slice(1, argLen - 1));
  1086. break;
  1087. }
  1088. }
  1089. }
  1090. eventProcessor && eventProcessor.afterTrigger
  1091. && eventProcessor.afterTrigger(type);
  1092. return this;
  1093. };
  1094. return Eventful;
  1095. }());
  1096. var LN2 = Math.log(2);
  1097. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1098. var cacheKey = rowMask + '-' + colMask;
  1099. var fullRank = rows.length;
  1100. if (detCache.hasOwnProperty(cacheKey)) {
  1101. return detCache[cacheKey];
  1102. }
  1103. if (rank === 1) {
  1104. var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);
  1105. return rows[rowStart][colStart];
  1106. }
  1107. var subRowMask = rowMask | (1 << rowStart);
  1108. var subRowStart = rowStart + 1;
  1109. while (rowMask & (1 << subRowStart)) {
  1110. subRowStart++;
  1111. }
  1112. var sum = 0;
  1113. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1114. var colTag = 1 << j;
  1115. if (!(colTag & colMask)) {
  1116. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]
  1117. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1118. colLocalIdx++;
  1119. }
  1120. }
  1121. detCache[cacheKey] = sum;
  1122. return sum;
  1123. }
  1124. function buildTransformer(src, dest) {
  1125. var mA = [
  1126. [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],
  1127. [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],
  1128. [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],
  1129. [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],
  1130. [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],
  1131. [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],
  1132. [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],
  1133. [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]
  1134. ];
  1135. var detCache = {};
  1136. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1137. if (det === 0) {
  1138. return;
  1139. }
  1140. var vh = [];
  1141. for (var i = 0; i < 8; i++) {
  1142. for (var j = 0; j < 8; j++) {
  1143. vh[j] == null && (vh[j] = 0);
  1144. vh[j] += ((i + j) % 2 ? -1 : 1)
  1145. * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)
  1146. / det * dest[i];
  1147. }
  1148. }
  1149. return function (out, srcPointX, srcPointY) {
  1150. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1151. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1152. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1153. };
  1154. }
  1155. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1156. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1157. if (el.getBoundingClientRect && env.domSupported && !isCanvasEl(el)) {
  1158. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1159. var markers = prepareCoordMarkers(el, saved);
  1160. var transformer = preparePointerTransformer(markers, saved, inverse);
  1161. if (transformer) {
  1162. transformer(out, inX, inY);
  1163. return true;
  1164. }
  1165. }
  1166. return false;
  1167. }
  1168. function prepareCoordMarkers(el, saved) {
  1169. var markers = saved.markers;
  1170. if (markers) {
  1171. return markers;
  1172. }
  1173. markers = saved.markers = [];
  1174. var propLR = ['left', 'right'];
  1175. var propTB = ['top', 'bottom'];
  1176. for (var i = 0; i < 4; i++) {
  1177. var marker = document.createElement('div');
  1178. var stl = marker.style;
  1179. var idxLR = i % 2;
  1180. var idxTB = (i >> 1) % 2;
  1181. stl.cssText = [
  1182. 'position: absolute',
  1183. 'visibility: hidden',
  1184. 'padding: 0',
  1185. 'margin: 0',
  1186. 'border-width: 0',
  1187. 'user-select: none',
  1188. 'width:0',
  1189. 'height:0',
  1190. propLR[idxLR] + ':0',
  1191. propTB[idxTB] + ':0',
  1192. propLR[1 - idxLR] + ':auto',
  1193. propTB[1 - idxTB] + ':auto',
  1194. ''
  1195. ].join('!important;');
  1196. el.appendChild(marker);
  1197. markers.push(marker);
  1198. }
  1199. return markers;
  1200. }
  1201. function preparePointerTransformer(markers, saved, inverse) {
  1202. var transformerName = inverse ? 'invTrans' : 'trans';
  1203. var transformer = saved[transformerName];
  1204. var oldSrcCoords = saved.srcCoords;
  1205. var srcCoords = [];
  1206. var destCoords = [];
  1207. var oldCoordTheSame = true;
  1208. for (var i = 0; i < 4; i++) {
  1209. var rect = markers[i].getBoundingClientRect();
  1210. var ii = 2 * i;
  1211. var x = rect.left;
  1212. var y = rect.top;
  1213. srcCoords.push(x, y);
  1214. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1215. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1216. }
  1217. return (oldCoordTheSame && transformer)
  1218. ? transformer
  1219. : (saved.srcCoords = srcCoords,
  1220. saved[transformerName] = inverse
  1221. ? buildTransformer(destCoords, srcCoords)
  1222. : buildTransformer(srcCoords, destCoords));
  1223. }
  1224. function isCanvasEl(el) {
  1225. return el.nodeName.toUpperCase() === 'CANVAS';
  1226. }
  1227. var replaceReg = /([&<>"'])/g;
  1228. var replaceMap = {
  1229. '&': '&amp;',
  1230. '<': '&lt;',
  1231. '>': '&gt;',
  1232. '"': '&quot;',
  1233. '\'': '&#39;'
  1234. };
  1235. function encodeHTML(source) {
  1236. return source == null
  1237. ? ''
  1238. : (source + '').replace(replaceReg, function (str, c) {
  1239. return replaceMap[c];
  1240. });
  1241. }
  1242. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1243. var _calcOut = [];
  1244. var firefoxNotSupportOffsetXY = env.browser.firefox
  1245. && +env.browser.version.split('.')[0] < 39;
  1246. function clientToLocal(el, e, out, calculate) {
  1247. out = out || {};
  1248. if (calculate) {
  1249. calculateZrXY(el, e, out);
  1250. }
  1251. else if (firefoxNotSupportOffsetXY
  1252. && e.layerX != null
  1253. && e.layerX !== e.offsetX) {
  1254. out.zrX = e.layerX;
  1255. out.zrY = e.layerY;
  1256. }
  1257. else if (e.offsetX != null) {
  1258. out.zrX = e.offsetX;
  1259. out.zrY = e.offsetY;
  1260. }
  1261. else {
  1262. calculateZrXY(el, e, out);
  1263. }
  1264. return out;
  1265. }
  1266. function calculateZrXY(el, e, out) {
  1267. if (env.domSupported && el.getBoundingClientRect) {
  1268. var ex = e.clientX;
  1269. var ey = e.clientY;
  1270. if (isCanvasEl(el)) {
  1271. var box = el.getBoundingClientRect();
  1272. out.zrX = ex - box.left;
  1273. out.zrY = ey - box.top;
  1274. return;
  1275. }
  1276. else {
  1277. if (transformCoordWithViewport(_calcOut, el, ex, ey)) {
  1278. out.zrX = _calcOut[0];
  1279. out.zrY = _calcOut[1];
  1280. return;
  1281. }
  1282. }
  1283. }
  1284. out.zrX = out.zrY = 0;
  1285. }
  1286. function getNativeEvent(e) {
  1287. return e
  1288. || window.event;
  1289. }
  1290. function normalizeEvent(el, e, calculate) {
  1291. e = getNativeEvent(e);
  1292. if (e.zrX != null) {
  1293. return e;
  1294. }
  1295. var eventType = e.type;
  1296. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1297. if (!isTouch) {
  1298. clientToLocal(el, e, e, calculate);
  1299. var wheelDelta = getWheelDeltaMayPolyfill(e);
  1300. e.zrDelta = wheelDelta ? wheelDelta / 120 : -(e.detail || 0) / 3;
  1301. }
  1302. else {
  1303. var touch = eventType !== 'touchend'
  1304. ? e.targetTouches[0]
  1305. : e.changedTouches[0];
  1306. touch && clientToLocal(el, touch, e, calculate);
  1307. }
  1308. var button = e.button;
  1309. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1310. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1311. }
  1312. return e;
  1313. }
  1314. function getWheelDeltaMayPolyfill(e) {
  1315. var rawWheelDelta = e.wheelDelta;
  1316. if (rawWheelDelta) {
  1317. return rawWheelDelta;
  1318. }
  1319. var deltaX = e.deltaX;
  1320. var deltaY = e.deltaY;
  1321. if (deltaX == null || deltaY == null) {
  1322. return rawWheelDelta;
  1323. }
  1324. var delta = deltaY !== 0 ? Math.abs(deltaY) : Math.abs(deltaX);
  1325. var sign = deltaY > 0 ? -1
  1326. : deltaY < 0 ? 1
  1327. : deltaX > 0 ? -1
  1328. : 1;
  1329. return 3 * delta * sign;
  1330. }
  1331. function addEventListener(el, name, handler, opt) {
  1332. el.addEventListener(name, handler, opt);
  1333. }
  1334. function removeEventListener(el, name, handler, opt) {
  1335. el.removeEventListener(name, handler, opt);
  1336. }
  1337. var stop = function (e) {
  1338. e.preventDefault();
  1339. e.stopPropagation();
  1340. e.cancelBubble = true;
  1341. };
  1342. var GestureMgr = (function () {
  1343. function GestureMgr() {
  1344. this._track = [];
  1345. }
  1346. GestureMgr.prototype.recognize = function (event, target, root) {
  1347. this._doTrack(event, target, root);
  1348. return this._recognize(event);
  1349. };
  1350. GestureMgr.prototype.clear = function () {
  1351. this._track.length = 0;
  1352. return this;
  1353. };
  1354. GestureMgr.prototype._doTrack = function (event, target, root) {
  1355. var touches = event.touches;
  1356. if (!touches) {
  1357. return;
  1358. }
  1359. var trackItem = {
  1360. points: [],
  1361. touches: [],
  1362. target: target,
  1363. event: event
  1364. };
  1365. for (var i = 0, len = touches.length; i < len; i++) {
  1366. var touch = touches[i];
  1367. var pos = clientToLocal(root, touch, {});
  1368. trackItem.points.push([pos.zrX, pos.zrY]);
  1369. trackItem.touches.push(touch);
  1370. }
  1371. this._track.push(trackItem);
  1372. };
  1373. GestureMgr.prototype._recognize = function (event) {
  1374. for (var eventName in recognizers) {
  1375. if (recognizers.hasOwnProperty(eventName)) {
  1376. var gestureInfo = recognizers[eventName](this._track, event);
  1377. if (gestureInfo) {
  1378. return gestureInfo;
  1379. }
  1380. }
  1381. }
  1382. };
  1383. return GestureMgr;
  1384. }());
  1385. function dist$1(pointPair) {
  1386. var dx = pointPair[1][0] - pointPair[0][0];
  1387. var dy = pointPair[1][1] - pointPair[0][1];
  1388. return Math.sqrt(dx * dx + dy * dy);
  1389. }
  1390. function center(pointPair) {
  1391. return [
  1392. (pointPair[0][0] + pointPair[1][0]) / 2,
  1393. (pointPair[0][1] + pointPair[1][1]) / 2
  1394. ];
  1395. }
  1396. var recognizers = {
  1397. pinch: function (tracks, event) {
  1398. var trackLen = tracks.length;
  1399. if (!trackLen) {
  1400. return;
  1401. }
  1402. var pinchEnd = (tracks[trackLen - 1] || {}).points;
  1403. var pinchPre = (tracks[trackLen - 2] || {}).points || pinchEnd;
  1404. if (pinchPre
  1405. && pinchPre.length > 1
  1406. && pinchEnd
  1407. && pinchEnd.length > 1) {
  1408. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1409. !isFinite(pinchScale) && (pinchScale = 1);
  1410. event.pinchScale = pinchScale;
  1411. var pinchCenter = center(pinchEnd);
  1412. event.pinchX = pinchCenter[0];
  1413. event.pinchY = pinchCenter[1];
  1414. return {
  1415. type: 'pinch',
  1416. target: tracks[0].target,
  1417. event: event
  1418. };
  1419. }
  1420. }
  1421. };
  1422. function create$1() {
  1423. return [1, 0, 0, 1, 0, 0];
  1424. }
  1425. function identity(out) {
  1426. out[0] = 1;
  1427. out[1] = 0;
  1428. out[2] = 0;
  1429. out[3] = 1;
  1430. out[4] = 0;
  1431. out[5] = 0;
  1432. return out;
  1433. }
  1434. function copy$1(out, m) {
  1435. out[0] = m[0];
  1436. out[1] = m[1];
  1437. out[2] = m[2];
  1438. out[3] = m[3];
  1439. out[4] = m[4];
  1440. out[5] = m[5];
  1441. return out;
  1442. }
  1443. function mul$1(out, m1, m2) {
  1444. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  1445. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  1446. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  1447. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  1448. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1449. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1450. out[0] = out0;
  1451. out[1] = out1;
  1452. out[2] = out2;
  1453. out[3] = out3;
  1454. out[4] = out4;
  1455. out[5] = out5;
  1456. return out;
  1457. }
  1458. function translate(out, a, v) {
  1459. out[0] = a[0];
  1460. out[1] = a[1];
  1461. out[2] = a[2];
  1462. out[3] = a[3];
  1463. out[4] = a[4] + v[0];
  1464. out[5] = a[5] + v[1];
  1465. return out;
  1466. }
  1467. function rotate(out, a, rad) {
  1468. var aa = a[0];
  1469. var ac = a[2];
  1470. var atx = a[4];
  1471. var ab = a[1];
  1472. var ad = a[3];
  1473. var aty = a[5];
  1474. var st = Math.sin(rad);
  1475. var ct = Math.cos(rad);
  1476. out[0] = aa * ct + ab * st;
  1477. out[1] = -aa * st + ab * ct;
  1478. out[2] = ac * ct + ad * st;
  1479. out[3] = -ac * st + ct * ad;
  1480. out[4] = ct * atx + st * aty;
  1481. out[5] = ct * aty - st * atx;
  1482. return out;
  1483. }
  1484. function scale$1(out, a, v) {
  1485. var vx = v[0];
  1486. var vy = v[1];
  1487. out[0] = a[0] * vx;
  1488. out[1] = a[1] * vy;
  1489. out[2] = a[2] * vx;
  1490. out[3] = a[3] * vy;
  1491. out[4] = a[4] * vx;
  1492. out[5] = a[5] * vy;
  1493. return out;
  1494. }
  1495. function invert(out, a) {
  1496. var aa = a[0];
  1497. var ac = a[2];
  1498. var atx = a[4];
  1499. var ab = a[1];
  1500. var ad = a[3];
  1501. var aty = a[5];
  1502. var det = aa * ad - ab * ac;
  1503. if (!det) {
  1504. return null;
  1505. }
  1506. det = 1.0 / det;
  1507. out[0] = ad * det;
  1508. out[1] = -ab * det;
  1509. out[2] = -ac * det;
  1510. out[3] = aa * det;
  1511. out[4] = (ac * aty - ad * atx) * det;
  1512. out[5] = (ab * atx - aa * aty) * det;
  1513. return out;
  1514. }
  1515. function clone$2(a) {
  1516. var b = create$1();
  1517. copy$1(b, a);
  1518. return b;
  1519. }
  1520. var matrix = /*#__PURE__*/Object.freeze({
  1521. __proto__: null,
  1522. create: create$1,
  1523. identity: identity,
  1524. copy: copy$1,
  1525. mul: mul$1,
  1526. translate: translate,
  1527. rotate: rotate,
  1528. scale: scale$1,
  1529. invert: invert,
  1530. clone: clone$2
  1531. });
  1532. var Point = (function () {
  1533. function Point(x, y) {
  1534. this.x = x || 0;
  1535. this.y = y || 0;
  1536. }
  1537. Point.prototype.copy = function (other) {
  1538. this.x = other.x;
  1539. this.y = other.y;
  1540. return this;
  1541. };
  1542. Point.prototype.clone = function () {
  1543. return new Point(this.x, this.y);
  1544. };
  1545. Point.prototype.set = function (x, y) {
  1546. this.x = x;
  1547. this.y = y;
  1548. return this;
  1549. };
  1550. Point.prototype.equal = function (other) {
  1551. return other.x === this.x && other.y === this.y;
  1552. };
  1553. Point.prototype.add = function (other) {
  1554. this.x += other.x;
  1555. this.y += other.y;
  1556. return this;
  1557. };
  1558. Point.prototype.scale = function (scalar) {
  1559. this.x *= scalar;
  1560. this.y *= scalar;
  1561. };
  1562. Point.prototype.scaleAndAdd = function (other, scalar) {
  1563. this.x += other.x * scalar;
  1564. this.y += other.y * scalar;
  1565. };
  1566. Point.prototype.sub = function (other) {
  1567. this.x -= other.x;
  1568. this.y -= other.y;
  1569. return this;
  1570. };
  1571. Point.prototype.dot = function (other) {
  1572. return this.x * other.x + this.y * other.y;
  1573. };
  1574. Point.prototype.len = function () {
  1575. return Math.sqrt(this.x * this.x + this.y * this.y);
  1576. };
  1577. Point.prototype.lenSquare = function () {
  1578. return this.x * this.x + this.y * this.y;
  1579. };
  1580. Point.prototype.normalize = function () {
  1581. var len = this.len();
  1582. this.x /= len;
  1583. this.y /= len;
  1584. return this;
  1585. };
  1586. Point.prototype.distance = function (other) {
  1587. var dx = this.x - other.x;
  1588. var dy = this.y - other.y;
  1589. return Math.sqrt(dx * dx + dy * dy);
  1590. };
  1591. Point.prototype.distanceSquare = function (other) {
  1592. var dx = this.x - other.x;
  1593. var dy = this.y - other.y;
  1594. return dx * dx + dy * dy;
  1595. };
  1596. Point.prototype.negate = function () {
  1597. this.x = -this.x;
  1598. this.y = -this.y;
  1599. return this;
  1600. };
  1601. Point.prototype.transform = function (m) {
  1602. if (!m) {
  1603. return;
  1604. }
  1605. var x = this.x;
  1606. var y = this.y;
  1607. this.x = m[0] * x + m[2] * y + m[4];
  1608. this.y = m[1] * x + m[3] * y + m[5];
  1609. return this;
  1610. };
  1611. Point.prototype.toArray = function (out) {
  1612. out[0] = this.x;
  1613. out[1] = this.y;
  1614. return out;
  1615. };
  1616. Point.prototype.fromArray = function (input) {
  1617. this.x = input[0];
  1618. this.y = input[1];
  1619. };
  1620. Point.set = function (p, x, y) {
  1621. p.x = x;
  1622. p.y = y;
  1623. };
  1624. Point.copy = function (p, p2) {
  1625. p.x = p2.x;
  1626. p.y = p2.y;
  1627. };
  1628. Point.len = function (p) {
  1629. return Math.sqrt(p.x * p.x + p.y * p.y);
  1630. };
  1631. Point.lenSquare = function (p) {
  1632. return p.x * p.x + p.y * p.y;
  1633. };
  1634. Point.dot = function (p0, p1) {
  1635. return p0.x * p1.x + p0.y * p1.y;
  1636. };
  1637. Point.add = function (out, p0, p1) {
  1638. out.x = p0.x + p1.x;
  1639. out.y = p0.y + p1.y;
  1640. };
  1641. Point.sub = function (out, p0, p1) {
  1642. out.x = p0.x - p1.x;
  1643. out.y = p0.y - p1.y;
  1644. };
  1645. Point.scale = function (out, p0, scalar) {
  1646. out.x = p0.x * scalar;
  1647. out.y = p0.y * scalar;
  1648. };
  1649. Point.scaleAndAdd = function (out, p0, p1, scalar) {
  1650. out.x = p0.x + p1.x * scalar;
  1651. out.y = p0.y + p1.y * scalar;
  1652. };
  1653. Point.lerp = function (out, p0, p1, t) {
  1654. var onet = 1 - t;
  1655. out.x = onet * p0.x + t * p1.x;
  1656. out.y = onet * p0.y + t * p1.y;
  1657. };
  1658. return Point;
  1659. }());
  1660. var mathMin = Math.min;
  1661. var mathMax = Math.max;
  1662. var lt = new Point();
  1663. var rb = new Point();
  1664. var lb = new Point();
  1665. var rt = new Point();
  1666. var minTv = new Point();
  1667. var maxTv = new Point();
  1668. var BoundingRect = (function () {
  1669. function BoundingRect(x, y, width, height) {
  1670. if (width < 0) {
  1671. x = x + width;
  1672. width = -width;
  1673. }
  1674. if (height < 0) {
  1675. y = y + height;
  1676. height = -height;
  1677. }
  1678. this.x = x;
  1679. this.y = y;
  1680. this.width = width;
  1681. this.height = height;
  1682. }
  1683. BoundingRect.prototype.union = function (other) {
  1684. var x = mathMin(other.x, this.x);
  1685. var y = mathMin(other.y, this.y);
  1686. if (isFinite(this.x) && isFinite(this.width)) {
  1687. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  1688. }
  1689. else {
  1690. this.width = other.width;
  1691. }
  1692. if (isFinite(this.y) && isFinite(this.height)) {
  1693. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  1694. }
  1695. else {
  1696. this.height = other.height;
  1697. }
  1698. this.x = x;
  1699. this.y = y;
  1700. };
  1701. BoundingRect.prototype.applyTransform = function (m) {
  1702. BoundingRect.applyTransform(this, this, m);
  1703. };
  1704. BoundingRect.prototype.calculateTransform = function (b) {
  1705. var a = this;
  1706. var sx = b.width / a.width;
  1707. var sy = b.height / a.height;
  1708. var m = create$1();
  1709. translate(m, m, [-a.x, -a.y]);
  1710. scale$1(m, m, [sx, sy]);
  1711. translate(m, m, [b.x, b.y]);
  1712. return m;
  1713. };
  1714. BoundingRect.prototype.intersect = function (b, mtv) {
  1715. if (!b) {
  1716. return false;
  1717. }
  1718. if (!(b instanceof BoundingRect)) {
  1719. b = BoundingRect.create(b);
  1720. }
  1721. var a = this;
  1722. var ax0 = a.x;
  1723. var ax1 = a.x + a.width;
  1724. var ay0 = a.y;
  1725. var ay1 = a.y + a.height;
  1726. var bx0 = b.x;
  1727. var bx1 = b.x + b.width;
  1728. var by0 = b.y;
  1729. var by1 = b.y + b.height;
  1730. var overlap = !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  1731. if (mtv) {
  1732. var dMin = Infinity;
  1733. var dMax = 0;
  1734. var d0 = Math.abs(ax1 - bx0);
  1735. var d1 = Math.abs(bx1 - ax0);
  1736. var d2 = Math.abs(ay1 - by0);
  1737. var d3 = Math.abs(by1 - ay0);
  1738. var dx = Math.min(d0, d1);
  1739. var dy = Math.min(d2, d3);
  1740. if (ax1 < bx0 || bx1 < ax0) {
  1741. if (dx > dMax) {
  1742. dMax = dx;
  1743. if (d0 < d1) {
  1744. Point.set(maxTv, -d0, 0);
  1745. }
  1746. else {
  1747. Point.set(maxTv, d1, 0);
  1748. }
  1749. }
  1750. }
  1751. else {
  1752. if (dx < dMin) {
  1753. dMin = dx;
  1754. if (d0 < d1) {
  1755. Point.set(minTv, d0, 0);
  1756. }
  1757. else {
  1758. Point.set(minTv, -d1, 0);
  1759. }
  1760. }
  1761. }
  1762. if (ay1 < by0 || by1 < ay0) {
  1763. if (dy > dMax) {
  1764. dMax = dy;
  1765. if (d2 < d3) {
  1766. Point.set(maxTv, 0, -d2);
  1767. }
  1768. else {
  1769. Point.set(maxTv, 0, d3);
  1770. }
  1771. }
  1772. }
  1773. else {
  1774. if (dx < dMin) {
  1775. dMin = dx;
  1776. if (d2 < d3) {
  1777. Point.set(minTv, 0, d2);
  1778. }
  1779. else {
  1780. Point.set(minTv, 0, -d3);
  1781. }
  1782. }
  1783. }
  1784. }
  1785. if (mtv) {
  1786. Point.copy(mtv, overlap ? minTv : maxTv);
  1787. }
  1788. return overlap;
  1789. };
  1790. BoundingRect.prototype.contain = function (x, y) {
  1791. var rect = this;
  1792. return x >= rect.x
  1793. && x <= (rect.x + rect.width)
  1794. && y >= rect.y
  1795. && y <= (rect.y + rect.height);
  1796. };
  1797. BoundingRect.prototype.clone = function () {
  1798. return new BoundingRect(this.x, this.y, this.width, this.height);
  1799. };
  1800. BoundingRect.prototype.copy = function (other) {
  1801. BoundingRect.copy(this, other);
  1802. };
  1803. BoundingRect.prototype.plain = function () {
  1804. return {
  1805. x: this.x,
  1806. y: this.y,
  1807. width: this.width,
  1808. height: this.height
  1809. };
  1810. };
  1811. BoundingRect.prototype.isFinite = function () {
  1812. return isFinite(this.x)
  1813. && isFinite(this.y)
  1814. && isFinite(this.width)
  1815. && isFinite(this.height);
  1816. };
  1817. BoundingRect.prototype.isZero = function () {
  1818. return this.width === 0 || this.height === 0;
  1819. };
  1820. BoundingRect.create = function (rect) {
  1821. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  1822. };
  1823. BoundingRect.copy = function (target, source) {
  1824. target.x = source.x;
  1825. target.y = source.y;
  1826. target.width = source.width;
  1827. target.height = source.height;
  1828. };
  1829. BoundingRect.applyTransform = function (target, source, m) {
  1830. if (!m) {
  1831. if (target !== source) {
  1832. BoundingRect.copy(target, source);
  1833. }
  1834. return;
  1835. }
  1836. if (m[1] < 1e-5 && m[1] > -1e-5 && m[2] < 1e-5 && m[2] > -1e-5) {
  1837. var sx = m[0];
  1838. var sy = m[3];
  1839. var tx = m[4];
  1840. var ty = m[5];
  1841. target.x = source.x * sx + tx;
  1842. target.y = source.y * sy + ty;
  1843. target.width = source.width * sx;
  1844. target.height = source.height * sy;
  1845. if (target.width < 0) {
  1846. target.x += target.width;
  1847. target.width = -target.width;
  1848. }
  1849. if (target.height < 0) {
  1850. target.y += target.height;
  1851. target.height = -target.height;
  1852. }
  1853. return;
  1854. }
  1855. lt.x = lb.x = source.x;
  1856. lt.y = rt.y = source.y;
  1857. rb.x = rt.x = source.x + source.width;
  1858. rb.y = lb.y = source.y + source.height;
  1859. lt.transform(m);
  1860. rt.transform(m);
  1861. rb.transform(m);
  1862. lb.transform(m);
  1863. target.x = mathMin(lt.x, rb.x, lb.x, rt.x);
  1864. target.y = mathMin(lt.y, rb.y, lb.y, rt.y);
  1865. var maxX = mathMax(lt.x, rb.x, lb.x, rt.x);
  1866. var maxY = mathMax(lt.y, rb.y, lb.y, rt.y);
  1867. target.width = maxX - target.x;
  1868. target.height = maxY - target.y;
  1869. };
  1870. return BoundingRect;
  1871. }());
  1872. var SILENT = 'silent';
  1873. function makeEventPacket(eveType, targetInfo, event) {
  1874. return {
  1875. type: eveType,
  1876. event: event,
  1877. target: targetInfo.target,
  1878. topTarget: targetInfo.topTarget,
  1879. cancelBubble: false,
  1880. offsetX: event.zrX,
  1881. offsetY: event.zrY,
  1882. gestureEvent: event.gestureEvent,
  1883. pinchX: event.pinchX,
  1884. pinchY: event.pinchY,
  1885. pinchScale: event.pinchScale,
  1886. wheelDelta: event.zrDelta,
  1887. zrByTouch: event.zrByTouch,
  1888. which: event.which,
  1889. stop: stopEvent
  1890. };
  1891. }
  1892. function stopEvent() {
  1893. stop(this.event);
  1894. }
  1895. var EmptyProxy = (function (_super) {
  1896. __extends(EmptyProxy, _super);
  1897. function EmptyProxy() {
  1898. var _this = _super !== null && _super.apply(this, arguments) || this;
  1899. _this.handler = null;
  1900. return _this;
  1901. }
  1902. EmptyProxy.prototype.dispose = function () { };
  1903. EmptyProxy.prototype.setCursor = function () { };
  1904. return EmptyProxy;
  1905. }(Eventful));
  1906. var HoveredResult = (function () {
  1907. function HoveredResult(x, y) {
  1908. this.x = x;
  1909. this.y = y;
  1910. }
  1911. return HoveredResult;
  1912. }());
  1913. var handlerNames = [
  1914. 'click', 'dblclick', 'mousewheel', 'mouseout',
  1915. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  1916. ];
  1917. var tmpRect = new BoundingRect(0, 0, 0, 0);
  1918. var Handler = (function (_super) {
  1919. __extends(Handler, _super);
  1920. function Handler(storage, painter, proxy, painterRoot, pointerSize) {
  1921. var _this = _super.call(this) || this;
  1922. _this._hovered = new HoveredResult(0, 0);
  1923. _this.storage = storage;
  1924. _this.painter = painter;
  1925. _this.painterRoot = painterRoot;
  1926. _this._pointerSize = pointerSize;
  1927. proxy = proxy || new EmptyProxy();
  1928. _this.proxy = null;
  1929. _this.setHandlerProxy(proxy);
  1930. _this._draggingMgr = new Draggable(_this);
  1931. return _this;
  1932. }
  1933. Handler.prototype.setHandlerProxy = function (proxy) {
  1934. if (this.proxy) {
  1935. this.proxy.dispose();
  1936. }
  1937. if (proxy) {
  1938. each(handlerNames, function (name) {
  1939. proxy.on && proxy.on(name, this[name], this);
  1940. }, this);
  1941. proxy.handler = this;
  1942. }
  1943. this.proxy = proxy;
  1944. };
  1945. Handler.prototype.mousemove = function (event) {
  1946. var x = event.zrX;
  1947. var y = event.zrY;
  1948. var isOutside = isOutsideBoundary(this, x, y);
  1949. var lastHovered = this._hovered;
  1950. var lastHoveredTarget = lastHovered.target;
  1951. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  1952. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  1953. lastHoveredTarget = lastHovered.target;
  1954. }
  1955. var hovered = this._hovered = isOutside ? new HoveredResult(x, y) : this.findHover(x, y);
  1956. var hoveredTarget = hovered.target;
  1957. var proxy = this.proxy;
  1958. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  1959. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  1960. this.dispatchToElement(lastHovered, 'mouseout', event);
  1961. }
  1962. this.dispatchToElement(hovered, 'mousemove', event);
  1963. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  1964. this.dispatchToElement(hovered, 'mouseover', event);
  1965. }
  1966. };
  1967. Handler.prototype.mouseout = function (event) {
  1968. var eventControl = event.zrEventControl;
  1969. if (eventControl !== 'only_globalout') {
  1970. this.dispatchToElement(this._hovered, 'mouseout', event);
  1971. }
  1972. if (eventControl !== 'no_globalout') {
  1973. this.trigger('globalout', { type: 'globalout', event: event });
  1974. }
  1975. };
  1976. Handler.prototype.resize = function () {
  1977. this._hovered = new HoveredResult(0, 0);
  1978. };
  1979. Handler.prototype.dispatch = function (eventName, eventArgs) {
  1980. var handler = this[eventName];
  1981. handler && handler.call(this, eventArgs);
  1982. };
  1983. Handler.prototype.dispose = function () {
  1984. this.proxy.dispose();
  1985. this.storage = null;
  1986. this.proxy = null;
  1987. this.painter = null;
  1988. };
  1989. Handler.prototype.setCursorStyle = function (cursorStyle) {
  1990. var proxy = this.proxy;
  1991. proxy.setCursor && proxy.setCursor(cursorStyle);
  1992. };
  1993. Handler.prototype.dispatchToElement = function (targetInfo, eventName, event) {
  1994. targetInfo = targetInfo || {};
  1995. var el = targetInfo.target;
  1996. if (el && el.silent) {
  1997. return;
  1998. }
  1999. var eventKey = ('on' + eventName);
  2000. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2001. while (el) {
  2002. el[eventKey]
  2003. && (eventPacket.cancelBubble = !!el[eventKey].call(el, eventPacket));
  2004. el.trigger(eventName, eventPacket);
  2005. el = el.__hostTarget ? el.__hostTarget : el.parent;
  2006. if (eventPacket.cancelBubble) {
  2007. break;
  2008. }
  2009. }
  2010. if (!eventPacket.cancelBubble) {
  2011. this.trigger(eventName, eventPacket);
  2012. if (this.painter && this.painter.eachOtherLayer) {
  2013. this.painter.eachOtherLayer(function (layer) {
  2014. if (typeof (layer[eventKey]) === 'function') {
  2015. layer[eventKey].call(layer, eventPacket);
  2016. }
  2017. if (layer.trigger) {
  2018. layer.trigger(eventName, eventPacket);
  2019. }
  2020. });
  2021. }
  2022. }
  2023. };
  2024. Handler.prototype.findHover = function (x, y, exclude) {
  2025. var list = this.storage.getDisplayList();
  2026. var out = new HoveredResult(x, y);
  2027. setHoverTarget(list, out, x, y, exclude);
  2028. if (this._pointerSize && !out.target) {
  2029. var candidates = [];
  2030. var pointerSize = this._pointerSize;
  2031. var targetSizeHalf = pointerSize / 2;
  2032. var pointerRect = new BoundingRect(x - targetSizeHalf, y - targetSizeHalf, pointerSize, pointerSize);
  2033. for (var i = list.length - 1; i >= 0; i--) {
  2034. var el = list[i];
  2035. if (el !== exclude
  2036. && !el.ignore
  2037. && !el.ignoreCoarsePointer
  2038. && (!el.parent || !el.parent.ignoreCoarsePointer)) {
  2039. tmpRect.copy(el.getBoundingRect());
  2040. if (el.transform) {
  2041. tmpRect.applyTransform(el.transform);
  2042. }
  2043. if (tmpRect.intersect(pointerRect)) {
  2044. candidates.push(el);
  2045. }
  2046. }
  2047. }
  2048. if (candidates.length) {
  2049. var rStep = 4;
  2050. var thetaStep = Math.PI / 12;
  2051. var PI2 = Math.PI * 2;
  2052. for (var r = 0; r < targetSizeHalf; r += rStep) {
  2053. for (var theta = 0; theta < PI2; theta += thetaStep) {
  2054. var x1 = x + r * Math.cos(theta);
  2055. var y1 = y + r * Math.sin(theta);
  2056. setHoverTarget(candidates, out, x1, y1, exclude);
  2057. if (out.target) {
  2058. return out;
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. return out;
  2065. };
  2066. Handler.prototype.processGesture = function (event, stage) {
  2067. if (!this._gestureMgr) {
  2068. this._gestureMgr = new GestureMgr();
  2069. }
  2070. var gestureMgr = this._gestureMgr;
  2071. stage === 'start' && gestureMgr.clear();
  2072. var gestureInfo = gestureMgr.recognize(event, this.findHover(event.zrX, event.zrY, null).target, this.proxy.dom);
  2073. stage === 'end' && gestureMgr.clear();
  2074. if (gestureInfo) {
  2075. var type = gestureInfo.type;
  2076. event.gestureEvent = type;
  2077. var res = new HoveredResult();
  2078. res.target = gestureInfo.target;
  2079. this.dispatchToElement(res, type, gestureInfo.event);
  2080. }
  2081. };
  2082. return Handler;
  2083. }(Eventful));
  2084. each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2085. Handler.prototype[name] = function (event) {
  2086. var x = event.zrX;
  2087. var y = event.zrY;
  2088. var isOutside = isOutsideBoundary(this, x, y);
  2089. var hovered;
  2090. var hoveredTarget;
  2091. if (name !== 'mouseup' || !isOutside) {
  2092. hovered = this.findHover(x, y);
  2093. hoveredTarget = hovered.target;
  2094. }
  2095. if (name === 'mousedown') {
  2096. this._downEl = hoveredTarget;
  2097. this._downPoint = [event.zrX, event.zrY];
  2098. this._upEl = hoveredTarget;
  2099. }
  2100. else if (name === 'mouseup') {
  2101. this._upEl = hoveredTarget;
  2102. }
  2103. else if (name === 'click') {
  2104. if (this._downEl !== this._upEl
  2105. || !this._downPoint
  2106. || dist(this._downPoint, [event.zrX, event.zrY]) > 4) {
  2107. return;
  2108. }
  2109. this._downPoint = null;
  2110. }
  2111. this.dispatchToElement(hovered, name, event);
  2112. };
  2113. });
  2114. function isHover(displayable, x, y) {
  2115. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2116. var el = displayable;
  2117. var isSilent = void 0;
  2118. var ignoreClip = false;
  2119. while (el) {
  2120. if (el.ignoreClip) {
  2121. ignoreClip = true;
  2122. }
  2123. if (!ignoreClip) {
  2124. var clipPath = el.getClipPath();
  2125. if (clipPath && !clipPath.contain(x, y)) {
  2126. return false;
  2127. }
  2128. if (el.silent) {
  2129. isSilent = true;
  2130. }
  2131. }
  2132. var hostEl = el.__hostTarget;
  2133. el = hostEl ? hostEl : el.parent;
  2134. }
  2135. return isSilent ? SILENT : true;
  2136. }
  2137. return false;
  2138. }
  2139. function setHoverTarget(list, out, x, y, exclude) {
  2140. for (var i = list.length - 1; i >= 0; i--) {
  2141. var el = list[i];
  2142. var hoverCheckResult = void 0;
  2143. if (el !== exclude
  2144. && !el.ignore
  2145. && (hoverCheckResult = isHover(el, x, y))) {
  2146. !out.topTarget && (out.topTarget = el);
  2147. if (hoverCheckResult !== SILENT) {
  2148. out.target = el;
  2149. break;
  2150. }
  2151. }
  2152. }
  2153. }
  2154. function isOutsideBoundary(handlerInstance, x, y) {
  2155. var painter = handlerInstance.painter;
  2156. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  2157. }
  2158. var DEFAULT_MIN_MERGE = 32;
  2159. var DEFAULT_MIN_GALLOPING = 7;
  2160. function minRunLength(n) {
  2161. var r = 0;
  2162. while (n >= DEFAULT_MIN_MERGE) {
  2163. r |= n & 1;
  2164. n >>= 1;
  2165. }
  2166. return n + r;
  2167. }
  2168. function makeAscendingRun(array, lo, hi, compare) {
  2169. var runHi = lo + 1;
  2170. if (runHi === hi) {
  2171. return 1;
  2172. }
  2173. if (compare(array[runHi++], array[lo]) < 0) {
  2174. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  2175. runHi++;
  2176. }
  2177. reverseRun(array, lo, runHi);
  2178. }
  2179. else {
  2180. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  2181. runHi++;
  2182. }
  2183. }
  2184. return runHi - lo;
  2185. }
  2186. function reverseRun(array, lo, hi) {
  2187. hi--;
  2188. while (lo < hi) {
  2189. var t = array[lo];
  2190. array[lo++] = array[hi];
  2191. array[hi--] = t;
  2192. }
  2193. }
  2194. function binaryInsertionSort(array, lo, hi, start, compare) {
  2195. if (start === lo) {
  2196. start++;
  2197. }
  2198. for (; start < hi; start++) {
  2199. var pivot = array[start];
  2200. var left = lo;
  2201. var right = start;
  2202. var mid;
  2203. while (left < right) {
  2204. mid = left + right >>> 1;
  2205. if (compare(pivot, array[mid]) < 0) {
  2206. right = mid;
  2207. }
  2208. else {
  2209. left = mid + 1;
  2210. }
  2211. }
  2212. var n = start - left;
  2213. switch (n) {
  2214. case 3:
  2215. array[left + 3] = array[left + 2];
  2216. case 2:
  2217. array[left + 2] = array[left + 1];
  2218. case 1:
  2219. array[left + 1] = array[left];
  2220. break;
  2221. default:
  2222. while (n > 0) {
  2223. array[left + n] = array[left + n - 1];
  2224. n--;
  2225. }
  2226. }
  2227. array[left] = pivot;
  2228. }
  2229. }
  2230. function gallopLeft(value, array, start, length, hint, compare) {
  2231. var lastOffset = 0;
  2232. var maxOffset = 0;
  2233. var offset = 1;
  2234. if (compare(value, array[start + hint]) > 0) {
  2235. maxOffset = length - hint;
  2236. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  2237. lastOffset = offset;
  2238. offset = (offset << 1) + 1;
  2239. if (offset <= 0) {
  2240. offset = maxOffset;
  2241. }
  2242. }
  2243. if (offset > maxOffset) {
  2244. offset = maxOffset;
  2245. }
  2246. lastOffset += hint;
  2247. offset += hint;
  2248. }
  2249. else {
  2250. maxOffset = hint + 1;
  2251. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  2252. lastOffset = offset;
  2253. offset = (offset << 1) + 1;
  2254. if (offset <= 0) {
  2255. offset = maxOffset;
  2256. }
  2257. }
  2258. if (offset > maxOffset) {
  2259. offset = maxOffset;
  2260. }
  2261. var tmp = lastOffset;
  2262. lastOffset = hint - offset;
  2263. offset = hint - tmp;
  2264. }
  2265. lastOffset++;
  2266. while (lastOffset < offset) {
  2267. var m = lastOffset + (offset - lastOffset >>> 1);
  2268. if (compare(value, array[start + m]) > 0) {
  2269. lastOffset = m + 1;
  2270. }
  2271. else {
  2272. offset = m;
  2273. }
  2274. }
  2275. return offset;
  2276. }
  2277. function gallopRight(value, array, start, length, hint, compare) {
  2278. var lastOffset = 0;
  2279. var maxOffset = 0;
  2280. var offset = 1;
  2281. if (compare(value, array[start + hint]) < 0) {
  2282. maxOffset = hint + 1;
  2283. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  2284. lastOffset = offset;
  2285. offset = (offset << 1) + 1;
  2286. if (offset <= 0) {
  2287. offset = maxOffset;
  2288. }
  2289. }
  2290. if (offset > maxOffset) {
  2291. offset = maxOffset;
  2292. }
  2293. var tmp = lastOffset;
  2294. lastOffset = hint - offset;
  2295. offset = hint - tmp;
  2296. }
  2297. else {
  2298. maxOffset = length - hint;
  2299. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  2300. lastOffset = offset;
  2301. offset = (offset << 1) + 1;
  2302. if (offset <= 0) {
  2303. offset = maxOffset;
  2304. }
  2305. }
  2306. if (offset > maxOffset) {
  2307. offset = maxOffset;
  2308. }
  2309. lastOffset += hint;
  2310. offset += hint;
  2311. }
  2312. lastOffset++;
  2313. while (lastOffset < offset) {
  2314. var m = lastOffset + (offset - lastOffset >>> 1);
  2315. if (compare(value, array[start + m]) < 0) {
  2316. offset = m;
  2317. }
  2318. else {
  2319. lastOffset = m + 1;
  2320. }
  2321. }
  2322. return offset;
  2323. }
  2324. function TimSort(array, compare) {
  2325. var minGallop = DEFAULT_MIN_GALLOPING;
  2326. var length = 0;
  2327. var runStart;
  2328. var runLength;
  2329. var stackSize = 0;
  2330. length = array.length;
  2331. var tmp = [];
  2332. runStart = [];
  2333. runLength = [];
  2334. function pushRun(_runStart, _runLength) {
  2335. runStart[stackSize] = _runStart;
  2336. runLength[stackSize] = _runLength;
  2337. stackSize += 1;
  2338. }
  2339. function mergeRuns() {
  2340. while (stackSize > 1) {
  2341. var n = stackSize - 2;
  2342. if ((n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1])
  2343. || (n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1])) {
  2344. if (runLength[n - 1] < runLength[n + 1]) {
  2345. n--;
  2346. }
  2347. }
  2348. else if (runLength[n] > runLength[n + 1]) {
  2349. break;
  2350. }
  2351. mergeAt(n);
  2352. }
  2353. }
  2354. function forceMergeRuns() {
  2355. while (stackSize > 1) {
  2356. var n = stackSize - 2;
  2357. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  2358. n--;
  2359. }
  2360. mergeAt(n);
  2361. }
  2362. }
  2363. function mergeAt(i) {
  2364. var start1 = runStart[i];
  2365. var length1 = runLength[i];
  2366. var start2 = runStart[i + 1];
  2367. var length2 = runLength[i + 1];
  2368. runLength[i] = length1 + length2;
  2369. if (i === stackSize - 3) {
  2370. runStart[i + 1] = runStart[i + 2];
  2371. runLength[i + 1] = runLength[i + 2];
  2372. }
  2373. stackSize--;
  2374. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  2375. start1 += k;
  2376. length1 -= k;
  2377. if (length1 === 0) {
  2378. return;
  2379. }
  2380. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  2381. if (length2 === 0) {
  2382. return;
  2383. }
  2384. if (length1 <= length2) {
  2385. mergeLow(start1, length1, start2, length2);
  2386. }
  2387. else {
  2388. mergeHigh(start1, length1, start2, length2);
  2389. }
  2390. }
  2391. function mergeLow(start1, length1, start2, length2) {
  2392. var i = 0;
  2393. for (i = 0; i < length1; i++) {
  2394. tmp[i] = array[start1 + i];
  2395. }
  2396. var cursor1 = 0;
  2397. var cursor2 = start2;
  2398. var dest = start1;
  2399. array[dest++] = array[cursor2++];
  2400. if (--length2 === 0) {
  2401. for (i = 0; i < length1; i++) {
  2402. array[dest + i] = tmp[cursor1 + i];
  2403. }
  2404. return;
  2405. }
  2406. if (length1 === 1) {
  2407. for (i = 0; i < length2; i++) {
  2408. array[dest + i] = array[cursor2 + i];
  2409. }
  2410. array[dest + length2] = tmp[cursor1];
  2411. return;
  2412. }
  2413. var _minGallop = minGallop;
  2414. var count1;
  2415. var count2;
  2416. var exit;
  2417. while (1) {
  2418. count1 = 0;
  2419. count2 = 0;
  2420. exit = false;
  2421. do {
  2422. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  2423. array[dest++] = array[cursor2++];
  2424. count2++;
  2425. count1 = 0;
  2426. if (--length2 === 0) {
  2427. exit = true;
  2428. break;
  2429. }
  2430. }
  2431. else {
  2432. array[dest++] = tmp[cursor1++];
  2433. count1++;
  2434. count2 = 0;
  2435. if (--length1 === 1) {
  2436. exit = true;
  2437. break;
  2438. }
  2439. }
  2440. } while ((count1 | count2) < _minGallop);
  2441. if (exit) {
  2442. break;
  2443. }
  2444. do {
  2445. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  2446. if (count1 !== 0) {
  2447. for (i = 0; i < count1; i++) {
  2448. array[dest + i] = tmp[cursor1 + i];
  2449. }
  2450. dest += count1;
  2451. cursor1 += count1;
  2452. length1 -= count1;
  2453. if (length1 <= 1) {
  2454. exit = true;
  2455. break;
  2456. }
  2457. }
  2458. array[dest++] = array[cursor2++];
  2459. if (--length2 === 0) {
  2460. exit = true;
  2461. break;
  2462. }
  2463. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  2464. if (count2 !== 0) {
  2465. for (i = 0; i < count2; i++) {
  2466. array[dest + i] = array[cursor2 + i];
  2467. }
  2468. dest += count2;
  2469. cursor2 += count2;
  2470. length2 -= count2;
  2471. if (length2 === 0) {
  2472. exit = true;
  2473. break;
  2474. }
  2475. }
  2476. array[dest++] = tmp[cursor1++];
  2477. if (--length1 === 1) {
  2478. exit = true;
  2479. break;
  2480. }
  2481. _minGallop--;
  2482. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2483. if (exit) {
  2484. break;
  2485. }
  2486. if (_minGallop < 0) {
  2487. _minGallop = 0;
  2488. }
  2489. _minGallop += 2;
  2490. }
  2491. minGallop = _minGallop;
  2492. minGallop < 1 && (minGallop = 1);
  2493. if (length1 === 1) {
  2494. for (i = 0; i < length2; i++) {
  2495. array[dest + i] = array[cursor2 + i];
  2496. }
  2497. array[dest + length2] = tmp[cursor1];
  2498. }
  2499. else if (length1 === 0) {
  2500. throw new Error();
  2501. }
  2502. else {
  2503. for (i = 0; i < length1; i++) {
  2504. array[dest + i] = tmp[cursor1 + i];
  2505. }
  2506. }
  2507. }
  2508. function mergeHigh(start1, length1, start2, length2) {
  2509. var i = 0;
  2510. for (i = 0; i < length2; i++) {
  2511. tmp[i] = array[start2 + i];
  2512. }
  2513. var cursor1 = start1 + length1 - 1;
  2514. var cursor2 = length2 - 1;
  2515. var dest = start2 + length2 - 1;
  2516. var customCursor = 0;
  2517. var customDest = 0;
  2518. array[dest--] = array[cursor1--];
  2519. if (--length1 === 0) {
  2520. customCursor = dest - (length2 - 1);
  2521. for (i = 0; i < length2; i++) {
  2522. array[customCursor + i] = tmp[i];
  2523. }
  2524. return;
  2525. }
  2526. if (length2 === 1) {
  2527. dest -= length1;
  2528. cursor1 -= length1;
  2529. customDest = dest + 1;
  2530. customCursor = cursor1 + 1;
  2531. for (i = length1 - 1; i >= 0; i--) {
  2532. array[customDest + i] = array[customCursor + i];
  2533. }
  2534. array[dest] = tmp[cursor2];
  2535. return;
  2536. }
  2537. var _minGallop = minGallop;
  2538. while (true) {
  2539. var count1 = 0;
  2540. var count2 = 0;
  2541. var exit = false;
  2542. do {
  2543. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  2544. array[dest--] = array[cursor1--];
  2545. count1++;
  2546. count2 = 0;
  2547. if (--length1 === 0) {
  2548. exit = true;
  2549. break;
  2550. }
  2551. }
  2552. else {
  2553. array[dest--] = tmp[cursor2--];
  2554. count2++;
  2555. count1 = 0;
  2556. if (--length2 === 1) {
  2557. exit = true;
  2558. break;
  2559. }
  2560. }
  2561. } while ((count1 | count2) < _minGallop);
  2562. if (exit) {
  2563. break;
  2564. }
  2565. do {
  2566. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  2567. if (count1 !== 0) {
  2568. dest -= count1;
  2569. cursor1 -= count1;
  2570. length1 -= count1;
  2571. customDest = dest + 1;
  2572. customCursor = cursor1 + 1;
  2573. for (i = count1 - 1; i >= 0; i--) {
  2574. array[customDest + i] = array[customCursor + i];
  2575. }
  2576. if (length1 === 0) {
  2577. exit = true;
  2578. break;
  2579. }
  2580. }
  2581. array[dest--] = tmp[cursor2--];
  2582. if (--length2 === 1) {
  2583. exit = true;
  2584. break;
  2585. }
  2586. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  2587. if (count2 !== 0) {
  2588. dest -= count2;
  2589. cursor2 -= count2;
  2590. length2 -= count2;
  2591. customDest = dest + 1;
  2592. customCursor = cursor2 + 1;
  2593. for (i = 0; i < count2; i++) {
  2594. array[customDest + i] = tmp[customCursor + i];
  2595. }
  2596. if (length2 <= 1) {
  2597. exit = true;
  2598. break;
  2599. }
  2600. }
  2601. array[dest--] = array[cursor1--];
  2602. if (--length1 === 0) {
  2603. exit = true;
  2604. break;
  2605. }
  2606. _minGallop--;
  2607. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2608. if (exit) {
  2609. break;
  2610. }
  2611. if (_minGallop < 0) {
  2612. _minGallop = 0;
  2613. }
  2614. _minGallop += 2;
  2615. }
  2616. minGallop = _minGallop;
  2617. if (minGallop < 1) {
  2618. minGallop = 1;
  2619. }
  2620. if (length2 === 1) {
  2621. dest -= length1;
  2622. cursor1 -= length1;
  2623. customDest = dest + 1;
  2624. customCursor = cursor1 + 1;
  2625. for (i = length1 - 1; i >= 0; i--) {
  2626. array[customDest + i] = array[customCursor + i];
  2627. }
  2628. array[dest] = tmp[cursor2];
  2629. }
  2630. else if (length2 === 0) {
  2631. throw new Error();
  2632. }
  2633. else {
  2634. customCursor = dest - (length2 - 1);
  2635. for (i = 0; i < length2; i++) {
  2636. array[customCursor + i] = tmp[i];
  2637. }
  2638. }
  2639. }
  2640. return {
  2641. mergeRuns: mergeRuns,
  2642. forceMergeRuns: forceMergeRuns,
  2643. pushRun: pushRun
  2644. };
  2645. }
  2646. function sort(array, compare, lo, hi) {
  2647. if (!lo) {
  2648. lo = 0;
  2649. }
  2650. if (!hi) {
  2651. hi = array.length;
  2652. }
  2653. var remaining = hi - lo;
  2654. if (remaining < 2) {
  2655. return;
  2656. }
  2657. var runLength = 0;
  2658. if (remaining < DEFAULT_MIN_MERGE) {
  2659. runLength = makeAscendingRun(array, lo, hi, compare);
  2660. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  2661. return;
  2662. }
  2663. var ts = TimSort(array, compare);
  2664. var minRun = minRunLength(remaining);
  2665. do {
  2666. runLength = makeAscendingRun(array, lo, hi, compare);
  2667. if (runLength < minRun) {
  2668. var force = remaining;
  2669. if (force > minRun) {
  2670. force = minRun;
  2671. }
  2672. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  2673. runLength = force;
  2674. }
  2675. ts.pushRun(lo, runLength);
  2676. ts.mergeRuns();
  2677. remaining -= runLength;
  2678. lo += runLength;
  2679. } while (remaining !== 0);
  2680. ts.forceMergeRuns();
  2681. }
  2682. var REDRAW_BIT = 1;
  2683. var STYLE_CHANGED_BIT = 2;
  2684. var SHAPE_CHANGED_BIT = 4;
  2685. var invalidZErrorLogged = false;
  2686. function logInvalidZError() {
  2687. if (invalidZErrorLogged) {
  2688. return;
  2689. }
  2690. invalidZErrorLogged = true;
  2691. console.warn('z / z2 / zlevel of displayable is invalid, which may cause unexpected errors');
  2692. }
  2693. function shapeCompareFunc(a, b) {
  2694. if (a.zlevel === b.zlevel) {
  2695. if (a.z === b.z) {
  2696. return a.z2 - b.z2;
  2697. }
  2698. return a.z - b.z;
  2699. }
  2700. return a.zlevel - b.zlevel;
  2701. }
  2702. var Storage = (function () {
  2703. function Storage() {
  2704. this._roots = [];
  2705. this._displayList = [];
  2706. this._displayListLen = 0;
  2707. this.displayableSortFunc = shapeCompareFunc;
  2708. }
  2709. Storage.prototype.traverse = function (cb, context) {
  2710. for (var i = 0; i < this._roots.length; i++) {
  2711. this._roots[i].traverse(cb, context);
  2712. }
  2713. };
  2714. Storage.prototype.getDisplayList = function (update, includeIgnore) {
  2715. includeIgnore = includeIgnore || false;
  2716. var displayList = this._displayList;
  2717. if (update || !displayList.length) {
  2718. this.updateDisplayList(includeIgnore);
  2719. }
  2720. return displayList;
  2721. };
  2722. Storage.prototype.updateDisplayList = function (includeIgnore) {
  2723. this._displayListLen = 0;
  2724. var roots = this._roots;
  2725. var displayList = this._displayList;
  2726. for (var i = 0, len = roots.length; i < len; i++) {
  2727. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  2728. }
  2729. displayList.length = this._displayListLen;
  2730. sort(displayList, shapeCompareFunc);
  2731. };
  2732. Storage.prototype._updateAndAddDisplayable = function (el, clipPaths, includeIgnore) {
  2733. if (el.ignore && !includeIgnore) {
  2734. return;
  2735. }
  2736. el.beforeUpdate();
  2737. el.update();
  2738. el.afterUpdate();
  2739. var userSetClipPath = el.getClipPath();
  2740. if (el.ignoreClip) {
  2741. clipPaths = null;
  2742. }
  2743. else if (userSetClipPath) {
  2744. if (clipPaths) {
  2745. clipPaths = clipPaths.slice();
  2746. }
  2747. else {
  2748. clipPaths = [];
  2749. }
  2750. var currentClipPath = userSetClipPath;
  2751. var parentClipPath = el;
  2752. while (currentClipPath) {
  2753. currentClipPath.parent = parentClipPath;
  2754. currentClipPath.updateTransform();
  2755. clipPaths.push(currentClipPath);
  2756. parentClipPath = currentClipPath;
  2757. currentClipPath = currentClipPath.getClipPath();
  2758. }
  2759. }
  2760. if (el.childrenRef) {
  2761. var children = el.childrenRef();
  2762. for (var i = 0; i < children.length; i++) {
  2763. var child = children[i];
  2764. if (el.__dirty) {
  2765. child.__dirty |= REDRAW_BIT;
  2766. }
  2767. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  2768. }
  2769. el.__dirty = 0;
  2770. }
  2771. else {
  2772. var disp = el;
  2773. if (clipPaths && clipPaths.length) {
  2774. disp.__clipPaths = clipPaths;
  2775. }
  2776. else if (disp.__clipPaths && disp.__clipPaths.length > 0) {
  2777. disp.__clipPaths = [];
  2778. }
  2779. if (isNaN(disp.z)) {
  2780. logInvalidZError();
  2781. disp.z = 0;
  2782. }
  2783. if (isNaN(disp.z2)) {
  2784. logInvalidZError();
  2785. disp.z2 = 0;
  2786. }
  2787. if (isNaN(disp.zlevel)) {
  2788. logInvalidZError();
  2789. disp.zlevel = 0;
  2790. }
  2791. this._displayList[this._displayListLen++] = disp;
  2792. }
  2793. var decalEl = el.getDecalElement && el.getDecalElement();
  2794. if (decalEl) {
  2795. this._updateAndAddDisplayable(decalEl, clipPaths, includeIgnore);
  2796. }
  2797. var textGuide = el.getTextGuideLine();
  2798. if (textGuide) {
  2799. this._updateAndAddDisplayable(textGuide, clipPaths, includeIgnore);
  2800. }
  2801. var textEl = el.getTextContent();
  2802. if (textEl) {
  2803. this._updateAndAddDisplayable(textEl, clipPaths, includeIgnore);
  2804. }
  2805. };
  2806. Storage.prototype.addRoot = function (el) {
  2807. if (el.__zr && el.__zr.storage === this) {
  2808. return;
  2809. }
  2810. this._roots.push(el);
  2811. };
  2812. Storage.prototype.delRoot = function (el) {
  2813. if (el instanceof Array) {
  2814. for (var i = 0, l = el.length; i < l; i++) {
  2815. this.delRoot(el[i]);
  2816. }
  2817. return;
  2818. }
  2819. var idx = indexOf(this._roots, el);
  2820. if (idx >= 0) {
  2821. this._roots.splice(idx, 1);
  2822. }
  2823. };
  2824. Storage.prototype.delAllRoots = function () {
  2825. this._roots = [];
  2826. this._displayList = [];
  2827. this._displayListLen = 0;
  2828. return;
  2829. };
  2830. Storage.prototype.getRoots = function () {
  2831. return this._roots;
  2832. };
  2833. Storage.prototype.dispose = function () {
  2834. this._displayList = null;
  2835. this._roots = null;
  2836. };
  2837. return Storage;
  2838. }());
  2839. var requestAnimationFrame;
  2840. requestAnimationFrame = (env.hasGlobalWindow
  2841. && ((window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  2842. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  2843. || window.mozRequestAnimationFrame
  2844. || window.webkitRequestAnimationFrame)) || function (func) {
  2845. return setTimeout(func, 16);
  2846. };
  2847. var requestAnimationFrame$1 = requestAnimationFrame;
  2848. var easingFuncs = {
  2849. linear: function (k) {
  2850. return k;
  2851. },
  2852. quadraticIn: function (k) {
  2853. return k * k;
  2854. },
  2855. quadraticOut: function (k) {
  2856. return k * (2 - k);
  2857. },
  2858. quadraticInOut: function (k) {
  2859. if ((k *= 2) < 1) {
  2860. return 0.5 * k * k;
  2861. }
  2862. return -0.5 * (--k * (k - 2) - 1);
  2863. },
  2864. cubicIn: function (k) {
  2865. return k * k * k;
  2866. },
  2867. cubicOut: function (k) {
  2868. return --k * k * k + 1;
  2869. },
  2870. cubicInOut: function (k) {
  2871. if ((k *= 2) < 1) {
  2872. return 0.5 * k * k * k;
  2873. }
  2874. return 0.5 * ((k -= 2) * k * k + 2);
  2875. },
  2876. quarticIn: function (k) {
  2877. return k * k * k * k;
  2878. },
  2879. quarticOut: function (k) {
  2880. return 1 - (--k * k * k * k);
  2881. },
  2882. quarticInOut: function (k) {
  2883. if ((k *= 2) < 1) {
  2884. return 0.5 * k * k * k * k;
  2885. }
  2886. return -0.5 * ((k -= 2) * k * k * k - 2);
  2887. },
  2888. quinticIn: function (k) {
  2889. return k * k * k * k * k;
  2890. },
  2891. quinticOut: function (k) {
  2892. return --k * k * k * k * k + 1;
  2893. },
  2894. quinticInOut: function (k) {
  2895. if ((k *= 2) < 1) {
  2896. return 0.5 * k * k * k * k * k;
  2897. }
  2898. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2899. },
  2900. sinusoidalIn: function (k) {
  2901. return 1 - Math.cos(k * Math.PI / 2);
  2902. },
  2903. sinusoidalOut: function (k) {
  2904. return Math.sin(k * Math.PI / 2);
  2905. },
  2906. sinusoidalInOut: function (k) {
  2907. return 0.5 * (1 - Math.cos(Math.PI * k));
  2908. },
  2909. exponentialIn: function (k) {
  2910. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2911. },
  2912. exponentialOut: function (k) {
  2913. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2914. },
  2915. exponentialInOut: function (k) {
  2916. if (k === 0) {
  2917. return 0;
  2918. }
  2919. if (k === 1) {
  2920. return 1;
  2921. }
  2922. if ((k *= 2) < 1) {
  2923. return 0.5 * Math.pow(1024, k - 1);
  2924. }
  2925. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2926. },
  2927. circularIn: function (k) {
  2928. return 1 - Math.sqrt(1 - k * k);
  2929. },
  2930. circularOut: function (k) {
  2931. return Math.sqrt(1 - (--k * k));
  2932. },
  2933. circularInOut: function (k) {
  2934. if ((k *= 2) < 1) {
  2935. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2936. }
  2937. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2938. },
  2939. elasticIn: function (k) {
  2940. var s;
  2941. var a = 0.1;
  2942. var p = 0.4;
  2943. if (k === 0) {
  2944. return 0;
  2945. }
  2946. if (k === 1) {
  2947. return 1;
  2948. }
  2949. if (!a || a < 1) {
  2950. a = 1;
  2951. s = p / 4;
  2952. }
  2953. else {
  2954. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2955. }
  2956. return -(a * Math.pow(2, 10 * (k -= 1))
  2957. * Math.sin((k - s) * (2 * Math.PI) / p));
  2958. },
  2959. elasticOut: function (k) {
  2960. var s;
  2961. var a = 0.1;
  2962. var p = 0.4;
  2963. if (k === 0) {
  2964. return 0;
  2965. }
  2966. if (k === 1) {
  2967. return 1;
  2968. }
  2969. if (!a || a < 1) {
  2970. a = 1;
  2971. s = p / 4;
  2972. }
  2973. else {
  2974. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2975. }
  2976. return (a * Math.pow(2, -10 * k)
  2977. * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  2978. },
  2979. elasticInOut: function (k) {
  2980. var s;
  2981. var a = 0.1;
  2982. var p = 0.4;
  2983. if (k === 0) {
  2984. return 0;
  2985. }
  2986. if (k === 1) {
  2987. return 1;
  2988. }
  2989. if (!a || a < 1) {
  2990. a = 1;
  2991. s = p / 4;
  2992. }
  2993. else {
  2994. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2995. }
  2996. if ((k *= 2) < 1) {
  2997. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  2998. * Math.sin((k - s) * (2 * Math.PI) / p));
  2999. }
  3000. return a * Math.pow(2, -10 * (k -= 1))
  3001. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  3002. },
  3003. backIn: function (k) {
  3004. var s = 1.70158;
  3005. return k * k * ((s + 1) * k - s);
  3006. },
  3007. backOut: function (k) {
  3008. var s = 1.70158;
  3009. return --k * k * ((s + 1) * k + s) + 1;
  3010. },
  3011. backInOut: function (k) {
  3012. var s = 1.70158 * 1.525;
  3013. if ((k *= 2) < 1) {
  3014. return 0.5 * (k * k * ((s + 1) * k - s));
  3015. }
  3016. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  3017. },
  3018. bounceIn: function (k) {
  3019. return 1 - easingFuncs.bounceOut(1 - k);
  3020. },
  3021. bounceOut: function (k) {
  3022. if (k < (1 / 2.75)) {
  3023. return 7.5625 * k * k;
  3024. }
  3025. else if (k < (2 / 2.75)) {
  3026. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  3027. }
  3028. else if (k < (2.5 / 2.75)) {
  3029. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  3030. }
  3031. else {
  3032. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  3033. }
  3034. },
  3035. bounceInOut: function (k) {
  3036. if (k < 0.5) {
  3037. return easingFuncs.bounceIn(k * 2) * 0.5;
  3038. }
  3039. return easingFuncs.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  3040. }
  3041. };
  3042. var mathPow = Math.pow;
  3043. var mathSqrt = Math.sqrt;
  3044. var EPSILON = 1e-8;
  3045. var EPSILON_NUMERIC = 1e-4;
  3046. var THREE_SQRT = mathSqrt(3);
  3047. var ONE_THIRD = 1 / 3;
  3048. var _v0 = create();
  3049. var _v1 = create();
  3050. var _v2 = create();
  3051. function isAroundZero(val) {
  3052. return val > -EPSILON && val < EPSILON;
  3053. }
  3054. function isNotAroundZero(val) {
  3055. return val > EPSILON || val < -EPSILON;
  3056. }
  3057. function cubicAt(p0, p1, p2, p3, t) {
  3058. var onet = 1 - t;
  3059. return onet * onet * (onet * p0 + 3 * t * p1)
  3060. + t * t * (t * p3 + 3 * onet * p2);
  3061. }
  3062. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  3063. var onet = 1 - t;
  3064. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  3065. + (p3 - p2) * t * t);
  3066. }
  3067. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  3068. var a = p3 + 3 * (p1 - p2) - p0;
  3069. var b = 3 * (p2 - p1 * 2 + p0);
  3070. var c = 3 * (p1 - p0);
  3071. var d = p0 - val;
  3072. var A = b * b - 3 * a * c;
  3073. var B = b * c - 9 * a * d;
  3074. var C = c * c - 3 * b * d;
  3075. var n = 0;
  3076. if (isAroundZero(A) && isAroundZero(B)) {
  3077. if (isAroundZero(b)) {
  3078. roots[0] = 0;
  3079. }
  3080. else {
  3081. var t1 = -c / b;
  3082. if (t1 >= 0 && t1 <= 1) {
  3083. roots[n++] = t1;
  3084. }
  3085. }
  3086. }
  3087. else {
  3088. var disc = B * B - 4 * A * C;
  3089. if (isAroundZero(disc)) {
  3090. var K = B / A;
  3091. var t1 = -b / a + K;
  3092. var t2 = -K / 2;
  3093. if (t1 >= 0 && t1 <= 1) {
  3094. roots[n++] = t1;
  3095. }
  3096. if (t2 >= 0 && t2 <= 1) {
  3097. roots[n++] = t2;
  3098. }
  3099. }
  3100. else if (disc > 0) {
  3101. var discSqrt = mathSqrt(disc);
  3102. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  3103. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  3104. if (Y1 < 0) {
  3105. Y1 = -mathPow(-Y1, ONE_THIRD);
  3106. }
  3107. else {
  3108. Y1 = mathPow(Y1, ONE_THIRD);
  3109. }
  3110. if (Y2 < 0) {
  3111. Y2 = -mathPow(-Y2, ONE_THIRD);
  3112. }
  3113. else {
  3114. Y2 = mathPow(Y2, ONE_THIRD);
  3115. }
  3116. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  3117. if (t1 >= 0 && t1 <= 1) {
  3118. roots[n++] = t1;
  3119. }
  3120. }
  3121. else {
  3122. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  3123. var theta = Math.acos(T) / 3;
  3124. var ASqrt = mathSqrt(A);
  3125. var tmp = Math.cos(theta);
  3126. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  3127. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  3128. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  3129. if (t1 >= 0 && t1 <= 1) {
  3130. roots[n++] = t1;
  3131. }
  3132. if (t2 >= 0 && t2 <= 1) {
  3133. roots[n++] = t2;
  3134. }
  3135. if (t3 >= 0 && t3 <= 1) {
  3136. roots[n++] = t3;
  3137. }
  3138. }
  3139. }
  3140. return n;
  3141. }
  3142. function cubicExtrema(p0, p1, p2, p3, extrema) {
  3143. var b = 6 * p2 - 12 * p1 + 6 * p0;
  3144. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  3145. var c = 3 * p1 - 3 * p0;
  3146. var n = 0;
  3147. if (isAroundZero(a)) {
  3148. if (isNotAroundZero(b)) {
  3149. var t1 = -c / b;
  3150. if (t1 >= 0 && t1 <= 1) {
  3151. extrema[n++] = t1;
  3152. }
  3153. }
  3154. }
  3155. else {
  3156. var disc = b * b - 4 * a * c;
  3157. if (isAroundZero(disc)) {
  3158. extrema[0] = -b / (2 * a);
  3159. }
  3160. else if (disc > 0) {
  3161. var discSqrt = mathSqrt(disc);
  3162. var t1 = (-b + discSqrt) / (2 * a);
  3163. var t2 = (-b - discSqrt) / (2 * a);
  3164. if (t1 >= 0 && t1 <= 1) {
  3165. extrema[n++] = t1;
  3166. }
  3167. if (t2 >= 0 && t2 <= 1) {
  3168. extrema[n++] = t2;
  3169. }
  3170. }
  3171. }
  3172. return n;
  3173. }
  3174. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  3175. var p01 = (p1 - p0) * t + p0;
  3176. var p12 = (p2 - p1) * t + p1;
  3177. var p23 = (p3 - p2) * t + p2;
  3178. var p012 = (p12 - p01) * t + p01;
  3179. var p123 = (p23 - p12) * t + p12;
  3180. var p0123 = (p123 - p012) * t + p012;
  3181. out[0] = p0;
  3182. out[1] = p01;
  3183. out[2] = p012;
  3184. out[3] = p0123;
  3185. out[4] = p0123;
  3186. out[5] = p123;
  3187. out[6] = p23;
  3188. out[7] = p3;
  3189. }
  3190. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  3191. var t;
  3192. var interval = 0.005;
  3193. var d = Infinity;
  3194. var prev;
  3195. var next;
  3196. var d1;
  3197. var d2;
  3198. _v0[0] = x;
  3199. _v0[1] = y;
  3200. for (var _t = 0; _t < 1; _t += 0.05) {
  3201. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  3202. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  3203. d1 = distSquare(_v0, _v1);
  3204. if (d1 < d) {
  3205. t = _t;
  3206. d = d1;
  3207. }
  3208. }
  3209. d = Infinity;
  3210. for (var i = 0; i < 32; i++) {
  3211. if (interval < EPSILON_NUMERIC) {
  3212. break;
  3213. }
  3214. prev = t - interval;
  3215. next = t + interval;
  3216. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  3217. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  3218. d1 = distSquare(_v1, _v0);
  3219. if (prev >= 0 && d1 < d) {
  3220. t = prev;
  3221. d = d1;
  3222. }
  3223. else {
  3224. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  3225. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  3226. d2 = distSquare(_v2, _v0);
  3227. if (next <= 1 && d2 < d) {
  3228. t = next;
  3229. d = d2;
  3230. }
  3231. else {
  3232. interval *= 0.5;
  3233. }
  3234. }
  3235. }
  3236. if (out) {
  3237. out[0] = cubicAt(x0, x1, x2, x3, t);
  3238. out[1] = cubicAt(y0, y1, y2, y3, t);
  3239. }
  3240. return mathSqrt(d);
  3241. }
  3242. function cubicLength(x0, y0, x1, y1, x2, y2, x3, y3, iteration) {
  3243. var px = x0;
  3244. var py = y0;
  3245. var d = 0;
  3246. var step = 1 / iteration;
  3247. for (var i = 1; i <= iteration; i++) {
  3248. var t = i * step;
  3249. var x = cubicAt(x0, x1, x2, x3, t);
  3250. var y = cubicAt(y0, y1, y2, y3, t);
  3251. var dx = x - px;
  3252. var dy = y - py;
  3253. d += Math.sqrt(dx * dx + dy * dy);
  3254. px = x;
  3255. py = y;
  3256. }
  3257. return d;
  3258. }
  3259. function quadraticAt(p0, p1, p2, t) {
  3260. var onet = 1 - t;
  3261. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  3262. }
  3263. function quadraticDerivativeAt(p0, p1, p2, t) {
  3264. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  3265. }
  3266. function quadraticRootAt(p0, p1, p2, val, roots) {
  3267. var a = p0 - 2 * p1 + p2;
  3268. var b = 2 * (p1 - p0);
  3269. var c = p0 - val;
  3270. var n = 0;
  3271. if (isAroundZero(a)) {
  3272. if (isNotAroundZero(b)) {
  3273. var t1 = -c / b;
  3274. if (t1 >= 0 && t1 <= 1) {
  3275. roots[n++] = t1;
  3276. }
  3277. }
  3278. }
  3279. else {
  3280. var disc = b * b - 4 * a * c;
  3281. if (isAroundZero(disc)) {
  3282. var t1 = -b / (2 * a);
  3283. if (t1 >= 0 && t1 <= 1) {
  3284. roots[n++] = t1;
  3285. }
  3286. }
  3287. else if (disc > 0) {
  3288. var discSqrt = mathSqrt(disc);
  3289. var t1 = (-b + discSqrt) / (2 * a);
  3290. var t2 = (-b - discSqrt) / (2 * a);
  3291. if (t1 >= 0 && t1 <= 1) {
  3292. roots[n++] = t1;
  3293. }
  3294. if (t2 >= 0 && t2 <= 1) {
  3295. roots[n++] = t2;
  3296. }
  3297. }
  3298. }
  3299. return n;
  3300. }
  3301. function quadraticExtremum(p0, p1, p2) {
  3302. var divider = p0 + p2 - 2 * p1;
  3303. if (divider === 0) {
  3304. return 0.5;
  3305. }
  3306. else {
  3307. return (p0 - p1) / divider;
  3308. }
  3309. }
  3310. function quadraticSubdivide(p0, p1, p2, t, out) {
  3311. var p01 = (p1 - p0) * t + p0;
  3312. var p12 = (p2 - p1) * t + p1;
  3313. var p012 = (p12 - p01) * t + p01;
  3314. out[0] = p0;
  3315. out[1] = p01;
  3316. out[2] = p012;
  3317. out[3] = p012;
  3318. out[4] = p12;
  3319. out[5] = p2;
  3320. }
  3321. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  3322. var t;
  3323. var interval = 0.005;
  3324. var d = Infinity;
  3325. _v0[0] = x;
  3326. _v0[1] = y;
  3327. for (var _t = 0; _t < 1; _t += 0.05) {
  3328. _v1[0] = quadraticAt(x0, x1, x2, _t);
  3329. _v1[1] = quadraticAt(y0, y1, y2, _t);
  3330. var d1 = distSquare(_v0, _v1);
  3331. if (d1 < d) {
  3332. t = _t;
  3333. d = d1;
  3334. }
  3335. }
  3336. d = Infinity;
  3337. for (var i = 0; i < 32; i++) {
  3338. if (interval < EPSILON_NUMERIC) {
  3339. break;
  3340. }
  3341. var prev = t - interval;
  3342. var next = t + interval;
  3343. _v1[0] = quadraticAt(x0, x1, x2, prev);
  3344. _v1[1] = quadraticAt(y0, y1, y2, prev);
  3345. var d1 = distSquare(_v1, _v0);
  3346. if (prev >= 0 && d1 < d) {
  3347. t = prev;
  3348. d = d1;
  3349. }
  3350. else {
  3351. _v2[0] = quadraticAt(x0, x1, x2, next);
  3352. _v2[1] = quadraticAt(y0, y1, y2, next);
  3353. var d2 = distSquare(_v2, _v0);
  3354. if (next <= 1 && d2 < d) {
  3355. t = next;
  3356. d = d2;
  3357. }
  3358. else {
  3359. interval *= 0.5;
  3360. }
  3361. }
  3362. }
  3363. if (out) {
  3364. out[0] = quadraticAt(x0, x1, x2, t);
  3365. out[1] = quadraticAt(y0, y1, y2, t);
  3366. }
  3367. return mathSqrt(d);
  3368. }
  3369. function quadraticLength(x0, y0, x1, y1, x2, y2, iteration) {
  3370. var px = x0;
  3371. var py = y0;
  3372. var d = 0;
  3373. var step = 1 / iteration;
  3374. for (var i = 1; i <= iteration; i++) {
  3375. var t = i * step;
  3376. var x = quadraticAt(x0, x1, x2, t);
  3377. var y = quadraticAt(y0, y1, y2, t);
  3378. var dx = x - px;
  3379. var dy = y - py;
  3380. d += Math.sqrt(dx * dx + dy * dy);
  3381. px = x;
  3382. py = y;
  3383. }
  3384. return d;
  3385. }
  3386. var regexp = /cubic-bezier\(([0-9,\.e ]+)\)/;
  3387. function createCubicEasingFunc(cubicEasingStr) {
  3388. var cubic = cubicEasingStr && regexp.exec(cubicEasingStr);
  3389. if (cubic) {
  3390. var points = cubic[1].split(',');
  3391. var a_1 = +trim(points[0]);
  3392. var b_1 = +trim(points[1]);
  3393. var c_1 = +trim(points[2]);
  3394. var d_1 = +trim(points[3]);
  3395. if (isNaN(a_1 + b_1 + c_1 + d_1)) {
  3396. return;
  3397. }
  3398. var roots_1 = [];
  3399. return function (p) {
  3400. return p <= 0
  3401. ? 0 : p >= 1
  3402. ? 1
  3403. : cubicRootAt(0, a_1, c_1, 1, p, roots_1) && cubicAt(0, b_1, d_1, 1, roots_1[0]);
  3404. };
  3405. }
  3406. }
  3407. var Clip = (function () {
  3408. function Clip(opts) {
  3409. this._inited = false;
  3410. this._startTime = 0;
  3411. this._pausedTime = 0;
  3412. this._paused = false;
  3413. this._life = opts.life || 1000;
  3414. this._delay = opts.delay || 0;
  3415. this.loop = opts.loop || false;
  3416. this.onframe = opts.onframe || noop;
  3417. this.ondestroy = opts.ondestroy || noop;
  3418. this.onrestart = opts.onrestart || noop;
  3419. opts.easing && this.setEasing(opts.easing);
  3420. }
  3421. Clip.prototype.step = function (globalTime, deltaTime) {
  3422. if (!this._inited) {
  3423. this._startTime = globalTime + this._delay;
  3424. this._inited = true;
  3425. }
  3426. if (this._paused) {
  3427. this._pausedTime += deltaTime;
  3428. return;
  3429. }
  3430. var life = this._life;
  3431. var elapsedTime = globalTime - this._startTime - this._pausedTime;
  3432. var percent = elapsedTime / life;
  3433. if (percent < 0) {
  3434. percent = 0;
  3435. }
  3436. percent = Math.min(percent, 1);
  3437. var easingFunc = this.easingFunc;
  3438. var schedule = easingFunc ? easingFunc(percent) : percent;
  3439. this.onframe(schedule);
  3440. if (percent === 1) {
  3441. if (this.loop) {
  3442. var remainder = elapsedTime % life;
  3443. this._startTime = globalTime - remainder;
  3444. this._pausedTime = 0;
  3445. this.onrestart();
  3446. }
  3447. else {
  3448. return true;
  3449. }
  3450. }
  3451. return false;
  3452. };
  3453. Clip.prototype.pause = function () {
  3454. this._paused = true;
  3455. };
  3456. Clip.prototype.resume = function () {
  3457. this._paused = false;
  3458. };
  3459. Clip.prototype.setEasing = function (easing) {
  3460. this.easing = easing;
  3461. this.easingFunc = isFunction(easing)
  3462. ? easing
  3463. : easingFuncs[easing] || createCubicEasingFunc(easing);
  3464. };
  3465. return Clip;
  3466. }());
  3467. var Entry = (function () {
  3468. function Entry(val) {
  3469. this.value = val;
  3470. }
  3471. return Entry;
  3472. }());
  3473. var LinkedList = (function () {
  3474. function LinkedList() {
  3475. this._len = 0;
  3476. }
  3477. LinkedList.prototype.insert = function (val) {
  3478. var entry = new Entry(val);
  3479. this.insertEntry(entry);
  3480. return entry;
  3481. };
  3482. LinkedList.prototype.insertEntry = function (entry) {
  3483. if (!this.head) {
  3484. this.head = this.tail = entry;
  3485. }
  3486. else {
  3487. this.tail.next = entry;
  3488. entry.prev = this.tail;
  3489. entry.next = null;
  3490. this.tail = entry;
  3491. }
  3492. this._len++;
  3493. };
  3494. LinkedList.prototype.remove = function (entry) {
  3495. var prev = entry.prev;
  3496. var next = entry.next;
  3497. if (prev) {
  3498. prev.next = next;
  3499. }
  3500. else {
  3501. this.head = next;
  3502. }
  3503. if (next) {
  3504. next.prev = prev;
  3505. }
  3506. else {
  3507. this.tail = prev;
  3508. }
  3509. entry.next = entry.prev = null;
  3510. this._len--;
  3511. };
  3512. LinkedList.prototype.len = function () {
  3513. return this._len;
  3514. };
  3515. LinkedList.prototype.clear = function () {
  3516. this.head = this.tail = null;
  3517. this._len = 0;
  3518. };
  3519. return LinkedList;
  3520. }());
  3521. var LRU = (function () {
  3522. function LRU(maxSize) {
  3523. this._list = new LinkedList();
  3524. this._maxSize = 10;
  3525. this._map = {};
  3526. this._maxSize = maxSize;
  3527. }
  3528. LRU.prototype.put = function (key, value) {
  3529. var list = this._list;
  3530. var map = this._map;
  3531. var removed = null;
  3532. if (map[key] == null) {
  3533. var len = list.len();
  3534. var entry = this._lastRemovedEntry;
  3535. if (len >= this._maxSize && len > 0) {
  3536. var leastUsedEntry = list.head;
  3537. list.remove(leastUsedEntry);
  3538. delete map[leastUsedEntry.key];
  3539. removed = leastUsedEntry.value;
  3540. this._lastRemovedEntry = leastUsedEntry;
  3541. }
  3542. if (entry) {
  3543. entry.value = value;
  3544. }
  3545. else {
  3546. entry = new Entry(value);
  3547. }
  3548. entry.key = key;
  3549. list.insertEntry(entry);
  3550. map[key] = entry;
  3551. }
  3552. return removed;
  3553. };
  3554. LRU.prototype.get = function (key) {
  3555. var entry = this._map[key];
  3556. var list = this._list;
  3557. if (entry != null) {
  3558. if (entry !== list.tail) {
  3559. list.remove(entry);
  3560. list.insertEntry(entry);
  3561. }
  3562. return entry.value;
  3563. }
  3564. };
  3565. LRU.prototype.clear = function () {
  3566. this._list.clear();
  3567. this._map = {};
  3568. };
  3569. LRU.prototype.len = function () {
  3570. return this._list.len();
  3571. };
  3572. return LRU;
  3573. }());
  3574. var kCSSColorTable = {
  3575. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  3576. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  3577. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  3578. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  3579. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  3580. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  3581. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  3582. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  3583. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  3584. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  3585. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  3586. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  3587. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  3588. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  3589. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  3590. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  3591. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  3592. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  3593. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  3594. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  3595. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  3596. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  3597. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  3598. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  3599. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  3600. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  3601. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  3602. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  3603. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  3604. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  3605. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  3606. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  3607. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  3608. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  3609. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  3610. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  3611. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  3612. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  3613. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  3614. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  3615. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  3616. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  3617. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  3618. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  3619. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  3620. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  3621. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  3622. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  3623. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  3624. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  3625. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  3626. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  3627. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  3628. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  3629. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  3630. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  3631. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  3632. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  3633. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  3634. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  3635. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  3636. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  3637. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  3638. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  3639. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  3640. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  3641. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  3642. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  3643. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  3644. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  3645. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  3646. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  3647. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  3648. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  3649. };
  3650. function clampCssByte(i) {
  3651. i = Math.round(i);
  3652. return i < 0 ? 0 : i > 255 ? 255 : i;
  3653. }
  3654. function clampCssAngle(i) {
  3655. i = Math.round(i);
  3656. return i < 0 ? 0 : i > 360 ? 360 : i;
  3657. }
  3658. function clampCssFloat(f) {
  3659. return f < 0 ? 0 : f > 1 ? 1 : f;
  3660. }
  3661. function parseCssInt(val) {
  3662. var str = val;
  3663. if (str.length && str.charAt(str.length - 1) === '%') {
  3664. return clampCssByte(parseFloat(str) / 100 * 255);
  3665. }
  3666. return clampCssByte(parseInt(str, 10));
  3667. }
  3668. function parseCssFloat(val) {
  3669. var str = val;
  3670. if (str.length && str.charAt(str.length - 1) === '%') {
  3671. return clampCssFloat(parseFloat(str) / 100);
  3672. }
  3673. return clampCssFloat(parseFloat(str));
  3674. }
  3675. function cssHueToRgb(m1, m2, h) {
  3676. if (h < 0) {
  3677. h += 1;
  3678. }
  3679. else if (h > 1) {
  3680. h -= 1;
  3681. }
  3682. if (h * 6 < 1) {
  3683. return m1 + (m2 - m1) * h * 6;
  3684. }
  3685. if (h * 2 < 1) {
  3686. return m2;
  3687. }
  3688. if (h * 3 < 2) {
  3689. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3690. }
  3691. return m1;
  3692. }
  3693. function lerpNumber(a, b, p) {
  3694. return a + (b - a) * p;
  3695. }
  3696. function setRgba(out, r, g, b, a) {
  3697. out[0] = r;
  3698. out[1] = g;
  3699. out[2] = b;
  3700. out[3] = a;
  3701. return out;
  3702. }
  3703. function copyRgba(out, a) {
  3704. out[0] = a[0];
  3705. out[1] = a[1];
  3706. out[2] = a[2];
  3707. out[3] = a[3];
  3708. return out;
  3709. }
  3710. var colorCache = new LRU(20);
  3711. var lastRemovedArr = null;
  3712. function putToCache(colorStr, rgbaArr) {
  3713. if (lastRemovedArr) {
  3714. copyRgba(lastRemovedArr, rgbaArr);
  3715. }
  3716. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  3717. }
  3718. function parse(colorStr, rgbaArr) {
  3719. if (!colorStr) {
  3720. return;
  3721. }
  3722. rgbaArr = rgbaArr || [];
  3723. var cached = colorCache.get(colorStr);
  3724. if (cached) {
  3725. return copyRgba(rgbaArr, cached);
  3726. }
  3727. colorStr = colorStr + '';
  3728. var str = colorStr.replace(/ /g, '').toLowerCase();
  3729. if (str in kCSSColorTable) {
  3730. copyRgba(rgbaArr, kCSSColorTable[str]);
  3731. putToCache(colorStr, rgbaArr);
  3732. return rgbaArr;
  3733. }
  3734. var strLen = str.length;
  3735. if (str.charAt(0) === '#') {
  3736. if (strLen === 4 || strLen === 5) {
  3737. var iv = parseInt(str.slice(1, 4), 16);
  3738. if (!(iv >= 0 && iv <= 0xfff)) {
  3739. setRgba(rgbaArr, 0, 0, 0, 1);
  3740. return;
  3741. }
  3742. 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);
  3743. putToCache(colorStr, rgbaArr);
  3744. return rgbaArr;
  3745. }
  3746. else if (strLen === 7 || strLen === 9) {
  3747. var iv = parseInt(str.slice(1, 7), 16);
  3748. if (!(iv >= 0 && iv <= 0xffffff)) {
  3749. setRgba(rgbaArr, 0, 0, 0, 1);
  3750. return;
  3751. }
  3752. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, strLen === 9 ? parseInt(str.slice(7), 16) / 0xff : 1);
  3753. putToCache(colorStr, rgbaArr);
  3754. return rgbaArr;
  3755. }
  3756. return;
  3757. }
  3758. var op = str.indexOf('(');
  3759. var ep = str.indexOf(')');
  3760. if (op !== -1 && ep + 1 === strLen) {
  3761. var fname = str.substr(0, op);
  3762. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3763. var alpha = 1;
  3764. switch (fname) {
  3765. case 'rgba':
  3766. if (params.length !== 4) {
  3767. return params.length === 3
  3768. ? setRgba(rgbaArr, +params[0], +params[1], +params[2], 1)
  3769. : setRgba(rgbaArr, 0, 0, 0, 1);
  3770. }
  3771. alpha = parseCssFloat(params.pop());
  3772. case 'rgb':
  3773. if (params.length >= 3) {
  3774. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), params.length === 3 ? alpha : parseCssFloat(params[3]));
  3775. putToCache(colorStr, rgbaArr);
  3776. return rgbaArr;
  3777. }
  3778. else {
  3779. setRgba(rgbaArr, 0, 0, 0, 1);
  3780. return;
  3781. }
  3782. case 'hsla':
  3783. if (params.length !== 4) {
  3784. setRgba(rgbaArr, 0, 0, 0, 1);
  3785. return;
  3786. }
  3787. params[3] = parseCssFloat(params[3]);
  3788. hsla2rgba(params, rgbaArr);
  3789. putToCache(colorStr, rgbaArr);
  3790. return rgbaArr;
  3791. case 'hsl':
  3792. if (params.length !== 3) {
  3793. setRgba(rgbaArr, 0, 0, 0, 1);
  3794. return;
  3795. }
  3796. hsla2rgba(params, rgbaArr);
  3797. putToCache(colorStr, rgbaArr);
  3798. return rgbaArr;
  3799. default:
  3800. return;
  3801. }
  3802. }
  3803. setRgba(rgbaArr, 0, 0, 0, 1);
  3804. return;
  3805. }
  3806. function hsla2rgba(hsla, rgba) {
  3807. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360;
  3808. var s = parseCssFloat(hsla[1]);
  3809. var l = parseCssFloat(hsla[2]);
  3810. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  3811. var m1 = l * 2 - m2;
  3812. rgba = rgba || [];
  3813. 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);
  3814. if (hsla.length === 4) {
  3815. rgba[3] = hsla[3];
  3816. }
  3817. return rgba;
  3818. }
  3819. function rgba2hsla(rgba) {
  3820. if (!rgba) {
  3821. return;
  3822. }
  3823. var R = rgba[0] / 255;
  3824. var G = rgba[1] / 255;
  3825. var B = rgba[2] / 255;
  3826. var vMin = Math.min(R, G, B);
  3827. var vMax = Math.max(R, G, B);
  3828. var delta = vMax - vMin;
  3829. var L = (vMax + vMin) / 2;
  3830. var H;
  3831. var S;
  3832. if (delta === 0) {
  3833. H = 0;
  3834. S = 0;
  3835. }
  3836. else {
  3837. if (L < 0.5) {
  3838. S = delta / (vMax + vMin);
  3839. }
  3840. else {
  3841. S = delta / (2 - vMax - vMin);
  3842. }
  3843. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  3844. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  3845. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  3846. if (R === vMax) {
  3847. H = deltaB - deltaG;
  3848. }
  3849. else if (G === vMax) {
  3850. H = (1 / 3) + deltaR - deltaB;
  3851. }
  3852. else if (B === vMax) {
  3853. H = (2 / 3) + deltaG - deltaR;
  3854. }
  3855. if (H < 0) {
  3856. H += 1;
  3857. }
  3858. if (H > 1) {
  3859. H -= 1;
  3860. }
  3861. }
  3862. var hsla = [H * 360, S, L];
  3863. if (rgba[3] != null) {
  3864. hsla.push(rgba[3]);
  3865. }
  3866. return hsla;
  3867. }
  3868. function lift(color, level) {
  3869. var colorArr = parse(color);
  3870. if (colorArr) {
  3871. for (var i = 0; i < 3; i++) {
  3872. if (level < 0) {
  3873. colorArr[i] = colorArr[i] * (1 - level) | 0;
  3874. }
  3875. else {
  3876. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  3877. }
  3878. if (colorArr[i] > 255) {
  3879. colorArr[i] = 255;
  3880. }
  3881. else if (colorArr[i] < 0) {
  3882. colorArr[i] = 0;
  3883. }
  3884. }
  3885. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  3886. }
  3887. }
  3888. function toHex(color) {
  3889. var colorArr = parse(color);
  3890. if (colorArr) {
  3891. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  3892. }
  3893. }
  3894. function fastLerp(normalizedValue, colors, out) {
  3895. if (!(colors && colors.length)
  3896. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3897. return;
  3898. }
  3899. out = out || [];
  3900. var value = normalizedValue * (colors.length - 1);
  3901. var leftIndex = Math.floor(value);
  3902. var rightIndex = Math.ceil(value);
  3903. var leftColor = colors[leftIndex];
  3904. var rightColor = colors[rightIndex];
  3905. var dv = value - leftIndex;
  3906. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  3907. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  3908. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  3909. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  3910. return out;
  3911. }
  3912. var fastMapToColor = fastLerp;
  3913. function lerp$1(normalizedValue, colors, fullOutput) {
  3914. if (!(colors && colors.length)
  3915. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3916. return;
  3917. }
  3918. var value = normalizedValue * (colors.length - 1);
  3919. var leftIndex = Math.floor(value);
  3920. var rightIndex = Math.ceil(value);
  3921. var leftColor = parse(colors[leftIndex]);
  3922. var rightColor = parse(colors[rightIndex]);
  3923. var dv = value - leftIndex;
  3924. var color = stringify([
  3925. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  3926. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  3927. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  3928. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  3929. ], 'rgba');
  3930. return fullOutput
  3931. ? {
  3932. color: color,
  3933. leftIndex: leftIndex,
  3934. rightIndex: rightIndex,
  3935. value: value
  3936. }
  3937. : color;
  3938. }
  3939. var mapToColor = lerp$1;
  3940. function modifyHSL(color, h, s, l) {
  3941. var colorArr = parse(color);
  3942. if (color) {
  3943. colorArr = rgba2hsla(colorArr);
  3944. h != null && (colorArr[0] = clampCssAngle(h));
  3945. s != null && (colorArr[1] = parseCssFloat(s));
  3946. l != null && (colorArr[2] = parseCssFloat(l));
  3947. return stringify(hsla2rgba(colorArr), 'rgba');
  3948. }
  3949. }
  3950. function modifyAlpha(color, alpha) {
  3951. var colorArr = parse(color);
  3952. if (colorArr && alpha != null) {
  3953. colorArr[3] = clampCssFloat(alpha);
  3954. return stringify(colorArr, 'rgba');
  3955. }
  3956. }
  3957. function stringify(arrColor, type) {
  3958. if (!arrColor || !arrColor.length) {
  3959. return;
  3960. }
  3961. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  3962. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  3963. colorStr += ',' + arrColor[3];
  3964. }
  3965. return type + '(' + colorStr + ')';
  3966. }
  3967. function lum(color, backgroundLum) {
  3968. var arr = parse(color);
  3969. return arr
  3970. ? (0.299 * arr[0] + 0.587 * arr[1] + 0.114 * arr[2]) * arr[3] / 255
  3971. + (1 - arr[3]) * backgroundLum
  3972. : 0;
  3973. }
  3974. function random() {
  3975. return stringify([
  3976. Math.round(Math.random() * 255),
  3977. Math.round(Math.random() * 255),
  3978. Math.round(Math.random() * 255)
  3979. ], 'rgb');
  3980. }
  3981. var color = /*#__PURE__*/Object.freeze({
  3982. __proto__: null,
  3983. parse: parse,
  3984. lift: lift,
  3985. toHex: toHex,
  3986. fastLerp: fastLerp,
  3987. fastMapToColor: fastMapToColor,
  3988. lerp: lerp$1,
  3989. mapToColor: mapToColor,
  3990. modifyHSL: modifyHSL,
  3991. modifyAlpha: modifyAlpha,
  3992. stringify: stringify,
  3993. lum: lum,
  3994. random: random
  3995. });
  3996. var mathRound = Math.round;
  3997. function normalizeColor(color) {
  3998. var opacity;
  3999. if (!color || color === 'transparent') {
  4000. color = 'none';
  4001. }
  4002. else if (typeof color === 'string' && color.indexOf('rgba') > -1) {
  4003. var arr = parse(color);
  4004. if (arr) {
  4005. color = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')';
  4006. opacity = arr[3];
  4007. }
  4008. }
  4009. return {
  4010. color: color,
  4011. opacity: opacity == null ? 1 : opacity
  4012. };
  4013. }
  4014. var EPSILON$1 = 1e-4;
  4015. function isAroundZero$1(transform) {
  4016. return transform < EPSILON$1 && transform > -EPSILON$1;
  4017. }
  4018. function round3(transform) {
  4019. return mathRound(transform * 1e3) / 1e3;
  4020. }
  4021. function round4(transform) {
  4022. return mathRound(transform * 1e4) / 1e4;
  4023. }
  4024. function getMatrixStr(m) {
  4025. return 'matrix('
  4026. + round3(m[0]) + ','
  4027. + round3(m[1]) + ','
  4028. + round3(m[2]) + ','
  4029. + round3(m[3]) + ','
  4030. + round4(m[4]) + ','
  4031. + round4(m[5])
  4032. + ')';
  4033. }
  4034. var TEXT_ALIGN_TO_ANCHOR = {
  4035. left: 'start',
  4036. right: 'end',
  4037. center: 'middle',
  4038. middle: 'middle'
  4039. };
  4040. function adjustTextY(y, lineHeight, textBaseline) {
  4041. if (textBaseline === 'top') {
  4042. y += lineHeight / 2;
  4043. }
  4044. else if (textBaseline === 'bottom') {
  4045. y -= lineHeight / 2;
  4046. }
  4047. return y;
  4048. }
  4049. function hasShadow(style) {
  4050. return style
  4051. && (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY);
  4052. }
  4053. function getShadowKey(displayable) {
  4054. var style = displayable.style;
  4055. var globalScale = displayable.getGlobalScale();
  4056. return [
  4057. style.shadowColor,
  4058. (style.shadowBlur || 0).toFixed(2),
  4059. (style.shadowOffsetX || 0).toFixed(2),
  4060. (style.shadowOffsetY || 0).toFixed(2),
  4061. globalScale[0],
  4062. globalScale[1]
  4063. ].join(',');
  4064. }
  4065. function isImagePattern(val) {
  4066. return val && (!!val.image);
  4067. }
  4068. function isSVGPattern(val) {
  4069. return val && (!!val.svgElement);
  4070. }
  4071. function isPattern(val) {
  4072. return isImagePattern(val) || isSVGPattern(val);
  4073. }
  4074. function isLinearGradient(val) {
  4075. return val.type === 'linear';
  4076. }
  4077. function isRadialGradient(val) {
  4078. return val.type === 'radial';
  4079. }
  4080. function isGradient(val) {
  4081. return val && (val.type === 'linear'
  4082. || val.type === 'radial');
  4083. }
  4084. function getIdURL(id) {
  4085. return "url(#" + id + ")";
  4086. }
  4087. function getPathPrecision(el) {
  4088. var scale = el.getGlobalScale();
  4089. var size = Math.max(scale[0], scale[1]);
  4090. return Math.max(Math.ceil(Math.log(size) / Math.log(10)), 1);
  4091. }
  4092. function getSRTTransformString(transform) {
  4093. var x = transform.x || 0;
  4094. var y = transform.y || 0;
  4095. var rotation = (transform.rotation || 0) * RADIAN_TO_DEGREE;
  4096. var scaleX = retrieve2(transform.scaleX, 1);
  4097. var scaleY = retrieve2(transform.scaleY, 1);
  4098. var skewX = transform.skewX || 0;
  4099. var skewY = transform.skewY || 0;
  4100. var res = [];
  4101. if (x || y) {
  4102. res.push("translate(" + x + "px," + y + "px)");
  4103. }
  4104. if (rotation) {
  4105. res.push("rotate(" + rotation + ")");
  4106. }
  4107. if (scaleX !== 1 || scaleY !== 1) {
  4108. res.push("scale(" + scaleX + "," + scaleY + ")");
  4109. }
  4110. if (skewX || skewY) {
  4111. res.push("skew(" + mathRound(skewX * RADIAN_TO_DEGREE) + "deg, " + mathRound(skewY * RADIAN_TO_DEGREE) + "deg)");
  4112. }
  4113. return res.join(' ');
  4114. }
  4115. var encodeBase64 = (function () {
  4116. if (env.hasGlobalWindow && isFunction(window.btoa)) {
  4117. return function (str) {
  4118. return window.btoa(unescape(str));
  4119. };
  4120. }
  4121. if (typeof Buffer !== 'undefined') {
  4122. return function (str) {
  4123. return Buffer.from(str).toString('base64');
  4124. };
  4125. }
  4126. return function (str) {
  4127. {
  4128. logError('Base64 isn\'t natively supported in the current environment.');
  4129. }
  4130. return null;
  4131. };
  4132. })();
  4133. var arraySlice = Array.prototype.slice;
  4134. function interpolateNumber(p0, p1, percent) {
  4135. return (p1 - p0) * percent + p0;
  4136. }
  4137. function interpolate1DArray(out, p0, p1, percent) {
  4138. var len = p0.length;
  4139. for (var i = 0; i < len; i++) {
  4140. out[i] = interpolateNumber(p0[i], p1[i], percent);
  4141. }
  4142. return out;
  4143. }
  4144. function interpolate2DArray(out, p0, p1, percent) {
  4145. var len = p0.length;
  4146. var len2 = len && p0[0].length;
  4147. for (var i = 0; i < len; i++) {
  4148. if (!out[i]) {
  4149. out[i] = [];
  4150. }
  4151. for (var j = 0; j < len2; j++) {
  4152. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  4153. }
  4154. }
  4155. return out;
  4156. }
  4157. function add1DArray(out, p0, p1, sign) {
  4158. var len = p0.length;
  4159. for (var i = 0; i < len; i++) {
  4160. out[i] = p0[i] + p1[i] * sign;
  4161. }
  4162. return out;
  4163. }
  4164. function add2DArray(out, p0, p1, sign) {
  4165. var len = p0.length;
  4166. var len2 = len && p0[0].length;
  4167. for (var i = 0; i < len; i++) {
  4168. if (!out[i]) {
  4169. out[i] = [];
  4170. }
  4171. for (var j = 0; j < len2; j++) {
  4172. out[i][j] = p0[i][j] + p1[i][j] * sign;
  4173. }
  4174. }
  4175. return out;
  4176. }
  4177. function fillColorStops(val0, val1) {
  4178. var len0 = val0.length;
  4179. var len1 = val1.length;
  4180. var shorterArr = len0 > len1 ? val1 : val0;
  4181. var shorterLen = Math.min(len0, len1);
  4182. var last = shorterArr[shorterLen - 1] || { color: [0, 0, 0, 0], offset: 0 };
  4183. for (var i = shorterLen; i < Math.max(len0, len1); i++) {
  4184. shorterArr.push({
  4185. offset: last.offset,
  4186. color: last.color.slice()
  4187. });
  4188. }
  4189. }
  4190. function fillArray(val0, val1, arrDim) {
  4191. var arr0 = val0;
  4192. var arr1 = val1;
  4193. if (!arr0.push || !arr1.push) {
  4194. return;
  4195. }
  4196. var arr0Len = arr0.length;
  4197. var arr1Len = arr1.length;
  4198. if (arr0Len !== arr1Len) {
  4199. var isPreviousLarger = arr0Len > arr1Len;
  4200. if (isPreviousLarger) {
  4201. arr0.length = arr1Len;
  4202. }
  4203. else {
  4204. for (var i = arr0Len; i < arr1Len; i++) {
  4205. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  4206. }
  4207. }
  4208. }
  4209. var len2 = arr0[0] && arr0[0].length;
  4210. for (var i = 0; i < arr0.length; i++) {
  4211. if (arrDim === 1) {
  4212. if (isNaN(arr0[i])) {
  4213. arr0[i] = arr1[i];
  4214. }
  4215. }
  4216. else {
  4217. for (var j = 0; j < len2; j++) {
  4218. if (isNaN(arr0[i][j])) {
  4219. arr0[i][j] = arr1[i][j];
  4220. }
  4221. }
  4222. }
  4223. }
  4224. }
  4225. function cloneValue(value) {
  4226. if (isArrayLike(value)) {
  4227. var len = value.length;
  4228. if (isArrayLike(value[0])) {
  4229. var ret = [];
  4230. for (var i = 0; i < len; i++) {
  4231. ret.push(arraySlice.call(value[i]));
  4232. }
  4233. return ret;
  4234. }
  4235. return arraySlice.call(value);
  4236. }
  4237. return value;
  4238. }
  4239. function rgba2String(rgba) {
  4240. rgba[0] = Math.floor(rgba[0]) || 0;
  4241. rgba[1] = Math.floor(rgba[1]) || 0;
  4242. rgba[2] = Math.floor(rgba[2]) || 0;
  4243. rgba[3] = rgba[3] == null ? 1 : rgba[3];
  4244. return 'rgba(' + rgba.join(',') + ')';
  4245. }
  4246. function guessArrayDim(value) {
  4247. return isArrayLike(value && value[0]) ? 2 : 1;
  4248. }
  4249. var VALUE_TYPE_NUMBER = 0;
  4250. var VALUE_TYPE_1D_ARRAY = 1;
  4251. var VALUE_TYPE_2D_ARRAY = 2;
  4252. var VALUE_TYPE_COLOR = 3;
  4253. var VALUE_TYPE_LINEAR_GRADIENT = 4;
  4254. var VALUE_TYPE_RADIAL_GRADIENT = 5;
  4255. var VALUE_TYPE_UNKOWN = 6;
  4256. function isGradientValueType(valType) {
  4257. return valType === VALUE_TYPE_LINEAR_GRADIENT || valType === VALUE_TYPE_RADIAL_GRADIENT;
  4258. }
  4259. function isArrayValueType(valType) {
  4260. return valType === VALUE_TYPE_1D_ARRAY || valType === VALUE_TYPE_2D_ARRAY;
  4261. }
  4262. var tmpRgba = [0, 0, 0, 0];
  4263. var Track = (function () {
  4264. function Track(propName) {
  4265. this.keyframes = [];
  4266. this.discrete = false;
  4267. this._invalid = false;
  4268. this._needsSort = false;
  4269. this._lastFr = 0;
  4270. this._lastFrP = 0;
  4271. this.propName = propName;
  4272. }
  4273. Track.prototype.isFinished = function () {
  4274. return this._finished;
  4275. };
  4276. Track.prototype.setFinished = function () {
  4277. this._finished = true;
  4278. if (this._additiveTrack) {
  4279. this._additiveTrack.setFinished();
  4280. }
  4281. };
  4282. Track.prototype.needsAnimate = function () {
  4283. return this.keyframes.length >= 1;
  4284. };
  4285. Track.prototype.getAdditiveTrack = function () {
  4286. return this._additiveTrack;
  4287. };
  4288. Track.prototype.addKeyframe = function (time, rawValue, easing) {
  4289. this._needsSort = true;
  4290. var keyframes = this.keyframes;
  4291. var len = keyframes.length;
  4292. var discrete = false;
  4293. var valType = VALUE_TYPE_UNKOWN;
  4294. var value = rawValue;
  4295. if (isArrayLike(rawValue)) {
  4296. var arrayDim = guessArrayDim(rawValue);
  4297. valType = arrayDim;
  4298. if (arrayDim === 1 && !isNumber(rawValue[0])
  4299. || arrayDim === 2 && !isNumber(rawValue[0][0])) {
  4300. discrete = true;
  4301. }
  4302. }
  4303. else {
  4304. if (isNumber(rawValue) && !eqNaN(rawValue)) {
  4305. valType = VALUE_TYPE_NUMBER;
  4306. }
  4307. else if (isString(rawValue)) {
  4308. if (!isNaN(+rawValue)) {
  4309. valType = VALUE_TYPE_NUMBER;
  4310. }
  4311. else {
  4312. var colorArray = parse(rawValue);
  4313. if (colorArray) {
  4314. value = colorArray;
  4315. valType = VALUE_TYPE_COLOR;
  4316. }
  4317. }
  4318. }
  4319. else if (isGradientObject(rawValue)) {
  4320. var parsedGradient = extend({}, value);
  4321. parsedGradient.colorStops = map(rawValue.colorStops, function (colorStop) { return ({
  4322. offset: colorStop.offset,
  4323. color: parse(colorStop.color)
  4324. }); });
  4325. if (isLinearGradient(rawValue)) {
  4326. valType = VALUE_TYPE_LINEAR_GRADIENT;
  4327. }
  4328. else if (isRadialGradient(rawValue)) {
  4329. valType = VALUE_TYPE_RADIAL_GRADIENT;
  4330. }
  4331. value = parsedGradient;
  4332. }
  4333. }
  4334. if (len === 0) {
  4335. this.valType = valType;
  4336. }
  4337. else if (valType !== this.valType || valType === VALUE_TYPE_UNKOWN) {
  4338. discrete = true;
  4339. }
  4340. this.discrete = this.discrete || discrete;
  4341. var kf = {
  4342. time: time,
  4343. value: value,
  4344. rawValue: rawValue,
  4345. percent: 0
  4346. };
  4347. if (easing) {
  4348. kf.easing = easing;
  4349. kf.easingFunc = isFunction(easing)
  4350. ? easing
  4351. : easingFuncs[easing] || createCubicEasingFunc(easing);
  4352. }
  4353. keyframes.push(kf);
  4354. return kf;
  4355. };
  4356. Track.prototype.prepare = function (maxTime, additiveTrack) {
  4357. var kfs = this.keyframes;
  4358. if (this._needsSort) {
  4359. kfs.sort(function (a, b) {
  4360. return a.time - b.time;
  4361. });
  4362. }
  4363. var valType = this.valType;
  4364. var kfsLen = kfs.length;
  4365. var lastKf = kfs[kfsLen - 1];
  4366. var isDiscrete = this.discrete;
  4367. var isArr = isArrayValueType(valType);
  4368. var isGradient = isGradientValueType(valType);
  4369. for (var i = 0; i < kfsLen; i++) {
  4370. var kf = kfs[i];
  4371. var value = kf.value;
  4372. var lastValue = lastKf.value;
  4373. kf.percent = kf.time / maxTime;
  4374. if (!isDiscrete) {
  4375. if (isArr && i !== kfsLen - 1) {
  4376. fillArray(value, lastValue, valType);
  4377. }
  4378. else if (isGradient) {
  4379. fillColorStops(value.colorStops, lastValue.colorStops);
  4380. }
  4381. }
  4382. }
  4383. if (!isDiscrete
  4384. && valType !== VALUE_TYPE_RADIAL_GRADIENT
  4385. && additiveTrack
  4386. && this.needsAnimate()
  4387. && additiveTrack.needsAnimate()
  4388. && valType === additiveTrack.valType
  4389. && !additiveTrack._finished) {
  4390. this._additiveTrack = additiveTrack;
  4391. var startValue = kfs[0].value;
  4392. for (var i = 0; i < kfsLen; i++) {
  4393. if (valType === VALUE_TYPE_NUMBER) {
  4394. kfs[i].additiveValue = kfs[i].value - startValue;
  4395. }
  4396. else if (valType === VALUE_TYPE_COLOR) {
  4397. kfs[i].additiveValue =
  4398. add1DArray([], kfs[i].value, startValue, -1);
  4399. }
  4400. else if (isArrayValueType(valType)) {
  4401. kfs[i].additiveValue = valType === VALUE_TYPE_1D_ARRAY
  4402. ? add1DArray([], kfs[i].value, startValue, -1)
  4403. : add2DArray([], kfs[i].value, startValue, -1);
  4404. }
  4405. }
  4406. }
  4407. };
  4408. Track.prototype.step = function (target, percent) {
  4409. if (this._finished) {
  4410. return;
  4411. }
  4412. if (this._additiveTrack && this._additiveTrack._finished) {
  4413. this._additiveTrack = null;
  4414. }
  4415. var isAdditive = this._additiveTrack != null;
  4416. var valueKey = isAdditive ? 'additiveValue' : 'value';
  4417. var valType = this.valType;
  4418. var keyframes = this.keyframes;
  4419. var kfsNum = keyframes.length;
  4420. var propName = this.propName;
  4421. var isValueColor = valType === VALUE_TYPE_COLOR;
  4422. var frameIdx;
  4423. var lastFrame = this._lastFr;
  4424. var mathMin = Math.min;
  4425. var frame;
  4426. var nextFrame;
  4427. if (kfsNum === 1) {
  4428. frame = nextFrame = keyframes[0];
  4429. }
  4430. else {
  4431. if (percent < 0) {
  4432. frameIdx = 0;
  4433. }
  4434. else if (percent < this._lastFrP) {
  4435. var start = mathMin(lastFrame + 1, kfsNum - 1);
  4436. for (frameIdx = start; frameIdx >= 0; frameIdx--) {
  4437. if (keyframes[frameIdx].percent <= percent) {
  4438. break;
  4439. }
  4440. }
  4441. frameIdx = mathMin(frameIdx, kfsNum - 2);
  4442. }
  4443. else {
  4444. for (frameIdx = lastFrame; frameIdx < kfsNum; frameIdx++) {
  4445. if (keyframes[frameIdx].percent > percent) {
  4446. break;
  4447. }
  4448. }
  4449. frameIdx = mathMin(frameIdx - 1, kfsNum - 2);
  4450. }
  4451. nextFrame = keyframes[frameIdx + 1];
  4452. frame = keyframes[frameIdx];
  4453. }
  4454. if (!(frame && nextFrame)) {
  4455. return;
  4456. }
  4457. this._lastFr = frameIdx;
  4458. this._lastFrP = percent;
  4459. var interval = (nextFrame.percent - frame.percent);
  4460. var w = interval === 0 ? 1 : mathMin((percent - frame.percent) / interval, 1);
  4461. if (nextFrame.easingFunc) {
  4462. w = nextFrame.easingFunc(w);
  4463. }
  4464. var targetArr = isAdditive ? this._additiveValue
  4465. : (isValueColor ? tmpRgba : target[propName]);
  4466. if ((isArrayValueType(valType) || isValueColor) && !targetArr) {
  4467. targetArr = this._additiveValue = [];
  4468. }
  4469. if (this.discrete) {
  4470. target[propName] = w < 1 ? frame.rawValue : nextFrame.rawValue;
  4471. }
  4472. else if (isArrayValueType(valType)) {
  4473. valType === VALUE_TYPE_1D_ARRAY
  4474. ? interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w)
  4475. : interpolate2DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4476. }
  4477. else if (isGradientValueType(valType)) {
  4478. var val = frame[valueKey];
  4479. var nextVal_1 = nextFrame[valueKey];
  4480. var isLinearGradient_1 = valType === VALUE_TYPE_LINEAR_GRADIENT;
  4481. target[propName] = {
  4482. type: isLinearGradient_1 ? 'linear' : 'radial',
  4483. x: interpolateNumber(val.x, nextVal_1.x, w),
  4484. y: interpolateNumber(val.y, nextVal_1.y, w),
  4485. colorStops: map(val.colorStops, function (colorStop, idx) {
  4486. var nextColorStop = nextVal_1.colorStops[idx];
  4487. return {
  4488. offset: interpolateNumber(colorStop.offset, nextColorStop.offset, w),
  4489. color: rgba2String(interpolate1DArray([], colorStop.color, nextColorStop.color, w))
  4490. };
  4491. }),
  4492. global: nextVal_1.global
  4493. };
  4494. if (isLinearGradient_1) {
  4495. target[propName].x2 = interpolateNumber(val.x2, nextVal_1.x2, w);
  4496. target[propName].y2 = interpolateNumber(val.y2, nextVal_1.y2, w);
  4497. }
  4498. else {
  4499. target[propName].r = interpolateNumber(val.r, nextVal_1.r, w);
  4500. }
  4501. }
  4502. else if (isValueColor) {
  4503. interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4504. if (!isAdditive) {
  4505. target[propName] = rgba2String(targetArr);
  4506. }
  4507. }
  4508. else {
  4509. var value = interpolateNumber(frame[valueKey], nextFrame[valueKey], w);
  4510. if (isAdditive) {
  4511. this._additiveValue = value;
  4512. }
  4513. else {
  4514. target[propName] = value;
  4515. }
  4516. }
  4517. if (isAdditive) {
  4518. this._addToTarget(target);
  4519. }
  4520. };
  4521. Track.prototype._addToTarget = function (target) {
  4522. var valType = this.valType;
  4523. var propName = this.propName;
  4524. var additiveValue = this._additiveValue;
  4525. if (valType === VALUE_TYPE_NUMBER) {
  4526. target[propName] = target[propName] + additiveValue;
  4527. }
  4528. else if (valType === VALUE_TYPE_COLOR) {
  4529. parse(target[propName], tmpRgba);
  4530. add1DArray(tmpRgba, tmpRgba, additiveValue, 1);
  4531. target[propName] = rgba2String(tmpRgba);
  4532. }
  4533. else if (valType === VALUE_TYPE_1D_ARRAY) {
  4534. add1DArray(target[propName], target[propName], additiveValue, 1);
  4535. }
  4536. else if (valType === VALUE_TYPE_2D_ARRAY) {
  4537. add2DArray(target[propName], target[propName], additiveValue, 1);
  4538. }
  4539. };
  4540. return Track;
  4541. }());
  4542. var Animator = (function () {
  4543. function Animator(target, loop, allowDiscreteAnimation, additiveTo) {
  4544. this._tracks = {};
  4545. this._trackKeys = [];
  4546. this._maxTime = 0;
  4547. this._started = 0;
  4548. this._clip = null;
  4549. this._target = target;
  4550. this._loop = loop;
  4551. if (loop && additiveTo) {
  4552. logError('Can\' use additive animation on looped animation.');
  4553. return;
  4554. }
  4555. this._additiveAnimators = additiveTo;
  4556. this._allowDiscrete = allowDiscreteAnimation;
  4557. }
  4558. Animator.prototype.getMaxTime = function () {
  4559. return this._maxTime;
  4560. };
  4561. Animator.prototype.getDelay = function () {
  4562. return this._delay;
  4563. };
  4564. Animator.prototype.getLoop = function () {
  4565. return this._loop;
  4566. };
  4567. Animator.prototype.getTarget = function () {
  4568. return this._target;
  4569. };
  4570. Animator.prototype.changeTarget = function (target) {
  4571. this._target = target;
  4572. };
  4573. Animator.prototype.when = function (time, props, easing) {
  4574. return this.whenWithKeys(time, props, keys(props), easing);
  4575. };
  4576. Animator.prototype.whenWithKeys = function (time, props, propNames, easing) {
  4577. var tracks = this._tracks;
  4578. for (var i = 0; i < propNames.length; i++) {
  4579. var propName = propNames[i];
  4580. var track = tracks[propName];
  4581. if (!track) {
  4582. track = tracks[propName] = new Track(propName);
  4583. var initialValue = void 0;
  4584. var additiveTrack = this._getAdditiveTrack(propName);
  4585. if (additiveTrack) {
  4586. var addtiveTrackKfs = additiveTrack.keyframes;
  4587. var lastFinalKf = addtiveTrackKfs[addtiveTrackKfs.length - 1];
  4588. initialValue = lastFinalKf && lastFinalKf.value;
  4589. if (additiveTrack.valType === VALUE_TYPE_COLOR && initialValue) {
  4590. initialValue = rgba2String(initialValue);
  4591. }
  4592. }
  4593. else {
  4594. initialValue = this._target[propName];
  4595. }
  4596. if (initialValue == null) {
  4597. continue;
  4598. }
  4599. if (time > 0) {
  4600. track.addKeyframe(0, cloneValue(initialValue), easing);
  4601. }
  4602. this._trackKeys.push(propName);
  4603. }
  4604. track.addKeyframe(time, cloneValue(props[propName]), easing);
  4605. }
  4606. this._maxTime = Math.max(this._maxTime, time);
  4607. return this;
  4608. };
  4609. Animator.prototype.pause = function () {
  4610. this._clip.pause();
  4611. this._paused = true;
  4612. };
  4613. Animator.prototype.resume = function () {
  4614. this._clip.resume();
  4615. this._paused = false;
  4616. };
  4617. Animator.prototype.isPaused = function () {
  4618. return !!this._paused;
  4619. };
  4620. Animator.prototype.duration = function (duration) {
  4621. this._maxTime = duration;
  4622. this._force = true;
  4623. return this;
  4624. };
  4625. Animator.prototype._doneCallback = function () {
  4626. this._setTracksFinished();
  4627. this._clip = null;
  4628. var doneList = this._doneCbs;
  4629. if (doneList) {
  4630. var len = doneList.length;
  4631. for (var i = 0; i < len; i++) {
  4632. doneList[i].call(this);
  4633. }
  4634. }
  4635. };
  4636. Animator.prototype._abortedCallback = function () {
  4637. this._setTracksFinished();
  4638. var animation = this.animation;
  4639. var abortedList = this._abortedCbs;
  4640. if (animation) {
  4641. animation.removeClip(this._clip);
  4642. }
  4643. this._clip = null;
  4644. if (abortedList) {
  4645. for (var i = 0; i < abortedList.length; i++) {
  4646. abortedList[i].call(this);
  4647. }
  4648. }
  4649. };
  4650. Animator.prototype._setTracksFinished = function () {
  4651. var tracks = this._tracks;
  4652. var tracksKeys = this._trackKeys;
  4653. for (var i = 0; i < tracksKeys.length; i++) {
  4654. tracks[tracksKeys[i]].setFinished();
  4655. }
  4656. };
  4657. Animator.prototype._getAdditiveTrack = function (trackName) {
  4658. var additiveTrack;
  4659. var additiveAnimators = this._additiveAnimators;
  4660. if (additiveAnimators) {
  4661. for (var i = 0; i < additiveAnimators.length; i++) {
  4662. var track = additiveAnimators[i].getTrack(trackName);
  4663. if (track) {
  4664. additiveTrack = track;
  4665. }
  4666. }
  4667. }
  4668. return additiveTrack;
  4669. };
  4670. Animator.prototype.start = function (easing) {
  4671. if (this._started > 0) {
  4672. return;
  4673. }
  4674. this._started = 1;
  4675. var self = this;
  4676. var tracks = [];
  4677. var maxTime = this._maxTime || 0;
  4678. for (var i = 0; i < this._trackKeys.length; i++) {
  4679. var propName = this._trackKeys[i];
  4680. var track = this._tracks[propName];
  4681. var additiveTrack = this._getAdditiveTrack(propName);
  4682. var kfs = track.keyframes;
  4683. var kfsNum = kfs.length;
  4684. track.prepare(maxTime, additiveTrack);
  4685. if (track.needsAnimate()) {
  4686. if (!this._allowDiscrete && track.discrete) {
  4687. var lastKf = kfs[kfsNum - 1];
  4688. if (lastKf) {
  4689. self._target[track.propName] = lastKf.rawValue;
  4690. }
  4691. track.setFinished();
  4692. }
  4693. else {
  4694. tracks.push(track);
  4695. }
  4696. }
  4697. }
  4698. if (tracks.length || this._force) {
  4699. var clip = new Clip({
  4700. life: maxTime,
  4701. loop: this._loop,
  4702. delay: this._delay || 0,
  4703. onframe: function (percent) {
  4704. self._started = 2;
  4705. var additiveAnimators = self._additiveAnimators;
  4706. if (additiveAnimators) {
  4707. var stillHasAdditiveAnimator = false;
  4708. for (var i = 0; i < additiveAnimators.length; i++) {
  4709. if (additiveAnimators[i]._clip) {
  4710. stillHasAdditiveAnimator = true;
  4711. break;
  4712. }
  4713. }
  4714. if (!stillHasAdditiveAnimator) {
  4715. self._additiveAnimators = null;
  4716. }
  4717. }
  4718. for (var i = 0; i < tracks.length; i++) {
  4719. tracks[i].step(self._target, percent);
  4720. }
  4721. var onframeList = self._onframeCbs;
  4722. if (onframeList) {
  4723. for (var i = 0; i < onframeList.length; i++) {
  4724. onframeList[i](self._target, percent);
  4725. }
  4726. }
  4727. },
  4728. ondestroy: function () {
  4729. self._doneCallback();
  4730. }
  4731. });
  4732. this._clip = clip;
  4733. if (this.animation) {
  4734. this.animation.addClip(clip);
  4735. }
  4736. if (easing) {
  4737. clip.setEasing(easing);
  4738. }
  4739. }
  4740. else {
  4741. this._doneCallback();
  4742. }
  4743. return this;
  4744. };
  4745. Animator.prototype.stop = function (forwardToLast) {
  4746. if (!this._clip) {
  4747. return;
  4748. }
  4749. var clip = this._clip;
  4750. if (forwardToLast) {
  4751. clip.onframe(1);
  4752. }
  4753. this._abortedCallback();
  4754. };
  4755. Animator.prototype.delay = function (time) {
  4756. this._delay = time;
  4757. return this;
  4758. };
  4759. Animator.prototype.during = function (cb) {
  4760. if (cb) {
  4761. if (!this._onframeCbs) {
  4762. this._onframeCbs = [];
  4763. }
  4764. this._onframeCbs.push(cb);
  4765. }
  4766. return this;
  4767. };
  4768. Animator.prototype.done = function (cb) {
  4769. if (cb) {
  4770. if (!this._doneCbs) {
  4771. this._doneCbs = [];
  4772. }
  4773. this._doneCbs.push(cb);
  4774. }
  4775. return this;
  4776. };
  4777. Animator.prototype.aborted = function (cb) {
  4778. if (cb) {
  4779. if (!this._abortedCbs) {
  4780. this._abortedCbs = [];
  4781. }
  4782. this._abortedCbs.push(cb);
  4783. }
  4784. return this;
  4785. };
  4786. Animator.prototype.getClip = function () {
  4787. return this._clip;
  4788. };
  4789. Animator.prototype.getTrack = function (propName) {
  4790. return this._tracks[propName];
  4791. };
  4792. Animator.prototype.getTracks = function () {
  4793. var _this = this;
  4794. return map(this._trackKeys, function (key) { return _this._tracks[key]; });
  4795. };
  4796. Animator.prototype.stopTracks = function (propNames, forwardToLast) {
  4797. if (!propNames.length || !this._clip) {
  4798. return true;
  4799. }
  4800. var tracks = this._tracks;
  4801. var tracksKeys = this._trackKeys;
  4802. for (var i = 0; i < propNames.length; i++) {
  4803. var track = tracks[propNames[i]];
  4804. if (track && !track.isFinished()) {
  4805. if (forwardToLast) {
  4806. track.step(this._target, 1);
  4807. }
  4808. else if (this._started === 1) {
  4809. track.step(this._target, 0);
  4810. }
  4811. track.setFinished();
  4812. }
  4813. }
  4814. var allAborted = true;
  4815. for (var i = 0; i < tracksKeys.length; i++) {
  4816. if (!tracks[tracksKeys[i]].isFinished()) {
  4817. allAborted = false;
  4818. break;
  4819. }
  4820. }
  4821. if (allAborted) {
  4822. this._abortedCallback();
  4823. }
  4824. return allAborted;
  4825. };
  4826. Animator.prototype.saveTo = function (target, trackKeys, firstOrLast) {
  4827. if (!target) {
  4828. return;
  4829. }
  4830. trackKeys = trackKeys || this._trackKeys;
  4831. for (var i = 0; i < trackKeys.length; i++) {
  4832. var propName = trackKeys[i];
  4833. var track = this._tracks[propName];
  4834. if (!track || track.isFinished()) {
  4835. continue;
  4836. }
  4837. var kfs = track.keyframes;
  4838. var kf = kfs[firstOrLast ? 0 : kfs.length - 1];
  4839. if (kf) {
  4840. target[propName] = cloneValue(kf.rawValue);
  4841. }
  4842. }
  4843. };
  4844. Animator.prototype.__changeFinalValue = function (finalProps, trackKeys) {
  4845. trackKeys = trackKeys || keys(finalProps);
  4846. for (var i = 0; i < trackKeys.length; i++) {
  4847. var propName = trackKeys[i];
  4848. var track = this._tracks[propName];
  4849. if (!track) {
  4850. continue;
  4851. }
  4852. var kfs = track.keyframes;
  4853. if (kfs.length > 1) {
  4854. var lastKf = kfs.pop();
  4855. track.addKeyframe(lastKf.time, finalProps[propName]);
  4856. track.prepare(this._maxTime, track.getAdditiveTrack());
  4857. }
  4858. }
  4859. };
  4860. return Animator;
  4861. }());
  4862. function getTime() {
  4863. return new Date().getTime();
  4864. }
  4865. var Animation = (function (_super) {
  4866. __extends(Animation, _super);
  4867. function Animation(opts) {
  4868. var _this = _super.call(this) || this;
  4869. _this._running = false;
  4870. _this._time = 0;
  4871. _this._pausedTime = 0;
  4872. _this._pauseStart = 0;
  4873. _this._paused = false;
  4874. opts = opts || {};
  4875. _this.stage = opts.stage || {};
  4876. return _this;
  4877. }
  4878. Animation.prototype.addClip = function (clip) {
  4879. if (clip.animation) {
  4880. this.removeClip(clip);
  4881. }
  4882. if (!this._head) {
  4883. this._head = this._tail = clip;
  4884. }
  4885. else {
  4886. this._tail.next = clip;
  4887. clip.prev = this._tail;
  4888. clip.next = null;
  4889. this._tail = clip;
  4890. }
  4891. clip.animation = this;
  4892. };
  4893. Animation.prototype.addAnimator = function (animator) {
  4894. animator.animation = this;
  4895. var clip = animator.getClip();
  4896. if (clip) {
  4897. this.addClip(clip);
  4898. }
  4899. };
  4900. Animation.prototype.removeClip = function (clip) {
  4901. if (!clip.animation) {
  4902. return;
  4903. }
  4904. var prev = clip.prev;
  4905. var next = clip.next;
  4906. if (prev) {
  4907. prev.next = next;
  4908. }
  4909. else {
  4910. this._head = next;
  4911. }
  4912. if (next) {
  4913. next.prev = prev;
  4914. }
  4915. else {
  4916. this._tail = prev;
  4917. }
  4918. clip.next = clip.prev = clip.animation = null;
  4919. };
  4920. Animation.prototype.removeAnimator = function (animator) {
  4921. var clip = animator.getClip();
  4922. if (clip) {
  4923. this.removeClip(clip);
  4924. }
  4925. animator.animation = null;
  4926. };
  4927. Animation.prototype.update = function (notTriggerFrameAndStageUpdate) {
  4928. var time = getTime() - this._pausedTime;
  4929. var delta = time - this._time;
  4930. var clip = this._head;
  4931. while (clip) {
  4932. var nextClip = clip.next;
  4933. var finished = clip.step(time, delta);
  4934. if (finished) {
  4935. clip.ondestroy();
  4936. this.removeClip(clip);
  4937. clip = nextClip;
  4938. }
  4939. else {
  4940. clip = nextClip;
  4941. }
  4942. }
  4943. this._time = time;
  4944. if (!notTriggerFrameAndStageUpdate) {
  4945. this.trigger('frame', delta);
  4946. this.stage.update && this.stage.update();
  4947. }
  4948. };
  4949. Animation.prototype._startLoop = function () {
  4950. var self = this;
  4951. this._running = true;
  4952. function step() {
  4953. if (self._running) {
  4954. requestAnimationFrame$1(step);
  4955. !self._paused && self.update();
  4956. }
  4957. }
  4958. requestAnimationFrame$1(step);
  4959. };
  4960. Animation.prototype.start = function () {
  4961. if (this._running) {
  4962. return;
  4963. }
  4964. this._time = getTime();
  4965. this._pausedTime = 0;
  4966. this._startLoop();
  4967. };
  4968. Animation.prototype.stop = function () {
  4969. this._running = false;
  4970. };
  4971. Animation.prototype.pause = function () {
  4972. if (!this._paused) {
  4973. this._pauseStart = getTime();
  4974. this._paused = true;
  4975. }
  4976. };
  4977. Animation.prototype.resume = function () {
  4978. if (this._paused) {
  4979. this._pausedTime += getTime() - this._pauseStart;
  4980. this._paused = false;
  4981. }
  4982. };
  4983. Animation.prototype.clear = function () {
  4984. var clip = this._head;
  4985. while (clip) {
  4986. var nextClip = clip.next;
  4987. clip.prev = clip.next = clip.animation = null;
  4988. clip = nextClip;
  4989. }
  4990. this._head = this._tail = null;
  4991. };
  4992. Animation.prototype.isFinished = function () {
  4993. return this._head == null;
  4994. };
  4995. Animation.prototype.animate = function (target, options) {
  4996. options = options || {};
  4997. this.start();
  4998. var animator = new Animator(target, options.loop);
  4999. this.addAnimator(animator);
  5000. return animator;
  5001. };
  5002. return Animation;
  5003. }(Eventful));
  5004. var TOUCH_CLICK_DELAY = 300;
  5005. var globalEventSupported = env.domSupported;
  5006. var localNativeListenerNames = (function () {
  5007. var mouseHandlerNames = [
  5008. 'click', 'dblclick', 'mousewheel', 'wheel', 'mouseout',
  5009. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  5010. ];
  5011. var touchHandlerNames = [
  5012. 'touchstart', 'touchend', 'touchmove'
  5013. ];
  5014. var pointerEventNameMap = {
  5015. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  5016. };
  5017. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  5018. var nm = name.replace('mouse', 'pointer');
  5019. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  5020. });
  5021. return {
  5022. mouse: mouseHandlerNames,
  5023. touch: touchHandlerNames,
  5024. pointer: pointerHandlerNames
  5025. };
  5026. })();
  5027. var globalNativeListenerNames = {
  5028. mouse: ['mousemove', 'mouseup'],
  5029. pointer: ['pointermove', 'pointerup']
  5030. };
  5031. var wheelEventSupported = false;
  5032. function isPointerFromTouch(event) {
  5033. var pointerType = event.pointerType;
  5034. return pointerType === 'pen' || pointerType === 'touch';
  5035. }
  5036. function setTouchTimer(scope) {
  5037. scope.touching = true;
  5038. if (scope.touchTimer != null) {
  5039. clearTimeout(scope.touchTimer);
  5040. scope.touchTimer = null;
  5041. }
  5042. scope.touchTimer = setTimeout(function () {
  5043. scope.touching = false;
  5044. scope.touchTimer = null;
  5045. }, 700);
  5046. }
  5047. function markTouch(event) {
  5048. event && (event.zrByTouch = true);
  5049. }
  5050. function normalizeGlobalEvent(instance, event) {
  5051. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  5052. }
  5053. function isLocalEl(instance, el) {
  5054. var elTmp = el;
  5055. var isLocal = false;
  5056. while (elTmp && elTmp.nodeType !== 9
  5057. && !(isLocal = elTmp.domBelongToZr
  5058. || (elTmp !== el && elTmp === instance.painterRoot))) {
  5059. elTmp = elTmp.parentNode;
  5060. }
  5061. return isLocal;
  5062. }
  5063. var FakeGlobalEvent = (function () {
  5064. function FakeGlobalEvent(instance, event) {
  5065. this.stopPropagation = noop;
  5066. this.stopImmediatePropagation = noop;
  5067. this.preventDefault = noop;
  5068. this.type = event.type;
  5069. this.target = this.currentTarget = instance.dom;
  5070. this.pointerType = event.pointerType;
  5071. this.clientX = event.clientX;
  5072. this.clientY = event.clientY;
  5073. }
  5074. return FakeGlobalEvent;
  5075. }());
  5076. var localDOMHandlers = {
  5077. mousedown: function (event) {
  5078. event = normalizeEvent(this.dom, event);
  5079. this.__mayPointerCapture = [event.zrX, event.zrY];
  5080. this.trigger('mousedown', event);
  5081. },
  5082. mousemove: function (event) {
  5083. event = normalizeEvent(this.dom, event);
  5084. var downPoint = this.__mayPointerCapture;
  5085. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  5086. this.__togglePointerCapture(true);
  5087. }
  5088. this.trigger('mousemove', event);
  5089. },
  5090. mouseup: function (event) {
  5091. event = normalizeEvent(this.dom, event);
  5092. this.__togglePointerCapture(false);
  5093. this.trigger('mouseup', event);
  5094. },
  5095. mouseout: function (event) {
  5096. event = normalizeEvent(this.dom, event);
  5097. var element = event.toElement || event.relatedTarget;
  5098. if (!isLocalEl(this, element)) {
  5099. if (this.__pointerCapturing) {
  5100. event.zrEventControl = 'no_globalout';
  5101. }
  5102. this.trigger('mouseout', event);
  5103. }
  5104. },
  5105. wheel: function (event) {
  5106. wheelEventSupported = true;
  5107. event = normalizeEvent(this.dom, event);
  5108. this.trigger('mousewheel', event);
  5109. },
  5110. mousewheel: function (event) {
  5111. if (wheelEventSupported) {
  5112. return;
  5113. }
  5114. event = normalizeEvent(this.dom, event);
  5115. this.trigger('mousewheel', event);
  5116. },
  5117. touchstart: function (event) {
  5118. event = normalizeEvent(this.dom, event);
  5119. markTouch(event);
  5120. this.__lastTouchMoment = new Date();
  5121. this.handler.processGesture(event, 'start');
  5122. localDOMHandlers.mousemove.call(this, event);
  5123. localDOMHandlers.mousedown.call(this, event);
  5124. },
  5125. touchmove: function (event) {
  5126. event = normalizeEvent(this.dom, event);
  5127. markTouch(event);
  5128. this.handler.processGesture(event, 'change');
  5129. localDOMHandlers.mousemove.call(this, event);
  5130. },
  5131. touchend: function (event) {
  5132. event = normalizeEvent(this.dom, event);
  5133. markTouch(event);
  5134. this.handler.processGesture(event, 'end');
  5135. localDOMHandlers.mouseup.call(this, event);
  5136. if (+new Date() - (+this.__lastTouchMoment) < TOUCH_CLICK_DELAY) {
  5137. localDOMHandlers.click.call(this, event);
  5138. }
  5139. },
  5140. pointerdown: function (event) {
  5141. localDOMHandlers.mousedown.call(this, event);
  5142. },
  5143. pointermove: function (event) {
  5144. if (!isPointerFromTouch(event)) {
  5145. localDOMHandlers.mousemove.call(this, event);
  5146. }
  5147. },
  5148. pointerup: function (event) {
  5149. localDOMHandlers.mouseup.call(this, event);
  5150. },
  5151. pointerout: function (event) {
  5152. if (!isPointerFromTouch(event)) {
  5153. localDOMHandlers.mouseout.call(this, event);
  5154. }
  5155. }
  5156. };
  5157. each(['click', 'dblclick', 'contextmenu'], function (name) {
  5158. localDOMHandlers[name] = function (event) {
  5159. event = normalizeEvent(this.dom, event);
  5160. this.trigger(name, event);
  5161. };
  5162. });
  5163. var globalDOMHandlers = {
  5164. pointermove: function (event) {
  5165. if (!isPointerFromTouch(event)) {
  5166. globalDOMHandlers.mousemove.call(this, event);
  5167. }
  5168. },
  5169. pointerup: function (event) {
  5170. globalDOMHandlers.mouseup.call(this, event);
  5171. },
  5172. mousemove: function (event) {
  5173. this.trigger('mousemove', event);
  5174. },
  5175. mouseup: function (event) {
  5176. var pointerCaptureReleasing = this.__pointerCapturing;
  5177. this.__togglePointerCapture(false);
  5178. this.trigger('mouseup', event);
  5179. if (pointerCaptureReleasing) {
  5180. event.zrEventControl = 'only_globalout';
  5181. this.trigger('mouseout', event);
  5182. }
  5183. }
  5184. };
  5185. function mountLocalDOMEventListeners(instance, scope) {
  5186. var domHandlers = scope.domHandlers;
  5187. if (env.pointerEventsSupported) {
  5188. each(localNativeListenerNames.pointer, function (nativeEventName) {
  5189. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5190. domHandlers[nativeEventName].call(instance, event);
  5191. });
  5192. });
  5193. }
  5194. else {
  5195. if (env.touchEventsSupported) {
  5196. each(localNativeListenerNames.touch, function (nativeEventName) {
  5197. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5198. domHandlers[nativeEventName].call(instance, event);
  5199. setTouchTimer(scope);
  5200. });
  5201. });
  5202. }
  5203. each(localNativeListenerNames.mouse, function (nativeEventName) {
  5204. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5205. event = getNativeEvent(event);
  5206. if (!scope.touching) {
  5207. domHandlers[nativeEventName].call(instance, event);
  5208. }
  5209. });
  5210. });
  5211. }
  5212. }
  5213. function mountGlobalDOMEventListeners(instance, scope) {
  5214. if (env.pointerEventsSupported) {
  5215. each(globalNativeListenerNames.pointer, mount);
  5216. }
  5217. else if (!env.touchEventsSupported) {
  5218. each(globalNativeListenerNames.mouse, mount);
  5219. }
  5220. function mount(nativeEventName) {
  5221. function nativeEventListener(event) {
  5222. event = getNativeEvent(event);
  5223. if (!isLocalEl(instance, event.target)) {
  5224. event = normalizeGlobalEvent(instance, event);
  5225. scope.domHandlers[nativeEventName].call(instance, event);
  5226. }
  5227. }
  5228. mountSingleDOMEventListener(scope, nativeEventName, nativeEventListener, { capture: true });
  5229. }
  5230. }
  5231. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  5232. scope.mounted[nativeEventName] = listener;
  5233. scope.listenerOpts[nativeEventName] = opt;
  5234. addEventListener(scope.domTarget, nativeEventName, listener, opt);
  5235. }
  5236. function unmountDOMEventListeners(scope) {
  5237. var mounted = scope.mounted;
  5238. for (var nativeEventName in mounted) {
  5239. if (mounted.hasOwnProperty(nativeEventName)) {
  5240. removeEventListener(scope.domTarget, nativeEventName, mounted[nativeEventName], scope.listenerOpts[nativeEventName]);
  5241. }
  5242. }
  5243. scope.mounted = {};
  5244. }
  5245. var DOMHandlerScope = (function () {
  5246. function DOMHandlerScope(domTarget, domHandlers) {
  5247. this.mounted = {};
  5248. this.listenerOpts = {};
  5249. this.touching = false;
  5250. this.domTarget = domTarget;
  5251. this.domHandlers = domHandlers;
  5252. }
  5253. return DOMHandlerScope;
  5254. }());
  5255. var HandlerDomProxy = (function (_super) {
  5256. __extends(HandlerDomProxy, _super);
  5257. function HandlerDomProxy(dom, painterRoot) {
  5258. var _this = _super.call(this) || this;
  5259. _this.__pointerCapturing = false;
  5260. _this.dom = dom;
  5261. _this.painterRoot = painterRoot;
  5262. _this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  5263. if (globalEventSupported) {
  5264. _this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  5265. }
  5266. mountLocalDOMEventListeners(_this, _this._localHandlerScope);
  5267. return _this;
  5268. }
  5269. HandlerDomProxy.prototype.dispose = function () {
  5270. unmountDOMEventListeners(this._localHandlerScope);
  5271. if (globalEventSupported) {
  5272. unmountDOMEventListeners(this._globalHandlerScope);
  5273. }
  5274. };
  5275. HandlerDomProxy.prototype.setCursor = function (cursorStyle) {
  5276. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  5277. };
  5278. HandlerDomProxy.prototype.__togglePointerCapture = function (isPointerCapturing) {
  5279. this.__mayPointerCapture = null;
  5280. if (globalEventSupported
  5281. && ((+this.__pointerCapturing) ^ (+isPointerCapturing))) {
  5282. this.__pointerCapturing = isPointerCapturing;
  5283. var globalHandlerScope = this._globalHandlerScope;
  5284. isPointerCapturing
  5285. ? mountGlobalDOMEventListeners(this, globalHandlerScope)
  5286. : unmountDOMEventListeners(globalHandlerScope);
  5287. }
  5288. };
  5289. return HandlerDomProxy;
  5290. }(Eventful));
  5291. var dpr = 1;
  5292. if (env.hasGlobalWindow) {
  5293. dpr = Math.max(window.devicePixelRatio
  5294. || (window.screen && window.screen.deviceXDPI / window.screen.logicalXDPI)
  5295. || 1, 1);
  5296. }
  5297. var devicePixelRatio = dpr;
  5298. var DARK_MODE_THRESHOLD = 0.4;
  5299. var DARK_LABEL_COLOR = '#333';
  5300. var LIGHT_LABEL_COLOR = '#ccc';
  5301. var LIGHTER_LABEL_COLOR = '#eee';
  5302. var mIdentity = identity;
  5303. var EPSILON$2 = 5e-5;
  5304. function isNotAroundZero$1(val) {
  5305. return val > EPSILON$2 || val < -EPSILON$2;
  5306. }
  5307. var scaleTmp = [];
  5308. var tmpTransform = [];
  5309. var originTransform = create$1();
  5310. var abs = Math.abs;
  5311. var Transformable = (function () {
  5312. function Transformable() {
  5313. }
  5314. Transformable.prototype.getLocalTransform = function (m) {
  5315. return Transformable.getLocalTransform(this, m);
  5316. };
  5317. Transformable.prototype.setPosition = function (arr) {
  5318. this.x = arr[0];
  5319. this.y = arr[1];
  5320. };
  5321. Transformable.prototype.setScale = function (arr) {
  5322. this.scaleX = arr[0];
  5323. this.scaleY = arr[1];
  5324. };
  5325. Transformable.prototype.setSkew = function (arr) {
  5326. this.skewX = arr[0];
  5327. this.skewY = arr[1];
  5328. };
  5329. Transformable.prototype.setOrigin = function (arr) {
  5330. this.originX = arr[0];
  5331. this.originY = arr[1];
  5332. };
  5333. Transformable.prototype.needLocalTransform = function () {
  5334. return isNotAroundZero$1(this.rotation)
  5335. || isNotAroundZero$1(this.x)
  5336. || isNotAroundZero$1(this.y)
  5337. || isNotAroundZero$1(this.scaleX - 1)
  5338. || isNotAroundZero$1(this.scaleY - 1)
  5339. || isNotAroundZero$1(this.skewX)
  5340. || isNotAroundZero$1(this.skewY);
  5341. };
  5342. Transformable.prototype.updateTransform = function () {
  5343. var parentTransform = this.parent && this.parent.transform;
  5344. var needLocalTransform = this.needLocalTransform();
  5345. var m = this.transform;
  5346. if (!(needLocalTransform || parentTransform)) {
  5347. m && mIdentity(m);
  5348. return;
  5349. }
  5350. m = m || create$1();
  5351. if (needLocalTransform) {
  5352. this.getLocalTransform(m);
  5353. }
  5354. else {
  5355. mIdentity(m);
  5356. }
  5357. if (parentTransform) {
  5358. if (needLocalTransform) {
  5359. mul$1(m, parentTransform, m);
  5360. }
  5361. else {
  5362. copy$1(m, parentTransform);
  5363. }
  5364. }
  5365. this.transform = m;
  5366. this._resolveGlobalScaleRatio(m);
  5367. };
  5368. Transformable.prototype._resolveGlobalScaleRatio = function (m) {
  5369. var globalScaleRatio = this.globalScaleRatio;
  5370. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  5371. this.getGlobalScale(scaleTmp);
  5372. var relX = scaleTmp[0] < 0 ? -1 : 1;
  5373. var relY = scaleTmp[1] < 0 ? -1 : 1;
  5374. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  5375. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  5376. m[0] *= sx;
  5377. m[1] *= sx;
  5378. m[2] *= sy;
  5379. m[3] *= sy;
  5380. }
  5381. this.invTransform = this.invTransform || create$1();
  5382. invert(this.invTransform, m);
  5383. };
  5384. Transformable.prototype.getComputedTransform = function () {
  5385. var transformNode = this;
  5386. var ancestors = [];
  5387. while (transformNode) {
  5388. ancestors.push(transformNode);
  5389. transformNode = transformNode.parent;
  5390. }
  5391. while (transformNode = ancestors.pop()) {
  5392. transformNode.updateTransform();
  5393. }
  5394. return this.transform;
  5395. };
  5396. Transformable.prototype.setLocalTransform = function (m) {
  5397. if (!m) {
  5398. return;
  5399. }
  5400. var sx = m[0] * m[0] + m[1] * m[1];
  5401. var sy = m[2] * m[2] + m[3] * m[3];
  5402. var rotation = Math.atan2(m[1], m[0]);
  5403. var shearX = Math.PI / 2 + rotation - Math.atan2(m[3], m[2]);
  5404. sy = Math.sqrt(sy) * Math.cos(shearX);
  5405. sx = Math.sqrt(sx);
  5406. this.skewX = shearX;
  5407. this.skewY = 0;
  5408. this.rotation = -rotation;
  5409. this.x = +m[4];
  5410. this.y = +m[5];
  5411. this.scaleX = sx;
  5412. this.scaleY = sy;
  5413. this.originX = 0;
  5414. this.originY = 0;
  5415. };
  5416. Transformable.prototype.decomposeTransform = function () {
  5417. if (!this.transform) {
  5418. return;
  5419. }
  5420. var parent = this.parent;
  5421. var m = this.transform;
  5422. if (parent && parent.transform) {
  5423. mul$1(tmpTransform, parent.invTransform, m);
  5424. m = tmpTransform;
  5425. }
  5426. var ox = this.originX;
  5427. var oy = this.originY;
  5428. if (ox || oy) {
  5429. originTransform[4] = ox;
  5430. originTransform[5] = oy;
  5431. mul$1(tmpTransform, m, originTransform);
  5432. tmpTransform[4] -= ox;
  5433. tmpTransform[5] -= oy;
  5434. m = tmpTransform;
  5435. }
  5436. this.setLocalTransform(m);
  5437. };
  5438. Transformable.prototype.getGlobalScale = function (out) {
  5439. var m = this.transform;
  5440. out = out || [];
  5441. if (!m) {
  5442. out[0] = 1;
  5443. out[1] = 1;
  5444. return out;
  5445. }
  5446. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  5447. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  5448. if (m[0] < 0) {
  5449. out[0] = -out[0];
  5450. }
  5451. if (m[3] < 0) {
  5452. out[1] = -out[1];
  5453. }
  5454. return out;
  5455. };
  5456. Transformable.prototype.transformCoordToLocal = function (x, y) {
  5457. var v2 = [x, y];
  5458. var invTransform = this.invTransform;
  5459. if (invTransform) {
  5460. applyTransform(v2, v2, invTransform);
  5461. }
  5462. return v2;
  5463. };
  5464. Transformable.prototype.transformCoordToGlobal = function (x, y) {
  5465. var v2 = [x, y];
  5466. var transform = this.transform;
  5467. if (transform) {
  5468. applyTransform(v2, v2, transform);
  5469. }
  5470. return v2;
  5471. };
  5472. Transformable.prototype.getLineScale = function () {
  5473. var m = this.transform;
  5474. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  5475. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  5476. : 1;
  5477. };
  5478. Transformable.prototype.copyTransform = function (source) {
  5479. copyTransform(this, source);
  5480. };
  5481. Transformable.getLocalTransform = function (target, m) {
  5482. m = m || [];
  5483. var ox = target.originX || 0;
  5484. var oy = target.originY || 0;
  5485. var sx = target.scaleX;
  5486. var sy = target.scaleY;
  5487. var ax = target.anchorX;
  5488. var ay = target.anchorY;
  5489. var rotation = target.rotation || 0;
  5490. var x = target.x;
  5491. var y = target.y;
  5492. var skewX = target.skewX ? Math.tan(target.skewX) : 0;
  5493. var skewY = target.skewY ? Math.tan(-target.skewY) : 0;
  5494. if (ox || oy || ax || ay) {
  5495. var dx = ox + ax;
  5496. var dy = oy + ay;
  5497. m[4] = -dx * sx - skewX * dy * sy;
  5498. m[5] = -dy * sy - skewY * dx * sx;
  5499. }
  5500. else {
  5501. m[4] = m[5] = 0;
  5502. }
  5503. m[0] = sx;
  5504. m[3] = sy;
  5505. m[1] = skewY * sx;
  5506. m[2] = skewX * sy;
  5507. rotation && rotate(m, m, rotation);
  5508. m[4] += ox + x;
  5509. m[5] += oy + y;
  5510. return m;
  5511. };
  5512. Transformable.initDefaultProps = (function () {
  5513. var proto = Transformable.prototype;
  5514. proto.scaleX =
  5515. proto.scaleY =
  5516. proto.globalScaleRatio = 1;
  5517. proto.x =
  5518. proto.y =
  5519. proto.originX =
  5520. proto.originY =
  5521. proto.skewX =
  5522. proto.skewY =
  5523. proto.rotation =
  5524. proto.anchorX =
  5525. proto.anchorY = 0;
  5526. })();
  5527. return Transformable;
  5528. }());
  5529. var TRANSFORMABLE_PROPS = [
  5530. 'x', 'y', 'originX', 'originY', 'anchorX', 'anchorY', 'rotation', 'scaleX', 'scaleY', 'skewX', 'skewY'
  5531. ];
  5532. function copyTransform(target, source) {
  5533. for (var i = 0; i < TRANSFORMABLE_PROPS.length; i++) {
  5534. var propName = TRANSFORMABLE_PROPS[i];
  5535. target[propName] = source[propName];
  5536. }
  5537. }
  5538. var textWidthCache = {};
  5539. function getWidth(text, font) {
  5540. font = font || DEFAULT_FONT;
  5541. var cacheOfFont = textWidthCache[font];
  5542. if (!cacheOfFont) {
  5543. cacheOfFont = textWidthCache[font] = new LRU(500);
  5544. }
  5545. var width = cacheOfFont.get(text);
  5546. if (width == null) {
  5547. width = platformApi.measureText(text, font).width;
  5548. cacheOfFont.put(text, width);
  5549. }
  5550. return width;
  5551. }
  5552. function innerGetBoundingRect(text, font, textAlign, textBaseline) {
  5553. var width = getWidth(text, font);
  5554. var height = getLineHeight(font);
  5555. var x = adjustTextX(0, width, textAlign);
  5556. var y = adjustTextY$1(0, height, textBaseline);
  5557. var rect = new BoundingRect(x, y, width, height);
  5558. return rect;
  5559. }
  5560. function getBoundingRect(text, font, textAlign, textBaseline) {
  5561. var textLines = ((text || '') + '').split('\n');
  5562. var len = textLines.length;
  5563. if (len === 1) {
  5564. return innerGetBoundingRect(textLines[0], font, textAlign, textBaseline);
  5565. }
  5566. else {
  5567. var uniondRect = new BoundingRect(0, 0, 0, 0);
  5568. for (var i = 0; i < textLines.length; i++) {
  5569. var rect = innerGetBoundingRect(textLines[i], font, textAlign, textBaseline);
  5570. i === 0 ? uniondRect.copy(rect) : uniondRect.union(rect);
  5571. }
  5572. return uniondRect;
  5573. }
  5574. }
  5575. function adjustTextX(x, width, textAlign) {
  5576. if (textAlign === 'right') {
  5577. x -= width;
  5578. }
  5579. else if (textAlign === 'center') {
  5580. x -= width / 2;
  5581. }
  5582. return x;
  5583. }
  5584. function adjustTextY$1(y, height, verticalAlign) {
  5585. if (verticalAlign === 'middle') {
  5586. y -= height / 2;
  5587. }
  5588. else if (verticalAlign === 'bottom') {
  5589. y -= height;
  5590. }
  5591. return y;
  5592. }
  5593. function getLineHeight(font) {
  5594. return getWidth('国', font);
  5595. }
  5596. function parsePercent(value, maxValue) {
  5597. if (typeof value === 'string') {
  5598. if (value.lastIndexOf('%') >= 0) {
  5599. return parseFloat(value) / 100 * maxValue;
  5600. }
  5601. return parseFloat(value);
  5602. }
  5603. return value;
  5604. }
  5605. function calculateTextPosition(out, opts, rect) {
  5606. var textPosition = opts.position || 'inside';
  5607. var distance = opts.distance != null ? opts.distance : 5;
  5608. var height = rect.height;
  5609. var width = rect.width;
  5610. var halfHeight = height / 2;
  5611. var x = rect.x;
  5612. var y = rect.y;
  5613. var textAlign = 'left';
  5614. var textVerticalAlign = 'top';
  5615. if (textPosition instanceof Array) {
  5616. x += parsePercent(textPosition[0], rect.width);
  5617. y += parsePercent(textPosition[1], rect.height);
  5618. textAlign = null;
  5619. textVerticalAlign = null;
  5620. }
  5621. else {
  5622. switch (textPosition) {
  5623. case 'left':
  5624. x -= distance;
  5625. y += halfHeight;
  5626. textAlign = 'right';
  5627. textVerticalAlign = 'middle';
  5628. break;
  5629. case 'right':
  5630. x += distance + width;
  5631. y += halfHeight;
  5632. textVerticalAlign = 'middle';
  5633. break;
  5634. case 'top':
  5635. x += width / 2;
  5636. y -= distance;
  5637. textAlign = 'center';
  5638. textVerticalAlign = 'bottom';
  5639. break;
  5640. case 'bottom':
  5641. x += width / 2;
  5642. y += height + distance;
  5643. textAlign = 'center';
  5644. break;
  5645. case 'inside':
  5646. x += width / 2;
  5647. y += halfHeight;
  5648. textAlign = 'center';
  5649. textVerticalAlign = 'middle';
  5650. break;
  5651. case 'insideLeft':
  5652. x += distance;
  5653. y += halfHeight;
  5654. textVerticalAlign = 'middle';
  5655. break;
  5656. case 'insideRight':
  5657. x += width - distance;
  5658. y += halfHeight;
  5659. textAlign = 'right';
  5660. textVerticalAlign = 'middle';
  5661. break;
  5662. case 'insideTop':
  5663. x += width / 2;
  5664. y += distance;
  5665. textAlign = 'center';
  5666. break;
  5667. case 'insideBottom':
  5668. x += width / 2;
  5669. y += height - distance;
  5670. textAlign = 'center';
  5671. textVerticalAlign = 'bottom';
  5672. break;
  5673. case 'insideTopLeft':
  5674. x += distance;
  5675. y += distance;
  5676. break;
  5677. case 'insideTopRight':
  5678. x += width - distance;
  5679. y += distance;
  5680. textAlign = 'right';
  5681. break;
  5682. case 'insideBottomLeft':
  5683. x += distance;
  5684. y += height - distance;
  5685. textVerticalAlign = 'bottom';
  5686. break;
  5687. case 'insideBottomRight':
  5688. x += width - distance;
  5689. y += height - distance;
  5690. textAlign = 'right';
  5691. textVerticalAlign = 'bottom';
  5692. break;
  5693. }
  5694. }
  5695. out = out || {};
  5696. out.x = x;
  5697. out.y = y;
  5698. out.align = textAlign;
  5699. out.verticalAlign = textVerticalAlign;
  5700. return out;
  5701. }
  5702. var PRESERVED_NORMAL_STATE = '__zr_normal__';
  5703. var PRIMARY_STATES_KEYS = TRANSFORMABLE_PROPS.concat(['ignore']);
  5704. var DEFAULT_ANIMATABLE_MAP = reduce(TRANSFORMABLE_PROPS, function (obj, key) {
  5705. obj[key] = true;
  5706. return obj;
  5707. }, { ignore: false });
  5708. var tmpTextPosCalcRes = {};
  5709. var tmpBoundingRect = new BoundingRect(0, 0, 0, 0);
  5710. var Element = (function () {
  5711. function Element(props) {
  5712. this.id = guid();
  5713. this.animators = [];
  5714. this.currentStates = [];
  5715. this.states = {};
  5716. this._init(props);
  5717. }
  5718. Element.prototype._init = function (props) {
  5719. this.attr(props);
  5720. };
  5721. Element.prototype.drift = function (dx, dy, e) {
  5722. switch (this.draggable) {
  5723. case 'horizontal':
  5724. dy = 0;
  5725. break;
  5726. case 'vertical':
  5727. dx = 0;
  5728. break;
  5729. }
  5730. var m = this.transform;
  5731. if (!m) {
  5732. m = this.transform = [1, 0, 0, 1, 0, 0];
  5733. }
  5734. m[4] += dx;
  5735. m[5] += dy;
  5736. this.decomposeTransform();
  5737. this.markRedraw();
  5738. };
  5739. Element.prototype.beforeUpdate = function () { };
  5740. Element.prototype.afterUpdate = function () { };
  5741. Element.prototype.update = function () {
  5742. this.updateTransform();
  5743. if (this.__dirty) {
  5744. this.updateInnerText();
  5745. }
  5746. };
  5747. Element.prototype.updateInnerText = function (forceUpdate) {
  5748. var textEl = this._textContent;
  5749. if (textEl && (!textEl.ignore || forceUpdate)) {
  5750. if (!this.textConfig) {
  5751. this.textConfig = {};
  5752. }
  5753. var textConfig = this.textConfig;
  5754. var isLocal = textConfig.local;
  5755. var innerTransformable = textEl.innerTransformable;
  5756. var textAlign = void 0;
  5757. var textVerticalAlign = void 0;
  5758. var textStyleChanged = false;
  5759. innerTransformable.parent = isLocal ? this : null;
  5760. var innerOrigin = false;
  5761. innerTransformable.copyTransform(textEl);
  5762. if (textConfig.position != null) {
  5763. var layoutRect = tmpBoundingRect;
  5764. if (textConfig.layoutRect) {
  5765. layoutRect.copy(textConfig.layoutRect);
  5766. }
  5767. else {
  5768. layoutRect.copy(this.getBoundingRect());
  5769. }
  5770. if (!isLocal) {
  5771. layoutRect.applyTransform(this.transform);
  5772. }
  5773. if (this.calculateTextPosition) {
  5774. this.calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5775. }
  5776. else {
  5777. calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5778. }
  5779. innerTransformable.x = tmpTextPosCalcRes.x;
  5780. innerTransformable.y = tmpTextPosCalcRes.y;
  5781. textAlign = tmpTextPosCalcRes.align;
  5782. textVerticalAlign = tmpTextPosCalcRes.verticalAlign;
  5783. var textOrigin = textConfig.origin;
  5784. if (textOrigin && textConfig.rotation != null) {
  5785. var relOriginX = void 0;
  5786. var relOriginY = void 0;
  5787. if (textOrigin === 'center') {
  5788. relOriginX = layoutRect.width * 0.5;
  5789. relOriginY = layoutRect.height * 0.5;
  5790. }
  5791. else {
  5792. relOriginX = parsePercent(textOrigin[0], layoutRect.width);
  5793. relOriginY = parsePercent(textOrigin[1], layoutRect.height);
  5794. }
  5795. innerOrigin = true;
  5796. innerTransformable.originX = -innerTransformable.x + relOriginX + (isLocal ? 0 : layoutRect.x);
  5797. innerTransformable.originY = -innerTransformable.y + relOriginY + (isLocal ? 0 : layoutRect.y);
  5798. }
  5799. }
  5800. if (textConfig.rotation != null) {
  5801. innerTransformable.rotation = textConfig.rotation;
  5802. }
  5803. var textOffset = textConfig.offset;
  5804. if (textOffset) {
  5805. innerTransformable.x += textOffset[0];
  5806. innerTransformable.y += textOffset[1];
  5807. if (!innerOrigin) {
  5808. innerTransformable.originX = -textOffset[0];
  5809. innerTransformable.originY = -textOffset[1];
  5810. }
  5811. }
  5812. var isInside = textConfig.inside == null
  5813. ? (typeof textConfig.position === 'string' && textConfig.position.indexOf('inside') >= 0)
  5814. : textConfig.inside;
  5815. var innerTextDefaultStyle = this._innerTextDefaultStyle || (this._innerTextDefaultStyle = {});
  5816. var textFill = void 0;
  5817. var textStroke = void 0;
  5818. var autoStroke = void 0;
  5819. if (isInside && this.canBeInsideText()) {
  5820. textFill = textConfig.insideFill;
  5821. textStroke = textConfig.insideStroke;
  5822. if (textFill == null || textFill === 'auto') {
  5823. textFill = this.getInsideTextFill();
  5824. }
  5825. if (textStroke == null || textStroke === 'auto') {
  5826. textStroke = this.getInsideTextStroke(textFill);
  5827. autoStroke = true;
  5828. }
  5829. }
  5830. else {
  5831. textFill = textConfig.outsideFill;
  5832. textStroke = textConfig.outsideStroke;
  5833. if (textFill == null || textFill === 'auto') {
  5834. textFill = this.getOutsideFill();
  5835. }
  5836. if (textStroke == null || textStroke === 'auto') {
  5837. textStroke = this.getOutsideStroke(textFill);
  5838. autoStroke = true;
  5839. }
  5840. }
  5841. textFill = textFill || '#000';
  5842. if (textFill !== innerTextDefaultStyle.fill
  5843. || textStroke !== innerTextDefaultStyle.stroke
  5844. || autoStroke !== innerTextDefaultStyle.autoStroke
  5845. || textAlign !== innerTextDefaultStyle.align
  5846. || textVerticalAlign !== innerTextDefaultStyle.verticalAlign) {
  5847. textStyleChanged = true;
  5848. innerTextDefaultStyle.fill = textFill;
  5849. innerTextDefaultStyle.stroke = textStroke;
  5850. innerTextDefaultStyle.autoStroke = autoStroke;
  5851. innerTextDefaultStyle.align = textAlign;
  5852. innerTextDefaultStyle.verticalAlign = textVerticalAlign;
  5853. textEl.setDefaultTextStyle(innerTextDefaultStyle);
  5854. }
  5855. textEl.__dirty |= REDRAW_BIT;
  5856. if (textStyleChanged) {
  5857. textEl.dirtyStyle(true);
  5858. }
  5859. }
  5860. };
  5861. Element.prototype.canBeInsideText = function () {
  5862. return true;
  5863. };
  5864. Element.prototype.getInsideTextFill = function () {
  5865. return '#fff';
  5866. };
  5867. Element.prototype.getInsideTextStroke = function (textFill) {
  5868. return '#000';
  5869. };
  5870. Element.prototype.getOutsideFill = function () {
  5871. return this.__zr && this.__zr.isDarkMode() ? LIGHT_LABEL_COLOR : DARK_LABEL_COLOR;
  5872. };
  5873. Element.prototype.getOutsideStroke = function (textFill) {
  5874. var backgroundColor = this.__zr && this.__zr.getBackgroundColor();
  5875. var colorArr = typeof backgroundColor === 'string' && parse(backgroundColor);
  5876. if (!colorArr) {
  5877. colorArr = [255, 255, 255, 1];
  5878. }
  5879. var alpha = colorArr[3];
  5880. var isDark = this.__zr.isDarkMode();
  5881. for (var i = 0; i < 3; i++) {
  5882. colorArr[i] = colorArr[i] * alpha + (isDark ? 0 : 255) * (1 - alpha);
  5883. }
  5884. colorArr[3] = 1;
  5885. return stringify(colorArr, 'rgba');
  5886. };
  5887. Element.prototype.traverse = function (cb, context) { };
  5888. Element.prototype.attrKV = function (key, value) {
  5889. if (key === 'textConfig') {
  5890. this.setTextConfig(value);
  5891. }
  5892. else if (key === 'textContent') {
  5893. this.setTextContent(value);
  5894. }
  5895. else if (key === 'clipPath') {
  5896. this.setClipPath(value);
  5897. }
  5898. else if (key === 'extra') {
  5899. this.extra = this.extra || {};
  5900. extend(this.extra, value);
  5901. }
  5902. else {
  5903. this[key] = value;
  5904. }
  5905. };
  5906. Element.prototype.hide = function () {
  5907. this.ignore = true;
  5908. this.markRedraw();
  5909. };
  5910. Element.prototype.show = function () {
  5911. this.ignore = false;
  5912. this.markRedraw();
  5913. };
  5914. Element.prototype.attr = function (keyOrObj, value) {
  5915. if (typeof keyOrObj === 'string') {
  5916. this.attrKV(keyOrObj, value);
  5917. }
  5918. else if (isObject(keyOrObj)) {
  5919. var obj = keyOrObj;
  5920. var keysArr = keys(obj);
  5921. for (var i = 0; i < keysArr.length; i++) {
  5922. var key = keysArr[i];
  5923. this.attrKV(key, keyOrObj[key]);
  5924. }
  5925. }
  5926. this.markRedraw();
  5927. return this;
  5928. };
  5929. Element.prototype.saveCurrentToNormalState = function (toState) {
  5930. this._innerSaveToNormal(toState);
  5931. var normalState = this._normalState;
  5932. for (var i = 0; i < this.animators.length; i++) {
  5933. var animator = this.animators[i];
  5934. var fromStateTransition = animator.__fromStateTransition;
  5935. if (animator.getLoop() || fromStateTransition && fromStateTransition !== PRESERVED_NORMAL_STATE) {
  5936. continue;
  5937. }
  5938. var targetName = animator.targetName;
  5939. var target = targetName
  5940. ? normalState[targetName] : normalState;
  5941. animator.saveTo(target);
  5942. }
  5943. };
  5944. Element.prototype._innerSaveToNormal = function (toState) {
  5945. var normalState = this._normalState;
  5946. if (!normalState) {
  5947. normalState = this._normalState = {};
  5948. }
  5949. if (toState.textConfig && !normalState.textConfig) {
  5950. normalState.textConfig = this.textConfig;
  5951. }
  5952. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS);
  5953. };
  5954. Element.prototype._savePrimaryToNormal = function (toState, normalState, primaryKeys) {
  5955. for (var i = 0; i < primaryKeys.length; i++) {
  5956. var key = primaryKeys[i];
  5957. if (toState[key] != null && !(key in normalState)) {
  5958. normalState[key] = this[key];
  5959. }
  5960. }
  5961. };
  5962. Element.prototype.hasState = function () {
  5963. return this.currentStates.length > 0;
  5964. };
  5965. Element.prototype.getState = function (name) {
  5966. return this.states[name];
  5967. };
  5968. Element.prototype.ensureState = function (name) {
  5969. var states = this.states;
  5970. if (!states[name]) {
  5971. states[name] = {};
  5972. }
  5973. return states[name];
  5974. };
  5975. Element.prototype.clearStates = function (noAnimation) {
  5976. this.useState(PRESERVED_NORMAL_STATE, false, noAnimation);
  5977. };
  5978. Element.prototype.useState = function (stateName, keepCurrentStates, noAnimation, forceUseHoverLayer) {
  5979. var toNormalState = stateName === PRESERVED_NORMAL_STATE;
  5980. var hasStates = this.hasState();
  5981. if (!hasStates && toNormalState) {
  5982. return;
  5983. }
  5984. var currentStates = this.currentStates;
  5985. var animationCfg = this.stateTransition;
  5986. if (indexOf(currentStates, stateName) >= 0 && (keepCurrentStates || currentStates.length === 1)) {
  5987. return;
  5988. }
  5989. var state;
  5990. if (this.stateProxy && !toNormalState) {
  5991. state = this.stateProxy(stateName);
  5992. }
  5993. if (!state) {
  5994. state = (this.states && this.states[stateName]);
  5995. }
  5996. if (!state && !toNormalState) {
  5997. logError("State " + stateName + " not exists.");
  5998. return;
  5999. }
  6000. if (!toNormalState) {
  6001. this.saveCurrentToNormalState(state);
  6002. }
  6003. var useHoverLayer = !!((state && state.hoverLayer) || forceUseHoverLayer);
  6004. if (useHoverLayer) {
  6005. this._toggleHoverLayerFlag(true);
  6006. }
  6007. this._applyStateObj(stateName, state, this._normalState, keepCurrentStates, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6008. var textContent = this._textContent;
  6009. var textGuide = this._textGuide;
  6010. if (textContent) {
  6011. textContent.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6012. }
  6013. if (textGuide) {
  6014. textGuide.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6015. }
  6016. if (toNormalState) {
  6017. this.currentStates = [];
  6018. this._normalState = {};
  6019. }
  6020. else {
  6021. if (!keepCurrentStates) {
  6022. this.currentStates = [stateName];
  6023. }
  6024. else {
  6025. this.currentStates.push(stateName);
  6026. }
  6027. }
  6028. this._updateAnimationTargets();
  6029. this.markRedraw();
  6030. if (!useHoverLayer && this.__inHover) {
  6031. this._toggleHoverLayerFlag(false);
  6032. this.__dirty &= ~REDRAW_BIT;
  6033. }
  6034. return state;
  6035. };
  6036. Element.prototype.useStates = function (states, noAnimation, forceUseHoverLayer) {
  6037. if (!states.length) {
  6038. this.clearStates();
  6039. }
  6040. else {
  6041. var stateObjects = [];
  6042. var currentStates = this.currentStates;
  6043. var len = states.length;
  6044. var notChange = len === currentStates.length;
  6045. if (notChange) {
  6046. for (var i = 0; i < len; i++) {
  6047. if (states[i] !== currentStates[i]) {
  6048. notChange = false;
  6049. break;
  6050. }
  6051. }
  6052. }
  6053. if (notChange) {
  6054. return;
  6055. }
  6056. for (var i = 0; i < len; i++) {
  6057. var stateName = states[i];
  6058. var stateObj = void 0;
  6059. if (this.stateProxy) {
  6060. stateObj = this.stateProxy(stateName, states);
  6061. }
  6062. if (!stateObj) {
  6063. stateObj = this.states[stateName];
  6064. }
  6065. if (stateObj) {
  6066. stateObjects.push(stateObj);
  6067. }
  6068. }
  6069. var lastStateObj = stateObjects[len - 1];
  6070. var useHoverLayer = !!((lastStateObj && lastStateObj.hoverLayer) || forceUseHoverLayer);
  6071. if (useHoverLayer) {
  6072. this._toggleHoverLayerFlag(true);
  6073. }
  6074. var mergedState = this._mergeStates(stateObjects);
  6075. var animationCfg = this.stateTransition;
  6076. this.saveCurrentToNormalState(mergedState);
  6077. this._applyStateObj(states.join(','), mergedState, this._normalState, false, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6078. var textContent = this._textContent;
  6079. var textGuide = this._textGuide;
  6080. if (textContent) {
  6081. textContent.useStates(states, noAnimation, useHoverLayer);
  6082. }
  6083. if (textGuide) {
  6084. textGuide.useStates(states, noAnimation, useHoverLayer);
  6085. }
  6086. this._updateAnimationTargets();
  6087. this.currentStates = states.slice();
  6088. this.markRedraw();
  6089. if (!useHoverLayer && this.__inHover) {
  6090. this._toggleHoverLayerFlag(false);
  6091. this.__dirty &= ~REDRAW_BIT;
  6092. }
  6093. }
  6094. };
  6095. Element.prototype._updateAnimationTargets = function () {
  6096. for (var i = 0; i < this.animators.length; i++) {
  6097. var animator = this.animators[i];
  6098. if (animator.targetName) {
  6099. animator.changeTarget(this[animator.targetName]);
  6100. }
  6101. }
  6102. };
  6103. Element.prototype.removeState = function (state) {
  6104. var idx = indexOf(this.currentStates, state);
  6105. if (idx >= 0) {
  6106. var currentStates = this.currentStates.slice();
  6107. currentStates.splice(idx, 1);
  6108. this.useStates(currentStates);
  6109. }
  6110. };
  6111. Element.prototype.replaceState = function (oldState, newState, forceAdd) {
  6112. var currentStates = this.currentStates.slice();
  6113. var idx = indexOf(currentStates, oldState);
  6114. var newStateExists = indexOf(currentStates, newState) >= 0;
  6115. if (idx >= 0) {
  6116. if (!newStateExists) {
  6117. currentStates[idx] = newState;
  6118. }
  6119. else {
  6120. currentStates.splice(idx, 1);
  6121. }
  6122. }
  6123. else if (forceAdd && !newStateExists) {
  6124. currentStates.push(newState);
  6125. }
  6126. this.useStates(currentStates);
  6127. };
  6128. Element.prototype.toggleState = function (state, enable) {
  6129. if (enable) {
  6130. this.useState(state, true);
  6131. }
  6132. else {
  6133. this.removeState(state);
  6134. }
  6135. };
  6136. Element.prototype._mergeStates = function (states) {
  6137. var mergedState = {};
  6138. var mergedTextConfig;
  6139. for (var i = 0; i < states.length; i++) {
  6140. var state = states[i];
  6141. extend(mergedState, state);
  6142. if (state.textConfig) {
  6143. mergedTextConfig = mergedTextConfig || {};
  6144. extend(mergedTextConfig, state.textConfig);
  6145. }
  6146. }
  6147. if (mergedTextConfig) {
  6148. mergedState.textConfig = mergedTextConfig;
  6149. }
  6150. return mergedState;
  6151. };
  6152. Element.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  6153. var needsRestoreToNormal = !(state && keepCurrentStates);
  6154. if (state && state.textConfig) {
  6155. this.textConfig = extend({}, keepCurrentStates ? this.textConfig : normalState.textConfig);
  6156. extend(this.textConfig, state.textConfig);
  6157. }
  6158. else if (needsRestoreToNormal) {
  6159. if (normalState.textConfig) {
  6160. this.textConfig = normalState.textConfig;
  6161. }
  6162. }
  6163. var transitionTarget = {};
  6164. var hasTransition = false;
  6165. for (var i = 0; i < PRIMARY_STATES_KEYS.length; i++) {
  6166. var key = PRIMARY_STATES_KEYS[i];
  6167. var propNeedsTransition = transition && DEFAULT_ANIMATABLE_MAP[key];
  6168. if (state && state[key] != null) {
  6169. if (propNeedsTransition) {
  6170. hasTransition = true;
  6171. transitionTarget[key] = state[key];
  6172. }
  6173. else {
  6174. this[key] = state[key];
  6175. }
  6176. }
  6177. else if (needsRestoreToNormal) {
  6178. if (normalState[key] != null) {
  6179. if (propNeedsTransition) {
  6180. hasTransition = true;
  6181. transitionTarget[key] = normalState[key];
  6182. }
  6183. else {
  6184. this[key] = normalState[key];
  6185. }
  6186. }
  6187. }
  6188. }
  6189. if (!transition) {
  6190. for (var i = 0; i < this.animators.length; i++) {
  6191. var animator = this.animators[i];
  6192. var targetName = animator.targetName;
  6193. if (!animator.getLoop()) {
  6194. animator.__changeFinalValue(targetName
  6195. ? (state || normalState)[targetName]
  6196. : (state || normalState));
  6197. }
  6198. }
  6199. }
  6200. if (hasTransition) {
  6201. this._transitionState(stateName, transitionTarget, animationCfg);
  6202. }
  6203. };
  6204. Element.prototype._attachComponent = function (componentEl) {
  6205. if (componentEl.__zr && !componentEl.__hostTarget) {
  6206. {
  6207. throw new Error('Text element has been added to zrender.');
  6208. }
  6209. }
  6210. if (componentEl === this) {
  6211. {
  6212. throw new Error('Recursive component attachment.');
  6213. }
  6214. }
  6215. var zr = this.__zr;
  6216. if (zr) {
  6217. componentEl.addSelfToZr(zr);
  6218. }
  6219. componentEl.__zr = zr;
  6220. componentEl.__hostTarget = this;
  6221. };
  6222. Element.prototype._detachComponent = function (componentEl) {
  6223. if (componentEl.__zr) {
  6224. componentEl.removeSelfFromZr(componentEl.__zr);
  6225. }
  6226. componentEl.__zr = null;
  6227. componentEl.__hostTarget = null;
  6228. };
  6229. Element.prototype.getClipPath = function () {
  6230. return this._clipPath;
  6231. };
  6232. Element.prototype.setClipPath = function (clipPath) {
  6233. if (this._clipPath && this._clipPath !== clipPath) {
  6234. this.removeClipPath();
  6235. }
  6236. this._attachComponent(clipPath);
  6237. this._clipPath = clipPath;
  6238. this.markRedraw();
  6239. };
  6240. Element.prototype.removeClipPath = function () {
  6241. var clipPath = this._clipPath;
  6242. if (clipPath) {
  6243. this._detachComponent(clipPath);
  6244. this._clipPath = null;
  6245. this.markRedraw();
  6246. }
  6247. };
  6248. Element.prototype.getTextContent = function () {
  6249. return this._textContent;
  6250. };
  6251. Element.prototype.setTextContent = function (textEl) {
  6252. var previousTextContent = this._textContent;
  6253. if (previousTextContent === textEl) {
  6254. return;
  6255. }
  6256. if (previousTextContent && previousTextContent !== textEl) {
  6257. this.removeTextContent();
  6258. }
  6259. {
  6260. if (textEl.__zr && !textEl.__hostTarget) {
  6261. throw new Error('Text element has been added to zrender.');
  6262. }
  6263. }
  6264. textEl.innerTransformable = new Transformable();
  6265. this._attachComponent(textEl);
  6266. this._textContent = textEl;
  6267. this.markRedraw();
  6268. };
  6269. Element.prototype.setTextConfig = function (cfg) {
  6270. if (!this.textConfig) {
  6271. this.textConfig = {};
  6272. }
  6273. extend(this.textConfig, cfg);
  6274. this.markRedraw();
  6275. };
  6276. Element.prototype.removeTextConfig = function () {
  6277. this.textConfig = null;
  6278. this.markRedraw();
  6279. };
  6280. Element.prototype.removeTextContent = function () {
  6281. var textEl = this._textContent;
  6282. if (textEl) {
  6283. textEl.innerTransformable = null;
  6284. this._detachComponent(textEl);
  6285. this._textContent = null;
  6286. this._innerTextDefaultStyle = null;
  6287. this.markRedraw();
  6288. }
  6289. };
  6290. Element.prototype.getTextGuideLine = function () {
  6291. return this._textGuide;
  6292. };
  6293. Element.prototype.setTextGuideLine = function (guideLine) {
  6294. if (this._textGuide && this._textGuide !== guideLine) {
  6295. this.removeTextGuideLine();
  6296. }
  6297. this._attachComponent(guideLine);
  6298. this._textGuide = guideLine;
  6299. this.markRedraw();
  6300. };
  6301. Element.prototype.removeTextGuideLine = function () {
  6302. var textGuide = this._textGuide;
  6303. if (textGuide) {
  6304. this._detachComponent(textGuide);
  6305. this._textGuide = null;
  6306. this.markRedraw();
  6307. }
  6308. };
  6309. Element.prototype.markRedraw = function () {
  6310. this.__dirty |= REDRAW_BIT;
  6311. var zr = this.__zr;
  6312. if (zr) {
  6313. if (this.__inHover) {
  6314. zr.refreshHover();
  6315. }
  6316. else {
  6317. zr.refresh();
  6318. }
  6319. }
  6320. if (this.__hostTarget) {
  6321. this.__hostTarget.markRedraw();
  6322. }
  6323. };
  6324. Element.prototype.dirty = function () {
  6325. this.markRedraw();
  6326. };
  6327. Element.prototype._toggleHoverLayerFlag = function (inHover) {
  6328. this.__inHover = inHover;
  6329. var textContent = this._textContent;
  6330. var textGuide = this._textGuide;
  6331. if (textContent) {
  6332. textContent.__inHover = inHover;
  6333. }
  6334. if (textGuide) {
  6335. textGuide.__inHover = inHover;
  6336. }
  6337. };
  6338. Element.prototype.addSelfToZr = function (zr) {
  6339. if (this.__zr === zr) {
  6340. return;
  6341. }
  6342. this.__zr = zr;
  6343. var animators = this.animators;
  6344. if (animators) {
  6345. for (var i = 0; i < animators.length; i++) {
  6346. zr.animation.addAnimator(animators[i]);
  6347. }
  6348. }
  6349. if (this._clipPath) {
  6350. this._clipPath.addSelfToZr(zr);
  6351. }
  6352. if (this._textContent) {
  6353. this._textContent.addSelfToZr(zr);
  6354. }
  6355. if (this._textGuide) {
  6356. this._textGuide.addSelfToZr(zr);
  6357. }
  6358. };
  6359. Element.prototype.removeSelfFromZr = function (zr) {
  6360. if (!this.__zr) {
  6361. return;
  6362. }
  6363. this.__zr = null;
  6364. var animators = this.animators;
  6365. if (animators) {
  6366. for (var i = 0; i < animators.length; i++) {
  6367. zr.animation.removeAnimator(animators[i]);
  6368. }
  6369. }
  6370. if (this._clipPath) {
  6371. this._clipPath.removeSelfFromZr(zr);
  6372. }
  6373. if (this._textContent) {
  6374. this._textContent.removeSelfFromZr(zr);
  6375. }
  6376. if (this._textGuide) {
  6377. this._textGuide.removeSelfFromZr(zr);
  6378. }
  6379. };
  6380. Element.prototype.animate = function (key, loop, allowDiscreteAnimation) {
  6381. var target = key ? this[key] : this;
  6382. {
  6383. if (!target) {
  6384. logError('Property "'
  6385. + key
  6386. + '" is not existed in element '
  6387. + this.id);
  6388. return;
  6389. }
  6390. }
  6391. var animator = new Animator(target, loop, allowDiscreteAnimation);
  6392. key && (animator.targetName = key);
  6393. this.addAnimator(animator, key);
  6394. return animator;
  6395. };
  6396. Element.prototype.addAnimator = function (animator, key) {
  6397. var zr = this.__zr;
  6398. var el = this;
  6399. animator.during(function () {
  6400. el.updateDuringAnimation(key);
  6401. }).done(function () {
  6402. var animators = el.animators;
  6403. var idx = indexOf(animators, animator);
  6404. if (idx >= 0) {
  6405. animators.splice(idx, 1);
  6406. }
  6407. });
  6408. this.animators.push(animator);
  6409. if (zr) {
  6410. zr.animation.addAnimator(animator);
  6411. }
  6412. zr && zr.wakeUp();
  6413. };
  6414. Element.prototype.updateDuringAnimation = function (key) {
  6415. this.markRedraw();
  6416. };
  6417. Element.prototype.stopAnimation = function (scope, forwardToLast) {
  6418. var animators = this.animators;
  6419. var len = animators.length;
  6420. var leftAnimators = [];
  6421. for (var i = 0; i < len; i++) {
  6422. var animator = animators[i];
  6423. if (!scope || scope === animator.scope) {
  6424. animator.stop(forwardToLast);
  6425. }
  6426. else {
  6427. leftAnimators.push(animator);
  6428. }
  6429. }
  6430. this.animators = leftAnimators;
  6431. return this;
  6432. };
  6433. Element.prototype.animateTo = function (target, cfg, animationProps) {
  6434. animateTo(this, target, cfg, animationProps);
  6435. };
  6436. Element.prototype.animateFrom = function (target, cfg, animationProps) {
  6437. animateTo(this, target, cfg, animationProps, true);
  6438. };
  6439. Element.prototype._transitionState = function (stateName, target, cfg, animationProps) {
  6440. var animators = animateTo(this, target, cfg, animationProps);
  6441. for (var i = 0; i < animators.length; i++) {
  6442. animators[i].__fromStateTransition = stateName;
  6443. }
  6444. };
  6445. Element.prototype.getBoundingRect = function () {
  6446. return null;
  6447. };
  6448. Element.prototype.getPaintRect = function () {
  6449. return null;
  6450. };
  6451. Element.initDefaultProps = (function () {
  6452. var elProto = Element.prototype;
  6453. elProto.type = 'element';
  6454. elProto.name = '';
  6455. elProto.ignore =
  6456. elProto.silent =
  6457. elProto.isGroup =
  6458. elProto.draggable =
  6459. elProto.dragging =
  6460. elProto.ignoreClip =
  6461. elProto.__inHover = false;
  6462. elProto.__dirty = REDRAW_BIT;
  6463. var logs = {};
  6464. function logDeprecatedError(key, xKey, yKey) {
  6465. if (!logs[key + xKey + yKey]) {
  6466. console.warn("DEPRECATED: '" + key + "' has been deprecated. use '" + xKey + "', '" + yKey + "' instead");
  6467. logs[key + xKey + yKey] = true;
  6468. }
  6469. }
  6470. function createLegacyProperty(key, privateKey, xKey, yKey) {
  6471. Object.defineProperty(elProto, key, {
  6472. get: function () {
  6473. {
  6474. logDeprecatedError(key, xKey, yKey);
  6475. }
  6476. if (!this[privateKey]) {
  6477. var pos = this[privateKey] = [];
  6478. enhanceArray(this, pos);
  6479. }
  6480. return this[privateKey];
  6481. },
  6482. set: function (pos) {
  6483. {
  6484. logDeprecatedError(key, xKey, yKey);
  6485. }
  6486. this[xKey] = pos[0];
  6487. this[yKey] = pos[1];
  6488. this[privateKey] = pos;
  6489. enhanceArray(this, pos);
  6490. }
  6491. });
  6492. function enhanceArray(self, pos) {
  6493. Object.defineProperty(pos, 0, {
  6494. get: function () {
  6495. return self[xKey];
  6496. },
  6497. set: function (val) {
  6498. self[xKey] = val;
  6499. }
  6500. });
  6501. Object.defineProperty(pos, 1, {
  6502. get: function () {
  6503. return self[yKey];
  6504. },
  6505. set: function (val) {
  6506. self[yKey] = val;
  6507. }
  6508. });
  6509. }
  6510. }
  6511. if (Object.defineProperty) {
  6512. createLegacyProperty('position', '_legacyPos', 'x', 'y');
  6513. createLegacyProperty('scale', '_legacyScale', 'scaleX', 'scaleY');
  6514. createLegacyProperty('origin', '_legacyOrigin', 'originX', 'originY');
  6515. }
  6516. })();
  6517. return Element;
  6518. }());
  6519. mixin(Element, Eventful);
  6520. mixin(Element, Transformable);
  6521. function animateTo(animatable, target, cfg, animationProps, reverse) {
  6522. cfg = cfg || {};
  6523. var animators = [];
  6524. animateToShallow(animatable, '', animatable, target, cfg, animationProps, animators, reverse);
  6525. var finishCount = animators.length;
  6526. var doneHappened = false;
  6527. var cfgDone = cfg.done;
  6528. var cfgAborted = cfg.aborted;
  6529. var doneCb = function () {
  6530. doneHappened = true;
  6531. finishCount--;
  6532. if (finishCount <= 0) {
  6533. doneHappened
  6534. ? (cfgDone && cfgDone())
  6535. : (cfgAborted && cfgAborted());
  6536. }
  6537. };
  6538. var abortedCb = function () {
  6539. finishCount--;
  6540. if (finishCount <= 0) {
  6541. doneHappened
  6542. ? (cfgDone && cfgDone())
  6543. : (cfgAborted && cfgAborted());
  6544. }
  6545. };
  6546. if (!finishCount) {
  6547. cfgDone && cfgDone();
  6548. }
  6549. if (animators.length > 0 && cfg.during) {
  6550. animators[0].during(function (target, percent) {
  6551. cfg.during(percent);
  6552. });
  6553. }
  6554. for (var i = 0; i < animators.length; i++) {
  6555. var animator = animators[i];
  6556. if (doneCb) {
  6557. animator.done(doneCb);
  6558. }
  6559. if (abortedCb) {
  6560. animator.aborted(abortedCb);
  6561. }
  6562. if (cfg.force) {
  6563. animator.duration(cfg.duration);
  6564. }
  6565. animator.start(cfg.easing);
  6566. }
  6567. return animators;
  6568. }
  6569. function copyArrShallow(source, target, len) {
  6570. for (var i = 0; i < len; i++) {
  6571. source[i] = target[i];
  6572. }
  6573. }
  6574. function is2DArray(value) {
  6575. return isArrayLike(value[0]);
  6576. }
  6577. function copyValue(target, source, key) {
  6578. if (isArrayLike(source[key])) {
  6579. if (!isArrayLike(target[key])) {
  6580. target[key] = [];
  6581. }
  6582. if (isTypedArray(source[key])) {
  6583. var len = source[key].length;
  6584. if (target[key].length !== len) {
  6585. target[key] = new (source[key].constructor)(len);
  6586. copyArrShallow(target[key], source[key], len);
  6587. }
  6588. }
  6589. else {
  6590. var sourceArr = source[key];
  6591. var targetArr = target[key];
  6592. var len0 = sourceArr.length;
  6593. if (is2DArray(sourceArr)) {
  6594. var len1 = sourceArr[0].length;
  6595. for (var i = 0; i < len0; i++) {
  6596. if (!targetArr[i]) {
  6597. targetArr[i] = Array.prototype.slice.call(sourceArr[i]);
  6598. }
  6599. else {
  6600. copyArrShallow(targetArr[i], sourceArr[i], len1);
  6601. }
  6602. }
  6603. }
  6604. else {
  6605. copyArrShallow(targetArr, sourceArr, len0);
  6606. }
  6607. targetArr.length = sourceArr.length;
  6608. }
  6609. }
  6610. else {
  6611. target[key] = source[key];
  6612. }
  6613. }
  6614. function isValueSame(val1, val2) {
  6615. return val1 === val2
  6616. || isArrayLike(val1) && isArrayLike(val2) && is1DArraySame(val1, val2);
  6617. }
  6618. function is1DArraySame(arr0, arr1) {
  6619. var len = arr0.length;
  6620. if (len !== arr1.length) {
  6621. return false;
  6622. }
  6623. for (var i = 0; i < len; i++) {
  6624. if (arr0[i] !== arr1[i]) {
  6625. return false;
  6626. }
  6627. }
  6628. return true;
  6629. }
  6630. function animateToShallow(animatable, topKey, animateObj, target, cfg, animationProps, animators, reverse) {
  6631. var targetKeys = keys(target);
  6632. var duration = cfg.duration;
  6633. var delay = cfg.delay;
  6634. var additive = cfg.additive;
  6635. var setToFinal = cfg.setToFinal;
  6636. var animateAll = !isObject(animationProps);
  6637. var existsAnimators = animatable.animators;
  6638. var animationKeys = [];
  6639. for (var k = 0; k < targetKeys.length; k++) {
  6640. var innerKey = targetKeys[k];
  6641. var targetVal = target[innerKey];
  6642. if (targetVal != null && animateObj[innerKey] != null
  6643. && (animateAll || animationProps[innerKey])) {
  6644. if (isObject(targetVal)
  6645. && !isArrayLike(targetVal)
  6646. && !isGradientObject(targetVal)) {
  6647. if (topKey) {
  6648. if (!reverse) {
  6649. animateObj[innerKey] = targetVal;
  6650. animatable.updateDuringAnimation(topKey);
  6651. }
  6652. continue;
  6653. }
  6654. animateToShallow(animatable, innerKey, animateObj[innerKey], targetVal, cfg, animationProps && animationProps[innerKey], animators, reverse);
  6655. }
  6656. else {
  6657. animationKeys.push(innerKey);
  6658. }
  6659. }
  6660. else if (!reverse) {
  6661. animateObj[innerKey] = targetVal;
  6662. animatable.updateDuringAnimation(topKey);
  6663. animationKeys.push(innerKey);
  6664. }
  6665. }
  6666. var keyLen = animationKeys.length;
  6667. if (!additive && keyLen) {
  6668. for (var i = 0; i < existsAnimators.length; i++) {
  6669. var animator = existsAnimators[i];
  6670. if (animator.targetName === topKey) {
  6671. var allAborted = animator.stopTracks(animationKeys);
  6672. if (allAborted) {
  6673. var idx = indexOf(existsAnimators, animator);
  6674. existsAnimators.splice(idx, 1);
  6675. }
  6676. }
  6677. }
  6678. }
  6679. if (!cfg.force) {
  6680. animationKeys = filter(animationKeys, function (key) { return !isValueSame(target[key], animateObj[key]); });
  6681. keyLen = animationKeys.length;
  6682. }
  6683. if (keyLen > 0
  6684. || (cfg.force && !animators.length)) {
  6685. var revertedSource = void 0;
  6686. var reversedTarget = void 0;
  6687. var sourceClone = void 0;
  6688. if (reverse) {
  6689. reversedTarget = {};
  6690. if (setToFinal) {
  6691. revertedSource = {};
  6692. }
  6693. for (var i = 0; i < keyLen; i++) {
  6694. var innerKey = animationKeys[i];
  6695. reversedTarget[innerKey] = animateObj[innerKey];
  6696. if (setToFinal) {
  6697. revertedSource[innerKey] = target[innerKey];
  6698. }
  6699. else {
  6700. animateObj[innerKey] = target[innerKey];
  6701. }
  6702. }
  6703. }
  6704. else if (setToFinal) {
  6705. sourceClone = {};
  6706. for (var i = 0; i < keyLen; i++) {
  6707. var innerKey = animationKeys[i];
  6708. sourceClone[innerKey] = cloneValue(animateObj[innerKey]);
  6709. copyValue(animateObj, target, innerKey);
  6710. }
  6711. }
  6712. var animator = new Animator(animateObj, false, false, additive ? filter(existsAnimators, function (animator) { return animator.targetName === topKey; }) : null);
  6713. animator.targetName = topKey;
  6714. if (cfg.scope) {
  6715. animator.scope = cfg.scope;
  6716. }
  6717. if (setToFinal && revertedSource) {
  6718. animator.whenWithKeys(0, revertedSource, animationKeys);
  6719. }
  6720. if (sourceClone) {
  6721. animator.whenWithKeys(0, sourceClone, animationKeys);
  6722. }
  6723. animator.whenWithKeys(duration == null ? 500 : duration, reverse ? reversedTarget : target, animationKeys).delay(delay || 0);
  6724. animatable.addAnimator(animator, topKey);
  6725. animators.push(animator);
  6726. }
  6727. }
  6728. var Group = (function (_super) {
  6729. __extends(Group, _super);
  6730. function Group(opts) {
  6731. var _this = _super.call(this) || this;
  6732. _this.isGroup = true;
  6733. _this._children = [];
  6734. _this.attr(opts);
  6735. return _this;
  6736. }
  6737. Group.prototype.childrenRef = function () {
  6738. return this._children;
  6739. };
  6740. Group.prototype.children = function () {
  6741. return this._children.slice();
  6742. };
  6743. Group.prototype.childAt = function (idx) {
  6744. return this._children[idx];
  6745. };
  6746. Group.prototype.childOfName = function (name) {
  6747. var children = this._children;
  6748. for (var i = 0; i < children.length; i++) {
  6749. if (children[i].name === name) {
  6750. return children[i];
  6751. }
  6752. }
  6753. };
  6754. Group.prototype.childCount = function () {
  6755. return this._children.length;
  6756. };
  6757. Group.prototype.add = function (child) {
  6758. if (child) {
  6759. if (child !== this && child.parent !== this) {
  6760. this._children.push(child);
  6761. this._doAdd(child);
  6762. }
  6763. {
  6764. if (child.__hostTarget) {
  6765. throw 'This elemenet has been used as an attachment';
  6766. }
  6767. }
  6768. }
  6769. return this;
  6770. };
  6771. Group.prototype.addBefore = function (child, nextSibling) {
  6772. if (child && child !== this && child.parent !== this
  6773. && nextSibling && nextSibling.parent === this) {
  6774. var children = this._children;
  6775. var idx = children.indexOf(nextSibling);
  6776. if (idx >= 0) {
  6777. children.splice(idx, 0, child);
  6778. this._doAdd(child);
  6779. }
  6780. }
  6781. return this;
  6782. };
  6783. Group.prototype.replace = function (oldChild, newChild) {
  6784. var idx = indexOf(this._children, oldChild);
  6785. if (idx >= 0) {
  6786. this.replaceAt(newChild, idx);
  6787. }
  6788. return this;
  6789. };
  6790. Group.prototype.replaceAt = function (child, index) {
  6791. var children = this._children;
  6792. var old = children[index];
  6793. if (child && child !== this && child.parent !== this && child !== old) {
  6794. children[index] = child;
  6795. old.parent = null;
  6796. var zr = this.__zr;
  6797. if (zr) {
  6798. old.removeSelfFromZr(zr);
  6799. }
  6800. this._doAdd(child);
  6801. }
  6802. return this;
  6803. };
  6804. Group.prototype._doAdd = function (child) {
  6805. if (child.parent) {
  6806. child.parent.remove(child);
  6807. }
  6808. child.parent = this;
  6809. var zr = this.__zr;
  6810. if (zr && zr !== child.__zr) {
  6811. child.addSelfToZr(zr);
  6812. }
  6813. zr && zr.refresh();
  6814. };
  6815. Group.prototype.remove = function (child) {
  6816. var zr = this.__zr;
  6817. var children = this._children;
  6818. var idx = indexOf(children, child);
  6819. if (idx < 0) {
  6820. return this;
  6821. }
  6822. children.splice(idx, 1);
  6823. child.parent = null;
  6824. if (zr) {
  6825. child.removeSelfFromZr(zr);
  6826. }
  6827. zr && zr.refresh();
  6828. return this;
  6829. };
  6830. Group.prototype.removeAll = function () {
  6831. var children = this._children;
  6832. var zr = this.__zr;
  6833. for (var i = 0; i < children.length; i++) {
  6834. var child = children[i];
  6835. if (zr) {
  6836. child.removeSelfFromZr(zr);
  6837. }
  6838. child.parent = null;
  6839. }
  6840. children.length = 0;
  6841. return this;
  6842. };
  6843. Group.prototype.eachChild = function (cb, context) {
  6844. var children = this._children;
  6845. for (var i = 0; i < children.length; i++) {
  6846. var child = children[i];
  6847. cb.call(context, child, i);
  6848. }
  6849. return this;
  6850. };
  6851. Group.prototype.traverse = function (cb, context) {
  6852. for (var i = 0; i < this._children.length; i++) {
  6853. var child = this._children[i];
  6854. var stopped = cb.call(context, child);
  6855. if (child.isGroup && !stopped) {
  6856. child.traverse(cb, context);
  6857. }
  6858. }
  6859. return this;
  6860. };
  6861. Group.prototype.addSelfToZr = function (zr) {
  6862. _super.prototype.addSelfToZr.call(this, zr);
  6863. for (var i = 0; i < this._children.length; i++) {
  6864. var child = this._children[i];
  6865. child.addSelfToZr(zr);
  6866. }
  6867. };
  6868. Group.prototype.removeSelfFromZr = function (zr) {
  6869. _super.prototype.removeSelfFromZr.call(this, zr);
  6870. for (var i = 0; i < this._children.length; i++) {
  6871. var child = this._children[i];
  6872. child.removeSelfFromZr(zr);
  6873. }
  6874. };
  6875. Group.prototype.getBoundingRect = function (includeChildren) {
  6876. var tmpRect = new BoundingRect(0, 0, 0, 0);
  6877. var children = includeChildren || this._children;
  6878. var tmpMat = [];
  6879. var rect = null;
  6880. for (var i = 0; i < children.length; i++) {
  6881. var child = children[i];
  6882. if (child.ignore || child.invisible) {
  6883. continue;
  6884. }
  6885. var childRect = child.getBoundingRect();
  6886. var transform = child.getLocalTransform(tmpMat);
  6887. if (transform) {
  6888. BoundingRect.applyTransform(tmpRect, childRect, transform);
  6889. rect = rect || tmpRect.clone();
  6890. rect.union(tmpRect);
  6891. }
  6892. else {
  6893. rect = rect || childRect.clone();
  6894. rect.union(childRect);
  6895. }
  6896. }
  6897. return rect || tmpRect;
  6898. };
  6899. return Group;
  6900. }(Element));
  6901. Group.prototype.type = 'group';
  6902. /*!
  6903. * ZRender, a high performance 2d drawing library.
  6904. *
  6905. * Copyright (c) 2013, Baidu Inc.
  6906. * All rights reserved.
  6907. *
  6908. * LICENSE
  6909. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  6910. */
  6911. var painterCtors = {};
  6912. var instances = {};
  6913. function delInstance(id) {
  6914. delete instances[id];
  6915. }
  6916. function isDarkMode(backgroundColor) {
  6917. if (!backgroundColor) {
  6918. return false;
  6919. }
  6920. if (typeof backgroundColor === 'string') {
  6921. return lum(backgroundColor, 1) < DARK_MODE_THRESHOLD;
  6922. }
  6923. else if (backgroundColor.colorStops) {
  6924. var colorStops = backgroundColor.colorStops;
  6925. var totalLum = 0;
  6926. var len = colorStops.length;
  6927. for (var i = 0; i < len; i++) {
  6928. totalLum += lum(colorStops[i].color, 1);
  6929. }
  6930. totalLum /= len;
  6931. return totalLum < DARK_MODE_THRESHOLD;
  6932. }
  6933. return false;
  6934. }
  6935. var ZRender = (function () {
  6936. function ZRender(id, dom, opts) {
  6937. var _this = this;
  6938. this._sleepAfterStill = 10;
  6939. this._stillFrameAccum = 0;
  6940. this._needsRefresh = true;
  6941. this._needsRefreshHover = true;
  6942. this._darkMode = false;
  6943. opts = opts || {};
  6944. this.dom = dom;
  6945. this.id = id;
  6946. var storage = new Storage();
  6947. var rendererType = opts.renderer || 'canvas';
  6948. if (!painterCtors[rendererType]) {
  6949. rendererType = keys(painterCtors)[0];
  6950. }
  6951. {
  6952. if (!painterCtors[rendererType]) {
  6953. throw new Error("Renderer '" + rendererType + "' is not imported. Please import it first.");
  6954. }
  6955. }
  6956. opts.useDirtyRect = opts.useDirtyRect == null
  6957. ? false
  6958. : opts.useDirtyRect;
  6959. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  6960. var ssrMode = opts.ssr || painter.ssrOnly;
  6961. this.storage = storage;
  6962. this.painter = painter;
  6963. var handerProxy = (!env.node && !env.worker && !ssrMode)
  6964. ? new HandlerDomProxy(painter.getViewportRoot(), painter.root)
  6965. : null;
  6966. var useCoarsePointer = opts.useCoarsePointer;
  6967. var usePointerSize = (useCoarsePointer == null || useCoarsePointer === 'auto')
  6968. ? env.touchEventsSupported
  6969. : !!useCoarsePointer;
  6970. var defaultPointerSize = 44;
  6971. var pointerSize;
  6972. if (usePointerSize) {
  6973. pointerSize = retrieve2(opts.pointerSize, defaultPointerSize);
  6974. }
  6975. this.handler = new Handler(storage, painter, handerProxy, painter.root, pointerSize);
  6976. this.animation = new Animation({
  6977. stage: {
  6978. update: ssrMode ? null : function () { return _this._flush(true); }
  6979. }
  6980. });
  6981. if (!ssrMode) {
  6982. this.animation.start();
  6983. }
  6984. }
  6985. ZRender.prototype.add = function (el) {
  6986. if (!el) {
  6987. return;
  6988. }
  6989. this.storage.addRoot(el);
  6990. el.addSelfToZr(this);
  6991. this.refresh();
  6992. };
  6993. ZRender.prototype.remove = function (el) {
  6994. if (!el) {
  6995. return;
  6996. }
  6997. this.storage.delRoot(el);
  6998. el.removeSelfFromZr(this);
  6999. this.refresh();
  7000. };
  7001. ZRender.prototype.configLayer = function (zLevel, config) {
  7002. if (this.painter.configLayer) {
  7003. this.painter.configLayer(zLevel, config);
  7004. }
  7005. this.refresh();
  7006. };
  7007. ZRender.prototype.setBackgroundColor = function (backgroundColor) {
  7008. if (this.painter.setBackgroundColor) {
  7009. this.painter.setBackgroundColor(backgroundColor);
  7010. }
  7011. this.refresh();
  7012. this._backgroundColor = backgroundColor;
  7013. this._darkMode = isDarkMode(backgroundColor);
  7014. };
  7015. ZRender.prototype.getBackgroundColor = function () {
  7016. return this._backgroundColor;
  7017. };
  7018. ZRender.prototype.setDarkMode = function (darkMode) {
  7019. this._darkMode = darkMode;
  7020. };
  7021. ZRender.prototype.isDarkMode = function () {
  7022. return this._darkMode;
  7023. };
  7024. ZRender.prototype.refreshImmediately = function (fromInside) {
  7025. if (!fromInside) {
  7026. this.animation.update(true);
  7027. }
  7028. this._needsRefresh = false;
  7029. this.painter.refresh();
  7030. this._needsRefresh = false;
  7031. };
  7032. ZRender.prototype.refresh = function () {
  7033. this._needsRefresh = true;
  7034. this.animation.start();
  7035. };
  7036. ZRender.prototype.flush = function () {
  7037. this._flush(false);
  7038. };
  7039. ZRender.prototype._flush = function (fromInside) {
  7040. var triggerRendered;
  7041. var start = getTime();
  7042. if (this._needsRefresh) {
  7043. triggerRendered = true;
  7044. this.refreshImmediately(fromInside);
  7045. }
  7046. if (this._needsRefreshHover) {
  7047. triggerRendered = true;
  7048. this.refreshHoverImmediately();
  7049. }
  7050. var end = getTime();
  7051. if (triggerRendered) {
  7052. this._stillFrameAccum = 0;
  7053. this.trigger('rendered', {
  7054. elapsedTime: end - start
  7055. });
  7056. }
  7057. else if (this._sleepAfterStill > 0) {
  7058. this._stillFrameAccum++;
  7059. if (this._stillFrameAccum > this._sleepAfterStill) {
  7060. this.animation.stop();
  7061. }
  7062. }
  7063. };
  7064. ZRender.prototype.setSleepAfterStill = function (stillFramesCount) {
  7065. this._sleepAfterStill = stillFramesCount;
  7066. };
  7067. ZRender.prototype.wakeUp = function () {
  7068. this.animation.start();
  7069. this._stillFrameAccum = 0;
  7070. };
  7071. ZRender.prototype.refreshHover = function () {
  7072. this._needsRefreshHover = true;
  7073. };
  7074. ZRender.prototype.refreshHoverImmediately = function () {
  7075. this._needsRefreshHover = false;
  7076. if (this.painter.refreshHover && this.painter.getType() === 'canvas') {
  7077. this.painter.refreshHover();
  7078. }
  7079. };
  7080. ZRender.prototype.resize = function (opts) {
  7081. opts = opts || {};
  7082. this.painter.resize(opts.width, opts.height);
  7083. this.handler.resize();
  7084. };
  7085. ZRender.prototype.clearAnimation = function () {
  7086. this.animation.clear();
  7087. };
  7088. ZRender.prototype.getWidth = function () {
  7089. return this.painter.getWidth();
  7090. };
  7091. ZRender.prototype.getHeight = function () {
  7092. return this.painter.getHeight();
  7093. };
  7094. ZRender.prototype.setCursorStyle = function (cursorStyle) {
  7095. this.handler.setCursorStyle(cursorStyle);
  7096. };
  7097. ZRender.prototype.findHover = function (x, y) {
  7098. return this.handler.findHover(x, y);
  7099. };
  7100. ZRender.prototype.on = function (eventName, eventHandler, context) {
  7101. this.handler.on(eventName, eventHandler, context);
  7102. return this;
  7103. };
  7104. ZRender.prototype.off = function (eventName, eventHandler) {
  7105. this.handler.off(eventName, eventHandler);
  7106. };
  7107. ZRender.prototype.trigger = function (eventName, event) {
  7108. this.handler.trigger(eventName, event);
  7109. };
  7110. ZRender.prototype.clear = function () {
  7111. var roots = this.storage.getRoots();
  7112. for (var i = 0; i < roots.length; i++) {
  7113. if (roots[i] instanceof Group) {
  7114. roots[i].removeSelfFromZr(this);
  7115. }
  7116. }
  7117. this.storage.delAllRoots();
  7118. this.painter.clear();
  7119. };
  7120. ZRender.prototype.dispose = function () {
  7121. this.animation.stop();
  7122. this.clear();
  7123. this.storage.dispose();
  7124. this.painter.dispose();
  7125. this.handler.dispose();
  7126. this.animation =
  7127. this.storage =
  7128. this.painter =
  7129. this.handler = null;
  7130. delInstance(this.id);
  7131. };
  7132. return ZRender;
  7133. }());
  7134. function init(dom, opts) {
  7135. var zr = new ZRender(guid(), dom, opts);
  7136. instances[zr.id] = zr;
  7137. return zr;
  7138. }
  7139. function dispose(zr) {
  7140. zr.dispose();
  7141. }
  7142. function disposeAll() {
  7143. for (var key in instances) {
  7144. if (instances.hasOwnProperty(key)) {
  7145. instances[key].dispose();
  7146. }
  7147. }
  7148. instances = {};
  7149. }
  7150. function getInstance(id) {
  7151. return instances[id];
  7152. }
  7153. function registerPainter(name, Ctor) {
  7154. painterCtors[name] = Ctor;
  7155. }
  7156. var version = '5.4.0';
  7157. var STYLE_MAGIC_KEY = '__zr_style_' + Math.round((Math.random() * 10));
  7158. var DEFAULT_COMMON_STYLE = {
  7159. shadowBlur: 0,
  7160. shadowOffsetX: 0,
  7161. shadowOffsetY: 0,
  7162. shadowColor: '#000',
  7163. opacity: 1,
  7164. blend: 'source-over'
  7165. };
  7166. var DEFAULT_COMMON_ANIMATION_PROPS = {
  7167. style: {
  7168. shadowBlur: true,
  7169. shadowOffsetX: true,
  7170. shadowOffsetY: true,
  7171. shadowColor: true,
  7172. opacity: true
  7173. }
  7174. };
  7175. DEFAULT_COMMON_STYLE[STYLE_MAGIC_KEY] = true;
  7176. var PRIMARY_STATES_KEYS$1 = ['z', 'z2', 'invisible'];
  7177. var PRIMARY_STATES_KEYS_IN_HOVER_LAYER = ['invisible'];
  7178. var Displayable = (function (_super) {
  7179. __extends(Displayable, _super);
  7180. function Displayable(props) {
  7181. return _super.call(this, props) || this;
  7182. }
  7183. Displayable.prototype._init = function (props) {
  7184. var keysArr = keys(props);
  7185. for (var i = 0; i < keysArr.length; i++) {
  7186. var key = keysArr[i];
  7187. if (key === 'style') {
  7188. this.useStyle(props[key]);
  7189. }
  7190. else {
  7191. _super.prototype.attrKV.call(this, key, props[key]);
  7192. }
  7193. }
  7194. if (!this.style) {
  7195. this.useStyle({});
  7196. }
  7197. };
  7198. Displayable.prototype.beforeBrush = function () { };
  7199. Displayable.prototype.afterBrush = function () { };
  7200. Displayable.prototype.innerBeforeBrush = function () { };
  7201. Displayable.prototype.innerAfterBrush = function () { };
  7202. Displayable.prototype.shouldBePainted = function (viewWidth, viewHeight, considerClipPath, considerAncestors) {
  7203. var m = this.transform;
  7204. if (this.ignore
  7205. || this.invisible
  7206. || this.style.opacity === 0
  7207. || (this.culling
  7208. && isDisplayableCulled(this, viewWidth, viewHeight))
  7209. || (m && !m[0] && !m[3])) {
  7210. return false;
  7211. }
  7212. if (considerClipPath && this.__clipPaths) {
  7213. for (var i = 0; i < this.__clipPaths.length; ++i) {
  7214. if (this.__clipPaths[i].isZeroArea()) {
  7215. return false;
  7216. }
  7217. }
  7218. }
  7219. if (considerAncestors && this.parent) {
  7220. var parent_1 = this.parent;
  7221. while (parent_1) {
  7222. if (parent_1.ignore) {
  7223. return false;
  7224. }
  7225. parent_1 = parent_1.parent;
  7226. }
  7227. }
  7228. return true;
  7229. };
  7230. Displayable.prototype.contain = function (x, y) {
  7231. return this.rectContain(x, y);
  7232. };
  7233. Displayable.prototype.traverse = function (cb, context) {
  7234. cb.call(context, this);
  7235. };
  7236. Displayable.prototype.rectContain = function (x, y) {
  7237. var coord = this.transformCoordToLocal(x, y);
  7238. var rect = this.getBoundingRect();
  7239. return rect.contain(coord[0], coord[1]);
  7240. };
  7241. Displayable.prototype.getPaintRect = function () {
  7242. var rect = this._paintRect;
  7243. if (!this._paintRect || this.__dirty) {
  7244. var transform = this.transform;
  7245. var elRect = this.getBoundingRect();
  7246. var style = this.style;
  7247. var shadowSize = style.shadowBlur || 0;
  7248. var shadowOffsetX = style.shadowOffsetX || 0;
  7249. var shadowOffsetY = style.shadowOffsetY || 0;
  7250. rect = this._paintRect || (this._paintRect = new BoundingRect(0, 0, 0, 0));
  7251. if (transform) {
  7252. BoundingRect.applyTransform(rect, elRect, transform);
  7253. }
  7254. else {
  7255. rect.copy(elRect);
  7256. }
  7257. if (shadowSize || shadowOffsetX || shadowOffsetY) {
  7258. rect.width += shadowSize * 2 + Math.abs(shadowOffsetX);
  7259. rect.height += shadowSize * 2 + Math.abs(shadowOffsetY);
  7260. rect.x = Math.min(rect.x, rect.x + shadowOffsetX - shadowSize);
  7261. rect.y = Math.min(rect.y, rect.y + shadowOffsetY - shadowSize);
  7262. }
  7263. var tolerance = this.dirtyRectTolerance;
  7264. if (!rect.isZero()) {
  7265. rect.x = Math.floor(rect.x - tolerance);
  7266. rect.y = Math.floor(rect.y - tolerance);
  7267. rect.width = Math.ceil(rect.width + 1 + tolerance * 2);
  7268. rect.height = Math.ceil(rect.height + 1 + tolerance * 2);
  7269. }
  7270. }
  7271. return rect;
  7272. };
  7273. Displayable.prototype.setPrevPaintRect = function (paintRect) {
  7274. if (paintRect) {
  7275. this._prevPaintRect = this._prevPaintRect || new BoundingRect(0, 0, 0, 0);
  7276. this._prevPaintRect.copy(paintRect);
  7277. }
  7278. else {
  7279. this._prevPaintRect = null;
  7280. }
  7281. };
  7282. Displayable.prototype.getPrevPaintRect = function () {
  7283. return this._prevPaintRect;
  7284. };
  7285. Displayable.prototype.animateStyle = function (loop) {
  7286. return this.animate('style', loop);
  7287. };
  7288. Displayable.prototype.updateDuringAnimation = function (targetKey) {
  7289. if (targetKey === 'style') {
  7290. this.dirtyStyle();
  7291. }
  7292. else {
  7293. this.markRedraw();
  7294. }
  7295. };
  7296. Displayable.prototype.attrKV = function (key, value) {
  7297. if (key !== 'style') {
  7298. _super.prototype.attrKV.call(this, key, value);
  7299. }
  7300. else {
  7301. if (!this.style) {
  7302. this.useStyle(value);
  7303. }
  7304. else {
  7305. this.setStyle(value);
  7306. }
  7307. }
  7308. };
  7309. Displayable.prototype.setStyle = function (keyOrObj, value) {
  7310. if (typeof keyOrObj === 'string') {
  7311. this.style[keyOrObj] = value;
  7312. }
  7313. else {
  7314. extend(this.style, keyOrObj);
  7315. }
  7316. this.dirtyStyle();
  7317. return this;
  7318. };
  7319. Displayable.prototype.dirtyStyle = function (notRedraw) {
  7320. if (!notRedraw) {
  7321. this.markRedraw();
  7322. }
  7323. this.__dirty |= STYLE_CHANGED_BIT;
  7324. if (this._rect) {
  7325. this._rect = null;
  7326. }
  7327. };
  7328. Displayable.prototype.dirty = function () {
  7329. this.dirtyStyle();
  7330. };
  7331. Displayable.prototype.styleChanged = function () {
  7332. return !!(this.__dirty & STYLE_CHANGED_BIT);
  7333. };
  7334. Displayable.prototype.styleUpdated = function () {
  7335. this.__dirty &= ~STYLE_CHANGED_BIT;
  7336. };
  7337. Displayable.prototype.createStyle = function (obj) {
  7338. return createObject(DEFAULT_COMMON_STYLE, obj);
  7339. };
  7340. Displayable.prototype.useStyle = function (obj) {
  7341. if (!obj[STYLE_MAGIC_KEY]) {
  7342. obj = this.createStyle(obj);
  7343. }
  7344. if (this.__inHover) {
  7345. this.__hoverStyle = obj;
  7346. }
  7347. else {
  7348. this.style = obj;
  7349. }
  7350. this.dirtyStyle();
  7351. };
  7352. Displayable.prototype.isStyleObject = function (obj) {
  7353. return obj[STYLE_MAGIC_KEY];
  7354. };
  7355. Displayable.prototype._innerSaveToNormal = function (toState) {
  7356. _super.prototype._innerSaveToNormal.call(this, toState);
  7357. var normalState = this._normalState;
  7358. if (toState.style && !normalState.style) {
  7359. normalState.style = this._mergeStyle(this.createStyle(), this.style);
  7360. }
  7361. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS$1);
  7362. };
  7363. Displayable.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  7364. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  7365. var needsRestoreToNormal = !(state && keepCurrentStates);
  7366. var targetStyle;
  7367. if (state && state.style) {
  7368. if (transition) {
  7369. if (keepCurrentStates) {
  7370. targetStyle = state.style;
  7371. }
  7372. else {
  7373. targetStyle = this._mergeStyle(this.createStyle(), normalState.style);
  7374. this._mergeStyle(targetStyle, state.style);
  7375. }
  7376. }
  7377. else {
  7378. targetStyle = this._mergeStyle(this.createStyle(), keepCurrentStates ? this.style : normalState.style);
  7379. this._mergeStyle(targetStyle, state.style);
  7380. }
  7381. }
  7382. else if (needsRestoreToNormal) {
  7383. targetStyle = normalState.style;
  7384. }
  7385. if (targetStyle) {
  7386. if (transition) {
  7387. var sourceStyle = this.style;
  7388. this.style = this.createStyle(needsRestoreToNormal ? {} : sourceStyle);
  7389. if (needsRestoreToNormal) {
  7390. var changedKeys = keys(sourceStyle);
  7391. for (var i = 0; i < changedKeys.length; i++) {
  7392. var key = changedKeys[i];
  7393. if (key in targetStyle) {
  7394. targetStyle[key] = targetStyle[key];
  7395. this.style[key] = sourceStyle[key];
  7396. }
  7397. }
  7398. }
  7399. var targetKeys = keys(targetStyle);
  7400. for (var i = 0; i < targetKeys.length; i++) {
  7401. var key = targetKeys[i];
  7402. this.style[key] = this.style[key];
  7403. }
  7404. this._transitionState(stateName, {
  7405. style: targetStyle
  7406. }, animationCfg, this.getAnimationStyleProps());
  7407. }
  7408. else {
  7409. this.useStyle(targetStyle);
  7410. }
  7411. }
  7412. var statesKeys = this.__inHover ? PRIMARY_STATES_KEYS_IN_HOVER_LAYER : PRIMARY_STATES_KEYS$1;
  7413. for (var i = 0; i < statesKeys.length; i++) {
  7414. var key = statesKeys[i];
  7415. if (state && state[key] != null) {
  7416. this[key] = state[key];
  7417. }
  7418. else if (needsRestoreToNormal) {
  7419. if (normalState[key] != null) {
  7420. this[key] = normalState[key];
  7421. }
  7422. }
  7423. }
  7424. };
  7425. Displayable.prototype._mergeStates = function (states) {
  7426. var mergedState = _super.prototype._mergeStates.call(this, states);
  7427. var mergedStyle;
  7428. for (var i = 0; i < states.length; i++) {
  7429. var state = states[i];
  7430. if (state.style) {
  7431. mergedStyle = mergedStyle || {};
  7432. this._mergeStyle(mergedStyle, state.style);
  7433. }
  7434. }
  7435. if (mergedStyle) {
  7436. mergedState.style = mergedStyle;
  7437. }
  7438. return mergedState;
  7439. };
  7440. Displayable.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  7441. extend(targetStyle, sourceStyle);
  7442. return targetStyle;
  7443. };
  7444. Displayable.prototype.getAnimationStyleProps = function () {
  7445. return DEFAULT_COMMON_ANIMATION_PROPS;
  7446. };
  7447. Displayable.initDefaultProps = (function () {
  7448. var dispProto = Displayable.prototype;
  7449. dispProto.type = 'displayable';
  7450. dispProto.invisible = false;
  7451. dispProto.z = 0;
  7452. dispProto.z2 = 0;
  7453. dispProto.zlevel = 0;
  7454. dispProto.culling = false;
  7455. dispProto.cursor = 'pointer';
  7456. dispProto.rectHover = false;
  7457. dispProto.incremental = false;
  7458. dispProto._rect = null;
  7459. dispProto.dirtyRectTolerance = 0;
  7460. dispProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT;
  7461. })();
  7462. return Displayable;
  7463. }(Element));
  7464. var tmpRect$1 = new BoundingRect(0, 0, 0, 0);
  7465. var viewRect = new BoundingRect(0, 0, 0, 0);
  7466. function isDisplayableCulled(el, width, height) {
  7467. tmpRect$1.copy(el.getBoundingRect());
  7468. if (el.transform) {
  7469. tmpRect$1.applyTransform(el.transform);
  7470. }
  7471. viewRect.width = width;
  7472. viewRect.height = height;
  7473. return !tmpRect$1.intersect(viewRect);
  7474. }
  7475. var mathMin$1 = Math.min;
  7476. var mathMax$1 = Math.max;
  7477. var mathSin = Math.sin;
  7478. var mathCos = Math.cos;
  7479. var PI2 = Math.PI * 2;
  7480. var start = create();
  7481. var end = create();
  7482. var extremity = create();
  7483. function fromPoints(points, min, max) {
  7484. if (points.length === 0) {
  7485. return;
  7486. }
  7487. var p = points[0];
  7488. var left = p[0];
  7489. var right = p[0];
  7490. var top = p[1];
  7491. var bottom = p[1];
  7492. for (var i = 1; i < points.length; i++) {
  7493. p = points[i];
  7494. left = mathMin$1(left, p[0]);
  7495. right = mathMax$1(right, p[0]);
  7496. top = mathMin$1(top, p[1]);
  7497. bottom = mathMax$1(bottom, p[1]);
  7498. }
  7499. min[0] = left;
  7500. min[1] = top;
  7501. max[0] = right;
  7502. max[1] = bottom;
  7503. }
  7504. function fromLine(x0, y0, x1, y1, min, max) {
  7505. min[0] = mathMin$1(x0, x1);
  7506. min[1] = mathMin$1(y0, y1);
  7507. max[0] = mathMax$1(x0, x1);
  7508. max[1] = mathMax$1(y0, y1);
  7509. }
  7510. var xDim = [];
  7511. var yDim = [];
  7512. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min, max) {
  7513. var cubicExtrema$1 = cubicExtrema;
  7514. var cubicAt$1 = cubicAt;
  7515. var n = cubicExtrema$1(x0, x1, x2, x3, xDim);
  7516. min[0] = Infinity;
  7517. min[1] = Infinity;
  7518. max[0] = -Infinity;
  7519. max[1] = -Infinity;
  7520. for (var i = 0; i < n; i++) {
  7521. var x = cubicAt$1(x0, x1, x2, x3, xDim[i]);
  7522. min[0] = mathMin$1(x, min[0]);
  7523. max[0] = mathMax$1(x, max[0]);
  7524. }
  7525. n = cubicExtrema$1(y0, y1, y2, y3, yDim);
  7526. for (var i = 0; i < n; i++) {
  7527. var y = cubicAt$1(y0, y1, y2, y3, yDim[i]);
  7528. min[1] = mathMin$1(y, min[1]);
  7529. max[1] = mathMax$1(y, max[1]);
  7530. }
  7531. min[0] = mathMin$1(x0, min[0]);
  7532. max[0] = mathMax$1(x0, max[0]);
  7533. min[0] = mathMin$1(x3, min[0]);
  7534. max[0] = mathMax$1(x3, max[0]);
  7535. min[1] = mathMin$1(y0, min[1]);
  7536. max[1] = mathMax$1(y0, max[1]);
  7537. min[1] = mathMin$1(y3, min[1]);
  7538. max[1] = mathMax$1(y3, max[1]);
  7539. }
  7540. function fromQuadratic(x0, y0, x1, y1, x2, y2, min, max) {
  7541. var quadraticExtremum$1 = quadraticExtremum;
  7542. var quadraticAt$1 = quadraticAt;
  7543. var tx = mathMax$1(mathMin$1(quadraticExtremum$1(x0, x1, x2), 1), 0);
  7544. var ty = mathMax$1(mathMin$1(quadraticExtremum$1(y0, y1, y2), 1), 0);
  7545. var x = quadraticAt$1(x0, x1, x2, tx);
  7546. var y = quadraticAt$1(y0, y1, y2, ty);
  7547. min[0] = mathMin$1(x0, x2, x);
  7548. min[1] = mathMin$1(y0, y2, y);
  7549. max[0] = mathMax$1(x0, x2, x);
  7550. max[1] = mathMax$1(y0, y2, y);
  7551. }
  7552. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min$1, max$1) {
  7553. var vec2Min = min;
  7554. var vec2Max = max;
  7555. var diff = Math.abs(startAngle - endAngle);
  7556. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  7557. min$1[0] = x - rx;
  7558. min$1[1] = y - ry;
  7559. max$1[0] = x + rx;
  7560. max$1[1] = y + ry;
  7561. return;
  7562. }
  7563. start[0] = mathCos(startAngle) * rx + x;
  7564. start[1] = mathSin(startAngle) * ry + y;
  7565. end[0] = mathCos(endAngle) * rx + x;
  7566. end[1] = mathSin(endAngle) * ry + y;
  7567. vec2Min(min$1, start, end);
  7568. vec2Max(max$1, start, end);
  7569. startAngle = startAngle % (PI2);
  7570. if (startAngle < 0) {
  7571. startAngle = startAngle + PI2;
  7572. }
  7573. endAngle = endAngle % (PI2);
  7574. if (endAngle < 0) {
  7575. endAngle = endAngle + PI2;
  7576. }
  7577. if (startAngle > endAngle && !anticlockwise) {
  7578. endAngle += PI2;
  7579. }
  7580. else if (startAngle < endAngle && anticlockwise) {
  7581. startAngle += PI2;
  7582. }
  7583. if (anticlockwise) {
  7584. var tmp = endAngle;
  7585. endAngle = startAngle;
  7586. startAngle = tmp;
  7587. }
  7588. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  7589. if (angle > startAngle) {
  7590. extremity[0] = mathCos(angle) * rx + x;
  7591. extremity[1] = mathSin(angle) * ry + y;
  7592. vec2Min(min$1, extremity, min$1);
  7593. vec2Max(max$1, extremity, max$1);
  7594. }
  7595. }
  7596. }
  7597. var CMD = {
  7598. M: 1,
  7599. L: 2,
  7600. C: 3,
  7601. Q: 4,
  7602. A: 5,
  7603. Z: 6,
  7604. R: 7
  7605. };
  7606. var tmpOutX = [];
  7607. var tmpOutY = [];
  7608. var min$1 = [];
  7609. var max$1 = [];
  7610. var min2 = [];
  7611. var max2 = [];
  7612. var mathMin$2 = Math.min;
  7613. var mathMax$2 = Math.max;
  7614. var mathCos$1 = Math.cos;
  7615. var mathSin$1 = Math.sin;
  7616. var mathAbs = Math.abs;
  7617. var PI = Math.PI;
  7618. var PI2$1 = PI * 2;
  7619. var hasTypedArray = typeof Float32Array !== 'undefined';
  7620. var tmpAngles = [];
  7621. function modPI2(radian) {
  7622. var n = Math.round(radian / PI * 1e8) / 1e8;
  7623. return (n % 2) * PI;
  7624. }
  7625. function normalizeArcAngles(angles, anticlockwise) {
  7626. var newStartAngle = modPI2(angles[0]);
  7627. if (newStartAngle < 0) {
  7628. newStartAngle += PI2$1;
  7629. }
  7630. var delta = newStartAngle - angles[0];
  7631. var newEndAngle = angles[1];
  7632. newEndAngle += delta;
  7633. if (!anticlockwise && newEndAngle - newStartAngle >= PI2$1) {
  7634. newEndAngle = newStartAngle + PI2$1;
  7635. }
  7636. else if (anticlockwise && newStartAngle - newEndAngle >= PI2$1) {
  7637. newEndAngle = newStartAngle - PI2$1;
  7638. }
  7639. else if (!anticlockwise && newStartAngle > newEndAngle) {
  7640. newEndAngle = newStartAngle + (PI2$1 - modPI2(newStartAngle - newEndAngle));
  7641. }
  7642. else if (anticlockwise && newStartAngle < newEndAngle) {
  7643. newEndAngle = newStartAngle - (PI2$1 - modPI2(newEndAngle - newStartAngle));
  7644. }
  7645. angles[0] = newStartAngle;
  7646. angles[1] = newEndAngle;
  7647. }
  7648. var PathProxy = (function () {
  7649. function PathProxy(notSaveData) {
  7650. this.dpr = 1;
  7651. this._xi = 0;
  7652. this._yi = 0;
  7653. this._x0 = 0;
  7654. this._y0 = 0;
  7655. this._len = 0;
  7656. if (notSaveData) {
  7657. this._saveData = false;
  7658. }
  7659. if (this._saveData) {
  7660. this.data = [];
  7661. }
  7662. }
  7663. PathProxy.prototype.increaseVersion = function () {
  7664. this._version++;
  7665. };
  7666. PathProxy.prototype.getVersion = function () {
  7667. return this._version;
  7668. };
  7669. PathProxy.prototype.setScale = function (sx, sy, segmentIgnoreThreshold) {
  7670. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  7671. if (segmentIgnoreThreshold > 0) {
  7672. this._ux = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  7673. this._uy = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  7674. }
  7675. };
  7676. PathProxy.prototype.setDPR = function (dpr) {
  7677. this.dpr = dpr;
  7678. };
  7679. PathProxy.prototype.setContext = function (ctx) {
  7680. this._ctx = ctx;
  7681. };
  7682. PathProxy.prototype.getContext = function () {
  7683. return this._ctx;
  7684. };
  7685. PathProxy.prototype.beginPath = function () {
  7686. this._ctx && this._ctx.beginPath();
  7687. this.reset();
  7688. return this;
  7689. };
  7690. PathProxy.prototype.reset = function () {
  7691. if (this._saveData) {
  7692. this._len = 0;
  7693. }
  7694. if (this._pathSegLen) {
  7695. this._pathSegLen = null;
  7696. this._pathLen = 0;
  7697. }
  7698. this._version++;
  7699. };
  7700. PathProxy.prototype.moveTo = function (x, y) {
  7701. this._drawPendingPt();
  7702. this.addData(CMD.M, x, y);
  7703. this._ctx && this._ctx.moveTo(x, y);
  7704. this._x0 = x;
  7705. this._y0 = y;
  7706. this._xi = x;
  7707. this._yi = y;
  7708. return this;
  7709. };
  7710. PathProxy.prototype.lineTo = function (x, y) {
  7711. var dx = mathAbs(x - this._xi);
  7712. var dy = mathAbs(y - this._yi);
  7713. var exceedUnit = dx > this._ux || dy > this._uy;
  7714. this.addData(CMD.L, x, y);
  7715. if (this._ctx && exceedUnit) {
  7716. this._ctx.lineTo(x, y);
  7717. }
  7718. if (exceedUnit) {
  7719. this._xi = x;
  7720. this._yi = y;
  7721. this._pendingPtDist = 0;
  7722. }
  7723. else {
  7724. var d2 = dx * dx + dy * dy;
  7725. if (d2 > this._pendingPtDist) {
  7726. this._pendingPtX = x;
  7727. this._pendingPtY = y;
  7728. this._pendingPtDist = d2;
  7729. }
  7730. }
  7731. return this;
  7732. };
  7733. PathProxy.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
  7734. this._drawPendingPt();
  7735. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  7736. if (this._ctx) {
  7737. this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  7738. }
  7739. this._xi = x3;
  7740. this._yi = y3;
  7741. return this;
  7742. };
  7743. PathProxy.prototype.quadraticCurveTo = function (x1, y1, x2, y2) {
  7744. this._drawPendingPt();
  7745. this.addData(CMD.Q, x1, y1, x2, y2);
  7746. if (this._ctx) {
  7747. this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  7748. }
  7749. this._xi = x2;
  7750. this._yi = y2;
  7751. return this;
  7752. };
  7753. PathProxy.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  7754. this._drawPendingPt();
  7755. tmpAngles[0] = startAngle;
  7756. tmpAngles[1] = endAngle;
  7757. normalizeArcAngles(tmpAngles, anticlockwise);
  7758. startAngle = tmpAngles[0];
  7759. endAngle = tmpAngles[1];
  7760. var delta = endAngle - startAngle;
  7761. this.addData(CMD.A, cx, cy, r, r, startAngle, delta, 0, anticlockwise ? 0 : 1);
  7762. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  7763. this._xi = mathCos$1(endAngle) * r + cx;
  7764. this._yi = mathSin$1(endAngle) * r + cy;
  7765. return this;
  7766. };
  7767. PathProxy.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  7768. this._drawPendingPt();
  7769. if (this._ctx) {
  7770. this._ctx.arcTo(x1, y1, x2, y2, radius);
  7771. }
  7772. return this;
  7773. };
  7774. PathProxy.prototype.rect = function (x, y, w, h) {
  7775. this._drawPendingPt();
  7776. this._ctx && this._ctx.rect(x, y, w, h);
  7777. this.addData(CMD.R, x, y, w, h);
  7778. return this;
  7779. };
  7780. PathProxy.prototype.closePath = function () {
  7781. this._drawPendingPt();
  7782. this.addData(CMD.Z);
  7783. var ctx = this._ctx;
  7784. var x0 = this._x0;
  7785. var y0 = this._y0;
  7786. if (ctx) {
  7787. ctx.closePath();
  7788. }
  7789. this._xi = x0;
  7790. this._yi = y0;
  7791. return this;
  7792. };
  7793. PathProxy.prototype.fill = function (ctx) {
  7794. ctx && ctx.fill();
  7795. this.toStatic();
  7796. };
  7797. PathProxy.prototype.stroke = function (ctx) {
  7798. ctx && ctx.stroke();
  7799. this.toStatic();
  7800. };
  7801. PathProxy.prototype.len = function () {
  7802. return this._len;
  7803. };
  7804. PathProxy.prototype.setData = function (data) {
  7805. var len = data.length;
  7806. if (!(this.data && this.data.length === len) && hasTypedArray) {
  7807. this.data = new Float32Array(len);
  7808. }
  7809. for (var i = 0; i < len; i++) {
  7810. this.data[i] = data[i];
  7811. }
  7812. this._len = len;
  7813. };
  7814. PathProxy.prototype.appendPath = function (path) {
  7815. if (!(path instanceof Array)) {
  7816. path = [path];
  7817. }
  7818. var len = path.length;
  7819. var appendSize = 0;
  7820. var offset = this._len;
  7821. for (var i = 0; i < len; i++) {
  7822. appendSize += path[i].len();
  7823. }
  7824. if (hasTypedArray && (this.data instanceof Float32Array)) {
  7825. this.data = new Float32Array(offset + appendSize);
  7826. }
  7827. for (var i = 0; i < len; i++) {
  7828. var appendPathData = path[i].data;
  7829. for (var k = 0; k < appendPathData.length; k++) {
  7830. this.data[offset++] = appendPathData[k];
  7831. }
  7832. }
  7833. this._len = offset;
  7834. };
  7835. PathProxy.prototype.addData = function (cmd, a, b, c, d, e, f, g, h) {
  7836. if (!this._saveData) {
  7837. return;
  7838. }
  7839. var data = this.data;
  7840. if (this._len + arguments.length > data.length) {
  7841. this._expandData();
  7842. data = this.data;
  7843. }
  7844. for (var i = 0; i < arguments.length; i++) {
  7845. data[this._len++] = arguments[i];
  7846. }
  7847. };
  7848. PathProxy.prototype._drawPendingPt = function () {
  7849. if (this._pendingPtDist > 0) {
  7850. this._ctx && this._ctx.lineTo(this._pendingPtX, this._pendingPtY);
  7851. this._pendingPtDist = 0;
  7852. }
  7853. };
  7854. PathProxy.prototype._expandData = function () {
  7855. if (!(this.data instanceof Array)) {
  7856. var newData = [];
  7857. for (var i = 0; i < this._len; i++) {
  7858. newData[i] = this.data[i];
  7859. }
  7860. this.data = newData;
  7861. }
  7862. };
  7863. PathProxy.prototype.toStatic = function () {
  7864. if (!this._saveData) {
  7865. return;
  7866. }
  7867. this._drawPendingPt();
  7868. var data = this.data;
  7869. if (data instanceof Array) {
  7870. data.length = this._len;
  7871. if (hasTypedArray && this._len > 11) {
  7872. this.data = new Float32Array(data);
  7873. }
  7874. }
  7875. };
  7876. PathProxy.prototype.getBoundingRect = function () {
  7877. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  7878. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  7879. var data = this.data;
  7880. var xi = 0;
  7881. var yi = 0;
  7882. var x0 = 0;
  7883. var y0 = 0;
  7884. var i;
  7885. for (i = 0; i < this._len;) {
  7886. var cmd = data[i++];
  7887. var isFirst = i === 1;
  7888. if (isFirst) {
  7889. xi = data[i];
  7890. yi = data[i + 1];
  7891. x0 = xi;
  7892. y0 = yi;
  7893. }
  7894. switch (cmd) {
  7895. case CMD.M:
  7896. xi = x0 = data[i++];
  7897. yi = y0 = data[i++];
  7898. min2[0] = x0;
  7899. min2[1] = y0;
  7900. max2[0] = x0;
  7901. max2[1] = y0;
  7902. break;
  7903. case CMD.L:
  7904. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  7905. xi = data[i++];
  7906. yi = data[i++];
  7907. break;
  7908. case CMD.C:
  7909. fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  7910. xi = data[i++];
  7911. yi = data[i++];
  7912. break;
  7913. case CMD.Q:
  7914. fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  7915. xi = data[i++];
  7916. yi = data[i++];
  7917. break;
  7918. case CMD.A:
  7919. var cx = data[i++];
  7920. var cy = data[i++];
  7921. var rx = data[i++];
  7922. var ry = data[i++];
  7923. var startAngle = data[i++];
  7924. var endAngle = data[i++] + startAngle;
  7925. i += 1;
  7926. var anticlockwise = !data[i++];
  7927. if (isFirst) {
  7928. x0 = mathCos$1(startAngle) * rx + cx;
  7929. y0 = mathSin$1(startAngle) * ry + cy;
  7930. }
  7931. fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  7932. xi = mathCos$1(endAngle) * rx + cx;
  7933. yi = mathSin$1(endAngle) * ry + cy;
  7934. break;
  7935. case CMD.R:
  7936. x0 = xi = data[i++];
  7937. y0 = yi = data[i++];
  7938. var width = data[i++];
  7939. var height = data[i++];
  7940. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  7941. break;
  7942. case CMD.Z:
  7943. xi = x0;
  7944. yi = y0;
  7945. break;
  7946. }
  7947. min(min$1, min$1, min2);
  7948. max(max$1, max$1, max2);
  7949. }
  7950. if (i === 0) {
  7951. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  7952. }
  7953. return new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  7954. };
  7955. PathProxy.prototype._calculateLength = function () {
  7956. var data = this.data;
  7957. var len = this._len;
  7958. var ux = this._ux;
  7959. var uy = this._uy;
  7960. var xi = 0;
  7961. var yi = 0;
  7962. var x0 = 0;
  7963. var y0 = 0;
  7964. if (!this._pathSegLen) {
  7965. this._pathSegLen = [];
  7966. }
  7967. var pathSegLen = this._pathSegLen;
  7968. var pathTotalLen = 0;
  7969. var segCount = 0;
  7970. for (var i = 0; i < len;) {
  7971. var cmd = data[i++];
  7972. var isFirst = i === 1;
  7973. if (isFirst) {
  7974. xi = data[i];
  7975. yi = data[i + 1];
  7976. x0 = xi;
  7977. y0 = yi;
  7978. }
  7979. var l = -1;
  7980. switch (cmd) {
  7981. case CMD.M:
  7982. xi = x0 = data[i++];
  7983. yi = y0 = data[i++];
  7984. break;
  7985. case CMD.L: {
  7986. var x2 = data[i++];
  7987. var y2 = data[i++];
  7988. var dx = x2 - xi;
  7989. var dy = y2 - yi;
  7990. if (mathAbs(dx) > ux || mathAbs(dy) > uy || i === len - 1) {
  7991. l = Math.sqrt(dx * dx + dy * dy);
  7992. xi = x2;
  7993. yi = y2;
  7994. }
  7995. break;
  7996. }
  7997. case CMD.C: {
  7998. var x1 = data[i++];
  7999. var y1 = data[i++];
  8000. var x2 = data[i++];
  8001. var y2 = data[i++];
  8002. var x3 = data[i++];
  8003. var y3 = data[i++];
  8004. l = cubicLength(xi, yi, x1, y1, x2, y2, x3, y3, 10);
  8005. xi = x3;
  8006. yi = y3;
  8007. break;
  8008. }
  8009. case CMD.Q: {
  8010. var x1 = data[i++];
  8011. var y1 = data[i++];
  8012. var x2 = data[i++];
  8013. var y2 = data[i++];
  8014. l = quadraticLength(xi, yi, x1, y1, x2, y2, 10);
  8015. xi = x2;
  8016. yi = y2;
  8017. break;
  8018. }
  8019. case CMD.A:
  8020. var cx = data[i++];
  8021. var cy = data[i++];
  8022. var rx = data[i++];
  8023. var ry = data[i++];
  8024. var startAngle = data[i++];
  8025. var delta = data[i++];
  8026. var endAngle = delta + startAngle;
  8027. i += 1;
  8028. var anticlockwise = !data[i++];
  8029. if (isFirst) {
  8030. x0 = mathCos$1(startAngle) * rx + cx;
  8031. y0 = mathSin$1(startAngle) * ry + cy;
  8032. }
  8033. l = mathMax$2(rx, ry) * mathMin$2(PI2$1, Math.abs(delta));
  8034. xi = mathCos$1(endAngle) * rx + cx;
  8035. yi = mathSin$1(endAngle) * ry + cy;
  8036. break;
  8037. case CMD.R: {
  8038. x0 = xi = data[i++];
  8039. y0 = yi = data[i++];
  8040. var width = data[i++];
  8041. var height = data[i++];
  8042. l = width * 2 + height * 2;
  8043. break;
  8044. }
  8045. case CMD.Z: {
  8046. var dx = x0 - xi;
  8047. var dy = y0 - yi;
  8048. l = Math.sqrt(dx * dx + dy * dy);
  8049. xi = x0;
  8050. yi = y0;
  8051. break;
  8052. }
  8053. }
  8054. if (l >= 0) {
  8055. pathSegLen[segCount++] = l;
  8056. pathTotalLen += l;
  8057. }
  8058. }
  8059. this._pathLen = pathTotalLen;
  8060. return pathTotalLen;
  8061. };
  8062. PathProxy.prototype.rebuildPath = function (ctx, percent) {
  8063. var d = this.data;
  8064. var ux = this._ux;
  8065. var uy = this._uy;
  8066. var len = this._len;
  8067. var x0;
  8068. var y0;
  8069. var xi;
  8070. var yi;
  8071. var x;
  8072. var y;
  8073. var drawPart = percent < 1;
  8074. var pathSegLen;
  8075. var pathTotalLen;
  8076. var accumLength = 0;
  8077. var segCount = 0;
  8078. var displayedLength;
  8079. var pendingPtDist = 0;
  8080. var pendingPtX;
  8081. var pendingPtY;
  8082. if (drawPart) {
  8083. if (!this._pathSegLen) {
  8084. this._calculateLength();
  8085. }
  8086. pathSegLen = this._pathSegLen;
  8087. pathTotalLen = this._pathLen;
  8088. displayedLength = percent * pathTotalLen;
  8089. if (!displayedLength) {
  8090. return;
  8091. }
  8092. }
  8093. lo: for (var i = 0; i < len;) {
  8094. var cmd = d[i++];
  8095. var isFirst = i === 1;
  8096. if (isFirst) {
  8097. xi = d[i];
  8098. yi = d[i + 1];
  8099. x0 = xi;
  8100. y0 = yi;
  8101. }
  8102. if (cmd !== CMD.L && pendingPtDist > 0) {
  8103. ctx.lineTo(pendingPtX, pendingPtY);
  8104. pendingPtDist = 0;
  8105. }
  8106. switch (cmd) {
  8107. case CMD.M:
  8108. x0 = xi = d[i++];
  8109. y0 = yi = d[i++];
  8110. ctx.moveTo(xi, yi);
  8111. break;
  8112. case CMD.L: {
  8113. x = d[i++];
  8114. y = d[i++];
  8115. var dx = mathAbs(x - xi);
  8116. var dy = mathAbs(y - yi);
  8117. if (dx > ux || dy > uy) {
  8118. if (drawPart) {
  8119. var l = pathSegLen[segCount++];
  8120. if (accumLength + l > displayedLength) {
  8121. var t = (displayedLength - accumLength) / l;
  8122. ctx.lineTo(xi * (1 - t) + x * t, yi * (1 - t) + y * t);
  8123. break lo;
  8124. }
  8125. accumLength += l;
  8126. }
  8127. ctx.lineTo(x, y);
  8128. xi = x;
  8129. yi = y;
  8130. pendingPtDist = 0;
  8131. }
  8132. else {
  8133. var d2 = dx * dx + dy * dy;
  8134. if (d2 > pendingPtDist) {
  8135. pendingPtX = x;
  8136. pendingPtY = y;
  8137. pendingPtDist = d2;
  8138. }
  8139. }
  8140. break;
  8141. }
  8142. case CMD.C: {
  8143. var x1 = d[i++];
  8144. var y1 = d[i++];
  8145. var x2 = d[i++];
  8146. var y2 = d[i++];
  8147. var x3 = d[i++];
  8148. var y3 = d[i++];
  8149. if (drawPart) {
  8150. var l = pathSegLen[segCount++];
  8151. if (accumLength + l > displayedLength) {
  8152. var t = (displayedLength - accumLength) / l;
  8153. cubicSubdivide(xi, x1, x2, x3, t, tmpOutX);
  8154. cubicSubdivide(yi, y1, y2, y3, t, tmpOutY);
  8155. ctx.bezierCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2], tmpOutX[3], tmpOutY[3]);
  8156. break lo;
  8157. }
  8158. accumLength += l;
  8159. }
  8160. ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  8161. xi = x3;
  8162. yi = y3;
  8163. break;
  8164. }
  8165. case CMD.Q: {
  8166. var x1 = d[i++];
  8167. var y1 = d[i++];
  8168. var x2 = d[i++];
  8169. var y2 = d[i++];
  8170. if (drawPart) {
  8171. var l = pathSegLen[segCount++];
  8172. if (accumLength + l > displayedLength) {
  8173. var t = (displayedLength - accumLength) / l;
  8174. quadraticSubdivide(xi, x1, x2, t, tmpOutX);
  8175. quadraticSubdivide(yi, y1, y2, t, tmpOutY);
  8176. ctx.quadraticCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2]);
  8177. break lo;
  8178. }
  8179. accumLength += l;
  8180. }
  8181. ctx.quadraticCurveTo(x1, y1, x2, y2);
  8182. xi = x2;
  8183. yi = y2;
  8184. break;
  8185. }
  8186. case CMD.A:
  8187. var cx = d[i++];
  8188. var cy = d[i++];
  8189. var rx = d[i++];
  8190. var ry = d[i++];
  8191. var startAngle = d[i++];
  8192. var delta = d[i++];
  8193. var psi = d[i++];
  8194. var anticlockwise = !d[i++];
  8195. var r = (rx > ry) ? rx : ry;
  8196. var isEllipse = mathAbs(rx - ry) > 1e-3;
  8197. var endAngle = startAngle + delta;
  8198. var breakBuild = false;
  8199. if (drawPart) {
  8200. var l = pathSegLen[segCount++];
  8201. if (accumLength + l > displayedLength) {
  8202. endAngle = startAngle + delta * (displayedLength - accumLength) / l;
  8203. breakBuild = true;
  8204. }
  8205. accumLength += l;
  8206. }
  8207. if (isEllipse && ctx.ellipse) {
  8208. ctx.ellipse(cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise);
  8209. }
  8210. else {
  8211. ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  8212. }
  8213. if (breakBuild) {
  8214. break lo;
  8215. }
  8216. if (isFirst) {
  8217. x0 = mathCos$1(startAngle) * rx + cx;
  8218. y0 = mathSin$1(startAngle) * ry + cy;
  8219. }
  8220. xi = mathCos$1(endAngle) * rx + cx;
  8221. yi = mathSin$1(endAngle) * ry + cy;
  8222. break;
  8223. case CMD.R:
  8224. x0 = xi = d[i];
  8225. y0 = yi = d[i + 1];
  8226. x = d[i++];
  8227. y = d[i++];
  8228. var width = d[i++];
  8229. var height = d[i++];
  8230. if (drawPart) {
  8231. var l = pathSegLen[segCount++];
  8232. if (accumLength + l > displayedLength) {
  8233. var d_1 = displayedLength - accumLength;
  8234. ctx.moveTo(x, y);
  8235. ctx.lineTo(x + mathMin$2(d_1, width), y);
  8236. d_1 -= width;
  8237. if (d_1 > 0) {
  8238. ctx.lineTo(x + width, y + mathMin$2(d_1, height));
  8239. }
  8240. d_1 -= height;
  8241. if (d_1 > 0) {
  8242. ctx.lineTo(x + mathMax$2(width - d_1, 0), y + height);
  8243. }
  8244. d_1 -= width;
  8245. if (d_1 > 0) {
  8246. ctx.lineTo(x, y + mathMax$2(height - d_1, 0));
  8247. }
  8248. break lo;
  8249. }
  8250. accumLength += l;
  8251. }
  8252. ctx.rect(x, y, width, height);
  8253. break;
  8254. case CMD.Z:
  8255. if (drawPart) {
  8256. var l = pathSegLen[segCount++];
  8257. if (accumLength + l > displayedLength) {
  8258. var t = (displayedLength - accumLength) / l;
  8259. ctx.lineTo(xi * (1 - t) + x0 * t, yi * (1 - t) + y0 * t);
  8260. break lo;
  8261. }
  8262. accumLength += l;
  8263. }
  8264. ctx.closePath();
  8265. xi = x0;
  8266. yi = y0;
  8267. }
  8268. }
  8269. };
  8270. PathProxy.prototype.clone = function () {
  8271. var newProxy = new PathProxy();
  8272. var data = this.data;
  8273. newProxy.data = data.slice ? data.slice()
  8274. : Array.prototype.slice.call(data);
  8275. newProxy._len = this._len;
  8276. return newProxy;
  8277. };
  8278. PathProxy.CMD = CMD;
  8279. PathProxy.initDefaultProps = (function () {
  8280. var proto = PathProxy.prototype;
  8281. proto._saveData = true;
  8282. proto._ux = 0;
  8283. proto._uy = 0;
  8284. proto._pendingPtDist = 0;
  8285. proto._version = 0;
  8286. })();
  8287. return PathProxy;
  8288. }());
  8289. function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
  8290. if (lineWidth === 0) {
  8291. return false;
  8292. }
  8293. var _l = lineWidth;
  8294. var _a = 0;
  8295. var _b = x0;
  8296. if ((y > y0 + _l && y > y1 + _l)
  8297. || (y < y0 - _l && y < y1 - _l)
  8298. || (x > x0 + _l && x > x1 + _l)
  8299. || (x < x0 - _l && x < x1 - _l)) {
  8300. return false;
  8301. }
  8302. if (x0 !== x1) {
  8303. _a = (y0 - y1) / (x0 - x1);
  8304. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  8305. }
  8306. else {
  8307. return Math.abs(x - x0) <= _l / 2;
  8308. }
  8309. var tmp = _a * x - y + _b;
  8310. var _s = tmp * tmp / (_a * _a + 1);
  8311. return _s <= _l / 2 * _l / 2;
  8312. }
  8313. function containStroke$1(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  8314. if (lineWidth === 0) {
  8315. return false;
  8316. }
  8317. var _l = lineWidth;
  8318. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  8319. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  8320. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  8321. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)) {
  8322. return false;
  8323. }
  8324. var d = cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  8325. return d <= _l / 2;
  8326. }
  8327. function containStroke$2(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  8328. if (lineWidth === 0) {
  8329. return false;
  8330. }
  8331. var _l = lineWidth;
  8332. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l)
  8333. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  8334. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  8335. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)) {
  8336. return false;
  8337. }
  8338. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  8339. return d <= _l / 2;
  8340. }
  8341. var PI2$2 = Math.PI * 2;
  8342. function normalizeRadian(angle) {
  8343. angle %= PI2$2;
  8344. if (angle < 0) {
  8345. angle += PI2$2;
  8346. }
  8347. return angle;
  8348. }
  8349. var PI2$3 = Math.PI * 2;
  8350. function containStroke$3(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  8351. if (lineWidth === 0) {
  8352. return false;
  8353. }
  8354. var _l = lineWidth;
  8355. x -= cx;
  8356. y -= cy;
  8357. var d = Math.sqrt(x * x + y * y);
  8358. if ((d - _l > r) || (d + _l < r)) {
  8359. return false;
  8360. }
  8361. if (Math.abs(startAngle - endAngle) % PI2$3 < 1e-4) {
  8362. return true;
  8363. }
  8364. if (anticlockwise) {
  8365. var tmp = startAngle;
  8366. startAngle = normalizeRadian(endAngle);
  8367. endAngle = normalizeRadian(tmp);
  8368. }
  8369. else {
  8370. startAngle = normalizeRadian(startAngle);
  8371. endAngle = normalizeRadian(endAngle);
  8372. }
  8373. if (startAngle > endAngle) {
  8374. endAngle += PI2$3;
  8375. }
  8376. var angle = Math.atan2(y, x);
  8377. if (angle < 0) {
  8378. angle += PI2$3;
  8379. }
  8380. return (angle >= startAngle && angle <= endAngle)
  8381. || (angle + PI2$3 >= startAngle && angle + PI2$3 <= endAngle);
  8382. }
  8383. function windingLine(x0, y0, x1, y1, x, y) {
  8384. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  8385. return 0;
  8386. }
  8387. if (y1 === y0) {
  8388. return 0;
  8389. }
  8390. var t = (y - y0) / (y1 - y0);
  8391. var dir = y1 < y0 ? 1 : -1;
  8392. if (t === 1 || t === 0) {
  8393. dir = y1 < y0 ? 0.5 : -0.5;
  8394. }
  8395. var x_ = t * (x1 - x0) + x0;
  8396. return x_ === x ? Infinity : x_ > x ? dir : 0;
  8397. }
  8398. var CMD$1 = PathProxy.CMD;
  8399. var PI2$4 = Math.PI * 2;
  8400. var EPSILON$3 = 1e-4;
  8401. function isAroundEqual(a, b) {
  8402. return Math.abs(a - b) < EPSILON$3;
  8403. }
  8404. var roots = [-1, -1, -1];
  8405. var extrema = [-1, -1];
  8406. function swapExtrema() {
  8407. var tmp = extrema[0];
  8408. extrema[0] = extrema[1];
  8409. extrema[1] = tmp;
  8410. }
  8411. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  8412. if ((y > y0 && y > y1 && y > y2 && y > y3)
  8413. || (y < y0 && y < y1 && y < y2 && y < y3)) {
  8414. return 0;
  8415. }
  8416. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  8417. if (nRoots === 0) {
  8418. return 0;
  8419. }
  8420. else {
  8421. var w = 0;
  8422. var nExtrema = -1;
  8423. var y0_ = void 0;
  8424. var y1_ = void 0;
  8425. for (var i = 0; i < nRoots; i++) {
  8426. var t = roots[i];
  8427. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  8428. var x_ = cubicAt(x0, x1, x2, x3, t);
  8429. if (x_ < x) {
  8430. continue;
  8431. }
  8432. if (nExtrema < 0) {
  8433. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  8434. if (extrema[1] < extrema[0] && nExtrema > 1) {
  8435. swapExtrema();
  8436. }
  8437. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  8438. if (nExtrema > 1) {
  8439. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  8440. }
  8441. }
  8442. if (nExtrema === 2) {
  8443. if (t < extrema[0]) {
  8444. w += y0_ < y0 ? unit : -unit;
  8445. }
  8446. else if (t < extrema[1]) {
  8447. w += y1_ < y0_ ? unit : -unit;
  8448. }
  8449. else {
  8450. w += y3 < y1_ ? unit : -unit;
  8451. }
  8452. }
  8453. else {
  8454. if (t < extrema[0]) {
  8455. w += y0_ < y0 ? unit : -unit;
  8456. }
  8457. else {
  8458. w += y3 < y0_ ? unit : -unit;
  8459. }
  8460. }
  8461. }
  8462. return w;
  8463. }
  8464. }
  8465. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  8466. if ((y > y0 && y > y1 && y > y2)
  8467. || (y < y0 && y < y1 && y < y2)) {
  8468. return 0;
  8469. }
  8470. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  8471. if (nRoots === 0) {
  8472. return 0;
  8473. }
  8474. else {
  8475. var t = quadraticExtremum(y0, y1, y2);
  8476. if (t >= 0 && t <= 1) {
  8477. var w = 0;
  8478. var y_ = quadraticAt(y0, y1, y2, t);
  8479. for (var i = 0; i < nRoots; i++) {
  8480. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  8481. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  8482. if (x_ < x) {
  8483. continue;
  8484. }
  8485. if (roots[i] < t) {
  8486. w += y_ < y0 ? unit : -unit;
  8487. }
  8488. else {
  8489. w += y2 < y_ ? unit : -unit;
  8490. }
  8491. }
  8492. return w;
  8493. }
  8494. else {
  8495. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  8496. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  8497. if (x_ < x) {
  8498. return 0;
  8499. }
  8500. return y2 < y0 ? unit : -unit;
  8501. }
  8502. }
  8503. }
  8504. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  8505. y -= cy;
  8506. if (y > r || y < -r) {
  8507. return 0;
  8508. }
  8509. var tmp = Math.sqrt(r * r - y * y);
  8510. roots[0] = -tmp;
  8511. roots[1] = tmp;
  8512. var dTheta = Math.abs(startAngle - endAngle);
  8513. if (dTheta < 1e-4) {
  8514. return 0;
  8515. }
  8516. if (dTheta >= PI2$4 - 1e-4) {
  8517. startAngle = 0;
  8518. endAngle = PI2$4;
  8519. var dir = anticlockwise ? 1 : -1;
  8520. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  8521. return dir;
  8522. }
  8523. else {
  8524. return 0;
  8525. }
  8526. }
  8527. if (startAngle > endAngle) {
  8528. var tmp_1 = startAngle;
  8529. startAngle = endAngle;
  8530. endAngle = tmp_1;
  8531. }
  8532. if (startAngle < 0) {
  8533. startAngle += PI2$4;
  8534. endAngle += PI2$4;
  8535. }
  8536. var w = 0;
  8537. for (var i = 0; i < 2; i++) {
  8538. var x_ = roots[i];
  8539. if (x_ + cx > x) {
  8540. var angle = Math.atan2(y, x_);
  8541. var dir = anticlockwise ? 1 : -1;
  8542. if (angle < 0) {
  8543. angle = PI2$4 + angle;
  8544. }
  8545. if ((angle >= startAngle && angle <= endAngle)
  8546. || (angle + PI2$4 >= startAngle && angle + PI2$4 <= endAngle)) {
  8547. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  8548. dir = -dir;
  8549. }
  8550. w += dir;
  8551. }
  8552. }
  8553. }
  8554. return w;
  8555. }
  8556. function containPath(path, lineWidth, isStroke, x, y) {
  8557. var data = path.data;
  8558. var len = path.len();
  8559. var w = 0;
  8560. var xi = 0;
  8561. var yi = 0;
  8562. var x0 = 0;
  8563. var y0 = 0;
  8564. var x1;
  8565. var y1;
  8566. for (var i = 0; i < len;) {
  8567. var cmd = data[i++];
  8568. var isFirst = i === 1;
  8569. if (cmd === CMD$1.M && i > 1) {
  8570. if (!isStroke) {
  8571. w += windingLine(xi, yi, x0, y0, x, y);
  8572. }
  8573. }
  8574. if (isFirst) {
  8575. xi = data[i];
  8576. yi = data[i + 1];
  8577. x0 = xi;
  8578. y0 = yi;
  8579. }
  8580. switch (cmd) {
  8581. case CMD$1.M:
  8582. x0 = data[i++];
  8583. y0 = data[i++];
  8584. xi = x0;
  8585. yi = y0;
  8586. break;
  8587. case CMD$1.L:
  8588. if (isStroke) {
  8589. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  8590. return true;
  8591. }
  8592. }
  8593. else {
  8594. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  8595. }
  8596. xi = data[i++];
  8597. yi = data[i++];
  8598. break;
  8599. case CMD$1.C:
  8600. if (isStroke) {
  8601. if (containStroke$1(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8602. return true;
  8603. }
  8604. }
  8605. else {
  8606. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8607. }
  8608. xi = data[i++];
  8609. yi = data[i++];
  8610. break;
  8611. case CMD$1.Q:
  8612. if (isStroke) {
  8613. if (containStroke$2(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8614. return true;
  8615. }
  8616. }
  8617. else {
  8618. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8619. }
  8620. xi = data[i++];
  8621. yi = data[i++];
  8622. break;
  8623. case CMD$1.A:
  8624. var cx = data[i++];
  8625. var cy = data[i++];
  8626. var rx = data[i++];
  8627. var ry = data[i++];
  8628. var theta = data[i++];
  8629. var dTheta = data[i++];
  8630. i += 1;
  8631. var anticlockwise = !!(1 - data[i++]);
  8632. x1 = Math.cos(theta) * rx + cx;
  8633. y1 = Math.sin(theta) * ry + cy;
  8634. if (!isFirst) {
  8635. w += windingLine(xi, yi, x1, y1, x, y);
  8636. }
  8637. else {
  8638. x0 = x1;
  8639. y0 = y1;
  8640. }
  8641. var _x = (x - cx) * ry / rx + cx;
  8642. if (isStroke) {
  8643. if (containStroke$3(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  8644. return true;
  8645. }
  8646. }
  8647. else {
  8648. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  8649. }
  8650. xi = Math.cos(theta + dTheta) * rx + cx;
  8651. yi = Math.sin(theta + dTheta) * ry + cy;
  8652. break;
  8653. case CMD$1.R:
  8654. x0 = xi = data[i++];
  8655. y0 = yi = data[i++];
  8656. var width = data[i++];
  8657. var height = data[i++];
  8658. x1 = x0 + width;
  8659. y1 = y0 + height;
  8660. if (isStroke) {
  8661. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  8662. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  8663. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  8664. || containStroke(x0, y1, x0, y0, lineWidth, x, y)) {
  8665. return true;
  8666. }
  8667. }
  8668. else {
  8669. w += windingLine(x1, y0, x1, y1, x, y);
  8670. w += windingLine(x0, y1, x0, y0, x, y);
  8671. }
  8672. break;
  8673. case CMD$1.Z:
  8674. if (isStroke) {
  8675. if (containStroke(xi, yi, x0, y0, lineWidth, x, y)) {
  8676. return true;
  8677. }
  8678. }
  8679. else {
  8680. w += windingLine(xi, yi, x0, y0, x, y);
  8681. }
  8682. xi = x0;
  8683. yi = y0;
  8684. break;
  8685. }
  8686. }
  8687. if (!isStroke && !isAroundEqual(yi, y0)) {
  8688. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  8689. }
  8690. return w !== 0;
  8691. }
  8692. function contain(pathProxy, x, y) {
  8693. return containPath(pathProxy, 0, false, x, y);
  8694. }
  8695. function containStroke$4(pathProxy, lineWidth, x, y) {
  8696. return containPath(pathProxy, lineWidth, true, x, y);
  8697. }
  8698. var DEFAULT_PATH_STYLE = defaults({
  8699. fill: '#000',
  8700. stroke: null,
  8701. strokePercent: 1,
  8702. fillOpacity: 1,
  8703. strokeOpacity: 1,
  8704. lineDashOffset: 0,
  8705. lineWidth: 1,
  8706. lineCap: 'butt',
  8707. miterLimit: 10,
  8708. strokeNoScale: false,
  8709. strokeFirst: false
  8710. }, DEFAULT_COMMON_STYLE);
  8711. var DEFAULT_PATH_ANIMATION_PROPS = {
  8712. style: defaults({
  8713. fill: true,
  8714. stroke: true,
  8715. strokePercent: true,
  8716. fillOpacity: true,
  8717. strokeOpacity: true,
  8718. lineDashOffset: true,
  8719. lineWidth: true,
  8720. miterLimit: true
  8721. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  8722. };
  8723. var pathCopyParams = TRANSFORMABLE_PROPS.concat(['invisible',
  8724. 'culling', 'z', 'z2', 'zlevel', 'parent'
  8725. ]);
  8726. var Path = (function (_super) {
  8727. __extends(Path, _super);
  8728. function Path(opts) {
  8729. return _super.call(this, opts) || this;
  8730. }
  8731. Path.prototype.update = function () {
  8732. var _this = this;
  8733. _super.prototype.update.call(this);
  8734. var style = this.style;
  8735. if (style.decal) {
  8736. var decalEl = this._decalEl = this._decalEl || new Path();
  8737. if (decalEl.buildPath === Path.prototype.buildPath) {
  8738. decalEl.buildPath = function (ctx) {
  8739. _this.buildPath(ctx, _this.shape);
  8740. };
  8741. }
  8742. decalEl.silent = true;
  8743. var decalElStyle = decalEl.style;
  8744. for (var key in style) {
  8745. if (decalElStyle[key] !== style[key]) {
  8746. decalElStyle[key] = style[key];
  8747. }
  8748. }
  8749. decalElStyle.fill = style.fill ? style.decal : null;
  8750. decalElStyle.decal = null;
  8751. decalElStyle.shadowColor = null;
  8752. style.strokeFirst && (decalElStyle.stroke = null);
  8753. for (var i = 0; i < pathCopyParams.length; ++i) {
  8754. decalEl[pathCopyParams[i]] = this[pathCopyParams[i]];
  8755. }
  8756. decalEl.__dirty |= REDRAW_BIT;
  8757. }
  8758. else if (this._decalEl) {
  8759. this._decalEl = null;
  8760. }
  8761. };
  8762. Path.prototype.getDecalElement = function () {
  8763. return this._decalEl;
  8764. };
  8765. Path.prototype._init = function (props) {
  8766. var keysArr = keys(props);
  8767. this.shape = this.getDefaultShape();
  8768. var defaultStyle = this.getDefaultStyle();
  8769. if (defaultStyle) {
  8770. this.useStyle(defaultStyle);
  8771. }
  8772. for (var i = 0; i < keysArr.length; i++) {
  8773. var key = keysArr[i];
  8774. var value = props[key];
  8775. if (key === 'style') {
  8776. if (!this.style) {
  8777. this.useStyle(value);
  8778. }
  8779. else {
  8780. extend(this.style, value);
  8781. }
  8782. }
  8783. else if (key === 'shape') {
  8784. extend(this.shape, value);
  8785. }
  8786. else {
  8787. _super.prototype.attrKV.call(this, key, value);
  8788. }
  8789. }
  8790. if (!this.style) {
  8791. this.useStyle({});
  8792. }
  8793. };
  8794. Path.prototype.getDefaultStyle = function () {
  8795. return null;
  8796. };
  8797. Path.prototype.getDefaultShape = function () {
  8798. return {};
  8799. };
  8800. Path.prototype.canBeInsideText = function () {
  8801. return this.hasFill();
  8802. };
  8803. Path.prototype.getInsideTextFill = function () {
  8804. var pathFill = this.style.fill;
  8805. if (pathFill !== 'none') {
  8806. if (isString(pathFill)) {
  8807. var fillLum = lum(pathFill, 0);
  8808. if (fillLum > 0.5) {
  8809. return DARK_LABEL_COLOR;
  8810. }
  8811. else if (fillLum > 0.2) {
  8812. return LIGHTER_LABEL_COLOR;
  8813. }
  8814. return LIGHT_LABEL_COLOR;
  8815. }
  8816. else if (pathFill) {
  8817. return LIGHT_LABEL_COLOR;
  8818. }
  8819. }
  8820. return DARK_LABEL_COLOR;
  8821. };
  8822. Path.prototype.getInsideTextStroke = function (textFill) {
  8823. var pathFill = this.style.fill;
  8824. if (isString(pathFill)) {
  8825. var zr = this.__zr;
  8826. var isDarkMode = !!(zr && zr.isDarkMode());
  8827. var isDarkLabel = lum(textFill, 0) < DARK_MODE_THRESHOLD;
  8828. if (isDarkMode === isDarkLabel) {
  8829. return pathFill;
  8830. }
  8831. }
  8832. };
  8833. Path.prototype.buildPath = function (ctx, shapeCfg, inBatch) { };
  8834. Path.prototype.pathUpdated = function () {
  8835. this.__dirty &= ~SHAPE_CHANGED_BIT;
  8836. };
  8837. Path.prototype.getUpdatedPathProxy = function (inBatch) {
  8838. !this.path && this.createPathProxy();
  8839. this.path.beginPath();
  8840. this.buildPath(this.path, this.shape, inBatch);
  8841. return this.path;
  8842. };
  8843. Path.prototype.createPathProxy = function () {
  8844. this.path = new PathProxy(false);
  8845. };
  8846. Path.prototype.hasStroke = function () {
  8847. var style = this.style;
  8848. var stroke = style.stroke;
  8849. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  8850. };
  8851. Path.prototype.hasFill = function () {
  8852. var style = this.style;
  8853. var fill = style.fill;
  8854. return fill != null && fill !== 'none';
  8855. };
  8856. Path.prototype.getBoundingRect = function () {
  8857. var rect = this._rect;
  8858. var style = this.style;
  8859. var needsUpdateRect = !rect;
  8860. if (needsUpdateRect) {
  8861. var firstInvoke = false;
  8862. if (!this.path) {
  8863. firstInvoke = true;
  8864. this.createPathProxy();
  8865. }
  8866. var path = this.path;
  8867. if (firstInvoke || (this.__dirty & SHAPE_CHANGED_BIT)) {
  8868. path.beginPath();
  8869. this.buildPath(path, this.shape, false);
  8870. this.pathUpdated();
  8871. }
  8872. rect = path.getBoundingRect();
  8873. }
  8874. this._rect = rect;
  8875. if (this.hasStroke() && this.path && this.path.len() > 0) {
  8876. var rectStroke = this._rectStroke || (this._rectStroke = rect.clone());
  8877. if (this.__dirty || needsUpdateRect) {
  8878. rectStroke.copy(rect);
  8879. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  8880. var w = style.lineWidth;
  8881. if (!this.hasFill()) {
  8882. var strokeContainThreshold = this.strokeContainThreshold;
  8883. w = Math.max(w, strokeContainThreshold == null ? 4 : strokeContainThreshold);
  8884. }
  8885. if (lineScale > 1e-10) {
  8886. rectStroke.width += w / lineScale;
  8887. rectStroke.height += w / lineScale;
  8888. rectStroke.x -= w / lineScale / 2;
  8889. rectStroke.y -= w / lineScale / 2;
  8890. }
  8891. }
  8892. return rectStroke;
  8893. }
  8894. return rect;
  8895. };
  8896. Path.prototype.contain = function (x, y) {
  8897. var localPos = this.transformCoordToLocal(x, y);
  8898. var rect = this.getBoundingRect();
  8899. var style = this.style;
  8900. x = localPos[0];
  8901. y = localPos[1];
  8902. if (rect.contain(x, y)) {
  8903. var pathProxy = this.path;
  8904. if (this.hasStroke()) {
  8905. var lineWidth = style.lineWidth;
  8906. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  8907. if (lineScale > 1e-10) {
  8908. if (!this.hasFill()) {
  8909. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  8910. }
  8911. if (containStroke$4(pathProxy, lineWidth / lineScale, x, y)) {
  8912. return true;
  8913. }
  8914. }
  8915. }
  8916. if (this.hasFill()) {
  8917. return contain(pathProxy, x, y);
  8918. }
  8919. }
  8920. return false;
  8921. };
  8922. Path.prototype.dirtyShape = function () {
  8923. this.__dirty |= SHAPE_CHANGED_BIT;
  8924. if (this._rect) {
  8925. this._rect = null;
  8926. }
  8927. if (this._decalEl) {
  8928. this._decalEl.dirtyShape();
  8929. }
  8930. this.markRedraw();
  8931. };
  8932. Path.prototype.dirty = function () {
  8933. this.dirtyStyle();
  8934. this.dirtyShape();
  8935. };
  8936. Path.prototype.animateShape = function (loop) {
  8937. return this.animate('shape', loop);
  8938. };
  8939. Path.prototype.updateDuringAnimation = function (targetKey) {
  8940. if (targetKey === 'style') {
  8941. this.dirtyStyle();
  8942. }
  8943. else if (targetKey === 'shape') {
  8944. this.dirtyShape();
  8945. }
  8946. else {
  8947. this.markRedraw();
  8948. }
  8949. };
  8950. Path.prototype.attrKV = function (key, value) {
  8951. if (key === 'shape') {
  8952. this.setShape(value);
  8953. }
  8954. else {
  8955. _super.prototype.attrKV.call(this, key, value);
  8956. }
  8957. };
  8958. Path.prototype.setShape = function (keyOrObj, value) {
  8959. var shape = this.shape;
  8960. if (!shape) {
  8961. shape = this.shape = {};
  8962. }
  8963. if (typeof keyOrObj === 'string') {
  8964. shape[keyOrObj] = value;
  8965. }
  8966. else {
  8967. extend(shape, keyOrObj);
  8968. }
  8969. this.dirtyShape();
  8970. return this;
  8971. };
  8972. Path.prototype.shapeChanged = function () {
  8973. return !!(this.__dirty & SHAPE_CHANGED_BIT);
  8974. };
  8975. Path.prototype.createStyle = function (obj) {
  8976. return createObject(DEFAULT_PATH_STYLE, obj);
  8977. };
  8978. Path.prototype._innerSaveToNormal = function (toState) {
  8979. _super.prototype._innerSaveToNormal.call(this, toState);
  8980. var normalState = this._normalState;
  8981. if (toState.shape && !normalState.shape) {
  8982. normalState.shape = extend({}, this.shape);
  8983. }
  8984. };
  8985. Path.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  8986. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  8987. var needsRestoreToNormal = !(state && keepCurrentStates);
  8988. var targetShape;
  8989. if (state && state.shape) {
  8990. if (transition) {
  8991. if (keepCurrentStates) {
  8992. targetShape = state.shape;
  8993. }
  8994. else {
  8995. targetShape = extend({}, normalState.shape);
  8996. extend(targetShape, state.shape);
  8997. }
  8998. }
  8999. else {
  9000. targetShape = extend({}, keepCurrentStates ? this.shape : normalState.shape);
  9001. extend(targetShape, state.shape);
  9002. }
  9003. }
  9004. else if (needsRestoreToNormal) {
  9005. targetShape = normalState.shape;
  9006. }
  9007. if (targetShape) {
  9008. if (transition) {
  9009. this.shape = extend({}, this.shape);
  9010. var targetShapePrimaryProps = {};
  9011. var shapeKeys = keys(targetShape);
  9012. for (var i = 0; i < shapeKeys.length; i++) {
  9013. var key = shapeKeys[i];
  9014. if (typeof targetShape[key] === 'object') {
  9015. this.shape[key] = targetShape[key];
  9016. }
  9017. else {
  9018. targetShapePrimaryProps[key] = targetShape[key];
  9019. }
  9020. }
  9021. this._transitionState(stateName, {
  9022. shape: targetShapePrimaryProps
  9023. }, animationCfg);
  9024. }
  9025. else {
  9026. this.shape = targetShape;
  9027. this.dirtyShape();
  9028. }
  9029. }
  9030. };
  9031. Path.prototype._mergeStates = function (states) {
  9032. var mergedState = _super.prototype._mergeStates.call(this, states);
  9033. var mergedShape;
  9034. for (var i = 0; i < states.length; i++) {
  9035. var state = states[i];
  9036. if (state.shape) {
  9037. mergedShape = mergedShape || {};
  9038. this._mergeStyle(mergedShape, state.shape);
  9039. }
  9040. }
  9041. if (mergedShape) {
  9042. mergedState.shape = mergedShape;
  9043. }
  9044. return mergedState;
  9045. };
  9046. Path.prototype.getAnimationStyleProps = function () {
  9047. return DEFAULT_PATH_ANIMATION_PROPS;
  9048. };
  9049. Path.prototype.isZeroArea = function () {
  9050. return false;
  9051. };
  9052. Path.extend = function (defaultProps) {
  9053. var Sub = (function (_super) {
  9054. __extends(Sub, _super);
  9055. function Sub(opts) {
  9056. var _this = _super.call(this, opts) || this;
  9057. defaultProps.init && defaultProps.init.call(_this, opts);
  9058. return _this;
  9059. }
  9060. Sub.prototype.getDefaultStyle = function () {
  9061. return clone(defaultProps.style);
  9062. };
  9063. Sub.prototype.getDefaultShape = function () {
  9064. return clone(defaultProps.shape);
  9065. };
  9066. return Sub;
  9067. }(Path));
  9068. for (var key in defaultProps) {
  9069. if (typeof defaultProps[key] === 'function') {
  9070. Sub.prototype[key] = defaultProps[key];
  9071. }
  9072. }
  9073. return Sub;
  9074. };
  9075. Path.initDefaultProps = (function () {
  9076. var pathProto = Path.prototype;
  9077. pathProto.type = 'path';
  9078. pathProto.strokeContainThreshold = 5;
  9079. pathProto.segmentIgnoreThreshold = 0;
  9080. pathProto.subPixelOptimize = false;
  9081. pathProto.autoBatch = false;
  9082. pathProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT | SHAPE_CHANGED_BIT;
  9083. })();
  9084. return Path;
  9085. }(Displayable));
  9086. var CMD$2 = PathProxy.CMD;
  9087. var points = [[], [], []];
  9088. var mathSqrt$1 = Math.sqrt;
  9089. var mathAtan2 = Math.atan2;
  9090. function transformPath(path, m) {
  9091. if (!m) {
  9092. return;
  9093. }
  9094. var data = path.data;
  9095. var len = path.len();
  9096. var cmd;
  9097. var nPoint;
  9098. var i;
  9099. var j;
  9100. var k;
  9101. var p;
  9102. var M = CMD$2.M;
  9103. var C = CMD$2.C;
  9104. var L = CMD$2.L;
  9105. var R = CMD$2.R;
  9106. var A = CMD$2.A;
  9107. var Q = CMD$2.Q;
  9108. for (i = 0, j = 0; i < len;) {
  9109. cmd = data[i++];
  9110. j = i;
  9111. nPoint = 0;
  9112. switch (cmd) {
  9113. case M:
  9114. nPoint = 1;
  9115. break;
  9116. case L:
  9117. nPoint = 1;
  9118. break;
  9119. case C:
  9120. nPoint = 3;
  9121. break;
  9122. case Q:
  9123. nPoint = 2;
  9124. break;
  9125. case A:
  9126. var x = m[4];
  9127. var y = m[5];
  9128. var sx = mathSqrt$1(m[0] * m[0] + m[1] * m[1]);
  9129. var sy = mathSqrt$1(m[2] * m[2] + m[3] * m[3]);
  9130. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  9131. data[i] *= sx;
  9132. data[i++] += x;
  9133. data[i] *= sy;
  9134. data[i++] += y;
  9135. data[i++] *= sx;
  9136. data[i++] *= sy;
  9137. data[i++] += angle;
  9138. data[i++] += angle;
  9139. i += 2;
  9140. j = i;
  9141. break;
  9142. case R:
  9143. p[0] = data[i++];
  9144. p[1] = data[i++];
  9145. applyTransform(p, p, m);
  9146. data[j++] = p[0];
  9147. data[j++] = p[1];
  9148. p[0] += data[i++];
  9149. p[1] += data[i++];
  9150. applyTransform(p, p, m);
  9151. data[j++] = p[0];
  9152. data[j++] = p[1];
  9153. }
  9154. for (k = 0; k < nPoint; k++) {
  9155. var p_1 = points[k];
  9156. p_1[0] = data[i++];
  9157. p_1[1] = data[i++];
  9158. applyTransform(p_1, p_1, m);
  9159. data[j++] = p_1[0];
  9160. data[j++] = p_1[1];
  9161. }
  9162. }
  9163. path.increaseVersion();
  9164. }
  9165. var mathSqrt$2 = Math.sqrt;
  9166. var mathSin$2 = Math.sin;
  9167. var mathCos$2 = Math.cos;
  9168. var PI$1 = Math.PI;
  9169. function vMag(v) {
  9170. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  9171. }
  9172. function vRatio(u, v) {
  9173. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  9174. }
  9175. function vAngle(u, v) {
  9176. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  9177. * Math.acos(vRatio(u, v));
  9178. }
  9179. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  9180. var psi = psiDeg * (PI$1 / 180.0);
  9181. var xp = mathCos$2(psi) * (x1 - x2) / 2.0
  9182. + mathSin$2(psi) * (y1 - y2) / 2.0;
  9183. var yp = -1 * mathSin$2(psi) * (x1 - x2) / 2.0
  9184. + mathCos$2(psi) * (y1 - y2) / 2.0;
  9185. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  9186. if (lambda > 1) {
  9187. rx *= mathSqrt$2(lambda);
  9188. ry *= mathSqrt$2(lambda);
  9189. }
  9190. var f = (fa === fs ? -1 : 1)
  9191. * mathSqrt$2((((rx * rx) * (ry * ry))
  9192. - ((rx * rx) * (yp * yp))
  9193. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  9194. + (ry * ry) * (xp * xp))) || 0;
  9195. var cxp = f * rx * yp / ry;
  9196. var cyp = f * -ry * xp / rx;
  9197. var cx = (x1 + x2) / 2.0
  9198. + mathCos$2(psi) * cxp
  9199. - mathSin$2(psi) * cyp;
  9200. var cy = (y1 + y2) / 2.0
  9201. + mathSin$2(psi) * cxp
  9202. + mathCos$2(psi) * cyp;
  9203. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  9204. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  9205. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  9206. var dTheta = vAngle(u, v);
  9207. if (vRatio(u, v) <= -1) {
  9208. dTheta = PI$1;
  9209. }
  9210. if (vRatio(u, v) >= 1) {
  9211. dTheta = 0;
  9212. }
  9213. if (dTheta < 0) {
  9214. var n = Math.round(dTheta / PI$1 * 1e6) / 1e6;
  9215. dTheta = PI$1 * 2 + (n % 2) * PI$1;
  9216. }
  9217. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  9218. }
  9219. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  9220. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  9221. function createPathProxyFromString(data) {
  9222. var path = new PathProxy();
  9223. if (!data) {
  9224. return path;
  9225. }
  9226. var cpx = 0;
  9227. var cpy = 0;
  9228. var subpathX = cpx;
  9229. var subpathY = cpy;
  9230. var prevCmd;
  9231. var CMD = PathProxy.CMD;
  9232. var cmdList = data.match(commandReg);
  9233. if (!cmdList) {
  9234. return path;
  9235. }
  9236. for (var l = 0; l < cmdList.length; l++) {
  9237. var cmdText = cmdList[l];
  9238. var cmdStr = cmdText.charAt(0);
  9239. var cmd = void 0;
  9240. var p = cmdText.match(numberReg) || [];
  9241. var pLen = p.length;
  9242. for (var i = 0; i < pLen; i++) {
  9243. p[i] = parseFloat(p[i]);
  9244. }
  9245. var off = 0;
  9246. while (off < pLen) {
  9247. var ctlPtx = void 0;
  9248. var ctlPty = void 0;
  9249. var rx = void 0;
  9250. var ry = void 0;
  9251. var psi = void 0;
  9252. var fa = void 0;
  9253. var fs = void 0;
  9254. var x1 = cpx;
  9255. var y1 = cpy;
  9256. var len = void 0;
  9257. var pathData = void 0;
  9258. switch (cmdStr) {
  9259. case 'l':
  9260. cpx += p[off++];
  9261. cpy += p[off++];
  9262. cmd = CMD.L;
  9263. path.addData(cmd, cpx, cpy);
  9264. break;
  9265. case 'L':
  9266. cpx = p[off++];
  9267. cpy = p[off++];
  9268. cmd = CMD.L;
  9269. path.addData(cmd, cpx, cpy);
  9270. break;
  9271. case 'm':
  9272. cpx += p[off++];
  9273. cpy += p[off++];
  9274. cmd = CMD.M;
  9275. path.addData(cmd, cpx, cpy);
  9276. subpathX = cpx;
  9277. subpathY = cpy;
  9278. cmdStr = 'l';
  9279. break;
  9280. case 'M':
  9281. cpx = p[off++];
  9282. cpy = p[off++];
  9283. cmd = CMD.M;
  9284. path.addData(cmd, cpx, cpy);
  9285. subpathX = cpx;
  9286. subpathY = cpy;
  9287. cmdStr = 'L';
  9288. break;
  9289. case 'h':
  9290. cpx += p[off++];
  9291. cmd = CMD.L;
  9292. path.addData(cmd, cpx, cpy);
  9293. break;
  9294. case 'H':
  9295. cpx = p[off++];
  9296. cmd = CMD.L;
  9297. path.addData(cmd, cpx, cpy);
  9298. break;
  9299. case 'v':
  9300. cpy += p[off++];
  9301. cmd = CMD.L;
  9302. path.addData(cmd, cpx, cpy);
  9303. break;
  9304. case 'V':
  9305. cpy = p[off++];
  9306. cmd = CMD.L;
  9307. path.addData(cmd, cpx, cpy);
  9308. break;
  9309. case 'C':
  9310. cmd = CMD.C;
  9311. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  9312. cpx = p[off - 2];
  9313. cpy = p[off - 1];
  9314. break;
  9315. case 'c':
  9316. cmd = CMD.C;
  9317. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  9318. cpx += p[off - 2];
  9319. cpy += p[off - 1];
  9320. break;
  9321. case 'S':
  9322. ctlPtx = cpx;
  9323. ctlPty = cpy;
  9324. len = path.len();
  9325. pathData = path.data;
  9326. if (prevCmd === CMD.C) {
  9327. ctlPtx += cpx - pathData[len - 4];
  9328. ctlPty += cpy - pathData[len - 3];
  9329. }
  9330. cmd = CMD.C;
  9331. x1 = p[off++];
  9332. y1 = p[off++];
  9333. cpx = p[off++];
  9334. cpy = p[off++];
  9335. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9336. break;
  9337. case 's':
  9338. ctlPtx = cpx;
  9339. ctlPty = cpy;
  9340. len = path.len();
  9341. pathData = path.data;
  9342. if (prevCmd === CMD.C) {
  9343. ctlPtx += cpx - pathData[len - 4];
  9344. ctlPty += cpy - pathData[len - 3];
  9345. }
  9346. cmd = CMD.C;
  9347. x1 = cpx + p[off++];
  9348. y1 = cpy + p[off++];
  9349. cpx += p[off++];
  9350. cpy += p[off++];
  9351. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9352. break;
  9353. case 'Q':
  9354. x1 = p[off++];
  9355. y1 = p[off++];
  9356. cpx = p[off++];
  9357. cpy = p[off++];
  9358. cmd = CMD.Q;
  9359. path.addData(cmd, x1, y1, cpx, cpy);
  9360. break;
  9361. case 'q':
  9362. x1 = p[off++] + cpx;
  9363. y1 = p[off++] + cpy;
  9364. cpx += p[off++];
  9365. cpy += p[off++];
  9366. cmd = CMD.Q;
  9367. path.addData(cmd, x1, y1, cpx, cpy);
  9368. break;
  9369. case 'T':
  9370. ctlPtx = cpx;
  9371. ctlPty = cpy;
  9372. len = path.len();
  9373. pathData = path.data;
  9374. if (prevCmd === CMD.Q) {
  9375. ctlPtx += cpx - pathData[len - 4];
  9376. ctlPty += cpy - pathData[len - 3];
  9377. }
  9378. cpx = p[off++];
  9379. cpy = p[off++];
  9380. cmd = CMD.Q;
  9381. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9382. break;
  9383. case 't':
  9384. ctlPtx = cpx;
  9385. ctlPty = cpy;
  9386. len = path.len();
  9387. pathData = path.data;
  9388. if (prevCmd === CMD.Q) {
  9389. ctlPtx += cpx - pathData[len - 4];
  9390. ctlPty += cpy - pathData[len - 3];
  9391. }
  9392. cpx += p[off++];
  9393. cpy += p[off++];
  9394. cmd = CMD.Q;
  9395. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9396. break;
  9397. case 'A':
  9398. rx = p[off++];
  9399. ry = p[off++];
  9400. psi = p[off++];
  9401. fa = p[off++];
  9402. fs = p[off++];
  9403. x1 = cpx, y1 = cpy;
  9404. cpx = p[off++];
  9405. cpy = p[off++];
  9406. cmd = CMD.A;
  9407. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9408. break;
  9409. case 'a':
  9410. rx = p[off++];
  9411. ry = p[off++];
  9412. psi = p[off++];
  9413. fa = p[off++];
  9414. fs = p[off++];
  9415. x1 = cpx, y1 = cpy;
  9416. cpx += p[off++];
  9417. cpy += p[off++];
  9418. cmd = CMD.A;
  9419. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9420. break;
  9421. }
  9422. }
  9423. if (cmdStr === 'z' || cmdStr === 'Z') {
  9424. cmd = CMD.Z;
  9425. path.addData(cmd);
  9426. cpx = subpathX;
  9427. cpy = subpathY;
  9428. }
  9429. prevCmd = cmd;
  9430. }
  9431. path.toStatic();
  9432. return path;
  9433. }
  9434. var SVGPath = (function (_super) {
  9435. __extends(SVGPath, _super);
  9436. function SVGPath() {
  9437. return _super !== null && _super.apply(this, arguments) || this;
  9438. }
  9439. SVGPath.prototype.applyTransform = function (m) { };
  9440. return SVGPath;
  9441. }(Path));
  9442. function isPathProxy(path) {
  9443. return path.setData != null;
  9444. }
  9445. function createPathOptions(str, opts) {
  9446. var pathProxy = createPathProxyFromString(str);
  9447. var innerOpts = extend({}, opts);
  9448. innerOpts.buildPath = function (path) {
  9449. if (isPathProxy(path)) {
  9450. path.setData(pathProxy.data);
  9451. var ctx = path.getContext();
  9452. if (ctx) {
  9453. path.rebuildPath(ctx, 1);
  9454. }
  9455. }
  9456. else {
  9457. var ctx = path;
  9458. pathProxy.rebuildPath(ctx, 1);
  9459. }
  9460. };
  9461. innerOpts.applyTransform = function (m) {
  9462. transformPath(pathProxy, m);
  9463. this.dirtyShape();
  9464. };
  9465. return innerOpts;
  9466. }
  9467. function createFromString(str, opts) {
  9468. return new SVGPath(createPathOptions(str, opts));
  9469. }
  9470. function extendFromString(str, defaultOpts) {
  9471. var innerOpts = createPathOptions(str, defaultOpts);
  9472. var Sub = (function (_super) {
  9473. __extends(Sub, _super);
  9474. function Sub(opts) {
  9475. var _this = _super.call(this, opts) || this;
  9476. _this.applyTransform = innerOpts.applyTransform;
  9477. _this.buildPath = innerOpts.buildPath;
  9478. return _this;
  9479. }
  9480. return Sub;
  9481. }(SVGPath));
  9482. return Sub;
  9483. }
  9484. function mergePath(pathEls, opts) {
  9485. var pathList = [];
  9486. var len = pathEls.length;
  9487. for (var i = 0; i < len; i++) {
  9488. var pathEl = pathEls[i];
  9489. pathList.push(pathEl.getUpdatedPathProxy(true));
  9490. }
  9491. var pathBundle = new Path(opts);
  9492. pathBundle.createPathProxy();
  9493. pathBundle.buildPath = function (path) {
  9494. if (isPathProxy(path)) {
  9495. path.appendPath(pathList);
  9496. var ctx = path.getContext();
  9497. if (ctx) {
  9498. path.rebuildPath(ctx, 1);
  9499. }
  9500. }
  9501. };
  9502. return pathBundle;
  9503. }
  9504. function clonePath(sourcePath, opts) {
  9505. opts = opts || {};
  9506. var path = new Path();
  9507. if (sourcePath.shape) {
  9508. path.setShape(sourcePath.shape);
  9509. }
  9510. path.setStyle(sourcePath.style);
  9511. if (opts.bakeTransform) {
  9512. transformPath(path.path, sourcePath.getComputedTransform());
  9513. }
  9514. else {
  9515. if (opts.toLocal) {
  9516. path.setLocalTransform(sourcePath.getComputedTransform());
  9517. }
  9518. else {
  9519. path.copyTransform(sourcePath);
  9520. }
  9521. }
  9522. path.buildPath = sourcePath.buildPath;
  9523. path.applyTransform = path.applyTransform;
  9524. path.z = sourcePath.z;
  9525. path.z2 = sourcePath.z2;
  9526. path.zlevel = sourcePath.zlevel;
  9527. return path;
  9528. }
  9529. var path = /*#__PURE__*/Object.freeze({
  9530. __proto__: null,
  9531. createFromString: createFromString,
  9532. extendFromString: extendFromString,
  9533. mergePath: mergePath,
  9534. clonePath: clonePath
  9535. });
  9536. var DEFAULT_IMAGE_STYLE = defaults({
  9537. x: 0,
  9538. y: 0
  9539. }, DEFAULT_COMMON_STYLE);
  9540. var DEFAULT_IMAGE_ANIMATION_PROPS = {
  9541. style: defaults({
  9542. x: true,
  9543. y: true,
  9544. width: true,
  9545. height: true,
  9546. sx: true,
  9547. sy: true,
  9548. sWidth: true,
  9549. sHeight: true
  9550. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  9551. };
  9552. function isImageLike(source) {
  9553. return !!(source
  9554. && typeof source !== 'string'
  9555. && source.width && source.height);
  9556. }
  9557. var ZRImage = (function (_super) {
  9558. __extends(ZRImage, _super);
  9559. function ZRImage() {
  9560. return _super !== null && _super.apply(this, arguments) || this;
  9561. }
  9562. ZRImage.prototype.createStyle = function (obj) {
  9563. return createObject(DEFAULT_IMAGE_STYLE, obj);
  9564. };
  9565. ZRImage.prototype._getSize = function (dim) {
  9566. var style = this.style;
  9567. var size = style[dim];
  9568. if (size != null) {
  9569. return size;
  9570. }
  9571. var imageSource = isImageLike(style.image)
  9572. ? style.image : this.__image;
  9573. if (!imageSource) {
  9574. return 0;
  9575. }
  9576. var otherDim = dim === 'width' ? 'height' : 'width';
  9577. var otherDimSize = style[otherDim];
  9578. if (otherDimSize == null) {
  9579. return imageSource[dim];
  9580. }
  9581. else {
  9582. return imageSource[dim] / imageSource[otherDim] * otherDimSize;
  9583. }
  9584. };
  9585. ZRImage.prototype.getWidth = function () {
  9586. return this._getSize('width');
  9587. };
  9588. ZRImage.prototype.getHeight = function () {
  9589. return this._getSize('height');
  9590. };
  9591. ZRImage.prototype.getAnimationStyleProps = function () {
  9592. return DEFAULT_IMAGE_ANIMATION_PROPS;
  9593. };
  9594. ZRImage.prototype.getBoundingRect = function () {
  9595. var style = this.style;
  9596. if (!this._rect) {
  9597. this._rect = new BoundingRect(style.x || 0, style.y || 0, this.getWidth(), this.getHeight());
  9598. }
  9599. return this._rect;
  9600. };
  9601. return ZRImage;
  9602. }(Displayable));
  9603. ZRImage.prototype.type = 'image';
  9604. var CircleShape = (function () {
  9605. function CircleShape() {
  9606. this.cx = 0;
  9607. this.cy = 0;
  9608. this.r = 0;
  9609. }
  9610. return CircleShape;
  9611. }());
  9612. var Circle = (function (_super) {
  9613. __extends(Circle, _super);
  9614. function Circle(opts) {
  9615. return _super.call(this, opts) || this;
  9616. }
  9617. Circle.prototype.getDefaultShape = function () {
  9618. return new CircleShape();
  9619. };
  9620. Circle.prototype.buildPath = function (ctx, shape) {
  9621. ctx.moveTo(shape.cx + shape.r, shape.cy);
  9622. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2);
  9623. };
  9624. return Circle;
  9625. }(Path));
  9626. Circle.prototype.type = 'circle';
  9627. function buildPath(ctx, shape) {
  9628. var x = shape.x;
  9629. var y = shape.y;
  9630. var width = shape.width;
  9631. var height = shape.height;
  9632. var r = shape.r;
  9633. var r1;
  9634. var r2;
  9635. var r3;
  9636. var r4;
  9637. if (width < 0) {
  9638. x = x + width;
  9639. width = -width;
  9640. }
  9641. if (height < 0) {
  9642. y = y + height;
  9643. height = -height;
  9644. }
  9645. if (typeof r === 'number') {
  9646. r1 = r2 = r3 = r4 = r;
  9647. }
  9648. else if (r instanceof Array) {
  9649. if (r.length === 1) {
  9650. r1 = r2 = r3 = r4 = r[0];
  9651. }
  9652. else if (r.length === 2) {
  9653. r1 = r3 = r[0];
  9654. r2 = r4 = r[1];
  9655. }
  9656. else if (r.length === 3) {
  9657. r1 = r[0];
  9658. r2 = r4 = r[1];
  9659. r3 = r[2];
  9660. }
  9661. else {
  9662. r1 = r[0];
  9663. r2 = r[1];
  9664. r3 = r[2];
  9665. r4 = r[3];
  9666. }
  9667. }
  9668. else {
  9669. r1 = r2 = r3 = r4 = 0;
  9670. }
  9671. var total;
  9672. if (r1 + r2 > width) {
  9673. total = r1 + r2;
  9674. r1 *= width / total;
  9675. r2 *= width / total;
  9676. }
  9677. if (r3 + r4 > width) {
  9678. total = r3 + r4;
  9679. r3 *= width / total;
  9680. r4 *= width / total;
  9681. }
  9682. if (r2 + r3 > height) {
  9683. total = r2 + r3;
  9684. r2 *= height / total;
  9685. r3 *= height / total;
  9686. }
  9687. if (r1 + r4 > height) {
  9688. total = r1 + r4;
  9689. r1 *= height / total;
  9690. r4 *= height / total;
  9691. }
  9692. ctx.moveTo(x + r1, y);
  9693. ctx.lineTo(x + width - r2, y);
  9694. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  9695. ctx.lineTo(x + width, y + height - r3);
  9696. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  9697. ctx.lineTo(x + r4, y + height);
  9698. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  9699. ctx.lineTo(x, y + r1);
  9700. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  9701. }
  9702. var round = Math.round;
  9703. function subPixelOptimizeLine(outputShape, inputShape, style) {
  9704. if (!inputShape) {
  9705. return;
  9706. }
  9707. var x1 = inputShape.x1;
  9708. var x2 = inputShape.x2;
  9709. var y1 = inputShape.y1;
  9710. var y2 = inputShape.y2;
  9711. outputShape.x1 = x1;
  9712. outputShape.x2 = x2;
  9713. outputShape.y1 = y1;
  9714. outputShape.y2 = y2;
  9715. var lineWidth = style && style.lineWidth;
  9716. if (!lineWidth) {
  9717. return outputShape;
  9718. }
  9719. if (round(x1 * 2) === round(x2 * 2)) {
  9720. outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true);
  9721. }
  9722. if (round(y1 * 2) === round(y2 * 2)) {
  9723. outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true);
  9724. }
  9725. return outputShape;
  9726. }
  9727. function subPixelOptimizeRect(outputShape, inputShape, style) {
  9728. if (!inputShape) {
  9729. return;
  9730. }
  9731. var originX = inputShape.x;
  9732. var originY = inputShape.y;
  9733. var originWidth = inputShape.width;
  9734. var originHeight = inputShape.height;
  9735. outputShape.x = originX;
  9736. outputShape.y = originY;
  9737. outputShape.width = originWidth;
  9738. outputShape.height = originHeight;
  9739. var lineWidth = style && style.lineWidth;
  9740. if (!lineWidth) {
  9741. return outputShape;
  9742. }
  9743. outputShape.x = subPixelOptimize(originX, lineWidth, true);
  9744. outputShape.y = subPixelOptimize(originY, lineWidth, true);
  9745. outputShape.width = Math.max(subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
  9746. outputShape.height = Math.max(subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
  9747. return outputShape;
  9748. }
  9749. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  9750. if (!lineWidth) {
  9751. return position;
  9752. }
  9753. var doubledPosition = round(position * 2);
  9754. return (doubledPosition + round(lineWidth)) % 2 === 0
  9755. ? doubledPosition / 2
  9756. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  9757. }
  9758. var RectShape = (function () {
  9759. function RectShape() {
  9760. this.x = 0;
  9761. this.y = 0;
  9762. this.width = 0;
  9763. this.height = 0;
  9764. }
  9765. return RectShape;
  9766. }());
  9767. var subPixelOptimizeOutputShape = {};
  9768. var Rect = (function (_super) {
  9769. __extends(Rect, _super);
  9770. function Rect(opts) {
  9771. return _super.call(this, opts) || this;
  9772. }
  9773. Rect.prototype.getDefaultShape = function () {
  9774. return new RectShape();
  9775. };
  9776. Rect.prototype.buildPath = function (ctx, shape) {
  9777. var x;
  9778. var y;
  9779. var width;
  9780. var height;
  9781. if (this.subPixelOptimize) {
  9782. var optimizedShape = subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style);
  9783. x = optimizedShape.x;
  9784. y = optimizedShape.y;
  9785. width = optimizedShape.width;
  9786. height = optimizedShape.height;
  9787. optimizedShape.r = shape.r;
  9788. shape = optimizedShape;
  9789. }
  9790. else {
  9791. x = shape.x;
  9792. y = shape.y;
  9793. width = shape.width;
  9794. height = shape.height;
  9795. }
  9796. if (!shape.r) {
  9797. ctx.rect(x, y, width, height);
  9798. }
  9799. else {
  9800. buildPath(ctx, shape);
  9801. }
  9802. };
  9803. Rect.prototype.isZeroArea = function () {
  9804. return !this.shape.width || !this.shape.height;
  9805. };
  9806. return Rect;
  9807. }(Path));
  9808. Rect.prototype.type = 'rect';
  9809. var EllipseShape = (function () {
  9810. function EllipseShape() {
  9811. this.cx = 0;
  9812. this.cy = 0;
  9813. this.rx = 0;
  9814. this.ry = 0;
  9815. }
  9816. return EllipseShape;
  9817. }());
  9818. var Ellipse = (function (_super) {
  9819. __extends(Ellipse, _super);
  9820. function Ellipse(opts) {
  9821. return _super.call(this, opts) || this;
  9822. }
  9823. Ellipse.prototype.getDefaultShape = function () {
  9824. return new EllipseShape();
  9825. };
  9826. Ellipse.prototype.buildPath = function (ctx, shape) {
  9827. var k = 0.5522848;
  9828. var x = shape.cx;
  9829. var y = shape.cy;
  9830. var a = shape.rx;
  9831. var b = shape.ry;
  9832. var ox = a * k;
  9833. var oy = b * k;
  9834. ctx.moveTo(x - a, y);
  9835. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  9836. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  9837. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  9838. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  9839. ctx.closePath();
  9840. };
  9841. return Ellipse;
  9842. }(Path));
  9843. Ellipse.prototype.type = 'ellipse';
  9844. var subPixelOptimizeOutputShape$1 = {};
  9845. var LineShape = (function () {
  9846. function LineShape() {
  9847. this.x1 = 0;
  9848. this.y1 = 0;
  9849. this.x2 = 0;
  9850. this.y2 = 0;
  9851. this.percent = 1;
  9852. }
  9853. return LineShape;
  9854. }());
  9855. var Line = (function (_super) {
  9856. __extends(Line, _super);
  9857. function Line(opts) {
  9858. return _super.call(this, opts) || this;
  9859. }
  9860. Line.prototype.getDefaultStyle = function () {
  9861. return {
  9862. stroke: '#000',
  9863. fill: null
  9864. };
  9865. };
  9866. Line.prototype.getDefaultShape = function () {
  9867. return new LineShape();
  9868. };
  9869. Line.prototype.buildPath = function (ctx, shape) {
  9870. var x1;
  9871. var y1;
  9872. var x2;
  9873. var y2;
  9874. if (this.subPixelOptimize) {
  9875. var optimizedShape = subPixelOptimizeLine(subPixelOptimizeOutputShape$1, shape, this.style);
  9876. x1 = optimizedShape.x1;
  9877. y1 = optimizedShape.y1;
  9878. x2 = optimizedShape.x2;
  9879. y2 = optimizedShape.y2;
  9880. }
  9881. else {
  9882. x1 = shape.x1;
  9883. y1 = shape.y1;
  9884. x2 = shape.x2;
  9885. y2 = shape.y2;
  9886. }
  9887. var percent = shape.percent;
  9888. if (percent === 0) {
  9889. return;
  9890. }
  9891. ctx.moveTo(x1, y1);
  9892. if (percent < 1) {
  9893. x2 = x1 * (1 - percent) + x2 * percent;
  9894. y2 = y1 * (1 - percent) + y2 * percent;
  9895. }
  9896. ctx.lineTo(x2, y2);
  9897. };
  9898. Line.prototype.pointAt = function (p) {
  9899. var shape = this.shape;
  9900. return [
  9901. shape.x1 * (1 - p) + shape.x2 * p,
  9902. shape.y1 * (1 - p) + shape.y2 * p
  9903. ];
  9904. };
  9905. return Line;
  9906. }(Path));
  9907. Line.prototype.type = 'line';
  9908. function smoothBezier(points, smooth, isLoop, constraint) {
  9909. var cps = [];
  9910. var v = [];
  9911. var v1 = [];
  9912. var v2 = [];
  9913. var prevPoint;
  9914. var nextPoint;
  9915. var min$1;
  9916. var max$1;
  9917. if (constraint) {
  9918. min$1 = [Infinity, Infinity];
  9919. max$1 = [-Infinity, -Infinity];
  9920. for (var i = 0, len = points.length; i < len; i++) {
  9921. min(min$1, min$1, points[i]);
  9922. max(max$1, max$1, points[i]);
  9923. }
  9924. min(min$1, min$1, constraint[0]);
  9925. max(max$1, max$1, constraint[1]);
  9926. }
  9927. for (var i = 0, len = points.length; i < len; i++) {
  9928. var point = points[i];
  9929. if (isLoop) {
  9930. prevPoint = points[i ? i - 1 : len - 1];
  9931. nextPoint = points[(i + 1) % len];
  9932. }
  9933. else {
  9934. if (i === 0 || i === len - 1) {
  9935. cps.push(clone$1(points[i]));
  9936. continue;
  9937. }
  9938. else {
  9939. prevPoint = points[i - 1];
  9940. nextPoint = points[i + 1];
  9941. }
  9942. }
  9943. sub(v, nextPoint, prevPoint);
  9944. scale(v, v, smooth);
  9945. var d0 = distance(point, prevPoint);
  9946. var d1 = distance(point, nextPoint);
  9947. var sum = d0 + d1;
  9948. if (sum !== 0) {
  9949. d0 /= sum;
  9950. d1 /= sum;
  9951. }
  9952. scale(v1, v, -d0);
  9953. scale(v2, v, d1);
  9954. var cp0 = add([], point, v1);
  9955. var cp1 = add([], point, v2);
  9956. if (constraint) {
  9957. max(cp0, cp0, min$1);
  9958. min(cp0, cp0, max$1);
  9959. max(cp1, cp1, min$1);
  9960. min(cp1, cp1, max$1);
  9961. }
  9962. cps.push(cp0);
  9963. cps.push(cp1);
  9964. }
  9965. if (isLoop) {
  9966. cps.push(cps.shift());
  9967. }
  9968. return cps;
  9969. }
  9970. function buildPath$1(ctx, shape, closePath) {
  9971. var smooth = shape.smooth;
  9972. var points = shape.points;
  9973. if (points && points.length >= 2) {
  9974. if (smooth) {
  9975. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  9976. ctx.moveTo(points[0][0], points[0][1]);
  9977. var len = points.length;
  9978. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  9979. var cp1 = controlPoints[i * 2];
  9980. var cp2 = controlPoints[i * 2 + 1];
  9981. var p = points[(i + 1) % len];
  9982. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  9983. }
  9984. }
  9985. else {
  9986. ctx.moveTo(points[0][0], points[0][1]);
  9987. for (var i = 1, l = points.length; i < l; i++) {
  9988. ctx.lineTo(points[i][0], points[i][1]);
  9989. }
  9990. }
  9991. closePath && ctx.closePath();
  9992. }
  9993. }
  9994. var PolygonShape = (function () {
  9995. function PolygonShape() {
  9996. this.points = null;
  9997. this.smooth = 0;
  9998. this.smoothConstraint = null;
  9999. }
  10000. return PolygonShape;
  10001. }());
  10002. var Polygon = (function (_super) {
  10003. __extends(Polygon, _super);
  10004. function Polygon(opts) {
  10005. return _super.call(this, opts) || this;
  10006. }
  10007. Polygon.prototype.getDefaultShape = function () {
  10008. return new PolygonShape();
  10009. };
  10010. Polygon.prototype.buildPath = function (ctx, shape) {
  10011. buildPath$1(ctx, shape, true);
  10012. };
  10013. return Polygon;
  10014. }(Path));
  10015. Polygon.prototype.type = 'polygon';
  10016. var PolylineShape = (function () {
  10017. function PolylineShape() {
  10018. this.points = null;
  10019. this.percent = 1;
  10020. this.smooth = 0;
  10021. this.smoothConstraint = null;
  10022. }
  10023. return PolylineShape;
  10024. }());
  10025. var Polyline = (function (_super) {
  10026. __extends(Polyline, _super);
  10027. function Polyline(opts) {
  10028. return _super.call(this, opts) || this;
  10029. }
  10030. Polyline.prototype.getDefaultStyle = function () {
  10031. return {
  10032. stroke: '#000',
  10033. fill: null
  10034. };
  10035. };
  10036. Polyline.prototype.getDefaultShape = function () {
  10037. return new PolylineShape();
  10038. };
  10039. Polyline.prototype.buildPath = function (ctx, shape) {
  10040. buildPath$1(ctx, shape, false);
  10041. };
  10042. return Polyline;
  10043. }(Path));
  10044. Polyline.prototype.type = 'polyline';
  10045. var Gradient = (function () {
  10046. function Gradient(colorStops) {
  10047. this.colorStops = colorStops || [];
  10048. }
  10049. Gradient.prototype.addColorStop = function (offset, color) {
  10050. this.colorStops.push({
  10051. offset: offset,
  10052. color: color
  10053. });
  10054. };
  10055. return Gradient;
  10056. }());
  10057. var LinearGradient = (function (_super) {
  10058. __extends(LinearGradient, _super);
  10059. function LinearGradient(x, y, x2, y2, colorStops, globalCoord) {
  10060. var _this = _super.call(this, colorStops) || this;
  10061. _this.x = x == null ? 0 : x;
  10062. _this.y = y == null ? 0 : y;
  10063. _this.x2 = x2 == null ? 1 : x2;
  10064. _this.y2 = y2 == null ? 0 : y2;
  10065. _this.type = 'linear';
  10066. _this.global = globalCoord || false;
  10067. return _this;
  10068. }
  10069. return LinearGradient;
  10070. }(Gradient));
  10071. var RadialGradient = (function (_super) {
  10072. __extends(RadialGradient, _super);
  10073. function RadialGradient(x, y, r, colorStops, globalCoord) {
  10074. var _this = _super.call(this, colorStops) || this;
  10075. _this.x = x == null ? 0.5 : x;
  10076. _this.y = y == null ? 0.5 : y;
  10077. _this.r = r == null ? 0.5 : r;
  10078. _this.type = 'radial';
  10079. _this.global = globalCoord || false;
  10080. return _this;
  10081. }
  10082. return RadialGradient;
  10083. }(Gradient));
  10084. var DEFAULT_TSPAN_STYLE = defaults({
  10085. strokeFirst: true,
  10086. font: DEFAULT_FONT,
  10087. x: 0,
  10088. y: 0,
  10089. textAlign: 'left',
  10090. textBaseline: 'top',
  10091. miterLimit: 2
  10092. }, DEFAULT_PATH_STYLE);
  10093. var TSpan = (function (_super) {
  10094. __extends(TSpan, _super);
  10095. function TSpan() {
  10096. return _super !== null && _super.apply(this, arguments) || this;
  10097. }
  10098. TSpan.prototype.hasStroke = function () {
  10099. var style = this.style;
  10100. var stroke = style.stroke;
  10101. return stroke != null && stroke !== 'none' && style.lineWidth > 0;
  10102. };
  10103. TSpan.prototype.hasFill = function () {
  10104. var style = this.style;
  10105. var fill = style.fill;
  10106. return fill != null && fill !== 'none';
  10107. };
  10108. TSpan.prototype.createStyle = function (obj) {
  10109. return createObject(DEFAULT_TSPAN_STYLE, obj);
  10110. };
  10111. TSpan.prototype.setBoundingRect = function (rect) {
  10112. this._rect = rect;
  10113. };
  10114. TSpan.prototype.getBoundingRect = function () {
  10115. var style = this.style;
  10116. if (!this._rect) {
  10117. var text = style.text;
  10118. text != null ? (text += '') : (text = '');
  10119. var rect = getBoundingRect(text, style.font, style.textAlign, style.textBaseline);
  10120. rect.x += style.x || 0;
  10121. rect.y += style.y || 0;
  10122. if (this.hasStroke()) {
  10123. var w = style.lineWidth;
  10124. rect.x -= w / 2;
  10125. rect.y -= w / 2;
  10126. rect.width += w;
  10127. rect.height += w;
  10128. }
  10129. this._rect = rect;
  10130. }
  10131. return this._rect;
  10132. };
  10133. TSpan.initDefaultProps = (function () {
  10134. var tspanProto = TSpan.prototype;
  10135. tspanProto.dirtyRectTolerance = 10;
  10136. })();
  10137. return TSpan;
  10138. }(Displayable));
  10139. TSpan.prototype.type = 'tspan';
  10140. function parseXML(svg) {
  10141. if (isString(svg)) {
  10142. var parser = new DOMParser();
  10143. svg = parser.parseFromString(svg, 'text/xml');
  10144. }
  10145. var svgNode = svg;
  10146. if (svgNode.nodeType === 9) {
  10147. svgNode = svgNode.firstChild;
  10148. }
  10149. while (svgNode.nodeName.toLowerCase() !== 'svg' || svgNode.nodeType !== 1) {
  10150. svgNode = svgNode.nextSibling;
  10151. }
  10152. return svgNode;
  10153. }
  10154. var nodeParsers;
  10155. var INHERITABLE_STYLE_ATTRIBUTES_MAP = {
  10156. 'fill': 'fill',
  10157. 'stroke': 'stroke',
  10158. 'stroke-width': 'lineWidth',
  10159. 'opacity': 'opacity',
  10160. 'fill-opacity': 'fillOpacity',
  10161. 'stroke-opacity': 'strokeOpacity',
  10162. 'stroke-dasharray': 'lineDash',
  10163. 'stroke-dashoffset': 'lineDashOffset',
  10164. 'stroke-linecap': 'lineCap',
  10165. 'stroke-linejoin': 'lineJoin',
  10166. 'stroke-miterlimit': 'miterLimit',
  10167. 'font-family': 'fontFamily',
  10168. 'font-size': 'fontSize',
  10169. 'font-style': 'fontStyle',
  10170. 'font-weight': 'fontWeight',
  10171. 'text-anchor': 'textAlign',
  10172. 'visibility': 'visibility',
  10173. 'display': 'display'
  10174. };
  10175. var INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS = keys(INHERITABLE_STYLE_ATTRIBUTES_MAP);
  10176. var SELF_STYLE_ATTRIBUTES_MAP = {
  10177. 'alignment-baseline': 'textBaseline',
  10178. 'stop-color': 'stopColor'
  10179. };
  10180. var SELF_STYLE_ATTRIBUTES_MAP_KEYS = keys(SELF_STYLE_ATTRIBUTES_MAP);
  10181. var SVGParser = (function () {
  10182. function SVGParser() {
  10183. this._defs = {};
  10184. this._root = null;
  10185. }
  10186. SVGParser.prototype.parse = function (xml, opt) {
  10187. opt = opt || {};
  10188. var svg = parseXML(xml);
  10189. {
  10190. if (!svg) {
  10191. throw new Error('Illegal svg');
  10192. }
  10193. }
  10194. this._defsUsePending = [];
  10195. var root = new Group();
  10196. this._root = root;
  10197. var named = [];
  10198. var viewBox = svg.getAttribute('viewBox') || '';
  10199. var width = parseFloat((svg.getAttribute('width') || opt.width));
  10200. var height = parseFloat((svg.getAttribute('height') || opt.height));
  10201. isNaN(width) && (width = null);
  10202. isNaN(height) && (height = null);
  10203. parseAttributes(svg, root, null, true, false);
  10204. var child = svg.firstChild;
  10205. while (child) {
  10206. this._parseNode(child, root, named, null, false, false);
  10207. child = child.nextSibling;
  10208. }
  10209. applyDefs(this._defs, this._defsUsePending);
  10210. this._defsUsePending = [];
  10211. var viewBoxRect;
  10212. var viewBoxTransform;
  10213. if (viewBox) {
  10214. var viewBoxArr = splitNumberSequence(viewBox);
  10215. if (viewBoxArr.length >= 4) {
  10216. viewBoxRect = {
  10217. x: parseFloat((viewBoxArr[0] || 0)),
  10218. y: parseFloat((viewBoxArr[1] || 0)),
  10219. width: parseFloat(viewBoxArr[2]),
  10220. height: parseFloat(viewBoxArr[3])
  10221. };
  10222. }
  10223. }
  10224. if (viewBoxRect && width != null && height != null) {
  10225. viewBoxTransform = makeViewBoxTransform(viewBoxRect, { x: 0, y: 0, width: width, height: height });
  10226. if (!opt.ignoreViewBox) {
  10227. var elRoot = root;
  10228. root = new Group();
  10229. root.add(elRoot);
  10230. elRoot.scaleX = elRoot.scaleY = viewBoxTransform.scale;
  10231. elRoot.x = viewBoxTransform.x;
  10232. elRoot.y = viewBoxTransform.y;
  10233. }
  10234. }
  10235. if (!opt.ignoreRootClip && width != null && height != null) {
  10236. root.setClipPath(new Rect({
  10237. shape: { x: 0, y: 0, width: width, height: height }
  10238. }));
  10239. }
  10240. return {
  10241. root: root,
  10242. width: width,
  10243. height: height,
  10244. viewBoxRect: viewBoxRect,
  10245. viewBoxTransform: viewBoxTransform,
  10246. named: named
  10247. };
  10248. };
  10249. SVGParser.prototype._parseNode = function (xmlNode, parentGroup, named, namedFrom, isInDefs, isInText) {
  10250. var nodeName = xmlNode.nodeName.toLowerCase();
  10251. var el;
  10252. var namedFromForSub = namedFrom;
  10253. if (nodeName === 'defs') {
  10254. isInDefs = true;
  10255. }
  10256. if (nodeName === 'text') {
  10257. isInText = true;
  10258. }
  10259. if (nodeName === 'defs' || nodeName === 'switch') {
  10260. el = parentGroup;
  10261. }
  10262. else {
  10263. if (!isInDefs) {
  10264. var parser_1 = nodeParsers[nodeName];
  10265. if (parser_1 && hasOwn(nodeParsers, nodeName)) {
  10266. el = parser_1.call(this, xmlNode, parentGroup);
  10267. var nameAttr = xmlNode.getAttribute('name');
  10268. if (nameAttr) {
  10269. var newNamed = {
  10270. name: nameAttr,
  10271. namedFrom: null,
  10272. svgNodeTagLower: nodeName,
  10273. el: el
  10274. };
  10275. named.push(newNamed);
  10276. if (nodeName === 'g') {
  10277. namedFromForSub = newNamed;
  10278. }
  10279. }
  10280. else if (namedFrom) {
  10281. named.push({
  10282. name: namedFrom.name,
  10283. namedFrom: namedFrom,
  10284. svgNodeTagLower: nodeName,
  10285. el: el
  10286. });
  10287. }
  10288. parentGroup.add(el);
  10289. }
  10290. }
  10291. var parser = paintServerParsers[nodeName];
  10292. if (parser && hasOwn(paintServerParsers, nodeName)) {
  10293. var def = parser.call(this, xmlNode);
  10294. var id = xmlNode.getAttribute('id');
  10295. if (id) {
  10296. this._defs[id] = def;
  10297. }
  10298. }
  10299. }
  10300. if (el && el.isGroup) {
  10301. var child = xmlNode.firstChild;
  10302. while (child) {
  10303. if (child.nodeType === 1) {
  10304. this._parseNode(child, el, named, namedFromForSub, isInDefs, isInText);
  10305. }
  10306. else if (child.nodeType === 3 && isInText) {
  10307. this._parseText(child, el);
  10308. }
  10309. child = child.nextSibling;
  10310. }
  10311. }
  10312. };
  10313. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  10314. var text = new TSpan({
  10315. style: {
  10316. text: xmlNode.textContent
  10317. },
  10318. silent: true,
  10319. x: this._textX || 0,
  10320. y: this._textY || 0
  10321. });
  10322. inheritStyle(parentGroup, text);
  10323. parseAttributes(xmlNode, text, this._defsUsePending, false, false);
  10324. applyTextAlignment(text, parentGroup);
  10325. var textStyle = text.style;
  10326. var fontSize = textStyle.fontSize;
  10327. if (fontSize && fontSize < 9) {
  10328. textStyle.fontSize = 9;
  10329. text.scaleX *= fontSize / 9;
  10330. text.scaleY *= fontSize / 9;
  10331. }
  10332. var font = (textStyle.fontSize || textStyle.fontFamily) && [
  10333. textStyle.fontStyle,
  10334. textStyle.fontWeight,
  10335. (textStyle.fontSize || 12) + 'px',
  10336. textStyle.fontFamily || 'sans-serif'
  10337. ].join(' ');
  10338. textStyle.font = font;
  10339. var rect = text.getBoundingRect();
  10340. this._textX += rect.width;
  10341. parentGroup.add(text);
  10342. return text;
  10343. };
  10344. SVGParser.internalField = (function () {
  10345. nodeParsers = {
  10346. 'g': function (xmlNode, parentGroup) {
  10347. var g = new Group();
  10348. inheritStyle(parentGroup, g);
  10349. parseAttributes(xmlNode, g, this._defsUsePending, false, false);
  10350. return g;
  10351. },
  10352. 'rect': function (xmlNode, parentGroup) {
  10353. var rect = new Rect();
  10354. inheritStyle(parentGroup, rect);
  10355. parseAttributes(xmlNode, rect, this._defsUsePending, false, false);
  10356. rect.setShape({
  10357. x: parseFloat(xmlNode.getAttribute('x') || '0'),
  10358. y: parseFloat(xmlNode.getAttribute('y') || '0'),
  10359. width: parseFloat(xmlNode.getAttribute('width') || '0'),
  10360. height: parseFloat(xmlNode.getAttribute('height') || '0')
  10361. });
  10362. rect.silent = true;
  10363. return rect;
  10364. },
  10365. 'circle': function (xmlNode, parentGroup) {
  10366. var circle = new Circle();
  10367. inheritStyle(parentGroup, circle);
  10368. parseAttributes(xmlNode, circle, this._defsUsePending, false, false);
  10369. circle.setShape({
  10370. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  10371. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  10372. r: parseFloat(xmlNode.getAttribute('r') || '0')
  10373. });
  10374. circle.silent = true;
  10375. return circle;
  10376. },
  10377. 'line': function (xmlNode, parentGroup) {
  10378. var line = new Line();
  10379. inheritStyle(parentGroup, line);
  10380. parseAttributes(xmlNode, line, this._defsUsePending, false, false);
  10381. line.setShape({
  10382. x1: parseFloat(xmlNode.getAttribute('x1') || '0'),
  10383. y1: parseFloat(xmlNode.getAttribute('y1') || '0'),
  10384. x2: parseFloat(xmlNode.getAttribute('x2') || '0'),
  10385. y2: parseFloat(xmlNode.getAttribute('y2') || '0')
  10386. });
  10387. line.silent = true;
  10388. return line;
  10389. },
  10390. 'ellipse': function (xmlNode, parentGroup) {
  10391. var ellipse = new Ellipse();
  10392. inheritStyle(parentGroup, ellipse);
  10393. parseAttributes(xmlNode, ellipse, this._defsUsePending, false, false);
  10394. ellipse.setShape({
  10395. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  10396. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  10397. rx: parseFloat(xmlNode.getAttribute('rx') || '0'),
  10398. ry: parseFloat(xmlNode.getAttribute('ry') || '0')
  10399. });
  10400. ellipse.silent = true;
  10401. return ellipse;
  10402. },
  10403. 'polygon': function (xmlNode, parentGroup) {
  10404. var pointsStr = xmlNode.getAttribute('points');
  10405. var pointsArr;
  10406. if (pointsStr) {
  10407. pointsArr = parsePoints(pointsStr);
  10408. }
  10409. var polygon = new Polygon({
  10410. shape: {
  10411. points: pointsArr || []
  10412. },
  10413. silent: true
  10414. });
  10415. inheritStyle(parentGroup, polygon);
  10416. parseAttributes(xmlNode, polygon, this._defsUsePending, false, false);
  10417. return polygon;
  10418. },
  10419. 'polyline': function (xmlNode, parentGroup) {
  10420. var pointsStr = xmlNode.getAttribute('points');
  10421. var pointsArr;
  10422. if (pointsStr) {
  10423. pointsArr = parsePoints(pointsStr);
  10424. }
  10425. var polyline = new Polyline({
  10426. shape: {
  10427. points: pointsArr || []
  10428. },
  10429. silent: true
  10430. });
  10431. inheritStyle(parentGroup, polyline);
  10432. parseAttributes(xmlNode, polyline, this._defsUsePending, false, false);
  10433. return polyline;
  10434. },
  10435. 'image': function (xmlNode, parentGroup) {
  10436. var img = new ZRImage();
  10437. inheritStyle(parentGroup, img);
  10438. parseAttributes(xmlNode, img, this._defsUsePending, false, false);
  10439. img.setStyle({
  10440. image: xmlNode.getAttribute('xlink:href') || xmlNode.getAttribute('href'),
  10441. x: +xmlNode.getAttribute('x'),
  10442. y: +xmlNode.getAttribute('y'),
  10443. width: +xmlNode.getAttribute('width'),
  10444. height: +xmlNode.getAttribute('height')
  10445. });
  10446. img.silent = true;
  10447. return img;
  10448. },
  10449. 'text': function (xmlNode, parentGroup) {
  10450. var x = xmlNode.getAttribute('x') || '0';
  10451. var y = xmlNode.getAttribute('y') || '0';
  10452. var dx = xmlNode.getAttribute('dx') || '0';
  10453. var dy = xmlNode.getAttribute('dy') || '0';
  10454. this._textX = parseFloat(x) + parseFloat(dx);
  10455. this._textY = parseFloat(y) + parseFloat(dy);
  10456. var g = new Group();
  10457. inheritStyle(parentGroup, g);
  10458. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  10459. return g;
  10460. },
  10461. 'tspan': function (xmlNode, parentGroup) {
  10462. var x = xmlNode.getAttribute('x');
  10463. var y = xmlNode.getAttribute('y');
  10464. if (x != null) {
  10465. this._textX = parseFloat(x);
  10466. }
  10467. if (y != null) {
  10468. this._textY = parseFloat(y);
  10469. }
  10470. var dx = xmlNode.getAttribute('dx') || '0';
  10471. var dy = xmlNode.getAttribute('dy') || '0';
  10472. var g = new Group();
  10473. inheritStyle(parentGroup, g);
  10474. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  10475. this._textX += parseFloat(dx);
  10476. this._textY += parseFloat(dy);
  10477. return g;
  10478. },
  10479. 'path': function (xmlNode, parentGroup) {
  10480. var d = xmlNode.getAttribute('d') || '';
  10481. var path = createFromString(d);
  10482. inheritStyle(parentGroup, path);
  10483. parseAttributes(xmlNode, path, this._defsUsePending, false, false);
  10484. path.silent = true;
  10485. return path;
  10486. }
  10487. };
  10488. })();
  10489. return SVGParser;
  10490. }());
  10491. var paintServerParsers = {
  10492. 'lineargradient': function (xmlNode) {
  10493. var x1 = parseInt(xmlNode.getAttribute('x1') || '0', 10);
  10494. var y1 = parseInt(xmlNode.getAttribute('y1') || '0', 10);
  10495. var x2 = parseInt(xmlNode.getAttribute('x2') || '10', 10);
  10496. var y2 = parseInt(xmlNode.getAttribute('y2') || '0', 10);
  10497. var gradient = new LinearGradient(x1, y1, x2, y2);
  10498. parsePaintServerUnit(xmlNode, gradient);
  10499. parseGradientColorStops(xmlNode, gradient);
  10500. return gradient;
  10501. },
  10502. 'radialgradient': function (xmlNode) {
  10503. var cx = parseInt(xmlNode.getAttribute('cx') || '0', 10);
  10504. var cy = parseInt(xmlNode.getAttribute('cy') || '0', 10);
  10505. var r = parseInt(xmlNode.getAttribute('r') || '0', 10);
  10506. var gradient = new RadialGradient(cx, cy, r);
  10507. parsePaintServerUnit(xmlNode, gradient);
  10508. parseGradientColorStops(xmlNode, gradient);
  10509. return gradient;
  10510. }
  10511. };
  10512. function parsePaintServerUnit(xmlNode, gradient) {
  10513. var gradientUnits = xmlNode.getAttribute('gradientUnits');
  10514. if (gradientUnits === 'userSpaceOnUse') {
  10515. gradient.global = true;
  10516. }
  10517. }
  10518. function parseGradientColorStops(xmlNode, gradient) {
  10519. var stop = xmlNode.firstChild;
  10520. while (stop) {
  10521. if (stop.nodeType === 1
  10522. && stop.nodeName.toLocaleLowerCase() === 'stop') {
  10523. var offsetStr = stop.getAttribute('offset');
  10524. var offset = void 0;
  10525. if (offsetStr && offsetStr.indexOf('%') > 0) {
  10526. offset = parseInt(offsetStr, 10) / 100;
  10527. }
  10528. else if (offsetStr) {
  10529. offset = parseFloat(offsetStr);
  10530. }
  10531. else {
  10532. offset = 0;
  10533. }
  10534. var styleVals = {};
  10535. parseInlineStyle(stop, styleVals, styleVals);
  10536. var stopColor = styleVals.stopColor
  10537. || stop.getAttribute('stop-color')
  10538. || '#000000';
  10539. gradient.colorStops.push({
  10540. offset: offset,
  10541. color: stopColor
  10542. });
  10543. }
  10544. stop = stop.nextSibling;
  10545. }
  10546. }
  10547. function inheritStyle(parent, child) {
  10548. if (parent && parent.__inheritedStyle) {
  10549. if (!child.__inheritedStyle) {
  10550. child.__inheritedStyle = {};
  10551. }
  10552. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  10553. }
  10554. }
  10555. function parsePoints(pointsString) {
  10556. var list = splitNumberSequence(pointsString);
  10557. var points = [];
  10558. for (var i = 0; i < list.length; i += 2) {
  10559. var x = parseFloat(list[i]);
  10560. var y = parseFloat(list[i + 1]);
  10561. points.push([x, y]);
  10562. }
  10563. return points;
  10564. }
  10565. function parseAttributes(xmlNode, el, defsUsePending, onlyInlineStyle, isTextGroup) {
  10566. var disp = el;
  10567. var inheritedStyle = disp.__inheritedStyle = disp.__inheritedStyle || {};
  10568. var selfStyle = {};
  10569. if (xmlNode.nodeType === 1) {
  10570. parseTransformAttribute(xmlNode, el);
  10571. parseInlineStyle(xmlNode, inheritedStyle, selfStyle);
  10572. if (!onlyInlineStyle) {
  10573. parseAttributeStyle(xmlNode, inheritedStyle, selfStyle);
  10574. }
  10575. }
  10576. disp.style = disp.style || {};
  10577. if (inheritedStyle.fill != null) {
  10578. disp.style.fill = getFillStrokeStyle(disp, 'fill', inheritedStyle.fill, defsUsePending);
  10579. }
  10580. if (inheritedStyle.stroke != null) {
  10581. disp.style.stroke = getFillStrokeStyle(disp, 'stroke', inheritedStyle.stroke, defsUsePending);
  10582. }
  10583. each([
  10584. 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'
  10585. ], function (propName) {
  10586. if (inheritedStyle[propName] != null) {
  10587. disp.style[propName] = parseFloat(inheritedStyle[propName]);
  10588. }
  10589. });
  10590. each([
  10591. 'lineDashOffset', 'lineCap', 'lineJoin', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign'
  10592. ], function (propName) {
  10593. if (inheritedStyle[propName] != null) {
  10594. disp.style[propName] = inheritedStyle[propName];
  10595. }
  10596. });
  10597. if (isTextGroup) {
  10598. disp.__selfStyle = selfStyle;
  10599. }
  10600. if (inheritedStyle.lineDash) {
  10601. disp.style.lineDash = map(splitNumberSequence(inheritedStyle.lineDash), function (str) {
  10602. return parseFloat(str);
  10603. });
  10604. }
  10605. if (inheritedStyle.visibility === 'hidden' || inheritedStyle.visibility === 'collapse') {
  10606. disp.invisible = true;
  10607. }
  10608. if (inheritedStyle.display === 'none') {
  10609. disp.ignore = true;
  10610. }
  10611. }
  10612. function applyTextAlignment(text, parentGroup) {
  10613. var parentSelfStyle = parentGroup.__selfStyle;
  10614. if (parentSelfStyle) {
  10615. var textBaseline = parentSelfStyle.textBaseline;
  10616. var zrTextBaseline = textBaseline;
  10617. if (!textBaseline || textBaseline === 'auto') {
  10618. zrTextBaseline = 'alphabetic';
  10619. }
  10620. else if (textBaseline === 'baseline') {
  10621. zrTextBaseline = 'alphabetic';
  10622. }
  10623. else if (textBaseline === 'before-edge' || textBaseline === 'text-before-edge') {
  10624. zrTextBaseline = 'top';
  10625. }
  10626. else if (textBaseline === 'after-edge' || textBaseline === 'text-after-edge') {
  10627. zrTextBaseline = 'bottom';
  10628. }
  10629. else if (textBaseline === 'central' || textBaseline === 'mathematical') {
  10630. zrTextBaseline = 'middle';
  10631. }
  10632. text.style.textBaseline = zrTextBaseline;
  10633. }
  10634. var parentInheritedStyle = parentGroup.__inheritedStyle;
  10635. if (parentInheritedStyle) {
  10636. var textAlign = parentInheritedStyle.textAlign;
  10637. var zrTextAlign = textAlign;
  10638. if (textAlign) {
  10639. if (textAlign === 'middle') {
  10640. zrTextAlign = 'center';
  10641. }
  10642. text.style.textAlign = zrTextAlign;
  10643. }
  10644. }
  10645. }
  10646. var urlRegex = /^url\(\s*#(.*?)\)/;
  10647. function getFillStrokeStyle(el, method, str, defsUsePending) {
  10648. var urlMatch = str && str.match(urlRegex);
  10649. if (urlMatch) {
  10650. var url = trim(urlMatch[1]);
  10651. defsUsePending.push([el, method, url]);
  10652. return;
  10653. }
  10654. if (str === 'none') {
  10655. str = null;
  10656. }
  10657. return str;
  10658. }
  10659. function applyDefs(defs, defsUsePending) {
  10660. for (var i = 0; i < defsUsePending.length; i++) {
  10661. var item = defsUsePending[i];
  10662. item[0].style[item[1]] = defs[item[2]];
  10663. }
  10664. }
  10665. var numberReg$1 = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  10666. function splitNumberSequence(rawStr) {
  10667. return rawStr.match(numberReg$1) || [];
  10668. }
  10669. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.eE,]*)\)/g;
  10670. var DEGREE_TO_ANGLE = Math.PI / 180;
  10671. function parseTransformAttribute(xmlNode, node) {
  10672. var transform = xmlNode.getAttribute('transform');
  10673. if (transform) {
  10674. transform = transform.replace(/,/g, ' ');
  10675. var transformOps_1 = [];
  10676. var mt = null;
  10677. transform.replace(transformRegex, function (str, type, value) {
  10678. transformOps_1.push(type, value);
  10679. return '';
  10680. });
  10681. for (var i = transformOps_1.length - 1; i > 0; i -= 2) {
  10682. var value = transformOps_1[i];
  10683. var type = transformOps_1[i - 1];
  10684. var valueArr = splitNumberSequence(value);
  10685. mt = mt || create$1();
  10686. switch (type) {
  10687. case 'translate':
  10688. translate(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || '0')]);
  10689. break;
  10690. case 'scale':
  10691. scale$1(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || valueArr[0])]);
  10692. break;
  10693. case 'rotate':
  10694. rotate(mt, mt, -parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10695. break;
  10696. case 'skewX':
  10697. var sx = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10698. mul$1(mt, [1, 0, sx, 1, 0, 0], mt);
  10699. break;
  10700. case 'skewY':
  10701. var sy = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10702. mul$1(mt, [1, sy, 0, 1, 0, 0], mt);
  10703. break;
  10704. case 'matrix':
  10705. mt[0] = parseFloat(valueArr[0]);
  10706. mt[1] = parseFloat(valueArr[1]);
  10707. mt[2] = parseFloat(valueArr[2]);
  10708. mt[3] = parseFloat(valueArr[3]);
  10709. mt[4] = parseFloat(valueArr[4]);
  10710. mt[5] = parseFloat(valueArr[5]);
  10711. break;
  10712. }
  10713. }
  10714. node.setLocalTransform(mt);
  10715. }
  10716. }
  10717. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  10718. function parseInlineStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  10719. var style = xmlNode.getAttribute('style');
  10720. if (!style) {
  10721. return;
  10722. }
  10723. styleRegex.lastIndex = 0;
  10724. var styleRegResult;
  10725. while ((styleRegResult = styleRegex.exec(style)) != null) {
  10726. var svgStlAttr = styleRegResult[1];
  10727. var zrInheritableStlAttr = hasOwn(INHERITABLE_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  10728. ? INHERITABLE_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  10729. : null;
  10730. if (zrInheritableStlAttr) {
  10731. inheritableStyleResult[zrInheritableStlAttr] = styleRegResult[2];
  10732. }
  10733. var zrSelfStlAttr = hasOwn(SELF_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  10734. ? SELF_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  10735. : null;
  10736. if (zrSelfStlAttr) {
  10737. selfStyleResult[zrSelfStlAttr] = styleRegResult[2];
  10738. }
  10739. }
  10740. }
  10741. function parseAttributeStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  10742. for (var i = 0; i < INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  10743. var svgAttrName = INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS[i];
  10744. var attrValue = xmlNode.getAttribute(svgAttrName);
  10745. if (attrValue != null) {
  10746. inheritableStyleResult[INHERITABLE_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  10747. }
  10748. }
  10749. for (var i = 0; i < SELF_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  10750. var svgAttrName = SELF_STYLE_ATTRIBUTES_MAP_KEYS[i];
  10751. var attrValue = xmlNode.getAttribute(svgAttrName);
  10752. if (attrValue != null) {
  10753. selfStyleResult[SELF_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  10754. }
  10755. }
  10756. }
  10757. function makeViewBoxTransform(viewBoxRect, boundingRect) {
  10758. var scaleX = boundingRect.width / viewBoxRect.width;
  10759. var scaleY = boundingRect.height / viewBoxRect.height;
  10760. var scale = Math.min(scaleX, scaleY);
  10761. return {
  10762. scale: scale,
  10763. x: -(viewBoxRect.x + viewBoxRect.width / 2) * scale + (boundingRect.x + boundingRect.width / 2),
  10764. y: -(viewBoxRect.y + viewBoxRect.height / 2) * scale + (boundingRect.y + boundingRect.height / 2)
  10765. };
  10766. }
  10767. function parseSVG(xml, opt) {
  10768. var parser = new SVGParser();
  10769. return parser.parse(xml, opt);
  10770. }
  10771. var PI$2 = Math.PI;
  10772. var PI2$5 = PI$2 * 2;
  10773. var mathSin$3 = Math.sin;
  10774. var mathCos$3 = Math.cos;
  10775. var mathACos = Math.acos;
  10776. var mathATan2 = Math.atan2;
  10777. var mathAbs$1 = Math.abs;
  10778. var mathSqrt$3 = Math.sqrt;
  10779. var mathMax$3 = Math.max;
  10780. var mathMin$3 = Math.min;
  10781. var e = 1e-4;
  10782. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  10783. var dx10 = x1 - x0;
  10784. var dy10 = y1 - y0;
  10785. var dx32 = x3 - x2;
  10786. var dy32 = y3 - y2;
  10787. var t = dy32 * dx10 - dx32 * dy10;
  10788. if (t * t < e) {
  10789. return;
  10790. }
  10791. t = (dx32 * (y0 - y2) - dy32 * (x0 - x2)) / t;
  10792. return [x0 + t * dx10, y0 + t * dy10];
  10793. }
  10794. function computeCornerTangents(x0, y0, x1, y1, radius, cr, clockwise) {
  10795. var x01 = x0 - x1;
  10796. var y01 = y0 - y1;
  10797. var lo = (clockwise ? cr : -cr) / mathSqrt$3(x01 * x01 + y01 * y01);
  10798. var ox = lo * y01;
  10799. var oy = -lo * x01;
  10800. var x11 = x0 + ox;
  10801. var y11 = y0 + oy;
  10802. var x10 = x1 + ox;
  10803. var y10 = y1 + oy;
  10804. var x00 = (x11 + x10) / 2;
  10805. var y00 = (y11 + y10) / 2;
  10806. var dx = x10 - x11;
  10807. var dy = y10 - y11;
  10808. var d2 = dx * dx + dy * dy;
  10809. var r = radius - cr;
  10810. var s = x11 * y10 - x10 * y11;
  10811. var d = (dy < 0 ? -1 : 1) * mathSqrt$3(mathMax$3(0, r * r * d2 - s * s));
  10812. var cx0 = (s * dy - dx * d) / d2;
  10813. var cy0 = (-s * dx - dy * d) / d2;
  10814. var cx1 = (s * dy + dx * d) / d2;
  10815. var cy1 = (-s * dx + dy * d) / d2;
  10816. var dx0 = cx0 - x00;
  10817. var dy0 = cy0 - y00;
  10818. var dx1 = cx1 - x00;
  10819. var dy1 = cy1 - y00;
  10820. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
  10821. cx0 = cx1;
  10822. cy0 = cy1;
  10823. }
  10824. return {
  10825. cx: cx0,
  10826. cy: cy0,
  10827. x0: -ox,
  10828. y0: -oy,
  10829. x1: cx0 * (radius / r - 1),
  10830. y1: cy0 * (radius / r - 1)
  10831. };
  10832. }
  10833. function normalizeCornerRadius(cr) {
  10834. var arr;
  10835. if (isArray(cr)) {
  10836. var len = cr.length;
  10837. if (!len) {
  10838. return cr;
  10839. }
  10840. if (len === 1) {
  10841. arr = [cr[0], cr[0], 0, 0];
  10842. }
  10843. else if (len === 2) {
  10844. arr = [cr[0], cr[0], cr[1], cr[1]];
  10845. }
  10846. else if (len === 3) {
  10847. arr = cr.concat(cr[2]);
  10848. }
  10849. else {
  10850. arr = cr;
  10851. }
  10852. }
  10853. else {
  10854. arr = [cr, cr, cr, cr];
  10855. }
  10856. return arr;
  10857. }
  10858. function buildPath$2(ctx, shape) {
  10859. var _a;
  10860. var radius = mathMax$3(shape.r, 0);
  10861. var innerRadius = mathMax$3(shape.r0 || 0, 0);
  10862. var hasRadius = radius > 0;
  10863. var hasInnerRadius = innerRadius > 0;
  10864. if (!hasRadius && !hasInnerRadius) {
  10865. return;
  10866. }
  10867. if (!hasRadius) {
  10868. radius = innerRadius;
  10869. innerRadius = 0;
  10870. }
  10871. if (innerRadius > radius) {
  10872. var tmp = radius;
  10873. radius = innerRadius;
  10874. innerRadius = tmp;
  10875. }
  10876. var startAngle = shape.startAngle, endAngle = shape.endAngle;
  10877. if (isNaN(startAngle) || isNaN(endAngle)) {
  10878. return;
  10879. }
  10880. var cx = shape.cx, cy = shape.cy;
  10881. var clockwise = !!shape.clockwise;
  10882. var arc = mathAbs$1(endAngle - startAngle);
  10883. var mod = arc > PI2$5 && arc % PI2$5;
  10884. mod > e && (arc = mod);
  10885. if (!(radius > e)) {
  10886. ctx.moveTo(cx, cy);
  10887. }
  10888. else if (arc > PI2$5 - e) {
  10889. ctx.moveTo(cx + radius * mathCos$3(startAngle), cy + radius * mathSin$3(startAngle));
  10890. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  10891. if (innerRadius > e) {
  10892. ctx.moveTo(cx + innerRadius * mathCos$3(endAngle), cy + innerRadius * mathSin$3(endAngle));
  10893. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  10894. }
  10895. }
  10896. else {
  10897. var icrStart = void 0;
  10898. var icrEnd = void 0;
  10899. var ocrStart = void 0;
  10900. var ocrEnd = void 0;
  10901. var ocrs = void 0;
  10902. var ocre = void 0;
  10903. var icrs = void 0;
  10904. var icre = void 0;
  10905. var ocrMax = void 0;
  10906. var icrMax = void 0;
  10907. var limitedOcrMax = void 0;
  10908. var limitedIcrMax = void 0;
  10909. var xre = void 0;
  10910. var yre = void 0;
  10911. var xirs = void 0;
  10912. var yirs = void 0;
  10913. var xrs = radius * mathCos$3(startAngle);
  10914. var yrs = radius * mathSin$3(startAngle);
  10915. var xire = innerRadius * mathCos$3(endAngle);
  10916. var yire = innerRadius * mathSin$3(endAngle);
  10917. var hasArc = arc > e;
  10918. if (hasArc) {
  10919. var cornerRadius = shape.cornerRadius;
  10920. if (cornerRadius) {
  10921. _a = normalizeCornerRadius(cornerRadius), icrStart = _a[0], icrEnd = _a[1], ocrStart = _a[2], ocrEnd = _a[3];
  10922. }
  10923. var halfRd = mathAbs$1(radius - innerRadius) / 2;
  10924. ocrs = mathMin$3(halfRd, ocrStart);
  10925. ocre = mathMin$3(halfRd, ocrEnd);
  10926. icrs = mathMin$3(halfRd, icrStart);
  10927. icre = mathMin$3(halfRd, icrEnd);
  10928. limitedOcrMax = ocrMax = mathMax$3(ocrs, ocre);
  10929. limitedIcrMax = icrMax = mathMax$3(icrs, icre);
  10930. if (ocrMax > e || icrMax > e) {
  10931. xre = radius * mathCos$3(endAngle);
  10932. yre = radius * mathSin$3(endAngle);
  10933. xirs = innerRadius * mathCos$3(startAngle);
  10934. yirs = innerRadius * mathSin$3(startAngle);
  10935. if (arc < PI$2) {
  10936. var it_1 = intersect(xrs, yrs, xirs, yirs, xre, yre, xire, yire);
  10937. if (it_1) {
  10938. var x0 = xrs - it_1[0];
  10939. var y0 = yrs - it_1[1];
  10940. var x1 = xre - it_1[0];
  10941. var y1 = yre - it_1[1];
  10942. var a = 1 / mathSin$3(mathACos((x0 * x1 + y0 * y1) / (mathSqrt$3(x0 * x0 + y0 * y0) * mathSqrt$3(x1 * x1 + y1 * y1))) / 2);
  10943. var b = mathSqrt$3(it_1[0] * it_1[0] + it_1[1] * it_1[1]);
  10944. limitedOcrMax = mathMin$3(ocrMax, (radius - b) / (a + 1));
  10945. limitedIcrMax = mathMin$3(icrMax, (innerRadius - b) / (a - 1));
  10946. }
  10947. }
  10948. }
  10949. }
  10950. if (!hasArc) {
  10951. ctx.moveTo(cx + xrs, cy + yrs);
  10952. }
  10953. else if (limitedOcrMax > e) {
  10954. var crStart = mathMin$3(ocrStart, limitedOcrMax);
  10955. var crEnd = mathMin$3(ocrEnd, limitedOcrMax);
  10956. var ct0 = computeCornerTangents(xirs, yirs, xrs, yrs, radius, crStart, clockwise);
  10957. var ct1 = computeCornerTangents(xre, yre, xire, yire, radius, crEnd, clockwise);
  10958. ctx.moveTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  10959. if (limitedOcrMax < ocrMax && crStart === crEnd) {
  10960. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedOcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  10961. }
  10962. else {
  10963. crStart > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crStart, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  10964. ctx.arc(cx, cy, radius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), !clockwise);
  10965. crEnd > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crEnd, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  10966. }
  10967. }
  10968. else {
  10969. ctx.moveTo(cx + xrs, cy + yrs);
  10970. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  10971. }
  10972. if (!(innerRadius > e) || !hasArc) {
  10973. ctx.lineTo(cx + xire, cy + yire);
  10974. }
  10975. else if (limitedIcrMax > e) {
  10976. var crStart = mathMin$3(icrStart, limitedIcrMax);
  10977. var crEnd = mathMin$3(icrEnd, limitedIcrMax);
  10978. var ct0 = computeCornerTangents(xire, yire, xre, yre, innerRadius, -crEnd, clockwise);
  10979. var ct1 = computeCornerTangents(xrs, yrs, xirs, yirs, innerRadius, -crStart, clockwise);
  10980. ctx.lineTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  10981. if (limitedIcrMax < icrMax && crStart === crEnd) {
  10982. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedIcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  10983. }
  10984. else {
  10985. crEnd > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crEnd, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  10986. ctx.arc(cx, cy, innerRadius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), clockwise);
  10987. crStart > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crStart, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  10988. }
  10989. }
  10990. else {
  10991. ctx.lineTo(cx + xire, cy + yire);
  10992. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  10993. }
  10994. }
  10995. ctx.closePath();
  10996. }
  10997. var SectorShape = (function () {
  10998. function SectorShape() {
  10999. this.cx = 0;
  11000. this.cy = 0;
  11001. this.r0 = 0;
  11002. this.r = 0;
  11003. this.startAngle = 0;
  11004. this.endAngle = Math.PI * 2;
  11005. this.clockwise = true;
  11006. this.cornerRadius = 0;
  11007. }
  11008. return SectorShape;
  11009. }());
  11010. var Sector = (function (_super) {
  11011. __extends(Sector, _super);
  11012. function Sector(opts) {
  11013. return _super.call(this, opts) || this;
  11014. }
  11015. Sector.prototype.getDefaultShape = function () {
  11016. return new SectorShape();
  11017. };
  11018. Sector.prototype.buildPath = function (ctx, shape) {
  11019. buildPath$2(ctx, shape);
  11020. };
  11021. Sector.prototype.isZeroArea = function () {
  11022. return this.shape.startAngle === this.shape.endAngle
  11023. || this.shape.r === this.shape.r0;
  11024. };
  11025. return Sector;
  11026. }(Path));
  11027. Sector.prototype.type = 'sector';
  11028. var CMD$3 = PathProxy.CMD;
  11029. function aroundEqual(a, b) {
  11030. return Math.abs(a - b) < 1e-5;
  11031. }
  11032. function pathToBezierCurves(path) {
  11033. var data = path.data;
  11034. var len = path.len();
  11035. var bezierArrayGroups = [];
  11036. var currentSubpath;
  11037. var xi = 0;
  11038. var yi = 0;
  11039. var x0 = 0;
  11040. var y0 = 0;
  11041. function createNewSubpath(x, y) {
  11042. if (currentSubpath && currentSubpath.length > 2) {
  11043. bezierArrayGroups.push(currentSubpath);
  11044. }
  11045. currentSubpath = [x, y];
  11046. }
  11047. function addLine(x0, y0, x1, y1) {
  11048. if (!(aroundEqual(x0, x1) && aroundEqual(y0, y1))) {
  11049. currentSubpath.push(x0, y0, x1, y1, x1, y1);
  11050. }
  11051. }
  11052. function addArc(startAngle, endAngle, cx, cy, rx, ry) {
  11053. var delta = Math.abs(endAngle - startAngle);
  11054. var len = Math.tan(delta / 4) * 4 / 3;
  11055. var dir = endAngle < startAngle ? -1 : 1;
  11056. var c1 = Math.cos(startAngle);
  11057. var s1 = Math.sin(startAngle);
  11058. var c2 = Math.cos(endAngle);
  11059. var s2 = Math.sin(endAngle);
  11060. var x1 = c1 * rx + cx;
  11061. var y1 = s1 * ry + cy;
  11062. var x4 = c2 * rx + cx;
  11063. var y4 = s2 * ry + cy;
  11064. var hx = rx * len * dir;
  11065. var hy = ry * len * dir;
  11066. currentSubpath.push(x1 - hx * s1, y1 + hy * c1, x4 + hx * s2, y4 - hy * c2, x4, y4);
  11067. }
  11068. var x1;
  11069. var y1;
  11070. var x2;
  11071. var y2;
  11072. for (var i = 0; i < len;) {
  11073. var cmd = data[i++];
  11074. var isFirst = i === 1;
  11075. if (isFirst) {
  11076. xi = data[i];
  11077. yi = data[i + 1];
  11078. x0 = xi;
  11079. y0 = yi;
  11080. if (cmd === CMD$3.L || cmd === CMD$3.C || cmd === CMD$3.Q) {
  11081. currentSubpath = [x0, y0];
  11082. }
  11083. }
  11084. switch (cmd) {
  11085. case CMD$3.M:
  11086. xi = x0 = data[i++];
  11087. yi = y0 = data[i++];
  11088. createNewSubpath(x0, y0);
  11089. break;
  11090. case CMD$3.L:
  11091. x1 = data[i++];
  11092. y1 = data[i++];
  11093. addLine(xi, yi, x1, y1);
  11094. xi = x1;
  11095. yi = y1;
  11096. break;
  11097. case CMD$3.C:
  11098. currentSubpath.push(data[i++], data[i++], data[i++], data[i++], xi = data[i++], yi = data[i++]);
  11099. break;
  11100. case CMD$3.Q:
  11101. x1 = data[i++];
  11102. y1 = data[i++];
  11103. x2 = data[i++];
  11104. y2 = data[i++];
  11105. currentSubpath.push(xi + 2 / 3 * (x1 - xi), yi + 2 / 3 * (y1 - yi), x2 + 2 / 3 * (x1 - x2), y2 + 2 / 3 * (y1 - y2), x2, y2);
  11106. xi = x2;
  11107. yi = y2;
  11108. break;
  11109. case CMD$3.A:
  11110. var cx = data[i++];
  11111. var cy = data[i++];
  11112. var rx = data[i++];
  11113. var ry = data[i++];
  11114. var startAngle = data[i++];
  11115. var endAngle = data[i++] + startAngle;
  11116. i += 1;
  11117. var anticlockwise = !data[i++];
  11118. x1 = Math.cos(startAngle) * rx + cx;
  11119. y1 = Math.sin(startAngle) * ry + cy;
  11120. if (isFirst) {
  11121. x0 = x1;
  11122. y0 = y1;
  11123. createNewSubpath(x0, y0);
  11124. }
  11125. else {
  11126. addLine(xi, yi, x1, y1);
  11127. }
  11128. xi = Math.cos(endAngle) * rx + cx;
  11129. yi = Math.sin(endAngle) * ry + cy;
  11130. var step = (anticlockwise ? -1 : 1) * Math.PI / 2;
  11131. for (var angle = startAngle; anticlockwise ? angle > endAngle : angle < endAngle; angle += step) {
  11132. var nextAngle = anticlockwise ? Math.max(angle + step, endAngle)
  11133. : Math.min(angle + step, endAngle);
  11134. addArc(angle, nextAngle, cx, cy, rx, ry);
  11135. }
  11136. break;
  11137. case CMD$3.R:
  11138. x0 = xi = data[i++];
  11139. y0 = yi = data[i++];
  11140. x1 = x0 + data[i++];
  11141. y1 = y0 + data[i++];
  11142. createNewSubpath(x1, y0);
  11143. addLine(x1, y0, x1, y1);
  11144. addLine(x1, y1, x0, y1);
  11145. addLine(x0, y1, x0, y0);
  11146. addLine(x0, y0, x1, y0);
  11147. break;
  11148. case CMD$3.Z:
  11149. currentSubpath && addLine(xi, yi, x0, y0);
  11150. xi = x0;
  11151. yi = y0;
  11152. break;
  11153. }
  11154. }
  11155. if (currentSubpath && currentSubpath.length > 2) {
  11156. bezierArrayGroups.push(currentSubpath);
  11157. }
  11158. return bezierArrayGroups;
  11159. }
  11160. function adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, out, scale) {
  11161. if (aroundEqual(x0, x1) && aroundEqual(y0, y1) && aroundEqual(x2, x3) && aroundEqual(y2, y3)) {
  11162. out.push(x3, y3);
  11163. return;
  11164. }
  11165. var PIXEL_DISTANCE = 2 / scale;
  11166. var PIXEL_DISTANCE_SQR = PIXEL_DISTANCE * PIXEL_DISTANCE;
  11167. var dx = x3 - x0;
  11168. var dy = y3 - y0;
  11169. var d = Math.sqrt(dx * dx + dy * dy);
  11170. dx /= d;
  11171. dy /= d;
  11172. var dx1 = x1 - x0;
  11173. var dy1 = y1 - y0;
  11174. var dx2 = x2 - x3;
  11175. var dy2 = y2 - y3;
  11176. var cp1LenSqr = dx1 * dx1 + dy1 * dy1;
  11177. var cp2LenSqr = dx2 * dx2 + dy2 * dy2;
  11178. if (cp1LenSqr < PIXEL_DISTANCE_SQR && cp2LenSqr < PIXEL_DISTANCE_SQR) {
  11179. out.push(x3, y3);
  11180. return;
  11181. }
  11182. var projLen1 = dx * dx1 + dy * dy1;
  11183. var projLen2 = -dx * dx2 - dy * dy2;
  11184. var d1Sqr = cp1LenSqr - projLen1 * projLen1;
  11185. var d2Sqr = cp2LenSqr - projLen2 * projLen2;
  11186. if (d1Sqr < PIXEL_DISTANCE_SQR && projLen1 >= 0
  11187. && d2Sqr < PIXEL_DISTANCE_SQR && projLen2 >= 0) {
  11188. out.push(x3, y3);
  11189. return;
  11190. }
  11191. var tmpSegX = [];
  11192. var tmpSegY = [];
  11193. cubicSubdivide(x0, x1, x2, x3, 0.5, tmpSegX);
  11194. cubicSubdivide(y0, y1, y2, y3, 0.5, tmpSegY);
  11195. adpativeBezier(tmpSegX[0], tmpSegY[0], tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], tmpSegX[3], tmpSegY[3], out, scale);
  11196. adpativeBezier(tmpSegX[4], tmpSegY[4], tmpSegX[5], tmpSegY[5], tmpSegX[6], tmpSegY[6], tmpSegX[7], tmpSegY[7], out, scale);
  11197. }
  11198. function pathToPolygons(path, scale) {
  11199. var bezierArrayGroups = pathToBezierCurves(path);
  11200. var polygons = [];
  11201. scale = scale || 1;
  11202. for (var i = 0; i < bezierArrayGroups.length; i++) {
  11203. var beziers = bezierArrayGroups[i];
  11204. var polygon = [];
  11205. var x0 = beziers[0];
  11206. var y0 = beziers[1];
  11207. polygon.push(x0, y0);
  11208. for (var k = 2; k < beziers.length;) {
  11209. var x1 = beziers[k++];
  11210. var y1 = beziers[k++];
  11211. var x2 = beziers[k++];
  11212. var y2 = beziers[k++];
  11213. var x3 = beziers[k++];
  11214. var y3 = beziers[k++];
  11215. adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, polygon, scale);
  11216. x0 = x3;
  11217. y0 = y3;
  11218. }
  11219. polygons.push(polygon);
  11220. }
  11221. return polygons;
  11222. }
  11223. function getDividingGrids(dimSize, rowDim, count) {
  11224. var rowSize = dimSize[rowDim];
  11225. var columnSize = dimSize[1 - rowDim];
  11226. var ratio = Math.abs(rowSize / columnSize);
  11227. var rowCount = Math.ceil(Math.sqrt(ratio * count));
  11228. var columnCount = Math.floor(count / rowCount);
  11229. if (columnCount === 0) {
  11230. columnCount = 1;
  11231. rowCount = count;
  11232. }
  11233. var grids = [];
  11234. for (var i = 0; i < rowCount; i++) {
  11235. grids.push(columnCount);
  11236. }
  11237. var currentCount = rowCount * columnCount;
  11238. var remained = count - currentCount;
  11239. if (remained > 0) {
  11240. for (var i = 0; i < remained; i++) {
  11241. grids[i % rowCount] += 1;
  11242. }
  11243. }
  11244. return grids;
  11245. }
  11246. function divideSector(sectorShape, count, outShapes) {
  11247. var r0 = sectorShape.r0;
  11248. var r = sectorShape.r;
  11249. var startAngle = sectorShape.startAngle;
  11250. var endAngle = sectorShape.endAngle;
  11251. var angle = Math.abs(endAngle - startAngle);
  11252. var arcLen = angle * r;
  11253. var deltaR = r - r0;
  11254. var isAngleRow = arcLen > Math.abs(deltaR);
  11255. var grids = getDividingGrids([arcLen, deltaR], isAngleRow ? 0 : 1, count);
  11256. var rowSize = (isAngleRow ? angle : deltaR) / grids.length;
  11257. for (var row = 0; row < grids.length; row++) {
  11258. var columnSize = (isAngleRow ? deltaR : angle) / grids[row];
  11259. for (var column = 0; column < grids[row]; column++) {
  11260. var newShape = {};
  11261. if (isAngleRow) {
  11262. newShape.startAngle = startAngle + rowSize * row;
  11263. newShape.endAngle = startAngle + rowSize * (row + 1);
  11264. newShape.r0 = r0 + columnSize * column;
  11265. newShape.r = r0 + columnSize * (column + 1);
  11266. }
  11267. else {
  11268. newShape.startAngle = startAngle + columnSize * column;
  11269. newShape.endAngle = startAngle + columnSize * (column + 1);
  11270. newShape.r0 = r0 + rowSize * row;
  11271. newShape.r = r0 + rowSize * (row + 1);
  11272. }
  11273. newShape.clockwise = sectorShape.clockwise;
  11274. newShape.cx = sectorShape.cx;
  11275. newShape.cy = sectorShape.cy;
  11276. outShapes.push(newShape);
  11277. }
  11278. }
  11279. }
  11280. function divideRect(rectShape, count, outShapes) {
  11281. var width = rectShape.width;
  11282. var height = rectShape.height;
  11283. var isHorizontalRow = width > height;
  11284. var grids = getDividingGrids([width, height], isHorizontalRow ? 0 : 1, count);
  11285. var rowSizeDim = isHorizontalRow ? 'width' : 'height';
  11286. var columnSizeDim = isHorizontalRow ? 'height' : 'width';
  11287. var rowDim = isHorizontalRow ? 'x' : 'y';
  11288. var columnDim = isHorizontalRow ? 'y' : 'x';
  11289. var rowSize = rectShape[rowSizeDim] / grids.length;
  11290. for (var row = 0; row < grids.length; row++) {
  11291. var columnSize = rectShape[columnSizeDim] / grids[row];
  11292. for (var column = 0; column < grids[row]; column++) {
  11293. var newShape = {};
  11294. newShape[rowDim] = row * rowSize;
  11295. newShape[columnDim] = column * columnSize;
  11296. newShape[rowSizeDim] = rowSize;
  11297. newShape[columnSizeDim] = columnSize;
  11298. newShape.x += rectShape.x;
  11299. newShape.y += rectShape.y;
  11300. outShapes.push(newShape);
  11301. }
  11302. }
  11303. }
  11304. function crossProduct2d(x1, y1, x2, y2) {
  11305. return x1 * y2 - x2 * y1;
  11306. }
  11307. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  11308. var mx = a2x - a1x;
  11309. var my = a2y - a1y;
  11310. var nx = b2x - b1x;
  11311. var ny = b2y - b1y;
  11312. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  11313. if (Math.abs(nmCrossProduct) < 1e-6) {
  11314. return null;
  11315. }
  11316. var b1a1x = a1x - b1x;
  11317. var b1a1y = a1y - b1y;
  11318. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  11319. if (p < 0 || p > 1) {
  11320. return null;
  11321. }
  11322. return new Point(p * mx + a1x, p * my + a1y);
  11323. }
  11324. function projPtOnLine(pt, lineA, lineB) {
  11325. var dir = new Point();
  11326. Point.sub(dir, lineB, lineA);
  11327. dir.normalize();
  11328. var dir2 = new Point();
  11329. Point.sub(dir2, pt, lineA);
  11330. var len = dir2.dot(dir);
  11331. return len;
  11332. }
  11333. function addToPoly(poly, pt) {
  11334. var last = poly[poly.length - 1];
  11335. if (last && last[0] === pt[0] && last[1] === pt[1]) {
  11336. return;
  11337. }
  11338. poly.push(pt);
  11339. }
  11340. function splitPolygonByLine(points, lineA, lineB) {
  11341. var len = points.length;
  11342. var intersections = [];
  11343. for (var i = 0; i < len; i++) {
  11344. var p0 = points[i];
  11345. var p1 = points[(i + 1) % len];
  11346. var intersectionPt = lineLineIntersect(p0[0], p0[1], p1[0], p1[1], lineA.x, lineA.y, lineB.x, lineB.y);
  11347. if (intersectionPt) {
  11348. intersections.push({
  11349. projPt: projPtOnLine(intersectionPt, lineA, lineB),
  11350. pt: intersectionPt,
  11351. idx: i
  11352. });
  11353. }
  11354. }
  11355. if (intersections.length < 2) {
  11356. return [{ points: points }, { points: points }];
  11357. }
  11358. intersections.sort(function (a, b) {
  11359. return a.projPt - b.projPt;
  11360. });
  11361. var splitPt0 = intersections[0];
  11362. var splitPt1 = intersections[intersections.length - 1];
  11363. if (splitPt1.idx < splitPt0.idx) {
  11364. var tmp = splitPt0;
  11365. splitPt0 = splitPt1;
  11366. splitPt1 = tmp;
  11367. }
  11368. var splitPt0Arr = [splitPt0.pt.x, splitPt0.pt.y];
  11369. var splitPt1Arr = [splitPt1.pt.x, splitPt1.pt.y];
  11370. var newPolyA = [splitPt0Arr];
  11371. var newPolyB = [splitPt1Arr];
  11372. for (var i = splitPt0.idx + 1; i <= splitPt1.idx; i++) {
  11373. addToPoly(newPolyA, points[i].slice());
  11374. }
  11375. addToPoly(newPolyA, splitPt1Arr);
  11376. addToPoly(newPolyA, splitPt0Arr);
  11377. for (var i = splitPt1.idx + 1; i <= splitPt0.idx + len; i++) {
  11378. addToPoly(newPolyB, points[i % len].slice());
  11379. }
  11380. addToPoly(newPolyB, splitPt0Arr);
  11381. addToPoly(newPolyB, splitPt1Arr);
  11382. return [{
  11383. points: newPolyA
  11384. }, {
  11385. points: newPolyB
  11386. }];
  11387. }
  11388. function binaryDividePolygon(polygonShape) {
  11389. var points = polygonShape.points;
  11390. var min = [];
  11391. var max = [];
  11392. fromPoints(points, min, max);
  11393. var boundingRect = new BoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  11394. var width = boundingRect.width;
  11395. var height = boundingRect.height;
  11396. var x = boundingRect.x;
  11397. var y = boundingRect.y;
  11398. var pt0 = new Point();
  11399. var pt1 = new Point();
  11400. if (width > height) {
  11401. pt0.x = pt1.x = x + width / 2;
  11402. pt0.y = y;
  11403. pt1.y = y + height;
  11404. }
  11405. else {
  11406. pt0.y = pt1.y = y + height / 2;
  11407. pt0.x = x;
  11408. pt1.x = x + width;
  11409. }
  11410. return splitPolygonByLine(points, pt0, pt1);
  11411. }
  11412. function binaryDivideRecursive(divider, shape, count, out) {
  11413. if (count === 1) {
  11414. out.push(shape);
  11415. }
  11416. else {
  11417. var mid = Math.floor(count / 2);
  11418. var sub = divider(shape);
  11419. binaryDivideRecursive(divider, sub[0], mid, out);
  11420. binaryDivideRecursive(divider, sub[1], count - mid, out);
  11421. }
  11422. return out;
  11423. }
  11424. function clone$3(path, count) {
  11425. var paths = [];
  11426. for (var i = 0; i < count; i++) {
  11427. paths.push(clonePath(path));
  11428. }
  11429. return paths;
  11430. }
  11431. function copyPathProps(source, target) {
  11432. target.setStyle(source.style);
  11433. target.z = source.z;
  11434. target.z2 = source.z2;
  11435. target.zlevel = source.zlevel;
  11436. }
  11437. function polygonConvert(points) {
  11438. var out = [];
  11439. for (var i = 0; i < points.length;) {
  11440. out.push([points[i++], points[i++]]);
  11441. }
  11442. return out;
  11443. }
  11444. function split(path, count) {
  11445. var outShapes = [];
  11446. var shape = path.shape;
  11447. var OutShapeCtor;
  11448. switch (path.type) {
  11449. case 'rect':
  11450. divideRect(shape, count, outShapes);
  11451. OutShapeCtor = Rect;
  11452. break;
  11453. case 'sector':
  11454. divideSector(shape, count, outShapes);
  11455. OutShapeCtor = Sector;
  11456. break;
  11457. case 'circle':
  11458. divideSector({
  11459. r0: 0, r: shape.r, startAngle: 0, endAngle: Math.PI * 2,
  11460. cx: shape.cx, cy: shape.cy
  11461. }, count, outShapes);
  11462. OutShapeCtor = Sector;
  11463. break;
  11464. default:
  11465. var m = path.getComputedTransform();
  11466. var scale = m ? Math.sqrt(Math.max(m[0] * m[0] + m[1] * m[1], m[2] * m[2] + m[3] * m[3])) : 1;
  11467. var polygons = map(pathToPolygons(path.getUpdatedPathProxy(), scale), function (poly) { return polygonConvert(poly); });
  11468. var polygonCount = polygons.length;
  11469. if (polygonCount === 0) {
  11470. binaryDivideRecursive(binaryDividePolygon, {
  11471. points: polygons[0]
  11472. }, count, outShapes);
  11473. }
  11474. else if (polygonCount === count) {
  11475. for (var i = 0; i < polygonCount; i++) {
  11476. outShapes.push({
  11477. points: polygons[i]
  11478. });
  11479. }
  11480. }
  11481. else {
  11482. var totalArea_1 = 0;
  11483. var items = map(polygons, function (poly) {
  11484. var min = [];
  11485. var max = [];
  11486. fromPoints(poly, min, max);
  11487. var area = (max[1] - min[1]) * (max[0] - min[0]);
  11488. totalArea_1 += area;
  11489. return { poly: poly, area: area };
  11490. });
  11491. items.sort(function (a, b) { return b.area - a.area; });
  11492. var left = count;
  11493. for (var i = 0; i < polygonCount; i++) {
  11494. var item = items[i];
  11495. if (left <= 0) {
  11496. break;
  11497. }
  11498. var selfCount = i === polygonCount - 1
  11499. ? left
  11500. : Math.ceil(item.area / totalArea_1 * count);
  11501. if (selfCount < 0) {
  11502. continue;
  11503. }
  11504. binaryDivideRecursive(binaryDividePolygon, {
  11505. points: item.poly
  11506. }, selfCount, outShapes);
  11507. left -= selfCount;
  11508. }
  11509. }
  11510. OutShapeCtor = Polygon;
  11511. break;
  11512. }
  11513. if (!OutShapeCtor) {
  11514. return clone$3(path, count);
  11515. }
  11516. var out = [];
  11517. for (var i = 0; i < outShapes.length; i++) {
  11518. var subPath = new OutShapeCtor();
  11519. subPath.setShape(outShapes[i]);
  11520. copyPathProps(path, subPath);
  11521. out.push(subPath);
  11522. }
  11523. return out;
  11524. }
  11525. function alignSubpath(subpath1, subpath2) {
  11526. var len1 = subpath1.length;
  11527. var len2 = subpath2.length;
  11528. if (len1 === len2) {
  11529. return [subpath1, subpath2];
  11530. }
  11531. var tmpSegX = [];
  11532. var tmpSegY = [];
  11533. var shorterPath = len1 < len2 ? subpath1 : subpath2;
  11534. var shorterLen = Math.min(len1, len2);
  11535. var diff = Math.abs(len2 - len1) / 6;
  11536. var shorterBezierCount = (shorterLen - 2) / 6;
  11537. var eachCurveSubDivCount = Math.ceil(diff / shorterBezierCount) + 1;
  11538. var newSubpath = [shorterPath[0], shorterPath[1]];
  11539. var remained = diff;
  11540. for (var i = 2; i < shorterLen;) {
  11541. var x0 = shorterPath[i - 2];
  11542. var y0 = shorterPath[i - 1];
  11543. var x1 = shorterPath[i++];
  11544. var y1 = shorterPath[i++];
  11545. var x2 = shorterPath[i++];
  11546. var y2 = shorterPath[i++];
  11547. var x3 = shorterPath[i++];
  11548. var y3 = shorterPath[i++];
  11549. if (remained <= 0) {
  11550. newSubpath.push(x1, y1, x2, y2, x3, y3);
  11551. continue;
  11552. }
  11553. var actualSubDivCount = Math.min(remained, eachCurveSubDivCount - 1) + 1;
  11554. for (var k = 1; k <= actualSubDivCount; k++) {
  11555. var p = k / actualSubDivCount;
  11556. cubicSubdivide(x0, x1, x2, x3, p, tmpSegX);
  11557. cubicSubdivide(y0, y1, y2, y3, p, tmpSegY);
  11558. x0 = tmpSegX[3];
  11559. y0 = tmpSegY[3];
  11560. newSubpath.push(tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], x0, y0);
  11561. x1 = tmpSegX[5];
  11562. y1 = tmpSegY[5];
  11563. x2 = tmpSegX[6];
  11564. y2 = tmpSegY[6];
  11565. }
  11566. remained -= actualSubDivCount - 1;
  11567. }
  11568. return shorterPath === subpath1 ? [newSubpath, subpath2] : [subpath1, newSubpath];
  11569. }
  11570. function createSubpath(lastSubpathSubpath, otherSubpath) {
  11571. var len = lastSubpathSubpath.length;
  11572. var lastX = lastSubpathSubpath[len - 2];
  11573. var lastY = lastSubpathSubpath[len - 1];
  11574. var newSubpath = [];
  11575. for (var i = 0; i < otherSubpath.length;) {
  11576. newSubpath[i++] = lastX;
  11577. newSubpath[i++] = lastY;
  11578. }
  11579. return newSubpath;
  11580. }
  11581. function alignBezierCurves(array1, array2) {
  11582. var _a;
  11583. var lastSubpath1;
  11584. var lastSubpath2;
  11585. var newArray1 = [];
  11586. var newArray2 = [];
  11587. for (var i = 0; i < Math.max(array1.length, array2.length); i++) {
  11588. var subpath1 = array1[i];
  11589. var subpath2 = array2[i];
  11590. var newSubpath1 = void 0;
  11591. var newSubpath2 = void 0;
  11592. if (!subpath1) {
  11593. newSubpath1 = createSubpath(lastSubpath1 || subpath2, subpath2);
  11594. newSubpath2 = subpath2;
  11595. }
  11596. else if (!subpath2) {
  11597. newSubpath2 = createSubpath(lastSubpath2 || subpath1, subpath1);
  11598. newSubpath1 = subpath1;
  11599. }
  11600. else {
  11601. _a = alignSubpath(subpath1, subpath2), newSubpath1 = _a[0], newSubpath2 = _a[1];
  11602. lastSubpath1 = newSubpath1;
  11603. lastSubpath2 = newSubpath2;
  11604. }
  11605. newArray1.push(newSubpath1);
  11606. newArray2.push(newSubpath2);
  11607. }
  11608. return [newArray1, newArray2];
  11609. }
  11610. function centroid(array) {
  11611. var signedArea = 0;
  11612. var cx = 0;
  11613. var cy = 0;
  11614. var len = array.length;
  11615. for (var i = 0, j = len - 2; i < len; j = i, i += 2) {
  11616. var x0 = array[j];
  11617. var y0 = array[j + 1];
  11618. var x1 = array[i];
  11619. var y1 = array[i + 1];
  11620. var a = x0 * y1 - x1 * y0;
  11621. signedArea += a;
  11622. cx += (x0 + x1) * a;
  11623. cy += (y0 + y1) * a;
  11624. }
  11625. if (signedArea === 0) {
  11626. return [array[0] || 0, array[1] || 0];
  11627. }
  11628. return [cx / signedArea / 3, cy / signedArea / 3, signedArea];
  11629. }
  11630. function findBestRingOffset(fromSubBeziers, toSubBeziers, fromCp, toCp) {
  11631. var bezierCount = (fromSubBeziers.length - 2) / 6;
  11632. var bestScore = Infinity;
  11633. var bestOffset = 0;
  11634. var len = fromSubBeziers.length;
  11635. var len2 = len - 2;
  11636. for (var offset = 0; offset < bezierCount; offset++) {
  11637. var cursorOffset = offset * 6;
  11638. var score = 0;
  11639. for (var k = 0; k < len; k += 2) {
  11640. var idx = k === 0 ? cursorOffset : ((cursorOffset + k - 2) % len2 + 2);
  11641. var x0 = fromSubBeziers[idx] - fromCp[0];
  11642. var y0 = fromSubBeziers[idx + 1] - fromCp[1];
  11643. var x1 = toSubBeziers[k] - toCp[0];
  11644. var y1 = toSubBeziers[k + 1] - toCp[1];
  11645. var dx = x1 - x0;
  11646. var dy = y1 - y0;
  11647. score += dx * dx + dy * dy;
  11648. }
  11649. if (score < bestScore) {
  11650. bestScore = score;
  11651. bestOffset = offset;
  11652. }
  11653. }
  11654. return bestOffset;
  11655. }
  11656. function reverse(array) {
  11657. var newArr = [];
  11658. var len = array.length;
  11659. for (var i = 0; i < len; i += 2) {
  11660. newArr[i] = array[len - i - 2];
  11661. newArr[i + 1] = array[len - i - 1];
  11662. }
  11663. return newArr;
  11664. }
  11665. function findBestMorphingRotation(fromArr, toArr, searchAngleIteration, searchAngleRange) {
  11666. var result = [];
  11667. var fromNeedsReverse;
  11668. for (var i = 0; i < fromArr.length; i++) {
  11669. var fromSubpathBezier = fromArr[i];
  11670. var toSubpathBezier = toArr[i];
  11671. var fromCp = centroid(fromSubpathBezier);
  11672. var toCp = centroid(toSubpathBezier);
  11673. if (fromNeedsReverse == null) {
  11674. fromNeedsReverse = fromCp[2] < 0 !== toCp[2] < 0;
  11675. }
  11676. var newFromSubpathBezier = [];
  11677. var newToSubpathBezier = [];
  11678. var bestAngle = 0;
  11679. var bestScore = Infinity;
  11680. var tmpArr = [];
  11681. var len = fromSubpathBezier.length;
  11682. if (fromNeedsReverse) {
  11683. fromSubpathBezier = reverse(fromSubpathBezier);
  11684. }
  11685. var offset = findBestRingOffset(fromSubpathBezier, toSubpathBezier, fromCp, toCp) * 6;
  11686. var len2 = len - 2;
  11687. for (var k = 0; k < len2; k += 2) {
  11688. var idx = (offset + k) % len2 + 2;
  11689. newFromSubpathBezier[k + 2] = fromSubpathBezier[idx] - fromCp[0];
  11690. newFromSubpathBezier[k + 3] = fromSubpathBezier[idx + 1] - fromCp[1];
  11691. }
  11692. newFromSubpathBezier[0] = fromSubpathBezier[offset] - fromCp[0];
  11693. newFromSubpathBezier[1] = fromSubpathBezier[offset + 1] - fromCp[1];
  11694. if (searchAngleIteration > 0) {
  11695. var step = searchAngleRange / searchAngleIteration;
  11696. for (var angle = -searchAngleRange / 2; angle <= searchAngleRange / 2; angle += step) {
  11697. var sa = Math.sin(angle);
  11698. var ca = Math.cos(angle);
  11699. var score = 0;
  11700. for (var k = 0; k < fromSubpathBezier.length; k += 2) {
  11701. var x0 = newFromSubpathBezier[k];
  11702. var y0 = newFromSubpathBezier[k + 1];
  11703. var x1 = toSubpathBezier[k] - toCp[0];
  11704. var y1 = toSubpathBezier[k + 1] - toCp[1];
  11705. var newX1 = x1 * ca - y1 * sa;
  11706. var newY1 = x1 * sa + y1 * ca;
  11707. tmpArr[k] = newX1;
  11708. tmpArr[k + 1] = newY1;
  11709. var dx = newX1 - x0;
  11710. var dy = newY1 - y0;
  11711. score += dx * dx + dy * dy;
  11712. }
  11713. if (score < bestScore) {
  11714. bestScore = score;
  11715. bestAngle = angle;
  11716. for (var m = 0; m < tmpArr.length; m++) {
  11717. newToSubpathBezier[m] = tmpArr[m];
  11718. }
  11719. }
  11720. }
  11721. }
  11722. else {
  11723. for (var i_1 = 0; i_1 < len; i_1 += 2) {
  11724. newToSubpathBezier[i_1] = toSubpathBezier[i_1] - toCp[0];
  11725. newToSubpathBezier[i_1 + 1] = toSubpathBezier[i_1 + 1] - toCp[1];
  11726. }
  11727. }
  11728. result.push({
  11729. from: newFromSubpathBezier,
  11730. to: newToSubpathBezier,
  11731. fromCp: fromCp,
  11732. toCp: toCp,
  11733. rotation: -bestAngle
  11734. });
  11735. }
  11736. return result;
  11737. }
  11738. function isCombineMorphing(path) {
  11739. return path.__isCombineMorphing;
  11740. }
  11741. function isMorphing(el) {
  11742. return el.__morphT >= 0;
  11743. }
  11744. var SAVED_METHOD_PREFIX = '__mOriginal_';
  11745. function saveAndModifyMethod(obj, methodName, modifiers) {
  11746. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  11747. var originalMethod = obj[savedMethodName] || obj[methodName];
  11748. if (!obj[savedMethodName]) {
  11749. obj[savedMethodName] = obj[methodName];
  11750. }
  11751. var replace = modifiers.replace;
  11752. var after = modifiers.after;
  11753. var before = modifiers.before;
  11754. obj[methodName] = function () {
  11755. var args = arguments;
  11756. var res;
  11757. before && before.apply(this, args);
  11758. if (replace) {
  11759. res = replace.apply(this, args);
  11760. }
  11761. else {
  11762. res = originalMethod.apply(this, args);
  11763. }
  11764. after && after.apply(this, args);
  11765. return res;
  11766. };
  11767. }
  11768. function restoreMethod(obj, methodName) {
  11769. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  11770. if (obj[savedMethodName]) {
  11771. obj[methodName] = obj[savedMethodName];
  11772. obj[savedMethodName] = null;
  11773. }
  11774. }
  11775. function applyTransformOnBeziers(bezierCurves, mm) {
  11776. for (var i = 0; i < bezierCurves.length; i++) {
  11777. var subBeziers = bezierCurves[i];
  11778. for (var k = 0; k < subBeziers.length;) {
  11779. var x = subBeziers[k];
  11780. var y = subBeziers[k + 1];
  11781. subBeziers[k++] = mm[0] * x + mm[2] * y + mm[4];
  11782. subBeziers[k++] = mm[1] * x + mm[3] * y + mm[5];
  11783. }
  11784. }
  11785. }
  11786. function prepareMorphPath(fromPath, toPath) {
  11787. var fromPathProxy = fromPath.getUpdatedPathProxy();
  11788. var toPathProxy = toPath.getUpdatedPathProxy();
  11789. var _a = alignBezierCurves(pathToBezierCurves(fromPathProxy), pathToBezierCurves(toPathProxy)), fromBezierCurves = _a[0], toBezierCurves = _a[1];
  11790. var fromPathTransform = fromPath.getComputedTransform();
  11791. var toPathTransform = toPath.getComputedTransform();
  11792. function updateIdentityTransform() {
  11793. this.transform = null;
  11794. }
  11795. fromPathTransform && applyTransformOnBeziers(fromBezierCurves, fromPathTransform);
  11796. toPathTransform && applyTransformOnBeziers(toBezierCurves, toPathTransform);
  11797. saveAndModifyMethod(toPath, 'updateTransform', { replace: updateIdentityTransform });
  11798. toPath.transform = null;
  11799. var morphingData = findBestMorphingRotation(fromBezierCurves, toBezierCurves, 10, Math.PI);
  11800. var tmpArr = [];
  11801. saveAndModifyMethod(toPath, 'buildPath', { replace: function (path) {
  11802. var t = toPath.__morphT;
  11803. var onet = 1 - t;
  11804. var newCp = [];
  11805. for (var i = 0; i < morphingData.length; i++) {
  11806. var item = morphingData[i];
  11807. var from = item.from;
  11808. var to = item.to;
  11809. var angle = item.rotation * t;
  11810. var fromCp = item.fromCp;
  11811. var toCp = item.toCp;
  11812. var sa = Math.sin(angle);
  11813. var ca = Math.cos(angle);
  11814. lerp(newCp, fromCp, toCp, t);
  11815. for (var m = 0; m < from.length; m += 2) {
  11816. var x0_1 = from[m];
  11817. var y0_1 = from[m + 1];
  11818. var x1 = to[m];
  11819. var y1 = to[m + 1];
  11820. var x = x0_1 * onet + x1 * t;
  11821. var y = y0_1 * onet + y1 * t;
  11822. tmpArr[m] = (x * ca - y * sa) + newCp[0];
  11823. tmpArr[m + 1] = (x * sa + y * ca) + newCp[1];
  11824. }
  11825. var x0 = tmpArr[0];
  11826. var y0 = tmpArr[1];
  11827. path.moveTo(x0, y0);
  11828. for (var m = 2; m < from.length;) {
  11829. var x1 = tmpArr[m++];
  11830. var y1 = tmpArr[m++];
  11831. var x2 = tmpArr[m++];
  11832. var y2 = tmpArr[m++];
  11833. var x3 = tmpArr[m++];
  11834. var y3 = tmpArr[m++];
  11835. if (x0 === x1 && y0 === y1 && x2 === x3 && y2 === y3) {
  11836. path.lineTo(x3, y3);
  11837. }
  11838. else {
  11839. path.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11840. }
  11841. x0 = x3;
  11842. y0 = y3;
  11843. }
  11844. }
  11845. } });
  11846. }
  11847. function morphPath(fromPath, toPath, animationOpts) {
  11848. if (!fromPath || !toPath) {
  11849. return toPath;
  11850. }
  11851. var oldDone = animationOpts.done;
  11852. var oldDuring = animationOpts.during;
  11853. prepareMorphPath(fromPath, toPath);
  11854. toPath.__morphT = 0;
  11855. function restoreToPath() {
  11856. restoreMethod(toPath, 'buildPath');
  11857. restoreMethod(toPath, 'updateTransform');
  11858. toPath.__morphT = -1;
  11859. toPath.createPathProxy();
  11860. toPath.dirtyShape();
  11861. }
  11862. toPath.animateTo({
  11863. __morphT: 1
  11864. }, defaults({
  11865. during: function (p) {
  11866. toPath.dirtyShape();
  11867. oldDuring && oldDuring(p);
  11868. },
  11869. done: function () {
  11870. restoreToPath();
  11871. oldDone && oldDone();
  11872. }
  11873. }, animationOpts));
  11874. return toPath;
  11875. }
  11876. function hilbert(x, y, minX, minY, maxX, maxY) {
  11877. var bits = 16;
  11878. x = (maxX === minX) ? 0 : Math.round(32767 * (x - minX) / (maxX - minX));
  11879. y = (maxY === minY) ? 0 : Math.round(32767 * (y - minY) / (maxY - minY));
  11880. var d = 0;
  11881. var tmp;
  11882. for (var s = (1 << bits) / 2; s > 0; s /= 2) {
  11883. var rx = 0;
  11884. var ry = 0;
  11885. if ((x & s) > 0) {
  11886. rx = 1;
  11887. }
  11888. if ((y & s) > 0) {
  11889. ry = 1;
  11890. }
  11891. d += s * s * ((3 * rx) ^ ry);
  11892. if (ry === 0) {
  11893. if (rx === 1) {
  11894. x = s - 1 - x;
  11895. y = s - 1 - y;
  11896. }
  11897. tmp = x;
  11898. x = y;
  11899. y = tmp;
  11900. }
  11901. }
  11902. return d;
  11903. }
  11904. function sortPaths(pathList) {
  11905. var xMin = Infinity;
  11906. var yMin = Infinity;
  11907. var xMax = -Infinity;
  11908. var yMax = -Infinity;
  11909. var cps = map(pathList, function (path) {
  11910. var rect = path.getBoundingRect();
  11911. var m = path.getComputedTransform();
  11912. var x = rect.x + rect.width / 2 + (m ? m[4] : 0);
  11913. var y = rect.y + rect.height / 2 + (m ? m[5] : 0);
  11914. xMin = Math.min(x, xMin);
  11915. yMin = Math.min(y, yMin);
  11916. xMax = Math.max(x, xMax);
  11917. yMax = Math.max(y, yMax);
  11918. return [x, y];
  11919. });
  11920. var items = map(cps, function (cp, idx) {
  11921. return {
  11922. cp: cp,
  11923. z: hilbert(cp[0], cp[1], xMin, yMin, xMax, yMax),
  11924. path: pathList[idx]
  11925. };
  11926. });
  11927. return items.sort(function (a, b) { return a.z - b.z; }).map(function (item) { return item.path; });
  11928. }
  11929. function defaultDividePath(param) {
  11930. return split(param.path, param.count);
  11931. }
  11932. function createEmptyReturn() {
  11933. return {
  11934. fromIndividuals: [],
  11935. toIndividuals: [],
  11936. count: 0
  11937. };
  11938. }
  11939. function combineMorph(fromList, toPath, animationOpts) {
  11940. var fromPathList = [];
  11941. function addFromPath(fromList) {
  11942. for (var i = 0; i < fromList.length; i++) {
  11943. var from = fromList[i];
  11944. if (isCombineMorphing(from)) {
  11945. addFromPath(from.childrenRef());
  11946. }
  11947. else if (from instanceof Path) {
  11948. fromPathList.push(from);
  11949. }
  11950. }
  11951. }
  11952. addFromPath(fromList);
  11953. var separateCount = fromPathList.length;
  11954. if (!separateCount) {
  11955. return createEmptyReturn();
  11956. }
  11957. var dividePath = animationOpts.dividePath || defaultDividePath;
  11958. var toSubPathList = dividePath({
  11959. path: toPath, count: separateCount
  11960. });
  11961. if (toSubPathList.length !== separateCount) {
  11962. console.error('Invalid morphing: unmatched splitted path');
  11963. return createEmptyReturn();
  11964. }
  11965. fromPathList = sortPaths(fromPathList);
  11966. toSubPathList = sortPaths(toSubPathList);
  11967. var oldDone = animationOpts.done;
  11968. var oldDuring = animationOpts.during;
  11969. var individualDelay = animationOpts.individualDelay;
  11970. var identityTransform = new Transformable();
  11971. for (var i = 0; i < separateCount; i++) {
  11972. var from = fromPathList[i];
  11973. var to = toSubPathList[i];
  11974. to.parent = toPath;
  11975. to.copyTransform(identityTransform);
  11976. if (!individualDelay) {
  11977. prepareMorphPath(from, to);
  11978. }
  11979. }
  11980. toPath.__isCombineMorphing = true;
  11981. toPath.childrenRef = function () {
  11982. return toSubPathList;
  11983. };
  11984. function addToSubPathListToZr(zr) {
  11985. for (var i = 0; i < toSubPathList.length; i++) {
  11986. toSubPathList[i].addSelfToZr(zr);
  11987. }
  11988. }
  11989. saveAndModifyMethod(toPath, 'addSelfToZr', {
  11990. after: function (zr) {
  11991. addToSubPathListToZr(zr);
  11992. }
  11993. });
  11994. saveAndModifyMethod(toPath, 'removeSelfFromZr', {
  11995. after: function (zr) {
  11996. for (var i = 0; i < toSubPathList.length; i++) {
  11997. toSubPathList[i].removeSelfFromZr(zr);
  11998. }
  11999. }
  12000. });
  12001. function restoreToPath() {
  12002. toPath.__isCombineMorphing = false;
  12003. toPath.__morphT = -1;
  12004. toPath.childrenRef = null;
  12005. restoreMethod(toPath, 'addSelfToZr');
  12006. restoreMethod(toPath, 'removeSelfFromZr');
  12007. }
  12008. var toLen = toSubPathList.length;
  12009. if (individualDelay) {
  12010. var animating_1 = toLen;
  12011. var eachDone = function () {
  12012. animating_1--;
  12013. if (animating_1 === 0) {
  12014. restoreToPath();
  12015. oldDone && oldDone();
  12016. }
  12017. };
  12018. for (var i = 0; i < toLen; i++) {
  12019. var indivdualAnimationOpts = individualDelay ? defaults({
  12020. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toSubPathList[i]),
  12021. done: eachDone
  12022. }, animationOpts) : animationOpts;
  12023. morphPath(fromPathList[i], toSubPathList[i], indivdualAnimationOpts);
  12024. }
  12025. }
  12026. else {
  12027. toPath.__morphT = 0;
  12028. toPath.animateTo({
  12029. __morphT: 1
  12030. }, defaults({
  12031. during: function (p) {
  12032. for (var i = 0; i < toLen; i++) {
  12033. var child = toSubPathList[i];
  12034. child.__morphT = toPath.__morphT;
  12035. child.dirtyShape();
  12036. }
  12037. oldDuring && oldDuring(p);
  12038. },
  12039. done: function () {
  12040. restoreToPath();
  12041. for (var i = 0; i < fromList.length; i++) {
  12042. restoreMethod(fromList[i], 'updateTransform');
  12043. }
  12044. oldDone && oldDone();
  12045. }
  12046. }, animationOpts));
  12047. }
  12048. if (toPath.__zr) {
  12049. addToSubPathListToZr(toPath.__zr);
  12050. }
  12051. return {
  12052. fromIndividuals: fromPathList,
  12053. toIndividuals: toSubPathList,
  12054. count: toLen
  12055. };
  12056. }
  12057. function separateMorph(fromPath, toPathList, animationOpts) {
  12058. var toLen = toPathList.length;
  12059. var fromPathList = [];
  12060. var dividePath = animationOpts.dividePath || defaultDividePath;
  12061. function addFromPath(fromList) {
  12062. for (var i = 0; i < fromList.length; i++) {
  12063. var from = fromList[i];
  12064. if (isCombineMorphing(from)) {
  12065. addFromPath(from.childrenRef());
  12066. }
  12067. else if (from instanceof Path) {
  12068. fromPathList.push(from);
  12069. }
  12070. }
  12071. }
  12072. if (isCombineMorphing(fromPath)) {
  12073. addFromPath(fromPath.childrenRef());
  12074. var fromLen = fromPathList.length;
  12075. if (fromLen < toLen) {
  12076. var k = 0;
  12077. for (var i = fromLen; i < toLen; i++) {
  12078. fromPathList.push(clonePath(fromPathList[k++ % fromLen]));
  12079. }
  12080. }
  12081. fromPathList.length = toLen;
  12082. }
  12083. else {
  12084. fromPathList = dividePath({ path: fromPath, count: toLen });
  12085. var fromPathTransform = fromPath.getComputedTransform();
  12086. for (var i = 0; i < fromPathList.length; i++) {
  12087. fromPathList[i].setLocalTransform(fromPathTransform);
  12088. }
  12089. if (fromPathList.length !== toLen) {
  12090. console.error('Invalid morphing: unmatched splitted path');
  12091. return createEmptyReturn();
  12092. }
  12093. }
  12094. fromPathList = sortPaths(fromPathList);
  12095. toPathList = sortPaths(toPathList);
  12096. var individualDelay = animationOpts.individualDelay;
  12097. for (var i = 0; i < toLen; i++) {
  12098. var indivdualAnimationOpts = individualDelay ? defaults({
  12099. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toPathList[i])
  12100. }, animationOpts) : animationOpts;
  12101. morphPath(fromPathList[i], toPathList[i], indivdualAnimationOpts);
  12102. }
  12103. return {
  12104. fromIndividuals: fromPathList,
  12105. toIndividuals: toPathList,
  12106. count: toPathList.length
  12107. };
  12108. }
  12109. var morphPath$1 = /*#__PURE__*/Object.freeze({
  12110. __proto__: null,
  12111. alignBezierCurves: alignBezierCurves,
  12112. centroid: centroid,
  12113. isCombineMorphing: isCombineMorphing,
  12114. isMorphing: isMorphing,
  12115. morphPath: morphPath,
  12116. combineMorph: combineMorph,
  12117. separateMorph: separateMorph,
  12118. defaultDividePath: split
  12119. });
  12120. var CompoundPath = (function (_super) {
  12121. __extends(CompoundPath, _super);
  12122. function CompoundPath() {
  12123. var _this = _super !== null && _super.apply(this, arguments) || this;
  12124. _this.type = 'compound';
  12125. return _this;
  12126. }
  12127. CompoundPath.prototype._updatePathDirty = function () {
  12128. var paths = this.shape.paths;
  12129. var dirtyPath = this.shapeChanged();
  12130. for (var i = 0; i < paths.length; i++) {
  12131. dirtyPath = dirtyPath || paths[i].shapeChanged();
  12132. }
  12133. if (dirtyPath) {
  12134. this.dirtyShape();
  12135. }
  12136. };
  12137. CompoundPath.prototype.beforeBrush = function () {
  12138. this._updatePathDirty();
  12139. var paths = this.shape.paths || [];
  12140. var scale = this.getGlobalScale();
  12141. for (var i = 0; i < paths.length; i++) {
  12142. if (!paths[i].path) {
  12143. paths[i].createPathProxy();
  12144. }
  12145. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  12146. }
  12147. };
  12148. CompoundPath.prototype.buildPath = function (ctx, shape) {
  12149. var paths = shape.paths || [];
  12150. for (var i = 0; i < paths.length; i++) {
  12151. paths[i].buildPath(ctx, paths[i].shape, true);
  12152. }
  12153. };
  12154. CompoundPath.prototype.afterBrush = function () {
  12155. var paths = this.shape.paths || [];
  12156. for (var i = 0; i < paths.length; i++) {
  12157. paths[i].pathUpdated();
  12158. }
  12159. };
  12160. CompoundPath.prototype.getBoundingRect = function () {
  12161. this._updatePathDirty.call(this);
  12162. return Path.prototype.getBoundingRect.call(this);
  12163. };
  12164. return CompoundPath;
  12165. }(Path));
  12166. var m = [];
  12167. var IncrementalDisplayable = (function (_super) {
  12168. __extends(IncrementalDisplayable, _super);
  12169. function IncrementalDisplayable() {
  12170. var _this = _super !== null && _super.apply(this, arguments) || this;
  12171. _this.notClear = true;
  12172. _this.incremental = true;
  12173. _this._displayables = [];
  12174. _this._temporaryDisplayables = [];
  12175. _this._cursor = 0;
  12176. return _this;
  12177. }
  12178. IncrementalDisplayable.prototype.traverse = function (cb, context) {
  12179. cb.call(context, this);
  12180. };
  12181. IncrementalDisplayable.prototype.useStyle = function () {
  12182. this.style = {};
  12183. };
  12184. IncrementalDisplayable.prototype.getCursor = function () {
  12185. return this._cursor;
  12186. };
  12187. IncrementalDisplayable.prototype.innerAfterBrush = function () {
  12188. this._cursor = this._displayables.length;
  12189. };
  12190. IncrementalDisplayable.prototype.clearDisplaybles = function () {
  12191. this._displayables = [];
  12192. this._temporaryDisplayables = [];
  12193. this._cursor = 0;
  12194. this.markRedraw();
  12195. this.notClear = false;
  12196. };
  12197. IncrementalDisplayable.prototype.clearTemporalDisplayables = function () {
  12198. this._temporaryDisplayables = [];
  12199. };
  12200. IncrementalDisplayable.prototype.addDisplayable = function (displayable, notPersistent) {
  12201. if (notPersistent) {
  12202. this._temporaryDisplayables.push(displayable);
  12203. }
  12204. else {
  12205. this._displayables.push(displayable);
  12206. }
  12207. this.markRedraw();
  12208. };
  12209. IncrementalDisplayable.prototype.addDisplayables = function (displayables, notPersistent) {
  12210. notPersistent = notPersistent || false;
  12211. for (var i = 0; i < displayables.length; i++) {
  12212. this.addDisplayable(displayables[i], notPersistent);
  12213. }
  12214. };
  12215. IncrementalDisplayable.prototype.getDisplayables = function () {
  12216. return this._displayables;
  12217. };
  12218. IncrementalDisplayable.prototype.getTemporalDisplayables = function () {
  12219. return this._temporaryDisplayables;
  12220. };
  12221. IncrementalDisplayable.prototype.eachPendingDisplayable = function (cb) {
  12222. for (var i = this._cursor; i < this._displayables.length; i++) {
  12223. cb && cb(this._displayables[i]);
  12224. }
  12225. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  12226. cb && cb(this._temporaryDisplayables[i]);
  12227. }
  12228. };
  12229. IncrementalDisplayable.prototype.update = function () {
  12230. this.updateTransform();
  12231. for (var i = this._cursor; i < this._displayables.length; i++) {
  12232. var displayable = this._displayables[i];
  12233. displayable.parent = this;
  12234. displayable.update();
  12235. displayable.parent = null;
  12236. }
  12237. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  12238. var displayable = this._temporaryDisplayables[i];
  12239. displayable.parent = this;
  12240. displayable.update();
  12241. displayable.parent = null;
  12242. }
  12243. };
  12244. IncrementalDisplayable.prototype.getBoundingRect = function () {
  12245. if (!this._rect) {
  12246. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  12247. for (var i = 0; i < this._displayables.length; i++) {
  12248. var displayable = this._displayables[i];
  12249. var childRect = displayable.getBoundingRect().clone();
  12250. if (displayable.needLocalTransform()) {
  12251. childRect.applyTransform(displayable.getLocalTransform(m));
  12252. }
  12253. rect.union(childRect);
  12254. }
  12255. this._rect = rect;
  12256. }
  12257. return this._rect;
  12258. };
  12259. IncrementalDisplayable.prototype.contain = function (x, y) {
  12260. var localPos = this.transformCoordToLocal(x, y);
  12261. var rect = this.getBoundingRect();
  12262. if (rect.contain(localPos[0], localPos[1])) {
  12263. for (var i = 0; i < this._displayables.length; i++) {
  12264. var displayable = this._displayables[i];
  12265. if (displayable.contain(x, y)) {
  12266. return true;
  12267. }
  12268. }
  12269. }
  12270. return false;
  12271. };
  12272. return IncrementalDisplayable;
  12273. }(Displayable));
  12274. var globalImageCache = new LRU(50);
  12275. function findExistImage(newImageOrSrc) {
  12276. if (typeof newImageOrSrc === 'string') {
  12277. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  12278. return cachedImgObj && cachedImgObj.image;
  12279. }
  12280. else {
  12281. return newImageOrSrc;
  12282. }
  12283. }
  12284. function createOrUpdateImage(newImageOrSrc, image, hostEl, onload, cbPayload) {
  12285. if (!newImageOrSrc) {
  12286. return image;
  12287. }
  12288. else if (typeof newImageOrSrc === 'string') {
  12289. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  12290. return image;
  12291. }
  12292. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  12293. var pendingWrap = { hostEl: hostEl, cb: onload, cbPayload: cbPayload };
  12294. if (cachedImgObj) {
  12295. image = cachedImgObj.image;
  12296. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  12297. }
  12298. else {
  12299. image = platformApi.loadImage(newImageOrSrc, imageOnLoad, imageOnLoad);
  12300. image.__zrImageSrc = newImageOrSrc;
  12301. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  12302. image: image,
  12303. pending: [pendingWrap]
  12304. });
  12305. }
  12306. return image;
  12307. }
  12308. else {
  12309. return newImageOrSrc;
  12310. }
  12311. }
  12312. function imageOnLoad() {
  12313. var cachedImgObj = this.__cachedImgObj;
  12314. this.onload = this.onerror = this.__cachedImgObj = null;
  12315. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  12316. var pendingWrap = cachedImgObj.pending[i];
  12317. var cb = pendingWrap.cb;
  12318. cb && cb(this, pendingWrap.cbPayload);
  12319. pendingWrap.hostEl.dirty();
  12320. }
  12321. cachedImgObj.pending.length = 0;
  12322. }
  12323. function isImageReady(image) {
  12324. return image && image.width && image.height;
  12325. }
  12326. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  12327. function truncateText(text, containerWidth, font, ellipsis, options) {
  12328. if (!containerWidth) {
  12329. return '';
  12330. }
  12331. var textLines = (text + '').split('\n');
  12332. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  12333. for (var i = 0, len = textLines.length; i < len; i++) {
  12334. textLines[i] = truncateSingleLine(textLines[i], options);
  12335. }
  12336. return textLines.join('\n');
  12337. }
  12338. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  12339. options = options || {};
  12340. var preparedOpts = extend({}, options);
  12341. preparedOpts.font = font;
  12342. ellipsis = retrieve2(ellipsis, '...');
  12343. preparedOpts.maxIterations = retrieve2(options.maxIterations, 2);
  12344. var minChar = preparedOpts.minChar = retrieve2(options.minChar, 0);
  12345. preparedOpts.cnCharWidth = getWidth('国', font);
  12346. var ascCharWidth = preparedOpts.ascCharWidth = getWidth('a', font);
  12347. preparedOpts.placeholder = retrieve2(options.placeholder, '');
  12348. var contentWidth = containerWidth = Math.max(0, containerWidth - 1);
  12349. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  12350. contentWidth -= ascCharWidth;
  12351. }
  12352. var ellipsisWidth = getWidth(ellipsis, font);
  12353. if (ellipsisWidth > contentWidth) {
  12354. ellipsis = '';
  12355. ellipsisWidth = 0;
  12356. }
  12357. contentWidth = containerWidth - ellipsisWidth;
  12358. preparedOpts.ellipsis = ellipsis;
  12359. preparedOpts.ellipsisWidth = ellipsisWidth;
  12360. preparedOpts.contentWidth = contentWidth;
  12361. preparedOpts.containerWidth = containerWidth;
  12362. return preparedOpts;
  12363. }
  12364. function truncateSingleLine(textLine, options) {
  12365. var containerWidth = options.containerWidth;
  12366. var font = options.font;
  12367. var contentWidth = options.contentWidth;
  12368. if (!containerWidth) {
  12369. return '';
  12370. }
  12371. var lineWidth = getWidth(textLine, font);
  12372. if (lineWidth <= containerWidth) {
  12373. return textLine;
  12374. }
  12375. for (var j = 0;; j++) {
  12376. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  12377. textLine += options.ellipsis;
  12378. break;
  12379. }
  12380. var subLength = j === 0
  12381. ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
  12382. : lineWidth > 0
  12383. ? Math.floor(textLine.length * contentWidth / lineWidth)
  12384. : 0;
  12385. textLine = textLine.substr(0, subLength);
  12386. lineWidth = getWidth(textLine, font);
  12387. }
  12388. if (textLine === '') {
  12389. textLine = options.placeholder;
  12390. }
  12391. return textLine;
  12392. }
  12393. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  12394. var width = 0;
  12395. var i = 0;
  12396. for (var len = text.length; i < len && width < contentWidth; i++) {
  12397. var charCode = text.charCodeAt(i);
  12398. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  12399. }
  12400. return i;
  12401. }
  12402. function parsePlainText(text, style) {
  12403. text != null && (text += '');
  12404. var overflow = style.overflow;
  12405. var padding = style.padding;
  12406. var font = style.font;
  12407. var truncate = overflow === 'truncate';
  12408. var calculatedLineHeight = getLineHeight(font);
  12409. var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
  12410. var bgColorDrawn = !!(style.backgroundColor);
  12411. var truncateLineOverflow = style.lineOverflow === 'truncate';
  12412. var width = style.width;
  12413. var lines;
  12414. if (width != null && (overflow === 'break' || overflow === 'breakAll')) {
  12415. lines = text ? wrapText(text, style.font, width, overflow === 'breakAll', 0).lines : [];
  12416. }
  12417. else {
  12418. lines = text ? text.split('\n') : [];
  12419. }
  12420. var contentHeight = lines.length * lineHeight;
  12421. var height = retrieve2(style.height, contentHeight);
  12422. if (contentHeight > height && truncateLineOverflow) {
  12423. var lineCount = Math.floor(height / lineHeight);
  12424. lines = lines.slice(0, lineCount);
  12425. }
  12426. if (text && truncate && width != null) {
  12427. var options = prepareTruncateOptions(width, font, style.ellipsis, {
  12428. minChar: style.truncateMinChar,
  12429. placeholder: style.placeholder
  12430. });
  12431. for (var i = 0; i < lines.length; i++) {
  12432. lines[i] = truncateSingleLine(lines[i], options);
  12433. }
  12434. }
  12435. var outerHeight = height;
  12436. var contentWidth = 0;
  12437. for (var i = 0; i < lines.length; i++) {
  12438. contentWidth = Math.max(getWidth(lines[i], font), contentWidth);
  12439. }
  12440. if (width == null) {
  12441. width = contentWidth;
  12442. }
  12443. var outerWidth = contentWidth;
  12444. if (padding) {
  12445. outerHeight += padding[0] + padding[2];
  12446. outerWidth += padding[1] + padding[3];
  12447. width += padding[1] + padding[3];
  12448. }
  12449. if (bgColorDrawn) {
  12450. outerWidth = width;
  12451. }
  12452. return {
  12453. lines: lines,
  12454. height: height,
  12455. outerWidth: outerWidth,
  12456. outerHeight: outerHeight,
  12457. lineHeight: lineHeight,
  12458. calculatedLineHeight: calculatedLineHeight,
  12459. contentWidth: contentWidth,
  12460. contentHeight: contentHeight,
  12461. width: width
  12462. };
  12463. }
  12464. var RichTextToken = (function () {
  12465. function RichTextToken() {
  12466. }
  12467. return RichTextToken;
  12468. }());
  12469. var RichTextLine = (function () {
  12470. function RichTextLine(tokens) {
  12471. this.tokens = [];
  12472. if (tokens) {
  12473. this.tokens = tokens;
  12474. }
  12475. }
  12476. return RichTextLine;
  12477. }());
  12478. var RichTextContentBlock = (function () {
  12479. function RichTextContentBlock() {
  12480. this.width = 0;
  12481. this.height = 0;
  12482. this.contentWidth = 0;
  12483. this.contentHeight = 0;
  12484. this.outerWidth = 0;
  12485. this.outerHeight = 0;
  12486. this.lines = [];
  12487. }
  12488. return RichTextContentBlock;
  12489. }());
  12490. function parseRichText(text, style) {
  12491. var contentBlock = new RichTextContentBlock();
  12492. text != null && (text += '');
  12493. if (!text) {
  12494. return contentBlock;
  12495. }
  12496. var topWidth = style.width;
  12497. var topHeight = style.height;
  12498. var overflow = style.overflow;
  12499. var wrapInfo = (overflow === 'break' || overflow === 'breakAll') && topWidth != null
  12500. ? { width: topWidth, accumWidth: 0, breakAll: overflow === 'breakAll' }
  12501. : null;
  12502. var lastIndex = STYLE_REG.lastIndex = 0;
  12503. var result;
  12504. while ((result = STYLE_REG.exec(text)) != null) {
  12505. var matchedIndex = result.index;
  12506. if (matchedIndex > lastIndex) {
  12507. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex), style, wrapInfo);
  12508. }
  12509. pushTokens(contentBlock, result[2], style, wrapInfo, result[1]);
  12510. lastIndex = STYLE_REG.lastIndex;
  12511. }
  12512. if (lastIndex < text.length) {
  12513. pushTokens(contentBlock, text.substring(lastIndex, text.length), style, wrapInfo);
  12514. }
  12515. var pendingList = [];
  12516. var calculatedHeight = 0;
  12517. var calculatedWidth = 0;
  12518. var stlPadding = style.padding;
  12519. var truncate = overflow === 'truncate';
  12520. var truncateLine = style.lineOverflow === 'truncate';
  12521. function finishLine(line, lineWidth, lineHeight) {
  12522. line.width = lineWidth;
  12523. line.lineHeight = lineHeight;
  12524. calculatedHeight += lineHeight;
  12525. calculatedWidth = Math.max(calculatedWidth, lineWidth);
  12526. }
  12527. outer: for (var i = 0; i < contentBlock.lines.length; i++) {
  12528. var line = contentBlock.lines[i];
  12529. var lineHeight = 0;
  12530. var lineWidth = 0;
  12531. for (var j = 0; j < line.tokens.length; j++) {
  12532. var token = line.tokens[j];
  12533. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  12534. var textPadding = token.textPadding = tokenStyle.padding;
  12535. var paddingH = textPadding ? textPadding[1] + textPadding[3] : 0;
  12536. var font = token.font = tokenStyle.font || style.font;
  12537. token.contentHeight = getLineHeight(font);
  12538. var tokenHeight = retrieve2(tokenStyle.height, token.contentHeight);
  12539. token.innerHeight = tokenHeight;
  12540. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  12541. token.height = tokenHeight;
  12542. token.lineHeight = retrieve3(tokenStyle.lineHeight, style.lineHeight, tokenHeight);
  12543. token.align = tokenStyle && tokenStyle.align || style.align;
  12544. token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
  12545. if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
  12546. if (j > 0) {
  12547. line.tokens = line.tokens.slice(0, j);
  12548. finishLine(line, lineWidth, lineHeight);
  12549. contentBlock.lines = contentBlock.lines.slice(0, i + 1);
  12550. }
  12551. else {
  12552. contentBlock.lines = contentBlock.lines.slice(0, i);
  12553. }
  12554. break outer;
  12555. }
  12556. var styleTokenWidth = tokenStyle.width;
  12557. var tokenWidthNotSpecified = styleTokenWidth == null || styleTokenWidth === 'auto';
  12558. if (typeof styleTokenWidth === 'string' && styleTokenWidth.charAt(styleTokenWidth.length - 1) === '%') {
  12559. token.percentWidth = styleTokenWidth;
  12560. pendingList.push(token);
  12561. token.contentWidth = getWidth(token.text, font);
  12562. }
  12563. else {
  12564. if (tokenWidthNotSpecified) {
  12565. var textBackgroundColor = tokenStyle.backgroundColor;
  12566. var bgImg = textBackgroundColor && textBackgroundColor.image;
  12567. if (bgImg) {
  12568. bgImg = findExistImage(bgImg);
  12569. if (isImageReady(bgImg)) {
  12570. token.width = Math.max(token.width, bgImg.width * tokenHeight / bgImg.height);
  12571. }
  12572. }
  12573. }
  12574. var remainTruncWidth = truncate && topWidth != null
  12575. ? topWidth - lineWidth : null;
  12576. if (remainTruncWidth != null && remainTruncWidth < token.width) {
  12577. if (!tokenWidthNotSpecified || remainTruncWidth < paddingH) {
  12578. token.text = '';
  12579. token.width = token.contentWidth = 0;
  12580. }
  12581. else {
  12582. token.text = truncateText(token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
  12583. token.width = token.contentWidth = getWidth(token.text, font);
  12584. }
  12585. }
  12586. else {
  12587. token.contentWidth = getWidth(token.text, font);
  12588. }
  12589. }
  12590. token.width += paddingH;
  12591. lineWidth += token.width;
  12592. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  12593. }
  12594. finishLine(line, lineWidth, lineHeight);
  12595. }
  12596. contentBlock.outerWidth = contentBlock.width = retrieve2(topWidth, calculatedWidth);
  12597. contentBlock.outerHeight = contentBlock.height = retrieve2(topHeight, calculatedHeight);
  12598. contentBlock.contentHeight = calculatedHeight;
  12599. contentBlock.contentWidth = calculatedWidth;
  12600. if (stlPadding) {
  12601. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  12602. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  12603. }
  12604. for (var i = 0; i < pendingList.length; i++) {
  12605. var token = pendingList[i];
  12606. var percentWidth = token.percentWidth;
  12607. token.width = parseInt(percentWidth, 10) / 100 * contentBlock.width;
  12608. }
  12609. return contentBlock;
  12610. }
  12611. function pushTokens(block, str, style, wrapInfo, styleName) {
  12612. var isEmptyStr = str === '';
  12613. var tokenStyle = styleName && style.rich[styleName] || {};
  12614. var lines = block.lines;
  12615. var font = tokenStyle.font || style.font;
  12616. var newLine = false;
  12617. var strLines;
  12618. var linesWidths;
  12619. if (wrapInfo) {
  12620. var tokenPadding = tokenStyle.padding;
  12621. var tokenPaddingH = tokenPadding ? tokenPadding[1] + tokenPadding[3] : 0;
  12622. if (tokenStyle.width != null && tokenStyle.width !== 'auto') {
  12623. var outerWidth_1 = parsePercent(tokenStyle.width, wrapInfo.width) + tokenPaddingH;
  12624. if (lines.length > 0) {
  12625. if (outerWidth_1 + wrapInfo.accumWidth > wrapInfo.width) {
  12626. strLines = str.split('\n');
  12627. newLine = true;
  12628. }
  12629. }
  12630. wrapInfo.accumWidth = outerWidth_1;
  12631. }
  12632. else {
  12633. var res = wrapText(str, font, wrapInfo.width, wrapInfo.breakAll, wrapInfo.accumWidth);
  12634. wrapInfo.accumWidth = res.accumWidth + tokenPaddingH;
  12635. linesWidths = res.linesWidths;
  12636. strLines = res.lines;
  12637. }
  12638. }
  12639. else {
  12640. strLines = str.split('\n');
  12641. }
  12642. for (var i = 0; i < strLines.length; i++) {
  12643. var text = strLines[i];
  12644. var token = new RichTextToken();
  12645. token.styleName = styleName;
  12646. token.text = text;
  12647. token.isLineHolder = !text && !isEmptyStr;
  12648. if (typeof tokenStyle.width === 'number') {
  12649. token.width = tokenStyle.width;
  12650. }
  12651. else {
  12652. token.width = linesWidths
  12653. ? linesWidths[i]
  12654. : getWidth(text, font);
  12655. }
  12656. if (!i && !newLine) {
  12657. var tokens = (lines[lines.length - 1] || (lines[0] = new RichTextLine())).tokens;
  12658. var tokensLen = tokens.length;
  12659. (tokensLen === 1 && tokens[0].isLineHolder)
  12660. ? (tokens[0] = token)
  12661. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  12662. }
  12663. else {
  12664. lines.push(new RichTextLine([token]));
  12665. }
  12666. }
  12667. }
  12668. function isLatin(ch) {
  12669. var code = ch.charCodeAt(0);
  12670. return code >= 0x21 && code <= 0x17F;
  12671. }
  12672. var breakCharMap = reduce(',&?/;] '.split(''), function (obj, ch) {
  12673. obj[ch] = true;
  12674. return obj;
  12675. }, {});
  12676. function isWordBreakChar(ch) {
  12677. if (isLatin(ch)) {
  12678. if (breakCharMap[ch]) {
  12679. return true;
  12680. }
  12681. return false;
  12682. }
  12683. return true;
  12684. }
  12685. function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
  12686. var lines = [];
  12687. var linesWidths = [];
  12688. var line = '';
  12689. var currentWord = '';
  12690. var currentWordWidth = 0;
  12691. var accumWidth = 0;
  12692. for (var i = 0; i < text.length; i++) {
  12693. var ch = text.charAt(i);
  12694. if (ch === '\n') {
  12695. if (currentWord) {
  12696. line += currentWord;
  12697. accumWidth += currentWordWidth;
  12698. }
  12699. lines.push(line);
  12700. linesWidths.push(accumWidth);
  12701. line = '';
  12702. currentWord = '';
  12703. currentWordWidth = 0;
  12704. accumWidth = 0;
  12705. continue;
  12706. }
  12707. var chWidth = getWidth(ch, font);
  12708. var inWord = isBreakAll ? false : !isWordBreakChar(ch);
  12709. if (!lines.length
  12710. ? lastAccumWidth + accumWidth + chWidth > lineWidth
  12711. : accumWidth + chWidth > lineWidth) {
  12712. if (!accumWidth) {
  12713. if (inWord) {
  12714. lines.push(currentWord);
  12715. linesWidths.push(currentWordWidth);
  12716. currentWord = ch;
  12717. currentWordWidth = chWidth;
  12718. }
  12719. else {
  12720. lines.push(ch);
  12721. linesWidths.push(chWidth);
  12722. }
  12723. }
  12724. else if (line || currentWord) {
  12725. if (inWord) {
  12726. if (!line) {
  12727. line = currentWord;
  12728. currentWord = '';
  12729. currentWordWidth = 0;
  12730. accumWidth = currentWordWidth;
  12731. }
  12732. lines.push(line);
  12733. linesWidths.push(accumWidth - currentWordWidth);
  12734. currentWord += ch;
  12735. currentWordWidth += chWidth;
  12736. line = '';
  12737. accumWidth = currentWordWidth;
  12738. }
  12739. else {
  12740. if (currentWord) {
  12741. line += currentWord;
  12742. currentWord = '';
  12743. currentWordWidth = 0;
  12744. }
  12745. lines.push(line);
  12746. linesWidths.push(accumWidth);
  12747. line = ch;
  12748. accumWidth = chWidth;
  12749. }
  12750. }
  12751. continue;
  12752. }
  12753. accumWidth += chWidth;
  12754. if (inWord) {
  12755. currentWord += ch;
  12756. currentWordWidth += chWidth;
  12757. }
  12758. else {
  12759. if (currentWord) {
  12760. line += currentWord;
  12761. currentWord = '';
  12762. currentWordWidth = 0;
  12763. }
  12764. line += ch;
  12765. }
  12766. }
  12767. if (!lines.length && !line) {
  12768. line = text;
  12769. currentWord = '';
  12770. currentWordWidth = 0;
  12771. }
  12772. if (currentWord) {
  12773. line += currentWord;
  12774. }
  12775. if (line) {
  12776. lines.push(line);
  12777. linesWidths.push(accumWidth);
  12778. }
  12779. if (lines.length === 1) {
  12780. accumWidth += lastAccumWidth;
  12781. }
  12782. return {
  12783. accumWidth: accumWidth,
  12784. lines: lines,
  12785. linesWidths: linesWidths
  12786. };
  12787. }
  12788. var DEFAULT_RICH_TEXT_COLOR = {
  12789. fill: '#000'
  12790. };
  12791. var DEFAULT_STROKE_LINE_WIDTH = 2;
  12792. var DEFAULT_TEXT_ANIMATION_PROPS = {
  12793. style: defaults({
  12794. fill: true,
  12795. stroke: true,
  12796. fillOpacity: true,
  12797. strokeOpacity: true,
  12798. lineWidth: true,
  12799. fontSize: true,
  12800. lineHeight: true,
  12801. width: true,
  12802. height: true,
  12803. textShadowColor: true,
  12804. textShadowBlur: true,
  12805. textShadowOffsetX: true,
  12806. textShadowOffsetY: true,
  12807. backgroundColor: true,
  12808. padding: true,
  12809. borderColor: true,
  12810. borderWidth: true,
  12811. borderRadius: true
  12812. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  12813. };
  12814. var ZRText = (function (_super) {
  12815. __extends(ZRText, _super);
  12816. function ZRText(opts) {
  12817. var _this = _super.call(this) || this;
  12818. _this.type = 'text';
  12819. _this._children = [];
  12820. _this._defaultStyle = DEFAULT_RICH_TEXT_COLOR;
  12821. _this.attr(opts);
  12822. return _this;
  12823. }
  12824. ZRText.prototype.childrenRef = function () {
  12825. return this._children;
  12826. };
  12827. ZRText.prototype.update = function () {
  12828. _super.prototype.update.call(this);
  12829. if (this.styleChanged()) {
  12830. this._updateSubTexts();
  12831. }
  12832. for (var i = 0; i < this._children.length; i++) {
  12833. var child = this._children[i];
  12834. child.zlevel = this.zlevel;
  12835. child.z = this.z;
  12836. child.z2 = this.z2;
  12837. child.culling = this.culling;
  12838. child.cursor = this.cursor;
  12839. child.invisible = this.invisible;
  12840. }
  12841. };
  12842. ZRText.prototype.updateTransform = function () {
  12843. var innerTransformable = this.innerTransformable;
  12844. if (innerTransformable) {
  12845. innerTransformable.updateTransform();
  12846. if (innerTransformable.transform) {
  12847. this.transform = innerTransformable.transform;
  12848. }
  12849. }
  12850. else {
  12851. _super.prototype.updateTransform.call(this);
  12852. }
  12853. };
  12854. ZRText.prototype.getLocalTransform = function (m) {
  12855. var innerTransformable = this.innerTransformable;
  12856. return innerTransformable
  12857. ? innerTransformable.getLocalTransform(m)
  12858. : _super.prototype.getLocalTransform.call(this, m);
  12859. };
  12860. ZRText.prototype.getComputedTransform = function () {
  12861. if (this.__hostTarget) {
  12862. this.__hostTarget.getComputedTransform();
  12863. this.__hostTarget.updateInnerText(true);
  12864. }
  12865. return _super.prototype.getComputedTransform.call(this);
  12866. };
  12867. ZRText.prototype._updateSubTexts = function () {
  12868. this._childCursor = 0;
  12869. normalizeTextStyle(this.style);
  12870. this.style.rich
  12871. ? this._updateRichTexts()
  12872. : this._updatePlainTexts();
  12873. this._children.length = this._childCursor;
  12874. this.styleUpdated();
  12875. };
  12876. ZRText.prototype.addSelfToZr = function (zr) {
  12877. _super.prototype.addSelfToZr.call(this, zr);
  12878. for (var i = 0; i < this._children.length; i++) {
  12879. this._children[i].__zr = zr;
  12880. }
  12881. };
  12882. ZRText.prototype.removeSelfFromZr = function (zr) {
  12883. _super.prototype.removeSelfFromZr.call(this, zr);
  12884. for (var i = 0; i < this._children.length; i++) {
  12885. this._children[i].__zr = null;
  12886. }
  12887. };
  12888. ZRText.prototype.getBoundingRect = function () {
  12889. if (this.styleChanged()) {
  12890. this._updateSubTexts();
  12891. }
  12892. if (!this._rect) {
  12893. var tmpRect = new BoundingRect(0, 0, 0, 0);
  12894. var children = this._children;
  12895. var tmpMat = [];
  12896. var rect = null;
  12897. for (var i = 0; i < children.length; i++) {
  12898. var child = children[i];
  12899. var childRect = child.getBoundingRect();
  12900. var transform = child.getLocalTransform(tmpMat);
  12901. if (transform) {
  12902. tmpRect.copy(childRect);
  12903. tmpRect.applyTransform(transform);
  12904. rect = rect || tmpRect.clone();
  12905. rect.union(tmpRect);
  12906. }
  12907. else {
  12908. rect = rect || childRect.clone();
  12909. rect.union(childRect);
  12910. }
  12911. }
  12912. this._rect = rect || tmpRect;
  12913. }
  12914. return this._rect;
  12915. };
  12916. ZRText.prototype.setDefaultTextStyle = function (defaultTextStyle) {
  12917. this._defaultStyle = defaultTextStyle || DEFAULT_RICH_TEXT_COLOR;
  12918. };
  12919. ZRText.prototype.setTextContent = function (textContent) {
  12920. {
  12921. throw new Error('Can\'t attach text on another text');
  12922. }
  12923. };
  12924. ZRText.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  12925. if (!sourceStyle) {
  12926. return targetStyle;
  12927. }
  12928. var sourceRich = sourceStyle.rich;
  12929. var targetRich = targetStyle.rich || (sourceRich && {});
  12930. extend(targetStyle, sourceStyle);
  12931. if (sourceRich && targetRich) {
  12932. this._mergeRich(targetRich, sourceRich);
  12933. targetStyle.rich = targetRich;
  12934. }
  12935. else if (targetRich) {
  12936. targetStyle.rich = targetRich;
  12937. }
  12938. return targetStyle;
  12939. };
  12940. ZRText.prototype._mergeRich = function (targetRich, sourceRich) {
  12941. var richNames = keys(sourceRich);
  12942. for (var i = 0; i < richNames.length; i++) {
  12943. var richName = richNames[i];
  12944. targetRich[richName] = targetRich[richName] || {};
  12945. extend(targetRich[richName], sourceRich[richName]);
  12946. }
  12947. };
  12948. ZRText.prototype.getAnimationStyleProps = function () {
  12949. return DEFAULT_TEXT_ANIMATION_PROPS;
  12950. };
  12951. ZRText.prototype._getOrCreateChild = function (Ctor) {
  12952. var child = this._children[this._childCursor];
  12953. if (!child || !(child instanceof Ctor)) {
  12954. child = new Ctor();
  12955. }
  12956. this._children[this._childCursor++] = child;
  12957. child.__zr = this.__zr;
  12958. child.parent = this;
  12959. return child;
  12960. };
  12961. ZRText.prototype._updatePlainTexts = function () {
  12962. var style = this.style;
  12963. var textFont = style.font || DEFAULT_FONT;
  12964. var textPadding = style.padding;
  12965. var text = getStyleText(style);
  12966. var contentBlock = parsePlainText(text, style);
  12967. var needDrawBg = needDrawBackground(style);
  12968. var bgColorDrawn = !!(style.backgroundColor);
  12969. var outerHeight = contentBlock.outerHeight;
  12970. var outerWidth = contentBlock.outerWidth;
  12971. var contentWidth = contentBlock.contentWidth;
  12972. var textLines = contentBlock.lines;
  12973. var lineHeight = contentBlock.lineHeight;
  12974. var defaultStyle = this._defaultStyle;
  12975. var baseX = style.x || 0;
  12976. var baseY = style.y || 0;
  12977. var textAlign = style.align || defaultStyle.align || 'left';
  12978. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
  12979. var textX = baseX;
  12980. var textY = adjustTextY$1(baseY, contentBlock.contentHeight, verticalAlign);
  12981. if (needDrawBg || textPadding) {
  12982. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  12983. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  12984. needDrawBg && this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  12985. }
  12986. textY += lineHeight / 2;
  12987. if (textPadding) {
  12988. textX = getTextXForPadding(baseX, textAlign, textPadding);
  12989. if (verticalAlign === 'top') {
  12990. textY += textPadding[0];
  12991. }
  12992. else if (verticalAlign === 'bottom') {
  12993. textY -= textPadding[2];
  12994. }
  12995. }
  12996. var defaultLineWidth = 0;
  12997. var useDefaultFill = false;
  12998. var textFill = getFill('fill' in style
  12999. ? style.fill
  13000. : (useDefaultFill = true, defaultStyle.fill));
  13001. var textStroke = getStroke('stroke' in style
  13002. ? style.stroke
  13003. : (!bgColorDrawn
  13004. && (!defaultStyle.autoStroke || useDefaultFill))
  13005. ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  13006. : null);
  13007. var hasShadow = style.textShadowBlur > 0;
  13008. var fixedBoundingRect = style.width != null
  13009. && (style.overflow === 'truncate' || style.overflow === 'break' || style.overflow === 'breakAll');
  13010. var calculatedLineHeight = contentBlock.calculatedLineHeight;
  13011. for (var i = 0; i < textLines.length; i++) {
  13012. var el = this._getOrCreateChild(TSpan);
  13013. var subElStyle = el.createStyle();
  13014. el.useStyle(subElStyle);
  13015. subElStyle.text = textLines[i];
  13016. subElStyle.x = textX;
  13017. subElStyle.y = textY;
  13018. if (textAlign) {
  13019. subElStyle.textAlign = textAlign;
  13020. }
  13021. subElStyle.textBaseline = 'middle';
  13022. subElStyle.opacity = style.opacity;
  13023. subElStyle.strokeFirst = true;
  13024. if (hasShadow) {
  13025. subElStyle.shadowBlur = style.textShadowBlur || 0;
  13026. subElStyle.shadowColor = style.textShadowColor || 'transparent';
  13027. subElStyle.shadowOffsetX = style.textShadowOffsetX || 0;
  13028. subElStyle.shadowOffsetY = style.textShadowOffsetY || 0;
  13029. }
  13030. subElStyle.stroke = textStroke;
  13031. subElStyle.fill = textFill;
  13032. if (textStroke) {
  13033. subElStyle.lineWidth = style.lineWidth || defaultLineWidth;
  13034. subElStyle.lineDash = style.lineDash;
  13035. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13036. }
  13037. subElStyle.font = textFont;
  13038. setSeparateFont(subElStyle, style);
  13039. textY += lineHeight;
  13040. if (fixedBoundingRect) {
  13041. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, style.width, subElStyle.textAlign), adjustTextY$1(subElStyle.y, calculatedLineHeight, subElStyle.textBaseline), contentWidth, calculatedLineHeight));
  13042. }
  13043. }
  13044. };
  13045. ZRText.prototype._updateRichTexts = function () {
  13046. var style = this.style;
  13047. var text = getStyleText(style);
  13048. var contentBlock = parseRichText(text, style);
  13049. var contentWidth = contentBlock.width;
  13050. var outerWidth = contentBlock.outerWidth;
  13051. var outerHeight = contentBlock.outerHeight;
  13052. var textPadding = style.padding;
  13053. var baseX = style.x || 0;
  13054. var baseY = style.y || 0;
  13055. var defaultStyle = this._defaultStyle;
  13056. var textAlign = style.align || defaultStyle.align;
  13057. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
  13058. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  13059. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  13060. var xLeft = boxX;
  13061. var lineTop = boxY;
  13062. if (textPadding) {
  13063. xLeft += textPadding[3];
  13064. lineTop += textPadding[0];
  13065. }
  13066. var xRight = xLeft + contentWidth;
  13067. if (needDrawBackground(style)) {
  13068. this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  13069. }
  13070. var bgColorDrawn = !!(style.backgroundColor);
  13071. for (var i = 0; i < contentBlock.lines.length; i++) {
  13072. var line = contentBlock.lines[i];
  13073. var tokens = line.tokens;
  13074. var tokenCount = tokens.length;
  13075. var lineHeight = line.lineHeight;
  13076. var remainedWidth = line.width;
  13077. var leftIndex = 0;
  13078. var lineXLeft = xLeft;
  13079. var lineXRight = xRight;
  13080. var rightIndex = tokenCount - 1;
  13081. var token = void 0;
  13082. while (leftIndex < tokenCount
  13083. && (token = tokens[leftIndex], !token.align || token.align === 'left')) {
  13084. this._placeToken(token, style, lineHeight, lineTop, lineXLeft, 'left', bgColorDrawn);
  13085. remainedWidth -= token.width;
  13086. lineXLeft += token.width;
  13087. leftIndex++;
  13088. }
  13089. while (rightIndex >= 0
  13090. && (token = tokens[rightIndex], token.align === 'right')) {
  13091. this._placeToken(token, style, lineHeight, lineTop, lineXRight, 'right', bgColorDrawn);
  13092. remainedWidth -= token.width;
  13093. lineXRight -= token.width;
  13094. rightIndex--;
  13095. }
  13096. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - remainedWidth) / 2;
  13097. while (leftIndex <= rightIndex) {
  13098. token = tokens[leftIndex];
  13099. this._placeToken(token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center', bgColorDrawn);
  13100. lineXLeft += token.width;
  13101. leftIndex++;
  13102. }
  13103. lineTop += lineHeight;
  13104. }
  13105. };
  13106. ZRText.prototype._placeToken = function (token, style, lineHeight, lineTop, x, textAlign, parentBgColorDrawn) {
  13107. var tokenStyle = style.rich[token.styleName] || {};
  13108. tokenStyle.text = token.text;
  13109. var verticalAlign = token.verticalAlign;
  13110. var y = lineTop + lineHeight / 2;
  13111. if (verticalAlign === 'top') {
  13112. y = lineTop + token.height / 2;
  13113. }
  13114. else if (verticalAlign === 'bottom') {
  13115. y = lineTop + lineHeight - token.height / 2;
  13116. }
  13117. var needDrawBg = !token.isLineHolder && needDrawBackground(tokenStyle);
  13118. needDrawBg && this._renderBackground(tokenStyle, style, textAlign === 'right'
  13119. ? x - token.width
  13120. : textAlign === 'center'
  13121. ? x - token.width / 2
  13122. : x, y - token.height / 2, token.width, token.height);
  13123. var bgColorDrawn = !!tokenStyle.backgroundColor;
  13124. var textPadding = token.textPadding;
  13125. if (textPadding) {
  13126. x = getTextXForPadding(x, textAlign, textPadding);
  13127. y -= token.height / 2 - textPadding[0] - token.innerHeight / 2;
  13128. }
  13129. var el = this._getOrCreateChild(TSpan);
  13130. var subElStyle = el.createStyle();
  13131. el.useStyle(subElStyle);
  13132. var defaultStyle = this._defaultStyle;
  13133. var useDefaultFill = false;
  13134. var defaultLineWidth = 0;
  13135. var textFill = getFill('fill' in tokenStyle ? tokenStyle.fill
  13136. : 'fill' in style ? style.fill
  13137. : (useDefaultFill = true, defaultStyle.fill));
  13138. var textStroke = getStroke('stroke' in tokenStyle ? tokenStyle.stroke
  13139. : 'stroke' in style ? style.stroke
  13140. : (!bgColorDrawn
  13141. && !parentBgColorDrawn
  13142. && (!defaultStyle.autoStroke || useDefaultFill)) ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  13143. : null);
  13144. var hasShadow = tokenStyle.textShadowBlur > 0
  13145. || style.textShadowBlur > 0;
  13146. subElStyle.text = token.text;
  13147. subElStyle.x = x;
  13148. subElStyle.y = y;
  13149. if (hasShadow) {
  13150. subElStyle.shadowBlur = tokenStyle.textShadowBlur || style.textShadowBlur || 0;
  13151. subElStyle.shadowColor = tokenStyle.textShadowColor || style.textShadowColor || 'transparent';
  13152. subElStyle.shadowOffsetX = tokenStyle.textShadowOffsetX || style.textShadowOffsetX || 0;
  13153. subElStyle.shadowOffsetY = tokenStyle.textShadowOffsetY || style.textShadowOffsetY || 0;
  13154. }
  13155. subElStyle.textAlign = textAlign;
  13156. subElStyle.textBaseline = 'middle';
  13157. subElStyle.font = token.font || DEFAULT_FONT;
  13158. subElStyle.opacity = retrieve3(tokenStyle.opacity, style.opacity, 1);
  13159. setSeparateFont(subElStyle, tokenStyle);
  13160. if (textStroke) {
  13161. subElStyle.lineWidth = retrieve3(tokenStyle.lineWidth, style.lineWidth, defaultLineWidth);
  13162. subElStyle.lineDash = retrieve2(tokenStyle.lineDash, style.lineDash);
  13163. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13164. subElStyle.stroke = textStroke;
  13165. }
  13166. if (textFill) {
  13167. subElStyle.fill = textFill;
  13168. }
  13169. var textWidth = token.contentWidth;
  13170. var textHeight = token.contentHeight;
  13171. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, textWidth, subElStyle.textAlign), adjustTextY$1(subElStyle.y, textHeight, subElStyle.textBaseline), textWidth, textHeight));
  13172. };
  13173. ZRText.prototype._renderBackground = function (style, topStyle, x, y, width, height) {
  13174. var textBackgroundColor = style.backgroundColor;
  13175. var textBorderWidth = style.borderWidth;
  13176. var textBorderColor = style.borderColor;
  13177. var isImageBg = textBackgroundColor && textBackgroundColor.image;
  13178. var isPlainOrGradientBg = textBackgroundColor && !isImageBg;
  13179. var textBorderRadius = style.borderRadius;
  13180. var self = this;
  13181. var rectEl;
  13182. var imgEl;
  13183. if (isPlainOrGradientBg || style.lineHeight || (textBorderWidth && textBorderColor)) {
  13184. rectEl = this._getOrCreateChild(Rect);
  13185. rectEl.useStyle(rectEl.createStyle());
  13186. rectEl.style.fill = null;
  13187. var rectShape = rectEl.shape;
  13188. rectShape.x = x;
  13189. rectShape.y = y;
  13190. rectShape.width = width;
  13191. rectShape.height = height;
  13192. rectShape.r = textBorderRadius;
  13193. rectEl.dirtyShape();
  13194. }
  13195. if (isPlainOrGradientBg) {
  13196. var rectStyle = rectEl.style;
  13197. rectStyle.fill = textBackgroundColor || null;
  13198. rectStyle.fillOpacity = retrieve2(style.fillOpacity, 1);
  13199. }
  13200. else if (isImageBg) {
  13201. imgEl = this._getOrCreateChild(ZRImage);
  13202. imgEl.onload = function () {
  13203. self.dirtyStyle();
  13204. };
  13205. var imgStyle = imgEl.style;
  13206. imgStyle.image = textBackgroundColor.image;
  13207. imgStyle.x = x;
  13208. imgStyle.y = y;
  13209. imgStyle.width = width;
  13210. imgStyle.height = height;
  13211. }
  13212. if (textBorderWidth && textBorderColor) {
  13213. var rectStyle = rectEl.style;
  13214. rectStyle.lineWidth = textBorderWidth;
  13215. rectStyle.stroke = textBorderColor;
  13216. rectStyle.strokeOpacity = retrieve2(style.strokeOpacity, 1);
  13217. rectStyle.lineDash = style.borderDash;
  13218. rectStyle.lineDashOffset = style.borderDashOffset || 0;
  13219. rectEl.strokeContainThreshold = 0;
  13220. if (rectEl.hasFill() && rectEl.hasStroke()) {
  13221. rectStyle.strokeFirst = true;
  13222. rectStyle.lineWidth *= 2;
  13223. }
  13224. }
  13225. var commonStyle = (rectEl || imgEl).style;
  13226. commonStyle.shadowBlur = style.shadowBlur || 0;
  13227. commonStyle.shadowColor = style.shadowColor || 'transparent';
  13228. commonStyle.shadowOffsetX = style.shadowOffsetX || 0;
  13229. commonStyle.shadowOffsetY = style.shadowOffsetY || 0;
  13230. commonStyle.opacity = retrieve3(style.opacity, topStyle.opacity, 1);
  13231. };
  13232. ZRText.makeFont = function (style) {
  13233. var font = '';
  13234. if (hasSeparateFont(style)) {
  13235. font = [
  13236. style.fontStyle,
  13237. style.fontWeight,
  13238. parseFontSize(style.fontSize),
  13239. style.fontFamily || 'sans-serif'
  13240. ].join(' ');
  13241. }
  13242. return font && trim(font) || style.textFont || style.font;
  13243. };
  13244. return ZRText;
  13245. }(Displayable));
  13246. var VALID_TEXT_ALIGN = { left: true, right: 1, center: 1 };
  13247. var VALID_TEXT_VERTICAL_ALIGN = { top: 1, bottom: 1, middle: 1 };
  13248. var FONT_PARTS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily'];
  13249. function parseFontSize(fontSize) {
  13250. if (typeof fontSize === 'string'
  13251. && (fontSize.indexOf('px') !== -1
  13252. || fontSize.indexOf('rem') !== -1
  13253. || fontSize.indexOf('em') !== -1)) {
  13254. return fontSize;
  13255. }
  13256. else if (!isNaN(+fontSize)) {
  13257. return fontSize + 'px';
  13258. }
  13259. else {
  13260. return DEFAULT_FONT_SIZE + 'px';
  13261. }
  13262. }
  13263. function setSeparateFont(targetStyle, sourceStyle) {
  13264. for (var i = 0; i < FONT_PARTS.length; i++) {
  13265. var fontProp = FONT_PARTS[i];
  13266. var val = sourceStyle[fontProp];
  13267. if (val != null) {
  13268. targetStyle[fontProp] = val;
  13269. }
  13270. }
  13271. }
  13272. function hasSeparateFont(style) {
  13273. return style.fontSize != null || style.fontFamily || style.fontWeight;
  13274. }
  13275. function normalizeTextStyle(style) {
  13276. normalizeStyle(style);
  13277. each(style.rich, normalizeStyle);
  13278. return style;
  13279. }
  13280. function normalizeStyle(style) {
  13281. if (style) {
  13282. style.font = ZRText.makeFont(style);
  13283. var textAlign = style.align;
  13284. textAlign === 'middle' && (textAlign = 'center');
  13285. style.align = (textAlign == null || VALID_TEXT_ALIGN[textAlign]) ? textAlign : 'left';
  13286. var verticalAlign = style.verticalAlign;
  13287. verticalAlign === 'center' && (verticalAlign = 'middle');
  13288. style.verticalAlign = (verticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[verticalAlign]) ? verticalAlign : 'top';
  13289. var textPadding = style.padding;
  13290. if (textPadding) {
  13291. style.padding = normalizeCssArray(style.padding);
  13292. }
  13293. }
  13294. }
  13295. function getStroke(stroke, lineWidth) {
  13296. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  13297. ? null
  13298. : (stroke.image || stroke.colorStops)
  13299. ? '#000'
  13300. : stroke;
  13301. }
  13302. function getFill(fill) {
  13303. return (fill == null || fill === 'none')
  13304. ? null
  13305. : (fill.image || fill.colorStops)
  13306. ? '#000'
  13307. : fill;
  13308. }
  13309. function getTextXForPadding(x, textAlign, textPadding) {
  13310. return textAlign === 'right'
  13311. ? (x - textPadding[1])
  13312. : textAlign === 'center'
  13313. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  13314. : (x + textPadding[3]);
  13315. }
  13316. function getStyleText(style) {
  13317. var text = style.text;
  13318. text != null && (text += '');
  13319. return text;
  13320. }
  13321. function needDrawBackground(style) {
  13322. return !!(style.backgroundColor
  13323. || style.lineHeight
  13324. || (style.borderWidth && style.borderColor));
  13325. }
  13326. var ArcShape = (function () {
  13327. function ArcShape() {
  13328. this.cx = 0;
  13329. this.cy = 0;
  13330. this.r = 0;
  13331. this.startAngle = 0;
  13332. this.endAngle = Math.PI * 2;
  13333. this.clockwise = true;
  13334. }
  13335. return ArcShape;
  13336. }());
  13337. var Arc = (function (_super) {
  13338. __extends(Arc, _super);
  13339. function Arc(opts) {
  13340. return _super.call(this, opts) || this;
  13341. }
  13342. Arc.prototype.getDefaultStyle = function () {
  13343. return {
  13344. stroke: '#000',
  13345. fill: null
  13346. };
  13347. };
  13348. Arc.prototype.getDefaultShape = function () {
  13349. return new ArcShape();
  13350. };
  13351. Arc.prototype.buildPath = function (ctx, shape) {
  13352. var x = shape.cx;
  13353. var y = shape.cy;
  13354. var r = Math.max(shape.r, 0);
  13355. var startAngle = shape.startAngle;
  13356. var endAngle = shape.endAngle;
  13357. var clockwise = shape.clockwise;
  13358. var unitX = Math.cos(startAngle);
  13359. var unitY = Math.sin(startAngle);
  13360. ctx.moveTo(unitX * r + x, unitY * r + y);
  13361. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13362. };
  13363. return Arc;
  13364. }(Path));
  13365. Arc.prototype.type = 'arc';
  13366. var out = [];
  13367. var BezierCurveShape = (function () {
  13368. function BezierCurveShape() {
  13369. this.x1 = 0;
  13370. this.y1 = 0;
  13371. this.x2 = 0;
  13372. this.y2 = 0;
  13373. this.cpx1 = 0;
  13374. this.cpy1 = 0;
  13375. this.percent = 1;
  13376. }
  13377. return BezierCurveShape;
  13378. }());
  13379. function someVectorAt(shape, t, isTangent) {
  13380. var cpx2 = shape.cpx2;
  13381. var cpy2 = shape.cpy2;
  13382. if (cpx2 != null || cpy2 != null) {
  13383. return [
  13384. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  13385. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  13386. ];
  13387. }
  13388. else {
  13389. return [
  13390. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  13391. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  13392. ];
  13393. }
  13394. }
  13395. var BezierCurve = (function (_super) {
  13396. __extends(BezierCurve, _super);
  13397. function BezierCurve(opts) {
  13398. return _super.call(this, opts) || this;
  13399. }
  13400. BezierCurve.prototype.getDefaultStyle = function () {
  13401. return {
  13402. stroke: '#000',
  13403. fill: null
  13404. };
  13405. };
  13406. BezierCurve.prototype.getDefaultShape = function () {
  13407. return new BezierCurveShape();
  13408. };
  13409. BezierCurve.prototype.buildPath = function (ctx, shape) {
  13410. var x1 = shape.x1;
  13411. var y1 = shape.y1;
  13412. var x2 = shape.x2;
  13413. var y2 = shape.y2;
  13414. var cpx1 = shape.cpx1;
  13415. var cpy1 = shape.cpy1;
  13416. var cpx2 = shape.cpx2;
  13417. var cpy2 = shape.cpy2;
  13418. var percent = shape.percent;
  13419. if (percent === 0) {
  13420. return;
  13421. }
  13422. ctx.moveTo(x1, y1);
  13423. if (cpx2 == null || cpy2 == null) {
  13424. if (percent < 1) {
  13425. quadraticSubdivide(x1, cpx1, x2, percent, out);
  13426. cpx1 = out[1];
  13427. x2 = out[2];
  13428. quadraticSubdivide(y1, cpy1, y2, percent, out);
  13429. cpy1 = out[1];
  13430. y2 = out[2];
  13431. }
  13432. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  13433. }
  13434. else {
  13435. if (percent < 1) {
  13436. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  13437. cpx1 = out[1];
  13438. cpx2 = out[2];
  13439. x2 = out[3];
  13440. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  13441. cpy1 = out[1];
  13442. cpy2 = out[2];
  13443. y2 = out[3];
  13444. }
  13445. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  13446. }
  13447. };
  13448. BezierCurve.prototype.pointAt = function (t) {
  13449. return someVectorAt(this.shape, t, false);
  13450. };
  13451. BezierCurve.prototype.tangentAt = function (t) {
  13452. var p = someVectorAt(this.shape, t, true);
  13453. return normalize(p, p);
  13454. };
  13455. return BezierCurve;
  13456. }(Path));
  13457. BezierCurve.prototype.type = 'bezier-curve';
  13458. var DropletShape = (function () {
  13459. function DropletShape() {
  13460. this.cx = 0;
  13461. this.cy = 0;
  13462. this.width = 0;
  13463. this.height = 0;
  13464. }
  13465. return DropletShape;
  13466. }());
  13467. var Droplet = (function (_super) {
  13468. __extends(Droplet, _super);
  13469. function Droplet(opts) {
  13470. return _super.call(this, opts) || this;
  13471. }
  13472. Droplet.prototype.getDefaultShape = function () {
  13473. return new DropletShape();
  13474. };
  13475. Droplet.prototype.buildPath = function (ctx, shape) {
  13476. var x = shape.cx;
  13477. var y = shape.cy;
  13478. var a = shape.width;
  13479. var b = shape.height;
  13480. ctx.moveTo(x, y + a);
  13481. ctx.bezierCurveTo(x + a, y + a, x + a * 3 / 2, y - a / 3, x, y - b);
  13482. ctx.bezierCurveTo(x - a * 3 / 2, y - a / 3, x - a, y + a, x, y + a);
  13483. ctx.closePath();
  13484. };
  13485. return Droplet;
  13486. }(Path));
  13487. Droplet.prototype.type = 'droplet';
  13488. var HeartShape = (function () {
  13489. function HeartShape() {
  13490. this.cx = 0;
  13491. this.cy = 0;
  13492. this.width = 0;
  13493. this.height = 0;
  13494. }
  13495. return HeartShape;
  13496. }());
  13497. var Heart = (function (_super) {
  13498. __extends(Heart, _super);
  13499. function Heart(opts) {
  13500. return _super.call(this, opts) || this;
  13501. }
  13502. Heart.prototype.getDefaultShape = function () {
  13503. return new HeartShape();
  13504. };
  13505. Heart.prototype.buildPath = function (ctx, shape) {
  13506. var x = shape.cx;
  13507. var y = shape.cy;
  13508. var a = shape.width;
  13509. var b = shape.height;
  13510. ctx.moveTo(x, y);
  13511. ctx.bezierCurveTo(x + a / 2, y - b * 2 / 3, x + a * 2, y + b / 3, x, y + b);
  13512. ctx.bezierCurveTo(x - a * 2, y + b / 3, x - a / 2, y - b * 2 / 3, x, y);
  13513. };
  13514. return Heart;
  13515. }(Path));
  13516. Heart.prototype.type = 'heart';
  13517. var PI$3 = Math.PI;
  13518. var sin = Math.sin;
  13519. var cos = Math.cos;
  13520. var IsogonShape = (function () {
  13521. function IsogonShape() {
  13522. this.x = 0;
  13523. this.y = 0;
  13524. this.r = 0;
  13525. this.n = 0;
  13526. }
  13527. return IsogonShape;
  13528. }());
  13529. var Isogon = (function (_super) {
  13530. __extends(Isogon, _super);
  13531. function Isogon(opts) {
  13532. return _super.call(this, opts) || this;
  13533. }
  13534. Isogon.prototype.getDefaultShape = function () {
  13535. return new IsogonShape();
  13536. };
  13537. Isogon.prototype.buildPath = function (ctx, shape) {
  13538. var n = shape.n;
  13539. if (!n || n < 2) {
  13540. return;
  13541. }
  13542. var x = shape.x;
  13543. var y = shape.y;
  13544. var r = shape.r;
  13545. var dStep = 2 * PI$3 / n;
  13546. var deg = -PI$3 / 2;
  13547. ctx.moveTo(x + r * cos(deg), y + r * sin(deg));
  13548. for (var i = 0, end = n - 1; i < end; i++) {
  13549. deg += dStep;
  13550. ctx.lineTo(x + r * cos(deg), y + r * sin(deg));
  13551. }
  13552. ctx.closePath();
  13553. return;
  13554. };
  13555. return Isogon;
  13556. }(Path));
  13557. Isogon.prototype.type = 'isogon';
  13558. var RingShape = (function () {
  13559. function RingShape() {
  13560. this.cx = 0;
  13561. this.cy = 0;
  13562. this.r = 0;
  13563. this.r0 = 0;
  13564. }
  13565. return RingShape;
  13566. }());
  13567. var Ring = (function (_super) {
  13568. __extends(Ring, _super);
  13569. function Ring(opts) {
  13570. return _super.call(this, opts) || this;
  13571. }
  13572. Ring.prototype.getDefaultShape = function () {
  13573. return new RingShape();
  13574. };
  13575. Ring.prototype.buildPath = function (ctx, shape) {
  13576. var x = shape.cx;
  13577. var y = shape.cy;
  13578. var PI2 = Math.PI * 2;
  13579. ctx.moveTo(x + shape.r, y);
  13580. ctx.arc(x, y, shape.r, 0, PI2, false);
  13581. ctx.moveTo(x + shape.r0, y);
  13582. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13583. };
  13584. return Ring;
  13585. }(Path));
  13586. Ring.prototype.type = 'ring';
  13587. var sin$1 = Math.sin;
  13588. var cos$1 = Math.cos;
  13589. var radian = Math.PI / 180;
  13590. var RoseShape = (function () {
  13591. function RoseShape() {
  13592. this.cx = 0;
  13593. this.cy = 0;
  13594. this.r = [];
  13595. this.k = 0;
  13596. this.n = 1;
  13597. }
  13598. return RoseShape;
  13599. }());
  13600. var Rose = (function (_super) {
  13601. __extends(Rose, _super);
  13602. function Rose(opts) {
  13603. return _super.call(this, opts) || this;
  13604. }
  13605. Rose.prototype.getDefaultStyle = function () {
  13606. return {
  13607. stroke: '#000',
  13608. fill: null
  13609. };
  13610. };
  13611. Rose.prototype.getDefaultShape = function () {
  13612. return new RoseShape();
  13613. };
  13614. Rose.prototype.buildPath = function (ctx, shape) {
  13615. var R = shape.r;
  13616. var k = shape.k;
  13617. var n = shape.n;
  13618. var x0 = shape.cx;
  13619. var y0 = shape.cy;
  13620. var x;
  13621. var y;
  13622. var r;
  13623. ctx.moveTo(x0, y0);
  13624. for (var i = 0, len = R.length; i < len; i++) {
  13625. r = R[i];
  13626. for (var j = 0; j <= 360 * n; j++) {
  13627. x = r
  13628. * sin$1(k / n * j % 360 * radian)
  13629. * cos$1(j * radian)
  13630. + x0;
  13631. y = r
  13632. * sin$1(k / n * j % 360 * radian)
  13633. * sin$1(j * radian)
  13634. + y0;
  13635. ctx.lineTo(x, y);
  13636. }
  13637. }
  13638. };
  13639. return Rose;
  13640. }(Path));
  13641. Rose.prototype.type = 'rose';
  13642. var PI$4 = Math.PI;
  13643. var cos$2 = Math.cos;
  13644. var sin$2 = Math.sin;
  13645. var StarShape = (function () {
  13646. function StarShape() {
  13647. this.cx = 0;
  13648. this.cy = 0;
  13649. this.n = 3;
  13650. this.r = 0;
  13651. }
  13652. return StarShape;
  13653. }());
  13654. var Star = (function (_super) {
  13655. __extends(Star, _super);
  13656. function Star(opts) {
  13657. return _super.call(this, opts) || this;
  13658. }
  13659. Star.prototype.getDefaultShape = function () {
  13660. return new StarShape();
  13661. };
  13662. Star.prototype.buildPath = function (ctx, shape) {
  13663. var n = shape.n;
  13664. if (!n || n < 2) {
  13665. return;
  13666. }
  13667. var x = shape.cx;
  13668. var y = shape.cy;
  13669. var r = shape.r;
  13670. var r0 = shape.r0;
  13671. if (r0 == null) {
  13672. r0 = n > 4
  13673. ? r * cos$2(2 * PI$4 / n) / cos$2(PI$4 / n)
  13674. : r / 3;
  13675. }
  13676. var dStep = PI$4 / n;
  13677. var deg = -PI$4 / 2;
  13678. var xStart = x + r * cos$2(deg);
  13679. var yStart = y + r * sin$2(deg);
  13680. deg += dStep;
  13681. ctx.moveTo(xStart, yStart);
  13682. for (var i = 0, end = n * 2 - 1, ri = void 0; i < end; i++) {
  13683. ri = i % 2 === 0 ? r0 : r;
  13684. ctx.lineTo(x + ri * cos$2(deg), y + ri * sin$2(deg));
  13685. deg += dStep;
  13686. }
  13687. ctx.closePath();
  13688. };
  13689. return Star;
  13690. }(Path));
  13691. Star.prototype.type = 'star';
  13692. var cos$3 = Math.cos;
  13693. var sin$3 = Math.sin;
  13694. var TrochoidShape = (function () {
  13695. function TrochoidShape() {
  13696. this.cx = 0;
  13697. this.cy = 0;
  13698. this.r = 0;
  13699. this.r0 = 0;
  13700. this.d = 0;
  13701. this.location = 'out';
  13702. }
  13703. return TrochoidShape;
  13704. }());
  13705. var Trochoid = (function (_super) {
  13706. __extends(Trochoid, _super);
  13707. function Trochoid(opts) {
  13708. return _super.call(this, opts) || this;
  13709. }
  13710. Trochoid.prototype.getDefaultStyle = function () {
  13711. return {
  13712. stroke: '#000',
  13713. fill: null
  13714. };
  13715. };
  13716. Trochoid.prototype.getDefaultShape = function () {
  13717. return new TrochoidShape();
  13718. };
  13719. Trochoid.prototype.buildPath = function (ctx, shape) {
  13720. var R = shape.r;
  13721. var r = shape.r0;
  13722. var d = shape.d;
  13723. var offsetX = shape.cx;
  13724. var offsetY = shape.cy;
  13725. var delta = shape.location === 'out' ? 1 : -1;
  13726. var x1;
  13727. var y1;
  13728. var x2;
  13729. var y2;
  13730. if (shape.location && R <= r) {
  13731. return;
  13732. }
  13733. var num = 0;
  13734. var i = 1;
  13735. var theta;
  13736. x1 = (R + delta * r) * cos$3(0)
  13737. - delta * d * cos$3(0) + offsetX;
  13738. y1 = (R + delta * r) * sin$3(0)
  13739. - d * sin$3(0) + offsetY;
  13740. ctx.moveTo(x1, y1);
  13741. do {
  13742. num++;
  13743. } while ((r * num) % (R + delta * r) !== 0);
  13744. do {
  13745. theta = Math.PI / 180 * i;
  13746. x2 = (R + delta * r) * cos$3(theta)
  13747. - delta * d * cos$3((R / r + delta) * theta)
  13748. + offsetX;
  13749. y2 = (R + delta * r) * sin$3(theta)
  13750. - d * sin$3((R / r + delta) * theta)
  13751. + offsetY;
  13752. ctx.lineTo(x2, y2);
  13753. i++;
  13754. } while (i <= (r * num) / (R + delta * r) * 360);
  13755. };
  13756. return Trochoid;
  13757. }(Path));
  13758. Trochoid.prototype.type = 'trochoid';
  13759. var Pattern = (function () {
  13760. function Pattern(image, repeat) {
  13761. this.image = image;
  13762. this.repeat = repeat;
  13763. this.x = 0;
  13764. this.y = 0;
  13765. this.rotation = 0;
  13766. this.scaleX = 1;
  13767. this.scaleY = 1;
  13768. }
  13769. return Pattern;
  13770. }());
  13771. var extent = [0, 0];
  13772. var extent2 = [0, 0];
  13773. var minTv$1 = new Point();
  13774. var maxTv$1 = new Point();
  13775. var OrientedBoundingRect = (function () {
  13776. function OrientedBoundingRect(rect, transform) {
  13777. this._corners = [];
  13778. this._axes = [];
  13779. this._origin = [0, 0];
  13780. for (var i = 0; i < 4; i++) {
  13781. this._corners[i] = new Point();
  13782. }
  13783. for (var i = 0; i < 2; i++) {
  13784. this._axes[i] = new Point();
  13785. }
  13786. if (rect) {
  13787. this.fromBoundingRect(rect, transform);
  13788. }
  13789. }
  13790. OrientedBoundingRect.prototype.fromBoundingRect = function (rect, transform) {
  13791. var corners = this._corners;
  13792. var axes = this._axes;
  13793. var x = rect.x;
  13794. var y = rect.y;
  13795. var x2 = x + rect.width;
  13796. var y2 = y + rect.height;
  13797. corners[0].set(x, y);
  13798. corners[1].set(x2, y);
  13799. corners[2].set(x2, y2);
  13800. corners[3].set(x, y2);
  13801. if (transform) {
  13802. for (var i = 0; i < 4; i++) {
  13803. corners[i].transform(transform);
  13804. }
  13805. }
  13806. Point.sub(axes[0], corners[1], corners[0]);
  13807. Point.sub(axes[1], corners[3], corners[0]);
  13808. axes[0].normalize();
  13809. axes[1].normalize();
  13810. for (var i = 0; i < 2; i++) {
  13811. this._origin[i] = axes[i].dot(corners[0]);
  13812. }
  13813. };
  13814. OrientedBoundingRect.prototype.intersect = function (other, mtv) {
  13815. var overlapped = true;
  13816. var noMtv = !mtv;
  13817. minTv$1.set(Infinity, Infinity);
  13818. maxTv$1.set(0, 0);
  13819. if (!this._intersectCheckOneSide(this, other, minTv$1, maxTv$1, noMtv, 1)) {
  13820. overlapped = false;
  13821. if (noMtv) {
  13822. return overlapped;
  13823. }
  13824. }
  13825. if (!this._intersectCheckOneSide(other, this, minTv$1, maxTv$1, noMtv, -1)) {
  13826. overlapped = false;
  13827. if (noMtv) {
  13828. return overlapped;
  13829. }
  13830. }
  13831. if (!noMtv) {
  13832. Point.copy(mtv, overlapped ? minTv$1 : maxTv$1);
  13833. }
  13834. return overlapped;
  13835. };
  13836. OrientedBoundingRect.prototype._intersectCheckOneSide = function (self, other, minTv, maxTv, noMtv, inverse) {
  13837. var overlapped = true;
  13838. for (var i = 0; i < 2; i++) {
  13839. var axis = this._axes[i];
  13840. this._getProjMinMaxOnAxis(i, self._corners, extent);
  13841. this._getProjMinMaxOnAxis(i, other._corners, extent2);
  13842. if (extent[1] < extent2[0] || extent[0] > extent2[1]) {
  13843. overlapped = false;
  13844. if (noMtv) {
  13845. return overlapped;
  13846. }
  13847. var dist0 = Math.abs(extent2[0] - extent[1]);
  13848. var dist1 = Math.abs(extent[0] - extent2[1]);
  13849. if (Math.min(dist0, dist1) > maxTv.len()) {
  13850. if (dist0 < dist1) {
  13851. Point.scale(maxTv, axis, -dist0 * inverse);
  13852. }
  13853. else {
  13854. Point.scale(maxTv, axis, dist1 * inverse);
  13855. }
  13856. }
  13857. }
  13858. else if (minTv) {
  13859. var dist0 = Math.abs(extent2[0] - extent[1]);
  13860. var dist1 = Math.abs(extent[0] - extent2[1]);
  13861. if (Math.min(dist0, dist1) < minTv.len()) {
  13862. if (dist0 < dist1) {
  13863. Point.scale(minTv, axis, dist0 * inverse);
  13864. }
  13865. else {
  13866. Point.scale(minTv, axis, -dist1 * inverse);
  13867. }
  13868. }
  13869. }
  13870. }
  13871. return overlapped;
  13872. };
  13873. OrientedBoundingRect.prototype._getProjMinMaxOnAxis = function (dim, corners, out) {
  13874. var axis = this._axes[dim];
  13875. var origin = this._origin;
  13876. var proj = corners[0].dot(axis) + origin[dim];
  13877. var min = proj;
  13878. var max = proj;
  13879. for (var i = 1; i < corners.length; i++) {
  13880. var proj_1 = corners[i].dot(axis) + origin[dim];
  13881. min = Math.min(proj_1, min);
  13882. max = Math.max(proj_1, max);
  13883. }
  13884. out[0] = min;
  13885. out[1] = max;
  13886. };
  13887. return OrientedBoundingRect;
  13888. }());
  13889. var DebugRect = (function () {
  13890. function DebugRect(style) {
  13891. var dom = this.dom = document.createElement('div');
  13892. dom.className = 'ec-debug-dirty-rect';
  13893. style = extend({}, style);
  13894. extend(style, {
  13895. backgroundColor: 'rgba(0, 0, 255, 0.2)',
  13896. border: '1px solid #00f'
  13897. });
  13898. dom.style.cssText = "\nposition: absolute;\nopacity: 0;\ntransition: opacity 0.5s linear;\npointer-events: none;\n";
  13899. for (var key in style) {
  13900. if (style.hasOwnProperty(key)) {
  13901. dom.style[key] = style[key];
  13902. }
  13903. }
  13904. }
  13905. DebugRect.prototype.update = function (rect) {
  13906. var domStyle = this.dom.style;
  13907. domStyle.width = rect.width + 'px';
  13908. domStyle.height = rect.height + 'px';
  13909. domStyle.left = rect.x + 'px';
  13910. domStyle.top = rect.y + 'px';
  13911. };
  13912. DebugRect.prototype.hide = function () {
  13913. this.dom.style.opacity = '0';
  13914. };
  13915. DebugRect.prototype.show = function (autoHideDelay) {
  13916. var _this = this;
  13917. clearTimeout(this._hideTimeout);
  13918. this.dom.style.opacity = '1';
  13919. this._hideTimeout = setTimeout(function () {
  13920. _this.hide();
  13921. }, autoHideDelay || 1000);
  13922. };
  13923. return DebugRect;
  13924. }());
  13925. function showDebugDirtyRect(zr, opts) {
  13926. opts = opts || {};
  13927. var painter = zr.painter;
  13928. if (!painter.getLayers) {
  13929. throw new Error('Debug dirty rect can only been used on canvas renderer.');
  13930. }
  13931. if (painter.isSingleCanvas()) {
  13932. throw new Error('Debug dirty rect can only been used on zrender inited with container.');
  13933. }
  13934. var debugViewRoot = document.createElement('div');
  13935. debugViewRoot.style.cssText = "\nposition:absolute;\nleft:0;\ntop:0;\nright:0;\nbottom:0;\npointer-events:none;\n";
  13936. debugViewRoot.className = 'ec-debug-dirty-rect-container';
  13937. var debugRects = [];
  13938. var dom = zr.dom;
  13939. dom.appendChild(debugViewRoot);
  13940. var computedStyle = getComputedStyle(dom);
  13941. if (computedStyle.position === 'static') {
  13942. dom.style.position = 'relative';
  13943. }
  13944. zr.on('rendered', function () {
  13945. if (painter.getLayers) {
  13946. var idx_1 = 0;
  13947. painter.eachBuiltinLayer(function (layer) {
  13948. if (!layer.debugGetPaintRects) {
  13949. return;
  13950. }
  13951. var paintRects = layer.debugGetPaintRects();
  13952. for (var i = 0; i < paintRects.length; i++) {
  13953. if (!paintRects[i].width || !paintRects[i].height) {
  13954. continue;
  13955. }
  13956. if (!debugRects[idx_1]) {
  13957. debugRects[idx_1] = new DebugRect(opts.style);
  13958. debugViewRoot.appendChild(debugRects[idx_1].dom);
  13959. }
  13960. debugRects[idx_1].show(opts.autoHideDelay);
  13961. debugRects[idx_1].update(paintRects[i]);
  13962. idx_1++;
  13963. }
  13964. });
  13965. for (var i = idx_1; i < debugRects.length; i++) {
  13966. debugRects[i].hide();
  13967. }
  13968. }
  13969. });
  13970. }
  13971. function isSafeNum(num) {
  13972. return isFinite(num);
  13973. }
  13974. function createLinearGradient(ctx, obj, rect) {
  13975. var x = obj.x == null ? 0 : obj.x;
  13976. var x2 = obj.x2 == null ? 1 : obj.x2;
  13977. var y = obj.y == null ? 0 : obj.y;
  13978. var y2 = obj.y2 == null ? 0 : obj.y2;
  13979. if (!obj.global) {
  13980. x = x * rect.width + rect.x;
  13981. x2 = x2 * rect.width + rect.x;
  13982. y = y * rect.height + rect.y;
  13983. y2 = y2 * rect.height + rect.y;
  13984. }
  13985. x = isSafeNum(x) ? x : 0;
  13986. x2 = isSafeNum(x2) ? x2 : 1;
  13987. y = isSafeNum(y) ? y : 0;
  13988. y2 = isSafeNum(y2) ? y2 : 0;
  13989. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  13990. return canvasGradient;
  13991. }
  13992. function createRadialGradient(ctx, obj, rect) {
  13993. var width = rect.width;
  13994. var height = rect.height;
  13995. var min = Math.min(width, height);
  13996. var x = obj.x == null ? 0.5 : obj.x;
  13997. var y = obj.y == null ? 0.5 : obj.y;
  13998. var r = obj.r == null ? 0.5 : obj.r;
  13999. if (!obj.global) {
  14000. x = x * width + rect.x;
  14001. y = y * height + rect.y;
  14002. r = r * min;
  14003. }
  14004. x = isSafeNum(x) ? x : 0.5;
  14005. y = isSafeNum(y) ? y : 0.5;
  14006. r = r >= 0 && isSafeNum(r) ? r : 0.5;
  14007. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  14008. return canvasGradient;
  14009. }
  14010. function getCanvasGradient(ctx, obj, rect) {
  14011. var canvasGradient = obj.type === 'radial'
  14012. ? createRadialGradient(ctx, obj, rect)
  14013. : createLinearGradient(ctx, obj, rect);
  14014. var colorStops = obj.colorStops;
  14015. for (var i = 0; i < colorStops.length; i++) {
  14016. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  14017. }
  14018. return canvasGradient;
  14019. }
  14020. function isClipPathChanged(clipPaths, prevClipPaths) {
  14021. if (clipPaths === prevClipPaths || (!clipPaths && !prevClipPaths)) {
  14022. return false;
  14023. }
  14024. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  14025. return true;
  14026. }
  14027. for (var i = 0; i < clipPaths.length; i++) {
  14028. if (clipPaths[i] !== prevClipPaths[i]) {
  14029. return true;
  14030. }
  14031. }
  14032. return false;
  14033. }
  14034. function parseInt10(val) {
  14035. return parseInt(val, 10);
  14036. }
  14037. function getSize(root, whIdx, opts) {
  14038. var wh = ['width', 'height'][whIdx];
  14039. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  14040. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  14041. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  14042. if (opts[wh] != null && opts[wh] !== 'auto') {
  14043. return parseFloat(opts[wh]);
  14044. }
  14045. var stl = document.defaultView.getComputedStyle(root);
  14046. return ((root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  14047. - (parseInt10(stl[plt]) || 0)
  14048. - (parseInt10(stl[prb]) || 0)) | 0;
  14049. }
  14050. function normalizeLineDash(lineType, lineWidth) {
  14051. if (!lineType || lineType === 'solid' || !(lineWidth > 0)) {
  14052. return null;
  14053. }
  14054. return lineType === 'dashed'
  14055. ? [4 * lineWidth, 2 * lineWidth]
  14056. : lineType === 'dotted'
  14057. ? [lineWidth]
  14058. : isNumber(lineType)
  14059. ? [lineType] : isArray(lineType) ? lineType : null;
  14060. }
  14061. function getLineDash(el) {
  14062. var style = el.style;
  14063. var lineDash = style.lineDash && style.lineWidth > 0 && normalizeLineDash(style.lineDash, style.lineWidth);
  14064. var lineDashOffset = style.lineDashOffset;
  14065. if (lineDash) {
  14066. var lineScale_1 = (style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1;
  14067. if (lineScale_1 && lineScale_1 !== 1) {
  14068. lineDash = map(lineDash, function (rawVal) {
  14069. return rawVal / lineScale_1;
  14070. });
  14071. lineDashOffset /= lineScale_1;
  14072. }
  14073. }
  14074. return [lineDash, lineDashOffset];
  14075. }
  14076. var pathProxyForDraw = new PathProxy(true);
  14077. function styleHasStroke(style) {
  14078. var stroke = style.stroke;
  14079. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  14080. }
  14081. function isValidStrokeFillStyle(strokeOrFill) {
  14082. return typeof strokeOrFill === 'string' && strokeOrFill !== 'none';
  14083. }
  14084. function styleHasFill(style) {
  14085. var fill = style.fill;
  14086. return fill != null && fill !== 'none';
  14087. }
  14088. function doFillPath(ctx, style) {
  14089. if (style.fillOpacity != null && style.fillOpacity !== 1) {
  14090. var originalGlobalAlpha = ctx.globalAlpha;
  14091. ctx.globalAlpha = style.fillOpacity * style.opacity;
  14092. ctx.fill();
  14093. ctx.globalAlpha = originalGlobalAlpha;
  14094. }
  14095. else {
  14096. ctx.fill();
  14097. }
  14098. }
  14099. function doStrokePath(ctx, style) {
  14100. if (style.strokeOpacity != null && style.strokeOpacity !== 1) {
  14101. var originalGlobalAlpha = ctx.globalAlpha;
  14102. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  14103. ctx.stroke();
  14104. ctx.globalAlpha = originalGlobalAlpha;
  14105. }
  14106. else {
  14107. ctx.stroke();
  14108. }
  14109. }
  14110. function createCanvasPattern(ctx, pattern, el) {
  14111. var image = createOrUpdateImage(pattern.image, pattern.__image, el);
  14112. if (isImageReady(image)) {
  14113. var canvasPattern = ctx.createPattern(image, pattern.repeat || 'repeat');
  14114. if (typeof DOMMatrix === 'function'
  14115. && canvasPattern
  14116. && canvasPattern.setTransform) {
  14117. var matrix = new DOMMatrix();
  14118. matrix.translateSelf((pattern.x || 0), (pattern.y || 0));
  14119. matrix.rotateSelf(0, 0, (pattern.rotation || 0) * RADIAN_TO_DEGREE);
  14120. matrix.scaleSelf((pattern.scaleX || 1), (pattern.scaleY || 1));
  14121. canvasPattern.setTransform(matrix);
  14122. }
  14123. return canvasPattern;
  14124. }
  14125. }
  14126. function brushPath(ctx, el, style, inBatch) {
  14127. var _a;
  14128. var hasStroke = styleHasStroke(style);
  14129. var hasFill = styleHasFill(style);
  14130. var strokePercent = style.strokePercent;
  14131. var strokePart = strokePercent < 1;
  14132. var firstDraw = !el.path;
  14133. if ((!el.silent || strokePart) && firstDraw) {
  14134. el.createPathProxy();
  14135. }
  14136. var path = el.path || pathProxyForDraw;
  14137. var dirtyFlag = el.__dirty;
  14138. if (!inBatch) {
  14139. var fill = style.fill;
  14140. var stroke = style.stroke;
  14141. var hasFillGradient = hasFill && !!fill.colorStops;
  14142. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  14143. var hasFillPattern = hasFill && !!fill.image;
  14144. var hasStrokePattern = hasStroke && !!stroke.image;
  14145. var fillGradient = void 0;
  14146. var strokeGradient = void 0;
  14147. var fillPattern = void 0;
  14148. var strokePattern = void 0;
  14149. var rect = void 0;
  14150. if (hasFillGradient || hasStrokeGradient) {
  14151. rect = el.getBoundingRect();
  14152. }
  14153. if (hasFillGradient) {
  14154. fillGradient = dirtyFlag
  14155. ? getCanvasGradient(ctx, fill, rect)
  14156. : el.__canvasFillGradient;
  14157. el.__canvasFillGradient = fillGradient;
  14158. }
  14159. if (hasStrokeGradient) {
  14160. strokeGradient = dirtyFlag
  14161. ? getCanvasGradient(ctx, stroke, rect)
  14162. : el.__canvasStrokeGradient;
  14163. el.__canvasStrokeGradient = strokeGradient;
  14164. }
  14165. if (hasFillPattern) {
  14166. fillPattern = (dirtyFlag || !el.__canvasFillPattern)
  14167. ? createCanvasPattern(ctx, fill, el)
  14168. : el.__canvasFillPattern;
  14169. el.__canvasFillPattern = fillPattern;
  14170. }
  14171. if (hasStrokePattern) {
  14172. strokePattern = (dirtyFlag || !el.__canvasStrokePattern)
  14173. ? createCanvasPattern(ctx, stroke, el)
  14174. : el.__canvasStrokePattern;
  14175. el.__canvasStrokePattern = fillPattern;
  14176. }
  14177. if (hasFillGradient) {
  14178. ctx.fillStyle = fillGradient;
  14179. }
  14180. else if (hasFillPattern) {
  14181. if (fillPattern) {
  14182. ctx.fillStyle = fillPattern;
  14183. }
  14184. else {
  14185. hasFill = false;
  14186. }
  14187. }
  14188. if (hasStrokeGradient) {
  14189. ctx.strokeStyle = strokeGradient;
  14190. }
  14191. else if (hasStrokePattern) {
  14192. if (strokePattern) {
  14193. ctx.strokeStyle = strokePattern;
  14194. }
  14195. else {
  14196. hasStroke = false;
  14197. }
  14198. }
  14199. }
  14200. var scale = el.getGlobalScale();
  14201. path.setScale(scale[0], scale[1], el.segmentIgnoreThreshold);
  14202. var lineDash;
  14203. var lineDashOffset;
  14204. if (ctx.setLineDash && style.lineDash) {
  14205. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14206. }
  14207. var needsRebuild = true;
  14208. if (firstDraw || (dirtyFlag & SHAPE_CHANGED_BIT)) {
  14209. path.setDPR(ctx.dpr);
  14210. if (strokePart) {
  14211. path.setContext(null);
  14212. }
  14213. else {
  14214. path.setContext(ctx);
  14215. needsRebuild = false;
  14216. }
  14217. path.reset();
  14218. el.buildPath(path, el.shape, inBatch);
  14219. path.toStatic();
  14220. el.pathUpdated();
  14221. }
  14222. if (needsRebuild) {
  14223. path.rebuildPath(ctx, strokePart ? strokePercent : 1);
  14224. }
  14225. if (lineDash) {
  14226. ctx.setLineDash(lineDash);
  14227. ctx.lineDashOffset = lineDashOffset;
  14228. }
  14229. if (!inBatch) {
  14230. if (style.strokeFirst) {
  14231. if (hasStroke) {
  14232. doStrokePath(ctx, style);
  14233. }
  14234. if (hasFill) {
  14235. doFillPath(ctx, style);
  14236. }
  14237. }
  14238. else {
  14239. if (hasFill) {
  14240. doFillPath(ctx, style);
  14241. }
  14242. if (hasStroke) {
  14243. doStrokePath(ctx, style);
  14244. }
  14245. }
  14246. }
  14247. if (lineDash) {
  14248. ctx.setLineDash([]);
  14249. }
  14250. }
  14251. function brushImage(ctx, el, style) {
  14252. var image = el.__image = createOrUpdateImage(style.image, el.__image, el, el.onload);
  14253. if (!image || !isImageReady(image)) {
  14254. return;
  14255. }
  14256. var x = style.x || 0;
  14257. var y = style.y || 0;
  14258. var width = el.getWidth();
  14259. var height = el.getHeight();
  14260. var aspect = image.width / image.height;
  14261. if (width == null && height != null) {
  14262. width = height * aspect;
  14263. }
  14264. else if (height == null && width != null) {
  14265. height = width / aspect;
  14266. }
  14267. else if (width == null && height == null) {
  14268. width = image.width;
  14269. height = image.height;
  14270. }
  14271. if (style.sWidth && style.sHeight) {
  14272. var sx = style.sx || 0;
  14273. var sy = style.sy || 0;
  14274. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  14275. }
  14276. else if (style.sx && style.sy) {
  14277. var sx = style.sx;
  14278. var sy = style.sy;
  14279. var sWidth = width - sx;
  14280. var sHeight = height - sy;
  14281. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  14282. }
  14283. else {
  14284. ctx.drawImage(image, x, y, width, height);
  14285. }
  14286. }
  14287. function brushText(ctx, el, style) {
  14288. var _a;
  14289. var text = style.text;
  14290. text != null && (text += '');
  14291. if (text) {
  14292. ctx.font = style.font || DEFAULT_FONT;
  14293. ctx.textAlign = style.textAlign;
  14294. ctx.textBaseline = style.textBaseline;
  14295. var lineDash = void 0;
  14296. var lineDashOffset = void 0;
  14297. if (ctx.setLineDash && style.lineDash) {
  14298. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14299. }
  14300. if (lineDash) {
  14301. ctx.setLineDash(lineDash);
  14302. ctx.lineDashOffset = lineDashOffset;
  14303. }
  14304. if (style.strokeFirst) {
  14305. if (styleHasStroke(style)) {
  14306. ctx.strokeText(text, style.x, style.y);
  14307. }
  14308. if (styleHasFill(style)) {
  14309. ctx.fillText(text, style.x, style.y);
  14310. }
  14311. }
  14312. else {
  14313. if (styleHasFill(style)) {
  14314. ctx.fillText(text, style.x, style.y);
  14315. }
  14316. if (styleHasStroke(style)) {
  14317. ctx.strokeText(text, style.x, style.y);
  14318. }
  14319. }
  14320. if (lineDash) {
  14321. ctx.setLineDash([]);
  14322. }
  14323. }
  14324. }
  14325. var SHADOW_NUMBER_PROPS = ['shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  14326. var STROKE_PROPS = [
  14327. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  14328. ];
  14329. function bindCommonProps(ctx, style, prevStyle, forceSetAll, scope) {
  14330. var styleChanged = false;
  14331. if (!forceSetAll) {
  14332. prevStyle = prevStyle || {};
  14333. if (style === prevStyle) {
  14334. return false;
  14335. }
  14336. }
  14337. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14338. flushPathDrawn(ctx, scope);
  14339. styleChanged = true;
  14340. var opacity = Math.max(Math.min(style.opacity, 1), 0);
  14341. ctx.globalAlpha = isNaN(opacity) ? DEFAULT_COMMON_STYLE.opacity : opacity;
  14342. }
  14343. if (forceSetAll || style.blend !== prevStyle.blend) {
  14344. if (!styleChanged) {
  14345. flushPathDrawn(ctx, scope);
  14346. styleChanged = true;
  14347. }
  14348. ctx.globalCompositeOperation = style.blend || DEFAULT_COMMON_STYLE.blend;
  14349. }
  14350. for (var i = 0; i < SHADOW_NUMBER_PROPS.length; i++) {
  14351. var propName = SHADOW_NUMBER_PROPS[i];
  14352. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14353. if (!styleChanged) {
  14354. flushPathDrawn(ctx, scope);
  14355. styleChanged = true;
  14356. }
  14357. ctx[propName] = ctx.dpr * (style[propName] || 0);
  14358. }
  14359. }
  14360. if (forceSetAll || style.shadowColor !== prevStyle.shadowColor) {
  14361. if (!styleChanged) {
  14362. flushPathDrawn(ctx, scope);
  14363. styleChanged = true;
  14364. }
  14365. ctx.shadowColor = style.shadowColor || DEFAULT_COMMON_STYLE.shadowColor;
  14366. }
  14367. return styleChanged;
  14368. }
  14369. function bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetAll, scope) {
  14370. var style = getStyle(el, scope.inHover);
  14371. var prevStyle = forceSetAll
  14372. ? null
  14373. : (prevEl && getStyle(prevEl, scope.inHover) || {});
  14374. if (style === prevStyle) {
  14375. return false;
  14376. }
  14377. var styleChanged = bindCommonProps(ctx, style, prevStyle, forceSetAll, scope);
  14378. if (forceSetAll || style.fill !== prevStyle.fill) {
  14379. if (!styleChanged) {
  14380. flushPathDrawn(ctx, scope);
  14381. styleChanged = true;
  14382. }
  14383. isValidStrokeFillStyle(style.fill) && (ctx.fillStyle = style.fill);
  14384. }
  14385. if (forceSetAll || style.stroke !== prevStyle.stroke) {
  14386. if (!styleChanged) {
  14387. flushPathDrawn(ctx, scope);
  14388. styleChanged = true;
  14389. }
  14390. isValidStrokeFillStyle(style.stroke) && (ctx.strokeStyle = style.stroke);
  14391. }
  14392. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14393. if (!styleChanged) {
  14394. flushPathDrawn(ctx, scope);
  14395. styleChanged = true;
  14396. }
  14397. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  14398. }
  14399. if (el.hasStroke()) {
  14400. var lineWidth = style.lineWidth;
  14401. var newLineWidth = lineWidth / ((style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1);
  14402. if (ctx.lineWidth !== newLineWidth) {
  14403. if (!styleChanged) {
  14404. flushPathDrawn(ctx, scope);
  14405. styleChanged = true;
  14406. }
  14407. ctx.lineWidth = newLineWidth;
  14408. }
  14409. }
  14410. for (var i = 0; i < STROKE_PROPS.length; i++) {
  14411. var prop = STROKE_PROPS[i];
  14412. var propName = prop[0];
  14413. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14414. if (!styleChanged) {
  14415. flushPathDrawn(ctx, scope);
  14416. styleChanged = true;
  14417. }
  14418. ctx[propName] = style[propName] || prop[1];
  14419. }
  14420. }
  14421. return styleChanged;
  14422. }
  14423. function bindImageStyle(ctx, el, prevEl, forceSetAll, scope) {
  14424. return bindCommonProps(ctx, getStyle(el, scope.inHover), prevEl && getStyle(prevEl, scope.inHover), forceSetAll, scope);
  14425. }
  14426. function setContextTransform(ctx, el) {
  14427. var m = el.transform;
  14428. var dpr = ctx.dpr || 1;
  14429. if (m) {
  14430. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  14431. }
  14432. else {
  14433. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  14434. }
  14435. }
  14436. function updateClipStatus(clipPaths, ctx, scope) {
  14437. var allClipped = false;
  14438. for (var i = 0; i < clipPaths.length; i++) {
  14439. var clipPath = clipPaths[i];
  14440. allClipped = allClipped || clipPath.isZeroArea();
  14441. setContextTransform(ctx, clipPath);
  14442. ctx.beginPath();
  14443. clipPath.buildPath(ctx, clipPath.shape);
  14444. ctx.clip();
  14445. }
  14446. scope.allClipped = allClipped;
  14447. }
  14448. function isTransformChanged(m0, m1) {
  14449. if (m0 && m1) {
  14450. return m0[0] !== m1[0]
  14451. || m0[1] !== m1[1]
  14452. || m0[2] !== m1[2]
  14453. || m0[3] !== m1[3]
  14454. || m0[4] !== m1[4]
  14455. || m0[5] !== m1[5];
  14456. }
  14457. else if (!m0 && !m1) {
  14458. return false;
  14459. }
  14460. return true;
  14461. }
  14462. var DRAW_TYPE_PATH = 1;
  14463. var DRAW_TYPE_IMAGE = 2;
  14464. var DRAW_TYPE_TEXT = 3;
  14465. var DRAW_TYPE_INCREMENTAL = 4;
  14466. function canPathBatch(style) {
  14467. var hasFill = styleHasFill(style);
  14468. var hasStroke = styleHasStroke(style);
  14469. return !(style.lineDash
  14470. || !(+hasFill ^ +hasStroke)
  14471. || (hasFill && typeof style.fill !== 'string')
  14472. || (hasStroke && typeof style.stroke !== 'string')
  14473. || style.strokePercent < 1
  14474. || style.strokeOpacity < 1
  14475. || style.fillOpacity < 1);
  14476. }
  14477. function flushPathDrawn(ctx, scope) {
  14478. scope.batchFill && ctx.fill();
  14479. scope.batchStroke && ctx.stroke();
  14480. scope.batchFill = '';
  14481. scope.batchStroke = '';
  14482. }
  14483. function getStyle(el, inHover) {
  14484. return inHover ? (el.__hoverStyle || el.style) : el.style;
  14485. }
  14486. function brushSingle(ctx, el) {
  14487. brush(ctx, el, { inHover: false, viewWidth: 0, viewHeight: 0 }, true);
  14488. }
  14489. function brush(ctx, el, scope, isLast) {
  14490. var m = el.transform;
  14491. if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false)) {
  14492. el.__dirty &= ~REDRAW_BIT;
  14493. el.__isRendered = false;
  14494. return;
  14495. }
  14496. var clipPaths = el.__clipPaths;
  14497. var prevElClipPaths = scope.prevElClipPaths;
  14498. var forceSetTransform = false;
  14499. var forceSetStyle = false;
  14500. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  14501. if (prevElClipPaths && prevElClipPaths.length) {
  14502. flushPathDrawn(ctx, scope);
  14503. ctx.restore();
  14504. forceSetStyle = forceSetTransform = true;
  14505. scope.prevElClipPaths = null;
  14506. scope.allClipped = false;
  14507. scope.prevEl = null;
  14508. }
  14509. if (clipPaths && clipPaths.length) {
  14510. flushPathDrawn(ctx, scope);
  14511. ctx.save();
  14512. updateClipStatus(clipPaths, ctx, scope);
  14513. forceSetTransform = true;
  14514. }
  14515. scope.prevElClipPaths = clipPaths;
  14516. }
  14517. if (scope.allClipped) {
  14518. el.__isRendered = false;
  14519. return;
  14520. }
  14521. el.beforeBrush && el.beforeBrush();
  14522. el.innerBeforeBrush();
  14523. var prevEl = scope.prevEl;
  14524. if (!prevEl) {
  14525. forceSetStyle = forceSetTransform = true;
  14526. }
  14527. var canBatchPath = el instanceof Path
  14528. && el.autoBatch
  14529. && canPathBatch(el.style);
  14530. if (forceSetTransform || isTransformChanged(m, prevEl.transform)) {
  14531. flushPathDrawn(ctx, scope);
  14532. setContextTransform(ctx, el);
  14533. }
  14534. else if (!canBatchPath) {
  14535. flushPathDrawn(ctx, scope);
  14536. }
  14537. var style = getStyle(el, scope.inHover);
  14538. if (el instanceof Path) {
  14539. if (scope.lastDrawType !== DRAW_TYPE_PATH) {
  14540. forceSetStyle = true;
  14541. scope.lastDrawType = DRAW_TYPE_PATH;
  14542. }
  14543. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14544. if (!canBatchPath || (!scope.batchFill && !scope.batchStroke)) {
  14545. ctx.beginPath();
  14546. }
  14547. brushPath(ctx, el, style, canBatchPath);
  14548. if (canBatchPath) {
  14549. scope.batchFill = style.fill || '';
  14550. scope.batchStroke = style.stroke || '';
  14551. }
  14552. }
  14553. else {
  14554. if (el instanceof TSpan) {
  14555. if (scope.lastDrawType !== DRAW_TYPE_TEXT) {
  14556. forceSetStyle = true;
  14557. scope.lastDrawType = DRAW_TYPE_TEXT;
  14558. }
  14559. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14560. brushText(ctx, el, style);
  14561. }
  14562. else if (el instanceof ZRImage) {
  14563. if (scope.lastDrawType !== DRAW_TYPE_IMAGE) {
  14564. forceSetStyle = true;
  14565. scope.lastDrawType = DRAW_TYPE_IMAGE;
  14566. }
  14567. bindImageStyle(ctx, el, prevEl, forceSetStyle, scope);
  14568. brushImage(ctx, el, style);
  14569. }
  14570. else if (el.getTemporalDisplayables) {
  14571. if (scope.lastDrawType !== DRAW_TYPE_INCREMENTAL) {
  14572. forceSetStyle = true;
  14573. scope.lastDrawType = DRAW_TYPE_INCREMENTAL;
  14574. }
  14575. brushIncremental(ctx, el, scope);
  14576. }
  14577. }
  14578. if (canBatchPath && isLast) {
  14579. flushPathDrawn(ctx, scope);
  14580. }
  14581. el.innerAfterBrush();
  14582. el.afterBrush && el.afterBrush();
  14583. scope.prevEl = el;
  14584. el.__dirty = 0;
  14585. el.__isRendered = true;
  14586. }
  14587. function brushIncremental(ctx, el, scope) {
  14588. var displayables = el.getDisplayables();
  14589. var temporalDisplayables = el.getTemporalDisplayables();
  14590. ctx.save();
  14591. var innerScope = {
  14592. prevElClipPaths: null,
  14593. prevEl: null,
  14594. allClipped: false,
  14595. viewWidth: scope.viewWidth,
  14596. viewHeight: scope.viewHeight,
  14597. inHover: scope.inHover
  14598. };
  14599. var i;
  14600. var len;
  14601. for (i = el.getCursor(), len = displayables.length; i < len; i++) {
  14602. var displayable = displayables[i];
  14603. displayable.beforeBrush && displayable.beforeBrush();
  14604. displayable.innerBeforeBrush();
  14605. brush(ctx, displayable, innerScope, i === len - 1);
  14606. displayable.innerAfterBrush();
  14607. displayable.afterBrush && displayable.afterBrush();
  14608. innerScope.prevEl = displayable;
  14609. }
  14610. for (var i_1 = 0, len_1 = temporalDisplayables.length; i_1 < len_1; i_1++) {
  14611. var displayable = temporalDisplayables[i_1];
  14612. displayable.beforeBrush && displayable.beforeBrush();
  14613. displayable.innerBeforeBrush();
  14614. brush(ctx, displayable, innerScope, i_1 === len_1 - 1);
  14615. displayable.innerAfterBrush();
  14616. displayable.afterBrush && displayable.afterBrush();
  14617. innerScope.prevEl = displayable;
  14618. }
  14619. el.clearTemporalDisplayables();
  14620. el.notClear = true;
  14621. ctx.restore();
  14622. }
  14623. function createDom(id, painter, dpr) {
  14624. var newDom = platformApi.createCanvas();
  14625. var width = painter.getWidth();
  14626. var height = painter.getHeight();
  14627. var newDomStyle = newDom.style;
  14628. if (newDomStyle) {
  14629. newDomStyle.position = 'absolute';
  14630. newDomStyle.left = '0';
  14631. newDomStyle.top = '0';
  14632. newDomStyle.width = width + 'px';
  14633. newDomStyle.height = height + 'px';
  14634. newDom.setAttribute('data-zr-dom-id', id);
  14635. }
  14636. newDom.width = width * dpr;
  14637. newDom.height = height * dpr;
  14638. return newDom;
  14639. }
  14640. var Layer = (function (_super) {
  14641. __extends(Layer, _super);
  14642. function Layer(id, painter, dpr) {
  14643. var _this = _super.call(this) || this;
  14644. _this.motionBlur = false;
  14645. _this.lastFrameAlpha = 0.7;
  14646. _this.dpr = 1;
  14647. _this.virtual = false;
  14648. _this.config = {};
  14649. _this.incremental = false;
  14650. _this.zlevel = 0;
  14651. _this.maxRepaintRectCount = 5;
  14652. _this.__dirty = true;
  14653. _this.__firstTimePaint = true;
  14654. _this.__used = false;
  14655. _this.__drawIndex = 0;
  14656. _this.__startIndex = 0;
  14657. _this.__endIndex = 0;
  14658. _this.__prevStartIndex = null;
  14659. _this.__prevEndIndex = null;
  14660. var dom;
  14661. dpr = dpr || devicePixelRatio;
  14662. if (typeof id === 'string') {
  14663. dom = createDom(id, painter, dpr);
  14664. }
  14665. else if (isObject(id)) {
  14666. dom = id;
  14667. id = dom.id;
  14668. }
  14669. _this.id = id;
  14670. _this.dom = dom;
  14671. var domStyle = dom.style;
  14672. if (domStyle) {
  14673. disableUserSelect(dom);
  14674. dom.onselectstart = function () { return false; };
  14675. domStyle.padding = '0';
  14676. domStyle.margin = '0';
  14677. domStyle.borderWidth = '0';
  14678. }
  14679. _this.painter = painter;
  14680. _this.dpr = dpr;
  14681. return _this;
  14682. }
  14683. Layer.prototype.getElementCount = function () {
  14684. return this.__endIndex - this.__startIndex;
  14685. };
  14686. Layer.prototype.afterBrush = function () {
  14687. this.__prevStartIndex = this.__startIndex;
  14688. this.__prevEndIndex = this.__endIndex;
  14689. };
  14690. Layer.prototype.initContext = function () {
  14691. this.ctx = this.dom.getContext('2d');
  14692. this.ctx.dpr = this.dpr;
  14693. };
  14694. Layer.prototype.setUnpainted = function () {
  14695. this.__firstTimePaint = true;
  14696. };
  14697. Layer.prototype.createBackBuffer = function () {
  14698. var dpr = this.dpr;
  14699. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  14700. this.ctxBack = this.domBack.getContext('2d');
  14701. if (dpr !== 1) {
  14702. this.ctxBack.scale(dpr, dpr);
  14703. }
  14704. };
  14705. Layer.prototype.createRepaintRects = function (displayList, prevList, viewWidth, viewHeight) {
  14706. if (this.__firstTimePaint) {
  14707. this.__firstTimePaint = false;
  14708. return null;
  14709. }
  14710. var mergedRepaintRects = [];
  14711. var maxRepaintRectCount = this.maxRepaintRectCount;
  14712. var full = false;
  14713. var pendingRect = new BoundingRect(0, 0, 0, 0);
  14714. function addRectToMergePool(rect) {
  14715. if (!rect.isFinite() || rect.isZero()) {
  14716. return;
  14717. }
  14718. if (mergedRepaintRects.length === 0) {
  14719. var boundingRect = new BoundingRect(0, 0, 0, 0);
  14720. boundingRect.copy(rect);
  14721. mergedRepaintRects.push(boundingRect);
  14722. }
  14723. else {
  14724. var isMerged = false;
  14725. var minDeltaArea = Infinity;
  14726. var bestRectToMergeIdx = 0;
  14727. for (var i = 0; i < mergedRepaintRects.length; ++i) {
  14728. var mergedRect = mergedRepaintRects[i];
  14729. if (mergedRect.intersect(rect)) {
  14730. var pendingRect_1 = new BoundingRect(0, 0, 0, 0);
  14731. pendingRect_1.copy(mergedRect);
  14732. pendingRect_1.union(rect);
  14733. mergedRepaintRects[i] = pendingRect_1;
  14734. isMerged = true;
  14735. break;
  14736. }
  14737. else if (full) {
  14738. pendingRect.copy(rect);
  14739. pendingRect.union(mergedRect);
  14740. var aArea = rect.width * rect.height;
  14741. var bArea = mergedRect.width * mergedRect.height;
  14742. var pendingArea = pendingRect.width * pendingRect.height;
  14743. var deltaArea = pendingArea - aArea - bArea;
  14744. if (deltaArea < minDeltaArea) {
  14745. minDeltaArea = deltaArea;
  14746. bestRectToMergeIdx = i;
  14747. }
  14748. }
  14749. }
  14750. if (full) {
  14751. mergedRepaintRects[bestRectToMergeIdx].union(rect);
  14752. isMerged = true;
  14753. }
  14754. if (!isMerged) {
  14755. var boundingRect = new BoundingRect(0, 0, 0, 0);
  14756. boundingRect.copy(rect);
  14757. mergedRepaintRects.push(boundingRect);
  14758. }
  14759. if (!full) {
  14760. full = mergedRepaintRects.length >= maxRepaintRectCount;
  14761. }
  14762. }
  14763. }
  14764. for (var i = this.__startIndex; i < this.__endIndex; ++i) {
  14765. var el = displayList[i];
  14766. if (el) {
  14767. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  14768. var prevRect = el.__isRendered && ((el.__dirty & REDRAW_BIT) || !shouldPaint)
  14769. ? el.getPrevPaintRect()
  14770. : null;
  14771. if (prevRect) {
  14772. addRectToMergePool(prevRect);
  14773. }
  14774. var curRect = shouldPaint && ((el.__dirty & REDRAW_BIT) || !el.__isRendered)
  14775. ? el.getPaintRect()
  14776. : null;
  14777. if (curRect) {
  14778. addRectToMergePool(curRect);
  14779. }
  14780. }
  14781. }
  14782. for (var i = this.__prevStartIndex; i < this.__prevEndIndex; ++i) {
  14783. var el = prevList[i];
  14784. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  14785. if (el && (!shouldPaint || !el.__zr) && el.__isRendered) {
  14786. var prevRect = el.getPrevPaintRect();
  14787. if (prevRect) {
  14788. addRectToMergePool(prevRect);
  14789. }
  14790. }
  14791. }
  14792. var hasIntersections;
  14793. do {
  14794. hasIntersections = false;
  14795. for (var i = 0; i < mergedRepaintRects.length;) {
  14796. if (mergedRepaintRects[i].isZero()) {
  14797. mergedRepaintRects.splice(i, 1);
  14798. continue;
  14799. }
  14800. for (var j = i + 1; j < mergedRepaintRects.length;) {
  14801. if (mergedRepaintRects[i].intersect(mergedRepaintRects[j])) {
  14802. hasIntersections = true;
  14803. mergedRepaintRects[i].union(mergedRepaintRects[j]);
  14804. mergedRepaintRects.splice(j, 1);
  14805. }
  14806. else {
  14807. j++;
  14808. }
  14809. }
  14810. i++;
  14811. }
  14812. } while (hasIntersections);
  14813. this._paintRects = mergedRepaintRects;
  14814. return mergedRepaintRects;
  14815. };
  14816. Layer.prototype.debugGetPaintRects = function () {
  14817. return (this._paintRects || []).slice();
  14818. };
  14819. Layer.prototype.resize = function (width, height) {
  14820. var dpr = this.dpr;
  14821. var dom = this.dom;
  14822. var domStyle = dom.style;
  14823. var domBack = this.domBack;
  14824. if (domStyle) {
  14825. domStyle.width = width + 'px';
  14826. domStyle.height = height + 'px';
  14827. }
  14828. dom.width = width * dpr;
  14829. dom.height = height * dpr;
  14830. if (domBack) {
  14831. domBack.width = width * dpr;
  14832. domBack.height = height * dpr;
  14833. if (dpr !== 1) {
  14834. this.ctxBack.scale(dpr, dpr);
  14835. }
  14836. }
  14837. };
  14838. Layer.prototype.clear = function (clearAll, clearColor, repaintRects) {
  14839. var dom = this.dom;
  14840. var ctx = this.ctx;
  14841. var width = dom.width;
  14842. var height = dom.height;
  14843. clearColor = clearColor || this.clearColor;
  14844. var haveMotionBLur = this.motionBlur && !clearAll;
  14845. var lastFrameAlpha = this.lastFrameAlpha;
  14846. var dpr = this.dpr;
  14847. var self = this;
  14848. if (haveMotionBLur) {
  14849. if (!this.domBack) {
  14850. this.createBackBuffer();
  14851. }
  14852. this.ctxBack.globalCompositeOperation = 'copy';
  14853. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  14854. }
  14855. var domBack = this.domBack;
  14856. function doClear(x, y, width, height) {
  14857. ctx.clearRect(x, y, width, height);
  14858. if (clearColor && clearColor !== 'transparent') {
  14859. var clearColorGradientOrPattern = void 0;
  14860. if (isGradientObject(clearColor)) {
  14861. clearColorGradientOrPattern = clearColor.__canvasGradient
  14862. || getCanvasGradient(ctx, clearColor, {
  14863. x: 0,
  14864. y: 0,
  14865. width: width,
  14866. height: height
  14867. });
  14868. clearColor.__canvasGradient = clearColorGradientOrPattern;
  14869. }
  14870. else if (isImagePatternObject(clearColor)) {
  14871. clearColor.scaleX = clearColor.scaleX || dpr;
  14872. clearColor.scaleY = clearColor.scaleY || dpr;
  14873. clearColorGradientOrPattern = createCanvasPattern(ctx, clearColor, {
  14874. dirty: function () {
  14875. self.setUnpainted();
  14876. self.__painter.refresh();
  14877. }
  14878. });
  14879. }
  14880. ctx.save();
  14881. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  14882. ctx.fillRect(x, y, width, height);
  14883. ctx.restore();
  14884. }
  14885. if (haveMotionBLur) {
  14886. ctx.save();
  14887. ctx.globalAlpha = lastFrameAlpha;
  14888. ctx.drawImage(domBack, x, y, width, height);
  14889. ctx.restore();
  14890. }
  14891. }
  14892. if (!repaintRects || haveMotionBLur) {
  14893. doClear(0, 0, width, height);
  14894. }
  14895. else if (repaintRects.length) {
  14896. each(repaintRects, function (rect) {
  14897. doClear(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  14898. });
  14899. }
  14900. };
  14901. return Layer;
  14902. }(Eventful));
  14903. var HOVER_LAYER_ZLEVEL = 1e5;
  14904. var CANVAS_ZLEVEL = 314159;
  14905. var EL_AFTER_INCREMENTAL_INC = 0.01;
  14906. var INCREMENTAL_INC = 0.001;
  14907. function isLayerValid(layer) {
  14908. if (!layer) {
  14909. return false;
  14910. }
  14911. if (layer.__builtin__) {
  14912. return true;
  14913. }
  14914. if (typeof (layer.resize) !== 'function'
  14915. || typeof (layer.refresh) !== 'function') {
  14916. return false;
  14917. }
  14918. return true;
  14919. }
  14920. function createRoot(width, height) {
  14921. var domRoot = document.createElement('div');
  14922. domRoot.style.cssText = [
  14923. 'position:relative',
  14924. 'width:' + width + 'px',
  14925. 'height:' + height + 'px',
  14926. 'padding:0',
  14927. 'margin:0',
  14928. 'border-width:0'
  14929. ].join(';') + ';';
  14930. return domRoot;
  14931. }
  14932. var CanvasPainter = (function () {
  14933. function CanvasPainter(root, storage, opts, id) {
  14934. this.type = 'canvas';
  14935. this._zlevelList = [];
  14936. this._prevDisplayList = [];
  14937. this._layers = {};
  14938. this._layerConfig = {};
  14939. this._needsManuallyCompositing = false;
  14940. this.type = 'canvas';
  14941. var singleCanvas = !root.nodeName
  14942. || root.nodeName.toUpperCase() === 'CANVAS';
  14943. this._opts = opts = extend({}, opts || {});
  14944. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  14945. this._singleCanvas = singleCanvas;
  14946. this.root = root;
  14947. var rootStyle = root.style;
  14948. if (rootStyle) {
  14949. disableUserSelect(root);
  14950. root.innerHTML = '';
  14951. }
  14952. this.storage = storage;
  14953. var zlevelList = this._zlevelList;
  14954. this._prevDisplayList = [];
  14955. var layers = this._layers;
  14956. if (!singleCanvas) {
  14957. this._width = getSize(root, 0, opts);
  14958. this._height = getSize(root, 1, opts);
  14959. var domRoot = this._domRoot = createRoot(this._width, this._height);
  14960. root.appendChild(domRoot);
  14961. }
  14962. else {
  14963. var rootCanvas = root;
  14964. var width = rootCanvas.width;
  14965. var height = rootCanvas.height;
  14966. if (opts.width != null) {
  14967. width = opts.width;
  14968. }
  14969. if (opts.height != null) {
  14970. height = opts.height;
  14971. }
  14972. this.dpr = opts.devicePixelRatio || 1;
  14973. rootCanvas.width = width * this.dpr;
  14974. rootCanvas.height = height * this.dpr;
  14975. this._width = width;
  14976. this._height = height;
  14977. var mainLayer = new Layer(rootCanvas, this, this.dpr);
  14978. mainLayer.__builtin__ = true;
  14979. mainLayer.initContext();
  14980. layers[CANVAS_ZLEVEL] = mainLayer;
  14981. mainLayer.zlevel = CANVAS_ZLEVEL;
  14982. zlevelList.push(CANVAS_ZLEVEL);
  14983. this._domRoot = root;
  14984. }
  14985. }
  14986. CanvasPainter.prototype.getType = function () {
  14987. return 'canvas';
  14988. };
  14989. CanvasPainter.prototype.isSingleCanvas = function () {
  14990. return this._singleCanvas;
  14991. };
  14992. CanvasPainter.prototype.getViewportRoot = function () {
  14993. return this._domRoot;
  14994. };
  14995. CanvasPainter.prototype.getViewportRootOffset = function () {
  14996. var viewportRoot = this.getViewportRoot();
  14997. if (viewportRoot) {
  14998. return {
  14999. offsetLeft: viewportRoot.offsetLeft || 0,
  15000. offsetTop: viewportRoot.offsetTop || 0
  15001. };
  15002. }
  15003. };
  15004. CanvasPainter.prototype.refresh = function (paintAll) {
  15005. var list = this.storage.getDisplayList(true);
  15006. var prevList = this._prevDisplayList;
  15007. var zlevelList = this._zlevelList;
  15008. this._redrawId = Math.random();
  15009. this._paintList(list, prevList, paintAll, this._redrawId);
  15010. for (var i = 0; i < zlevelList.length; i++) {
  15011. var z = zlevelList[i];
  15012. var layer = this._layers[z];
  15013. if (!layer.__builtin__ && layer.refresh) {
  15014. var clearColor = i === 0 ? this._backgroundColor : null;
  15015. layer.refresh(clearColor);
  15016. }
  15017. }
  15018. if (this._opts.useDirtyRect) {
  15019. this._prevDisplayList = list.slice();
  15020. }
  15021. return this;
  15022. };
  15023. CanvasPainter.prototype.refreshHover = function () {
  15024. this._paintHoverList(this.storage.getDisplayList(false));
  15025. };
  15026. CanvasPainter.prototype._paintHoverList = function (list) {
  15027. var len = list.length;
  15028. var hoverLayer = this._hoverlayer;
  15029. hoverLayer && hoverLayer.clear();
  15030. if (!len) {
  15031. return;
  15032. }
  15033. var scope = {
  15034. inHover: true,
  15035. viewWidth: this._width,
  15036. viewHeight: this._height
  15037. };
  15038. var ctx;
  15039. for (var i = 0; i < len; i++) {
  15040. var el = list[i];
  15041. if (el.__inHover) {
  15042. if (!hoverLayer) {
  15043. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  15044. }
  15045. if (!ctx) {
  15046. ctx = hoverLayer.ctx;
  15047. ctx.save();
  15048. }
  15049. brush(ctx, el, scope, i === len - 1);
  15050. }
  15051. }
  15052. if (ctx) {
  15053. ctx.restore();
  15054. }
  15055. };
  15056. CanvasPainter.prototype.getHoverLayer = function () {
  15057. return this.getLayer(HOVER_LAYER_ZLEVEL);
  15058. };
  15059. CanvasPainter.prototype.paintOne = function (ctx, el) {
  15060. brushSingle(ctx, el);
  15061. };
  15062. CanvasPainter.prototype._paintList = function (list, prevList, paintAll, redrawId) {
  15063. if (this._redrawId !== redrawId) {
  15064. return;
  15065. }
  15066. paintAll = paintAll || false;
  15067. this._updateLayerStatus(list);
  15068. var _a = this._doPaintList(list, prevList, paintAll), finished = _a.finished, needsRefreshHover = _a.needsRefreshHover;
  15069. if (this._needsManuallyCompositing) {
  15070. this._compositeManually();
  15071. }
  15072. if (needsRefreshHover) {
  15073. this._paintHoverList(list);
  15074. }
  15075. if (!finished) {
  15076. var self_1 = this;
  15077. requestAnimationFrame$1(function () {
  15078. self_1._paintList(list, prevList, paintAll, redrawId);
  15079. });
  15080. }
  15081. else {
  15082. this.eachLayer(function (layer) {
  15083. layer.afterBrush && layer.afterBrush();
  15084. });
  15085. }
  15086. };
  15087. CanvasPainter.prototype._compositeManually = function () {
  15088. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  15089. var width = this._domRoot.width;
  15090. var height = this._domRoot.height;
  15091. ctx.clearRect(0, 0, width, height);
  15092. this.eachBuiltinLayer(function (layer) {
  15093. if (layer.virtual) {
  15094. ctx.drawImage(layer.dom, 0, 0, width, height);
  15095. }
  15096. });
  15097. };
  15098. CanvasPainter.prototype._doPaintList = function (list, prevList, paintAll) {
  15099. var _this = this;
  15100. var layerList = [];
  15101. var useDirtyRect = this._opts.useDirtyRect;
  15102. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  15103. var zlevel = this._zlevelList[zi];
  15104. var layer = this._layers[zlevel];
  15105. if (layer.__builtin__
  15106. && layer !== this._hoverlayer
  15107. && (layer.__dirty || paintAll)) {
  15108. layerList.push(layer);
  15109. }
  15110. }
  15111. var finished = true;
  15112. var needsRefreshHover = false;
  15113. var _loop_1 = function (k) {
  15114. var layer = layerList[k];
  15115. var ctx = layer.ctx;
  15116. var repaintRects = useDirtyRect
  15117. && layer.createRepaintRects(list, prevList, this_1._width, this_1._height);
  15118. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  15119. var useTimer = !paintAll && layer.incremental && Date.now;
  15120. var startTime = useTimer && Date.now();
  15121. var clearColor = layer.zlevel === this_1._zlevelList[0]
  15122. ? this_1._backgroundColor : null;
  15123. if (layer.__startIndex === layer.__endIndex) {
  15124. layer.clear(false, clearColor, repaintRects);
  15125. }
  15126. else if (start === layer.__startIndex) {
  15127. var firstEl = list[start];
  15128. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  15129. layer.clear(false, clearColor, repaintRects);
  15130. }
  15131. }
  15132. if (start === -1) {
  15133. console.error('For some unknown reason. drawIndex is -1');
  15134. start = layer.__startIndex;
  15135. }
  15136. var i;
  15137. var repaint = function (repaintRect) {
  15138. var scope = {
  15139. inHover: false,
  15140. allClipped: false,
  15141. prevEl: null,
  15142. viewWidth: _this._width,
  15143. viewHeight: _this._height
  15144. };
  15145. for (i = start; i < layer.__endIndex; i++) {
  15146. var el = list[i];
  15147. if (el.__inHover) {
  15148. needsRefreshHover = true;
  15149. }
  15150. _this._doPaintEl(el, layer, useDirtyRect, repaintRect, scope, i === layer.__endIndex - 1);
  15151. if (useTimer) {
  15152. var dTime = Date.now() - startTime;
  15153. if (dTime > 15) {
  15154. break;
  15155. }
  15156. }
  15157. }
  15158. if (scope.prevElClipPaths) {
  15159. ctx.restore();
  15160. }
  15161. };
  15162. if (repaintRects) {
  15163. if (repaintRects.length === 0) {
  15164. i = layer.__endIndex;
  15165. }
  15166. else {
  15167. var dpr = this_1.dpr;
  15168. for (var r = 0; r < repaintRects.length; ++r) {
  15169. var rect = repaintRects[r];
  15170. ctx.save();
  15171. ctx.beginPath();
  15172. ctx.rect(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  15173. ctx.clip();
  15174. repaint(rect);
  15175. ctx.restore();
  15176. }
  15177. }
  15178. }
  15179. else {
  15180. ctx.save();
  15181. repaint();
  15182. ctx.restore();
  15183. }
  15184. layer.__drawIndex = i;
  15185. if (layer.__drawIndex < layer.__endIndex) {
  15186. finished = false;
  15187. }
  15188. };
  15189. var this_1 = this;
  15190. for (var k = 0; k < layerList.length; k++) {
  15191. _loop_1(k);
  15192. }
  15193. if (env.wxa) {
  15194. each(this._layers, function (layer) {
  15195. if (layer && layer.ctx && layer.ctx.draw) {
  15196. layer.ctx.draw();
  15197. }
  15198. });
  15199. }
  15200. return {
  15201. finished: finished,
  15202. needsRefreshHover: needsRefreshHover
  15203. };
  15204. };
  15205. CanvasPainter.prototype._doPaintEl = function (el, currentLayer, useDirtyRect, repaintRect, scope, isLast) {
  15206. var ctx = currentLayer.ctx;
  15207. if (useDirtyRect) {
  15208. var paintRect = el.getPaintRect();
  15209. if (!repaintRect || paintRect && paintRect.intersect(repaintRect)) {
  15210. brush(ctx, el, scope, isLast);
  15211. el.setPrevPaintRect(paintRect);
  15212. }
  15213. }
  15214. else {
  15215. brush(ctx, el, scope, isLast);
  15216. }
  15217. };
  15218. CanvasPainter.prototype.getLayer = function (zlevel, virtual) {
  15219. if (this._singleCanvas && !this._needsManuallyCompositing) {
  15220. zlevel = CANVAS_ZLEVEL;
  15221. }
  15222. var layer = this._layers[zlevel];
  15223. if (!layer) {
  15224. layer = new Layer('zr_' + zlevel, this, this.dpr);
  15225. layer.zlevel = zlevel;
  15226. layer.__builtin__ = true;
  15227. if (this._layerConfig[zlevel]) {
  15228. merge(layer, this._layerConfig[zlevel], true);
  15229. }
  15230. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  15231. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  15232. }
  15233. if (virtual) {
  15234. layer.virtual = virtual;
  15235. }
  15236. this.insertLayer(zlevel, layer);
  15237. layer.initContext();
  15238. }
  15239. return layer;
  15240. };
  15241. CanvasPainter.prototype.insertLayer = function (zlevel, layer) {
  15242. var layersMap = this._layers;
  15243. var zlevelList = this._zlevelList;
  15244. var len = zlevelList.length;
  15245. var domRoot = this._domRoot;
  15246. var prevLayer = null;
  15247. var i = -1;
  15248. if (layersMap[zlevel]) {
  15249. {
  15250. logError('ZLevel ' + zlevel + ' has been used already');
  15251. }
  15252. return;
  15253. }
  15254. if (!isLayerValid(layer)) {
  15255. {
  15256. logError('Layer of zlevel ' + zlevel + ' is not valid');
  15257. }
  15258. return;
  15259. }
  15260. if (len > 0 && zlevel > zlevelList[0]) {
  15261. for (i = 0; i < len - 1; i++) {
  15262. if (zlevelList[i] < zlevel
  15263. && zlevelList[i + 1] > zlevel) {
  15264. break;
  15265. }
  15266. }
  15267. prevLayer = layersMap[zlevelList[i]];
  15268. }
  15269. zlevelList.splice(i + 1, 0, zlevel);
  15270. layersMap[zlevel] = layer;
  15271. if (!layer.virtual) {
  15272. if (prevLayer) {
  15273. var prevDom = prevLayer.dom;
  15274. if (prevDom.nextSibling) {
  15275. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  15276. }
  15277. else {
  15278. domRoot.appendChild(layer.dom);
  15279. }
  15280. }
  15281. else {
  15282. if (domRoot.firstChild) {
  15283. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  15284. }
  15285. else {
  15286. domRoot.appendChild(layer.dom);
  15287. }
  15288. }
  15289. }
  15290. layer.__painter = this;
  15291. };
  15292. CanvasPainter.prototype.eachLayer = function (cb, context) {
  15293. var zlevelList = this._zlevelList;
  15294. for (var i = 0; i < zlevelList.length; i++) {
  15295. var z = zlevelList[i];
  15296. cb.call(context, this._layers[z], z);
  15297. }
  15298. };
  15299. CanvasPainter.prototype.eachBuiltinLayer = function (cb, context) {
  15300. var zlevelList = this._zlevelList;
  15301. for (var i = 0; i < zlevelList.length; i++) {
  15302. var z = zlevelList[i];
  15303. var layer = this._layers[z];
  15304. if (layer.__builtin__) {
  15305. cb.call(context, layer, z);
  15306. }
  15307. }
  15308. };
  15309. CanvasPainter.prototype.eachOtherLayer = function (cb, context) {
  15310. var zlevelList = this._zlevelList;
  15311. for (var i = 0; i < zlevelList.length; i++) {
  15312. var z = zlevelList[i];
  15313. var layer = this._layers[z];
  15314. if (!layer.__builtin__) {
  15315. cb.call(context, layer, z);
  15316. }
  15317. }
  15318. };
  15319. CanvasPainter.prototype.getLayers = function () {
  15320. return this._layers;
  15321. };
  15322. CanvasPainter.prototype._updateLayerStatus = function (list) {
  15323. this.eachBuiltinLayer(function (layer, z) {
  15324. layer.__dirty = layer.__used = false;
  15325. });
  15326. function updatePrevLayer(idx) {
  15327. if (prevLayer) {
  15328. if (prevLayer.__endIndex !== idx) {
  15329. prevLayer.__dirty = true;
  15330. }
  15331. prevLayer.__endIndex = idx;
  15332. }
  15333. }
  15334. if (this._singleCanvas) {
  15335. for (var i_1 = 1; i_1 < list.length; i_1++) {
  15336. var el = list[i_1];
  15337. if (el.zlevel !== list[i_1 - 1].zlevel || el.incremental) {
  15338. this._needsManuallyCompositing = true;
  15339. break;
  15340. }
  15341. }
  15342. }
  15343. var prevLayer = null;
  15344. var incrementalLayerCount = 0;
  15345. var prevZlevel;
  15346. var i;
  15347. for (i = 0; i < list.length; i++) {
  15348. var el = list[i];
  15349. var zlevel = el.zlevel;
  15350. var layer = void 0;
  15351. if (prevZlevel !== zlevel) {
  15352. prevZlevel = zlevel;
  15353. incrementalLayerCount = 0;
  15354. }
  15355. if (el.incremental) {
  15356. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  15357. layer.incremental = true;
  15358. incrementalLayerCount = 1;
  15359. }
  15360. else {
  15361. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  15362. }
  15363. if (!layer.__builtin__) {
  15364. logError('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  15365. }
  15366. if (layer !== prevLayer) {
  15367. layer.__used = true;
  15368. if (layer.__startIndex !== i) {
  15369. layer.__dirty = true;
  15370. }
  15371. layer.__startIndex = i;
  15372. if (!layer.incremental) {
  15373. layer.__drawIndex = i;
  15374. }
  15375. else {
  15376. layer.__drawIndex = -1;
  15377. }
  15378. updatePrevLayer(i);
  15379. prevLayer = layer;
  15380. }
  15381. if ((el.__dirty & REDRAW_BIT) && !el.__inHover) {
  15382. layer.__dirty = true;
  15383. if (layer.incremental && layer.__drawIndex < 0) {
  15384. layer.__drawIndex = i;
  15385. }
  15386. }
  15387. }
  15388. updatePrevLayer(i);
  15389. this.eachBuiltinLayer(function (layer, z) {
  15390. if (!layer.__used && layer.getElementCount() > 0) {
  15391. layer.__dirty = true;
  15392. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  15393. }
  15394. if (layer.__dirty && layer.__drawIndex < 0) {
  15395. layer.__drawIndex = layer.__startIndex;
  15396. }
  15397. });
  15398. };
  15399. CanvasPainter.prototype.clear = function () {
  15400. this.eachBuiltinLayer(this._clearLayer);
  15401. return this;
  15402. };
  15403. CanvasPainter.prototype._clearLayer = function (layer) {
  15404. layer.clear();
  15405. };
  15406. CanvasPainter.prototype.setBackgroundColor = function (backgroundColor) {
  15407. this._backgroundColor = backgroundColor;
  15408. each(this._layers, function (layer) {
  15409. layer.setUnpainted();
  15410. });
  15411. };
  15412. CanvasPainter.prototype.configLayer = function (zlevel, config) {
  15413. if (config) {
  15414. var layerConfig = this._layerConfig;
  15415. if (!layerConfig[zlevel]) {
  15416. layerConfig[zlevel] = config;
  15417. }
  15418. else {
  15419. merge(layerConfig[zlevel], config, true);
  15420. }
  15421. for (var i = 0; i < this._zlevelList.length; i++) {
  15422. var _zlevel = this._zlevelList[i];
  15423. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  15424. var layer = this._layers[_zlevel];
  15425. merge(layer, layerConfig[zlevel], true);
  15426. }
  15427. }
  15428. }
  15429. };
  15430. CanvasPainter.prototype.delLayer = function (zlevel) {
  15431. var layers = this._layers;
  15432. var zlevelList = this._zlevelList;
  15433. var layer = layers[zlevel];
  15434. if (!layer) {
  15435. return;
  15436. }
  15437. layer.dom.parentNode.removeChild(layer.dom);
  15438. delete layers[zlevel];
  15439. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  15440. };
  15441. CanvasPainter.prototype.resize = function (width, height) {
  15442. if (!this._domRoot.style) {
  15443. if (width == null || height == null) {
  15444. return;
  15445. }
  15446. this._width = width;
  15447. this._height = height;
  15448. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  15449. }
  15450. else {
  15451. var domRoot = this._domRoot;
  15452. domRoot.style.display = 'none';
  15453. var opts = this._opts;
  15454. var root = this.root;
  15455. width != null && (opts.width = width);
  15456. height != null && (opts.height = height);
  15457. width = getSize(root, 0, opts);
  15458. height = getSize(root, 1, opts);
  15459. domRoot.style.display = '';
  15460. if (this._width !== width || height !== this._height) {
  15461. domRoot.style.width = width + 'px';
  15462. domRoot.style.height = height + 'px';
  15463. for (var id in this._layers) {
  15464. if (this._layers.hasOwnProperty(id)) {
  15465. this._layers[id].resize(width, height);
  15466. }
  15467. }
  15468. this.refresh(true);
  15469. }
  15470. this._width = width;
  15471. this._height = height;
  15472. }
  15473. return this;
  15474. };
  15475. CanvasPainter.prototype.clearLayer = function (zlevel) {
  15476. var layer = this._layers[zlevel];
  15477. if (layer) {
  15478. layer.clear();
  15479. }
  15480. };
  15481. CanvasPainter.prototype.dispose = function () {
  15482. this.root.innerHTML = '';
  15483. this.root =
  15484. this.storage =
  15485. this._domRoot =
  15486. this._layers = null;
  15487. };
  15488. CanvasPainter.prototype.getRenderedCanvas = function (opts) {
  15489. opts = opts || {};
  15490. if (this._singleCanvas && !this._compositeManually) {
  15491. return this._layers[CANVAS_ZLEVEL].dom;
  15492. }
  15493. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  15494. imageLayer.initContext();
  15495. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  15496. var ctx = imageLayer.ctx;
  15497. if (opts.pixelRatio <= this.dpr) {
  15498. this.refresh();
  15499. var width_1 = imageLayer.dom.width;
  15500. var height_1 = imageLayer.dom.height;
  15501. this.eachLayer(function (layer) {
  15502. if (layer.__builtin__) {
  15503. ctx.drawImage(layer.dom, 0, 0, width_1, height_1);
  15504. }
  15505. else if (layer.renderToCanvas) {
  15506. ctx.save();
  15507. layer.renderToCanvas(ctx);
  15508. ctx.restore();
  15509. }
  15510. });
  15511. }
  15512. else {
  15513. var scope = {
  15514. inHover: false,
  15515. viewWidth: this._width,
  15516. viewHeight: this._height
  15517. };
  15518. var displayList = this.storage.getDisplayList(true);
  15519. for (var i = 0, len = displayList.length; i < len; i++) {
  15520. var el = displayList[i];
  15521. brush(ctx, el, scope, i === len - 1);
  15522. }
  15523. }
  15524. return imageLayer.dom;
  15525. };
  15526. CanvasPainter.prototype.getWidth = function () {
  15527. return this._width;
  15528. };
  15529. CanvasPainter.prototype.getHeight = function () {
  15530. return this._height;
  15531. };
  15532. return CanvasPainter;
  15533. }());
  15534. var mathSin$4 = Math.sin;
  15535. var mathCos$4 = Math.cos;
  15536. var PI$5 = Math.PI;
  15537. var PI2$6 = Math.PI * 2;
  15538. var degree = 180 / PI$5;
  15539. var SVGPathRebuilder = (function () {
  15540. function SVGPathRebuilder() {
  15541. }
  15542. SVGPathRebuilder.prototype.reset = function (precision) {
  15543. this._start = true;
  15544. this._d = [];
  15545. this._str = '';
  15546. this._p = Math.pow(10, precision || 4);
  15547. };
  15548. SVGPathRebuilder.prototype.moveTo = function (x, y) {
  15549. this._add('M', x, y);
  15550. };
  15551. SVGPathRebuilder.prototype.lineTo = function (x, y) {
  15552. this._add('L', x, y);
  15553. };
  15554. SVGPathRebuilder.prototype.bezierCurveTo = function (x, y, x2, y2, x3, y3) {
  15555. this._add('C', x, y, x2, y2, x3, y3);
  15556. };
  15557. SVGPathRebuilder.prototype.quadraticCurveTo = function (x, y, x2, y2) {
  15558. this._add('Q', x, y, x2, y2);
  15559. };
  15560. SVGPathRebuilder.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  15561. this.ellipse(cx, cy, r, r, 0, startAngle, endAngle, anticlockwise);
  15562. };
  15563. SVGPathRebuilder.prototype.ellipse = function (cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise) {
  15564. var dTheta = endAngle - startAngle;
  15565. var clockwise = !anticlockwise;
  15566. var dThetaPositive = Math.abs(dTheta);
  15567. var isCircle = isAroundZero$1(dThetaPositive - PI2$6)
  15568. || (clockwise ? dTheta >= PI2$6 : -dTheta >= PI2$6);
  15569. var unifiedTheta = dTheta > 0 ? dTheta % PI2$6 : (dTheta % PI2$6 + PI2$6);
  15570. var large = false;
  15571. if (isCircle) {
  15572. large = true;
  15573. }
  15574. else if (isAroundZero$1(dThetaPositive)) {
  15575. large = false;
  15576. }
  15577. else {
  15578. large = (unifiedTheta >= PI$5) === !!clockwise;
  15579. }
  15580. var x0 = cx + rx * mathCos$4(startAngle);
  15581. var y0 = cy + ry * mathSin$4(startAngle);
  15582. if (this._start) {
  15583. this._add('M', x0, y0);
  15584. }
  15585. var xRot = Math.round(psi * degree);
  15586. if (isCircle) {
  15587. var p = 1 / this._p;
  15588. var dTheta_1 = (clockwise ? 1 : -1) * (PI2$6 - p);
  15589. this._add('A', rx, ry, xRot, 1, +clockwise, cx + rx * mathCos$4(startAngle + dTheta_1), cy + ry * mathSin$4(startAngle + dTheta_1));
  15590. if (p > 1e-2) {
  15591. this._add('A', rx, ry, xRot, 0, +clockwise, x0, y0);
  15592. }
  15593. }
  15594. else {
  15595. var x = cx + rx * mathCos$4(endAngle);
  15596. var y = cy + ry * mathSin$4(endAngle);
  15597. this._add('A', rx, ry, xRot, +large, +clockwise, x, y);
  15598. }
  15599. };
  15600. SVGPathRebuilder.prototype.rect = function (x, y, w, h) {
  15601. this._add('M', x, y);
  15602. this._add('l', w, 0);
  15603. this._add('l', 0, h);
  15604. this._add('l', -w, 0);
  15605. this._add('Z');
  15606. };
  15607. SVGPathRebuilder.prototype.closePath = function () {
  15608. if (this._d.length > 0) {
  15609. this._add('Z');
  15610. }
  15611. };
  15612. SVGPathRebuilder.prototype._add = function (cmd, a, b, c, d, e, f, g, h) {
  15613. var vals = [];
  15614. var p = this._p;
  15615. for (var i = 1; i < arguments.length; i++) {
  15616. var val = arguments[i];
  15617. if (isNaN(val)) {
  15618. this._invalid = true;
  15619. return;
  15620. }
  15621. vals.push(Math.round(val * p) / p);
  15622. }
  15623. this._d.push(cmd + vals.join(' '));
  15624. this._start = cmd === 'Z';
  15625. };
  15626. SVGPathRebuilder.prototype.generateStr = function () {
  15627. this._str = this._invalid ? '' : this._d.join('');
  15628. this._d = [];
  15629. };
  15630. SVGPathRebuilder.prototype.getStr = function () {
  15631. return this._str;
  15632. };
  15633. return SVGPathRebuilder;
  15634. }());
  15635. var NONE = 'none';
  15636. var mathRound$1 = Math.round;
  15637. function pathHasFill(style) {
  15638. var fill = style.fill;
  15639. return fill != null && fill !== NONE;
  15640. }
  15641. function pathHasStroke(style) {
  15642. var stroke = style.stroke;
  15643. return stroke != null && stroke !== NONE;
  15644. }
  15645. var strokeProps = ['lineCap', 'miterLimit', 'lineJoin'];
  15646. var svgStrokeProps = map(strokeProps, function (prop) { return "stroke-" + prop.toLowerCase(); });
  15647. function mapStyleToAttrs(updateAttr, style, el, forceUpdate) {
  15648. var opacity = style.opacity == null ? 1 : style.opacity;
  15649. if (el instanceof ZRImage) {
  15650. updateAttr('opacity', opacity);
  15651. return;
  15652. }
  15653. if (pathHasFill(style)) {
  15654. var fill = normalizeColor(style.fill);
  15655. updateAttr('fill', fill.color);
  15656. var fillOpacity = style.fillOpacity != null
  15657. ? style.fillOpacity * fill.opacity * opacity
  15658. : fill.opacity * opacity;
  15659. if (forceUpdate || fillOpacity < 1) {
  15660. updateAttr('fill-opacity', fillOpacity);
  15661. }
  15662. }
  15663. else {
  15664. updateAttr('fill', NONE);
  15665. }
  15666. if (pathHasStroke(style)) {
  15667. var stroke = normalizeColor(style.stroke);
  15668. updateAttr('stroke', stroke.color);
  15669. var strokeScale = style.strokeNoScale
  15670. ? el.getLineScale()
  15671. : 1;
  15672. var strokeWidth = (strokeScale ? (style.lineWidth || 0) / strokeScale : 0);
  15673. var strokeOpacity = style.strokeOpacity != null
  15674. ? style.strokeOpacity * stroke.opacity * opacity
  15675. : stroke.opacity * opacity;
  15676. var strokeFirst = style.strokeFirst;
  15677. if (forceUpdate || strokeWidth !== 1) {
  15678. updateAttr('stroke-width', strokeWidth);
  15679. }
  15680. if (forceUpdate || strokeFirst) {
  15681. updateAttr('paint-order', strokeFirst ? 'stroke' : 'fill');
  15682. }
  15683. if (forceUpdate || strokeOpacity < 1) {
  15684. updateAttr('stroke-opacity', strokeOpacity);
  15685. }
  15686. if (style.lineDash) {
  15687. var _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  15688. if (lineDash) {
  15689. lineDashOffset = mathRound$1(lineDashOffset || 0);
  15690. updateAttr('stroke-dasharray', lineDash.join(','));
  15691. if (lineDashOffset || forceUpdate) {
  15692. updateAttr('stroke-dashoffset', lineDashOffset);
  15693. }
  15694. }
  15695. }
  15696. else if (forceUpdate) {
  15697. updateAttr('stroke-dasharray', NONE);
  15698. }
  15699. for (var i = 0; i < strokeProps.length; i++) {
  15700. var propName = strokeProps[i];
  15701. if (forceUpdate || style[propName] !== DEFAULT_PATH_STYLE[propName]) {
  15702. var val = style[propName] || DEFAULT_PATH_STYLE[propName];
  15703. val && updateAttr(svgStrokeProps[i], val);
  15704. }
  15705. }
  15706. }
  15707. else if (forceUpdate) {
  15708. updateAttr('stroke', NONE);
  15709. }
  15710. }
  15711. var SVGNS = 'http://www.w3.org/2000/svg';
  15712. var XLINKNS = 'http://www.w3.org/1999/xlink';
  15713. var XMLNS = 'http://www.w3.org/2000/xmlns/';
  15714. var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
  15715. function createElement(name) {
  15716. return document.createElementNS(SVGNS, name);
  15717. }
  15718. function createVNode(tag, key, attrs, children, text) {
  15719. return {
  15720. tag: tag,
  15721. attrs: attrs || {},
  15722. children: children,
  15723. text: text,
  15724. key: key
  15725. };
  15726. }
  15727. function createElementOpen(name, attrs) {
  15728. var attrsStr = [];
  15729. if (attrs) {
  15730. for (var key in attrs) {
  15731. var val = attrs[key];
  15732. var part = key;
  15733. if (val === false) {
  15734. continue;
  15735. }
  15736. else if (val !== true && val != null) {
  15737. part += "=\"" + val + "\"";
  15738. }
  15739. attrsStr.push(part);
  15740. }
  15741. }
  15742. return "<" + name + " " + attrsStr.join(' ') + ">";
  15743. }
  15744. function createElementClose(name) {
  15745. return "</" + name + ">";
  15746. }
  15747. function vNodeToString(el, opts) {
  15748. opts = opts || {};
  15749. var S = opts.newline ? '\n' : '';
  15750. function convertElToString(el) {
  15751. var children = el.children, tag = el.tag, attrs = el.attrs;
  15752. return createElementOpen(tag, attrs)
  15753. + encodeHTML(el.text)
  15754. + (children ? "" + S + map(children, function (child) { return convertElToString(child); }).join(S) + S : '')
  15755. + createElementClose(tag);
  15756. }
  15757. return convertElToString(el);
  15758. }
  15759. function getCssString(selectorNodes, animationNodes, opts) {
  15760. opts = opts || {};
  15761. var S = opts.newline ? '\n' : '';
  15762. var bracketBegin = " {" + S;
  15763. var bracketEnd = S + "}";
  15764. var selectors = map(keys(selectorNodes), function (className) {
  15765. return className + bracketBegin + map(keys(selectorNodes[className]), function (attrName) {
  15766. return attrName + ":" + selectorNodes[className][attrName] + ";";
  15767. }).join(S) + bracketEnd;
  15768. }).join(S);
  15769. var animations = map(keys(animationNodes), function (animationName) {
  15770. return "@keyframes " + animationName + bracketBegin + map(keys(animationNodes[animationName]), function (percent) {
  15771. return percent + bracketBegin + map(keys(animationNodes[animationName][percent]), function (attrName) {
  15772. var val = animationNodes[animationName][percent][attrName];
  15773. if (attrName === 'd') {
  15774. val = "path(\"" + val + "\")";
  15775. }
  15776. return attrName + ":" + val + ";";
  15777. }).join(S) + bracketEnd;
  15778. }).join(S) + bracketEnd;
  15779. }).join(S);
  15780. if (!selectors && !animations) {
  15781. return '';
  15782. }
  15783. return ['<![CDATA[', selectors, animations, ']]>'].join(S);
  15784. }
  15785. function createBrushScope(zrId) {
  15786. return {
  15787. zrId: zrId,
  15788. shadowCache: {},
  15789. patternCache: {},
  15790. gradientCache: {},
  15791. clipPathCache: {},
  15792. defs: {},
  15793. cssNodes: {},
  15794. cssAnims: {},
  15795. cssClassIdx: 0,
  15796. cssAnimIdx: 0,
  15797. shadowIdx: 0,
  15798. gradientIdx: 0,
  15799. patternIdx: 0,
  15800. clipPathIdx: 0
  15801. };
  15802. }
  15803. function createSVGVNode(width, height, children, useViewBox) {
  15804. return createVNode('svg', 'root', {
  15805. 'width': width,
  15806. 'height': height,
  15807. 'xmlns': SVGNS,
  15808. 'xmlns:xlink': XLINKNS,
  15809. 'version': '1.1',
  15810. 'baseProfile': 'full',
  15811. 'viewBox': useViewBox ? "0 0 " + width + " " + height : false
  15812. }, children);
  15813. }
  15814. var EASING_MAP = {
  15815. cubicIn: '0.32,0,0.67,0',
  15816. cubicOut: '0.33,1,0.68,1',
  15817. cubicInOut: '0.65,0,0.35,1',
  15818. quadraticIn: '0.11,0,0.5,0',
  15819. quadraticOut: '0.5,1,0.89,1',
  15820. quadraticInOut: '0.45,0,0.55,1',
  15821. quarticIn: '0.5,0,0.75,0',
  15822. quarticOut: '0.25,1,0.5,1',
  15823. quarticInOut: '0.76,0,0.24,1',
  15824. quinticIn: '0.64,0,0.78,0',
  15825. quinticOut: '0.22,1,0.36,1',
  15826. quinticInOut: '0.83,0,0.17,1',
  15827. sinusoidalIn: '0.12,0,0.39,0',
  15828. sinusoidalOut: '0.61,1,0.88,1',
  15829. sinusoidalInOut: '0.37,0,0.63,1',
  15830. exponentialIn: '0.7,0,0.84,0',
  15831. exponentialOut: '0.16,1,0.3,1',
  15832. exponentialInOut: '0.87,0,0.13,1',
  15833. circularIn: '0.55,0,1,0.45',
  15834. circularOut: '0,0.55,0.45,1',
  15835. circularInOut: '0.85,0,0.15,1'
  15836. };
  15837. var transformOriginKey = 'transform-origin';
  15838. function buildPathString(el, kfShape, path) {
  15839. var shape = extend({}, el.shape);
  15840. extend(shape, kfShape);
  15841. el.buildPath(path, shape);
  15842. var svgPathBuilder = new SVGPathRebuilder();
  15843. svgPathBuilder.reset(getPathPrecision(el));
  15844. path.rebuildPath(svgPathBuilder, 1);
  15845. svgPathBuilder.generateStr();
  15846. return svgPathBuilder.getStr();
  15847. }
  15848. function setTransformOrigin(target, transform) {
  15849. var originX = transform.originX, originY = transform.originY;
  15850. if (originX || originY) {
  15851. target[transformOriginKey] = originX + "px " + originY + "px";
  15852. }
  15853. }
  15854. var ANIMATE_STYLE_MAP = {
  15855. fill: 'fill',
  15856. opacity: 'opacity',
  15857. lineWidth: 'stroke-width',
  15858. lineDashOffset: 'stroke-dashoffset'
  15859. };
  15860. function addAnimation(cssAnim, scope) {
  15861. var animationName = scope.zrId + '-ani-' + scope.cssAnimIdx++;
  15862. scope.cssAnims[animationName] = cssAnim;
  15863. return animationName;
  15864. }
  15865. function createCompoundPathCSSAnimation(el, attrs, scope) {
  15866. var paths = el.shape.paths;
  15867. var composedAnim = {};
  15868. var cssAnimationCfg;
  15869. var cssAnimationName;
  15870. each(paths, function (path) {
  15871. var subScope = createBrushScope(scope.zrId);
  15872. subScope.animation = true;
  15873. createCSSAnimation(path, {}, subScope, true);
  15874. var cssAnims = subScope.cssAnims;
  15875. var cssNodes = subScope.cssNodes;
  15876. var animNames = keys(cssAnims);
  15877. var len = animNames.length;
  15878. if (!len) {
  15879. return;
  15880. }
  15881. cssAnimationName = animNames[len - 1];
  15882. var lastAnim = cssAnims[cssAnimationName];
  15883. for (var percent in lastAnim) {
  15884. var kf = lastAnim[percent];
  15885. composedAnim[percent] = composedAnim[percent] || { d: '' };
  15886. composedAnim[percent].d += kf.d || '';
  15887. }
  15888. for (var className in cssNodes) {
  15889. var val = cssNodes[className].animation;
  15890. if (val.indexOf(cssAnimationName) >= 0) {
  15891. cssAnimationCfg = val;
  15892. }
  15893. }
  15894. });
  15895. if (!cssAnimationCfg) {
  15896. return;
  15897. }
  15898. attrs.d = false;
  15899. var animationName = addAnimation(composedAnim, scope);
  15900. return cssAnimationCfg.replace(cssAnimationName, animationName);
  15901. }
  15902. function getEasingFunc(easing) {
  15903. return isString(easing)
  15904. ? EASING_MAP[easing]
  15905. ? "cubic-bezier(" + EASING_MAP[easing] + ")"
  15906. : createCubicEasingFunc(easing) ? easing : ''
  15907. : '';
  15908. }
  15909. function createCSSAnimation(el, attrs, scope, onlyShape) {
  15910. var animators = el.animators;
  15911. var len = animators.length;
  15912. var cssAnimations = [];
  15913. if (el instanceof CompoundPath) {
  15914. var animationCfg = createCompoundPathCSSAnimation(el, attrs, scope);
  15915. if (animationCfg) {
  15916. cssAnimations.push(animationCfg);
  15917. }
  15918. else if (!len) {
  15919. return;
  15920. }
  15921. }
  15922. else if (!len) {
  15923. return;
  15924. }
  15925. var groupAnimators = {};
  15926. for (var i = 0; i < len; i++) {
  15927. var animator = animators[i];
  15928. var cfgArr = [animator.getMaxTime() / 1000 + 's'];
  15929. var easing = getEasingFunc(animator.getClip().easing);
  15930. var delay = animator.getDelay();
  15931. if (easing) {
  15932. cfgArr.push(easing);
  15933. }
  15934. else {
  15935. cfgArr.push('linear');
  15936. }
  15937. if (delay) {
  15938. cfgArr.push(delay / 1000 + 's');
  15939. }
  15940. if (animator.getLoop()) {
  15941. cfgArr.push('infinite');
  15942. }
  15943. var cfg = cfgArr.join(' ');
  15944. groupAnimators[cfg] = groupAnimators[cfg] || [cfg, []];
  15945. groupAnimators[cfg][1].push(animator);
  15946. }
  15947. function createSingleCSSAnimation(groupAnimator) {
  15948. var animators = groupAnimator[1];
  15949. var len = animators.length;
  15950. var transformKfs = {};
  15951. var shapeKfs = {};
  15952. var finalKfs = {};
  15953. var animationTimingFunctionAttrName = 'animation-timing-function';
  15954. function saveAnimatorTrackToCssKfs(animator, cssKfs, toCssAttrName) {
  15955. var tracks = animator.getTracks();
  15956. var maxTime = animator.getMaxTime();
  15957. for (var k = 0; k < tracks.length; k++) {
  15958. var track = tracks[k];
  15959. if (track.needsAnimate()) {
  15960. var kfs = track.keyframes;
  15961. var attrName = track.propName;
  15962. toCssAttrName && (attrName = toCssAttrName(attrName));
  15963. if (attrName) {
  15964. for (var i = 0; i < kfs.length; i++) {
  15965. var kf = kfs[i];
  15966. var percent = Math.round(kf.time / maxTime * 100) + '%';
  15967. var kfEasing = getEasingFunc(kf.easing);
  15968. var rawValue = kf.rawValue;
  15969. if (isString(rawValue) || isNumber(rawValue)) {
  15970. cssKfs[percent] = cssKfs[percent] || {};
  15971. cssKfs[percent][attrName] = kf.rawValue;
  15972. if (kfEasing) {
  15973. cssKfs[percent][animationTimingFunctionAttrName] = kfEasing;
  15974. }
  15975. }
  15976. }
  15977. }
  15978. }
  15979. }
  15980. }
  15981. for (var i = 0; i < len; i++) {
  15982. var animator = animators[i];
  15983. var targetProp = animator.targetName;
  15984. if (!targetProp) {
  15985. !onlyShape && saveAnimatorTrackToCssKfs(animator, transformKfs);
  15986. }
  15987. else if (targetProp === 'shape') {
  15988. saveAnimatorTrackToCssKfs(animator, shapeKfs);
  15989. }
  15990. }
  15991. for (var percent in transformKfs) {
  15992. var transform = {};
  15993. copyTransform(transform, el);
  15994. extend(transform, transformKfs[percent]);
  15995. var str = getSRTTransformString(transform);
  15996. var timingFunction = transformKfs[percent][animationTimingFunctionAttrName];
  15997. finalKfs[percent] = str ? {
  15998. transform: str
  15999. } : {};
  16000. setTransformOrigin(finalKfs[percent], transform);
  16001. if (timingFunction) {
  16002. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16003. }
  16004. }
  16005. var path;
  16006. var canAnimateShape = true;
  16007. for (var percent in shapeKfs) {
  16008. finalKfs[percent] = finalKfs[percent] || {};
  16009. var isFirst = !path;
  16010. var timingFunction = shapeKfs[percent][animationTimingFunctionAttrName];
  16011. if (isFirst) {
  16012. path = new PathProxy();
  16013. }
  16014. var len_1 = path.len();
  16015. path.reset();
  16016. finalKfs[percent].d = buildPathString(el, shapeKfs[percent], path);
  16017. var newLen = path.len();
  16018. if (!isFirst && len_1 !== newLen) {
  16019. canAnimateShape = false;
  16020. break;
  16021. }
  16022. if (timingFunction) {
  16023. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16024. }
  16025. }
  16026. if (!canAnimateShape) {
  16027. for (var percent in finalKfs) {
  16028. delete finalKfs[percent].d;
  16029. }
  16030. }
  16031. if (!onlyShape) {
  16032. for (var i = 0; i < len; i++) {
  16033. var animator = animators[i];
  16034. var targetProp = animator.targetName;
  16035. if (targetProp === 'style') {
  16036. saveAnimatorTrackToCssKfs(animator, finalKfs, function (propName) { return ANIMATE_STYLE_MAP[propName]; });
  16037. }
  16038. }
  16039. }
  16040. var percents = keys(finalKfs);
  16041. var allTransformOriginSame = true;
  16042. var transformOrigin;
  16043. for (var i = 1; i < percents.length; i++) {
  16044. var p0 = percents[i - 1];
  16045. var p1 = percents[i];
  16046. if (finalKfs[p0][transformOriginKey] !== finalKfs[p1][transformOriginKey]) {
  16047. allTransformOriginSame = false;
  16048. break;
  16049. }
  16050. transformOrigin = finalKfs[p0][transformOriginKey];
  16051. }
  16052. if (allTransformOriginSame && transformOrigin) {
  16053. for (var percent in finalKfs) {
  16054. if (finalKfs[percent][transformOriginKey]) {
  16055. delete finalKfs[percent][transformOriginKey];
  16056. }
  16057. }
  16058. attrs[transformOriginKey] = transformOrigin;
  16059. }
  16060. if (filter(percents, function (percent) { return keys(finalKfs[percent]).length > 0; }).length) {
  16061. var animationName = addAnimation(finalKfs, scope);
  16062. return animationName + " " + groupAnimator[0] + " both";
  16063. }
  16064. }
  16065. for (var key in groupAnimators) {
  16066. var animationCfg = createSingleCSSAnimation(groupAnimators[key]);
  16067. if (animationCfg) {
  16068. cssAnimations.push(animationCfg);
  16069. }
  16070. }
  16071. if (cssAnimations.length) {
  16072. var className = scope.zrId + '-cls-' + scope.cssClassIdx++;
  16073. scope.cssNodes['.' + className] = {
  16074. animation: cssAnimations.join(',')
  16075. };
  16076. attrs["class"] = className;
  16077. }
  16078. }
  16079. var round$1 = Math.round;
  16080. function isImageLike$1(val) {
  16081. return val && isString(val.src);
  16082. }
  16083. function isCanvasLike(val) {
  16084. return val && isFunction(val.toDataURL);
  16085. }
  16086. function setStyleAttrs(attrs, style, el, scope) {
  16087. mapStyleToAttrs(function (key, val) {
  16088. var isFillStroke = key === 'fill' || key === 'stroke';
  16089. if (isFillStroke && isGradient(val)) {
  16090. setGradient(style, attrs, key, scope);
  16091. }
  16092. else if (isFillStroke && isPattern(val)) {
  16093. setPattern(el, attrs, key, scope);
  16094. }
  16095. else {
  16096. attrs[key] = val;
  16097. }
  16098. }, style, el, false);
  16099. setShadow(el, attrs, scope);
  16100. }
  16101. function noRotateScale(m) {
  16102. return isAroundZero$1(m[0] - 1)
  16103. && isAroundZero$1(m[1])
  16104. && isAroundZero$1(m[2])
  16105. && isAroundZero$1(m[3] - 1);
  16106. }
  16107. function noTranslate(m) {
  16108. return isAroundZero$1(m[4]) && isAroundZero$1(m[5]);
  16109. }
  16110. function setTransform(attrs, m, compress) {
  16111. if (m && !(noTranslate(m) && noRotateScale(m))) {
  16112. var mul = compress ? 10 : 1e4;
  16113. attrs.transform = noRotateScale(m)
  16114. ? "translate(" + round$1(m[4] * mul) / mul + " " + round$1(m[5] * mul) / mul + ")" : getMatrixStr(m);
  16115. }
  16116. }
  16117. function convertPolyShape(shape, attrs, mul) {
  16118. var points = shape.points;
  16119. var strArr = [];
  16120. for (var i = 0; i < points.length; i++) {
  16121. strArr.push(round$1(points[i][0] * mul) / mul);
  16122. strArr.push(round$1(points[i][1] * mul) / mul);
  16123. }
  16124. attrs.points = strArr.join(' ');
  16125. }
  16126. function validatePolyShape(shape) {
  16127. return !shape.smooth;
  16128. }
  16129. function createAttrsConvert(desc) {
  16130. var normalizedDesc = map(desc, function (item) {
  16131. return (typeof item === 'string' ? [item, item] : item);
  16132. });
  16133. return function (shape, attrs, mul) {
  16134. for (var i = 0; i < normalizedDesc.length; i++) {
  16135. var item = normalizedDesc[i];
  16136. var val = shape[item[0]];
  16137. if (val != null) {
  16138. attrs[item[1]] = round$1(val * mul) / mul;
  16139. }
  16140. }
  16141. };
  16142. }
  16143. var buitinShapesDef = {
  16144. circle: [createAttrsConvert(['cx', 'cy', 'r'])],
  16145. polyline: [convertPolyShape, validatePolyShape],
  16146. polygon: [convertPolyShape, validatePolyShape]
  16147. };
  16148. function hasShapeAnimation(el) {
  16149. var animators = el.animators;
  16150. for (var i = 0; i < animators.length; i++) {
  16151. if (animators[i].targetName === 'shape') {
  16152. return true;
  16153. }
  16154. }
  16155. return false;
  16156. }
  16157. function brushSVGPath(el, scope) {
  16158. var style = el.style;
  16159. var shape = el.shape;
  16160. var builtinShpDef = buitinShapesDef[el.type];
  16161. var attrs = {};
  16162. var needsAnimate = scope.animation;
  16163. var svgElType = 'path';
  16164. var strokePercent = el.style.strokePercent;
  16165. var precision = (scope.compress && getPathPrecision(el)) || 4;
  16166. if (builtinShpDef
  16167. && !scope.willUpdate
  16168. && !(builtinShpDef[1] && !builtinShpDef[1](shape))
  16169. && !(needsAnimate && hasShapeAnimation(el))
  16170. && !(strokePercent < 1)) {
  16171. svgElType = el.type;
  16172. var mul = Math.pow(10, precision);
  16173. builtinShpDef[0](shape, attrs, mul);
  16174. }
  16175. else {
  16176. if (!el.path) {
  16177. el.createPathProxy();
  16178. }
  16179. var path = el.path;
  16180. if (el.shapeChanged()) {
  16181. path.beginPath();
  16182. el.buildPath(path, el.shape);
  16183. el.pathUpdated();
  16184. }
  16185. var pathVersion = path.getVersion();
  16186. var elExt = el;
  16187. var svgPathBuilder = elExt.__svgPathBuilder;
  16188. if (elExt.__svgPathVersion !== pathVersion
  16189. || !svgPathBuilder
  16190. || strokePercent !== elExt.__svgPathStrokePercent) {
  16191. if (!svgPathBuilder) {
  16192. svgPathBuilder = elExt.__svgPathBuilder = new SVGPathRebuilder();
  16193. }
  16194. svgPathBuilder.reset(precision);
  16195. path.rebuildPath(svgPathBuilder, strokePercent);
  16196. svgPathBuilder.generateStr();
  16197. elExt.__svgPathVersion = pathVersion;
  16198. elExt.__svgPathStrokePercent = strokePercent;
  16199. }
  16200. attrs.d = svgPathBuilder.getStr();
  16201. }
  16202. setTransform(attrs, el.transform);
  16203. setStyleAttrs(attrs, style, el, scope);
  16204. scope.animation && createCSSAnimation(el, attrs, scope);
  16205. return createVNode(svgElType, el.id + '', attrs);
  16206. }
  16207. function brushSVGImage(el, scope) {
  16208. var style = el.style;
  16209. var image = style.image;
  16210. if (image && !isString(image)) {
  16211. if (isImageLike$1(image)) {
  16212. image = image.src;
  16213. }
  16214. else if (isCanvasLike(image)) {
  16215. image = image.toDataURL();
  16216. }
  16217. }
  16218. if (!image) {
  16219. return;
  16220. }
  16221. var x = style.x || 0;
  16222. var y = style.y || 0;
  16223. var dw = style.width;
  16224. var dh = style.height;
  16225. var attrs = {
  16226. href: image,
  16227. width: dw,
  16228. height: dh
  16229. };
  16230. if (x) {
  16231. attrs.x = x;
  16232. }
  16233. if (y) {
  16234. attrs.y = y;
  16235. }
  16236. setTransform(attrs, el.transform);
  16237. setStyleAttrs(attrs, style, el, scope);
  16238. scope.animation && createCSSAnimation(el, attrs, scope);
  16239. return createVNode('image', el.id + '', attrs);
  16240. }
  16241. function brushSVGTSpan(el, scope) {
  16242. var style = el.style;
  16243. var text = style.text;
  16244. text != null && (text += '');
  16245. if (!text || isNaN(style.x) || isNaN(style.y)) {
  16246. return;
  16247. }
  16248. var font = style.font || DEFAULT_FONT;
  16249. var x = style.x || 0;
  16250. var y = adjustTextY(style.y || 0, getLineHeight(font), style.textBaseline);
  16251. var textAlign = TEXT_ALIGN_TO_ANCHOR[style.textAlign]
  16252. || style.textAlign;
  16253. var attrs = {
  16254. 'dominant-baseline': 'central',
  16255. 'text-anchor': textAlign
  16256. };
  16257. if (hasSeparateFont(style)) {
  16258. var separatedFontStr = '';
  16259. var fontStyle = style.fontStyle;
  16260. var fontSize = parseFontSize(style.fontSize);
  16261. if (!parseFloat(fontSize)) {
  16262. return;
  16263. }
  16264. var fontFamily = style.fontFamily || DEFAULT_FONT_FAMILY;
  16265. var fontWeight = style.fontWeight;
  16266. separatedFontStr += "font-size:" + fontSize + ";font-family:" + fontFamily + ";";
  16267. if (fontStyle && fontStyle !== 'normal') {
  16268. separatedFontStr += "font-style:" + fontStyle + ";";
  16269. }
  16270. if (fontWeight && fontWeight !== 'normal') {
  16271. separatedFontStr += "font-weight:" + fontWeight + ";";
  16272. }
  16273. attrs.style = separatedFontStr;
  16274. }
  16275. else {
  16276. attrs.style = "font: " + font;
  16277. }
  16278. if (text.match(/\s/)) {
  16279. attrs['xml:space'] = 'preserve';
  16280. }
  16281. if (x) {
  16282. attrs.x = x;
  16283. }
  16284. if (y) {
  16285. attrs.y = y;
  16286. }
  16287. setTransform(attrs, el.transform);
  16288. setStyleAttrs(attrs, style, el, scope);
  16289. scope.animation && createCSSAnimation(el, attrs, scope);
  16290. return createVNode('text', el.id + '', attrs, undefined, text);
  16291. }
  16292. function brush$1(el, scope) {
  16293. if (el instanceof Path) {
  16294. return brushSVGPath(el, scope);
  16295. }
  16296. else if (el instanceof ZRImage) {
  16297. return brushSVGImage(el, scope);
  16298. }
  16299. else if (el instanceof TSpan) {
  16300. return brushSVGTSpan(el, scope);
  16301. }
  16302. }
  16303. function setShadow(el, attrs, scope) {
  16304. var style = el.style;
  16305. if (hasShadow(style)) {
  16306. var shadowKey = getShadowKey(el);
  16307. var shadowCache = scope.shadowCache;
  16308. var shadowId = shadowCache[shadowKey];
  16309. if (!shadowId) {
  16310. var globalScale = el.getGlobalScale();
  16311. var scaleX = globalScale[0];
  16312. var scaleY = globalScale[1];
  16313. if (!scaleX || !scaleY) {
  16314. return;
  16315. }
  16316. var offsetX = style.shadowOffsetX || 0;
  16317. var offsetY = style.shadowOffsetY || 0;
  16318. var blur_1 = style.shadowBlur;
  16319. var _a = normalizeColor(style.shadowColor), opacity = _a.opacity, color = _a.color;
  16320. var stdDx = blur_1 / 2 / scaleX;
  16321. var stdDy = blur_1 / 2 / scaleY;
  16322. var stdDeviation = stdDx + ' ' + stdDy;
  16323. shadowId = scope.zrId + '-s' + scope.shadowIdx++;
  16324. scope.defs[shadowId] = createVNode('filter', shadowId, {
  16325. 'id': shadowId,
  16326. 'x': '-100%',
  16327. 'y': '-100%',
  16328. 'width': '300%',
  16329. 'height': '300%'
  16330. }, [
  16331. createVNode('feDropShadow', '', {
  16332. 'dx': offsetX / scaleX,
  16333. 'dy': offsetY / scaleY,
  16334. 'stdDeviation': stdDeviation,
  16335. 'flood-color': color,
  16336. 'flood-opacity': opacity
  16337. })
  16338. ]);
  16339. shadowCache[shadowKey] = shadowId;
  16340. }
  16341. attrs.filter = getIdURL(shadowId);
  16342. }
  16343. }
  16344. function setGradient(style, attrs, target, scope) {
  16345. var val = style[target];
  16346. var gradientTag;
  16347. var gradientAttrs = {
  16348. 'gradientUnits': val.global
  16349. ? 'userSpaceOnUse'
  16350. : 'objectBoundingBox'
  16351. };
  16352. if (isLinearGradient(val)) {
  16353. gradientTag = 'linearGradient';
  16354. gradientAttrs.x1 = val.x;
  16355. gradientAttrs.y1 = val.y;
  16356. gradientAttrs.x2 = val.x2;
  16357. gradientAttrs.y2 = val.y2;
  16358. }
  16359. else if (isRadialGradient(val)) {
  16360. gradientTag = 'radialGradient';
  16361. gradientAttrs.cx = retrieve2(val.x, 0.5);
  16362. gradientAttrs.cy = retrieve2(val.y, 0.5);
  16363. gradientAttrs.r = retrieve2(val.r, 0.5);
  16364. }
  16365. else {
  16366. {
  16367. logError('Illegal gradient type.');
  16368. }
  16369. return;
  16370. }
  16371. var colors = val.colorStops;
  16372. var colorStops = [];
  16373. for (var i = 0, len = colors.length; i < len; ++i) {
  16374. var offset = round4(colors[i].offset) * 100 + '%';
  16375. var stopColor = colors[i].color;
  16376. var _a = normalizeColor(stopColor), color = _a.color, opacity = _a.opacity;
  16377. var stopsAttrs = {
  16378. 'offset': offset
  16379. };
  16380. stopsAttrs['stop-color'] = color;
  16381. if (opacity < 1) {
  16382. stopsAttrs['stop-opacity'] = opacity;
  16383. }
  16384. colorStops.push(createVNode('stop', i + '', stopsAttrs));
  16385. }
  16386. var gradientVNode = createVNode(gradientTag, '', gradientAttrs, colorStops);
  16387. var gradientKey = vNodeToString(gradientVNode);
  16388. var gradientCache = scope.gradientCache;
  16389. var gradientId = gradientCache[gradientKey];
  16390. if (!gradientId) {
  16391. gradientId = scope.zrId + '-g' + scope.gradientIdx++;
  16392. gradientCache[gradientKey] = gradientId;
  16393. gradientAttrs.id = gradientId;
  16394. scope.defs[gradientId] = createVNode(gradientTag, gradientId, gradientAttrs, colorStops);
  16395. }
  16396. attrs[target] = getIdURL(gradientId);
  16397. }
  16398. function setPattern(el, attrs, target, scope) {
  16399. var val = el.style[target];
  16400. var patternAttrs = {
  16401. 'patternUnits': 'userSpaceOnUse'
  16402. };
  16403. var child;
  16404. if (isImagePattern(val)) {
  16405. var imageWidth_1 = val.imageWidth;
  16406. var imageHeight_1 = val.imageHeight;
  16407. var imageSrc = void 0;
  16408. var patternImage = val.image;
  16409. if (isString(patternImage)) {
  16410. imageSrc = patternImage;
  16411. }
  16412. else if (isImageLike$1(patternImage)) {
  16413. imageSrc = patternImage.src;
  16414. }
  16415. else if (isCanvasLike(patternImage)) {
  16416. imageSrc = patternImage.toDataURL();
  16417. }
  16418. if (typeof Image === 'undefined') {
  16419. var errMsg = 'Image width/height must been given explictly in svg-ssr renderer.';
  16420. assert(imageWidth_1, errMsg);
  16421. assert(imageHeight_1, errMsg);
  16422. }
  16423. else if (imageWidth_1 == null || imageHeight_1 == null) {
  16424. var setSizeToVNode_1 = function (vNode, img) {
  16425. if (vNode) {
  16426. var svgEl = vNode.elm;
  16427. var width = (vNode.attrs.width = imageWidth_1 || img.width);
  16428. var height = (vNode.attrs.height = imageHeight_1 || img.height);
  16429. if (svgEl) {
  16430. svgEl.setAttribute('width', width);
  16431. svgEl.setAttribute('height', height);
  16432. }
  16433. }
  16434. };
  16435. var createdImage = createOrUpdateImage(imageSrc, null, el, function (img) {
  16436. setSizeToVNode_1(patternVNode, img);
  16437. setSizeToVNode_1(child, img);
  16438. });
  16439. if (createdImage && createdImage.width && createdImage.height) {
  16440. imageWidth_1 = imageWidth_1 || createdImage.width;
  16441. imageHeight_1 = imageHeight_1 || createdImage.height;
  16442. }
  16443. }
  16444. child = createVNode('image', 'img', {
  16445. href: imageSrc,
  16446. width: imageWidth_1,
  16447. height: imageHeight_1
  16448. });
  16449. patternAttrs.width = imageWidth_1;
  16450. patternAttrs.height = imageHeight_1;
  16451. }
  16452. else if (val.svgElement) {
  16453. child = clone(val.svgElement);
  16454. patternAttrs.width = val.svgWidth;
  16455. patternAttrs.height = val.svgHeight;
  16456. }
  16457. if (!child) {
  16458. return;
  16459. }
  16460. patternAttrs.patternTransform = getSRTTransformString(val);
  16461. var patternVNode = createVNode('pattern', '', patternAttrs, [child]);
  16462. var patternKey = vNodeToString(patternVNode);
  16463. var patternCache = scope.patternCache;
  16464. var patternId = patternCache[patternKey];
  16465. if (!patternId) {
  16466. patternId = scope.zrId + '-p' + scope.patternIdx++;
  16467. patternCache[patternKey] = patternId;
  16468. patternAttrs.id = patternId;
  16469. patternVNode = scope.defs[patternId] = createVNode('pattern', patternId, patternAttrs, [child]);
  16470. }
  16471. attrs[target] = getIdURL(patternId);
  16472. }
  16473. function setClipPath(clipPath, attrs, scope) {
  16474. var clipPathCache = scope.clipPathCache, defs = scope.defs;
  16475. var clipPathId = clipPathCache[clipPath.id];
  16476. if (!clipPathId) {
  16477. clipPathId = scope.zrId + '-c' + scope.clipPathIdx++;
  16478. var clipPathAttrs = {
  16479. id: clipPathId
  16480. };
  16481. clipPathCache[clipPath.id] = clipPathId;
  16482. defs[clipPathId] = createVNode('clipPath', clipPathId, clipPathAttrs, [brushSVGPath(clipPath, scope)]);
  16483. }
  16484. attrs['clip-path'] = getIdURL(clipPathId);
  16485. }
  16486. function createTextNode(text) {
  16487. return document.createTextNode(text);
  16488. }
  16489. function insertBefore(parentNode, newNode, referenceNode) {
  16490. parentNode.insertBefore(newNode, referenceNode);
  16491. }
  16492. function removeChild(node, child) {
  16493. node.removeChild(child);
  16494. }
  16495. function appendChild(node, child) {
  16496. node.appendChild(child);
  16497. }
  16498. function parentNode(node) {
  16499. return node.parentNode;
  16500. }
  16501. function nextSibling(node) {
  16502. return node.nextSibling;
  16503. }
  16504. function setTextContent(node, text) {
  16505. node.textContent = text;
  16506. }
  16507. var colonChar = 58;
  16508. var xChar = 120;
  16509. var emptyNode = createVNode('', '');
  16510. function isUndef(s) {
  16511. return s === undefined;
  16512. }
  16513. function isDef(s) {
  16514. return s !== undefined;
  16515. }
  16516. function createKeyToOldIdx(children, beginIdx, endIdx) {
  16517. var map = {};
  16518. for (var i = beginIdx; i <= endIdx; ++i) {
  16519. var key = children[i].key;
  16520. if (key !== undefined) {
  16521. {
  16522. if (map[key] != null) {
  16523. console.error("Duplicate key " + key);
  16524. }
  16525. }
  16526. map[key] = i;
  16527. }
  16528. }
  16529. return map;
  16530. }
  16531. function sameVnode(vnode1, vnode2) {
  16532. var isSameKey = vnode1.key === vnode2.key;
  16533. var isSameTag = vnode1.tag === vnode2.tag;
  16534. return isSameTag && isSameKey;
  16535. }
  16536. function createElm(vnode) {
  16537. var i;
  16538. var children = vnode.children;
  16539. var tag = vnode.tag;
  16540. if (isDef(tag)) {
  16541. var elm = (vnode.elm = createElement(tag));
  16542. updateAttrs(emptyNode, vnode);
  16543. if (isArray(children)) {
  16544. for (i = 0; i < children.length; ++i) {
  16545. var ch = children[i];
  16546. if (ch != null) {
  16547. appendChild(elm, createElm(ch));
  16548. }
  16549. }
  16550. }
  16551. else if (isDef(vnode.text) && !isObject(vnode.text)) {
  16552. appendChild(elm, createTextNode(vnode.text));
  16553. }
  16554. }
  16555. else {
  16556. vnode.elm = createTextNode(vnode.text);
  16557. }
  16558. return vnode.elm;
  16559. }
  16560. function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
  16561. for (; startIdx <= endIdx; ++startIdx) {
  16562. var ch = vnodes[startIdx];
  16563. if (ch != null) {
  16564. insertBefore(parentElm, createElm(ch), before);
  16565. }
  16566. }
  16567. }
  16568. function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
  16569. for (; startIdx <= endIdx; ++startIdx) {
  16570. var ch = vnodes[startIdx];
  16571. if (ch != null) {
  16572. if (isDef(ch.tag)) {
  16573. var parent_1 = parentNode(ch.elm);
  16574. removeChild(parent_1, ch.elm);
  16575. }
  16576. else {
  16577. removeChild(parentElm, ch.elm);
  16578. }
  16579. }
  16580. }
  16581. }
  16582. function updateAttrs(oldVnode, vnode) {
  16583. var key;
  16584. var elm = vnode.elm;
  16585. var oldAttrs = oldVnode && oldVnode.attrs || {};
  16586. var attrs = vnode.attrs || {};
  16587. if (oldAttrs === attrs) {
  16588. return;
  16589. }
  16590. for (key in attrs) {
  16591. var cur = attrs[key];
  16592. var old = oldAttrs[key];
  16593. if (old !== cur) {
  16594. if (cur === true) {
  16595. elm.setAttribute(key, '');
  16596. }
  16597. else if (cur === false) {
  16598. elm.removeAttribute(key);
  16599. }
  16600. else {
  16601. if (key.charCodeAt(0) !== xChar) {
  16602. elm.setAttribute(key, cur);
  16603. }
  16604. else if (key === 'xmlns:xlink' || key === 'xmlns') {
  16605. elm.setAttributeNS(XMLNS, key, cur);
  16606. }
  16607. else if (key.charCodeAt(3) === colonChar) {
  16608. elm.setAttributeNS(XML_NAMESPACE, key, cur);
  16609. }
  16610. else if (key.charCodeAt(5) === colonChar) {
  16611. elm.setAttributeNS(XLINKNS, key, cur);
  16612. }
  16613. else {
  16614. elm.setAttribute(key, cur);
  16615. }
  16616. }
  16617. }
  16618. }
  16619. for (key in oldAttrs) {
  16620. if (!(key in attrs)) {
  16621. elm.removeAttribute(key);
  16622. }
  16623. }
  16624. }
  16625. function updateChildren(parentElm, oldCh, newCh) {
  16626. var oldStartIdx = 0;
  16627. var newStartIdx = 0;
  16628. var oldEndIdx = oldCh.length - 1;
  16629. var oldStartVnode = oldCh[0];
  16630. var oldEndVnode = oldCh[oldEndIdx];
  16631. var newEndIdx = newCh.length - 1;
  16632. var newStartVnode = newCh[0];
  16633. var newEndVnode = newCh[newEndIdx];
  16634. var oldKeyToIdx;
  16635. var idxInOld;
  16636. var elmToMove;
  16637. var before;
  16638. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  16639. if (oldStartVnode == null) {
  16640. oldStartVnode = oldCh[++oldStartIdx];
  16641. }
  16642. else if (oldEndVnode == null) {
  16643. oldEndVnode = oldCh[--oldEndIdx];
  16644. }
  16645. else if (newStartVnode == null) {
  16646. newStartVnode = newCh[++newStartIdx];
  16647. }
  16648. else if (newEndVnode == null) {
  16649. newEndVnode = newCh[--newEndIdx];
  16650. }
  16651. else if (sameVnode(oldStartVnode, newStartVnode)) {
  16652. patchVnode(oldStartVnode, newStartVnode);
  16653. oldStartVnode = oldCh[++oldStartIdx];
  16654. newStartVnode = newCh[++newStartIdx];
  16655. }
  16656. else if (sameVnode(oldEndVnode, newEndVnode)) {
  16657. patchVnode(oldEndVnode, newEndVnode);
  16658. oldEndVnode = oldCh[--oldEndIdx];
  16659. newEndVnode = newCh[--newEndIdx];
  16660. }
  16661. else if (sameVnode(oldStartVnode, newEndVnode)) {
  16662. patchVnode(oldStartVnode, newEndVnode);
  16663. insertBefore(parentElm, oldStartVnode.elm, nextSibling(oldEndVnode.elm));
  16664. oldStartVnode = oldCh[++oldStartIdx];
  16665. newEndVnode = newCh[--newEndIdx];
  16666. }
  16667. else if (sameVnode(oldEndVnode, newStartVnode)) {
  16668. patchVnode(oldEndVnode, newStartVnode);
  16669. insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
  16670. oldEndVnode = oldCh[--oldEndIdx];
  16671. newStartVnode = newCh[++newStartIdx];
  16672. }
  16673. else {
  16674. if (isUndef(oldKeyToIdx)) {
  16675. oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
  16676. }
  16677. idxInOld = oldKeyToIdx[newStartVnode.key];
  16678. if (isUndef(idxInOld)) {
  16679. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  16680. }
  16681. else {
  16682. elmToMove = oldCh[idxInOld];
  16683. if (elmToMove.tag !== newStartVnode.tag) {
  16684. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  16685. }
  16686. else {
  16687. patchVnode(elmToMove, newStartVnode);
  16688. oldCh[idxInOld] = undefined;
  16689. insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
  16690. }
  16691. }
  16692. newStartVnode = newCh[++newStartIdx];
  16693. }
  16694. }
  16695. if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
  16696. if (oldStartIdx > oldEndIdx) {
  16697. before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm;
  16698. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
  16699. }
  16700. else {
  16701. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
  16702. }
  16703. }
  16704. }
  16705. function patchVnode(oldVnode, vnode) {
  16706. var elm = (vnode.elm = oldVnode.elm);
  16707. var oldCh = oldVnode.children;
  16708. var ch = vnode.children;
  16709. if (oldVnode === vnode) {
  16710. return;
  16711. }
  16712. updateAttrs(oldVnode, vnode);
  16713. if (isUndef(vnode.text)) {
  16714. if (isDef(oldCh) && isDef(ch)) {
  16715. if (oldCh !== ch) {
  16716. updateChildren(elm, oldCh, ch);
  16717. }
  16718. }
  16719. else if (isDef(ch)) {
  16720. if (isDef(oldVnode.text)) {
  16721. setTextContent(elm, '');
  16722. }
  16723. addVnodes(elm, null, ch, 0, ch.length - 1);
  16724. }
  16725. else if (isDef(oldCh)) {
  16726. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  16727. }
  16728. else if (isDef(oldVnode.text)) {
  16729. setTextContent(elm, '');
  16730. }
  16731. }
  16732. else if (oldVnode.text !== vnode.text) {
  16733. if (isDef(oldCh)) {
  16734. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  16735. }
  16736. setTextContent(elm, vnode.text);
  16737. }
  16738. }
  16739. function patch(oldVnode, vnode) {
  16740. if (sameVnode(oldVnode, vnode)) {
  16741. patchVnode(oldVnode, vnode);
  16742. }
  16743. else {
  16744. var elm = oldVnode.elm;
  16745. var parent_2 = parentNode(elm);
  16746. createElm(vnode);
  16747. if (parent_2 !== null) {
  16748. insertBefore(parent_2, vnode.elm, nextSibling(elm));
  16749. removeVnodes(parent_2, [oldVnode], 0, 0);
  16750. }
  16751. }
  16752. return vnode;
  16753. }
  16754. var svgId = 0;
  16755. var SVGPainter = (function () {
  16756. function SVGPainter(root, storage, opts) {
  16757. this.type = 'svg';
  16758. this.refreshHover = createMethodNotSupport('refreshHover');
  16759. this.configLayer = createMethodNotSupport('configLayer');
  16760. this.storage = storage;
  16761. this._opts = opts = extend({}, opts);
  16762. this.root = root;
  16763. this._id = 'zr' + svgId++;
  16764. this._oldVNode = createSVGVNode(opts.width, opts.height);
  16765. if (root && !opts.ssr) {
  16766. var viewport = this._viewport = document.createElement('div');
  16767. viewport.style.cssText = 'position:relative;overflow:hidden';
  16768. var svgDom = this._svgDom = this._oldVNode.elm = createElement('svg');
  16769. updateAttrs(null, this._oldVNode);
  16770. viewport.appendChild(svgDom);
  16771. root.appendChild(viewport);
  16772. }
  16773. this.resize(opts.width, opts.height);
  16774. }
  16775. SVGPainter.prototype.getType = function () {
  16776. return this.type;
  16777. };
  16778. SVGPainter.prototype.getViewportRoot = function () {
  16779. return this._viewport;
  16780. };
  16781. SVGPainter.prototype.getViewportRootOffset = function () {
  16782. var viewportRoot = this.getViewportRoot();
  16783. if (viewportRoot) {
  16784. return {
  16785. offsetLeft: viewportRoot.offsetLeft || 0,
  16786. offsetTop: viewportRoot.offsetTop || 0
  16787. };
  16788. }
  16789. };
  16790. SVGPainter.prototype.getSvgDom = function () {
  16791. return this._svgDom;
  16792. };
  16793. SVGPainter.prototype.refresh = function () {
  16794. if (this.root) {
  16795. var vnode = this.renderToVNode({
  16796. willUpdate: true
  16797. });
  16798. vnode.attrs.style = 'position:absolute;left:0;top:0;user-select:none';
  16799. patch(this._oldVNode, vnode);
  16800. this._oldVNode = vnode;
  16801. }
  16802. };
  16803. SVGPainter.prototype.renderOneToVNode = function (el) {
  16804. return brush$1(el, createBrushScope(this._id));
  16805. };
  16806. SVGPainter.prototype.renderToVNode = function (opts) {
  16807. opts = opts || {};
  16808. var list = this.storage.getDisplayList(true);
  16809. var bgColor = this._backgroundColor;
  16810. var width = this._width;
  16811. var height = this._height;
  16812. var scope = createBrushScope(this._id);
  16813. scope.animation = opts.animation;
  16814. scope.willUpdate = opts.willUpdate;
  16815. scope.compress = opts.compress;
  16816. var children = [];
  16817. if (bgColor && bgColor !== 'none') {
  16818. var _a = normalizeColor(bgColor), color = _a.color, opacity = _a.opacity;
  16819. this._bgVNode = createVNode('rect', 'bg', {
  16820. width: width,
  16821. height: height,
  16822. x: '0',
  16823. y: '0',
  16824. id: '0',
  16825. fill: color,
  16826. 'fill-opacity': opacity
  16827. });
  16828. children.push(this._bgVNode);
  16829. }
  16830. else {
  16831. this._bgVNode = null;
  16832. }
  16833. var mainVNode = !opts.compress
  16834. ? (this._mainVNode = createVNode('g', 'main', {}, [])) : null;
  16835. this._paintList(list, scope, mainVNode ? mainVNode.children : children);
  16836. mainVNode && children.push(mainVNode);
  16837. var defs = map(keys(scope.defs), function (id) { return scope.defs[id]; });
  16838. if (defs.length) {
  16839. children.push(createVNode('defs', 'defs', {}, defs));
  16840. }
  16841. if (opts.animation) {
  16842. var animationCssStr = getCssString(scope.cssNodes, scope.cssAnims, { newline: true });
  16843. if (animationCssStr) {
  16844. var styleNode = createVNode('style', 'stl', {}, [], animationCssStr);
  16845. children.push(styleNode);
  16846. }
  16847. }
  16848. return createSVGVNode(width, height, children, opts.useViewBox);
  16849. };
  16850. SVGPainter.prototype.renderToString = function (opts) {
  16851. opts = opts || {};
  16852. return vNodeToString(this.renderToVNode({
  16853. animation: retrieve2(opts.cssAnimation, true),
  16854. willUpdate: false,
  16855. compress: true,
  16856. useViewBox: retrieve2(opts.useViewBox, true)
  16857. }), { newline: true });
  16858. };
  16859. SVGPainter.prototype.setBackgroundColor = function (backgroundColor) {
  16860. this._backgroundColor = backgroundColor;
  16861. var bgVNode = this._bgVNode;
  16862. if (bgVNode && bgVNode.elm) {
  16863. var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
  16864. bgVNode.elm.setAttribute('fill', color);
  16865. if (opacity < 1) {
  16866. bgVNode.elm.setAttribute('fill-opacity', opacity);
  16867. }
  16868. }
  16869. };
  16870. SVGPainter.prototype.getSvgRoot = function () {
  16871. return this._mainVNode && this._mainVNode.elm;
  16872. };
  16873. SVGPainter.prototype._paintList = function (list, scope, out) {
  16874. var listLen = list.length;
  16875. var clipPathsGroupsStack = [];
  16876. var clipPathsGroupsStackDepth = 0;
  16877. var currentClipPathGroup;
  16878. var prevClipPaths;
  16879. var clipGroupNodeIdx = 0;
  16880. for (var i = 0; i < listLen; i++) {
  16881. var displayable = list[i];
  16882. if (!displayable.invisible) {
  16883. var clipPaths = displayable.__clipPaths;
  16884. var len = clipPaths && clipPaths.length || 0;
  16885. var prevLen = prevClipPaths && prevClipPaths.length || 0;
  16886. var lca = void 0;
  16887. for (lca = Math.max(len - 1, prevLen - 1); lca >= 0; lca--) {
  16888. if (clipPaths && prevClipPaths
  16889. && clipPaths[lca] === prevClipPaths[lca]) {
  16890. break;
  16891. }
  16892. }
  16893. for (var i_1 = prevLen - 1; i_1 > lca; i_1--) {
  16894. clipPathsGroupsStackDepth--;
  16895. currentClipPathGroup = clipPathsGroupsStack[clipPathsGroupsStackDepth - 1];
  16896. }
  16897. for (var i_2 = lca + 1; i_2 < len; i_2++) {
  16898. var groupAttrs = {};
  16899. setClipPath(clipPaths[i_2], groupAttrs, scope);
  16900. var g = createVNode('g', 'clip-g-' + clipGroupNodeIdx++, groupAttrs, []);
  16901. (currentClipPathGroup ? currentClipPathGroup.children : out).push(g);
  16902. clipPathsGroupsStack[clipPathsGroupsStackDepth++] = g;
  16903. currentClipPathGroup = g;
  16904. }
  16905. prevClipPaths = clipPaths;
  16906. var ret = brush$1(displayable, scope);
  16907. if (ret) {
  16908. (currentClipPathGroup ? currentClipPathGroup.children : out).push(ret);
  16909. }
  16910. }
  16911. }
  16912. };
  16913. SVGPainter.prototype.resize = function (width, height) {
  16914. var opts = this._opts;
  16915. var root = this.root;
  16916. var viewport = this._viewport;
  16917. width != null && (opts.width = width);
  16918. height != null && (opts.height = height);
  16919. if (root && viewport) {
  16920. viewport.style.display = 'none';
  16921. width = getSize(root, 0, opts);
  16922. height = getSize(root, 1, opts);
  16923. viewport.style.display = '';
  16924. }
  16925. if (this._width !== width || this._height !== height) {
  16926. this._width = width;
  16927. this._height = height;
  16928. if (viewport) {
  16929. var viewportStyle = viewport.style;
  16930. viewportStyle.width = width + 'px';
  16931. viewportStyle.height = height + 'px';
  16932. }
  16933. var svgDom = this._svgDom;
  16934. if (svgDom) {
  16935. svgDom.setAttribute('width', width);
  16936. svgDom.setAttribute('height', height);
  16937. }
  16938. }
  16939. };
  16940. SVGPainter.prototype.getWidth = function () {
  16941. return this._width;
  16942. };
  16943. SVGPainter.prototype.getHeight = function () {
  16944. return this._height;
  16945. };
  16946. SVGPainter.prototype.dispose = function () {
  16947. if (this.root) {
  16948. this.root.innerHTML = '';
  16949. }
  16950. this._svgDom =
  16951. this._viewport =
  16952. this.storage =
  16953. this._oldVNode =
  16954. this._bgVNode =
  16955. this._mainVNode = null;
  16956. };
  16957. SVGPainter.prototype.clear = function () {
  16958. if (this._svgDom) {
  16959. this._svgDom.innerHTML = null;
  16960. }
  16961. this._oldVNode = null;
  16962. };
  16963. SVGPainter.prototype.toDataURL = function (base64) {
  16964. var str = encodeURIComponent(this.renderToString());
  16965. var prefix = 'data:image/svg+xml;';
  16966. if (base64) {
  16967. str = encodeBase64(str);
  16968. return str && prefix + 'base64,' + str;
  16969. }
  16970. return prefix + 'charset=UTF-8,' + str;
  16971. };
  16972. return SVGPainter;
  16973. }());
  16974. function createMethodNotSupport(method) {
  16975. return function () {
  16976. {
  16977. logError('In SVG mode painter not support method "' + method + '"');
  16978. }
  16979. };
  16980. }
  16981. registerPainter('canvas', CanvasPainter);
  16982. registerPainter('svg', SVGPainter);
  16983. exports.Arc = Arc;
  16984. exports.ArcShape = ArcShape;
  16985. exports.BezierCurve = BezierCurve;
  16986. exports.BezierCurveShape = BezierCurveShape;
  16987. exports.BoundingRect = BoundingRect;
  16988. exports.Circle = Circle;
  16989. exports.CircleShape = CircleShape;
  16990. exports.CompoundPath = CompoundPath;
  16991. exports.Displayable = Displayable;
  16992. exports.Droplet = Droplet;
  16993. exports.DropletShape = DropletShape;
  16994. exports.Element = Element;
  16995. exports.Ellipse = Ellipse;
  16996. exports.EllipseShape = EllipseShape;
  16997. exports.Group = Group;
  16998. exports.Heart = Heart;
  16999. exports.HeartShape = HeartShape;
  17000. exports.Image = ZRImage;
  17001. exports.IncrementalDisplayable = IncrementalDisplayable;
  17002. exports.Isogon = Isogon;
  17003. exports.IsogonShape = IsogonShape;
  17004. exports.Line = Line;
  17005. exports.LineShape = LineShape;
  17006. exports.LinearGradient = LinearGradient;
  17007. exports.OrientedBoundingRect = OrientedBoundingRect;
  17008. exports.Path = Path;
  17009. exports.Pattern = Pattern;
  17010. exports.Point = Point;
  17011. exports.Polygon = Polygon;
  17012. exports.PolygonShape = PolygonShape;
  17013. exports.Polyline = Polyline;
  17014. exports.PolylineShape = PolylineShape;
  17015. exports.RadialGradient = RadialGradient;
  17016. exports.Rect = Rect;
  17017. exports.RectShape = RectShape;
  17018. exports.Ring = Ring;
  17019. exports.RingShape = RingShape;
  17020. exports.Rose = Rose;
  17021. exports.RoseShape = RoseShape;
  17022. exports.Sector = Sector;
  17023. exports.SectorShape = SectorShape;
  17024. exports.Star = Star;
  17025. exports.StarShape = StarShape;
  17026. exports.TSpan = TSpan;
  17027. exports.Text = ZRText;
  17028. exports.Trochoid = Trochoid;
  17029. exports.TrochoidShape = TrochoidShape;
  17030. exports.color = color;
  17031. exports.dispose = dispose;
  17032. exports.disposeAll = disposeAll;
  17033. exports.getInstance = getInstance;
  17034. exports.init = init;
  17035. exports.matrix = matrix;
  17036. exports.morph = morphPath$1;
  17037. exports.parseSVG = parseSVG;
  17038. exports.path = path;
  17039. exports.registerPainter = registerPainter;
  17040. exports.setPlatformAPI = setPlatformAPI;
  17041. exports.showDebugDirtyRect = showDebugDirtyRect;
  17042. exports.util = util;
  17043. exports.vector = vector;
  17044. exports.version = version;
  17045. Object.defineProperty(exports, '__esModule', { value: true });
  17046. })));
  17047. //# sourceMappingURL=zrender.js.map