zrender.js 633 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.zrender = {}));
  5. }(this, (function (exports) { 'use strict';
  6. var Browser = (function () {
  7. function Browser() {
  8. this.firefox = false;
  9. this.ie = false;
  10. this.edge = false;
  11. this.newEdge = false;
  12. this.weChat = false;
  13. }
  14. return Browser;
  15. }());
  16. var Env = (function () {
  17. function Env() {
  18. this.browser = new Browser();
  19. this.node = false;
  20. this.wxa = false;
  21. this.worker = false;
  22. this.svgSupported = false;
  23. this.touchEventsSupported = false;
  24. this.pointerEventsSupported = false;
  25. this.domSupported = false;
  26. this.transformSupported = false;
  27. this.transform3dSupported = false;
  28. this.hasGlobalWindow = typeof window !== 'undefined';
  29. }
  30. return Env;
  31. }());
  32. var env = new Env();
  33. if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
  34. env.wxa = true;
  35. env.touchEventsSupported = true;
  36. }
  37. else if (typeof document === 'undefined' && typeof self !== 'undefined') {
  38. env.worker = true;
  39. }
  40. else if (typeof navigator === 'undefined') {
  41. env.node = true;
  42. env.svgSupported = true;
  43. }
  44. else {
  45. detect(navigator.userAgent, env);
  46. }
  47. function detect(ua, env) {
  48. var browser = env.browser;
  49. var firefox = ua.match(/Firefox\/([\d.]+)/);
  50. var ie = ua.match(/MSIE\s([\d.]+)/)
  51. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  52. var edge = ua.match(/Edge?\/([\d.]+)/);
  53. var weChat = (/micromessenger/i).test(ua);
  54. if (firefox) {
  55. browser.firefox = true;
  56. browser.version = firefox[1];
  57. }
  58. if (ie) {
  59. browser.ie = true;
  60. browser.version = ie[1];
  61. }
  62. if (edge) {
  63. browser.edge = true;
  64. browser.version = edge[1];
  65. browser.newEdge = +edge[1].split('.')[0] > 18;
  66. }
  67. if (weChat) {
  68. browser.weChat = true;
  69. }
  70. env.svgSupported = typeof SVGRect !== 'undefined';
  71. env.touchEventsSupported = 'ontouchstart' in window && !browser.ie && !browser.edge;
  72. env.pointerEventsSupported = 'onpointerdown' in window
  73. && (browser.edge || (browser.ie && +browser.version >= 11));
  74. env.domSupported = typeof document !== 'undefined';
  75. var style = document.documentElement.style;
  76. env.transform3dSupported = ((browser.ie && 'transition' in style)
  77. || browser.edge
  78. || (('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()))
  79. || 'MozPerspective' in style)
  80. && !('OTransition' in style);
  81. env.transformSupported = env.transform3dSupported
  82. || (browser.ie && +browser.version >= 9);
  83. }
  84. var DEFAULT_FONT_SIZE = 12;
  85. var DEFAULT_FONT_FAMILY = 'sans-serif';
  86. var DEFAULT_FONT = DEFAULT_FONT_SIZE + "px " + DEFAULT_FONT_FAMILY;
  87. var OFFSET = 20;
  88. var SCALE = 100;
  89. var defaultWidthMapStr = "007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N";
  90. function getTextWidthMap(mapStr) {
  91. var map = {};
  92. if (typeof JSON === 'undefined') {
  93. return map;
  94. }
  95. for (var i = 0; i < mapStr.length; i++) {
  96. var char = String.fromCharCode(i + 32);
  97. var size = (mapStr.charCodeAt(i) - OFFSET) / SCALE;
  98. map[char] = size;
  99. }
  100. return map;
  101. }
  102. var DEFAULT_TEXT_WIDTH_MAP = getTextWidthMap(defaultWidthMapStr);
  103. var platformApi = {
  104. createCanvas: function () {
  105. return typeof document !== 'undefined'
  106. && document.createElement('canvas');
  107. },
  108. measureText: (function () {
  109. var _ctx;
  110. var _cachedFont;
  111. return function (text, font) {
  112. if (!_ctx) {
  113. var canvas = platformApi.createCanvas();
  114. _ctx = canvas && canvas.getContext('2d');
  115. }
  116. if (_ctx) {
  117. if (_cachedFont !== font) {
  118. _cachedFont = _ctx.font = font || DEFAULT_FONT;
  119. }
  120. return _ctx.measureText(text);
  121. }
  122. else {
  123. text = text || '';
  124. font = font || DEFAULT_FONT;
  125. var res = /(\d+)px/.exec(font);
  126. var fontSize = res && +res[1] || DEFAULT_FONT_SIZE;
  127. var width = 0;
  128. if (font.indexOf('mono') >= 0) {
  129. width = fontSize * text.length;
  130. }
  131. else {
  132. for (var i = 0; i < text.length; i++) {
  133. var preCalcWidth = DEFAULT_TEXT_WIDTH_MAP[text[i]];
  134. width += preCalcWidth == null ? fontSize : (preCalcWidth * fontSize);
  135. }
  136. }
  137. return { width: width };
  138. }
  139. };
  140. })(),
  141. loadImage: function (src, onload, onerror) {
  142. var image = new Image();
  143. image.onload = onload;
  144. image.onerror = onerror;
  145. image.src = src;
  146. return image;
  147. }
  148. };
  149. function setPlatformAPI(newPlatformApis) {
  150. for (var key in platformApi) {
  151. if (newPlatformApis[key]) {
  152. platformApi[key] = newPlatformApis[key];
  153. }
  154. }
  155. }
  156. var BUILTIN_OBJECT = reduce([
  157. 'Function',
  158. 'RegExp',
  159. 'Date',
  160. 'Error',
  161. 'CanvasGradient',
  162. 'CanvasPattern',
  163. 'Image',
  164. 'Canvas'
  165. ], function (obj, val) {
  166. obj['[object ' + val + ']'] = true;
  167. return obj;
  168. }, {});
  169. var TYPED_ARRAY = reduce([
  170. 'Int8',
  171. 'Uint8',
  172. 'Uint8Clamped',
  173. 'Int16',
  174. 'Uint16',
  175. 'Int32',
  176. 'Uint32',
  177. 'Float32',
  178. 'Float64'
  179. ], function (obj, val) {
  180. obj['[object ' + val + 'Array]'] = true;
  181. return obj;
  182. }, {});
  183. var objToString = Object.prototype.toString;
  184. var arrayProto = Array.prototype;
  185. var nativeForEach = arrayProto.forEach;
  186. var nativeFilter = arrayProto.filter;
  187. var nativeSlice = arrayProto.slice;
  188. var nativeMap = arrayProto.map;
  189. var ctorFunction = function () { }.constructor;
  190. var protoFunction = ctorFunction ? ctorFunction.prototype : null;
  191. var protoKey = '__proto__';
  192. var idStart = 0x0907;
  193. function guid() {
  194. return idStart++;
  195. }
  196. function logError() {
  197. var args = [];
  198. for (var _i = 0; _i < arguments.length; _i++) {
  199. args[_i] = arguments[_i];
  200. }
  201. if (typeof console !== 'undefined') {
  202. console.error.apply(console, args);
  203. }
  204. }
  205. function clone(source) {
  206. if (source == null || typeof source !== 'object') {
  207. return source;
  208. }
  209. var result = source;
  210. var typeStr = objToString.call(source);
  211. if (typeStr === '[object Array]') {
  212. if (!isPrimitive(source)) {
  213. result = [];
  214. for (var i = 0, len = source.length; i < len; i++) {
  215. result[i] = clone(source[i]);
  216. }
  217. }
  218. }
  219. else if (TYPED_ARRAY[typeStr]) {
  220. if (!isPrimitive(source)) {
  221. var Ctor = source.constructor;
  222. if (Ctor.from) {
  223. result = Ctor.from(source);
  224. }
  225. else {
  226. result = new Ctor(source.length);
  227. for (var i = 0, len = source.length; i < len; i++) {
  228. result[i] = source[i];
  229. }
  230. }
  231. }
  232. }
  233. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  234. result = {};
  235. for (var key in source) {
  236. if (source.hasOwnProperty(key) && key !== protoKey) {
  237. result[key] = clone(source[key]);
  238. }
  239. }
  240. }
  241. return result;
  242. }
  243. function merge(target, source, overwrite) {
  244. if (!isObject(source) || !isObject(target)) {
  245. return overwrite ? clone(source) : target;
  246. }
  247. for (var key in source) {
  248. if (source.hasOwnProperty(key) && key !== protoKey) {
  249. var targetProp = target[key];
  250. var sourceProp = source[key];
  251. if (isObject(sourceProp)
  252. && isObject(targetProp)
  253. && !isArray(sourceProp)
  254. && !isArray(targetProp)
  255. && !isDom(sourceProp)
  256. && !isDom(targetProp)
  257. && !isBuiltInObject(sourceProp)
  258. && !isBuiltInObject(targetProp)
  259. && !isPrimitive(sourceProp)
  260. && !isPrimitive(targetProp)) {
  261. merge(targetProp, sourceProp, overwrite);
  262. }
  263. else if (overwrite || !(key in target)) {
  264. target[key] = clone(source[key]);
  265. }
  266. }
  267. }
  268. return target;
  269. }
  270. function mergeAll(targetAndSources, overwrite) {
  271. var result = targetAndSources[0];
  272. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  273. result = merge(result, targetAndSources[i], overwrite);
  274. }
  275. return result;
  276. }
  277. function extend(target, source) {
  278. if (Object.assign) {
  279. Object.assign(target, source);
  280. }
  281. else {
  282. for (var key in source) {
  283. if (source.hasOwnProperty(key) && key !== protoKey) {
  284. target[key] = source[key];
  285. }
  286. }
  287. }
  288. return target;
  289. }
  290. function defaults(target, source, overlay) {
  291. var keysArr = keys(source);
  292. for (var i = 0; i < keysArr.length; i++) {
  293. var key = keysArr[i];
  294. if ((overlay ? source[key] != null : target[key] == null)) {
  295. target[key] = source[key];
  296. }
  297. }
  298. return target;
  299. }
  300. var createCanvas = platformApi.createCanvas;
  301. function indexOf(array, value) {
  302. if (array) {
  303. if (array.indexOf) {
  304. return array.indexOf(value);
  305. }
  306. for (var i = 0, len = array.length; i < len; i++) {
  307. if (array[i] === value) {
  308. return i;
  309. }
  310. }
  311. }
  312. return -1;
  313. }
  314. function inherits(clazz, baseClazz) {
  315. var clazzPrototype = clazz.prototype;
  316. function F() { }
  317. F.prototype = baseClazz.prototype;
  318. clazz.prototype = new F();
  319. for (var prop in clazzPrototype) {
  320. if (clazzPrototype.hasOwnProperty(prop)) {
  321. clazz.prototype[prop] = clazzPrototype[prop];
  322. }
  323. }
  324. clazz.prototype.constructor = clazz;
  325. clazz.superClass = baseClazz;
  326. }
  327. function mixin(target, source, override) {
  328. target = 'prototype' in target ? target.prototype : target;
  329. source = 'prototype' in source ? source.prototype : source;
  330. if (Object.getOwnPropertyNames) {
  331. var keyList = Object.getOwnPropertyNames(source);
  332. for (var i = 0; i < keyList.length; i++) {
  333. var key = keyList[i];
  334. if (key !== 'constructor') {
  335. if ((override ? source[key] != null : target[key] == null)) {
  336. target[key] = source[key];
  337. }
  338. }
  339. }
  340. }
  341. else {
  342. defaults(target, source, override);
  343. }
  344. }
  345. function isArrayLike(data) {
  346. if (!data) {
  347. return false;
  348. }
  349. if (typeof data === 'string') {
  350. return false;
  351. }
  352. return typeof data.length === 'number';
  353. }
  354. function each(arr, cb, context) {
  355. if (!(arr && cb)) {
  356. return;
  357. }
  358. if (arr.forEach && arr.forEach === nativeForEach) {
  359. arr.forEach(cb, context);
  360. }
  361. else if (arr.length === +arr.length) {
  362. for (var i = 0, len = arr.length; i < len; i++) {
  363. cb.call(context, arr[i], i, arr);
  364. }
  365. }
  366. else {
  367. for (var key in arr) {
  368. if (arr.hasOwnProperty(key)) {
  369. cb.call(context, arr[key], key, arr);
  370. }
  371. }
  372. }
  373. }
  374. function map(arr, cb, context) {
  375. if (!arr) {
  376. return [];
  377. }
  378. if (!cb) {
  379. return slice(arr);
  380. }
  381. if (arr.map && arr.map === nativeMap) {
  382. return arr.map(cb, context);
  383. }
  384. else {
  385. var result = [];
  386. for (var i = 0, len = arr.length; i < len; i++) {
  387. result.push(cb.call(context, arr[i], i, arr));
  388. }
  389. return result;
  390. }
  391. }
  392. function reduce(arr, cb, memo, context) {
  393. if (!(arr && cb)) {
  394. return;
  395. }
  396. for (var i = 0, len = arr.length; i < len; i++) {
  397. memo = cb.call(context, memo, arr[i], i, arr);
  398. }
  399. return memo;
  400. }
  401. function filter(arr, cb, context) {
  402. if (!arr) {
  403. return [];
  404. }
  405. if (!cb) {
  406. return slice(arr);
  407. }
  408. if (arr.filter && arr.filter === nativeFilter) {
  409. return arr.filter(cb, context);
  410. }
  411. else {
  412. var result = [];
  413. for (var i = 0, len = arr.length; i < len; i++) {
  414. if (cb.call(context, arr[i], i, arr)) {
  415. result.push(arr[i]);
  416. }
  417. }
  418. return result;
  419. }
  420. }
  421. function find(arr, cb, context) {
  422. if (!(arr && cb)) {
  423. return;
  424. }
  425. for (var i = 0, len = arr.length; i < len; i++) {
  426. if (cb.call(context, arr[i], i, arr)) {
  427. return arr[i];
  428. }
  429. }
  430. }
  431. function keys(obj) {
  432. if (!obj) {
  433. return [];
  434. }
  435. if (Object.keys) {
  436. return Object.keys(obj);
  437. }
  438. var keyList = [];
  439. for (var key in obj) {
  440. if (obj.hasOwnProperty(key)) {
  441. keyList.push(key);
  442. }
  443. }
  444. return keyList;
  445. }
  446. function bindPolyfill(func, context) {
  447. var args = [];
  448. for (var _i = 2; _i < arguments.length; _i++) {
  449. args[_i - 2] = arguments[_i];
  450. }
  451. return function () {
  452. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  453. };
  454. }
  455. var bind = (protoFunction && isFunction(protoFunction.bind))
  456. ? protoFunction.call.bind(protoFunction.bind)
  457. : bindPolyfill;
  458. function curry(func) {
  459. var args = [];
  460. for (var _i = 1; _i < arguments.length; _i++) {
  461. args[_i - 1] = arguments[_i];
  462. }
  463. return function () {
  464. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  465. };
  466. }
  467. function isArray(value) {
  468. if (Array.isArray) {
  469. return Array.isArray(value);
  470. }
  471. return objToString.call(value) === '[object Array]';
  472. }
  473. function isFunction(value) {
  474. return typeof value === 'function';
  475. }
  476. function isString(value) {
  477. return typeof value === 'string';
  478. }
  479. function isStringSafe(value) {
  480. return objToString.call(value) === '[object String]';
  481. }
  482. function isNumber(value) {
  483. return typeof value === 'number';
  484. }
  485. function isObject(value) {
  486. var type = typeof value;
  487. return type === 'function' || (!!value && type === 'object');
  488. }
  489. function isBuiltInObject(value) {
  490. return !!BUILTIN_OBJECT[objToString.call(value)];
  491. }
  492. function isTypedArray(value) {
  493. return !!TYPED_ARRAY[objToString.call(value)];
  494. }
  495. function isDom(value) {
  496. return typeof value === 'object'
  497. && typeof value.nodeType === 'number'
  498. && typeof value.ownerDocument === 'object';
  499. }
  500. function isGradientObject(value) {
  501. return value.colorStops != null;
  502. }
  503. function isImagePatternObject(value) {
  504. return value.image != null;
  505. }
  506. function isRegExp(value) {
  507. return objToString.call(value) === '[object RegExp]';
  508. }
  509. function eqNaN(value) {
  510. return value !== value;
  511. }
  512. function retrieve() {
  513. var args = [];
  514. for (var _i = 0; _i < arguments.length; _i++) {
  515. args[_i] = arguments[_i];
  516. }
  517. for (var i = 0, len = args.length; i < len; i++) {
  518. if (args[i] != null) {
  519. return args[i];
  520. }
  521. }
  522. }
  523. function retrieve2(value0, value1) {
  524. return value0 != null
  525. ? value0
  526. : value1;
  527. }
  528. function retrieve3(value0, value1, value2) {
  529. return value0 != null
  530. ? value0
  531. : value1 != null
  532. ? value1
  533. : value2;
  534. }
  535. function slice(arr) {
  536. var args = [];
  537. for (var _i = 1; _i < arguments.length; _i++) {
  538. args[_i - 1] = arguments[_i];
  539. }
  540. return nativeSlice.apply(arr, args);
  541. }
  542. function normalizeCssArray(val) {
  543. if (typeof (val) === 'number') {
  544. return [val, val, val, val];
  545. }
  546. var len = val.length;
  547. if (len === 2) {
  548. return [val[0], val[1], val[0], val[1]];
  549. }
  550. else if (len === 3) {
  551. return [val[0], val[1], val[2], val[1]];
  552. }
  553. return val;
  554. }
  555. function assert(condition, message) {
  556. if (!condition) {
  557. throw new Error(message);
  558. }
  559. }
  560. function trim(str) {
  561. if (str == null) {
  562. return null;
  563. }
  564. else if (typeof str.trim === 'function') {
  565. return str.trim();
  566. }
  567. else {
  568. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  569. }
  570. }
  571. var primitiveKey = '__ec_primitive__';
  572. function setAsPrimitive(obj) {
  573. obj[primitiveKey] = true;
  574. }
  575. function isPrimitive(obj) {
  576. return obj[primitiveKey];
  577. }
  578. var MapPolyfill = (function () {
  579. function MapPolyfill() {
  580. this.data = {};
  581. }
  582. MapPolyfill.prototype["delete"] = function (key) {
  583. var existed = this.has(key);
  584. if (existed) {
  585. delete this.data[key];
  586. }
  587. return existed;
  588. };
  589. MapPolyfill.prototype.has = function (key) {
  590. return this.data.hasOwnProperty(key);
  591. };
  592. MapPolyfill.prototype.get = function (key) {
  593. return this.data[key];
  594. };
  595. MapPolyfill.prototype.set = function (key, value) {
  596. this.data[key] = value;
  597. return this;
  598. };
  599. MapPolyfill.prototype.keys = function () {
  600. return keys(this.data);
  601. };
  602. MapPolyfill.prototype.forEach = function (callback) {
  603. var data = this.data;
  604. for (var key in data) {
  605. if (data.hasOwnProperty(key)) {
  606. callback(data[key], key);
  607. }
  608. }
  609. };
  610. return MapPolyfill;
  611. }());
  612. var isNativeMapSupported = typeof Map === 'function';
  613. function maybeNativeMap() {
  614. return (isNativeMapSupported ? new Map() : new MapPolyfill());
  615. }
  616. var HashMap = (function () {
  617. function HashMap(obj) {
  618. var isArr = isArray(obj);
  619. this.data = maybeNativeMap();
  620. var thisMap = this;
  621. (obj instanceof HashMap)
  622. ? obj.each(visit)
  623. : (obj && each(obj, visit));
  624. function visit(value, key) {
  625. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  626. }
  627. }
  628. HashMap.prototype.hasKey = function (key) {
  629. return this.data.has(key);
  630. };
  631. HashMap.prototype.get = function (key) {
  632. return this.data.get(key);
  633. };
  634. HashMap.prototype.set = function (key, value) {
  635. this.data.set(key, value);
  636. return value;
  637. };
  638. HashMap.prototype.each = function (cb, context) {
  639. this.data.forEach(function (value, key) {
  640. cb.call(context, value, key);
  641. });
  642. };
  643. HashMap.prototype.keys = function () {
  644. var keys = this.data.keys();
  645. return isNativeMapSupported
  646. ? Array.from(keys)
  647. : keys;
  648. };
  649. HashMap.prototype.removeKey = function (key) {
  650. this.data["delete"](key);
  651. };
  652. return HashMap;
  653. }());
  654. function createHashMap(obj) {
  655. return new HashMap(obj);
  656. }
  657. function concatArray(a, b) {
  658. var newArray = new a.constructor(a.length + b.length);
  659. for (var i = 0; i < a.length; i++) {
  660. newArray[i] = a[i];
  661. }
  662. var offset = a.length;
  663. for (var i = 0; i < b.length; i++) {
  664. newArray[i + offset] = b[i];
  665. }
  666. return newArray;
  667. }
  668. function createObject(proto, properties) {
  669. var obj;
  670. if (Object.create) {
  671. obj = Object.create(proto);
  672. }
  673. else {
  674. var StyleCtor = function () { };
  675. StyleCtor.prototype = proto;
  676. obj = new StyleCtor();
  677. }
  678. if (properties) {
  679. extend(obj, properties);
  680. }
  681. return obj;
  682. }
  683. function disableUserSelect(dom) {
  684. var domStyle = dom.style;
  685. domStyle.webkitUserSelect = 'none';
  686. domStyle.userSelect = 'none';
  687. domStyle.webkitTapHighlightColor = 'rgba(0,0,0,0)';
  688. domStyle['-webkit-touch-callout'] = 'none';
  689. }
  690. function hasOwn(own, prop) {
  691. return own.hasOwnProperty(prop);
  692. }
  693. function noop() { }
  694. var RADIAN_TO_DEGREE = 180 / Math.PI;
  695. var util = /*#__PURE__*/Object.freeze({
  696. __proto__: null,
  697. guid: guid,
  698. logError: logError,
  699. clone: clone,
  700. merge: merge,
  701. mergeAll: mergeAll,
  702. extend: extend,
  703. defaults: defaults,
  704. createCanvas: createCanvas,
  705. indexOf: indexOf,
  706. inherits: inherits,
  707. mixin: mixin,
  708. isArrayLike: isArrayLike,
  709. each: each,
  710. map: map,
  711. reduce: reduce,
  712. filter: filter,
  713. find: find,
  714. keys: keys,
  715. bind: bind,
  716. curry: curry,
  717. isArray: isArray,
  718. isFunction: isFunction,
  719. isString: isString,
  720. isStringSafe: isStringSafe,
  721. isNumber: isNumber,
  722. isObject: isObject,
  723. isBuiltInObject: isBuiltInObject,
  724. isTypedArray: isTypedArray,
  725. isDom: isDom,
  726. isGradientObject: isGradientObject,
  727. isImagePatternObject: isImagePatternObject,
  728. isRegExp: isRegExp,
  729. eqNaN: eqNaN,
  730. retrieve: retrieve,
  731. retrieve2: retrieve2,
  732. retrieve3: retrieve3,
  733. slice: slice,
  734. normalizeCssArray: normalizeCssArray,
  735. assert: assert,
  736. trim: trim,
  737. setAsPrimitive: setAsPrimitive,
  738. isPrimitive: isPrimitive,
  739. HashMap: HashMap,
  740. createHashMap: createHashMap,
  741. concatArray: concatArray,
  742. createObject: createObject,
  743. disableUserSelect: disableUserSelect,
  744. hasOwn: hasOwn,
  745. noop: noop,
  746. RADIAN_TO_DEGREE: RADIAN_TO_DEGREE
  747. });
  748. /*! *****************************************************************************
  749. Copyright (c) Microsoft Corporation. All rights reserved.
  750. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  751. this file except in compliance with the License. You may obtain a copy of the
  752. License at http://www.apache.org/licenses/LICENSE-2.0
  753. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  754. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  755. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  756. MERCHANTABLITY OR NON-INFRINGEMENT.
  757. See the Apache Version 2.0 License for specific language governing permissions
  758. and limitations under the License.
  759. ***************************************************************************** */
  760. /* global Reflect, Promise */
  761. var extendStatics = function(d, b) {
  762. extendStatics = Object.setPrototypeOf ||
  763. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  764. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  765. return extendStatics(d, b);
  766. };
  767. function __extends(d, b) {
  768. extendStatics(d, b);
  769. function __() { this.constructor = d; }
  770. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  771. }
  772. function create(x, y) {
  773. if (x == null) {
  774. x = 0;
  775. }
  776. if (y == null) {
  777. y = 0;
  778. }
  779. return [x, y];
  780. }
  781. function copy(out, v) {
  782. out[0] = v[0];
  783. out[1] = v[1];
  784. return out;
  785. }
  786. function clone$1(v) {
  787. return [v[0], v[1]];
  788. }
  789. function set(out, a, b) {
  790. out[0] = a;
  791. out[1] = b;
  792. return out;
  793. }
  794. function add(out, v1, v2) {
  795. out[0] = v1[0] + v2[0];
  796. out[1] = v1[1] + v2[1];
  797. return out;
  798. }
  799. function scaleAndAdd(out, v1, v2, a) {
  800. out[0] = v1[0] + v2[0] * a;
  801. out[1] = v1[1] + v2[1] * a;
  802. return out;
  803. }
  804. function sub(out, v1, v2) {
  805. out[0] = v1[0] - v2[0];
  806. out[1] = v1[1] - v2[1];
  807. return out;
  808. }
  809. function len(v) {
  810. return Math.sqrt(lenSquare(v));
  811. }
  812. var length = len;
  813. function lenSquare(v) {
  814. return v[0] * v[0] + v[1] * v[1];
  815. }
  816. var lengthSquare = lenSquare;
  817. function mul(out, v1, v2) {
  818. out[0] = v1[0] * v2[0];
  819. out[1] = v1[1] * v2[1];
  820. return out;
  821. }
  822. function div(out, v1, v2) {
  823. out[0] = v1[0] / v2[0];
  824. out[1] = v1[1] / v2[1];
  825. return out;
  826. }
  827. function dot(v1, v2) {
  828. return v1[0] * v2[0] + v1[1] * v2[1];
  829. }
  830. function scale(out, v, s) {
  831. out[0] = v[0] * s;
  832. out[1] = v[1] * s;
  833. return out;
  834. }
  835. function normalize(out, v) {
  836. var d = len(v);
  837. if (d === 0) {
  838. out[0] = 0;
  839. out[1] = 0;
  840. }
  841. else {
  842. out[0] = v[0] / d;
  843. out[1] = v[1] / d;
  844. }
  845. return out;
  846. }
  847. function distance(v1, v2) {
  848. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0])
  849. + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  850. }
  851. var dist = distance;
  852. function distanceSquare(v1, v2) {
  853. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  854. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  855. }
  856. var distSquare = distanceSquare;
  857. function negate(out, v) {
  858. out[0] = -v[0];
  859. out[1] = -v[1];
  860. return out;
  861. }
  862. function lerp(out, v1, v2, t) {
  863. out[0] = v1[0] + t * (v2[0] - v1[0]);
  864. out[1] = v1[1] + t * (v2[1] - v1[1]);
  865. return out;
  866. }
  867. function applyTransform(out, v, m) {
  868. var x = v[0];
  869. var y = v[1];
  870. out[0] = m[0] * x + m[2] * y + m[4];
  871. out[1] = m[1] * x + m[3] * y + m[5];
  872. return out;
  873. }
  874. function min(out, v1, v2) {
  875. out[0] = Math.min(v1[0], v2[0]);
  876. out[1] = Math.min(v1[1], v2[1]);
  877. return out;
  878. }
  879. function max(out, v1, v2) {
  880. out[0] = Math.max(v1[0], v2[0]);
  881. out[1] = Math.max(v1[1], v2[1]);
  882. return out;
  883. }
  884. var vector = /*#__PURE__*/Object.freeze({
  885. __proto__: null,
  886. create: create,
  887. copy: copy,
  888. clone: clone$1,
  889. set: set,
  890. add: add,
  891. scaleAndAdd: scaleAndAdd,
  892. sub: sub,
  893. len: len,
  894. length: length,
  895. lenSquare: lenSquare,
  896. lengthSquare: lengthSquare,
  897. mul: mul,
  898. div: div,
  899. dot: dot,
  900. scale: scale,
  901. normalize: normalize,
  902. distance: distance,
  903. dist: dist,
  904. distanceSquare: distanceSquare,
  905. distSquare: distSquare,
  906. negate: negate,
  907. lerp: lerp,
  908. applyTransform: applyTransform,
  909. min: min,
  910. max: max
  911. });
  912. var Param = (function () {
  913. function Param(target, e) {
  914. this.target = target;
  915. this.topTarget = e && e.topTarget;
  916. }
  917. return Param;
  918. }());
  919. var Draggable = (function () {
  920. function Draggable(handler) {
  921. this.handler = handler;
  922. handler.on('mousedown', this._dragStart, this);
  923. handler.on('mousemove', this._drag, this);
  924. handler.on('mouseup', this._dragEnd, this);
  925. }
  926. Draggable.prototype._dragStart = function (e) {
  927. var draggingTarget = e.target;
  928. while (draggingTarget && !draggingTarget.draggable) {
  929. draggingTarget = draggingTarget.parent || draggingTarget.__hostTarget;
  930. }
  931. if (draggingTarget) {
  932. this._draggingTarget = draggingTarget;
  933. draggingTarget.dragging = true;
  934. this._x = e.offsetX;
  935. this._y = e.offsetY;
  936. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragstart', e.event);
  937. }
  938. };
  939. Draggable.prototype._drag = function (e) {
  940. var draggingTarget = this._draggingTarget;
  941. if (draggingTarget) {
  942. var x = e.offsetX;
  943. var y = e.offsetY;
  944. var dx = x - this._x;
  945. var dy = y - this._y;
  946. this._x = x;
  947. this._y = y;
  948. draggingTarget.drift(dx, dy, e);
  949. this.handler.dispatchToElement(new Param(draggingTarget, e), 'drag', e.event);
  950. var dropTarget = this.handler.findHover(x, y, draggingTarget).target;
  951. var lastDropTarget = this._dropTarget;
  952. this._dropTarget = dropTarget;
  953. if (draggingTarget !== dropTarget) {
  954. if (lastDropTarget && dropTarget !== lastDropTarget) {
  955. this.handler.dispatchToElement(new Param(lastDropTarget, e), 'dragleave', e.event);
  956. }
  957. if (dropTarget && dropTarget !== lastDropTarget) {
  958. this.handler.dispatchToElement(new Param(dropTarget, e), 'dragenter', e.event);
  959. }
  960. }
  961. }
  962. };
  963. Draggable.prototype._dragEnd = function (e) {
  964. var draggingTarget = this._draggingTarget;
  965. if (draggingTarget) {
  966. draggingTarget.dragging = false;
  967. }
  968. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragend', e.event);
  969. if (this._dropTarget) {
  970. this.handler.dispatchToElement(new Param(this._dropTarget, e), 'drop', e.event);
  971. }
  972. this._draggingTarget = null;
  973. this._dropTarget = null;
  974. };
  975. return Draggable;
  976. }());
  977. var Eventful = (function () {
  978. function Eventful(eventProcessors) {
  979. if (eventProcessors) {
  980. this._$eventProcessor = eventProcessors;
  981. }
  982. }
  983. Eventful.prototype.on = function (event, query, handler, context) {
  984. if (!this._$handlers) {
  985. this._$handlers = {};
  986. }
  987. var _h = this._$handlers;
  988. if (typeof query === 'function') {
  989. context = handler;
  990. handler = query;
  991. query = null;
  992. }
  993. if (!handler || !event) {
  994. return this;
  995. }
  996. var eventProcessor = this._$eventProcessor;
  997. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  998. query = eventProcessor.normalizeQuery(query);
  999. }
  1000. if (!_h[event]) {
  1001. _h[event] = [];
  1002. }
  1003. for (var i = 0; i < _h[event].length; i++) {
  1004. if (_h[event][i].h === handler) {
  1005. return this;
  1006. }
  1007. }
  1008. var wrap = {
  1009. h: handler,
  1010. query: query,
  1011. ctx: (context || this),
  1012. callAtLast: handler.zrEventfulCallAtLast
  1013. };
  1014. var lastIndex = _h[event].length - 1;
  1015. var lastWrap = _h[event][lastIndex];
  1016. (lastWrap && lastWrap.callAtLast)
  1017. ? _h[event].splice(lastIndex, 0, wrap)
  1018. : _h[event].push(wrap);
  1019. return this;
  1020. };
  1021. Eventful.prototype.isSilent = function (eventName) {
  1022. var _h = this._$handlers;
  1023. return !_h || !_h[eventName] || !_h[eventName].length;
  1024. };
  1025. Eventful.prototype.off = function (eventType, handler) {
  1026. var _h = this._$handlers;
  1027. if (!_h) {
  1028. return this;
  1029. }
  1030. if (!eventType) {
  1031. this._$handlers = {};
  1032. return this;
  1033. }
  1034. if (handler) {
  1035. if (_h[eventType]) {
  1036. var newList = [];
  1037. for (var i = 0, l = _h[eventType].length; i < l; i++) {
  1038. if (_h[eventType][i].h !== handler) {
  1039. newList.push(_h[eventType][i]);
  1040. }
  1041. }
  1042. _h[eventType] = newList;
  1043. }
  1044. if (_h[eventType] && _h[eventType].length === 0) {
  1045. delete _h[eventType];
  1046. }
  1047. }
  1048. else {
  1049. delete _h[eventType];
  1050. }
  1051. return this;
  1052. };
  1053. Eventful.prototype.trigger = function (eventType) {
  1054. var args = [];
  1055. for (var _i = 1; _i < arguments.length; _i++) {
  1056. args[_i - 1] = arguments[_i];
  1057. }
  1058. if (!this._$handlers) {
  1059. return this;
  1060. }
  1061. var _h = this._$handlers[eventType];
  1062. var eventProcessor = this._$eventProcessor;
  1063. if (_h) {
  1064. var argLen = args.length;
  1065. var len = _h.length;
  1066. for (var i = 0; i < len; i++) {
  1067. var hItem = _h[i];
  1068. if (eventProcessor
  1069. && eventProcessor.filter
  1070. && hItem.query != null
  1071. && !eventProcessor.filter(eventType, hItem.query)) {
  1072. continue;
  1073. }
  1074. switch (argLen) {
  1075. case 0:
  1076. hItem.h.call(hItem.ctx);
  1077. break;
  1078. case 1:
  1079. hItem.h.call(hItem.ctx, args[0]);
  1080. break;
  1081. case 2:
  1082. hItem.h.call(hItem.ctx, args[0], args[1]);
  1083. break;
  1084. default:
  1085. hItem.h.apply(hItem.ctx, args);
  1086. break;
  1087. }
  1088. }
  1089. }
  1090. eventProcessor && eventProcessor.afterTrigger
  1091. && eventProcessor.afterTrigger(eventType);
  1092. return this;
  1093. };
  1094. Eventful.prototype.triggerWithContext = function (type) {
  1095. var args = [];
  1096. for (var _i = 1; _i < arguments.length; _i++) {
  1097. args[_i - 1] = arguments[_i];
  1098. }
  1099. if (!this._$handlers) {
  1100. return this;
  1101. }
  1102. var _h = this._$handlers[type];
  1103. var eventProcessor = this._$eventProcessor;
  1104. if (_h) {
  1105. var argLen = args.length;
  1106. var ctx = args[argLen - 1];
  1107. var len = _h.length;
  1108. for (var i = 0; i < len; i++) {
  1109. var hItem = _h[i];
  1110. if (eventProcessor
  1111. && eventProcessor.filter
  1112. && hItem.query != null
  1113. && !eventProcessor.filter(type, hItem.query)) {
  1114. continue;
  1115. }
  1116. switch (argLen) {
  1117. case 0:
  1118. hItem.h.call(ctx);
  1119. break;
  1120. case 1:
  1121. hItem.h.call(ctx, args[0]);
  1122. break;
  1123. case 2:
  1124. hItem.h.call(ctx, args[0], args[1]);
  1125. break;
  1126. default:
  1127. hItem.h.apply(ctx, args.slice(1, argLen - 1));
  1128. break;
  1129. }
  1130. }
  1131. }
  1132. eventProcessor && eventProcessor.afterTrigger
  1133. && eventProcessor.afterTrigger(type);
  1134. return this;
  1135. };
  1136. return Eventful;
  1137. }());
  1138. var LN2 = Math.log(2);
  1139. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1140. var cacheKey = rowMask + '-' + colMask;
  1141. var fullRank = rows.length;
  1142. if (detCache.hasOwnProperty(cacheKey)) {
  1143. return detCache[cacheKey];
  1144. }
  1145. if (rank === 1) {
  1146. var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);
  1147. return rows[rowStart][colStart];
  1148. }
  1149. var subRowMask = rowMask | (1 << rowStart);
  1150. var subRowStart = rowStart + 1;
  1151. while (rowMask & (1 << subRowStart)) {
  1152. subRowStart++;
  1153. }
  1154. var sum = 0;
  1155. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1156. var colTag = 1 << j;
  1157. if (!(colTag & colMask)) {
  1158. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]
  1159. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1160. colLocalIdx++;
  1161. }
  1162. }
  1163. detCache[cacheKey] = sum;
  1164. return sum;
  1165. }
  1166. function buildTransformer(src, dest) {
  1167. var mA = [
  1168. [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],
  1169. [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],
  1170. [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],
  1171. [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],
  1172. [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],
  1173. [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],
  1174. [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],
  1175. [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]
  1176. ];
  1177. var detCache = {};
  1178. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1179. if (det === 0) {
  1180. return;
  1181. }
  1182. var vh = [];
  1183. for (var i = 0; i < 8; i++) {
  1184. for (var j = 0; j < 8; j++) {
  1185. vh[j] == null && (vh[j] = 0);
  1186. vh[j] += ((i + j) % 2 ? -1 : 1)
  1187. * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)
  1188. / det * dest[i];
  1189. }
  1190. }
  1191. return function (out, srcPointX, srcPointY) {
  1192. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1193. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1194. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1195. };
  1196. }
  1197. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1198. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1199. if (el.getBoundingClientRect && env.domSupported && !isCanvasEl(el)) {
  1200. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1201. var markers = prepareCoordMarkers(el, saved);
  1202. var transformer = preparePointerTransformer(markers, saved, inverse);
  1203. if (transformer) {
  1204. transformer(out, inX, inY);
  1205. return true;
  1206. }
  1207. }
  1208. return false;
  1209. }
  1210. function prepareCoordMarkers(el, saved) {
  1211. var markers = saved.markers;
  1212. if (markers) {
  1213. return markers;
  1214. }
  1215. markers = saved.markers = [];
  1216. var propLR = ['left', 'right'];
  1217. var propTB = ['top', 'bottom'];
  1218. for (var i = 0; i < 4; i++) {
  1219. var marker = document.createElement('div');
  1220. var stl = marker.style;
  1221. var idxLR = i % 2;
  1222. var idxTB = (i >> 1) % 2;
  1223. stl.cssText = [
  1224. 'position: absolute',
  1225. 'visibility: hidden',
  1226. 'padding: 0',
  1227. 'margin: 0',
  1228. 'border-width: 0',
  1229. 'user-select: none',
  1230. 'width:0',
  1231. 'height:0',
  1232. propLR[idxLR] + ':0',
  1233. propTB[idxTB] + ':0',
  1234. propLR[1 - idxLR] + ':auto',
  1235. propTB[1 - idxTB] + ':auto',
  1236. ''
  1237. ].join('!important;');
  1238. el.appendChild(marker);
  1239. markers.push(marker);
  1240. }
  1241. return markers;
  1242. }
  1243. function preparePointerTransformer(markers, saved, inverse) {
  1244. var transformerName = inverse ? 'invTrans' : 'trans';
  1245. var transformer = saved[transformerName];
  1246. var oldSrcCoords = saved.srcCoords;
  1247. var srcCoords = [];
  1248. var destCoords = [];
  1249. var oldCoordTheSame = true;
  1250. for (var i = 0; i < 4; i++) {
  1251. var rect = markers[i].getBoundingClientRect();
  1252. var ii = 2 * i;
  1253. var x = rect.left;
  1254. var y = rect.top;
  1255. srcCoords.push(x, y);
  1256. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1257. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1258. }
  1259. return (oldCoordTheSame && transformer)
  1260. ? transformer
  1261. : (saved.srcCoords = srcCoords,
  1262. saved[transformerName] = inverse
  1263. ? buildTransformer(destCoords, srcCoords)
  1264. : buildTransformer(srcCoords, destCoords));
  1265. }
  1266. function isCanvasEl(el) {
  1267. return el.nodeName.toUpperCase() === 'CANVAS';
  1268. }
  1269. var replaceReg = /([&<>"'])/g;
  1270. var replaceMap = {
  1271. '&': '&amp;',
  1272. '<': '&lt;',
  1273. '>': '&gt;',
  1274. '"': '&quot;',
  1275. '\'': '&#39;'
  1276. };
  1277. function encodeHTML(source) {
  1278. return source == null
  1279. ? ''
  1280. : (source + '').replace(replaceReg, function (str, c) {
  1281. return replaceMap[c];
  1282. });
  1283. }
  1284. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1285. var _calcOut = [];
  1286. var firefoxNotSupportOffsetXY = env.browser.firefox
  1287. && +env.browser.version.split('.')[0] < 39;
  1288. function clientToLocal(el, e, out, calculate) {
  1289. out = out || {};
  1290. if (calculate) {
  1291. calculateZrXY(el, e, out);
  1292. }
  1293. else if (firefoxNotSupportOffsetXY
  1294. && e.layerX != null
  1295. && e.layerX !== e.offsetX) {
  1296. out.zrX = e.layerX;
  1297. out.zrY = e.layerY;
  1298. }
  1299. else if (e.offsetX != null) {
  1300. out.zrX = e.offsetX;
  1301. out.zrY = e.offsetY;
  1302. }
  1303. else {
  1304. calculateZrXY(el, e, out);
  1305. }
  1306. return out;
  1307. }
  1308. function calculateZrXY(el, e, out) {
  1309. if (env.domSupported && el.getBoundingClientRect) {
  1310. var ex = e.clientX;
  1311. var ey = e.clientY;
  1312. if (isCanvasEl(el)) {
  1313. var box = el.getBoundingClientRect();
  1314. out.zrX = ex - box.left;
  1315. out.zrY = ey - box.top;
  1316. return;
  1317. }
  1318. else {
  1319. if (transformCoordWithViewport(_calcOut, el, ex, ey)) {
  1320. out.zrX = _calcOut[0];
  1321. out.zrY = _calcOut[1];
  1322. return;
  1323. }
  1324. }
  1325. }
  1326. out.zrX = out.zrY = 0;
  1327. }
  1328. function getNativeEvent(e) {
  1329. return e
  1330. || window.event;
  1331. }
  1332. function normalizeEvent(el, e, calculate) {
  1333. e = getNativeEvent(e);
  1334. if (e.zrX != null) {
  1335. return e;
  1336. }
  1337. var eventType = e.type;
  1338. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1339. if (!isTouch) {
  1340. clientToLocal(el, e, e, calculate);
  1341. var wheelDelta = getWheelDeltaMayPolyfill(e);
  1342. e.zrDelta = wheelDelta ? wheelDelta / 120 : -(e.detail || 0) / 3;
  1343. }
  1344. else {
  1345. var touch = eventType !== 'touchend'
  1346. ? e.targetTouches[0]
  1347. : e.changedTouches[0];
  1348. touch && clientToLocal(el, touch, e, calculate);
  1349. }
  1350. var button = e.button;
  1351. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1352. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1353. }
  1354. return e;
  1355. }
  1356. function getWheelDeltaMayPolyfill(e) {
  1357. var rawWheelDelta = e.wheelDelta;
  1358. if (rawWheelDelta) {
  1359. return rawWheelDelta;
  1360. }
  1361. var deltaX = e.deltaX;
  1362. var deltaY = e.deltaY;
  1363. if (deltaX == null || deltaY == null) {
  1364. return rawWheelDelta;
  1365. }
  1366. var delta = deltaY !== 0 ? Math.abs(deltaY) : Math.abs(deltaX);
  1367. var sign = deltaY > 0 ? -1
  1368. : deltaY < 0 ? 1
  1369. : deltaX > 0 ? -1
  1370. : 1;
  1371. return 3 * delta * sign;
  1372. }
  1373. function addEventListener(el, name, handler, opt) {
  1374. el.addEventListener(name, handler, opt);
  1375. }
  1376. function removeEventListener(el, name, handler, opt) {
  1377. el.removeEventListener(name, handler, opt);
  1378. }
  1379. var stop = function (e) {
  1380. e.preventDefault();
  1381. e.stopPropagation();
  1382. e.cancelBubble = true;
  1383. };
  1384. var GestureMgr = (function () {
  1385. function GestureMgr() {
  1386. this._track = [];
  1387. }
  1388. GestureMgr.prototype.recognize = function (event, target, root) {
  1389. this._doTrack(event, target, root);
  1390. return this._recognize(event);
  1391. };
  1392. GestureMgr.prototype.clear = function () {
  1393. this._track.length = 0;
  1394. return this;
  1395. };
  1396. GestureMgr.prototype._doTrack = function (event, target, root) {
  1397. var touches = event.touches;
  1398. if (!touches) {
  1399. return;
  1400. }
  1401. var trackItem = {
  1402. points: [],
  1403. touches: [],
  1404. target: target,
  1405. event: event
  1406. };
  1407. for (var i = 0, len = touches.length; i < len; i++) {
  1408. var touch = touches[i];
  1409. var pos = clientToLocal(root, touch, {});
  1410. trackItem.points.push([pos.zrX, pos.zrY]);
  1411. trackItem.touches.push(touch);
  1412. }
  1413. this._track.push(trackItem);
  1414. };
  1415. GestureMgr.prototype._recognize = function (event) {
  1416. for (var eventName in recognizers) {
  1417. if (recognizers.hasOwnProperty(eventName)) {
  1418. var gestureInfo = recognizers[eventName](this._track, event);
  1419. if (gestureInfo) {
  1420. return gestureInfo;
  1421. }
  1422. }
  1423. }
  1424. };
  1425. return GestureMgr;
  1426. }());
  1427. function dist$1(pointPair) {
  1428. var dx = pointPair[1][0] - pointPair[0][0];
  1429. var dy = pointPair[1][1] - pointPair[0][1];
  1430. return Math.sqrt(dx * dx + dy * dy);
  1431. }
  1432. function center(pointPair) {
  1433. return [
  1434. (pointPair[0][0] + pointPair[1][0]) / 2,
  1435. (pointPair[0][1] + pointPair[1][1]) / 2
  1436. ];
  1437. }
  1438. var recognizers = {
  1439. pinch: function (tracks, event) {
  1440. var trackLen = tracks.length;
  1441. if (!trackLen) {
  1442. return;
  1443. }
  1444. var pinchEnd = (tracks[trackLen - 1] || {}).points;
  1445. var pinchPre = (tracks[trackLen - 2] || {}).points || pinchEnd;
  1446. if (pinchPre
  1447. && pinchPre.length > 1
  1448. && pinchEnd
  1449. && pinchEnd.length > 1) {
  1450. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1451. !isFinite(pinchScale) && (pinchScale = 1);
  1452. event.pinchScale = pinchScale;
  1453. var pinchCenter = center(pinchEnd);
  1454. event.pinchX = pinchCenter[0];
  1455. event.pinchY = pinchCenter[1];
  1456. return {
  1457. type: 'pinch',
  1458. target: tracks[0].target,
  1459. event: event
  1460. };
  1461. }
  1462. }
  1463. };
  1464. function create$1() {
  1465. return [1, 0, 0, 1, 0, 0];
  1466. }
  1467. function identity(out) {
  1468. out[0] = 1;
  1469. out[1] = 0;
  1470. out[2] = 0;
  1471. out[3] = 1;
  1472. out[4] = 0;
  1473. out[5] = 0;
  1474. return out;
  1475. }
  1476. function copy$1(out, m) {
  1477. out[0] = m[0];
  1478. out[1] = m[1];
  1479. out[2] = m[2];
  1480. out[3] = m[3];
  1481. out[4] = m[4];
  1482. out[5] = m[5];
  1483. return out;
  1484. }
  1485. function mul$1(out, m1, m2) {
  1486. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  1487. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  1488. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  1489. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  1490. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1491. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1492. out[0] = out0;
  1493. out[1] = out1;
  1494. out[2] = out2;
  1495. out[3] = out3;
  1496. out[4] = out4;
  1497. out[5] = out5;
  1498. return out;
  1499. }
  1500. function translate(out, a, v) {
  1501. out[0] = a[0];
  1502. out[1] = a[1];
  1503. out[2] = a[2];
  1504. out[3] = a[3];
  1505. out[4] = a[4] + v[0];
  1506. out[5] = a[5] + v[1];
  1507. return out;
  1508. }
  1509. function rotate(out, a, rad) {
  1510. var aa = a[0];
  1511. var ac = a[2];
  1512. var atx = a[4];
  1513. var ab = a[1];
  1514. var ad = a[3];
  1515. var aty = a[5];
  1516. var st = Math.sin(rad);
  1517. var ct = Math.cos(rad);
  1518. out[0] = aa * ct + ab * st;
  1519. out[1] = -aa * st + ab * ct;
  1520. out[2] = ac * ct + ad * st;
  1521. out[3] = -ac * st + ct * ad;
  1522. out[4] = ct * atx + st * aty;
  1523. out[5] = ct * aty - st * atx;
  1524. return out;
  1525. }
  1526. function scale$1(out, a, v) {
  1527. var vx = v[0];
  1528. var vy = v[1];
  1529. out[0] = a[0] * vx;
  1530. out[1] = a[1] * vy;
  1531. out[2] = a[2] * vx;
  1532. out[3] = a[3] * vy;
  1533. out[4] = a[4] * vx;
  1534. out[5] = a[5] * vy;
  1535. return out;
  1536. }
  1537. function invert(out, a) {
  1538. var aa = a[0];
  1539. var ac = a[2];
  1540. var atx = a[4];
  1541. var ab = a[1];
  1542. var ad = a[3];
  1543. var aty = a[5];
  1544. var det = aa * ad - ab * ac;
  1545. if (!det) {
  1546. return null;
  1547. }
  1548. det = 1.0 / det;
  1549. out[0] = ad * det;
  1550. out[1] = -ab * det;
  1551. out[2] = -ac * det;
  1552. out[3] = aa * det;
  1553. out[4] = (ac * aty - ad * atx) * det;
  1554. out[5] = (ab * atx - aa * aty) * det;
  1555. return out;
  1556. }
  1557. function clone$2(a) {
  1558. var b = create$1();
  1559. copy$1(b, a);
  1560. return b;
  1561. }
  1562. var matrix = /*#__PURE__*/Object.freeze({
  1563. __proto__: null,
  1564. create: create$1,
  1565. identity: identity,
  1566. copy: copy$1,
  1567. mul: mul$1,
  1568. translate: translate,
  1569. rotate: rotate,
  1570. scale: scale$1,
  1571. invert: invert,
  1572. clone: clone$2
  1573. });
  1574. var Point = (function () {
  1575. function Point(x, y) {
  1576. this.x = x || 0;
  1577. this.y = y || 0;
  1578. }
  1579. Point.prototype.copy = function (other) {
  1580. this.x = other.x;
  1581. this.y = other.y;
  1582. return this;
  1583. };
  1584. Point.prototype.clone = function () {
  1585. return new Point(this.x, this.y);
  1586. };
  1587. Point.prototype.set = function (x, y) {
  1588. this.x = x;
  1589. this.y = y;
  1590. return this;
  1591. };
  1592. Point.prototype.equal = function (other) {
  1593. return other.x === this.x && other.y === this.y;
  1594. };
  1595. Point.prototype.add = function (other) {
  1596. this.x += other.x;
  1597. this.y += other.y;
  1598. return this;
  1599. };
  1600. Point.prototype.scale = function (scalar) {
  1601. this.x *= scalar;
  1602. this.y *= scalar;
  1603. };
  1604. Point.prototype.scaleAndAdd = function (other, scalar) {
  1605. this.x += other.x * scalar;
  1606. this.y += other.y * scalar;
  1607. };
  1608. Point.prototype.sub = function (other) {
  1609. this.x -= other.x;
  1610. this.y -= other.y;
  1611. return this;
  1612. };
  1613. Point.prototype.dot = function (other) {
  1614. return this.x * other.x + this.y * other.y;
  1615. };
  1616. Point.prototype.len = function () {
  1617. return Math.sqrt(this.x * this.x + this.y * this.y);
  1618. };
  1619. Point.prototype.lenSquare = function () {
  1620. return this.x * this.x + this.y * this.y;
  1621. };
  1622. Point.prototype.normalize = function () {
  1623. var len = this.len();
  1624. this.x /= len;
  1625. this.y /= len;
  1626. return this;
  1627. };
  1628. Point.prototype.distance = function (other) {
  1629. var dx = this.x - other.x;
  1630. var dy = this.y - other.y;
  1631. return Math.sqrt(dx * dx + dy * dy);
  1632. };
  1633. Point.prototype.distanceSquare = function (other) {
  1634. var dx = this.x - other.x;
  1635. var dy = this.y - other.y;
  1636. return dx * dx + dy * dy;
  1637. };
  1638. Point.prototype.negate = function () {
  1639. this.x = -this.x;
  1640. this.y = -this.y;
  1641. return this;
  1642. };
  1643. Point.prototype.transform = function (m) {
  1644. if (!m) {
  1645. return;
  1646. }
  1647. var x = this.x;
  1648. var y = this.y;
  1649. this.x = m[0] * x + m[2] * y + m[4];
  1650. this.y = m[1] * x + m[3] * y + m[5];
  1651. return this;
  1652. };
  1653. Point.prototype.toArray = function (out) {
  1654. out[0] = this.x;
  1655. out[1] = this.y;
  1656. return out;
  1657. };
  1658. Point.prototype.fromArray = function (input) {
  1659. this.x = input[0];
  1660. this.y = input[1];
  1661. };
  1662. Point.set = function (p, x, y) {
  1663. p.x = x;
  1664. p.y = y;
  1665. };
  1666. Point.copy = function (p, p2) {
  1667. p.x = p2.x;
  1668. p.y = p2.y;
  1669. };
  1670. Point.len = function (p) {
  1671. return Math.sqrt(p.x * p.x + p.y * p.y);
  1672. };
  1673. Point.lenSquare = function (p) {
  1674. return p.x * p.x + p.y * p.y;
  1675. };
  1676. Point.dot = function (p0, p1) {
  1677. return p0.x * p1.x + p0.y * p1.y;
  1678. };
  1679. Point.add = function (out, p0, p1) {
  1680. out.x = p0.x + p1.x;
  1681. out.y = p0.y + p1.y;
  1682. };
  1683. Point.sub = function (out, p0, p1) {
  1684. out.x = p0.x - p1.x;
  1685. out.y = p0.y - p1.y;
  1686. };
  1687. Point.scale = function (out, p0, scalar) {
  1688. out.x = p0.x * scalar;
  1689. out.y = p0.y * scalar;
  1690. };
  1691. Point.scaleAndAdd = function (out, p0, p1, scalar) {
  1692. out.x = p0.x + p1.x * scalar;
  1693. out.y = p0.y + p1.y * scalar;
  1694. };
  1695. Point.lerp = function (out, p0, p1, t) {
  1696. var onet = 1 - t;
  1697. out.x = onet * p0.x + t * p1.x;
  1698. out.y = onet * p0.y + t * p1.y;
  1699. };
  1700. return Point;
  1701. }());
  1702. var mathMin = Math.min;
  1703. var mathMax = Math.max;
  1704. var lt = new Point();
  1705. var rb = new Point();
  1706. var lb = new Point();
  1707. var rt = new Point();
  1708. var minTv = new Point();
  1709. var maxTv = new Point();
  1710. var BoundingRect = (function () {
  1711. function BoundingRect(x, y, width, height) {
  1712. if (width < 0) {
  1713. x = x + width;
  1714. width = -width;
  1715. }
  1716. if (height < 0) {
  1717. y = y + height;
  1718. height = -height;
  1719. }
  1720. this.x = x;
  1721. this.y = y;
  1722. this.width = width;
  1723. this.height = height;
  1724. }
  1725. BoundingRect.prototype.union = function (other) {
  1726. var x = mathMin(other.x, this.x);
  1727. var y = mathMin(other.y, this.y);
  1728. if (isFinite(this.x) && isFinite(this.width)) {
  1729. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  1730. }
  1731. else {
  1732. this.width = other.width;
  1733. }
  1734. if (isFinite(this.y) && isFinite(this.height)) {
  1735. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  1736. }
  1737. else {
  1738. this.height = other.height;
  1739. }
  1740. this.x = x;
  1741. this.y = y;
  1742. };
  1743. BoundingRect.prototype.applyTransform = function (m) {
  1744. BoundingRect.applyTransform(this, this, m);
  1745. };
  1746. BoundingRect.prototype.calculateTransform = function (b) {
  1747. var a = this;
  1748. var sx = b.width / a.width;
  1749. var sy = b.height / a.height;
  1750. var m = create$1();
  1751. translate(m, m, [-a.x, -a.y]);
  1752. scale$1(m, m, [sx, sy]);
  1753. translate(m, m, [b.x, b.y]);
  1754. return m;
  1755. };
  1756. BoundingRect.prototype.intersect = function (b, mtv) {
  1757. if (!b) {
  1758. return false;
  1759. }
  1760. if (!(b instanceof BoundingRect)) {
  1761. b = BoundingRect.create(b);
  1762. }
  1763. var a = this;
  1764. var ax0 = a.x;
  1765. var ax1 = a.x + a.width;
  1766. var ay0 = a.y;
  1767. var ay1 = a.y + a.height;
  1768. var bx0 = b.x;
  1769. var bx1 = b.x + b.width;
  1770. var by0 = b.y;
  1771. var by1 = b.y + b.height;
  1772. var overlap = !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  1773. if (mtv) {
  1774. var dMin = Infinity;
  1775. var dMax = 0;
  1776. var d0 = Math.abs(ax1 - bx0);
  1777. var d1 = Math.abs(bx1 - ax0);
  1778. var d2 = Math.abs(ay1 - by0);
  1779. var d3 = Math.abs(by1 - ay0);
  1780. var dx = Math.min(d0, d1);
  1781. var dy = Math.min(d2, d3);
  1782. if (ax1 < bx0 || bx1 < ax0) {
  1783. if (dx > dMax) {
  1784. dMax = dx;
  1785. if (d0 < d1) {
  1786. Point.set(maxTv, -d0, 0);
  1787. }
  1788. else {
  1789. Point.set(maxTv, d1, 0);
  1790. }
  1791. }
  1792. }
  1793. else {
  1794. if (dx < dMin) {
  1795. dMin = dx;
  1796. if (d0 < d1) {
  1797. Point.set(minTv, d0, 0);
  1798. }
  1799. else {
  1800. Point.set(minTv, -d1, 0);
  1801. }
  1802. }
  1803. }
  1804. if (ay1 < by0 || by1 < ay0) {
  1805. if (dy > dMax) {
  1806. dMax = dy;
  1807. if (d2 < d3) {
  1808. Point.set(maxTv, 0, -d2);
  1809. }
  1810. else {
  1811. Point.set(maxTv, 0, d3);
  1812. }
  1813. }
  1814. }
  1815. else {
  1816. if (dx < dMin) {
  1817. dMin = dx;
  1818. if (d2 < d3) {
  1819. Point.set(minTv, 0, d2);
  1820. }
  1821. else {
  1822. Point.set(minTv, 0, -d3);
  1823. }
  1824. }
  1825. }
  1826. }
  1827. if (mtv) {
  1828. Point.copy(mtv, overlap ? minTv : maxTv);
  1829. }
  1830. return overlap;
  1831. };
  1832. BoundingRect.prototype.contain = function (x, y) {
  1833. var rect = this;
  1834. return x >= rect.x
  1835. && x <= (rect.x + rect.width)
  1836. && y >= rect.y
  1837. && y <= (rect.y + rect.height);
  1838. };
  1839. BoundingRect.prototype.clone = function () {
  1840. return new BoundingRect(this.x, this.y, this.width, this.height);
  1841. };
  1842. BoundingRect.prototype.copy = function (other) {
  1843. BoundingRect.copy(this, other);
  1844. };
  1845. BoundingRect.prototype.plain = function () {
  1846. return {
  1847. x: this.x,
  1848. y: this.y,
  1849. width: this.width,
  1850. height: this.height
  1851. };
  1852. };
  1853. BoundingRect.prototype.isFinite = function () {
  1854. return isFinite(this.x)
  1855. && isFinite(this.y)
  1856. && isFinite(this.width)
  1857. && isFinite(this.height);
  1858. };
  1859. BoundingRect.prototype.isZero = function () {
  1860. return this.width === 0 || this.height === 0;
  1861. };
  1862. BoundingRect.create = function (rect) {
  1863. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  1864. };
  1865. BoundingRect.copy = function (target, source) {
  1866. target.x = source.x;
  1867. target.y = source.y;
  1868. target.width = source.width;
  1869. target.height = source.height;
  1870. };
  1871. BoundingRect.applyTransform = function (target, source, m) {
  1872. if (!m) {
  1873. if (target !== source) {
  1874. BoundingRect.copy(target, source);
  1875. }
  1876. return;
  1877. }
  1878. if (m[1] < 1e-5 && m[1] > -1e-5 && m[2] < 1e-5 && m[2] > -1e-5) {
  1879. var sx = m[0];
  1880. var sy = m[3];
  1881. var tx = m[4];
  1882. var ty = m[5];
  1883. target.x = source.x * sx + tx;
  1884. target.y = source.y * sy + ty;
  1885. target.width = source.width * sx;
  1886. target.height = source.height * sy;
  1887. if (target.width < 0) {
  1888. target.x += target.width;
  1889. target.width = -target.width;
  1890. }
  1891. if (target.height < 0) {
  1892. target.y += target.height;
  1893. target.height = -target.height;
  1894. }
  1895. return;
  1896. }
  1897. lt.x = lb.x = source.x;
  1898. lt.y = rt.y = source.y;
  1899. rb.x = rt.x = source.x + source.width;
  1900. rb.y = lb.y = source.y + source.height;
  1901. lt.transform(m);
  1902. rt.transform(m);
  1903. rb.transform(m);
  1904. lb.transform(m);
  1905. target.x = mathMin(lt.x, rb.x, lb.x, rt.x);
  1906. target.y = mathMin(lt.y, rb.y, lb.y, rt.y);
  1907. var maxX = mathMax(lt.x, rb.x, lb.x, rt.x);
  1908. var maxY = mathMax(lt.y, rb.y, lb.y, rt.y);
  1909. target.width = maxX - target.x;
  1910. target.height = maxY - target.y;
  1911. };
  1912. return BoundingRect;
  1913. }());
  1914. var SILENT = 'silent';
  1915. function makeEventPacket(eveType, targetInfo, event) {
  1916. return {
  1917. type: eveType,
  1918. event: event,
  1919. target: targetInfo.target,
  1920. topTarget: targetInfo.topTarget,
  1921. cancelBubble: false,
  1922. offsetX: event.zrX,
  1923. offsetY: event.zrY,
  1924. gestureEvent: event.gestureEvent,
  1925. pinchX: event.pinchX,
  1926. pinchY: event.pinchY,
  1927. pinchScale: event.pinchScale,
  1928. wheelDelta: event.zrDelta,
  1929. zrByTouch: event.zrByTouch,
  1930. which: event.which,
  1931. stop: stopEvent
  1932. };
  1933. }
  1934. function stopEvent() {
  1935. stop(this.event);
  1936. }
  1937. var EmptyProxy = (function (_super) {
  1938. __extends(EmptyProxy, _super);
  1939. function EmptyProxy() {
  1940. var _this = _super !== null && _super.apply(this, arguments) || this;
  1941. _this.handler = null;
  1942. return _this;
  1943. }
  1944. EmptyProxy.prototype.dispose = function () { };
  1945. EmptyProxy.prototype.setCursor = function () { };
  1946. return EmptyProxy;
  1947. }(Eventful));
  1948. var HoveredResult = (function () {
  1949. function HoveredResult(x, y) {
  1950. this.x = x;
  1951. this.y = y;
  1952. }
  1953. return HoveredResult;
  1954. }());
  1955. var handlerNames = [
  1956. 'click', 'dblclick', 'mousewheel', 'mouseout',
  1957. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  1958. ];
  1959. var tmpRect = new BoundingRect(0, 0, 0, 0);
  1960. var Handler = (function (_super) {
  1961. __extends(Handler, _super);
  1962. function Handler(storage, painter, proxy, painterRoot, pointerSize) {
  1963. var _this = _super.call(this) || this;
  1964. _this._hovered = new HoveredResult(0, 0);
  1965. _this.storage = storage;
  1966. _this.painter = painter;
  1967. _this.painterRoot = painterRoot;
  1968. _this._pointerSize = pointerSize;
  1969. proxy = proxy || new EmptyProxy();
  1970. _this.proxy = null;
  1971. _this.setHandlerProxy(proxy);
  1972. _this._draggingMgr = new Draggable(_this);
  1973. return _this;
  1974. }
  1975. Handler.prototype.setHandlerProxy = function (proxy) {
  1976. if (this.proxy) {
  1977. this.proxy.dispose();
  1978. }
  1979. if (proxy) {
  1980. each(handlerNames, function (name) {
  1981. proxy.on && proxy.on(name, this[name], this);
  1982. }, this);
  1983. proxy.handler = this;
  1984. }
  1985. this.proxy = proxy;
  1986. };
  1987. Handler.prototype.mousemove = function (event) {
  1988. var x = event.zrX;
  1989. var y = event.zrY;
  1990. var isOutside = isOutsideBoundary(this, x, y);
  1991. var lastHovered = this._hovered;
  1992. var lastHoveredTarget = lastHovered.target;
  1993. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  1994. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  1995. lastHoveredTarget = lastHovered.target;
  1996. }
  1997. var hovered = this._hovered = isOutside ? new HoveredResult(x, y) : this.findHover(x, y);
  1998. var hoveredTarget = hovered.target;
  1999. var proxy = this.proxy;
  2000. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  2001. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2002. this.dispatchToElement(lastHovered, 'mouseout', event);
  2003. }
  2004. this.dispatchToElement(hovered, 'mousemove', event);
  2005. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2006. this.dispatchToElement(hovered, 'mouseover', event);
  2007. }
  2008. };
  2009. Handler.prototype.mouseout = function (event) {
  2010. var eventControl = event.zrEventControl;
  2011. if (eventControl !== 'only_globalout') {
  2012. this.dispatchToElement(this._hovered, 'mouseout', event);
  2013. }
  2014. if (eventControl !== 'no_globalout') {
  2015. this.trigger('globalout', { type: 'globalout', event: event });
  2016. }
  2017. };
  2018. Handler.prototype.resize = function () {
  2019. this._hovered = new HoveredResult(0, 0);
  2020. };
  2021. Handler.prototype.dispatch = function (eventName, eventArgs) {
  2022. var handler = this[eventName];
  2023. handler && handler.call(this, eventArgs);
  2024. };
  2025. Handler.prototype.dispose = function () {
  2026. this.proxy.dispose();
  2027. this.storage = null;
  2028. this.proxy = null;
  2029. this.painter = null;
  2030. };
  2031. Handler.prototype.setCursorStyle = function (cursorStyle) {
  2032. var proxy = this.proxy;
  2033. proxy.setCursor && proxy.setCursor(cursorStyle);
  2034. };
  2035. Handler.prototype.dispatchToElement = function (targetInfo, eventName, event) {
  2036. targetInfo = targetInfo || {};
  2037. var el = targetInfo.target;
  2038. if (el && el.silent) {
  2039. return;
  2040. }
  2041. var eventKey = ('on' + eventName);
  2042. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2043. while (el) {
  2044. el[eventKey]
  2045. && (eventPacket.cancelBubble = !!el[eventKey].call(el, eventPacket));
  2046. el.trigger(eventName, eventPacket);
  2047. el = el.__hostTarget ? el.__hostTarget : el.parent;
  2048. if (eventPacket.cancelBubble) {
  2049. break;
  2050. }
  2051. }
  2052. if (!eventPacket.cancelBubble) {
  2053. this.trigger(eventName, eventPacket);
  2054. if (this.painter && this.painter.eachOtherLayer) {
  2055. this.painter.eachOtherLayer(function (layer) {
  2056. if (typeof (layer[eventKey]) === 'function') {
  2057. layer[eventKey].call(layer, eventPacket);
  2058. }
  2059. if (layer.trigger) {
  2060. layer.trigger(eventName, eventPacket);
  2061. }
  2062. });
  2063. }
  2064. }
  2065. };
  2066. Handler.prototype.findHover = function (x, y, exclude) {
  2067. var list = this.storage.getDisplayList();
  2068. var out = new HoveredResult(x, y);
  2069. setHoverTarget(list, out, x, y, exclude);
  2070. if (this._pointerSize && !out.target) {
  2071. var candidates = [];
  2072. var pointerSize = this._pointerSize;
  2073. var targetSizeHalf = pointerSize / 2;
  2074. var pointerRect = new BoundingRect(x - targetSizeHalf, y - targetSizeHalf, pointerSize, pointerSize);
  2075. for (var i = list.length - 1; i >= 0; i--) {
  2076. var el = list[i];
  2077. if (el !== exclude
  2078. && !el.ignore
  2079. && !el.ignoreCoarsePointer
  2080. && (!el.parent || !el.parent.ignoreCoarsePointer)) {
  2081. tmpRect.copy(el.getBoundingRect());
  2082. if (el.transform) {
  2083. tmpRect.applyTransform(el.transform);
  2084. }
  2085. if (tmpRect.intersect(pointerRect)) {
  2086. candidates.push(el);
  2087. }
  2088. }
  2089. }
  2090. if (candidates.length) {
  2091. var rStep = 4;
  2092. var thetaStep = Math.PI / 12;
  2093. var PI2 = Math.PI * 2;
  2094. for (var r = 0; r < targetSizeHalf; r += rStep) {
  2095. for (var theta = 0; theta < PI2; theta += thetaStep) {
  2096. var x1 = x + r * Math.cos(theta);
  2097. var y1 = y + r * Math.sin(theta);
  2098. setHoverTarget(candidates, out, x1, y1, exclude);
  2099. if (out.target) {
  2100. return out;
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. return out;
  2107. };
  2108. Handler.prototype.processGesture = function (event, stage) {
  2109. if (!this._gestureMgr) {
  2110. this._gestureMgr = new GestureMgr();
  2111. }
  2112. var gestureMgr = this._gestureMgr;
  2113. stage === 'start' && gestureMgr.clear();
  2114. var gestureInfo = gestureMgr.recognize(event, this.findHover(event.zrX, event.zrY, null).target, this.proxy.dom);
  2115. stage === 'end' && gestureMgr.clear();
  2116. if (gestureInfo) {
  2117. var type = gestureInfo.type;
  2118. event.gestureEvent = type;
  2119. var res = new HoveredResult();
  2120. res.target = gestureInfo.target;
  2121. this.dispatchToElement(res, type, gestureInfo.event);
  2122. }
  2123. };
  2124. return Handler;
  2125. }(Eventful));
  2126. each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2127. Handler.prototype[name] = function (event) {
  2128. var x = event.zrX;
  2129. var y = event.zrY;
  2130. var isOutside = isOutsideBoundary(this, x, y);
  2131. var hovered;
  2132. var hoveredTarget;
  2133. if (name !== 'mouseup' || !isOutside) {
  2134. hovered = this.findHover(x, y);
  2135. hoveredTarget = hovered.target;
  2136. }
  2137. if (name === 'mousedown') {
  2138. this._downEl = hoveredTarget;
  2139. this._downPoint = [event.zrX, event.zrY];
  2140. this._upEl = hoveredTarget;
  2141. }
  2142. else if (name === 'mouseup') {
  2143. this._upEl = hoveredTarget;
  2144. }
  2145. else if (name === 'click') {
  2146. if (this._downEl !== this._upEl
  2147. || !this._downPoint
  2148. || dist(this._downPoint, [event.zrX, event.zrY]) > 4) {
  2149. return;
  2150. }
  2151. this._downPoint = null;
  2152. }
  2153. this.dispatchToElement(hovered, name, event);
  2154. };
  2155. });
  2156. function isHover(displayable, x, y) {
  2157. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2158. var el = displayable;
  2159. var isSilent = void 0;
  2160. var ignoreClip = false;
  2161. while (el) {
  2162. if (el.ignoreClip) {
  2163. ignoreClip = true;
  2164. }
  2165. if (!ignoreClip) {
  2166. var clipPath = el.getClipPath();
  2167. if (clipPath && !clipPath.contain(x, y)) {
  2168. return false;
  2169. }
  2170. if (el.silent) {
  2171. isSilent = true;
  2172. }
  2173. }
  2174. var hostEl = el.__hostTarget;
  2175. el = hostEl ? hostEl : el.parent;
  2176. }
  2177. return isSilent ? SILENT : true;
  2178. }
  2179. return false;
  2180. }
  2181. function setHoverTarget(list, out, x, y, exclude) {
  2182. for (var i = list.length - 1; i >= 0; i--) {
  2183. var el = list[i];
  2184. var hoverCheckResult = void 0;
  2185. if (el !== exclude
  2186. && !el.ignore
  2187. && (hoverCheckResult = isHover(el, x, y))) {
  2188. !out.topTarget && (out.topTarget = el);
  2189. if (hoverCheckResult !== SILENT) {
  2190. out.target = el;
  2191. break;
  2192. }
  2193. }
  2194. }
  2195. }
  2196. function isOutsideBoundary(handlerInstance, x, y) {
  2197. var painter = handlerInstance.painter;
  2198. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  2199. }
  2200. var DEFAULT_MIN_MERGE = 32;
  2201. var DEFAULT_MIN_GALLOPING = 7;
  2202. function minRunLength(n) {
  2203. var r = 0;
  2204. while (n >= DEFAULT_MIN_MERGE) {
  2205. r |= n & 1;
  2206. n >>= 1;
  2207. }
  2208. return n + r;
  2209. }
  2210. function makeAscendingRun(array, lo, hi, compare) {
  2211. var runHi = lo + 1;
  2212. if (runHi === hi) {
  2213. return 1;
  2214. }
  2215. if (compare(array[runHi++], array[lo]) < 0) {
  2216. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  2217. runHi++;
  2218. }
  2219. reverseRun(array, lo, runHi);
  2220. }
  2221. else {
  2222. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  2223. runHi++;
  2224. }
  2225. }
  2226. return runHi - lo;
  2227. }
  2228. function reverseRun(array, lo, hi) {
  2229. hi--;
  2230. while (lo < hi) {
  2231. var t = array[lo];
  2232. array[lo++] = array[hi];
  2233. array[hi--] = t;
  2234. }
  2235. }
  2236. function binaryInsertionSort(array, lo, hi, start, compare) {
  2237. if (start === lo) {
  2238. start++;
  2239. }
  2240. for (; start < hi; start++) {
  2241. var pivot = array[start];
  2242. var left = lo;
  2243. var right = start;
  2244. var mid;
  2245. while (left < right) {
  2246. mid = left + right >>> 1;
  2247. if (compare(pivot, array[mid]) < 0) {
  2248. right = mid;
  2249. }
  2250. else {
  2251. left = mid + 1;
  2252. }
  2253. }
  2254. var n = start - left;
  2255. switch (n) {
  2256. case 3:
  2257. array[left + 3] = array[left + 2];
  2258. case 2:
  2259. array[left + 2] = array[left + 1];
  2260. case 1:
  2261. array[left + 1] = array[left];
  2262. break;
  2263. default:
  2264. while (n > 0) {
  2265. array[left + n] = array[left + n - 1];
  2266. n--;
  2267. }
  2268. }
  2269. array[left] = pivot;
  2270. }
  2271. }
  2272. function gallopLeft(value, array, start, length, hint, compare) {
  2273. var lastOffset = 0;
  2274. var maxOffset = 0;
  2275. var offset = 1;
  2276. if (compare(value, array[start + hint]) > 0) {
  2277. maxOffset = length - hint;
  2278. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  2279. lastOffset = offset;
  2280. offset = (offset << 1) + 1;
  2281. if (offset <= 0) {
  2282. offset = maxOffset;
  2283. }
  2284. }
  2285. if (offset > maxOffset) {
  2286. offset = maxOffset;
  2287. }
  2288. lastOffset += hint;
  2289. offset += hint;
  2290. }
  2291. else {
  2292. maxOffset = hint + 1;
  2293. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  2294. lastOffset = offset;
  2295. offset = (offset << 1) + 1;
  2296. if (offset <= 0) {
  2297. offset = maxOffset;
  2298. }
  2299. }
  2300. if (offset > maxOffset) {
  2301. offset = maxOffset;
  2302. }
  2303. var tmp = lastOffset;
  2304. lastOffset = hint - offset;
  2305. offset = hint - tmp;
  2306. }
  2307. lastOffset++;
  2308. while (lastOffset < offset) {
  2309. var m = lastOffset + (offset - lastOffset >>> 1);
  2310. if (compare(value, array[start + m]) > 0) {
  2311. lastOffset = m + 1;
  2312. }
  2313. else {
  2314. offset = m;
  2315. }
  2316. }
  2317. return offset;
  2318. }
  2319. function gallopRight(value, array, start, length, hint, compare) {
  2320. var lastOffset = 0;
  2321. var maxOffset = 0;
  2322. var offset = 1;
  2323. if (compare(value, array[start + hint]) < 0) {
  2324. maxOffset = hint + 1;
  2325. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  2326. lastOffset = offset;
  2327. offset = (offset << 1) + 1;
  2328. if (offset <= 0) {
  2329. offset = maxOffset;
  2330. }
  2331. }
  2332. if (offset > maxOffset) {
  2333. offset = maxOffset;
  2334. }
  2335. var tmp = lastOffset;
  2336. lastOffset = hint - offset;
  2337. offset = hint - tmp;
  2338. }
  2339. else {
  2340. maxOffset = length - hint;
  2341. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  2342. lastOffset = offset;
  2343. offset = (offset << 1) + 1;
  2344. if (offset <= 0) {
  2345. offset = maxOffset;
  2346. }
  2347. }
  2348. if (offset > maxOffset) {
  2349. offset = maxOffset;
  2350. }
  2351. lastOffset += hint;
  2352. offset += hint;
  2353. }
  2354. lastOffset++;
  2355. while (lastOffset < offset) {
  2356. var m = lastOffset + (offset - lastOffset >>> 1);
  2357. if (compare(value, array[start + m]) < 0) {
  2358. offset = m;
  2359. }
  2360. else {
  2361. lastOffset = m + 1;
  2362. }
  2363. }
  2364. return offset;
  2365. }
  2366. function TimSort(array, compare) {
  2367. var minGallop = DEFAULT_MIN_GALLOPING;
  2368. var length = 0;
  2369. var runStart;
  2370. var runLength;
  2371. var stackSize = 0;
  2372. length = array.length;
  2373. var tmp = [];
  2374. runStart = [];
  2375. runLength = [];
  2376. function pushRun(_runStart, _runLength) {
  2377. runStart[stackSize] = _runStart;
  2378. runLength[stackSize] = _runLength;
  2379. stackSize += 1;
  2380. }
  2381. function mergeRuns() {
  2382. while (stackSize > 1) {
  2383. var n = stackSize - 2;
  2384. if ((n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1])
  2385. || (n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1])) {
  2386. if (runLength[n - 1] < runLength[n + 1]) {
  2387. n--;
  2388. }
  2389. }
  2390. else if (runLength[n] > runLength[n + 1]) {
  2391. break;
  2392. }
  2393. mergeAt(n);
  2394. }
  2395. }
  2396. function forceMergeRuns() {
  2397. while (stackSize > 1) {
  2398. var n = stackSize - 2;
  2399. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  2400. n--;
  2401. }
  2402. mergeAt(n);
  2403. }
  2404. }
  2405. function mergeAt(i) {
  2406. var start1 = runStart[i];
  2407. var length1 = runLength[i];
  2408. var start2 = runStart[i + 1];
  2409. var length2 = runLength[i + 1];
  2410. runLength[i] = length1 + length2;
  2411. if (i === stackSize - 3) {
  2412. runStart[i + 1] = runStart[i + 2];
  2413. runLength[i + 1] = runLength[i + 2];
  2414. }
  2415. stackSize--;
  2416. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  2417. start1 += k;
  2418. length1 -= k;
  2419. if (length1 === 0) {
  2420. return;
  2421. }
  2422. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  2423. if (length2 === 0) {
  2424. return;
  2425. }
  2426. if (length1 <= length2) {
  2427. mergeLow(start1, length1, start2, length2);
  2428. }
  2429. else {
  2430. mergeHigh(start1, length1, start2, length2);
  2431. }
  2432. }
  2433. function mergeLow(start1, length1, start2, length2) {
  2434. var i = 0;
  2435. for (i = 0; i < length1; i++) {
  2436. tmp[i] = array[start1 + i];
  2437. }
  2438. var cursor1 = 0;
  2439. var cursor2 = start2;
  2440. var dest = start1;
  2441. array[dest++] = array[cursor2++];
  2442. if (--length2 === 0) {
  2443. for (i = 0; i < length1; i++) {
  2444. array[dest + i] = tmp[cursor1 + i];
  2445. }
  2446. return;
  2447. }
  2448. if (length1 === 1) {
  2449. for (i = 0; i < length2; i++) {
  2450. array[dest + i] = array[cursor2 + i];
  2451. }
  2452. array[dest + length2] = tmp[cursor1];
  2453. return;
  2454. }
  2455. var _minGallop = minGallop;
  2456. var count1;
  2457. var count2;
  2458. var exit;
  2459. while (1) {
  2460. count1 = 0;
  2461. count2 = 0;
  2462. exit = false;
  2463. do {
  2464. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  2465. array[dest++] = array[cursor2++];
  2466. count2++;
  2467. count1 = 0;
  2468. if (--length2 === 0) {
  2469. exit = true;
  2470. break;
  2471. }
  2472. }
  2473. else {
  2474. array[dest++] = tmp[cursor1++];
  2475. count1++;
  2476. count2 = 0;
  2477. if (--length1 === 1) {
  2478. exit = true;
  2479. break;
  2480. }
  2481. }
  2482. } while ((count1 | count2) < _minGallop);
  2483. if (exit) {
  2484. break;
  2485. }
  2486. do {
  2487. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  2488. if (count1 !== 0) {
  2489. for (i = 0; i < count1; i++) {
  2490. array[dest + i] = tmp[cursor1 + i];
  2491. }
  2492. dest += count1;
  2493. cursor1 += count1;
  2494. length1 -= count1;
  2495. if (length1 <= 1) {
  2496. exit = true;
  2497. break;
  2498. }
  2499. }
  2500. array[dest++] = array[cursor2++];
  2501. if (--length2 === 0) {
  2502. exit = true;
  2503. break;
  2504. }
  2505. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  2506. if (count2 !== 0) {
  2507. for (i = 0; i < count2; i++) {
  2508. array[dest + i] = array[cursor2 + i];
  2509. }
  2510. dest += count2;
  2511. cursor2 += count2;
  2512. length2 -= count2;
  2513. if (length2 === 0) {
  2514. exit = true;
  2515. break;
  2516. }
  2517. }
  2518. array[dest++] = tmp[cursor1++];
  2519. if (--length1 === 1) {
  2520. exit = true;
  2521. break;
  2522. }
  2523. _minGallop--;
  2524. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2525. if (exit) {
  2526. break;
  2527. }
  2528. if (_minGallop < 0) {
  2529. _minGallop = 0;
  2530. }
  2531. _minGallop += 2;
  2532. }
  2533. minGallop = _minGallop;
  2534. minGallop < 1 && (minGallop = 1);
  2535. if (length1 === 1) {
  2536. for (i = 0; i < length2; i++) {
  2537. array[dest + i] = array[cursor2 + i];
  2538. }
  2539. array[dest + length2] = tmp[cursor1];
  2540. }
  2541. else if (length1 === 0) {
  2542. throw new Error();
  2543. }
  2544. else {
  2545. for (i = 0; i < length1; i++) {
  2546. array[dest + i] = tmp[cursor1 + i];
  2547. }
  2548. }
  2549. }
  2550. function mergeHigh(start1, length1, start2, length2) {
  2551. var i = 0;
  2552. for (i = 0; i < length2; i++) {
  2553. tmp[i] = array[start2 + i];
  2554. }
  2555. var cursor1 = start1 + length1 - 1;
  2556. var cursor2 = length2 - 1;
  2557. var dest = start2 + length2 - 1;
  2558. var customCursor = 0;
  2559. var customDest = 0;
  2560. array[dest--] = array[cursor1--];
  2561. if (--length1 === 0) {
  2562. customCursor = dest - (length2 - 1);
  2563. for (i = 0; i < length2; i++) {
  2564. array[customCursor + i] = tmp[i];
  2565. }
  2566. return;
  2567. }
  2568. if (length2 === 1) {
  2569. dest -= length1;
  2570. cursor1 -= length1;
  2571. customDest = dest + 1;
  2572. customCursor = cursor1 + 1;
  2573. for (i = length1 - 1; i >= 0; i--) {
  2574. array[customDest + i] = array[customCursor + i];
  2575. }
  2576. array[dest] = tmp[cursor2];
  2577. return;
  2578. }
  2579. var _minGallop = minGallop;
  2580. while (true) {
  2581. var count1 = 0;
  2582. var count2 = 0;
  2583. var exit = false;
  2584. do {
  2585. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  2586. array[dest--] = array[cursor1--];
  2587. count1++;
  2588. count2 = 0;
  2589. if (--length1 === 0) {
  2590. exit = true;
  2591. break;
  2592. }
  2593. }
  2594. else {
  2595. array[dest--] = tmp[cursor2--];
  2596. count2++;
  2597. count1 = 0;
  2598. if (--length2 === 1) {
  2599. exit = true;
  2600. break;
  2601. }
  2602. }
  2603. } while ((count1 | count2) < _minGallop);
  2604. if (exit) {
  2605. break;
  2606. }
  2607. do {
  2608. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  2609. if (count1 !== 0) {
  2610. dest -= count1;
  2611. cursor1 -= count1;
  2612. length1 -= count1;
  2613. customDest = dest + 1;
  2614. customCursor = cursor1 + 1;
  2615. for (i = count1 - 1; i >= 0; i--) {
  2616. array[customDest + i] = array[customCursor + i];
  2617. }
  2618. if (length1 === 0) {
  2619. exit = true;
  2620. break;
  2621. }
  2622. }
  2623. array[dest--] = tmp[cursor2--];
  2624. if (--length2 === 1) {
  2625. exit = true;
  2626. break;
  2627. }
  2628. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  2629. if (count2 !== 0) {
  2630. dest -= count2;
  2631. cursor2 -= count2;
  2632. length2 -= count2;
  2633. customDest = dest + 1;
  2634. customCursor = cursor2 + 1;
  2635. for (i = 0; i < count2; i++) {
  2636. array[customDest + i] = tmp[customCursor + i];
  2637. }
  2638. if (length2 <= 1) {
  2639. exit = true;
  2640. break;
  2641. }
  2642. }
  2643. array[dest--] = array[cursor1--];
  2644. if (--length1 === 0) {
  2645. exit = true;
  2646. break;
  2647. }
  2648. _minGallop--;
  2649. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2650. if (exit) {
  2651. break;
  2652. }
  2653. if (_minGallop < 0) {
  2654. _minGallop = 0;
  2655. }
  2656. _minGallop += 2;
  2657. }
  2658. minGallop = _minGallop;
  2659. if (minGallop < 1) {
  2660. minGallop = 1;
  2661. }
  2662. if (length2 === 1) {
  2663. dest -= length1;
  2664. cursor1 -= length1;
  2665. customDest = dest + 1;
  2666. customCursor = cursor1 + 1;
  2667. for (i = length1 - 1; i >= 0; i--) {
  2668. array[customDest + i] = array[customCursor + i];
  2669. }
  2670. array[dest] = tmp[cursor2];
  2671. }
  2672. else if (length2 === 0) {
  2673. throw new Error();
  2674. }
  2675. else {
  2676. customCursor = dest - (length2 - 1);
  2677. for (i = 0; i < length2; i++) {
  2678. array[customCursor + i] = tmp[i];
  2679. }
  2680. }
  2681. }
  2682. return {
  2683. mergeRuns: mergeRuns,
  2684. forceMergeRuns: forceMergeRuns,
  2685. pushRun: pushRun
  2686. };
  2687. }
  2688. function sort(array, compare, lo, hi) {
  2689. if (!lo) {
  2690. lo = 0;
  2691. }
  2692. if (!hi) {
  2693. hi = array.length;
  2694. }
  2695. var remaining = hi - lo;
  2696. if (remaining < 2) {
  2697. return;
  2698. }
  2699. var runLength = 0;
  2700. if (remaining < DEFAULT_MIN_MERGE) {
  2701. runLength = makeAscendingRun(array, lo, hi, compare);
  2702. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  2703. return;
  2704. }
  2705. var ts = TimSort(array, compare);
  2706. var minRun = minRunLength(remaining);
  2707. do {
  2708. runLength = makeAscendingRun(array, lo, hi, compare);
  2709. if (runLength < minRun) {
  2710. var force = remaining;
  2711. if (force > minRun) {
  2712. force = minRun;
  2713. }
  2714. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  2715. runLength = force;
  2716. }
  2717. ts.pushRun(lo, runLength);
  2718. ts.mergeRuns();
  2719. remaining -= runLength;
  2720. lo += runLength;
  2721. } while (remaining !== 0);
  2722. ts.forceMergeRuns();
  2723. }
  2724. var REDRAW_BIT = 1;
  2725. var STYLE_CHANGED_BIT = 2;
  2726. var SHAPE_CHANGED_BIT = 4;
  2727. var invalidZErrorLogged = false;
  2728. function logInvalidZError() {
  2729. if (invalidZErrorLogged) {
  2730. return;
  2731. }
  2732. invalidZErrorLogged = true;
  2733. console.warn('z / z2 / zlevel of displayable is invalid, which may cause unexpected errors');
  2734. }
  2735. function shapeCompareFunc(a, b) {
  2736. if (a.zlevel === b.zlevel) {
  2737. if (a.z === b.z) {
  2738. return a.z2 - b.z2;
  2739. }
  2740. return a.z - b.z;
  2741. }
  2742. return a.zlevel - b.zlevel;
  2743. }
  2744. var Storage = (function () {
  2745. function Storage() {
  2746. this._roots = [];
  2747. this._displayList = [];
  2748. this._displayListLen = 0;
  2749. this.displayableSortFunc = shapeCompareFunc;
  2750. }
  2751. Storage.prototype.traverse = function (cb, context) {
  2752. for (var i = 0; i < this._roots.length; i++) {
  2753. this._roots[i].traverse(cb, context);
  2754. }
  2755. };
  2756. Storage.prototype.getDisplayList = function (update, includeIgnore) {
  2757. includeIgnore = includeIgnore || false;
  2758. var displayList = this._displayList;
  2759. if (update || !displayList.length) {
  2760. this.updateDisplayList(includeIgnore);
  2761. }
  2762. return displayList;
  2763. };
  2764. Storage.prototype.updateDisplayList = function (includeIgnore) {
  2765. this._displayListLen = 0;
  2766. var roots = this._roots;
  2767. var displayList = this._displayList;
  2768. for (var i = 0, len = roots.length; i < len; i++) {
  2769. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  2770. }
  2771. displayList.length = this._displayListLen;
  2772. sort(displayList, shapeCompareFunc);
  2773. };
  2774. Storage.prototype._updateAndAddDisplayable = function (el, clipPaths, includeIgnore) {
  2775. if (el.ignore && !includeIgnore) {
  2776. return;
  2777. }
  2778. el.beforeUpdate();
  2779. el.update();
  2780. el.afterUpdate();
  2781. var userSetClipPath = el.getClipPath();
  2782. if (el.ignoreClip) {
  2783. clipPaths = null;
  2784. }
  2785. else if (userSetClipPath) {
  2786. if (clipPaths) {
  2787. clipPaths = clipPaths.slice();
  2788. }
  2789. else {
  2790. clipPaths = [];
  2791. }
  2792. var currentClipPath = userSetClipPath;
  2793. var parentClipPath = el;
  2794. while (currentClipPath) {
  2795. currentClipPath.parent = parentClipPath;
  2796. currentClipPath.updateTransform();
  2797. clipPaths.push(currentClipPath);
  2798. parentClipPath = currentClipPath;
  2799. currentClipPath = currentClipPath.getClipPath();
  2800. }
  2801. }
  2802. if (el.childrenRef) {
  2803. var children = el.childrenRef();
  2804. for (var i = 0; i < children.length; i++) {
  2805. var child = children[i];
  2806. if (el.__dirty) {
  2807. child.__dirty |= REDRAW_BIT;
  2808. }
  2809. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  2810. }
  2811. el.__dirty = 0;
  2812. }
  2813. else {
  2814. var disp = el;
  2815. if (clipPaths && clipPaths.length) {
  2816. disp.__clipPaths = clipPaths;
  2817. }
  2818. else if (disp.__clipPaths && disp.__clipPaths.length > 0) {
  2819. disp.__clipPaths = [];
  2820. }
  2821. if (isNaN(disp.z)) {
  2822. logInvalidZError();
  2823. disp.z = 0;
  2824. }
  2825. if (isNaN(disp.z2)) {
  2826. logInvalidZError();
  2827. disp.z2 = 0;
  2828. }
  2829. if (isNaN(disp.zlevel)) {
  2830. logInvalidZError();
  2831. disp.zlevel = 0;
  2832. }
  2833. this._displayList[this._displayListLen++] = disp;
  2834. }
  2835. var decalEl = el.getDecalElement && el.getDecalElement();
  2836. if (decalEl) {
  2837. this._updateAndAddDisplayable(decalEl, clipPaths, includeIgnore);
  2838. }
  2839. var textGuide = el.getTextGuideLine();
  2840. if (textGuide) {
  2841. this._updateAndAddDisplayable(textGuide, clipPaths, includeIgnore);
  2842. }
  2843. var textEl = el.getTextContent();
  2844. if (textEl) {
  2845. this._updateAndAddDisplayable(textEl, clipPaths, includeIgnore);
  2846. }
  2847. };
  2848. Storage.prototype.addRoot = function (el) {
  2849. if (el.__zr && el.__zr.storage === this) {
  2850. return;
  2851. }
  2852. this._roots.push(el);
  2853. };
  2854. Storage.prototype.delRoot = function (el) {
  2855. if (el instanceof Array) {
  2856. for (var i = 0, l = el.length; i < l; i++) {
  2857. this.delRoot(el[i]);
  2858. }
  2859. return;
  2860. }
  2861. var idx = indexOf(this._roots, el);
  2862. if (idx >= 0) {
  2863. this._roots.splice(idx, 1);
  2864. }
  2865. };
  2866. Storage.prototype.delAllRoots = function () {
  2867. this._roots = [];
  2868. this._displayList = [];
  2869. this._displayListLen = 0;
  2870. return;
  2871. };
  2872. Storage.prototype.getRoots = function () {
  2873. return this._roots;
  2874. };
  2875. Storage.prototype.dispose = function () {
  2876. this._displayList = null;
  2877. this._roots = null;
  2878. };
  2879. return Storage;
  2880. }());
  2881. var requestAnimationFrame;
  2882. requestAnimationFrame = (env.hasGlobalWindow
  2883. && ((window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  2884. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  2885. || window.mozRequestAnimationFrame
  2886. || window.webkitRequestAnimationFrame)) || function (func) {
  2887. return setTimeout(func, 16);
  2888. };
  2889. var requestAnimationFrame$1 = requestAnimationFrame;
  2890. var easingFuncs = {
  2891. linear: function (k) {
  2892. return k;
  2893. },
  2894. quadraticIn: function (k) {
  2895. return k * k;
  2896. },
  2897. quadraticOut: function (k) {
  2898. return k * (2 - k);
  2899. },
  2900. quadraticInOut: function (k) {
  2901. if ((k *= 2) < 1) {
  2902. return 0.5 * k * k;
  2903. }
  2904. return -0.5 * (--k * (k - 2) - 1);
  2905. },
  2906. cubicIn: function (k) {
  2907. return k * k * k;
  2908. },
  2909. cubicOut: function (k) {
  2910. return --k * k * k + 1;
  2911. },
  2912. cubicInOut: function (k) {
  2913. if ((k *= 2) < 1) {
  2914. return 0.5 * k * k * k;
  2915. }
  2916. return 0.5 * ((k -= 2) * k * k + 2);
  2917. },
  2918. quarticIn: function (k) {
  2919. return k * k * k * k;
  2920. },
  2921. quarticOut: function (k) {
  2922. return 1 - (--k * k * k * k);
  2923. },
  2924. quarticInOut: function (k) {
  2925. if ((k *= 2) < 1) {
  2926. return 0.5 * k * k * k * k;
  2927. }
  2928. return -0.5 * ((k -= 2) * k * k * k - 2);
  2929. },
  2930. quinticIn: function (k) {
  2931. return k * k * k * k * k;
  2932. },
  2933. quinticOut: function (k) {
  2934. return --k * k * k * k * k + 1;
  2935. },
  2936. quinticInOut: function (k) {
  2937. if ((k *= 2) < 1) {
  2938. return 0.5 * k * k * k * k * k;
  2939. }
  2940. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2941. },
  2942. sinusoidalIn: function (k) {
  2943. return 1 - Math.cos(k * Math.PI / 2);
  2944. },
  2945. sinusoidalOut: function (k) {
  2946. return Math.sin(k * Math.PI / 2);
  2947. },
  2948. sinusoidalInOut: function (k) {
  2949. return 0.5 * (1 - Math.cos(Math.PI * k));
  2950. },
  2951. exponentialIn: function (k) {
  2952. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2953. },
  2954. exponentialOut: function (k) {
  2955. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2956. },
  2957. exponentialInOut: function (k) {
  2958. if (k === 0) {
  2959. return 0;
  2960. }
  2961. if (k === 1) {
  2962. return 1;
  2963. }
  2964. if ((k *= 2) < 1) {
  2965. return 0.5 * Math.pow(1024, k - 1);
  2966. }
  2967. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2968. },
  2969. circularIn: function (k) {
  2970. return 1 - Math.sqrt(1 - k * k);
  2971. },
  2972. circularOut: function (k) {
  2973. return Math.sqrt(1 - (--k * k));
  2974. },
  2975. circularInOut: function (k) {
  2976. if ((k *= 2) < 1) {
  2977. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2978. }
  2979. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2980. },
  2981. elasticIn: function (k) {
  2982. var s;
  2983. var a = 0.1;
  2984. var p = 0.4;
  2985. if (k === 0) {
  2986. return 0;
  2987. }
  2988. if (k === 1) {
  2989. return 1;
  2990. }
  2991. if (!a || a < 1) {
  2992. a = 1;
  2993. s = p / 4;
  2994. }
  2995. else {
  2996. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2997. }
  2998. return -(a * Math.pow(2, 10 * (k -= 1))
  2999. * Math.sin((k - s) * (2 * Math.PI) / p));
  3000. },
  3001. elasticOut: function (k) {
  3002. var s;
  3003. var a = 0.1;
  3004. var p = 0.4;
  3005. if (k === 0) {
  3006. return 0;
  3007. }
  3008. if (k === 1) {
  3009. return 1;
  3010. }
  3011. if (!a || a < 1) {
  3012. a = 1;
  3013. s = p / 4;
  3014. }
  3015. else {
  3016. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3017. }
  3018. return (a * Math.pow(2, -10 * k)
  3019. * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  3020. },
  3021. elasticInOut: function (k) {
  3022. var s;
  3023. var a = 0.1;
  3024. var p = 0.4;
  3025. if (k === 0) {
  3026. return 0;
  3027. }
  3028. if (k === 1) {
  3029. return 1;
  3030. }
  3031. if (!a || a < 1) {
  3032. a = 1;
  3033. s = p / 4;
  3034. }
  3035. else {
  3036. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3037. }
  3038. if ((k *= 2) < 1) {
  3039. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  3040. * Math.sin((k - s) * (2 * Math.PI) / p));
  3041. }
  3042. return a * Math.pow(2, -10 * (k -= 1))
  3043. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  3044. },
  3045. backIn: function (k) {
  3046. var s = 1.70158;
  3047. return k * k * ((s + 1) * k - s);
  3048. },
  3049. backOut: function (k) {
  3050. var s = 1.70158;
  3051. return --k * k * ((s + 1) * k + s) + 1;
  3052. },
  3053. backInOut: function (k) {
  3054. var s = 1.70158 * 1.525;
  3055. if ((k *= 2) < 1) {
  3056. return 0.5 * (k * k * ((s + 1) * k - s));
  3057. }
  3058. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  3059. },
  3060. bounceIn: function (k) {
  3061. return 1 - easingFuncs.bounceOut(1 - k);
  3062. },
  3063. bounceOut: function (k) {
  3064. if (k < (1 / 2.75)) {
  3065. return 7.5625 * k * k;
  3066. }
  3067. else if (k < (2 / 2.75)) {
  3068. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  3069. }
  3070. else if (k < (2.5 / 2.75)) {
  3071. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  3072. }
  3073. else {
  3074. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  3075. }
  3076. },
  3077. bounceInOut: function (k) {
  3078. if (k < 0.5) {
  3079. return easingFuncs.bounceIn(k * 2) * 0.5;
  3080. }
  3081. return easingFuncs.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  3082. }
  3083. };
  3084. var mathPow = Math.pow;
  3085. var mathSqrt = Math.sqrt;
  3086. var EPSILON = 1e-8;
  3087. var EPSILON_NUMERIC = 1e-4;
  3088. var THREE_SQRT = mathSqrt(3);
  3089. var ONE_THIRD = 1 / 3;
  3090. var _v0 = create();
  3091. var _v1 = create();
  3092. var _v2 = create();
  3093. function isAroundZero(val) {
  3094. return val > -EPSILON && val < EPSILON;
  3095. }
  3096. function isNotAroundZero(val) {
  3097. return val > EPSILON || val < -EPSILON;
  3098. }
  3099. function cubicAt(p0, p1, p2, p3, t) {
  3100. var onet = 1 - t;
  3101. return onet * onet * (onet * p0 + 3 * t * p1)
  3102. + t * t * (t * p3 + 3 * onet * p2);
  3103. }
  3104. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  3105. var onet = 1 - t;
  3106. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  3107. + (p3 - p2) * t * t);
  3108. }
  3109. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  3110. var a = p3 + 3 * (p1 - p2) - p0;
  3111. var b = 3 * (p2 - p1 * 2 + p0);
  3112. var c = 3 * (p1 - p0);
  3113. var d = p0 - val;
  3114. var A = b * b - 3 * a * c;
  3115. var B = b * c - 9 * a * d;
  3116. var C = c * c - 3 * b * d;
  3117. var n = 0;
  3118. if (isAroundZero(A) && isAroundZero(B)) {
  3119. if (isAroundZero(b)) {
  3120. roots[0] = 0;
  3121. }
  3122. else {
  3123. var t1 = -c / b;
  3124. if (t1 >= 0 && t1 <= 1) {
  3125. roots[n++] = t1;
  3126. }
  3127. }
  3128. }
  3129. else {
  3130. var disc = B * B - 4 * A * C;
  3131. if (isAroundZero(disc)) {
  3132. var K = B / A;
  3133. var t1 = -b / a + K;
  3134. var t2 = -K / 2;
  3135. if (t1 >= 0 && t1 <= 1) {
  3136. roots[n++] = t1;
  3137. }
  3138. if (t2 >= 0 && t2 <= 1) {
  3139. roots[n++] = t2;
  3140. }
  3141. }
  3142. else if (disc > 0) {
  3143. var discSqrt = mathSqrt(disc);
  3144. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  3145. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  3146. if (Y1 < 0) {
  3147. Y1 = -mathPow(-Y1, ONE_THIRD);
  3148. }
  3149. else {
  3150. Y1 = mathPow(Y1, ONE_THIRD);
  3151. }
  3152. if (Y2 < 0) {
  3153. Y2 = -mathPow(-Y2, ONE_THIRD);
  3154. }
  3155. else {
  3156. Y2 = mathPow(Y2, ONE_THIRD);
  3157. }
  3158. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  3159. if (t1 >= 0 && t1 <= 1) {
  3160. roots[n++] = t1;
  3161. }
  3162. }
  3163. else {
  3164. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  3165. var theta = Math.acos(T) / 3;
  3166. var ASqrt = mathSqrt(A);
  3167. var tmp = Math.cos(theta);
  3168. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  3169. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  3170. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  3171. if (t1 >= 0 && t1 <= 1) {
  3172. roots[n++] = t1;
  3173. }
  3174. if (t2 >= 0 && t2 <= 1) {
  3175. roots[n++] = t2;
  3176. }
  3177. if (t3 >= 0 && t3 <= 1) {
  3178. roots[n++] = t3;
  3179. }
  3180. }
  3181. }
  3182. return n;
  3183. }
  3184. function cubicExtrema(p0, p1, p2, p3, extrema) {
  3185. var b = 6 * p2 - 12 * p1 + 6 * p0;
  3186. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  3187. var c = 3 * p1 - 3 * p0;
  3188. var n = 0;
  3189. if (isAroundZero(a)) {
  3190. if (isNotAroundZero(b)) {
  3191. var t1 = -c / b;
  3192. if (t1 >= 0 && t1 <= 1) {
  3193. extrema[n++] = t1;
  3194. }
  3195. }
  3196. }
  3197. else {
  3198. var disc = b * b - 4 * a * c;
  3199. if (isAroundZero(disc)) {
  3200. extrema[0] = -b / (2 * a);
  3201. }
  3202. else if (disc > 0) {
  3203. var discSqrt = mathSqrt(disc);
  3204. var t1 = (-b + discSqrt) / (2 * a);
  3205. var t2 = (-b - discSqrt) / (2 * a);
  3206. if (t1 >= 0 && t1 <= 1) {
  3207. extrema[n++] = t1;
  3208. }
  3209. if (t2 >= 0 && t2 <= 1) {
  3210. extrema[n++] = t2;
  3211. }
  3212. }
  3213. }
  3214. return n;
  3215. }
  3216. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  3217. var p01 = (p1 - p0) * t + p0;
  3218. var p12 = (p2 - p1) * t + p1;
  3219. var p23 = (p3 - p2) * t + p2;
  3220. var p012 = (p12 - p01) * t + p01;
  3221. var p123 = (p23 - p12) * t + p12;
  3222. var p0123 = (p123 - p012) * t + p012;
  3223. out[0] = p0;
  3224. out[1] = p01;
  3225. out[2] = p012;
  3226. out[3] = p0123;
  3227. out[4] = p0123;
  3228. out[5] = p123;
  3229. out[6] = p23;
  3230. out[7] = p3;
  3231. }
  3232. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  3233. var t;
  3234. var interval = 0.005;
  3235. var d = Infinity;
  3236. var prev;
  3237. var next;
  3238. var d1;
  3239. var d2;
  3240. _v0[0] = x;
  3241. _v0[1] = y;
  3242. for (var _t = 0; _t < 1; _t += 0.05) {
  3243. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  3244. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  3245. d1 = distSquare(_v0, _v1);
  3246. if (d1 < d) {
  3247. t = _t;
  3248. d = d1;
  3249. }
  3250. }
  3251. d = Infinity;
  3252. for (var i = 0; i < 32; i++) {
  3253. if (interval < EPSILON_NUMERIC) {
  3254. break;
  3255. }
  3256. prev = t - interval;
  3257. next = t + interval;
  3258. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  3259. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  3260. d1 = distSquare(_v1, _v0);
  3261. if (prev >= 0 && d1 < d) {
  3262. t = prev;
  3263. d = d1;
  3264. }
  3265. else {
  3266. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  3267. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  3268. d2 = distSquare(_v2, _v0);
  3269. if (next <= 1 && d2 < d) {
  3270. t = next;
  3271. d = d2;
  3272. }
  3273. else {
  3274. interval *= 0.5;
  3275. }
  3276. }
  3277. }
  3278. if (out) {
  3279. out[0] = cubicAt(x0, x1, x2, x3, t);
  3280. out[1] = cubicAt(y0, y1, y2, y3, t);
  3281. }
  3282. return mathSqrt(d);
  3283. }
  3284. function cubicLength(x0, y0, x1, y1, x2, y2, x3, y3, iteration) {
  3285. var px = x0;
  3286. var py = y0;
  3287. var d = 0;
  3288. var step = 1 / iteration;
  3289. for (var i = 1; i <= iteration; i++) {
  3290. var t = i * step;
  3291. var x = cubicAt(x0, x1, x2, x3, t);
  3292. var y = cubicAt(y0, y1, y2, y3, t);
  3293. var dx = x - px;
  3294. var dy = y - py;
  3295. d += Math.sqrt(dx * dx + dy * dy);
  3296. px = x;
  3297. py = y;
  3298. }
  3299. return d;
  3300. }
  3301. function quadraticAt(p0, p1, p2, t) {
  3302. var onet = 1 - t;
  3303. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  3304. }
  3305. function quadraticDerivativeAt(p0, p1, p2, t) {
  3306. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  3307. }
  3308. function quadraticRootAt(p0, p1, p2, val, roots) {
  3309. var a = p0 - 2 * p1 + p2;
  3310. var b = 2 * (p1 - p0);
  3311. var c = p0 - val;
  3312. var n = 0;
  3313. if (isAroundZero(a)) {
  3314. if (isNotAroundZero(b)) {
  3315. var t1 = -c / b;
  3316. if (t1 >= 0 && t1 <= 1) {
  3317. roots[n++] = t1;
  3318. }
  3319. }
  3320. }
  3321. else {
  3322. var disc = b * b - 4 * a * c;
  3323. if (isAroundZero(disc)) {
  3324. var t1 = -b / (2 * a);
  3325. if (t1 >= 0 && t1 <= 1) {
  3326. roots[n++] = t1;
  3327. }
  3328. }
  3329. else if (disc > 0) {
  3330. var discSqrt = mathSqrt(disc);
  3331. var t1 = (-b + discSqrt) / (2 * a);
  3332. var t2 = (-b - discSqrt) / (2 * a);
  3333. if (t1 >= 0 && t1 <= 1) {
  3334. roots[n++] = t1;
  3335. }
  3336. if (t2 >= 0 && t2 <= 1) {
  3337. roots[n++] = t2;
  3338. }
  3339. }
  3340. }
  3341. return n;
  3342. }
  3343. function quadraticExtremum(p0, p1, p2) {
  3344. var divider = p0 + p2 - 2 * p1;
  3345. if (divider === 0) {
  3346. return 0.5;
  3347. }
  3348. else {
  3349. return (p0 - p1) / divider;
  3350. }
  3351. }
  3352. function quadraticSubdivide(p0, p1, p2, t, out) {
  3353. var p01 = (p1 - p0) * t + p0;
  3354. var p12 = (p2 - p1) * t + p1;
  3355. var p012 = (p12 - p01) * t + p01;
  3356. out[0] = p0;
  3357. out[1] = p01;
  3358. out[2] = p012;
  3359. out[3] = p012;
  3360. out[4] = p12;
  3361. out[5] = p2;
  3362. }
  3363. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  3364. var t;
  3365. var interval = 0.005;
  3366. var d = Infinity;
  3367. _v0[0] = x;
  3368. _v0[1] = y;
  3369. for (var _t = 0; _t < 1; _t += 0.05) {
  3370. _v1[0] = quadraticAt(x0, x1, x2, _t);
  3371. _v1[1] = quadraticAt(y0, y1, y2, _t);
  3372. var d1 = distSquare(_v0, _v1);
  3373. if (d1 < d) {
  3374. t = _t;
  3375. d = d1;
  3376. }
  3377. }
  3378. d = Infinity;
  3379. for (var i = 0; i < 32; i++) {
  3380. if (interval < EPSILON_NUMERIC) {
  3381. break;
  3382. }
  3383. var prev = t - interval;
  3384. var next = t + interval;
  3385. _v1[0] = quadraticAt(x0, x1, x2, prev);
  3386. _v1[1] = quadraticAt(y0, y1, y2, prev);
  3387. var d1 = distSquare(_v1, _v0);
  3388. if (prev >= 0 && d1 < d) {
  3389. t = prev;
  3390. d = d1;
  3391. }
  3392. else {
  3393. _v2[0] = quadraticAt(x0, x1, x2, next);
  3394. _v2[1] = quadraticAt(y0, y1, y2, next);
  3395. var d2 = distSquare(_v2, _v0);
  3396. if (next <= 1 && d2 < d) {
  3397. t = next;
  3398. d = d2;
  3399. }
  3400. else {
  3401. interval *= 0.5;
  3402. }
  3403. }
  3404. }
  3405. if (out) {
  3406. out[0] = quadraticAt(x0, x1, x2, t);
  3407. out[1] = quadraticAt(y0, y1, y2, t);
  3408. }
  3409. return mathSqrt(d);
  3410. }
  3411. function quadraticLength(x0, y0, x1, y1, x2, y2, iteration) {
  3412. var px = x0;
  3413. var py = y0;
  3414. var d = 0;
  3415. var step = 1 / iteration;
  3416. for (var i = 1; i <= iteration; i++) {
  3417. var t = i * step;
  3418. var x = quadraticAt(x0, x1, x2, t);
  3419. var y = quadraticAt(y0, y1, y2, t);
  3420. var dx = x - px;
  3421. var dy = y - py;
  3422. d += Math.sqrt(dx * dx + dy * dy);
  3423. px = x;
  3424. py = y;
  3425. }
  3426. return d;
  3427. }
  3428. var regexp = /cubic-bezier\(([0-9,\.e ]+)\)/;
  3429. function createCubicEasingFunc(cubicEasingStr) {
  3430. var cubic = cubicEasingStr && regexp.exec(cubicEasingStr);
  3431. if (cubic) {
  3432. var points = cubic[1].split(',');
  3433. var a_1 = +trim(points[0]);
  3434. var b_1 = +trim(points[1]);
  3435. var c_1 = +trim(points[2]);
  3436. var d_1 = +trim(points[3]);
  3437. if (isNaN(a_1 + b_1 + c_1 + d_1)) {
  3438. return;
  3439. }
  3440. var roots_1 = [];
  3441. return function (p) {
  3442. return p <= 0
  3443. ? 0 : p >= 1
  3444. ? 1
  3445. : cubicRootAt(0, a_1, c_1, 1, p, roots_1) && cubicAt(0, b_1, d_1, 1, roots_1[0]);
  3446. };
  3447. }
  3448. }
  3449. var Clip = (function () {
  3450. function Clip(opts) {
  3451. this._inited = false;
  3452. this._startTime = 0;
  3453. this._pausedTime = 0;
  3454. this._paused = false;
  3455. this._life = opts.life || 1000;
  3456. this._delay = opts.delay || 0;
  3457. this.loop = opts.loop || false;
  3458. this.onframe = opts.onframe || noop;
  3459. this.ondestroy = opts.ondestroy || noop;
  3460. this.onrestart = opts.onrestart || noop;
  3461. opts.easing && this.setEasing(opts.easing);
  3462. }
  3463. Clip.prototype.step = function (globalTime, deltaTime) {
  3464. if (!this._inited) {
  3465. this._startTime = globalTime + this._delay;
  3466. this._inited = true;
  3467. }
  3468. if (this._paused) {
  3469. this._pausedTime += deltaTime;
  3470. return;
  3471. }
  3472. var life = this._life;
  3473. var elapsedTime = globalTime - this._startTime - this._pausedTime;
  3474. var percent = elapsedTime / life;
  3475. if (percent < 0) {
  3476. percent = 0;
  3477. }
  3478. percent = Math.min(percent, 1);
  3479. var easingFunc = this.easingFunc;
  3480. var schedule = easingFunc ? easingFunc(percent) : percent;
  3481. this.onframe(schedule);
  3482. if (percent === 1) {
  3483. if (this.loop) {
  3484. var remainder = elapsedTime % life;
  3485. this._startTime = globalTime - remainder;
  3486. this._pausedTime = 0;
  3487. this.onrestart();
  3488. }
  3489. else {
  3490. return true;
  3491. }
  3492. }
  3493. return false;
  3494. };
  3495. Clip.prototype.pause = function () {
  3496. this._paused = true;
  3497. };
  3498. Clip.prototype.resume = function () {
  3499. this._paused = false;
  3500. };
  3501. Clip.prototype.setEasing = function (easing) {
  3502. this.easing = easing;
  3503. this.easingFunc = isFunction(easing)
  3504. ? easing
  3505. : easingFuncs[easing] || createCubicEasingFunc(easing);
  3506. };
  3507. return Clip;
  3508. }());
  3509. var Entry = (function () {
  3510. function Entry(val) {
  3511. this.value = val;
  3512. }
  3513. return Entry;
  3514. }());
  3515. var LinkedList = (function () {
  3516. function LinkedList() {
  3517. this._len = 0;
  3518. }
  3519. LinkedList.prototype.insert = function (val) {
  3520. var entry = new Entry(val);
  3521. this.insertEntry(entry);
  3522. return entry;
  3523. };
  3524. LinkedList.prototype.insertEntry = function (entry) {
  3525. if (!this.head) {
  3526. this.head = this.tail = entry;
  3527. }
  3528. else {
  3529. this.tail.next = entry;
  3530. entry.prev = this.tail;
  3531. entry.next = null;
  3532. this.tail = entry;
  3533. }
  3534. this._len++;
  3535. };
  3536. LinkedList.prototype.remove = function (entry) {
  3537. var prev = entry.prev;
  3538. var next = entry.next;
  3539. if (prev) {
  3540. prev.next = next;
  3541. }
  3542. else {
  3543. this.head = next;
  3544. }
  3545. if (next) {
  3546. next.prev = prev;
  3547. }
  3548. else {
  3549. this.tail = prev;
  3550. }
  3551. entry.next = entry.prev = null;
  3552. this._len--;
  3553. };
  3554. LinkedList.prototype.len = function () {
  3555. return this._len;
  3556. };
  3557. LinkedList.prototype.clear = function () {
  3558. this.head = this.tail = null;
  3559. this._len = 0;
  3560. };
  3561. return LinkedList;
  3562. }());
  3563. var LRU = (function () {
  3564. function LRU(maxSize) {
  3565. this._list = new LinkedList();
  3566. this._maxSize = 10;
  3567. this._map = {};
  3568. this._maxSize = maxSize;
  3569. }
  3570. LRU.prototype.put = function (key, value) {
  3571. var list = this._list;
  3572. var map = this._map;
  3573. var removed = null;
  3574. if (map[key] == null) {
  3575. var len = list.len();
  3576. var entry = this._lastRemovedEntry;
  3577. if (len >= this._maxSize && len > 0) {
  3578. var leastUsedEntry = list.head;
  3579. list.remove(leastUsedEntry);
  3580. delete map[leastUsedEntry.key];
  3581. removed = leastUsedEntry.value;
  3582. this._lastRemovedEntry = leastUsedEntry;
  3583. }
  3584. if (entry) {
  3585. entry.value = value;
  3586. }
  3587. else {
  3588. entry = new Entry(value);
  3589. }
  3590. entry.key = key;
  3591. list.insertEntry(entry);
  3592. map[key] = entry;
  3593. }
  3594. return removed;
  3595. };
  3596. LRU.prototype.get = function (key) {
  3597. var entry = this._map[key];
  3598. var list = this._list;
  3599. if (entry != null) {
  3600. if (entry !== list.tail) {
  3601. list.remove(entry);
  3602. list.insertEntry(entry);
  3603. }
  3604. return entry.value;
  3605. }
  3606. };
  3607. LRU.prototype.clear = function () {
  3608. this._list.clear();
  3609. this._map = {};
  3610. };
  3611. LRU.prototype.len = function () {
  3612. return this._list.len();
  3613. };
  3614. return LRU;
  3615. }());
  3616. var kCSSColorTable = {
  3617. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  3618. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  3619. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  3620. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  3621. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  3622. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  3623. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  3624. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  3625. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  3626. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  3627. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  3628. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  3629. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  3630. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  3631. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  3632. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  3633. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  3634. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  3635. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  3636. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  3637. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  3638. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  3639. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  3640. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  3641. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  3642. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  3643. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  3644. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  3645. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  3646. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  3647. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  3648. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  3649. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  3650. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  3651. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  3652. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  3653. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  3654. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  3655. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  3656. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  3657. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  3658. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  3659. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  3660. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  3661. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  3662. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  3663. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  3664. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  3665. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  3666. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  3667. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  3668. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  3669. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  3670. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  3671. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  3672. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  3673. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  3674. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  3675. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  3676. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  3677. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  3678. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  3679. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  3680. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  3681. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  3682. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  3683. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  3684. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  3685. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  3686. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  3687. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  3688. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  3689. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  3690. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  3691. };
  3692. function clampCssByte(i) {
  3693. i = Math.round(i);
  3694. return i < 0 ? 0 : i > 255 ? 255 : i;
  3695. }
  3696. function clampCssAngle(i) {
  3697. i = Math.round(i);
  3698. return i < 0 ? 0 : i > 360 ? 360 : i;
  3699. }
  3700. function clampCssFloat(f) {
  3701. return f < 0 ? 0 : f > 1 ? 1 : f;
  3702. }
  3703. function parseCssInt(val) {
  3704. var str = val;
  3705. if (str.length && str.charAt(str.length - 1) === '%') {
  3706. return clampCssByte(parseFloat(str) / 100 * 255);
  3707. }
  3708. return clampCssByte(parseInt(str, 10));
  3709. }
  3710. function parseCssFloat(val) {
  3711. var str = val;
  3712. if (str.length && str.charAt(str.length - 1) === '%') {
  3713. return clampCssFloat(parseFloat(str) / 100);
  3714. }
  3715. return clampCssFloat(parseFloat(str));
  3716. }
  3717. function cssHueToRgb(m1, m2, h) {
  3718. if (h < 0) {
  3719. h += 1;
  3720. }
  3721. else if (h > 1) {
  3722. h -= 1;
  3723. }
  3724. if (h * 6 < 1) {
  3725. return m1 + (m2 - m1) * h * 6;
  3726. }
  3727. if (h * 2 < 1) {
  3728. return m2;
  3729. }
  3730. if (h * 3 < 2) {
  3731. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3732. }
  3733. return m1;
  3734. }
  3735. function lerpNumber(a, b, p) {
  3736. return a + (b - a) * p;
  3737. }
  3738. function setRgba(out, r, g, b, a) {
  3739. out[0] = r;
  3740. out[1] = g;
  3741. out[2] = b;
  3742. out[3] = a;
  3743. return out;
  3744. }
  3745. function copyRgba(out, a) {
  3746. out[0] = a[0];
  3747. out[1] = a[1];
  3748. out[2] = a[2];
  3749. out[3] = a[3];
  3750. return out;
  3751. }
  3752. var colorCache = new LRU(20);
  3753. var lastRemovedArr = null;
  3754. function putToCache(colorStr, rgbaArr) {
  3755. if (lastRemovedArr) {
  3756. copyRgba(lastRemovedArr, rgbaArr);
  3757. }
  3758. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  3759. }
  3760. function parse(colorStr, rgbaArr) {
  3761. if (!colorStr) {
  3762. return;
  3763. }
  3764. rgbaArr = rgbaArr || [];
  3765. var cached = colorCache.get(colorStr);
  3766. if (cached) {
  3767. return copyRgba(rgbaArr, cached);
  3768. }
  3769. colorStr = colorStr + '';
  3770. var str = colorStr.replace(/ /g, '').toLowerCase();
  3771. if (str in kCSSColorTable) {
  3772. copyRgba(rgbaArr, kCSSColorTable[str]);
  3773. putToCache(colorStr, rgbaArr);
  3774. return rgbaArr;
  3775. }
  3776. var strLen = str.length;
  3777. if (str.charAt(0) === '#') {
  3778. if (strLen === 4 || strLen === 5) {
  3779. var iv = parseInt(str.slice(1, 4), 16);
  3780. if (!(iv >= 0 && iv <= 0xfff)) {
  3781. setRgba(rgbaArr, 0, 0, 0, 1);
  3782. return;
  3783. }
  3784. setRgba(rgbaArr, ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8), (iv & 0xf0) | ((iv & 0xf0) >> 4), (iv & 0xf) | ((iv & 0xf) << 4), strLen === 5 ? parseInt(str.slice(4), 16) / 0xf : 1);
  3785. putToCache(colorStr, rgbaArr);
  3786. return rgbaArr;
  3787. }
  3788. else if (strLen === 7 || strLen === 9) {
  3789. var iv = parseInt(str.slice(1, 7), 16);
  3790. if (!(iv >= 0 && iv <= 0xffffff)) {
  3791. setRgba(rgbaArr, 0, 0, 0, 1);
  3792. return;
  3793. }
  3794. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, strLen === 9 ? parseInt(str.slice(7), 16) / 0xff : 1);
  3795. putToCache(colorStr, rgbaArr);
  3796. return rgbaArr;
  3797. }
  3798. return;
  3799. }
  3800. var op = str.indexOf('(');
  3801. var ep = str.indexOf(')');
  3802. if (op !== -1 && ep + 1 === strLen) {
  3803. var fname = str.substr(0, op);
  3804. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3805. var alpha = 1;
  3806. switch (fname) {
  3807. case 'rgba':
  3808. if (params.length !== 4) {
  3809. return params.length === 3
  3810. ? setRgba(rgbaArr, +params[0], +params[1], +params[2], 1)
  3811. : setRgba(rgbaArr, 0, 0, 0, 1);
  3812. }
  3813. alpha = parseCssFloat(params.pop());
  3814. case 'rgb':
  3815. if (params.length >= 3) {
  3816. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), params.length === 3 ? alpha : parseCssFloat(params[3]));
  3817. putToCache(colorStr, rgbaArr);
  3818. return rgbaArr;
  3819. }
  3820. else {
  3821. setRgba(rgbaArr, 0, 0, 0, 1);
  3822. return;
  3823. }
  3824. case 'hsla':
  3825. if (params.length !== 4) {
  3826. setRgba(rgbaArr, 0, 0, 0, 1);
  3827. return;
  3828. }
  3829. params[3] = parseCssFloat(params[3]);
  3830. hsla2rgba(params, rgbaArr);
  3831. putToCache(colorStr, rgbaArr);
  3832. return rgbaArr;
  3833. case 'hsl':
  3834. if (params.length !== 3) {
  3835. setRgba(rgbaArr, 0, 0, 0, 1);
  3836. return;
  3837. }
  3838. hsla2rgba(params, rgbaArr);
  3839. putToCache(colorStr, rgbaArr);
  3840. return rgbaArr;
  3841. default:
  3842. return;
  3843. }
  3844. }
  3845. setRgba(rgbaArr, 0, 0, 0, 1);
  3846. return;
  3847. }
  3848. function hsla2rgba(hsla, rgba) {
  3849. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360;
  3850. var s = parseCssFloat(hsla[1]);
  3851. var l = parseCssFloat(hsla[2]);
  3852. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  3853. var m1 = l * 2 - m2;
  3854. rgba = rgba || [];
  3855. setRgba(rgba, clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255), clampCssByte(cssHueToRgb(m1, m2, h) * 255), clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255), 1);
  3856. if (hsla.length === 4) {
  3857. rgba[3] = hsla[3];
  3858. }
  3859. return rgba;
  3860. }
  3861. function rgba2hsla(rgba) {
  3862. if (!rgba) {
  3863. return;
  3864. }
  3865. var R = rgba[0] / 255;
  3866. var G = rgba[1] / 255;
  3867. var B = rgba[2] / 255;
  3868. var vMin = Math.min(R, G, B);
  3869. var vMax = Math.max(R, G, B);
  3870. var delta = vMax - vMin;
  3871. var L = (vMax + vMin) / 2;
  3872. var H;
  3873. var S;
  3874. if (delta === 0) {
  3875. H = 0;
  3876. S = 0;
  3877. }
  3878. else {
  3879. if (L < 0.5) {
  3880. S = delta / (vMax + vMin);
  3881. }
  3882. else {
  3883. S = delta / (2 - vMax - vMin);
  3884. }
  3885. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  3886. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  3887. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  3888. if (R === vMax) {
  3889. H = deltaB - deltaG;
  3890. }
  3891. else if (G === vMax) {
  3892. H = (1 / 3) + deltaR - deltaB;
  3893. }
  3894. else if (B === vMax) {
  3895. H = (2 / 3) + deltaG - deltaR;
  3896. }
  3897. if (H < 0) {
  3898. H += 1;
  3899. }
  3900. if (H > 1) {
  3901. H -= 1;
  3902. }
  3903. }
  3904. var hsla = [H * 360, S, L];
  3905. if (rgba[3] != null) {
  3906. hsla.push(rgba[3]);
  3907. }
  3908. return hsla;
  3909. }
  3910. function lift(color, level) {
  3911. var colorArr = parse(color);
  3912. if (colorArr) {
  3913. for (var i = 0; i < 3; i++) {
  3914. if (level < 0) {
  3915. colorArr[i] = colorArr[i] * (1 - level) | 0;
  3916. }
  3917. else {
  3918. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  3919. }
  3920. if (colorArr[i] > 255) {
  3921. colorArr[i] = 255;
  3922. }
  3923. else if (colorArr[i] < 0) {
  3924. colorArr[i] = 0;
  3925. }
  3926. }
  3927. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  3928. }
  3929. }
  3930. function toHex(color) {
  3931. var colorArr = parse(color);
  3932. if (colorArr) {
  3933. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  3934. }
  3935. }
  3936. function fastLerp(normalizedValue, colors, out) {
  3937. if (!(colors && colors.length)
  3938. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3939. return;
  3940. }
  3941. out = out || [];
  3942. var value = normalizedValue * (colors.length - 1);
  3943. var leftIndex = Math.floor(value);
  3944. var rightIndex = Math.ceil(value);
  3945. var leftColor = colors[leftIndex];
  3946. var rightColor = colors[rightIndex];
  3947. var dv = value - leftIndex;
  3948. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  3949. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  3950. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  3951. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  3952. return out;
  3953. }
  3954. var fastMapToColor = fastLerp;
  3955. function lerp$1(normalizedValue, colors, fullOutput) {
  3956. if (!(colors && colors.length)
  3957. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3958. return;
  3959. }
  3960. var value = normalizedValue * (colors.length - 1);
  3961. var leftIndex = Math.floor(value);
  3962. var rightIndex = Math.ceil(value);
  3963. var leftColor = parse(colors[leftIndex]);
  3964. var rightColor = parse(colors[rightIndex]);
  3965. var dv = value - leftIndex;
  3966. var color = stringify([
  3967. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  3968. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  3969. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  3970. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  3971. ], 'rgba');
  3972. return fullOutput
  3973. ? {
  3974. color: color,
  3975. leftIndex: leftIndex,
  3976. rightIndex: rightIndex,
  3977. value: value
  3978. }
  3979. : color;
  3980. }
  3981. var mapToColor = lerp$1;
  3982. function modifyHSL(color, h, s, l) {
  3983. var colorArr = parse(color);
  3984. if (color) {
  3985. colorArr = rgba2hsla(colorArr);
  3986. h != null && (colorArr[0] = clampCssAngle(h));
  3987. s != null && (colorArr[1] = parseCssFloat(s));
  3988. l != null && (colorArr[2] = parseCssFloat(l));
  3989. return stringify(hsla2rgba(colorArr), 'rgba');
  3990. }
  3991. }
  3992. function modifyAlpha(color, alpha) {
  3993. var colorArr = parse(color);
  3994. if (colorArr && alpha != null) {
  3995. colorArr[3] = clampCssFloat(alpha);
  3996. return stringify(colorArr, 'rgba');
  3997. }
  3998. }
  3999. function stringify(arrColor, type) {
  4000. if (!arrColor || !arrColor.length) {
  4001. return;
  4002. }
  4003. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  4004. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  4005. colorStr += ',' + arrColor[3];
  4006. }
  4007. return type + '(' + colorStr + ')';
  4008. }
  4009. function lum(color, backgroundLum) {
  4010. var arr = parse(color);
  4011. return arr
  4012. ? (0.299 * arr[0] + 0.587 * arr[1] + 0.114 * arr[2]) * arr[3] / 255
  4013. + (1 - arr[3]) * backgroundLum
  4014. : 0;
  4015. }
  4016. function random() {
  4017. return stringify([
  4018. Math.round(Math.random() * 255),
  4019. Math.round(Math.random() * 255),
  4020. Math.round(Math.random() * 255)
  4021. ], 'rgb');
  4022. }
  4023. var color = /*#__PURE__*/Object.freeze({
  4024. __proto__: null,
  4025. parse: parse,
  4026. lift: lift,
  4027. toHex: toHex,
  4028. fastLerp: fastLerp,
  4029. fastMapToColor: fastMapToColor,
  4030. lerp: lerp$1,
  4031. mapToColor: mapToColor,
  4032. modifyHSL: modifyHSL,
  4033. modifyAlpha: modifyAlpha,
  4034. stringify: stringify,
  4035. lum: lum,
  4036. random: random
  4037. });
  4038. var mathRound = Math.round;
  4039. function normalizeColor(color) {
  4040. var opacity;
  4041. if (!color || color === 'transparent') {
  4042. color = 'none';
  4043. }
  4044. else if (typeof color === 'string' && color.indexOf('rgba') > -1) {
  4045. var arr = parse(color);
  4046. if (arr) {
  4047. color = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')';
  4048. opacity = arr[3];
  4049. }
  4050. }
  4051. return {
  4052. color: color,
  4053. opacity: opacity == null ? 1 : opacity
  4054. };
  4055. }
  4056. var EPSILON$1 = 1e-4;
  4057. function isAroundZero$1(transform) {
  4058. return transform < EPSILON$1 && transform > -EPSILON$1;
  4059. }
  4060. function round3(transform) {
  4061. return mathRound(transform * 1e3) / 1e3;
  4062. }
  4063. function round4(transform) {
  4064. return mathRound(transform * 1e4) / 1e4;
  4065. }
  4066. function getMatrixStr(m) {
  4067. return 'matrix('
  4068. + round3(m[0]) + ','
  4069. + round3(m[1]) + ','
  4070. + round3(m[2]) + ','
  4071. + round3(m[3]) + ','
  4072. + round4(m[4]) + ','
  4073. + round4(m[5])
  4074. + ')';
  4075. }
  4076. var TEXT_ALIGN_TO_ANCHOR = {
  4077. left: 'start',
  4078. right: 'end',
  4079. center: 'middle',
  4080. middle: 'middle'
  4081. };
  4082. function adjustTextY(y, lineHeight, textBaseline) {
  4083. if (textBaseline === 'top') {
  4084. y += lineHeight / 2;
  4085. }
  4086. else if (textBaseline === 'bottom') {
  4087. y -= lineHeight / 2;
  4088. }
  4089. return y;
  4090. }
  4091. function hasShadow(style) {
  4092. return style
  4093. && (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY);
  4094. }
  4095. function getShadowKey(displayable) {
  4096. var style = displayable.style;
  4097. var globalScale = displayable.getGlobalScale();
  4098. return [
  4099. style.shadowColor,
  4100. (style.shadowBlur || 0).toFixed(2),
  4101. (style.shadowOffsetX || 0).toFixed(2),
  4102. (style.shadowOffsetY || 0).toFixed(2),
  4103. globalScale[0],
  4104. globalScale[1]
  4105. ].join(',');
  4106. }
  4107. function isImagePattern(val) {
  4108. return val && (!!val.image);
  4109. }
  4110. function isSVGPattern(val) {
  4111. return val && (!!val.svgElement);
  4112. }
  4113. function isPattern(val) {
  4114. return isImagePattern(val) || isSVGPattern(val);
  4115. }
  4116. function isLinearGradient(val) {
  4117. return val.type === 'linear';
  4118. }
  4119. function isRadialGradient(val) {
  4120. return val.type === 'radial';
  4121. }
  4122. function isGradient(val) {
  4123. return val && (val.type === 'linear'
  4124. || val.type === 'radial');
  4125. }
  4126. function getIdURL(id) {
  4127. return "url(#" + id + ")";
  4128. }
  4129. function getPathPrecision(el) {
  4130. var scale = el.getGlobalScale();
  4131. var size = Math.max(scale[0], scale[1]);
  4132. return Math.max(Math.ceil(Math.log(size) / Math.log(10)), 1);
  4133. }
  4134. function getSRTTransformString(transform) {
  4135. var x = transform.x || 0;
  4136. var y = transform.y || 0;
  4137. var rotation = (transform.rotation || 0) * RADIAN_TO_DEGREE;
  4138. var scaleX = retrieve2(transform.scaleX, 1);
  4139. var scaleY = retrieve2(transform.scaleY, 1);
  4140. var skewX = transform.skewX || 0;
  4141. var skewY = transform.skewY || 0;
  4142. var res = [];
  4143. if (x || y) {
  4144. res.push("translate(" + x + "px," + y + "px)");
  4145. }
  4146. if (rotation) {
  4147. res.push("rotate(" + rotation + ")");
  4148. }
  4149. if (scaleX !== 1 || scaleY !== 1) {
  4150. res.push("scale(" + scaleX + "," + scaleY + ")");
  4151. }
  4152. if (skewX || skewY) {
  4153. res.push("skew(" + mathRound(skewX * RADIAN_TO_DEGREE) + "deg, " + mathRound(skewY * RADIAN_TO_DEGREE) + "deg)");
  4154. }
  4155. return res.join(' ');
  4156. }
  4157. var encodeBase64 = (function () {
  4158. if (env.hasGlobalWindow && isFunction(window.btoa)) {
  4159. return function (str) {
  4160. return window.btoa(unescape(encodeURIComponent(str)));
  4161. };
  4162. }
  4163. if (typeof Buffer !== 'undefined') {
  4164. return function (str) {
  4165. return Buffer.from(str).toString('base64');
  4166. };
  4167. }
  4168. return function (str) {
  4169. {
  4170. logError('Base64 isn\'t natively supported in the current environment.');
  4171. }
  4172. return null;
  4173. };
  4174. })();
  4175. var arraySlice = Array.prototype.slice;
  4176. function interpolateNumber(p0, p1, percent) {
  4177. return (p1 - p0) * percent + p0;
  4178. }
  4179. function interpolate1DArray(out, p0, p1, percent) {
  4180. var len = p0.length;
  4181. for (var i = 0; i < len; i++) {
  4182. out[i] = interpolateNumber(p0[i], p1[i], percent);
  4183. }
  4184. return out;
  4185. }
  4186. function interpolate2DArray(out, p0, p1, percent) {
  4187. var len = p0.length;
  4188. var len2 = len && p0[0].length;
  4189. for (var i = 0; i < len; i++) {
  4190. if (!out[i]) {
  4191. out[i] = [];
  4192. }
  4193. for (var j = 0; j < len2; j++) {
  4194. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  4195. }
  4196. }
  4197. return out;
  4198. }
  4199. function add1DArray(out, p0, p1, sign) {
  4200. var len = p0.length;
  4201. for (var i = 0; i < len; i++) {
  4202. out[i] = p0[i] + p1[i] * sign;
  4203. }
  4204. return out;
  4205. }
  4206. function add2DArray(out, p0, p1, sign) {
  4207. var len = p0.length;
  4208. var len2 = len && p0[0].length;
  4209. for (var i = 0; i < len; i++) {
  4210. if (!out[i]) {
  4211. out[i] = [];
  4212. }
  4213. for (var j = 0; j < len2; j++) {
  4214. out[i][j] = p0[i][j] + p1[i][j] * sign;
  4215. }
  4216. }
  4217. return out;
  4218. }
  4219. function fillColorStops(val0, val1) {
  4220. var len0 = val0.length;
  4221. var len1 = val1.length;
  4222. var shorterArr = len0 > len1 ? val1 : val0;
  4223. var shorterLen = Math.min(len0, len1);
  4224. var last = shorterArr[shorterLen - 1] || { color: [0, 0, 0, 0], offset: 0 };
  4225. for (var i = shorterLen; i < Math.max(len0, len1); i++) {
  4226. shorterArr.push({
  4227. offset: last.offset,
  4228. color: last.color.slice()
  4229. });
  4230. }
  4231. }
  4232. function fillArray(val0, val1, arrDim) {
  4233. var arr0 = val0;
  4234. var arr1 = val1;
  4235. if (!arr0.push || !arr1.push) {
  4236. return;
  4237. }
  4238. var arr0Len = arr0.length;
  4239. var arr1Len = arr1.length;
  4240. if (arr0Len !== arr1Len) {
  4241. var isPreviousLarger = arr0Len > arr1Len;
  4242. if (isPreviousLarger) {
  4243. arr0.length = arr1Len;
  4244. }
  4245. else {
  4246. for (var i = arr0Len; i < arr1Len; i++) {
  4247. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  4248. }
  4249. }
  4250. }
  4251. var len2 = arr0[0] && arr0[0].length;
  4252. for (var i = 0; i < arr0.length; i++) {
  4253. if (arrDim === 1) {
  4254. if (isNaN(arr0[i])) {
  4255. arr0[i] = arr1[i];
  4256. }
  4257. }
  4258. else {
  4259. for (var j = 0; j < len2; j++) {
  4260. if (isNaN(arr0[i][j])) {
  4261. arr0[i][j] = arr1[i][j];
  4262. }
  4263. }
  4264. }
  4265. }
  4266. }
  4267. function cloneValue(value) {
  4268. if (isArrayLike(value)) {
  4269. var len = value.length;
  4270. if (isArrayLike(value[0])) {
  4271. var ret = [];
  4272. for (var i = 0; i < len; i++) {
  4273. ret.push(arraySlice.call(value[i]));
  4274. }
  4275. return ret;
  4276. }
  4277. return arraySlice.call(value);
  4278. }
  4279. return value;
  4280. }
  4281. function rgba2String(rgba) {
  4282. rgba[0] = Math.floor(rgba[0]) || 0;
  4283. rgba[1] = Math.floor(rgba[1]) || 0;
  4284. rgba[2] = Math.floor(rgba[2]) || 0;
  4285. rgba[3] = rgba[3] == null ? 1 : rgba[3];
  4286. return 'rgba(' + rgba.join(',') + ')';
  4287. }
  4288. function guessArrayDim(value) {
  4289. return isArrayLike(value && value[0]) ? 2 : 1;
  4290. }
  4291. var VALUE_TYPE_NUMBER = 0;
  4292. var VALUE_TYPE_1D_ARRAY = 1;
  4293. var VALUE_TYPE_2D_ARRAY = 2;
  4294. var VALUE_TYPE_COLOR = 3;
  4295. var VALUE_TYPE_LINEAR_GRADIENT = 4;
  4296. var VALUE_TYPE_RADIAL_GRADIENT = 5;
  4297. var VALUE_TYPE_UNKOWN = 6;
  4298. function isGradientValueType(valType) {
  4299. return valType === VALUE_TYPE_LINEAR_GRADIENT || valType === VALUE_TYPE_RADIAL_GRADIENT;
  4300. }
  4301. function isArrayValueType(valType) {
  4302. return valType === VALUE_TYPE_1D_ARRAY || valType === VALUE_TYPE_2D_ARRAY;
  4303. }
  4304. var tmpRgba = [0, 0, 0, 0];
  4305. var Track = (function () {
  4306. function Track(propName) {
  4307. this.keyframes = [];
  4308. this.discrete = false;
  4309. this._invalid = false;
  4310. this._needsSort = false;
  4311. this._lastFr = 0;
  4312. this._lastFrP = 0;
  4313. this.propName = propName;
  4314. }
  4315. Track.prototype.isFinished = function () {
  4316. return this._finished;
  4317. };
  4318. Track.prototype.setFinished = function () {
  4319. this._finished = true;
  4320. if (this._additiveTrack) {
  4321. this._additiveTrack.setFinished();
  4322. }
  4323. };
  4324. Track.prototype.needsAnimate = function () {
  4325. return this.keyframes.length >= 1;
  4326. };
  4327. Track.prototype.getAdditiveTrack = function () {
  4328. return this._additiveTrack;
  4329. };
  4330. Track.prototype.addKeyframe = function (time, rawValue, easing) {
  4331. this._needsSort = true;
  4332. var keyframes = this.keyframes;
  4333. var len = keyframes.length;
  4334. var discrete = false;
  4335. var valType = VALUE_TYPE_UNKOWN;
  4336. var value = rawValue;
  4337. if (isArrayLike(rawValue)) {
  4338. var arrayDim = guessArrayDim(rawValue);
  4339. valType = arrayDim;
  4340. if (arrayDim === 1 && !isNumber(rawValue[0])
  4341. || arrayDim === 2 && !isNumber(rawValue[0][0])) {
  4342. discrete = true;
  4343. }
  4344. }
  4345. else {
  4346. if (isNumber(rawValue) && !eqNaN(rawValue)) {
  4347. valType = VALUE_TYPE_NUMBER;
  4348. }
  4349. else if (isString(rawValue)) {
  4350. if (!isNaN(+rawValue)) {
  4351. valType = VALUE_TYPE_NUMBER;
  4352. }
  4353. else {
  4354. var colorArray = parse(rawValue);
  4355. if (colorArray) {
  4356. value = colorArray;
  4357. valType = VALUE_TYPE_COLOR;
  4358. }
  4359. }
  4360. }
  4361. else if (isGradientObject(rawValue)) {
  4362. var parsedGradient = extend({}, value);
  4363. parsedGradient.colorStops = map(rawValue.colorStops, function (colorStop) { return ({
  4364. offset: colorStop.offset,
  4365. color: parse(colorStop.color)
  4366. }); });
  4367. if (isLinearGradient(rawValue)) {
  4368. valType = VALUE_TYPE_LINEAR_GRADIENT;
  4369. }
  4370. else if (isRadialGradient(rawValue)) {
  4371. valType = VALUE_TYPE_RADIAL_GRADIENT;
  4372. }
  4373. value = parsedGradient;
  4374. }
  4375. }
  4376. if (len === 0) {
  4377. this.valType = valType;
  4378. }
  4379. else if (valType !== this.valType || valType === VALUE_TYPE_UNKOWN) {
  4380. discrete = true;
  4381. }
  4382. this.discrete = this.discrete || discrete;
  4383. var kf = {
  4384. time: time,
  4385. value: value,
  4386. rawValue: rawValue,
  4387. percent: 0
  4388. };
  4389. if (easing) {
  4390. kf.easing = easing;
  4391. kf.easingFunc = isFunction(easing)
  4392. ? easing
  4393. : easingFuncs[easing] || createCubicEasingFunc(easing);
  4394. }
  4395. keyframes.push(kf);
  4396. return kf;
  4397. };
  4398. Track.prototype.prepare = function (maxTime, additiveTrack) {
  4399. var kfs = this.keyframes;
  4400. if (this._needsSort) {
  4401. kfs.sort(function (a, b) {
  4402. return a.time - b.time;
  4403. });
  4404. }
  4405. var valType = this.valType;
  4406. var kfsLen = kfs.length;
  4407. var lastKf = kfs[kfsLen - 1];
  4408. var isDiscrete = this.discrete;
  4409. var isArr = isArrayValueType(valType);
  4410. var isGradient = isGradientValueType(valType);
  4411. for (var i = 0; i < kfsLen; i++) {
  4412. var kf = kfs[i];
  4413. var value = kf.value;
  4414. var lastValue = lastKf.value;
  4415. kf.percent = kf.time / maxTime;
  4416. if (!isDiscrete) {
  4417. if (isArr && i !== kfsLen - 1) {
  4418. fillArray(value, lastValue, valType);
  4419. }
  4420. else if (isGradient) {
  4421. fillColorStops(value.colorStops, lastValue.colorStops);
  4422. }
  4423. }
  4424. }
  4425. if (!isDiscrete
  4426. && valType !== VALUE_TYPE_RADIAL_GRADIENT
  4427. && additiveTrack
  4428. && this.needsAnimate()
  4429. && additiveTrack.needsAnimate()
  4430. && valType === additiveTrack.valType
  4431. && !additiveTrack._finished) {
  4432. this._additiveTrack = additiveTrack;
  4433. var startValue = kfs[0].value;
  4434. for (var i = 0; i < kfsLen; i++) {
  4435. if (valType === VALUE_TYPE_NUMBER) {
  4436. kfs[i].additiveValue = kfs[i].value - startValue;
  4437. }
  4438. else if (valType === VALUE_TYPE_COLOR) {
  4439. kfs[i].additiveValue =
  4440. add1DArray([], kfs[i].value, startValue, -1);
  4441. }
  4442. else if (isArrayValueType(valType)) {
  4443. kfs[i].additiveValue = valType === VALUE_TYPE_1D_ARRAY
  4444. ? add1DArray([], kfs[i].value, startValue, -1)
  4445. : add2DArray([], kfs[i].value, startValue, -1);
  4446. }
  4447. }
  4448. }
  4449. };
  4450. Track.prototype.step = function (target, percent) {
  4451. if (this._finished) {
  4452. return;
  4453. }
  4454. if (this._additiveTrack && this._additiveTrack._finished) {
  4455. this._additiveTrack = null;
  4456. }
  4457. var isAdditive = this._additiveTrack != null;
  4458. var valueKey = isAdditive ? 'additiveValue' : 'value';
  4459. var valType = this.valType;
  4460. var keyframes = this.keyframes;
  4461. var kfsNum = keyframes.length;
  4462. var propName = this.propName;
  4463. var isValueColor = valType === VALUE_TYPE_COLOR;
  4464. var frameIdx;
  4465. var lastFrame = this._lastFr;
  4466. var mathMin = Math.min;
  4467. var frame;
  4468. var nextFrame;
  4469. if (kfsNum === 1) {
  4470. frame = nextFrame = keyframes[0];
  4471. }
  4472. else {
  4473. if (percent < 0) {
  4474. frameIdx = 0;
  4475. }
  4476. else if (percent < this._lastFrP) {
  4477. var start = mathMin(lastFrame + 1, kfsNum - 1);
  4478. for (frameIdx = start; frameIdx >= 0; frameIdx--) {
  4479. if (keyframes[frameIdx].percent <= percent) {
  4480. break;
  4481. }
  4482. }
  4483. frameIdx = mathMin(frameIdx, kfsNum - 2);
  4484. }
  4485. else {
  4486. for (frameIdx = lastFrame; frameIdx < kfsNum; frameIdx++) {
  4487. if (keyframes[frameIdx].percent > percent) {
  4488. break;
  4489. }
  4490. }
  4491. frameIdx = mathMin(frameIdx - 1, kfsNum - 2);
  4492. }
  4493. nextFrame = keyframes[frameIdx + 1];
  4494. frame = keyframes[frameIdx];
  4495. }
  4496. if (!(frame && nextFrame)) {
  4497. return;
  4498. }
  4499. this._lastFr = frameIdx;
  4500. this._lastFrP = percent;
  4501. var interval = (nextFrame.percent - frame.percent);
  4502. var w = interval === 0 ? 1 : mathMin((percent - frame.percent) / interval, 1);
  4503. if (nextFrame.easingFunc) {
  4504. w = nextFrame.easingFunc(w);
  4505. }
  4506. var targetArr = isAdditive ? this._additiveValue
  4507. : (isValueColor ? tmpRgba : target[propName]);
  4508. if ((isArrayValueType(valType) || isValueColor) && !targetArr) {
  4509. targetArr = this._additiveValue = [];
  4510. }
  4511. if (this.discrete) {
  4512. target[propName] = w < 1 ? frame.rawValue : nextFrame.rawValue;
  4513. }
  4514. else if (isArrayValueType(valType)) {
  4515. valType === VALUE_TYPE_1D_ARRAY
  4516. ? interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w)
  4517. : interpolate2DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4518. }
  4519. else if (isGradientValueType(valType)) {
  4520. var val = frame[valueKey];
  4521. var nextVal_1 = nextFrame[valueKey];
  4522. var isLinearGradient_1 = valType === VALUE_TYPE_LINEAR_GRADIENT;
  4523. target[propName] = {
  4524. type: isLinearGradient_1 ? 'linear' : 'radial',
  4525. x: interpolateNumber(val.x, nextVal_1.x, w),
  4526. y: interpolateNumber(val.y, nextVal_1.y, w),
  4527. colorStops: map(val.colorStops, function (colorStop, idx) {
  4528. var nextColorStop = nextVal_1.colorStops[idx];
  4529. return {
  4530. offset: interpolateNumber(colorStop.offset, nextColorStop.offset, w),
  4531. color: rgba2String(interpolate1DArray([], colorStop.color, nextColorStop.color, w))
  4532. };
  4533. }),
  4534. global: nextVal_1.global
  4535. };
  4536. if (isLinearGradient_1) {
  4537. target[propName].x2 = interpolateNumber(val.x2, nextVal_1.x2, w);
  4538. target[propName].y2 = interpolateNumber(val.y2, nextVal_1.y2, w);
  4539. }
  4540. else {
  4541. target[propName].r = interpolateNumber(val.r, nextVal_1.r, w);
  4542. }
  4543. }
  4544. else if (isValueColor) {
  4545. interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4546. if (!isAdditive) {
  4547. target[propName] = rgba2String(targetArr);
  4548. }
  4549. }
  4550. else {
  4551. var value = interpolateNumber(frame[valueKey], nextFrame[valueKey], w);
  4552. if (isAdditive) {
  4553. this._additiveValue = value;
  4554. }
  4555. else {
  4556. target[propName] = value;
  4557. }
  4558. }
  4559. if (isAdditive) {
  4560. this._addToTarget(target);
  4561. }
  4562. };
  4563. Track.prototype._addToTarget = function (target) {
  4564. var valType = this.valType;
  4565. var propName = this.propName;
  4566. var additiveValue = this._additiveValue;
  4567. if (valType === VALUE_TYPE_NUMBER) {
  4568. target[propName] = target[propName] + additiveValue;
  4569. }
  4570. else if (valType === VALUE_TYPE_COLOR) {
  4571. parse(target[propName], tmpRgba);
  4572. add1DArray(tmpRgba, tmpRgba, additiveValue, 1);
  4573. target[propName] = rgba2String(tmpRgba);
  4574. }
  4575. else if (valType === VALUE_TYPE_1D_ARRAY) {
  4576. add1DArray(target[propName], target[propName], additiveValue, 1);
  4577. }
  4578. else if (valType === VALUE_TYPE_2D_ARRAY) {
  4579. add2DArray(target[propName], target[propName], additiveValue, 1);
  4580. }
  4581. };
  4582. return Track;
  4583. }());
  4584. var Animator = (function () {
  4585. function Animator(target, loop, allowDiscreteAnimation, additiveTo) {
  4586. this._tracks = {};
  4587. this._trackKeys = [];
  4588. this._maxTime = 0;
  4589. this._started = 0;
  4590. this._clip = null;
  4591. this._target = target;
  4592. this._loop = loop;
  4593. if (loop && additiveTo) {
  4594. logError('Can\' use additive animation on looped animation.');
  4595. return;
  4596. }
  4597. this._additiveAnimators = additiveTo;
  4598. this._allowDiscrete = allowDiscreteAnimation;
  4599. }
  4600. Animator.prototype.getMaxTime = function () {
  4601. return this._maxTime;
  4602. };
  4603. Animator.prototype.getDelay = function () {
  4604. return this._delay;
  4605. };
  4606. Animator.prototype.getLoop = function () {
  4607. return this._loop;
  4608. };
  4609. Animator.prototype.getTarget = function () {
  4610. return this._target;
  4611. };
  4612. Animator.prototype.changeTarget = function (target) {
  4613. this._target = target;
  4614. };
  4615. Animator.prototype.when = function (time, props, easing) {
  4616. return this.whenWithKeys(time, props, keys(props), easing);
  4617. };
  4618. Animator.prototype.whenWithKeys = function (time, props, propNames, easing) {
  4619. var tracks = this._tracks;
  4620. for (var i = 0; i < propNames.length; i++) {
  4621. var propName = propNames[i];
  4622. var track = tracks[propName];
  4623. if (!track) {
  4624. track = tracks[propName] = new Track(propName);
  4625. var initialValue = void 0;
  4626. var additiveTrack = this._getAdditiveTrack(propName);
  4627. if (additiveTrack) {
  4628. var addtiveTrackKfs = additiveTrack.keyframes;
  4629. var lastFinalKf = addtiveTrackKfs[addtiveTrackKfs.length - 1];
  4630. initialValue = lastFinalKf && lastFinalKf.value;
  4631. if (additiveTrack.valType === VALUE_TYPE_COLOR && initialValue) {
  4632. initialValue = rgba2String(initialValue);
  4633. }
  4634. }
  4635. else {
  4636. initialValue = this._target[propName];
  4637. }
  4638. if (initialValue == null) {
  4639. continue;
  4640. }
  4641. if (time > 0) {
  4642. track.addKeyframe(0, cloneValue(initialValue), easing);
  4643. }
  4644. this._trackKeys.push(propName);
  4645. }
  4646. track.addKeyframe(time, cloneValue(props[propName]), easing);
  4647. }
  4648. this._maxTime = Math.max(this._maxTime, time);
  4649. return this;
  4650. };
  4651. Animator.prototype.pause = function () {
  4652. this._clip.pause();
  4653. this._paused = true;
  4654. };
  4655. Animator.prototype.resume = function () {
  4656. this._clip.resume();
  4657. this._paused = false;
  4658. };
  4659. Animator.prototype.isPaused = function () {
  4660. return !!this._paused;
  4661. };
  4662. Animator.prototype.duration = function (duration) {
  4663. this._maxTime = duration;
  4664. this._force = true;
  4665. return this;
  4666. };
  4667. Animator.prototype._doneCallback = function () {
  4668. this._setTracksFinished();
  4669. this._clip = null;
  4670. var doneList = this._doneCbs;
  4671. if (doneList) {
  4672. var len = doneList.length;
  4673. for (var i = 0; i < len; i++) {
  4674. doneList[i].call(this);
  4675. }
  4676. }
  4677. };
  4678. Animator.prototype._abortedCallback = function () {
  4679. this._setTracksFinished();
  4680. var animation = this.animation;
  4681. var abortedList = this._abortedCbs;
  4682. if (animation) {
  4683. animation.removeClip(this._clip);
  4684. }
  4685. this._clip = null;
  4686. if (abortedList) {
  4687. for (var i = 0; i < abortedList.length; i++) {
  4688. abortedList[i].call(this);
  4689. }
  4690. }
  4691. };
  4692. Animator.prototype._setTracksFinished = function () {
  4693. var tracks = this._tracks;
  4694. var tracksKeys = this._trackKeys;
  4695. for (var i = 0; i < tracksKeys.length; i++) {
  4696. tracks[tracksKeys[i]].setFinished();
  4697. }
  4698. };
  4699. Animator.prototype._getAdditiveTrack = function (trackName) {
  4700. var additiveTrack;
  4701. var additiveAnimators = this._additiveAnimators;
  4702. if (additiveAnimators) {
  4703. for (var i = 0; i < additiveAnimators.length; i++) {
  4704. var track = additiveAnimators[i].getTrack(trackName);
  4705. if (track) {
  4706. additiveTrack = track;
  4707. }
  4708. }
  4709. }
  4710. return additiveTrack;
  4711. };
  4712. Animator.prototype.start = function (easing) {
  4713. if (this._started > 0) {
  4714. return;
  4715. }
  4716. this._started = 1;
  4717. var self = this;
  4718. var tracks = [];
  4719. var maxTime = this._maxTime || 0;
  4720. for (var i = 0; i < this._trackKeys.length; i++) {
  4721. var propName = this._trackKeys[i];
  4722. var track = this._tracks[propName];
  4723. var additiveTrack = this._getAdditiveTrack(propName);
  4724. var kfs = track.keyframes;
  4725. var kfsNum = kfs.length;
  4726. track.prepare(maxTime, additiveTrack);
  4727. if (track.needsAnimate()) {
  4728. if (!this._allowDiscrete && track.discrete) {
  4729. var lastKf = kfs[kfsNum - 1];
  4730. if (lastKf) {
  4731. self._target[track.propName] = lastKf.rawValue;
  4732. }
  4733. track.setFinished();
  4734. }
  4735. else {
  4736. tracks.push(track);
  4737. }
  4738. }
  4739. }
  4740. if (tracks.length || this._force) {
  4741. var clip = new Clip({
  4742. life: maxTime,
  4743. loop: this._loop,
  4744. delay: this._delay || 0,
  4745. onframe: function (percent) {
  4746. self._started = 2;
  4747. var additiveAnimators = self._additiveAnimators;
  4748. if (additiveAnimators) {
  4749. var stillHasAdditiveAnimator = false;
  4750. for (var i = 0; i < additiveAnimators.length; i++) {
  4751. if (additiveAnimators[i]._clip) {
  4752. stillHasAdditiveAnimator = true;
  4753. break;
  4754. }
  4755. }
  4756. if (!stillHasAdditiveAnimator) {
  4757. self._additiveAnimators = null;
  4758. }
  4759. }
  4760. for (var i = 0; i < tracks.length; i++) {
  4761. tracks[i].step(self._target, percent);
  4762. }
  4763. var onframeList = self._onframeCbs;
  4764. if (onframeList) {
  4765. for (var i = 0; i < onframeList.length; i++) {
  4766. onframeList[i](self._target, percent);
  4767. }
  4768. }
  4769. },
  4770. ondestroy: function () {
  4771. self._doneCallback();
  4772. }
  4773. });
  4774. this._clip = clip;
  4775. if (this.animation) {
  4776. this.animation.addClip(clip);
  4777. }
  4778. if (easing) {
  4779. clip.setEasing(easing);
  4780. }
  4781. }
  4782. else {
  4783. this._doneCallback();
  4784. }
  4785. return this;
  4786. };
  4787. Animator.prototype.stop = function (forwardToLast) {
  4788. if (!this._clip) {
  4789. return;
  4790. }
  4791. var clip = this._clip;
  4792. if (forwardToLast) {
  4793. clip.onframe(1);
  4794. }
  4795. this._abortedCallback();
  4796. };
  4797. Animator.prototype.delay = function (time) {
  4798. this._delay = time;
  4799. return this;
  4800. };
  4801. Animator.prototype.during = function (cb) {
  4802. if (cb) {
  4803. if (!this._onframeCbs) {
  4804. this._onframeCbs = [];
  4805. }
  4806. this._onframeCbs.push(cb);
  4807. }
  4808. return this;
  4809. };
  4810. Animator.prototype.done = function (cb) {
  4811. if (cb) {
  4812. if (!this._doneCbs) {
  4813. this._doneCbs = [];
  4814. }
  4815. this._doneCbs.push(cb);
  4816. }
  4817. return this;
  4818. };
  4819. Animator.prototype.aborted = function (cb) {
  4820. if (cb) {
  4821. if (!this._abortedCbs) {
  4822. this._abortedCbs = [];
  4823. }
  4824. this._abortedCbs.push(cb);
  4825. }
  4826. return this;
  4827. };
  4828. Animator.prototype.getClip = function () {
  4829. return this._clip;
  4830. };
  4831. Animator.prototype.getTrack = function (propName) {
  4832. return this._tracks[propName];
  4833. };
  4834. Animator.prototype.getTracks = function () {
  4835. var _this = this;
  4836. return map(this._trackKeys, function (key) { return _this._tracks[key]; });
  4837. };
  4838. Animator.prototype.stopTracks = function (propNames, forwardToLast) {
  4839. if (!propNames.length || !this._clip) {
  4840. return true;
  4841. }
  4842. var tracks = this._tracks;
  4843. var tracksKeys = this._trackKeys;
  4844. for (var i = 0; i < propNames.length; i++) {
  4845. var track = tracks[propNames[i]];
  4846. if (track && !track.isFinished()) {
  4847. if (forwardToLast) {
  4848. track.step(this._target, 1);
  4849. }
  4850. else if (this._started === 1) {
  4851. track.step(this._target, 0);
  4852. }
  4853. track.setFinished();
  4854. }
  4855. }
  4856. var allAborted = true;
  4857. for (var i = 0; i < tracksKeys.length; i++) {
  4858. if (!tracks[tracksKeys[i]].isFinished()) {
  4859. allAborted = false;
  4860. break;
  4861. }
  4862. }
  4863. if (allAborted) {
  4864. this._abortedCallback();
  4865. }
  4866. return allAborted;
  4867. };
  4868. Animator.prototype.saveTo = function (target, trackKeys, firstOrLast) {
  4869. if (!target) {
  4870. return;
  4871. }
  4872. trackKeys = trackKeys || this._trackKeys;
  4873. for (var i = 0; i < trackKeys.length; i++) {
  4874. var propName = trackKeys[i];
  4875. var track = this._tracks[propName];
  4876. if (!track || track.isFinished()) {
  4877. continue;
  4878. }
  4879. var kfs = track.keyframes;
  4880. var kf = kfs[firstOrLast ? 0 : kfs.length - 1];
  4881. if (kf) {
  4882. target[propName] = cloneValue(kf.rawValue);
  4883. }
  4884. }
  4885. };
  4886. Animator.prototype.__changeFinalValue = function (finalProps, trackKeys) {
  4887. trackKeys = trackKeys || keys(finalProps);
  4888. for (var i = 0; i < trackKeys.length; i++) {
  4889. var propName = trackKeys[i];
  4890. var track = this._tracks[propName];
  4891. if (!track) {
  4892. continue;
  4893. }
  4894. var kfs = track.keyframes;
  4895. if (kfs.length > 1) {
  4896. var lastKf = kfs.pop();
  4897. track.addKeyframe(lastKf.time, finalProps[propName]);
  4898. track.prepare(this._maxTime, track.getAdditiveTrack());
  4899. }
  4900. }
  4901. };
  4902. return Animator;
  4903. }());
  4904. function getTime() {
  4905. return new Date().getTime();
  4906. }
  4907. var Animation = (function (_super) {
  4908. __extends(Animation, _super);
  4909. function Animation(opts) {
  4910. var _this = _super.call(this) || this;
  4911. _this._running = false;
  4912. _this._time = 0;
  4913. _this._pausedTime = 0;
  4914. _this._pauseStart = 0;
  4915. _this._paused = false;
  4916. opts = opts || {};
  4917. _this.stage = opts.stage || {};
  4918. return _this;
  4919. }
  4920. Animation.prototype.addClip = function (clip) {
  4921. if (clip.animation) {
  4922. this.removeClip(clip);
  4923. }
  4924. if (!this._head) {
  4925. this._head = this._tail = clip;
  4926. }
  4927. else {
  4928. this._tail.next = clip;
  4929. clip.prev = this._tail;
  4930. clip.next = null;
  4931. this._tail = clip;
  4932. }
  4933. clip.animation = this;
  4934. };
  4935. Animation.prototype.addAnimator = function (animator) {
  4936. animator.animation = this;
  4937. var clip = animator.getClip();
  4938. if (clip) {
  4939. this.addClip(clip);
  4940. }
  4941. };
  4942. Animation.prototype.removeClip = function (clip) {
  4943. if (!clip.animation) {
  4944. return;
  4945. }
  4946. var prev = clip.prev;
  4947. var next = clip.next;
  4948. if (prev) {
  4949. prev.next = next;
  4950. }
  4951. else {
  4952. this._head = next;
  4953. }
  4954. if (next) {
  4955. next.prev = prev;
  4956. }
  4957. else {
  4958. this._tail = prev;
  4959. }
  4960. clip.next = clip.prev = clip.animation = null;
  4961. };
  4962. Animation.prototype.removeAnimator = function (animator) {
  4963. var clip = animator.getClip();
  4964. if (clip) {
  4965. this.removeClip(clip);
  4966. }
  4967. animator.animation = null;
  4968. };
  4969. Animation.prototype.update = function (notTriggerFrameAndStageUpdate) {
  4970. var time = getTime() - this._pausedTime;
  4971. var delta = time - this._time;
  4972. var clip = this._head;
  4973. while (clip) {
  4974. var nextClip = clip.next;
  4975. var finished = clip.step(time, delta);
  4976. if (finished) {
  4977. clip.ondestroy();
  4978. this.removeClip(clip);
  4979. clip = nextClip;
  4980. }
  4981. else {
  4982. clip = nextClip;
  4983. }
  4984. }
  4985. this._time = time;
  4986. if (!notTriggerFrameAndStageUpdate) {
  4987. this.trigger('frame', delta);
  4988. this.stage.update && this.stage.update();
  4989. }
  4990. };
  4991. Animation.prototype._startLoop = function () {
  4992. var self = this;
  4993. this._running = true;
  4994. function step() {
  4995. if (self._running) {
  4996. requestAnimationFrame$1(step);
  4997. !self._paused && self.update();
  4998. }
  4999. }
  5000. requestAnimationFrame$1(step);
  5001. };
  5002. Animation.prototype.start = function () {
  5003. if (this._running) {
  5004. return;
  5005. }
  5006. this._time = getTime();
  5007. this._pausedTime = 0;
  5008. this._startLoop();
  5009. };
  5010. Animation.prototype.stop = function () {
  5011. this._running = false;
  5012. };
  5013. Animation.prototype.pause = function () {
  5014. if (!this._paused) {
  5015. this._pauseStart = getTime();
  5016. this._paused = true;
  5017. }
  5018. };
  5019. Animation.prototype.resume = function () {
  5020. if (this._paused) {
  5021. this._pausedTime += getTime() - this._pauseStart;
  5022. this._paused = false;
  5023. }
  5024. };
  5025. Animation.prototype.clear = function () {
  5026. var clip = this._head;
  5027. while (clip) {
  5028. var nextClip = clip.next;
  5029. clip.prev = clip.next = clip.animation = null;
  5030. clip = nextClip;
  5031. }
  5032. this._head = this._tail = null;
  5033. };
  5034. Animation.prototype.isFinished = function () {
  5035. return this._head == null;
  5036. };
  5037. Animation.prototype.animate = function (target, options) {
  5038. options = options || {};
  5039. this.start();
  5040. var animator = new Animator(target, options.loop);
  5041. this.addAnimator(animator);
  5042. return animator;
  5043. };
  5044. return Animation;
  5045. }(Eventful));
  5046. var TOUCH_CLICK_DELAY = 300;
  5047. var globalEventSupported = env.domSupported;
  5048. var localNativeListenerNames = (function () {
  5049. var mouseHandlerNames = [
  5050. 'click', 'dblclick', 'mousewheel', 'wheel', 'mouseout',
  5051. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  5052. ];
  5053. var touchHandlerNames = [
  5054. 'touchstart', 'touchend', 'touchmove'
  5055. ];
  5056. var pointerEventNameMap = {
  5057. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  5058. };
  5059. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  5060. var nm = name.replace('mouse', 'pointer');
  5061. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  5062. });
  5063. return {
  5064. mouse: mouseHandlerNames,
  5065. touch: touchHandlerNames,
  5066. pointer: pointerHandlerNames
  5067. };
  5068. })();
  5069. var globalNativeListenerNames = {
  5070. mouse: ['mousemove', 'mouseup'],
  5071. pointer: ['pointermove', 'pointerup']
  5072. };
  5073. var wheelEventSupported = false;
  5074. function isPointerFromTouch(event) {
  5075. var pointerType = event.pointerType;
  5076. return pointerType === 'pen' || pointerType === 'touch';
  5077. }
  5078. function setTouchTimer(scope) {
  5079. scope.touching = true;
  5080. if (scope.touchTimer != null) {
  5081. clearTimeout(scope.touchTimer);
  5082. scope.touchTimer = null;
  5083. }
  5084. scope.touchTimer = setTimeout(function () {
  5085. scope.touching = false;
  5086. scope.touchTimer = null;
  5087. }, 700);
  5088. }
  5089. function markTouch(event) {
  5090. event && (event.zrByTouch = true);
  5091. }
  5092. function normalizeGlobalEvent(instance, event) {
  5093. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  5094. }
  5095. function isLocalEl(instance, el) {
  5096. var elTmp = el;
  5097. var isLocal = false;
  5098. while (elTmp && elTmp.nodeType !== 9
  5099. && !(isLocal = elTmp.domBelongToZr
  5100. || (elTmp !== el && elTmp === instance.painterRoot))) {
  5101. elTmp = elTmp.parentNode;
  5102. }
  5103. return isLocal;
  5104. }
  5105. var FakeGlobalEvent = (function () {
  5106. function FakeGlobalEvent(instance, event) {
  5107. this.stopPropagation = noop;
  5108. this.stopImmediatePropagation = noop;
  5109. this.preventDefault = noop;
  5110. this.type = event.type;
  5111. this.target = this.currentTarget = instance.dom;
  5112. this.pointerType = event.pointerType;
  5113. this.clientX = event.clientX;
  5114. this.clientY = event.clientY;
  5115. }
  5116. return FakeGlobalEvent;
  5117. }());
  5118. var localDOMHandlers = {
  5119. mousedown: function (event) {
  5120. event = normalizeEvent(this.dom, event);
  5121. this.__mayPointerCapture = [event.zrX, event.zrY];
  5122. this.trigger('mousedown', event);
  5123. },
  5124. mousemove: function (event) {
  5125. event = normalizeEvent(this.dom, event);
  5126. var downPoint = this.__mayPointerCapture;
  5127. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  5128. this.__togglePointerCapture(true);
  5129. }
  5130. this.trigger('mousemove', event);
  5131. },
  5132. mouseup: function (event) {
  5133. event = normalizeEvent(this.dom, event);
  5134. this.__togglePointerCapture(false);
  5135. this.trigger('mouseup', event);
  5136. },
  5137. mouseout: function (event) {
  5138. event = normalizeEvent(this.dom, event);
  5139. var element = event.toElement || event.relatedTarget;
  5140. if (!isLocalEl(this, element)) {
  5141. if (this.__pointerCapturing) {
  5142. event.zrEventControl = 'no_globalout';
  5143. }
  5144. this.trigger('mouseout', event);
  5145. }
  5146. },
  5147. wheel: function (event) {
  5148. wheelEventSupported = true;
  5149. event = normalizeEvent(this.dom, event);
  5150. this.trigger('mousewheel', event);
  5151. },
  5152. mousewheel: function (event) {
  5153. if (wheelEventSupported) {
  5154. return;
  5155. }
  5156. event = normalizeEvent(this.dom, event);
  5157. this.trigger('mousewheel', event);
  5158. },
  5159. touchstart: function (event) {
  5160. event = normalizeEvent(this.dom, event);
  5161. markTouch(event);
  5162. this.__lastTouchMoment = new Date();
  5163. this.handler.processGesture(event, 'start');
  5164. localDOMHandlers.mousemove.call(this, event);
  5165. localDOMHandlers.mousedown.call(this, event);
  5166. },
  5167. touchmove: function (event) {
  5168. event = normalizeEvent(this.dom, event);
  5169. markTouch(event);
  5170. this.handler.processGesture(event, 'change');
  5171. localDOMHandlers.mousemove.call(this, event);
  5172. },
  5173. touchend: function (event) {
  5174. event = normalizeEvent(this.dom, event);
  5175. markTouch(event);
  5176. this.handler.processGesture(event, 'end');
  5177. localDOMHandlers.mouseup.call(this, event);
  5178. if (+new Date() - (+this.__lastTouchMoment) < TOUCH_CLICK_DELAY) {
  5179. localDOMHandlers.click.call(this, event);
  5180. }
  5181. },
  5182. pointerdown: function (event) {
  5183. localDOMHandlers.mousedown.call(this, event);
  5184. },
  5185. pointermove: function (event) {
  5186. if (!isPointerFromTouch(event)) {
  5187. localDOMHandlers.mousemove.call(this, event);
  5188. }
  5189. },
  5190. pointerup: function (event) {
  5191. localDOMHandlers.mouseup.call(this, event);
  5192. },
  5193. pointerout: function (event) {
  5194. if (!isPointerFromTouch(event)) {
  5195. localDOMHandlers.mouseout.call(this, event);
  5196. }
  5197. }
  5198. };
  5199. each(['click', 'dblclick', 'contextmenu'], function (name) {
  5200. localDOMHandlers[name] = function (event) {
  5201. event = normalizeEvent(this.dom, event);
  5202. this.trigger(name, event);
  5203. };
  5204. });
  5205. var globalDOMHandlers = {
  5206. pointermove: function (event) {
  5207. if (!isPointerFromTouch(event)) {
  5208. globalDOMHandlers.mousemove.call(this, event);
  5209. }
  5210. },
  5211. pointerup: function (event) {
  5212. globalDOMHandlers.mouseup.call(this, event);
  5213. },
  5214. mousemove: function (event) {
  5215. this.trigger('mousemove', event);
  5216. },
  5217. mouseup: function (event) {
  5218. var pointerCaptureReleasing = this.__pointerCapturing;
  5219. this.__togglePointerCapture(false);
  5220. this.trigger('mouseup', event);
  5221. if (pointerCaptureReleasing) {
  5222. event.zrEventControl = 'only_globalout';
  5223. this.trigger('mouseout', event);
  5224. }
  5225. }
  5226. };
  5227. function mountLocalDOMEventListeners(instance, scope) {
  5228. var domHandlers = scope.domHandlers;
  5229. if (env.pointerEventsSupported) {
  5230. each(localNativeListenerNames.pointer, function (nativeEventName) {
  5231. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5232. domHandlers[nativeEventName].call(instance, event);
  5233. });
  5234. });
  5235. }
  5236. else {
  5237. if (env.touchEventsSupported) {
  5238. each(localNativeListenerNames.touch, function (nativeEventName) {
  5239. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5240. domHandlers[nativeEventName].call(instance, event);
  5241. setTouchTimer(scope);
  5242. });
  5243. });
  5244. }
  5245. each(localNativeListenerNames.mouse, function (nativeEventName) {
  5246. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5247. event = getNativeEvent(event);
  5248. if (!scope.touching) {
  5249. domHandlers[nativeEventName].call(instance, event);
  5250. }
  5251. });
  5252. });
  5253. }
  5254. }
  5255. function mountGlobalDOMEventListeners(instance, scope) {
  5256. if (env.pointerEventsSupported) {
  5257. each(globalNativeListenerNames.pointer, mount);
  5258. }
  5259. else if (!env.touchEventsSupported) {
  5260. each(globalNativeListenerNames.mouse, mount);
  5261. }
  5262. function mount(nativeEventName) {
  5263. function nativeEventListener(event) {
  5264. event = getNativeEvent(event);
  5265. if (!isLocalEl(instance, event.target)) {
  5266. event = normalizeGlobalEvent(instance, event);
  5267. scope.domHandlers[nativeEventName].call(instance, event);
  5268. }
  5269. }
  5270. mountSingleDOMEventListener(scope, nativeEventName, nativeEventListener, { capture: true });
  5271. }
  5272. }
  5273. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  5274. scope.mounted[nativeEventName] = listener;
  5275. scope.listenerOpts[nativeEventName] = opt;
  5276. addEventListener(scope.domTarget, nativeEventName, listener, opt);
  5277. }
  5278. function unmountDOMEventListeners(scope) {
  5279. var mounted = scope.mounted;
  5280. for (var nativeEventName in mounted) {
  5281. if (mounted.hasOwnProperty(nativeEventName)) {
  5282. removeEventListener(scope.domTarget, nativeEventName, mounted[nativeEventName], scope.listenerOpts[nativeEventName]);
  5283. }
  5284. }
  5285. scope.mounted = {};
  5286. }
  5287. var DOMHandlerScope = (function () {
  5288. function DOMHandlerScope(domTarget, domHandlers) {
  5289. this.mounted = {};
  5290. this.listenerOpts = {};
  5291. this.touching = false;
  5292. this.domTarget = domTarget;
  5293. this.domHandlers = domHandlers;
  5294. }
  5295. return DOMHandlerScope;
  5296. }());
  5297. var HandlerDomProxy = (function (_super) {
  5298. __extends(HandlerDomProxy, _super);
  5299. function HandlerDomProxy(dom, painterRoot) {
  5300. var _this = _super.call(this) || this;
  5301. _this.__pointerCapturing = false;
  5302. _this.dom = dom;
  5303. _this.painterRoot = painterRoot;
  5304. _this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  5305. if (globalEventSupported) {
  5306. _this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  5307. }
  5308. mountLocalDOMEventListeners(_this, _this._localHandlerScope);
  5309. return _this;
  5310. }
  5311. HandlerDomProxy.prototype.dispose = function () {
  5312. unmountDOMEventListeners(this._localHandlerScope);
  5313. if (globalEventSupported) {
  5314. unmountDOMEventListeners(this._globalHandlerScope);
  5315. }
  5316. };
  5317. HandlerDomProxy.prototype.setCursor = function (cursorStyle) {
  5318. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  5319. };
  5320. HandlerDomProxy.prototype.__togglePointerCapture = function (isPointerCapturing) {
  5321. this.__mayPointerCapture = null;
  5322. if (globalEventSupported
  5323. && ((+this.__pointerCapturing) ^ (+isPointerCapturing))) {
  5324. this.__pointerCapturing = isPointerCapturing;
  5325. var globalHandlerScope = this._globalHandlerScope;
  5326. isPointerCapturing
  5327. ? mountGlobalDOMEventListeners(this, globalHandlerScope)
  5328. : unmountDOMEventListeners(globalHandlerScope);
  5329. }
  5330. };
  5331. return HandlerDomProxy;
  5332. }(Eventful));
  5333. var dpr = 1;
  5334. if (env.hasGlobalWindow) {
  5335. dpr = Math.max(window.devicePixelRatio
  5336. || (window.screen && window.screen.deviceXDPI / window.screen.logicalXDPI)
  5337. || 1, 1);
  5338. }
  5339. var devicePixelRatio = dpr;
  5340. var DARK_MODE_THRESHOLD = 0.4;
  5341. var DARK_LABEL_COLOR = '#333';
  5342. var LIGHT_LABEL_COLOR = '#ccc';
  5343. var LIGHTER_LABEL_COLOR = '#eee';
  5344. var mIdentity = identity;
  5345. var EPSILON$2 = 5e-5;
  5346. function isNotAroundZero$1(val) {
  5347. return val > EPSILON$2 || val < -EPSILON$2;
  5348. }
  5349. var scaleTmp = [];
  5350. var tmpTransform = [];
  5351. var originTransform = create$1();
  5352. var abs = Math.abs;
  5353. var Transformable = (function () {
  5354. function Transformable() {
  5355. }
  5356. Transformable.prototype.getLocalTransform = function (m) {
  5357. return Transformable.getLocalTransform(this, m);
  5358. };
  5359. Transformable.prototype.setPosition = function (arr) {
  5360. this.x = arr[0];
  5361. this.y = arr[1];
  5362. };
  5363. Transformable.prototype.setScale = function (arr) {
  5364. this.scaleX = arr[0];
  5365. this.scaleY = arr[1];
  5366. };
  5367. Transformable.prototype.setSkew = function (arr) {
  5368. this.skewX = arr[0];
  5369. this.skewY = arr[1];
  5370. };
  5371. Transformable.prototype.setOrigin = function (arr) {
  5372. this.originX = arr[0];
  5373. this.originY = arr[1];
  5374. };
  5375. Transformable.prototype.needLocalTransform = function () {
  5376. return isNotAroundZero$1(this.rotation)
  5377. || isNotAroundZero$1(this.x)
  5378. || isNotAroundZero$1(this.y)
  5379. || isNotAroundZero$1(this.scaleX - 1)
  5380. || isNotAroundZero$1(this.scaleY - 1)
  5381. || isNotAroundZero$1(this.skewX)
  5382. || isNotAroundZero$1(this.skewY);
  5383. };
  5384. Transformable.prototype.updateTransform = function () {
  5385. var parentTransform = this.parent && this.parent.transform;
  5386. var needLocalTransform = this.needLocalTransform();
  5387. var m = this.transform;
  5388. if (!(needLocalTransform || parentTransform)) {
  5389. m && mIdentity(m);
  5390. return;
  5391. }
  5392. m = m || create$1();
  5393. if (needLocalTransform) {
  5394. this.getLocalTransform(m);
  5395. }
  5396. else {
  5397. mIdentity(m);
  5398. }
  5399. if (parentTransform) {
  5400. if (needLocalTransform) {
  5401. mul$1(m, parentTransform, m);
  5402. }
  5403. else {
  5404. copy$1(m, parentTransform);
  5405. }
  5406. }
  5407. this.transform = m;
  5408. this._resolveGlobalScaleRatio(m);
  5409. };
  5410. Transformable.prototype._resolveGlobalScaleRatio = function (m) {
  5411. var globalScaleRatio = this.globalScaleRatio;
  5412. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  5413. this.getGlobalScale(scaleTmp);
  5414. var relX = scaleTmp[0] < 0 ? -1 : 1;
  5415. var relY = scaleTmp[1] < 0 ? -1 : 1;
  5416. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  5417. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  5418. m[0] *= sx;
  5419. m[1] *= sx;
  5420. m[2] *= sy;
  5421. m[3] *= sy;
  5422. }
  5423. this.invTransform = this.invTransform || create$1();
  5424. invert(this.invTransform, m);
  5425. };
  5426. Transformable.prototype.getComputedTransform = function () {
  5427. var transformNode = this;
  5428. var ancestors = [];
  5429. while (transformNode) {
  5430. ancestors.push(transformNode);
  5431. transformNode = transformNode.parent;
  5432. }
  5433. while (transformNode = ancestors.pop()) {
  5434. transformNode.updateTransform();
  5435. }
  5436. return this.transform;
  5437. };
  5438. Transformable.prototype.setLocalTransform = function (m) {
  5439. if (!m) {
  5440. return;
  5441. }
  5442. var sx = m[0] * m[0] + m[1] * m[1];
  5443. var sy = m[2] * m[2] + m[3] * m[3];
  5444. var rotation = Math.atan2(m[1], m[0]);
  5445. var shearX = Math.PI / 2 + rotation - Math.atan2(m[3], m[2]);
  5446. sy = Math.sqrt(sy) * Math.cos(shearX);
  5447. sx = Math.sqrt(sx);
  5448. this.skewX = shearX;
  5449. this.skewY = 0;
  5450. this.rotation = -rotation;
  5451. this.x = +m[4];
  5452. this.y = +m[5];
  5453. this.scaleX = sx;
  5454. this.scaleY = sy;
  5455. this.originX = 0;
  5456. this.originY = 0;
  5457. };
  5458. Transformable.prototype.decomposeTransform = function () {
  5459. if (!this.transform) {
  5460. return;
  5461. }
  5462. var parent = this.parent;
  5463. var m = this.transform;
  5464. if (parent && parent.transform) {
  5465. mul$1(tmpTransform, parent.invTransform, m);
  5466. m = tmpTransform;
  5467. }
  5468. var ox = this.originX;
  5469. var oy = this.originY;
  5470. if (ox || oy) {
  5471. originTransform[4] = ox;
  5472. originTransform[5] = oy;
  5473. mul$1(tmpTransform, m, originTransform);
  5474. tmpTransform[4] -= ox;
  5475. tmpTransform[5] -= oy;
  5476. m = tmpTransform;
  5477. }
  5478. this.setLocalTransform(m);
  5479. };
  5480. Transformable.prototype.getGlobalScale = function (out) {
  5481. var m = this.transform;
  5482. out = out || [];
  5483. if (!m) {
  5484. out[0] = 1;
  5485. out[1] = 1;
  5486. return out;
  5487. }
  5488. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  5489. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  5490. if (m[0] < 0) {
  5491. out[0] = -out[0];
  5492. }
  5493. if (m[3] < 0) {
  5494. out[1] = -out[1];
  5495. }
  5496. return out;
  5497. };
  5498. Transformable.prototype.transformCoordToLocal = function (x, y) {
  5499. var v2 = [x, y];
  5500. var invTransform = this.invTransform;
  5501. if (invTransform) {
  5502. applyTransform(v2, v2, invTransform);
  5503. }
  5504. return v2;
  5505. };
  5506. Transformable.prototype.transformCoordToGlobal = function (x, y) {
  5507. var v2 = [x, y];
  5508. var transform = this.transform;
  5509. if (transform) {
  5510. applyTransform(v2, v2, transform);
  5511. }
  5512. return v2;
  5513. };
  5514. Transformable.prototype.getLineScale = function () {
  5515. var m = this.transform;
  5516. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  5517. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  5518. : 1;
  5519. };
  5520. Transformable.prototype.copyTransform = function (source) {
  5521. copyTransform(this, source);
  5522. };
  5523. Transformable.getLocalTransform = function (target, m) {
  5524. m = m || [];
  5525. var ox = target.originX || 0;
  5526. var oy = target.originY || 0;
  5527. var sx = target.scaleX;
  5528. var sy = target.scaleY;
  5529. var ax = target.anchorX;
  5530. var ay = target.anchorY;
  5531. var rotation = target.rotation || 0;
  5532. var x = target.x;
  5533. var y = target.y;
  5534. var skewX = target.skewX ? Math.tan(target.skewX) : 0;
  5535. var skewY = target.skewY ? Math.tan(-target.skewY) : 0;
  5536. if (ox || oy || ax || ay) {
  5537. var dx = ox + ax;
  5538. var dy = oy + ay;
  5539. m[4] = -dx * sx - skewX * dy * sy;
  5540. m[5] = -dy * sy - skewY * dx * sx;
  5541. }
  5542. else {
  5543. m[4] = m[5] = 0;
  5544. }
  5545. m[0] = sx;
  5546. m[3] = sy;
  5547. m[1] = skewY * sx;
  5548. m[2] = skewX * sy;
  5549. rotation && rotate(m, m, rotation);
  5550. m[4] += ox + x;
  5551. m[5] += oy + y;
  5552. return m;
  5553. };
  5554. Transformable.initDefaultProps = (function () {
  5555. var proto = Transformable.prototype;
  5556. proto.scaleX =
  5557. proto.scaleY =
  5558. proto.globalScaleRatio = 1;
  5559. proto.x =
  5560. proto.y =
  5561. proto.originX =
  5562. proto.originY =
  5563. proto.skewX =
  5564. proto.skewY =
  5565. proto.rotation =
  5566. proto.anchorX =
  5567. proto.anchorY = 0;
  5568. })();
  5569. return Transformable;
  5570. }());
  5571. var TRANSFORMABLE_PROPS = [
  5572. 'x', 'y', 'originX', 'originY', 'anchorX', 'anchorY', 'rotation', 'scaleX', 'scaleY', 'skewX', 'skewY'
  5573. ];
  5574. function copyTransform(target, source) {
  5575. for (var i = 0; i < TRANSFORMABLE_PROPS.length; i++) {
  5576. var propName = TRANSFORMABLE_PROPS[i];
  5577. target[propName] = source[propName];
  5578. }
  5579. }
  5580. var textWidthCache = {};
  5581. function getWidth(text, font) {
  5582. font = font || DEFAULT_FONT;
  5583. var cacheOfFont = textWidthCache[font];
  5584. if (!cacheOfFont) {
  5585. cacheOfFont = textWidthCache[font] = new LRU(500);
  5586. }
  5587. var width = cacheOfFont.get(text);
  5588. if (width == null) {
  5589. width = platformApi.measureText(text, font).width;
  5590. cacheOfFont.put(text, width);
  5591. }
  5592. return width;
  5593. }
  5594. function innerGetBoundingRect(text, font, textAlign, textBaseline) {
  5595. var width = getWidth(text, font);
  5596. var height = getLineHeight(font);
  5597. var x = adjustTextX(0, width, textAlign);
  5598. var y = adjustTextY$1(0, height, textBaseline);
  5599. var rect = new BoundingRect(x, y, width, height);
  5600. return rect;
  5601. }
  5602. function getBoundingRect(text, font, textAlign, textBaseline) {
  5603. var textLines = ((text || '') + '').split('\n');
  5604. var len = textLines.length;
  5605. if (len === 1) {
  5606. return innerGetBoundingRect(textLines[0], font, textAlign, textBaseline);
  5607. }
  5608. else {
  5609. var uniondRect = new BoundingRect(0, 0, 0, 0);
  5610. for (var i = 0; i < textLines.length; i++) {
  5611. var rect = innerGetBoundingRect(textLines[i], font, textAlign, textBaseline);
  5612. i === 0 ? uniondRect.copy(rect) : uniondRect.union(rect);
  5613. }
  5614. return uniondRect;
  5615. }
  5616. }
  5617. function adjustTextX(x, width, textAlign) {
  5618. if (textAlign === 'right') {
  5619. x -= width;
  5620. }
  5621. else if (textAlign === 'center') {
  5622. x -= width / 2;
  5623. }
  5624. return x;
  5625. }
  5626. function adjustTextY$1(y, height, verticalAlign) {
  5627. if (verticalAlign === 'middle') {
  5628. y -= height / 2;
  5629. }
  5630. else if (verticalAlign === 'bottom') {
  5631. y -= height;
  5632. }
  5633. return y;
  5634. }
  5635. function getLineHeight(font) {
  5636. return getWidth('国', font);
  5637. }
  5638. function parsePercent(value, maxValue) {
  5639. if (typeof value === 'string') {
  5640. if (value.lastIndexOf('%') >= 0) {
  5641. return parseFloat(value) / 100 * maxValue;
  5642. }
  5643. return parseFloat(value);
  5644. }
  5645. return value;
  5646. }
  5647. function calculateTextPosition(out, opts, rect) {
  5648. var textPosition = opts.position || 'inside';
  5649. var distance = opts.distance != null ? opts.distance : 5;
  5650. var height = rect.height;
  5651. var width = rect.width;
  5652. var halfHeight = height / 2;
  5653. var x = rect.x;
  5654. var y = rect.y;
  5655. var textAlign = 'left';
  5656. var textVerticalAlign = 'top';
  5657. if (textPosition instanceof Array) {
  5658. x += parsePercent(textPosition[0], rect.width);
  5659. y += parsePercent(textPosition[1], rect.height);
  5660. textAlign = null;
  5661. textVerticalAlign = null;
  5662. }
  5663. else {
  5664. switch (textPosition) {
  5665. case 'left':
  5666. x -= distance;
  5667. y += halfHeight;
  5668. textAlign = 'right';
  5669. textVerticalAlign = 'middle';
  5670. break;
  5671. case 'right':
  5672. x += distance + width;
  5673. y += halfHeight;
  5674. textVerticalAlign = 'middle';
  5675. break;
  5676. case 'top':
  5677. x += width / 2;
  5678. y -= distance;
  5679. textAlign = 'center';
  5680. textVerticalAlign = 'bottom';
  5681. break;
  5682. case 'bottom':
  5683. x += width / 2;
  5684. y += height + distance;
  5685. textAlign = 'center';
  5686. break;
  5687. case 'inside':
  5688. x += width / 2;
  5689. y += halfHeight;
  5690. textAlign = 'center';
  5691. textVerticalAlign = 'middle';
  5692. break;
  5693. case 'insideLeft':
  5694. x += distance;
  5695. y += halfHeight;
  5696. textVerticalAlign = 'middle';
  5697. break;
  5698. case 'insideRight':
  5699. x += width - distance;
  5700. y += halfHeight;
  5701. textAlign = 'right';
  5702. textVerticalAlign = 'middle';
  5703. break;
  5704. case 'insideTop':
  5705. x += width / 2;
  5706. y += distance;
  5707. textAlign = 'center';
  5708. break;
  5709. case 'insideBottom':
  5710. x += width / 2;
  5711. y += height - distance;
  5712. textAlign = 'center';
  5713. textVerticalAlign = 'bottom';
  5714. break;
  5715. case 'insideTopLeft':
  5716. x += distance;
  5717. y += distance;
  5718. break;
  5719. case 'insideTopRight':
  5720. x += width - distance;
  5721. y += distance;
  5722. textAlign = 'right';
  5723. break;
  5724. case 'insideBottomLeft':
  5725. x += distance;
  5726. y += height - distance;
  5727. textVerticalAlign = 'bottom';
  5728. break;
  5729. case 'insideBottomRight':
  5730. x += width - distance;
  5731. y += height - distance;
  5732. textAlign = 'right';
  5733. textVerticalAlign = 'bottom';
  5734. break;
  5735. }
  5736. }
  5737. out = out || {};
  5738. out.x = x;
  5739. out.y = y;
  5740. out.align = textAlign;
  5741. out.verticalAlign = textVerticalAlign;
  5742. return out;
  5743. }
  5744. var PRESERVED_NORMAL_STATE = '__zr_normal__';
  5745. var PRIMARY_STATES_KEYS = TRANSFORMABLE_PROPS.concat(['ignore']);
  5746. var DEFAULT_ANIMATABLE_MAP = reduce(TRANSFORMABLE_PROPS, function (obj, key) {
  5747. obj[key] = true;
  5748. return obj;
  5749. }, { ignore: false });
  5750. var tmpTextPosCalcRes = {};
  5751. var tmpBoundingRect = new BoundingRect(0, 0, 0, 0);
  5752. var Element = (function () {
  5753. function Element(props) {
  5754. this.id = guid();
  5755. this.animators = [];
  5756. this.currentStates = [];
  5757. this.states = {};
  5758. this._init(props);
  5759. }
  5760. Element.prototype._init = function (props) {
  5761. this.attr(props);
  5762. };
  5763. Element.prototype.drift = function (dx, dy, e) {
  5764. switch (this.draggable) {
  5765. case 'horizontal':
  5766. dy = 0;
  5767. break;
  5768. case 'vertical':
  5769. dx = 0;
  5770. break;
  5771. }
  5772. var m = this.transform;
  5773. if (!m) {
  5774. m = this.transform = [1, 0, 0, 1, 0, 0];
  5775. }
  5776. m[4] += dx;
  5777. m[5] += dy;
  5778. this.decomposeTransform();
  5779. this.markRedraw();
  5780. };
  5781. Element.prototype.beforeUpdate = function () { };
  5782. Element.prototype.afterUpdate = function () { };
  5783. Element.prototype.update = function () {
  5784. this.updateTransform();
  5785. if (this.__dirty) {
  5786. this.updateInnerText();
  5787. }
  5788. };
  5789. Element.prototype.updateInnerText = function (forceUpdate) {
  5790. var textEl = this._textContent;
  5791. if (textEl && (!textEl.ignore || forceUpdate)) {
  5792. if (!this.textConfig) {
  5793. this.textConfig = {};
  5794. }
  5795. var textConfig = this.textConfig;
  5796. var isLocal = textConfig.local;
  5797. var innerTransformable = textEl.innerTransformable;
  5798. var textAlign = void 0;
  5799. var textVerticalAlign = void 0;
  5800. var textStyleChanged = false;
  5801. innerTransformable.parent = isLocal ? this : null;
  5802. var innerOrigin = false;
  5803. innerTransformable.copyTransform(textEl);
  5804. if (textConfig.position != null) {
  5805. var layoutRect = tmpBoundingRect;
  5806. if (textConfig.layoutRect) {
  5807. layoutRect.copy(textConfig.layoutRect);
  5808. }
  5809. else {
  5810. layoutRect.copy(this.getBoundingRect());
  5811. }
  5812. if (!isLocal) {
  5813. layoutRect.applyTransform(this.transform);
  5814. }
  5815. if (this.calculateTextPosition) {
  5816. this.calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5817. }
  5818. else {
  5819. calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5820. }
  5821. innerTransformable.x = tmpTextPosCalcRes.x;
  5822. innerTransformable.y = tmpTextPosCalcRes.y;
  5823. textAlign = tmpTextPosCalcRes.align;
  5824. textVerticalAlign = tmpTextPosCalcRes.verticalAlign;
  5825. var textOrigin = textConfig.origin;
  5826. if (textOrigin && textConfig.rotation != null) {
  5827. var relOriginX = void 0;
  5828. var relOriginY = void 0;
  5829. if (textOrigin === 'center') {
  5830. relOriginX = layoutRect.width * 0.5;
  5831. relOriginY = layoutRect.height * 0.5;
  5832. }
  5833. else {
  5834. relOriginX = parsePercent(textOrigin[0], layoutRect.width);
  5835. relOriginY = parsePercent(textOrigin[1], layoutRect.height);
  5836. }
  5837. innerOrigin = true;
  5838. innerTransformable.originX = -innerTransformable.x + relOriginX + (isLocal ? 0 : layoutRect.x);
  5839. innerTransformable.originY = -innerTransformable.y + relOriginY + (isLocal ? 0 : layoutRect.y);
  5840. }
  5841. }
  5842. if (textConfig.rotation != null) {
  5843. innerTransformable.rotation = textConfig.rotation;
  5844. }
  5845. var textOffset = textConfig.offset;
  5846. if (textOffset) {
  5847. innerTransformable.x += textOffset[0];
  5848. innerTransformable.y += textOffset[1];
  5849. if (!innerOrigin) {
  5850. innerTransformable.originX = -textOffset[0];
  5851. innerTransformable.originY = -textOffset[1];
  5852. }
  5853. }
  5854. var isInside = textConfig.inside == null
  5855. ? (typeof textConfig.position === 'string' && textConfig.position.indexOf('inside') >= 0)
  5856. : textConfig.inside;
  5857. var innerTextDefaultStyle = this._innerTextDefaultStyle || (this._innerTextDefaultStyle = {});
  5858. var textFill = void 0;
  5859. var textStroke = void 0;
  5860. var autoStroke = void 0;
  5861. if (isInside && this.canBeInsideText()) {
  5862. textFill = textConfig.insideFill;
  5863. textStroke = textConfig.insideStroke;
  5864. if (textFill == null || textFill === 'auto') {
  5865. textFill = this.getInsideTextFill();
  5866. }
  5867. if (textStroke == null || textStroke === 'auto') {
  5868. textStroke = this.getInsideTextStroke(textFill);
  5869. autoStroke = true;
  5870. }
  5871. }
  5872. else {
  5873. textFill = textConfig.outsideFill;
  5874. textStroke = textConfig.outsideStroke;
  5875. if (textFill == null || textFill === 'auto') {
  5876. textFill = this.getOutsideFill();
  5877. }
  5878. if (textStroke == null || textStroke === 'auto') {
  5879. textStroke = this.getOutsideStroke(textFill);
  5880. autoStroke = true;
  5881. }
  5882. }
  5883. textFill = textFill || '#000';
  5884. if (textFill !== innerTextDefaultStyle.fill
  5885. || textStroke !== innerTextDefaultStyle.stroke
  5886. || autoStroke !== innerTextDefaultStyle.autoStroke
  5887. || textAlign !== innerTextDefaultStyle.align
  5888. || textVerticalAlign !== innerTextDefaultStyle.verticalAlign) {
  5889. textStyleChanged = true;
  5890. innerTextDefaultStyle.fill = textFill;
  5891. innerTextDefaultStyle.stroke = textStroke;
  5892. innerTextDefaultStyle.autoStroke = autoStroke;
  5893. innerTextDefaultStyle.align = textAlign;
  5894. innerTextDefaultStyle.verticalAlign = textVerticalAlign;
  5895. textEl.setDefaultTextStyle(innerTextDefaultStyle);
  5896. }
  5897. textEl.__dirty |= REDRAW_BIT;
  5898. if (textStyleChanged) {
  5899. textEl.dirtyStyle(true);
  5900. }
  5901. }
  5902. };
  5903. Element.prototype.canBeInsideText = function () {
  5904. return true;
  5905. };
  5906. Element.prototype.getInsideTextFill = function () {
  5907. return '#fff';
  5908. };
  5909. Element.prototype.getInsideTextStroke = function (textFill) {
  5910. return '#000';
  5911. };
  5912. Element.prototype.getOutsideFill = function () {
  5913. return this.__zr && this.__zr.isDarkMode() ? LIGHT_LABEL_COLOR : DARK_LABEL_COLOR;
  5914. };
  5915. Element.prototype.getOutsideStroke = function (textFill) {
  5916. var backgroundColor = this.__zr && this.__zr.getBackgroundColor();
  5917. var colorArr = typeof backgroundColor === 'string' && parse(backgroundColor);
  5918. if (!colorArr) {
  5919. colorArr = [255, 255, 255, 1];
  5920. }
  5921. var alpha = colorArr[3];
  5922. var isDark = this.__zr.isDarkMode();
  5923. for (var i = 0; i < 3; i++) {
  5924. colorArr[i] = colorArr[i] * alpha + (isDark ? 0 : 255) * (1 - alpha);
  5925. }
  5926. colorArr[3] = 1;
  5927. return stringify(colorArr, 'rgba');
  5928. };
  5929. Element.prototype.traverse = function (cb, context) { };
  5930. Element.prototype.attrKV = function (key, value) {
  5931. if (key === 'textConfig') {
  5932. this.setTextConfig(value);
  5933. }
  5934. else if (key === 'textContent') {
  5935. this.setTextContent(value);
  5936. }
  5937. else if (key === 'clipPath') {
  5938. this.setClipPath(value);
  5939. }
  5940. else if (key === 'extra') {
  5941. this.extra = this.extra || {};
  5942. extend(this.extra, value);
  5943. }
  5944. else {
  5945. this[key] = value;
  5946. }
  5947. };
  5948. Element.prototype.hide = function () {
  5949. this.ignore = true;
  5950. this.markRedraw();
  5951. };
  5952. Element.prototype.show = function () {
  5953. this.ignore = false;
  5954. this.markRedraw();
  5955. };
  5956. Element.prototype.attr = function (keyOrObj, value) {
  5957. if (typeof keyOrObj === 'string') {
  5958. this.attrKV(keyOrObj, value);
  5959. }
  5960. else if (isObject(keyOrObj)) {
  5961. var obj = keyOrObj;
  5962. var keysArr = keys(obj);
  5963. for (var i = 0; i < keysArr.length; i++) {
  5964. var key = keysArr[i];
  5965. this.attrKV(key, keyOrObj[key]);
  5966. }
  5967. }
  5968. this.markRedraw();
  5969. return this;
  5970. };
  5971. Element.prototype.saveCurrentToNormalState = function (toState) {
  5972. this._innerSaveToNormal(toState);
  5973. var normalState = this._normalState;
  5974. for (var i = 0; i < this.animators.length; i++) {
  5975. var animator = this.animators[i];
  5976. var fromStateTransition = animator.__fromStateTransition;
  5977. if (animator.getLoop() || fromStateTransition && fromStateTransition !== PRESERVED_NORMAL_STATE) {
  5978. continue;
  5979. }
  5980. var targetName = animator.targetName;
  5981. var target = targetName
  5982. ? normalState[targetName] : normalState;
  5983. animator.saveTo(target);
  5984. }
  5985. };
  5986. Element.prototype._innerSaveToNormal = function (toState) {
  5987. var normalState = this._normalState;
  5988. if (!normalState) {
  5989. normalState = this._normalState = {};
  5990. }
  5991. if (toState.textConfig && !normalState.textConfig) {
  5992. normalState.textConfig = this.textConfig;
  5993. }
  5994. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS);
  5995. };
  5996. Element.prototype._savePrimaryToNormal = function (toState, normalState, primaryKeys) {
  5997. for (var i = 0; i < primaryKeys.length; i++) {
  5998. var key = primaryKeys[i];
  5999. if (toState[key] != null && !(key in normalState)) {
  6000. normalState[key] = this[key];
  6001. }
  6002. }
  6003. };
  6004. Element.prototype.hasState = function () {
  6005. return this.currentStates.length > 0;
  6006. };
  6007. Element.prototype.getState = function (name) {
  6008. return this.states[name];
  6009. };
  6010. Element.prototype.ensureState = function (name) {
  6011. var states = this.states;
  6012. if (!states[name]) {
  6013. states[name] = {};
  6014. }
  6015. return states[name];
  6016. };
  6017. Element.prototype.clearStates = function (noAnimation) {
  6018. this.useState(PRESERVED_NORMAL_STATE, false, noAnimation);
  6019. };
  6020. Element.prototype.useState = function (stateName, keepCurrentStates, noAnimation, forceUseHoverLayer) {
  6021. var toNormalState = stateName === PRESERVED_NORMAL_STATE;
  6022. var hasStates = this.hasState();
  6023. if (!hasStates && toNormalState) {
  6024. return;
  6025. }
  6026. var currentStates = this.currentStates;
  6027. var animationCfg = this.stateTransition;
  6028. if (indexOf(currentStates, stateName) >= 0 && (keepCurrentStates || currentStates.length === 1)) {
  6029. return;
  6030. }
  6031. var state;
  6032. if (this.stateProxy && !toNormalState) {
  6033. state = this.stateProxy(stateName);
  6034. }
  6035. if (!state) {
  6036. state = (this.states && this.states[stateName]);
  6037. }
  6038. if (!state && !toNormalState) {
  6039. logError("State " + stateName + " not exists.");
  6040. return;
  6041. }
  6042. if (!toNormalState) {
  6043. this.saveCurrentToNormalState(state);
  6044. }
  6045. var useHoverLayer = !!((state && state.hoverLayer) || forceUseHoverLayer);
  6046. if (useHoverLayer) {
  6047. this._toggleHoverLayerFlag(true);
  6048. }
  6049. this._applyStateObj(stateName, state, this._normalState, keepCurrentStates, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6050. var textContent = this._textContent;
  6051. var textGuide = this._textGuide;
  6052. if (textContent) {
  6053. textContent.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6054. }
  6055. if (textGuide) {
  6056. textGuide.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6057. }
  6058. if (toNormalState) {
  6059. this.currentStates = [];
  6060. this._normalState = {};
  6061. }
  6062. else {
  6063. if (!keepCurrentStates) {
  6064. this.currentStates = [stateName];
  6065. }
  6066. else {
  6067. this.currentStates.push(stateName);
  6068. }
  6069. }
  6070. this._updateAnimationTargets();
  6071. this.markRedraw();
  6072. if (!useHoverLayer && this.__inHover) {
  6073. this._toggleHoverLayerFlag(false);
  6074. this.__dirty &= ~REDRAW_BIT;
  6075. }
  6076. return state;
  6077. };
  6078. Element.prototype.useStates = function (states, noAnimation, forceUseHoverLayer) {
  6079. if (!states.length) {
  6080. this.clearStates();
  6081. }
  6082. else {
  6083. var stateObjects = [];
  6084. var currentStates = this.currentStates;
  6085. var len = states.length;
  6086. var notChange = len === currentStates.length;
  6087. if (notChange) {
  6088. for (var i = 0; i < len; i++) {
  6089. if (states[i] !== currentStates[i]) {
  6090. notChange = false;
  6091. break;
  6092. }
  6093. }
  6094. }
  6095. if (notChange) {
  6096. return;
  6097. }
  6098. for (var i = 0; i < len; i++) {
  6099. var stateName = states[i];
  6100. var stateObj = void 0;
  6101. if (this.stateProxy) {
  6102. stateObj = this.stateProxy(stateName, states);
  6103. }
  6104. if (!stateObj) {
  6105. stateObj = this.states[stateName];
  6106. }
  6107. if (stateObj) {
  6108. stateObjects.push(stateObj);
  6109. }
  6110. }
  6111. var lastStateObj = stateObjects[len - 1];
  6112. var useHoverLayer = !!((lastStateObj && lastStateObj.hoverLayer) || forceUseHoverLayer);
  6113. if (useHoverLayer) {
  6114. this._toggleHoverLayerFlag(true);
  6115. }
  6116. var mergedState = this._mergeStates(stateObjects);
  6117. var animationCfg = this.stateTransition;
  6118. this.saveCurrentToNormalState(mergedState);
  6119. this._applyStateObj(states.join(','), mergedState, this._normalState, false, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6120. var textContent = this._textContent;
  6121. var textGuide = this._textGuide;
  6122. if (textContent) {
  6123. textContent.useStates(states, noAnimation, useHoverLayer);
  6124. }
  6125. if (textGuide) {
  6126. textGuide.useStates(states, noAnimation, useHoverLayer);
  6127. }
  6128. this._updateAnimationTargets();
  6129. this.currentStates = states.slice();
  6130. this.markRedraw();
  6131. if (!useHoverLayer && this.__inHover) {
  6132. this._toggleHoverLayerFlag(false);
  6133. this.__dirty &= ~REDRAW_BIT;
  6134. }
  6135. }
  6136. };
  6137. Element.prototype._updateAnimationTargets = function () {
  6138. for (var i = 0; i < this.animators.length; i++) {
  6139. var animator = this.animators[i];
  6140. if (animator.targetName) {
  6141. animator.changeTarget(this[animator.targetName]);
  6142. }
  6143. }
  6144. };
  6145. Element.prototype.removeState = function (state) {
  6146. var idx = indexOf(this.currentStates, state);
  6147. if (idx >= 0) {
  6148. var currentStates = this.currentStates.slice();
  6149. currentStates.splice(idx, 1);
  6150. this.useStates(currentStates);
  6151. }
  6152. };
  6153. Element.prototype.replaceState = function (oldState, newState, forceAdd) {
  6154. var currentStates = this.currentStates.slice();
  6155. var idx = indexOf(currentStates, oldState);
  6156. var newStateExists = indexOf(currentStates, newState) >= 0;
  6157. if (idx >= 0) {
  6158. if (!newStateExists) {
  6159. currentStates[idx] = newState;
  6160. }
  6161. else {
  6162. currentStates.splice(idx, 1);
  6163. }
  6164. }
  6165. else if (forceAdd && !newStateExists) {
  6166. currentStates.push(newState);
  6167. }
  6168. this.useStates(currentStates);
  6169. };
  6170. Element.prototype.toggleState = function (state, enable) {
  6171. if (enable) {
  6172. this.useState(state, true);
  6173. }
  6174. else {
  6175. this.removeState(state);
  6176. }
  6177. };
  6178. Element.prototype._mergeStates = function (states) {
  6179. var mergedState = {};
  6180. var mergedTextConfig;
  6181. for (var i = 0; i < states.length; i++) {
  6182. var state = states[i];
  6183. extend(mergedState, state);
  6184. if (state.textConfig) {
  6185. mergedTextConfig = mergedTextConfig || {};
  6186. extend(mergedTextConfig, state.textConfig);
  6187. }
  6188. }
  6189. if (mergedTextConfig) {
  6190. mergedState.textConfig = mergedTextConfig;
  6191. }
  6192. return mergedState;
  6193. };
  6194. Element.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  6195. var needsRestoreToNormal = !(state && keepCurrentStates);
  6196. if (state && state.textConfig) {
  6197. this.textConfig = extend({}, keepCurrentStates ? this.textConfig : normalState.textConfig);
  6198. extend(this.textConfig, state.textConfig);
  6199. }
  6200. else if (needsRestoreToNormal) {
  6201. if (normalState.textConfig) {
  6202. this.textConfig = normalState.textConfig;
  6203. }
  6204. }
  6205. var transitionTarget = {};
  6206. var hasTransition = false;
  6207. for (var i = 0; i < PRIMARY_STATES_KEYS.length; i++) {
  6208. var key = PRIMARY_STATES_KEYS[i];
  6209. var propNeedsTransition = transition && DEFAULT_ANIMATABLE_MAP[key];
  6210. if (state && state[key] != null) {
  6211. if (propNeedsTransition) {
  6212. hasTransition = true;
  6213. transitionTarget[key] = state[key];
  6214. }
  6215. else {
  6216. this[key] = state[key];
  6217. }
  6218. }
  6219. else if (needsRestoreToNormal) {
  6220. if (normalState[key] != null) {
  6221. if (propNeedsTransition) {
  6222. hasTransition = true;
  6223. transitionTarget[key] = normalState[key];
  6224. }
  6225. else {
  6226. this[key] = normalState[key];
  6227. }
  6228. }
  6229. }
  6230. }
  6231. if (!transition) {
  6232. for (var i = 0; i < this.animators.length; i++) {
  6233. var animator = this.animators[i];
  6234. var targetName = animator.targetName;
  6235. if (!animator.getLoop()) {
  6236. animator.__changeFinalValue(targetName
  6237. ? (state || normalState)[targetName]
  6238. : (state || normalState));
  6239. }
  6240. }
  6241. }
  6242. if (hasTransition) {
  6243. this._transitionState(stateName, transitionTarget, animationCfg);
  6244. }
  6245. };
  6246. Element.prototype._attachComponent = function (componentEl) {
  6247. if (componentEl.__zr && !componentEl.__hostTarget) {
  6248. {
  6249. throw new Error('Text element has been added to zrender.');
  6250. }
  6251. }
  6252. if (componentEl === this) {
  6253. {
  6254. throw new Error('Recursive component attachment.');
  6255. }
  6256. }
  6257. var zr = this.__zr;
  6258. if (zr) {
  6259. componentEl.addSelfToZr(zr);
  6260. }
  6261. componentEl.__zr = zr;
  6262. componentEl.__hostTarget = this;
  6263. };
  6264. Element.prototype._detachComponent = function (componentEl) {
  6265. if (componentEl.__zr) {
  6266. componentEl.removeSelfFromZr(componentEl.__zr);
  6267. }
  6268. componentEl.__zr = null;
  6269. componentEl.__hostTarget = null;
  6270. };
  6271. Element.prototype.getClipPath = function () {
  6272. return this._clipPath;
  6273. };
  6274. Element.prototype.setClipPath = function (clipPath) {
  6275. if (this._clipPath && this._clipPath !== clipPath) {
  6276. this.removeClipPath();
  6277. }
  6278. this._attachComponent(clipPath);
  6279. this._clipPath = clipPath;
  6280. this.markRedraw();
  6281. };
  6282. Element.prototype.removeClipPath = function () {
  6283. var clipPath = this._clipPath;
  6284. if (clipPath) {
  6285. this._detachComponent(clipPath);
  6286. this._clipPath = null;
  6287. this.markRedraw();
  6288. }
  6289. };
  6290. Element.prototype.getTextContent = function () {
  6291. return this._textContent;
  6292. };
  6293. Element.prototype.setTextContent = function (textEl) {
  6294. var previousTextContent = this._textContent;
  6295. if (previousTextContent === textEl) {
  6296. return;
  6297. }
  6298. if (previousTextContent && previousTextContent !== textEl) {
  6299. this.removeTextContent();
  6300. }
  6301. {
  6302. if (textEl.__zr && !textEl.__hostTarget) {
  6303. throw new Error('Text element has been added to zrender.');
  6304. }
  6305. }
  6306. textEl.innerTransformable = new Transformable();
  6307. this._attachComponent(textEl);
  6308. this._textContent = textEl;
  6309. this.markRedraw();
  6310. };
  6311. Element.prototype.setTextConfig = function (cfg) {
  6312. if (!this.textConfig) {
  6313. this.textConfig = {};
  6314. }
  6315. extend(this.textConfig, cfg);
  6316. this.markRedraw();
  6317. };
  6318. Element.prototype.removeTextConfig = function () {
  6319. this.textConfig = null;
  6320. this.markRedraw();
  6321. };
  6322. Element.prototype.removeTextContent = function () {
  6323. var textEl = this._textContent;
  6324. if (textEl) {
  6325. textEl.innerTransformable = null;
  6326. this._detachComponent(textEl);
  6327. this._textContent = null;
  6328. this._innerTextDefaultStyle = null;
  6329. this.markRedraw();
  6330. }
  6331. };
  6332. Element.prototype.getTextGuideLine = function () {
  6333. return this._textGuide;
  6334. };
  6335. Element.prototype.setTextGuideLine = function (guideLine) {
  6336. if (this._textGuide && this._textGuide !== guideLine) {
  6337. this.removeTextGuideLine();
  6338. }
  6339. this._attachComponent(guideLine);
  6340. this._textGuide = guideLine;
  6341. this.markRedraw();
  6342. };
  6343. Element.prototype.removeTextGuideLine = function () {
  6344. var textGuide = this._textGuide;
  6345. if (textGuide) {
  6346. this._detachComponent(textGuide);
  6347. this._textGuide = null;
  6348. this.markRedraw();
  6349. }
  6350. };
  6351. Element.prototype.markRedraw = function () {
  6352. this.__dirty |= REDRAW_BIT;
  6353. var zr = this.__zr;
  6354. if (zr) {
  6355. if (this.__inHover) {
  6356. zr.refreshHover();
  6357. }
  6358. else {
  6359. zr.refresh();
  6360. }
  6361. }
  6362. if (this.__hostTarget) {
  6363. this.__hostTarget.markRedraw();
  6364. }
  6365. };
  6366. Element.prototype.dirty = function () {
  6367. this.markRedraw();
  6368. };
  6369. Element.prototype._toggleHoverLayerFlag = function (inHover) {
  6370. this.__inHover = inHover;
  6371. var textContent = this._textContent;
  6372. var textGuide = this._textGuide;
  6373. if (textContent) {
  6374. textContent.__inHover = inHover;
  6375. }
  6376. if (textGuide) {
  6377. textGuide.__inHover = inHover;
  6378. }
  6379. };
  6380. Element.prototype.addSelfToZr = function (zr) {
  6381. if (this.__zr === zr) {
  6382. return;
  6383. }
  6384. this.__zr = zr;
  6385. var animators = this.animators;
  6386. if (animators) {
  6387. for (var i = 0; i < animators.length; i++) {
  6388. zr.animation.addAnimator(animators[i]);
  6389. }
  6390. }
  6391. if (this._clipPath) {
  6392. this._clipPath.addSelfToZr(zr);
  6393. }
  6394. if (this._textContent) {
  6395. this._textContent.addSelfToZr(zr);
  6396. }
  6397. if (this._textGuide) {
  6398. this._textGuide.addSelfToZr(zr);
  6399. }
  6400. };
  6401. Element.prototype.removeSelfFromZr = function (zr) {
  6402. if (!this.__zr) {
  6403. return;
  6404. }
  6405. this.__zr = null;
  6406. var animators = this.animators;
  6407. if (animators) {
  6408. for (var i = 0; i < animators.length; i++) {
  6409. zr.animation.removeAnimator(animators[i]);
  6410. }
  6411. }
  6412. if (this._clipPath) {
  6413. this._clipPath.removeSelfFromZr(zr);
  6414. }
  6415. if (this._textContent) {
  6416. this._textContent.removeSelfFromZr(zr);
  6417. }
  6418. if (this._textGuide) {
  6419. this._textGuide.removeSelfFromZr(zr);
  6420. }
  6421. };
  6422. Element.prototype.animate = function (key, loop, allowDiscreteAnimation) {
  6423. var target = key ? this[key] : this;
  6424. {
  6425. if (!target) {
  6426. logError('Property "'
  6427. + key
  6428. + '" is not existed in element '
  6429. + this.id);
  6430. return;
  6431. }
  6432. }
  6433. var animator = new Animator(target, loop, allowDiscreteAnimation);
  6434. key && (animator.targetName = key);
  6435. this.addAnimator(animator, key);
  6436. return animator;
  6437. };
  6438. Element.prototype.addAnimator = function (animator, key) {
  6439. var zr = this.__zr;
  6440. var el = this;
  6441. animator.during(function () {
  6442. el.updateDuringAnimation(key);
  6443. }).done(function () {
  6444. var animators = el.animators;
  6445. var idx = indexOf(animators, animator);
  6446. if (idx >= 0) {
  6447. animators.splice(idx, 1);
  6448. }
  6449. });
  6450. this.animators.push(animator);
  6451. if (zr) {
  6452. zr.animation.addAnimator(animator);
  6453. }
  6454. zr && zr.wakeUp();
  6455. };
  6456. Element.prototype.updateDuringAnimation = function (key) {
  6457. this.markRedraw();
  6458. };
  6459. Element.prototype.stopAnimation = function (scope, forwardToLast) {
  6460. var animators = this.animators;
  6461. var len = animators.length;
  6462. var leftAnimators = [];
  6463. for (var i = 0; i < len; i++) {
  6464. var animator = animators[i];
  6465. if (!scope || scope === animator.scope) {
  6466. animator.stop(forwardToLast);
  6467. }
  6468. else {
  6469. leftAnimators.push(animator);
  6470. }
  6471. }
  6472. this.animators = leftAnimators;
  6473. return this;
  6474. };
  6475. Element.prototype.animateTo = function (target, cfg, animationProps) {
  6476. animateTo(this, target, cfg, animationProps);
  6477. };
  6478. Element.prototype.animateFrom = function (target, cfg, animationProps) {
  6479. animateTo(this, target, cfg, animationProps, true);
  6480. };
  6481. Element.prototype._transitionState = function (stateName, target, cfg, animationProps) {
  6482. var animators = animateTo(this, target, cfg, animationProps);
  6483. for (var i = 0; i < animators.length; i++) {
  6484. animators[i].__fromStateTransition = stateName;
  6485. }
  6486. };
  6487. Element.prototype.getBoundingRect = function () {
  6488. return null;
  6489. };
  6490. Element.prototype.getPaintRect = function () {
  6491. return null;
  6492. };
  6493. Element.initDefaultProps = (function () {
  6494. var elProto = Element.prototype;
  6495. elProto.type = 'element';
  6496. elProto.name = '';
  6497. elProto.ignore =
  6498. elProto.silent =
  6499. elProto.isGroup =
  6500. elProto.draggable =
  6501. elProto.dragging =
  6502. elProto.ignoreClip =
  6503. elProto.__inHover = false;
  6504. elProto.__dirty = REDRAW_BIT;
  6505. var logs = {};
  6506. function logDeprecatedError(key, xKey, yKey) {
  6507. if (!logs[key + xKey + yKey]) {
  6508. console.warn("DEPRECATED: '" + key + "' has been deprecated. use '" + xKey + "', '" + yKey + "' instead");
  6509. logs[key + xKey + yKey] = true;
  6510. }
  6511. }
  6512. function createLegacyProperty(key, privateKey, xKey, yKey) {
  6513. Object.defineProperty(elProto, key, {
  6514. get: function () {
  6515. {
  6516. logDeprecatedError(key, xKey, yKey);
  6517. }
  6518. if (!this[privateKey]) {
  6519. var pos = this[privateKey] = [];
  6520. enhanceArray(this, pos);
  6521. }
  6522. return this[privateKey];
  6523. },
  6524. set: function (pos) {
  6525. {
  6526. logDeprecatedError(key, xKey, yKey);
  6527. }
  6528. this[xKey] = pos[0];
  6529. this[yKey] = pos[1];
  6530. this[privateKey] = pos;
  6531. enhanceArray(this, pos);
  6532. }
  6533. });
  6534. function enhanceArray(self, pos) {
  6535. Object.defineProperty(pos, 0, {
  6536. get: function () {
  6537. return self[xKey];
  6538. },
  6539. set: function (val) {
  6540. self[xKey] = val;
  6541. }
  6542. });
  6543. Object.defineProperty(pos, 1, {
  6544. get: function () {
  6545. return self[yKey];
  6546. },
  6547. set: function (val) {
  6548. self[yKey] = val;
  6549. }
  6550. });
  6551. }
  6552. }
  6553. if (Object.defineProperty) {
  6554. createLegacyProperty('position', '_legacyPos', 'x', 'y');
  6555. createLegacyProperty('scale', '_legacyScale', 'scaleX', 'scaleY');
  6556. createLegacyProperty('origin', '_legacyOrigin', 'originX', 'originY');
  6557. }
  6558. })();
  6559. return Element;
  6560. }());
  6561. mixin(Element, Eventful);
  6562. mixin(Element, Transformable);
  6563. function animateTo(animatable, target, cfg, animationProps, reverse) {
  6564. cfg = cfg || {};
  6565. var animators = [];
  6566. animateToShallow(animatable, '', animatable, target, cfg, animationProps, animators, reverse);
  6567. var finishCount = animators.length;
  6568. var doneHappened = false;
  6569. var cfgDone = cfg.done;
  6570. var cfgAborted = cfg.aborted;
  6571. var doneCb = function () {
  6572. doneHappened = true;
  6573. finishCount--;
  6574. if (finishCount <= 0) {
  6575. doneHappened
  6576. ? (cfgDone && cfgDone())
  6577. : (cfgAborted && cfgAborted());
  6578. }
  6579. };
  6580. var abortedCb = function () {
  6581. finishCount--;
  6582. if (finishCount <= 0) {
  6583. doneHappened
  6584. ? (cfgDone && cfgDone())
  6585. : (cfgAborted && cfgAborted());
  6586. }
  6587. };
  6588. if (!finishCount) {
  6589. cfgDone && cfgDone();
  6590. }
  6591. if (animators.length > 0 && cfg.during) {
  6592. animators[0].during(function (target, percent) {
  6593. cfg.during(percent);
  6594. });
  6595. }
  6596. for (var i = 0; i < animators.length; i++) {
  6597. var animator = animators[i];
  6598. if (doneCb) {
  6599. animator.done(doneCb);
  6600. }
  6601. if (abortedCb) {
  6602. animator.aborted(abortedCb);
  6603. }
  6604. if (cfg.force) {
  6605. animator.duration(cfg.duration);
  6606. }
  6607. animator.start(cfg.easing);
  6608. }
  6609. return animators;
  6610. }
  6611. function copyArrShallow(source, target, len) {
  6612. for (var i = 0; i < len; i++) {
  6613. source[i] = target[i];
  6614. }
  6615. }
  6616. function is2DArray(value) {
  6617. return isArrayLike(value[0]);
  6618. }
  6619. function copyValue(target, source, key) {
  6620. if (isArrayLike(source[key])) {
  6621. if (!isArrayLike(target[key])) {
  6622. target[key] = [];
  6623. }
  6624. if (isTypedArray(source[key])) {
  6625. var len = source[key].length;
  6626. if (target[key].length !== len) {
  6627. target[key] = new (source[key].constructor)(len);
  6628. copyArrShallow(target[key], source[key], len);
  6629. }
  6630. }
  6631. else {
  6632. var sourceArr = source[key];
  6633. var targetArr = target[key];
  6634. var len0 = sourceArr.length;
  6635. if (is2DArray(sourceArr)) {
  6636. var len1 = sourceArr[0].length;
  6637. for (var i = 0; i < len0; i++) {
  6638. if (!targetArr[i]) {
  6639. targetArr[i] = Array.prototype.slice.call(sourceArr[i]);
  6640. }
  6641. else {
  6642. copyArrShallow(targetArr[i], sourceArr[i], len1);
  6643. }
  6644. }
  6645. }
  6646. else {
  6647. copyArrShallow(targetArr, sourceArr, len0);
  6648. }
  6649. targetArr.length = sourceArr.length;
  6650. }
  6651. }
  6652. else {
  6653. target[key] = source[key];
  6654. }
  6655. }
  6656. function isValueSame(val1, val2) {
  6657. return val1 === val2
  6658. || isArrayLike(val1) && isArrayLike(val2) && is1DArraySame(val1, val2);
  6659. }
  6660. function is1DArraySame(arr0, arr1) {
  6661. var len = arr0.length;
  6662. if (len !== arr1.length) {
  6663. return false;
  6664. }
  6665. for (var i = 0; i < len; i++) {
  6666. if (arr0[i] !== arr1[i]) {
  6667. return false;
  6668. }
  6669. }
  6670. return true;
  6671. }
  6672. function animateToShallow(animatable, topKey, animateObj, target, cfg, animationProps, animators, reverse) {
  6673. var targetKeys = keys(target);
  6674. var duration = cfg.duration;
  6675. var delay = cfg.delay;
  6676. var additive = cfg.additive;
  6677. var setToFinal = cfg.setToFinal;
  6678. var animateAll = !isObject(animationProps);
  6679. var existsAnimators = animatable.animators;
  6680. var animationKeys = [];
  6681. for (var k = 0; k < targetKeys.length; k++) {
  6682. var innerKey = targetKeys[k];
  6683. var targetVal = target[innerKey];
  6684. if (targetVal != null && animateObj[innerKey] != null
  6685. && (animateAll || animationProps[innerKey])) {
  6686. if (isObject(targetVal)
  6687. && !isArrayLike(targetVal)
  6688. && !isGradientObject(targetVal)) {
  6689. if (topKey) {
  6690. if (!reverse) {
  6691. animateObj[innerKey] = targetVal;
  6692. animatable.updateDuringAnimation(topKey);
  6693. }
  6694. continue;
  6695. }
  6696. animateToShallow(animatable, innerKey, animateObj[innerKey], targetVal, cfg, animationProps && animationProps[innerKey], animators, reverse);
  6697. }
  6698. else {
  6699. animationKeys.push(innerKey);
  6700. }
  6701. }
  6702. else if (!reverse) {
  6703. animateObj[innerKey] = targetVal;
  6704. animatable.updateDuringAnimation(topKey);
  6705. animationKeys.push(innerKey);
  6706. }
  6707. }
  6708. var keyLen = animationKeys.length;
  6709. if (!additive && keyLen) {
  6710. for (var i = 0; i < existsAnimators.length; i++) {
  6711. var animator = existsAnimators[i];
  6712. if (animator.targetName === topKey) {
  6713. var allAborted = animator.stopTracks(animationKeys);
  6714. if (allAborted) {
  6715. var idx = indexOf(existsAnimators, animator);
  6716. existsAnimators.splice(idx, 1);
  6717. }
  6718. }
  6719. }
  6720. }
  6721. if (!cfg.force) {
  6722. animationKeys = filter(animationKeys, function (key) { return !isValueSame(target[key], animateObj[key]); });
  6723. keyLen = animationKeys.length;
  6724. }
  6725. if (keyLen > 0
  6726. || (cfg.force && !animators.length)) {
  6727. var revertedSource = void 0;
  6728. var reversedTarget = void 0;
  6729. var sourceClone = void 0;
  6730. if (reverse) {
  6731. reversedTarget = {};
  6732. if (setToFinal) {
  6733. revertedSource = {};
  6734. }
  6735. for (var i = 0; i < keyLen; i++) {
  6736. var innerKey = animationKeys[i];
  6737. reversedTarget[innerKey] = animateObj[innerKey];
  6738. if (setToFinal) {
  6739. revertedSource[innerKey] = target[innerKey];
  6740. }
  6741. else {
  6742. animateObj[innerKey] = target[innerKey];
  6743. }
  6744. }
  6745. }
  6746. else if (setToFinal) {
  6747. sourceClone = {};
  6748. for (var i = 0; i < keyLen; i++) {
  6749. var innerKey = animationKeys[i];
  6750. sourceClone[innerKey] = cloneValue(animateObj[innerKey]);
  6751. copyValue(animateObj, target, innerKey);
  6752. }
  6753. }
  6754. var animator = new Animator(animateObj, false, false, additive ? filter(existsAnimators, function (animator) { return animator.targetName === topKey; }) : null);
  6755. animator.targetName = topKey;
  6756. if (cfg.scope) {
  6757. animator.scope = cfg.scope;
  6758. }
  6759. if (setToFinal && revertedSource) {
  6760. animator.whenWithKeys(0, revertedSource, animationKeys);
  6761. }
  6762. if (sourceClone) {
  6763. animator.whenWithKeys(0, sourceClone, animationKeys);
  6764. }
  6765. animator.whenWithKeys(duration == null ? 500 : duration, reverse ? reversedTarget : target, animationKeys).delay(delay || 0);
  6766. animatable.addAnimator(animator, topKey);
  6767. animators.push(animator);
  6768. }
  6769. }
  6770. var Group = (function (_super) {
  6771. __extends(Group, _super);
  6772. function Group(opts) {
  6773. var _this = _super.call(this) || this;
  6774. _this.isGroup = true;
  6775. _this._children = [];
  6776. _this.attr(opts);
  6777. return _this;
  6778. }
  6779. Group.prototype.childrenRef = function () {
  6780. return this._children;
  6781. };
  6782. Group.prototype.children = function () {
  6783. return this._children.slice();
  6784. };
  6785. Group.prototype.childAt = function (idx) {
  6786. return this._children[idx];
  6787. };
  6788. Group.prototype.childOfName = function (name) {
  6789. var children = this._children;
  6790. for (var i = 0; i < children.length; i++) {
  6791. if (children[i].name === name) {
  6792. return children[i];
  6793. }
  6794. }
  6795. };
  6796. Group.prototype.childCount = function () {
  6797. return this._children.length;
  6798. };
  6799. Group.prototype.add = function (child) {
  6800. if (child) {
  6801. if (child !== this && child.parent !== this) {
  6802. this._children.push(child);
  6803. this._doAdd(child);
  6804. }
  6805. {
  6806. if (child.__hostTarget) {
  6807. throw 'This elemenet has been used as an attachment';
  6808. }
  6809. }
  6810. }
  6811. return this;
  6812. };
  6813. Group.prototype.addBefore = function (child, nextSibling) {
  6814. if (child && child !== this && child.parent !== this
  6815. && nextSibling && nextSibling.parent === this) {
  6816. var children = this._children;
  6817. var idx = children.indexOf(nextSibling);
  6818. if (idx >= 0) {
  6819. children.splice(idx, 0, child);
  6820. this._doAdd(child);
  6821. }
  6822. }
  6823. return this;
  6824. };
  6825. Group.prototype.replace = function (oldChild, newChild) {
  6826. var idx = indexOf(this._children, oldChild);
  6827. if (idx >= 0) {
  6828. this.replaceAt(newChild, idx);
  6829. }
  6830. return this;
  6831. };
  6832. Group.prototype.replaceAt = function (child, index) {
  6833. var children = this._children;
  6834. var old = children[index];
  6835. if (child && child !== this && child.parent !== this && child !== old) {
  6836. children[index] = child;
  6837. old.parent = null;
  6838. var zr = this.__zr;
  6839. if (zr) {
  6840. old.removeSelfFromZr(zr);
  6841. }
  6842. this._doAdd(child);
  6843. }
  6844. return this;
  6845. };
  6846. Group.prototype._doAdd = function (child) {
  6847. if (child.parent) {
  6848. child.parent.remove(child);
  6849. }
  6850. child.parent = this;
  6851. var zr = this.__zr;
  6852. if (zr && zr !== child.__zr) {
  6853. child.addSelfToZr(zr);
  6854. }
  6855. zr && zr.refresh();
  6856. };
  6857. Group.prototype.remove = function (child) {
  6858. var zr = this.__zr;
  6859. var children = this._children;
  6860. var idx = indexOf(children, child);
  6861. if (idx < 0) {
  6862. return this;
  6863. }
  6864. children.splice(idx, 1);
  6865. child.parent = null;
  6866. if (zr) {
  6867. child.removeSelfFromZr(zr);
  6868. }
  6869. zr && zr.refresh();
  6870. return this;
  6871. };
  6872. Group.prototype.removeAll = function () {
  6873. var children = this._children;
  6874. var zr = this.__zr;
  6875. for (var i = 0; i < children.length; i++) {
  6876. var child = children[i];
  6877. if (zr) {
  6878. child.removeSelfFromZr(zr);
  6879. }
  6880. child.parent = null;
  6881. }
  6882. children.length = 0;
  6883. return this;
  6884. };
  6885. Group.prototype.eachChild = function (cb, context) {
  6886. var children = this._children;
  6887. for (var i = 0; i < children.length; i++) {
  6888. var child = children[i];
  6889. cb.call(context, child, i);
  6890. }
  6891. return this;
  6892. };
  6893. Group.prototype.traverse = function (cb, context) {
  6894. for (var i = 0; i < this._children.length; i++) {
  6895. var child = this._children[i];
  6896. var stopped = cb.call(context, child);
  6897. if (child.isGroup && !stopped) {
  6898. child.traverse(cb, context);
  6899. }
  6900. }
  6901. return this;
  6902. };
  6903. Group.prototype.addSelfToZr = function (zr) {
  6904. _super.prototype.addSelfToZr.call(this, zr);
  6905. for (var i = 0; i < this._children.length; i++) {
  6906. var child = this._children[i];
  6907. child.addSelfToZr(zr);
  6908. }
  6909. };
  6910. Group.prototype.removeSelfFromZr = function (zr) {
  6911. _super.prototype.removeSelfFromZr.call(this, zr);
  6912. for (var i = 0; i < this._children.length; i++) {
  6913. var child = this._children[i];
  6914. child.removeSelfFromZr(zr);
  6915. }
  6916. };
  6917. Group.prototype.getBoundingRect = function (includeChildren) {
  6918. var tmpRect = new BoundingRect(0, 0, 0, 0);
  6919. var children = includeChildren || this._children;
  6920. var tmpMat = [];
  6921. var rect = null;
  6922. for (var i = 0; i < children.length; i++) {
  6923. var child = children[i];
  6924. if (child.ignore || child.invisible) {
  6925. continue;
  6926. }
  6927. var childRect = child.getBoundingRect();
  6928. var transform = child.getLocalTransform(tmpMat);
  6929. if (transform) {
  6930. BoundingRect.applyTransform(tmpRect, childRect, transform);
  6931. rect = rect || tmpRect.clone();
  6932. rect.union(tmpRect);
  6933. }
  6934. else {
  6935. rect = rect || childRect.clone();
  6936. rect.union(childRect);
  6937. }
  6938. }
  6939. return rect || tmpRect;
  6940. };
  6941. return Group;
  6942. }(Element));
  6943. Group.prototype.type = 'group';
  6944. /*!
  6945. * ZRender, a high performance 2d drawing library.
  6946. *
  6947. * Copyright (c) 2013, Baidu Inc.
  6948. * All rights reserved.
  6949. *
  6950. * LICENSE
  6951. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  6952. */
  6953. var painterCtors = {};
  6954. var instances = {};
  6955. function delInstance(id) {
  6956. delete instances[id];
  6957. }
  6958. function isDarkMode(backgroundColor) {
  6959. if (!backgroundColor) {
  6960. return false;
  6961. }
  6962. if (typeof backgroundColor === 'string') {
  6963. return lum(backgroundColor, 1) < DARK_MODE_THRESHOLD;
  6964. }
  6965. else if (backgroundColor.colorStops) {
  6966. var colorStops = backgroundColor.colorStops;
  6967. var totalLum = 0;
  6968. var len = colorStops.length;
  6969. for (var i = 0; i < len; i++) {
  6970. totalLum += lum(colorStops[i].color, 1);
  6971. }
  6972. totalLum /= len;
  6973. return totalLum < DARK_MODE_THRESHOLD;
  6974. }
  6975. return false;
  6976. }
  6977. var ZRender = (function () {
  6978. function ZRender(id, dom, opts) {
  6979. var _this = this;
  6980. this._sleepAfterStill = 10;
  6981. this._stillFrameAccum = 0;
  6982. this._needsRefresh = true;
  6983. this._needsRefreshHover = true;
  6984. this._darkMode = false;
  6985. opts = opts || {};
  6986. this.dom = dom;
  6987. this.id = id;
  6988. var storage = new Storage();
  6989. var rendererType = opts.renderer || 'canvas';
  6990. if (!painterCtors[rendererType]) {
  6991. rendererType = keys(painterCtors)[0];
  6992. }
  6993. {
  6994. if (!painterCtors[rendererType]) {
  6995. throw new Error("Renderer '" + rendererType + "' is not imported. Please import it first.");
  6996. }
  6997. }
  6998. opts.useDirtyRect = opts.useDirtyRect == null
  6999. ? false
  7000. : opts.useDirtyRect;
  7001. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  7002. var ssrMode = opts.ssr || painter.ssrOnly;
  7003. this.storage = storage;
  7004. this.painter = painter;
  7005. var handerProxy = (!env.node && !env.worker && !ssrMode)
  7006. ? new HandlerDomProxy(painter.getViewportRoot(), painter.root)
  7007. : null;
  7008. var useCoarsePointer = opts.useCoarsePointer;
  7009. var usePointerSize = (useCoarsePointer == null || useCoarsePointer === 'auto')
  7010. ? env.touchEventsSupported
  7011. : !!useCoarsePointer;
  7012. var defaultPointerSize = 44;
  7013. var pointerSize;
  7014. if (usePointerSize) {
  7015. pointerSize = retrieve2(opts.pointerSize, defaultPointerSize);
  7016. }
  7017. this.handler = new Handler(storage, painter, handerProxy, painter.root, pointerSize);
  7018. this.animation = new Animation({
  7019. stage: {
  7020. update: ssrMode ? null : function () { return _this._flush(true); }
  7021. }
  7022. });
  7023. if (!ssrMode) {
  7024. this.animation.start();
  7025. }
  7026. }
  7027. ZRender.prototype.add = function (el) {
  7028. if (!el) {
  7029. return;
  7030. }
  7031. this.storage.addRoot(el);
  7032. el.addSelfToZr(this);
  7033. this.refresh();
  7034. };
  7035. ZRender.prototype.remove = function (el) {
  7036. if (!el) {
  7037. return;
  7038. }
  7039. this.storage.delRoot(el);
  7040. el.removeSelfFromZr(this);
  7041. this.refresh();
  7042. };
  7043. ZRender.prototype.configLayer = function (zLevel, config) {
  7044. if (this.painter.configLayer) {
  7045. this.painter.configLayer(zLevel, config);
  7046. }
  7047. this.refresh();
  7048. };
  7049. ZRender.prototype.setBackgroundColor = function (backgroundColor) {
  7050. if (this.painter.setBackgroundColor) {
  7051. this.painter.setBackgroundColor(backgroundColor);
  7052. }
  7053. this.refresh();
  7054. this._backgroundColor = backgroundColor;
  7055. this._darkMode = isDarkMode(backgroundColor);
  7056. };
  7057. ZRender.prototype.getBackgroundColor = function () {
  7058. return this._backgroundColor;
  7059. };
  7060. ZRender.prototype.setDarkMode = function (darkMode) {
  7061. this._darkMode = darkMode;
  7062. };
  7063. ZRender.prototype.isDarkMode = function () {
  7064. return this._darkMode;
  7065. };
  7066. ZRender.prototype.refreshImmediately = function (fromInside) {
  7067. if (!fromInside) {
  7068. this.animation.update(true);
  7069. }
  7070. this._needsRefresh = false;
  7071. this.painter.refresh();
  7072. this._needsRefresh = false;
  7073. };
  7074. ZRender.prototype.refresh = function () {
  7075. this._needsRefresh = true;
  7076. this.animation.start();
  7077. };
  7078. ZRender.prototype.flush = function () {
  7079. this._flush(false);
  7080. };
  7081. ZRender.prototype._flush = function (fromInside) {
  7082. var triggerRendered;
  7083. var start = getTime();
  7084. if (this._needsRefresh) {
  7085. triggerRendered = true;
  7086. this.refreshImmediately(fromInside);
  7087. }
  7088. if (this._needsRefreshHover) {
  7089. triggerRendered = true;
  7090. this.refreshHoverImmediately();
  7091. }
  7092. var end = getTime();
  7093. if (triggerRendered) {
  7094. this._stillFrameAccum = 0;
  7095. this.trigger('rendered', {
  7096. elapsedTime: end - start
  7097. });
  7098. }
  7099. else if (this._sleepAfterStill > 0) {
  7100. this._stillFrameAccum++;
  7101. if (this._stillFrameAccum > this._sleepAfterStill) {
  7102. this.animation.stop();
  7103. }
  7104. }
  7105. };
  7106. ZRender.prototype.setSleepAfterStill = function (stillFramesCount) {
  7107. this._sleepAfterStill = stillFramesCount;
  7108. };
  7109. ZRender.prototype.wakeUp = function () {
  7110. this.animation.start();
  7111. this._stillFrameAccum = 0;
  7112. };
  7113. ZRender.prototype.refreshHover = function () {
  7114. this._needsRefreshHover = true;
  7115. };
  7116. ZRender.prototype.refreshHoverImmediately = function () {
  7117. this._needsRefreshHover = false;
  7118. if (this.painter.refreshHover && this.painter.getType() === 'canvas') {
  7119. this.painter.refreshHover();
  7120. }
  7121. };
  7122. ZRender.prototype.resize = function (opts) {
  7123. opts = opts || {};
  7124. this.painter.resize(opts.width, opts.height);
  7125. this.handler.resize();
  7126. };
  7127. ZRender.prototype.clearAnimation = function () {
  7128. this.animation.clear();
  7129. };
  7130. ZRender.prototype.getWidth = function () {
  7131. return this.painter.getWidth();
  7132. };
  7133. ZRender.prototype.getHeight = function () {
  7134. return this.painter.getHeight();
  7135. };
  7136. ZRender.prototype.setCursorStyle = function (cursorStyle) {
  7137. this.handler.setCursorStyle(cursorStyle);
  7138. };
  7139. ZRender.prototype.findHover = function (x, y) {
  7140. return this.handler.findHover(x, y);
  7141. };
  7142. ZRender.prototype.on = function (eventName, eventHandler, context) {
  7143. this.handler.on(eventName, eventHandler, context);
  7144. return this;
  7145. };
  7146. ZRender.prototype.off = function (eventName, eventHandler) {
  7147. this.handler.off(eventName, eventHandler);
  7148. };
  7149. ZRender.prototype.trigger = function (eventName, event) {
  7150. this.handler.trigger(eventName, event);
  7151. };
  7152. ZRender.prototype.clear = function () {
  7153. var roots = this.storage.getRoots();
  7154. for (var i = 0; i < roots.length; i++) {
  7155. if (roots[i] instanceof Group) {
  7156. roots[i].removeSelfFromZr(this);
  7157. }
  7158. }
  7159. this.storage.delAllRoots();
  7160. this.painter.clear();
  7161. };
  7162. ZRender.prototype.dispose = function () {
  7163. this.animation.stop();
  7164. this.clear();
  7165. this.storage.dispose();
  7166. this.painter.dispose();
  7167. this.handler.dispose();
  7168. this.animation =
  7169. this.storage =
  7170. this.painter =
  7171. this.handler = null;
  7172. delInstance(this.id);
  7173. };
  7174. return ZRender;
  7175. }());
  7176. function init(dom, opts) {
  7177. var zr = new ZRender(guid(), dom, opts);
  7178. instances[zr.id] = zr;
  7179. return zr;
  7180. }
  7181. function dispose(zr) {
  7182. zr.dispose();
  7183. }
  7184. function disposeAll() {
  7185. for (var key in instances) {
  7186. if (instances.hasOwnProperty(key)) {
  7187. instances[key].dispose();
  7188. }
  7189. }
  7190. instances = {};
  7191. }
  7192. function getInstance(id) {
  7193. return instances[id];
  7194. }
  7195. function registerPainter(name, Ctor) {
  7196. painterCtors[name] = Ctor;
  7197. }
  7198. var version = '5.4.3';
  7199. var STYLE_MAGIC_KEY = '__zr_style_' + Math.round((Math.random() * 10));
  7200. var DEFAULT_COMMON_STYLE = {
  7201. shadowBlur: 0,
  7202. shadowOffsetX: 0,
  7203. shadowOffsetY: 0,
  7204. shadowColor: '#000',
  7205. opacity: 1,
  7206. blend: 'source-over'
  7207. };
  7208. var DEFAULT_COMMON_ANIMATION_PROPS = {
  7209. style: {
  7210. shadowBlur: true,
  7211. shadowOffsetX: true,
  7212. shadowOffsetY: true,
  7213. shadowColor: true,
  7214. opacity: true
  7215. }
  7216. };
  7217. DEFAULT_COMMON_STYLE[STYLE_MAGIC_KEY] = true;
  7218. var PRIMARY_STATES_KEYS$1 = ['z', 'z2', 'invisible'];
  7219. var PRIMARY_STATES_KEYS_IN_HOVER_LAYER = ['invisible'];
  7220. var Displayable = (function (_super) {
  7221. __extends(Displayable, _super);
  7222. function Displayable(props) {
  7223. return _super.call(this, props) || this;
  7224. }
  7225. Displayable.prototype._init = function (props) {
  7226. var keysArr = keys(props);
  7227. for (var i = 0; i < keysArr.length; i++) {
  7228. var key = keysArr[i];
  7229. if (key === 'style') {
  7230. this.useStyle(props[key]);
  7231. }
  7232. else {
  7233. _super.prototype.attrKV.call(this, key, props[key]);
  7234. }
  7235. }
  7236. if (!this.style) {
  7237. this.useStyle({});
  7238. }
  7239. };
  7240. Displayable.prototype.beforeBrush = function () { };
  7241. Displayable.prototype.afterBrush = function () { };
  7242. Displayable.prototype.innerBeforeBrush = function () { };
  7243. Displayable.prototype.innerAfterBrush = function () { };
  7244. Displayable.prototype.shouldBePainted = function (viewWidth, viewHeight, considerClipPath, considerAncestors) {
  7245. var m = this.transform;
  7246. if (this.ignore
  7247. || this.invisible
  7248. || this.style.opacity === 0
  7249. || (this.culling
  7250. && isDisplayableCulled(this, viewWidth, viewHeight))
  7251. || (m && !m[0] && !m[3])) {
  7252. return false;
  7253. }
  7254. if (considerClipPath && this.__clipPaths) {
  7255. for (var i = 0; i < this.__clipPaths.length; ++i) {
  7256. if (this.__clipPaths[i].isZeroArea()) {
  7257. return false;
  7258. }
  7259. }
  7260. }
  7261. if (considerAncestors && this.parent) {
  7262. var parent_1 = this.parent;
  7263. while (parent_1) {
  7264. if (parent_1.ignore) {
  7265. return false;
  7266. }
  7267. parent_1 = parent_1.parent;
  7268. }
  7269. }
  7270. return true;
  7271. };
  7272. Displayable.prototype.contain = function (x, y) {
  7273. return this.rectContain(x, y);
  7274. };
  7275. Displayable.prototype.traverse = function (cb, context) {
  7276. cb.call(context, this);
  7277. };
  7278. Displayable.prototype.rectContain = function (x, y) {
  7279. var coord = this.transformCoordToLocal(x, y);
  7280. var rect = this.getBoundingRect();
  7281. return rect.contain(coord[0], coord[1]);
  7282. };
  7283. Displayable.prototype.getPaintRect = function () {
  7284. var rect = this._paintRect;
  7285. if (!this._paintRect || this.__dirty) {
  7286. var transform = this.transform;
  7287. var elRect = this.getBoundingRect();
  7288. var style = this.style;
  7289. var shadowSize = style.shadowBlur || 0;
  7290. var shadowOffsetX = style.shadowOffsetX || 0;
  7291. var shadowOffsetY = style.shadowOffsetY || 0;
  7292. rect = this._paintRect || (this._paintRect = new BoundingRect(0, 0, 0, 0));
  7293. if (transform) {
  7294. BoundingRect.applyTransform(rect, elRect, transform);
  7295. }
  7296. else {
  7297. rect.copy(elRect);
  7298. }
  7299. if (shadowSize || shadowOffsetX || shadowOffsetY) {
  7300. rect.width += shadowSize * 2 + Math.abs(shadowOffsetX);
  7301. rect.height += shadowSize * 2 + Math.abs(shadowOffsetY);
  7302. rect.x = Math.min(rect.x, rect.x + shadowOffsetX - shadowSize);
  7303. rect.y = Math.min(rect.y, rect.y + shadowOffsetY - shadowSize);
  7304. }
  7305. var tolerance = this.dirtyRectTolerance;
  7306. if (!rect.isZero()) {
  7307. rect.x = Math.floor(rect.x - tolerance);
  7308. rect.y = Math.floor(rect.y - tolerance);
  7309. rect.width = Math.ceil(rect.width + 1 + tolerance * 2);
  7310. rect.height = Math.ceil(rect.height + 1 + tolerance * 2);
  7311. }
  7312. }
  7313. return rect;
  7314. };
  7315. Displayable.prototype.setPrevPaintRect = function (paintRect) {
  7316. if (paintRect) {
  7317. this._prevPaintRect = this._prevPaintRect || new BoundingRect(0, 0, 0, 0);
  7318. this._prevPaintRect.copy(paintRect);
  7319. }
  7320. else {
  7321. this._prevPaintRect = null;
  7322. }
  7323. };
  7324. Displayable.prototype.getPrevPaintRect = function () {
  7325. return this._prevPaintRect;
  7326. };
  7327. Displayable.prototype.animateStyle = function (loop) {
  7328. return this.animate('style', loop);
  7329. };
  7330. Displayable.prototype.updateDuringAnimation = function (targetKey) {
  7331. if (targetKey === 'style') {
  7332. this.dirtyStyle();
  7333. }
  7334. else {
  7335. this.markRedraw();
  7336. }
  7337. };
  7338. Displayable.prototype.attrKV = function (key, value) {
  7339. if (key !== 'style') {
  7340. _super.prototype.attrKV.call(this, key, value);
  7341. }
  7342. else {
  7343. if (!this.style) {
  7344. this.useStyle(value);
  7345. }
  7346. else {
  7347. this.setStyle(value);
  7348. }
  7349. }
  7350. };
  7351. Displayable.prototype.setStyle = function (keyOrObj, value) {
  7352. if (typeof keyOrObj === 'string') {
  7353. this.style[keyOrObj] = value;
  7354. }
  7355. else {
  7356. extend(this.style, keyOrObj);
  7357. }
  7358. this.dirtyStyle();
  7359. return this;
  7360. };
  7361. Displayable.prototype.dirtyStyle = function (notRedraw) {
  7362. if (!notRedraw) {
  7363. this.markRedraw();
  7364. }
  7365. this.__dirty |= STYLE_CHANGED_BIT;
  7366. if (this._rect) {
  7367. this._rect = null;
  7368. }
  7369. };
  7370. Displayable.prototype.dirty = function () {
  7371. this.dirtyStyle();
  7372. };
  7373. Displayable.prototype.styleChanged = function () {
  7374. return !!(this.__dirty & STYLE_CHANGED_BIT);
  7375. };
  7376. Displayable.prototype.styleUpdated = function () {
  7377. this.__dirty &= ~STYLE_CHANGED_BIT;
  7378. };
  7379. Displayable.prototype.createStyle = function (obj) {
  7380. return createObject(DEFAULT_COMMON_STYLE, obj);
  7381. };
  7382. Displayable.prototype.useStyle = function (obj) {
  7383. if (!obj[STYLE_MAGIC_KEY]) {
  7384. obj = this.createStyle(obj);
  7385. }
  7386. if (this.__inHover) {
  7387. this.__hoverStyle = obj;
  7388. }
  7389. else {
  7390. this.style = obj;
  7391. }
  7392. this.dirtyStyle();
  7393. };
  7394. Displayable.prototype.isStyleObject = function (obj) {
  7395. return obj[STYLE_MAGIC_KEY];
  7396. };
  7397. Displayable.prototype._innerSaveToNormal = function (toState) {
  7398. _super.prototype._innerSaveToNormal.call(this, toState);
  7399. var normalState = this._normalState;
  7400. if (toState.style && !normalState.style) {
  7401. normalState.style = this._mergeStyle(this.createStyle(), this.style);
  7402. }
  7403. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS$1);
  7404. };
  7405. Displayable.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  7406. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  7407. var needsRestoreToNormal = !(state && keepCurrentStates);
  7408. var targetStyle;
  7409. if (state && state.style) {
  7410. if (transition) {
  7411. if (keepCurrentStates) {
  7412. targetStyle = state.style;
  7413. }
  7414. else {
  7415. targetStyle = this._mergeStyle(this.createStyle(), normalState.style);
  7416. this._mergeStyle(targetStyle, state.style);
  7417. }
  7418. }
  7419. else {
  7420. targetStyle = this._mergeStyle(this.createStyle(), keepCurrentStates ? this.style : normalState.style);
  7421. this._mergeStyle(targetStyle, state.style);
  7422. }
  7423. }
  7424. else if (needsRestoreToNormal) {
  7425. targetStyle = normalState.style;
  7426. }
  7427. if (targetStyle) {
  7428. if (transition) {
  7429. var sourceStyle = this.style;
  7430. this.style = this.createStyle(needsRestoreToNormal ? {} : sourceStyle);
  7431. if (needsRestoreToNormal) {
  7432. var changedKeys = keys(sourceStyle);
  7433. for (var i = 0; i < changedKeys.length; i++) {
  7434. var key = changedKeys[i];
  7435. if (key in targetStyle) {
  7436. targetStyle[key] = targetStyle[key];
  7437. this.style[key] = sourceStyle[key];
  7438. }
  7439. }
  7440. }
  7441. var targetKeys = keys(targetStyle);
  7442. for (var i = 0; i < targetKeys.length; i++) {
  7443. var key = targetKeys[i];
  7444. this.style[key] = this.style[key];
  7445. }
  7446. this._transitionState(stateName, {
  7447. style: targetStyle
  7448. }, animationCfg, this.getAnimationStyleProps());
  7449. }
  7450. else {
  7451. this.useStyle(targetStyle);
  7452. }
  7453. }
  7454. var statesKeys = this.__inHover ? PRIMARY_STATES_KEYS_IN_HOVER_LAYER : PRIMARY_STATES_KEYS$1;
  7455. for (var i = 0; i < statesKeys.length; i++) {
  7456. var key = statesKeys[i];
  7457. if (state && state[key] != null) {
  7458. this[key] = state[key];
  7459. }
  7460. else if (needsRestoreToNormal) {
  7461. if (normalState[key] != null) {
  7462. this[key] = normalState[key];
  7463. }
  7464. }
  7465. }
  7466. };
  7467. Displayable.prototype._mergeStates = function (states) {
  7468. var mergedState = _super.prototype._mergeStates.call(this, states);
  7469. var mergedStyle;
  7470. for (var i = 0; i < states.length; i++) {
  7471. var state = states[i];
  7472. if (state.style) {
  7473. mergedStyle = mergedStyle || {};
  7474. this._mergeStyle(mergedStyle, state.style);
  7475. }
  7476. }
  7477. if (mergedStyle) {
  7478. mergedState.style = mergedStyle;
  7479. }
  7480. return mergedState;
  7481. };
  7482. Displayable.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  7483. extend(targetStyle, sourceStyle);
  7484. return targetStyle;
  7485. };
  7486. Displayable.prototype.getAnimationStyleProps = function () {
  7487. return DEFAULT_COMMON_ANIMATION_PROPS;
  7488. };
  7489. Displayable.initDefaultProps = (function () {
  7490. var dispProto = Displayable.prototype;
  7491. dispProto.type = 'displayable';
  7492. dispProto.invisible = false;
  7493. dispProto.z = 0;
  7494. dispProto.z2 = 0;
  7495. dispProto.zlevel = 0;
  7496. dispProto.culling = false;
  7497. dispProto.cursor = 'pointer';
  7498. dispProto.rectHover = false;
  7499. dispProto.incremental = false;
  7500. dispProto._rect = null;
  7501. dispProto.dirtyRectTolerance = 0;
  7502. dispProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT;
  7503. })();
  7504. return Displayable;
  7505. }(Element));
  7506. var tmpRect$1 = new BoundingRect(0, 0, 0, 0);
  7507. var viewRect = new BoundingRect(0, 0, 0, 0);
  7508. function isDisplayableCulled(el, width, height) {
  7509. tmpRect$1.copy(el.getBoundingRect());
  7510. if (el.transform) {
  7511. tmpRect$1.applyTransform(el.transform);
  7512. }
  7513. viewRect.width = width;
  7514. viewRect.height = height;
  7515. return !tmpRect$1.intersect(viewRect);
  7516. }
  7517. var mathMin$1 = Math.min;
  7518. var mathMax$1 = Math.max;
  7519. var mathSin = Math.sin;
  7520. var mathCos = Math.cos;
  7521. var PI2 = Math.PI * 2;
  7522. var start = create();
  7523. var end = create();
  7524. var extremity = create();
  7525. function fromPoints(points, min, max) {
  7526. if (points.length === 0) {
  7527. return;
  7528. }
  7529. var p = points[0];
  7530. var left = p[0];
  7531. var right = p[0];
  7532. var top = p[1];
  7533. var bottom = p[1];
  7534. for (var i = 1; i < points.length; i++) {
  7535. p = points[i];
  7536. left = mathMin$1(left, p[0]);
  7537. right = mathMax$1(right, p[0]);
  7538. top = mathMin$1(top, p[1]);
  7539. bottom = mathMax$1(bottom, p[1]);
  7540. }
  7541. min[0] = left;
  7542. min[1] = top;
  7543. max[0] = right;
  7544. max[1] = bottom;
  7545. }
  7546. function fromLine(x0, y0, x1, y1, min, max) {
  7547. min[0] = mathMin$1(x0, x1);
  7548. min[1] = mathMin$1(y0, y1);
  7549. max[0] = mathMax$1(x0, x1);
  7550. max[1] = mathMax$1(y0, y1);
  7551. }
  7552. var xDim = [];
  7553. var yDim = [];
  7554. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min, max) {
  7555. var cubicExtrema$1 = cubicExtrema;
  7556. var cubicAt$1 = cubicAt;
  7557. var n = cubicExtrema$1(x0, x1, x2, x3, xDim);
  7558. min[0] = Infinity;
  7559. min[1] = Infinity;
  7560. max[0] = -Infinity;
  7561. max[1] = -Infinity;
  7562. for (var i = 0; i < n; i++) {
  7563. var x = cubicAt$1(x0, x1, x2, x3, xDim[i]);
  7564. min[0] = mathMin$1(x, min[0]);
  7565. max[0] = mathMax$1(x, max[0]);
  7566. }
  7567. n = cubicExtrema$1(y0, y1, y2, y3, yDim);
  7568. for (var i = 0; i < n; i++) {
  7569. var y = cubicAt$1(y0, y1, y2, y3, yDim[i]);
  7570. min[1] = mathMin$1(y, min[1]);
  7571. max[1] = mathMax$1(y, max[1]);
  7572. }
  7573. min[0] = mathMin$1(x0, min[0]);
  7574. max[0] = mathMax$1(x0, max[0]);
  7575. min[0] = mathMin$1(x3, min[0]);
  7576. max[0] = mathMax$1(x3, max[0]);
  7577. min[1] = mathMin$1(y0, min[1]);
  7578. max[1] = mathMax$1(y0, max[1]);
  7579. min[1] = mathMin$1(y3, min[1]);
  7580. max[1] = mathMax$1(y3, max[1]);
  7581. }
  7582. function fromQuadratic(x0, y0, x1, y1, x2, y2, min, max) {
  7583. var quadraticExtremum$1 = quadraticExtremum;
  7584. var quadraticAt$1 = quadraticAt;
  7585. var tx = mathMax$1(mathMin$1(quadraticExtremum$1(x0, x1, x2), 1), 0);
  7586. var ty = mathMax$1(mathMin$1(quadraticExtremum$1(y0, y1, y2), 1), 0);
  7587. var x = quadraticAt$1(x0, x1, x2, tx);
  7588. var y = quadraticAt$1(y0, y1, y2, ty);
  7589. min[0] = mathMin$1(x0, x2, x);
  7590. min[1] = mathMin$1(y0, y2, y);
  7591. max[0] = mathMax$1(x0, x2, x);
  7592. max[1] = mathMax$1(y0, y2, y);
  7593. }
  7594. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min$1, max$1) {
  7595. var vec2Min = min;
  7596. var vec2Max = max;
  7597. var diff = Math.abs(startAngle - endAngle);
  7598. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  7599. min$1[0] = x - rx;
  7600. min$1[1] = y - ry;
  7601. max$1[0] = x + rx;
  7602. max$1[1] = y + ry;
  7603. return;
  7604. }
  7605. start[0] = mathCos(startAngle) * rx + x;
  7606. start[1] = mathSin(startAngle) * ry + y;
  7607. end[0] = mathCos(endAngle) * rx + x;
  7608. end[1] = mathSin(endAngle) * ry + y;
  7609. vec2Min(min$1, start, end);
  7610. vec2Max(max$1, start, end);
  7611. startAngle = startAngle % (PI2);
  7612. if (startAngle < 0) {
  7613. startAngle = startAngle + PI2;
  7614. }
  7615. endAngle = endAngle % (PI2);
  7616. if (endAngle < 0) {
  7617. endAngle = endAngle + PI2;
  7618. }
  7619. if (startAngle > endAngle && !anticlockwise) {
  7620. endAngle += PI2;
  7621. }
  7622. else if (startAngle < endAngle && anticlockwise) {
  7623. startAngle += PI2;
  7624. }
  7625. if (anticlockwise) {
  7626. var tmp = endAngle;
  7627. endAngle = startAngle;
  7628. startAngle = tmp;
  7629. }
  7630. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  7631. if (angle > startAngle) {
  7632. extremity[0] = mathCos(angle) * rx + x;
  7633. extremity[1] = mathSin(angle) * ry + y;
  7634. vec2Min(min$1, extremity, min$1);
  7635. vec2Max(max$1, extremity, max$1);
  7636. }
  7637. }
  7638. }
  7639. var CMD = {
  7640. M: 1,
  7641. L: 2,
  7642. C: 3,
  7643. Q: 4,
  7644. A: 5,
  7645. Z: 6,
  7646. R: 7
  7647. };
  7648. var tmpOutX = [];
  7649. var tmpOutY = [];
  7650. var min$1 = [];
  7651. var max$1 = [];
  7652. var min2 = [];
  7653. var max2 = [];
  7654. var mathMin$2 = Math.min;
  7655. var mathMax$2 = Math.max;
  7656. var mathCos$1 = Math.cos;
  7657. var mathSin$1 = Math.sin;
  7658. var mathAbs = Math.abs;
  7659. var PI = Math.PI;
  7660. var PI2$1 = PI * 2;
  7661. var hasTypedArray = typeof Float32Array !== 'undefined';
  7662. var tmpAngles = [];
  7663. function modPI2(radian) {
  7664. var n = Math.round(radian / PI * 1e8) / 1e8;
  7665. return (n % 2) * PI;
  7666. }
  7667. function normalizeArcAngles(angles, anticlockwise) {
  7668. var newStartAngle = modPI2(angles[0]);
  7669. if (newStartAngle < 0) {
  7670. newStartAngle += PI2$1;
  7671. }
  7672. var delta = newStartAngle - angles[0];
  7673. var newEndAngle = angles[1];
  7674. newEndAngle += delta;
  7675. if (!anticlockwise && newEndAngle - newStartAngle >= PI2$1) {
  7676. newEndAngle = newStartAngle + PI2$1;
  7677. }
  7678. else if (anticlockwise && newStartAngle - newEndAngle >= PI2$1) {
  7679. newEndAngle = newStartAngle - PI2$1;
  7680. }
  7681. else if (!anticlockwise && newStartAngle > newEndAngle) {
  7682. newEndAngle = newStartAngle + (PI2$1 - modPI2(newStartAngle - newEndAngle));
  7683. }
  7684. else if (anticlockwise && newStartAngle < newEndAngle) {
  7685. newEndAngle = newStartAngle - (PI2$1 - modPI2(newEndAngle - newStartAngle));
  7686. }
  7687. angles[0] = newStartAngle;
  7688. angles[1] = newEndAngle;
  7689. }
  7690. var PathProxy = (function () {
  7691. function PathProxy(notSaveData) {
  7692. this.dpr = 1;
  7693. this._xi = 0;
  7694. this._yi = 0;
  7695. this._x0 = 0;
  7696. this._y0 = 0;
  7697. this._len = 0;
  7698. if (notSaveData) {
  7699. this._saveData = false;
  7700. }
  7701. if (this._saveData) {
  7702. this.data = [];
  7703. }
  7704. }
  7705. PathProxy.prototype.increaseVersion = function () {
  7706. this._version++;
  7707. };
  7708. PathProxy.prototype.getVersion = function () {
  7709. return this._version;
  7710. };
  7711. PathProxy.prototype.setScale = function (sx, sy, segmentIgnoreThreshold) {
  7712. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  7713. if (segmentIgnoreThreshold > 0) {
  7714. this._ux = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  7715. this._uy = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  7716. }
  7717. };
  7718. PathProxy.prototype.setDPR = function (dpr) {
  7719. this.dpr = dpr;
  7720. };
  7721. PathProxy.prototype.setContext = function (ctx) {
  7722. this._ctx = ctx;
  7723. };
  7724. PathProxy.prototype.getContext = function () {
  7725. return this._ctx;
  7726. };
  7727. PathProxy.prototype.beginPath = function () {
  7728. this._ctx && this._ctx.beginPath();
  7729. this.reset();
  7730. return this;
  7731. };
  7732. PathProxy.prototype.reset = function () {
  7733. if (this._saveData) {
  7734. this._len = 0;
  7735. }
  7736. if (this._pathSegLen) {
  7737. this._pathSegLen = null;
  7738. this._pathLen = 0;
  7739. }
  7740. this._version++;
  7741. };
  7742. PathProxy.prototype.moveTo = function (x, y) {
  7743. this._drawPendingPt();
  7744. this.addData(CMD.M, x, y);
  7745. this._ctx && this._ctx.moveTo(x, y);
  7746. this._x0 = x;
  7747. this._y0 = y;
  7748. this._xi = x;
  7749. this._yi = y;
  7750. return this;
  7751. };
  7752. PathProxy.prototype.lineTo = function (x, y) {
  7753. var dx = mathAbs(x - this._xi);
  7754. var dy = mathAbs(y - this._yi);
  7755. var exceedUnit = dx > this._ux || dy > this._uy;
  7756. this.addData(CMD.L, x, y);
  7757. if (this._ctx && exceedUnit) {
  7758. this._ctx.lineTo(x, y);
  7759. }
  7760. if (exceedUnit) {
  7761. this._xi = x;
  7762. this._yi = y;
  7763. this._pendingPtDist = 0;
  7764. }
  7765. else {
  7766. var d2 = dx * dx + dy * dy;
  7767. if (d2 > this._pendingPtDist) {
  7768. this._pendingPtX = x;
  7769. this._pendingPtY = y;
  7770. this._pendingPtDist = d2;
  7771. }
  7772. }
  7773. return this;
  7774. };
  7775. PathProxy.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
  7776. this._drawPendingPt();
  7777. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  7778. if (this._ctx) {
  7779. this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  7780. }
  7781. this._xi = x3;
  7782. this._yi = y3;
  7783. return this;
  7784. };
  7785. PathProxy.prototype.quadraticCurveTo = function (x1, y1, x2, y2) {
  7786. this._drawPendingPt();
  7787. this.addData(CMD.Q, x1, y1, x2, y2);
  7788. if (this._ctx) {
  7789. this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  7790. }
  7791. this._xi = x2;
  7792. this._yi = y2;
  7793. return this;
  7794. };
  7795. PathProxy.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  7796. this._drawPendingPt();
  7797. tmpAngles[0] = startAngle;
  7798. tmpAngles[1] = endAngle;
  7799. normalizeArcAngles(tmpAngles, anticlockwise);
  7800. startAngle = tmpAngles[0];
  7801. endAngle = tmpAngles[1];
  7802. var delta = endAngle - startAngle;
  7803. this.addData(CMD.A, cx, cy, r, r, startAngle, delta, 0, anticlockwise ? 0 : 1);
  7804. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  7805. this._xi = mathCos$1(endAngle) * r + cx;
  7806. this._yi = mathSin$1(endAngle) * r + cy;
  7807. return this;
  7808. };
  7809. PathProxy.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  7810. this._drawPendingPt();
  7811. if (this._ctx) {
  7812. this._ctx.arcTo(x1, y1, x2, y2, radius);
  7813. }
  7814. return this;
  7815. };
  7816. PathProxy.prototype.rect = function (x, y, w, h) {
  7817. this._drawPendingPt();
  7818. this._ctx && this._ctx.rect(x, y, w, h);
  7819. this.addData(CMD.R, x, y, w, h);
  7820. return this;
  7821. };
  7822. PathProxy.prototype.closePath = function () {
  7823. this._drawPendingPt();
  7824. this.addData(CMD.Z);
  7825. var ctx = this._ctx;
  7826. var x0 = this._x0;
  7827. var y0 = this._y0;
  7828. if (ctx) {
  7829. ctx.closePath();
  7830. }
  7831. this._xi = x0;
  7832. this._yi = y0;
  7833. return this;
  7834. };
  7835. PathProxy.prototype.fill = function (ctx) {
  7836. ctx && ctx.fill();
  7837. this.toStatic();
  7838. };
  7839. PathProxy.prototype.stroke = function (ctx) {
  7840. ctx && ctx.stroke();
  7841. this.toStatic();
  7842. };
  7843. PathProxy.prototype.len = function () {
  7844. return this._len;
  7845. };
  7846. PathProxy.prototype.setData = function (data) {
  7847. var len = data.length;
  7848. if (!(this.data && this.data.length === len) && hasTypedArray) {
  7849. this.data = new Float32Array(len);
  7850. }
  7851. for (var i = 0; i < len; i++) {
  7852. this.data[i] = data[i];
  7853. }
  7854. this._len = len;
  7855. };
  7856. PathProxy.prototype.appendPath = function (path) {
  7857. if (!(path instanceof Array)) {
  7858. path = [path];
  7859. }
  7860. var len = path.length;
  7861. var appendSize = 0;
  7862. var offset = this._len;
  7863. for (var i = 0; i < len; i++) {
  7864. appendSize += path[i].len();
  7865. }
  7866. if (hasTypedArray && (this.data instanceof Float32Array)) {
  7867. this.data = new Float32Array(offset + appendSize);
  7868. }
  7869. for (var i = 0; i < len; i++) {
  7870. var appendPathData = path[i].data;
  7871. for (var k = 0; k < appendPathData.length; k++) {
  7872. this.data[offset++] = appendPathData[k];
  7873. }
  7874. }
  7875. this._len = offset;
  7876. };
  7877. PathProxy.prototype.addData = function (cmd, a, b, c, d, e, f, g, h) {
  7878. if (!this._saveData) {
  7879. return;
  7880. }
  7881. var data = this.data;
  7882. if (this._len + arguments.length > data.length) {
  7883. this._expandData();
  7884. data = this.data;
  7885. }
  7886. for (var i = 0; i < arguments.length; i++) {
  7887. data[this._len++] = arguments[i];
  7888. }
  7889. };
  7890. PathProxy.prototype._drawPendingPt = function () {
  7891. if (this._pendingPtDist > 0) {
  7892. this._ctx && this._ctx.lineTo(this._pendingPtX, this._pendingPtY);
  7893. this._pendingPtDist = 0;
  7894. }
  7895. };
  7896. PathProxy.prototype._expandData = function () {
  7897. if (!(this.data instanceof Array)) {
  7898. var newData = [];
  7899. for (var i = 0; i < this._len; i++) {
  7900. newData[i] = this.data[i];
  7901. }
  7902. this.data = newData;
  7903. }
  7904. };
  7905. PathProxy.prototype.toStatic = function () {
  7906. if (!this._saveData) {
  7907. return;
  7908. }
  7909. this._drawPendingPt();
  7910. var data = this.data;
  7911. if (data instanceof Array) {
  7912. data.length = this._len;
  7913. if (hasTypedArray && this._len > 11) {
  7914. this.data = new Float32Array(data);
  7915. }
  7916. }
  7917. };
  7918. PathProxy.prototype.getBoundingRect = function () {
  7919. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  7920. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  7921. var data = this.data;
  7922. var xi = 0;
  7923. var yi = 0;
  7924. var x0 = 0;
  7925. var y0 = 0;
  7926. var i;
  7927. for (i = 0; i < this._len;) {
  7928. var cmd = data[i++];
  7929. var isFirst = i === 1;
  7930. if (isFirst) {
  7931. xi = data[i];
  7932. yi = data[i + 1];
  7933. x0 = xi;
  7934. y0 = yi;
  7935. }
  7936. switch (cmd) {
  7937. case CMD.M:
  7938. xi = x0 = data[i++];
  7939. yi = y0 = data[i++];
  7940. min2[0] = x0;
  7941. min2[1] = y0;
  7942. max2[0] = x0;
  7943. max2[1] = y0;
  7944. break;
  7945. case CMD.L:
  7946. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  7947. xi = data[i++];
  7948. yi = data[i++];
  7949. break;
  7950. case CMD.C:
  7951. fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  7952. xi = data[i++];
  7953. yi = data[i++];
  7954. break;
  7955. case CMD.Q:
  7956. fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  7957. xi = data[i++];
  7958. yi = data[i++];
  7959. break;
  7960. case CMD.A:
  7961. var cx = data[i++];
  7962. var cy = data[i++];
  7963. var rx = data[i++];
  7964. var ry = data[i++];
  7965. var startAngle = data[i++];
  7966. var endAngle = data[i++] + startAngle;
  7967. i += 1;
  7968. var anticlockwise = !data[i++];
  7969. if (isFirst) {
  7970. x0 = mathCos$1(startAngle) * rx + cx;
  7971. y0 = mathSin$1(startAngle) * ry + cy;
  7972. }
  7973. fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  7974. xi = mathCos$1(endAngle) * rx + cx;
  7975. yi = mathSin$1(endAngle) * ry + cy;
  7976. break;
  7977. case CMD.R:
  7978. x0 = xi = data[i++];
  7979. y0 = yi = data[i++];
  7980. var width = data[i++];
  7981. var height = data[i++];
  7982. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  7983. break;
  7984. case CMD.Z:
  7985. xi = x0;
  7986. yi = y0;
  7987. break;
  7988. }
  7989. min(min$1, min$1, min2);
  7990. max(max$1, max$1, max2);
  7991. }
  7992. if (i === 0) {
  7993. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  7994. }
  7995. return new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  7996. };
  7997. PathProxy.prototype._calculateLength = function () {
  7998. var data = this.data;
  7999. var len = this._len;
  8000. var ux = this._ux;
  8001. var uy = this._uy;
  8002. var xi = 0;
  8003. var yi = 0;
  8004. var x0 = 0;
  8005. var y0 = 0;
  8006. if (!this._pathSegLen) {
  8007. this._pathSegLen = [];
  8008. }
  8009. var pathSegLen = this._pathSegLen;
  8010. var pathTotalLen = 0;
  8011. var segCount = 0;
  8012. for (var i = 0; i < len;) {
  8013. var cmd = data[i++];
  8014. var isFirst = i === 1;
  8015. if (isFirst) {
  8016. xi = data[i];
  8017. yi = data[i + 1];
  8018. x0 = xi;
  8019. y0 = yi;
  8020. }
  8021. var l = -1;
  8022. switch (cmd) {
  8023. case CMD.M:
  8024. xi = x0 = data[i++];
  8025. yi = y0 = data[i++];
  8026. break;
  8027. case CMD.L: {
  8028. var x2 = data[i++];
  8029. var y2 = data[i++];
  8030. var dx = x2 - xi;
  8031. var dy = y2 - yi;
  8032. if (mathAbs(dx) > ux || mathAbs(dy) > uy || i === len - 1) {
  8033. l = Math.sqrt(dx * dx + dy * dy);
  8034. xi = x2;
  8035. yi = y2;
  8036. }
  8037. break;
  8038. }
  8039. case CMD.C: {
  8040. var x1 = data[i++];
  8041. var y1 = data[i++];
  8042. var x2 = data[i++];
  8043. var y2 = data[i++];
  8044. var x3 = data[i++];
  8045. var y3 = data[i++];
  8046. l = cubicLength(xi, yi, x1, y1, x2, y2, x3, y3, 10);
  8047. xi = x3;
  8048. yi = y3;
  8049. break;
  8050. }
  8051. case CMD.Q: {
  8052. var x1 = data[i++];
  8053. var y1 = data[i++];
  8054. var x2 = data[i++];
  8055. var y2 = data[i++];
  8056. l = quadraticLength(xi, yi, x1, y1, x2, y2, 10);
  8057. xi = x2;
  8058. yi = y2;
  8059. break;
  8060. }
  8061. case CMD.A:
  8062. var cx = data[i++];
  8063. var cy = data[i++];
  8064. var rx = data[i++];
  8065. var ry = data[i++];
  8066. var startAngle = data[i++];
  8067. var delta = data[i++];
  8068. var endAngle = delta + startAngle;
  8069. i += 1;
  8070. var anticlockwise = !data[i++];
  8071. if (isFirst) {
  8072. x0 = mathCos$1(startAngle) * rx + cx;
  8073. y0 = mathSin$1(startAngle) * ry + cy;
  8074. }
  8075. l = mathMax$2(rx, ry) * mathMin$2(PI2$1, Math.abs(delta));
  8076. xi = mathCos$1(endAngle) * rx + cx;
  8077. yi = mathSin$1(endAngle) * ry + cy;
  8078. break;
  8079. case CMD.R: {
  8080. x0 = xi = data[i++];
  8081. y0 = yi = data[i++];
  8082. var width = data[i++];
  8083. var height = data[i++];
  8084. l = width * 2 + height * 2;
  8085. break;
  8086. }
  8087. case CMD.Z: {
  8088. var dx = x0 - xi;
  8089. var dy = y0 - yi;
  8090. l = Math.sqrt(dx * dx + dy * dy);
  8091. xi = x0;
  8092. yi = y0;
  8093. break;
  8094. }
  8095. }
  8096. if (l >= 0) {
  8097. pathSegLen[segCount++] = l;
  8098. pathTotalLen += l;
  8099. }
  8100. }
  8101. this._pathLen = pathTotalLen;
  8102. return pathTotalLen;
  8103. };
  8104. PathProxy.prototype.rebuildPath = function (ctx, percent) {
  8105. var d = this.data;
  8106. var ux = this._ux;
  8107. var uy = this._uy;
  8108. var len = this._len;
  8109. var x0;
  8110. var y0;
  8111. var xi;
  8112. var yi;
  8113. var x;
  8114. var y;
  8115. var drawPart = percent < 1;
  8116. var pathSegLen;
  8117. var pathTotalLen;
  8118. var accumLength = 0;
  8119. var segCount = 0;
  8120. var displayedLength;
  8121. var pendingPtDist = 0;
  8122. var pendingPtX;
  8123. var pendingPtY;
  8124. if (drawPart) {
  8125. if (!this._pathSegLen) {
  8126. this._calculateLength();
  8127. }
  8128. pathSegLen = this._pathSegLen;
  8129. pathTotalLen = this._pathLen;
  8130. displayedLength = percent * pathTotalLen;
  8131. if (!displayedLength) {
  8132. return;
  8133. }
  8134. }
  8135. lo: for (var i = 0; i < len;) {
  8136. var cmd = d[i++];
  8137. var isFirst = i === 1;
  8138. if (isFirst) {
  8139. xi = d[i];
  8140. yi = d[i + 1];
  8141. x0 = xi;
  8142. y0 = yi;
  8143. }
  8144. if (cmd !== CMD.L && pendingPtDist > 0) {
  8145. ctx.lineTo(pendingPtX, pendingPtY);
  8146. pendingPtDist = 0;
  8147. }
  8148. switch (cmd) {
  8149. case CMD.M:
  8150. x0 = xi = d[i++];
  8151. y0 = yi = d[i++];
  8152. ctx.moveTo(xi, yi);
  8153. break;
  8154. case CMD.L: {
  8155. x = d[i++];
  8156. y = d[i++];
  8157. var dx = mathAbs(x - xi);
  8158. var dy = mathAbs(y - yi);
  8159. if (dx > ux || dy > uy) {
  8160. if (drawPart) {
  8161. var l = pathSegLen[segCount++];
  8162. if (accumLength + l > displayedLength) {
  8163. var t = (displayedLength - accumLength) / l;
  8164. ctx.lineTo(xi * (1 - t) + x * t, yi * (1 - t) + y * t);
  8165. break lo;
  8166. }
  8167. accumLength += l;
  8168. }
  8169. ctx.lineTo(x, y);
  8170. xi = x;
  8171. yi = y;
  8172. pendingPtDist = 0;
  8173. }
  8174. else {
  8175. var d2 = dx * dx + dy * dy;
  8176. if (d2 > pendingPtDist) {
  8177. pendingPtX = x;
  8178. pendingPtY = y;
  8179. pendingPtDist = d2;
  8180. }
  8181. }
  8182. break;
  8183. }
  8184. case CMD.C: {
  8185. var x1 = d[i++];
  8186. var y1 = d[i++];
  8187. var x2 = d[i++];
  8188. var y2 = d[i++];
  8189. var x3 = d[i++];
  8190. var y3 = d[i++];
  8191. if (drawPart) {
  8192. var l = pathSegLen[segCount++];
  8193. if (accumLength + l > displayedLength) {
  8194. var t = (displayedLength - accumLength) / l;
  8195. cubicSubdivide(xi, x1, x2, x3, t, tmpOutX);
  8196. cubicSubdivide(yi, y1, y2, y3, t, tmpOutY);
  8197. ctx.bezierCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2], tmpOutX[3], tmpOutY[3]);
  8198. break lo;
  8199. }
  8200. accumLength += l;
  8201. }
  8202. ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  8203. xi = x3;
  8204. yi = y3;
  8205. break;
  8206. }
  8207. case CMD.Q: {
  8208. var x1 = d[i++];
  8209. var y1 = d[i++];
  8210. var x2 = d[i++];
  8211. var y2 = d[i++];
  8212. if (drawPart) {
  8213. var l = pathSegLen[segCount++];
  8214. if (accumLength + l > displayedLength) {
  8215. var t = (displayedLength - accumLength) / l;
  8216. quadraticSubdivide(xi, x1, x2, t, tmpOutX);
  8217. quadraticSubdivide(yi, y1, y2, t, tmpOutY);
  8218. ctx.quadraticCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2]);
  8219. break lo;
  8220. }
  8221. accumLength += l;
  8222. }
  8223. ctx.quadraticCurveTo(x1, y1, x2, y2);
  8224. xi = x2;
  8225. yi = y2;
  8226. break;
  8227. }
  8228. case CMD.A:
  8229. var cx = d[i++];
  8230. var cy = d[i++];
  8231. var rx = d[i++];
  8232. var ry = d[i++];
  8233. var startAngle = d[i++];
  8234. var delta = d[i++];
  8235. var psi = d[i++];
  8236. var anticlockwise = !d[i++];
  8237. var r = (rx > ry) ? rx : ry;
  8238. var isEllipse = mathAbs(rx - ry) > 1e-3;
  8239. var endAngle = startAngle + delta;
  8240. var breakBuild = false;
  8241. if (drawPart) {
  8242. var l = pathSegLen[segCount++];
  8243. if (accumLength + l > displayedLength) {
  8244. endAngle = startAngle + delta * (displayedLength - accumLength) / l;
  8245. breakBuild = true;
  8246. }
  8247. accumLength += l;
  8248. }
  8249. if (isEllipse && ctx.ellipse) {
  8250. ctx.ellipse(cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise);
  8251. }
  8252. else {
  8253. ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  8254. }
  8255. if (breakBuild) {
  8256. break lo;
  8257. }
  8258. if (isFirst) {
  8259. x0 = mathCos$1(startAngle) * rx + cx;
  8260. y0 = mathSin$1(startAngle) * ry + cy;
  8261. }
  8262. xi = mathCos$1(endAngle) * rx + cx;
  8263. yi = mathSin$1(endAngle) * ry + cy;
  8264. break;
  8265. case CMD.R:
  8266. x0 = xi = d[i];
  8267. y0 = yi = d[i + 1];
  8268. x = d[i++];
  8269. y = d[i++];
  8270. var width = d[i++];
  8271. var height = d[i++];
  8272. if (drawPart) {
  8273. var l = pathSegLen[segCount++];
  8274. if (accumLength + l > displayedLength) {
  8275. var d_1 = displayedLength - accumLength;
  8276. ctx.moveTo(x, y);
  8277. ctx.lineTo(x + mathMin$2(d_1, width), y);
  8278. d_1 -= width;
  8279. if (d_1 > 0) {
  8280. ctx.lineTo(x + width, y + mathMin$2(d_1, height));
  8281. }
  8282. d_1 -= height;
  8283. if (d_1 > 0) {
  8284. ctx.lineTo(x + mathMax$2(width - d_1, 0), y + height);
  8285. }
  8286. d_1 -= width;
  8287. if (d_1 > 0) {
  8288. ctx.lineTo(x, y + mathMax$2(height - d_1, 0));
  8289. }
  8290. break lo;
  8291. }
  8292. accumLength += l;
  8293. }
  8294. ctx.rect(x, y, width, height);
  8295. break;
  8296. case CMD.Z:
  8297. if (drawPart) {
  8298. var l = pathSegLen[segCount++];
  8299. if (accumLength + l > displayedLength) {
  8300. var t = (displayedLength - accumLength) / l;
  8301. ctx.lineTo(xi * (1 - t) + x0 * t, yi * (1 - t) + y0 * t);
  8302. break lo;
  8303. }
  8304. accumLength += l;
  8305. }
  8306. ctx.closePath();
  8307. xi = x0;
  8308. yi = y0;
  8309. }
  8310. }
  8311. };
  8312. PathProxy.prototype.clone = function () {
  8313. var newProxy = new PathProxy();
  8314. var data = this.data;
  8315. newProxy.data = data.slice ? data.slice()
  8316. : Array.prototype.slice.call(data);
  8317. newProxy._len = this._len;
  8318. return newProxy;
  8319. };
  8320. PathProxy.CMD = CMD;
  8321. PathProxy.initDefaultProps = (function () {
  8322. var proto = PathProxy.prototype;
  8323. proto._saveData = true;
  8324. proto._ux = 0;
  8325. proto._uy = 0;
  8326. proto._pendingPtDist = 0;
  8327. proto._version = 0;
  8328. })();
  8329. return PathProxy;
  8330. }());
  8331. function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
  8332. if (lineWidth === 0) {
  8333. return false;
  8334. }
  8335. var _l = lineWidth;
  8336. var _a = 0;
  8337. var _b = x0;
  8338. if ((y > y0 + _l && y > y1 + _l)
  8339. || (y < y0 - _l && y < y1 - _l)
  8340. || (x > x0 + _l && x > x1 + _l)
  8341. || (x < x0 - _l && x < x1 - _l)) {
  8342. return false;
  8343. }
  8344. if (x0 !== x1) {
  8345. _a = (y0 - y1) / (x0 - x1);
  8346. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  8347. }
  8348. else {
  8349. return Math.abs(x - x0) <= _l / 2;
  8350. }
  8351. var tmp = _a * x - y + _b;
  8352. var _s = tmp * tmp / (_a * _a + 1);
  8353. return _s <= _l / 2 * _l / 2;
  8354. }
  8355. function containStroke$1(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  8356. if (lineWidth === 0) {
  8357. return false;
  8358. }
  8359. var _l = lineWidth;
  8360. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  8361. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  8362. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  8363. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)) {
  8364. return false;
  8365. }
  8366. var d = cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  8367. return d <= _l / 2;
  8368. }
  8369. function containStroke$2(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  8370. if (lineWidth === 0) {
  8371. return false;
  8372. }
  8373. var _l = lineWidth;
  8374. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l)
  8375. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  8376. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  8377. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)) {
  8378. return false;
  8379. }
  8380. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  8381. return d <= _l / 2;
  8382. }
  8383. var PI2$2 = Math.PI * 2;
  8384. function normalizeRadian(angle) {
  8385. angle %= PI2$2;
  8386. if (angle < 0) {
  8387. angle += PI2$2;
  8388. }
  8389. return angle;
  8390. }
  8391. var PI2$3 = Math.PI * 2;
  8392. function containStroke$3(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  8393. if (lineWidth === 0) {
  8394. return false;
  8395. }
  8396. var _l = lineWidth;
  8397. x -= cx;
  8398. y -= cy;
  8399. var d = Math.sqrt(x * x + y * y);
  8400. if ((d - _l > r) || (d + _l < r)) {
  8401. return false;
  8402. }
  8403. if (Math.abs(startAngle - endAngle) % PI2$3 < 1e-4) {
  8404. return true;
  8405. }
  8406. if (anticlockwise) {
  8407. var tmp = startAngle;
  8408. startAngle = normalizeRadian(endAngle);
  8409. endAngle = normalizeRadian(tmp);
  8410. }
  8411. else {
  8412. startAngle = normalizeRadian(startAngle);
  8413. endAngle = normalizeRadian(endAngle);
  8414. }
  8415. if (startAngle > endAngle) {
  8416. endAngle += PI2$3;
  8417. }
  8418. var angle = Math.atan2(y, x);
  8419. if (angle < 0) {
  8420. angle += PI2$3;
  8421. }
  8422. return (angle >= startAngle && angle <= endAngle)
  8423. || (angle + PI2$3 >= startAngle && angle + PI2$3 <= endAngle);
  8424. }
  8425. function windingLine(x0, y0, x1, y1, x, y) {
  8426. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  8427. return 0;
  8428. }
  8429. if (y1 === y0) {
  8430. return 0;
  8431. }
  8432. var t = (y - y0) / (y1 - y0);
  8433. var dir = y1 < y0 ? 1 : -1;
  8434. if (t === 1 || t === 0) {
  8435. dir = y1 < y0 ? 0.5 : -0.5;
  8436. }
  8437. var x_ = t * (x1 - x0) + x0;
  8438. return x_ === x ? Infinity : x_ > x ? dir : 0;
  8439. }
  8440. var CMD$1 = PathProxy.CMD;
  8441. var PI2$4 = Math.PI * 2;
  8442. var EPSILON$3 = 1e-4;
  8443. function isAroundEqual(a, b) {
  8444. return Math.abs(a - b) < EPSILON$3;
  8445. }
  8446. var roots = [-1, -1, -1];
  8447. var extrema = [-1, -1];
  8448. function swapExtrema() {
  8449. var tmp = extrema[0];
  8450. extrema[0] = extrema[1];
  8451. extrema[1] = tmp;
  8452. }
  8453. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  8454. if ((y > y0 && y > y1 && y > y2 && y > y3)
  8455. || (y < y0 && y < y1 && y < y2 && y < y3)) {
  8456. return 0;
  8457. }
  8458. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  8459. if (nRoots === 0) {
  8460. return 0;
  8461. }
  8462. else {
  8463. var w = 0;
  8464. var nExtrema = -1;
  8465. var y0_ = void 0;
  8466. var y1_ = void 0;
  8467. for (var i = 0; i < nRoots; i++) {
  8468. var t = roots[i];
  8469. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  8470. var x_ = cubicAt(x0, x1, x2, x3, t);
  8471. if (x_ < x) {
  8472. continue;
  8473. }
  8474. if (nExtrema < 0) {
  8475. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  8476. if (extrema[1] < extrema[0] && nExtrema > 1) {
  8477. swapExtrema();
  8478. }
  8479. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  8480. if (nExtrema > 1) {
  8481. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  8482. }
  8483. }
  8484. if (nExtrema === 2) {
  8485. if (t < extrema[0]) {
  8486. w += y0_ < y0 ? unit : -unit;
  8487. }
  8488. else if (t < extrema[1]) {
  8489. w += y1_ < y0_ ? unit : -unit;
  8490. }
  8491. else {
  8492. w += y3 < y1_ ? unit : -unit;
  8493. }
  8494. }
  8495. else {
  8496. if (t < extrema[0]) {
  8497. w += y0_ < y0 ? unit : -unit;
  8498. }
  8499. else {
  8500. w += y3 < y0_ ? unit : -unit;
  8501. }
  8502. }
  8503. }
  8504. return w;
  8505. }
  8506. }
  8507. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  8508. if ((y > y0 && y > y1 && y > y2)
  8509. || (y < y0 && y < y1 && y < y2)) {
  8510. return 0;
  8511. }
  8512. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  8513. if (nRoots === 0) {
  8514. return 0;
  8515. }
  8516. else {
  8517. var t = quadraticExtremum(y0, y1, y2);
  8518. if (t >= 0 && t <= 1) {
  8519. var w = 0;
  8520. var y_ = quadraticAt(y0, y1, y2, t);
  8521. for (var i = 0; i < nRoots; i++) {
  8522. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  8523. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  8524. if (x_ < x) {
  8525. continue;
  8526. }
  8527. if (roots[i] < t) {
  8528. w += y_ < y0 ? unit : -unit;
  8529. }
  8530. else {
  8531. w += y2 < y_ ? unit : -unit;
  8532. }
  8533. }
  8534. return w;
  8535. }
  8536. else {
  8537. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  8538. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  8539. if (x_ < x) {
  8540. return 0;
  8541. }
  8542. return y2 < y0 ? unit : -unit;
  8543. }
  8544. }
  8545. }
  8546. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  8547. y -= cy;
  8548. if (y > r || y < -r) {
  8549. return 0;
  8550. }
  8551. var tmp = Math.sqrt(r * r - y * y);
  8552. roots[0] = -tmp;
  8553. roots[1] = tmp;
  8554. var dTheta = Math.abs(startAngle - endAngle);
  8555. if (dTheta < 1e-4) {
  8556. return 0;
  8557. }
  8558. if (dTheta >= PI2$4 - 1e-4) {
  8559. startAngle = 0;
  8560. endAngle = PI2$4;
  8561. var dir = anticlockwise ? 1 : -1;
  8562. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  8563. return dir;
  8564. }
  8565. else {
  8566. return 0;
  8567. }
  8568. }
  8569. if (startAngle > endAngle) {
  8570. var tmp_1 = startAngle;
  8571. startAngle = endAngle;
  8572. endAngle = tmp_1;
  8573. }
  8574. if (startAngle < 0) {
  8575. startAngle += PI2$4;
  8576. endAngle += PI2$4;
  8577. }
  8578. var w = 0;
  8579. for (var i = 0; i < 2; i++) {
  8580. var x_ = roots[i];
  8581. if (x_ + cx > x) {
  8582. var angle = Math.atan2(y, x_);
  8583. var dir = anticlockwise ? 1 : -1;
  8584. if (angle < 0) {
  8585. angle = PI2$4 + angle;
  8586. }
  8587. if ((angle >= startAngle && angle <= endAngle)
  8588. || (angle + PI2$4 >= startAngle && angle + PI2$4 <= endAngle)) {
  8589. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  8590. dir = -dir;
  8591. }
  8592. w += dir;
  8593. }
  8594. }
  8595. }
  8596. return w;
  8597. }
  8598. function containPath(path, lineWidth, isStroke, x, y) {
  8599. var data = path.data;
  8600. var len = path.len();
  8601. var w = 0;
  8602. var xi = 0;
  8603. var yi = 0;
  8604. var x0 = 0;
  8605. var y0 = 0;
  8606. var x1;
  8607. var y1;
  8608. for (var i = 0; i < len;) {
  8609. var cmd = data[i++];
  8610. var isFirst = i === 1;
  8611. if (cmd === CMD$1.M && i > 1) {
  8612. if (!isStroke) {
  8613. w += windingLine(xi, yi, x0, y0, x, y);
  8614. }
  8615. }
  8616. if (isFirst) {
  8617. xi = data[i];
  8618. yi = data[i + 1];
  8619. x0 = xi;
  8620. y0 = yi;
  8621. }
  8622. switch (cmd) {
  8623. case CMD$1.M:
  8624. x0 = data[i++];
  8625. y0 = data[i++];
  8626. xi = x0;
  8627. yi = y0;
  8628. break;
  8629. case CMD$1.L:
  8630. if (isStroke) {
  8631. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  8632. return true;
  8633. }
  8634. }
  8635. else {
  8636. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  8637. }
  8638. xi = data[i++];
  8639. yi = data[i++];
  8640. break;
  8641. case CMD$1.C:
  8642. if (isStroke) {
  8643. if (containStroke$1(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8644. return true;
  8645. }
  8646. }
  8647. else {
  8648. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8649. }
  8650. xi = data[i++];
  8651. yi = data[i++];
  8652. break;
  8653. case CMD$1.Q:
  8654. if (isStroke) {
  8655. if (containStroke$2(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8656. return true;
  8657. }
  8658. }
  8659. else {
  8660. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8661. }
  8662. xi = data[i++];
  8663. yi = data[i++];
  8664. break;
  8665. case CMD$1.A:
  8666. var cx = data[i++];
  8667. var cy = data[i++];
  8668. var rx = data[i++];
  8669. var ry = data[i++];
  8670. var theta = data[i++];
  8671. var dTheta = data[i++];
  8672. i += 1;
  8673. var anticlockwise = !!(1 - data[i++]);
  8674. x1 = Math.cos(theta) * rx + cx;
  8675. y1 = Math.sin(theta) * ry + cy;
  8676. if (!isFirst) {
  8677. w += windingLine(xi, yi, x1, y1, x, y);
  8678. }
  8679. else {
  8680. x0 = x1;
  8681. y0 = y1;
  8682. }
  8683. var _x = (x - cx) * ry / rx + cx;
  8684. if (isStroke) {
  8685. if (containStroke$3(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  8686. return true;
  8687. }
  8688. }
  8689. else {
  8690. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  8691. }
  8692. xi = Math.cos(theta + dTheta) * rx + cx;
  8693. yi = Math.sin(theta + dTheta) * ry + cy;
  8694. break;
  8695. case CMD$1.R:
  8696. x0 = xi = data[i++];
  8697. y0 = yi = data[i++];
  8698. var width = data[i++];
  8699. var height = data[i++];
  8700. x1 = x0 + width;
  8701. y1 = y0 + height;
  8702. if (isStroke) {
  8703. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  8704. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  8705. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  8706. || containStroke(x0, y1, x0, y0, lineWidth, x, y)) {
  8707. return true;
  8708. }
  8709. }
  8710. else {
  8711. w += windingLine(x1, y0, x1, y1, x, y);
  8712. w += windingLine(x0, y1, x0, y0, x, y);
  8713. }
  8714. break;
  8715. case CMD$1.Z:
  8716. if (isStroke) {
  8717. if (containStroke(xi, yi, x0, y0, lineWidth, x, y)) {
  8718. return true;
  8719. }
  8720. }
  8721. else {
  8722. w += windingLine(xi, yi, x0, y0, x, y);
  8723. }
  8724. xi = x0;
  8725. yi = y0;
  8726. break;
  8727. }
  8728. }
  8729. if (!isStroke && !isAroundEqual(yi, y0)) {
  8730. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  8731. }
  8732. return w !== 0;
  8733. }
  8734. function contain(pathProxy, x, y) {
  8735. return containPath(pathProxy, 0, false, x, y);
  8736. }
  8737. function containStroke$4(pathProxy, lineWidth, x, y) {
  8738. return containPath(pathProxy, lineWidth, true, x, y);
  8739. }
  8740. var DEFAULT_PATH_STYLE = defaults({
  8741. fill: '#000',
  8742. stroke: null,
  8743. strokePercent: 1,
  8744. fillOpacity: 1,
  8745. strokeOpacity: 1,
  8746. lineDashOffset: 0,
  8747. lineWidth: 1,
  8748. lineCap: 'butt',
  8749. miterLimit: 10,
  8750. strokeNoScale: false,
  8751. strokeFirst: false
  8752. }, DEFAULT_COMMON_STYLE);
  8753. var DEFAULT_PATH_ANIMATION_PROPS = {
  8754. style: defaults({
  8755. fill: true,
  8756. stroke: true,
  8757. strokePercent: true,
  8758. fillOpacity: true,
  8759. strokeOpacity: true,
  8760. lineDashOffset: true,
  8761. lineWidth: true,
  8762. miterLimit: true
  8763. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  8764. };
  8765. var pathCopyParams = TRANSFORMABLE_PROPS.concat(['invisible',
  8766. 'culling', 'z', 'z2', 'zlevel', 'parent'
  8767. ]);
  8768. var Path = (function (_super) {
  8769. __extends(Path, _super);
  8770. function Path(opts) {
  8771. return _super.call(this, opts) || this;
  8772. }
  8773. Path.prototype.update = function () {
  8774. var _this = this;
  8775. _super.prototype.update.call(this);
  8776. var style = this.style;
  8777. if (style.decal) {
  8778. var decalEl = this._decalEl = this._decalEl || new Path();
  8779. if (decalEl.buildPath === Path.prototype.buildPath) {
  8780. decalEl.buildPath = function (ctx) {
  8781. _this.buildPath(ctx, _this.shape);
  8782. };
  8783. }
  8784. decalEl.silent = true;
  8785. var decalElStyle = decalEl.style;
  8786. for (var key in style) {
  8787. if (decalElStyle[key] !== style[key]) {
  8788. decalElStyle[key] = style[key];
  8789. }
  8790. }
  8791. decalElStyle.fill = style.fill ? style.decal : null;
  8792. decalElStyle.decal = null;
  8793. decalElStyle.shadowColor = null;
  8794. style.strokeFirst && (decalElStyle.stroke = null);
  8795. for (var i = 0; i < pathCopyParams.length; ++i) {
  8796. decalEl[pathCopyParams[i]] = this[pathCopyParams[i]];
  8797. }
  8798. decalEl.__dirty |= REDRAW_BIT;
  8799. }
  8800. else if (this._decalEl) {
  8801. this._decalEl = null;
  8802. }
  8803. };
  8804. Path.prototype.getDecalElement = function () {
  8805. return this._decalEl;
  8806. };
  8807. Path.prototype._init = function (props) {
  8808. var keysArr = keys(props);
  8809. this.shape = this.getDefaultShape();
  8810. var defaultStyle = this.getDefaultStyle();
  8811. if (defaultStyle) {
  8812. this.useStyle(defaultStyle);
  8813. }
  8814. for (var i = 0; i < keysArr.length; i++) {
  8815. var key = keysArr[i];
  8816. var value = props[key];
  8817. if (key === 'style') {
  8818. if (!this.style) {
  8819. this.useStyle(value);
  8820. }
  8821. else {
  8822. extend(this.style, value);
  8823. }
  8824. }
  8825. else if (key === 'shape') {
  8826. extend(this.shape, value);
  8827. }
  8828. else {
  8829. _super.prototype.attrKV.call(this, key, value);
  8830. }
  8831. }
  8832. if (!this.style) {
  8833. this.useStyle({});
  8834. }
  8835. };
  8836. Path.prototype.getDefaultStyle = function () {
  8837. return null;
  8838. };
  8839. Path.prototype.getDefaultShape = function () {
  8840. return {};
  8841. };
  8842. Path.prototype.canBeInsideText = function () {
  8843. return this.hasFill();
  8844. };
  8845. Path.prototype.getInsideTextFill = function () {
  8846. var pathFill = this.style.fill;
  8847. if (pathFill !== 'none') {
  8848. if (isString(pathFill)) {
  8849. var fillLum = lum(pathFill, 0);
  8850. if (fillLum > 0.5) {
  8851. return DARK_LABEL_COLOR;
  8852. }
  8853. else if (fillLum > 0.2) {
  8854. return LIGHTER_LABEL_COLOR;
  8855. }
  8856. return LIGHT_LABEL_COLOR;
  8857. }
  8858. else if (pathFill) {
  8859. return LIGHT_LABEL_COLOR;
  8860. }
  8861. }
  8862. return DARK_LABEL_COLOR;
  8863. };
  8864. Path.prototype.getInsideTextStroke = function (textFill) {
  8865. var pathFill = this.style.fill;
  8866. if (isString(pathFill)) {
  8867. var zr = this.__zr;
  8868. var isDarkMode = !!(zr && zr.isDarkMode());
  8869. var isDarkLabel = lum(textFill, 0) < DARK_MODE_THRESHOLD;
  8870. if (isDarkMode === isDarkLabel) {
  8871. return pathFill;
  8872. }
  8873. }
  8874. };
  8875. Path.prototype.buildPath = function (ctx, shapeCfg, inBatch) { };
  8876. Path.prototype.pathUpdated = function () {
  8877. this.__dirty &= ~SHAPE_CHANGED_BIT;
  8878. };
  8879. Path.prototype.getUpdatedPathProxy = function (inBatch) {
  8880. !this.path && this.createPathProxy();
  8881. this.path.beginPath();
  8882. this.buildPath(this.path, this.shape, inBatch);
  8883. return this.path;
  8884. };
  8885. Path.prototype.createPathProxy = function () {
  8886. this.path = new PathProxy(false);
  8887. };
  8888. Path.prototype.hasStroke = function () {
  8889. var style = this.style;
  8890. var stroke = style.stroke;
  8891. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  8892. };
  8893. Path.prototype.hasFill = function () {
  8894. var style = this.style;
  8895. var fill = style.fill;
  8896. return fill != null && fill !== 'none';
  8897. };
  8898. Path.prototype.getBoundingRect = function () {
  8899. var rect = this._rect;
  8900. var style = this.style;
  8901. var needsUpdateRect = !rect;
  8902. if (needsUpdateRect) {
  8903. var firstInvoke = false;
  8904. if (!this.path) {
  8905. firstInvoke = true;
  8906. this.createPathProxy();
  8907. }
  8908. var path = this.path;
  8909. if (firstInvoke || (this.__dirty & SHAPE_CHANGED_BIT)) {
  8910. path.beginPath();
  8911. this.buildPath(path, this.shape, false);
  8912. this.pathUpdated();
  8913. }
  8914. rect = path.getBoundingRect();
  8915. }
  8916. this._rect = rect;
  8917. if (this.hasStroke() && this.path && this.path.len() > 0) {
  8918. var rectStroke = this._rectStroke || (this._rectStroke = rect.clone());
  8919. if (this.__dirty || needsUpdateRect) {
  8920. rectStroke.copy(rect);
  8921. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  8922. var w = style.lineWidth;
  8923. if (!this.hasFill()) {
  8924. var strokeContainThreshold = this.strokeContainThreshold;
  8925. w = Math.max(w, strokeContainThreshold == null ? 4 : strokeContainThreshold);
  8926. }
  8927. if (lineScale > 1e-10) {
  8928. rectStroke.width += w / lineScale;
  8929. rectStroke.height += w / lineScale;
  8930. rectStroke.x -= w / lineScale / 2;
  8931. rectStroke.y -= w / lineScale / 2;
  8932. }
  8933. }
  8934. return rectStroke;
  8935. }
  8936. return rect;
  8937. };
  8938. Path.prototype.contain = function (x, y) {
  8939. var localPos = this.transformCoordToLocal(x, y);
  8940. var rect = this.getBoundingRect();
  8941. var style = this.style;
  8942. x = localPos[0];
  8943. y = localPos[1];
  8944. if (rect.contain(x, y)) {
  8945. var pathProxy = this.path;
  8946. if (this.hasStroke()) {
  8947. var lineWidth = style.lineWidth;
  8948. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  8949. if (lineScale > 1e-10) {
  8950. if (!this.hasFill()) {
  8951. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  8952. }
  8953. if (containStroke$4(pathProxy, lineWidth / lineScale, x, y)) {
  8954. return true;
  8955. }
  8956. }
  8957. }
  8958. if (this.hasFill()) {
  8959. return contain(pathProxy, x, y);
  8960. }
  8961. }
  8962. return false;
  8963. };
  8964. Path.prototype.dirtyShape = function () {
  8965. this.__dirty |= SHAPE_CHANGED_BIT;
  8966. if (this._rect) {
  8967. this._rect = null;
  8968. }
  8969. if (this._decalEl) {
  8970. this._decalEl.dirtyShape();
  8971. }
  8972. this.markRedraw();
  8973. };
  8974. Path.prototype.dirty = function () {
  8975. this.dirtyStyle();
  8976. this.dirtyShape();
  8977. };
  8978. Path.prototype.animateShape = function (loop) {
  8979. return this.animate('shape', loop);
  8980. };
  8981. Path.prototype.updateDuringAnimation = function (targetKey) {
  8982. if (targetKey === 'style') {
  8983. this.dirtyStyle();
  8984. }
  8985. else if (targetKey === 'shape') {
  8986. this.dirtyShape();
  8987. }
  8988. else {
  8989. this.markRedraw();
  8990. }
  8991. };
  8992. Path.prototype.attrKV = function (key, value) {
  8993. if (key === 'shape') {
  8994. this.setShape(value);
  8995. }
  8996. else {
  8997. _super.prototype.attrKV.call(this, key, value);
  8998. }
  8999. };
  9000. Path.prototype.setShape = function (keyOrObj, value) {
  9001. var shape = this.shape;
  9002. if (!shape) {
  9003. shape = this.shape = {};
  9004. }
  9005. if (typeof keyOrObj === 'string') {
  9006. shape[keyOrObj] = value;
  9007. }
  9008. else {
  9009. extend(shape, keyOrObj);
  9010. }
  9011. this.dirtyShape();
  9012. return this;
  9013. };
  9014. Path.prototype.shapeChanged = function () {
  9015. return !!(this.__dirty & SHAPE_CHANGED_BIT);
  9016. };
  9017. Path.prototype.createStyle = function (obj) {
  9018. return createObject(DEFAULT_PATH_STYLE, obj);
  9019. };
  9020. Path.prototype._innerSaveToNormal = function (toState) {
  9021. _super.prototype._innerSaveToNormal.call(this, toState);
  9022. var normalState = this._normalState;
  9023. if (toState.shape && !normalState.shape) {
  9024. normalState.shape = extend({}, this.shape);
  9025. }
  9026. };
  9027. Path.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  9028. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  9029. var needsRestoreToNormal = !(state && keepCurrentStates);
  9030. var targetShape;
  9031. if (state && state.shape) {
  9032. if (transition) {
  9033. if (keepCurrentStates) {
  9034. targetShape = state.shape;
  9035. }
  9036. else {
  9037. targetShape = extend({}, normalState.shape);
  9038. extend(targetShape, state.shape);
  9039. }
  9040. }
  9041. else {
  9042. targetShape = extend({}, keepCurrentStates ? this.shape : normalState.shape);
  9043. extend(targetShape, state.shape);
  9044. }
  9045. }
  9046. else if (needsRestoreToNormal) {
  9047. targetShape = normalState.shape;
  9048. }
  9049. if (targetShape) {
  9050. if (transition) {
  9051. this.shape = extend({}, this.shape);
  9052. var targetShapePrimaryProps = {};
  9053. var shapeKeys = keys(targetShape);
  9054. for (var i = 0; i < shapeKeys.length; i++) {
  9055. var key = shapeKeys[i];
  9056. if (typeof targetShape[key] === 'object') {
  9057. this.shape[key] = targetShape[key];
  9058. }
  9059. else {
  9060. targetShapePrimaryProps[key] = targetShape[key];
  9061. }
  9062. }
  9063. this._transitionState(stateName, {
  9064. shape: targetShapePrimaryProps
  9065. }, animationCfg);
  9066. }
  9067. else {
  9068. this.shape = targetShape;
  9069. this.dirtyShape();
  9070. }
  9071. }
  9072. };
  9073. Path.prototype._mergeStates = function (states) {
  9074. var mergedState = _super.prototype._mergeStates.call(this, states);
  9075. var mergedShape;
  9076. for (var i = 0; i < states.length; i++) {
  9077. var state = states[i];
  9078. if (state.shape) {
  9079. mergedShape = mergedShape || {};
  9080. this._mergeStyle(mergedShape, state.shape);
  9081. }
  9082. }
  9083. if (mergedShape) {
  9084. mergedState.shape = mergedShape;
  9085. }
  9086. return mergedState;
  9087. };
  9088. Path.prototype.getAnimationStyleProps = function () {
  9089. return DEFAULT_PATH_ANIMATION_PROPS;
  9090. };
  9091. Path.prototype.isZeroArea = function () {
  9092. return false;
  9093. };
  9094. Path.extend = function (defaultProps) {
  9095. var Sub = (function (_super) {
  9096. __extends(Sub, _super);
  9097. function Sub(opts) {
  9098. var _this = _super.call(this, opts) || this;
  9099. defaultProps.init && defaultProps.init.call(_this, opts);
  9100. return _this;
  9101. }
  9102. Sub.prototype.getDefaultStyle = function () {
  9103. return clone(defaultProps.style);
  9104. };
  9105. Sub.prototype.getDefaultShape = function () {
  9106. return clone(defaultProps.shape);
  9107. };
  9108. return Sub;
  9109. }(Path));
  9110. for (var key in defaultProps) {
  9111. if (typeof defaultProps[key] === 'function') {
  9112. Sub.prototype[key] = defaultProps[key];
  9113. }
  9114. }
  9115. return Sub;
  9116. };
  9117. Path.initDefaultProps = (function () {
  9118. var pathProto = Path.prototype;
  9119. pathProto.type = 'path';
  9120. pathProto.strokeContainThreshold = 5;
  9121. pathProto.segmentIgnoreThreshold = 0;
  9122. pathProto.subPixelOptimize = false;
  9123. pathProto.autoBatch = false;
  9124. pathProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT | SHAPE_CHANGED_BIT;
  9125. })();
  9126. return Path;
  9127. }(Displayable));
  9128. var CMD$2 = PathProxy.CMD;
  9129. var points = [[], [], []];
  9130. var mathSqrt$1 = Math.sqrt;
  9131. var mathAtan2 = Math.atan2;
  9132. function transformPath(path, m) {
  9133. if (!m) {
  9134. return;
  9135. }
  9136. var data = path.data;
  9137. var len = path.len();
  9138. var cmd;
  9139. var nPoint;
  9140. var i;
  9141. var j;
  9142. var k;
  9143. var p;
  9144. var M = CMD$2.M;
  9145. var C = CMD$2.C;
  9146. var L = CMD$2.L;
  9147. var R = CMD$2.R;
  9148. var A = CMD$2.A;
  9149. var Q = CMD$2.Q;
  9150. for (i = 0, j = 0; i < len;) {
  9151. cmd = data[i++];
  9152. j = i;
  9153. nPoint = 0;
  9154. switch (cmd) {
  9155. case M:
  9156. nPoint = 1;
  9157. break;
  9158. case L:
  9159. nPoint = 1;
  9160. break;
  9161. case C:
  9162. nPoint = 3;
  9163. break;
  9164. case Q:
  9165. nPoint = 2;
  9166. break;
  9167. case A:
  9168. var x = m[4];
  9169. var y = m[5];
  9170. var sx = mathSqrt$1(m[0] * m[0] + m[1] * m[1]);
  9171. var sy = mathSqrt$1(m[2] * m[2] + m[3] * m[3]);
  9172. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  9173. data[i] *= sx;
  9174. data[i++] += x;
  9175. data[i] *= sy;
  9176. data[i++] += y;
  9177. data[i++] *= sx;
  9178. data[i++] *= sy;
  9179. data[i++] += angle;
  9180. data[i++] += angle;
  9181. i += 2;
  9182. j = i;
  9183. break;
  9184. case R:
  9185. p[0] = data[i++];
  9186. p[1] = data[i++];
  9187. applyTransform(p, p, m);
  9188. data[j++] = p[0];
  9189. data[j++] = p[1];
  9190. p[0] += data[i++];
  9191. p[1] += data[i++];
  9192. applyTransform(p, p, m);
  9193. data[j++] = p[0];
  9194. data[j++] = p[1];
  9195. }
  9196. for (k = 0; k < nPoint; k++) {
  9197. var p_1 = points[k];
  9198. p_1[0] = data[i++];
  9199. p_1[1] = data[i++];
  9200. applyTransform(p_1, p_1, m);
  9201. data[j++] = p_1[0];
  9202. data[j++] = p_1[1];
  9203. }
  9204. }
  9205. path.increaseVersion();
  9206. }
  9207. var mathSqrt$2 = Math.sqrt;
  9208. var mathSin$2 = Math.sin;
  9209. var mathCos$2 = Math.cos;
  9210. var PI$1 = Math.PI;
  9211. function vMag(v) {
  9212. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  9213. }
  9214. function vRatio(u, v) {
  9215. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  9216. }
  9217. function vAngle(u, v) {
  9218. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  9219. * Math.acos(vRatio(u, v));
  9220. }
  9221. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  9222. var psi = psiDeg * (PI$1 / 180.0);
  9223. var xp = mathCos$2(psi) * (x1 - x2) / 2.0
  9224. + mathSin$2(psi) * (y1 - y2) / 2.0;
  9225. var yp = -1 * mathSin$2(psi) * (x1 - x2) / 2.0
  9226. + mathCos$2(psi) * (y1 - y2) / 2.0;
  9227. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  9228. if (lambda > 1) {
  9229. rx *= mathSqrt$2(lambda);
  9230. ry *= mathSqrt$2(lambda);
  9231. }
  9232. var f = (fa === fs ? -1 : 1)
  9233. * mathSqrt$2((((rx * rx) * (ry * ry))
  9234. - ((rx * rx) * (yp * yp))
  9235. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  9236. + (ry * ry) * (xp * xp))) || 0;
  9237. var cxp = f * rx * yp / ry;
  9238. var cyp = f * -ry * xp / rx;
  9239. var cx = (x1 + x2) / 2.0
  9240. + mathCos$2(psi) * cxp
  9241. - mathSin$2(psi) * cyp;
  9242. var cy = (y1 + y2) / 2.0
  9243. + mathSin$2(psi) * cxp
  9244. + mathCos$2(psi) * cyp;
  9245. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  9246. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  9247. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  9248. var dTheta = vAngle(u, v);
  9249. if (vRatio(u, v) <= -1) {
  9250. dTheta = PI$1;
  9251. }
  9252. if (vRatio(u, v) >= 1) {
  9253. dTheta = 0;
  9254. }
  9255. if (dTheta < 0) {
  9256. var n = Math.round(dTheta / PI$1 * 1e6) / 1e6;
  9257. dTheta = PI$1 * 2 + (n % 2) * PI$1;
  9258. }
  9259. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  9260. }
  9261. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  9262. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  9263. function createPathProxyFromString(data) {
  9264. var path = new PathProxy();
  9265. if (!data) {
  9266. return path;
  9267. }
  9268. var cpx = 0;
  9269. var cpy = 0;
  9270. var subpathX = cpx;
  9271. var subpathY = cpy;
  9272. var prevCmd;
  9273. var CMD = PathProxy.CMD;
  9274. var cmdList = data.match(commandReg);
  9275. if (!cmdList) {
  9276. return path;
  9277. }
  9278. for (var l = 0; l < cmdList.length; l++) {
  9279. var cmdText = cmdList[l];
  9280. var cmdStr = cmdText.charAt(0);
  9281. var cmd = void 0;
  9282. var p = cmdText.match(numberReg) || [];
  9283. var pLen = p.length;
  9284. for (var i = 0; i < pLen; i++) {
  9285. p[i] = parseFloat(p[i]);
  9286. }
  9287. var off = 0;
  9288. while (off < pLen) {
  9289. var ctlPtx = void 0;
  9290. var ctlPty = void 0;
  9291. var rx = void 0;
  9292. var ry = void 0;
  9293. var psi = void 0;
  9294. var fa = void 0;
  9295. var fs = void 0;
  9296. var x1 = cpx;
  9297. var y1 = cpy;
  9298. var len = void 0;
  9299. var pathData = void 0;
  9300. switch (cmdStr) {
  9301. case 'l':
  9302. cpx += p[off++];
  9303. cpy += p[off++];
  9304. cmd = CMD.L;
  9305. path.addData(cmd, cpx, cpy);
  9306. break;
  9307. case 'L':
  9308. cpx = p[off++];
  9309. cpy = p[off++];
  9310. cmd = CMD.L;
  9311. path.addData(cmd, cpx, cpy);
  9312. break;
  9313. case 'm':
  9314. cpx += p[off++];
  9315. cpy += p[off++];
  9316. cmd = CMD.M;
  9317. path.addData(cmd, cpx, cpy);
  9318. subpathX = cpx;
  9319. subpathY = cpy;
  9320. cmdStr = 'l';
  9321. break;
  9322. case 'M':
  9323. cpx = p[off++];
  9324. cpy = p[off++];
  9325. cmd = CMD.M;
  9326. path.addData(cmd, cpx, cpy);
  9327. subpathX = cpx;
  9328. subpathY = cpy;
  9329. cmdStr = 'L';
  9330. break;
  9331. case 'h':
  9332. cpx += p[off++];
  9333. cmd = CMD.L;
  9334. path.addData(cmd, cpx, cpy);
  9335. break;
  9336. case 'H':
  9337. cpx = p[off++];
  9338. cmd = CMD.L;
  9339. path.addData(cmd, cpx, cpy);
  9340. break;
  9341. case 'v':
  9342. cpy += p[off++];
  9343. cmd = CMD.L;
  9344. path.addData(cmd, cpx, cpy);
  9345. break;
  9346. case 'V':
  9347. cpy = p[off++];
  9348. cmd = CMD.L;
  9349. path.addData(cmd, cpx, cpy);
  9350. break;
  9351. case 'C':
  9352. cmd = CMD.C;
  9353. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  9354. cpx = p[off - 2];
  9355. cpy = p[off - 1];
  9356. break;
  9357. case 'c':
  9358. cmd = CMD.C;
  9359. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  9360. cpx += p[off - 2];
  9361. cpy += p[off - 1];
  9362. break;
  9363. case 'S':
  9364. ctlPtx = cpx;
  9365. ctlPty = cpy;
  9366. len = path.len();
  9367. pathData = path.data;
  9368. if (prevCmd === CMD.C) {
  9369. ctlPtx += cpx - pathData[len - 4];
  9370. ctlPty += cpy - pathData[len - 3];
  9371. }
  9372. cmd = CMD.C;
  9373. x1 = p[off++];
  9374. y1 = p[off++];
  9375. cpx = p[off++];
  9376. cpy = p[off++];
  9377. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9378. break;
  9379. case 's':
  9380. ctlPtx = cpx;
  9381. ctlPty = cpy;
  9382. len = path.len();
  9383. pathData = path.data;
  9384. if (prevCmd === CMD.C) {
  9385. ctlPtx += cpx - pathData[len - 4];
  9386. ctlPty += cpy - pathData[len - 3];
  9387. }
  9388. cmd = CMD.C;
  9389. x1 = cpx + p[off++];
  9390. y1 = cpy + p[off++];
  9391. cpx += p[off++];
  9392. cpy += p[off++];
  9393. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9394. break;
  9395. case 'Q':
  9396. x1 = p[off++];
  9397. y1 = p[off++];
  9398. cpx = p[off++];
  9399. cpy = p[off++];
  9400. cmd = CMD.Q;
  9401. path.addData(cmd, x1, y1, cpx, cpy);
  9402. break;
  9403. case 'q':
  9404. x1 = p[off++] + cpx;
  9405. y1 = p[off++] + cpy;
  9406. cpx += p[off++];
  9407. cpy += p[off++];
  9408. cmd = CMD.Q;
  9409. path.addData(cmd, x1, y1, cpx, cpy);
  9410. break;
  9411. case 'T':
  9412. ctlPtx = cpx;
  9413. ctlPty = cpy;
  9414. len = path.len();
  9415. pathData = path.data;
  9416. if (prevCmd === CMD.Q) {
  9417. ctlPtx += cpx - pathData[len - 4];
  9418. ctlPty += cpy - pathData[len - 3];
  9419. }
  9420. cpx = p[off++];
  9421. cpy = p[off++];
  9422. cmd = CMD.Q;
  9423. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9424. break;
  9425. case 't':
  9426. ctlPtx = cpx;
  9427. ctlPty = cpy;
  9428. len = path.len();
  9429. pathData = path.data;
  9430. if (prevCmd === CMD.Q) {
  9431. ctlPtx += cpx - pathData[len - 4];
  9432. ctlPty += cpy - pathData[len - 3];
  9433. }
  9434. cpx += p[off++];
  9435. cpy += p[off++];
  9436. cmd = CMD.Q;
  9437. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9438. break;
  9439. case 'A':
  9440. rx = p[off++];
  9441. ry = p[off++];
  9442. psi = p[off++];
  9443. fa = p[off++];
  9444. fs = p[off++];
  9445. x1 = cpx, y1 = cpy;
  9446. cpx = p[off++];
  9447. cpy = p[off++];
  9448. cmd = CMD.A;
  9449. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9450. break;
  9451. case 'a':
  9452. rx = p[off++];
  9453. ry = p[off++];
  9454. psi = p[off++];
  9455. fa = p[off++];
  9456. fs = p[off++];
  9457. x1 = cpx, y1 = cpy;
  9458. cpx += p[off++];
  9459. cpy += p[off++];
  9460. cmd = CMD.A;
  9461. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9462. break;
  9463. }
  9464. }
  9465. if (cmdStr === 'z' || cmdStr === 'Z') {
  9466. cmd = CMD.Z;
  9467. path.addData(cmd);
  9468. cpx = subpathX;
  9469. cpy = subpathY;
  9470. }
  9471. prevCmd = cmd;
  9472. }
  9473. path.toStatic();
  9474. return path;
  9475. }
  9476. var SVGPath = (function (_super) {
  9477. __extends(SVGPath, _super);
  9478. function SVGPath() {
  9479. return _super !== null && _super.apply(this, arguments) || this;
  9480. }
  9481. SVGPath.prototype.applyTransform = function (m) { };
  9482. return SVGPath;
  9483. }(Path));
  9484. function isPathProxy(path) {
  9485. return path.setData != null;
  9486. }
  9487. function createPathOptions(str, opts) {
  9488. var pathProxy = createPathProxyFromString(str);
  9489. var innerOpts = extend({}, opts);
  9490. innerOpts.buildPath = function (path) {
  9491. if (isPathProxy(path)) {
  9492. path.setData(pathProxy.data);
  9493. var ctx = path.getContext();
  9494. if (ctx) {
  9495. path.rebuildPath(ctx, 1);
  9496. }
  9497. }
  9498. else {
  9499. var ctx = path;
  9500. pathProxy.rebuildPath(ctx, 1);
  9501. }
  9502. };
  9503. innerOpts.applyTransform = function (m) {
  9504. transformPath(pathProxy, m);
  9505. this.dirtyShape();
  9506. };
  9507. return innerOpts;
  9508. }
  9509. function createFromString(str, opts) {
  9510. return new SVGPath(createPathOptions(str, opts));
  9511. }
  9512. function extendFromString(str, defaultOpts) {
  9513. var innerOpts = createPathOptions(str, defaultOpts);
  9514. var Sub = (function (_super) {
  9515. __extends(Sub, _super);
  9516. function Sub(opts) {
  9517. var _this = _super.call(this, opts) || this;
  9518. _this.applyTransform = innerOpts.applyTransform;
  9519. _this.buildPath = innerOpts.buildPath;
  9520. return _this;
  9521. }
  9522. return Sub;
  9523. }(SVGPath));
  9524. return Sub;
  9525. }
  9526. function mergePath(pathEls, opts) {
  9527. var pathList = [];
  9528. var len = pathEls.length;
  9529. for (var i = 0; i < len; i++) {
  9530. var pathEl = pathEls[i];
  9531. pathList.push(pathEl.getUpdatedPathProxy(true));
  9532. }
  9533. var pathBundle = new Path(opts);
  9534. pathBundle.createPathProxy();
  9535. pathBundle.buildPath = function (path) {
  9536. if (isPathProxy(path)) {
  9537. path.appendPath(pathList);
  9538. var ctx = path.getContext();
  9539. if (ctx) {
  9540. path.rebuildPath(ctx, 1);
  9541. }
  9542. }
  9543. };
  9544. return pathBundle;
  9545. }
  9546. function clonePath(sourcePath, opts) {
  9547. opts = opts || {};
  9548. var path = new Path();
  9549. if (sourcePath.shape) {
  9550. path.setShape(sourcePath.shape);
  9551. }
  9552. path.setStyle(sourcePath.style);
  9553. if (opts.bakeTransform) {
  9554. transformPath(path.path, sourcePath.getComputedTransform());
  9555. }
  9556. else {
  9557. if (opts.toLocal) {
  9558. path.setLocalTransform(sourcePath.getComputedTransform());
  9559. }
  9560. else {
  9561. path.copyTransform(sourcePath);
  9562. }
  9563. }
  9564. path.buildPath = sourcePath.buildPath;
  9565. path.applyTransform = path.applyTransform;
  9566. path.z = sourcePath.z;
  9567. path.z2 = sourcePath.z2;
  9568. path.zlevel = sourcePath.zlevel;
  9569. return path;
  9570. }
  9571. var path = /*#__PURE__*/Object.freeze({
  9572. __proto__: null,
  9573. createFromString: createFromString,
  9574. extendFromString: extendFromString,
  9575. mergePath: mergePath,
  9576. clonePath: clonePath
  9577. });
  9578. var DEFAULT_IMAGE_STYLE = defaults({
  9579. x: 0,
  9580. y: 0
  9581. }, DEFAULT_COMMON_STYLE);
  9582. var DEFAULT_IMAGE_ANIMATION_PROPS = {
  9583. style: defaults({
  9584. x: true,
  9585. y: true,
  9586. width: true,
  9587. height: true,
  9588. sx: true,
  9589. sy: true,
  9590. sWidth: true,
  9591. sHeight: true
  9592. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  9593. };
  9594. function isImageLike(source) {
  9595. return !!(source
  9596. && typeof source !== 'string'
  9597. && source.width && source.height);
  9598. }
  9599. var ZRImage = (function (_super) {
  9600. __extends(ZRImage, _super);
  9601. function ZRImage() {
  9602. return _super !== null && _super.apply(this, arguments) || this;
  9603. }
  9604. ZRImage.prototype.createStyle = function (obj) {
  9605. return createObject(DEFAULT_IMAGE_STYLE, obj);
  9606. };
  9607. ZRImage.prototype._getSize = function (dim) {
  9608. var style = this.style;
  9609. var size = style[dim];
  9610. if (size != null) {
  9611. return size;
  9612. }
  9613. var imageSource = isImageLike(style.image)
  9614. ? style.image : this.__image;
  9615. if (!imageSource) {
  9616. return 0;
  9617. }
  9618. var otherDim = dim === 'width' ? 'height' : 'width';
  9619. var otherDimSize = style[otherDim];
  9620. if (otherDimSize == null) {
  9621. return imageSource[dim];
  9622. }
  9623. else {
  9624. return imageSource[dim] / imageSource[otherDim] * otherDimSize;
  9625. }
  9626. };
  9627. ZRImage.prototype.getWidth = function () {
  9628. return this._getSize('width');
  9629. };
  9630. ZRImage.prototype.getHeight = function () {
  9631. return this._getSize('height');
  9632. };
  9633. ZRImage.prototype.getAnimationStyleProps = function () {
  9634. return DEFAULT_IMAGE_ANIMATION_PROPS;
  9635. };
  9636. ZRImage.prototype.getBoundingRect = function () {
  9637. var style = this.style;
  9638. if (!this._rect) {
  9639. this._rect = new BoundingRect(style.x || 0, style.y || 0, this.getWidth(), this.getHeight());
  9640. }
  9641. return this._rect;
  9642. };
  9643. return ZRImage;
  9644. }(Displayable));
  9645. ZRImage.prototype.type = 'image';
  9646. var CircleShape = (function () {
  9647. function CircleShape() {
  9648. this.cx = 0;
  9649. this.cy = 0;
  9650. this.r = 0;
  9651. }
  9652. return CircleShape;
  9653. }());
  9654. var Circle = (function (_super) {
  9655. __extends(Circle, _super);
  9656. function Circle(opts) {
  9657. return _super.call(this, opts) || this;
  9658. }
  9659. Circle.prototype.getDefaultShape = function () {
  9660. return new CircleShape();
  9661. };
  9662. Circle.prototype.buildPath = function (ctx, shape) {
  9663. ctx.moveTo(shape.cx + shape.r, shape.cy);
  9664. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2);
  9665. };
  9666. return Circle;
  9667. }(Path));
  9668. Circle.prototype.type = 'circle';
  9669. function buildPath(ctx, shape) {
  9670. var x = shape.x;
  9671. var y = shape.y;
  9672. var width = shape.width;
  9673. var height = shape.height;
  9674. var r = shape.r;
  9675. var r1;
  9676. var r2;
  9677. var r3;
  9678. var r4;
  9679. if (width < 0) {
  9680. x = x + width;
  9681. width = -width;
  9682. }
  9683. if (height < 0) {
  9684. y = y + height;
  9685. height = -height;
  9686. }
  9687. if (typeof r === 'number') {
  9688. r1 = r2 = r3 = r4 = r;
  9689. }
  9690. else if (r instanceof Array) {
  9691. if (r.length === 1) {
  9692. r1 = r2 = r3 = r4 = r[0];
  9693. }
  9694. else if (r.length === 2) {
  9695. r1 = r3 = r[0];
  9696. r2 = r4 = r[1];
  9697. }
  9698. else if (r.length === 3) {
  9699. r1 = r[0];
  9700. r2 = r4 = r[1];
  9701. r3 = r[2];
  9702. }
  9703. else {
  9704. r1 = r[0];
  9705. r2 = r[1];
  9706. r3 = r[2];
  9707. r4 = r[3];
  9708. }
  9709. }
  9710. else {
  9711. r1 = r2 = r3 = r4 = 0;
  9712. }
  9713. var total;
  9714. if (r1 + r2 > width) {
  9715. total = r1 + r2;
  9716. r1 *= width / total;
  9717. r2 *= width / total;
  9718. }
  9719. if (r3 + r4 > width) {
  9720. total = r3 + r4;
  9721. r3 *= width / total;
  9722. r4 *= width / total;
  9723. }
  9724. if (r2 + r3 > height) {
  9725. total = r2 + r3;
  9726. r2 *= height / total;
  9727. r3 *= height / total;
  9728. }
  9729. if (r1 + r4 > height) {
  9730. total = r1 + r4;
  9731. r1 *= height / total;
  9732. r4 *= height / total;
  9733. }
  9734. ctx.moveTo(x + r1, y);
  9735. ctx.lineTo(x + width - r2, y);
  9736. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  9737. ctx.lineTo(x + width, y + height - r3);
  9738. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  9739. ctx.lineTo(x + r4, y + height);
  9740. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  9741. ctx.lineTo(x, y + r1);
  9742. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  9743. }
  9744. var round = Math.round;
  9745. function subPixelOptimizeLine(outputShape, inputShape, style) {
  9746. if (!inputShape) {
  9747. return;
  9748. }
  9749. var x1 = inputShape.x1;
  9750. var x2 = inputShape.x2;
  9751. var y1 = inputShape.y1;
  9752. var y2 = inputShape.y2;
  9753. outputShape.x1 = x1;
  9754. outputShape.x2 = x2;
  9755. outputShape.y1 = y1;
  9756. outputShape.y2 = y2;
  9757. var lineWidth = style && style.lineWidth;
  9758. if (!lineWidth) {
  9759. return outputShape;
  9760. }
  9761. if (round(x1 * 2) === round(x2 * 2)) {
  9762. outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true);
  9763. }
  9764. if (round(y1 * 2) === round(y2 * 2)) {
  9765. outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true);
  9766. }
  9767. return outputShape;
  9768. }
  9769. function subPixelOptimizeRect(outputShape, inputShape, style) {
  9770. if (!inputShape) {
  9771. return;
  9772. }
  9773. var originX = inputShape.x;
  9774. var originY = inputShape.y;
  9775. var originWidth = inputShape.width;
  9776. var originHeight = inputShape.height;
  9777. outputShape.x = originX;
  9778. outputShape.y = originY;
  9779. outputShape.width = originWidth;
  9780. outputShape.height = originHeight;
  9781. var lineWidth = style && style.lineWidth;
  9782. if (!lineWidth) {
  9783. return outputShape;
  9784. }
  9785. outputShape.x = subPixelOptimize(originX, lineWidth, true);
  9786. outputShape.y = subPixelOptimize(originY, lineWidth, true);
  9787. outputShape.width = Math.max(subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
  9788. outputShape.height = Math.max(subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
  9789. return outputShape;
  9790. }
  9791. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  9792. if (!lineWidth) {
  9793. return position;
  9794. }
  9795. var doubledPosition = round(position * 2);
  9796. return (doubledPosition + round(lineWidth)) % 2 === 0
  9797. ? doubledPosition / 2
  9798. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  9799. }
  9800. var RectShape = (function () {
  9801. function RectShape() {
  9802. this.x = 0;
  9803. this.y = 0;
  9804. this.width = 0;
  9805. this.height = 0;
  9806. }
  9807. return RectShape;
  9808. }());
  9809. var subPixelOptimizeOutputShape = {};
  9810. var Rect = (function (_super) {
  9811. __extends(Rect, _super);
  9812. function Rect(opts) {
  9813. return _super.call(this, opts) || this;
  9814. }
  9815. Rect.prototype.getDefaultShape = function () {
  9816. return new RectShape();
  9817. };
  9818. Rect.prototype.buildPath = function (ctx, shape) {
  9819. var x;
  9820. var y;
  9821. var width;
  9822. var height;
  9823. if (this.subPixelOptimize) {
  9824. var optimizedShape = subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style);
  9825. x = optimizedShape.x;
  9826. y = optimizedShape.y;
  9827. width = optimizedShape.width;
  9828. height = optimizedShape.height;
  9829. optimizedShape.r = shape.r;
  9830. shape = optimizedShape;
  9831. }
  9832. else {
  9833. x = shape.x;
  9834. y = shape.y;
  9835. width = shape.width;
  9836. height = shape.height;
  9837. }
  9838. if (!shape.r) {
  9839. ctx.rect(x, y, width, height);
  9840. }
  9841. else {
  9842. buildPath(ctx, shape);
  9843. }
  9844. };
  9845. Rect.prototype.isZeroArea = function () {
  9846. return !this.shape.width || !this.shape.height;
  9847. };
  9848. return Rect;
  9849. }(Path));
  9850. Rect.prototype.type = 'rect';
  9851. var EllipseShape = (function () {
  9852. function EllipseShape() {
  9853. this.cx = 0;
  9854. this.cy = 0;
  9855. this.rx = 0;
  9856. this.ry = 0;
  9857. }
  9858. return EllipseShape;
  9859. }());
  9860. var Ellipse = (function (_super) {
  9861. __extends(Ellipse, _super);
  9862. function Ellipse(opts) {
  9863. return _super.call(this, opts) || this;
  9864. }
  9865. Ellipse.prototype.getDefaultShape = function () {
  9866. return new EllipseShape();
  9867. };
  9868. Ellipse.prototype.buildPath = function (ctx, shape) {
  9869. var k = 0.5522848;
  9870. var x = shape.cx;
  9871. var y = shape.cy;
  9872. var a = shape.rx;
  9873. var b = shape.ry;
  9874. var ox = a * k;
  9875. var oy = b * k;
  9876. ctx.moveTo(x - a, y);
  9877. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  9878. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  9879. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  9880. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  9881. ctx.closePath();
  9882. };
  9883. return Ellipse;
  9884. }(Path));
  9885. Ellipse.prototype.type = 'ellipse';
  9886. var subPixelOptimizeOutputShape$1 = {};
  9887. var LineShape = (function () {
  9888. function LineShape() {
  9889. this.x1 = 0;
  9890. this.y1 = 0;
  9891. this.x2 = 0;
  9892. this.y2 = 0;
  9893. this.percent = 1;
  9894. }
  9895. return LineShape;
  9896. }());
  9897. var Line = (function (_super) {
  9898. __extends(Line, _super);
  9899. function Line(opts) {
  9900. return _super.call(this, opts) || this;
  9901. }
  9902. Line.prototype.getDefaultStyle = function () {
  9903. return {
  9904. stroke: '#000',
  9905. fill: null
  9906. };
  9907. };
  9908. Line.prototype.getDefaultShape = function () {
  9909. return new LineShape();
  9910. };
  9911. Line.prototype.buildPath = function (ctx, shape) {
  9912. var x1;
  9913. var y1;
  9914. var x2;
  9915. var y2;
  9916. if (this.subPixelOptimize) {
  9917. var optimizedShape = subPixelOptimizeLine(subPixelOptimizeOutputShape$1, shape, this.style);
  9918. x1 = optimizedShape.x1;
  9919. y1 = optimizedShape.y1;
  9920. x2 = optimizedShape.x2;
  9921. y2 = optimizedShape.y2;
  9922. }
  9923. else {
  9924. x1 = shape.x1;
  9925. y1 = shape.y1;
  9926. x2 = shape.x2;
  9927. y2 = shape.y2;
  9928. }
  9929. var percent = shape.percent;
  9930. if (percent === 0) {
  9931. return;
  9932. }
  9933. ctx.moveTo(x1, y1);
  9934. if (percent < 1) {
  9935. x2 = x1 * (1 - percent) + x2 * percent;
  9936. y2 = y1 * (1 - percent) + y2 * percent;
  9937. }
  9938. ctx.lineTo(x2, y2);
  9939. };
  9940. Line.prototype.pointAt = function (p) {
  9941. var shape = this.shape;
  9942. return [
  9943. shape.x1 * (1 - p) + shape.x2 * p,
  9944. shape.y1 * (1 - p) + shape.y2 * p
  9945. ];
  9946. };
  9947. return Line;
  9948. }(Path));
  9949. Line.prototype.type = 'line';
  9950. function smoothBezier(points, smooth, isLoop, constraint) {
  9951. var cps = [];
  9952. var v = [];
  9953. var v1 = [];
  9954. var v2 = [];
  9955. var prevPoint;
  9956. var nextPoint;
  9957. var min$1;
  9958. var max$1;
  9959. if (constraint) {
  9960. min$1 = [Infinity, Infinity];
  9961. max$1 = [-Infinity, -Infinity];
  9962. for (var i = 0, len = points.length; i < len; i++) {
  9963. min(min$1, min$1, points[i]);
  9964. max(max$1, max$1, points[i]);
  9965. }
  9966. min(min$1, min$1, constraint[0]);
  9967. max(max$1, max$1, constraint[1]);
  9968. }
  9969. for (var i = 0, len = points.length; i < len; i++) {
  9970. var point = points[i];
  9971. if (isLoop) {
  9972. prevPoint = points[i ? i - 1 : len - 1];
  9973. nextPoint = points[(i + 1) % len];
  9974. }
  9975. else {
  9976. if (i === 0 || i === len - 1) {
  9977. cps.push(clone$1(points[i]));
  9978. continue;
  9979. }
  9980. else {
  9981. prevPoint = points[i - 1];
  9982. nextPoint = points[i + 1];
  9983. }
  9984. }
  9985. sub(v, nextPoint, prevPoint);
  9986. scale(v, v, smooth);
  9987. var d0 = distance(point, prevPoint);
  9988. var d1 = distance(point, nextPoint);
  9989. var sum = d0 + d1;
  9990. if (sum !== 0) {
  9991. d0 /= sum;
  9992. d1 /= sum;
  9993. }
  9994. scale(v1, v, -d0);
  9995. scale(v2, v, d1);
  9996. var cp0 = add([], point, v1);
  9997. var cp1 = add([], point, v2);
  9998. if (constraint) {
  9999. max(cp0, cp0, min$1);
  10000. min(cp0, cp0, max$1);
  10001. max(cp1, cp1, min$1);
  10002. min(cp1, cp1, max$1);
  10003. }
  10004. cps.push(cp0);
  10005. cps.push(cp1);
  10006. }
  10007. if (isLoop) {
  10008. cps.push(cps.shift());
  10009. }
  10010. return cps;
  10011. }
  10012. function buildPath$1(ctx, shape, closePath) {
  10013. var smooth = shape.smooth;
  10014. var points = shape.points;
  10015. if (points && points.length >= 2) {
  10016. if (smooth) {
  10017. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  10018. ctx.moveTo(points[0][0], points[0][1]);
  10019. var len = points.length;
  10020. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  10021. var cp1 = controlPoints[i * 2];
  10022. var cp2 = controlPoints[i * 2 + 1];
  10023. var p = points[(i + 1) % len];
  10024. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  10025. }
  10026. }
  10027. else {
  10028. ctx.moveTo(points[0][0], points[0][1]);
  10029. for (var i = 1, l = points.length; i < l; i++) {
  10030. ctx.lineTo(points[i][0], points[i][1]);
  10031. }
  10032. }
  10033. closePath && ctx.closePath();
  10034. }
  10035. }
  10036. var PolygonShape = (function () {
  10037. function PolygonShape() {
  10038. this.points = null;
  10039. this.smooth = 0;
  10040. this.smoothConstraint = null;
  10041. }
  10042. return PolygonShape;
  10043. }());
  10044. var Polygon = (function (_super) {
  10045. __extends(Polygon, _super);
  10046. function Polygon(opts) {
  10047. return _super.call(this, opts) || this;
  10048. }
  10049. Polygon.prototype.getDefaultShape = function () {
  10050. return new PolygonShape();
  10051. };
  10052. Polygon.prototype.buildPath = function (ctx, shape) {
  10053. buildPath$1(ctx, shape, true);
  10054. };
  10055. return Polygon;
  10056. }(Path));
  10057. Polygon.prototype.type = 'polygon';
  10058. var PolylineShape = (function () {
  10059. function PolylineShape() {
  10060. this.points = null;
  10061. this.percent = 1;
  10062. this.smooth = 0;
  10063. this.smoothConstraint = null;
  10064. }
  10065. return PolylineShape;
  10066. }());
  10067. var Polyline = (function (_super) {
  10068. __extends(Polyline, _super);
  10069. function Polyline(opts) {
  10070. return _super.call(this, opts) || this;
  10071. }
  10072. Polyline.prototype.getDefaultStyle = function () {
  10073. return {
  10074. stroke: '#000',
  10075. fill: null
  10076. };
  10077. };
  10078. Polyline.prototype.getDefaultShape = function () {
  10079. return new PolylineShape();
  10080. };
  10081. Polyline.prototype.buildPath = function (ctx, shape) {
  10082. buildPath$1(ctx, shape, false);
  10083. };
  10084. return Polyline;
  10085. }(Path));
  10086. Polyline.prototype.type = 'polyline';
  10087. var Gradient = (function () {
  10088. function Gradient(colorStops) {
  10089. this.colorStops = colorStops || [];
  10090. }
  10091. Gradient.prototype.addColorStop = function (offset, color) {
  10092. this.colorStops.push({
  10093. offset: offset,
  10094. color: color
  10095. });
  10096. };
  10097. return Gradient;
  10098. }());
  10099. var LinearGradient = (function (_super) {
  10100. __extends(LinearGradient, _super);
  10101. function LinearGradient(x, y, x2, y2, colorStops, globalCoord) {
  10102. var _this = _super.call(this, colorStops) || this;
  10103. _this.x = x == null ? 0 : x;
  10104. _this.y = y == null ? 0 : y;
  10105. _this.x2 = x2 == null ? 1 : x2;
  10106. _this.y2 = y2 == null ? 0 : y2;
  10107. _this.type = 'linear';
  10108. _this.global = globalCoord || false;
  10109. return _this;
  10110. }
  10111. return LinearGradient;
  10112. }(Gradient));
  10113. var RadialGradient = (function (_super) {
  10114. __extends(RadialGradient, _super);
  10115. function RadialGradient(x, y, r, colorStops, globalCoord) {
  10116. var _this = _super.call(this, colorStops) || this;
  10117. _this.x = x == null ? 0.5 : x;
  10118. _this.y = y == null ? 0.5 : y;
  10119. _this.r = r == null ? 0.5 : r;
  10120. _this.type = 'radial';
  10121. _this.global = globalCoord || false;
  10122. return _this;
  10123. }
  10124. return RadialGradient;
  10125. }(Gradient));
  10126. var DEFAULT_TSPAN_STYLE = defaults({
  10127. strokeFirst: true,
  10128. font: DEFAULT_FONT,
  10129. x: 0,
  10130. y: 0,
  10131. textAlign: 'left',
  10132. textBaseline: 'top',
  10133. miterLimit: 2
  10134. }, DEFAULT_PATH_STYLE);
  10135. var TSpan = (function (_super) {
  10136. __extends(TSpan, _super);
  10137. function TSpan() {
  10138. return _super !== null && _super.apply(this, arguments) || this;
  10139. }
  10140. TSpan.prototype.hasStroke = function () {
  10141. var style = this.style;
  10142. var stroke = style.stroke;
  10143. return stroke != null && stroke !== 'none' && style.lineWidth > 0;
  10144. };
  10145. TSpan.prototype.hasFill = function () {
  10146. var style = this.style;
  10147. var fill = style.fill;
  10148. return fill != null && fill !== 'none';
  10149. };
  10150. TSpan.prototype.createStyle = function (obj) {
  10151. return createObject(DEFAULT_TSPAN_STYLE, obj);
  10152. };
  10153. TSpan.prototype.setBoundingRect = function (rect) {
  10154. this._rect = rect;
  10155. };
  10156. TSpan.prototype.getBoundingRect = function () {
  10157. var style = this.style;
  10158. if (!this._rect) {
  10159. var text = style.text;
  10160. text != null ? (text += '') : (text = '');
  10161. var rect = getBoundingRect(text, style.font, style.textAlign, style.textBaseline);
  10162. rect.x += style.x || 0;
  10163. rect.y += style.y || 0;
  10164. if (this.hasStroke()) {
  10165. var w = style.lineWidth;
  10166. rect.x -= w / 2;
  10167. rect.y -= w / 2;
  10168. rect.width += w;
  10169. rect.height += w;
  10170. }
  10171. this._rect = rect;
  10172. }
  10173. return this._rect;
  10174. };
  10175. TSpan.initDefaultProps = (function () {
  10176. var tspanProto = TSpan.prototype;
  10177. tspanProto.dirtyRectTolerance = 10;
  10178. })();
  10179. return TSpan;
  10180. }(Displayable));
  10181. TSpan.prototype.type = 'tspan';
  10182. function parseXML(svg) {
  10183. if (isString(svg)) {
  10184. var parser = new DOMParser();
  10185. svg = parser.parseFromString(svg, 'text/xml');
  10186. }
  10187. var svgNode = svg;
  10188. if (svgNode.nodeType === 9) {
  10189. svgNode = svgNode.firstChild;
  10190. }
  10191. while (svgNode.nodeName.toLowerCase() !== 'svg' || svgNode.nodeType !== 1) {
  10192. svgNode = svgNode.nextSibling;
  10193. }
  10194. return svgNode;
  10195. }
  10196. var nodeParsers;
  10197. var INHERITABLE_STYLE_ATTRIBUTES_MAP = {
  10198. 'fill': 'fill',
  10199. 'stroke': 'stroke',
  10200. 'stroke-width': 'lineWidth',
  10201. 'opacity': 'opacity',
  10202. 'fill-opacity': 'fillOpacity',
  10203. 'stroke-opacity': 'strokeOpacity',
  10204. 'stroke-dasharray': 'lineDash',
  10205. 'stroke-dashoffset': 'lineDashOffset',
  10206. 'stroke-linecap': 'lineCap',
  10207. 'stroke-linejoin': 'lineJoin',
  10208. 'stroke-miterlimit': 'miterLimit',
  10209. 'font-family': 'fontFamily',
  10210. 'font-size': 'fontSize',
  10211. 'font-style': 'fontStyle',
  10212. 'font-weight': 'fontWeight',
  10213. 'text-anchor': 'textAlign',
  10214. 'visibility': 'visibility',
  10215. 'display': 'display'
  10216. };
  10217. var INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS = keys(INHERITABLE_STYLE_ATTRIBUTES_MAP);
  10218. var SELF_STYLE_ATTRIBUTES_MAP = {
  10219. 'alignment-baseline': 'textBaseline',
  10220. 'stop-color': 'stopColor'
  10221. };
  10222. var SELF_STYLE_ATTRIBUTES_MAP_KEYS = keys(SELF_STYLE_ATTRIBUTES_MAP);
  10223. var SVGParser = (function () {
  10224. function SVGParser() {
  10225. this._defs = {};
  10226. this._root = null;
  10227. }
  10228. SVGParser.prototype.parse = function (xml, opt) {
  10229. opt = opt || {};
  10230. var svg = parseXML(xml);
  10231. {
  10232. if (!svg) {
  10233. throw new Error('Illegal svg');
  10234. }
  10235. }
  10236. this._defsUsePending = [];
  10237. var root = new Group();
  10238. this._root = root;
  10239. var named = [];
  10240. var viewBox = svg.getAttribute('viewBox') || '';
  10241. var width = parseFloat((svg.getAttribute('width') || opt.width));
  10242. var height = parseFloat((svg.getAttribute('height') || opt.height));
  10243. isNaN(width) && (width = null);
  10244. isNaN(height) && (height = null);
  10245. parseAttributes(svg, root, null, true, false);
  10246. var child = svg.firstChild;
  10247. while (child) {
  10248. this._parseNode(child, root, named, null, false, false);
  10249. child = child.nextSibling;
  10250. }
  10251. applyDefs(this._defs, this._defsUsePending);
  10252. this._defsUsePending = [];
  10253. var viewBoxRect;
  10254. var viewBoxTransform;
  10255. if (viewBox) {
  10256. var viewBoxArr = splitNumberSequence(viewBox);
  10257. if (viewBoxArr.length >= 4) {
  10258. viewBoxRect = {
  10259. x: parseFloat((viewBoxArr[0] || 0)),
  10260. y: parseFloat((viewBoxArr[1] || 0)),
  10261. width: parseFloat(viewBoxArr[2]),
  10262. height: parseFloat(viewBoxArr[3])
  10263. };
  10264. }
  10265. }
  10266. if (viewBoxRect && width != null && height != null) {
  10267. viewBoxTransform = makeViewBoxTransform(viewBoxRect, { x: 0, y: 0, width: width, height: height });
  10268. if (!opt.ignoreViewBox) {
  10269. var elRoot = root;
  10270. root = new Group();
  10271. root.add(elRoot);
  10272. elRoot.scaleX = elRoot.scaleY = viewBoxTransform.scale;
  10273. elRoot.x = viewBoxTransform.x;
  10274. elRoot.y = viewBoxTransform.y;
  10275. }
  10276. }
  10277. if (!opt.ignoreRootClip && width != null && height != null) {
  10278. root.setClipPath(new Rect({
  10279. shape: { x: 0, y: 0, width: width, height: height }
  10280. }));
  10281. }
  10282. return {
  10283. root: root,
  10284. width: width,
  10285. height: height,
  10286. viewBoxRect: viewBoxRect,
  10287. viewBoxTransform: viewBoxTransform,
  10288. named: named
  10289. };
  10290. };
  10291. SVGParser.prototype._parseNode = function (xmlNode, parentGroup, named, namedFrom, isInDefs, isInText) {
  10292. var nodeName = xmlNode.nodeName.toLowerCase();
  10293. var el;
  10294. var namedFromForSub = namedFrom;
  10295. if (nodeName === 'defs') {
  10296. isInDefs = true;
  10297. }
  10298. if (nodeName === 'text') {
  10299. isInText = true;
  10300. }
  10301. if (nodeName === 'defs' || nodeName === 'switch') {
  10302. el = parentGroup;
  10303. }
  10304. else {
  10305. if (!isInDefs) {
  10306. var parser_1 = nodeParsers[nodeName];
  10307. if (parser_1 && hasOwn(nodeParsers, nodeName)) {
  10308. el = parser_1.call(this, xmlNode, parentGroup);
  10309. var nameAttr = xmlNode.getAttribute('name');
  10310. if (nameAttr) {
  10311. var newNamed = {
  10312. name: nameAttr,
  10313. namedFrom: null,
  10314. svgNodeTagLower: nodeName,
  10315. el: el
  10316. };
  10317. named.push(newNamed);
  10318. if (nodeName === 'g') {
  10319. namedFromForSub = newNamed;
  10320. }
  10321. }
  10322. else if (namedFrom) {
  10323. named.push({
  10324. name: namedFrom.name,
  10325. namedFrom: namedFrom,
  10326. svgNodeTagLower: nodeName,
  10327. el: el
  10328. });
  10329. }
  10330. parentGroup.add(el);
  10331. }
  10332. }
  10333. var parser = paintServerParsers[nodeName];
  10334. if (parser && hasOwn(paintServerParsers, nodeName)) {
  10335. var def = parser.call(this, xmlNode);
  10336. var id = xmlNode.getAttribute('id');
  10337. if (id) {
  10338. this._defs[id] = def;
  10339. }
  10340. }
  10341. }
  10342. if (el && el.isGroup) {
  10343. var child = xmlNode.firstChild;
  10344. while (child) {
  10345. if (child.nodeType === 1) {
  10346. this._parseNode(child, el, named, namedFromForSub, isInDefs, isInText);
  10347. }
  10348. else if (child.nodeType === 3 && isInText) {
  10349. this._parseText(child, el);
  10350. }
  10351. child = child.nextSibling;
  10352. }
  10353. }
  10354. };
  10355. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  10356. var text = new TSpan({
  10357. style: {
  10358. text: xmlNode.textContent
  10359. },
  10360. silent: true,
  10361. x: this._textX || 0,
  10362. y: this._textY || 0
  10363. });
  10364. inheritStyle(parentGroup, text);
  10365. parseAttributes(xmlNode, text, this._defsUsePending, false, false);
  10366. applyTextAlignment(text, parentGroup);
  10367. var textStyle = text.style;
  10368. var fontSize = textStyle.fontSize;
  10369. if (fontSize && fontSize < 9) {
  10370. textStyle.fontSize = 9;
  10371. text.scaleX *= fontSize / 9;
  10372. text.scaleY *= fontSize / 9;
  10373. }
  10374. var font = (textStyle.fontSize || textStyle.fontFamily) && [
  10375. textStyle.fontStyle,
  10376. textStyle.fontWeight,
  10377. (textStyle.fontSize || 12) + 'px',
  10378. textStyle.fontFamily || 'sans-serif'
  10379. ].join(' ');
  10380. textStyle.font = font;
  10381. var rect = text.getBoundingRect();
  10382. this._textX += rect.width;
  10383. parentGroup.add(text);
  10384. return text;
  10385. };
  10386. SVGParser.internalField = (function () {
  10387. nodeParsers = {
  10388. 'g': function (xmlNode, parentGroup) {
  10389. var g = new Group();
  10390. inheritStyle(parentGroup, g);
  10391. parseAttributes(xmlNode, g, this._defsUsePending, false, false);
  10392. return g;
  10393. },
  10394. 'rect': function (xmlNode, parentGroup) {
  10395. var rect = new Rect();
  10396. inheritStyle(parentGroup, rect);
  10397. parseAttributes(xmlNode, rect, this._defsUsePending, false, false);
  10398. rect.setShape({
  10399. x: parseFloat(xmlNode.getAttribute('x') || '0'),
  10400. y: parseFloat(xmlNode.getAttribute('y') || '0'),
  10401. width: parseFloat(xmlNode.getAttribute('width') || '0'),
  10402. height: parseFloat(xmlNode.getAttribute('height') || '0')
  10403. });
  10404. rect.silent = true;
  10405. return rect;
  10406. },
  10407. 'circle': function (xmlNode, parentGroup) {
  10408. var circle = new Circle();
  10409. inheritStyle(parentGroup, circle);
  10410. parseAttributes(xmlNode, circle, this._defsUsePending, false, false);
  10411. circle.setShape({
  10412. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  10413. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  10414. r: parseFloat(xmlNode.getAttribute('r') || '0')
  10415. });
  10416. circle.silent = true;
  10417. return circle;
  10418. },
  10419. 'line': function (xmlNode, parentGroup) {
  10420. var line = new Line();
  10421. inheritStyle(parentGroup, line);
  10422. parseAttributes(xmlNode, line, this._defsUsePending, false, false);
  10423. line.setShape({
  10424. x1: parseFloat(xmlNode.getAttribute('x1') || '0'),
  10425. y1: parseFloat(xmlNode.getAttribute('y1') || '0'),
  10426. x2: parseFloat(xmlNode.getAttribute('x2') || '0'),
  10427. y2: parseFloat(xmlNode.getAttribute('y2') || '0')
  10428. });
  10429. line.silent = true;
  10430. return line;
  10431. },
  10432. 'ellipse': function (xmlNode, parentGroup) {
  10433. var ellipse = new Ellipse();
  10434. inheritStyle(parentGroup, ellipse);
  10435. parseAttributes(xmlNode, ellipse, this._defsUsePending, false, false);
  10436. ellipse.setShape({
  10437. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  10438. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  10439. rx: parseFloat(xmlNode.getAttribute('rx') || '0'),
  10440. ry: parseFloat(xmlNode.getAttribute('ry') || '0')
  10441. });
  10442. ellipse.silent = true;
  10443. return ellipse;
  10444. },
  10445. 'polygon': function (xmlNode, parentGroup) {
  10446. var pointsStr = xmlNode.getAttribute('points');
  10447. var pointsArr;
  10448. if (pointsStr) {
  10449. pointsArr = parsePoints(pointsStr);
  10450. }
  10451. var polygon = new Polygon({
  10452. shape: {
  10453. points: pointsArr || []
  10454. },
  10455. silent: true
  10456. });
  10457. inheritStyle(parentGroup, polygon);
  10458. parseAttributes(xmlNode, polygon, this._defsUsePending, false, false);
  10459. return polygon;
  10460. },
  10461. 'polyline': function (xmlNode, parentGroup) {
  10462. var pointsStr = xmlNode.getAttribute('points');
  10463. var pointsArr;
  10464. if (pointsStr) {
  10465. pointsArr = parsePoints(pointsStr);
  10466. }
  10467. var polyline = new Polyline({
  10468. shape: {
  10469. points: pointsArr || []
  10470. },
  10471. silent: true
  10472. });
  10473. inheritStyle(parentGroup, polyline);
  10474. parseAttributes(xmlNode, polyline, this._defsUsePending, false, false);
  10475. return polyline;
  10476. },
  10477. 'image': function (xmlNode, parentGroup) {
  10478. var img = new ZRImage();
  10479. inheritStyle(parentGroup, img);
  10480. parseAttributes(xmlNode, img, this._defsUsePending, false, false);
  10481. img.setStyle({
  10482. image: xmlNode.getAttribute('xlink:href') || xmlNode.getAttribute('href'),
  10483. x: +xmlNode.getAttribute('x'),
  10484. y: +xmlNode.getAttribute('y'),
  10485. width: +xmlNode.getAttribute('width'),
  10486. height: +xmlNode.getAttribute('height')
  10487. });
  10488. img.silent = true;
  10489. return img;
  10490. },
  10491. 'text': function (xmlNode, parentGroup) {
  10492. var x = xmlNode.getAttribute('x') || '0';
  10493. var y = xmlNode.getAttribute('y') || '0';
  10494. var dx = xmlNode.getAttribute('dx') || '0';
  10495. var dy = xmlNode.getAttribute('dy') || '0';
  10496. this._textX = parseFloat(x) + parseFloat(dx);
  10497. this._textY = parseFloat(y) + parseFloat(dy);
  10498. var g = new Group();
  10499. inheritStyle(parentGroup, g);
  10500. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  10501. return g;
  10502. },
  10503. 'tspan': function (xmlNode, parentGroup) {
  10504. var x = xmlNode.getAttribute('x');
  10505. var y = xmlNode.getAttribute('y');
  10506. if (x != null) {
  10507. this._textX = parseFloat(x);
  10508. }
  10509. if (y != null) {
  10510. this._textY = parseFloat(y);
  10511. }
  10512. var dx = xmlNode.getAttribute('dx') || '0';
  10513. var dy = xmlNode.getAttribute('dy') || '0';
  10514. var g = new Group();
  10515. inheritStyle(parentGroup, g);
  10516. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  10517. this._textX += parseFloat(dx);
  10518. this._textY += parseFloat(dy);
  10519. return g;
  10520. },
  10521. 'path': function (xmlNode, parentGroup) {
  10522. var d = xmlNode.getAttribute('d') || '';
  10523. var path = createFromString(d);
  10524. inheritStyle(parentGroup, path);
  10525. parseAttributes(xmlNode, path, this._defsUsePending, false, false);
  10526. path.silent = true;
  10527. return path;
  10528. }
  10529. };
  10530. })();
  10531. return SVGParser;
  10532. }());
  10533. var paintServerParsers = {
  10534. 'lineargradient': function (xmlNode) {
  10535. var x1 = parseInt(xmlNode.getAttribute('x1') || '0', 10);
  10536. var y1 = parseInt(xmlNode.getAttribute('y1') || '0', 10);
  10537. var x2 = parseInt(xmlNode.getAttribute('x2') || '10', 10);
  10538. var y2 = parseInt(xmlNode.getAttribute('y2') || '0', 10);
  10539. var gradient = new LinearGradient(x1, y1, x2, y2);
  10540. parsePaintServerUnit(xmlNode, gradient);
  10541. parseGradientColorStops(xmlNode, gradient);
  10542. return gradient;
  10543. },
  10544. 'radialgradient': function (xmlNode) {
  10545. var cx = parseInt(xmlNode.getAttribute('cx') || '0', 10);
  10546. var cy = parseInt(xmlNode.getAttribute('cy') || '0', 10);
  10547. var r = parseInt(xmlNode.getAttribute('r') || '0', 10);
  10548. var gradient = new RadialGradient(cx, cy, r);
  10549. parsePaintServerUnit(xmlNode, gradient);
  10550. parseGradientColorStops(xmlNode, gradient);
  10551. return gradient;
  10552. }
  10553. };
  10554. function parsePaintServerUnit(xmlNode, gradient) {
  10555. var gradientUnits = xmlNode.getAttribute('gradientUnits');
  10556. if (gradientUnits === 'userSpaceOnUse') {
  10557. gradient.global = true;
  10558. }
  10559. }
  10560. function parseGradientColorStops(xmlNode, gradient) {
  10561. var stop = xmlNode.firstChild;
  10562. while (stop) {
  10563. if (stop.nodeType === 1
  10564. && stop.nodeName.toLocaleLowerCase() === 'stop') {
  10565. var offsetStr = stop.getAttribute('offset');
  10566. var offset = void 0;
  10567. if (offsetStr && offsetStr.indexOf('%') > 0) {
  10568. offset = parseInt(offsetStr, 10) / 100;
  10569. }
  10570. else if (offsetStr) {
  10571. offset = parseFloat(offsetStr);
  10572. }
  10573. else {
  10574. offset = 0;
  10575. }
  10576. var styleVals = {};
  10577. parseInlineStyle(stop, styleVals, styleVals);
  10578. var stopColor = styleVals.stopColor
  10579. || stop.getAttribute('stop-color')
  10580. || '#000000';
  10581. gradient.colorStops.push({
  10582. offset: offset,
  10583. color: stopColor
  10584. });
  10585. }
  10586. stop = stop.nextSibling;
  10587. }
  10588. }
  10589. function inheritStyle(parent, child) {
  10590. if (parent && parent.__inheritedStyle) {
  10591. if (!child.__inheritedStyle) {
  10592. child.__inheritedStyle = {};
  10593. }
  10594. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  10595. }
  10596. }
  10597. function parsePoints(pointsString) {
  10598. var list = splitNumberSequence(pointsString);
  10599. var points = [];
  10600. for (var i = 0; i < list.length; i += 2) {
  10601. var x = parseFloat(list[i]);
  10602. var y = parseFloat(list[i + 1]);
  10603. points.push([x, y]);
  10604. }
  10605. return points;
  10606. }
  10607. function parseAttributes(xmlNode, el, defsUsePending, onlyInlineStyle, isTextGroup) {
  10608. var disp = el;
  10609. var inheritedStyle = disp.__inheritedStyle = disp.__inheritedStyle || {};
  10610. var selfStyle = {};
  10611. if (xmlNode.nodeType === 1) {
  10612. parseTransformAttribute(xmlNode, el);
  10613. parseInlineStyle(xmlNode, inheritedStyle, selfStyle);
  10614. if (!onlyInlineStyle) {
  10615. parseAttributeStyle(xmlNode, inheritedStyle, selfStyle);
  10616. }
  10617. }
  10618. disp.style = disp.style || {};
  10619. if (inheritedStyle.fill != null) {
  10620. disp.style.fill = getFillStrokeStyle(disp, 'fill', inheritedStyle.fill, defsUsePending);
  10621. }
  10622. if (inheritedStyle.stroke != null) {
  10623. disp.style.stroke = getFillStrokeStyle(disp, 'stroke', inheritedStyle.stroke, defsUsePending);
  10624. }
  10625. each([
  10626. 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'
  10627. ], function (propName) {
  10628. if (inheritedStyle[propName] != null) {
  10629. disp.style[propName] = parseFloat(inheritedStyle[propName]);
  10630. }
  10631. });
  10632. each([
  10633. 'lineDashOffset', 'lineCap', 'lineJoin', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign'
  10634. ], function (propName) {
  10635. if (inheritedStyle[propName] != null) {
  10636. disp.style[propName] = inheritedStyle[propName];
  10637. }
  10638. });
  10639. if (isTextGroup) {
  10640. disp.__selfStyle = selfStyle;
  10641. }
  10642. if (inheritedStyle.lineDash) {
  10643. disp.style.lineDash = map(splitNumberSequence(inheritedStyle.lineDash), function (str) {
  10644. return parseFloat(str);
  10645. });
  10646. }
  10647. if (inheritedStyle.visibility === 'hidden' || inheritedStyle.visibility === 'collapse') {
  10648. disp.invisible = true;
  10649. }
  10650. if (inheritedStyle.display === 'none') {
  10651. disp.ignore = true;
  10652. }
  10653. }
  10654. function applyTextAlignment(text, parentGroup) {
  10655. var parentSelfStyle = parentGroup.__selfStyle;
  10656. if (parentSelfStyle) {
  10657. var textBaseline = parentSelfStyle.textBaseline;
  10658. var zrTextBaseline = textBaseline;
  10659. if (!textBaseline || textBaseline === 'auto') {
  10660. zrTextBaseline = 'alphabetic';
  10661. }
  10662. else if (textBaseline === 'baseline') {
  10663. zrTextBaseline = 'alphabetic';
  10664. }
  10665. else if (textBaseline === 'before-edge' || textBaseline === 'text-before-edge') {
  10666. zrTextBaseline = 'top';
  10667. }
  10668. else if (textBaseline === 'after-edge' || textBaseline === 'text-after-edge') {
  10669. zrTextBaseline = 'bottom';
  10670. }
  10671. else if (textBaseline === 'central' || textBaseline === 'mathematical') {
  10672. zrTextBaseline = 'middle';
  10673. }
  10674. text.style.textBaseline = zrTextBaseline;
  10675. }
  10676. var parentInheritedStyle = parentGroup.__inheritedStyle;
  10677. if (parentInheritedStyle) {
  10678. var textAlign = parentInheritedStyle.textAlign;
  10679. var zrTextAlign = textAlign;
  10680. if (textAlign) {
  10681. if (textAlign === 'middle') {
  10682. zrTextAlign = 'center';
  10683. }
  10684. text.style.textAlign = zrTextAlign;
  10685. }
  10686. }
  10687. }
  10688. var urlRegex = /^url\(\s*#(.*?)\)/;
  10689. function getFillStrokeStyle(el, method, str, defsUsePending) {
  10690. var urlMatch = str && str.match(urlRegex);
  10691. if (urlMatch) {
  10692. var url = trim(urlMatch[1]);
  10693. defsUsePending.push([el, method, url]);
  10694. return;
  10695. }
  10696. if (str === 'none') {
  10697. str = null;
  10698. }
  10699. return str;
  10700. }
  10701. function applyDefs(defs, defsUsePending) {
  10702. for (var i = 0; i < defsUsePending.length; i++) {
  10703. var item = defsUsePending[i];
  10704. item[0].style[item[1]] = defs[item[2]];
  10705. }
  10706. }
  10707. var numberReg$1 = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  10708. function splitNumberSequence(rawStr) {
  10709. return rawStr.match(numberReg$1) || [];
  10710. }
  10711. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.eE,]*)\)/g;
  10712. var DEGREE_TO_ANGLE = Math.PI / 180;
  10713. function parseTransformAttribute(xmlNode, node) {
  10714. var transform = xmlNode.getAttribute('transform');
  10715. if (transform) {
  10716. transform = transform.replace(/,/g, ' ');
  10717. var transformOps_1 = [];
  10718. var mt = null;
  10719. transform.replace(transformRegex, function (str, type, value) {
  10720. transformOps_1.push(type, value);
  10721. return '';
  10722. });
  10723. for (var i = transformOps_1.length - 1; i > 0; i -= 2) {
  10724. var value = transformOps_1[i];
  10725. var type = transformOps_1[i - 1];
  10726. var valueArr = splitNumberSequence(value);
  10727. mt = mt || create$1();
  10728. switch (type) {
  10729. case 'translate':
  10730. translate(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || '0')]);
  10731. break;
  10732. case 'scale':
  10733. scale$1(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || valueArr[0])]);
  10734. break;
  10735. case 'rotate':
  10736. rotate(mt, mt, -parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10737. break;
  10738. case 'skewX':
  10739. var sx = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10740. mul$1(mt, [1, 0, sx, 1, 0, 0], mt);
  10741. break;
  10742. case 'skewY':
  10743. var sy = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  10744. mul$1(mt, [1, sy, 0, 1, 0, 0], mt);
  10745. break;
  10746. case 'matrix':
  10747. mt[0] = parseFloat(valueArr[0]);
  10748. mt[1] = parseFloat(valueArr[1]);
  10749. mt[2] = parseFloat(valueArr[2]);
  10750. mt[3] = parseFloat(valueArr[3]);
  10751. mt[4] = parseFloat(valueArr[4]);
  10752. mt[5] = parseFloat(valueArr[5]);
  10753. break;
  10754. }
  10755. }
  10756. node.setLocalTransform(mt);
  10757. }
  10758. }
  10759. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  10760. function parseInlineStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  10761. var style = xmlNode.getAttribute('style');
  10762. if (!style) {
  10763. return;
  10764. }
  10765. styleRegex.lastIndex = 0;
  10766. var styleRegResult;
  10767. while ((styleRegResult = styleRegex.exec(style)) != null) {
  10768. var svgStlAttr = styleRegResult[1];
  10769. var zrInheritableStlAttr = hasOwn(INHERITABLE_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  10770. ? INHERITABLE_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  10771. : null;
  10772. if (zrInheritableStlAttr) {
  10773. inheritableStyleResult[zrInheritableStlAttr] = styleRegResult[2];
  10774. }
  10775. var zrSelfStlAttr = hasOwn(SELF_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  10776. ? SELF_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  10777. : null;
  10778. if (zrSelfStlAttr) {
  10779. selfStyleResult[zrSelfStlAttr] = styleRegResult[2];
  10780. }
  10781. }
  10782. }
  10783. function parseAttributeStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  10784. for (var i = 0; i < INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  10785. var svgAttrName = INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS[i];
  10786. var attrValue = xmlNode.getAttribute(svgAttrName);
  10787. if (attrValue != null) {
  10788. inheritableStyleResult[INHERITABLE_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  10789. }
  10790. }
  10791. for (var i = 0; i < SELF_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  10792. var svgAttrName = SELF_STYLE_ATTRIBUTES_MAP_KEYS[i];
  10793. var attrValue = xmlNode.getAttribute(svgAttrName);
  10794. if (attrValue != null) {
  10795. selfStyleResult[SELF_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  10796. }
  10797. }
  10798. }
  10799. function makeViewBoxTransform(viewBoxRect, boundingRect) {
  10800. var scaleX = boundingRect.width / viewBoxRect.width;
  10801. var scaleY = boundingRect.height / viewBoxRect.height;
  10802. var scale = Math.min(scaleX, scaleY);
  10803. return {
  10804. scale: scale,
  10805. x: -(viewBoxRect.x + viewBoxRect.width / 2) * scale + (boundingRect.x + boundingRect.width / 2),
  10806. y: -(viewBoxRect.y + viewBoxRect.height / 2) * scale + (boundingRect.y + boundingRect.height / 2)
  10807. };
  10808. }
  10809. function parseSVG(xml, opt) {
  10810. var parser = new SVGParser();
  10811. return parser.parse(xml, opt);
  10812. }
  10813. var PI$2 = Math.PI;
  10814. var PI2$5 = PI$2 * 2;
  10815. var mathSin$3 = Math.sin;
  10816. var mathCos$3 = Math.cos;
  10817. var mathACos = Math.acos;
  10818. var mathATan2 = Math.atan2;
  10819. var mathAbs$1 = Math.abs;
  10820. var mathSqrt$3 = Math.sqrt;
  10821. var mathMax$3 = Math.max;
  10822. var mathMin$3 = Math.min;
  10823. var e = 1e-4;
  10824. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  10825. var dx10 = x1 - x0;
  10826. var dy10 = y1 - y0;
  10827. var dx32 = x3 - x2;
  10828. var dy32 = y3 - y2;
  10829. var t = dy32 * dx10 - dx32 * dy10;
  10830. if (t * t < e) {
  10831. return;
  10832. }
  10833. t = (dx32 * (y0 - y2) - dy32 * (x0 - x2)) / t;
  10834. return [x0 + t * dx10, y0 + t * dy10];
  10835. }
  10836. function computeCornerTangents(x0, y0, x1, y1, radius, cr, clockwise) {
  10837. var x01 = x0 - x1;
  10838. var y01 = y0 - y1;
  10839. var lo = (clockwise ? cr : -cr) / mathSqrt$3(x01 * x01 + y01 * y01);
  10840. var ox = lo * y01;
  10841. var oy = -lo * x01;
  10842. var x11 = x0 + ox;
  10843. var y11 = y0 + oy;
  10844. var x10 = x1 + ox;
  10845. var y10 = y1 + oy;
  10846. var x00 = (x11 + x10) / 2;
  10847. var y00 = (y11 + y10) / 2;
  10848. var dx = x10 - x11;
  10849. var dy = y10 - y11;
  10850. var d2 = dx * dx + dy * dy;
  10851. var r = radius - cr;
  10852. var s = x11 * y10 - x10 * y11;
  10853. var d = (dy < 0 ? -1 : 1) * mathSqrt$3(mathMax$3(0, r * r * d2 - s * s));
  10854. var cx0 = (s * dy - dx * d) / d2;
  10855. var cy0 = (-s * dx - dy * d) / d2;
  10856. var cx1 = (s * dy + dx * d) / d2;
  10857. var cy1 = (-s * dx + dy * d) / d2;
  10858. var dx0 = cx0 - x00;
  10859. var dy0 = cy0 - y00;
  10860. var dx1 = cx1 - x00;
  10861. var dy1 = cy1 - y00;
  10862. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
  10863. cx0 = cx1;
  10864. cy0 = cy1;
  10865. }
  10866. return {
  10867. cx: cx0,
  10868. cy: cy0,
  10869. x0: -ox,
  10870. y0: -oy,
  10871. x1: cx0 * (radius / r - 1),
  10872. y1: cy0 * (radius / r - 1)
  10873. };
  10874. }
  10875. function normalizeCornerRadius(cr) {
  10876. var arr;
  10877. if (isArray(cr)) {
  10878. var len = cr.length;
  10879. if (!len) {
  10880. return cr;
  10881. }
  10882. if (len === 1) {
  10883. arr = [cr[0], cr[0], 0, 0];
  10884. }
  10885. else if (len === 2) {
  10886. arr = [cr[0], cr[0], cr[1], cr[1]];
  10887. }
  10888. else if (len === 3) {
  10889. arr = cr.concat(cr[2]);
  10890. }
  10891. else {
  10892. arr = cr;
  10893. }
  10894. }
  10895. else {
  10896. arr = [cr, cr, cr, cr];
  10897. }
  10898. return arr;
  10899. }
  10900. function buildPath$2(ctx, shape) {
  10901. var _a;
  10902. var radius = mathMax$3(shape.r, 0);
  10903. var innerRadius = mathMax$3(shape.r0 || 0, 0);
  10904. var hasRadius = radius > 0;
  10905. var hasInnerRadius = innerRadius > 0;
  10906. if (!hasRadius && !hasInnerRadius) {
  10907. return;
  10908. }
  10909. if (!hasRadius) {
  10910. radius = innerRadius;
  10911. innerRadius = 0;
  10912. }
  10913. if (innerRadius > radius) {
  10914. var tmp = radius;
  10915. radius = innerRadius;
  10916. innerRadius = tmp;
  10917. }
  10918. var startAngle = shape.startAngle, endAngle = shape.endAngle;
  10919. if (isNaN(startAngle) || isNaN(endAngle)) {
  10920. return;
  10921. }
  10922. var cx = shape.cx, cy = shape.cy;
  10923. var clockwise = !!shape.clockwise;
  10924. var arc = mathAbs$1(endAngle - startAngle);
  10925. var mod = arc > PI2$5 && arc % PI2$5;
  10926. mod > e && (arc = mod);
  10927. if (!(radius > e)) {
  10928. ctx.moveTo(cx, cy);
  10929. }
  10930. else if (arc > PI2$5 - e) {
  10931. ctx.moveTo(cx + radius * mathCos$3(startAngle), cy + radius * mathSin$3(startAngle));
  10932. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  10933. if (innerRadius > e) {
  10934. ctx.moveTo(cx + innerRadius * mathCos$3(endAngle), cy + innerRadius * mathSin$3(endAngle));
  10935. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  10936. }
  10937. }
  10938. else {
  10939. var icrStart = void 0;
  10940. var icrEnd = void 0;
  10941. var ocrStart = void 0;
  10942. var ocrEnd = void 0;
  10943. var ocrs = void 0;
  10944. var ocre = void 0;
  10945. var icrs = void 0;
  10946. var icre = void 0;
  10947. var ocrMax = void 0;
  10948. var icrMax = void 0;
  10949. var limitedOcrMax = void 0;
  10950. var limitedIcrMax = void 0;
  10951. var xre = void 0;
  10952. var yre = void 0;
  10953. var xirs = void 0;
  10954. var yirs = void 0;
  10955. var xrs = radius * mathCos$3(startAngle);
  10956. var yrs = radius * mathSin$3(startAngle);
  10957. var xire = innerRadius * mathCos$3(endAngle);
  10958. var yire = innerRadius * mathSin$3(endAngle);
  10959. var hasArc = arc > e;
  10960. if (hasArc) {
  10961. var cornerRadius = shape.cornerRadius;
  10962. if (cornerRadius) {
  10963. _a = normalizeCornerRadius(cornerRadius), icrStart = _a[0], icrEnd = _a[1], ocrStart = _a[2], ocrEnd = _a[3];
  10964. }
  10965. var halfRd = mathAbs$1(radius - innerRadius) / 2;
  10966. ocrs = mathMin$3(halfRd, ocrStart);
  10967. ocre = mathMin$3(halfRd, ocrEnd);
  10968. icrs = mathMin$3(halfRd, icrStart);
  10969. icre = mathMin$3(halfRd, icrEnd);
  10970. limitedOcrMax = ocrMax = mathMax$3(ocrs, ocre);
  10971. limitedIcrMax = icrMax = mathMax$3(icrs, icre);
  10972. if (ocrMax > e || icrMax > e) {
  10973. xre = radius * mathCos$3(endAngle);
  10974. yre = radius * mathSin$3(endAngle);
  10975. xirs = innerRadius * mathCos$3(startAngle);
  10976. yirs = innerRadius * mathSin$3(startAngle);
  10977. if (arc < PI$2) {
  10978. var it_1 = intersect(xrs, yrs, xirs, yirs, xre, yre, xire, yire);
  10979. if (it_1) {
  10980. var x0 = xrs - it_1[0];
  10981. var y0 = yrs - it_1[1];
  10982. var x1 = xre - it_1[0];
  10983. var y1 = yre - it_1[1];
  10984. var a = 1 / mathSin$3(mathACos((x0 * x1 + y0 * y1) / (mathSqrt$3(x0 * x0 + y0 * y0) * mathSqrt$3(x1 * x1 + y1 * y1))) / 2);
  10985. var b = mathSqrt$3(it_1[0] * it_1[0] + it_1[1] * it_1[1]);
  10986. limitedOcrMax = mathMin$3(ocrMax, (radius - b) / (a + 1));
  10987. limitedIcrMax = mathMin$3(icrMax, (innerRadius - b) / (a - 1));
  10988. }
  10989. }
  10990. }
  10991. }
  10992. if (!hasArc) {
  10993. ctx.moveTo(cx + xrs, cy + yrs);
  10994. }
  10995. else if (limitedOcrMax > e) {
  10996. var crStart = mathMin$3(ocrStart, limitedOcrMax);
  10997. var crEnd = mathMin$3(ocrEnd, limitedOcrMax);
  10998. var ct0 = computeCornerTangents(xirs, yirs, xrs, yrs, radius, crStart, clockwise);
  10999. var ct1 = computeCornerTangents(xre, yre, xire, yire, radius, crEnd, clockwise);
  11000. ctx.moveTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  11001. if (limitedOcrMax < ocrMax && crStart === crEnd) {
  11002. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedOcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11003. }
  11004. else {
  11005. crStart > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crStart, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  11006. ctx.arc(cx, cy, radius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), !clockwise);
  11007. crEnd > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crEnd, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11008. }
  11009. }
  11010. else {
  11011. ctx.moveTo(cx + xrs, cy + yrs);
  11012. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  11013. }
  11014. if (!(innerRadius > e) || !hasArc) {
  11015. ctx.lineTo(cx + xire, cy + yire);
  11016. }
  11017. else if (limitedIcrMax > e) {
  11018. var crStart = mathMin$3(icrStart, limitedIcrMax);
  11019. var crEnd = mathMin$3(icrEnd, limitedIcrMax);
  11020. var ct0 = computeCornerTangents(xire, yire, xre, yre, innerRadius, -crEnd, clockwise);
  11021. var ct1 = computeCornerTangents(xrs, yrs, xirs, yirs, innerRadius, -crStart, clockwise);
  11022. ctx.lineTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  11023. if (limitedIcrMax < icrMax && crStart === crEnd) {
  11024. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedIcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11025. }
  11026. else {
  11027. crEnd > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crEnd, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  11028. ctx.arc(cx, cy, innerRadius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), clockwise);
  11029. crStart > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crStart, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11030. }
  11031. }
  11032. else {
  11033. ctx.lineTo(cx + xire, cy + yire);
  11034. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  11035. }
  11036. }
  11037. ctx.closePath();
  11038. }
  11039. var SectorShape = (function () {
  11040. function SectorShape() {
  11041. this.cx = 0;
  11042. this.cy = 0;
  11043. this.r0 = 0;
  11044. this.r = 0;
  11045. this.startAngle = 0;
  11046. this.endAngle = Math.PI * 2;
  11047. this.clockwise = true;
  11048. this.cornerRadius = 0;
  11049. }
  11050. return SectorShape;
  11051. }());
  11052. var Sector = (function (_super) {
  11053. __extends(Sector, _super);
  11054. function Sector(opts) {
  11055. return _super.call(this, opts) || this;
  11056. }
  11057. Sector.prototype.getDefaultShape = function () {
  11058. return new SectorShape();
  11059. };
  11060. Sector.prototype.buildPath = function (ctx, shape) {
  11061. buildPath$2(ctx, shape);
  11062. };
  11063. Sector.prototype.isZeroArea = function () {
  11064. return this.shape.startAngle === this.shape.endAngle
  11065. || this.shape.r === this.shape.r0;
  11066. };
  11067. return Sector;
  11068. }(Path));
  11069. Sector.prototype.type = 'sector';
  11070. var CMD$3 = PathProxy.CMD;
  11071. function aroundEqual(a, b) {
  11072. return Math.abs(a - b) < 1e-5;
  11073. }
  11074. function pathToBezierCurves(path) {
  11075. var data = path.data;
  11076. var len = path.len();
  11077. var bezierArrayGroups = [];
  11078. var currentSubpath;
  11079. var xi = 0;
  11080. var yi = 0;
  11081. var x0 = 0;
  11082. var y0 = 0;
  11083. function createNewSubpath(x, y) {
  11084. if (currentSubpath && currentSubpath.length > 2) {
  11085. bezierArrayGroups.push(currentSubpath);
  11086. }
  11087. currentSubpath = [x, y];
  11088. }
  11089. function addLine(x0, y0, x1, y1) {
  11090. if (!(aroundEqual(x0, x1) && aroundEqual(y0, y1))) {
  11091. currentSubpath.push(x0, y0, x1, y1, x1, y1);
  11092. }
  11093. }
  11094. function addArc(startAngle, endAngle, cx, cy, rx, ry) {
  11095. var delta = Math.abs(endAngle - startAngle);
  11096. var len = Math.tan(delta / 4) * 4 / 3;
  11097. var dir = endAngle < startAngle ? -1 : 1;
  11098. var c1 = Math.cos(startAngle);
  11099. var s1 = Math.sin(startAngle);
  11100. var c2 = Math.cos(endAngle);
  11101. var s2 = Math.sin(endAngle);
  11102. var x1 = c1 * rx + cx;
  11103. var y1 = s1 * ry + cy;
  11104. var x4 = c2 * rx + cx;
  11105. var y4 = s2 * ry + cy;
  11106. var hx = rx * len * dir;
  11107. var hy = ry * len * dir;
  11108. currentSubpath.push(x1 - hx * s1, y1 + hy * c1, x4 + hx * s2, y4 - hy * c2, x4, y4);
  11109. }
  11110. var x1;
  11111. var y1;
  11112. var x2;
  11113. var y2;
  11114. for (var i = 0; i < len;) {
  11115. var cmd = data[i++];
  11116. var isFirst = i === 1;
  11117. if (isFirst) {
  11118. xi = data[i];
  11119. yi = data[i + 1];
  11120. x0 = xi;
  11121. y0 = yi;
  11122. if (cmd === CMD$3.L || cmd === CMD$3.C || cmd === CMD$3.Q) {
  11123. currentSubpath = [x0, y0];
  11124. }
  11125. }
  11126. switch (cmd) {
  11127. case CMD$3.M:
  11128. xi = x0 = data[i++];
  11129. yi = y0 = data[i++];
  11130. createNewSubpath(x0, y0);
  11131. break;
  11132. case CMD$3.L:
  11133. x1 = data[i++];
  11134. y1 = data[i++];
  11135. addLine(xi, yi, x1, y1);
  11136. xi = x1;
  11137. yi = y1;
  11138. break;
  11139. case CMD$3.C:
  11140. currentSubpath.push(data[i++], data[i++], data[i++], data[i++], xi = data[i++], yi = data[i++]);
  11141. break;
  11142. case CMD$3.Q:
  11143. x1 = data[i++];
  11144. y1 = data[i++];
  11145. x2 = data[i++];
  11146. y2 = data[i++];
  11147. currentSubpath.push(xi + 2 / 3 * (x1 - xi), yi + 2 / 3 * (y1 - yi), x2 + 2 / 3 * (x1 - x2), y2 + 2 / 3 * (y1 - y2), x2, y2);
  11148. xi = x2;
  11149. yi = y2;
  11150. break;
  11151. case CMD$3.A:
  11152. var cx = data[i++];
  11153. var cy = data[i++];
  11154. var rx = data[i++];
  11155. var ry = data[i++];
  11156. var startAngle = data[i++];
  11157. var endAngle = data[i++] + startAngle;
  11158. i += 1;
  11159. var anticlockwise = !data[i++];
  11160. x1 = Math.cos(startAngle) * rx + cx;
  11161. y1 = Math.sin(startAngle) * ry + cy;
  11162. if (isFirst) {
  11163. x0 = x1;
  11164. y0 = y1;
  11165. createNewSubpath(x0, y0);
  11166. }
  11167. else {
  11168. addLine(xi, yi, x1, y1);
  11169. }
  11170. xi = Math.cos(endAngle) * rx + cx;
  11171. yi = Math.sin(endAngle) * ry + cy;
  11172. var step = (anticlockwise ? -1 : 1) * Math.PI / 2;
  11173. for (var angle = startAngle; anticlockwise ? angle > endAngle : angle < endAngle; angle += step) {
  11174. var nextAngle = anticlockwise ? Math.max(angle + step, endAngle)
  11175. : Math.min(angle + step, endAngle);
  11176. addArc(angle, nextAngle, cx, cy, rx, ry);
  11177. }
  11178. break;
  11179. case CMD$3.R:
  11180. x0 = xi = data[i++];
  11181. y0 = yi = data[i++];
  11182. x1 = x0 + data[i++];
  11183. y1 = y0 + data[i++];
  11184. createNewSubpath(x1, y0);
  11185. addLine(x1, y0, x1, y1);
  11186. addLine(x1, y1, x0, y1);
  11187. addLine(x0, y1, x0, y0);
  11188. addLine(x0, y0, x1, y0);
  11189. break;
  11190. case CMD$3.Z:
  11191. currentSubpath && addLine(xi, yi, x0, y0);
  11192. xi = x0;
  11193. yi = y0;
  11194. break;
  11195. }
  11196. }
  11197. if (currentSubpath && currentSubpath.length > 2) {
  11198. bezierArrayGroups.push(currentSubpath);
  11199. }
  11200. return bezierArrayGroups;
  11201. }
  11202. function adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, out, scale) {
  11203. if (aroundEqual(x0, x1) && aroundEqual(y0, y1) && aroundEqual(x2, x3) && aroundEqual(y2, y3)) {
  11204. out.push(x3, y3);
  11205. return;
  11206. }
  11207. var PIXEL_DISTANCE = 2 / scale;
  11208. var PIXEL_DISTANCE_SQR = PIXEL_DISTANCE * PIXEL_DISTANCE;
  11209. var dx = x3 - x0;
  11210. var dy = y3 - y0;
  11211. var d = Math.sqrt(dx * dx + dy * dy);
  11212. dx /= d;
  11213. dy /= d;
  11214. var dx1 = x1 - x0;
  11215. var dy1 = y1 - y0;
  11216. var dx2 = x2 - x3;
  11217. var dy2 = y2 - y3;
  11218. var cp1LenSqr = dx1 * dx1 + dy1 * dy1;
  11219. var cp2LenSqr = dx2 * dx2 + dy2 * dy2;
  11220. if (cp1LenSqr < PIXEL_DISTANCE_SQR && cp2LenSqr < PIXEL_DISTANCE_SQR) {
  11221. out.push(x3, y3);
  11222. return;
  11223. }
  11224. var projLen1 = dx * dx1 + dy * dy1;
  11225. var projLen2 = -dx * dx2 - dy * dy2;
  11226. var d1Sqr = cp1LenSqr - projLen1 * projLen1;
  11227. var d2Sqr = cp2LenSqr - projLen2 * projLen2;
  11228. if (d1Sqr < PIXEL_DISTANCE_SQR && projLen1 >= 0
  11229. && d2Sqr < PIXEL_DISTANCE_SQR && projLen2 >= 0) {
  11230. out.push(x3, y3);
  11231. return;
  11232. }
  11233. var tmpSegX = [];
  11234. var tmpSegY = [];
  11235. cubicSubdivide(x0, x1, x2, x3, 0.5, tmpSegX);
  11236. cubicSubdivide(y0, y1, y2, y3, 0.5, tmpSegY);
  11237. adpativeBezier(tmpSegX[0], tmpSegY[0], tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], tmpSegX[3], tmpSegY[3], out, scale);
  11238. adpativeBezier(tmpSegX[4], tmpSegY[4], tmpSegX[5], tmpSegY[5], tmpSegX[6], tmpSegY[6], tmpSegX[7], tmpSegY[7], out, scale);
  11239. }
  11240. function pathToPolygons(path, scale) {
  11241. var bezierArrayGroups = pathToBezierCurves(path);
  11242. var polygons = [];
  11243. scale = scale || 1;
  11244. for (var i = 0; i < bezierArrayGroups.length; i++) {
  11245. var beziers = bezierArrayGroups[i];
  11246. var polygon = [];
  11247. var x0 = beziers[0];
  11248. var y0 = beziers[1];
  11249. polygon.push(x0, y0);
  11250. for (var k = 2; k < beziers.length;) {
  11251. var x1 = beziers[k++];
  11252. var y1 = beziers[k++];
  11253. var x2 = beziers[k++];
  11254. var y2 = beziers[k++];
  11255. var x3 = beziers[k++];
  11256. var y3 = beziers[k++];
  11257. adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, polygon, scale);
  11258. x0 = x3;
  11259. y0 = y3;
  11260. }
  11261. polygons.push(polygon);
  11262. }
  11263. return polygons;
  11264. }
  11265. function getDividingGrids(dimSize, rowDim, count) {
  11266. var rowSize = dimSize[rowDim];
  11267. var columnSize = dimSize[1 - rowDim];
  11268. var ratio = Math.abs(rowSize / columnSize);
  11269. var rowCount = Math.ceil(Math.sqrt(ratio * count));
  11270. var columnCount = Math.floor(count / rowCount);
  11271. if (columnCount === 0) {
  11272. columnCount = 1;
  11273. rowCount = count;
  11274. }
  11275. var grids = [];
  11276. for (var i = 0; i < rowCount; i++) {
  11277. grids.push(columnCount);
  11278. }
  11279. var currentCount = rowCount * columnCount;
  11280. var remained = count - currentCount;
  11281. if (remained > 0) {
  11282. for (var i = 0; i < remained; i++) {
  11283. grids[i % rowCount] += 1;
  11284. }
  11285. }
  11286. return grids;
  11287. }
  11288. function divideSector(sectorShape, count, outShapes) {
  11289. var r0 = sectorShape.r0;
  11290. var r = sectorShape.r;
  11291. var startAngle = sectorShape.startAngle;
  11292. var endAngle = sectorShape.endAngle;
  11293. var angle = Math.abs(endAngle - startAngle);
  11294. var arcLen = angle * r;
  11295. var deltaR = r - r0;
  11296. var isAngleRow = arcLen > Math.abs(deltaR);
  11297. var grids = getDividingGrids([arcLen, deltaR], isAngleRow ? 0 : 1, count);
  11298. var rowSize = (isAngleRow ? angle : deltaR) / grids.length;
  11299. for (var row = 0; row < grids.length; row++) {
  11300. var columnSize = (isAngleRow ? deltaR : angle) / grids[row];
  11301. for (var column = 0; column < grids[row]; column++) {
  11302. var newShape = {};
  11303. if (isAngleRow) {
  11304. newShape.startAngle = startAngle + rowSize * row;
  11305. newShape.endAngle = startAngle + rowSize * (row + 1);
  11306. newShape.r0 = r0 + columnSize * column;
  11307. newShape.r = r0 + columnSize * (column + 1);
  11308. }
  11309. else {
  11310. newShape.startAngle = startAngle + columnSize * column;
  11311. newShape.endAngle = startAngle + columnSize * (column + 1);
  11312. newShape.r0 = r0 + rowSize * row;
  11313. newShape.r = r0 + rowSize * (row + 1);
  11314. }
  11315. newShape.clockwise = sectorShape.clockwise;
  11316. newShape.cx = sectorShape.cx;
  11317. newShape.cy = sectorShape.cy;
  11318. outShapes.push(newShape);
  11319. }
  11320. }
  11321. }
  11322. function divideRect(rectShape, count, outShapes) {
  11323. var width = rectShape.width;
  11324. var height = rectShape.height;
  11325. var isHorizontalRow = width > height;
  11326. var grids = getDividingGrids([width, height], isHorizontalRow ? 0 : 1, count);
  11327. var rowSizeDim = isHorizontalRow ? 'width' : 'height';
  11328. var columnSizeDim = isHorizontalRow ? 'height' : 'width';
  11329. var rowDim = isHorizontalRow ? 'x' : 'y';
  11330. var columnDim = isHorizontalRow ? 'y' : 'x';
  11331. var rowSize = rectShape[rowSizeDim] / grids.length;
  11332. for (var row = 0; row < grids.length; row++) {
  11333. var columnSize = rectShape[columnSizeDim] / grids[row];
  11334. for (var column = 0; column < grids[row]; column++) {
  11335. var newShape = {};
  11336. newShape[rowDim] = row * rowSize;
  11337. newShape[columnDim] = column * columnSize;
  11338. newShape[rowSizeDim] = rowSize;
  11339. newShape[columnSizeDim] = columnSize;
  11340. newShape.x += rectShape.x;
  11341. newShape.y += rectShape.y;
  11342. outShapes.push(newShape);
  11343. }
  11344. }
  11345. }
  11346. function crossProduct2d(x1, y1, x2, y2) {
  11347. return x1 * y2 - x2 * y1;
  11348. }
  11349. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  11350. var mx = a2x - a1x;
  11351. var my = a2y - a1y;
  11352. var nx = b2x - b1x;
  11353. var ny = b2y - b1y;
  11354. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  11355. if (Math.abs(nmCrossProduct) < 1e-6) {
  11356. return null;
  11357. }
  11358. var b1a1x = a1x - b1x;
  11359. var b1a1y = a1y - b1y;
  11360. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  11361. if (p < 0 || p > 1) {
  11362. return null;
  11363. }
  11364. return new Point(p * mx + a1x, p * my + a1y);
  11365. }
  11366. function projPtOnLine(pt, lineA, lineB) {
  11367. var dir = new Point();
  11368. Point.sub(dir, lineB, lineA);
  11369. dir.normalize();
  11370. var dir2 = new Point();
  11371. Point.sub(dir2, pt, lineA);
  11372. var len = dir2.dot(dir);
  11373. return len;
  11374. }
  11375. function addToPoly(poly, pt) {
  11376. var last = poly[poly.length - 1];
  11377. if (last && last[0] === pt[0] && last[1] === pt[1]) {
  11378. return;
  11379. }
  11380. poly.push(pt);
  11381. }
  11382. function splitPolygonByLine(points, lineA, lineB) {
  11383. var len = points.length;
  11384. var intersections = [];
  11385. for (var i = 0; i < len; i++) {
  11386. var p0 = points[i];
  11387. var p1 = points[(i + 1) % len];
  11388. var intersectionPt = lineLineIntersect(p0[0], p0[1], p1[0], p1[1], lineA.x, lineA.y, lineB.x, lineB.y);
  11389. if (intersectionPt) {
  11390. intersections.push({
  11391. projPt: projPtOnLine(intersectionPt, lineA, lineB),
  11392. pt: intersectionPt,
  11393. idx: i
  11394. });
  11395. }
  11396. }
  11397. if (intersections.length < 2) {
  11398. return [{ points: points }, { points: points }];
  11399. }
  11400. intersections.sort(function (a, b) {
  11401. return a.projPt - b.projPt;
  11402. });
  11403. var splitPt0 = intersections[0];
  11404. var splitPt1 = intersections[intersections.length - 1];
  11405. if (splitPt1.idx < splitPt0.idx) {
  11406. var tmp = splitPt0;
  11407. splitPt0 = splitPt1;
  11408. splitPt1 = tmp;
  11409. }
  11410. var splitPt0Arr = [splitPt0.pt.x, splitPt0.pt.y];
  11411. var splitPt1Arr = [splitPt1.pt.x, splitPt1.pt.y];
  11412. var newPolyA = [splitPt0Arr];
  11413. var newPolyB = [splitPt1Arr];
  11414. for (var i = splitPt0.idx + 1; i <= splitPt1.idx; i++) {
  11415. addToPoly(newPolyA, points[i].slice());
  11416. }
  11417. addToPoly(newPolyA, splitPt1Arr);
  11418. addToPoly(newPolyA, splitPt0Arr);
  11419. for (var i = splitPt1.idx + 1; i <= splitPt0.idx + len; i++) {
  11420. addToPoly(newPolyB, points[i % len].slice());
  11421. }
  11422. addToPoly(newPolyB, splitPt0Arr);
  11423. addToPoly(newPolyB, splitPt1Arr);
  11424. return [{
  11425. points: newPolyA
  11426. }, {
  11427. points: newPolyB
  11428. }];
  11429. }
  11430. function binaryDividePolygon(polygonShape) {
  11431. var points = polygonShape.points;
  11432. var min = [];
  11433. var max = [];
  11434. fromPoints(points, min, max);
  11435. var boundingRect = new BoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  11436. var width = boundingRect.width;
  11437. var height = boundingRect.height;
  11438. var x = boundingRect.x;
  11439. var y = boundingRect.y;
  11440. var pt0 = new Point();
  11441. var pt1 = new Point();
  11442. if (width > height) {
  11443. pt0.x = pt1.x = x + width / 2;
  11444. pt0.y = y;
  11445. pt1.y = y + height;
  11446. }
  11447. else {
  11448. pt0.y = pt1.y = y + height / 2;
  11449. pt0.x = x;
  11450. pt1.x = x + width;
  11451. }
  11452. return splitPolygonByLine(points, pt0, pt1);
  11453. }
  11454. function binaryDivideRecursive(divider, shape, count, out) {
  11455. if (count === 1) {
  11456. out.push(shape);
  11457. }
  11458. else {
  11459. var mid = Math.floor(count / 2);
  11460. var sub = divider(shape);
  11461. binaryDivideRecursive(divider, sub[0], mid, out);
  11462. binaryDivideRecursive(divider, sub[1], count - mid, out);
  11463. }
  11464. return out;
  11465. }
  11466. function clone$3(path, count) {
  11467. var paths = [];
  11468. for (var i = 0; i < count; i++) {
  11469. paths.push(clonePath(path));
  11470. }
  11471. return paths;
  11472. }
  11473. function copyPathProps(source, target) {
  11474. target.setStyle(source.style);
  11475. target.z = source.z;
  11476. target.z2 = source.z2;
  11477. target.zlevel = source.zlevel;
  11478. }
  11479. function polygonConvert(points) {
  11480. var out = [];
  11481. for (var i = 0; i < points.length;) {
  11482. out.push([points[i++], points[i++]]);
  11483. }
  11484. return out;
  11485. }
  11486. function split(path, count) {
  11487. var outShapes = [];
  11488. var shape = path.shape;
  11489. var OutShapeCtor;
  11490. switch (path.type) {
  11491. case 'rect':
  11492. divideRect(shape, count, outShapes);
  11493. OutShapeCtor = Rect;
  11494. break;
  11495. case 'sector':
  11496. divideSector(shape, count, outShapes);
  11497. OutShapeCtor = Sector;
  11498. break;
  11499. case 'circle':
  11500. divideSector({
  11501. r0: 0, r: shape.r, startAngle: 0, endAngle: Math.PI * 2,
  11502. cx: shape.cx, cy: shape.cy
  11503. }, count, outShapes);
  11504. OutShapeCtor = Sector;
  11505. break;
  11506. default:
  11507. var m = path.getComputedTransform();
  11508. var scale = m ? Math.sqrt(Math.max(m[0] * m[0] + m[1] * m[1], m[2] * m[2] + m[3] * m[3])) : 1;
  11509. var polygons = map(pathToPolygons(path.getUpdatedPathProxy(), scale), function (poly) { return polygonConvert(poly); });
  11510. var polygonCount = polygons.length;
  11511. if (polygonCount === 0) {
  11512. binaryDivideRecursive(binaryDividePolygon, {
  11513. points: polygons[0]
  11514. }, count, outShapes);
  11515. }
  11516. else if (polygonCount === count) {
  11517. for (var i = 0; i < polygonCount; i++) {
  11518. outShapes.push({
  11519. points: polygons[i]
  11520. });
  11521. }
  11522. }
  11523. else {
  11524. var totalArea_1 = 0;
  11525. var items = map(polygons, function (poly) {
  11526. var min = [];
  11527. var max = [];
  11528. fromPoints(poly, min, max);
  11529. var area = (max[1] - min[1]) * (max[0] - min[0]);
  11530. totalArea_1 += area;
  11531. return { poly: poly, area: area };
  11532. });
  11533. items.sort(function (a, b) { return b.area - a.area; });
  11534. var left = count;
  11535. for (var i = 0; i < polygonCount; i++) {
  11536. var item = items[i];
  11537. if (left <= 0) {
  11538. break;
  11539. }
  11540. var selfCount = i === polygonCount - 1
  11541. ? left
  11542. : Math.ceil(item.area / totalArea_1 * count);
  11543. if (selfCount < 0) {
  11544. continue;
  11545. }
  11546. binaryDivideRecursive(binaryDividePolygon, {
  11547. points: item.poly
  11548. }, selfCount, outShapes);
  11549. left -= selfCount;
  11550. }
  11551. }
  11552. OutShapeCtor = Polygon;
  11553. break;
  11554. }
  11555. if (!OutShapeCtor) {
  11556. return clone$3(path, count);
  11557. }
  11558. var out = [];
  11559. for (var i = 0; i < outShapes.length; i++) {
  11560. var subPath = new OutShapeCtor();
  11561. subPath.setShape(outShapes[i]);
  11562. copyPathProps(path, subPath);
  11563. out.push(subPath);
  11564. }
  11565. return out;
  11566. }
  11567. function alignSubpath(subpath1, subpath2) {
  11568. var len1 = subpath1.length;
  11569. var len2 = subpath2.length;
  11570. if (len1 === len2) {
  11571. return [subpath1, subpath2];
  11572. }
  11573. var tmpSegX = [];
  11574. var tmpSegY = [];
  11575. var shorterPath = len1 < len2 ? subpath1 : subpath2;
  11576. var shorterLen = Math.min(len1, len2);
  11577. var diff = Math.abs(len2 - len1) / 6;
  11578. var shorterBezierCount = (shorterLen - 2) / 6;
  11579. var eachCurveSubDivCount = Math.ceil(diff / shorterBezierCount) + 1;
  11580. var newSubpath = [shorterPath[0], shorterPath[1]];
  11581. var remained = diff;
  11582. for (var i = 2; i < shorterLen;) {
  11583. var x0 = shorterPath[i - 2];
  11584. var y0 = shorterPath[i - 1];
  11585. var x1 = shorterPath[i++];
  11586. var y1 = shorterPath[i++];
  11587. var x2 = shorterPath[i++];
  11588. var y2 = shorterPath[i++];
  11589. var x3 = shorterPath[i++];
  11590. var y3 = shorterPath[i++];
  11591. if (remained <= 0) {
  11592. newSubpath.push(x1, y1, x2, y2, x3, y3);
  11593. continue;
  11594. }
  11595. var actualSubDivCount = Math.min(remained, eachCurveSubDivCount - 1) + 1;
  11596. for (var k = 1; k <= actualSubDivCount; k++) {
  11597. var p = k / actualSubDivCount;
  11598. cubicSubdivide(x0, x1, x2, x3, p, tmpSegX);
  11599. cubicSubdivide(y0, y1, y2, y3, p, tmpSegY);
  11600. x0 = tmpSegX[3];
  11601. y0 = tmpSegY[3];
  11602. newSubpath.push(tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], x0, y0);
  11603. x1 = tmpSegX[5];
  11604. y1 = tmpSegY[5];
  11605. x2 = tmpSegX[6];
  11606. y2 = tmpSegY[6];
  11607. }
  11608. remained -= actualSubDivCount - 1;
  11609. }
  11610. return shorterPath === subpath1 ? [newSubpath, subpath2] : [subpath1, newSubpath];
  11611. }
  11612. function createSubpath(lastSubpathSubpath, otherSubpath) {
  11613. var len = lastSubpathSubpath.length;
  11614. var lastX = lastSubpathSubpath[len - 2];
  11615. var lastY = lastSubpathSubpath[len - 1];
  11616. var newSubpath = [];
  11617. for (var i = 0; i < otherSubpath.length;) {
  11618. newSubpath[i++] = lastX;
  11619. newSubpath[i++] = lastY;
  11620. }
  11621. return newSubpath;
  11622. }
  11623. function alignBezierCurves(array1, array2) {
  11624. var _a;
  11625. var lastSubpath1;
  11626. var lastSubpath2;
  11627. var newArray1 = [];
  11628. var newArray2 = [];
  11629. for (var i = 0; i < Math.max(array1.length, array2.length); i++) {
  11630. var subpath1 = array1[i];
  11631. var subpath2 = array2[i];
  11632. var newSubpath1 = void 0;
  11633. var newSubpath2 = void 0;
  11634. if (!subpath1) {
  11635. newSubpath1 = createSubpath(lastSubpath1 || subpath2, subpath2);
  11636. newSubpath2 = subpath2;
  11637. }
  11638. else if (!subpath2) {
  11639. newSubpath2 = createSubpath(lastSubpath2 || subpath1, subpath1);
  11640. newSubpath1 = subpath1;
  11641. }
  11642. else {
  11643. _a = alignSubpath(subpath1, subpath2), newSubpath1 = _a[0], newSubpath2 = _a[1];
  11644. lastSubpath1 = newSubpath1;
  11645. lastSubpath2 = newSubpath2;
  11646. }
  11647. newArray1.push(newSubpath1);
  11648. newArray2.push(newSubpath2);
  11649. }
  11650. return [newArray1, newArray2];
  11651. }
  11652. function centroid(array) {
  11653. var signedArea = 0;
  11654. var cx = 0;
  11655. var cy = 0;
  11656. var len = array.length;
  11657. for (var i = 0, j = len - 2; i < len; j = i, i += 2) {
  11658. var x0 = array[j];
  11659. var y0 = array[j + 1];
  11660. var x1 = array[i];
  11661. var y1 = array[i + 1];
  11662. var a = x0 * y1 - x1 * y0;
  11663. signedArea += a;
  11664. cx += (x0 + x1) * a;
  11665. cy += (y0 + y1) * a;
  11666. }
  11667. if (signedArea === 0) {
  11668. return [array[0] || 0, array[1] || 0];
  11669. }
  11670. return [cx / signedArea / 3, cy / signedArea / 3, signedArea];
  11671. }
  11672. function findBestRingOffset(fromSubBeziers, toSubBeziers, fromCp, toCp) {
  11673. var bezierCount = (fromSubBeziers.length - 2) / 6;
  11674. var bestScore = Infinity;
  11675. var bestOffset = 0;
  11676. var len = fromSubBeziers.length;
  11677. var len2 = len - 2;
  11678. for (var offset = 0; offset < bezierCount; offset++) {
  11679. var cursorOffset = offset * 6;
  11680. var score = 0;
  11681. for (var k = 0; k < len; k += 2) {
  11682. var idx = k === 0 ? cursorOffset : ((cursorOffset + k - 2) % len2 + 2);
  11683. var x0 = fromSubBeziers[idx] - fromCp[0];
  11684. var y0 = fromSubBeziers[idx + 1] - fromCp[1];
  11685. var x1 = toSubBeziers[k] - toCp[0];
  11686. var y1 = toSubBeziers[k + 1] - toCp[1];
  11687. var dx = x1 - x0;
  11688. var dy = y1 - y0;
  11689. score += dx * dx + dy * dy;
  11690. }
  11691. if (score < bestScore) {
  11692. bestScore = score;
  11693. bestOffset = offset;
  11694. }
  11695. }
  11696. return bestOffset;
  11697. }
  11698. function reverse(array) {
  11699. var newArr = [];
  11700. var len = array.length;
  11701. for (var i = 0; i < len; i += 2) {
  11702. newArr[i] = array[len - i - 2];
  11703. newArr[i + 1] = array[len - i - 1];
  11704. }
  11705. return newArr;
  11706. }
  11707. function findBestMorphingRotation(fromArr, toArr, searchAngleIteration, searchAngleRange) {
  11708. var result = [];
  11709. var fromNeedsReverse;
  11710. for (var i = 0; i < fromArr.length; i++) {
  11711. var fromSubpathBezier = fromArr[i];
  11712. var toSubpathBezier = toArr[i];
  11713. var fromCp = centroid(fromSubpathBezier);
  11714. var toCp = centroid(toSubpathBezier);
  11715. if (fromNeedsReverse == null) {
  11716. fromNeedsReverse = fromCp[2] < 0 !== toCp[2] < 0;
  11717. }
  11718. var newFromSubpathBezier = [];
  11719. var newToSubpathBezier = [];
  11720. var bestAngle = 0;
  11721. var bestScore = Infinity;
  11722. var tmpArr = [];
  11723. var len = fromSubpathBezier.length;
  11724. if (fromNeedsReverse) {
  11725. fromSubpathBezier = reverse(fromSubpathBezier);
  11726. }
  11727. var offset = findBestRingOffset(fromSubpathBezier, toSubpathBezier, fromCp, toCp) * 6;
  11728. var len2 = len - 2;
  11729. for (var k = 0; k < len2; k += 2) {
  11730. var idx = (offset + k) % len2 + 2;
  11731. newFromSubpathBezier[k + 2] = fromSubpathBezier[idx] - fromCp[0];
  11732. newFromSubpathBezier[k + 3] = fromSubpathBezier[idx + 1] - fromCp[1];
  11733. }
  11734. newFromSubpathBezier[0] = fromSubpathBezier[offset] - fromCp[0];
  11735. newFromSubpathBezier[1] = fromSubpathBezier[offset + 1] - fromCp[1];
  11736. if (searchAngleIteration > 0) {
  11737. var step = searchAngleRange / searchAngleIteration;
  11738. for (var angle = -searchAngleRange / 2; angle <= searchAngleRange / 2; angle += step) {
  11739. var sa = Math.sin(angle);
  11740. var ca = Math.cos(angle);
  11741. var score = 0;
  11742. for (var k = 0; k < fromSubpathBezier.length; k += 2) {
  11743. var x0 = newFromSubpathBezier[k];
  11744. var y0 = newFromSubpathBezier[k + 1];
  11745. var x1 = toSubpathBezier[k] - toCp[0];
  11746. var y1 = toSubpathBezier[k + 1] - toCp[1];
  11747. var newX1 = x1 * ca - y1 * sa;
  11748. var newY1 = x1 * sa + y1 * ca;
  11749. tmpArr[k] = newX1;
  11750. tmpArr[k + 1] = newY1;
  11751. var dx = newX1 - x0;
  11752. var dy = newY1 - y0;
  11753. score += dx * dx + dy * dy;
  11754. }
  11755. if (score < bestScore) {
  11756. bestScore = score;
  11757. bestAngle = angle;
  11758. for (var m = 0; m < tmpArr.length; m++) {
  11759. newToSubpathBezier[m] = tmpArr[m];
  11760. }
  11761. }
  11762. }
  11763. }
  11764. else {
  11765. for (var i_1 = 0; i_1 < len; i_1 += 2) {
  11766. newToSubpathBezier[i_1] = toSubpathBezier[i_1] - toCp[0];
  11767. newToSubpathBezier[i_1 + 1] = toSubpathBezier[i_1 + 1] - toCp[1];
  11768. }
  11769. }
  11770. result.push({
  11771. from: newFromSubpathBezier,
  11772. to: newToSubpathBezier,
  11773. fromCp: fromCp,
  11774. toCp: toCp,
  11775. rotation: -bestAngle
  11776. });
  11777. }
  11778. return result;
  11779. }
  11780. function isCombineMorphing(path) {
  11781. return path.__isCombineMorphing;
  11782. }
  11783. function isMorphing(el) {
  11784. return el.__morphT >= 0;
  11785. }
  11786. var SAVED_METHOD_PREFIX = '__mOriginal_';
  11787. function saveAndModifyMethod(obj, methodName, modifiers) {
  11788. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  11789. var originalMethod = obj[savedMethodName] || obj[methodName];
  11790. if (!obj[savedMethodName]) {
  11791. obj[savedMethodName] = obj[methodName];
  11792. }
  11793. var replace = modifiers.replace;
  11794. var after = modifiers.after;
  11795. var before = modifiers.before;
  11796. obj[methodName] = function () {
  11797. var args = arguments;
  11798. var res;
  11799. before && before.apply(this, args);
  11800. if (replace) {
  11801. res = replace.apply(this, args);
  11802. }
  11803. else {
  11804. res = originalMethod.apply(this, args);
  11805. }
  11806. after && after.apply(this, args);
  11807. return res;
  11808. };
  11809. }
  11810. function restoreMethod(obj, methodName) {
  11811. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  11812. if (obj[savedMethodName]) {
  11813. obj[methodName] = obj[savedMethodName];
  11814. obj[savedMethodName] = null;
  11815. }
  11816. }
  11817. function applyTransformOnBeziers(bezierCurves, mm) {
  11818. for (var i = 0; i < bezierCurves.length; i++) {
  11819. var subBeziers = bezierCurves[i];
  11820. for (var k = 0; k < subBeziers.length;) {
  11821. var x = subBeziers[k];
  11822. var y = subBeziers[k + 1];
  11823. subBeziers[k++] = mm[0] * x + mm[2] * y + mm[4];
  11824. subBeziers[k++] = mm[1] * x + mm[3] * y + mm[5];
  11825. }
  11826. }
  11827. }
  11828. function prepareMorphPath(fromPath, toPath) {
  11829. var fromPathProxy = fromPath.getUpdatedPathProxy();
  11830. var toPathProxy = toPath.getUpdatedPathProxy();
  11831. var _a = alignBezierCurves(pathToBezierCurves(fromPathProxy), pathToBezierCurves(toPathProxy)), fromBezierCurves = _a[0], toBezierCurves = _a[1];
  11832. var fromPathTransform = fromPath.getComputedTransform();
  11833. var toPathTransform = toPath.getComputedTransform();
  11834. function updateIdentityTransform() {
  11835. this.transform = null;
  11836. }
  11837. fromPathTransform && applyTransformOnBeziers(fromBezierCurves, fromPathTransform);
  11838. toPathTransform && applyTransformOnBeziers(toBezierCurves, toPathTransform);
  11839. saveAndModifyMethod(toPath, 'updateTransform', { replace: updateIdentityTransform });
  11840. toPath.transform = null;
  11841. var morphingData = findBestMorphingRotation(fromBezierCurves, toBezierCurves, 10, Math.PI);
  11842. var tmpArr = [];
  11843. saveAndModifyMethod(toPath, 'buildPath', { replace: function (path) {
  11844. var t = toPath.__morphT;
  11845. var onet = 1 - t;
  11846. var newCp = [];
  11847. for (var i = 0; i < morphingData.length; i++) {
  11848. var item = morphingData[i];
  11849. var from = item.from;
  11850. var to = item.to;
  11851. var angle = item.rotation * t;
  11852. var fromCp = item.fromCp;
  11853. var toCp = item.toCp;
  11854. var sa = Math.sin(angle);
  11855. var ca = Math.cos(angle);
  11856. lerp(newCp, fromCp, toCp, t);
  11857. for (var m = 0; m < from.length; m += 2) {
  11858. var x0_1 = from[m];
  11859. var y0_1 = from[m + 1];
  11860. var x1 = to[m];
  11861. var y1 = to[m + 1];
  11862. var x = x0_1 * onet + x1 * t;
  11863. var y = y0_1 * onet + y1 * t;
  11864. tmpArr[m] = (x * ca - y * sa) + newCp[0];
  11865. tmpArr[m + 1] = (x * sa + y * ca) + newCp[1];
  11866. }
  11867. var x0 = tmpArr[0];
  11868. var y0 = tmpArr[1];
  11869. path.moveTo(x0, y0);
  11870. for (var m = 2; m < from.length;) {
  11871. var x1 = tmpArr[m++];
  11872. var y1 = tmpArr[m++];
  11873. var x2 = tmpArr[m++];
  11874. var y2 = tmpArr[m++];
  11875. var x3 = tmpArr[m++];
  11876. var y3 = tmpArr[m++];
  11877. if (x0 === x1 && y0 === y1 && x2 === x3 && y2 === y3) {
  11878. path.lineTo(x3, y3);
  11879. }
  11880. else {
  11881. path.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11882. }
  11883. x0 = x3;
  11884. y0 = y3;
  11885. }
  11886. }
  11887. } });
  11888. }
  11889. function morphPath(fromPath, toPath, animationOpts) {
  11890. if (!fromPath || !toPath) {
  11891. return toPath;
  11892. }
  11893. var oldDone = animationOpts.done;
  11894. var oldDuring = animationOpts.during;
  11895. prepareMorphPath(fromPath, toPath);
  11896. toPath.__morphT = 0;
  11897. function restoreToPath() {
  11898. restoreMethod(toPath, 'buildPath');
  11899. restoreMethod(toPath, 'updateTransform');
  11900. toPath.__morphT = -1;
  11901. toPath.createPathProxy();
  11902. toPath.dirtyShape();
  11903. }
  11904. toPath.animateTo({
  11905. __morphT: 1
  11906. }, defaults({
  11907. during: function (p) {
  11908. toPath.dirtyShape();
  11909. oldDuring && oldDuring(p);
  11910. },
  11911. done: function () {
  11912. restoreToPath();
  11913. oldDone && oldDone();
  11914. }
  11915. }, animationOpts));
  11916. return toPath;
  11917. }
  11918. function hilbert(x, y, minX, minY, maxX, maxY) {
  11919. var bits = 16;
  11920. x = (maxX === minX) ? 0 : Math.round(32767 * (x - minX) / (maxX - minX));
  11921. y = (maxY === minY) ? 0 : Math.round(32767 * (y - minY) / (maxY - minY));
  11922. var d = 0;
  11923. var tmp;
  11924. for (var s = (1 << bits) / 2; s > 0; s /= 2) {
  11925. var rx = 0;
  11926. var ry = 0;
  11927. if ((x & s) > 0) {
  11928. rx = 1;
  11929. }
  11930. if ((y & s) > 0) {
  11931. ry = 1;
  11932. }
  11933. d += s * s * ((3 * rx) ^ ry);
  11934. if (ry === 0) {
  11935. if (rx === 1) {
  11936. x = s - 1 - x;
  11937. y = s - 1 - y;
  11938. }
  11939. tmp = x;
  11940. x = y;
  11941. y = tmp;
  11942. }
  11943. }
  11944. return d;
  11945. }
  11946. function sortPaths(pathList) {
  11947. var xMin = Infinity;
  11948. var yMin = Infinity;
  11949. var xMax = -Infinity;
  11950. var yMax = -Infinity;
  11951. var cps = map(pathList, function (path) {
  11952. var rect = path.getBoundingRect();
  11953. var m = path.getComputedTransform();
  11954. var x = rect.x + rect.width / 2 + (m ? m[4] : 0);
  11955. var y = rect.y + rect.height / 2 + (m ? m[5] : 0);
  11956. xMin = Math.min(x, xMin);
  11957. yMin = Math.min(y, yMin);
  11958. xMax = Math.max(x, xMax);
  11959. yMax = Math.max(y, yMax);
  11960. return [x, y];
  11961. });
  11962. var items = map(cps, function (cp, idx) {
  11963. return {
  11964. cp: cp,
  11965. z: hilbert(cp[0], cp[1], xMin, yMin, xMax, yMax),
  11966. path: pathList[idx]
  11967. };
  11968. });
  11969. return items.sort(function (a, b) { return a.z - b.z; }).map(function (item) { return item.path; });
  11970. }
  11971. function defaultDividePath(param) {
  11972. return split(param.path, param.count);
  11973. }
  11974. function createEmptyReturn() {
  11975. return {
  11976. fromIndividuals: [],
  11977. toIndividuals: [],
  11978. count: 0
  11979. };
  11980. }
  11981. function combineMorph(fromList, toPath, animationOpts) {
  11982. var fromPathList = [];
  11983. function addFromPath(fromList) {
  11984. for (var i = 0; i < fromList.length; i++) {
  11985. var from = fromList[i];
  11986. if (isCombineMorphing(from)) {
  11987. addFromPath(from.childrenRef());
  11988. }
  11989. else if (from instanceof Path) {
  11990. fromPathList.push(from);
  11991. }
  11992. }
  11993. }
  11994. addFromPath(fromList);
  11995. var separateCount = fromPathList.length;
  11996. if (!separateCount) {
  11997. return createEmptyReturn();
  11998. }
  11999. var dividePath = animationOpts.dividePath || defaultDividePath;
  12000. var toSubPathList = dividePath({
  12001. path: toPath, count: separateCount
  12002. });
  12003. if (toSubPathList.length !== separateCount) {
  12004. console.error('Invalid morphing: unmatched splitted path');
  12005. return createEmptyReturn();
  12006. }
  12007. fromPathList = sortPaths(fromPathList);
  12008. toSubPathList = sortPaths(toSubPathList);
  12009. var oldDone = animationOpts.done;
  12010. var oldDuring = animationOpts.during;
  12011. var individualDelay = animationOpts.individualDelay;
  12012. var identityTransform = new Transformable();
  12013. for (var i = 0; i < separateCount; i++) {
  12014. var from = fromPathList[i];
  12015. var to = toSubPathList[i];
  12016. to.parent = toPath;
  12017. to.copyTransform(identityTransform);
  12018. if (!individualDelay) {
  12019. prepareMorphPath(from, to);
  12020. }
  12021. }
  12022. toPath.__isCombineMorphing = true;
  12023. toPath.childrenRef = function () {
  12024. return toSubPathList;
  12025. };
  12026. function addToSubPathListToZr(zr) {
  12027. for (var i = 0; i < toSubPathList.length; i++) {
  12028. toSubPathList[i].addSelfToZr(zr);
  12029. }
  12030. }
  12031. saveAndModifyMethod(toPath, 'addSelfToZr', {
  12032. after: function (zr) {
  12033. addToSubPathListToZr(zr);
  12034. }
  12035. });
  12036. saveAndModifyMethod(toPath, 'removeSelfFromZr', {
  12037. after: function (zr) {
  12038. for (var i = 0; i < toSubPathList.length; i++) {
  12039. toSubPathList[i].removeSelfFromZr(zr);
  12040. }
  12041. }
  12042. });
  12043. function restoreToPath() {
  12044. toPath.__isCombineMorphing = false;
  12045. toPath.__morphT = -1;
  12046. toPath.childrenRef = null;
  12047. restoreMethod(toPath, 'addSelfToZr');
  12048. restoreMethod(toPath, 'removeSelfFromZr');
  12049. }
  12050. var toLen = toSubPathList.length;
  12051. if (individualDelay) {
  12052. var animating_1 = toLen;
  12053. var eachDone = function () {
  12054. animating_1--;
  12055. if (animating_1 === 0) {
  12056. restoreToPath();
  12057. oldDone && oldDone();
  12058. }
  12059. };
  12060. for (var i = 0; i < toLen; i++) {
  12061. var indivdualAnimationOpts = individualDelay ? defaults({
  12062. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toSubPathList[i]),
  12063. done: eachDone
  12064. }, animationOpts) : animationOpts;
  12065. morphPath(fromPathList[i], toSubPathList[i], indivdualAnimationOpts);
  12066. }
  12067. }
  12068. else {
  12069. toPath.__morphT = 0;
  12070. toPath.animateTo({
  12071. __morphT: 1
  12072. }, defaults({
  12073. during: function (p) {
  12074. for (var i = 0; i < toLen; i++) {
  12075. var child = toSubPathList[i];
  12076. child.__morphT = toPath.__morphT;
  12077. child.dirtyShape();
  12078. }
  12079. oldDuring && oldDuring(p);
  12080. },
  12081. done: function () {
  12082. restoreToPath();
  12083. for (var i = 0; i < fromList.length; i++) {
  12084. restoreMethod(fromList[i], 'updateTransform');
  12085. }
  12086. oldDone && oldDone();
  12087. }
  12088. }, animationOpts));
  12089. }
  12090. if (toPath.__zr) {
  12091. addToSubPathListToZr(toPath.__zr);
  12092. }
  12093. return {
  12094. fromIndividuals: fromPathList,
  12095. toIndividuals: toSubPathList,
  12096. count: toLen
  12097. };
  12098. }
  12099. function separateMorph(fromPath, toPathList, animationOpts) {
  12100. var toLen = toPathList.length;
  12101. var fromPathList = [];
  12102. var dividePath = animationOpts.dividePath || defaultDividePath;
  12103. function addFromPath(fromList) {
  12104. for (var i = 0; i < fromList.length; i++) {
  12105. var from = fromList[i];
  12106. if (isCombineMorphing(from)) {
  12107. addFromPath(from.childrenRef());
  12108. }
  12109. else if (from instanceof Path) {
  12110. fromPathList.push(from);
  12111. }
  12112. }
  12113. }
  12114. if (isCombineMorphing(fromPath)) {
  12115. addFromPath(fromPath.childrenRef());
  12116. var fromLen = fromPathList.length;
  12117. if (fromLen < toLen) {
  12118. var k = 0;
  12119. for (var i = fromLen; i < toLen; i++) {
  12120. fromPathList.push(clonePath(fromPathList[k++ % fromLen]));
  12121. }
  12122. }
  12123. fromPathList.length = toLen;
  12124. }
  12125. else {
  12126. fromPathList = dividePath({ path: fromPath, count: toLen });
  12127. var fromPathTransform = fromPath.getComputedTransform();
  12128. for (var i = 0; i < fromPathList.length; i++) {
  12129. fromPathList[i].setLocalTransform(fromPathTransform);
  12130. }
  12131. if (fromPathList.length !== toLen) {
  12132. console.error('Invalid morphing: unmatched splitted path');
  12133. return createEmptyReturn();
  12134. }
  12135. }
  12136. fromPathList = sortPaths(fromPathList);
  12137. toPathList = sortPaths(toPathList);
  12138. var individualDelay = animationOpts.individualDelay;
  12139. for (var i = 0; i < toLen; i++) {
  12140. var indivdualAnimationOpts = individualDelay ? defaults({
  12141. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toPathList[i])
  12142. }, animationOpts) : animationOpts;
  12143. morphPath(fromPathList[i], toPathList[i], indivdualAnimationOpts);
  12144. }
  12145. return {
  12146. fromIndividuals: fromPathList,
  12147. toIndividuals: toPathList,
  12148. count: toPathList.length
  12149. };
  12150. }
  12151. var morphPath$1 = /*#__PURE__*/Object.freeze({
  12152. __proto__: null,
  12153. alignBezierCurves: alignBezierCurves,
  12154. centroid: centroid,
  12155. isCombineMorphing: isCombineMorphing,
  12156. isMorphing: isMorphing,
  12157. morphPath: morphPath,
  12158. combineMorph: combineMorph,
  12159. separateMorph: separateMorph,
  12160. defaultDividePath: split
  12161. });
  12162. var CompoundPath = (function (_super) {
  12163. __extends(CompoundPath, _super);
  12164. function CompoundPath() {
  12165. var _this = _super !== null && _super.apply(this, arguments) || this;
  12166. _this.type = 'compound';
  12167. return _this;
  12168. }
  12169. CompoundPath.prototype._updatePathDirty = function () {
  12170. var paths = this.shape.paths;
  12171. var dirtyPath = this.shapeChanged();
  12172. for (var i = 0; i < paths.length; i++) {
  12173. dirtyPath = dirtyPath || paths[i].shapeChanged();
  12174. }
  12175. if (dirtyPath) {
  12176. this.dirtyShape();
  12177. }
  12178. };
  12179. CompoundPath.prototype.beforeBrush = function () {
  12180. this._updatePathDirty();
  12181. var paths = this.shape.paths || [];
  12182. var scale = this.getGlobalScale();
  12183. for (var i = 0; i < paths.length; i++) {
  12184. if (!paths[i].path) {
  12185. paths[i].createPathProxy();
  12186. }
  12187. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  12188. }
  12189. };
  12190. CompoundPath.prototype.buildPath = function (ctx, shape) {
  12191. var paths = shape.paths || [];
  12192. for (var i = 0; i < paths.length; i++) {
  12193. paths[i].buildPath(ctx, paths[i].shape, true);
  12194. }
  12195. };
  12196. CompoundPath.prototype.afterBrush = function () {
  12197. var paths = this.shape.paths || [];
  12198. for (var i = 0; i < paths.length; i++) {
  12199. paths[i].pathUpdated();
  12200. }
  12201. };
  12202. CompoundPath.prototype.getBoundingRect = function () {
  12203. this._updatePathDirty.call(this);
  12204. return Path.prototype.getBoundingRect.call(this);
  12205. };
  12206. return CompoundPath;
  12207. }(Path));
  12208. var m = [];
  12209. var IncrementalDisplayable = (function (_super) {
  12210. __extends(IncrementalDisplayable, _super);
  12211. function IncrementalDisplayable() {
  12212. var _this = _super !== null && _super.apply(this, arguments) || this;
  12213. _this.notClear = true;
  12214. _this.incremental = true;
  12215. _this._displayables = [];
  12216. _this._temporaryDisplayables = [];
  12217. _this._cursor = 0;
  12218. return _this;
  12219. }
  12220. IncrementalDisplayable.prototype.traverse = function (cb, context) {
  12221. cb.call(context, this);
  12222. };
  12223. IncrementalDisplayable.prototype.useStyle = function () {
  12224. this.style = {};
  12225. };
  12226. IncrementalDisplayable.prototype.getCursor = function () {
  12227. return this._cursor;
  12228. };
  12229. IncrementalDisplayable.prototype.innerAfterBrush = function () {
  12230. this._cursor = this._displayables.length;
  12231. };
  12232. IncrementalDisplayable.prototype.clearDisplaybles = function () {
  12233. this._displayables = [];
  12234. this._temporaryDisplayables = [];
  12235. this._cursor = 0;
  12236. this.markRedraw();
  12237. this.notClear = false;
  12238. };
  12239. IncrementalDisplayable.prototype.clearTemporalDisplayables = function () {
  12240. this._temporaryDisplayables = [];
  12241. };
  12242. IncrementalDisplayable.prototype.addDisplayable = function (displayable, notPersistent) {
  12243. if (notPersistent) {
  12244. this._temporaryDisplayables.push(displayable);
  12245. }
  12246. else {
  12247. this._displayables.push(displayable);
  12248. }
  12249. this.markRedraw();
  12250. };
  12251. IncrementalDisplayable.prototype.addDisplayables = function (displayables, notPersistent) {
  12252. notPersistent = notPersistent || false;
  12253. for (var i = 0; i < displayables.length; i++) {
  12254. this.addDisplayable(displayables[i], notPersistent);
  12255. }
  12256. };
  12257. IncrementalDisplayable.prototype.getDisplayables = function () {
  12258. return this._displayables;
  12259. };
  12260. IncrementalDisplayable.prototype.getTemporalDisplayables = function () {
  12261. return this._temporaryDisplayables;
  12262. };
  12263. IncrementalDisplayable.prototype.eachPendingDisplayable = function (cb) {
  12264. for (var i = this._cursor; i < this._displayables.length; i++) {
  12265. cb && cb(this._displayables[i]);
  12266. }
  12267. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  12268. cb && cb(this._temporaryDisplayables[i]);
  12269. }
  12270. };
  12271. IncrementalDisplayable.prototype.update = function () {
  12272. this.updateTransform();
  12273. for (var i = this._cursor; i < this._displayables.length; i++) {
  12274. var displayable = this._displayables[i];
  12275. displayable.parent = this;
  12276. displayable.update();
  12277. displayable.parent = null;
  12278. }
  12279. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  12280. var displayable = this._temporaryDisplayables[i];
  12281. displayable.parent = this;
  12282. displayable.update();
  12283. displayable.parent = null;
  12284. }
  12285. };
  12286. IncrementalDisplayable.prototype.getBoundingRect = function () {
  12287. if (!this._rect) {
  12288. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  12289. for (var i = 0; i < this._displayables.length; i++) {
  12290. var displayable = this._displayables[i];
  12291. var childRect = displayable.getBoundingRect().clone();
  12292. if (displayable.needLocalTransform()) {
  12293. childRect.applyTransform(displayable.getLocalTransform(m));
  12294. }
  12295. rect.union(childRect);
  12296. }
  12297. this._rect = rect;
  12298. }
  12299. return this._rect;
  12300. };
  12301. IncrementalDisplayable.prototype.contain = function (x, y) {
  12302. var localPos = this.transformCoordToLocal(x, y);
  12303. var rect = this.getBoundingRect();
  12304. if (rect.contain(localPos[0], localPos[1])) {
  12305. for (var i = 0; i < this._displayables.length; i++) {
  12306. var displayable = this._displayables[i];
  12307. if (displayable.contain(x, y)) {
  12308. return true;
  12309. }
  12310. }
  12311. }
  12312. return false;
  12313. };
  12314. return IncrementalDisplayable;
  12315. }(Displayable));
  12316. var globalImageCache = new LRU(50);
  12317. function findExistImage(newImageOrSrc) {
  12318. if (typeof newImageOrSrc === 'string') {
  12319. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  12320. return cachedImgObj && cachedImgObj.image;
  12321. }
  12322. else {
  12323. return newImageOrSrc;
  12324. }
  12325. }
  12326. function createOrUpdateImage(newImageOrSrc, image, hostEl, onload, cbPayload) {
  12327. if (!newImageOrSrc) {
  12328. return image;
  12329. }
  12330. else if (typeof newImageOrSrc === 'string') {
  12331. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  12332. return image;
  12333. }
  12334. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  12335. var pendingWrap = { hostEl: hostEl, cb: onload, cbPayload: cbPayload };
  12336. if (cachedImgObj) {
  12337. image = cachedImgObj.image;
  12338. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  12339. }
  12340. else {
  12341. image = platformApi.loadImage(newImageOrSrc, imageOnLoad, imageOnLoad);
  12342. image.__zrImageSrc = newImageOrSrc;
  12343. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  12344. image: image,
  12345. pending: [pendingWrap]
  12346. });
  12347. }
  12348. return image;
  12349. }
  12350. else {
  12351. return newImageOrSrc;
  12352. }
  12353. }
  12354. function imageOnLoad() {
  12355. var cachedImgObj = this.__cachedImgObj;
  12356. this.onload = this.onerror = this.__cachedImgObj = null;
  12357. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  12358. var pendingWrap = cachedImgObj.pending[i];
  12359. var cb = pendingWrap.cb;
  12360. cb && cb(this, pendingWrap.cbPayload);
  12361. pendingWrap.hostEl.dirty();
  12362. }
  12363. cachedImgObj.pending.length = 0;
  12364. }
  12365. function isImageReady(image) {
  12366. return image && image.width && image.height;
  12367. }
  12368. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  12369. function truncateText(text, containerWidth, font, ellipsis, options) {
  12370. if (!containerWidth) {
  12371. return '';
  12372. }
  12373. var textLines = (text + '').split('\n');
  12374. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  12375. for (var i = 0, len = textLines.length; i < len; i++) {
  12376. textLines[i] = truncateSingleLine(textLines[i], options);
  12377. }
  12378. return textLines.join('\n');
  12379. }
  12380. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  12381. options = options || {};
  12382. var preparedOpts = extend({}, options);
  12383. preparedOpts.font = font;
  12384. ellipsis = retrieve2(ellipsis, '...');
  12385. preparedOpts.maxIterations = retrieve2(options.maxIterations, 2);
  12386. var minChar = preparedOpts.minChar = retrieve2(options.minChar, 0);
  12387. preparedOpts.cnCharWidth = getWidth('国', font);
  12388. var ascCharWidth = preparedOpts.ascCharWidth = getWidth('a', font);
  12389. preparedOpts.placeholder = retrieve2(options.placeholder, '');
  12390. var contentWidth = containerWidth = Math.max(0, containerWidth - 1);
  12391. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  12392. contentWidth -= ascCharWidth;
  12393. }
  12394. var ellipsisWidth = getWidth(ellipsis, font);
  12395. if (ellipsisWidth > contentWidth) {
  12396. ellipsis = '';
  12397. ellipsisWidth = 0;
  12398. }
  12399. contentWidth = containerWidth - ellipsisWidth;
  12400. preparedOpts.ellipsis = ellipsis;
  12401. preparedOpts.ellipsisWidth = ellipsisWidth;
  12402. preparedOpts.contentWidth = contentWidth;
  12403. preparedOpts.containerWidth = containerWidth;
  12404. return preparedOpts;
  12405. }
  12406. function truncateSingleLine(textLine, options) {
  12407. var containerWidth = options.containerWidth;
  12408. var font = options.font;
  12409. var contentWidth = options.contentWidth;
  12410. if (!containerWidth) {
  12411. return '';
  12412. }
  12413. var lineWidth = getWidth(textLine, font);
  12414. if (lineWidth <= containerWidth) {
  12415. return textLine;
  12416. }
  12417. for (var j = 0;; j++) {
  12418. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  12419. textLine += options.ellipsis;
  12420. break;
  12421. }
  12422. var subLength = j === 0
  12423. ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
  12424. : lineWidth > 0
  12425. ? Math.floor(textLine.length * contentWidth / lineWidth)
  12426. : 0;
  12427. textLine = textLine.substr(0, subLength);
  12428. lineWidth = getWidth(textLine, font);
  12429. }
  12430. if (textLine === '') {
  12431. textLine = options.placeholder;
  12432. }
  12433. return textLine;
  12434. }
  12435. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  12436. var width = 0;
  12437. var i = 0;
  12438. for (var len = text.length; i < len && width < contentWidth; i++) {
  12439. var charCode = text.charCodeAt(i);
  12440. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  12441. }
  12442. return i;
  12443. }
  12444. function parsePlainText(text, style) {
  12445. text != null && (text += '');
  12446. var overflow = style.overflow;
  12447. var padding = style.padding;
  12448. var font = style.font;
  12449. var truncate = overflow === 'truncate';
  12450. var calculatedLineHeight = getLineHeight(font);
  12451. var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
  12452. var bgColorDrawn = !!(style.backgroundColor);
  12453. var truncateLineOverflow = style.lineOverflow === 'truncate';
  12454. var width = style.width;
  12455. var lines;
  12456. if (width != null && (overflow === 'break' || overflow === 'breakAll')) {
  12457. lines = text ? wrapText(text, style.font, width, overflow === 'breakAll', 0).lines : [];
  12458. }
  12459. else {
  12460. lines = text ? text.split('\n') : [];
  12461. }
  12462. var contentHeight = lines.length * lineHeight;
  12463. var height = retrieve2(style.height, contentHeight);
  12464. if (contentHeight > height && truncateLineOverflow) {
  12465. var lineCount = Math.floor(height / lineHeight);
  12466. lines = lines.slice(0, lineCount);
  12467. }
  12468. if (text && truncate && width != null) {
  12469. var options = prepareTruncateOptions(width, font, style.ellipsis, {
  12470. minChar: style.truncateMinChar,
  12471. placeholder: style.placeholder
  12472. });
  12473. for (var i = 0; i < lines.length; i++) {
  12474. lines[i] = truncateSingleLine(lines[i], options);
  12475. }
  12476. }
  12477. var outerHeight = height;
  12478. var contentWidth = 0;
  12479. for (var i = 0; i < lines.length; i++) {
  12480. contentWidth = Math.max(getWidth(lines[i], font), contentWidth);
  12481. }
  12482. if (width == null) {
  12483. width = contentWidth;
  12484. }
  12485. var outerWidth = contentWidth;
  12486. if (padding) {
  12487. outerHeight += padding[0] + padding[2];
  12488. outerWidth += padding[1] + padding[3];
  12489. width += padding[1] + padding[3];
  12490. }
  12491. if (bgColorDrawn) {
  12492. outerWidth = width;
  12493. }
  12494. return {
  12495. lines: lines,
  12496. height: height,
  12497. outerWidth: outerWidth,
  12498. outerHeight: outerHeight,
  12499. lineHeight: lineHeight,
  12500. calculatedLineHeight: calculatedLineHeight,
  12501. contentWidth: contentWidth,
  12502. contentHeight: contentHeight,
  12503. width: width
  12504. };
  12505. }
  12506. var RichTextToken = (function () {
  12507. function RichTextToken() {
  12508. }
  12509. return RichTextToken;
  12510. }());
  12511. var RichTextLine = (function () {
  12512. function RichTextLine(tokens) {
  12513. this.tokens = [];
  12514. if (tokens) {
  12515. this.tokens = tokens;
  12516. }
  12517. }
  12518. return RichTextLine;
  12519. }());
  12520. var RichTextContentBlock = (function () {
  12521. function RichTextContentBlock() {
  12522. this.width = 0;
  12523. this.height = 0;
  12524. this.contentWidth = 0;
  12525. this.contentHeight = 0;
  12526. this.outerWidth = 0;
  12527. this.outerHeight = 0;
  12528. this.lines = [];
  12529. }
  12530. return RichTextContentBlock;
  12531. }());
  12532. function parseRichText(text, style) {
  12533. var contentBlock = new RichTextContentBlock();
  12534. text != null && (text += '');
  12535. if (!text) {
  12536. return contentBlock;
  12537. }
  12538. var topWidth = style.width;
  12539. var topHeight = style.height;
  12540. var overflow = style.overflow;
  12541. var wrapInfo = (overflow === 'break' || overflow === 'breakAll') && topWidth != null
  12542. ? { width: topWidth, accumWidth: 0, breakAll: overflow === 'breakAll' }
  12543. : null;
  12544. var lastIndex = STYLE_REG.lastIndex = 0;
  12545. var result;
  12546. while ((result = STYLE_REG.exec(text)) != null) {
  12547. var matchedIndex = result.index;
  12548. if (matchedIndex > lastIndex) {
  12549. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex), style, wrapInfo);
  12550. }
  12551. pushTokens(contentBlock, result[2], style, wrapInfo, result[1]);
  12552. lastIndex = STYLE_REG.lastIndex;
  12553. }
  12554. if (lastIndex < text.length) {
  12555. pushTokens(contentBlock, text.substring(lastIndex, text.length), style, wrapInfo);
  12556. }
  12557. var pendingList = [];
  12558. var calculatedHeight = 0;
  12559. var calculatedWidth = 0;
  12560. var stlPadding = style.padding;
  12561. var truncate = overflow === 'truncate';
  12562. var truncateLine = style.lineOverflow === 'truncate';
  12563. function finishLine(line, lineWidth, lineHeight) {
  12564. line.width = lineWidth;
  12565. line.lineHeight = lineHeight;
  12566. calculatedHeight += lineHeight;
  12567. calculatedWidth = Math.max(calculatedWidth, lineWidth);
  12568. }
  12569. outer: for (var i = 0; i < contentBlock.lines.length; i++) {
  12570. var line = contentBlock.lines[i];
  12571. var lineHeight = 0;
  12572. var lineWidth = 0;
  12573. for (var j = 0; j < line.tokens.length; j++) {
  12574. var token = line.tokens[j];
  12575. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  12576. var textPadding = token.textPadding = tokenStyle.padding;
  12577. var paddingH = textPadding ? textPadding[1] + textPadding[3] : 0;
  12578. var font = token.font = tokenStyle.font || style.font;
  12579. token.contentHeight = getLineHeight(font);
  12580. var tokenHeight = retrieve2(tokenStyle.height, token.contentHeight);
  12581. token.innerHeight = tokenHeight;
  12582. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  12583. token.height = tokenHeight;
  12584. token.lineHeight = retrieve3(tokenStyle.lineHeight, style.lineHeight, tokenHeight);
  12585. token.align = tokenStyle && tokenStyle.align || style.align;
  12586. token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
  12587. if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
  12588. if (j > 0) {
  12589. line.tokens = line.tokens.slice(0, j);
  12590. finishLine(line, lineWidth, lineHeight);
  12591. contentBlock.lines = contentBlock.lines.slice(0, i + 1);
  12592. }
  12593. else {
  12594. contentBlock.lines = contentBlock.lines.slice(0, i);
  12595. }
  12596. break outer;
  12597. }
  12598. var styleTokenWidth = tokenStyle.width;
  12599. var tokenWidthNotSpecified = styleTokenWidth == null || styleTokenWidth === 'auto';
  12600. if (typeof styleTokenWidth === 'string' && styleTokenWidth.charAt(styleTokenWidth.length - 1) === '%') {
  12601. token.percentWidth = styleTokenWidth;
  12602. pendingList.push(token);
  12603. token.contentWidth = getWidth(token.text, font);
  12604. }
  12605. else {
  12606. if (tokenWidthNotSpecified) {
  12607. var textBackgroundColor = tokenStyle.backgroundColor;
  12608. var bgImg = textBackgroundColor && textBackgroundColor.image;
  12609. if (bgImg) {
  12610. bgImg = findExistImage(bgImg);
  12611. if (isImageReady(bgImg)) {
  12612. token.width = Math.max(token.width, bgImg.width * tokenHeight / bgImg.height);
  12613. }
  12614. }
  12615. }
  12616. var remainTruncWidth = truncate && topWidth != null
  12617. ? topWidth - lineWidth : null;
  12618. if (remainTruncWidth != null && remainTruncWidth < token.width) {
  12619. if (!tokenWidthNotSpecified || remainTruncWidth < paddingH) {
  12620. token.text = '';
  12621. token.width = token.contentWidth = 0;
  12622. }
  12623. else {
  12624. token.text = truncateText(token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
  12625. token.width = token.contentWidth = getWidth(token.text, font);
  12626. }
  12627. }
  12628. else {
  12629. token.contentWidth = getWidth(token.text, font);
  12630. }
  12631. }
  12632. token.width += paddingH;
  12633. lineWidth += token.width;
  12634. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  12635. }
  12636. finishLine(line, lineWidth, lineHeight);
  12637. }
  12638. contentBlock.outerWidth = contentBlock.width = retrieve2(topWidth, calculatedWidth);
  12639. contentBlock.outerHeight = contentBlock.height = retrieve2(topHeight, calculatedHeight);
  12640. contentBlock.contentHeight = calculatedHeight;
  12641. contentBlock.contentWidth = calculatedWidth;
  12642. if (stlPadding) {
  12643. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  12644. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  12645. }
  12646. for (var i = 0; i < pendingList.length; i++) {
  12647. var token = pendingList[i];
  12648. var percentWidth = token.percentWidth;
  12649. token.width = parseInt(percentWidth, 10) / 100 * contentBlock.width;
  12650. }
  12651. return contentBlock;
  12652. }
  12653. function pushTokens(block, str, style, wrapInfo, styleName) {
  12654. var isEmptyStr = str === '';
  12655. var tokenStyle = styleName && style.rich[styleName] || {};
  12656. var lines = block.lines;
  12657. var font = tokenStyle.font || style.font;
  12658. var newLine = false;
  12659. var strLines;
  12660. var linesWidths;
  12661. if (wrapInfo) {
  12662. var tokenPadding = tokenStyle.padding;
  12663. var tokenPaddingH = tokenPadding ? tokenPadding[1] + tokenPadding[3] : 0;
  12664. if (tokenStyle.width != null && tokenStyle.width !== 'auto') {
  12665. var outerWidth_1 = parsePercent(tokenStyle.width, wrapInfo.width) + tokenPaddingH;
  12666. if (lines.length > 0) {
  12667. if (outerWidth_1 + wrapInfo.accumWidth > wrapInfo.width) {
  12668. strLines = str.split('\n');
  12669. newLine = true;
  12670. }
  12671. }
  12672. wrapInfo.accumWidth = outerWidth_1;
  12673. }
  12674. else {
  12675. var res = wrapText(str, font, wrapInfo.width, wrapInfo.breakAll, wrapInfo.accumWidth);
  12676. wrapInfo.accumWidth = res.accumWidth + tokenPaddingH;
  12677. linesWidths = res.linesWidths;
  12678. strLines = res.lines;
  12679. }
  12680. }
  12681. else {
  12682. strLines = str.split('\n');
  12683. }
  12684. for (var i = 0; i < strLines.length; i++) {
  12685. var text = strLines[i];
  12686. var token = new RichTextToken();
  12687. token.styleName = styleName;
  12688. token.text = text;
  12689. token.isLineHolder = !text && !isEmptyStr;
  12690. if (typeof tokenStyle.width === 'number') {
  12691. token.width = tokenStyle.width;
  12692. }
  12693. else {
  12694. token.width = linesWidths
  12695. ? linesWidths[i]
  12696. : getWidth(text, font);
  12697. }
  12698. if (!i && !newLine) {
  12699. var tokens = (lines[lines.length - 1] || (lines[0] = new RichTextLine())).tokens;
  12700. var tokensLen = tokens.length;
  12701. (tokensLen === 1 && tokens[0].isLineHolder)
  12702. ? (tokens[0] = token)
  12703. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  12704. }
  12705. else {
  12706. lines.push(new RichTextLine([token]));
  12707. }
  12708. }
  12709. }
  12710. function isAlphabeticLetter(ch) {
  12711. var code = ch.charCodeAt(0);
  12712. return code >= 0x20 && code <= 0x24F
  12713. || code >= 0x370 && code <= 0x10FF
  12714. || code >= 0x1200 && code <= 0x13FF
  12715. || code >= 0x1E00 && code <= 0x206F;
  12716. }
  12717. var breakCharMap = reduce(',&?/;] '.split(''), function (obj, ch) {
  12718. obj[ch] = true;
  12719. return obj;
  12720. }, {});
  12721. function isWordBreakChar(ch) {
  12722. if (isAlphabeticLetter(ch)) {
  12723. if (breakCharMap[ch]) {
  12724. return true;
  12725. }
  12726. return false;
  12727. }
  12728. return true;
  12729. }
  12730. function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
  12731. var lines = [];
  12732. var linesWidths = [];
  12733. var line = '';
  12734. var currentWord = '';
  12735. var currentWordWidth = 0;
  12736. var accumWidth = 0;
  12737. for (var i = 0; i < text.length; i++) {
  12738. var ch = text.charAt(i);
  12739. if (ch === '\n') {
  12740. if (currentWord) {
  12741. line += currentWord;
  12742. accumWidth += currentWordWidth;
  12743. }
  12744. lines.push(line);
  12745. linesWidths.push(accumWidth);
  12746. line = '';
  12747. currentWord = '';
  12748. currentWordWidth = 0;
  12749. accumWidth = 0;
  12750. continue;
  12751. }
  12752. var chWidth = getWidth(ch, font);
  12753. var inWord = isBreakAll ? false : !isWordBreakChar(ch);
  12754. if (!lines.length
  12755. ? lastAccumWidth + accumWidth + chWidth > lineWidth
  12756. : accumWidth + chWidth > lineWidth) {
  12757. if (!accumWidth) {
  12758. if (inWord) {
  12759. lines.push(currentWord);
  12760. linesWidths.push(currentWordWidth);
  12761. currentWord = ch;
  12762. currentWordWidth = chWidth;
  12763. }
  12764. else {
  12765. lines.push(ch);
  12766. linesWidths.push(chWidth);
  12767. }
  12768. }
  12769. else if (line || currentWord) {
  12770. if (inWord) {
  12771. if (!line) {
  12772. line = currentWord;
  12773. currentWord = '';
  12774. currentWordWidth = 0;
  12775. accumWidth = currentWordWidth;
  12776. }
  12777. lines.push(line);
  12778. linesWidths.push(accumWidth - currentWordWidth);
  12779. currentWord += ch;
  12780. currentWordWidth += chWidth;
  12781. line = '';
  12782. accumWidth = currentWordWidth;
  12783. }
  12784. else {
  12785. if (currentWord) {
  12786. line += currentWord;
  12787. currentWord = '';
  12788. currentWordWidth = 0;
  12789. }
  12790. lines.push(line);
  12791. linesWidths.push(accumWidth);
  12792. line = ch;
  12793. accumWidth = chWidth;
  12794. }
  12795. }
  12796. continue;
  12797. }
  12798. accumWidth += chWidth;
  12799. if (inWord) {
  12800. currentWord += ch;
  12801. currentWordWidth += chWidth;
  12802. }
  12803. else {
  12804. if (currentWord) {
  12805. line += currentWord;
  12806. currentWord = '';
  12807. currentWordWidth = 0;
  12808. }
  12809. line += ch;
  12810. }
  12811. }
  12812. if (!lines.length && !line) {
  12813. line = text;
  12814. currentWord = '';
  12815. currentWordWidth = 0;
  12816. }
  12817. if (currentWord) {
  12818. line += currentWord;
  12819. }
  12820. if (line) {
  12821. lines.push(line);
  12822. linesWidths.push(accumWidth);
  12823. }
  12824. if (lines.length === 1) {
  12825. accumWidth += lastAccumWidth;
  12826. }
  12827. return {
  12828. accumWidth: accumWidth,
  12829. lines: lines,
  12830. linesWidths: linesWidths
  12831. };
  12832. }
  12833. var DEFAULT_RICH_TEXT_COLOR = {
  12834. fill: '#000'
  12835. };
  12836. var DEFAULT_STROKE_LINE_WIDTH = 2;
  12837. var DEFAULT_TEXT_ANIMATION_PROPS = {
  12838. style: defaults({
  12839. fill: true,
  12840. stroke: true,
  12841. fillOpacity: true,
  12842. strokeOpacity: true,
  12843. lineWidth: true,
  12844. fontSize: true,
  12845. lineHeight: true,
  12846. width: true,
  12847. height: true,
  12848. textShadowColor: true,
  12849. textShadowBlur: true,
  12850. textShadowOffsetX: true,
  12851. textShadowOffsetY: true,
  12852. backgroundColor: true,
  12853. padding: true,
  12854. borderColor: true,
  12855. borderWidth: true,
  12856. borderRadius: true
  12857. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  12858. };
  12859. var ZRText = (function (_super) {
  12860. __extends(ZRText, _super);
  12861. function ZRText(opts) {
  12862. var _this = _super.call(this) || this;
  12863. _this.type = 'text';
  12864. _this._children = [];
  12865. _this._defaultStyle = DEFAULT_RICH_TEXT_COLOR;
  12866. _this.attr(opts);
  12867. return _this;
  12868. }
  12869. ZRText.prototype.childrenRef = function () {
  12870. return this._children;
  12871. };
  12872. ZRText.prototype.update = function () {
  12873. _super.prototype.update.call(this);
  12874. if (this.styleChanged()) {
  12875. this._updateSubTexts();
  12876. }
  12877. for (var i = 0; i < this._children.length; i++) {
  12878. var child = this._children[i];
  12879. child.zlevel = this.zlevel;
  12880. child.z = this.z;
  12881. child.z2 = this.z2;
  12882. child.culling = this.culling;
  12883. child.cursor = this.cursor;
  12884. child.invisible = this.invisible;
  12885. }
  12886. };
  12887. ZRText.prototype.updateTransform = function () {
  12888. var innerTransformable = this.innerTransformable;
  12889. if (innerTransformable) {
  12890. innerTransformable.updateTransform();
  12891. if (innerTransformable.transform) {
  12892. this.transform = innerTransformable.transform;
  12893. }
  12894. }
  12895. else {
  12896. _super.prototype.updateTransform.call(this);
  12897. }
  12898. };
  12899. ZRText.prototype.getLocalTransform = function (m) {
  12900. var innerTransformable = this.innerTransformable;
  12901. return innerTransformable
  12902. ? innerTransformable.getLocalTransform(m)
  12903. : _super.prototype.getLocalTransform.call(this, m);
  12904. };
  12905. ZRText.prototype.getComputedTransform = function () {
  12906. if (this.__hostTarget) {
  12907. this.__hostTarget.getComputedTransform();
  12908. this.__hostTarget.updateInnerText(true);
  12909. }
  12910. return _super.prototype.getComputedTransform.call(this);
  12911. };
  12912. ZRText.prototype._updateSubTexts = function () {
  12913. this._childCursor = 0;
  12914. normalizeTextStyle(this.style);
  12915. this.style.rich
  12916. ? this._updateRichTexts()
  12917. : this._updatePlainTexts();
  12918. this._children.length = this._childCursor;
  12919. this.styleUpdated();
  12920. };
  12921. ZRText.prototype.addSelfToZr = function (zr) {
  12922. _super.prototype.addSelfToZr.call(this, zr);
  12923. for (var i = 0; i < this._children.length; i++) {
  12924. this._children[i].__zr = zr;
  12925. }
  12926. };
  12927. ZRText.prototype.removeSelfFromZr = function (zr) {
  12928. _super.prototype.removeSelfFromZr.call(this, zr);
  12929. for (var i = 0; i < this._children.length; i++) {
  12930. this._children[i].__zr = null;
  12931. }
  12932. };
  12933. ZRText.prototype.getBoundingRect = function () {
  12934. if (this.styleChanged()) {
  12935. this._updateSubTexts();
  12936. }
  12937. if (!this._rect) {
  12938. var tmpRect = new BoundingRect(0, 0, 0, 0);
  12939. var children = this._children;
  12940. var tmpMat = [];
  12941. var rect = null;
  12942. for (var i = 0; i < children.length; i++) {
  12943. var child = children[i];
  12944. var childRect = child.getBoundingRect();
  12945. var transform = child.getLocalTransform(tmpMat);
  12946. if (transform) {
  12947. tmpRect.copy(childRect);
  12948. tmpRect.applyTransform(transform);
  12949. rect = rect || tmpRect.clone();
  12950. rect.union(tmpRect);
  12951. }
  12952. else {
  12953. rect = rect || childRect.clone();
  12954. rect.union(childRect);
  12955. }
  12956. }
  12957. this._rect = rect || tmpRect;
  12958. }
  12959. return this._rect;
  12960. };
  12961. ZRText.prototype.setDefaultTextStyle = function (defaultTextStyle) {
  12962. this._defaultStyle = defaultTextStyle || DEFAULT_RICH_TEXT_COLOR;
  12963. };
  12964. ZRText.prototype.setTextContent = function (textContent) {
  12965. {
  12966. throw new Error('Can\'t attach text on another text');
  12967. }
  12968. };
  12969. ZRText.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  12970. if (!sourceStyle) {
  12971. return targetStyle;
  12972. }
  12973. var sourceRich = sourceStyle.rich;
  12974. var targetRich = targetStyle.rich || (sourceRich && {});
  12975. extend(targetStyle, sourceStyle);
  12976. if (sourceRich && targetRich) {
  12977. this._mergeRich(targetRich, sourceRich);
  12978. targetStyle.rich = targetRich;
  12979. }
  12980. else if (targetRich) {
  12981. targetStyle.rich = targetRich;
  12982. }
  12983. return targetStyle;
  12984. };
  12985. ZRText.prototype._mergeRich = function (targetRich, sourceRich) {
  12986. var richNames = keys(sourceRich);
  12987. for (var i = 0; i < richNames.length; i++) {
  12988. var richName = richNames[i];
  12989. targetRich[richName] = targetRich[richName] || {};
  12990. extend(targetRich[richName], sourceRich[richName]);
  12991. }
  12992. };
  12993. ZRText.prototype.getAnimationStyleProps = function () {
  12994. return DEFAULT_TEXT_ANIMATION_PROPS;
  12995. };
  12996. ZRText.prototype._getOrCreateChild = function (Ctor) {
  12997. var child = this._children[this._childCursor];
  12998. if (!child || !(child instanceof Ctor)) {
  12999. child = new Ctor();
  13000. }
  13001. this._children[this._childCursor++] = child;
  13002. child.__zr = this.__zr;
  13003. child.parent = this;
  13004. return child;
  13005. };
  13006. ZRText.prototype._updatePlainTexts = function () {
  13007. var style = this.style;
  13008. var textFont = style.font || DEFAULT_FONT;
  13009. var textPadding = style.padding;
  13010. var text = getStyleText(style);
  13011. var contentBlock = parsePlainText(text, style);
  13012. var needDrawBg = needDrawBackground(style);
  13013. var bgColorDrawn = !!(style.backgroundColor);
  13014. var outerHeight = contentBlock.outerHeight;
  13015. var outerWidth = contentBlock.outerWidth;
  13016. var contentWidth = contentBlock.contentWidth;
  13017. var textLines = contentBlock.lines;
  13018. var lineHeight = contentBlock.lineHeight;
  13019. var defaultStyle = this._defaultStyle;
  13020. var baseX = style.x || 0;
  13021. var baseY = style.y || 0;
  13022. var textAlign = style.align || defaultStyle.align || 'left';
  13023. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
  13024. var textX = baseX;
  13025. var textY = adjustTextY$1(baseY, contentBlock.contentHeight, verticalAlign);
  13026. if (needDrawBg || textPadding) {
  13027. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  13028. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  13029. needDrawBg && this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  13030. }
  13031. textY += lineHeight / 2;
  13032. if (textPadding) {
  13033. textX = getTextXForPadding(baseX, textAlign, textPadding);
  13034. if (verticalAlign === 'top') {
  13035. textY += textPadding[0];
  13036. }
  13037. else if (verticalAlign === 'bottom') {
  13038. textY -= textPadding[2];
  13039. }
  13040. }
  13041. var defaultLineWidth = 0;
  13042. var useDefaultFill = false;
  13043. var textFill = getFill('fill' in style
  13044. ? style.fill
  13045. : (useDefaultFill = true, defaultStyle.fill));
  13046. var textStroke = getStroke('stroke' in style
  13047. ? style.stroke
  13048. : (!bgColorDrawn
  13049. && (!defaultStyle.autoStroke || useDefaultFill))
  13050. ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  13051. : null);
  13052. var hasShadow = style.textShadowBlur > 0;
  13053. var fixedBoundingRect = style.width != null
  13054. && (style.overflow === 'truncate' || style.overflow === 'break' || style.overflow === 'breakAll');
  13055. var calculatedLineHeight = contentBlock.calculatedLineHeight;
  13056. for (var i = 0; i < textLines.length; i++) {
  13057. var el = this._getOrCreateChild(TSpan);
  13058. var subElStyle = el.createStyle();
  13059. el.useStyle(subElStyle);
  13060. subElStyle.text = textLines[i];
  13061. subElStyle.x = textX;
  13062. subElStyle.y = textY;
  13063. if (textAlign) {
  13064. subElStyle.textAlign = textAlign;
  13065. }
  13066. subElStyle.textBaseline = 'middle';
  13067. subElStyle.opacity = style.opacity;
  13068. subElStyle.strokeFirst = true;
  13069. if (hasShadow) {
  13070. subElStyle.shadowBlur = style.textShadowBlur || 0;
  13071. subElStyle.shadowColor = style.textShadowColor || 'transparent';
  13072. subElStyle.shadowOffsetX = style.textShadowOffsetX || 0;
  13073. subElStyle.shadowOffsetY = style.textShadowOffsetY || 0;
  13074. }
  13075. subElStyle.stroke = textStroke;
  13076. subElStyle.fill = textFill;
  13077. if (textStroke) {
  13078. subElStyle.lineWidth = style.lineWidth || defaultLineWidth;
  13079. subElStyle.lineDash = style.lineDash;
  13080. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13081. }
  13082. subElStyle.font = textFont;
  13083. setSeparateFont(subElStyle, style);
  13084. textY += lineHeight;
  13085. if (fixedBoundingRect) {
  13086. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, style.width, subElStyle.textAlign), adjustTextY$1(subElStyle.y, calculatedLineHeight, subElStyle.textBaseline), contentWidth, calculatedLineHeight));
  13087. }
  13088. }
  13089. };
  13090. ZRText.prototype._updateRichTexts = function () {
  13091. var style = this.style;
  13092. var text = getStyleText(style);
  13093. var contentBlock = parseRichText(text, style);
  13094. var contentWidth = contentBlock.width;
  13095. var outerWidth = contentBlock.outerWidth;
  13096. var outerHeight = contentBlock.outerHeight;
  13097. var textPadding = style.padding;
  13098. var baseX = style.x || 0;
  13099. var baseY = style.y || 0;
  13100. var defaultStyle = this._defaultStyle;
  13101. var textAlign = style.align || defaultStyle.align;
  13102. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
  13103. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  13104. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  13105. var xLeft = boxX;
  13106. var lineTop = boxY;
  13107. if (textPadding) {
  13108. xLeft += textPadding[3];
  13109. lineTop += textPadding[0];
  13110. }
  13111. var xRight = xLeft + contentWidth;
  13112. if (needDrawBackground(style)) {
  13113. this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  13114. }
  13115. var bgColorDrawn = !!(style.backgroundColor);
  13116. for (var i = 0; i < contentBlock.lines.length; i++) {
  13117. var line = contentBlock.lines[i];
  13118. var tokens = line.tokens;
  13119. var tokenCount = tokens.length;
  13120. var lineHeight = line.lineHeight;
  13121. var remainedWidth = line.width;
  13122. var leftIndex = 0;
  13123. var lineXLeft = xLeft;
  13124. var lineXRight = xRight;
  13125. var rightIndex = tokenCount - 1;
  13126. var token = void 0;
  13127. while (leftIndex < tokenCount
  13128. && (token = tokens[leftIndex], !token.align || token.align === 'left')) {
  13129. this._placeToken(token, style, lineHeight, lineTop, lineXLeft, 'left', bgColorDrawn);
  13130. remainedWidth -= token.width;
  13131. lineXLeft += token.width;
  13132. leftIndex++;
  13133. }
  13134. while (rightIndex >= 0
  13135. && (token = tokens[rightIndex], token.align === 'right')) {
  13136. this._placeToken(token, style, lineHeight, lineTop, lineXRight, 'right', bgColorDrawn);
  13137. remainedWidth -= token.width;
  13138. lineXRight -= token.width;
  13139. rightIndex--;
  13140. }
  13141. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - remainedWidth) / 2;
  13142. while (leftIndex <= rightIndex) {
  13143. token = tokens[leftIndex];
  13144. this._placeToken(token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center', bgColorDrawn);
  13145. lineXLeft += token.width;
  13146. leftIndex++;
  13147. }
  13148. lineTop += lineHeight;
  13149. }
  13150. };
  13151. ZRText.prototype._placeToken = function (token, style, lineHeight, lineTop, x, textAlign, parentBgColorDrawn) {
  13152. var tokenStyle = style.rich[token.styleName] || {};
  13153. tokenStyle.text = token.text;
  13154. var verticalAlign = token.verticalAlign;
  13155. var y = lineTop + lineHeight / 2;
  13156. if (verticalAlign === 'top') {
  13157. y = lineTop + token.height / 2;
  13158. }
  13159. else if (verticalAlign === 'bottom') {
  13160. y = lineTop + lineHeight - token.height / 2;
  13161. }
  13162. var needDrawBg = !token.isLineHolder && needDrawBackground(tokenStyle);
  13163. needDrawBg && this._renderBackground(tokenStyle, style, textAlign === 'right'
  13164. ? x - token.width
  13165. : textAlign === 'center'
  13166. ? x - token.width / 2
  13167. : x, y - token.height / 2, token.width, token.height);
  13168. var bgColorDrawn = !!tokenStyle.backgroundColor;
  13169. var textPadding = token.textPadding;
  13170. if (textPadding) {
  13171. x = getTextXForPadding(x, textAlign, textPadding);
  13172. y -= token.height / 2 - textPadding[0] - token.innerHeight / 2;
  13173. }
  13174. var el = this._getOrCreateChild(TSpan);
  13175. var subElStyle = el.createStyle();
  13176. el.useStyle(subElStyle);
  13177. var defaultStyle = this._defaultStyle;
  13178. var useDefaultFill = false;
  13179. var defaultLineWidth = 0;
  13180. var textFill = getFill('fill' in tokenStyle ? tokenStyle.fill
  13181. : 'fill' in style ? style.fill
  13182. : (useDefaultFill = true, defaultStyle.fill));
  13183. var textStroke = getStroke('stroke' in tokenStyle ? tokenStyle.stroke
  13184. : 'stroke' in style ? style.stroke
  13185. : (!bgColorDrawn
  13186. && !parentBgColorDrawn
  13187. && (!defaultStyle.autoStroke || useDefaultFill)) ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, defaultStyle.stroke)
  13188. : null);
  13189. var hasShadow = tokenStyle.textShadowBlur > 0
  13190. || style.textShadowBlur > 0;
  13191. subElStyle.text = token.text;
  13192. subElStyle.x = x;
  13193. subElStyle.y = y;
  13194. if (hasShadow) {
  13195. subElStyle.shadowBlur = tokenStyle.textShadowBlur || style.textShadowBlur || 0;
  13196. subElStyle.shadowColor = tokenStyle.textShadowColor || style.textShadowColor || 'transparent';
  13197. subElStyle.shadowOffsetX = tokenStyle.textShadowOffsetX || style.textShadowOffsetX || 0;
  13198. subElStyle.shadowOffsetY = tokenStyle.textShadowOffsetY || style.textShadowOffsetY || 0;
  13199. }
  13200. subElStyle.textAlign = textAlign;
  13201. subElStyle.textBaseline = 'middle';
  13202. subElStyle.font = token.font || DEFAULT_FONT;
  13203. subElStyle.opacity = retrieve3(tokenStyle.opacity, style.opacity, 1);
  13204. setSeparateFont(subElStyle, tokenStyle);
  13205. if (textStroke) {
  13206. subElStyle.lineWidth = retrieve3(tokenStyle.lineWidth, style.lineWidth, defaultLineWidth);
  13207. subElStyle.lineDash = retrieve2(tokenStyle.lineDash, style.lineDash);
  13208. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13209. subElStyle.stroke = textStroke;
  13210. }
  13211. if (textFill) {
  13212. subElStyle.fill = textFill;
  13213. }
  13214. var textWidth = token.contentWidth;
  13215. var textHeight = token.contentHeight;
  13216. el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, textWidth, subElStyle.textAlign), adjustTextY$1(subElStyle.y, textHeight, subElStyle.textBaseline), textWidth, textHeight));
  13217. };
  13218. ZRText.prototype._renderBackground = function (style, topStyle, x, y, width, height) {
  13219. var textBackgroundColor = style.backgroundColor;
  13220. var textBorderWidth = style.borderWidth;
  13221. var textBorderColor = style.borderColor;
  13222. var isImageBg = textBackgroundColor && textBackgroundColor.image;
  13223. var isPlainOrGradientBg = textBackgroundColor && !isImageBg;
  13224. var textBorderRadius = style.borderRadius;
  13225. var self = this;
  13226. var rectEl;
  13227. var imgEl;
  13228. if (isPlainOrGradientBg || style.lineHeight || (textBorderWidth && textBorderColor)) {
  13229. rectEl = this._getOrCreateChild(Rect);
  13230. rectEl.useStyle(rectEl.createStyle());
  13231. rectEl.style.fill = null;
  13232. var rectShape = rectEl.shape;
  13233. rectShape.x = x;
  13234. rectShape.y = y;
  13235. rectShape.width = width;
  13236. rectShape.height = height;
  13237. rectShape.r = textBorderRadius;
  13238. rectEl.dirtyShape();
  13239. }
  13240. if (isPlainOrGradientBg) {
  13241. var rectStyle = rectEl.style;
  13242. rectStyle.fill = textBackgroundColor || null;
  13243. rectStyle.fillOpacity = retrieve2(style.fillOpacity, 1);
  13244. }
  13245. else if (isImageBg) {
  13246. imgEl = this._getOrCreateChild(ZRImage);
  13247. imgEl.onload = function () {
  13248. self.dirtyStyle();
  13249. };
  13250. var imgStyle = imgEl.style;
  13251. imgStyle.image = textBackgroundColor.image;
  13252. imgStyle.x = x;
  13253. imgStyle.y = y;
  13254. imgStyle.width = width;
  13255. imgStyle.height = height;
  13256. }
  13257. if (textBorderWidth && textBorderColor) {
  13258. var rectStyle = rectEl.style;
  13259. rectStyle.lineWidth = textBorderWidth;
  13260. rectStyle.stroke = textBorderColor;
  13261. rectStyle.strokeOpacity = retrieve2(style.strokeOpacity, 1);
  13262. rectStyle.lineDash = style.borderDash;
  13263. rectStyle.lineDashOffset = style.borderDashOffset || 0;
  13264. rectEl.strokeContainThreshold = 0;
  13265. if (rectEl.hasFill() && rectEl.hasStroke()) {
  13266. rectStyle.strokeFirst = true;
  13267. rectStyle.lineWidth *= 2;
  13268. }
  13269. }
  13270. var commonStyle = (rectEl || imgEl).style;
  13271. commonStyle.shadowBlur = style.shadowBlur || 0;
  13272. commonStyle.shadowColor = style.shadowColor || 'transparent';
  13273. commonStyle.shadowOffsetX = style.shadowOffsetX || 0;
  13274. commonStyle.shadowOffsetY = style.shadowOffsetY || 0;
  13275. commonStyle.opacity = retrieve3(style.opacity, topStyle.opacity, 1);
  13276. };
  13277. ZRText.makeFont = function (style) {
  13278. var font = '';
  13279. if (hasSeparateFont(style)) {
  13280. font = [
  13281. style.fontStyle,
  13282. style.fontWeight,
  13283. parseFontSize(style.fontSize),
  13284. style.fontFamily || 'sans-serif'
  13285. ].join(' ');
  13286. }
  13287. return font && trim(font) || style.textFont || style.font;
  13288. };
  13289. return ZRText;
  13290. }(Displayable));
  13291. var VALID_TEXT_ALIGN = { left: true, right: 1, center: 1 };
  13292. var VALID_TEXT_VERTICAL_ALIGN = { top: 1, bottom: 1, middle: 1 };
  13293. var FONT_PARTS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily'];
  13294. function parseFontSize(fontSize) {
  13295. if (typeof fontSize === 'string'
  13296. && (fontSize.indexOf('px') !== -1
  13297. || fontSize.indexOf('rem') !== -1
  13298. || fontSize.indexOf('em') !== -1)) {
  13299. return fontSize;
  13300. }
  13301. else if (!isNaN(+fontSize)) {
  13302. return fontSize + 'px';
  13303. }
  13304. else {
  13305. return DEFAULT_FONT_SIZE + 'px';
  13306. }
  13307. }
  13308. function setSeparateFont(targetStyle, sourceStyle) {
  13309. for (var i = 0; i < FONT_PARTS.length; i++) {
  13310. var fontProp = FONT_PARTS[i];
  13311. var val = sourceStyle[fontProp];
  13312. if (val != null) {
  13313. targetStyle[fontProp] = val;
  13314. }
  13315. }
  13316. }
  13317. function hasSeparateFont(style) {
  13318. return style.fontSize != null || style.fontFamily || style.fontWeight;
  13319. }
  13320. function normalizeTextStyle(style) {
  13321. normalizeStyle(style);
  13322. each(style.rich, normalizeStyle);
  13323. return style;
  13324. }
  13325. function normalizeStyle(style) {
  13326. if (style) {
  13327. style.font = ZRText.makeFont(style);
  13328. var textAlign = style.align;
  13329. textAlign === 'middle' && (textAlign = 'center');
  13330. style.align = (textAlign == null || VALID_TEXT_ALIGN[textAlign]) ? textAlign : 'left';
  13331. var verticalAlign = style.verticalAlign;
  13332. verticalAlign === 'center' && (verticalAlign = 'middle');
  13333. style.verticalAlign = (verticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[verticalAlign]) ? verticalAlign : 'top';
  13334. var textPadding = style.padding;
  13335. if (textPadding) {
  13336. style.padding = normalizeCssArray(style.padding);
  13337. }
  13338. }
  13339. }
  13340. function getStroke(stroke, lineWidth) {
  13341. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  13342. ? null
  13343. : (stroke.image || stroke.colorStops)
  13344. ? '#000'
  13345. : stroke;
  13346. }
  13347. function getFill(fill) {
  13348. return (fill == null || fill === 'none')
  13349. ? null
  13350. : (fill.image || fill.colorStops)
  13351. ? '#000'
  13352. : fill;
  13353. }
  13354. function getTextXForPadding(x, textAlign, textPadding) {
  13355. return textAlign === 'right'
  13356. ? (x - textPadding[1])
  13357. : textAlign === 'center'
  13358. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  13359. : (x + textPadding[3]);
  13360. }
  13361. function getStyleText(style) {
  13362. var text = style.text;
  13363. text != null && (text += '');
  13364. return text;
  13365. }
  13366. function needDrawBackground(style) {
  13367. return !!(style.backgroundColor
  13368. || style.lineHeight
  13369. || (style.borderWidth && style.borderColor));
  13370. }
  13371. var ArcShape = (function () {
  13372. function ArcShape() {
  13373. this.cx = 0;
  13374. this.cy = 0;
  13375. this.r = 0;
  13376. this.startAngle = 0;
  13377. this.endAngle = Math.PI * 2;
  13378. this.clockwise = true;
  13379. }
  13380. return ArcShape;
  13381. }());
  13382. var Arc = (function (_super) {
  13383. __extends(Arc, _super);
  13384. function Arc(opts) {
  13385. return _super.call(this, opts) || this;
  13386. }
  13387. Arc.prototype.getDefaultStyle = function () {
  13388. return {
  13389. stroke: '#000',
  13390. fill: null
  13391. };
  13392. };
  13393. Arc.prototype.getDefaultShape = function () {
  13394. return new ArcShape();
  13395. };
  13396. Arc.prototype.buildPath = function (ctx, shape) {
  13397. var x = shape.cx;
  13398. var y = shape.cy;
  13399. var r = Math.max(shape.r, 0);
  13400. var startAngle = shape.startAngle;
  13401. var endAngle = shape.endAngle;
  13402. var clockwise = shape.clockwise;
  13403. var unitX = Math.cos(startAngle);
  13404. var unitY = Math.sin(startAngle);
  13405. ctx.moveTo(unitX * r + x, unitY * r + y);
  13406. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13407. };
  13408. return Arc;
  13409. }(Path));
  13410. Arc.prototype.type = 'arc';
  13411. var out = [];
  13412. var BezierCurveShape = (function () {
  13413. function BezierCurveShape() {
  13414. this.x1 = 0;
  13415. this.y1 = 0;
  13416. this.x2 = 0;
  13417. this.y2 = 0;
  13418. this.cpx1 = 0;
  13419. this.cpy1 = 0;
  13420. this.percent = 1;
  13421. }
  13422. return BezierCurveShape;
  13423. }());
  13424. function someVectorAt(shape, t, isTangent) {
  13425. var cpx2 = shape.cpx2;
  13426. var cpy2 = shape.cpy2;
  13427. if (cpx2 != null || cpy2 != null) {
  13428. return [
  13429. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  13430. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  13431. ];
  13432. }
  13433. else {
  13434. return [
  13435. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  13436. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  13437. ];
  13438. }
  13439. }
  13440. var BezierCurve = (function (_super) {
  13441. __extends(BezierCurve, _super);
  13442. function BezierCurve(opts) {
  13443. return _super.call(this, opts) || this;
  13444. }
  13445. BezierCurve.prototype.getDefaultStyle = function () {
  13446. return {
  13447. stroke: '#000',
  13448. fill: null
  13449. };
  13450. };
  13451. BezierCurve.prototype.getDefaultShape = function () {
  13452. return new BezierCurveShape();
  13453. };
  13454. BezierCurve.prototype.buildPath = function (ctx, shape) {
  13455. var x1 = shape.x1;
  13456. var y1 = shape.y1;
  13457. var x2 = shape.x2;
  13458. var y2 = shape.y2;
  13459. var cpx1 = shape.cpx1;
  13460. var cpy1 = shape.cpy1;
  13461. var cpx2 = shape.cpx2;
  13462. var cpy2 = shape.cpy2;
  13463. var percent = shape.percent;
  13464. if (percent === 0) {
  13465. return;
  13466. }
  13467. ctx.moveTo(x1, y1);
  13468. if (cpx2 == null || cpy2 == null) {
  13469. if (percent < 1) {
  13470. quadraticSubdivide(x1, cpx1, x2, percent, out);
  13471. cpx1 = out[1];
  13472. x2 = out[2];
  13473. quadraticSubdivide(y1, cpy1, y2, percent, out);
  13474. cpy1 = out[1];
  13475. y2 = out[2];
  13476. }
  13477. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  13478. }
  13479. else {
  13480. if (percent < 1) {
  13481. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  13482. cpx1 = out[1];
  13483. cpx2 = out[2];
  13484. x2 = out[3];
  13485. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  13486. cpy1 = out[1];
  13487. cpy2 = out[2];
  13488. y2 = out[3];
  13489. }
  13490. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  13491. }
  13492. };
  13493. BezierCurve.prototype.pointAt = function (t) {
  13494. return someVectorAt(this.shape, t, false);
  13495. };
  13496. BezierCurve.prototype.tangentAt = function (t) {
  13497. var p = someVectorAt(this.shape, t, true);
  13498. return normalize(p, p);
  13499. };
  13500. return BezierCurve;
  13501. }(Path));
  13502. BezierCurve.prototype.type = 'bezier-curve';
  13503. var DropletShape = (function () {
  13504. function DropletShape() {
  13505. this.cx = 0;
  13506. this.cy = 0;
  13507. this.width = 0;
  13508. this.height = 0;
  13509. }
  13510. return DropletShape;
  13511. }());
  13512. var Droplet = (function (_super) {
  13513. __extends(Droplet, _super);
  13514. function Droplet(opts) {
  13515. return _super.call(this, opts) || this;
  13516. }
  13517. Droplet.prototype.getDefaultShape = function () {
  13518. return new DropletShape();
  13519. };
  13520. Droplet.prototype.buildPath = function (ctx, shape) {
  13521. var x = shape.cx;
  13522. var y = shape.cy;
  13523. var a = shape.width;
  13524. var b = shape.height;
  13525. ctx.moveTo(x, y + a);
  13526. ctx.bezierCurveTo(x + a, y + a, x + a * 3 / 2, y - a / 3, x, y - b);
  13527. ctx.bezierCurveTo(x - a * 3 / 2, y - a / 3, x - a, y + a, x, y + a);
  13528. ctx.closePath();
  13529. };
  13530. return Droplet;
  13531. }(Path));
  13532. Droplet.prototype.type = 'droplet';
  13533. var HeartShape = (function () {
  13534. function HeartShape() {
  13535. this.cx = 0;
  13536. this.cy = 0;
  13537. this.width = 0;
  13538. this.height = 0;
  13539. }
  13540. return HeartShape;
  13541. }());
  13542. var Heart = (function (_super) {
  13543. __extends(Heart, _super);
  13544. function Heart(opts) {
  13545. return _super.call(this, opts) || this;
  13546. }
  13547. Heart.prototype.getDefaultShape = function () {
  13548. return new HeartShape();
  13549. };
  13550. Heart.prototype.buildPath = function (ctx, shape) {
  13551. var x = shape.cx;
  13552. var y = shape.cy;
  13553. var a = shape.width;
  13554. var b = shape.height;
  13555. ctx.moveTo(x, y);
  13556. ctx.bezierCurveTo(x + a / 2, y - b * 2 / 3, x + a * 2, y + b / 3, x, y + b);
  13557. ctx.bezierCurveTo(x - a * 2, y + b / 3, x - a / 2, y - b * 2 / 3, x, y);
  13558. };
  13559. return Heart;
  13560. }(Path));
  13561. Heart.prototype.type = 'heart';
  13562. var PI$3 = Math.PI;
  13563. var sin = Math.sin;
  13564. var cos = Math.cos;
  13565. var IsogonShape = (function () {
  13566. function IsogonShape() {
  13567. this.x = 0;
  13568. this.y = 0;
  13569. this.r = 0;
  13570. this.n = 0;
  13571. }
  13572. return IsogonShape;
  13573. }());
  13574. var Isogon = (function (_super) {
  13575. __extends(Isogon, _super);
  13576. function Isogon(opts) {
  13577. return _super.call(this, opts) || this;
  13578. }
  13579. Isogon.prototype.getDefaultShape = function () {
  13580. return new IsogonShape();
  13581. };
  13582. Isogon.prototype.buildPath = function (ctx, shape) {
  13583. var n = shape.n;
  13584. if (!n || n < 2) {
  13585. return;
  13586. }
  13587. var x = shape.x;
  13588. var y = shape.y;
  13589. var r = shape.r;
  13590. var dStep = 2 * PI$3 / n;
  13591. var deg = -PI$3 / 2;
  13592. ctx.moveTo(x + r * cos(deg), y + r * sin(deg));
  13593. for (var i = 0, end = n - 1; i < end; i++) {
  13594. deg += dStep;
  13595. ctx.lineTo(x + r * cos(deg), y + r * sin(deg));
  13596. }
  13597. ctx.closePath();
  13598. return;
  13599. };
  13600. return Isogon;
  13601. }(Path));
  13602. Isogon.prototype.type = 'isogon';
  13603. var RingShape = (function () {
  13604. function RingShape() {
  13605. this.cx = 0;
  13606. this.cy = 0;
  13607. this.r = 0;
  13608. this.r0 = 0;
  13609. }
  13610. return RingShape;
  13611. }());
  13612. var Ring = (function (_super) {
  13613. __extends(Ring, _super);
  13614. function Ring(opts) {
  13615. return _super.call(this, opts) || this;
  13616. }
  13617. Ring.prototype.getDefaultShape = function () {
  13618. return new RingShape();
  13619. };
  13620. Ring.prototype.buildPath = function (ctx, shape) {
  13621. var x = shape.cx;
  13622. var y = shape.cy;
  13623. var PI2 = Math.PI * 2;
  13624. ctx.moveTo(x + shape.r, y);
  13625. ctx.arc(x, y, shape.r, 0, PI2, false);
  13626. ctx.moveTo(x + shape.r0, y);
  13627. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13628. };
  13629. return Ring;
  13630. }(Path));
  13631. Ring.prototype.type = 'ring';
  13632. var sin$1 = Math.sin;
  13633. var cos$1 = Math.cos;
  13634. var radian = Math.PI / 180;
  13635. var RoseShape = (function () {
  13636. function RoseShape() {
  13637. this.cx = 0;
  13638. this.cy = 0;
  13639. this.r = [];
  13640. this.k = 0;
  13641. this.n = 1;
  13642. }
  13643. return RoseShape;
  13644. }());
  13645. var Rose = (function (_super) {
  13646. __extends(Rose, _super);
  13647. function Rose(opts) {
  13648. return _super.call(this, opts) || this;
  13649. }
  13650. Rose.prototype.getDefaultStyle = function () {
  13651. return {
  13652. stroke: '#000',
  13653. fill: null
  13654. };
  13655. };
  13656. Rose.prototype.getDefaultShape = function () {
  13657. return new RoseShape();
  13658. };
  13659. Rose.prototype.buildPath = function (ctx, shape) {
  13660. var R = shape.r;
  13661. var k = shape.k;
  13662. var n = shape.n;
  13663. var x0 = shape.cx;
  13664. var y0 = shape.cy;
  13665. var x;
  13666. var y;
  13667. var r;
  13668. ctx.moveTo(x0, y0);
  13669. for (var i = 0, len = R.length; i < len; i++) {
  13670. r = R[i];
  13671. for (var j = 0; j <= 360 * n; j++) {
  13672. x = r
  13673. * sin$1(k / n * j % 360 * radian)
  13674. * cos$1(j * radian)
  13675. + x0;
  13676. y = r
  13677. * sin$1(k / n * j % 360 * radian)
  13678. * sin$1(j * radian)
  13679. + y0;
  13680. ctx.lineTo(x, y);
  13681. }
  13682. }
  13683. };
  13684. return Rose;
  13685. }(Path));
  13686. Rose.prototype.type = 'rose';
  13687. var PI$4 = Math.PI;
  13688. var cos$2 = Math.cos;
  13689. var sin$2 = Math.sin;
  13690. var StarShape = (function () {
  13691. function StarShape() {
  13692. this.cx = 0;
  13693. this.cy = 0;
  13694. this.n = 3;
  13695. this.r = 0;
  13696. }
  13697. return StarShape;
  13698. }());
  13699. var Star = (function (_super) {
  13700. __extends(Star, _super);
  13701. function Star(opts) {
  13702. return _super.call(this, opts) || this;
  13703. }
  13704. Star.prototype.getDefaultShape = function () {
  13705. return new StarShape();
  13706. };
  13707. Star.prototype.buildPath = function (ctx, shape) {
  13708. var n = shape.n;
  13709. if (!n || n < 2) {
  13710. return;
  13711. }
  13712. var x = shape.cx;
  13713. var y = shape.cy;
  13714. var r = shape.r;
  13715. var r0 = shape.r0;
  13716. if (r0 == null) {
  13717. r0 = n > 4
  13718. ? r * cos$2(2 * PI$4 / n) / cos$2(PI$4 / n)
  13719. : r / 3;
  13720. }
  13721. var dStep = PI$4 / n;
  13722. var deg = -PI$4 / 2;
  13723. var xStart = x + r * cos$2(deg);
  13724. var yStart = y + r * sin$2(deg);
  13725. deg += dStep;
  13726. ctx.moveTo(xStart, yStart);
  13727. for (var i = 0, end = n * 2 - 1, ri = void 0; i < end; i++) {
  13728. ri = i % 2 === 0 ? r0 : r;
  13729. ctx.lineTo(x + ri * cos$2(deg), y + ri * sin$2(deg));
  13730. deg += dStep;
  13731. }
  13732. ctx.closePath();
  13733. };
  13734. return Star;
  13735. }(Path));
  13736. Star.prototype.type = 'star';
  13737. var cos$3 = Math.cos;
  13738. var sin$3 = Math.sin;
  13739. var TrochoidShape = (function () {
  13740. function TrochoidShape() {
  13741. this.cx = 0;
  13742. this.cy = 0;
  13743. this.r = 0;
  13744. this.r0 = 0;
  13745. this.d = 0;
  13746. this.location = 'out';
  13747. }
  13748. return TrochoidShape;
  13749. }());
  13750. var Trochoid = (function (_super) {
  13751. __extends(Trochoid, _super);
  13752. function Trochoid(opts) {
  13753. return _super.call(this, opts) || this;
  13754. }
  13755. Trochoid.prototype.getDefaultStyle = function () {
  13756. return {
  13757. stroke: '#000',
  13758. fill: null
  13759. };
  13760. };
  13761. Trochoid.prototype.getDefaultShape = function () {
  13762. return new TrochoidShape();
  13763. };
  13764. Trochoid.prototype.buildPath = function (ctx, shape) {
  13765. var R = shape.r;
  13766. var r = shape.r0;
  13767. var d = shape.d;
  13768. var offsetX = shape.cx;
  13769. var offsetY = shape.cy;
  13770. var delta = shape.location === 'out' ? 1 : -1;
  13771. var x1;
  13772. var y1;
  13773. var x2;
  13774. var y2;
  13775. if (shape.location && R <= r) {
  13776. return;
  13777. }
  13778. var num = 0;
  13779. var i = 1;
  13780. var theta;
  13781. x1 = (R + delta * r) * cos$3(0)
  13782. - delta * d * cos$3(0) + offsetX;
  13783. y1 = (R + delta * r) * sin$3(0)
  13784. - d * sin$3(0) + offsetY;
  13785. ctx.moveTo(x1, y1);
  13786. do {
  13787. num++;
  13788. } while ((r * num) % (R + delta * r) !== 0);
  13789. do {
  13790. theta = Math.PI / 180 * i;
  13791. x2 = (R + delta * r) * cos$3(theta)
  13792. - delta * d * cos$3((R / r + delta) * theta)
  13793. + offsetX;
  13794. y2 = (R + delta * r) * sin$3(theta)
  13795. - d * sin$3((R / r + delta) * theta)
  13796. + offsetY;
  13797. ctx.lineTo(x2, y2);
  13798. i++;
  13799. } while (i <= (r * num) / (R + delta * r) * 360);
  13800. };
  13801. return Trochoid;
  13802. }(Path));
  13803. Trochoid.prototype.type = 'trochoid';
  13804. var Pattern = (function () {
  13805. function Pattern(image, repeat) {
  13806. this.image = image;
  13807. this.repeat = repeat;
  13808. this.x = 0;
  13809. this.y = 0;
  13810. this.rotation = 0;
  13811. this.scaleX = 1;
  13812. this.scaleY = 1;
  13813. }
  13814. return Pattern;
  13815. }());
  13816. var extent = [0, 0];
  13817. var extent2 = [0, 0];
  13818. var minTv$1 = new Point();
  13819. var maxTv$1 = new Point();
  13820. var OrientedBoundingRect = (function () {
  13821. function OrientedBoundingRect(rect, transform) {
  13822. this._corners = [];
  13823. this._axes = [];
  13824. this._origin = [0, 0];
  13825. for (var i = 0; i < 4; i++) {
  13826. this._corners[i] = new Point();
  13827. }
  13828. for (var i = 0; i < 2; i++) {
  13829. this._axes[i] = new Point();
  13830. }
  13831. if (rect) {
  13832. this.fromBoundingRect(rect, transform);
  13833. }
  13834. }
  13835. OrientedBoundingRect.prototype.fromBoundingRect = function (rect, transform) {
  13836. var corners = this._corners;
  13837. var axes = this._axes;
  13838. var x = rect.x;
  13839. var y = rect.y;
  13840. var x2 = x + rect.width;
  13841. var y2 = y + rect.height;
  13842. corners[0].set(x, y);
  13843. corners[1].set(x2, y);
  13844. corners[2].set(x2, y2);
  13845. corners[3].set(x, y2);
  13846. if (transform) {
  13847. for (var i = 0; i < 4; i++) {
  13848. corners[i].transform(transform);
  13849. }
  13850. }
  13851. Point.sub(axes[0], corners[1], corners[0]);
  13852. Point.sub(axes[1], corners[3], corners[0]);
  13853. axes[0].normalize();
  13854. axes[1].normalize();
  13855. for (var i = 0; i < 2; i++) {
  13856. this._origin[i] = axes[i].dot(corners[0]);
  13857. }
  13858. };
  13859. OrientedBoundingRect.prototype.intersect = function (other, mtv) {
  13860. var overlapped = true;
  13861. var noMtv = !mtv;
  13862. minTv$1.set(Infinity, Infinity);
  13863. maxTv$1.set(0, 0);
  13864. if (!this._intersectCheckOneSide(this, other, minTv$1, maxTv$1, noMtv, 1)) {
  13865. overlapped = false;
  13866. if (noMtv) {
  13867. return overlapped;
  13868. }
  13869. }
  13870. if (!this._intersectCheckOneSide(other, this, minTv$1, maxTv$1, noMtv, -1)) {
  13871. overlapped = false;
  13872. if (noMtv) {
  13873. return overlapped;
  13874. }
  13875. }
  13876. if (!noMtv) {
  13877. Point.copy(mtv, overlapped ? minTv$1 : maxTv$1);
  13878. }
  13879. return overlapped;
  13880. };
  13881. OrientedBoundingRect.prototype._intersectCheckOneSide = function (self, other, minTv, maxTv, noMtv, inverse) {
  13882. var overlapped = true;
  13883. for (var i = 0; i < 2; i++) {
  13884. var axis = this._axes[i];
  13885. this._getProjMinMaxOnAxis(i, self._corners, extent);
  13886. this._getProjMinMaxOnAxis(i, other._corners, extent2);
  13887. if (extent[1] < extent2[0] || extent[0] > extent2[1]) {
  13888. overlapped = false;
  13889. if (noMtv) {
  13890. return overlapped;
  13891. }
  13892. var dist0 = Math.abs(extent2[0] - extent[1]);
  13893. var dist1 = Math.abs(extent[0] - extent2[1]);
  13894. if (Math.min(dist0, dist1) > maxTv.len()) {
  13895. if (dist0 < dist1) {
  13896. Point.scale(maxTv, axis, -dist0 * inverse);
  13897. }
  13898. else {
  13899. Point.scale(maxTv, axis, dist1 * inverse);
  13900. }
  13901. }
  13902. }
  13903. else if (minTv) {
  13904. var dist0 = Math.abs(extent2[0] - extent[1]);
  13905. var dist1 = Math.abs(extent[0] - extent2[1]);
  13906. if (Math.min(dist0, dist1) < minTv.len()) {
  13907. if (dist0 < dist1) {
  13908. Point.scale(minTv, axis, dist0 * inverse);
  13909. }
  13910. else {
  13911. Point.scale(minTv, axis, -dist1 * inverse);
  13912. }
  13913. }
  13914. }
  13915. }
  13916. return overlapped;
  13917. };
  13918. OrientedBoundingRect.prototype._getProjMinMaxOnAxis = function (dim, corners, out) {
  13919. var axis = this._axes[dim];
  13920. var origin = this._origin;
  13921. var proj = corners[0].dot(axis) + origin[dim];
  13922. var min = proj;
  13923. var max = proj;
  13924. for (var i = 1; i < corners.length; i++) {
  13925. var proj_1 = corners[i].dot(axis) + origin[dim];
  13926. min = Math.min(proj_1, min);
  13927. max = Math.max(proj_1, max);
  13928. }
  13929. out[0] = min;
  13930. out[1] = max;
  13931. };
  13932. return OrientedBoundingRect;
  13933. }());
  13934. var DebugRect = (function () {
  13935. function DebugRect(style) {
  13936. var dom = this.dom = document.createElement('div');
  13937. dom.className = 'ec-debug-dirty-rect';
  13938. style = extend({}, style);
  13939. extend(style, {
  13940. backgroundColor: 'rgba(0, 0, 255, 0.2)',
  13941. border: '1px solid #00f'
  13942. });
  13943. dom.style.cssText = "\nposition: absolute;\nopacity: 0;\ntransition: opacity 0.5s linear;\npointer-events: none;\n";
  13944. for (var key in style) {
  13945. if (style.hasOwnProperty(key)) {
  13946. dom.style[key] = style[key];
  13947. }
  13948. }
  13949. }
  13950. DebugRect.prototype.update = function (rect) {
  13951. var domStyle = this.dom.style;
  13952. domStyle.width = rect.width + 'px';
  13953. domStyle.height = rect.height + 'px';
  13954. domStyle.left = rect.x + 'px';
  13955. domStyle.top = rect.y + 'px';
  13956. };
  13957. DebugRect.prototype.hide = function () {
  13958. this.dom.style.opacity = '0';
  13959. };
  13960. DebugRect.prototype.show = function (autoHideDelay) {
  13961. var _this = this;
  13962. clearTimeout(this._hideTimeout);
  13963. this.dom.style.opacity = '1';
  13964. this._hideTimeout = setTimeout(function () {
  13965. _this.hide();
  13966. }, autoHideDelay || 1000);
  13967. };
  13968. return DebugRect;
  13969. }());
  13970. function showDebugDirtyRect(zr, opts) {
  13971. opts = opts || {};
  13972. var painter = zr.painter;
  13973. if (!painter.getLayers) {
  13974. throw new Error('Debug dirty rect can only been used on canvas renderer.');
  13975. }
  13976. if (painter.isSingleCanvas()) {
  13977. throw new Error('Debug dirty rect can only been used on zrender inited with container.');
  13978. }
  13979. var debugViewRoot = document.createElement('div');
  13980. debugViewRoot.style.cssText = "\nposition:absolute;\nleft:0;\ntop:0;\nright:0;\nbottom:0;\npointer-events:none;\n";
  13981. debugViewRoot.className = 'ec-debug-dirty-rect-container';
  13982. var debugRects = [];
  13983. var dom = zr.dom;
  13984. dom.appendChild(debugViewRoot);
  13985. var computedStyle = getComputedStyle(dom);
  13986. if (computedStyle.position === 'static') {
  13987. dom.style.position = 'relative';
  13988. }
  13989. zr.on('rendered', function () {
  13990. if (painter.getLayers) {
  13991. var idx_1 = 0;
  13992. painter.eachBuiltinLayer(function (layer) {
  13993. if (!layer.debugGetPaintRects) {
  13994. return;
  13995. }
  13996. var paintRects = layer.debugGetPaintRects();
  13997. for (var i = 0; i < paintRects.length; i++) {
  13998. if (!paintRects[i].width || !paintRects[i].height) {
  13999. continue;
  14000. }
  14001. if (!debugRects[idx_1]) {
  14002. debugRects[idx_1] = new DebugRect(opts.style);
  14003. debugViewRoot.appendChild(debugRects[idx_1].dom);
  14004. }
  14005. debugRects[idx_1].show(opts.autoHideDelay);
  14006. debugRects[idx_1].update(paintRects[i]);
  14007. idx_1++;
  14008. }
  14009. });
  14010. for (var i = idx_1; i < debugRects.length; i++) {
  14011. debugRects[i].hide();
  14012. }
  14013. }
  14014. });
  14015. }
  14016. function isSafeNum(num) {
  14017. return isFinite(num);
  14018. }
  14019. function createLinearGradient(ctx, obj, rect) {
  14020. var x = obj.x == null ? 0 : obj.x;
  14021. var x2 = obj.x2 == null ? 1 : obj.x2;
  14022. var y = obj.y == null ? 0 : obj.y;
  14023. var y2 = obj.y2 == null ? 0 : obj.y2;
  14024. if (!obj.global) {
  14025. x = x * rect.width + rect.x;
  14026. x2 = x2 * rect.width + rect.x;
  14027. y = y * rect.height + rect.y;
  14028. y2 = y2 * rect.height + rect.y;
  14029. }
  14030. x = isSafeNum(x) ? x : 0;
  14031. x2 = isSafeNum(x2) ? x2 : 1;
  14032. y = isSafeNum(y) ? y : 0;
  14033. y2 = isSafeNum(y2) ? y2 : 0;
  14034. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  14035. return canvasGradient;
  14036. }
  14037. function createRadialGradient(ctx, obj, rect) {
  14038. var width = rect.width;
  14039. var height = rect.height;
  14040. var min = Math.min(width, height);
  14041. var x = obj.x == null ? 0.5 : obj.x;
  14042. var y = obj.y == null ? 0.5 : obj.y;
  14043. var r = obj.r == null ? 0.5 : obj.r;
  14044. if (!obj.global) {
  14045. x = x * width + rect.x;
  14046. y = y * height + rect.y;
  14047. r = r * min;
  14048. }
  14049. x = isSafeNum(x) ? x : 0.5;
  14050. y = isSafeNum(y) ? y : 0.5;
  14051. r = r >= 0 && isSafeNum(r) ? r : 0.5;
  14052. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  14053. return canvasGradient;
  14054. }
  14055. function getCanvasGradient(ctx, obj, rect) {
  14056. var canvasGradient = obj.type === 'radial'
  14057. ? createRadialGradient(ctx, obj, rect)
  14058. : createLinearGradient(ctx, obj, rect);
  14059. var colorStops = obj.colorStops;
  14060. for (var i = 0; i < colorStops.length; i++) {
  14061. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  14062. }
  14063. return canvasGradient;
  14064. }
  14065. function isClipPathChanged(clipPaths, prevClipPaths) {
  14066. if (clipPaths === prevClipPaths || (!clipPaths && !prevClipPaths)) {
  14067. return false;
  14068. }
  14069. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  14070. return true;
  14071. }
  14072. for (var i = 0; i < clipPaths.length; i++) {
  14073. if (clipPaths[i] !== prevClipPaths[i]) {
  14074. return true;
  14075. }
  14076. }
  14077. return false;
  14078. }
  14079. function parseInt10(val) {
  14080. return parseInt(val, 10);
  14081. }
  14082. function getSize(root, whIdx, opts) {
  14083. var wh = ['width', 'height'][whIdx];
  14084. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  14085. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  14086. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  14087. if (opts[wh] != null && opts[wh] !== 'auto') {
  14088. return parseFloat(opts[wh]);
  14089. }
  14090. var stl = document.defaultView.getComputedStyle(root);
  14091. return ((root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  14092. - (parseInt10(stl[plt]) || 0)
  14093. - (parseInt10(stl[prb]) || 0)) | 0;
  14094. }
  14095. function normalizeLineDash(lineType, lineWidth) {
  14096. if (!lineType || lineType === 'solid' || !(lineWidth > 0)) {
  14097. return null;
  14098. }
  14099. return lineType === 'dashed'
  14100. ? [4 * lineWidth, 2 * lineWidth]
  14101. : lineType === 'dotted'
  14102. ? [lineWidth]
  14103. : isNumber(lineType)
  14104. ? [lineType] : isArray(lineType) ? lineType : null;
  14105. }
  14106. function getLineDash(el) {
  14107. var style = el.style;
  14108. var lineDash = style.lineDash && style.lineWidth > 0 && normalizeLineDash(style.lineDash, style.lineWidth);
  14109. var lineDashOffset = style.lineDashOffset;
  14110. if (lineDash) {
  14111. var lineScale_1 = (style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1;
  14112. if (lineScale_1 && lineScale_1 !== 1) {
  14113. lineDash = map(lineDash, function (rawVal) {
  14114. return rawVal / lineScale_1;
  14115. });
  14116. lineDashOffset /= lineScale_1;
  14117. }
  14118. }
  14119. return [lineDash, lineDashOffset];
  14120. }
  14121. var pathProxyForDraw = new PathProxy(true);
  14122. function styleHasStroke(style) {
  14123. var stroke = style.stroke;
  14124. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  14125. }
  14126. function isValidStrokeFillStyle(strokeOrFill) {
  14127. return typeof strokeOrFill === 'string' && strokeOrFill !== 'none';
  14128. }
  14129. function styleHasFill(style) {
  14130. var fill = style.fill;
  14131. return fill != null && fill !== 'none';
  14132. }
  14133. function doFillPath(ctx, style) {
  14134. if (style.fillOpacity != null && style.fillOpacity !== 1) {
  14135. var originalGlobalAlpha = ctx.globalAlpha;
  14136. ctx.globalAlpha = style.fillOpacity * style.opacity;
  14137. ctx.fill();
  14138. ctx.globalAlpha = originalGlobalAlpha;
  14139. }
  14140. else {
  14141. ctx.fill();
  14142. }
  14143. }
  14144. function doStrokePath(ctx, style) {
  14145. if (style.strokeOpacity != null && style.strokeOpacity !== 1) {
  14146. var originalGlobalAlpha = ctx.globalAlpha;
  14147. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  14148. ctx.stroke();
  14149. ctx.globalAlpha = originalGlobalAlpha;
  14150. }
  14151. else {
  14152. ctx.stroke();
  14153. }
  14154. }
  14155. function createCanvasPattern(ctx, pattern, el) {
  14156. var image = createOrUpdateImage(pattern.image, pattern.__image, el);
  14157. if (isImageReady(image)) {
  14158. var canvasPattern = ctx.createPattern(image, pattern.repeat || 'repeat');
  14159. if (typeof DOMMatrix === 'function'
  14160. && canvasPattern
  14161. && canvasPattern.setTransform) {
  14162. var matrix = new DOMMatrix();
  14163. matrix.translateSelf((pattern.x || 0), (pattern.y || 0));
  14164. matrix.rotateSelf(0, 0, (pattern.rotation || 0) * RADIAN_TO_DEGREE);
  14165. matrix.scaleSelf((pattern.scaleX || 1), (pattern.scaleY || 1));
  14166. canvasPattern.setTransform(matrix);
  14167. }
  14168. return canvasPattern;
  14169. }
  14170. }
  14171. function brushPath(ctx, el, style, inBatch) {
  14172. var _a;
  14173. var hasStroke = styleHasStroke(style);
  14174. var hasFill = styleHasFill(style);
  14175. var strokePercent = style.strokePercent;
  14176. var strokePart = strokePercent < 1;
  14177. var firstDraw = !el.path;
  14178. if ((!el.silent || strokePart) && firstDraw) {
  14179. el.createPathProxy();
  14180. }
  14181. var path = el.path || pathProxyForDraw;
  14182. var dirtyFlag = el.__dirty;
  14183. if (!inBatch) {
  14184. var fill = style.fill;
  14185. var stroke = style.stroke;
  14186. var hasFillGradient = hasFill && !!fill.colorStops;
  14187. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  14188. var hasFillPattern = hasFill && !!fill.image;
  14189. var hasStrokePattern = hasStroke && !!stroke.image;
  14190. var fillGradient = void 0;
  14191. var strokeGradient = void 0;
  14192. var fillPattern = void 0;
  14193. var strokePattern = void 0;
  14194. var rect = void 0;
  14195. if (hasFillGradient || hasStrokeGradient) {
  14196. rect = el.getBoundingRect();
  14197. }
  14198. if (hasFillGradient) {
  14199. fillGradient = dirtyFlag
  14200. ? getCanvasGradient(ctx, fill, rect)
  14201. : el.__canvasFillGradient;
  14202. el.__canvasFillGradient = fillGradient;
  14203. }
  14204. if (hasStrokeGradient) {
  14205. strokeGradient = dirtyFlag
  14206. ? getCanvasGradient(ctx, stroke, rect)
  14207. : el.__canvasStrokeGradient;
  14208. el.__canvasStrokeGradient = strokeGradient;
  14209. }
  14210. if (hasFillPattern) {
  14211. fillPattern = (dirtyFlag || !el.__canvasFillPattern)
  14212. ? createCanvasPattern(ctx, fill, el)
  14213. : el.__canvasFillPattern;
  14214. el.__canvasFillPattern = fillPattern;
  14215. }
  14216. if (hasStrokePattern) {
  14217. strokePattern = (dirtyFlag || !el.__canvasStrokePattern)
  14218. ? createCanvasPattern(ctx, stroke, el)
  14219. : el.__canvasStrokePattern;
  14220. el.__canvasStrokePattern = fillPattern;
  14221. }
  14222. if (hasFillGradient) {
  14223. ctx.fillStyle = fillGradient;
  14224. }
  14225. else if (hasFillPattern) {
  14226. if (fillPattern) {
  14227. ctx.fillStyle = fillPattern;
  14228. }
  14229. else {
  14230. hasFill = false;
  14231. }
  14232. }
  14233. if (hasStrokeGradient) {
  14234. ctx.strokeStyle = strokeGradient;
  14235. }
  14236. else if (hasStrokePattern) {
  14237. if (strokePattern) {
  14238. ctx.strokeStyle = strokePattern;
  14239. }
  14240. else {
  14241. hasStroke = false;
  14242. }
  14243. }
  14244. }
  14245. var scale = el.getGlobalScale();
  14246. path.setScale(scale[0], scale[1], el.segmentIgnoreThreshold);
  14247. var lineDash;
  14248. var lineDashOffset;
  14249. if (ctx.setLineDash && style.lineDash) {
  14250. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14251. }
  14252. var needsRebuild = true;
  14253. if (firstDraw || (dirtyFlag & SHAPE_CHANGED_BIT)) {
  14254. path.setDPR(ctx.dpr);
  14255. if (strokePart) {
  14256. path.setContext(null);
  14257. }
  14258. else {
  14259. path.setContext(ctx);
  14260. needsRebuild = false;
  14261. }
  14262. path.reset();
  14263. el.buildPath(path, el.shape, inBatch);
  14264. path.toStatic();
  14265. el.pathUpdated();
  14266. }
  14267. if (needsRebuild) {
  14268. path.rebuildPath(ctx, strokePart ? strokePercent : 1);
  14269. }
  14270. if (lineDash) {
  14271. ctx.setLineDash(lineDash);
  14272. ctx.lineDashOffset = lineDashOffset;
  14273. }
  14274. if (!inBatch) {
  14275. if (style.strokeFirst) {
  14276. if (hasStroke) {
  14277. doStrokePath(ctx, style);
  14278. }
  14279. if (hasFill) {
  14280. doFillPath(ctx, style);
  14281. }
  14282. }
  14283. else {
  14284. if (hasFill) {
  14285. doFillPath(ctx, style);
  14286. }
  14287. if (hasStroke) {
  14288. doStrokePath(ctx, style);
  14289. }
  14290. }
  14291. }
  14292. if (lineDash) {
  14293. ctx.setLineDash([]);
  14294. }
  14295. }
  14296. function brushImage(ctx, el, style) {
  14297. var image = el.__image = createOrUpdateImage(style.image, el.__image, el, el.onload);
  14298. if (!image || !isImageReady(image)) {
  14299. return;
  14300. }
  14301. var x = style.x || 0;
  14302. var y = style.y || 0;
  14303. var width = el.getWidth();
  14304. var height = el.getHeight();
  14305. var aspect = image.width / image.height;
  14306. if (width == null && height != null) {
  14307. width = height * aspect;
  14308. }
  14309. else if (height == null && width != null) {
  14310. height = width / aspect;
  14311. }
  14312. else if (width == null && height == null) {
  14313. width = image.width;
  14314. height = image.height;
  14315. }
  14316. if (style.sWidth && style.sHeight) {
  14317. var sx = style.sx || 0;
  14318. var sy = style.sy || 0;
  14319. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  14320. }
  14321. else if (style.sx && style.sy) {
  14322. var sx = style.sx;
  14323. var sy = style.sy;
  14324. var sWidth = width - sx;
  14325. var sHeight = height - sy;
  14326. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  14327. }
  14328. else {
  14329. ctx.drawImage(image, x, y, width, height);
  14330. }
  14331. }
  14332. function brushText(ctx, el, style) {
  14333. var _a;
  14334. var text = style.text;
  14335. text != null && (text += '');
  14336. if (text) {
  14337. ctx.font = style.font || DEFAULT_FONT;
  14338. ctx.textAlign = style.textAlign;
  14339. ctx.textBaseline = style.textBaseline;
  14340. var lineDash = void 0;
  14341. var lineDashOffset = void 0;
  14342. if (ctx.setLineDash && style.lineDash) {
  14343. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14344. }
  14345. if (lineDash) {
  14346. ctx.setLineDash(lineDash);
  14347. ctx.lineDashOffset = lineDashOffset;
  14348. }
  14349. if (style.strokeFirst) {
  14350. if (styleHasStroke(style)) {
  14351. ctx.strokeText(text, style.x, style.y);
  14352. }
  14353. if (styleHasFill(style)) {
  14354. ctx.fillText(text, style.x, style.y);
  14355. }
  14356. }
  14357. else {
  14358. if (styleHasFill(style)) {
  14359. ctx.fillText(text, style.x, style.y);
  14360. }
  14361. if (styleHasStroke(style)) {
  14362. ctx.strokeText(text, style.x, style.y);
  14363. }
  14364. }
  14365. if (lineDash) {
  14366. ctx.setLineDash([]);
  14367. }
  14368. }
  14369. }
  14370. var SHADOW_NUMBER_PROPS = ['shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  14371. var STROKE_PROPS = [
  14372. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  14373. ];
  14374. function bindCommonProps(ctx, style, prevStyle, forceSetAll, scope) {
  14375. var styleChanged = false;
  14376. if (!forceSetAll) {
  14377. prevStyle = prevStyle || {};
  14378. if (style === prevStyle) {
  14379. return false;
  14380. }
  14381. }
  14382. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14383. flushPathDrawn(ctx, scope);
  14384. styleChanged = true;
  14385. var opacity = Math.max(Math.min(style.opacity, 1), 0);
  14386. ctx.globalAlpha = isNaN(opacity) ? DEFAULT_COMMON_STYLE.opacity : opacity;
  14387. }
  14388. if (forceSetAll || style.blend !== prevStyle.blend) {
  14389. if (!styleChanged) {
  14390. flushPathDrawn(ctx, scope);
  14391. styleChanged = true;
  14392. }
  14393. ctx.globalCompositeOperation = style.blend || DEFAULT_COMMON_STYLE.blend;
  14394. }
  14395. for (var i = 0; i < SHADOW_NUMBER_PROPS.length; i++) {
  14396. var propName = SHADOW_NUMBER_PROPS[i];
  14397. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14398. if (!styleChanged) {
  14399. flushPathDrawn(ctx, scope);
  14400. styleChanged = true;
  14401. }
  14402. ctx[propName] = ctx.dpr * (style[propName] || 0);
  14403. }
  14404. }
  14405. if (forceSetAll || style.shadowColor !== prevStyle.shadowColor) {
  14406. if (!styleChanged) {
  14407. flushPathDrawn(ctx, scope);
  14408. styleChanged = true;
  14409. }
  14410. ctx.shadowColor = style.shadowColor || DEFAULT_COMMON_STYLE.shadowColor;
  14411. }
  14412. return styleChanged;
  14413. }
  14414. function bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetAll, scope) {
  14415. var style = getStyle(el, scope.inHover);
  14416. var prevStyle = forceSetAll
  14417. ? null
  14418. : (prevEl && getStyle(prevEl, scope.inHover) || {});
  14419. if (style === prevStyle) {
  14420. return false;
  14421. }
  14422. var styleChanged = bindCommonProps(ctx, style, prevStyle, forceSetAll, scope);
  14423. if (forceSetAll || style.fill !== prevStyle.fill) {
  14424. if (!styleChanged) {
  14425. flushPathDrawn(ctx, scope);
  14426. styleChanged = true;
  14427. }
  14428. isValidStrokeFillStyle(style.fill) && (ctx.fillStyle = style.fill);
  14429. }
  14430. if (forceSetAll || style.stroke !== prevStyle.stroke) {
  14431. if (!styleChanged) {
  14432. flushPathDrawn(ctx, scope);
  14433. styleChanged = true;
  14434. }
  14435. isValidStrokeFillStyle(style.stroke) && (ctx.strokeStyle = style.stroke);
  14436. }
  14437. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14438. if (!styleChanged) {
  14439. flushPathDrawn(ctx, scope);
  14440. styleChanged = true;
  14441. }
  14442. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  14443. }
  14444. if (el.hasStroke()) {
  14445. var lineWidth = style.lineWidth;
  14446. var newLineWidth = lineWidth / ((style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1);
  14447. if (ctx.lineWidth !== newLineWidth) {
  14448. if (!styleChanged) {
  14449. flushPathDrawn(ctx, scope);
  14450. styleChanged = true;
  14451. }
  14452. ctx.lineWidth = newLineWidth;
  14453. }
  14454. }
  14455. for (var i = 0; i < STROKE_PROPS.length; i++) {
  14456. var prop = STROKE_PROPS[i];
  14457. var propName = prop[0];
  14458. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14459. if (!styleChanged) {
  14460. flushPathDrawn(ctx, scope);
  14461. styleChanged = true;
  14462. }
  14463. ctx[propName] = style[propName] || prop[1];
  14464. }
  14465. }
  14466. return styleChanged;
  14467. }
  14468. function bindImageStyle(ctx, el, prevEl, forceSetAll, scope) {
  14469. return bindCommonProps(ctx, getStyle(el, scope.inHover), prevEl && getStyle(prevEl, scope.inHover), forceSetAll, scope);
  14470. }
  14471. function setContextTransform(ctx, el) {
  14472. var m = el.transform;
  14473. var dpr = ctx.dpr || 1;
  14474. if (m) {
  14475. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  14476. }
  14477. else {
  14478. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  14479. }
  14480. }
  14481. function updateClipStatus(clipPaths, ctx, scope) {
  14482. var allClipped = false;
  14483. for (var i = 0; i < clipPaths.length; i++) {
  14484. var clipPath = clipPaths[i];
  14485. allClipped = allClipped || clipPath.isZeroArea();
  14486. setContextTransform(ctx, clipPath);
  14487. ctx.beginPath();
  14488. clipPath.buildPath(ctx, clipPath.shape);
  14489. ctx.clip();
  14490. }
  14491. scope.allClipped = allClipped;
  14492. }
  14493. function isTransformChanged(m0, m1) {
  14494. if (m0 && m1) {
  14495. return m0[0] !== m1[0]
  14496. || m0[1] !== m1[1]
  14497. || m0[2] !== m1[2]
  14498. || m0[3] !== m1[3]
  14499. || m0[4] !== m1[4]
  14500. || m0[5] !== m1[5];
  14501. }
  14502. else if (!m0 && !m1) {
  14503. return false;
  14504. }
  14505. return true;
  14506. }
  14507. var DRAW_TYPE_PATH = 1;
  14508. var DRAW_TYPE_IMAGE = 2;
  14509. var DRAW_TYPE_TEXT = 3;
  14510. var DRAW_TYPE_INCREMENTAL = 4;
  14511. function canPathBatch(style) {
  14512. var hasFill = styleHasFill(style);
  14513. var hasStroke = styleHasStroke(style);
  14514. return !(style.lineDash
  14515. || !(+hasFill ^ +hasStroke)
  14516. || (hasFill && typeof style.fill !== 'string')
  14517. || (hasStroke && typeof style.stroke !== 'string')
  14518. || style.strokePercent < 1
  14519. || style.strokeOpacity < 1
  14520. || style.fillOpacity < 1);
  14521. }
  14522. function flushPathDrawn(ctx, scope) {
  14523. scope.batchFill && ctx.fill();
  14524. scope.batchStroke && ctx.stroke();
  14525. scope.batchFill = '';
  14526. scope.batchStroke = '';
  14527. }
  14528. function getStyle(el, inHover) {
  14529. return inHover ? (el.__hoverStyle || el.style) : el.style;
  14530. }
  14531. function brushSingle(ctx, el) {
  14532. brush(ctx, el, { inHover: false, viewWidth: 0, viewHeight: 0 }, true);
  14533. }
  14534. function brush(ctx, el, scope, isLast) {
  14535. var m = el.transform;
  14536. if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false)) {
  14537. el.__dirty &= ~REDRAW_BIT;
  14538. el.__isRendered = false;
  14539. return;
  14540. }
  14541. var clipPaths = el.__clipPaths;
  14542. var prevElClipPaths = scope.prevElClipPaths;
  14543. var forceSetTransform = false;
  14544. var forceSetStyle = false;
  14545. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  14546. if (prevElClipPaths && prevElClipPaths.length) {
  14547. flushPathDrawn(ctx, scope);
  14548. ctx.restore();
  14549. forceSetStyle = forceSetTransform = true;
  14550. scope.prevElClipPaths = null;
  14551. scope.allClipped = false;
  14552. scope.prevEl = null;
  14553. }
  14554. if (clipPaths && clipPaths.length) {
  14555. flushPathDrawn(ctx, scope);
  14556. ctx.save();
  14557. updateClipStatus(clipPaths, ctx, scope);
  14558. forceSetTransform = true;
  14559. }
  14560. scope.prevElClipPaths = clipPaths;
  14561. }
  14562. if (scope.allClipped) {
  14563. el.__isRendered = false;
  14564. return;
  14565. }
  14566. el.beforeBrush && el.beforeBrush();
  14567. el.innerBeforeBrush();
  14568. var prevEl = scope.prevEl;
  14569. if (!prevEl) {
  14570. forceSetStyle = forceSetTransform = true;
  14571. }
  14572. var canBatchPath = el instanceof Path
  14573. && el.autoBatch
  14574. && canPathBatch(el.style);
  14575. if (forceSetTransform || isTransformChanged(m, prevEl.transform)) {
  14576. flushPathDrawn(ctx, scope);
  14577. setContextTransform(ctx, el);
  14578. }
  14579. else if (!canBatchPath) {
  14580. flushPathDrawn(ctx, scope);
  14581. }
  14582. var style = getStyle(el, scope.inHover);
  14583. if (el instanceof Path) {
  14584. if (scope.lastDrawType !== DRAW_TYPE_PATH) {
  14585. forceSetStyle = true;
  14586. scope.lastDrawType = DRAW_TYPE_PATH;
  14587. }
  14588. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14589. if (!canBatchPath || (!scope.batchFill && !scope.batchStroke)) {
  14590. ctx.beginPath();
  14591. }
  14592. brushPath(ctx, el, style, canBatchPath);
  14593. if (canBatchPath) {
  14594. scope.batchFill = style.fill || '';
  14595. scope.batchStroke = style.stroke || '';
  14596. }
  14597. }
  14598. else {
  14599. if (el instanceof TSpan) {
  14600. if (scope.lastDrawType !== DRAW_TYPE_TEXT) {
  14601. forceSetStyle = true;
  14602. scope.lastDrawType = DRAW_TYPE_TEXT;
  14603. }
  14604. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14605. brushText(ctx, el, style);
  14606. }
  14607. else if (el instanceof ZRImage) {
  14608. if (scope.lastDrawType !== DRAW_TYPE_IMAGE) {
  14609. forceSetStyle = true;
  14610. scope.lastDrawType = DRAW_TYPE_IMAGE;
  14611. }
  14612. bindImageStyle(ctx, el, prevEl, forceSetStyle, scope);
  14613. brushImage(ctx, el, style);
  14614. }
  14615. else if (el.getTemporalDisplayables) {
  14616. if (scope.lastDrawType !== DRAW_TYPE_INCREMENTAL) {
  14617. forceSetStyle = true;
  14618. scope.lastDrawType = DRAW_TYPE_INCREMENTAL;
  14619. }
  14620. brushIncremental(ctx, el, scope);
  14621. }
  14622. }
  14623. if (canBatchPath && isLast) {
  14624. flushPathDrawn(ctx, scope);
  14625. }
  14626. el.innerAfterBrush();
  14627. el.afterBrush && el.afterBrush();
  14628. scope.prevEl = el;
  14629. el.__dirty = 0;
  14630. el.__isRendered = true;
  14631. }
  14632. function brushIncremental(ctx, el, scope) {
  14633. var displayables = el.getDisplayables();
  14634. var temporalDisplayables = el.getTemporalDisplayables();
  14635. ctx.save();
  14636. var innerScope = {
  14637. prevElClipPaths: null,
  14638. prevEl: null,
  14639. allClipped: false,
  14640. viewWidth: scope.viewWidth,
  14641. viewHeight: scope.viewHeight,
  14642. inHover: scope.inHover
  14643. };
  14644. var i;
  14645. var len;
  14646. for (i = el.getCursor(), len = displayables.length; i < len; i++) {
  14647. var displayable = displayables[i];
  14648. displayable.beforeBrush && displayable.beforeBrush();
  14649. displayable.innerBeforeBrush();
  14650. brush(ctx, displayable, innerScope, i === len - 1);
  14651. displayable.innerAfterBrush();
  14652. displayable.afterBrush && displayable.afterBrush();
  14653. innerScope.prevEl = displayable;
  14654. }
  14655. for (var i_1 = 0, len_1 = temporalDisplayables.length; i_1 < len_1; i_1++) {
  14656. var displayable = temporalDisplayables[i_1];
  14657. displayable.beforeBrush && displayable.beforeBrush();
  14658. displayable.innerBeforeBrush();
  14659. brush(ctx, displayable, innerScope, i_1 === len_1 - 1);
  14660. displayable.innerAfterBrush();
  14661. displayable.afterBrush && displayable.afterBrush();
  14662. innerScope.prevEl = displayable;
  14663. }
  14664. el.clearTemporalDisplayables();
  14665. el.notClear = true;
  14666. ctx.restore();
  14667. }
  14668. function createDom(id, painter, dpr) {
  14669. var newDom = platformApi.createCanvas();
  14670. var width = painter.getWidth();
  14671. var height = painter.getHeight();
  14672. var newDomStyle = newDom.style;
  14673. if (newDomStyle) {
  14674. newDomStyle.position = 'absolute';
  14675. newDomStyle.left = '0';
  14676. newDomStyle.top = '0';
  14677. newDomStyle.width = width + 'px';
  14678. newDomStyle.height = height + 'px';
  14679. newDom.setAttribute('data-zr-dom-id', id);
  14680. }
  14681. newDom.width = width * dpr;
  14682. newDom.height = height * dpr;
  14683. return newDom;
  14684. }
  14685. var Layer = (function (_super) {
  14686. __extends(Layer, _super);
  14687. function Layer(id, painter, dpr) {
  14688. var _this = _super.call(this) || this;
  14689. _this.motionBlur = false;
  14690. _this.lastFrameAlpha = 0.7;
  14691. _this.dpr = 1;
  14692. _this.virtual = false;
  14693. _this.config = {};
  14694. _this.incremental = false;
  14695. _this.zlevel = 0;
  14696. _this.maxRepaintRectCount = 5;
  14697. _this.__dirty = true;
  14698. _this.__firstTimePaint = true;
  14699. _this.__used = false;
  14700. _this.__drawIndex = 0;
  14701. _this.__startIndex = 0;
  14702. _this.__endIndex = 0;
  14703. _this.__prevStartIndex = null;
  14704. _this.__prevEndIndex = null;
  14705. var dom;
  14706. dpr = dpr || devicePixelRatio;
  14707. if (typeof id === 'string') {
  14708. dom = createDom(id, painter, dpr);
  14709. }
  14710. else if (isObject(id)) {
  14711. dom = id;
  14712. id = dom.id;
  14713. }
  14714. _this.id = id;
  14715. _this.dom = dom;
  14716. var domStyle = dom.style;
  14717. if (domStyle) {
  14718. disableUserSelect(dom);
  14719. dom.onselectstart = function () { return false; };
  14720. domStyle.padding = '0';
  14721. domStyle.margin = '0';
  14722. domStyle.borderWidth = '0';
  14723. }
  14724. _this.painter = painter;
  14725. _this.dpr = dpr;
  14726. return _this;
  14727. }
  14728. Layer.prototype.getElementCount = function () {
  14729. return this.__endIndex - this.__startIndex;
  14730. };
  14731. Layer.prototype.afterBrush = function () {
  14732. this.__prevStartIndex = this.__startIndex;
  14733. this.__prevEndIndex = this.__endIndex;
  14734. };
  14735. Layer.prototype.initContext = function () {
  14736. this.ctx = this.dom.getContext('2d');
  14737. this.ctx.dpr = this.dpr;
  14738. };
  14739. Layer.prototype.setUnpainted = function () {
  14740. this.__firstTimePaint = true;
  14741. };
  14742. Layer.prototype.createBackBuffer = function () {
  14743. var dpr = this.dpr;
  14744. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  14745. this.ctxBack = this.domBack.getContext('2d');
  14746. if (dpr !== 1) {
  14747. this.ctxBack.scale(dpr, dpr);
  14748. }
  14749. };
  14750. Layer.prototype.createRepaintRects = function (displayList, prevList, viewWidth, viewHeight) {
  14751. if (this.__firstTimePaint) {
  14752. this.__firstTimePaint = false;
  14753. return null;
  14754. }
  14755. var mergedRepaintRects = [];
  14756. var maxRepaintRectCount = this.maxRepaintRectCount;
  14757. var full = false;
  14758. var pendingRect = new BoundingRect(0, 0, 0, 0);
  14759. function addRectToMergePool(rect) {
  14760. if (!rect.isFinite() || rect.isZero()) {
  14761. return;
  14762. }
  14763. if (mergedRepaintRects.length === 0) {
  14764. var boundingRect = new BoundingRect(0, 0, 0, 0);
  14765. boundingRect.copy(rect);
  14766. mergedRepaintRects.push(boundingRect);
  14767. }
  14768. else {
  14769. var isMerged = false;
  14770. var minDeltaArea = Infinity;
  14771. var bestRectToMergeIdx = 0;
  14772. for (var i = 0; i < mergedRepaintRects.length; ++i) {
  14773. var mergedRect = mergedRepaintRects[i];
  14774. if (mergedRect.intersect(rect)) {
  14775. var pendingRect_1 = new BoundingRect(0, 0, 0, 0);
  14776. pendingRect_1.copy(mergedRect);
  14777. pendingRect_1.union(rect);
  14778. mergedRepaintRects[i] = pendingRect_1;
  14779. isMerged = true;
  14780. break;
  14781. }
  14782. else if (full) {
  14783. pendingRect.copy(rect);
  14784. pendingRect.union(mergedRect);
  14785. var aArea = rect.width * rect.height;
  14786. var bArea = mergedRect.width * mergedRect.height;
  14787. var pendingArea = pendingRect.width * pendingRect.height;
  14788. var deltaArea = pendingArea - aArea - bArea;
  14789. if (deltaArea < minDeltaArea) {
  14790. minDeltaArea = deltaArea;
  14791. bestRectToMergeIdx = i;
  14792. }
  14793. }
  14794. }
  14795. if (full) {
  14796. mergedRepaintRects[bestRectToMergeIdx].union(rect);
  14797. isMerged = true;
  14798. }
  14799. if (!isMerged) {
  14800. var boundingRect = new BoundingRect(0, 0, 0, 0);
  14801. boundingRect.copy(rect);
  14802. mergedRepaintRects.push(boundingRect);
  14803. }
  14804. if (!full) {
  14805. full = mergedRepaintRects.length >= maxRepaintRectCount;
  14806. }
  14807. }
  14808. }
  14809. for (var i = this.__startIndex; i < this.__endIndex; ++i) {
  14810. var el = displayList[i];
  14811. if (el) {
  14812. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  14813. var prevRect = el.__isRendered && ((el.__dirty & REDRAW_BIT) || !shouldPaint)
  14814. ? el.getPrevPaintRect()
  14815. : null;
  14816. if (prevRect) {
  14817. addRectToMergePool(prevRect);
  14818. }
  14819. var curRect = shouldPaint && ((el.__dirty & REDRAW_BIT) || !el.__isRendered)
  14820. ? el.getPaintRect()
  14821. : null;
  14822. if (curRect) {
  14823. addRectToMergePool(curRect);
  14824. }
  14825. }
  14826. }
  14827. for (var i = this.__prevStartIndex; i < this.__prevEndIndex; ++i) {
  14828. var el = prevList[i];
  14829. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  14830. if (el && (!shouldPaint || !el.__zr) && el.__isRendered) {
  14831. var prevRect = el.getPrevPaintRect();
  14832. if (prevRect) {
  14833. addRectToMergePool(prevRect);
  14834. }
  14835. }
  14836. }
  14837. var hasIntersections;
  14838. do {
  14839. hasIntersections = false;
  14840. for (var i = 0; i < mergedRepaintRects.length;) {
  14841. if (mergedRepaintRects[i].isZero()) {
  14842. mergedRepaintRects.splice(i, 1);
  14843. continue;
  14844. }
  14845. for (var j = i + 1; j < mergedRepaintRects.length;) {
  14846. if (mergedRepaintRects[i].intersect(mergedRepaintRects[j])) {
  14847. hasIntersections = true;
  14848. mergedRepaintRects[i].union(mergedRepaintRects[j]);
  14849. mergedRepaintRects.splice(j, 1);
  14850. }
  14851. else {
  14852. j++;
  14853. }
  14854. }
  14855. i++;
  14856. }
  14857. } while (hasIntersections);
  14858. this._paintRects = mergedRepaintRects;
  14859. return mergedRepaintRects;
  14860. };
  14861. Layer.prototype.debugGetPaintRects = function () {
  14862. return (this._paintRects || []).slice();
  14863. };
  14864. Layer.prototype.resize = function (width, height) {
  14865. var dpr = this.dpr;
  14866. var dom = this.dom;
  14867. var domStyle = dom.style;
  14868. var domBack = this.domBack;
  14869. if (domStyle) {
  14870. domStyle.width = width + 'px';
  14871. domStyle.height = height + 'px';
  14872. }
  14873. dom.width = width * dpr;
  14874. dom.height = height * dpr;
  14875. if (domBack) {
  14876. domBack.width = width * dpr;
  14877. domBack.height = height * dpr;
  14878. if (dpr !== 1) {
  14879. this.ctxBack.scale(dpr, dpr);
  14880. }
  14881. }
  14882. };
  14883. Layer.prototype.clear = function (clearAll, clearColor, repaintRects) {
  14884. var dom = this.dom;
  14885. var ctx = this.ctx;
  14886. var width = dom.width;
  14887. var height = dom.height;
  14888. clearColor = clearColor || this.clearColor;
  14889. var haveMotionBLur = this.motionBlur && !clearAll;
  14890. var lastFrameAlpha = this.lastFrameAlpha;
  14891. var dpr = this.dpr;
  14892. var self = this;
  14893. if (haveMotionBLur) {
  14894. if (!this.domBack) {
  14895. this.createBackBuffer();
  14896. }
  14897. this.ctxBack.globalCompositeOperation = 'copy';
  14898. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  14899. }
  14900. var domBack = this.domBack;
  14901. function doClear(x, y, width, height) {
  14902. ctx.clearRect(x, y, width, height);
  14903. if (clearColor && clearColor !== 'transparent') {
  14904. var clearColorGradientOrPattern = void 0;
  14905. if (isGradientObject(clearColor)) {
  14906. var shouldCache = clearColor.global || (clearColor.__width === width
  14907. && clearColor.__height === height);
  14908. clearColorGradientOrPattern = shouldCache
  14909. && clearColor.__canvasGradient
  14910. || getCanvasGradient(ctx, clearColor, {
  14911. x: 0,
  14912. y: 0,
  14913. width: width,
  14914. height: height
  14915. });
  14916. clearColor.__canvasGradient = clearColorGradientOrPattern;
  14917. clearColor.__width = width;
  14918. clearColor.__height = height;
  14919. }
  14920. else if (isImagePatternObject(clearColor)) {
  14921. clearColor.scaleX = clearColor.scaleX || dpr;
  14922. clearColor.scaleY = clearColor.scaleY || dpr;
  14923. clearColorGradientOrPattern = createCanvasPattern(ctx, clearColor, {
  14924. dirty: function () {
  14925. self.setUnpainted();
  14926. self.__painter.refresh();
  14927. }
  14928. });
  14929. }
  14930. ctx.save();
  14931. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  14932. ctx.fillRect(x, y, width, height);
  14933. ctx.restore();
  14934. }
  14935. if (haveMotionBLur) {
  14936. ctx.save();
  14937. ctx.globalAlpha = lastFrameAlpha;
  14938. ctx.drawImage(domBack, x, y, width, height);
  14939. ctx.restore();
  14940. }
  14941. }
  14942. if (!repaintRects || haveMotionBLur) {
  14943. doClear(0, 0, width, height);
  14944. }
  14945. else if (repaintRects.length) {
  14946. each(repaintRects, function (rect) {
  14947. doClear(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  14948. });
  14949. }
  14950. };
  14951. return Layer;
  14952. }(Eventful));
  14953. var HOVER_LAYER_ZLEVEL = 1e5;
  14954. var CANVAS_ZLEVEL = 314159;
  14955. var EL_AFTER_INCREMENTAL_INC = 0.01;
  14956. var INCREMENTAL_INC = 0.001;
  14957. function isLayerValid(layer) {
  14958. if (!layer) {
  14959. return false;
  14960. }
  14961. if (layer.__builtin__) {
  14962. return true;
  14963. }
  14964. if (typeof (layer.resize) !== 'function'
  14965. || typeof (layer.refresh) !== 'function') {
  14966. return false;
  14967. }
  14968. return true;
  14969. }
  14970. function createRoot(width, height) {
  14971. var domRoot = document.createElement('div');
  14972. domRoot.style.cssText = [
  14973. 'position:relative',
  14974. 'width:' + width + 'px',
  14975. 'height:' + height + 'px',
  14976. 'padding:0',
  14977. 'margin:0',
  14978. 'border-width:0'
  14979. ].join(';') + ';';
  14980. return domRoot;
  14981. }
  14982. var CanvasPainter = (function () {
  14983. function CanvasPainter(root, storage, opts, id) {
  14984. this.type = 'canvas';
  14985. this._zlevelList = [];
  14986. this._prevDisplayList = [];
  14987. this._layers = {};
  14988. this._layerConfig = {};
  14989. this._needsManuallyCompositing = false;
  14990. this.type = 'canvas';
  14991. var singleCanvas = !root.nodeName
  14992. || root.nodeName.toUpperCase() === 'CANVAS';
  14993. this._opts = opts = extend({}, opts || {});
  14994. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  14995. this._singleCanvas = singleCanvas;
  14996. this.root = root;
  14997. var rootStyle = root.style;
  14998. if (rootStyle) {
  14999. disableUserSelect(root);
  15000. root.innerHTML = '';
  15001. }
  15002. this.storage = storage;
  15003. var zlevelList = this._zlevelList;
  15004. this._prevDisplayList = [];
  15005. var layers = this._layers;
  15006. if (!singleCanvas) {
  15007. this._width = getSize(root, 0, opts);
  15008. this._height = getSize(root, 1, opts);
  15009. var domRoot = this._domRoot = createRoot(this._width, this._height);
  15010. root.appendChild(domRoot);
  15011. }
  15012. else {
  15013. var rootCanvas = root;
  15014. var width = rootCanvas.width;
  15015. var height = rootCanvas.height;
  15016. if (opts.width != null) {
  15017. width = opts.width;
  15018. }
  15019. if (opts.height != null) {
  15020. height = opts.height;
  15021. }
  15022. this.dpr = opts.devicePixelRatio || 1;
  15023. rootCanvas.width = width * this.dpr;
  15024. rootCanvas.height = height * this.dpr;
  15025. this._width = width;
  15026. this._height = height;
  15027. var mainLayer = new Layer(rootCanvas, this, this.dpr);
  15028. mainLayer.__builtin__ = true;
  15029. mainLayer.initContext();
  15030. layers[CANVAS_ZLEVEL] = mainLayer;
  15031. mainLayer.zlevel = CANVAS_ZLEVEL;
  15032. zlevelList.push(CANVAS_ZLEVEL);
  15033. this._domRoot = root;
  15034. }
  15035. }
  15036. CanvasPainter.prototype.getType = function () {
  15037. return 'canvas';
  15038. };
  15039. CanvasPainter.prototype.isSingleCanvas = function () {
  15040. return this._singleCanvas;
  15041. };
  15042. CanvasPainter.prototype.getViewportRoot = function () {
  15043. return this._domRoot;
  15044. };
  15045. CanvasPainter.prototype.getViewportRootOffset = function () {
  15046. var viewportRoot = this.getViewportRoot();
  15047. if (viewportRoot) {
  15048. return {
  15049. offsetLeft: viewportRoot.offsetLeft || 0,
  15050. offsetTop: viewportRoot.offsetTop || 0
  15051. };
  15052. }
  15053. };
  15054. CanvasPainter.prototype.refresh = function (paintAll) {
  15055. var list = this.storage.getDisplayList(true);
  15056. var prevList = this._prevDisplayList;
  15057. var zlevelList = this._zlevelList;
  15058. this._redrawId = Math.random();
  15059. this._paintList(list, prevList, paintAll, this._redrawId);
  15060. for (var i = 0; i < zlevelList.length; i++) {
  15061. var z = zlevelList[i];
  15062. var layer = this._layers[z];
  15063. if (!layer.__builtin__ && layer.refresh) {
  15064. var clearColor = i === 0 ? this._backgroundColor : null;
  15065. layer.refresh(clearColor);
  15066. }
  15067. }
  15068. if (this._opts.useDirtyRect) {
  15069. this._prevDisplayList = list.slice();
  15070. }
  15071. return this;
  15072. };
  15073. CanvasPainter.prototype.refreshHover = function () {
  15074. this._paintHoverList(this.storage.getDisplayList(false));
  15075. };
  15076. CanvasPainter.prototype._paintHoverList = function (list) {
  15077. var len = list.length;
  15078. var hoverLayer = this._hoverlayer;
  15079. hoverLayer && hoverLayer.clear();
  15080. if (!len) {
  15081. return;
  15082. }
  15083. var scope = {
  15084. inHover: true,
  15085. viewWidth: this._width,
  15086. viewHeight: this._height
  15087. };
  15088. var ctx;
  15089. for (var i = 0; i < len; i++) {
  15090. var el = list[i];
  15091. if (el.__inHover) {
  15092. if (!hoverLayer) {
  15093. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  15094. }
  15095. if (!ctx) {
  15096. ctx = hoverLayer.ctx;
  15097. ctx.save();
  15098. }
  15099. brush(ctx, el, scope, i === len - 1);
  15100. }
  15101. }
  15102. if (ctx) {
  15103. ctx.restore();
  15104. }
  15105. };
  15106. CanvasPainter.prototype.getHoverLayer = function () {
  15107. return this.getLayer(HOVER_LAYER_ZLEVEL);
  15108. };
  15109. CanvasPainter.prototype.paintOne = function (ctx, el) {
  15110. brushSingle(ctx, el);
  15111. };
  15112. CanvasPainter.prototype._paintList = function (list, prevList, paintAll, redrawId) {
  15113. if (this._redrawId !== redrawId) {
  15114. return;
  15115. }
  15116. paintAll = paintAll || false;
  15117. this._updateLayerStatus(list);
  15118. var _a = this._doPaintList(list, prevList, paintAll), finished = _a.finished, needsRefreshHover = _a.needsRefreshHover;
  15119. if (this._needsManuallyCompositing) {
  15120. this._compositeManually();
  15121. }
  15122. if (needsRefreshHover) {
  15123. this._paintHoverList(list);
  15124. }
  15125. if (!finished) {
  15126. var self_1 = this;
  15127. requestAnimationFrame$1(function () {
  15128. self_1._paintList(list, prevList, paintAll, redrawId);
  15129. });
  15130. }
  15131. else {
  15132. this.eachLayer(function (layer) {
  15133. layer.afterBrush && layer.afterBrush();
  15134. });
  15135. }
  15136. };
  15137. CanvasPainter.prototype._compositeManually = function () {
  15138. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  15139. var width = this._domRoot.width;
  15140. var height = this._domRoot.height;
  15141. ctx.clearRect(0, 0, width, height);
  15142. this.eachBuiltinLayer(function (layer) {
  15143. if (layer.virtual) {
  15144. ctx.drawImage(layer.dom, 0, 0, width, height);
  15145. }
  15146. });
  15147. };
  15148. CanvasPainter.prototype._doPaintList = function (list, prevList, paintAll) {
  15149. var _this = this;
  15150. var layerList = [];
  15151. var useDirtyRect = this._opts.useDirtyRect;
  15152. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  15153. var zlevel = this._zlevelList[zi];
  15154. var layer = this._layers[zlevel];
  15155. if (layer.__builtin__
  15156. && layer !== this._hoverlayer
  15157. && (layer.__dirty || paintAll)) {
  15158. layerList.push(layer);
  15159. }
  15160. }
  15161. var finished = true;
  15162. var needsRefreshHover = false;
  15163. var _loop_1 = function (k) {
  15164. var layer = layerList[k];
  15165. var ctx = layer.ctx;
  15166. var repaintRects = useDirtyRect
  15167. && layer.createRepaintRects(list, prevList, this_1._width, this_1._height);
  15168. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  15169. var useTimer = !paintAll && layer.incremental && Date.now;
  15170. var startTime = useTimer && Date.now();
  15171. var clearColor = layer.zlevel === this_1._zlevelList[0]
  15172. ? this_1._backgroundColor : null;
  15173. if (layer.__startIndex === layer.__endIndex) {
  15174. layer.clear(false, clearColor, repaintRects);
  15175. }
  15176. else if (start === layer.__startIndex) {
  15177. var firstEl = list[start];
  15178. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  15179. layer.clear(false, clearColor, repaintRects);
  15180. }
  15181. }
  15182. if (start === -1) {
  15183. console.error('For some unknown reason. drawIndex is -1');
  15184. start = layer.__startIndex;
  15185. }
  15186. var i;
  15187. var repaint = function (repaintRect) {
  15188. var scope = {
  15189. inHover: false,
  15190. allClipped: false,
  15191. prevEl: null,
  15192. viewWidth: _this._width,
  15193. viewHeight: _this._height
  15194. };
  15195. for (i = start; i < layer.__endIndex; i++) {
  15196. var el = list[i];
  15197. if (el.__inHover) {
  15198. needsRefreshHover = true;
  15199. }
  15200. _this._doPaintEl(el, layer, useDirtyRect, repaintRect, scope, i === layer.__endIndex - 1);
  15201. if (useTimer) {
  15202. var dTime = Date.now() - startTime;
  15203. if (dTime > 15) {
  15204. break;
  15205. }
  15206. }
  15207. }
  15208. if (scope.prevElClipPaths) {
  15209. ctx.restore();
  15210. }
  15211. };
  15212. if (repaintRects) {
  15213. if (repaintRects.length === 0) {
  15214. i = layer.__endIndex;
  15215. }
  15216. else {
  15217. var dpr = this_1.dpr;
  15218. for (var r = 0; r < repaintRects.length; ++r) {
  15219. var rect = repaintRects[r];
  15220. ctx.save();
  15221. ctx.beginPath();
  15222. ctx.rect(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  15223. ctx.clip();
  15224. repaint(rect);
  15225. ctx.restore();
  15226. }
  15227. }
  15228. }
  15229. else {
  15230. ctx.save();
  15231. repaint();
  15232. ctx.restore();
  15233. }
  15234. layer.__drawIndex = i;
  15235. if (layer.__drawIndex < layer.__endIndex) {
  15236. finished = false;
  15237. }
  15238. };
  15239. var this_1 = this;
  15240. for (var k = 0; k < layerList.length; k++) {
  15241. _loop_1(k);
  15242. }
  15243. if (env.wxa) {
  15244. each(this._layers, function (layer) {
  15245. if (layer && layer.ctx && layer.ctx.draw) {
  15246. layer.ctx.draw();
  15247. }
  15248. });
  15249. }
  15250. return {
  15251. finished: finished,
  15252. needsRefreshHover: needsRefreshHover
  15253. };
  15254. };
  15255. CanvasPainter.prototype._doPaintEl = function (el, currentLayer, useDirtyRect, repaintRect, scope, isLast) {
  15256. var ctx = currentLayer.ctx;
  15257. if (useDirtyRect) {
  15258. var paintRect = el.getPaintRect();
  15259. if (!repaintRect || paintRect && paintRect.intersect(repaintRect)) {
  15260. brush(ctx, el, scope, isLast);
  15261. el.setPrevPaintRect(paintRect);
  15262. }
  15263. }
  15264. else {
  15265. brush(ctx, el, scope, isLast);
  15266. }
  15267. };
  15268. CanvasPainter.prototype.getLayer = function (zlevel, virtual) {
  15269. if (this._singleCanvas && !this._needsManuallyCompositing) {
  15270. zlevel = CANVAS_ZLEVEL;
  15271. }
  15272. var layer = this._layers[zlevel];
  15273. if (!layer) {
  15274. layer = new Layer('zr_' + zlevel, this, this.dpr);
  15275. layer.zlevel = zlevel;
  15276. layer.__builtin__ = true;
  15277. if (this._layerConfig[zlevel]) {
  15278. merge(layer, this._layerConfig[zlevel], true);
  15279. }
  15280. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  15281. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  15282. }
  15283. if (virtual) {
  15284. layer.virtual = virtual;
  15285. }
  15286. this.insertLayer(zlevel, layer);
  15287. layer.initContext();
  15288. }
  15289. return layer;
  15290. };
  15291. CanvasPainter.prototype.insertLayer = function (zlevel, layer) {
  15292. var layersMap = this._layers;
  15293. var zlevelList = this._zlevelList;
  15294. var len = zlevelList.length;
  15295. var domRoot = this._domRoot;
  15296. var prevLayer = null;
  15297. var i = -1;
  15298. if (layersMap[zlevel]) {
  15299. {
  15300. logError('ZLevel ' + zlevel + ' has been used already');
  15301. }
  15302. return;
  15303. }
  15304. if (!isLayerValid(layer)) {
  15305. {
  15306. logError('Layer of zlevel ' + zlevel + ' is not valid');
  15307. }
  15308. return;
  15309. }
  15310. if (len > 0 && zlevel > zlevelList[0]) {
  15311. for (i = 0; i < len - 1; i++) {
  15312. if (zlevelList[i] < zlevel
  15313. && zlevelList[i + 1] > zlevel) {
  15314. break;
  15315. }
  15316. }
  15317. prevLayer = layersMap[zlevelList[i]];
  15318. }
  15319. zlevelList.splice(i + 1, 0, zlevel);
  15320. layersMap[zlevel] = layer;
  15321. if (!layer.virtual) {
  15322. if (prevLayer) {
  15323. var prevDom = prevLayer.dom;
  15324. if (prevDom.nextSibling) {
  15325. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  15326. }
  15327. else {
  15328. domRoot.appendChild(layer.dom);
  15329. }
  15330. }
  15331. else {
  15332. if (domRoot.firstChild) {
  15333. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  15334. }
  15335. else {
  15336. domRoot.appendChild(layer.dom);
  15337. }
  15338. }
  15339. }
  15340. layer.__painter = this;
  15341. };
  15342. CanvasPainter.prototype.eachLayer = function (cb, context) {
  15343. var zlevelList = this._zlevelList;
  15344. for (var i = 0; i < zlevelList.length; i++) {
  15345. var z = zlevelList[i];
  15346. cb.call(context, this._layers[z], z);
  15347. }
  15348. };
  15349. CanvasPainter.prototype.eachBuiltinLayer = function (cb, context) {
  15350. var zlevelList = this._zlevelList;
  15351. for (var i = 0; i < zlevelList.length; i++) {
  15352. var z = zlevelList[i];
  15353. var layer = this._layers[z];
  15354. if (layer.__builtin__) {
  15355. cb.call(context, layer, z);
  15356. }
  15357. }
  15358. };
  15359. CanvasPainter.prototype.eachOtherLayer = function (cb, context) {
  15360. var zlevelList = this._zlevelList;
  15361. for (var i = 0; i < zlevelList.length; i++) {
  15362. var z = zlevelList[i];
  15363. var layer = this._layers[z];
  15364. if (!layer.__builtin__) {
  15365. cb.call(context, layer, z);
  15366. }
  15367. }
  15368. };
  15369. CanvasPainter.prototype.getLayers = function () {
  15370. return this._layers;
  15371. };
  15372. CanvasPainter.prototype._updateLayerStatus = function (list) {
  15373. this.eachBuiltinLayer(function (layer, z) {
  15374. layer.__dirty = layer.__used = false;
  15375. });
  15376. function updatePrevLayer(idx) {
  15377. if (prevLayer) {
  15378. if (prevLayer.__endIndex !== idx) {
  15379. prevLayer.__dirty = true;
  15380. }
  15381. prevLayer.__endIndex = idx;
  15382. }
  15383. }
  15384. if (this._singleCanvas) {
  15385. for (var i_1 = 1; i_1 < list.length; i_1++) {
  15386. var el = list[i_1];
  15387. if (el.zlevel !== list[i_1 - 1].zlevel || el.incremental) {
  15388. this._needsManuallyCompositing = true;
  15389. break;
  15390. }
  15391. }
  15392. }
  15393. var prevLayer = null;
  15394. var incrementalLayerCount = 0;
  15395. var prevZlevel;
  15396. var i;
  15397. for (i = 0; i < list.length; i++) {
  15398. var el = list[i];
  15399. var zlevel = el.zlevel;
  15400. var layer = void 0;
  15401. if (prevZlevel !== zlevel) {
  15402. prevZlevel = zlevel;
  15403. incrementalLayerCount = 0;
  15404. }
  15405. if (el.incremental) {
  15406. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  15407. layer.incremental = true;
  15408. incrementalLayerCount = 1;
  15409. }
  15410. else {
  15411. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  15412. }
  15413. if (!layer.__builtin__) {
  15414. logError('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  15415. }
  15416. if (layer !== prevLayer) {
  15417. layer.__used = true;
  15418. if (layer.__startIndex !== i) {
  15419. layer.__dirty = true;
  15420. }
  15421. layer.__startIndex = i;
  15422. if (!layer.incremental) {
  15423. layer.__drawIndex = i;
  15424. }
  15425. else {
  15426. layer.__drawIndex = -1;
  15427. }
  15428. updatePrevLayer(i);
  15429. prevLayer = layer;
  15430. }
  15431. if ((el.__dirty & REDRAW_BIT) && !el.__inHover) {
  15432. layer.__dirty = true;
  15433. if (layer.incremental && layer.__drawIndex < 0) {
  15434. layer.__drawIndex = i;
  15435. }
  15436. }
  15437. }
  15438. updatePrevLayer(i);
  15439. this.eachBuiltinLayer(function (layer, z) {
  15440. if (!layer.__used && layer.getElementCount() > 0) {
  15441. layer.__dirty = true;
  15442. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  15443. }
  15444. if (layer.__dirty && layer.__drawIndex < 0) {
  15445. layer.__drawIndex = layer.__startIndex;
  15446. }
  15447. });
  15448. };
  15449. CanvasPainter.prototype.clear = function () {
  15450. this.eachBuiltinLayer(this._clearLayer);
  15451. return this;
  15452. };
  15453. CanvasPainter.prototype._clearLayer = function (layer) {
  15454. layer.clear();
  15455. };
  15456. CanvasPainter.prototype.setBackgroundColor = function (backgroundColor) {
  15457. this._backgroundColor = backgroundColor;
  15458. each(this._layers, function (layer) {
  15459. layer.setUnpainted();
  15460. });
  15461. };
  15462. CanvasPainter.prototype.configLayer = function (zlevel, config) {
  15463. if (config) {
  15464. var layerConfig = this._layerConfig;
  15465. if (!layerConfig[zlevel]) {
  15466. layerConfig[zlevel] = config;
  15467. }
  15468. else {
  15469. merge(layerConfig[zlevel], config, true);
  15470. }
  15471. for (var i = 0; i < this._zlevelList.length; i++) {
  15472. var _zlevel = this._zlevelList[i];
  15473. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  15474. var layer = this._layers[_zlevel];
  15475. merge(layer, layerConfig[zlevel], true);
  15476. }
  15477. }
  15478. }
  15479. };
  15480. CanvasPainter.prototype.delLayer = function (zlevel) {
  15481. var layers = this._layers;
  15482. var zlevelList = this._zlevelList;
  15483. var layer = layers[zlevel];
  15484. if (!layer) {
  15485. return;
  15486. }
  15487. layer.dom.parentNode.removeChild(layer.dom);
  15488. delete layers[zlevel];
  15489. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  15490. };
  15491. CanvasPainter.prototype.resize = function (width, height) {
  15492. if (!this._domRoot.style) {
  15493. if (width == null || height == null) {
  15494. return;
  15495. }
  15496. this._width = width;
  15497. this._height = height;
  15498. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  15499. }
  15500. else {
  15501. var domRoot = this._domRoot;
  15502. domRoot.style.display = 'none';
  15503. var opts = this._opts;
  15504. var root = this.root;
  15505. width != null && (opts.width = width);
  15506. height != null && (opts.height = height);
  15507. width = getSize(root, 0, opts);
  15508. height = getSize(root, 1, opts);
  15509. domRoot.style.display = '';
  15510. if (this._width !== width || height !== this._height) {
  15511. domRoot.style.width = width + 'px';
  15512. domRoot.style.height = height + 'px';
  15513. for (var id in this._layers) {
  15514. if (this._layers.hasOwnProperty(id)) {
  15515. this._layers[id].resize(width, height);
  15516. }
  15517. }
  15518. this.refresh(true);
  15519. }
  15520. this._width = width;
  15521. this._height = height;
  15522. }
  15523. return this;
  15524. };
  15525. CanvasPainter.prototype.clearLayer = function (zlevel) {
  15526. var layer = this._layers[zlevel];
  15527. if (layer) {
  15528. layer.clear();
  15529. }
  15530. };
  15531. CanvasPainter.prototype.dispose = function () {
  15532. this.root.innerHTML = '';
  15533. this.root =
  15534. this.storage =
  15535. this._domRoot =
  15536. this._layers = null;
  15537. };
  15538. CanvasPainter.prototype.getRenderedCanvas = function (opts) {
  15539. opts = opts || {};
  15540. if (this._singleCanvas && !this._compositeManually) {
  15541. return this._layers[CANVAS_ZLEVEL].dom;
  15542. }
  15543. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  15544. imageLayer.initContext();
  15545. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  15546. var ctx = imageLayer.ctx;
  15547. if (opts.pixelRatio <= this.dpr) {
  15548. this.refresh();
  15549. var width_1 = imageLayer.dom.width;
  15550. var height_1 = imageLayer.dom.height;
  15551. this.eachLayer(function (layer) {
  15552. if (layer.__builtin__) {
  15553. ctx.drawImage(layer.dom, 0, 0, width_1, height_1);
  15554. }
  15555. else if (layer.renderToCanvas) {
  15556. ctx.save();
  15557. layer.renderToCanvas(ctx);
  15558. ctx.restore();
  15559. }
  15560. });
  15561. }
  15562. else {
  15563. var scope = {
  15564. inHover: false,
  15565. viewWidth: this._width,
  15566. viewHeight: this._height
  15567. };
  15568. var displayList = this.storage.getDisplayList(true);
  15569. for (var i = 0, len = displayList.length; i < len; i++) {
  15570. var el = displayList[i];
  15571. brush(ctx, el, scope, i === len - 1);
  15572. }
  15573. }
  15574. return imageLayer.dom;
  15575. };
  15576. CanvasPainter.prototype.getWidth = function () {
  15577. return this._width;
  15578. };
  15579. CanvasPainter.prototype.getHeight = function () {
  15580. return this._height;
  15581. };
  15582. return CanvasPainter;
  15583. }());
  15584. var mathSin$4 = Math.sin;
  15585. var mathCos$4 = Math.cos;
  15586. var PI$5 = Math.PI;
  15587. var PI2$6 = Math.PI * 2;
  15588. var degree = 180 / PI$5;
  15589. var SVGPathRebuilder = (function () {
  15590. function SVGPathRebuilder() {
  15591. }
  15592. SVGPathRebuilder.prototype.reset = function (precision) {
  15593. this._start = true;
  15594. this._d = [];
  15595. this._str = '';
  15596. this._p = Math.pow(10, precision || 4);
  15597. };
  15598. SVGPathRebuilder.prototype.moveTo = function (x, y) {
  15599. this._add('M', x, y);
  15600. };
  15601. SVGPathRebuilder.prototype.lineTo = function (x, y) {
  15602. this._add('L', x, y);
  15603. };
  15604. SVGPathRebuilder.prototype.bezierCurveTo = function (x, y, x2, y2, x3, y3) {
  15605. this._add('C', x, y, x2, y2, x3, y3);
  15606. };
  15607. SVGPathRebuilder.prototype.quadraticCurveTo = function (x, y, x2, y2) {
  15608. this._add('Q', x, y, x2, y2);
  15609. };
  15610. SVGPathRebuilder.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  15611. this.ellipse(cx, cy, r, r, 0, startAngle, endAngle, anticlockwise);
  15612. };
  15613. SVGPathRebuilder.prototype.ellipse = function (cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise) {
  15614. var dTheta = endAngle - startAngle;
  15615. var clockwise = !anticlockwise;
  15616. var dThetaPositive = Math.abs(dTheta);
  15617. var isCircle = isAroundZero$1(dThetaPositive - PI2$6)
  15618. || (clockwise ? dTheta >= PI2$6 : -dTheta >= PI2$6);
  15619. var unifiedTheta = dTheta > 0 ? dTheta % PI2$6 : (dTheta % PI2$6 + PI2$6);
  15620. var large = false;
  15621. if (isCircle) {
  15622. large = true;
  15623. }
  15624. else if (isAroundZero$1(dThetaPositive)) {
  15625. large = false;
  15626. }
  15627. else {
  15628. large = (unifiedTheta >= PI$5) === !!clockwise;
  15629. }
  15630. var x0 = cx + rx * mathCos$4(startAngle);
  15631. var y0 = cy + ry * mathSin$4(startAngle);
  15632. if (this._start) {
  15633. this._add('M', x0, y0);
  15634. }
  15635. var xRot = Math.round(psi * degree);
  15636. if (isCircle) {
  15637. var p = 1 / this._p;
  15638. var dTheta_1 = (clockwise ? 1 : -1) * (PI2$6 - p);
  15639. this._add('A', rx, ry, xRot, 1, +clockwise, cx + rx * mathCos$4(startAngle + dTheta_1), cy + ry * mathSin$4(startAngle + dTheta_1));
  15640. if (p > 1e-2) {
  15641. this._add('A', rx, ry, xRot, 0, +clockwise, x0, y0);
  15642. }
  15643. }
  15644. else {
  15645. var x = cx + rx * mathCos$4(endAngle);
  15646. var y = cy + ry * mathSin$4(endAngle);
  15647. this._add('A', rx, ry, xRot, +large, +clockwise, x, y);
  15648. }
  15649. };
  15650. SVGPathRebuilder.prototype.rect = function (x, y, w, h) {
  15651. this._add('M', x, y);
  15652. this._add('l', w, 0);
  15653. this._add('l', 0, h);
  15654. this._add('l', -w, 0);
  15655. this._add('Z');
  15656. };
  15657. SVGPathRebuilder.prototype.closePath = function () {
  15658. if (this._d.length > 0) {
  15659. this._add('Z');
  15660. }
  15661. };
  15662. SVGPathRebuilder.prototype._add = function (cmd, a, b, c, d, e, f, g, h) {
  15663. var vals = [];
  15664. var p = this._p;
  15665. for (var i = 1; i < arguments.length; i++) {
  15666. var val = arguments[i];
  15667. if (isNaN(val)) {
  15668. this._invalid = true;
  15669. return;
  15670. }
  15671. vals.push(Math.round(val * p) / p);
  15672. }
  15673. this._d.push(cmd + vals.join(' '));
  15674. this._start = cmd === 'Z';
  15675. };
  15676. SVGPathRebuilder.prototype.generateStr = function () {
  15677. this._str = this._invalid ? '' : this._d.join('');
  15678. this._d = [];
  15679. };
  15680. SVGPathRebuilder.prototype.getStr = function () {
  15681. return this._str;
  15682. };
  15683. return SVGPathRebuilder;
  15684. }());
  15685. var NONE = 'none';
  15686. var mathRound$1 = Math.round;
  15687. function pathHasFill(style) {
  15688. var fill = style.fill;
  15689. return fill != null && fill !== NONE;
  15690. }
  15691. function pathHasStroke(style) {
  15692. var stroke = style.stroke;
  15693. return stroke != null && stroke !== NONE;
  15694. }
  15695. var strokeProps = ['lineCap', 'miterLimit', 'lineJoin'];
  15696. var svgStrokeProps = map(strokeProps, function (prop) { return "stroke-" + prop.toLowerCase(); });
  15697. function mapStyleToAttrs(updateAttr, style, el, forceUpdate) {
  15698. var opacity = style.opacity == null ? 1 : style.opacity;
  15699. if (el instanceof ZRImage) {
  15700. updateAttr('opacity', opacity);
  15701. return;
  15702. }
  15703. if (pathHasFill(style)) {
  15704. var fill = normalizeColor(style.fill);
  15705. updateAttr('fill', fill.color);
  15706. var fillOpacity = style.fillOpacity != null
  15707. ? style.fillOpacity * fill.opacity * opacity
  15708. : fill.opacity * opacity;
  15709. if (forceUpdate || fillOpacity < 1) {
  15710. updateAttr('fill-opacity', fillOpacity);
  15711. }
  15712. }
  15713. else {
  15714. updateAttr('fill', NONE);
  15715. }
  15716. if (pathHasStroke(style)) {
  15717. var stroke = normalizeColor(style.stroke);
  15718. updateAttr('stroke', stroke.color);
  15719. var strokeScale = style.strokeNoScale
  15720. ? el.getLineScale()
  15721. : 1;
  15722. var strokeWidth = (strokeScale ? (style.lineWidth || 0) / strokeScale : 0);
  15723. var strokeOpacity = style.strokeOpacity != null
  15724. ? style.strokeOpacity * stroke.opacity * opacity
  15725. : stroke.opacity * opacity;
  15726. var strokeFirst = style.strokeFirst;
  15727. if (forceUpdate || strokeWidth !== 1) {
  15728. updateAttr('stroke-width', strokeWidth);
  15729. }
  15730. if (forceUpdate || strokeFirst) {
  15731. updateAttr('paint-order', strokeFirst ? 'stroke' : 'fill');
  15732. }
  15733. if (forceUpdate || strokeOpacity < 1) {
  15734. updateAttr('stroke-opacity', strokeOpacity);
  15735. }
  15736. if (style.lineDash) {
  15737. var _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  15738. if (lineDash) {
  15739. lineDashOffset = mathRound$1(lineDashOffset || 0);
  15740. updateAttr('stroke-dasharray', lineDash.join(','));
  15741. if (lineDashOffset || forceUpdate) {
  15742. updateAttr('stroke-dashoffset', lineDashOffset);
  15743. }
  15744. }
  15745. }
  15746. else if (forceUpdate) {
  15747. updateAttr('stroke-dasharray', NONE);
  15748. }
  15749. for (var i = 0; i < strokeProps.length; i++) {
  15750. var propName = strokeProps[i];
  15751. if (forceUpdate || style[propName] !== DEFAULT_PATH_STYLE[propName]) {
  15752. var val = style[propName] || DEFAULT_PATH_STYLE[propName];
  15753. val && updateAttr(svgStrokeProps[i], val);
  15754. }
  15755. }
  15756. }
  15757. else if (forceUpdate) {
  15758. updateAttr('stroke', NONE);
  15759. }
  15760. }
  15761. var SVGNS = 'http://www.w3.org/2000/svg';
  15762. var XLINKNS = 'http://www.w3.org/1999/xlink';
  15763. var XMLNS = 'http://www.w3.org/2000/xmlns/';
  15764. var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
  15765. function createElement(name) {
  15766. return document.createElementNS(SVGNS, name);
  15767. }
  15768. function createVNode(tag, key, attrs, children, text) {
  15769. return {
  15770. tag: tag,
  15771. attrs: attrs || {},
  15772. children: children,
  15773. text: text,
  15774. key: key
  15775. };
  15776. }
  15777. function createElementOpen(name, attrs) {
  15778. var attrsStr = [];
  15779. if (attrs) {
  15780. for (var key in attrs) {
  15781. var val = attrs[key];
  15782. var part = key;
  15783. if (val === false) {
  15784. continue;
  15785. }
  15786. else if (val !== true && val != null) {
  15787. part += "=\"" + val + "\"";
  15788. }
  15789. attrsStr.push(part);
  15790. }
  15791. }
  15792. return "<" + name + " " + attrsStr.join(' ') + ">";
  15793. }
  15794. function createElementClose(name) {
  15795. return "</" + name + ">";
  15796. }
  15797. function vNodeToString(el, opts) {
  15798. opts = opts || {};
  15799. var S = opts.newline ? '\n' : '';
  15800. function convertElToString(el) {
  15801. var children = el.children, tag = el.tag, attrs = el.attrs, text = el.text;
  15802. return createElementOpen(tag, attrs)
  15803. + (tag !== 'style' ? encodeHTML(text) : text || '')
  15804. + (children ? "" + S + map(children, function (child) { return convertElToString(child); }).join(S) + S : '')
  15805. + createElementClose(tag);
  15806. }
  15807. return convertElToString(el);
  15808. }
  15809. function getCssString(selectorNodes, animationNodes, opts) {
  15810. opts = opts || {};
  15811. var S = opts.newline ? '\n' : '';
  15812. var bracketBegin = " {" + S;
  15813. var bracketEnd = S + "}";
  15814. var selectors = map(keys(selectorNodes), function (className) {
  15815. return className + bracketBegin + map(keys(selectorNodes[className]), function (attrName) {
  15816. return attrName + ":" + selectorNodes[className][attrName] + ";";
  15817. }).join(S) + bracketEnd;
  15818. }).join(S);
  15819. var animations = map(keys(animationNodes), function (animationName) {
  15820. return "@keyframes " + animationName + bracketBegin + map(keys(animationNodes[animationName]), function (percent) {
  15821. return percent + bracketBegin + map(keys(animationNodes[animationName][percent]), function (attrName) {
  15822. var val = animationNodes[animationName][percent][attrName];
  15823. if (attrName === 'd') {
  15824. val = "path(\"" + val + "\")";
  15825. }
  15826. return attrName + ":" + val + ";";
  15827. }).join(S) + bracketEnd;
  15828. }).join(S) + bracketEnd;
  15829. }).join(S);
  15830. if (!selectors && !animations) {
  15831. return '';
  15832. }
  15833. return ['<![CDATA[', selectors, animations, ']]>'].join(S);
  15834. }
  15835. function createBrushScope(zrId) {
  15836. return {
  15837. zrId: zrId,
  15838. shadowCache: {},
  15839. patternCache: {},
  15840. gradientCache: {},
  15841. clipPathCache: {},
  15842. defs: {},
  15843. cssNodes: {},
  15844. cssAnims: {},
  15845. cssClassIdx: 0,
  15846. cssAnimIdx: 0,
  15847. shadowIdx: 0,
  15848. gradientIdx: 0,
  15849. patternIdx: 0,
  15850. clipPathIdx: 0
  15851. };
  15852. }
  15853. function createSVGVNode(width, height, children, useViewBox) {
  15854. return createVNode('svg', 'root', {
  15855. 'width': width,
  15856. 'height': height,
  15857. 'xmlns': SVGNS,
  15858. 'xmlns:xlink': XLINKNS,
  15859. 'version': '1.1',
  15860. 'baseProfile': 'full',
  15861. 'viewBox': useViewBox ? "0 0 " + width + " " + height : false
  15862. }, children);
  15863. }
  15864. var EASING_MAP = {
  15865. cubicIn: '0.32,0,0.67,0',
  15866. cubicOut: '0.33,1,0.68,1',
  15867. cubicInOut: '0.65,0,0.35,1',
  15868. quadraticIn: '0.11,0,0.5,0',
  15869. quadraticOut: '0.5,1,0.89,1',
  15870. quadraticInOut: '0.45,0,0.55,1',
  15871. quarticIn: '0.5,0,0.75,0',
  15872. quarticOut: '0.25,1,0.5,1',
  15873. quarticInOut: '0.76,0,0.24,1',
  15874. quinticIn: '0.64,0,0.78,0',
  15875. quinticOut: '0.22,1,0.36,1',
  15876. quinticInOut: '0.83,0,0.17,1',
  15877. sinusoidalIn: '0.12,0,0.39,0',
  15878. sinusoidalOut: '0.61,1,0.88,1',
  15879. sinusoidalInOut: '0.37,0,0.63,1',
  15880. exponentialIn: '0.7,0,0.84,0',
  15881. exponentialOut: '0.16,1,0.3,1',
  15882. exponentialInOut: '0.87,0,0.13,1',
  15883. circularIn: '0.55,0,1,0.45',
  15884. circularOut: '0,0.55,0.45,1',
  15885. circularInOut: '0.85,0,0.15,1'
  15886. };
  15887. var transformOriginKey = 'transform-origin';
  15888. function buildPathString(el, kfShape, path) {
  15889. var shape = extend({}, el.shape);
  15890. extend(shape, kfShape);
  15891. el.buildPath(path, shape);
  15892. var svgPathBuilder = new SVGPathRebuilder();
  15893. svgPathBuilder.reset(getPathPrecision(el));
  15894. path.rebuildPath(svgPathBuilder, 1);
  15895. svgPathBuilder.generateStr();
  15896. return svgPathBuilder.getStr();
  15897. }
  15898. function setTransformOrigin(target, transform) {
  15899. var originX = transform.originX, originY = transform.originY;
  15900. if (originX || originY) {
  15901. target[transformOriginKey] = originX + "px " + originY + "px";
  15902. }
  15903. }
  15904. var ANIMATE_STYLE_MAP = {
  15905. fill: 'fill',
  15906. opacity: 'opacity',
  15907. lineWidth: 'stroke-width',
  15908. lineDashOffset: 'stroke-dashoffset'
  15909. };
  15910. function addAnimation(cssAnim, scope) {
  15911. var animationName = scope.zrId + '-ani-' + scope.cssAnimIdx++;
  15912. scope.cssAnims[animationName] = cssAnim;
  15913. return animationName;
  15914. }
  15915. function createCompoundPathCSSAnimation(el, attrs, scope) {
  15916. var paths = el.shape.paths;
  15917. var composedAnim = {};
  15918. var cssAnimationCfg;
  15919. var cssAnimationName;
  15920. each(paths, function (path) {
  15921. var subScope = createBrushScope(scope.zrId);
  15922. subScope.animation = true;
  15923. createCSSAnimation(path, {}, subScope, true);
  15924. var cssAnims = subScope.cssAnims;
  15925. var cssNodes = subScope.cssNodes;
  15926. var animNames = keys(cssAnims);
  15927. var len = animNames.length;
  15928. if (!len) {
  15929. return;
  15930. }
  15931. cssAnimationName = animNames[len - 1];
  15932. var lastAnim = cssAnims[cssAnimationName];
  15933. for (var percent in lastAnim) {
  15934. var kf = lastAnim[percent];
  15935. composedAnim[percent] = composedAnim[percent] || { d: '' };
  15936. composedAnim[percent].d += kf.d || '';
  15937. }
  15938. for (var className in cssNodes) {
  15939. var val = cssNodes[className].animation;
  15940. if (val.indexOf(cssAnimationName) >= 0) {
  15941. cssAnimationCfg = val;
  15942. }
  15943. }
  15944. });
  15945. if (!cssAnimationCfg) {
  15946. return;
  15947. }
  15948. attrs.d = false;
  15949. var animationName = addAnimation(composedAnim, scope);
  15950. return cssAnimationCfg.replace(cssAnimationName, animationName);
  15951. }
  15952. function getEasingFunc(easing) {
  15953. return isString(easing)
  15954. ? EASING_MAP[easing]
  15955. ? "cubic-bezier(" + EASING_MAP[easing] + ")"
  15956. : createCubicEasingFunc(easing) ? easing : ''
  15957. : '';
  15958. }
  15959. function createCSSAnimation(el, attrs, scope, onlyShape) {
  15960. var animators = el.animators;
  15961. var len = animators.length;
  15962. var cssAnimations = [];
  15963. if (el instanceof CompoundPath) {
  15964. var animationCfg = createCompoundPathCSSAnimation(el, attrs, scope);
  15965. if (animationCfg) {
  15966. cssAnimations.push(animationCfg);
  15967. }
  15968. else if (!len) {
  15969. return;
  15970. }
  15971. }
  15972. else if (!len) {
  15973. return;
  15974. }
  15975. var groupAnimators = {};
  15976. for (var i = 0; i < len; i++) {
  15977. var animator = animators[i];
  15978. var cfgArr = [animator.getMaxTime() / 1000 + 's'];
  15979. var easing = getEasingFunc(animator.getClip().easing);
  15980. var delay = animator.getDelay();
  15981. if (easing) {
  15982. cfgArr.push(easing);
  15983. }
  15984. else {
  15985. cfgArr.push('linear');
  15986. }
  15987. if (delay) {
  15988. cfgArr.push(delay / 1000 + 's');
  15989. }
  15990. if (animator.getLoop()) {
  15991. cfgArr.push('infinite');
  15992. }
  15993. var cfg = cfgArr.join(' ');
  15994. groupAnimators[cfg] = groupAnimators[cfg] || [cfg, []];
  15995. groupAnimators[cfg][1].push(animator);
  15996. }
  15997. function createSingleCSSAnimation(groupAnimator) {
  15998. var animators = groupAnimator[1];
  15999. var len = animators.length;
  16000. var transformKfs = {};
  16001. var shapeKfs = {};
  16002. var finalKfs = {};
  16003. var animationTimingFunctionAttrName = 'animation-timing-function';
  16004. function saveAnimatorTrackToCssKfs(animator, cssKfs, toCssAttrName) {
  16005. var tracks = animator.getTracks();
  16006. var maxTime = animator.getMaxTime();
  16007. for (var k = 0; k < tracks.length; k++) {
  16008. var track = tracks[k];
  16009. if (track.needsAnimate()) {
  16010. var kfs = track.keyframes;
  16011. var attrName = track.propName;
  16012. toCssAttrName && (attrName = toCssAttrName(attrName));
  16013. if (attrName) {
  16014. for (var i = 0; i < kfs.length; i++) {
  16015. var kf = kfs[i];
  16016. var percent = Math.round(kf.time / maxTime * 100) + '%';
  16017. var kfEasing = getEasingFunc(kf.easing);
  16018. var rawValue = kf.rawValue;
  16019. if (isString(rawValue) || isNumber(rawValue)) {
  16020. cssKfs[percent] = cssKfs[percent] || {};
  16021. cssKfs[percent][attrName] = kf.rawValue;
  16022. if (kfEasing) {
  16023. cssKfs[percent][animationTimingFunctionAttrName] = kfEasing;
  16024. }
  16025. }
  16026. }
  16027. }
  16028. }
  16029. }
  16030. }
  16031. for (var i = 0; i < len; i++) {
  16032. var animator = animators[i];
  16033. var targetProp = animator.targetName;
  16034. if (!targetProp) {
  16035. !onlyShape && saveAnimatorTrackToCssKfs(animator, transformKfs);
  16036. }
  16037. else if (targetProp === 'shape') {
  16038. saveAnimatorTrackToCssKfs(animator, shapeKfs);
  16039. }
  16040. }
  16041. for (var percent in transformKfs) {
  16042. var transform = {};
  16043. copyTransform(transform, el);
  16044. extend(transform, transformKfs[percent]);
  16045. var str = getSRTTransformString(transform);
  16046. var timingFunction = transformKfs[percent][animationTimingFunctionAttrName];
  16047. finalKfs[percent] = str ? {
  16048. transform: str
  16049. } : {};
  16050. setTransformOrigin(finalKfs[percent], transform);
  16051. if (timingFunction) {
  16052. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16053. }
  16054. }
  16055. var path;
  16056. var canAnimateShape = true;
  16057. for (var percent in shapeKfs) {
  16058. finalKfs[percent] = finalKfs[percent] || {};
  16059. var isFirst = !path;
  16060. var timingFunction = shapeKfs[percent][animationTimingFunctionAttrName];
  16061. if (isFirst) {
  16062. path = new PathProxy();
  16063. }
  16064. var len_1 = path.len();
  16065. path.reset();
  16066. finalKfs[percent].d = buildPathString(el, shapeKfs[percent], path);
  16067. var newLen = path.len();
  16068. if (!isFirst && len_1 !== newLen) {
  16069. canAnimateShape = false;
  16070. break;
  16071. }
  16072. if (timingFunction) {
  16073. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16074. }
  16075. }
  16076. if (!canAnimateShape) {
  16077. for (var percent in finalKfs) {
  16078. delete finalKfs[percent].d;
  16079. }
  16080. }
  16081. if (!onlyShape) {
  16082. for (var i = 0; i < len; i++) {
  16083. var animator = animators[i];
  16084. var targetProp = animator.targetName;
  16085. if (targetProp === 'style') {
  16086. saveAnimatorTrackToCssKfs(animator, finalKfs, function (propName) { return ANIMATE_STYLE_MAP[propName]; });
  16087. }
  16088. }
  16089. }
  16090. var percents = keys(finalKfs);
  16091. var allTransformOriginSame = true;
  16092. var transformOrigin;
  16093. for (var i = 1; i < percents.length; i++) {
  16094. var p0 = percents[i - 1];
  16095. var p1 = percents[i];
  16096. if (finalKfs[p0][transformOriginKey] !== finalKfs[p1][transformOriginKey]) {
  16097. allTransformOriginSame = false;
  16098. break;
  16099. }
  16100. transformOrigin = finalKfs[p0][transformOriginKey];
  16101. }
  16102. if (allTransformOriginSame && transformOrigin) {
  16103. for (var percent in finalKfs) {
  16104. if (finalKfs[percent][transformOriginKey]) {
  16105. delete finalKfs[percent][transformOriginKey];
  16106. }
  16107. }
  16108. attrs[transformOriginKey] = transformOrigin;
  16109. }
  16110. if (filter(percents, function (percent) { return keys(finalKfs[percent]).length > 0; }).length) {
  16111. var animationName = addAnimation(finalKfs, scope);
  16112. return animationName + " " + groupAnimator[0] + " both";
  16113. }
  16114. }
  16115. for (var key in groupAnimators) {
  16116. var animationCfg = createSingleCSSAnimation(groupAnimators[key]);
  16117. if (animationCfg) {
  16118. cssAnimations.push(animationCfg);
  16119. }
  16120. }
  16121. if (cssAnimations.length) {
  16122. var className = scope.zrId + '-cls-' + scope.cssClassIdx++;
  16123. scope.cssNodes['.' + className] = {
  16124. animation: cssAnimations.join(',')
  16125. };
  16126. attrs["class"] = className;
  16127. }
  16128. }
  16129. var round$1 = Math.round;
  16130. function isImageLike$1(val) {
  16131. return val && isString(val.src);
  16132. }
  16133. function isCanvasLike(val) {
  16134. return val && isFunction(val.toDataURL);
  16135. }
  16136. function setStyleAttrs(attrs, style, el, scope) {
  16137. mapStyleToAttrs(function (key, val) {
  16138. var isFillStroke = key === 'fill' || key === 'stroke';
  16139. if (isFillStroke && isGradient(val)) {
  16140. setGradient(style, attrs, key, scope);
  16141. }
  16142. else if (isFillStroke && isPattern(val)) {
  16143. setPattern(el, attrs, key, scope);
  16144. }
  16145. else {
  16146. attrs[key] = val;
  16147. }
  16148. }, style, el, false);
  16149. setShadow(el, attrs, scope);
  16150. }
  16151. function noRotateScale(m) {
  16152. return isAroundZero$1(m[0] - 1)
  16153. && isAroundZero$1(m[1])
  16154. && isAroundZero$1(m[2])
  16155. && isAroundZero$1(m[3] - 1);
  16156. }
  16157. function noTranslate(m) {
  16158. return isAroundZero$1(m[4]) && isAroundZero$1(m[5]);
  16159. }
  16160. function setTransform(attrs, m, compress) {
  16161. if (m && !(noTranslate(m) && noRotateScale(m))) {
  16162. var mul = compress ? 10 : 1e4;
  16163. attrs.transform = noRotateScale(m)
  16164. ? "translate(" + round$1(m[4] * mul) / mul + " " + round$1(m[5] * mul) / mul + ")" : getMatrixStr(m);
  16165. }
  16166. }
  16167. function convertPolyShape(shape, attrs, mul) {
  16168. var points = shape.points;
  16169. var strArr = [];
  16170. for (var i = 0; i < points.length; i++) {
  16171. strArr.push(round$1(points[i][0] * mul) / mul);
  16172. strArr.push(round$1(points[i][1] * mul) / mul);
  16173. }
  16174. attrs.points = strArr.join(' ');
  16175. }
  16176. function validatePolyShape(shape) {
  16177. return !shape.smooth;
  16178. }
  16179. function createAttrsConvert(desc) {
  16180. var normalizedDesc = map(desc, function (item) {
  16181. return (typeof item === 'string' ? [item, item] : item);
  16182. });
  16183. return function (shape, attrs, mul) {
  16184. for (var i = 0; i < normalizedDesc.length; i++) {
  16185. var item = normalizedDesc[i];
  16186. var val = shape[item[0]];
  16187. if (val != null) {
  16188. attrs[item[1]] = round$1(val * mul) / mul;
  16189. }
  16190. }
  16191. };
  16192. }
  16193. var builtinShapesDef = {
  16194. circle: [createAttrsConvert(['cx', 'cy', 'r'])],
  16195. polyline: [convertPolyShape, validatePolyShape],
  16196. polygon: [convertPolyShape, validatePolyShape]
  16197. };
  16198. function hasShapeAnimation(el) {
  16199. var animators = el.animators;
  16200. for (var i = 0; i < animators.length; i++) {
  16201. if (animators[i].targetName === 'shape') {
  16202. return true;
  16203. }
  16204. }
  16205. return false;
  16206. }
  16207. function brushSVGPath(el, scope) {
  16208. var style = el.style;
  16209. var shape = el.shape;
  16210. var builtinShpDef = builtinShapesDef[el.type];
  16211. var attrs = {};
  16212. var needsAnimate = scope.animation;
  16213. var svgElType = 'path';
  16214. var strokePercent = el.style.strokePercent;
  16215. var precision = (scope.compress && getPathPrecision(el)) || 4;
  16216. if (builtinShpDef
  16217. && !scope.willUpdate
  16218. && !(builtinShpDef[1] && !builtinShpDef[1](shape))
  16219. && !(needsAnimate && hasShapeAnimation(el))
  16220. && !(strokePercent < 1)) {
  16221. svgElType = el.type;
  16222. var mul = Math.pow(10, precision);
  16223. builtinShpDef[0](shape, attrs, mul);
  16224. }
  16225. else {
  16226. var needBuildPath = !el.path || el.shapeChanged();
  16227. if (!el.path) {
  16228. el.createPathProxy();
  16229. }
  16230. var path = el.path;
  16231. if (needBuildPath) {
  16232. path.beginPath();
  16233. el.buildPath(path, el.shape);
  16234. el.pathUpdated();
  16235. }
  16236. var pathVersion = path.getVersion();
  16237. var elExt = el;
  16238. var svgPathBuilder = elExt.__svgPathBuilder;
  16239. if (elExt.__svgPathVersion !== pathVersion
  16240. || !svgPathBuilder
  16241. || strokePercent !== elExt.__svgPathStrokePercent) {
  16242. if (!svgPathBuilder) {
  16243. svgPathBuilder = elExt.__svgPathBuilder = new SVGPathRebuilder();
  16244. }
  16245. svgPathBuilder.reset(precision);
  16246. path.rebuildPath(svgPathBuilder, strokePercent);
  16247. svgPathBuilder.generateStr();
  16248. elExt.__svgPathVersion = pathVersion;
  16249. elExt.__svgPathStrokePercent = strokePercent;
  16250. }
  16251. attrs.d = svgPathBuilder.getStr();
  16252. }
  16253. setTransform(attrs, el.transform);
  16254. setStyleAttrs(attrs, style, el, scope);
  16255. scope.animation && createCSSAnimation(el, attrs, scope);
  16256. return createVNode(svgElType, el.id + '', attrs);
  16257. }
  16258. function brushSVGImage(el, scope) {
  16259. var style = el.style;
  16260. var image = style.image;
  16261. if (image && !isString(image)) {
  16262. if (isImageLike$1(image)) {
  16263. image = image.src;
  16264. }
  16265. else if (isCanvasLike(image)) {
  16266. image = image.toDataURL();
  16267. }
  16268. }
  16269. if (!image) {
  16270. return;
  16271. }
  16272. var x = style.x || 0;
  16273. var y = style.y || 0;
  16274. var dw = style.width;
  16275. var dh = style.height;
  16276. var attrs = {
  16277. href: image,
  16278. width: dw,
  16279. height: dh
  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('image', el.id + '', attrs);
  16291. }
  16292. function brushSVGTSpan(el, scope) {
  16293. var style = el.style;
  16294. var text = style.text;
  16295. text != null && (text += '');
  16296. if (!text || isNaN(style.x) || isNaN(style.y)) {
  16297. return;
  16298. }
  16299. var font = style.font || DEFAULT_FONT;
  16300. var x = style.x || 0;
  16301. var y = adjustTextY(style.y || 0, getLineHeight(font), style.textBaseline);
  16302. var textAlign = TEXT_ALIGN_TO_ANCHOR[style.textAlign]
  16303. || style.textAlign;
  16304. var attrs = {
  16305. 'dominant-baseline': 'central',
  16306. 'text-anchor': textAlign
  16307. };
  16308. if (hasSeparateFont(style)) {
  16309. var separatedFontStr = '';
  16310. var fontStyle = style.fontStyle;
  16311. var fontSize = parseFontSize(style.fontSize);
  16312. if (!parseFloat(fontSize)) {
  16313. return;
  16314. }
  16315. var fontFamily = style.fontFamily || DEFAULT_FONT_FAMILY;
  16316. var fontWeight = style.fontWeight;
  16317. separatedFontStr += "font-size:" + fontSize + ";font-family:" + fontFamily + ";";
  16318. if (fontStyle && fontStyle !== 'normal') {
  16319. separatedFontStr += "font-style:" + fontStyle + ";";
  16320. }
  16321. if (fontWeight && fontWeight !== 'normal') {
  16322. separatedFontStr += "font-weight:" + fontWeight + ";";
  16323. }
  16324. attrs.style = separatedFontStr;
  16325. }
  16326. else {
  16327. attrs.style = "font: " + font;
  16328. }
  16329. if (text.match(/\s/)) {
  16330. attrs['xml:space'] = 'preserve';
  16331. }
  16332. if (x) {
  16333. attrs.x = x;
  16334. }
  16335. if (y) {
  16336. attrs.y = y;
  16337. }
  16338. setTransform(attrs, el.transform);
  16339. setStyleAttrs(attrs, style, el, scope);
  16340. scope.animation && createCSSAnimation(el, attrs, scope);
  16341. return createVNode('text', el.id + '', attrs, undefined, text);
  16342. }
  16343. function brush$1(el, scope) {
  16344. if (el instanceof Path) {
  16345. return brushSVGPath(el, scope);
  16346. }
  16347. else if (el instanceof ZRImage) {
  16348. return brushSVGImage(el, scope);
  16349. }
  16350. else if (el instanceof TSpan) {
  16351. return brushSVGTSpan(el, scope);
  16352. }
  16353. }
  16354. function setShadow(el, attrs, scope) {
  16355. var style = el.style;
  16356. if (hasShadow(style)) {
  16357. var shadowKey = getShadowKey(el);
  16358. var shadowCache = scope.shadowCache;
  16359. var shadowId = shadowCache[shadowKey];
  16360. if (!shadowId) {
  16361. var globalScale = el.getGlobalScale();
  16362. var scaleX = globalScale[0];
  16363. var scaleY = globalScale[1];
  16364. if (!scaleX || !scaleY) {
  16365. return;
  16366. }
  16367. var offsetX = style.shadowOffsetX || 0;
  16368. var offsetY = style.shadowOffsetY || 0;
  16369. var blur_1 = style.shadowBlur;
  16370. var _a = normalizeColor(style.shadowColor), opacity = _a.opacity, color = _a.color;
  16371. var stdDx = blur_1 / 2 / scaleX;
  16372. var stdDy = blur_1 / 2 / scaleY;
  16373. var stdDeviation = stdDx + ' ' + stdDy;
  16374. shadowId = scope.zrId + '-s' + scope.shadowIdx++;
  16375. scope.defs[shadowId] = createVNode('filter', shadowId, {
  16376. 'id': shadowId,
  16377. 'x': '-100%',
  16378. 'y': '-100%',
  16379. 'width': '300%',
  16380. 'height': '300%'
  16381. }, [
  16382. createVNode('feDropShadow', '', {
  16383. 'dx': offsetX / scaleX,
  16384. 'dy': offsetY / scaleY,
  16385. 'stdDeviation': stdDeviation,
  16386. 'flood-color': color,
  16387. 'flood-opacity': opacity
  16388. })
  16389. ]);
  16390. shadowCache[shadowKey] = shadowId;
  16391. }
  16392. attrs.filter = getIdURL(shadowId);
  16393. }
  16394. }
  16395. function setGradient(style, attrs, target, scope) {
  16396. var val = style[target];
  16397. var gradientTag;
  16398. var gradientAttrs = {
  16399. 'gradientUnits': val.global
  16400. ? 'userSpaceOnUse'
  16401. : 'objectBoundingBox'
  16402. };
  16403. if (isLinearGradient(val)) {
  16404. gradientTag = 'linearGradient';
  16405. gradientAttrs.x1 = val.x;
  16406. gradientAttrs.y1 = val.y;
  16407. gradientAttrs.x2 = val.x2;
  16408. gradientAttrs.y2 = val.y2;
  16409. }
  16410. else if (isRadialGradient(val)) {
  16411. gradientTag = 'radialGradient';
  16412. gradientAttrs.cx = retrieve2(val.x, 0.5);
  16413. gradientAttrs.cy = retrieve2(val.y, 0.5);
  16414. gradientAttrs.r = retrieve2(val.r, 0.5);
  16415. }
  16416. else {
  16417. {
  16418. logError('Illegal gradient type.');
  16419. }
  16420. return;
  16421. }
  16422. var colors = val.colorStops;
  16423. var colorStops = [];
  16424. for (var i = 0, len = colors.length; i < len; ++i) {
  16425. var offset = round4(colors[i].offset) * 100 + '%';
  16426. var stopColor = colors[i].color;
  16427. var _a = normalizeColor(stopColor), color = _a.color, opacity = _a.opacity;
  16428. var stopsAttrs = {
  16429. 'offset': offset
  16430. };
  16431. stopsAttrs['stop-color'] = color;
  16432. if (opacity < 1) {
  16433. stopsAttrs['stop-opacity'] = opacity;
  16434. }
  16435. colorStops.push(createVNode('stop', i + '', stopsAttrs));
  16436. }
  16437. var gradientVNode = createVNode(gradientTag, '', gradientAttrs, colorStops);
  16438. var gradientKey = vNodeToString(gradientVNode);
  16439. var gradientCache = scope.gradientCache;
  16440. var gradientId = gradientCache[gradientKey];
  16441. if (!gradientId) {
  16442. gradientId = scope.zrId + '-g' + scope.gradientIdx++;
  16443. gradientCache[gradientKey] = gradientId;
  16444. gradientAttrs.id = gradientId;
  16445. scope.defs[gradientId] = createVNode(gradientTag, gradientId, gradientAttrs, colorStops);
  16446. }
  16447. attrs[target] = getIdURL(gradientId);
  16448. }
  16449. function setPattern(el, attrs, target, scope) {
  16450. var val = el.style[target];
  16451. var boundingRect = el.getBoundingRect();
  16452. var patternAttrs = {};
  16453. var repeat = val.repeat;
  16454. var noRepeat = repeat === 'no-repeat';
  16455. var repeatX = repeat === 'repeat-x';
  16456. var repeatY = repeat === 'repeat-y';
  16457. var child;
  16458. if (isImagePattern(val)) {
  16459. var imageWidth_1 = val.imageWidth;
  16460. var imageHeight_1 = val.imageHeight;
  16461. var imageSrc = void 0;
  16462. var patternImage = val.image;
  16463. if (isString(patternImage)) {
  16464. imageSrc = patternImage;
  16465. }
  16466. else if (isImageLike$1(patternImage)) {
  16467. imageSrc = patternImage.src;
  16468. }
  16469. else if (isCanvasLike(patternImage)) {
  16470. imageSrc = patternImage.toDataURL();
  16471. }
  16472. if (typeof Image === 'undefined') {
  16473. var errMsg = 'Image width/height must been given explictly in svg-ssr renderer.';
  16474. assert(imageWidth_1, errMsg);
  16475. assert(imageHeight_1, errMsg);
  16476. }
  16477. else if (imageWidth_1 == null || imageHeight_1 == null) {
  16478. var setSizeToVNode_1 = function (vNode, img) {
  16479. if (vNode) {
  16480. var svgEl = vNode.elm;
  16481. var width = imageWidth_1 || img.width;
  16482. var height = imageHeight_1 || img.height;
  16483. if (vNode.tag === 'pattern') {
  16484. if (repeatX) {
  16485. height = 1;
  16486. width /= boundingRect.width;
  16487. }
  16488. else if (repeatY) {
  16489. width = 1;
  16490. height /= boundingRect.height;
  16491. }
  16492. }
  16493. vNode.attrs.width = width;
  16494. vNode.attrs.height = height;
  16495. if (svgEl) {
  16496. svgEl.setAttribute('width', width);
  16497. svgEl.setAttribute('height', height);
  16498. }
  16499. }
  16500. };
  16501. var createdImage = createOrUpdateImage(imageSrc, null, el, function (img) {
  16502. noRepeat || setSizeToVNode_1(patternVNode, img);
  16503. setSizeToVNode_1(child, img);
  16504. });
  16505. if (createdImage && createdImage.width && createdImage.height) {
  16506. imageWidth_1 = imageWidth_1 || createdImage.width;
  16507. imageHeight_1 = imageHeight_1 || createdImage.height;
  16508. }
  16509. }
  16510. child = createVNode('image', 'img', {
  16511. href: imageSrc,
  16512. width: imageWidth_1,
  16513. height: imageHeight_1
  16514. });
  16515. patternAttrs.width = imageWidth_1;
  16516. patternAttrs.height = imageHeight_1;
  16517. }
  16518. else if (val.svgElement) {
  16519. child = clone(val.svgElement);
  16520. patternAttrs.width = val.svgWidth;
  16521. patternAttrs.height = val.svgHeight;
  16522. }
  16523. if (!child) {
  16524. return;
  16525. }
  16526. var patternWidth;
  16527. var patternHeight;
  16528. if (noRepeat) {
  16529. patternWidth = patternHeight = 1;
  16530. }
  16531. else if (repeatX) {
  16532. patternHeight = 1;
  16533. patternWidth = patternAttrs.width / boundingRect.width;
  16534. }
  16535. else if (repeatY) {
  16536. patternWidth = 1;
  16537. patternHeight = patternAttrs.height / boundingRect.height;
  16538. }
  16539. else {
  16540. patternAttrs.patternUnits = 'userSpaceOnUse';
  16541. }
  16542. if (patternWidth != null && !isNaN(patternWidth)) {
  16543. patternAttrs.width = patternWidth;
  16544. }
  16545. if (patternHeight != null && !isNaN(patternHeight)) {
  16546. patternAttrs.height = patternHeight;
  16547. }
  16548. var patternTransform = getSRTTransformString(val);
  16549. patternTransform && (patternAttrs.patternTransform = patternTransform);
  16550. var patternVNode = createVNode('pattern', '', patternAttrs, [child]);
  16551. var patternKey = vNodeToString(patternVNode);
  16552. var patternCache = scope.patternCache;
  16553. var patternId = patternCache[patternKey];
  16554. if (!patternId) {
  16555. patternId = scope.zrId + '-p' + scope.patternIdx++;
  16556. patternCache[patternKey] = patternId;
  16557. patternAttrs.id = patternId;
  16558. patternVNode = scope.defs[patternId] = createVNode('pattern', patternId, patternAttrs, [child]);
  16559. }
  16560. attrs[target] = getIdURL(patternId);
  16561. }
  16562. function setClipPath(clipPath, attrs, scope) {
  16563. var clipPathCache = scope.clipPathCache, defs = scope.defs;
  16564. var clipPathId = clipPathCache[clipPath.id];
  16565. if (!clipPathId) {
  16566. clipPathId = scope.zrId + '-c' + scope.clipPathIdx++;
  16567. var clipPathAttrs = {
  16568. id: clipPathId
  16569. };
  16570. clipPathCache[clipPath.id] = clipPathId;
  16571. defs[clipPathId] = createVNode('clipPath', clipPathId, clipPathAttrs, [brushSVGPath(clipPath, scope)]);
  16572. }
  16573. attrs['clip-path'] = getIdURL(clipPathId);
  16574. }
  16575. function createTextNode(text) {
  16576. return document.createTextNode(text);
  16577. }
  16578. function insertBefore(parentNode, newNode, referenceNode) {
  16579. parentNode.insertBefore(newNode, referenceNode);
  16580. }
  16581. function removeChild(node, child) {
  16582. node.removeChild(child);
  16583. }
  16584. function appendChild(node, child) {
  16585. node.appendChild(child);
  16586. }
  16587. function parentNode(node) {
  16588. return node.parentNode;
  16589. }
  16590. function nextSibling(node) {
  16591. return node.nextSibling;
  16592. }
  16593. function setTextContent(node, text) {
  16594. node.textContent = text;
  16595. }
  16596. var colonChar = 58;
  16597. var xChar = 120;
  16598. var emptyNode = createVNode('', '');
  16599. function isUndef(s) {
  16600. return s === undefined;
  16601. }
  16602. function isDef(s) {
  16603. return s !== undefined;
  16604. }
  16605. function createKeyToOldIdx(children, beginIdx, endIdx) {
  16606. var map = {};
  16607. for (var i = beginIdx; i <= endIdx; ++i) {
  16608. var key = children[i].key;
  16609. if (key !== undefined) {
  16610. {
  16611. if (map[key] != null) {
  16612. console.error("Duplicate key " + key);
  16613. }
  16614. }
  16615. map[key] = i;
  16616. }
  16617. }
  16618. return map;
  16619. }
  16620. function sameVnode(vnode1, vnode2) {
  16621. var isSameKey = vnode1.key === vnode2.key;
  16622. var isSameTag = vnode1.tag === vnode2.tag;
  16623. return isSameTag && isSameKey;
  16624. }
  16625. function createElm(vnode) {
  16626. var i;
  16627. var children = vnode.children;
  16628. var tag = vnode.tag;
  16629. if (isDef(tag)) {
  16630. var elm = (vnode.elm = createElement(tag));
  16631. updateAttrs(emptyNode, vnode);
  16632. if (isArray(children)) {
  16633. for (i = 0; i < children.length; ++i) {
  16634. var ch = children[i];
  16635. if (ch != null) {
  16636. appendChild(elm, createElm(ch));
  16637. }
  16638. }
  16639. }
  16640. else if (isDef(vnode.text) && !isObject(vnode.text)) {
  16641. appendChild(elm, createTextNode(vnode.text));
  16642. }
  16643. }
  16644. else {
  16645. vnode.elm = createTextNode(vnode.text);
  16646. }
  16647. return vnode.elm;
  16648. }
  16649. function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
  16650. for (; startIdx <= endIdx; ++startIdx) {
  16651. var ch = vnodes[startIdx];
  16652. if (ch != null) {
  16653. insertBefore(parentElm, createElm(ch), before);
  16654. }
  16655. }
  16656. }
  16657. function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
  16658. for (; startIdx <= endIdx; ++startIdx) {
  16659. var ch = vnodes[startIdx];
  16660. if (ch != null) {
  16661. if (isDef(ch.tag)) {
  16662. var parent_1 = parentNode(ch.elm);
  16663. removeChild(parent_1, ch.elm);
  16664. }
  16665. else {
  16666. removeChild(parentElm, ch.elm);
  16667. }
  16668. }
  16669. }
  16670. }
  16671. function updateAttrs(oldVnode, vnode) {
  16672. var key;
  16673. var elm = vnode.elm;
  16674. var oldAttrs = oldVnode && oldVnode.attrs || {};
  16675. var attrs = vnode.attrs || {};
  16676. if (oldAttrs === attrs) {
  16677. return;
  16678. }
  16679. for (key in attrs) {
  16680. var cur = attrs[key];
  16681. var old = oldAttrs[key];
  16682. if (old !== cur) {
  16683. if (cur === true) {
  16684. elm.setAttribute(key, '');
  16685. }
  16686. else if (cur === false) {
  16687. elm.removeAttribute(key);
  16688. }
  16689. else {
  16690. if (key.charCodeAt(0) !== xChar) {
  16691. elm.setAttribute(key, cur);
  16692. }
  16693. else if (key === 'xmlns:xlink' || key === 'xmlns') {
  16694. elm.setAttributeNS(XMLNS, key, cur);
  16695. }
  16696. else if (key.charCodeAt(3) === colonChar) {
  16697. elm.setAttributeNS(XML_NAMESPACE, key, cur);
  16698. }
  16699. else if (key.charCodeAt(5) === colonChar) {
  16700. elm.setAttributeNS(XLINKNS, key, cur);
  16701. }
  16702. else {
  16703. elm.setAttribute(key, cur);
  16704. }
  16705. }
  16706. }
  16707. }
  16708. for (key in oldAttrs) {
  16709. if (!(key in attrs)) {
  16710. elm.removeAttribute(key);
  16711. }
  16712. }
  16713. }
  16714. function updateChildren(parentElm, oldCh, newCh) {
  16715. var oldStartIdx = 0;
  16716. var newStartIdx = 0;
  16717. var oldEndIdx = oldCh.length - 1;
  16718. var oldStartVnode = oldCh[0];
  16719. var oldEndVnode = oldCh[oldEndIdx];
  16720. var newEndIdx = newCh.length - 1;
  16721. var newStartVnode = newCh[0];
  16722. var newEndVnode = newCh[newEndIdx];
  16723. var oldKeyToIdx;
  16724. var idxInOld;
  16725. var elmToMove;
  16726. var before;
  16727. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  16728. if (oldStartVnode == null) {
  16729. oldStartVnode = oldCh[++oldStartIdx];
  16730. }
  16731. else if (oldEndVnode == null) {
  16732. oldEndVnode = oldCh[--oldEndIdx];
  16733. }
  16734. else if (newStartVnode == null) {
  16735. newStartVnode = newCh[++newStartIdx];
  16736. }
  16737. else if (newEndVnode == null) {
  16738. newEndVnode = newCh[--newEndIdx];
  16739. }
  16740. else if (sameVnode(oldStartVnode, newStartVnode)) {
  16741. patchVnode(oldStartVnode, newStartVnode);
  16742. oldStartVnode = oldCh[++oldStartIdx];
  16743. newStartVnode = newCh[++newStartIdx];
  16744. }
  16745. else if (sameVnode(oldEndVnode, newEndVnode)) {
  16746. patchVnode(oldEndVnode, newEndVnode);
  16747. oldEndVnode = oldCh[--oldEndIdx];
  16748. newEndVnode = newCh[--newEndIdx];
  16749. }
  16750. else if (sameVnode(oldStartVnode, newEndVnode)) {
  16751. patchVnode(oldStartVnode, newEndVnode);
  16752. insertBefore(parentElm, oldStartVnode.elm, nextSibling(oldEndVnode.elm));
  16753. oldStartVnode = oldCh[++oldStartIdx];
  16754. newEndVnode = newCh[--newEndIdx];
  16755. }
  16756. else if (sameVnode(oldEndVnode, newStartVnode)) {
  16757. patchVnode(oldEndVnode, newStartVnode);
  16758. insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
  16759. oldEndVnode = oldCh[--oldEndIdx];
  16760. newStartVnode = newCh[++newStartIdx];
  16761. }
  16762. else {
  16763. if (isUndef(oldKeyToIdx)) {
  16764. oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
  16765. }
  16766. idxInOld = oldKeyToIdx[newStartVnode.key];
  16767. if (isUndef(idxInOld)) {
  16768. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  16769. }
  16770. else {
  16771. elmToMove = oldCh[idxInOld];
  16772. if (elmToMove.tag !== newStartVnode.tag) {
  16773. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  16774. }
  16775. else {
  16776. patchVnode(elmToMove, newStartVnode);
  16777. oldCh[idxInOld] = undefined;
  16778. insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
  16779. }
  16780. }
  16781. newStartVnode = newCh[++newStartIdx];
  16782. }
  16783. }
  16784. if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
  16785. if (oldStartIdx > oldEndIdx) {
  16786. before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm;
  16787. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
  16788. }
  16789. else {
  16790. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
  16791. }
  16792. }
  16793. }
  16794. function patchVnode(oldVnode, vnode) {
  16795. var elm = (vnode.elm = oldVnode.elm);
  16796. var oldCh = oldVnode.children;
  16797. var ch = vnode.children;
  16798. if (oldVnode === vnode) {
  16799. return;
  16800. }
  16801. updateAttrs(oldVnode, vnode);
  16802. if (isUndef(vnode.text)) {
  16803. if (isDef(oldCh) && isDef(ch)) {
  16804. if (oldCh !== ch) {
  16805. updateChildren(elm, oldCh, ch);
  16806. }
  16807. }
  16808. else if (isDef(ch)) {
  16809. if (isDef(oldVnode.text)) {
  16810. setTextContent(elm, '');
  16811. }
  16812. addVnodes(elm, null, ch, 0, ch.length - 1);
  16813. }
  16814. else if (isDef(oldCh)) {
  16815. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  16816. }
  16817. else if (isDef(oldVnode.text)) {
  16818. setTextContent(elm, '');
  16819. }
  16820. }
  16821. else if (oldVnode.text !== vnode.text) {
  16822. if (isDef(oldCh)) {
  16823. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  16824. }
  16825. setTextContent(elm, vnode.text);
  16826. }
  16827. }
  16828. function patch(oldVnode, vnode) {
  16829. if (sameVnode(oldVnode, vnode)) {
  16830. patchVnode(oldVnode, vnode);
  16831. }
  16832. else {
  16833. var elm = oldVnode.elm;
  16834. var parent_2 = parentNode(elm);
  16835. createElm(vnode);
  16836. if (parent_2 !== null) {
  16837. insertBefore(parent_2, vnode.elm, nextSibling(elm));
  16838. removeVnodes(parent_2, [oldVnode], 0, 0);
  16839. }
  16840. }
  16841. return vnode;
  16842. }
  16843. var svgId = 0;
  16844. var SVGPainter = (function () {
  16845. function SVGPainter(root, storage, opts) {
  16846. this.type = 'svg';
  16847. this.refreshHover = createMethodNotSupport('refreshHover');
  16848. this.configLayer = createMethodNotSupport('configLayer');
  16849. this.storage = storage;
  16850. this._opts = opts = extend({}, opts);
  16851. this.root = root;
  16852. this._id = 'zr' + svgId++;
  16853. this._oldVNode = createSVGVNode(opts.width, opts.height);
  16854. if (root && !opts.ssr) {
  16855. var viewport = this._viewport = document.createElement('div');
  16856. viewport.style.cssText = 'position:relative;overflow:hidden';
  16857. var svgDom = this._svgDom = this._oldVNode.elm = createElement('svg');
  16858. updateAttrs(null, this._oldVNode);
  16859. viewport.appendChild(svgDom);
  16860. root.appendChild(viewport);
  16861. }
  16862. this.resize(opts.width, opts.height);
  16863. }
  16864. SVGPainter.prototype.getType = function () {
  16865. return this.type;
  16866. };
  16867. SVGPainter.prototype.getViewportRoot = function () {
  16868. return this._viewport;
  16869. };
  16870. SVGPainter.prototype.getViewportRootOffset = function () {
  16871. var viewportRoot = this.getViewportRoot();
  16872. if (viewportRoot) {
  16873. return {
  16874. offsetLeft: viewportRoot.offsetLeft || 0,
  16875. offsetTop: viewportRoot.offsetTop || 0
  16876. };
  16877. }
  16878. };
  16879. SVGPainter.prototype.getSvgDom = function () {
  16880. return this._svgDom;
  16881. };
  16882. SVGPainter.prototype.refresh = function () {
  16883. if (this.root) {
  16884. var vnode = this.renderToVNode({
  16885. willUpdate: true
  16886. });
  16887. vnode.attrs.style = 'position:absolute;left:0;top:0;user-select:none';
  16888. patch(this._oldVNode, vnode);
  16889. this._oldVNode = vnode;
  16890. }
  16891. };
  16892. SVGPainter.prototype.renderOneToVNode = function (el) {
  16893. return brush$1(el, createBrushScope(this._id));
  16894. };
  16895. SVGPainter.prototype.renderToVNode = function (opts) {
  16896. opts = opts || {};
  16897. var list = this.storage.getDisplayList(true);
  16898. var width = this._width;
  16899. var height = this._height;
  16900. var scope = createBrushScope(this._id);
  16901. scope.animation = opts.animation;
  16902. scope.willUpdate = opts.willUpdate;
  16903. scope.compress = opts.compress;
  16904. var children = [];
  16905. var bgVNode = this._bgVNode = createBackgroundVNode(width, height, this._backgroundColor, scope);
  16906. bgVNode && children.push(bgVNode);
  16907. var mainVNode = !opts.compress
  16908. ? (this._mainVNode = createVNode('g', 'main', {}, [])) : null;
  16909. this._paintList(list, scope, mainVNode ? mainVNode.children : children);
  16910. mainVNode && children.push(mainVNode);
  16911. var defs = map(keys(scope.defs), function (id) { return scope.defs[id]; });
  16912. if (defs.length) {
  16913. children.push(createVNode('defs', 'defs', {}, defs));
  16914. }
  16915. if (opts.animation) {
  16916. var animationCssStr = getCssString(scope.cssNodes, scope.cssAnims, { newline: true });
  16917. if (animationCssStr) {
  16918. var styleNode = createVNode('style', 'stl', {}, [], animationCssStr);
  16919. children.push(styleNode);
  16920. }
  16921. }
  16922. return createSVGVNode(width, height, children, opts.useViewBox);
  16923. };
  16924. SVGPainter.prototype.renderToString = function (opts) {
  16925. opts = opts || {};
  16926. return vNodeToString(this.renderToVNode({
  16927. animation: retrieve2(opts.cssAnimation, true),
  16928. willUpdate: false,
  16929. compress: true,
  16930. useViewBox: retrieve2(opts.useViewBox, true)
  16931. }), { newline: true });
  16932. };
  16933. SVGPainter.prototype.setBackgroundColor = function (backgroundColor) {
  16934. this._backgroundColor = backgroundColor;
  16935. };
  16936. SVGPainter.prototype.getSvgRoot = function () {
  16937. return this._mainVNode && this._mainVNode.elm;
  16938. };
  16939. SVGPainter.prototype._paintList = function (list, scope, out) {
  16940. var listLen = list.length;
  16941. var clipPathsGroupsStack = [];
  16942. var clipPathsGroupsStackDepth = 0;
  16943. var currentClipPathGroup;
  16944. var prevClipPaths;
  16945. var clipGroupNodeIdx = 0;
  16946. for (var i = 0; i < listLen; i++) {
  16947. var displayable = list[i];
  16948. if (!displayable.invisible) {
  16949. var clipPaths = displayable.__clipPaths;
  16950. var len = clipPaths && clipPaths.length || 0;
  16951. var prevLen = prevClipPaths && prevClipPaths.length || 0;
  16952. var lca = void 0;
  16953. for (lca = Math.max(len - 1, prevLen - 1); lca >= 0; lca--) {
  16954. if (clipPaths && prevClipPaths
  16955. && clipPaths[lca] === prevClipPaths[lca]) {
  16956. break;
  16957. }
  16958. }
  16959. for (var i_1 = prevLen - 1; i_1 > lca; i_1--) {
  16960. clipPathsGroupsStackDepth--;
  16961. currentClipPathGroup = clipPathsGroupsStack[clipPathsGroupsStackDepth - 1];
  16962. }
  16963. for (var i_2 = lca + 1; i_2 < len; i_2++) {
  16964. var groupAttrs = {};
  16965. setClipPath(clipPaths[i_2], groupAttrs, scope);
  16966. var g = createVNode('g', 'clip-g-' + clipGroupNodeIdx++, groupAttrs, []);
  16967. (currentClipPathGroup ? currentClipPathGroup.children : out).push(g);
  16968. clipPathsGroupsStack[clipPathsGroupsStackDepth++] = g;
  16969. currentClipPathGroup = g;
  16970. }
  16971. prevClipPaths = clipPaths;
  16972. var ret = brush$1(displayable, scope);
  16973. if (ret) {
  16974. (currentClipPathGroup ? currentClipPathGroup.children : out).push(ret);
  16975. }
  16976. }
  16977. }
  16978. };
  16979. SVGPainter.prototype.resize = function (width, height) {
  16980. var opts = this._opts;
  16981. var root = this.root;
  16982. var viewport = this._viewport;
  16983. width != null && (opts.width = width);
  16984. height != null && (opts.height = height);
  16985. if (root && viewport) {
  16986. viewport.style.display = 'none';
  16987. width = getSize(root, 0, opts);
  16988. height = getSize(root, 1, opts);
  16989. viewport.style.display = '';
  16990. }
  16991. if (this._width !== width || this._height !== height) {
  16992. this._width = width;
  16993. this._height = height;
  16994. if (viewport) {
  16995. var viewportStyle = viewport.style;
  16996. viewportStyle.width = width + 'px';
  16997. viewportStyle.height = height + 'px';
  16998. }
  16999. if (!isPattern(this._backgroundColor)) {
  17000. var svgDom = this._svgDom;
  17001. if (svgDom) {
  17002. svgDom.setAttribute('width', width);
  17003. svgDom.setAttribute('height', height);
  17004. }
  17005. var bgEl = this._bgVNode && this._bgVNode.elm;
  17006. if (bgEl) {
  17007. bgEl.setAttribute('width', width);
  17008. bgEl.setAttribute('height', height);
  17009. }
  17010. }
  17011. else {
  17012. this.refresh();
  17013. }
  17014. }
  17015. };
  17016. SVGPainter.prototype.getWidth = function () {
  17017. return this._width;
  17018. };
  17019. SVGPainter.prototype.getHeight = function () {
  17020. return this._height;
  17021. };
  17022. SVGPainter.prototype.dispose = function () {
  17023. if (this.root) {
  17024. this.root.innerHTML = '';
  17025. }
  17026. this._svgDom =
  17027. this._viewport =
  17028. this.storage =
  17029. this._oldVNode =
  17030. this._bgVNode =
  17031. this._mainVNode = null;
  17032. };
  17033. SVGPainter.prototype.clear = function () {
  17034. if (this._svgDom) {
  17035. this._svgDom.innerHTML = null;
  17036. }
  17037. this._oldVNode = null;
  17038. };
  17039. SVGPainter.prototype.toDataURL = function (base64) {
  17040. var str = this.renderToString();
  17041. var prefix = 'data:image/svg+xml;';
  17042. if (base64) {
  17043. str = encodeBase64(str);
  17044. return str && prefix + 'base64,' + str;
  17045. }
  17046. return prefix + 'charset=UTF-8,' + encodeURIComponent(str);
  17047. };
  17048. return SVGPainter;
  17049. }());
  17050. function createMethodNotSupport(method) {
  17051. return function () {
  17052. {
  17053. logError('In SVG mode painter not support method "' + method + '"');
  17054. }
  17055. };
  17056. }
  17057. function createBackgroundVNode(width, height, backgroundColor, scope) {
  17058. var bgVNode;
  17059. if (backgroundColor && backgroundColor !== 'none') {
  17060. bgVNode = createVNode('rect', 'bg', {
  17061. width: width,
  17062. height: height,
  17063. x: '0',
  17064. y: '0',
  17065. id: '0'
  17066. });
  17067. if (isGradient(backgroundColor)) {
  17068. setGradient({ fill: backgroundColor }, bgVNode.attrs, 'fill', scope);
  17069. }
  17070. else if (isPattern(backgroundColor)) {
  17071. setPattern({
  17072. style: {
  17073. fill: backgroundColor
  17074. },
  17075. dirty: noop,
  17076. getBoundingRect: function () { return ({ width: width, height: height }); }
  17077. }, bgVNode.attrs, 'fill', scope);
  17078. }
  17079. else {
  17080. var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
  17081. bgVNode.attrs.fill = color;
  17082. opacity < 1 && (bgVNode.attrs['fill-opacity'] = opacity);
  17083. }
  17084. }
  17085. return bgVNode;
  17086. }
  17087. registerPainter('canvas', CanvasPainter);
  17088. registerPainter('svg', SVGPainter);
  17089. exports.Arc = Arc;
  17090. exports.ArcShape = ArcShape;
  17091. exports.BezierCurve = BezierCurve;
  17092. exports.BezierCurveShape = BezierCurveShape;
  17093. exports.BoundingRect = BoundingRect;
  17094. exports.Circle = Circle;
  17095. exports.CircleShape = CircleShape;
  17096. exports.CompoundPath = CompoundPath;
  17097. exports.Displayable = Displayable;
  17098. exports.Droplet = Droplet;
  17099. exports.DropletShape = DropletShape;
  17100. exports.Element = Element;
  17101. exports.Ellipse = Ellipse;
  17102. exports.EllipseShape = EllipseShape;
  17103. exports.Group = Group;
  17104. exports.Heart = Heart;
  17105. exports.HeartShape = HeartShape;
  17106. exports.Image = ZRImage;
  17107. exports.IncrementalDisplayable = IncrementalDisplayable;
  17108. exports.Isogon = Isogon;
  17109. exports.IsogonShape = IsogonShape;
  17110. exports.Line = Line;
  17111. exports.LineShape = LineShape;
  17112. exports.LinearGradient = LinearGradient;
  17113. exports.OrientedBoundingRect = OrientedBoundingRect;
  17114. exports.Path = Path;
  17115. exports.Pattern = Pattern;
  17116. exports.Point = Point;
  17117. exports.Polygon = Polygon;
  17118. exports.PolygonShape = PolygonShape;
  17119. exports.Polyline = Polyline;
  17120. exports.PolylineShape = PolylineShape;
  17121. exports.RadialGradient = RadialGradient;
  17122. exports.Rect = Rect;
  17123. exports.RectShape = RectShape;
  17124. exports.Ring = Ring;
  17125. exports.RingShape = RingShape;
  17126. exports.Rose = Rose;
  17127. exports.RoseShape = RoseShape;
  17128. exports.Sector = Sector;
  17129. exports.SectorShape = SectorShape;
  17130. exports.Star = Star;
  17131. exports.StarShape = StarShape;
  17132. exports.TSpan = TSpan;
  17133. exports.Text = ZRText;
  17134. exports.Trochoid = Trochoid;
  17135. exports.TrochoidShape = TrochoidShape;
  17136. exports.color = color;
  17137. exports.dispose = dispose;
  17138. exports.disposeAll = disposeAll;
  17139. exports.getInstance = getInstance;
  17140. exports.init = init;
  17141. exports.matrix = matrix;
  17142. exports.morph = morphPath$1;
  17143. exports.parseSVG = parseSVG;
  17144. exports.path = path;
  17145. exports.registerPainter = registerPainter;
  17146. exports.setPlatformAPI = setPlatformAPI;
  17147. exports.showDebugDirtyRect = showDebugDirtyRect;
  17148. exports.util = util;
  17149. exports.vector = vector;
  17150. exports.version = version;
  17151. Object.defineProperty(exports, '__esModule', { value: true });
  17152. })));
  17153. //# sourceMappingURL=zrender.js.map