zrender.js 653 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.zrender = {}));
  5. }(this, (function (exports) { 'use strict';
  6. var Browser = (function () {
  7. function Browser() {
  8. this.firefox = false;
  9. this.ie = false;
  10. this.edge = false;
  11. this.newEdge = false;
  12. this.weChat = false;
  13. }
  14. return Browser;
  15. }());
  16. var Env = (function () {
  17. function Env() {
  18. this.browser = new Browser();
  19. this.node = false;
  20. this.wxa = false;
  21. this.worker = false;
  22. this.svgSupported = false;
  23. this.touchEventsSupported = false;
  24. this.pointerEventsSupported = false;
  25. this.domSupported = false;
  26. this.transformSupported = false;
  27. this.transform3dSupported = false;
  28. this.hasGlobalWindow = typeof window !== 'undefined';
  29. }
  30. return Env;
  31. }());
  32. var env = new Env();
  33. if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
  34. env.wxa = true;
  35. env.touchEventsSupported = true;
  36. }
  37. else if (typeof document === 'undefined' && typeof self !== 'undefined') {
  38. env.worker = true;
  39. }
  40. else if (!env.hasGlobalWindow
  41. || 'Deno' in window
  42. || (typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string'
  43. && navigator.userAgent.indexOf('Node.js') > -1)) {
  44. env.node = true;
  45. env.svgSupported = true;
  46. }
  47. else {
  48. detect(navigator.userAgent, env);
  49. }
  50. function detect(ua, env) {
  51. var browser = env.browser;
  52. var firefox = ua.match(/Firefox\/([\d.]+)/);
  53. var ie = ua.match(/MSIE\s([\d.]+)/)
  54. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  55. var edge = ua.match(/Edge?\/([\d.]+)/);
  56. var weChat = (/micromessenger/i).test(ua);
  57. if (firefox) {
  58. browser.firefox = true;
  59. browser.version = firefox[1];
  60. }
  61. if (ie) {
  62. browser.ie = true;
  63. browser.version = ie[1];
  64. }
  65. if (edge) {
  66. browser.edge = true;
  67. browser.version = edge[1];
  68. browser.newEdge = +edge[1].split('.')[0] > 18;
  69. }
  70. if (weChat) {
  71. browser.weChat = true;
  72. }
  73. env.svgSupported = typeof SVGRect !== 'undefined';
  74. env.touchEventsSupported = 'ontouchstart' in window && !browser.ie && !browser.edge;
  75. env.pointerEventsSupported = 'onpointerdown' in window
  76. && (browser.edge || (browser.ie && +browser.version >= 11));
  77. var domSupported = env.domSupported = typeof document !== 'undefined';
  78. if (domSupported) {
  79. var style = document.documentElement.style;
  80. env.transform3dSupported = ((browser.ie && 'transition' in style)
  81. || browser.edge
  82. || (('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()))
  83. || 'MozPerspective' in style)
  84. && !('OTransition' in style);
  85. env.transformSupported = env.transform3dSupported
  86. || (browser.ie && +browser.version >= 9);
  87. }
  88. }
  89. var DEFAULT_FONT_SIZE = 12;
  90. var DEFAULT_FONT_FAMILY = 'sans-serif';
  91. var DEFAULT_FONT = DEFAULT_FONT_SIZE + "px " + DEFAULT_FONT_FAMILY;
  92. var OFFSET = 20;
  93. var SCALE = 100;
  94. var defaultWidthMapStr = "007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N";
  95. function getTextWidthMap(mapStr) {
  96. var map = {};
  97. if (typeof JSON === 'undefined') {
  98. return map;
  99. }
  100. for (var i = 0; i < mapStr.length; i++) {
  101. var char = String.fromCharCode(i + 32);
  102. var size = (mapStr.charCodeAt(i) - OFFSET) / SCALE;
  103. map[char] = size;
  104. }
  105. return map;
  106. }
  107. var DEFAULT_TEXT_WIDTH_MAP = getTextWidthMap(defaultWidthMapStr);
  108. var platformApi = {
  109. createCanvas: function () {
  110. return typeof document !== 'undefined'
  111. && document.createElement('canvas');
  112. },
  113. measureText: (function () {
  114. var _ctx;
  115. var _cachedFont;
  116. return function (text, font) {
  117. if (!_ctx) {
  118. var canvas = platformApi.createCanvas();
  119. _ctx = canvas && canvas.getContext('2d');
  120. }
  121. if (_ctx) {
  122. if (_cachedFont !== font) {
  123. _cachedFont = _ctx.font = font || DEFAULT_FONT;
  124. }
  125. return _ctx.measureText(text);
  126. }
  127. else {
  128. text = text || '';
  129. font = font || DEFAULT_FONT;
  130. var res = /((?:\d+)?\.?\d*)px/.exec(font);
  131. var fontSize = res && +res[1] || DEFAULT_FONT_SIZE;
  132. var width = 0;
  133. if (font.indexOf('mono') >= 0) {
  134. width = fontSize * text.length;
  135. }
  136. else {
  137. for (var i = 0; i < text.length; i++) {
  138. var preCalcWidth = DEFAULT_TEXT_WIDTH_MAP[text[i]];
  139. width += preCalcWidth == null ? fontSize : (preCalcWidth * fontSize);
  140. }
  141. }
  142. return { width: width };
  143. }
  144. };
  145. })(),
  146. loadImage: function (src, onload, onerror) {
  147. var image = new Image();
  148. image.onload = onload;
  149. image.onerror = onerror;
  150. image.src = src;
  151. return image;
  152. }
  153. };
  154. function setPlatformAPI(newPlatformApis) {
  155. for (var key in platformApi) {
  156. if (newPlatformApis[key]) {
  157. platformApi[key] = newPlatformApis[key];
  158. }
  159. }
  160. }
  161. var BUILTIN_OBJECT = reduce([
  162. 'Function',
  163. 'RegExp',
  164. 'Date',
  165. 'Error',
  166. 'CanvasGradient',
  167. 'CanvasPattern',
  168. 'Image',
  169. 'Canvas'
  170. ], function (obj, val) {
  171. obj['[object ' + val + ']'] = true;
  172. return obj;
  173. }, {});
  174. var TYPED_ARRAY = reduce([
  175. 'Int8',
  176. 'Uint8',
  177. 'Uint8Clamped',
  178. 'Int16',
  179. 'Uint16',
  180. 'Int32',
  181. 'Uint32',
  182. 'Float32',
  183. 'Float64'
  184. ], function (obj, val) {
  185. obj['[object ' + val + 'Array]'] = true;
  186. return obj;
  187. }, {});
  188. var objToString = Object.prototype.toString;
  189. var arrayProto = Array.prototype;
  190. var nativeForEach = arrayProto.forEach;
  191. var nativeFilter = arrayProto.filter;
  192. var nativeSlice = arrayProto.slice;
  193. var nativeMap = arrayProto.map;
  194. var ctorFunction = function () { }.constructor;
  195. var protoFunction = ctorFunction ? ctorFunction.prototype : null;
  196. var protoKey = '__proto__';
  197. var idStart = 0x0907;
  198. function guid() {
  199. return idStart++;
  200. }
  201. function logError() {
  202. var args = [];
  203. for (var _i = 0; _i < arguments.length; _i++) {
  204. args[_i] = arguments[_i];
  205. }
  206. if (typeof console !== 'undefined') {
  207. console.error.apply(console, args);
  208. }
  209. }
  210. function clone(source) {
  211. if (source == null || typeof source !== 'object') {
  212. return source;
  213. }
  214. var result = source;
  215. var typeStr = objToString.call(source);
  216. if (typeStr === '[object Array]') {
  217. if (!isPrimitive(source)) {
  218. result = [];
  219. for (var i = 0, len = source.length; i < len; i++) {
  220. result[i] = clone(source[i]);
  221. }
  222. }
  223. }
  224. else if (TYPED_ARRAY[typeStr]) {
  225. if (!isPrimitive(source)) {
  226. var Ctor = source.constructor;
  227. if (Ctor.from) {
  228. result = Ctor.from(source);
  229. }
  230. else {
  231. result = new Ctor(source.length);
  232. for (var i = 0, len = source.length; i < len; i++) {
  233. result[i] = source[i];
  234. }
  235. }
  236. }
  237. }
  238. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  239. result = {};
  240. for (var key in source) {
  241. if (source.hasOwnProperty(key) && key !== protoKey) {
  242. result[key] = clone(source[key]);
  243. }
  244. }
  245. }
  246. return result;
  247. }
  248. function merge(target, source, overwrite) {
  249. if (!isObject(source) || !isObject(target)) {
  250. return overwrite ? clone(source) : target;
  251. }
  252. for (var key in source) {
  253. if (source.hasOwnProperty(key) && key !== protoKey) {
  254. var targetProp = target[key];
  255. var sourceProp = source[key];
  256. if (isObject(sourceProp)
  257. && isObject(targetProp)
  258. && !isArray(sourceProp)
  259. && !isArray(targetProp)
  260. && !isDom(sourceProp)
  261. && !isDom(targetProp)
  262. && !isBuiltInObject(sourceProp)
  263. && !isBuiltInObject(targetProp)
  264. && !isPrimitive(sourceProp)
  265. && !isPrimitive(targetProp)) {
  266. merge(targetProp, sourceProp, overwrite);
  267. }
  268. else if (overwrite || !(key in target)) {
  269. target[key] = clone(source[key]);
  270. }
  271. }
  272. }
  273. return target;
  274. }
  275. function mergeAll(targetAndSources, overwrite) {
  276. var result = targetAndSources[0];
  277. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  278. result = merge(result, targetAndSources[i], overwrite);
  279. }
  280. return result;
  281. }
  282. function extend(target, source) {
  283. if (Object.assign) {
  284. Object.assign(target, source);
  285. }
  286. else {
  287. for (var key in source) {
  288. if (source.hasOwnProperty(key) && key !== protoKey) {
  289. target[key] = source[key];
  290. }
  291. }
  292. }
  293. return target;
  294. }
  295. function defaults(target, source, overlay) {
  296. var keysArr = keys(source);
  297. for (var i = 0, len = keysArr.length; i < len; i++) {
  298. var key = keysArr[i];
  299. if ((overlay ? source[key] != null : target[key] == null)) {
  300. target[key] = source[key];
  301. }
  302. }
  303. return target;
  304. }
  305. var createCanvas = platformApi.createCanvas;
  306. function indexOf(array, value) {
  307. if (array) {
  308. if (array.indexOf) {
  309. return array.indexOf(value);
  310. }
  311. for (var i = 0, len = array.length; i < len; i++) {
  312. if (array[i] === value) {
  313. return i;
  314. }
  315. }
  316. }
  317. return -1;
  318. }
  319. function inherits(clazz, baseClazz) {
  320. var clazzPrototype = clazz.prototype;
  321. function F() { }
  322. F.prototype = baseClazz.prototype;
  323. clazz.prototype = new F();
  324. for (var prop in clazzPrototype) {
  325. if (clazzPrototype.hasOwnProperty(prop)) {
  326. clazz.prototype[prop] = clazzPrototype[prop];
  327. }
  328. }
  329. clazz.prototype.constructor = clazz;
  330. clazz.superClass = baseClazz;
  331. }
  332. function mixin(target, source, override) {
  333. target = 'prototype' in target ? target.prototype : target;
  334. source = 'prototype' in source ? source.prototype : source;
  335. if (Object.getOwnPropertyNames) {
  336. var keyList = Object.getOwnPropertyNames(source);
  337. for (var i = 0; i < keyList.length; i++) {
  338. var key = keyList[i];
  339. if (key !== 'constructor') {
  340. if ((override ? source[key] != null : target[key] == null)) {
  341. target[key] = source[key];
  342. }
  343. }
  344. }
  345. }
  346. else {
  347. defaults(target, source, override);
  348. }
  349. }
  350. function isArrayLike(data) {
  351. if (!data) {
  352. return false;
  353. }
  354. if (typeof data === 'string') {
  355. return false;
  356. }
  357. return typeof data.length === 'number';
  358. }
  359. function each(arr, cb, context) {
  360. if (!(arr && cb)) {
  361. return;
  362. }
  363. if (arr.forEach && arr.forEach === nativeForEach) {
  364. arr.forEach(cb, context);
  365. }
  366. else if (arr.length === +arr.length) {
  367. for (var i = 0, len = arr.length; i < len; i++) {
  368. cb.call(context, arr[i], i, arr);
  369. }
  370. }
  371. else {
  372. for (var key in arr) {
  373. if (arr.hasOwnProperty(key)) {
  374. cb.call(context, arr[key], key, arr);
  375. }
  376. }
  377. }
  378. }
  379. function map(arr, cb, context) {
  380. if (!arr) {
  381. return [];
  382. }
  383. if (!cb) {
  384. return slice(arr);
  385. }
  386. if (arr.map && arr.map === nativeMap) {
  387. return arr.map(cb, context);
  388. }
  389. else {
  390. var result = [];
  391. for (var i = 0, len = arr.length; i < len; i++) {
  392. result.push(cb.call(context, arr[i], i, arr));
  393. }
  394. return result;
  395. }
  396. }
  397. function reduce(arr, cb, memo, context) {
  398. if (!(arr && cb)) {
  399. return;
  400. }
  401. for (var i = 0, len = arr.length; i < len; i++) {
  402. memo = cb.call(context, memo, arr[i], i, arr);
  403. }
  404. return memo;
  405. }
  406. function filter(arr, cb, context) {
  407. if (!arr) {
  408. return [];
  409. }
  410. if (!cb) {
  411. return slice(arr);
  412. }
  413. if (arr.filter && arr.filter === nativeFilter) {
  414. return arr.filter(cb, context);
  415. }
  416. else {
  417. var result = [];
  418. for (var i = 0, len = arr.length; i < len; i++) {
  419. if (cb.call(context, arr[i], i, arr)) {
  420. result.push(arr[i]);
  421. }
  422. }
  423. return result;
  424. }
  425. }
  426. function find(arr, cb, context) {
  427. if (!(arr && cb)) {
  428. return;
  429. }
  430. for (var i = 0, len = arr.length; i < len; i++) {
  431. if (cb.call(context, arr[i], i, arr)) {
  432. return arr[i];
  433. }
  434. }
  435. }
  436. function keys(obj) {
  437. if (!obj) {
  438. return [];
  439. }
  440. if (Object.keys) {
  441. return Object.keys(obj);
  442. }
  443. var keyList = [];
  444. for (var key in obj) {
  445. if (obj.hasOwnProperty(key)) {
  446. keyList.push(key);
  447. }
  448. }
  449. return keyList;
  450. }
  451. function bindPolyfill(func, context) {
  452. var args = [];
  453. for (var _i = 2; _i < arguments.length; _i++) {
  454. args[_i - 2] = arguments[_i];
  455. }
  456. return function () {
  457. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  458. };
  459. }
  460. var bind = (protoFunction && isFunction(protoFunction.bind))
  461. ? protoFunction.call.bind(protoFunction.bind)
  462. : bindPolyfill;
  463. function curry(func) {
  464. var args = [];
  465. for (var _i = 1; _i < arguments.length; _i++) {
  466. args[_i - 1] = arguments[_i];
  467. }
  468. return function () {
  469. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  470. };
  471. }
  472. function isArray(value) {
  473. if (Array.isArray) {
  474. return Array.isArray(value);
  475. }
  476. return objToString.call(value) === '[object Array]';
  477. }
  478. function isFunction(value) {
  479. return typeof value === 'function';
  480. }
  481. function isString(value) {
  482. return typeof value === 'string';
  483. }
  484. function isStringSafe(value) {
  485. return objToString.call(value) === '[object String]';
  486. }
  487. function isNumber(value) {
  488. return typeof value === 'number';
  489. }
  490. function isObject(value) {
  491. var type = typeof value;
  492. return type === 'function' || (!!value && type === 'object');
  493. }
  494. function isBuiltInObject(value) {
  495. return !!BUILTIN_OBJECT[objToString.call(value)];
  496. }
  497. function isTypedArray(value) {
  498. return !!TYPED_ARRAY[objToString.call(value)];
  499. }
  500. function isDom(value) {
  501. return typeof value === 'object'
  502. && typeof value.nodeType === 'number'
  503. && typeof value.ownerDocument === 'object';
  504. }
  505. function isGradientObject(value) {
  506. return value.colorStops != null;
  507. }
  508. function isImagePatternObject(value) {
  509. return value.image != null;
  510. }
  511. function isRegExp(value) {
  512. return objToString.call(value) === '[object RegExp]';
  513. }
  514. function eqNaN(value) {
  515. return value !== value;
  516. }
  517. function retrieve() {
  518. var args = [];
  519. for (var _i = 0; _i < arguments.length; _i++) {
  520. args[_i] = arguments[_i];
  521. }
  522. for (var i = 0, len = args.length; i < len; i++) {
  523. if (args[i] != null) {
  524. return args[i];
  525. }
  526. }
  527. }
  528. function retrieve2(value0, value1) {
  529. return value0 != null
  530. ? value0
  531. : value1;
  532. }
  533. function retrieve3(value0, value1, value2) {
  534. return value0 != null
  535. ? value0
  536. : value1 != null
  537. ? value1
  538. : value2;
  539. }
  540. function slice(arr) {
  541. var args = [];
  542. for (var _i = 1; _i < arguments.length; _i++) {
  543. args[_i - 1] = arguments[_i];
  544. }
  545. return nativeSlice.apply(arr, args);
  546. }
  547. function normalizeCssArray(val) {
  548. if (typeof (val) === 'number') {
  549. return [val, val, val, val];
  550. }
  551. var len = val.length;
  552. if (len === 2) {
  553. return [val[0], val[1], val[0], val[1]];
  554. }
  555. else if (len === 3) {
  556. return [val[0], val[1], val[2], val[1]];
  557. }
  558. return val;
  559. }
  560. function assert(condition, message) {
  561. if (!condition) {
  562. throw new Error(message);
  563. }
  564. }
  565. function trim(str) {
  566. if (str == null) {
  567. return null;
  568. }
  569. else if (typeof str.trim === 'function') {
  570. return str.trim();
  571. }
  572. else {
  573. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  574. }
  575. }
  576. var primitiveKey = '__ec_primitive__';
  577. function setAsPrimitive(obj) {
  578. obj[primitiveKey] = true;
  579. }
  580. function isPrimitive(obj) {
  581. return obj[primitiveKey];
  582. }
  583. var MapPolyfill = (function () {
  584. function MapPolyfill() {
  585. this.data = {};
  586. }
  587. MapPolyfill.prototype["delete"] = function (key) {
  588. var existed = this.has(key);
  589. if (existed) {
  590. delete this.data[key];
  591. }
  592. return existed;
  593. };
  594. MapPolyfill.prototype.has = function (key) {
  595. return this.data.hasOwnProperty(key);
  596. };
  597. MapPolyfill.prototype.get = function (key) {
  598. return this.data[key];
  599. };
  600. MapPolyfill.prototype.set = function (key, value) {
  601. this.data[key] = value;
  602. return this;
  603. };
  604. MapPolyfill.prototype.keys = function () {
  605. return keys(this.data);
  606. };
  607. MapPolyfill.prototype.forEach = function (callback) {
  608. var data = this.data;
  609. for (var key in data) {
  610. if (data.hasOwnProperty(key)) {
  611. callback(data[key], key);
  612. }
  613. }
  614. };
  615. return MapPolyfill;
  616. }());
  617. var isNativeMapSupported = typeof Map === 'function';
  618. function maybeNativeMap() {
  619. return (isNativeMapSupported ? new Map() : new MapPolyfill());
  620. }
  621. var HashMap = (function () {
  622. function HashMap(obj) {
  623. var isArr = isArray(obj);
  624. this.data = maybeNativeMap();
  625. var thisMap = this;
  626. (obj instanceof HashMap)
  627. ? obj.each(visit)
  628. : (obj && each(obj, visit));
  629. function visit(value, key) {
  630. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  631. }
  632. }
  633. HashMap.prototype.hasKey = function (key) {
  634. return this.data.has(key);
  635. };
  636. HashMap.prototype.get = function (key) {
  637. return this.data.get(key);
  638. };
  639. HashMap.prototype.set = function (key, value) {
  640. this.data.set(key, value);
  641. return value;
  642. };
  643. HashMap.prototype.each = function (cb, context) {
  644. this.data.forEach(function (value, key) {
  645. cb.call(context, value, key);
  646. });
  647. };
  648. HashMap.prototype.keys = function () {
  649. var keys = this.data.keys();
  650. return isNativeMapSupported
  651. ? Array.from(keys)
  652. : keys;
  653. };
  654. HashMap.prototype.removeKey = function (key) {
  655. this.data["delete"](key);
  656. };
  657. return HashMap;
  658. }());
  659. function createHashMap(obj) {
  660. return new HashMap(obj);
  661. }
  662. function concatArray(a, b) {
  663. var newArray = new a.constructor(a.length + b.length);
  664. for (var i = 0; i < a.length; i++) {
  665. newArray[i] = a[i];
  666. }
  667. var offset = a.length;
  668. for (var i = 0; i < b.length; i++) {
  669. newArray[i + offset] = b[i];
  670. }
  671. return newArray;
  672. }
  673. function createObject(proto, properties) {
  674. var obj;
  675. if (Object.create) {
  676. obj = Object.create(proto);
  677. }
  678. else {
  679. var StyleCtor = function () { };
  680. StyleCtor.prototype = proto;
  681. obj = new StyleCtor();
  682. }
  683. if (properties) {
  684. extend(obj, properties);
  685. }
  686. return obj;
  687. }
  688. function disableUserSelect(dom) {
  689. var domStyle = dom.style;
  690. domStyle.webkitUserSelect = 'none';
  691. domStyle.userSelect = 'none';
  692. domStyle.webkitTapHighlightColor = 'rgba(0,0,0,0)';
  693. domStyle['-webkit-touch-callout'] = 'none';
  694. }
  695. function hasOwn(own, prop) {
  696. return own.hasOwnProperty(prop);
  697. }
  698. function noop() { }
  699. var RADIAN_TO_DEGREE = 180 / Math.PI;
  700. var EPSILON = Number.EPSILON || Math.pow(2, -52);
  701. var util = /*#__PURE__*/Object.freeze({
  702. __proto__: null,
  703. guid: guid,
  704. logError: logError,
  705. clone: clone,
  706. merge: merge,
  707. mergeAll: mergeAll,
  708. extend: extend,
  709. defaults: defaults,
  710. createCanvas: createCanvas,
  711. indexOf: indexOf,
  712. inherits: inherits,
  713. mixin: mixin,
  714. isArrayLike: isArrayLike,
  715. each: each,
  716. map: map,
  717. reduce: reduce,
  718. filter: filter,
  719. find: find,
  720. keys: keys,
  721. bind: bind,
  722. curry: curry,
  723. isArray: isArray,
  724. isFunction: isFunction,
  725. isString: isString,
  726. isStringSafe: isStringSafe,
  727. isNumber: isNumber,
  728. isObject: isObject,
  729. isBuiltInObject: isBuiltInObject,
  730. isTypedArray: isTypedArray,
  731. isDom: isDom,
  732. isGradientObject: isGradientObject,
  733. isImagePatternObject: isImagePatternObject,
  734. isRegExp: isRegExp,
  735. eqNaN: eqNaN,
  736. retrieve: retrieve,
  737. retrieve2: retrieve2,
  738. retrieve3: retrieve3,
  739. slice: slice,
  740. normalizeCssArray: normalizeCssArray,
  741. assert: assert,
  742. trim: trim,
  743. setAsPrimitive: setAsPrimitive,
  744. isPrimitive: isPrimitive,
  745. HashMap: HashMap,
  746. createHashMap: createHashMap,
  747. concatArray: concatArray,
  748. createObject: createObject,
  749. disableUserSelect: disableUserSelect,
  750. hasOwn: hasOwn,
  751. noop: noop,
  752. RADIAN_TO_DEGREE: RADIAN_TO_DEGREE,
  753. EPSILON: EPSILON
  754. });
  755. /*! *****************************************************************************
  756. Copyright (c) Microsoft Corporation. All rights reserved.
  757. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  758. this file except in compliance with the License. You may obtain a copy of the
  759. License at http://www.apache.org/licenses/LICENSE-2.0
  760. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  761. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  762. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  763. MERCHANTABLITY OR NON-INFRINGEMENT.
  764. See the Apache Version 2.0 License for specific language governing permissions
  765. and limitations under the License.
  766. ***************************************************************************** */
  767. /* global Reflect, Promise */
  768. var extendStatics = function(d, b) {
  769. extendStatics = Object.setPrototypeOf ||
  770. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  771. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  772. return extendStatics(d, b);
  773. };
  774. function __extends(d, b) {
  775. extendStatics(d, b);
  776. function __() { this.constructor = d; }
  777. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  778. }
  779. function create(x, y) {
  780. if (x == null) {
  781. x = 0;
  782. }
  783. if (y == null) {
  784. y = 0;
  785. }
  786. return [x, y];
  787. }
  788. function copy(out, v) {
  789. out[0] = v[0];
  790. out[1] = v[1];
  791. return out;
  792. }
  793. function clone$1(v) {
  794. return [v[0], v[1]];
  795. }
  796. function set(out, a, b) {
  797. out[0] = a;
  798. out[1] = b;
  799. return out;
  800. }
  801. function add(out, v1, v2) {
  802. out[0] = v1[0] + v2[0];
  803. out[1] = v1[1] + v2[1];
  804. return out;
  805. }
  806. function scaleAndAdd(out, v1, v2, a) {
  807. out[0] = v1[0] + v2[0] * a;
  808. out[1] = v1[1] + v2[1] * a;
  809. return out;
  810. }
  811. function sub(out, v1, v2) {
  812. out[0] = v1[0] - v2[0];
  813. out[1] = v1[1] - v2[1];
  814. return out;
  815. }
  816. function len(v) {
  817. return Math.sqrt(lenSquare(v));
  818. }
  819. var length = len;
  820. function lenSquare(v) {
  821. return v[0] * v[0] + v[1] * v[1];
  822. }
  823. var lengthSquare = lenSquare;
  824. function mul(out, v1, v2) {
  825. out[0] = v1[0] * v2[0];
  826. out[1] = v1[1] * v2[1];
  827. return out;
  828. }
  829. function div(out, v1, v2) {
  830. out[0] = v1[0] / v2[0];
  831. out[1] = v1[1] / v2[1];
  832. return out;
  833. }
  834. function dot(v1, v2) {
  835. return v1[0] * v2[0] + v1[1] * v2[1];
  836. }
  837. function scale(out, v, s) {
  838. out[0] = v[0] * s;
  839. out[1] = v[1] * s;
  840. return out;
  841. }
  842. function normalize(out, v) {
  843. var d = len(v);
  844. if (d === 0) {
  845. out[0] = 0;
  846. out[1] = 0;
  847. }
  848. else {
  849. out[0] = v[0] / d;
  850. out[1] = v[1] / d;
  851. }
  852. return out;
  853. }
  854. function distance(v1, v2) {
  855. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0])
  856. + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  857. }
  858. var dist = distance;
  859. function distanceSquare(v1, v2) {
  860. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  861. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  862. }
  863. var distSquare = distanceSquare;
  864. function negate(out, v) {
  865. out[0] = -v[0];
  866. out[1] = -v[1];
  867. return out;
  868. }
  869. function lerp(out, v1, v2, t) {
  870. out[0] = v1[0] + t * (v2[0] - v1[0]);
  871. out[1] = v1[1] + t * (v2[1] - v1[1]);
  872. return out;
  873. }
  874. function applyTransform(out, v, m) {
  875. var x = v[0];
  876. var y = v[1];
  877. out[0] = m[0] * x + m[2] * y + m[4];
  878. out[1] = m[1] * x + m[3] * y + m[5];
  879. return out;
  880. }
  881. function min(out, v1, v2) {
  882. out[0] = Math.min(v1[0], v2[0]);
  883. out[1] = Math.min(v1[1], v2[1]);
  884. return out;
  885. }
  886. function max(out, v1, v2) {
  887. out[0] = Math.max(v1[0], v2[0]);
  888. out[1] = Math.max(v1[1], v2[1]);
  889. return out;
  890. }
  891. var vector = /*#__PURE__*/Object.freeze({
  892. __proto__: null,
  893. create: create,
  894. copy: copy,
  895. clone: clone$1,
  896. set: set,
  897. add: add,
  898. scaleAndAdd: scaleAndAdd,
  899. sub: sub,
  900. len: len,
  901. length: length,
  902. lenSquare: lenSquare,
  903. lengthSquare: lengthSquare,
  904. mul: mul,
  905. div: div,
  906. dot: dot,
  907. scale: scale,
  908. normalize: normalize,
  909. distance: distance,
  910. dist: dist,
  911. distanceSquare: distanceSquare,
  912. distSquare: distSquare,
  913. negate: negate,
  914. lerp: lerp,
  915. applyTransform: applyTransform,
  916. min: min,
  917. max: max
  918. });
  919. var Param = (function () {
  920. function Param(target, e) {
  921. this.target = target;
  922. this.topTarget = e && e.topTarget;
  923. }
  924. return Param;
  925. }());
  926. var Draggable = (function () {
  927. function Draggable(handler) {
  928. this.handler = handler;
  929. handler.on('mousedown', this._dragStart, this);
  930. handler.on('mousemove', this._drag, this);
  931. handler.on('mouseup', this._dragEnd, this);
  932. }
  933. Draggable.prototype._dragStart = function (e) {
  934. var draggingTarget = e.target;
  935. while (draggingTarget && !draggingTarget.draggable) {
  936. draggingTarget = draggingTarget.parent || draggingTarget.__hostTarget;
  937. }
  938. if (draggingTarget) {
  939. this._draggingTarget = draggingTarget;
  940. draggingTarget.dragging = true;
  941. this._x = e.offsetX;
  942. this._y = e.offsetY;
  943. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragstart', e.event);
  944. }
  945. };
  946. Draggable.prototype._drag = function (e) {
  947. var draggingTarget = this._draggingTarget;
  948. if (draggingTarget) {
  949. var x = e.offsetX;
  950. var y = e.offsetY;
  951. var dx = x - this._x;
  952. var dy = y - this._y;
  953. this._x = x;
  954. this._y = y;
  955. draggingTarget.drift(dx, dy, e);
  956. this.handler.dispatchToElement(new Param(draggingTarget, e), 'drag', e.event);
  957. var dropTarget = this.handler.findHover(x, y, draggingTarget).target;
  958. var lastDropTarget = this._dropTarget;
  959. this._dropTarget = dropTarget;
  960. if (draggingTarget !== dropTarget) {
  961. if (lastDropTarget && dropTarget !== lastDropTarget) {
  962. this.handler.dispatchToElement(new Param(lastDropTarget, e), 'dragleave', e.event);
  963. }
  964. if (dropTarget && dropTarget !== lastDropTarget) {
  965. this.handler.dispatchToElement(new Param(dropTarget, e), 'dragenter', e.event);
  966. }
  967. }
  968. }
  969. };
  970. Draggable.prototype._dragEnd = function (e) {
  971. var draggingTarget = this._draggingTarget;
  972. if (draggingTarget) {
  973. draggingTarget.dragging = false;
  974. }
  975. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragend', e.event);
  976. if (this._dropTarget) {
  977. this.handler.dispatchToElement(new Param(this._dropTarget, e), 'drop', e.event);
  978. }
  979. this._draggingTarget = null;
  980. this._dropTarget = null;
  981. };
  982. return Draggable;
  983. }());
  984. var Eventful = (function () {
  985. function Eventful(eventProcessors) {
  986. if (eventProcessors) {
  987. this._$eventProcessor = eventProcessors;
  988. }
  989. }
  990. Eventful.prototype.on = function (event, query, handler, context) {
  991. if (!this._$handlers) {
  992. this._$handlers = {};
  993. }
  994. var _h = this._$handlers;
  995. if (typeof query === 'function') {
  996. context = handler;
  997. handler = query;
  998. query = null;
  999. }
  1000. if (!handler || !event) {
  1001. return this;
  1002. }
  1003. var eventProcessor = this._$eventProcessor;
  1004. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  1005. query = eventProcessor.normalizeQuery(query);
  1006. }
  1007. if (!_h[event]) {
  1008. _h[event] = [];
  1009. }
  1010. for (var i = 0; i < _h[event].length; i++) {
  1011. if (_h[event][i].h === handler) {
  1012. return this;
  1013. }
  1014. }
  1015. var wrap = {
  1016. h: handler,
  1017. query: query,
  1018. ctx: (context || this),
  1019. callAtLast: handler.zrEventfulCallAtLast
  1020. };
  1021. var lastIndex = _h[event].length - 1;
  1022. var lastWrap = _h[event][lastIndex];
  1023. (lastWrap && lastWrap.callAtLast)
  1024. ? _h[event].splice(lastIndex, 0, wrap)
  1025. : _h[event].push(wrap);
  1026. return this;
  1027. };
  1028. Eventful.prototype.isSilent = function (eventName) {
  1029. var _h = this._$handlers;
  1030. return !_h || !_h[eventName] || !_h[eventName].length;
  1031. };
  1032. Eventful.prototype.off = function (eventType, handler) {
  1033. var _h = this._$handlers;
  1034. if (!_h) {
  1035. return this;
  1036. }
  1037. if (!eventType) {
  1038. this._$handlers = {};
  1039. return this;
  1040. }
  1041. if (handler) {
  1042. if (_h[eventType]) {
  1043. var newList = [];
  1044. for (var i = 0, l = _h[eventType].length; i < l; i++) {
  1045. if (_h[eventType][i].h !== handler) {
  1046. newList.push(_h[eventType][i]);
  1047. }
  1048. }
  1049. _h[eventType] = newList;
  1050. }
  1051. if (_h[eventType] && _h[eventType].length === 0) {
  1052. delete _h[eventType];
  1053. }
  1054. }
  1055. else {
  1056. delete _h[eventType];
  1057. }
  1058. return this;
  1059. };
  1060. Eventful.prototype.trigger = function (eventType) {
  1061. var args = [];
  1062. for (var _i = 1; _i < arguments.length; _i++) {
  1063. args[_i - 1] = arguments[_i];
  1064. }
  1065. if (!this._$handlers) {
  1066. return this;
  1067. }
  1068. var _h = this._$handlers[eventType];
  1069. var eventProcessor = this._$eventProcessor;
  1070. if (_h) {
  1071. var argLen = args.length;
  1072. var len = _h.length;
  1073. for (var i = 0; i < len; i++) {
  1074. var hItem = _h[i];
  1075. if (eventProcessor
  1076. && eventProcessor.filter
  1077. && hItem.query != null
  1078. && !eventProcessor.filter(eventType, hItem.query)) {
  1079. continue;
  1080. }
  1081. switch (argLen) {
  1082. case 0:
  1083. hItem.h.call(hItem.ctx);
  1084. break;
  1085. case 1:
  1086. hItem.h.call(hItem.ctx, args[0]);
  1087. break;
  1088. case 2:
  1089. hItem.h.call(hItem.ctx, args[0], args[1]);
  1090. break;
  1091. default:
  1092. hItem.h.apply(hItem.ctx, args);
  1093. break;
  1094. }
  1095. }
  1096. }
  1097. eventProcessor && eventProcessor.afterTrigger
  1098. && eventProcessor.afterTrigger(eventType);
  1099. return this;
  1100. };
  1101. Eventful.prototype.triggerWithContext = function (type) {
  1102. var args = [];
  1103. for (var _i = 1; _i < arguments.length; _i++) {
  1104. args[_i - 1] = arguments[_i];
  1105. }
  1106. if (!this._$handlers) {
  1107. return this;
  1108. }
  1109. var _h = this._$handlers[type];
  1110. var eventProcessor = this._$eventProcessor;
  1111. if (_h) {
  1112. var argLen = args.length;
  1113. var ctx = args[argLen - 1];
  1114. var len = _h.length;
  1115. for (var i = 0; i < len; i++) {
  1116. var hItem = _h[i];
  1117. if (eventProcessor
  1118. && eventProcessor.filter
  1119. && hItem.query != null
  1120. && !eventProcessor.filter(type, hItem.query)) {
  1121. continue;
  1122. }
  1123. switch (argLen) {
  1124. case 0:
  1125. hItem.h.call(ctx);
  1126. break;
  1127. case 1:
  1128. hItem.h.call(ctx, args[0]);
  1129. break;
  1130. case 2:
  1131. hItem.h.call(ctx, args[0], args[1]);
  1132. break;
  1133. default:
  1134. hItem.h.apply(ctx, args.slice(1, argLen - 1));
  1135. break;
  1136. }
  1137. }
  1138. }
  1139. eventProcessor && eventProcessor.afterTrigger
  1140. && eventProcessor.afterTrigger(type);
  1141. return this;
  1142. };
  1143. return Eventful;
  1144. }());
  1145. var LN2 = Math.log(2);
  1146. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1147. var cacheKey = rowMask + '-' + colMask;
  1148. var fullRank = rows.length;
  1149. if (detCache.hasOwnProperty(cacheKey)) {
  1150. return detCache[cacheKey];
  1151. }
  1152. if (rank === 1) {
  1153. var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);
  1154. return rows[rowStart][colStart];
  1155. }
  1156. var subRowMask = rowMask | (1 << rowStart);
  1157. var subRowStart = rowStart + 1;
  1158. while (rowMask & (1 << subRowStart)) {
  1159. subRowStart++;
  1160. }
  1161. var sum = 0;
  1162. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1163. var colTag = 1 << j;
  1164. if (!(colTag & colMask)) {
  1165. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]
  1166. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1167. colLocalIdx++;
  1168. }
  1169. }
  1170. detCache[cacheKey] = sum;
  1171. return sum;
  1172. }
  1173. function buildTransformer(src, dest) {
  1174. var mA = [
  1175. [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],
  1176. [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],
  1177. [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],
  1178. [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],
  1179. [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],
  1180. [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],
  1181. [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],
  1182. [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]
  1183. ];
  1184. var detCache = {};
  1185. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1186. if (det === 0) {
  1187. return;
  1188. }
  1189. var vh = [];
  1190. for (var i = 0; i < 8; i++) {
  1191. for (var j = 0; j < 8; j++) {
  1192. vh[j] == null && (vh[j] = 0);
  1193. vh[j] += ((i + j) % 2 ? -1 : 1)
  1194. * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)
  1195. / det * dest[i];
  1196. }
  1197. }
  1198. return function (out, srcPointX, srcPointY) {
  1199. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1200. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1201. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1202. };
  1203. }
  1204. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1205. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1206. if (el.getBoundingClientRect && env.domSupported && !isCanvasEl(el)) {
  1207. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1208. var markers = prepareCoordMarkers(el, saved);
  1209. var transformer = preparePointerTransformer(markers, saved, inverse);
  1210. if (transformer) {
  1211. transformer(out, inX, inY);
  1212. return true;
  1213. }
  1214. }
  1215. return false;
  1216. }
  1217. function prepareCoordMarkers(el, saved) {
  1218. var markers = saved.markers;
  1219. if (markers) {
  1220. return markers;
  1221. }
  1222. markers = saved.markers = [];
  1223. var propLR = ['left', 'right'];
  1224. var propTB = ['top', 'bottom'];
  1225. for (var i = 0; i < 4; i++) {
  1226. var marker = document.createElement('div');
  1227. var stl = marker.style;
  1228. var idxLR = i % 2;
  1229. var idxTB = (i >> 1) % 2;
  1230. stl.cssText = [
  1231. 'position: absolute',
  1232. 'visibility: hidden',
  1233. 'padding: 0',
  1234. 'margin: 0',
  1235. 'border-width: 0',
  1236. 'user-select: none',
  1237. 'width:0',
  1238. 'height:0',
  1239. propLR[idxLR] + ':0',
  1240. propTB[idxTB] + ':0',
  1241. propLR[1 - idxLR] + ':auto',
  1242. propTB[1 - idxTB] + ':auto',
  1243. ''
  1244. ].join('!important;');
  1245. el.appendChild(marker);
  1246. markers.push(marker);
  1247. }
  1248. saved.clearMarkers = function () {
  1249. each(markers, function (marker) {
  1250. marker.parentNode && marker.parentNode.removeChild(marker);
  1251. });
  1252. };
  1253. return markers;
  1254. }
  1255. function preparePointerTransformer(markers, saved, inverse) {
  1256. var transformerName = inverse ? 'invTrans' : 'trans';
  1257. var transformer = saved[transformerName];
  1258. var oldSrcCoords = saved.srcCoords;
  1259. var srcCoords = [];
  1260. var destCoords = [];
  1261. var oldCoordTheSame = true;
  1262. for (var i = 0; i < 4; i++) {
  1263. var rect = markers[i].getBoundingClientRect();
  1264. var ii = 2 * i;
  1265. var x = rect.left;
  1266. var y = rect.top;
  1267. srcCoords.push(x, y);
  1268. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1269. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1270. }
  1271. return (oldCoordTheSame && transformer)
  1272. ? transformer
  1273. : (saved.srcCoords = srcCoords,
  1274. saved[transformerName] = inverse
  1275. ? buildTransformer(destCoords, srcCoords)
  1276. : buildTransformer(srcCoords, destCoords));
  1277. }
  1278. function isCanvasEl(el) {
  1279. return el.nodeName.toUpperCase() === 'CANVAS';
  1280. }
  1281. var replaceReg = /([&<>"'])/g;
  1282. var replaceMap = {
  1283. '&': '&amp;',
  1284. '<': '&lt;',
  1285. '>': '&gt;',
  1286. '"': '&quot;',
  1287. '\'': '&#39;'
  1288. };
  1289. function encodeHTML(source) {
  1290. return source == null
  1291. ? ''
  1292. : (source + '').replace(replaceReg, function (str, c) {
  1293. return replaceMap[c];
  1294. });
  1295. }
  1296. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1297. var _calcOut = [];
  1298. var firefoxNotSupportOffsetXY = env.browser.firefox
  1299. && +env.browser.version.split('.')[0] < 39;
  1300. function clientToLocal(el, e, out, calculate) {
  1301. out = out || {};
  1302. if (calculate) {
  1303. calculateZrXY(el, e, out);
  1304. }
  1305. else if (firefoxNotSupportOffsetXY
  1306. && e.layerX != null
  1307. && e.layerX !== e.offsetX) {
  1308. out.zrX = e.layerX;
  1309. out.zrY = e.layerY;
  1310. }
  1311. else if (e.offsetX != null) {
  1312. out.zrX = e.offsetX;
  1313. out.zrY = e.offsetY;
  1314. }
  1315. else {
  1316. calculateZrXY(el, e, out);
  1317. }
  1318. return out;
  1319. }
  1320. function calculateZrXY(el, e, out) {
  1321. if (env.domSupported && el.getBoundingClientRect) {
  1322. var ex = e.clientX;
  1323. var ey = e.clientY;
  1324. if (isCanvasEl(el)) {
  1325. var box = el.getBoundingClientRect();
  1326. out.zrX = ex - box.left;
  1327. out.zrY = ey - box.top;
  1328. return;
  1329. }
  1330. else {
  1331. if (transformCoordWithViewport(_calcOut, el, ex, ey)) {
  1332. out.zrX = _calcOut[0];
  1333. out.zrY = _calcOut[1];
  1334. return;
  1335. }
  1336. }
  1337. }
  1338. out.zrX = out.zrY = 0;
  1339. }
  1340. function getNativeEvent(e) {
  1341. return e
  1342. || window.event;
  1343. }
  1344. function normalizeEvent(el, e, calculate) {
  1345. e = getNativeEvent(e);
  1346. if (e.zrX != null) {
  1347. return e;
  1348. }
  1349. var eventType = e.type;
  1350. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1351. if (!isTouch) {
  1352. clientToLocal(el, e, e, calculate);
  1353. var wheelDelta = getWheelDeltaMayPolyfill(e);
  1354. e.zrDelta = wheelDelta ? wheelDelta / 120 : -(e.detail || 0) / 3;
  1355. }
  1356. else {
  1357. var touch = eventType !== 'touchend'
  1358. ? e.targetTouches[0]
  1359. : e.changedTouches[0];
  1360. touch && clientToLocal(el, touch, e, calculate);
  1361. }
  1362. var button = e.button;
  1363. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1364. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1365. }
  1366. return e;
  1367. }
  1368. function getWheelDeltaMayPolyfill(e) {
  1369. var rawWheelDelta = e.wheelDelta;
  1370. if (rawWheelDelta) {
  1371. return rawWheelDelta;
  1372. }
  1373. var deltaX = e.deltaX;
  1374. var deltaY = e.deltaY;
  1375. if (deltaX == null || deltaY == null) {
  1376. return rawWheelDelta;
  1377. }
  1378. var delta = deltaY !== 0 ? Math.abs(deltaY) : Math.abs(deltaX);
  1379. var sign = deltaY > 0 ? -1
  1380. : deltaY < 0 ? 1
  1381. : deltaX > 0 ? -1
  1382. : 1;
  1383. return 3 * delta * sign;
  1384. }
  1385. function addEventListener(el, name, handler, opt) {
  1386. el.addEventListener(name, handler, opt);
  1387. }
  1388. function removeEventListener(el, name, handler, opt) {
  1389. el.removeEventListener(name, handler, opt);
  1390. }
  1391. var stop = function (e) {
  1392. e.preventDefault();
  1393. e.stopPropagation();
  1394. e.cancelBubble = true;
  1395. };
  1396. var GestureMgr = (function () {
  1397. function GestureMgr() {
  1398. this._track = [];
  1399. }
  1400. GestureMgr.prototype.recognize = function (event, target, root) {
  1401. this._doTrack(event, target, root);
  1402. return this._recognize(event);
  1403. };
  1404. GestureMgr.prototype.clear = function () {
  1405. this._track.length = 0;
  1406. return this;
  1407. };
  1408. GestureMgr.prototype._doTrack = function (event, target, root) {
  1409. var touches = event.touches;
  1410. if (!touches) {
  1411. return;
  1412. }
  1413. var trackItem = {
  1414. points: [],
  1415. touches: [],
  1416. target: target,
  1417. event: event
  1418. };
  1419. for (var i = 0, len = touches.length; i < len; i++) {
  1420. var touch = touches[i];
  1421. var pos = clientToLocal(root, touch, {});
  1422. trackItem.points.push([pos.zrX, pos.zrY]);
  1423. trackItem.touches.push(touch);
  1424. }
  1425. this._track.push(trackItem);
  1426. };
  1427. GestureMgr.prototype._recognize = function (event) {
  1428. for (var eventName in recognizers) {
  1429. if (recognizers.hasOwnProperty(eventName)) {
  1430. var gestureInfo = recognizers[eventName](this._track, event);
  1431. if (gestureInfo) {
  1432. return gestureInfo;
  1433. }
  1434. }
  1435. }
  1436. };
  1437. return GestureMgr;
  1438. }());
  1439. function dist$1(pointPair) {
  1440. var dx = pointPair[1][0] - pointPair[0][0];
  1441. var dy = pointPair[1][1] - pointPair[0][1];
  1442. return Math.sqrt(dx * dx + dy * dy);
  1443. }
  1444. function center(pointPair) {
  1445. return [
  1446. (pointPair[0][0] + pointPair[1][0]) / 2,
  1447. (pointPair[0][1] + pointPair[1][1]) / 2
  1448. ];
  1449. }
  1450. var recognizers = {
  1451. pinch: function (tracks, event) {
  1452. var trackLen = tracks.length;
  1453. if (!trackLen) {
  1454. return;
  1455. }
  1456. var pinchEnd = (tracks[trackLen - 1] || {}).points;
  1457. var pinchPre = (tracks[trackLen - 2] || {}).points || pinchEnd;
  1458. if (pinchPre
  1459. && pinchPre.length > 1
  1460. && pinchEnd
  1461. && pinchEnd.length > 1) {
  1462. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1463. !isFinite(pinchScale) && (pinchScale = 1);
  1464. event.pinchScale = pinchScale;
  1465. var pinchCenter = center(pinchEnd);
  1466. event.pinchX = pinchCenter[0];
  1467. event.pinchY = pinchCenter[1];
  1468. return {
  1469. type: 'pinch',
  1470. target: tracks[0].target,
  1471. event: event
  1472. };
  1473. }
  1474. }
  1475. };
  1476. function create$1() {
  1477. return [1, 0, 0, 1, 0, 0];
  1478. }
  1479. function identity(out) {
  1480. out[0] = 1;
  1481. out[1] = 0;
  1482. out[2] = 0;
  1483. out[3] = 1;
  1484. out[4] = 0;
  1485. out[5] = 0;
  1486. return out;
  1487. }
  1488. function copy$1(out, m) {
  1489. out[0] = m[0];
  1490. out[1] = m[1];
  1491. out[2] = m[2];
  1492. out[3] = m[3];
  1493. out[4] = m[4];
  1494. out[5] = m[5];
  1495. return out;
  1496. }
  1497. function mul$1(out, m1, m2) {
  1498. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  1499. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  1500. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  1501. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  1502. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1503. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1504. out[0] = out0;
  1505. out[1] = out1;
  1506. out[2] = out2;
  1507. out[3] = out3;
  1508. out[4] = out4;
  1509. out[5] = out5;
  1510. return out;
  1511. }
  1512. function translate(out, a, v) {
  1513. out[0] = a[0];
  1514. out[1] = a[1];
  1515. out[2] = a[2];
  1516. out[3] = a[3];
  1517. out[4] = a[4] + v[0];
  1518. out[5] = a[5] + v[1];
  1519. return out;
  1520. }
  1521. function rotate(out, a, rad, pivot) {
  1522. if (pivot === void 0) { pivot = [0, 0]; }
  1523. var aa = a[0];
  1524. var ac = a[2];
  1525. var atx = a[4];
  1526. var ab = a[1];
  1527. var ad = a[3];
  1528. var aty = a[5];
  1529. var st = Math.sin(rad);
  1530. var ct = Math.cos(rad);
  1531. out[0] = aa * ct + ab * st;
  1532. out[1] = -aa * st + ab * ct;
  1533. out[2] = ac * ct + ad * st;
  1534. out[3] = -ac * st + ct * ad;
  1535. out[4] = ct * (atx - pivot[0]) + st * (aty - pivot[1]) + pivot[0];
  1536. out[5] = ct * (aty - pivot[1]) - st * (atx - pivot[0]) + pivot[1];
  1537. return out;
  1538. }
  1539. function scale$1(out, a, v) {
  1540. var vx = v[0];
  1541. var vy = v[1];
  1542. out[0] = a[0] * vx;
  1543. out[1] = a[1] * vy;
  1544. out[2] = a[2] * vx;
  1545. out[3] = a[3] * vy;
  1546. out[4] = a[4] * vx;
  1547. out[5] = a[5] * vy;
  1548. return out;
  1549. }
  1550. function invert(out, a) {
  1551. var aa = a[0];
  1552. var ac = a[2];
  1553. var atx = a[4];
  1554. var ab = a[1];
  1555. var ad = a[3];
  1556. var aty = a[5];
  1557. var det = aa * ad - ab * ac;
  1558. if (!det) {
  1559. return null;
  1560. }
  1561. det = 1.0 / det;
  1562. out[0] = ad * det;
  1563. out[1] = -ab * det;
  1564. out[2] = -ac * det;
  1565. out[3] = aa * det;
  1566. out[4] = (ac * aty - ad * atx) * det;
  1567. out[5] = (ab * atx - aa * aty) * det;
  1568. return out;
  1569. }
  1570. function clone$2(a) {
  1571. var b = create$1();
  1572. copy$1(b, a);
  1573. return b;
  1574. }
  1575. var matrix = /*#__PURE__*/Object.freeze({
  1576. __proto__: null,
  1577. create: create$1,
  1578. identity: identity,
  1579. copy: copy$1,
  1580. mul: mul$1,
  1581. translate: translate,
  1582. rotate: rotate,
  1583. scale: scale$1,
  1584. invert: invert,
  1585. clone: clone$2
  1586. });
  1587. var Point = (function () {
  1588. function Point(x, y) {
  1589. this.x = x || 0;
  1590. this.y = y || 0;
  1591. }
  1592. Point.prototype.copy = function (other) {
  1593. this.x = other.x;
  1594. this.y = other.y;
  1595. return this;
  1596. };
  1597. Point.prototype.clone = function () {
  1598. return new Point(this.x, this.y);
  1599. };
  1600. Point.prototype.set = function (x, y) {
  1601. this.x = x;
  1602. this.y = y;
  1603. return this;
  1604. };
  1605. Point.prototype.equal = function (other) {
  1606. return other.x === this.x && other.y === this.y;
  1607. };
  1608. Point.prototype.add = function (other) {
  1609. this.x += other.x;
  1610. this.y += other.y;
  1611. return this;
  1612. };
  1613. Point.prototype.scale = function (scalar) {
  1614. this.x *= scalar;
  1615. this.y *= scalar;
  1616. };
  1617. Point.prototype.scaleAndAdd = function (other, scalar) {
  1618. this.x += other.x * scalar;
  1619. this.y += other.y * scalar;
  1620. };
  1621. Point.prototype.sub = function (other) {
  1622. this.x -= other.x;
  1623. this.y -= other.y;
  1624. return this;
  1625. };
  1626. Point.prototype.dot = function (other) {
  1627. return this.x * other.x + this.y * other.y;
  1628. };
  1629. Point.prototype.len = function () {
  1630. return Math.sqrt(this.x * this.x + this.y * this.y);
  1631. };
  1632. Point.prototype.lenSquare = function () {
  1633. return this.x * this.x + this.y * this.y;
  1634. };
  1635. Point.prototype.normalize = function () {
  1636. var len = this.len();
  1637. this.x /= len;
  1638. this.y /= len;
  1639. return this;
  1640. };
  1641. Point.prototype.distance = function (other) {
  1642. var dx = this.x - other.x;
  1643. var dy = this.y - other.y;
  1644. return Math.sqrt(dx * dx + dy * dy);
  1645. };
  1646. Point.prototype.distanceSquare = function (other) {
  1647. var dx = this.x - other.x;
  1648. var dy = this.y - other.y;
  1649. return dx * dx + dy * dy;
  1650. };
  1651. Point.prototype.negate = function () {
  1652. this.x = -this.x;
  1653. this.y = -this.y;
  1654. return this;
  1655. };
  1656. Point.prototype.transform = function (m) {
  1657. if (!m) {
  1658. return;
  1659. }
  1660. var x = this.x;
  1661. var y = this.y;
  1662. this.x = m[0] * x + m[2] * y + m[4];
  1663. this.y = m[1] * x + m[3] * y + m[5];
  1664. return this;
  1665. };
  1666. Point.prototype.toArray = function (out) {
  1667. out[0] = this.x;
  1668. out[1] = this.y;
  1669. return out;
  1670. };
  1671. Point.prototype.fromArray = function (input) {
  1672. this.x = input[0];
  1673. this.y = input[1];
  1674. };
  1675. Point.set = function (p, x, y) {
  1676. p.x = x;
  1677. p.y = y;
  1678. };
  1679. Point.copy = function (p, p2) {
  1680. p.x = p2.x;
  1681. p.y = p2.y;
  1682. };
  1683. Point.len = function (p) {
  1684. return Math.sqrt(p.x * p.x + p.y * p.y);
  1685. };
  1686. Point.lenSquare = function (p) {
  1687. return p.x * p.x + p.y * p.y;
  1688. };
  1689. Point.dot = function (p0, p1) {
  1690. return p0.x * p1.x + p0.y * p1.y;
  1691. };
  1692. Point.add = function (out, p0, p1) {
  1693. out.x = p0.x + p1.x;
  1694. out.y = p0.y + p1.y;
  1695. };
  1696. Point.sub = function (out, p0, p1) {
  1697. out.x = p0.x - p1.x;
  1698. out.y = p0.y - p1.y;
  1699. };
  1700. Point.scale = function (out, p0, scalar) {
  1701. out.x = p0.x * scalar;
  1702. out.y = p0.y * scalar;
  1703. };
  1704. Point.scaleAndAdd = function (out, p0, p1, scalar) {
  1705. out.x = p0.x + p1.x * scalar;
  1706. out.y = p0.y + p1.y * scalar;
  1707. };
  1708. Point.lerp = function (out, p0, p1, t) {
  1709. var onet = 1 - t;
  1710. out.x = onet * p0.x + t * p1.x;
  1711. out.y = onet * p0.y + t * p1.y;
  1712. };
  1713. return Point;
  1714. }());
  1715. var mathMin = Math.min;
  1716. var mathMax = Math.max;
  1717. var mathAbs = Math.abs;
  1718. var XY = ['x', 'y'];
  1719. var WH = ['width', 'height'];
  1720. var lt = new Point();
  1721. var rb = new Point();
  1722. var lb = new Point();
  1723. var rt = new Point();
  1724. var _intersectCtx = createIntersectContext();
  1725. var _minTv = _intersectCtx.minTv;
  1726. var _maxTv = _intersectCtx.maxTv;
  1727. var _lenMinMax = [0, 0];
  1728. var BoundingRect = (function () {
  1729. function BoundingRect(x, y, width, height) {
  1730. BoundingRect.set(this, x, y, width, height);
  1731. }
  1732. BoundingRect.set = function (target, x, y, width, height) {
  1733. if (width < 0) {
  1734. x = x + width;
  1735. width = -width;
  1736. }
  1737. if (height < 0) {
  1738. y = y + height;
  1739. height = -height;
  1740. }
  1741. target.x = x;
  1742. target.y = y;
  1743. target.width = width;
  1744. target.height = height;
  1745. return target;
  1746. };
  1747. BoundingRect.prototype.union = function (other) {
  1748. var x = mathMin(other.x, this.x);
  1749. var y = mathMin(other.y, this.y);
  1750. if (isFinite(this.x) && isFinite(this.width)) {
  1751. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  1752. }
  1753. else {
  1754. this.width = other.width;
  1755. }
  1756. if (isFinite(this.y) && isFinite(this.height)) {
  1757. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  1758. }
  1759. else {
  1760. this.height = other.height;
  1761. }
  1762. this.x = x;
  1763. this.y = y;
  1764. };
  1765. BoundingRect.prototype.applyTransform = function (m) {
  1766. BoundingRect.applyTransform(this, this, m);
  1767. };
  1768. BoundingRect.prototype.calculateTransform = function (b) {
  1769. var a = this;
  1770. var sx = b.width / a.width;
  1771. var sy = b.height / a.height;
  1772. var m = create$1();
  1773. translate(m, m, [-a.x, -a.y]);
  1774. scale$1(m, m, [sx, sy]);
  1775. translate(m, m, [b.x, b.y]);
  1776. return m;
  1777. };
  1778. BoundingRect.prototype.intersect = function (b, mtv, opt) {
  1779. return BoundingRect.intersect(this, b, mtv, opt);
  1780. };
  1781. BoundingRect.intersect = function (a, b, mtv, opt) {
  1782. if (mtv) {
  1783. Point.set(mtv, 0, 0);
  1784. }
  1785. var outIntersectRect = opt && opt.outIntersectRect || null;
  1786. var clamp = opt && opt.clamp;
  1787. if (outIntersectRect) {
  1788. outIntersectRect.x = outIntersectRect.y = outIntersectRect.width = outIntersectRect.height = NaN;
  1789. }
  1790. if (!a || !b) {
  1791. return false;
  1792. }
  1793. if (!(a instanceof BoundingRect)) {
  1794. a = BoundingRect.set(_tmpIntersectA, a.x, a.y, a.width, a.height);
  1795. }
  1796. if (!(b instanceof BoundingRect)) {
  1797. b = BoundingRect.set(_tmpIntersectB, b.x, b.y, b.width, b.height);
  1798. }
  1799. var useMTV = !!mtv;
  1800. _intersectCtx.reset(opt, useMTV);
  1801. var touchThreshold = _intersectCtx.touchThreshold;
  1802. var ax0 = a.x + touchThreshold;
  1803. var ax1 = a.x + a.width - touchThreshold;
  1804. var ay0 = a.y + touchThreshold;
  1805. var ay1 = a.y + a.height - touchThreshold;
  1806. var bx0 = b.x + touchThreshold;
  1807. var bx1 = b.x + b.width - touchThreshold;
  1808. var by0 = b.y + touchThreshold;
  1809. var by1 = b.y + b.height - touchThreshold;
  1810. if (ax0 > ax1 || ay0 > ay1 || bx0 > bx1 || by0 > by1) {
  1811. return false;
  1812. }
  1813. var overlap = !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  1814. if (useMTV || outIntersectRect) {
  1815. _lenMinMax[0] = Infinity;
  1816. _lenMinMax[1] = 0;
  1817. intersectOneDim(ax0, ax1, bx0, bx1, 0, useMTV, outIntersectRect, clamp);
  1818. intersectOneDim(ay0, ay1, by0, by1, 1, useMTV, outIntersectRect, clamp);
  1819. if (useMTV) {
  1820. Point.copy(mtv, overlap
  1821. ? (_intersectCtx.useDir ? _intersectCtx.dirMinTv : _minTv)
  1822. : _maxTv);
  1823. }
  1824. }
  1825. return overlap;
  1826. };
  1827. BoundingRect.contain = function (rect, x, y) {
  1828. return x >= rect.x
  1829. && x <= (rect.x + rect.width)
  1830. && y >= rect.y
  1831. && y <= (rect.y + rect.height);
  1832. };
  1833. BoundingRect.prototype.contain = function (x, y) {
  1834. return BoundingRect.contain(this, x, y);
  1835. };
  1836. BoundingRect.prototype.clone = function () {
  1837. return new BoundingRect(this.x, this.y, this.width, this.height);
  1838. };
  1839. BoundingRect.prototype.copy = function (other) {
  1840. BoundingRect.copy(this, other);
  1841. };
  1842. BoundingRect.prototype.plain = function () {
  1843. return {
  1844. x: this.x,
  1845. y: this.y,
  1846. width: this.width,
  1847. height: this.height
  1848. };
  1849. };
  1850. BoundingRect.prototype.isFinite = function () {
  1851. return isFinite(this.x)
  1852. && isFinite(this.y)
  1853. && isFinite(this.width)
  1854. && isFinite(this.height);
  1855. };
  1856. BoundingRect.prototype.isZero = function () {
  1857. return this.width === 0 || this.height === 0;
  1858. };
  1859. BoundingRect.create = function (rect) {
  1860. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  1861. };
  1862. BoundingRect.copy = function (target, source) {
  1863. target.x = source.x;
  1864. target.y = source.y;
  1865. target.width = source.width;
  1866. target.height = source.height;
  1867. return target;
  1868. };
  1869. BoundingRect.applyTransform = function (target, source, m) {
  1870. if (!m) {
  1871. if (target !== source) {
  1872. BoundingRect.copy(target, source);
  1873. }
  1874. return;
  1875. }
  1876. if (m[1] < 1e-5 && m[1] > -1e-5 && m[2] < 1e-5 && m[2] > -1e-5) {
  1877. var sx = m[0];
  1878. var sy = m[3];
  1879. var tx = m[4];
  1880. var ty = m[5];
  1881. target.x = source.x * sx + tx;
  1882. target.y = source.y * sy + ty;
  1883. target.width = source.width * sx;
  1884. target.height = source.height * sy;
  1885. if (target.width < 0) {
  1886. target.x += target.width;
  1887. target.width = -target.width;
  1888. }
  1889. if (target.height < 0) {
  1890. target.y += target.height;
  1891. target.height = -target.height;
  1892. }
  1893. return;
  1894. }
  1895. lt.x = lb.x = source.x;
  1896. lt.y = rt.y = source.y;
  1897. rb.x = rt.x = source.x + source.width;
  1898. rb.y = lb.y = source.y + source.height;
  1899. lt.transform(m);
  1900. rt.transform(m);
  1901. rb.transform(m);
  1902. lb.transform(m);
  1903. target.x = mathMin(lt.x, rb.x, lb.x, rt.x);
  1904. target.y = mathMin(lt.y, rb.y, lb.y, rt.y);
  1905. var maxX = mathMax(lt.x, rb.x, lb.x, rt.x);
  1906. var maxY = mathMax(lt.y, rb.y, lb.y, rt.y);
  1907. target.width = maxX - target.x;
  1908. target.height = maxY - target.y;
  1909. };
  1910. return BoundingRect;
  1911. }());
  1912. var _tmpIntersectA = new BoundingRect(0, 0, 0, 0);
  1913. var _tmpIntersectB = new BoundingRect(0, 0, 0, 0);
  1914. function intersectOneDim(a0, a1, b0, b1, updateDimIdx, useMTV, outIntersectRect, clamp) {
  1915. var d0 = mathAbs(a1 - b0);
  1916. var d1 = mathAbs(b1 - a0);
  1917. var d01min = mathMin(d0, d1);
  1918. var updateDim = XY[updateDimIdx];
  1919. var zeroDim = XY[1 - updateDimIdx];
  1920. var wh = WH[updateDimIdx];
  1921. if (a1 < b0 || b1 < a0) {
  1922. if (d0 < d1) {
  1923. if (useMTV) {
  1924. _maxTv[updateDim] = -d0;
  1925. }
  1926. if (clamp) {
  1927. outIntersectRect[updateDim] = a1;
  1928. outIntersectRect[wh] = 0;
  1929. }
  1930. }
  1931. else {
  1932. if (useMTV) {
  1933. _maxTv[updateDim] = d1;
  1934. }
  1935. if (clamp) {
  1936. outIntersectRect[updateDim] = a0;
  1937. outIntersectRect[wh] = 0;
  1938. }
  1939. }
  1940. }
  1941. else {
  1942. if (outIntersectRect) {
  1943. outIntersectRect[updateDim] = mathMax(a0, b0);
  1944. outIntersectRect[wh] = mathMin(a1, b1) - outIntersectRect[updateDim];
  1945. }
  1946. if (useMTV) {
  1947. if (d01min < _lenMinMax[0] || _intersectCtx.useDir) {
  1948. _lenMinMax[0] = mathMin(d01min, _lenMinMax[0]);
  1949. if (d0 < d1 || !_intersectCtx.bidirectional) {
  1950. _minTv[updateDim] = d0;
  1951. _minTv[zeroDim] = 0;
  1952. if (_intersectCtx.useDir) {
  1953. _intersectCtx.calcDirMTV();
  1954. }
  1955. }
  1956. if (d0 >= d1 || !_intersectCtx.bidirectional) {
  1957. _minTv[updateDim] = -d1;
  1958. _minTv[zeroDim] = 0;
  1959. if (_intersectCtx.useDir) {
  1960. _intersectCtx.calcDirMTV();
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. }
  1967. function createIntersectContext() {
  1968. var _direction = 0;
  1969. var _dirCheckVec = new Point();
  1970. var _dirTmp = new Point();
  1971. var _ctx = {
  1972. minTv: new Point(),
  1973. maxTv: new Point(),
  1974. useDir: false,
  1975. dirMinTv: new Point(),
  1976. touchThreshold: 0,
  1977. bidirectional: true,
  1978. negativeSize: false,
  1979. reset: function (opt, useMTV) {
  1980. _ctx.touchThreshold = 0;
  1981. if (opt && opt.touchThreshold != null) {
  1982. _ctx.touchThreshold = mathMax(0, opt.touchThreshold);
  1983. }
  1984. _ctx.negativeSize = false;
  1985. if (!useMTV) {
  1986. return;
  1987. }
  1988. _ctx.minTv.set(Infinity, Infinity);
  1989. _ctx.maxTv.set(0, 0);
  1990. _ctx.useDir = false;
  1991. if (opt && opt.direction != null) {
  1992. _ctx.useDir = true;
  1993. _ctx.dirMinTv.copy(_ctx.minTv);
  1994. _dirTmp.copy(_ctx.minTv);
  1995. _direction = opt.direction;
  1996. _ctx.bidirectional = opt.bidirectional == null || !!opt.bidirectional;
  1997. if (!_ctx.bidirectional) {
  1998. _dirCheckVec.set(Math.cos(_direction), Math.sin(_direction));
  1999. }
  2000. }
  2001. },
  2002. calcDirMTV: function () {
  2003. var minTv = _ctx.minTv;
  2004. var dirMinTv = _ctx.dirMinTv;
  2005. var squareMag = minTv.y * minTv.y + minTv.x * minTv.x;
  2006. var dirSin = Math.sin(_direction);
  2007. var dirCos = Math.cos(_direction);
  2008. var dotProd = dirSin * minTv.y + dirCos * minTv.x;
  2009. if (nearZero(dotProd)) {
  2010. if (nearZero(minTv.x) && nearZero(minTv.y)) {
  2011. dirMinTv.set(0, 0);
  2012. }
  2013. return;
  2014. }
  2015. _dirTmp.x = squareMag * dirCos / dotProd;
  2016. _dirTmp.y = squareMag * dirSin / dotProd;
  2017. if (nearZero(_dirTmp.x) && nearZero(_dirTmp.y)) {
  2018. dirMinTv.set(0, 0);
  2019. return;
  2020. }
  2021. if ((_ctx.bidirectional
  2022. || _dirCheckVec.dot(_dirTmp) > 0)
  2023. && _dirTmp.len() < dirMinTv.len()) {
  2024. dirMinTv.copy(_dirTmp);
  2025. }
  2026. }
  2027. };
  2028. function nearZero(val) {
  2029. return mathAbs(val) < 1e-10;
  2030. }
  2031. return _ctx;
  2032. }
  2033. var SILENT = 'silent';
  2034. function makeEventPacket(eveType, targetInfo, event) {
  2035. return {
  2036. type: eveType,
  2037. event: event,
  2038. target: targetInfo.target,
  2039. topTarget: targetInfo.topTarget,
  2040. cancelBubble: false,
  2041. offsetX: event.zrX,
  2042. offsetY: event.zrY,
  2043. gestureEvent: event.gestureEvent,
  2044. pinchX: event.pinchX,
  2045. pinchY: event.pinchY,
  2046. pinchScale: event.pinchScale,
  2047. wheelDelta: event.zrDelta,
  2048. zrByTouch: event.zrByTouch,
  2049. which: event.which,
  2050. stop: stopEvent
  2051. };
  2052. }
  2053. function stopEvent() {
  2054. stop(this.event);
  2055. }
  2056. var EmptyProxy = (function (_super) {
  2057. __extends(EmptyProxy, _super);
  2058. function EmptyProxy() {
  2059. var _this = _super !== null && _super.apply(this, arguments) || this;
  2060. _this.handler = null;
  2061. return _this;
  2062. }
  2063. EmptyProxy.prototype.dispose = function () { };
  2064. EmptyProxy.prototype.setCursor = function () { };
  2065. return EmptyProxy;
  2066. }(Eventful));
  2067. var HoveredResult = (function () {
  2068. function HoveredResult(x, y) {
  2069. this.x = x;
  2070. this.y = y;
  2071. }
  2072. return HoveredResult;
  2073. }());
  2074. var handlerNames = [
  2075. 'click', 'dblclick', 'mousewheel', 'mouseout',
  2076. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  2077. ];
  2078. var tmpRect = new BoundingRect(0, 0, 0, 0);
  2079. var Handler = (function (_super) {
  2080. __extends(Handler, _super);
  2081. function Handler(storage, painter, proxy, painterRoot, pointerSize) {
  2082. var _this = _super.call(this) || this;
  2083. _this._hovered = new HoveredResult(0, 0);
  2084. _this.storage = storage;
  2085. _this.painter = painter;
  2086. _this.painterRoot = painterRoot;
  2087. _this._pointerSize = pointerSize;
  2088. proxy = proxy || new EmptyProxy();
  2089. _this.proxy = null;
  2090. _this.setHandlerProxy(proxy);
  2091. _this._draggingMgr = new Draggable(_this);
  2092. return _this;
  2093. }
  2094. Handler.prototype.setHandlerProxy = function (proxy) {
  2095. if (this.proxy) {
  2096. this.proxy.dispose();
  2097. }
  2098. if (proxy) {
  2099. each(handlerNames, function (name) {
  2100. proxy.on && proxy.on(name, this[name], this);
  2101. }, this);
  2102. proxy.handler = this;
  2103. }
  2104. this.proxy = proxy;
  2105. };
  2106. Handler.prototype.mousemove = function (event) {
  2107. var x = event.zrX;
  2108. var y = event.zrY;
  2109. var isOutside = isOutsideBoundary(this, x, y);
  2110. var lastHovered = this._hovered;
  2111. var lastHoveredTarget = lastHovered.target;
  2112. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  2113. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  2114. lastHoveredTarget = lastHovered.target;
  2115. }
  2116. var hovered = this._hovered = isOutside ? new HoveredResult(x, y) : this.findHover(x, y);
  2117. var hoveredTarget = hovered.target;
  2118. var proxy = this.proxy;
  2119. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  2120. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2121. this.dispatchToElement(lastHovered, 'mouseout', event);
  2122. }
  2123. this.dispatchToElement(hovered, 'mousemove', event);
  2124. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2125. this.dispatchToElement(hovered, 'mouseover', event);
  2126. }
  2127. };
  2128. Handler.prototype.mouseout = function (event) {
  2129. var eventControl = event.zrEventControl;
  2130. if (eventControl !== 'only_globalout') {
  2131. this.dispatchToElement(this._hovered, 'mouseout', event);
  2132. }
  2133. if (eventControl !== 'no_globalout') {
  2134. this.trigger('globalout', { type: 'globalout', event: event });
  2135. }
  2136. };
  2137. Handler.prototype.resize = function () {
  2138. this._hovered = new HoveredResult(0, 0);
  2139. };
  2140. Handler.prototype.dispatch = function (eventName, eventArgs) {
  2141. var handler = this[eventName];
  2142. handler && handler.call(this, eventArgs);
  2143. };
  2144. Handler.prototype.dispose = function () {
  2145. this.proxy.dispose();
  2146. this.storage = null;
  2147. this.proxy = null;
  2148. this.painter = null;
  2149. };
  2150. Handler.prototype.setCursorStyle = function (cursorStyle) {
  2151. var proxy = this.proxy;
  2152. proxy.setCursor && proxy.setCursor(cursorStyle);
  2153. };
  2154. Handler.prototype.dispatchToElement = function (targetInfo, eventName, event) {
  2155. targetInfo = targetInfo || {};
  2156. var el = targetInfo.target;
  2157. if (el && el.silent) {
  2158. return;
  2159. }
  2160. var eventKey = ('on' + eventName);
  2161. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2162. while (el) {
  2163. el[eventKey]
  2164. && (eventPacket.cancelBubble = !!el[eventKey].call(el, eventPacket));
  2165. el.trigger(eventName, eventPacket);
  2166. el = el.__hostTarget ? el.__hostTarget : el.parent;
  2167. if (eventPacket.cancelBubble) {
  2168. break;
  2169. }
  2170. }
  2171. if (!eventPacket.cancelBubble) {
  2172. this.trigger(eventName, eventPacket);
  2173. if (this.painter && this.painter.eachOtherLayer) {
  2174. this.painter.eachOtherLayer(function (layer) {
  2175. if (typeof (layer[eventKey]) === 'function') {
  2176. layer[eventKey].call(layer, eventPacket);
  2177. }
  2178. if (layer.trigger) {
  2179. layer.trigger(eventName, eventPacket);
  2180. }
  2181. });
  2182. }
  2183. }
  2184. };
  2185. Handler.prototype.findHover = function (x, y, exclude) {
  2186. var list = this.storage.getDisplayList();
  2187. var out = new HoveredResult(x, y);
  2188. setHoverTarget(list, out, x, y, exclude);
  2189. if (this._pointerSize && !out.target) {
  2190. var candidates = [];
  2191. var pointerSize = this._pointerSize;
  2192. var targetSizeHalf = pointerSize / 2;
  2193. var pointerRect = new BoundingRect(x - targetSizeHalf, y - targetSizeHalf, pointerSize, pointerSize);
  2194. for (var i = list.length - 1; i >= 0; i--) {
  2195. var el = list[i];
  2196. if (el !== exclude
  2197. && !el.ignore
  2198. && !el.ignoreCoarsePointer
  2199. && (!el.parent || !el.parent.ignoreCoarsePointer)) {
  2200. tmpRect.copy(el.getBoundingRect());
  2201. if (el.transform) {
  2202. tmpRect.applyTransform(el.transform);
  2203. }
  2204. if (tmpRect.intersect(pointerRect)) {
  2205. candidates.push(el);
  2206. }
  2207. }
  2208. }
  2209. if (candidates.length) {
  2210. var rStep = 4;
  2211. var thetaStep = Math.PI / 12;
  2212. var PI2 = Math.PI * 2;
  2213. for (var r = 0; r < targetSizeHalf; r += rStep) {
  2214. for (var theta = 0; theta < PI2; theta += thetaStep) {
  2215. var x1 = x + r * Math.cos(theta);
  2216. var y1 = y + r * Math.sin(theta);
  2217. setHoverTarget(candidates, out, x1, y1, exclude);
  2218. if (out.target) {
  2219. return out;
  2220. }
  2221. }
  2222. }
  2223. }
  2224. }
  2225. return out;
  2226. };
  2227. Handler.prototype.processGesture = function (event, stage) {
  2228. if (!this._gestureMgr) {
  2229. this._gestureMgr = new GestureMgr();
  2230. }
  2231. var gestureMgr = this._gestureMgr;
  2232. stage === 'start' && gestureMgr.clear();
  2233. var gestureInfo = gestureMgr.recognize(event, this.findHover(event.zrX, event.zrY, null).target, this.proxy.dom);
  2234. stage === 'end' && gestureMgr.clear();
  2235. if (gestureInfo) {
  2236. var type = gestureInfo.type;
  2237. event.gestureEvent = type;
  2238. var res = new HoveredResult();
  2239. res.target = gestureInfo.target;
  2240. this.dispatchToElement(res, type, gestureInfo.event);
  2241. }
  2242. };
  2243. return Handler;
  2244. }(Eventful));
  2245. each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2246. Handler.prototype[name] = function (event) {
  2247. var x = event.zrX;
  2248. var y = event.zrY;
  2249. var isOutside = isOutsideBoundary(this, x, y);
  2250. var hovered;
  2251. var hoveredTarget;
  2252. if (name !== 'mouseup' || !isOutside) {
  2253. hovered = this.findHover(x, y);
  2254. hoveredTarget = hovered.target;
  2255. }
  2256. if (name === 'mousedown') {
  2257. this._downEl = hoveredTarget;
  2258. this._downPoint = [event.zrX, event.zrY];
  2259. this._upEl = hoveredTarget;
  2260. }
  2261. else if (name === 'mouseup') {
  2262. this._upEl = hoveredTarget;
  2263. }
  2264. else if (name === 'click') {
  2265. if (this._downEl !== this._upEl
  2266. || !this._downPoint
  2267. || dist(this._downPoint, [event.zrX, event.zrY]) > 4) {
  2268. return;
  2269. }
  2270. this._downPoint = null;
  2271. }
  2272. this.dispatchToElement(hovered, name, event);
  2273. };
  2274. });
  2275. function isHover(displayable, x, y) {
  2276. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2277. var el = displayable;
  2278. var isSilent = void 0;
  2279. var ignoreClip = false;
  2280. while (el) {
  2281. if (el.ignoreClip) {
  2282. ignoreClip = true;
  2283. }
  2284. if (!ignoreClip) {
  2285. var clipPath = el.getClipPath();
  2286. if (clipPath && !clipPath.contain(x, y)) {
  2287. return false;
  2288. }
  2289. }
  2290. if (el.silent) {
  2291. isSilent = true;
  2292. }
  2293. var hostEl = el.__hostTarget;
  2294. el = hostEl ? (el.ignoreHostSilent ? null : hostEl) : el.parent;
  2295. }
  2296. return isSilent ? SILENT : true;
  2297. }
  2298. return false;
  2299. }
  2300. function setHoverTarget(list, out, x, y, exclude) {
  2301. for (var i = list.length - 1; i >= 0; i--) {
  2302. var el = list[i];
  2303. var hoverCheckResult = void 0;
  2304. if (el !== exclude
  2305. && !el.ignore
  2306. && (hoverCheckResult = isHover(el, x, y))) {
  2307. !out.topTarget && (out.topTarget = el);
  2308. if (hoverCheckResult !== SILENT) {
  2309. out.target = el;
  2310. break;
  2311. }
  2312. }
  2313. }
  2314. }
  2315. function isOutsideBoundary(handlerInstance, x, y) {
  2316. var painter = handlerInstance.painter;
  2317. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  2318. }
  2319. var DEFAULT_MIN_MERGE = 32;
  2320. var DEFAULT_MIN_GALLOPING = 7;
  2321. function minRunLength(n) {
  2322. var r = 0;
  2323. while (n >= DEFAULT_MIN_MERGE) {
  2324. r |= n & 1;
  2325. n >>= 1;
  2326. }
  2327. return n + r;
  2328. }
  2329. function makeAscendingRun(array, lo, hi, compare) {
  2330. var runHi = lo + 1;
  2331. if (runHi === hi) {
  2332. return 1;
  2333. }
  2334. if (compare(array[runHi++], array[lo]) < 0) {
  2335. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  2336. runHi++;
  2337. }
  2338. reverseRun(array, lo, runHi);
  2339. }
  2340. else {
  2341. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  2342. runHi++;
  2343. }
  2344. }
  2345. return runHi - lo;
  2346. }
  2347. function reverseRun(array, lo, hi) {
  2348. hi--;
  2349. while (lo < hi) {
  2350. var t = array[lo];
  2351. array[lo++] = array[hi];
  2352. array[hi--] = t;
  2353. }
  2354. }
  2355. function binaryInsertionSort(array, lo, hi, start, compare) {
  2356. if (start === lo) {
  2357. start++;
  2358. }
  2359. for (; start < hi; start++) {
  2360. var pivot = array[start];
  2361. var left = lo;
  2362. var right = start;
  2363. var mid;
  2364. while (left < right) {
  2365. mid = left + right >>> 1;
  2366. if (compare(pivot, array[mid]) < 0) {
  2367. right = mid;
  2368. }
  2369. else {
  2370. left = mid + 1;
  2371. }
  2372. }
  2373. var n = start - left;
  2374. switch (n) {
  2375. case 3:
  2376. array[left + 3] = array[left + 2];
  2377. case 2:
  2378. array[left + 2] = array[left + 1];
  2379. case 1:
  2380. array[left + 1] = array[left];
  2381. break;
  2382. default:
  2383. while (n > 0) {
  2384. array[left + n] = array[left + n - 1];
  2385. n--;
  2386. }
  2387. }
  2388. array[left] = pivot;
  2389. }
  2390. }
  2391. function gallopLeft(value, array, start, length, hint, compare) {
  2392. var lastOffset = 0;
  2393. var maxOffset = 0;
  2394. var offset = 1;
  2395. if (compare(value, array[start + hint]) > 0) {
  2396. maxOffset = length - hint;
  2397. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  2398. lastOffset = offset;
  2399. offset = (offset << 1) + 1;
  2400. if (offset <= 0) {
  2401. offset = maxOffset;
  2402. }
  2403. }
  2404. if (offset > maxOffset) {
  2405. offset = maxOffset;
  2406. }
  2407. lastOffset += hint;
  2408. offset += hint;
  2409. }
  2410. else {
  2411. maxOffset = hint + 1;
  2412. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  2413. lastOffset = offset;
  2414. offset = (offset << 1) + 1;
  2415. if (offset <= 0) {
  2416. offset = maxOffset;
  2417. }
  2418. }
  2419. if (offset > maxOffset) {
  2420. offset = maxOffset;
  2421. }
  2422. var tmp = lastOffset;
  2423. lastOffset = hint - offset;
  2424. offset = hint - tmp;
  2425. }
  2426. lastOffset++;
  2427. while (lastOffset < offset) {
  2428. var m = lastOffset + (offset - lastOffset >>> 1);
  2429. if (compare(value, array[start + m]) > 0) {
  2430. lastOffset = m + 1;
  2431. }
  2432. else {
  2433. offset = m;
  2434. }
  2435. }
  2436. return offset;
  2437. }
  2438. function gallopRight(value, array, start, length, hint, compare) {
  2439. var lastOffset = 0;
  2440. var maxOffset = 0;
  2441. var offset = 1;
  2442. if (compare(value, array[start + hint]) < 0) {
  2443. maxOffset = hint + 1;
  2444. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  2445. lastOffset = offset;
  2446. offset = (offset << 1) + 1;
  2447. if (offset <= 0) {
  2448. offset = maxOffset;
  2449. }
  2450. }
  2451. if (offset > maxOffset) {
  2452. offset = maxOffset;
  2453. }
  2454. var tmp = lastOffset;
  2455. lastOffset = hint - offset;
  2456. offset = hint - tmp;
  2457. }
  2458. else {
  2459. maxOffset = length - hint;
  2460. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  2461. lastOffset = offset;
  2462. offset = (offset << 1) + 1;
  2463. if (offset <= 0) {
  2464. offset = maxOffset;
  2465. }
  2466. }
  2467. if (offset > maxOffset) {
  2468. offset = maxOffset;
  2469. }
  2470. lastOffset += hint;
  2471. offset += hint;
  2472. }
  2473. lastOffset++;
  2474. while (lastOffset < offset) {
  2475. var m = lastOffset + (offset - lastOffset >>> 1);
  2476. if (compare(value, array[start + m]) < 0) {
  2477. offset = m;
  2478. }
  2479. else {
  2480. lastOffset = m + 1;
  2481. }
  2482. }
  2483. return offset;
  2484. }
  2485. function TimSort(array, compare) {
  2486. var minGallop = DEFAULT_MIN_GALLOPING;
  2487. var runStart;
  2488. var runLength;
  2489. var stackSize = 0;
  2490. var tmp = [];
  2491. runStart = [];
  2492. runLength = [];
  2493. function pushRun(_runStart, _runLength) {
  2494. runStart[stackSize] = _runStart;
  2495. runLength[stackSize] = _runLength;
  2496. stackSize += 1;
  2497. }
  2498. function mergeRuns() {
  2499. while (stackSize > 1) {
  2500. var n = stackSize - 2;
  2501. if ((n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1])
  2502. || (n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1])) {
  2503. if (runLength[n - 1] < runLength[n + 1]) {
  2504. n--;
  2505. }
  2506. }
  2507. else if (runLength[n] > runLength[n + 1]) {
  2508. break;
  2509. }
  2510. mergeAt(n);
  2511. }
  2512. }
  2513. function forceMergeRuns() {
  2514. while (stackSize > 1) {
  2515. var n = stackSize - 2;
  2516. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  2517. n--;
  2518. }
  2519. mergeAt(n);
  2520. }
  2521. }
  2522. function mergeAt(i) {
  2523. var start1 = runStart[i];
  2524. var length1 = runLength[i];
  2525. var start2 = runStart[i + 1];
  2526. var length2 = runLength[i + 1];
  2527. runLength[i] = length1 + length2;
  2528. if (i === stackSize - 3) {
  2529. runStart[i + 1] = runStart[i + 2];
  2530. runLength[i + 1] = runLength[i + 2];
  2531. }
  2532. stackSize--;
  2533. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  2534. start1 += k;
  2535. length1 -= k;
  2536. if (length1 === 0) {
  2537. return;
  2538. }
  2539. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  2540. if (length2 === 0) {
  2541. return;
  2542. }
  2543. if (length1 <= length2) {
  2544. mergeLow(start1, length1, start2, length2);
  2545. }
  2546. else {
  2547. mergeHigh(start1, length1, start2, length2);
  2548. }
  2549. }
  2550. function mergeLow(start1, length1, start2, length2) {
  2551. var i = 0;
  2552. for (i = 0; i < length1; i++) {
  2553. tmp[i] = array[start1 + i];
  2554. }
  2555. var cursor1 = 0;
  2556. var cursor2 = start2;
  2557. var dest = start1;
  2558. array[dest++] = array[cursor2++];
  2559. if (--length2 === 0) {
  2560. for (i = 0; i < length1; i++) {
  2561. array[dest + i] = tmp[cursor1 + i];
  2562. }
  2563. return;
  2564. }
  2565. if (length1 === 1) {
  2566. for (i = 0; i < length2; i++) {
  2567. array[dest + i] = array[cursor2 + i];
  2568. }
  2569. array[dest + length2] = tmp[cursor1];
  2570. return;
  2571. }
  2572. var _minGallop = minGallop;
  2573. var count1;
  2574. var count2;
  2575. var exit;
  2576. while (1) {
  2577. count1 = 0;
  2578. count2 = 0;
  2579. exit = false;
  2580. do {
  2581. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  2582. array[dest++] = array[cursor2++];
  2583. count2++;
  2584. count1 = 0;
  2585. if (--length2 === 0) {
  2586. exit = true;
  2587. break;
  2588. }
  2589. }
  2590. else {
  2591. array[dest++] = tmp[cursor1++];
  2592. count1++;
  2593. count2 = 0;
  2594. if (--length1 === 1) {
  2595. exit = true;
  2596. break;
  2597. }
  2598. }
  2599. } while ((count1 | count2) < _minGallop);
  2600. if (exit) {
  2601. break;
  2602. }
  2603. do {
  2604. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  2605. if (count1 !== 0) {
  2606. for (i = 0; i < count1; i++) {
  2607. array[dest + i] = tmp[cursor1 + i];
  2608. }
  2609. dest += count1;
  2610. cursor1 += count1;
  2611. length1 -= count1;
  2612. if (length1 <= 1) {
  2613. exit = true;
  2614. break;
  2615. }
  2616. }
  2617. array[dest++] = array[cursor2++];
  2618. if (--length2 === 0) {
  2619. exit = true;
  2620. break;
  2621. }
  2622. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  2623. if (count2 !== 0) {
  2624. for (i = 0; i < count2; i++) {
  2625. array[dest + i] = array[cursor2 + i];
  2626. }
  2627. dest += count2;
  2628. cursor2 += count2;
  2629. length2 -= count2;
  2630. if (length2 === 0) {
  2631. exit = true;
  2632. break;
  2633. }
  2634. }
  2635. array[dest++] = tmp[cursor1++];
  2636. if (--length1 === 1) {
  2637. exit = true;
  2638. break;
  2639. }
  2640. _minGallop--;
  2641. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2642. if (exit) {
  2643. break;
  2644. }
  2645. if (_minGallop < 0) {
  2646. _minGallop = 0;
  2647. }
  2648. _minGallop += 2;
  2649. }
  2650. minGallop = _minGallop;
  2651. minGallop < 1 && (minGallop = 1);
  2652. if (length1 === 1) {
  2653. for (i = 0; i < length2; i++) {
  2654. array[dest + i] = array[cursor2 + i];
  2655. }
  2656. array[dest + length2] = tmp[cursor1];
  2657. }
  2658. else if (length1 === 0) {
  2659. throw new Error();
  2660. }
  2661. else {
  2662. for (i = 0; i < length1; i++) {
  2663. array[dest + i] = tmp[cursor1 + i];
  2664. }
  2665. }
  2666. }
  2667. function mergeHigh(start1, length1, start2, length2) {
  2668. var i = 0;
  2669. for (i = 0; i < length2; i++) {
  2670. tmp[i] = array[start2 + i];
  2671. }
  2672. var cursor1 = start1 + length1 - 1;
  2673. var cursor2 = length2 - 1;
  2674. var dest = start2 + length2 - 1;
  2675. var customCursor = 0;
  2676. var customDest = 0;
  2677. array[dest--] = array[cursor1--];
  2678. if (--length1 === 0) {
  2679. customCursor = dest - (length2 - 1);
  2680. for (i = 0; i < length2; i++) {
  2681. array[customCursor + i] = tmp[i];
  2682. }
  2683. return;
  2684. }
  2685. if (length2 === 1) {
  2686. dest -= length1;
  2687. cursor1 -= length1;
  2688. customDest = dest + 1;
  2689. customCursor = cursor1 + 1;
  2690. for (i = length1 - 1; i >= 0; i--) {
  2691. array[customDest + i] = array[customCursor + i];
  2692. }
  2693. array[dest] = tmp[cursor2];
  2694. return;
  2695. }
  2696. var _minGallop = minGallop;
  2697. while (true) {
  2698. var count1 = 0;
  2699. var count2 = 0;
  2700. var exit = false;
  2701. do {
  2702. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  2703. array[dest--] = array[cursor1--];
  2704. count1++;
  2705. count2 = 0;
  2706. if (--length1 === 0) {
  2707. exit = true;
  2708. break;
  2709. }
  2710. }
  2711. else {
  2712. array[dest--] = tmp[cursor2--];
  2713. count2++;
  2714. count1 = 0;
  2715. if (--length2 === 1) {
  2716. exit = true;
  2717. break;
  2718. }
  2719. }
  2720. } while ((count1 | count2) < _minGallop);
  2721. if (exit) {
  2722. break;
  2723. }
  2724. do {
  2725. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  2726. if (count1 !== 0) {
  2727. dest -= count1;
  2728. cursor1 -= count1;
  2729. length1 -= count1;
  2730. customDest = dest + 1;
  2731. customCursor = cursor1 + 1;
  2732. for (i = count1 - 1; i >= 0; i--) {
  2733. array[customDest + i] = array[customCursor + i];
  2734. }
  2735. if (length1 === 0) {
  2736. exit = true;
  2737. break;
  2738. }
  2739. }
  2740. array[dest--] = tmp[cursor2--];
  2741. if (--length2 === 1) {
  2742. exit = true;
  2743. break;
  2744. }
  2745. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  2746. if (count2 !== 0) {
  2747. dest -= count2;
  2748. cursor2 -= count2;
  2749. length2 -= count2;
  2750. customDest = dest + 1;
  2751. customCursor = cursor2 + 1;
  2752. for (i = 0; i < count2; i++) {
  2753. array[customDest + i] = tmp[customCursor + i];
  2754. }
  2755. if (length2 <= 1) {
  2756. exit = true;
  2757. break;
  2758. }
  2759. }
  2760. array[dest--] = array[cursor1--];
  2761. if (--length1 === 0) {
  2762. exit = true;
  2763. break;
  2764. }
  2765. _minGallop--;
  2766. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2767. if (exit) {
  2768. break;
  2769. }
  2770. if (_minGallop < 0) {
  2771. _minGallop = 0;
  2772. }
  2773. _minGallop += 2;
  2774. }
  2775. minGallop = _minGallop;
  2776. if (minGallop < 1) {
  2777. minGallop = 1;
  2778. }
  2779. if (length2 === 1) {
  2780. dest -= length1;
  2781. cursor1 -= length1;
  2782. customDest = dest + 1;
  2783. customCursor = cursor1 + 1;
  2784. for (i = length1 - 1; i >= 0; i--) {
  2785. array[customDest + i] = array[customCursor + i];
  2786. }
  2787. array[dest] = tmp[cursor2];
  2788. }
  2789. else if (length2 === 0) {
  2790. throw new Error();
  2791. }
  2792. else {
  2793. customCursor = dest - (length2 - 1);
  2794. for (i = 0; i < length2; i++) {
  2795. array[customCursor + i] = tmp[i];
  2796. }
  2797. }
  2798. }
  2799. return {
  2800. mergeRuns: mergeRuns,
  2801. forceMergeRuns: forceMergeRuns,
  2802. pushRun: pushRun
  2803. };
  2804. }
  2805. function sort(array, compare, lo, hi) {
  2806. if (!lo) {
  2807. lo = 0;
  2808. }
  2809. if (!hi) {
  2810. hi = array.length;
  2811. }
  2812. var remaining = hi - lo;
  2813. if (remaining < 2) {
  2814. return;
  2815. }
  2816. var runLength = 0;
  2817. if (remaining < DEFAULT_MIN_MERGE) {
  2818. runLength = makeAscendingRun(array, lo, hi, compare);
  2819. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  2820. return;
  2821. }
  2822. var ts = TimSort(array, compare);
  2823. var minRun = minRunLength(remaining);
  2824. do {
  2825. runLength = makeAscendingRun(array, lo, hi, compare);
  2826. if (runLength < minRun) {
  2827. var force = remaining;
  2828. if (force > minRun) {
  2829. force = minRun;
  2830. }
  2831. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  2832. runLength = force;
  2833. }
  2834. ts.pushRun(lo, runLength);
  2835. ts.mergeRuns();
  2836. remaining -= runLength;
  2837. lo += runLength;
  2838. } while (remaining !== 0);
  2839. ts.forceMergeRuns();
  2840. }
  2841. var REDRAW_BIT = 1;
  2842. var STYLE_CHANGED_BIT = 2;
  2843. var SHAPE_CHANGED_BIT = 4;
  2844. var invalidZErrorLogged = false;
  2845. function logInvalidZError() {
  2846. if (invalidZErrorLogged) {
  2847. return;
  2848. }
  2849. invalidZErrorLogged = true;
  2850. console.warn('z / z2 / zlevel of displayable is invalid, which may cause unexpected errors');
  2851. }
  2852. function shapeCompareFunc(a, b) {
  2853. if (a.zlevel === b.zlevel) {
  2854. if (a.z === b.z) {
  2855. return a.z2 - b.z2;
  2856. }
  2857. return a.z - b.z;
  2858. }
  2859. return a.zlevel - b.zlevel;
  2860. }
  2861. var Storage = (function () {
  2862. function Storage() {
  2863. this._roots = [];
  2864. this._displayList = [];
  2865. this._displayListLen = 0;
  2866. this.displayableSortFunc = shapeCompareFunc;
  2867. }
  2868. Storage.prototype.traverse = function (cb, context) {
  2869. for (var i = 0; i < this._roots.length; i++) {
  2870. this._roots[i].traverse(cb, context);
  2871. }
  2872. };
  2873. Storage.prototype.getDisplayList = function (update, includeIgnore) {
  2874. includeIgnore = includeIgnore || false;
  2875. var displayList = this._displayList;
  2876. if (update || !displayList.length) {
  2877. this.updateDisplayList(includeIgnore);
  2878. }
  2879. return displayList;
  2880. };
  2881. Storage.prototype.updateDisplayList = function (includeIgnore) {
  2882. this._displayListLen = 0;
  2883. var roots = this._roots;
  2884. var displayList = this._displayList;
  2885. for (var i = 0, len = roots.length; i < len; i++) {
  2886. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  2887. }
  2888. displayList.length = this._displayListLen;
  2889. sort(displayList, shapeCompareFunc);
  2890. };
  2891. Storage.prototype._updateAndAddDisplayable = function (el, parentClipPaths, includeIgnore) {
  2892. if (el.ignore && !includeIgnore) {
  2893. return;
  2894. }
  2895. el.beforeUpdate();
  2896. el.update();
  2897. el.afterUpdate();
  2898. var userSetClipPath = el.getClipPath();
  2899. var parentHasClipPaths = parentClipPaths && parentClipPaths.length;
  2900. var clipPathIdx = 0;
  2901. var thisClipPaths = el.__clipPaths;
  2902. if (!el.ignoreClip
  2903. && (parentHasClipPaths || userSetClipPath)) {
  2904. if (!thisClipPaths) {
  2905. thisClipPaths = el.__clipPaths = [];
  2906. }
  2907. if (parentHasClipPaths) {
  2908. for (var idx = 0; idx < parentClipPaths.length; idx++) {
  2909. thisClipPaths[clipPathIdx++] = parentClipPaths[idx];
  2910. }
  2911. }
  2912. var currentClipPath = userSetClipPath;
  2913. var parentClipPath = el;
  2914. while (currentClipPath) {
  2915. currentClipPath.parent = parentClipPath;
  2916. currentClipPath.updateTransform();
  2917. thisClipPaths[clipPathIdx++] = currentClipPath;
  2918. parentClipPath = currentClipPath;
  2919. currentClipPath = currentClipPath.getClipPath();
  2920. }
  2921. }
  2922. if (thisClipPaths) {
  2923. thisClipPaths.length = clipPathIdx;
  2924. }
  2925. if (el.childrenRef) {
  2926. var children = el.childrenRef();
  2927. for (var i = 0; i < children.length; i++) {
  2928. var child = children[i];
  2929. if (el.__dirty) {
  2930. child.__dirty |= REDRAW_BIT;
  2931. }
  2932. this._updateAndAddDisplayable(child, thisClipPaths, includeIgnore);
  2933. }
  2934. el.__dirty = 0;
  2935. }
  2936. else {
  2937. var disp = el;
  2938. if (isNaN(disp.z)) {
  2939. logInvalidZError();
  2940. disp.z = 0;
  2941. }
  2942. if (isNaN(disp.z2)) {
  2943. logInvalidZError();
  2944. disp.z2 = 0;
  2945. }
  2946. if (isNaN(disp.zlevel)) {
  2947. logInvalidZError();
  2948. disp.zlevel = 0;
  2949. }
  2950. this._displayList[this._displayListLen++] = disp;
  2951. }
  2952. var decalEl = el.getDecalElement && el.getDecalElement();
  2953. if (decalEl) {
  2954. this._updateAndAddDisplayable(decalEl, thisClipPaths, includeIgnore);
  2955. }
  2956. var textGuide = el.getTextGuideLine();
  2957. if (textGuide) {
  2958. this._updateAndAddDisplayable(textGuide, thisClipPaths, includeIgnore);
  2959. }
  2960. var textEl = el.getTextContent();
  2961. if (textEl) {
  2962. this._updateAndAddDisplayable(textEl, thisClipPaths, includeIgnore);
  2963. }
  2964. };
  2965. Storage.prototype.addRoot = function (el) {
  2966. if (el.__zr && el.__zr.storage === this) {
  2967. return;
  2968. }
  2969. this._roots.push(el);
  2970. };
  2971. Storage.prototype.delRoot = function (el) {
  2972. if (el instanceof Array) {
  2973. for (var i = 0, l = el.length; i < l; i++) {
  2974. this.delRoot(el[i]);
  2975. }
  2976. return;
  2977. }
  2978. var idx = indexOf(this._roots, el);
  2979. if (idx >= 0) {
  2980. this._roots.splice(idx, 1);
  2981. }
  2982. };
  2983. Storage.prototype.delAllRoots = function () {
  2984. this._roots = [];
  2985. this._displayList = [];
  2986. this._displayListLen = 0;
  2987. return;
  2988. };
  2989. Storage.prototype.getRoots = function () {
  2990. return this._roots;
  2991. };
  2992. Storage.prototype.dispose = function () {
  2993. this._displayList = null;
  2994. this._roots = null;
  2995. };
  2996. return Storage;
  2997. }());
  2998. var requestAnimationFrame;
  2999. requestAnimationFrame = (env.hasGlobalWindow
  3000. && ((window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  3001. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  3002. || window.mozRequestAnimationFrame
  3003. || window.webkitRequestAnimationFrame)) || function (func) {
  3004. return setTimeout(func, 16);
  3005. };
  3006. var requestAnimationFrame$1 = requestAnimationFrame;
  3007. var easingFuncs = {
  3008. linear: function (k) {
  3009. return k;
  3010. },
  3011. quadraticIn: function (k) {
  3012. return k * k;
  3013. },
  3014. quadraticOut: function (k) {
  3015. return k * (2 - k);
  3016. },
  3017. quadraticInOut: function (k) {
  3018. if ((k *= 2) < 1) {
  3019. return 0.5 * k * k;
  3020. }
  3021. return -0.5 * (--k * (k - 2) - 1);
  3022. },
  3023. cubicIn: function (k) {
  3024. return k * k * k;
  3025. },
  3026. cubicOut: function (k) {
  3027. return --k * k * k + 1;
  3028. },
  3029. cubicInOut: function (k) {
  3030. if ((k *= 2) < 1) {
  3031. return 0.5 * k * k * k;
  3032. }
  3033. return 0.5 * ((k -= 2) * k * k + 2);
  3034. },
  3035. quarticIn: function (k) {
  3036. return k * k * k * k;
  3037. },
  3038. quarticOut: function (k) {
  3039. return 1 - (--k * k * k * k);
  3040. },
  3041. quarticInOut: function (k) {
  3042. if ((k *= 2) < 1) {
  3043. return 0.5 * k * k * k * k;
  3044. }
  3045. return -0.5 * ((k -= 2) * k * k * k - 2);
  3046. },
  3047. quinticIn: function (k) {
  3048. return k * k * k * k * k;
  3049. },
  3050. quinticOut: function (k) {
  3051. return --k * k * k * k * k + 1;
  3052. },
  3053. quinticInOut: function (k) {
  3054. if ((k *= 2) < 1) {
  3055. return 0.5 * k * k * k * k * k;
  3056. }
  3057. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  3058. },
  3059. sinusoidalIn: function (k) {
  3060. return 1 - Math.cos(k * Math.PI / 2);
  3061. },
  3062. sinusoidalOut: function (k) {
  3063. return Math.sin(k * Math.PI / 2);
  3064. },
  3065. sinusoidalInOut: function (k) {
  3066. return 0.5 * (1 - Math.cos(Math.PI * k));
  3067. },
  3068. exponentialIn: function (k) {
  3069. return k === 0 ? 0 : Math.pow(1024, k - 1);
  3070. },
  3071. exponentialOut: function (k) {
  3072. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  3073. },
  3074. exponentialInOut: function (k) {
  3075. if (k === 0) {
  3076. return 0;
  3077. }
  3078. if (k === 1) {
  3079. return 1;
  3080. }
  3081. if ((k *= 2) < 1) {
  3082. return 0.5 * Math.pow(1024, k - 1);
  3083. }
  3084. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  3085. },
  3086. circularIn: function (k) {
  3087. return 1 - Math.sqrt(1 - k * k);
  3088. },
  3089. circularOut: function (k) {
  3090. return Math.sqrt(1 - (--k * k));
  3091. },
  3092. circularInOut: function (k) {
  3093. if ((k *= 2) < 1) {
  3094. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  3095. }
  3096. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  3097. },
  3098. elasticIn: function (k) {
  3099. var s;
  3100. var a = 0.1;
  3101. var p = 0.4;
  3102. if (k === 0) {
  3103. return 0;
  3104. }
  3105. if (k === 1) {
  3106. return 1;
  3107. }
  3108. if (!a || a < 1) {
  3109. a = 1;
  3110. s = p / 4;
  3111. }
  3112. else {
  3113. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3114. }
  3115. return -(a * Math.pow(2, 10 * (k -= 1))
  3116. * Math.sin((k - s) * (2 * Math.PI) / p));
  3117. },
  3118. elasticOut: function (k) {
  3119. var s;
  3120. var a = 0.1;
  3121. var p = 0.4;
  3122. if (k === 0) {
  3123. return 0;
  3124. }
  3125. if (k === 1) {
  3126. return 1;
  3127. }
  3128. if (!a || a < 1) {
  3129. a = 1;
  3130. s = p / 4;
  3131. }
  3132. else {
  3133. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3134. }
  3135. return (a * Math.pow(2, -10 * k)
  3136. * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  3137. },
  3138. elasticInOut: function (k) {
  3139. var s;
  3140. var a = 0.1;
  3141. var p = 0.4;
  3142. if (k === 0) {
  3143. return 0;
  3144. }
  3145. if (k === 1) {
  3146. return 1;
  3147. }
  3148. if (!a || a < 1) {
  3149. a = 1;
  3150. s = p / 4;
  3151. }
  3152. else {
  3153. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3154. }
  3155. if ((k *= 2) < 1) {
  3156. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  3157. * Math.sin((k - s) * (2 * Math.PI) / p));
  3158. }
  3159. return a * Math.pow(2, -10 * (k -= 1))
  3160. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  3161. },
  3162. backIn: function (k) {
  3163. var s = 1.70158;
  3164. return k * k * ((s + 1) * k - s);
  3165. },
  3166. backOut: function (k) {
  3167. var s = 1.70158;
  3168. return --k * k * ((s + 1) * k + s) + 1;
  3169. },
  3170. backInOut: function (k) {
  3171. var s = 1.70158 * 1.525;
  3172. if ((k *= 2) < 1) {
  3173. return 0.5 * (k * k * ((s + 1) * k - s));
  3174. }
  3175. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  3176. },
  3177. bounceIn: function (k) {
  3178. return 1 - easingFuncs.bounceOut(1 - k);
  3179. },
  3180. bounceOut: function (k) {
  3181. if (k < (1 / 2.75)) {
  3182. return 7.5625 * k * k;
  3183. }
  3184. else if (k < (2 / 2.75)) {
  3185. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  3186. }
  3187. else if (k < (2.5 / 2.75)) {
  3188. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  3189. }
  3190. else {
  3191. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  3192. }
  3193. },
  3194. bounceInOut: function (k) {
  3195. if (k < 0.5) {
  3196. return easingFuncs.bounceIn(k * 2) * 0.5;
  3197. }
  3198. return easingFuncs.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  3199. }
  3200. };
  3201. var mathPow = Math.pow;
  3202. var mathSqrt = Math.sqrt;
  3203. var EPSILON$1 = 1e-8;
  3204. var EPSILON_NUMERIC = 1e-4;
  3205. var THREE_SQRT = mathSqrt(3);
  3206. var ONE_THIRD = 1 / 3;
  3207. var _v0 = create();
  3208. var _v1 = create();
  3209. var _v2 = create();
  3210. function isAroundZero(val) {
  3211. return val > -EPSILON$1 && val < EPSILON$1;
  3212. }
  3213. function isNotAroundZero(val) {
  3214. return val > EPSILON$1 || val < -EPSILON$1;
  3215. }
  3216. function cubicAt(p0, p1, p2, p3, t) {
  3217. var onet = 1 - t;
  3218. return onet * onet * (onet * p0 + 3 * t * p1)
  3219. + t * t * (t * p3 + 3 * onet * p2);
  3220. }
  3221. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  3222. var onet = 1 - t;
  3223. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  3224. + (p3 - p2) * t * t);
  3225. }
  3226. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  3227. var a = p3 + 3 * (p1 - p2) - p0;
  3228. var b = 3 * (p2 - p1 * 2 + p0);
  3229. var c = 3 * (p1 - p0);
  3230. var d = p0 - val;
  3231. var A = b * b - 3 * a * c;
  3232. var B = b * c - 9 * a * d;
  3233. var C = c * c - 3 * b * d;
  3234. var n = 0;
  3235. if (isAroundZero(A) && isAroundZero(B)) {
  3236. if (isAroundZero(b)) {
  3237. roots[0] = 0;
  3238. }
  3239. else {
  3240. var t1 = -c / b;
  3241. if (t1 >= 0 && t1 <= 1) {
  3242. roots[n++] = t1;
  3243. }
  3244. }
  3245. }
  3246. else {
  3247. var disc = B * B - 4 * A * C;
  3248. if (isAroundZero(disc)) {
  3249. var K = B / A;
  3250. var t1 = -b / a + K;
  3251. var t2 = -K / 2;
  3252. if (t1 >= 0 && t1 <= 1) {
  3253. roots[n++] = t1;
  3254. }
  3255. if (t2 >= 0 && t2 <= 1) {
  3256. roots[n++] = t2;
  3257. }
  3258. }
  3259. else if (disc > 0) {
  3260. var discSqrt = mathSqrt(disc);
  3261. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  3262. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  3263. if (Y1 < 0) {
  3264. Y1 = -mathPow(-Y1, ONE_THIRD);
  3265. }
  3266. else {
  3267. Y1 = mathPow(Y1, ONE_THIRD);
  3268. }
  3269. if (Y2 < 0) {
  3270. Y2 = -mathPow(-Y2, ONE_THIRD);
  3271. }
  3272. else {
  3273. Y2 = mathPow(Y2, ONE_THIRD);
  3274. }
  3275. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  3276. if (t1 >= 0 && t1 <= 1) {
  3277. roots[n++] = t1;
  3278. }
  3279. }
  3280. else {
  3281. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  3282. var theta = Math.acos(T) / 3;
  3283. var ASqrt = mathSqrt(A);
  3284. var tmp = Math.cos(theta);
  3285. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  3286. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  3287. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  3288. if (t1 >= 0 && t1 <= 1) {
  3289. roots[n++] = t1;
  3290. }
  3291. if (t2 >= 0 && t2 <= 1) {
  3292. roots[n++] = t2;
  3293. }
  3294. if (t3 >= 0 && t3 <= 1) {
  3295. roots[n++] = t3;
  3296. }
  3297. }
  3298. }
  3299. return n;
  3300. }
  3301. function cubicExtrema(p0, p1, p2, p3, extrema) {
  3302. var b = 6 * p2 - 12 * p1 + 6 * p0;
  3303. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  3304. var c = 3 * p1 - 3 * p0;
  3305. var n = 0;
  3306. if (isAroundZero(a)) {
  3307. if (isNotAroundZero(b)) {
  3308. var t1 = -c / b;
  3309. if (t1 >= 0 && t1 <= 1) {
  3310. extrema[n++] = t1;
  3311. }
  3312. }
  3313. }
  3314. else {
  3315. var disc = b * b - 4 * a * c;
  3316. if (isAroundZero(disc)) {
  3317. extrema[0] = -b / (2 * a);
  3318. }
  3319. else if (disc > 0) {
  3320. var discSqrt = mathSqrt(disc);
  3321. var t1 = (-b + discSqrt) / (2 * a);
  3322. var t2 = (-b - discSqrt) / (2 * a);
  3323. if (t1 >= 0 && t1 <= 1) {
  3324. extrema[n++] = t1;
  3325. }
  3326. if (t2 >= 0 && t2 <= 1) {
  3327. extrema[n++] = t2;
  3328. }
  3329. }
  3330. }
  3331. return n;
  3332. }
  3333. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  3334. var p01 = (p1 - p0) * t + p0;
  3335. var p12 = (p2 - p1) * t + p1;
  3336. var p23 = (p3 - p2) * t + p2;
  3337. var p012 = (p12 - p01) * t + p01;
  3338. var p123 = (p23 - p12) * t + p12;
  3339. var p0123 = (p123 - p012) * t + p012;
  3340. out[0] = p0;
  3341. out[1] = p01;
  3342. out[2] = p012;
  3343. out[3] = p0123;
  3344. out[4] = p0123;
  3345. out[5] = p123;
  3346. out[6] = p23;
  3347. out[7] = p3;
  3348. }
  3349. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  3350. var t;
  3351. var interval = 0.005;
  3352. var d = Infinity;
  3353. var prev;
  3354. var next;
  3355. var d1;
  3356. var d2;
  3357. _v0[0] = x;
  3358. _v0[1] = y;
  3359. for (var _t = 0; _t < 1; _t += 0.05) {
  3360. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  3361. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  3362. d1 = distSquare(_v0, _v1);
  3363. if (d1 < d) {
  3364. t = _t;
  3365. d = d1;
  3366. }
  3367. }
  3368. d = Infinity;
  3369. for (var i = 0; i < 32; i++) {
  3370. if (interval < EPSILON_NUMERIC) {
  3371. break;
  3372. }
  3373. prev = t - interval;
  3374. next = t + interval;
  3375. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  3376. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  3377. d1 = distSquare(_v1, _v0);
  3378. if (prev >= 0 && d1 < d) {
  3379. t = prev;
  3380. d = d1;
  3381. }
  3382. else {
  3383. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  3384. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  3385. d2 = distSquare(_v2, _v0);
  3386. if (next <= 1 && d2 < d) {
  3387. t = next;
  3388. d = d2;
  3389. }
  3390. else {
  3391. interval *= 0.5;
  3392. }
  3393. }
  3394. }
  3395. if (out) {
  3396. out[0] = cubicAt(x0, x1, x2, x3, t);
  3397. out[1] = cubicAt(y0, y1, y2, y3, t);
  3398. }
  3399. return mathSqrt(d);
  3400. }
  3401. function cubicLength(x0, y0, x1, y1, x2, y2, x3, y3, iteration) {
  3402. var px = x0;
  3403. var py = y0;
  3404. var d = 0;
  3405. var step = 1 / iteration;
  3406. for (var i = 1; i <= iteration; i++) {
  3407. var t = i * step;
  3408. var x = cubicAt(x0, x1, x2, x3, t);
  3409. var y = cubicAt(y0, y1, y2, y3, t);
  3410. var dx = x - px;
  3411. var dy = y - py;
  3412. d += Math.sqrt(dx * dx + dy * dy);
  3413. px = x;
  3414. py = y;
  3415. }
  3416. return d;
  3417. }
  3418. function quadraticAt(p0, p1, p2, t) {
  3419. var onet = 1 - t;
  3420. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  3421. }
  3422. function quadraticDerivativeAt(p0, p1, p2, t) {
  3423. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  3424. }
  3425. function quadraticRootAt(p0, p1, p2, val, roots) {
  3426. var a = p0 - 2 * p1 + p2;
  3427. var b = 2 * (p1 - p0);
  3428. var c = p0 - val;
  3429. var n = 0;
  3430. if (isAroundZero(a)) {
  3431. if (isNotAroundZero(b)) {
  3432. var t1 = -c / b;
  3433. if (t1 >= 0 && t1 <= 1) {
  3434. roots[n++] = t1;
  3435. }
  3436. }
  3437. }
  3438. else {
  3439. var disc = b * b - 4 * a * c;
  3440. if (isAroundZero(disc)) {
  3441. var t1 = -b / (2 * a);
  3442. if (t1 >= 0 && t1 <= 1) {
  3443. roots[n++] = t1;
  3444. }
  3445. }
  3446. else if (disc > 0) {
  3447. var discSqrt = mathSqrt(disc);
  3448. var t1 = (-b + discSqrt) / (2 * a);
  3449. var t2 = (-b - discSqrt) / (2 * a);
  3450. if (t1 >= 0 && t1 <= 1) {
  3451. roots[n++] = t1;
  3452. }
  3453. if (t2 >= 0 && t2 <= 1) {
  3454. roots[n++] = t2;
  3455. }
  3456. }
  3457. }
  3458. return n;
  3459. }
  3460. function quadraticExtremum(p0, p1, p2) {
  3461. var divider = p0 + p2 - 2 * p1;
  3462. if (divider === 0) {
  3463. return 0.5;
  3464. }
  3465. else {
  3466. return (p0 - p1) / divider;
  3467. }
  3468. }
  3469. function quadraticSubdivide(p0, p1, p2, t, out) {
  3470. var p01 = (p1 - p0) * t + p0;
  3471. var p12 = (p2 - p1) * t + p1;
  3472. var p012 = (p12 - p01) * t + p01;
  3473. out[0] = p0;
  3474. out[1] = p01;
  3475. out[2] = p012;
  3476. out[3] = p012;
  3477. out[4] = p12;
  3478. out[5] = p2;
  3479. }
  3480. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  3481. var t;
  3482. var interval = 0.005;
  3483. var d = Infinity;
  3484. _v0[0] = x;
  3485. _v0[1] = y;
  3486. for (var _t = 0; _t < 1; _t += 0.05) {
  3487. _v1[0] = quadraticAt(x0, x1, x2, _t);
  3488. _v1[1] = quadraticAt(y0, y1, y2, _t);
  3489. var d1 = distSquare(_v0, _v1);
  3490. if (d1 < d) {
  3491. t = _t;
  3492. d = d1;
  3493. }
  3494. }
  3495. d = Infinity;
  3496. for (var i = 0; i < 32; i++) {
  3497. if (interval < EPSILON_NUMERIC) {
  3498. break;
  3499. }
  3500. var prev = t - interval;
  3501. var next = t + interval;
  3502. _v1[0] = quadraticAt(x0, x1, x2, prev);
  3503. _v1[1] = quadraticAt(y0, y1, y2, prev);
  3504. var d1 = distSquare(_v1, _v0);
  3505. if (prev >= 0 && d1 < d) {
  3506. t = prev;
  3507. d = d1;
  3508. }
  3509. else {
  3510. _v2[0] = quadraticAt(x0, x1, x2, next);
  3511. _v2[1] = quadraticAt(y0, y1, y2, next);
  3512. var d2 = distSquare(_v2, _v0);
  3513. if (next <= 1 && d2 < d) {
  3514. t = next;
  3515. d = d2;
  3516. }
  3517. else {
  3518. interval *= 0.5;
  3519. }
  3520. }
  3521. }
  3522. if (out) {
  3523. out[0] = quadraticAt(x0, x1, x2, t);
  3524. out[1] = quadraticAt(y0, y1, y2, t);
  3525. }
  3526. return mathSqrt(d);
  3527. }
  3528. function quadraticLength(x0, y0, x1, y1, x2, y2, iteration) {
  3529. var px = x0;
  3530. var py = y0;
  3531. var d = 0;
  3532. var step = 1 / iteration;
  3533. for (var i = 1; i <= iteration; i++) {
  3534. var t = i * step;
  3535. var x = quadraticAt(x0, x1, x2, t);
  3536. var y = quadraticAt(y0, y1, y2, t);
  3537. var dx = x - px;
  3538. var dy = y - py;
  3539. d += Math.sqrt(dx * dx + dy * dy);
  3540. px = x;
  3541. py = y;
  3542. }
  3543. return d;
  3544. }
  3545. var regexp = /cubic-bezier\(([0-9,\.e ]+)\)/;
  3546. function createCubicEasingFunc(cubicEasingStr) {
  3547. var cubic = cubicEasingStr && regexp.exec(cubicEasingStr);
  3548. if (cubic) {
  3549. var points = cubic[1].split(',');
  3550. var a_1 = +trim(points[0]);
  3551. var b_1 = +trim(points[1]);
  3552. var c_1 = +trim(points[2]);
  3553. var d_1 = +trim(points[3]);
  3554. if (isNaN(a_1 + b_1 + c_1 + d_1)) {
  3555. return;
  3556. }
  3557. var roots_1 = [];
  3558. return function (p) {
  3559. return p <= 0
  3560. ? 0 : p >= 1
  3561. ? 1
  3562. : cubicRootAt(0, a_1, c_1, 1, p, roots_1) && cubicAt(0, b_1, d_1, 1, roots_1[0]);
  3563. };
  3564. }
  3565. }
  3566. var Clip = (function () {
  3567. function Clip(opts) {
  3568. this._inited = false;
  3569. this._startTime = 0;
  3570. this._pausedTime = 0;
  3571. this._paused = false;
  3572. this._life = opts.life || 1000;
  3573. this._delay = opts.delay || 0;
  3574. this.loop = opts.loop || false;
  3575. this.onframe = opts.onframe || noop;
  3576. this.ondestroy = opts.ondestroy || noop;
  3577. this.onrestart = opts.onrestart || noop;
  3578. opts.easing && this.setEasing(opts.easing);
  3579. }
  3580. Clip.prototype.step = function (globalTime, deltaTime) {
  3581. if (!this._inited) {
  3582. this._startTime = globalTime + this._delay;
  3583. this._inited = true;
  3584. }
  3585. if (this._paused) {
  3586. this._pausedTime += deltaTime;
  3587. return;
  3588. }
  3589. var life = this._life;
  3590. var elapsedTime = globalTime - this._startTime - this._pausedTime;
  3591. var percent = elapsedTime / life;
  3592. if (percent < 0) {
  3593. percent = 0;
  3594. }
  3595. percent = Math.min(percent, 1);
  3596. var easingFunc = this.easingFunc;
  3597. var schedule = easingFunc ? easingFunc(percent) : percent;
  3598. this.onframe(schedule);
  3599. if (percent === 1) {
  3600. if (this.loop) {
  3601. var remainder = elapsedTime % life;
  3602. this._startTime = globalTime - remainder;
  3603. this._pausedTime = 0;
  3604. this.onrestart();
  3605. }
  3606. else {
  3607. return true;
  3608. }
  3609. }
  3610. return false;
  3611. };
  3612. Clip.prototype.pause = function () {
  3613. this._paused = true;
  3614. };
  3615. Clip.prototype.resume = function () {
  3616. this._paused = false;
  3617. };
  3618. Clip.prototype.setEasing = function (easing) {
  3619. this.easing = easing;
  3620. this.easingFunc = isFunction(easing)
  3621. ? easing
  3622. : easingFuncs[easing] || createCubicEasingFunc(easing);
  3623. };
  3624. return Clip;
  3625. }());
  3626. var Entry = (function () {
  3627. function Entry(val) {
  3628. this.value = val;
  3629. }
  3630. return Entry;
  3631. }());
  3632. var LinkedList = (function () {
  3633. function LinkedList() {
  3634. this._len = 0;
  3635. }
  3636. LinkedList.prototype.insert = function (val) {
  3637. var entry = new Entry(val);
  3638. this.insertEntry(entry);
  3639. return entry;
  3640. };
  3641. LinkedList.prototype.insertEntry = function (entry) {
  3642. if (!this.head) {
  3643. this.head = this.tail = entry;
  3644. }
  3645. else {
  3646. this.tail.next = entry;
  3647. entry.prev = this.tail;
  3648. entry.next = null;
  3649. this.tail = entry;
  3650. }
  3651. this._len++;
  3652. };
  3653. LinkedList.prototype.remove = function (entry) {
  3654. var prev = entry.prev;
  3655. var next = entry.next;
  3656. if (prev) {
  3657. prev.next = next;
  3658. }
  3659. else {
  3660. this.head = next;
  3661. }
  3662. if (next) {
  3663. next.prev = prev;
  3664. }
  3665. else {
  3666. this.tail = prev;
  3667. }
  3668. entry.next = entry.prev = null;
  3669. this._len--;
  3670. };
  3671. LinkedList.prototype.len = function () {
  3672. return this._len;
  3673. };
  3674. LinkedList.prototype.clear = function () {
  3675. this.head = this.tail = null;
  3676. this._len = 0;
  3677. };
  3678. return LinkedList;
  3679. }());
  3680. var LRU = (function () {
  3681. function LRU(maxSize) {
  3682. this._list = new LinkedList();
  3683. this._maxSize = 10;
  3684. this._map = {};
  3685. this._maxSize = maxSize;
  3686. }
  3687. LRU.prototype.put = function (key, value) {
  3688. var list = this._list;
  3689. var map = this._map;
  3690. var removed = null;
  3691. if (map[key] == null) {
  3692. var len = list.len();
  3693. var entry = this._lastRemovedEntry;
  3694. if (len >= this._maxSize && len > 0) {
  3695. var leastUsedEntry = list.head;
  3696. list.remove(leastUsedEntry);
  3697. delete map[leastUsedEntry.key];
  3698. removed = leastUsedEntry.value;
  3699. this._lastRemovedEntry = leastUsedEntry;
  3700. }
  3701. if (entry) {
  3702. entry.value = value;
  3703. }
  3704. else {
  3705. entry = new Entry(value);
  3706. }
  3707. entry.key = key;
  3708. list.insertEntry(entry);
  3709. map[key] = entry;
  3710. }
  3711. return removed;
  3712. };
  3713. LRU.prototype.get = function (key) {
  3714. var entry = this._map[key];
  3715. var list = this._list;
  3716. if (entry != null) {
  3717. if (entry !== list.tail) {
  3718. list.remove(entry);
  3719. list.insertEntry(entry);
  3720. }
  3721. return entry.value;
  3722. }
  3723. };
  3724. LRU.prototype.clear = function () {
  3725. this._list.clear();
  3726. this._map = {};
  3727. };
  3728. LRU.prototype.len = function () {
  3729. return this._list.len();
  3730. };
  3731. return LRU;
  3732. }());
  3733. var kCSSColorTable = {
  3734. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  3735. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  3736. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  3737. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  3738. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  3739. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  3740. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  3741. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  3742. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  3743. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  3744. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  3745. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  3746. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  3747. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  3748. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  3749. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  3750. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  3751. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  3752. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  3753. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  3754. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  3755. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  3756. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  3757. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  3758. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  3759. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  3760. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  3761. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  3762. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  3763. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  3764. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  3765. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  3766. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  3767. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  3768. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  3769. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  3770. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  3771. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  3772. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  3773. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  3774. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  3775. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  3776. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  3777. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  3778. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  3779. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  3780. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  3781. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  3782. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  3783. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  3784. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  3785. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  3786. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  3787. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  3788. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  3789. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  3790. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  3791. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  3792. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  3793. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  3794. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  3795. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  3796. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  3797. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  3798. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  3799. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  3800. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  3801. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  3802. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  3803. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  3804. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  3805. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  3806. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  3807. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  3808. };
  3809. function clampCssByte(i) {
  3810. i = Math.round(i);
  3811. return i < 0 ? 0 : i > 255 ? 255 : i;
  3812. }
  3813. function clampCssAngle(i) {
  3814. i = Math.round(i);
  3815. return i < 0 ? 0 : i > 360 ? 360 : i;
  3816. }
  3817. function clampCssFloat(f) {
  3818. return f < 0 ? 0 : f > 1 ? 1 : f;
  3819. }
  3820. function parseCssInt(val) {
  3821. var str = val;
  3822. if (str.length && str.charAt(str.length - 1) === '%') {
  3823. return clampCssByte(parseFloat(str) / 100 * 255);
  3824. }
  3825. return clampCssByte(parseInt(str, 10));
  3826. }
  3827. function parseCssFloat(val) {
  3828. var str = val;
  3829. if (str.length && str.charAt(str.length - 1) === '%') {
  3830. return clampCssFloat(parseFloat(str) / 100);
  3831. }
  3832. return clampCssFloat(parseFloat(str));
  3833. }
  3834. function cssHueToRgb(m1, m2, h) {
  3835. if (h < 0) {
  3836. h += 1;
  3837. }
  3838. else if (h > 1) {
  3839. h -= 1;
  3840. }
  3841. if (h * 6 < 1) {
  3842. return m1 + (m2 - m1) * h * 6;
  3843. }
  3844. if (h * 2 < 1) {
  3845. return m2;
  3846. }
  3847. if (h * 3 < 2) {
  3848. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3849. }
  3850. return m1;
  3851. }
  3852. function lerpNumber(a, b, p) {
  3853. return a + (b - a) * p;
  3854. }
  3855. function setRgba(out, r, g, b, a) {
  3856. out[0] = r;
  3857. out[1] = g;
  3858. out[2] = b;
  3859. out[3] = a;
  3860. return out;
  3861. }
  3862. function copyRgba(out, a) {
  3863. out[0] = a[0];
  3864. out[1] = a[1];
  3865. out[2] = a[2];
  3866. out[3] = a[3];
  3867. return out;
  3868. }
  3869. var colorCache = new LRU(20);
  3870. var lastRemovedArr = null;
  3871. function putToCache(colorStr, rgbaArr) {
  3872. if (lastRemovedArr) {
  3873. copyRgba(lastRemovedArr, rgbaArr);
  3874. }
  3875. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  3876. }
  3877. function parse(colorStr, rgbaArr) {
  3878. if (!colorStr) {
  3879. return;
  3880. }
  3881. rgbaArr = rgbaArr || [];
  3882. var cached = colorCache.get(colorStr);
  3883. if (cached) {
  3884. return copyRgba(rgbaArr, cached);
  3885. }
  3886. colorStr = colorStr + '';
  3887. var str = colorStr.replace(/ /g, '').toLowerCase();
  3888. if (str in kCSSColorTable) {
  3889. copyRgba(rgbaArr, kCSSColorTable[str]);
  3890. putToCache(colorStr, rgbaArr);
  3891. return rgbaArr;
  3892. }
  3893. var strLen = str.length;
  3894. if (str.charAt(0) === '#') {
  3895. if (strLen === 4 || strLen === 5) {
  3896. var iv = parseInt(str.slice(1, 4), 16);
  3897. if (!(iv >= 0 && iv <= 0xfff)) {
  3898. setRgba(rgbaArr, 0, 0, 0, 1);
  3899. return;
  3900. }
  3901. 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);
  3902. putToCache(colorStr, rgbaArr);
  3903. return rgbaArr;
  3904. }
  3905. else if (strLen === 7 || strLen === 9) {
  3906. var iv = parseInt(str.slice(1, 7), 16);
  3907. if (!(iv >= 0 && iv <= 0xffffff)) {
  3908. setRgba(rgbaArr, 0, 0, 0, 1);
  3909. return;
  3910. }
  3911. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, strLen === 9 ? parseInt(str.slice(7), 16) / 0xff : 1);
  3912. putToCache(colorStr, rgbaArr);
  3913. return rgbaArr;
  3914. }
  3915. return;
  3916. }
  3917. var op = str.indexOf('(');
  3918. var ep = str.indexOf(')');
  3919. if (op !== -1 && ep + 1 === strLen) {
  3920. var fname = str.substr(0, op);
  3921. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3922. var alpha = 1;
  3923. switch (fname) {
  3924. case 'rgba':
  3925. if (params.length !== 4) {
  3926. return params.length === 3
  3927. ? setRgba(rgbaArr, +params[0], +params[1], +params[2], 1)
  3928. : setRgba(rgbaArr, 0, 0, 0, 1);
  3929. }
  3930. alpha = parseCssFloat(params.pop());
  3931. case 'rgb':
  3932. if (params.length >= 3) {
  3933. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), params.length === 3 ? alpha : parseCssFloat(params[3]));
  3934. putToCache(colorStr, rgbaArr);
  3935. return rgbaArr;
  3936. }
  3937. else {
  3938. setRgba(rgbaArr, 0, 0, 0, 1);
  3939. return;
  3940. }
  3941. case 'hsla':
  3942. if (params.length !== 4) {
  3943. setRgba(rgbaArr, 0, 0, 0, 1);
  3944. return;
  3945. }
  3946. params[3] = parseCssFloat(params[3]);
  3947. hsla2rgba(params, rgbaArr);
  3948. putToCache(colorStr, rgbaArr);
  3949. return rgbaArr;
  3950. case 'hsl':
  3951. if (params.length !== 3) {
  3952. setRgba(rgbaArr, 0, 0, 0, 1);
  3953. return;
  3954. }
  3955. hsla2rgba(params, rgbaArr);
  3956. putToCache(colorStr, rgbaArr);
  3957. return rgbaArr;
  3958. default:
  3959. return;
  3960. }
  3961. }
  3962. setRgba(rgbaArr, 0, 0, 0, 1);
  3963. return;
  3964. }
  3965. function hsla2rgba(hsla, rgba) {
  3966. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360;
  3967. var s = parseCssFloat(hsla[1]);
  3968. var l = parseCssFloat(hsla[2]);
  3969. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  3970. var m1 = l * 2 - m2;
  3971. rgba = rgba || [];
  3972. 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);
  3973. if (hsla.length === 4) {
  3974. rgba[3] = hsla[3];
  3975. }
  3976. return rgba;
  3977. }
  3978. function rgba2hsla(rgba) {
  3979. if (!rgba) {
  3980. return;
  3981. }
  3982. var R = rgba[0] / 255;
  3983. var G = rgba[1] / 255;
  3984. var B = rgba[2] / 255;
  3985. var vMin = Math.min(R, G, B);
  3986. var vMax = Math.max(R, G, B);
  3987. var delta = vMax - vMin;
  3988. var L = (vMax + vMin) / 2;
  3989. var H;
  3990. var S;
  3991. if (delta === 0) {
  3992. H = 0;
  3993. S = 0;
  3994. }
  3995. else {
  3996. if (L < 0.5) {
  3997. S = delta / (vMax + vMin);
  3998. }
  3999. else {
  4000. S = delta / (2 - vMax - vMin);
  4001. }
  4002. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  4003. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  4004. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  4005. if (R === vMax) {
  4006. H = deltaB - deltaG;
  4007. }
  4008. else if (G === vMax) {
  4009. H = (1 / 3) + deltaR - deltaB;
  4010. }
  4011. else if (B === vMax) {
  4012. H = (2 / 3) + deltaG - deltaR;
  4013. }
  4014. if (H < 0) {
  4015. H += 1;
  4016. }
  4017. if (H > 1) {
  4018. H -= 1;
  4019. }
  4020. }
  4021. var hsla = [H * 360, S, L];
  4022. if (rgba[3] != null) {
  4023. hsla.push(rgba[3]);
  4024. }
  4025. return hsla;
  4026. }
  4027. function lift(color, level) {
  4028. var colorArr = parse(color);
  4029. if (colorArr) {
  4030. for (var i = 0; i < 3; i++) {
  4031. if (level < 0) {
  4032. colorArr[i] = colorArr[i] * (1 - level) | 0;
  4033. }
  4034. else {
  4035. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  4036. }
  4037. if (colorArr[i] > 255) {
  4038. colorArr[i] = 255;
  4039. }
  4040. else if (colorArr[i] < 0) {
  4041. colorArr[i] = 0;
  4042. }
  4043. }
  4044. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  4045. }
  4046. }
  4047. function toHex(color) {
  4048. var colorArr = parse(color);
  4049. if (colorArr) {
  4050. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  4051. }
  4052. }
  4053. function fastLerp(normalizedValue, colors, out) {
  4054. if (!(colors && colors.length)
  4055. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  4056. return;
  4057. }
  4058. out = out || [];
  4059. var value = normalizedValue * (colors.length - 1);
  4060. var leftIndex = Math.floor(value);
  4061. var rightIndex = Math.ceil(value);
  4062. var leftColor = colors[leftIndex];
  4063. var rightColor = colors[rightIndex];
  4064. var dv = value - leftIndex;
  4065. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  4066. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  4067. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  4068. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  4069. return out;
  4070. }
  4071. var fastMapToColor = fastLerp;
  4072. function lerp$1(normalizedValue, colors, fullOutput) {
  4073. if (!(colors && colors.length)
  4074. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  4075. return;
  4076. }
  4077. var value = normalizedValue * (colors.length - 1);
  4078. var leftIndex = Math.floor(value);
  4079. var rightIndex = Math.ceil(value);
  4080. var leftColor = parse(colors[leftIndex]);
  4081. var rightColor = parse(colors[rightIndex]);
  4082. var dv = value - leftIndex;
  4083. var color = stringify([
  4084. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  4085. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  4086. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  4087. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  4088. ], 'rgba');
  4089. return fullOutput
  4090. ? {
  4091. color: color,
  4092. leftIndex: leftIndex,
  4093. rightIndex: rightIndex,
  4094. value: value
  4095. }
  4096. : color;
  4097. }
  4098. var mapToColor = lerp$1;
  4099. function modifyHSL(color, h, s, l) {
  4100. var colorArr = parse(color);
  4101. if (color) {
  4102. colorArr = rgba2hsla(colorArr);
  4103. h != null && (colorArr[0] = clampCssAngle(isFunction(h) ? h(colorArr[0]) : h));
  4104. s != null && (colorArr[1] = parseCssFloat(isFunction(s) ? s(colorArr[1]) : s));
  4105. l != null && (colorArr[2] = parseCssFloat(isFunction(l) ? l(colorArr[2]) : l));
  4106. return stringify(hsla2rgba(colorArr), 'rgba');
  4107. }
  4108. }
  4109. function modifyAlpha(color, alpha) {
  4110. var colorArr = parse(color);
  4111. if (colorArr && alpha != null) {
  4112. colorArr[3] = clampCssFloat(alpha);
  4113. return stringify(colorArr, 'rgba');
  4114. }
  4115. }
  4116. function stringify(arrColor, type) {
  4117. if (!arrColor || !arrColor.length) {
  4118. return;
  4119. }
  4120. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  4121. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  4122. colorStr += ',' + arrColor[3];
  4123. }
  4124. return type + '(' + colorStr + ')';
  4125. }
  4126. function lum(color, backgroundLum) {
  4127. var arr = parse(color);
  4128. return arr
  4129. ? (0.299 * arr[0] + 0.587 * arr[1] + 0.114 * arr[2]) * arr[3] / 255
  4130. + (1 - arr[3]) * backgroundLum
  4131. : 0;
  4132. }
  4133. function random() {
  4134. return stringify([
  4135. Math.round(Math.random() * 255),
  4136. Math.round(Math.random() * 255),
  4137. Math.round(Math.random() * 255)
  4138. ], 'rgb');
  4139. }
  4140. var liftedColorCache = new LRU(100);
  4141. function liftColor(color) {
  4142. if (isString(color)) {
  4143. var liftedColor = liftedColorCache.get(color);
  4144. if (!liftedColor) {
  4145. liftedColor = lift(color, -0.1);
  4146. liftedColorCache.put(color, liftedColor);
  4147. }
  4148. return liftedColor;
  4149. }
  4150. else if (isGradientObject(color)) {
  4151. var ret = extend({}, color);
  4152. ret.colorStops = map(color.colorStops, function (stop) { return ({
  4153. offset: stop.offset,
  4154. color: lift(stop.color, -0.1)
  4155. }); });
  4156. return ret;
  4157. }
  4158. return color;
  4159. }
  4160. var color = /*#__PURE__*/Object.freeze({
  4161. __proto__: null,
  4162. parseCssInt: parseCssInt,
  4163. parseCssFloat: parseCssFloat,
  4164. parse: parse,
  4165. lift: lift,
  4166. toHex: toHex,
  4167. fastLerp: fastLerp,
  4168. fastMapToColor: fastMapToColor,
  4169. lerp: lerp$1,
  4170. mapToColor: mapToColor,
  4171. modifyHSL: modifyHSL,
  4172. modifyAlpha: modifyAlpha,
  4173. stringify: stringify,
  4174. lum: lum,
  4175. random: random,
  4176. liftColor: liftColor
  4177. });
  4178. var mathRound = Math.round;
  4179. function normalizeColor(color) {
  4180. var opacity;
  4181. if (!color || color === 'transparent') {
  4182. color = 'none';
  4183. }
  4184. else if (typeof color === 'string' && color.indexOf('rgba') > -1) {
  4185. var arr = parse(color);
  4186. if (arr) {
  4187. color = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')';
  4188. opacity = arr[3];
  4189. }
  4190. }
  4191. return {
  4192. color: color,
  4193. opacity: opacity == null ? 1 : opacity
  4194. };
  4195. }
  4196. var EPSILON$2 = 1e-4;
  4197. function isAroundZero$1(transform) {
  4198. return transform < EPSILON$2 && transform > -EPSILON$2;
  4199. }
  4200. function round3(transform) {
  4201. return mathRound(transform * 1e3) / 1e3;
  4202. }
  4203. function round4(transform) {
  4204. return mathRound(transform * 1e4) / 1e4;
  4205. }
  4206. function getMatrixStr(m) {
  4207. return 'matrix('
  4208. + round3(m[0]) + ','
  4209. + round3(m[1]) + ','
  4210. + round3(m[2]) + ','
  4211. + round3(m[3]) + ','
  4212. + round4(m[4]) + ','
  4213. + round4(m[5])
  4214. + ')';
  4215. }
  4216. var TEXT_ALIGN_TO_ANCHOR = {
  4217. left: 'start',
  4218. right: 'end',
  4219. center: 'middle',
  4220. middle: 'middle'
  4221. };
  4222. function adjustTextY(y, lineHeight, textBaseline) {
  4223. if (textBaseline === 'top') {
  4224. y += lineHeight / 2;
  4225. }
  4226. else if (textBaseline === 'bottom') {
  4227. y -= lineHeight / 2;
  4228. }
  4229. return y;
  4230. }
  4231. function hasShadow(style) {
  4232. return style
  4233. && (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY);
  4234. }
  4235. function getShadowKey(displayable) {
  4236. var style = displayable.style;
  4237. var globalScale = displayable.getGlobalScale();
  4238. return [
  4239. style.shadowColor,
  4240. (style.shadowBlur || 0).toFixed(2),
  4241. (style.shadowOffsetX || 0).toFixed(2),
  4242. (style.shadowOffsetY || 0).toFixed(2),
  4243. globalScale[0],
  4244. globalScale[1]
  4245. ].join(',');
  4246. }
  4247. function isImagePattern(val) {
  4248. return val && (!!val.image);
  4249. }
  4250. function isSVGPattern(val) {
  4251. return val && (!!val.svgElement);
  4252. }
  4253. function isPattern(val) {
  4254. return isImagePattern(val) || isSVGPattern(val);
  4255. }
  4256. function isLinearGradient(val) {
  4257. return val.type === 'linear';
  4258. }
  4259. function isRadialGradient(val) {
  4260. return val.type === 'radial';
  4261. }
  4262. function isGradient(val) {
  4263. return val && (val.type === 'linear'
  4264. || val.type === 'radial');
  4265. }
  4266. function getIdURL(id) {
  4267. return "url(#" + id + ")";
  4268. }
  4269. function getPathPrecision(el) {
  4270. var scale = el.getGlobalScale();
  4271. var size = Math.max(scale[0], scale[1]);
  4272. return Math.max(Math.ceil(Math.log(size) / Math.log(10)), 1);
  4273. }
  4274. function getSRTTransformString(transform) {
  4275. var x = transform.x || 0;
  4276. var y = transform.y || 0;
  4277. var rotation = (transform.rotation || 0) * RADIAN_TO_DEGREE;
  4278. var scaleX = retrieve2(transform.scaleX, 1);
  4279. var scaleY = retrieve2(transform.scaleY, 1);
  4280. var skewX = transform.skewX || 0;
  4281. var skewY = transform.skewY || 0;
  4282. var res = [];
  4283. if (x || y) {
  4284. res.push("translate(" + x + "px," + y + "px)");
  4285. }
  4286. if (rotation) {
  4287. res.push("rotate(" + rotation + ")");
  4288. }
  4289. if (scaleX !== 1 || scaleY !== 1) {
  4290. res.push("scale(" + scaleX + "," + scaleY + ")");
  4291. }
  4292. if (skewX || skewY) {
  4293. res.push("skew(" + mathRound(skewX * RADIAN_TO_DEGREE) + "deg, " + mathRound(skewY * RADIAN_TO_DEGREE) + "deg)");
  4294. }
  4295. return res.join(' ');
  4296. }
  4297. var encodeBase64 = (function () {
  4298. if (env.hasGlobalWindow && isFunction(window.btoa)) {
  4299. return function (str) {
  4300. return window.btoa(unescape(encodeURIComponent(str)));
  4301. };
  4302. }
  4303. if (typeof Buffer !== 'undefined') {
  4304. return function (str) {
  4305. return Buffer.from(str).toString('base64');
  4306. };
  4307. }
  4308. return function (str) {
  4309. {
  4310. logError('Base64 isn\'t natively supported in the current environment.');
  4311. }
  4312. return null;
  4313. };
  4314. })();
  4315. var arraySlice = Array.prototype.slice;
  4316. function interpolateNumber(p0, p1, percent) {
  4317. return (p1 - p0) * percent + p0;
  4318. }
  4319. function interpolate1DArray(out, p0, p1, percent) {
  4320. var len = p0.length;
  4321. for (var i = 0; i < len; i++) {
  4322. out[i] = interpolateNumber(p0[i], p1[i], percent);
  4323. }
  4324. return out;
  4325. }
  4326. function interpolate2DArray(out, p0, p1, percent) {
  4327. var len = p0.length;
  4328. var len2 = len && p0[0].length;
  4329. for (var i = 0; i < len; i++) {
  4330. if (!out[i]) {
  4331. out[i] = [];
  4332. }
  4333. for (var j = 0; j < len2; j++) {
  4334. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  4335. }
  4336. }
  4337. return out;
  4338. }
  4339. function add1DArray(out, p0, p1, sign) {
  4340. var len = p0.length;
  4341. for (var i = 0; i < len; i++) {
  4342. out[i] = p0[i] + p1[i] * sign;
  4343. }
  4344. return out;
  4345. }
  4346. function add2DArray(out, p0, p1, sign) {
  4347. var len = p0.length;
  4348. var len2 = len && p0[0].length;
  4349. for (var i = 0; i < len; i++) {
  4350. if (!out[i]) {
  4351. out[i] = [];
  4352. }
  4353. for (var j = 0; j < len2; j++) {
  4354. out[i][j] = p0[i][j] + p1[i][j] * sign;
  4355. }
  4356. }
  4357. return out;
  4358. }
  4359. function fillColorStops(val0, val1) {
  4360. var len0 = val0.length;
  4361. var len1 = val1.length;
  4362. var shorterArr = len0 > len1 ? val1 : val0;
  4363. var shorterLen = Math.min(len0, len1);
  4364. var last = shorterArr[shorterLen - 1] || { color: [0, 0, 0, 0], offset: 0 };
  4365. for (var i = shorterLen; i < Math.max(len0, len1); i++) {
  4366. shorterArr.push({
  4367. offset: last.offset,
  4368. color: last.color.slice()
  4369. });
  4370. }
  4371. }
  4372. function fillArray(val0, val1, arrDim) {
  4373. var arr0 = val0;
  4374. var arr1 = val1;
  4375. if (!arr0.push || !arr1.push) {
  4376. return;
  4377. }
  4378. var arr0Len = arr0.length;
  4379. var arr1Len = arr1.length;
  4380. if (arr0Len !== arr1Len) {
  4381. var isPreviousLarger = arr0Len > arr1Len;
  4382. if (isPreviousLarger) {
  4383. arr0.length = arr1Len;
  4384. }
  4385. else {
  4386. for (var i = arr0Len; i < arr1Len; i++) {
  4387. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  4388. }
  4389. }
  4390. }
  4391. var len2 = arr0[0] && arr0[0].length;
  4392. for (var i = 0; i < arr0.length; i++) {
  4393. if (arrDim === 1) {
  4394. if (isNaN(arr0[i])) {
  4395. arr0[i] = arr1[i];
  4396. }
  4397. }
  4398. else {
  4399. for (var j = 0; j < len2; j++) {
  4400. if (isNaN(arr0[i][j])) {
  4401. arr0[i][j] = arr1[i][j];
  4402. }
  4403. }
  4404. }
  4405. }
  4406. }
  4407. function cloneValue(value) {
  4408. if (isArrayLike(value)) {
  4409. var len = value.length;
  4410. if (isArrayLike(value[0])) {
  4411. var ret = [];
  4412. for (var i = 0; i < len; i++) {
  4413. ret.push(arraySlice.call(value[i]));
  4414. }
  4415. return ret;
  4416. }
  4417. return arraySlice.call(value);
  4418. }
  4419. return value;
  4420. }
  4421. function rgba2String(rgba) {
  4422. rgba[0] = Math.floor(rgba[0]) || 0;
  4423. rgba[1] = Math.floor(rgba[1]) || 0;
  4424. rgba[2] = Math.floor(rgba[2]) || 0;
  4425. rgba[3] = rgba[3] == null ? 1 : rgba[3];
  4426. return 'rgba(' + rgba.join(',') + ')';
  4427. }
  4428. function guessArrayDim(value) {
  4429. return isArrayLike(value && value[0]) ? 2 : 1;
  4430. }
  4431. var VALUE_TYPE_NUMBER = 0;
  4432. var VALUE_TYPE_1D_ARRAY = 1;
  4433. var VALUE_TYPE_2D_ARRAY = 2;
  4434. var VALUE_TYPE_COLOR = 3;
  4435. var VALUE_TYPE_LINEAR_GRADIENT = 4;
  4436. var VALUE_TYPE_RADIAL_GRADIENT = 5;
  4437. var VALUE_TYPE_UNKOWN = 6;
  4438. function isGradientValueType(valType) {
  4439. return valType === VALUE_TYPE_LINEAR_GRADIENT || valType === VALUE_TYPE_RADIAL_GRADIENT;
  4440. }
  4441. function isArrayValueType(valType) {
  4442. return valType === VALUE_TYPE_1D_ARRAY || valType === VALUE_TYPE_2D_ARRAY;
  4443. }
  4444. var tmpRgba = [0, 0, 0, 0];
  4445. var Track = (function () {
  4446. function Track(propName) {
  4447. this.keyframes = [];
  4448. this.discrete = false;
  4449. this._invalid = false;
  4450. this._needsSort = false;
  4451. this._lastFr = 0;
  4452. this._lastFrP = 0;
  4453. this.propName = propName;
  4454. }
  4455. Track.prototype.isFinished = function () {
  4456. return this._finished;
  4457. };
  4458. Track.prototype.setFinished = function () {
  4459. this._finished = true;
  4460. if (this._additiveTrack) {
  4461. this._additiveTrack.setFinished();
  4462. }
  4463. };
  4464. Track.prototype.needsAnimate = function () {
  4465. return this.keyframes.length >= 1;
  4466. };
  4467. Track.prototype.getAdditiveTrack = function () {
  4468. return this._additiveTrack;
  4469. };
  4470. Track.prototype.addKeyframe = function (time, rawValue, easing) {
  4471. this._needsSort = true;
  4472. var keyframes = this.keyframes;
  4473. var len = keyframes.length;
  4474. var discrete = false;
  4475. var valType = VALUE_TYPE_UNKOWN;
  4476. var value = rawValue;
  4477. if (isArrayLike(rawValue)) {
  4478. var arrayDim = guessArrayDim(rawValue);
  4479. valType = arrayDim;
  4480. if (arrayDim === 1 && !isNumber(rawValue[0])
  4481. || arrayDim === 2 && !isNumber(rawValue[0][0])) {
  4482. discrete = true;
  4483. }
  4484. }
  4485. else {
  4486. if (isNumber(rawValue) && !eqNaN(rawValue)) {
  4487. valType = VALUE_TYPE_NUMBER;
  4488. }
  4489. else if (isString(rawValue)) {
  4490. if (!isNaN(+rawValue)) {
  4491. valType = VALUE_TYPE_NUMBER;
  4492. }
  4493. else {
  4494. var colorArray = parse(rawValue);
  4495. if (colorArray) {
  4496. value = colorArray;
  4497. valType = VALUE_TYPE_COLOR;
  4498. }
  4499. }
  4500. }
  4501. else if (isGradientObject(rawValue)) {
  4502. var parsedGradient = extend({}, value);
  4503. parsedGradient.colorStops = map(rawValue.colorStops, function (colorStop) { return ({
  4504. offset: colorStop.offset,
  4505. color: parse(colorStop.color)
  4506. }); });
  4507. if (isLinearGradient(rawValue)) {
  4508. valType = VALUE_TYPE_LINEAR_GRADIENT;
  4509. }
  4510. else if (isRadialGradient(rawValue)) {
  4511. valType = VALUE_TYPE_RADIAL_GRADIENT;
  4512. }
  4513. value = parsedGradient;
  4514. }
  4515. }
  4516. if (len === 0) {
  4517. this.valType = valType;
  4518. }
  4519. else if (valType !== this.valType || valType === VALUE_TYPE_UNKOWN) {
  4520. discrete = true;
  4521. }
  4522. this.discrete = this.discrete || discrete;
  4523. var kf = {
  4524. time: time,
  4525. value: value,
  4526. rawValue: rawValue,
  4527. percent: 0
  4528. };
  4529. if (easing) {
  4530. kf.easing = easing;
  4531. kf.easingFunc = isFunction(easing)
  4532. ? easing
  4533. : easingFuncs[easing] || createCubicEasingFunc(easing);
  4534. }
  4535. keyframes.push(kf);
  4536. return kf;
  4537. };
  4538. Track.prototype.prepare = function (maxTime, additiveTrack) {
  4539. var kfs = this.keyframes;
  4540. if (this._needsSort) {
  4541. kfs.sort(function (a, b) {
  4542. return a.time - b.time;
  4543. });
  4544. }
  4545. var valType = this.valType;
  4546. var kfsLen = kfs.length;
  4547. var lastKf = kfs[kfsLen - 1];
  4548. var isDiscrete = this.discrete;
  4549. var isArr = isArrayValueType(valType);
  4550. var isGradient = isGradientValueType(valType);
  4551. for (var i = 0; i < kfsLen; i++) {
  4552. var kf = kfs[i];
  4553. var value = kf.value;
  4554. var lastValue = lastKf.value;
  4555. kf.percent = kf.time / maxTime;
  4556. if (!isDiscrete) {
  4557. if (isArr && i !== kfsLen - 1) {
  4558. fillArray(value, lastValue, valType);
  4559. }
  4560. else if (isGradient) {
  4561. fillColorStops(value.colorStops, lastValue.colorStops);
  4562. }
  4563. }
  4564. }
  4565. if (!isDiscrete
  4566. && valType !== VALUE_TYPE_RADIAL_GRADIENT
  4567. && additiveTrack
  4568. && this.needsAnimate()
  4569. && additiveTrack.needsAnimate()
  4570. && valType === additiveTrack.valType
  4571. && !additiveTrack._finished) {
  4572. this._additiveTrack = additiveTrack;
  4573. var startValue = kfs[0].value;
  4574. for (var i = 0; i < kfsLen; i++) {
  4575. if (valType === VALUE_TYPE_NUMBER) {
  4576. kfs[i].additiveValue = kfs[i].value - startValue;
  4577. }
  4578. else if (valType === VALUE_TYPE_COLOR) {
  4579. kfs[i].additiveValue =
  4580. add1DArray([], kfs[i].value, startValue, -1);
  4581. }
  4582. else if (isArrayValueType(valType)) {
  4583. kfs[i].additiveValue = valType === VALUE_TYPE_1D_ARRAY
  4584. ? add1DArray([], kfs[i].value, startValue, -1)
  4585. : add2DArray([], kfs[i].value, startValue, -1);
  4586. }
  4587. }
  4588. }
  4589. };
  4590. Track.prototype.step = function (target, percent) {
  4591. if (this._finished) {
  4592. return;
  4593. }
  4594. if (this._additiveTrack && this._additiveTrack._finished) {
  4595. this._additiveTrack = null;
  4596. }
  4597. var isAdditive = this._additiveTrack != null;
  4598. var valueKey = isAdditive ? 'additiveValue' : 'value';
  4599. var valType = this.valType;
  4600. var keyframes = this.keyframes;
  4601. var kfsNum = keyframes.length;
  4602. var propName = this.propName;
  4603. var isValueColor = valType === VALUE_TYPE_COLOR;
  4604. var frameIdx;
  4605. var lastFrame = this._lastFr;
  4606. var mathMin = Math.min;
  4607. var frame;
  4608. var nextFrame;
  4609. if (kfsNum === 1) {
  4610. frame = nextFrame = keyframes[0];
  4611. }
  4612. else {
  4613. if (percent < 0) {
  4614. frameIdx = 0;
  4615. }
  4616. else if (percent < this._lastFrP) {
  4617. var start = mathMin(lastFrame + 1, kfsNum - 1);
  4618. for (frameIdx = start; frameIdx >= 0; frameIdx--) {
  4619. if (keyframes[frameIdx].percent <= percent) {
  4620. break;
  4621. }
  4622. }
  4623. frameIdx = mathMin(frameIdx, kfsNum - 2);
  4624. }
  4625. else {
  4626. for (frameIdx = lastFrame; frameIdx < kfsNum; frameIdx++) {
  4627. if (keyframes[frameIdx].percent > percent) {
  4628. break;
  4629. }
  4630. }
  4631. frameIdx = mathMin(frameIdx - 1, kfsNum - 2);
  4632. }
  4633. nextFrame = keyframes[frameIdx + 1];
  4634. frame = keyframes[frameIdx];
  4635. }
  4636. if (!(frame && nextFrame)) {
  4637. return;
  4638. }
  4639. this._lastFr = frameIdx;
  4640. this._lastFrP = percent;
  4641. var interval = (nextFrame.percent - frame.percent);
  4642. var w = interval === 0 ? 1 : mathMin((percent - frame.percent) / interval, 1);
  4643. if (nextFrame.easingFunc) {
  4644. w = nextFrame.easingFunc(w);
  4645. }
  4646. var targetArr = isAdditive ? this._additiveValue
  4647. : (isValueColor ? tmpRgba : target[propName]);
  4648. if ((isArrayValueType(valType) || isValueColor) && !targetArr) {
  4649. targetArr = this._additiveValue = [];
  4650. }
  4651. if (this.discrete) {
  4652. target[propName] = w < 1 ? frame.rawValue : nextFrame.rawValue;
  4653. }
  4654. else if (isArrayValueType(valType)) {
  4655. valType === VALUE_TYPE_1D_ARRAY
  4656. ? interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w)
  4657. : interpolate2DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4658. }
  4659. else if (isGradientValueType(valType)) {
  4660. var val = frame[valueKey];
  4661. var nextVal_1 = nextFrame[valueKey];
  4662. var isLinearGradient_1 = valType === VALUE_TYPE_LINEAR_GRADIENT;
  4663. target[propName] = {
  4664. type: isLinearGradient_1 ? 'linear' : 'radial',
  4665. x: interpolateNumber(val.x, nextVal_1.x, w),
  4666. y: interpolateNumber(val.y, nextVal_1.y, w),
  4667. colorStops: map(val.colorStops, function (colorStop, idx) {
  4668. var nextColorStop = nextVal_1.colorStops[idx];
  4669. return {
  4670. offset: interpolateNumber(colorStop.offset, nextColorStop.offset, w),
  4671. color: rgba2String(interpolate1DArray([], colorStop.color, nextColorStop.color, w))
  4672. };
  4673. }),
  4674. global: nextVal_1.global
  4675. };
  4676. if (isLinearGradient_1) {
  4677. target[propName].x2 = interpolateNumber(val.x2, nextVal_1.x2, w);
  4678. target[propName].y2 = interpolateNumber(val.y2, nextVal_1.y2, w);
  4679. }
  4680. else {
  4681. target[propName].r = interpolateNumber(val.r, nextVal_1.r, w);
  4682. }
  4683. }
  4684. else if (isValueColor) {
  4685. interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4686. if (!isAdditive) {
  4687. target[propName] = rgba2String(targetArr);
  4688. }
  4689. }
  4690. else {
  4691. var value = interpolateNumber(frame[valueKey], nextFrame[valueKey], w);
  4692. if (isAdditive) {
  4693. this._additiveValue = value;
  4694. }
  4695. else {
  4696. target[propName] = value;
  4697. }
  4698. }
  4699. if (isAdditive) {
  4700. this._addToTarget(target);
  4701. }
  4702. };
  4703. Track.prototype._addToTarget = function (target) {
  4704. var valType = this.valType;
  4705. var propName = this.propName;
  4706. var additiveValue = this._additiveValue;
  4707. if (valType === VALUE_TYPE_NUMBER) {
  4708. target[propName] = target[propName] + additiveValue;
  4709. }
  4710. else if (valType === VALUE_TYPE_COLOR) {
  4711. parse(target[propName], tmpRgba);
  4712. add1DArray(tmpRgba, tmpRgba, additiveValue, 1);
  4713. target[propName] = rgba2String(tmpRgba);
  4714. }
  4715. else if (valType === VALUE_TYPE_1D_ARRAY) {
  4716. add1DArray(target[propName], target[propName], additiveValue, 1);
  4717. }
  4718. else if (valType === VALUE_TYPE_2D_ARRAY) {
  4719. add2DArray(target[propName], target[propName], additiveValue, 1);
  4720. }
  4721. };
  4722. return Track;
  4723. }());
  4724. var Animator = (function () {
  4725. function Animator(target, loop, allowDiscreteAnimation, additiveTo) {
  4726. this._tracks = {};
  4727. this._trackKeys = [];
  4728. this._maxTime = 0;
  4729. this._started = 0;
  4730. this._clip = null;
  4731. this._target = target;
  4732. this._loop = loop;
  4733. if (loop && additiveTo) {
  4734. logError('Can\' use additive animation on looped animation.');
  4735. return;
  4736. }
  4737. this._additiveAnimators = additiveTo;
  4738. this._allowDiscrete = allowDiscreteAnimation;
  4739. }
  4740. Animator.prototype.getMaxTime = function () {
  4741. return this._maxTime;
  4742. };
  4743. Animator.prototype.getDelay = function () {
  4744. return this._delay;
  4745. };
  4746. Animator.prototype.getLoop = function () {
  4747. return this._loop;
  4748. };
  4749. Animator.prototype.getTarget = function () {
  4750. return this._target;
  4751. };
  4752. Animator.prototype.changeTarget = function (target) {
  4753. this._target = target;
  4754. };
  4755. Animator.prototype.when = function (time, props, easing) {
  4756. return this.whenWithKeys(time, props, keys(props), easing);
  4757. };
  4758. Animator.prototype.whenWithKeys = function (time, props, propNames, easing) {
  4759. var tracks = this._tracks;
  4760. for (var i = 0; i < propNames.length; i++) {
  4761. var propName = propNames[i];
  4762. var track = tracks[propName];
  4763. if (!track) {
  4764. track = tracks[propName] = new Track(propName);
  4765. var initialValue = void 0;
  4766. var additiveTrack = this._getAdditiveTrack(propName);
  4767. if (additiveTrack) {
  4768. var addtiveTrackKfs = additiveTrack.keyframes;
  4769. var lastFinalKf = addtiveTrackKfs[addtiveTrackKfs.length - 1];
  4770. initialValue = lastFinalKf && lastFinalKf.value;
  4771. if (additiveTrack.valType === VALUE_TYPE_COLOR && initialValue) {
  4772. initialValue = rgba2String(initialValue);
  4773. }
  4774. }
  4775. else {
  4776. initialValue = this._target[propName];
  4777. }
  4778. if (initialValue == null) {
  4779. continue;
  4780. }
  4781. if (time > 0) {
  4782. track.addKeyframe(0, cloneValue(initialValue), easing);
  4783. }
  4784. this._trackKeys.push(propName);
  4785. }
  4786. track.addKeyframe(time, cloneValue(props[propName]), easing);
  4787. }
  4788. this._maxTime = Math.max(this._maxTime, time);
  4789. return this;
  4790. };
  4791. Animator.prototype.pause = function () {
  4792. this._clip.pause();
  4793. this._paused = true;
  4794. };
  4795. Animator.prototype.resume = function () {
  4796. this._clip.resume();
  4797. this._paused = false;
  4798. };
  4799. Animator.prototype.isPaused = function () {
  4800. return !!this._paused;
  4801. };
  4802. Animator.prototype.duration = function (duration) {
  4803. this._maxTime = duration;
  4804. this._force = true;
  4805. return this;
  4806. };
  4807. Animator.prototype._doneCallback = function () {
  4808. this._setTracksFinished();
  4809. this._clip = null;
  4810. var doneList = this._doneCbs;
  4811. if (doneList) {
  4812. var len = doneList.length;
  4813. for (var i = 0; i < len; i++) {
  4814. doneList[i].call(this);
  4815. }
  4816. }
  4817. };
  4818. Animator.prototype._abortedCallback = function () {
  4819. this._setTracksFinished();
  4820. var animation = this.animation;
  4821. var abortedList = this._abortedCbs;
  4822. if (animation) {
  4823. animation.removeClip(this._clip);
  4824. }
  4825. this._clip = null;
  4826. if (abortedList) {
  4827. for (var i = 0; i < abortedList.length; i++) {
  4828. abortedList[i].call(this);
  4829. }
  4830. }
  4831. };
  4832. Animator.prototype._setTracksFinished = function () {
  4833. var tracks = this._tracks;
  4834. var tracksKeys = this._trackKeys;
  4835. for (var i = 0; i < tracksKeys.length; i++) {
  4836. tracks[tracksKeys[i]].setFinished();
  4837. }
  4838. };
  4839. Animator.prototype._getAdditiveTrack = function (trackName) {
  4840. var additiveTrack;
  4841. var additiveAnimators = this._additiveAnimators;
  4842. if (additiveAnimators) {
  4843. for (var i = 0; i < additiveAnimators.length; i++) {
  4844. var track = additiveAnimators[i].getTrack(trackName);
  4845. if (track) {
  4846. additiveTrack = track;
  4847. }
  4848. }
  4849. }
  4850. return additiveTrack;
  4851. };
  4852. Animator.prototype.start = function (easing) {
  4853. if (this._started > 0) {
  4854. return;
  4855. }
  4856. this._started = 1;
  4857. var self = this;
  4858. var tracks = [];
  4859. var maxTime = this._maxTime || 0;
  4860. for (var i = 0; i < this._trackKeys.length; i++) {
  4861. var propName = this._trackKeys[i];
  4862. var track = this._tracks[propName];
  4863. var additiveTrack = this._getAdditiveTrack(propName);
  4864. var kfs = track.keyframes;
  4865. var kfsNum = kfs.length;
  4866. track.prepare(maxTime, additiveTrack);
  4867. if (track.needsAnimate()) {
  4868. if (!this._allowDiscrete && track.discrete) {
  4869. var lastKf = kfs[kfsNum - 1];
  4870. if (lastKf) {
  4871. self._target[track.propName] = lastKf.rawValue;
  4872. }
  4873. track.setFinished();
  4874. }
  4875. else {
  4876. tracks.push(track);
  4877. }
  4878. }
  4879. }
  4880. if (tracks.length || this._force) {
  4881. var clip = new Clip({
  4882. life: maxTime,
  4883. loop: this._loop,
  4884. delay: this._delay || 0,
  4885. onframe: function (percent) {
  4886. self._started = 2;
  4887. var additiveAnimators = self._additiveAnimators;
  4888. if (additiveAnimators) {
  4889. var stillHasAdditiveAnimator = false;
  4890. for (var i = 0; i < additiveAnimators.length; i++) {
  4891. if (additiveAnimators[i]._clip) {
  4892. stillHasAdditiveAnimator = true;
  4893. break;
  4894. }
  4895. }
  4896. if (!stillHasAdditiveAnimator) {
  4897. self._additiveAnimators = null;
  4898. }
  4899. }
  4900. for (var i = 0; i < tracks.length; i++) {
  4901. tracks[i].step(self._target, percent);
  4902. }
  4903. var onframeList = self._onframeCbs;
  4904. if (onframeList) {
  4905. for (var i = 0; i < onframeList.length; i++) {
  4906. onframeList[i](self._target, percent);
  4907. }
  4908. }
  4909. },
  4910. ondestroy: function () {
  4911. self._doneCallback();
  4912. }
  4913. });
  4914. this._clip = clip;
  4915. if (this.animation) {
  4916. this.animation.addClip(clip);
  4917. }
  4918. if (easing) {
  4919. clip.setEasing(easing);
  4920. }
  4921. }
  4922. else {
  4923. this._doneCallback();
  4924. }
  4925. return this;
  4926. };
  4927. Animator.prototype.stop = function (forwardToLast) {
  4928. if (!this._clip) {
  4929. return;
  4930. }
  4931. var clip = this._clip;
  4932. if (forwardToLast) {
  4933. clip.onframe(1);
  4934. }
  4935. this._abortedCallback();
  4936. };
  4937. Animator.prototype.delay = function (time) {
  4938. this._delay = time;
  4939. return this;
  4940. };
  4941. Animator.prototype.during = function (cb) {
  4942. if (cb) {
  4943. if (!this._onframeCbs) {
  4944. this._onframeCbs = [];
  4945. }
  4946. this._onframeCbs.push(cb);
  4947. }
  4948. return this;
  4949. };
  4950. Animator.prototype.done = function (cb) {
  4951. if (cb) {
  4952. if (!this._doneCbs) {
  4953. this._doneCbs = [];
  4954. }
  4955. this._doneCbs.push(cb);
  4956. }
  4957. return this;
  4958. };
  4959. Animator.prototype.aborted = function (cb) {
  4960. if (cb) {
  4961. if (!this._abortedCbs) {
  4962. this._abortedCbs = [];
  4963. }
  4964. this._abortedCbs.push(cb);
  4965. }
  4966. return this;
  4967. };
  4968. Animator.prototype.getClip = function () {
  4969. return this._clip;
  4970. };
  4971. Animator.prototype.getTrack = function (propName) {
  4972. return this._tracks[propName];
  4973. };
  4974. Animator.prototype.getTracks = function () {
  4975. var _this = this;
  4976. return map(this._trackKeys, function (key) { return _this._tracks[key]; });
  4977. };
  4978. Animator.prototype.stopTracks = function (propNames, forwardToLast) {
  4979. if (!propNames.length || !this._clip) {
  4980. return true;
  4981. }
  4982. var tracks = this._tracks;
  4983. var tracksKeys = this._trackKeys;
  4984. for (var i = 0; i < propNames.length; i++) {
  4985. var track = tracks[propNames[i]];
  4986. if (track && !track.isFinished()) {
  4987. if (forwardToLast) {
  4988. track.step(this._target, 1);
  4989. }
  4990. else if (this._started === 1) {
  4991. track.step(this._target, 0);
  4992. }
  4993. track.setFinished();
  4994. }
  4995. }
  4996. var allAborted = true;
  4997. for (var i = 0; i < tracksKeys.length; i++) {
  4998. if (!tracks[tracksKeys[i]].isFinished()) {
  4999. allAborted = false;
  5000. break;
  5001. }
  5002. }
  5003. if (allAborted) {
  5004. this._abortedCallback();
  5005. }
  5006. return allAborted;
  5007. };
  5008. Animator.prototype.saveTo = function (target, trackKeys, firstOrLast) {
  5009. if (!target) {
  5010. return;
  5011. }
  5012. trackKeys = trackKeys || this._trackKeys;
  5013. for (var i = 0; i < trackKeys.length; i++) {
  5014. var propName = trackKeys[i];
  5015. var track = this._tracks[propName];
  5016. if (!track || track.isFinished()) {
  5017. continue;
  5018. }
  5019. var kfs = track.keyframes;
  5020. var kf = kfs[firstOrLast ? 0 : kfs.length - 1];
  5021. if (kf) {
  5022. target[propName] = cloneValue(kf.rawValue);
  5023. }
  5024. }
  5025. };
  5026. Animator.prototype.__changeFinalValue = function (finalProps, trackKeys) {
  5027. trackKeys = trackKeys || keys(finalProps);
  5028. for (var i = 0; i < trackKeys.length; i++) {
  5029. var propName = trackKeys[i];
  5030. var track = this._tracks[propName];
  5031. if (!track) {
  5032. continue;
  5033. }
  5034. var kfs = track.keyframes;
  5035. if (kfs.length > 1) {
  5036. var lastKf = kfs.pop();
  5037. track.addKeyframe(lastKf.time, finalProps[propName]);
  5038. track.prepare(this._maxTime, track.getAdditiveTrack());
  5039. }
  5040. }
  5041. };
  5042. return Animator;
  5043. }());
  5044. function getTime() {
  5045. return new Date().getTime();
  5046. }
  5047. var Animation = (function (_super) {
  5048. __extends(Animation, _super);
  5049. function Animation(opts) {
  5050. var _this = _super.call(this) || this;
  5051. _this._running = false;
  5052. _this._time = 0;
  5053. _this._pausedTime = 0;
  5054. _this._pauseStart = 0;
  5055. _this._paused = false;
  5056. opts = opts || {};
  5057. _this.stage = opts.stage || {};
  5058. return _this;
  5059. }
  5060. Animation.prototype.addClip = function (clip) {
  5061. if (clip.animation) {
  5062. this.removeClip(clip);
  5063. }
  5064. if (!this._head) {
  5065. this._head = this._tail = clip;
  5066. }
  5067. else {
  5068. this._tail.next = clip;
  5069. clip.prev = this._tail;
  5070. clip.next = null;
  5071. this._tail = clip;
  5072. }
  5073. clip.animation = this;
  5074. };
  5075. Animation.prototype.addAnimator = function (animator) {
  5076. animator.animation = this;
  5077. var clip = animator.getClip();
  5078. if (clip) {
  5079. this.addClip(clip);
  5080. }
  5081. };
  5082. Animation.prototype.removeClip = function (clip) {
  5083. if (!clip.animation) {
  5084. return;
  5085. }
  5086. var prev = clip.prev;
  5087. var next = clip.next;
  5088. if (prev) {
  5089. prev.next = next;
  5090. }
  5091. else {
  5092. this._head = next;
  5093. }
  5094. if (next) {
  5095. next.prev = prev;
  5096. }
  5097. else {
  5098. this._tail = prev;
  5099. }
  5100. clip.next = clip.prev = clip.animation = null;
  5101. };
  5102. Animation.prototype.removeAnimator = function (animator) {
  5103. var clip = animator.getClip();
  5104. if (clip) {
  5105. this.removeClip(clip);
  5106. }
  5107. animator.animation = null;
  5108. };
  5109. Animation.prototype.update = function (notTriggerFrameAndStageUpdate) {
  5110. var time = getTime() - this._pausedTime;
  5111. var delta = time - this._time;
  5112. var clip = this._head;
  5113. while (clip) {
  5114. var nextClip = clip.next;
  5115. var finished = clip.step(time, delta);
  5116. if (finished) {
  5117. clip.ondestroy();
  5118. this.removeClip(clip);
  5119. clip = nextClip;
  5120. }
  5121. else {
  5122. clip = nextClip;
  5123. }
  5124. }
  5125. this._time = time;
  5126. if (!notTriggerFrameAndStageUpdate) {
  5127. this.trigger('frame', delta);
  5128. this.stage.update && this.stage.update();
  5129. }
  5130. };
  5131. Animation.prototype._startLoop = function () {
  5132. var self = this;
  5133. this._running = true;
  5134. function step() {
  5135. if (self._running) {
  5136. requestAnimationFrame$1(step);
  5137. !self._paused && self.update();
  5138. }
  5139. }
  5140. requestAnimationFrame$1(step);
  5141. };
  5142. Animation.prototype.start = function () {
  5143. if (this._running) {
  5144. return;
  5145. }
  5146. this._time = getTime();
  5147. this._pausedTime = 0;
  5148. this._startLoop();
  5149. };
  5150. Animation.prototype.stop = function () {
  5151. this._running = false;
  5152. };
  5153. Animation.prototype.pause = function () {
  5154. if (!this._paused) {
  5155. this._pauseStart = getTime();
  5156. this._paused = true;
  5157. }
  5158. };
  5159. Animation.prototype.resume = function () {
  5160. if (this._paused) {
  5161. this._pausedTime += getTime() - this._pauseStart;
  5162. this._paused = false;
  5163. }
  5164. };
  5165. Animation.prototype.clear = function () {
  5166. var clip = this._head;
  5167. while (clip) {
  5168. var nextClip = clip.next;
  5169. clip.prev = clip.next = clip.animation = null;
  5170. clip = nextClip;
  5171. }
  5172. this._head = this._tail = null;
  5173. };
  5174. Animation.prototype.isFinished = function () {
  5175. return this._head == null;
  5176. };
  5177. Animation.prototype.animate = function (target, options) {
  5178. options = options || {};
  5179. this.start();
  5180. var animator = new Animator(target, options.loop);
  5181. this.addAnimator(animator);
  5182. return animator;
  5183. };
  5184. return Animation;
  5185. }(Eventful));
  5186. var TOUCH_CLICK_DELAY = 300;
  5187. var globalEventSupported = env.domSupported;
  5188. var localNativeListenerNames = (function () {
  5189. var mouseHandlerNames = [
  5190. 'click', 'dblclick', 'mousewheel', 'wheel', 'mouseout',
  5191. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  5192. ];
  5193. var touchHandlerNames = [
  5194. 'touchstart', 'touchend', 'touchmove'
  5195. ];
  5196. var pointerEventNameMap = {
  5197. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  5198. };
  5199. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  5200. var nm = name.replace('mouse', 'pointer');
  5201. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  5202. });
  5203. return {
  5204. mouse: mouseHandlerNames,
  5205. touch: touchHandlerNames,
  5206. pointer: pointerHandlerNames
  5207. };
  5208. })();
  5209. var globalNativeListenerNames = {
  5210. mouse: ['mousemove', 'mouseup'],
  5211. pointer: ['pointermove', 'pointerup']
  5212. };
  5213. var wheelEventSupported = false;
  5214. function isPointerFromTouch(event) {
  5215. var pointerType = event.pointerType;
  5216. return pointerType === 'pen' || pointerType === 'touch';
  5217. }
  5218. function setTouchTimer(scope) {
  5219. scope.touching = true;
  5220. if (scope.touchTimer != null) {
  5221. clearTimeout(scope.touchTimer);
  5222. scope.touchTimer = null;
  5223. }
  5224. scope.touchTimer = setTimeout(function () {
  5225. scope.touching = false;
  5226. scope.touchTimer = null;
  5227. }, 700);
  5228. }
  5229. function markTouch(event) {
  5230. event && (event.zrByTouch = true);
  5231. }
  5232. function normalizeGlobalEvent(instance, event) {
  5233. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  5234. }
  5235. function isLocalEl(instance, el) {
  5236. var elTmp = el;
  5237. var isLocal = false;
  5238. while (elTmp && elTmp.nodeType !== 9
  5239. && !(isLocal = elTmp.domBelongToZr
  5240. || (elTmp !== el && elTmp === instance.painterRoot))) {
  5241. elTmp = elTmp.parentNode;
  5242. }
  5243. return isLocal;
  5244. }
  5245. var FakeGlobalEvent = (function () {
  5246. function FakeGlobalEvent(instance, event) {
  5247. this.stopPropagation = noop;
  5248. this.stopImmediatePropagation = noop;
  5249. this.preventDefault = noop;
  5250. this.type = event.type;
  5251. this.target = this.currentTarget = instance.dom;
  5252. this.pointerType = event.pointerType;
  5253. this.clientX = event.clientX;
  5254. this.clientY = event.clientY;
  5255. }
  5256. return FakeGlobalEvent;
  5257. }());
  5258. var localDOMHandlers = {
  5259. mousedown: function (event) {
  5260. event = normalizeEvent(this.dom, event);
  5261. this.__mayPointerCapture = [event.zrX, event.zrY];
  5262. this.trigger('mousedown', event);
  5263. },
  5264. mousemove: function (event) {
  5265. event = normalizeEvent(this.dom, event);
  5266. var downPoint = this.__mayPointerCapture;
  5267. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  5268. this.__togglePointerCapture(true);
  5269. }
  5270. this.trigger('mousemove', event);
  5271. },
  5272. mouseup: function (event) {
  5273. event = normalizeEvent(this.dom, event);
  5274. this.__togglePointerCapture(false);
  5275. this.trigger('mouseup', event);
  5276. },
  5277. mouseout: function (event) {
  5278. event = normalizeEvent(this.dom, event);
  5279. var element = event.toElement || event.relatedTarget;
  5280. if (!isLocalEl(this, element)) {
  5281. if (this.__pointerCapturing) {
  5282. event.zrEventControl = 'no_globalout';
  5283. }
  5284. this.trigger('mouseout', event);
  5285. }
  5286. },
  5287. wheel: function (event) {
  5288. wheelEventSupported = true;
  5289. event = normalizeEvent(this.dom, event);
  5290. this.trigger('mousewheel', event);
  5291. },
  5292. mousewheel: function (event) {
  5293. if (wheelEventSupported) {
  5294. return;
  5295. }
  5296. event = normalizeEvent(this.dom, event);
  5297. this.trigger('mousewheel', event);
  5298. },
  5299. touchstart: function (event) {
  5300. event = normalizeEvent(this.dom, event);
  5301. markTouch(event);
  5302. this.__lastTouchMoment = new Date();
  5303. this.handler.processGesture(event, 'start');
  5304. localDOMHandlers.mousemove.call(this, event);
  5305. localDOMHandlers.mousedown.call(this, event);
  5306. },
  5307. touchmove: function (event) {
  5308. event = normalizeEvent(this.dom, event);
  5309. markTouch(event);
  5310. this.handler.processGesture(event, 'change');
  5311. localDOMHandlers.mousemove.call(this, event);
  5312. },
  5313. touchend: function (event) {
  5314. event = normalizeEvent(this.dom, event);
  5315. markTouch(event);
  5316. this.handler.processGesture(event, 'end');
  5317. localDOMHandlers.mouseup.call(this, event);
  5318. if (+new Date() - (+this.__lastTouchMoment) < TOUCH_CLICK_DELAY) {
  5319. localDOMHandlers.click.call(this, event);
  5320. }
  5321. },
  5322. pointerdown: function (event) {
  5323. localDOMHandlers.mousedown.call(this, event);
  5324. },
  5325. pointermove: function (event) {
  5326. if (!isPointerFromTouch(event)) {
  5327. localDOMHandlers.mousemove.call(this, event);
  5328. }
  5329. },
  5330. pointerup: function (event) {
  5331. localDOMHandlers.mouseup.call(this, event);
  5332. },
  5333. pointerout: function (event) {
  5334. if (!isPointerFromTouch(event)) {
  5335. localDOMHandlers.mouseout.call(this, event);
  5336. }
  5337. }
  5338. };
  5339. each(['click', 'dblclick', 'contextmenu'], function (name) {
  5340. localDOMHandlers[name] = function (event) {
  5341. event = normalizeEvent(this.dom, event);
  5342. this.trigger(name, event);
  5343. };
  5344. });
  5345. var globalDOMHandlers = {
  5346. pointermove: function (event) {
  5347. if (!isPointerFromTouch(event)) {
  5348. globalDOMHandlers.mousemove.call(this, event);
  5349. }
  5350. },
  5351. pointerup: function (event) {
  5352. globalDOMHandlers.mouseup.call(this, event);
  5353. },
  5354. mousemove: function (event) {
  5355. this.trigger('mousemove', event);
  5356. },
  5357. mouseup: function (event) {
  5358. var pointerCaptureReleasing = this.__pointerCapturing;
  5359. this.__togglePointerCapture(false);
  5360. this.trigger('mouseup', event);
  5361. if (pointerCaptureReleasing) {
  5362. event.zrEventControl = 'only_globalout';
  5363. this.trigger('mouseout', event);
  5364. }
  5365. }
  5366. };
  5367. function mountLocalDOMEventListeners(instance, scope) {
  5368. var domHandlers = scope.domHandlers;
  5369. if (env.pointerEventsSupported) {
  5370. each(localNativeListenerNames.pointer, function (nativeEventName) {
  5371. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5372. domHandlers[nativeEventName].call(instance, event);
  5373. });
  5374. });
  5375. }
  5376. else {
  5377. if (env.touchEventsSupported) {
  5378. each(localNativeListenerNames.touch, function (nativeEventName) {
  5379. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5380. domHandlers[nativeEventName].call(instance, event);
  5381. setTouchTimer(scope);
  5382. });
  5383. });
  5384. }
  5385. each(localNativeListenerNames.mouse, function (nativeEventName) {
  5386. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5387. event = getNativeEvent(event);
  5388. if (!scope.touching) {
  5389. domHandlers[nativeEventName].call(instance, event);
  5390. }
  5391. });
  5392. });
  5393. }
  5394. }
  5395. function mountGlobalDOMEventListeners(instance, scope) {
  5396. if (env.pointerEventsSupported) {
  5397. each(globalNativeListenerNames.pointer, mount);
  5398. }
  5399. else if (!env.touchEventsSupported) {
  5400. each(globalNativeListenerNames.mouse, mount);
  5401. }
  5402. function mount(nativeEventName) {
  5403. function nativeEventListener(event) {
  5404. event = getNativeEvent(event);
  5405. if (!isLocalEl(instance, event.target)) {
  5406. event = normalizeGlobalEvent(instance, event);
  5407. scope.domHandlers[nativeEventName].call(instance, event);
  5408. }
  5409. }
  5410. mountSingleDOMEventListener(scope, nativeEventName, nativeEventListener, { capture: true });
  5411. }
  5412. }
  5413. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  5414. scope.mounted[nativeEventName] = listener;
  5415. scope.listenerOpts[nativeEventName] = opt;
  5416. addEventListener(scope.domTarget, nativeEventName, listener, opt);
  5417. }
  5418. function unmountDOMEventListeners(scope) {
  5419. var mounted = scope.mounted;
  5420. for (var nativeEventName in mounted) {
  5421. if (mounted.hasOwnProperty(nativeEventName)) {
  5422. removeEventListener(scope.domTarget, nativeEventName, mounted[nativeEventName], scope.listenerOpts[nativeEventName]);
  5423. }
  5424. }
  5425. scope.mounted = {};
  5426. }
  5427. var DOMHandlerScope = (function () {
  5428. function DOMHandlerScope(domTarget, domHandlers) {
  5429. this.mounted = {};
  5430. this.listenerOpts = {};
  5431. this.touching = false;
  5432. this.domTarget = domTarget;
  5433. this.domHandlers = domHandlers;
  5434. }
  5435. return DOMHandlerScope;
  5436. }());
  5437. var HandlerDomProxy = (function (_super) {
  5438. __extends(HandlerDomProxy, _super);
  5439. function HandlerDomProxy(dom, painterRoot) {
  5440. var _this = _super.call(this) || this;
  5441. _this.__pointerCapturing = false;
  5442. _this.dom = dom;
  5443. _this.painterRoot = painterRoot;
  5444. _this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  5445. if (globalEventSupported) {
  5446. _this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  5447. }
  5448. mountLocalDOMEventListeners(_this, _this._localHandlerScope);
  5449. return _this;
  5450. }
  5451. HandlerDomProxy.prototype.dispose = function () {
  5452. unmountDOMEventListeners(this._localHandlerScope);
  5453. if (globalEventSupported) {
  5454. unmountDOMEventListeners(this._globalHandlerScope);
  5455. }
  5456. };
  5457. HandlerDomProxy.prototype.setCursor = function (cursorStyle) {
  5458. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  5459. };
  5460. HandlerDomProxy.prototype.__togglePointerCapture = function (isPointerCapturing) {
  5461. this.__mayPointerCapture = null;
  5462. if (globalEventSupported
  5463. && ((+this.__pointerCapturing) ^ (+isPointerCapturing))) {
  5464. this.__pointerCapturing = isPointerCapturing;
  5465. var globalHandlerScope = this._globalHandlerScope;
  5466. isPointerCapturing
  5467. ? mountGlobalDOMEventListeners(this, globalHandlerScope)
  5468. : unmountDOMEventListeners(globalHandlerScope);
  5469. }
  5470. };
  5471. return HandlerDomProxy;
  5472. }(Eventful));
  5473. var dpr = 1;
  5474. if (env.hasGlobalWindow) {
  5475. dpr = Math.max(window.devicePixelRatio
  5476. || (window.screen && window.screen.deviceXDPI / window.screen.logicalXDPI)
  5477. || 1, 1);
  5478. }
  5479. var devicePixelRatio = dpr;
  5480. var DARK_MODE_THRESHOLD = 0.4;
  5481. var DARK_LABEL_COLOR = '#333';
  5482. var LIGHT_LABEL_COLOR = '#ccc';
  5483. var LIGHTER_LABEL_COLOR = '#eee';
  5484. var mIdentity = identity;
  5485. var EPSILON$3 = 5e-5;
  5486. function isNotAroundZero$1(val) {
  5487. return val > EPSILON$3 || val < -EPSILON$3;
  5488. }
  5489. var scaleTmp = [];
  5490. var tmpTransform = [];
  5491. var originTransform = create$1();
  5492. var abs = Math.abs;
  5493. var Transformable = (function () {
  5494. function Transformable() {
  5495. }
  5496. Transformable.prototype.getLocalTransform = function (m) {
  5497. return Transformable.getLocalTransform(this, m);
  5498. };
  5499. Transformable.prototype.setPosition = function (arr) {
  5500. this.x = arr[0];
  5501. this.y = arr[1];
  5502. };
  5503. Transformable.prototype.setScale = function (arr) {
  5504. this.scaleX = arr[0];
  5505. this.scaleY = arr[1];
  5506. };
  5507. Transformable.prototype.setSkew = function (arr) {
  5508. this.skewX = arr[0];
  5509. this.skewY = arr[1];
  5510. };
  5511. Transformable.prototype.setOrigin = function (arr) {
  5512. this.originX = arr[0];
  5513. this.originY = arr[1];
  5514. };
  5515. Transformable.prototype.needLocalTransform = function () {
  5516. return isNotAroundZero$1(this.rotation)
  5517. || isNotAroundZero$1(this.x)
  5518. || isNotAroundZero$1(this.y)
  5519. || isNotAroundZero$1(this.scaleX - 1)
  5520. || isNotAroundZero$1(this.scaleY - 1)
  5521. || isNotAroundZero$1(this.skewX)
  5522. || isNotAroundZero$1(this.skewY);
  5523. };
  5524. Transformable.prototype.updateTransform = function () {
  5525. var parentTransform = this.parent && this.parent.transform;
  5526. var needLocalTransform = this.needLocalTransform();
  5527. var m = this.transform;
  5528. if (!(needLocalTransform || parentTransform)) {
  5529. if (m) {
  5530. mIdentity(m);
  5531. this.invTransform = null;
  5532. }
  5533. return;
  5534. }
  5535. m = m || create$1();
  5536. if (needLocalTransform) {
  5537. this.getLocalTransform(m);
  5538. }
  5539. else {
  5540. mIdentity(m);
  5541. }
  5542. if (parentTransform) {
  5543. if (needLocalTransform) {
  5544. mul$1(m, parentTransform, m);
  5545. }
  5546. else {
  5547. copy$1(m, parentTransform);
  5548. }
  5549. }
  5550. this.transform = m;
  5551. this._resolveGlobalScaleRatio(m);
  5552. };
  5553. Transformable.prototype._resolveGlobalScaleRatio = function (m) {
  5554. var globalScaleRatio = this.globalScaleRatio;
  5555. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  5556. this.getGlobalScale(scaleTmp);
  5557. var relX = scaleTmp[0] < 0 ? -1 : 1;
  5558. var relY = scaleTmp[1] < 0 ? -1 : 1;
  5559. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  5560. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  5561. m[0] *= sx;
  5562. m[1] *= sx;
  5563. m[2] *= sy;
  5564. m[3] *= sy;
  5565. }
  5566. this.invTransform = this.invTransform || create$1();
  5567. invert(this.invTransform, m);
  5568. };
  5569. Transformable.prototype.getComputedTransform = function () {
  5570. var transformNode = this;
  5571. var ancestors = [];
  5572. while (transformNode) {
  5573. ancestors.push(transformNode);
  5574. transformNode = transformNode.parent;
  5575. }
  5576. while (transformNode = ancestors.pop()) {
  5577. transformNode.updateTransform();
  5578. }
  5579. return this.transform;
  5580. };
  5581. Transformable.prototype.setLocalTransform = function (m) {
  5582. if (!m) {
  5583. return;
  5584. }
  5585. var sx = m[0] * m[0] + m[1] * m[1];
  5586. var sy = m[2] * m[2] + m[3] * m[3];
  5587. var rotation = Math.atan2(m[1], m[0]);
  5588. var shearX = Math.PI / 2 + rotation - Math.atan2(m[3], m[2]);
  5589. sy = Math.sqrt(sy) * Math.cos(shearX);
  5590. sx = Math.sqrt(sx);
  5591. this.skewX = shearX;
  5592. this.skewY = 0;
  5593. this.rotation = -rotation;
  5594. this.x = +m[4];
  5595. this.y = +m[5];
  5596. this.scaleX = sx;
  5597. this.scaleY = sy;
  5598. this.originX = 0;
  5599. this.originY = 0;
  5600. };
  5601. Transformable.prototype.decomposeTransform = function () {
  5602. if (!this.transform) {
  5603. return;
  5604. }
  5605. var parent = this.parent;
  5606. var m = this.transform;
  5607. if (parent && parent.transform) {
  5608. parent.invTransform = parent.invTransform || create$1();
  5609. mul$1(tmpTransform, parent.invTransform, m);
  5610. m = tmpTransform;
  5611. }
  5612. var ox = this.originX;
  5613. var oy = this.originY;
  5614. if (ox || oy) {
  5615. originTransform[4] = ox;
  5616. originTransform[5] = oy;
  5617. mul$1(tmpTransform, m, originTransform);
  5618. tmpTransform[4] -= ox;
  5619. tmpTransform[5] -= oy;
  5620. m = tmpTransform;
  5621. }
  5622. this.setLocalTransform(m);
  5623. };
  5624. Transformable.prototype.getGlobalScale = function (out) {
  5625. var m = this.transform;
  5626. out = out || [];
  5627. if (!m) {
  5628. out[0] = 1;
  5629. out[1] = 1;
  5630. return out;
  5631. }
  5632. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  5633. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  5634. if (m[0] < 0) {
  5635. out[0] = -out[0];
  5636. }
  5637. if (m[3] < 0) {
  5638. out[1] = -out[1];
  5639. }
  5640. return out;
  5641. };
  5642. Transformable.prototype.transformCoordToLocal = function (x, y) {
  5643. var v2 = [x, y];
  5644. var invTransform = this.invTransform;
  5645. if (invTransform) {
  5646. applyTransform(v2, v2, invTransform);
  5647. }
  5648. return v2;
  5649. };
  5650. Transformable.prototype.transformCoordToGlobal = function (x, y) {
  5651. var v2 = [x, y];
  5652. var transform = this.transform;
  5653. if (transform) {
  5654. applyTransform(v2, v2, transform);
  5655. }
  5656. return v2;
  5657. };
  5658. Transformable.prototype.getLineScale = function () {
  5659. var m = this.transform;
  5660. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  5661. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  5662. : 1;
  5663. };
  5664. Transformable.prototype.copyTransform = function (source) {
  5665. copyTransform(this, source);
  5666. };
  5667. Transformable.getLocalTransform = function (target, m) {
  5668. m = m || [];
  5669. var ox = target.originX || 0;
  5670. var oy = target.originY || 0;
  5671. var sx = target.scaleX;
  5672. var sy = target.scaleY;
  5673. var ax = target.anchorX;
  5674. var ay = target.anchorY;
  5675. var rotation = target.rotation || 0;
  5676. var x = target.x;
  5677. var y = target.y;
  5678. var skewX = target.skewX ? Math.tan(target.skewX) : 0;
  5679. var skewY = target.skewY ? Math.tan(-target.skewY) : 0;
  5680. if (ox || oy || ax || ay) {
  5681. var dx = ox + ax;
  5682. var dy = oy + ay;
  5683. m[4] = -dx * sx - skewX * dy * sy;
  5684. m[5] = -dy * sy - skewY * dx * sx;
  5685. }
  5686. else {
  5687. m[4] = m[5] = 0;
  5688. }
  5689. m[0] = sx;
  5690. m[3] = sy;
  5691. m[1] = skewY * sx;
  5692. m[2] = skewX * sy;
  5693. rotation && rotate(m, m, rotation);
  5694. m[4] += ox + x;
  5695. m[5] += oy + y;
  5696. return m;
  5697. };
  5698. Transformable.initDefaultProps = (function () {
  5699. var proto = Transformable.prototype;
  5700. proto.scaleX =
  5701. proto.scaleY =
  5702. proto.globalScaleRatio = 1;
  5703. proto.x =
  5704. proto.y =
  5705. proto.originX =
  5706. proto.originY =
  5707. proto.skewX =
  5708. proto.skewY =
  5709. proto.rotation =
  5710. proto.anchorX =
  5711. proto.anchorY = 0;
  5712. })();
  5713. return Transformable;
  5714. }());
  5715. var TRANSFORMABLE_PROPS = [
  5716. 'x', 'y', 'originX', 'originY', 'anchorX', 'anchorY', 'rotation', 'scaleX', 'scaleY', 'skewX', 'skewY'
  5717. ];
  5718. function copyTransform(target, source) {
  5719. for (var i = 0; i < TRANSFORMABLE_PROPS.length; i++) {
  5720. var propName = TRANSFORMABLE_PROPS[i];
  5721. target[propName] = source[propName];
  5722. }
  5723. }
  5724. function ensureFontMeasureInfo(font) {
  5725. if (!_fontMeasureInfoCache) {
  5726. _fontMeasureInfoCache = new LRU(100);
  5727. }
  5728. font = font || DEFAULT_FONT;
  5729. var measureInfo = _fontMeasureInfoCache.get(font);
  5730. if (!measureInfo) {
  5731. measureInfo = {
  5732. font: font,
  5733. strWidthCache: new LRU(500),
  5734. asciiWidthMap: null,
  5735. asciiWidthMapTried: false,
  5736. stWideCharWidth: platformApi.measureText('国', font).width,
  5737. asciiCharWidth: platformApi.measureText('a', font).width,
  5738. };
  5739. _fontMeasureInfoCache.put(font, measureInfo);
  5740. }
  5741. return measureInfo;
  5742. }
  5743. var _fontMeasureInfoCache;
  5744. function tryCreateASCIIWidthMap(font) {
  5745. if (_getASCIIWidthMapLongCount >= GET_ASCII_WIDTH_LONG_COUNT_MAX) {
  5746. return;
  5747. }
  5748. font = font || DEFAULT_FONT;
  5749. var asciiWidthMap = [];
  5750. var start = +(new Date());
  5751. for (var code = 0; code <= 127; code++) {
  5752. asciiWidthMap[code] = platformApi.measureText(String.fromCharCode(code), font).width;
  5753. }
  5754. var cost = +(new Date()) - start;
  5755. if (cost > 16) {
  5756. _getASCIIWidthMapLongCount = GET_ASCII_WIDTH_LONG_COUNT_MAX;
  5757. }
  5758. else if (cost > 2) {
  5759. _getASCIIWidthMapLongCount++;
  5760. }
  5761. return asciiWidthMap;
  5762. }
  5763. var _getASCIIWidthMapLongCount = 0;
  5764. var GET_ASCII_WIDTH_LONG_COUNT_MAX = 5;
  5765. function measureCharWidth(fontMeasureInfo, charCode) {
  5766. if (!fontMeasureInfo.asciiWidthMapTried) {
  5767. fontMeasureInfo.asciiWidthMap = tryCreateASCIIWidthMap(fontMeasureInfo.font);
  5768. fontMeasureInfo.asciiWidthMapTried = true;
  5769. }
  5770. return (0 <= charCode && charCode <= 127)
  5771. ? (fontMeasureInfo.asciiWidthMap != null
  5772. ? fontMeasureInfo.asciiWidthMap[charCode]
  5773. : fontMeasureInfo.asciiCharWidth)
  5774. : fontMeasureInfo.stWideCharWidth;
  5775. }
  5776. function measureWidth(fontMeasureInfo, text) {
  5777. var strWidthCache = fontMeasureInfo.strWidthCache;
  5778. var width = strWidthCache.get(text);
  5779. if (width == null) {
  5780. width = platformApi.measureText(text, fontMeasureInfo.font).width;
  5781. strWidthCache.put(text, width);
  5782. }
  5783. return width;
  5784. }
  5785. function adjustTextX(x, width, textAlign, inverse) {
  5786. if (textAlign === 'right') {
  5787. !inverse ? (x -= width) : (x += width);
  5788. }
  5789. else if (textAlign === 'center') {
  5790. !inverse ? (x -= width / 2) : (x += width / 2);
  5791. }
  5792. return x;
  5793. }
  5794. function adjustTextY$1(y, height, verticalAlign, inverse) {
  5795. if (verticalAlign === 'middle') {
  5796. !inverse ? (y -= height / 2) : (y += height / 2);
  5797. }
  5798. else if (verticalAlign === 'bottom') {
  5799. !inverse ? (y -= height) : (y += height);
  5800. }
  5801. return y;
  5802. }
  5803. function getLineHeight(font) {
  5804. return ensureFontMeasureInfo(font).stWideCharWidth;
  5805. }
  5806. function parsePercent(value, maxValue) {
  5807. if (typeof value === 'string') {
  5808. if (value.lastIndexOf('%') >= 0) {
  5809. return parseFloat(value) / 100 * maxValue;
  5810. }
  5811. return parseFloat(value);
  5812. }
  5813. return value;
  5814. }
  5815. function calculateTextPosition(out, opts, rect) {
  5816. var textPosition = opts.position || 'inside';
  5817. var distance = opts.distance != null ? opts.distance : 5;
  5818. var height = rect.height;
  5819. var width = rect.width;
  5820. var halfHeight = height / 2;
  5821. var x = rect.x;
  5822. var y = rect.y;
  5823. var textAlign = 'left';
  5824. var textVerticalAlign = 'top';
  5825. if (textPosition instanceof Array) {
  5826. x += parsePercent(textPosition[0], rect.width);
  5827. y += parsePercent(textPosition[1], rect.height);
  5828. textAlign = null;
  5829. textVerticalAlign = null;
  5830. }
  5831. else {
  5832. switch (textPosition) {
  5833. case 'left':
  5834. x -= distance;
  5835. y += halfHeight;
  5836. textAlign = 'right';
  5837. textVerticalAlign = 'middle';
  5838. break;
  5839. case 'right':
  5840. x += distance + width;
  5841. y += halfHeight;
  5842. textVerticalAlign = 'middle';
  5843. break;
  5844. case 'top':
  5845. x += width / 2;
  5846. y -= distance;
  5847. textAlign = 'center';
  5848. textVerticalAlign = 'bottom';
  5849. break;
  5850. case 'bottom':
  5851. x += width / 2;
  5852. y += height + distance;
  5853. textAlign = 'center';
  5854. break;
  5855. case 'inside':
  5856. x += width / 2;
  5857. y += halfHeight;
  5858. textAlign = 'center';
  5859. textVerticalAlign = 'middle';
  5860. break;
  5861. case 'insideLeft':
  5862. x += distance;
  5863. y += halfHeight;
  5864. textVerticalAlign = 'middle';
  5865. break;
  5866. case 'insideRight':
  5867. x += width - distance;
  5868. y += halfHeight;
  5869. textAlign = 'right';
  5870. textVerticalAlign = 'middle';
  5871. break;
  5872. case 'insideTop':
  5873. x += width / 2;
  5874. y += distance;
  5875. textAlign = 'center';
  5876. break;
  5877. case 'insideBottom':
  5878. x += width / 2;
  5879. y += height - distance;
  5880. textAlign = 'center';
  5881. textVerticalAlign = 'bottom';
  5882. break;
  5883. case 'insideTopLeft':
  5884. x += distance;
  5885. y += distance;
  5886. break;
  5887. case 'insideTopRight':
  5888. x += width - distance;
  5889. y += distance;
  5890. textAlign = 'right';
  5891. break;
  5892. case 'insideBottomLeft':
  5893. x += distance;
  5894. y += height - distance;
  5895. textVerticalAlign = 'bottom';
  5896. break;
  5897. case 'insideBottomRight':
  5898. x += width - distance;
  5899. y += height - distance;
  5900. textAlign = 'right';
  5901. textVerticalAlign = 'bottom';
  5902. break;
  5903. }
  5904. }
  5905. out = out || {};
  5906. out.x = x;
  5907. out.y = y;
  5908. out.align = textAlign;
  5909. out.verticalAlign = textVerticalAlign;
  5910. return out;
  5911. }
  5912. var PRESERVED_NORMAL_STATE = '__zr_normal__';
  5913. var PRIMARY_STATES_KEYS = TRANSFORMABLE_PROPS.concat(['ignore']);
  5914. var DEFAULT_ANIMATABLE_MAP = reduce(TRANSFORMABLE_PROPS, function (obj, key) {
  5915. obj[key] = true;
  5916. return obj;
  5917. }, { ignore: false });
  5918. var tmpTextPosCalcRes = {};
  5919. var tmpBoundingRect = new BoundingRect(0, 0, 0, 0);
  5920. var tmpInnerTextTrans = [];
  5921. var Element = (function () {
  5922. function Element(props) {
  5923. this.id = guid();
  5924. this.animators = [];
  5925. this.currentStates = [];
  5926. this.states = {};
  5927. this._init(props);
  5928. }
  5929. Element.prototype._init = function (props) {
  5930. this.attr(props);
  5931. };
  5932. Element.prototype.drift = function (dx, dy, e) {
  5933. switch (this.draggable) {
  5934. case 'horizontal':
  5935. dy = 0;
  5936. break;
  5937. case 'vertical':
  5938. dx = 0;
  5939. break;
  5940. }
  5941. var m = this.transform;
  5942. if (!m) {
  5943. m = this.transform = [1, 0, 0, 1, 0, 0];
  5944. }
  5945. m[4] += dx;
  5946. m[5] += dy;
  5947. this.decomposeTransform();
  5948. this.markRedraw();
  5949. };
  5950. Element.prototype.beforeUpdate = function () { };
  5951. Element.prototype.afterUpdate = function () { };
  5952. Element.prototype.update = function () {
  5953. this.updateTransform();
  5954. if (this.__dirty) {
  5955. this.updateInnerText();
  5956. }
  5957. };
  5958. Element.prototype.updateInnerText = function (forceUpdate) {
  5959. var textEl = this._textContent;
  5960. if (textEl && (!textEl.ignore || forceUpdate)) {
  5961. if (!this.textConfig) {
  5962. this.textConfig = {};
  5963. }
  5964. var textConfig = this.textConfig;
  5965. var isLocal = textConfig.local;
  5966. var innerTransformable = textEl.innerTransformable;
  5967. var textAlign = void 0;
  5968. var textVerticalAlign = void 0;
  5969. var textStyleChanged = false;
  5970. innerTransformable.parent = isLocal ? this : null;
  5971. var innerOrigin = false;
  5972. innerTransformable.copyTransform(textEl);
  5973. var hasPosition = textConfig.position != null;
  5974. var autoOverflowArea = textConfig.autoOverflowArea;
  5975. var layoutRect = void 0;
  5976. if (autoOverflowArea || hasPosition) {
  5977. layoutRect = tmpBoundingRect;
  5978. if (textConfig.layoutRect) {
  5979. layoutRect.copy(textConfig.layoutRect);
  5980. }
  5981. else {
  5982. layoutRect.copy(this.getBoundingRect());
  5983. }
  5984. if (!isLocal) {
  5985. layoutRect.applyTransform(this.transform);
  5986. }
  5987. }
  5988. if (hasPosition) {
  5989. if (this.calculateTextPosition) {
  5990. this.calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5991. }
  5992. else {
  5993. calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  5994. }
  5995. innerTransformable.x = tmpTextPosCalcRes.x;
  5996. innerTransformable.y = tmpTextPosCalcRes.y;
  5997. textAlign = tmpTextPosCalcRes.align;
  5998. textVerticalAlign = tmpTextPosCalcRes.verticalAlign;
  5999. var textOrigin = textConfig.origin;
  6000. if (textOrigin && textConfig.rotation != null) {
  6001. var relOriginX = void 0;
  6002. var relOriginY = void 0;
  6003. if (textOrigin === 'center') {
  6004. relOriginX = layoutRect.width * 0.5;
  6005. relOriginY = layoutRect.height * 0.5;
  6006. }
  6007. else {
  6008. relOriginX = parsePercent(textOrigin[0], layoutRect.width);
  6009. relOriginY = parsePercent(textOrigin[1], layoutRect.height);
  6010. }
  6011. innerOrigin = true;
  6012. innerTransformable.originX = -innerTransformable.x + relOriginX + (isLocal ? 0 : layoutRect.x);
  6013. innerTransformable.originY = -innerTransformable.y + relOriginY + (isLocal ? 0 : layoutRect.y);
  6014. }
  6015. }
  6016. if (textConfig.rotation != null) {
  6017. innerTransformable.rotation = textConfig.rotation;
  6018. }
  6019. var textOffset = textConfig.offset;
  6020. if (textOffset) {
  6021. innerTransformable.x += textOffset[0];
  6022. innerTransformable.y += textOffset[1];
  6023. if (!innerOrigin) {
  6024. innerTransformable.originX = -textOffset[0];
  6025. innerTransformable.originY = -textOffset[1];
  6026. }
  6027. }
  6028. var innerTextDefaultStyle = this._innerTextDefaultStyle || (this._innerTextDefaultStyle = {});
  6029. if (autoOverflowArea) {
  6030. var overflowRect = innerTextDefaultStyle.overflowRect =
  6031. innerTextDefaultStyle.overflowRect || new BoundingRect(0, 0, 0, 0);
  6032. innerTransformable.getLocalTransform(tmpInnerTextTrans);
  6033. invert(tmpInnerTextTrans, tmpInnerTextTrans);
  6034. BoundingRect.copy(overflowRect, layoutRect);
  6035. overflowRect.applyTransform(tmpInnerTextTrans);
  6036. }
  6037. else {
  6038. innerTextDefaultStyle.overflowRect = null;
  6039. }
  6040. var isInside = textConfig.inside == null
  6041. ? (typeof textConfig.position === 'string' && textConfig.position.indexOf('inside') >= 0)
  6042. : textConfig.inside;
  6043. var textFill = void 0;
  6044. var textStroke = void 0;
  6045. var autoStroke = void 0;
  6046. if (isInside && this.canBeInsideText()) {
  6047. textFill = textConfig.insideFill;
  6048. textStroke = textConfig.insideStroke;
  6049. if (textFill == null || textFill === 'auto') {
  6050. textFill = this.getInsideTextFill();
  6051. }
  6052. if (textStroke == null || textStroke === 'auto') {
  6053. textStroke = this.getInsideTextStroke(textFill);
  6054. autoStroke = true;
  6055. }
  6056. }
  6057. else {
  6058. textFill = textConfig.outsideFill;
  6059. textStroke = textConfig.outsideStroke;
  6060. if (textFill == null || textFill === 'auto') {
  6061. textFill = this.getOutsideFill();
  6062. }
  6063. if (textStroke == null || textStroke === 'auto') {
  6064. textStroke = this.getOutsideStroke(textFill);
  6065. autoStroke = true;
  6066. }
  6067. }
  6068. textFill = textFill || '#000';
  6069. if (textFill !== innerTextDefaultStyle.fill
  6070. || textStroke !== innerTextDefaultStyle.stroke
  6071. || autoStroke !== innerTextDefaultStyle.autoStroke
  6072. || textAlign !== innerTextDefaultStyle.align
  6073. || textVerticalAlign !== innerTextDefaultStyle.verticalAlign) {
  6074. textStyleChanged = true;
  6075. innerTextDefaultStyle.fill = textFill;
  6076. innerTextDefaultStyle.stroke = textStroke;
  6077. innerTextDefaultStyle.autoStroke = autoStroke;
  6078. innerTextDefaultStyle.align = textAlign;
  6079. innerTextDefaultStyle.verticalAlign = textVerticalAlign;
  6080. textEl.setDefaultTextStyle(innerTextDefaultStyle);
  6081. }
  6082. textEl.__dirty |= REDRAW_BIT;
  6083. if (textStyleChanged) {
  6084. textEl.dirtyStyle(true);
  6085. }
  6086. }
  6087. };
  6088. Element.prototype.canBeInsideText = function () {
  6089. return true;
  6090. };
  6091. Element.prototype.getInsideTextFill = function () {
  6092. return '#fff';
  6093. };
  6094. Element.prototype.getInsideTextStroke = function (textFill) {
  6095. return '#000';
  6096. };
  6097. Element.prototype.getOutsideFill = function () {
  6098. return this.__zr && this.__zr.isDarkMode() ? LIGHT_LABEL_COLOR : DARK_LABEL_COLOR;
  6099. };
  6100. Element.prototype.getOutsideStroke = function (textFill) {
  6101. var backgroundColor = this.__zr && this.__zr.getBackgroundColor();
  6102. var colorArr = typeof backgroundColor === 'string' && parse(backgroundColor);
  6103. if (!colorArr) {
  6104. colorArr = [255, 255, 255, 1];
  6105. }
  6106. var alpha = colorArr[3];
  6107. var isDark = this.__zr.isDarkMode();
  6108. for (var i = 0; i < 3; i++) {
  6109. colorArr[i] = colorArr[i] * alpha + (isDark ? 0 : 255) * (1 - alpha);
  6110. }
  6111. colorArr[3] = 1;
  6112. return stringify(colorArr, 'rgba');
  6113. };
  6114. Element.prototype.traverse = function (cb, context) { };
  6115. Element.prototype.attrKV = function (key, value) {
  6116. if (key === 'textConfig') {
  6117. this.setTextConfig(value);
  6118. }
  6119. else if (key === 'textContent') {
  6120. this.setTextContent(value);
  6121. }
  6122. else if (key === 'clipPath') {
  6123. this.setClipPath(value);
  6124. }
  6125. else if (key === 'extra') {
  6126. this.extra = this.extra || {};
  6127. extend(this.extra, value);
  6128. }
  6129. else {
  6130. this[key] = value;
  6131. }
  6132. };
  6133. Element.prototype.hide = function () {
  6134. this.ignore = true;
  6135. this.markRedraw();
  6136. };
  6137. Element.prototype.show = function () {
  6138. this.ignore = false;
  6139. this.markRedraw();
  6140. };
  6141. Element.prototype.attr = function (keyOrObj, value) {
  6142. if (typeof keyOrObj === 'string') {
  6143. this.attrKV(keyOrObj, value);
  6144. }
  6145. else if (isObject(keyOrObj)) {
  6146. var obj = keyOrObj;
  6147. var keysArr = keys(obj);
  6148. for (var i = 0; i < keysArr.length; i++) {
  6149. var key = keysArr[i];
  6150. this.attrKV(key, keyOrObj[key]);
  6151. }
  6152. }
  6153. this.markRedraw();
  6154. return this;
  6155. };
  6156. Element.prototype.saveCurrentToNormalState = function (toState) {
  6157. this._innerSaveToNormal(toState);
  6158. var normalState = this._normalState;
  6159. for (var i = 0; i < this.animators.length; i++) {
  6160. var animator = this.animators[i];
  6161. var fromStateTransition = animator.__fromStateTransition;
  6162. if (animator.getLoop() || fromStateTransition && fromStateTransition !== PRESERVED_NORMAL_STATE) {
  6163. continue;
  6164. }
  6165. var targetName = animator.targetName;
  6166. var target = targetName
  6167. ? normalState[targetName] : normalState;
  6168. animator.saveTo(target);
  6169. }
  6170. };
  6171. Element.prototype._innerSaveToNormal = function (toState) {
  6172. var normalState = this._normalState;
  6173. if (!normalState) {
  6174. normalState = this._normalState = {};
  6175. }
  6176. if (toState.textConfig && !normalState.textConfig) {
  6177. normalState.textConfig = this.textConfig;
  6178. }
  6179. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS);
  6180. };
  6181. Element.prototype._savePrimaryToNormal = function (toState, normalState, primaryKeys) {
  6182. for (var i = 0; i < primaryKeys.length; i++) {
  6183. var key = primaryKeys[i];
  6184. if (toState[key] != null && !(key in normalState)) {
  6185. normalState[key] = this[key];
  6186. }
  6187. }
  6188. };
  6189. Element.prototype.hasState = function () {
  6190. return this.currentStates.length > 0;
  6191. };
  6192. Element.prototype.getState = function (name) {
  6193. return this.states[name];
  6194. };
  6195. Element.prototype.ensureState = function (name) {
  6196. var states = this.states;
  6197. if (!states[name]) {
  6198. states[name] = {};
  6199. }
  6200. return states[name];
  6201. };
  6202. Element.prototype.clearStates = function (noAnimation) {
  6203. this.useState(PRESERVED_NORMAL_STATE, false, noAnimation);
  6204. };
  6205. Element.prototype.useState = function (stateName, keepCurrentStates, noAnimation, forceUseHoverLayer) {
  6206. var toNormalState = stateName === PRESERVED_NORMAL_STATE;
  6207. var hasStates = this.hasState();
  6208. if (!hasStates && toNormalState) {
  6209. return;
  6210. }
  6211. var currentStates = this.currentStates;
  6212. var animationCfg = this.stateTransition;
  6213. if (indexOf(currentStates, stateName) >= 0 && (keepCurrentStates || currentStates.length === 1)) {
  6214. return;
  6215. }
  6216. var state;
  6217. if (this.stateProxy && !toNormalState) {
  6218. state = this.stateProxy(stateName);
  6219. }
  6220. if (!state) {
  6221. state = (this.states && this.states[stateName]);
  6222. }
  6223. if (!state && !toNormalState) {
  6224. logError("State " + stateName + " not exists.");
  6225. return;
  6226. }
  6227. if (!toNormalState) {
  6228. this.saveCurrentToNormalState(state);
  6229. }
  6230. var useHoverLayer = !!((state && state.hoverLayer) || forceUseHoverLayer);
  6231. if (useHoverLayer) {
  6232. this._toggleHoverLayerFlag(true);
  6233. }
  6234. this._applyStateObj(stateName, state, this._normalState, keepCurrentStates, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6235. var textContent = this._textContent;
  6236. var textGuide = this._textGuide;
  6237. if (textContent) {
  6238. textContent.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6239. }
  6240. if (textGuide) {
  6241. textGuide.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6242. }
  6243. if (toNormalState) {
  6244. this.currentStates = [];
  6245. this._normalState = {};
  6246. }
  6247. else {
  6248. if (!keepCurrentStates) {
  6249. this.currentStates = [stateName];
  6250. }
  6251. else {
  6252. this.currentStates.push(stateName);
  6253. }
  6254. }
  6255. this._updateAnimationTargets();
  6256. this.markRedraw();
  6257. if (!useHoverLayer && this.__inHover) {
  6258. this._toggleHoverLayerFlag(false);
  6259. this.__dirty &= ~REDRAW_BIT;
  6260. }
  6261. return state;
  6262. };
  6263. Element.prototype.useStates = function (states, noAnimation, forceUseHoverLayer) {
  6264. if (!states.length) {
  6265. this.clearStates();
  6266. }
  6267. else {
  6268. var stateObjects = [];
  6269. var currentStates = this.currentStates;
  6270. var len = states.length;
  6271. var notChange = len === currentStates.length;
  6272. if (notChange) {
  6273. for (var i = 0; i < len; i++) {
  6274. if (states[i] !== currentStates[i]) {
  6275. notChange = false;
  6276. break;
  6277. }
  6278. }
  6279. }
  6280. if (notChange) {
  6281. return;
  6282. }
  6283. for (var i = 0; i < len; i++) {
  6284. var stateName = states[i];
  6285. var stateObj = void 0;
  6286. if (this.stateProxy) {
  6287. stateObj = this.stateProxy(stateName, states);
  6288. }
  6289. if (!stateObj) {
  6290. stateObj = this.states[stateName];
  6291. }
  6292. if (stateObj) {
  6293. stateObjects.push(stateObj);
  6294. }
  6295. }
  6296. var lastStateObj = stateObjects[len - 1];
  6297. var useHoverLayer = !!((lastStateObj && lastStateObj.hoverLayer) || forceUseHoverLayer);
  6298. if (useHoverLayer) {
  6299. this._toggleHoverLayerFlag(true);
  6300. }
  6301. var mergedState = this._mergeStates(stateObjects);
  6302. var animationCfg = this.stateTransition;
  6303. this.saveCurrentToNormalState(mergedState);
  6304. this._applyStateObj(states.join(','), mergedState, this._normalState, false, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6305. var textContent = this._textContent;
  6306. var textGuide = this._textGuide;
  6307. if (textContent) {
  6308. textContent.useStates(states, noAnimation, useHoverLayer);
  6309. }
  6310. if (textGuide) {
  6311. textGuide.useStates(states, noAnimation, useHoverLayer);
  6312. }
  6313. this._updateAnimationTargets();
  6314. this.currentStates = states.slice();
  6315. this.markRedraw();
  6316. if (!useHoverLayer && this.__inHover) {
  6317. this._toggleHoverLayerFlag(false);
  6318. this.__dirty &= ~REDRAW_BIT;
  6319. }
  6320. }
  6321. };
  6322. Element.prototype.isSilent = function () {
  6323. var el = this;
  6324. while (el) {
  6325. if (el.silent) {
  6326. return true;
  6327. }
  6328. var hostEl = el.__hostTarget;
  6329. el = hostEl ? (el.ignoreHostSilent ? null : hostEl) : el.parent;
  6330. }
  6331. return false;
  6332. };
  6333. Element.prototype._updateAnimationTargets = function () {
  6334. for (var i = 0; i < this.animators.length; i++) {
  6335. var animator = this.animators[i];
  6336. if (animator.targetName) {
  6337. animator.changeTarget(this[animator.targetName]);
  6338. }
  6339. }
  6340. };
  6341. Element.prototype.removeState = function (state) {
  6342. var idx = indexOf(this.currentStates, state);
  6343. if (idx >= 0) {
  6344. var currentStates = this.currentStates.slice();
  6345. currentStates.splice(idx, 1);
  6346. this.useStates(currentStates);
  6347. }
  6348. };
  6349. Element.prototype.replaceState = function (oldState, newState, forceAdd) {
  6350. var currentStates = this.currentStates.slice();
  6351. var idx = indexOf(currentStates, oldState);
  6352. var newStateExists = indexOf(currentStates, newState) >= 0;
  6353. if (idx >= 0) {
  6354. if (!newStateExists) {
  6355. currentStates[idx] = newState;
  6356. }
  6357. else {
  6358. currentStates.splice(idx, 1);
  6359. }
  6360. }
  6361. else if (forceAdd && !newStateExists) {
  6362. currentStates.push(newState);
  6363. }
  6364. this.useStates(currentStates);
  6365. };
  6366. Element.prototype.toggleState = function (state, enable) {
  6367. if (enable) {
  6368. this.useState(state, true);
  6369. }
  6370. else {
  6371. this.removeState(state);
  6372. }
  6373. };
  6374. Element.prototype._mergeStates = function (states) {
  6375. var mergedState = {};
  6376. var mergedTextConfig;
  6377. for (var i = 0; i < states.length; i++) {
  6378. var state = states[i];
  6379. extend(mergedState, state);
  6380. if (state.textConfig) {
  6381. mergedTextConfig = mergedTextConfig || {};
  6382. extend(mergedTextConfig, state.textConfig);
  6383. }
  6384. }
  6385. if (mergedTextConfig) {
  6386. mergedState.textConfig = mergedTextConfig;
  6387. }
  6388. return mergedState;
  6389. };
  6390. Element.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  6391. var needsRestoreToNormal = !(state && keepCurrentStates);
  6392. if (state && state.textConfig) {
  6393. this.textConfig = extend({}, keepCurrentStates ? this.textConfig : normalState.textConfig);
  6394. extend(this.textConfig, state.textConfig);
  6395. }
  6396. else if (needsRestoreToNormal) {
  6397. if (normalState.textConfig) {
  6398. this.textConfig = normalState.textConfig;
  6399. }
  6400. }
  6401. var transitionTarget = {};
  6402. var hasTransition = false;
  6403. for (var i = 0; i < PRIMARY_STATES_KEYS.length; i++) {
  6404. var key = PRIMARY_STATES_KEYS[i];
  6405. var propNeedsTransition = transition && DEFAULT_ANIMATABLE_MAP[key];
  6406. if (state && state[key] != null) {
  6407. if (propNeedsTransition) {
  6408. hasTransition = true;
  6409. transitionTarget[key] = state[key];
  6410. }
  6411. else {
  6412. this[key] = state[key];
  6413. }
  6414. }
  6415. else if (needsRestoreToNormal) {
  6416. if (normalState[key] != null) {
  6417. if (propNeedsTransition) {
  6418. hasTransition = true;
  6419. transitionTarget[key] = normalState[key];
  6420. }
  6421. else {
  6422. this[key] = normalState[key];
  6423. }
  6424. }
  6425. }
  6426. }
  6427. if (!transition) {
  6428. for (var i = 0; i < this.animators.length; i++) {
  6429. var animator = this.animators[i];
  6430. var targetName = animator.targetName;
  6431. if (!animator.getLoop()) {
  6432. animator.__changeFinalValue(targetName
  6433. ? (state || normalState)[targetName]
  6434. : (state || normalState));
  6435. }
  6436. }
  6437. }
  6438. if (hasTransition) {
  6439. this._transitionState(stateName, transitionTarget, animationCfg);
  6440. }
  6441. };
  6442. Element.prototype._attachComponent = function (componentEl) {
  6443. if (componentEl.__zr && !componentEl.__hostTarget) {
  6444. {
  6445. throw new Error('Text element has been added to zrender.');
  6446. }
  6447. }
  6448. if (componentEl === this) {
  6449. {
  6450. throw new Error('Recursive component attachment.');
  6451. }
  6452. }
  6453. var zr = this.__zr;
  6454. if (zr) {
  6455. componentEl.addSelfToZr(zr);
  6456. }
  6457. componentEl.__zr = zr;
  6458. componentEl.__hostTarget = this;
  6459. };
  6460. Element.prototype._detachComponent = function (componentEl) {
  6461. if (componentEl.__zr) {
  6462. componentEl.removeSelfFromZr(componentEl.__zr);
  6463. }
  6464. componentEl.__zr = null;
  6465. componentEl.__hostTarget = null;
  6466. };
  6467. Element.prototype.getClipPath = function () {
  6468. return this._clipPath;
  6469. };
  6470. Element.prototype.setClipPath = function (clipPath) {
  6471. if (this._clipPath && this._clipPath !== clipPath) {
  6472. this.removeClipPath();
  6473. }
  6474. this._attachComponent(clipPath);
  6475. this._clipPath = clipPath;
  6476. this.markRedraw();
  6477. };
  6478. Element.prototype.removeClipPath = function () {
  6479. var clipPath = this._clipPath;
  6480. if (clipPath) {
  6481. this._detachComponent(clipPath);
  6482. this._clipPath = null;
  6483. this.markRedraw();
  6484. }
  6485. };
  6486. Element.prototype.getTextContent = function () {
  6487. return this._textContent;
  6488. };
  6489. Element.prototype.setTextContent = function (textEl) {
  6490. var previousTextContent = this._textContent;
  6491. if (previousTextContent === textEl) {
  6492. return;
  6493. }
  6494. if (previousTextContent && previousTextContent !== textEl) {
  6495. this.removeTextContent();
  6496. }
  6497. {
  6498. if (textEl.__zr && !textEl.__hostTarget) {
  6499. throw new Error('Text element has been added to zrender.');
  6500. }
  6501. }
  6502. textEl.innerTransformable = new Transformable();
  6503. this._attachComponent(textEl);
  6504. this._textContent = textEl;
  6505. this.markRedraw();
  6506. };
  6507. Element.prototype.setTextConfig = function (cfg) {
  6508. if (!this.textConfig) {
  6509. this.textConfig = {};
  6510. }
  6511. extend(this.textConfig, cfg);
  6512. this.markRedraw();
  6513. };
  6514. Element.prototype.removeTextConfig = function () {
  6515. this.textConfig = null;
  6516. this.markRedraw();
  6517. };
  6518. Element.prototype.removeTextContent = function () {
  6519. var textEl = this._textContent;
  6520. if (textEl) {
  6521. textEl.innerTransformable = null;
  6522. this._detachComponent(textEl);
  6523. this._textContent = null;
  6524. this._innerTextDefaultStyle = null;
  6525. this.markRedraw();
  6526. }
  6527. };
  6528. Element.prototype.getTextGuideLine = function () {
  6529. return this._textGuide;
  6530. };
  6531. Element.prototype.setTextGuideLine = function (guideLine) {
  6532. if (this._textGuide && this._textGuide !== guideLine) {
  6533. this.removeTextGuideLine();
  6534. }
  6535. this._attachComponent(guideLine);
  6536. this._textGuide = guideLine;
  6537. this.markRedraw();
  6538. };
  6539. Element.prototype.removeTextGuideLine = function () {
  6540. var textGuide = this._textGuide;
  6541. if (textGuide) {
  6542. this._detachComponent(textGuide);
  6543. this._textGuide = null;
  6544. this.markRedraw();
  6545. }
  6546. };
  6547. Element.prototype.markRedraw = function () {
  6548. this.__dirty |= REDRAW_BIT;
  6549. var zr = this.__zr;
  6550. if (zr) {
  6551. if (this.__inHover) {
  6552. zr.refreshHover();
  6553. }
  6554. else {
  6555. zr.refresh();
  6556. }
  6557. }
  6558. if (this.__hostTarget) {
  6559. this.__hostTarget.markRedraw();
  6560. }
  6561. };
  6562. Element.prototype.dirty = function () {
  6563. this.markRedraw();
  6564. };
  6565. Element.prototype._toggleHoverLayerFlag = function (inHover) {
  6566. this.__inHover = inHover;
  6567. var textContent = this._textContent;
  6568. var textGuide = this._textGuide;
  6569. if (textContent) {
  6570. textContent.__inHover = inHover;
  6571. }
  6572. if (textGuide) {
  6573. textGuide.__inHover = inHover;
  6574. }
  6575. };
  6576. Element.prototype.addSelfToZr = function (zr) {
  6577. if (this.__zr === zr) {
  6578. return;
  6579. }
  6580. this.__zr = zr;
  6581. var animators = this.animators;
  6582. if (animators) {
  6583. for (var i = 0; i < animators.length; i++) {
  6584. zr.animation.addAnimator(animators[i]);
  6585. }
  6586. }
  6587. if (this._clipPath) {
  6588. this._clipPath.addSelfToZr(zr);
  6589. }
  6590. if (this._textContent) {
  6591. this._textContent.addSelfToZr(zr);
  6592. }
  6593. if (this._textGuide) {
  6594. this._textGuide.addSelfToZr(zr);
  6595. }
  6596. };
  6597. Element.prototype.removeSelfFromZr = function (zr) {
  6598. if (!this.__zr) {
  6599. return;
  6600. }
  6601. this.__zr = null;
  6602. var animators = this.animators;
  6603. if (animators) {
  6604. for (var i = 0; i < animators.length; i++) {
  6605. zr.animation.removeAnimator(animators[i]);
  6606. }
  6607. }
  6608. if (this._clipPath) {
  6609. this._clipPath.removeSelfFromZr(zr);
  6610. }
  6611. if (this._textContent) {
  6612. this._textContent.removeSelfFromZr(zr);
  6613. }
  6614. if (this._textGuide) {
  6615. this._textGuide.removeSelfFromZr(zr);
  6616. }
  6617. };
  6618. Element.prototype.animate = function (key, loop, allowDiscreteAnimation) {
  6619. var target = key ? this[key] : this;
  6620. {
  6621. if (!target) {
  6622. logError('Property "'
  6623. + key
  6624. + '" is not existed in element '
  6625. + this.id);
  6626. return;
  6627. }
  6628. }
  6629. var animator = new Animator(target, loop, allowDiscreteAnimation);
  6630. key && (animator.targetName = key);
  6631. this.addAnimator(animator, key);
  6632. return animator;
  6633. };
  6634. Element.prototype.addAnimator = function (animator, key) {
  6635. var zr = this.__zr;
  6636. var el = this;
  6637. animator.during(function () {
  6638. el.updateDuringAnimation(key);
  6639. }).done(function () {
  6640. var animators = el.animators;
  6641. var idx = indexOf(animators, animator);
  6642. if (idx >= 0) {
  6643. animators.splice(idx, 1);
  6644. }
  6645. });
  6646. this.animators.push(animator);
  6647. if (zr) {
  6648. zr.animation.addAnimator(animator);
  6649. }
  6650. zr && zr.wakeUp();
  6651. };
  6652. Element.prototype.updateDuringAnimation = function (key) {
  6653. this.markRedraw();
  6654. };
  6655. Element.prototype.stopAnimation = function (scope, forwardToLast) {
  6656. var animators = this.animators;
  6657. var len = animators.length;
  6658. var leftAnimators = [];
  6659. for (var i = 0; i < len; i++) {
  6660. var animator = animators[i];
  6661. if (!scope || scope === animator.scope) {
  6662. animator.stop(forwardToLast);
  6663. }
  6664. else {
  6665. leftAnimators.push(animator);
  6666. }
  6667. }
  6668. this.animators = leftAnimators;
  6669. return this;
  6670. };
  6671. Element.prototype.animateTo = function (target, cfg, animationProps) {
  6672. animateTo(this, target, cfg, animationProps);
  6673. };
  6674. Element.prototype.animateFrom = function (target, cfg, animationProps) {
  6675. animateTo(this, target, cfg, animationProps, true);
  6676. };
  6677. Element.prototype._transitionState = function (stateName, target, cfg, animationProps) {
  6678. var animators = animateTo(this, target, cfg, animationProps);
  6679. for (var i = 0; i < animators.length; i++) {
  6680. animators[i].__fromStateTransition = stateName;
  6681. }
  6682. };
  6683. Element.prototype.getBoundingRect = function () {
  6684. return null;
  6685. };
  6686. Element.prototype.getPaintRect = function () {
  6687. return null;
  6688. };
  6689. Element.initDefaultProps = (function () {
  6690. var elProto = Element.prototype;
  6691. elProto.type = 'element';
  6692. elProto.name = '';
  6693. elProto.ignore =
  6694. elProto.silent =
  6695. elProto.ignoreHostSilent =
  6696. elProto.isGroup =
  6697. elProto.draggable =
  6698. elProto.dragging =
  6699. elProto.ignoreClip =
  6700. elProto.__inHover = false;
  6701. elProto.__dirty = REDRAW_BIT;
  6702. var logs = {};
  6703. function logDeprecatedError(key, xKey, yKey) {
  6704. if (!logs[key + xKey + yKey]) {
  6705. console.warn("DEPRECATED: '" + key + "' has been deprecated. use '" + xKey + "', '" + yKey + "' instead");
  6706. logs[key + xKey + yKey] = true;
  6707. }
  6708. }
  6709. function createLegacyProperty(key, privateKey, xKey, yKey) {
  6710. Object.defineProperty(elProto, key, {
  6711. get: function () {
  6712. {
  6713. logDeprecatedError(key, xKey, yKey);
  6714. }
  6715. if (!this[privateKey]) {
  6716. var pos = this[privateKey] = [];
  6717. enhanceArray(this, pos);
  6718. }
  6719. return this[privateKey];
  6720. },
  6721. set: function (pos) {
  6722. {
  6723. logDeprecatedError(key, xKey, yKey);
  6724. }
  6725. this[xKey] = pos[0];
  6726. this[yKey] = pos[1];
  6727. this[privateKey] = pos;
  6728. enhanceArray(this, pos);
  6729. }
  6730. });
  6731. function enhanceArray(self, pos) {
  6732. Object.defineProperty(pos, 0, {
  6733. get: function () {
  6734. return self[xKey];
  6735. },
  6736. set: function (val) {
  6737. self[xKey] = val;
  6738. }
  6739. });
  6740. Object.defineProperty(pos, 1, {
  6741. get: function () {
  6742. return self[yKey];
  6743. },
  6744. set: function (val) {
  6745. self[yKey] = val;
  6746. }
  6747. });
  6748. }
  6749. }
  6750. if (Object.defineProperty) {
  6751. createLegacyProperty('position', '_legacyPos', 'x', 'y');
  6752. createLegacyProperty('scale', '_legacyScale', 'scaleX', 'scaleY');
  6753. createLegacyProperty('origin', '_legacyOrigin', 'originX', 'originY');
  6754. }
  6755. })();
  6756. return Element;
  6757. }());
  6758. mixin(Element, Eventful);
  6759. mixin(Element, Transformable);
  6760. function animateTo(animatable, target, cfg, animationProps, reverse) {
  6761. cfg = cfg || {};
  6762. var animators = [];
  6763. animateToShallow(animatable, '', animatable, target, cfg, animationProps, animators, reverse);
  6764. var finishCount = animators.length;
  6765. var doneHappened = false;
  6766. var cfgDone = cfg.done;
  6767. var cfgAborted = cfg.aborted;
  6768. var doneCb = function () {
  6769. doneHappened = true;
  6770. finishCount--;
  6771. if (finishCount <= 0) {
  6772. doneHappened
  6773. ? (cfgDone && cfgDone())
  6774. : (cfgAborted && cfgAborted());
  6775. }
  6776. };
  6777. var abortedCb = function () {
  6778. finishCount--;
  6779. if (finishCount <= 0) {
  6780. doneHappened
  6781. ? (cfgDone && cfgDone())
  6782. : (cfgAborted && cfgAborted());
  6783. }
  6784. };
  6785. if (!finishCount) {
  6786. cfgDone && cfgDone();
  6787. }
  6788. if (animators.length > 0 && cfg.during) {
  6789. animators[0].during(function (target, percent) {
  6790. cfg.during(percent);
  6791. });
  6792. }
  6793. for (var i = 0; i < animators.length; i++) {
  6794. var animator = animators[i];
  6795. if (doneCb) {
  6796. animator.done(doneCb);
  6797. }
  6798. if (abortedCb) {
  6799. animator.aborted(abortedCb);
  6800. }
  6801. if (cfg.force) {
  6802. animator.duration(cfg.duration);
  6803. }
  6804. animator.start(cfg.easing);
  6805. }
  6806. return animators;
  6807. }
  6808. function copyArrShallow(source, target, len) {
  6809. for (var i = 0; i < len; i++) {
  6810. source[i] = target[i];
  6811. }
  6812. }
  6813. function is2DArray(value) {
  6814. return isArrayLike(value[0]);
  6815. }
  6816. function copyValue(target, source, key) {
  6817. if (isArrayLike(source[key])) {
  6818. if (!isArrayLike(target[key])) {
  6819. target[key] = [];
  6820. }
  6821. if (isTypedArray(source[key])) {
  6822. var len = source[key].length;
  6823. if (target[key].length !== len) {
  6824. target[key] = new (source[key].constructor)(len);
  6825. copyArrShallow(target[key], source[key], len);
  6826. }
  6827. }
  6828. else {
  6829. var sourceArr = source[key];
  6830. var targetArr = target[key];
  6831. var len0 = sourceArr.length;
  6832. if (is2DArray(sourceArr)) {
  6833. var len1 = sourceArr[0].length;
  6834. for (var i = 0; i < len0; i++) {
  6835. if (!targetArr[i]) {
  6836. targetArr[i] = Array.prototype.slice.call(sourceArr[i]);
  6837. }
  6838. else {
  6839. copyArrShallow(targetArr[i], sourceArr[i], len1);
  6840. }
  6841. }
  6842. }
  6843. else {
  6844. copyArrShallow(targetArr, sourceArr, len0);
  6845. }
  6846. targetArr.length = sourceArr.length;
  6847. }
  6848. }
  6849. else {
  6850. target[key] = source[key];
  6851. }
  6852. }
  6853. function isValueSame(val1, val2) {
  6854. return val1 === val2
  6855. || isArrayLike(val1) && isArrayLike(val2) && is1DArraySame(val1, val2);
  6856. }
  6857. function is1DArraySame(arr0, arr1) {
  6858. var len = arr0.length;
  6859. if (len !== arr1.length) {
  6860. return false;
  6861. }
  6862. for (var i = 0; i < len; i++) {
  6863. if (arr0[i] !== arr1[i]) {
  6864. return false;
  6865. }
  6866. }
  6867. return true;
  6868. }
  6869. function animateToShallow(animatable, topKey, animateObj, target, cfg, animationProps, animators, reverse) {
  6870. var targetKeys = keys(target);
  6871. var duration = cfg.duration;
  6872. var delay = cfg.delay;
  6873. var additive = cfg.additive;
  6874. var setToFinal = cfg.setToFinal;
  6875. var animateAll = !isObject(animationProps);
  6876. var existsAnimators = animatable.animators;
  6877. var animationKeys = [];
  6878. for (var k = 0; k < targetKeys.length; k++) {
  6879. var innerKey = targetKeys[k];
  6880. var targetVal = target[innerKey];
  6881. if (targetVal != null && animateObj[innerKey] != null
  6882. && (animateAll || animationProps[innerKey])) {
  6883. if (isObject(targetVal)
  6884. && !isArrayLike(targetVal)
  6885. && !isGradientObject(targetVal)) {
  6886. if (topKey) {
  6887. if (!reverse) {
  6888. animateObj[innerKey] = targetVal;
  6889. animatable.updateDuringAnimation(topKey);
  6890. }
  6891. continue;
  6892. }
  6893. animateToShallow(animatable, innerKey, animateObj[innerKey], targetVal, cfg, animationProps && animationProps[innerKey], animators, reverse);
  6894. }
  6895. else {
  6896. animationKeys.push(innerKey);
  6897. }
  6898. }
  6899. else if (!reverse) {
  6900. animateObj[innerKey] = targetVal;
  6901. animatable.updateDuringAnimation(topKey);
  6902. animationKeys.push(innerKey);
  6903. }
  6904. }
  6905. var keyLen = animationKeys.length;
  6906. if (!additive && keyLen) {
  6907. for (var i = 0; i < existsAnimators.length; i++) {
  6908. var animator = existsAnimators[i];
  6909. if (animator.targetName === topKey) {
  6910. var allAborted = animator.stopTracks(animationKeys);
  6911. if (allAborted) {
  6912. var idx = indexOf(existsAnimators, animator);
  6913. existsAnimators.splice(idx, 1);
  6914. }
  6915. }
  6916. }
  6917. }
  6918. if (!cfg.force) {
  6919. animationKeys = filter(animationKeys, function (key) { return !isValueSame(target[key], animateObj[key]); });
  6920. keyLen = animationKeys.length;
  6921. }
  6922. if (keyLen > 0
  6923. || (cfg.force && !animators.length)) {
  6924. var revertedSource = void 0;
  6925. var reversedTarget = void 0;
  6926. var sourceClone = void 0;
  6927. if (reverse) {
  6928. reversedTarget = {};
  6929. if (setToFinal) {
  6930. revertedSource = {};
  6931. }
  6932. for (var i = 0; i < keyLen; i++) {
  6933. var innerKey = animationKeys[i];
  6934. reversedTarget[innerKey] = animateObj[innerKey];
  6935. if (setToFinal) {
  6936. revertedSource[innerKey] = target[innerKey];
  6937. }
  6938. else {
  6939. animateObj[innerKey] = target[innerKey];
  6940. }
  6941. }
  6942. }
  6943. else if (setToFinal) {
  6944. sourceClone = {};
  6945. for (var i = 0; i < keyLen; i++) {
  6946. var innerKey = animationKeys[i];
  6947. sourceClone[innerKey] = cloneValue(animateObj[innerKey]);
  6948. copyValue(animateObj, target, innerKey);
  6949. }
  6950. }
  6951. var animator = new Animator(animateObj, false, false, additive ? filter(existsAnimators, function (animator) { return animator.targetName === topKey; }) : null);
  6952. animator.targetName = topKey;
  6953. if (cfg.scope) {
  6954. animator.scope = cfg.scope;
  6955. }
  6956. if (setToFinal && revertedSource) {
  6957. animator.whenWithKeys(0, revertedSource, animationKeys);
  6958. }
  6959. if (sourceClone) {
  6960. animator.whenWithKeys(0, sourceClone, animationKeys);
  6961. }
  6962. animator.whenWithKeys(duration == null ? 500 : duration, reverse ? reversedTarget : target, animationKeys).delay(delay || 0);
  6963. animatable.addAnimator(animator, topKey);
  6964. animators.push(animator);
  6965. }
  6966. }
  6967. var Group = (function (_super) {
  6968. __extends(Group, _super);
  6969. function Group(opts) {
  6970. var _this = _super.call(this) || this;
  6971. _this.isGroup = true;
  6972. _this._children = [];
  6973. _this.attr(opts);
  6974. return _this;
  6975. }
  6976. Group.prototype.childrenRef = function () {
  6977. return this._children;
  6978. };
  6979. Group.prototype.children = function () {
  6980. return this._children.slice();
  6981. };
  6982. Group.prototype.childAt = function (idx) {
  6983. return this._children[idx];
  6984. };
  6985. Group.prototype.childOfName = function (name) {
  6986. var children = this._children;
  6987. for (var i = 0; i < children.length; i++) {
  6988. if (children[i].name === name) {
  6989. return children[i];
  6990. }
  6991. }
  6992. };
  6993. Group.prototype.childCount = function () {
  6994. return this._children.length;
  6995. };
  6996. Group.prototype.add = function (child) {
  6997. if (child) {
  6998. if (child !== this && child.parent !== this) {
  6999. this._children.push(child);
  7000. this._doAdd(child);
  7001. }
  7002. {
  7003. if (child.__hostTarget) {
  7004. throw 'This elemenet has been used as an attachment';
  7005. }
  7006. }
  7007. }
  7008. return this;
  7009. };
  7010. Group.prototype.addBefore = function (child, nextSibling) {
  7011. if (child && child !== this && child.parent !== this
  7012. && nextSibling && nextSibling.parent === this) {
  7013. var children = this._children;
  7014. var idx = children.indexOf(nextSibling);
  7015. if (idx >= 0) {
  7016. children.splice(idx, 0, child);
  7017. this._doAdd(child);
  7018. }
  7019. }
  7020. return this;
  7021. };
  7022. Group.prototype.replace = function (oldChild, newChild) {
  7023. var idx = indexOf(this._children, oldChild);
  7024. if (idx >= 0) {
  7025. this.replaceAt(newChild, idx);
  7026. }
  7027. return this;
  7028. };
  7029. Group.prototype.replaceAt = function (child, index) {
  7030. var children = this._children;
  7031. var old = children[index];
  7032. if (child && child !== this && child.parent !== this && child !== old) {
  7033. children[index] = child;
  7034. old.parent = null;
  7035. var zr = this.__zr;
  7036. if (zr) {
  7037. old.removeSelfFromZr(zr);
  7038. }
  7039. this._doAdd(child);
  7040. }
  7041. return this;
  7042. };
  7043. Group.prototype._doAdd = function (child) {
  7044. if (child.parent) {
  7045. child.parent.remove(child);
  7046. }
  7047. child.parent = this;
  7048. var zr = this.__zr;
  7049. if (zr && zr !== child.__zr) {
  7050. child.addSelfToZr(zr);
  7051. }
  7052. zr && zr.refresh();
  7053. };
  7054. Group.prototype.remove = function (child) {
  7055. var zr = this.__zr;
  7056. var children = this._children;
  7057. var idx = indexOf(children, child);
  7058. if (idx < 0) {
  7059. return this;
  7060. }
  7061. children.splice(idx, 1);
  7062. child.parent = null;
  7063. if (zr) {
  7064. child.removeSelfFromZr(zr);
  7065. }
  7066. zr && zr.refresh();
  7067. return this;
  7068. };
  7069. Group.prototype.removeAll = function () {
  7070. var children = this._children;
  7071. var zr = this.__zr;
  7072. for (var i = 0; i < children.length; i++) {
  7073. var child = children[i];
  7074. if (zr) {
  7075. child.removeSelfFromZr(zr);
  7076. }
  7077. child.parent = null;
  7078. }
  7079. children.length = 0;
  7080. return this;
  7081. };
  7082. Group.prototype.eachChild = function (cb, context) {
  7083. var children = this._children;
  7084. for (var i = 0; i < children.length; i++) {
  7085. var child = children[i];
  7086. cb.call(context, child, i);
  7087. }
  7088. return this;
  7089. };
  7090. Group.prototype.traverse = function (cb, context) {
  7091. for (var i = 0; i < this._children.length; i++) {
  7092. var child = this._children[i];
  7093. var stopped = cb.call(context, child);
  7094. if (child.isGroup && !stopped) {
  7095. child.traverse(cb, context);
  7096. }
  7097. }
  7098. return this;
  7099. };
  7100. Group.prototype.addSelfToZr = function (zr) {
  7101. _super.prototype.addSelfToZr.call(this, zr);
  7102. for (var i = 0; i < this._children.length; i++) {
  7103. var child = this._children[i];
  7104. child.addSelfToZr(zr);
  7105. }
  7106. };
  7107. Group.prototype.removeSelfFromZr = function (zr) {
  7108. _super.prototype.removeSelfFromZr.call(this, zr);
  7109. for (var i = 0; i < this._children.length; i++) {
  7110. var child = this._children[i];
  7111. child.removeSelfFromZr(zr);
  7112. }
  7113. };
  7114. Group.prototype.getBoundingRect = function (includeChildren) {
  7115. var tmpRect = new BoundingRect(0, 0, 0, 0);
  7116. var children = includeChildren || this._children;
  7117. var tmpMat = [];
  7118. var rect = null;
  7119. for (var i = 0; i < children.length; i++) {
  7120. var child = children[i];
  7121. if (child.ignore || child.invisible) {
  7122. continue;
  7123. }
  7124. var childRect = child.getBoundingRect();
  7125. var transform = child.getLocalTransform(tmpMat);
  7126. if (transform) {
  7127. BoundingRect.applyTransform(tmpRect, childRect, transform);
  7128. rect = rect || tmpRect.clone();
  7129. rect.union(tmpRect);
  7130. }
  7131. else {
  7132. rect = rect || childRect.clone();
  7133. rect.union(childRect);
  7134. }
  7135. }
  7136. return rect || tmpRect;
  7137. };
  7138. return Group;
  7139. }(Element));
  7140. Group.prototype.type = 'group';
  7141. /*!
  7142. * ZRender, a high performance 2d drawing library.
  7143. *
  7144. * Copyright (c) 2013, Baidu Inc.
  7145. * All rights reserved.
  7146. *
  7147. * LICENSE
  7148. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  7149. */
  7150. var painterCtors = {};
  7151. var instances = {};
  7152. function delInstance(id) {
  7153. delete instances[id];
  7154. }
  7155. function isDarkMode(backgroundColor) {
  7156. if (!backgroundColor) {
  7157. return false;
  7158. }
  7159. if (typeof backgroundColor === 'string') {
  7160. return lum(backgroundColor, 1) < DARK_MODE_THRESHOLD;
  7161. }
  7162. else if (backgroundColor.colorStops) {
  7163. var colorStops = backgroundColor.colorStops;
  7164. var totalLum = 0;
  7165. var len = colorStops.length;
  7166. for (var i = 0; i < len; i++) {
  7167. totalLum += lum(colorStops[i].color, 1);
  7168. }
  7169. totalLum /= len;
  7170. return totalLum < DARK_MODE_THRESHOLD;
  7171. }
  7172. return false;
  7173. }
  7174. var ZRender = (function () {
  7175. function ZRender(id, dom, opts) {
  7176. var _this = this;
  7177. this._sleepAfterStill = 10;
  7178. this._stillFrameAccum = 0;
  7179. this._needsRefresh = true;
  7180. this._needsRefreshHover = true;
  7181. this._darkMode = false;
  7182. opts = opts || {};
  7183. this.dom = dom;
  7184. this.id = id;
  7185. var storage = new Storage();
  7186. var rendererType = opts.renderer || 'canvas';
  7187. if (!painterCtors[rendererType]) {
  7188. rendererType = keys(painterCtors)[0];
  7189. }
  7190. {
  7191. if (!painterCtors[rendererType]) {
  7192. throw new Error("Renderer '" + rendererType + "' is not imported. Please import it first.");
  7193. }
  7194. }
  7195. opts.useDirtyRect = opts.useDirtyRect == null
  7196. ? false
  7197. : opts.useDirtyRect;
  7198. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  7199. var ssrMode = opts.ssr || painter.ssrOnly;
  7200. this.storage = storage;
  7201. this.painter = painter;
  7202. var handlerProxy = (!env.node && !env.worker && !ssrMode)
  7203. ? new HandlerDomProxy(painter.getViewportRoot(), painter.root)
  7204. : null;
  7205. var useCoarsePointer = opts.useCoarsePointer;
  7206. var usePointerSize = (useCoarsePointer == null || useCoarsePointer === 'auto')
  7207. ? env.touchEventsSupported
  7208. : !!useCoarsePointer;
  7209. var defaultPointerSize = 44;
  7210. var pointerSize;
  7211. if (usePointerSize) {
  7212. pointerSize = retrieve2(opts.pointerSize, defaultPointerSize);
  7213. }
  7214. this.handler = new Handler(storage, painter, handlerProxy, painter.root, pointerSize);
  7215. this.animation = new Animation({
  7216. stage: {
  7217. update: ssrMode ? null : function () { return _this._flush(true); }
  7218. }
  7219. });
  7220. if (!ssrMode) {
  7221. this.animation.start();
  7222. }
  7223. }
  7224. ZRender.prototype.add = function (el) {
  7225. if (this._disposed || !el) {
  7226. return;
  7227. }
  7228. this.storage.addRoot(el);
  7229. el.addSelfToZr(this);
  7230. this.refresh();
  7231. };
  7232. ZRender.prototype.remove = function (el) {
  7233. if (this._disposed || !el) {
  7234. return;
  7235. }
  7236. this.storage.delRoot(el);
  7237. el.removeSelfFromZr(this);
  7238. this.refresh();
  7239. };
  7240. ZRender.prototype.configLayer = function (zLevel, config) {
  7241. if (this._disposed) {
  7242. return;
  7243. }
  7244. if (this.painter.configLayer) {
  7245. this.painter.configLayer(zLevel, config);
  7246. }
  7247. this.refresh();
  7248. };
  7249. ZRender.prototype.setBackgroundColor = function (backgroundColor) {
  7250. if (this._disposed) {
  7251. return;
  7252. }
  7253. if (this.painter.setBackgroundColor) {
  7254. this.painter.setBackgroundColor(backgroundColor);
  7255. }
  7256. this.refresh();
  7257. this._backgroundColor = backgroundColor;
  7258. this._darkMode = isDarkMode(backgroundColor);
  7259. };
  7260. ZRender.prototype.getBackgroundColor = function () {
  7261. return this._backgroundColor;
  7262. };
  7263. ZRender.prototype.setDarkMode = function (darkMode) {
  7264. this._darkMode = darkMode;
  7265. };
  7266. ZRender.prototype.isDarkMode = function () {
  7267. return this._darkMode;
  7268. };
  7269. ZRender.prototype.refreshImmediately = function (fromInside) {
  7270. if (this._disposed) {
  7271. return;
  7272. }
  7273. if (!fromInside) {
  7274. this.animation.update(true);
  7275. }
  7276. this._needsRefresh = false;
  7277. this.painter.refresh();
  7278. this._needsRefresh = false;
  7279. };
  7280. ZRender.prototype.refresh = function () {
  7281. if (this._disposed) {
  7282. return;
  7283. }
  7284. this._needsRefresh = true;
  7285. this.animation.start();
  7286. };
  7287. ZRender.prototype.flush = function () {
  7288. if (this._disposed) {
  7289. return;
  7290. }
  7291. this._flush(false);
  7292. };
  7293. ZRender.prototype._flush = function (fromInside) {
  7294. var triggerRendered;
  7295. var start = getTime();
  7296. if (this._needsRefresh) {
  7297. triggerRendered = true;
  7298. this.refreshImmediately(fromInside);
  7299. }
  7300. if (this._needsRefreshHover) {
  7301. triggerRendered = true;
  7302. this.refreshHoverImmediately();
  7303. }
  7304. var end = getTime();
  7305. if (triggerRendered) {
  7306. this._stillFrameAccum = 0;
  7307. this.trigger('rendered', {
  7308. elapsedTime: end - start
  7309. });
  7310. }
  7311. else if (this._sleepAfterStill > 0) {
  7312. this._stillFrameAccum++;
  7313. if (this._stillFrameAccum > this._sleepAfterStill) {
  7314. this.animation.stop();
  7315. }
  7316. }
  7317. };
  7318. ZRender.prototype.setSleepAfterStill = function (stillFramesCount) {
  7319. this._sleepAfterStill = stillFramesCount;
  7320. };
  7321. ZRender.prototype.wakeUp = function () {
  7322. if (this._disposed) {
  7323. return;
  7324. }
  7325. this.animation.start();
  7326. this._stillFrameAccum = 0;
  7327. };
  7328. ZRender.prototype.refreshHover = function () {
  7329. this._needsRefreshHover = true;
  7330. };
  7331. ZRender.prototype.refreshHoverImmediately = function () {
  7332. if (this._disposed) {
  7333. return;
  7334. }
  7335. this._needsRefreshHover = false;
  7336. if (this.painter.refreshHover && this.painter.getType() === 'canvas') {
  7337. this.painter.refreshHover();
  7338. }
  7339. };
  7340. ZRender.prototype.resize = function (opts) {
  7341. if (this._disposed) {
  7342. return;
  7343. }
  7344. opts = opts || {};
  7345. this.painter.resize(opts.width, opts.height);
  7346. this.handler.resize();
  7347. };
  7348. ZRender.prototype.clearAnimation = function () {
  7349. if (this._disposed) {
  7350. return;
  7351. }
  7352. this.animation.clear();
  7353. };
  7354. ZRender.prototype.getWidth = function () {
  7355. if (this._disposed) {
  7356. return;
  7357. }
  7358. return this.painter.getWidth();
  7359. };
  7360. ZRender.prototype.getHeight = function () {
  7361. if (this._disposed) {
  7362. return;
  7363. }
  7364. return this.painter.getHeight();
  7365. };
  7366. ZRender.prototype.setCursorStyle = function (cursorStyle) {
  7367. if (this._disposed) {
  7368. return;
  7369. }
  7370. this.handler.setCursorStyle(cursorStyle);
  7371. };
  7372. ZRender.prototype.findHover = function (x, y) {
  7373. if (this._disposed) {
  7374. return;
  7375. }
  7376. return this.handler.findHover(x, y);
  7377. };
  7378. ZRender.prototype.on = function (eventName, eventHandler, context) {
  7379. if (!this._disposed) {
  7380. this.handler.on(eventName, eventHandler, context);
  7381. }
  7382. return this;
  7383. };
  7384. ZRender.prototype.off = function (eventName, eventHandler) {
  7385. if (this._disposed) {
  7386. return;
  7387. }
  7388. this.handler.off(eventName, eventHandler);
  7389. };
  7390. ZRender.prototype.trigger = function (eventName, event) {
  7391. if (this._disposed) {
  7392. return;
  7393. }
  7394. this.handler.trigger(eventName, event);
  7395. };
  7396. ZRender.prototype.clear = function () {
  7397. if (this._disposed) {
  7398. return;
  7399. }
  7400. var roots = this.storage.getRoots();
  7401. for (var i = 0; i < roots.length; i++) {
  7402. if (roots[i] instanceof Group) {
  7403. roots[i].removeSelfFromZr(this);
  7404. }
  7405. }
  7406. this.storage.delAllRoots();
  7407. this.painter.clear();
  7408. };
  7409. ZRender.prototype.dispose = function () {
  7410. if (this._disposed) {
  7411. return;
  7412. }
  7413. this.animation.stop();
  7414. this.clear();
  7415. this.storage.dispose();
  7416. this.painter.dispose();
  7417. this.handler.dispose();
  7418. this.animation =
  7419. this.storage =
  7420. this.painter =
  7421. this.handler = null;
  7422. this._disposed = true;
  7423. delInstance(this.id);
  7424. };
  7425. return ZRender;
  7426. }());
  7427. function init(dom, opts) {
  7428. var zr = new ZRender(guid(), dom, opts);
  7429. instances[zr.id] = zr;
  7430. return zr;
  7431. }
  7432. function dispose(zr) {
  7433. zr.dispose();
  7434. }
  7435. function disposeAll() {
  7436. for (var key in instances) {
  7437. if (instances.hasOwnProperty(key)) {
  7438. instances[key].dispose();
  7439. }
  7440. }
  7441. instances = {};
  7442. }
  7443. function getInstance(id) {
  7444. return instances[id];
  7445. }
  7446. function registerPainter(name, Ctor) {
  7447. painterCtors[name] = Ctor;
  7448. }
  7449. var ssrDataGetter;
  7450. function getElementSSRData(el) {
  7451. if (typeof ssrDataGetter === 'function') {
  7452. return ssrDataGetter(el);
  7453. }
  7454. }
  7455. function registerSSRDataGetter(getter) {
  7456. ssrDataGetter = getter;
  7457. }
  7458. var version = '6.0.0';
  7459. var STYLE_MAGIC_KEY = '__zr_style_' + Math.round((Math.random() * 10));
  7460. var DEFAULT_COMMON_STYLE = {
  7461. shadowBlur: 0,
  7462. shadowOffsetX: 0,
  7463. shadowOffsetY: 0,
  7464. shadowColor: '#000',
  7465. opacity: 1,
  7466. blend: 'source-over'
  7467. };
  7468. var DEFAULT_COMMON_ANIMATION_PROPS = {
  7469. style: {
  7470. shadowBlur: true,
  7471. shadowOffsetX: true,
  7472. shadowOffsetY: true,
  7473. shadowColor: true,
  7474. opacity: true
  7475. }
  7476. };
  7477. DEFAULT_COMMON_STYLE[STYLE_MAGIC_KEY] = true;
  7478. var PRIMARY_STATES_KEYS$1 = ['z', 'z2', 'invisible'];
  7479. var PRIMARY_STATES_KEYS_IN_HOVER_LAYER = ['invisible'];
  7480. var Displayable = (function (_super) {
  7481. __extends(Displayable, _super);
  7482. function Displayable(props) {
  7483. return _super.call(this, props) || this;
  7484. }
  7485. Displayable.prototype._init = function (props) {
  7486. var keysArr = keys(props);
  7487. for (var i = 0; i < keysArr.length; i++) {
  7488. var key = keysArr[i];
  7489. if (key === 'style') {
  7490. this.useStyle(props[key]);
  7491. }
  7492. else {
  7493. _super.prototype.attrKV.call(this, key, props[key]);
  7494. }
  7495. }
  7496. if (!this.style) {
  7497. this.useStyle({});
  7498. }
  7499. };
  7500. Displayable.prototype.beforeBrush = function () { };
  7501. Displayable.prototype.afterBrush = function () { };
  7502. Displayable.prototype.innerBeforeBrush = function () { };
  7503. Displayable.prototype.innerAfterBrush = function () { };
  7504. Displayable.prototype.shouldBePainted = function (viewWidth, viewHeight, considerClipPath, considerAncestors) {
  7505. var m = this.transform;
  7506. if (this.ignore
  7507. || this.invisible
  7508. || this.style.opacity === 0
  7509. || (this.culling
  7510. && isDisplayableCulled(this, viewWidth, viewHeight))
  7511. || (m && !m[0] && !m[3])) {
  7512. return false;
  7513. }
  7514. if (considerClipPath && this.__clipPaths && this.__clipPaths.length) {
  7515. for (var i = 0; i < this.__clipPaths.length; ++i) {
  7516. if (this.__clipPaths[i].isZeroArea()) {
  7517. return false;
  7518. }
  7519. }
  7520. }
  7521. if (considerAncestors && this.parent) {
  7522. var parent_1 = this.parent;
  7523. while (parent_1) {
  7524. if (parent_1.ignore) {
  7525. return false;
  7526. }
  7527. parent_1 = parent_1.parent;
  7528. }
  7529. }
  7530. return true;
  7531. };
  7532. Displayable.prototype.contain = function (x, y) {
  7533. return this.rectContain(x, y);
  7534. };
  7535. Displayable.prototype.traverse = function (cb, context) {
  7536. cb.call(context, this);
  7537. };
  7538. Displayable.prototype.rectContain = function (x, y) {
  7539. var coord = this.transformCoordToLocal(x, y);
  7540. var rect = this.getBoundingRect();
  7541. return rect.contain(coord[0], coord[1]);
  7542. };
  7543. Displayable.prototype.getPaintRect = function () {
  7544. var rect = this._paintRect;
  7545. if (!this._paintRect || this.__dirty) {
  7546. var transform = this.transform;
  7547. var elRect = this.getBoundingRect();
  7548. var style = this.style;
  7549. var shadowSize = style.shadowBlur || 0;
  7550. var shadowOffsetX = style.shadowOffsetX || 0;
  7551. var shadowOffsetY = style.shadowOffsetY || 0;
  7552. rect = this._paintRect || (this._paintRect = new BoundingRect(0, 0, 0, 0));
  7553. if (transform) {
  7554. BoundingRect.applyTransform(rect, elRect, transform);
  7555. }
  7556. else {
  7557. rect.copy(elRect);
  7558. }
  7559. if (shadowSize || shadowOffsetX || shadowOffsetY) {
  7560. rect.width += shadowSize * 2 + Math.abs(shadowOffsetX);
  7561. rect.height += shadowSize * 2 + Math.abs(shadowOffsetY);
  7562. rect.x = Math.min(rect.x, rect.x + shadowOffsetX - shadowSize);
  7563. rect.y = Math.min(rect.y, rect.y + shadowOffsetY - shadowSize);
  7564. }
  7565. var tolerance = this.dirtyRectTolerance;
  7566. if (!rect.isZero()) {
  7567. rect.x = Math.floor(rect.x - tolerance);
  7568. rect.y = Math.floor(rect.y - tolerance);
  7569. rect.width = Math.ceil(rect.width + 1 + tolerance * 2);
  7570. rect.height = Math.ceil(rect.height + 1 + tolerance * 2);
  7571. }
  7572. }
  7573. return rect;
  7574. };
  7575. Displayable.prototype.setPrevPaintRect = function (paintRect) {
  7576. if (paintRect) {
  7577. this._prevPaintRect = this._prevPaintRect || new BoundingRect(0, 0, 0, 0);
  7578. this._prevPaintRect.copy(paintRect);
  7579. }
  7580. else {
  7581. this._prevPaintRect = null;
  7582. }
  7583. };
  7584. Displayable.prototype.getPrevPaintRect = function () {
  7585. return this._prevPaintRect;
  7586. };
  7587. Displayable.prototype.animateStyle = function (loop) {
  7588. return this.animate('style', loop);
  7589. };
  7590. Displayable.prototype.updateDuringAnimation = function (targetKey) {
  7591. if (targetKey === 'style') {
  7592. this.dirtyStyle();
  7593. }
  7594. else {
  7595. this.markRedraw();
  7596. }
  7597. };
  7598. Displayable.prototype.attrKV = function (key, value) {
  7599. if (key !== 'style') {
  7600. _super.prototype.attrKV.call(this, key, value);
  7601. }
  7602. else {
  7603. if (!this.style) {
  7604. this.useStyle(value);
  7605. }
  7606. else {
  7607. this.setStyle(value);
  7608. }
  7609. }
  7610. };
  7611. Displayable.prototype.setStyle = function (keyOrObj, value) {
  7612. if (typeof keyOrObj === 'string') {
  7613. this.style[keyOrObj] = value;
  7614. }
  7615. else {
  7616. extend(this.style, keyOrObj);
  7617. }
  7618. this.dirtyStyle();
  7619. return this;
  7620. };
  7621. Displayable.prototype.dirtyStyle = function (notRedraw) {
  7622. if (!notRedraw) {
  7623. this.markRedraw();
  7624. }
  7625. this.__dirty |= STYLE_CHANGED_BIT;
  7626. if (this._rect) {
  7627. this._rect = null;
  7628. }
  7629. };
  7630. Displayable.prototype.dirty = function () {
  7631. this.dirtyStyle();
  7632. };
  7633. Displayable.prototype.styleChanged = function () {
  7634. return !!(this.__dirty & STYLE_CHANGED_BIT);
  7635. };
  7636. Displayable.prototype.styleUpdated = function () {
  7637. this.__dirty &= ~STYLE_CHANGED_BIT;
  7638. };
  7639. Displayable.prototype.createStyle = function (obj) {
  7640. return createObject(DEFAULT_COMMON_STYLE, obj);
  7641. };
  7642. Displayable.prototype.useStyle = function (obj) {
  7643. if (!obj[STYLE_MAGIC_KEY]) {
  7644. obj = this.createStyle(obj);
  7645. }
  7646. if (this.__inHover) {
  7647. this.__hoverStyle = obj;
  7648. }
  7649. else {
  7650. this.style = obj;
  7651. }
  7652. this.dirtyStyle();
  7653. };
  7654. Displayable.prototype.isStyleObject = function (obj) {
  7655. return obj[STYLE_MAGIC_KEY];
  7656. };
  7657. Displayable.prototype._innerSaveToNormal = function (toState) {
  7658. _super.prototype._innerSaveToNormal.call(this, toState);
  7659. var normalState = this._normalState;
  7660. if (toState.style && !normalState.style) {
  7661. normalState.style = this._mergeStyle(this.createStyle(), this.style);
  7662. }
  7663. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS$1);
  7664. };
  7665. Displayable.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  7666. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  7667. var needsRestoreToNormal = !(state && keepCurrentStates);
  7668. var targetStyle;
  7669. if (state && state.style) {
  7670. if (transition) {
  7671. if (keepCurrentStates) {
  7672. targetStyle = state.style;
  7673. }
  7674. else {
  7675. targetStyle = this._mergeStyle(this.createStyle(), normalState.style);
  7676. this._mergeStyle(targetStyle, state.style);
  7677. }
  7678. }
  7679. else {
  7680. targetStyle = this._mergeStyle(this.createStyle(), keepCurrentStates ? this.style : normalState.style);
  7681. this._mergeStyle(targetStyle, state.style);
  7682. }
  7683. }
  7684. else if (needsRestoreToNormal) {
  7685. targetStyle = normalState.style;
  7686. }
  7687. if (targetStyle) {
  7688. if (transition) {
  7689. var sourceStyle = this.style;
  7690. this.style = this.createStyle(needsRestoreToNormal ? {} : sourceStyle);
  7691. if (needsRestoreToNormal) {
  7692. var changedKeys = keys(sourceStyle);
  7693. for (var i = 0; i < changedKeys.length; i++) {
  7694. var key = changedKeys[i];
  7695. if (key in targetStyle) {
  7696. targetStyle[key] = targetStyle[key];
  7697. this.style[key] = sourceStyle[key];
  7698. }
  7699. }
  7700. }
  7701. var targetKeys = keys(targetStyle);
  7702. for (var i = 0; i < targetKeys.length; i++) {
  7703. var key = targetKeys[i];
  7704. this.style[key] = this.style[key];
  7705. }
  7706. this._transitionState(stateName, {
  7707. style: targetStyle
  7708. }, animationCfg, this.getAnimationStyleProps());
  7709. }
  7710. else {
  7711. this.useStyle(targetStyle);
  7712. }
  7713. }
  7714. var statesKeys = this.__inHover ? PRIMARY_STATES_KEYS_IN_HOVER_LAYER : PRIMARY_STATES_KEYS$1;
  7715. for (var i = 0; i < statesKeys.length; i++) {
  7716. var key = statesKeys[i];
  7717. if (state && state[key] != null) {
  7718. this[key] = state[key];
  7719. }
  7720. else if (needsRestoreToNormal) {
  7721. if (normalState[key] != null) {
  7722. this[key] = normalState[key];
  7723. }
  7724. }
  7725. }
  7726. };
  7727. Displayable.prototype._mergeStates = function (states) {
  7728. var mergedState = _super.prototype._mergeStates.call(this, states);
  7729. var mergedStyle;
  7730. for (var i = 0; i < states.length; i++) {
  7731. var state = states[i];
  7732. if (state.style) {
  7733. mergedStyle = mergedStyle || {};
  7734. this._mergeStyle(mergedStyle, state.style);
  7735. }
  7736. }
  7737. if (mergedStyle) {
  7738. mergedState.style = mergedStyle;
  7739. }
  7740. return mergedState;
  7741. };
  7742. Displayable.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  7743. extend(targetStyle, sourceStyle);
  7744. return targetStyle;
  7745. };
  7746. Displayable.prototype.getAnimationStyleProps = function () {
  7747. return DEFAULT_COMMON_ANIMATION_PROPS;
  7748. };
  7749. Displayable.initDefaultProps = (function () {
  7750. var dispProto = Displayable.prototype;
  7751. dispProto.type = 'displayable';
  7752. dispProto.invisible = false;
  7753. dispProto.z = 0;
  7754. dispProto.z2 = 0;
  7755. dispProto.zlevel = 0;
  7756. dispProto.culling = false;
  7757. dispProto.cursor = 'pointer';
  7758. dispProto.rectHover = false;
  7759. dispProto.incremental = false;
  7760. dispProto._rect = null;
  7761. dispProto.dirtyRectTolerance = 0;
  7762. dispProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT;
  7763. })();
  7764. return Displayable;
  7765. }(Element));
  7766. var tmpRect$1 = new BoundingRect(0, 0, 0, 0);
  7767. var viewRect = new BoundingRect(0, 0, 0, 0);
  7768. function isDisplayableCulled(el, width, height) {
  7769. tmpRect$1.copy(el.getBoundingRect());
  7770. if (el.transform) {
  7771. tmpRect$1.applyTransform(el.transform);
  7772. }
  7773. viewRect.width = width;
  7774. viewRect.height = height;
  7775. return !tmpRect$1.intersect(viewRect);
  7776. }
  7777. var mathMin$1 = Math.min;
  7778. var mathMax$1 = Math.max;
  7779. var mathSin = Math.sin;
  7780. var mathCos = Math.cos;
  7781. var PI2 = Math.PI * 2;
  7782. var start = create();
  7783. var end = create();
  7784. var extremity = create();
  7785. function fromPoints(points, min, max) {
  7786. if (points.length === 0) {
  7787. return;
  7788. }
  7789. var p = points[0];
  7790. var left = p[0];
  7791. var right = p[0];
  7792. var top = p[1];
  7793. var bottom = p[1];
  7794. for (var i = 1; i < points.length; i++) {
  7795. p = points[i];
  7796. left = mathMin$1(left, p[0]);
  7797. right = mathMax$1(right, p[0]);
  7798. top = mathMin$1(top, p[1]);
  7799. bottom = mathMax$1(bottom, p[1]);
  7800. }
  7801. min[0] = left;
  7802. min[1] = top;
  7803. max[0] = right;
  7804. max[1] = bottom;
  7805. }
  7806. function fromLine(x0, y0, x1, y1, min, max) {
  7807. min[0] = mathMin$1(x0, x1);
  7808. min[1] = mathMin$1(y0, y1);
  7809. max[0] = mathMax$1(x0, x1);
  7810. max[1] = mathMax$1(y0, y1);
  7811. }
  7812. var xDim = [];
  7813. var yDim = [];
  7814. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min, max) {
  7815. var cubicExtrema$1 = cubicExtrema;
  7816. var cubicAt$1 = cubicAt;
  7817. var n = cubicExtrema$1(x0, x1, x2, x3, xDim);
  7818. min[0] = Infinity;
  7819. min[1] = Infinity;
  7820. max[0] = -Infinity;
  7821. max[1] = -Infinity;
  7822. for (var i = 0; i < n; i++) {
  7823. var x = cubicAt$1(x0, x1, x2, x3, xDim[i]);
  7824. min[0] = mathMin$1(x, min[0]);
  7825. max[0] = mathMax$1(x, max[0]);
  7826. }
  7827. n = cubicExtrema$1(y0, y1, y2, y3, yDim);
  7828. for (var i = 0; i < n; i++) {
  7829. var y = cubicAt$1(y0, y1, y2, y3, yDim[i]);
  7830. min[1] = mathMin$1(y, min[1]);
  7831. max[1] = mathMax$1(y, max[1]);
  7832. }
  7833. min[0] = mathMin$1(x0, min[0]);
  7834. max[0] = mathMax$1(x0, max[0]);
  7835. min[0] = mathMin$1(x3, min[0]);
  7836. max[0] = mathMax$1(x3, max[0]);
  7837. min[1] = mathMin$1(y0, min[1]);
  7838. max[1] = mathMax$1(y0, max[1]);
  7839. min[1] = mathMin$1(y3, min[1]);
  7840. max[1] = mathMax$1(y3, max[1]);
  7841. }
  7842. function fromQuadratic(x0, y0, x1, y1, x2, y2, min, max) {
  7843. var quadraticExtremum$1 = quadraticExtremum;
  7844. var quadraticAt$1 = quadraticAt;
  7845. var tx = mathMax$1(mathMin$1(quadraticExtremum$1(x0, x1, x2), 1), 0);
  7846. var ty = mathMax$1(mathMin$1(quadraticExtremum$1(y0, y1, y2), 1), 0);
  7847. var x = quadraticAt$1(x0, x1, x2, tx);
  7848. var y = quadraticAt$1(y0, y1, y2, ty);
  7849. min[0] = mathMin$1(x0, x2, x);
  7850. min[1] = mathMin$1(y0, y2, y);
  7851. max[0] = mathMax$1(x0, x2, x);
  7852. max[1] = mathMax$1(y0, y2, y);
  7853. }
  7854. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min$1, max$1) {
  7855. var vec2Min = min;
  7856. var vec2Max = max;
  7857. var diff = Math.abs(startAngle - endAngle);
  7858. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  7859. min$1[0] = x - rx;
  7860. min$1[1] = y - ry;
  7861. max$1[0] = x + rx;
  7862. max$1[1] = y + ry;
  7863. return;
  7864. }
  7865. start[0] = mathCos(startAngle) * rx + x;
  7866. start[1] = mathSin(startAngle) * ry + y;
  7867. end[0] = mathCos(endAngle) * rx + x;
  7868. end[1] = mathSin(endAngle) * ry + y;
  7869. vec2Min(min$1, start, end);
  7870. vec2Max(max$1, start, end);
  7871. startAngle = startAngle % (PI2);
  7872. if (startAngle < 0) {
  7873. startAngle = startAngle + PI2;
  7874. }
  7875. endAngle = endAngle % (PI2);
  7876. if (endAngle < 0) {
  7877. endAngle = endAngle + PI2;
  7878. }
  7879. if (startAngle > endAngle && !anticlockwise) {
  7880. endAngle += PI2;
  7881. }
  7882. else if (startAngle < endAngle && anticlockwise) {
  7883. startAngle += PI2;
  7884. }
  7885. if (anticlockwise) {
  7886. var tmp = endAngle;
  7887. endAngle = startAngle;
  7888. startAngle = tmp;
  7889. }
  7890. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  7891. if (angle > startAngle) {
  7892. extremity[0] = mathCos(angle) * rx + x;
  7893. extremity[1] = mathSin(angle) * ry + y;
  7894. vec2Min(min$1, extremity, min$1);
  7895. vec2Max(max$1, extremity, max$1);
  7896. }
  7897. }
  7898. }
  7899. var CMD = {
  7900. M: 1,
  7901. L: 2,
  7902. C: 3,
  7903. Q: 4,
  7904. A: 5,
  7905. Z: 6,
  7906. R: 7
  7907. };
  7908. var tmpOutX = [];
  7909. var tmpOutY = [];
  7910. var min$1 = [];
  7911. var max$1 = [];
  7912. var min2 = [];
  7913. var max2 = [];
  7914. var mathMin$2 = Math.min;
  7915. var mathMax$2 = Math.max;
  7916. var mathCos$1 = Math.cos;
  7917. var mathSin$1 = Math.sin;
  7918. var mathAbs$1 = Math.abs;
  7919. var PI = Math.PI;
  7920. var PI2$1 = PI * 2;
  7921. var hasTypedArray = typeof Float32Array !== 'undefined';
  7922. var tmpAngles = [];
  7923. function modPI2(radian) {
  7924. var n = Math.round(radian / PI * 1e8) / 1e8;
  7925. return (n % 2) * PI;
  7926. }
  7927. function normalizeArcAngles(angles, anticlockwise) {
  7928. var newStartAngle = modPI2(angles[0]);
  7929. if (newStartAngle < 0) {
  7930. newStartAngle += PI2$1;
  7931. }
  7932. var delta = newStartAngle - angles[0];
  7933. var newEndAngle = angles[1];
  7934. newEndAngle += delta;
  7935. if (!anticlockwise && newEndAngle - newStartAngle >= PI2$1) {
  7936. newEndAngle = newStartAngle + PI2$1;
  7937. }
  7938. else if (anticlockwise && newStartAngle - newEndAngle >= PI2$1) {
  7939. newEndAngle = newStartAngle - PI2$1;
  7940. }
  7941. else if (!anticlockwise && newStartAngle > newEndAngle) {
  7942. newEndAngle = newStartAngle + (PI2$1 - modPI2(newStartAngle - newEndAngle));
  7943. }
  7944. else if (anticlockwise && newStartAngle < newEndAngle) {
  7945. newEndAngle = newStartAngle - (PI2$1 - modPI2(newEndAngle - newStartAngle));
  7946. }
  7947. angles[0] = newStartAngle;
  7948. angles[1] = newEndAngle;
  7949. }
  7950. var PathProxy = (function () {
  7951. function PathProxy(notSaveData) {
  7952. this.dpr = 1;
  7953. this._xi = 0;
  7954. this._yi = 0;
  7955. this._x0 = 0;
  7956. this._y0 = 0;
  7957. this._len = 0;
  7958. if (notSaveData) {
  7959. this._saveData = false;
  7960. }
  7961. if (this._saveData) {
  7962. this.data = [];
  7963. }
  7964. }
  7965. PathProxy.prototype.increaseVersion = function () {
  7966. this._version++;
  7967. };
  7968. PathProxy.prototype.getVersion = function () {
  7969. return this._version;
  7970. };
  7971. PathProxy.prototype.setScale = function (sx, sy, segmentIgnoreThreshold) {
  7972. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  7973. if (segmentIgnoreThreshold > 0) {
  7974. this._ux = mathAbs$1(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  7975. this._uy = mathAbs$1(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  7976. }
  7977. };
  7978. PathProxy.prototype.setDPR = function (dpr) {
  7979. this.dpr = dpr;
  7980. };
  7981. PathProxy.prototype.setContext = function (ctx) {
  7982. this._ctx = ctx;
  7983. };
  7984. PathProxy.prototype.getContext = function () {
  7985. return this._ctx;
  7986. };
  7987. PathProxy.prototype.beginPath = function () {
  7988. this._ctx && this._ctx.beginPath();
  7989. this.reset();
  7990. return this;
  7991. };
  7992. PathProxy.prototype.reset = function () {
  7993. if (this._saveData) {
  7994. this._len = 0;
  7995. }
  7996. if (this._pathSegLen) {
  7997. this._pathSegLen = null;
  7998. this._pathLen = 0;
  7999. }
  8000. this._version++;
  8001. };
  8002. PathProxy.prototype.moveTo = function (x, y) {
  8003. this._drawPendingPt();
  8004. this.addData(CMD.M, x, y);
  8005. this._ctx && this._ctx.moveTo(x, y);
  8006. this._x0 = x;
  8007. this._y0 = y;
  8008. this._xi = x;
  8009. this._yi = y;
  8010. return this;
  8011. };
  8012. PathProxy.prototype.lineTo = function (x, y) {
  8013. var dx = mathAbs$1(x - this._xi);
  8014. var dy = mathAbs$1(y - this._yi);
  8015. var exceedUnit = dx > this._ux || dy > this._uy;
  8016. this.addData(CMD.L, x, y);
  8017. if (this._ctx && exceedUnit) {
  8018. this._ctx.lineTo(x, y);
  8019. }
  8020. if (exceedUnit) {
  8021. this._xi = x;
  8022. this._yi = y;
  8023. this._pendingPtDist = 0;
  8024. }
  8025. else {
  8026. var d2 = dx * dx + dy * dy;
  8027. if (d2 > this._pendingPtDist) {
  8028. this._pendingPtX = x;
  8029. this._pendingPtY = y;
  8030. this._pendingPtDist = d2;
  8031. }
  8032. }
  8033. return this;
  8034. };
  8035. PathProxy.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
  8036. this._drawPendingPt();
  8037. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  8038. if (this._ctx) {
  8039. this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  8040. }
  8041. this._xi = x3;
  8042. this._yi = y3;
  8043. return this;
  8044. };
  8045. PathProxy.prototype.quadraticCurveTo = function (x1, y1, x2, y2) {
  8046. this._drawPendingPt();
  8047. this.addData(CMD.Q, x1, y1, x2, y2);
  8048. if (this._ctx) {
  8049. this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  8050. }
  8051. this._xi = x2;
  8052. this._yi = y2;
  8053. return this;
  8054. };
  8055. PathProxy.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  8056. this._drawPendingPt();
  8057. tmpAngles[0] = startAngle;
  8058. tmpAngles[1] = endAngle;
  8059. normalizeArcAngles(tmpAngles, anticlockwise);
  8060. startAngle = tmpAngles[0];
  8061. endAngle = tmpAngles[1];
  8062. var delta = endAngle - startAngle;
  8063. this.addData(CMD.A, cx, cy, r, r, startAngle, delta, 0, anticlockwise ? 0 : 1);
  8064. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  8065. this._xi = mathCos$1(endAngle) * r + cx;
  8066. this._yi = mathSin$1(endAngle) * r + cy;
  8067. return this;
  8068. };
  8069. PathProxy.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  8070. this._drawPendingPt();
  8071. if (this._ctx) {
  8072. this._ctx.arcTo(x1, y1, x2, y2, radius);
  8073. }
  8074. return this;
  8075. };
  8076. PathProxy.prototype.rect = function (x, y, w, h) {
  8077. this._drawPendingPt();
  8078. this._ctx && this._ctx.rect(x, y, w, h);
  8079. this.addData(CMD.R, x, y, w, h);
  8080. return this;
  8081. };
  8082. PathProxy.prototype.closePath = function () {
  8083. this._drawPendingPt();
  8084. this.addData(CMD.Z);
  8085. var ctx = this._ctx;
  8086. var x0 = this._x0;
  8087. var y0 = this._y0;
  8088. if (ctx) {
  8089. ctx.closePath();
  8090. }
  8091. this._xi = x0;
  8092. this._yi = y0;
  8093. return this;
  8094. };
  8095. PathProxy.prototype.fill = function (ctx) {
  8096. ctx && ctx.fill();
  8097. this.toStatic();
  8098. };
  8099. PathProxy.prototype.stroke = function (ctx) {
  8100. ctx && ctx.stroke();
  8101. this.toStatic();
  8102. };
  8103. PathProxy.prototype.len = function () {
  8104. return this._len;
  8105. };
  8106. PathProxy.prototype.setData = function (data) {
  8107. if (!this._saveData) {
  8108. return;
  8109. }
  8110. var len = data.length;
  8111. if (!(this.data && this.data.length === len) && hasTypedArray) {
  8112. this.data = new Float32Array(len);
  8113. }
  8114. for (var i = 0; i < len; i++) {
  8115. this.data[i] = data[i];
  8116. }
  8117. this._len = len;
  8118. };
  8119. PathProxy.prototype.appendPath = function (path) {
  8120. if (!this._saveData) {
  8121. return;
  8122. }
  8123. if (!(path instanceof Array)) {
  8124. path = [path];
  8125. }
  8126. var len = path.length;
  8127. var appendSize = 0;
  8128. var offset = this._len;
  8129. for (var i = 0; i < len; i++) {
  8130. appendSize += path[i].len();
  8131. }
  8132. var oldData = this.data;
  8133. if (hasTypedArray && (oldData instanceof Float32Array || !oldData)) {
  8134. this.data = new Float32Array(offset + appendSize);
  8135. if (offset > 0 && oldData) {
  8136. for (var k = 0; k < offset; k++) {
  8137. this.data[k] = oldData[k];
  8138. }
  8139. }
  8140. }
  8141. for (var i = 0; i < len; i++) {
  8142. var appendPathData = path[i].data;
  8143. for (var k = 0; k < appendPathData.length; k++) {
  8144. this.data[offset++] = appendPathData[k];
  8145. }
  8146. }
  8147. this._len = offset;
  8148. };
  8149. PathProxy.prototype.addData = function (cmd, a, b, c, d, e, f, g, h) {
  8150. if (!this._saveData) {
  8151. return;
  8152. }
  8153. var data = this.data;
  8154. if (this._len + arguments.length > data.length) {
  8155. this._expandData();
  8156. data = this.data;
  8157. }
  8158. for (var i = 0; i < arguments.length; i++) {
  8159. data[this._len++] = arguments[i];
  8160. }
  8161. };
  8162. PathProxy.prototype._drawPendingPt = function () {
  8163. if (this._pendingPtDist > 0) {
  8164. this._ctx && this._ctx.lineTo(this._pendingPtX, this._pendingPtY);
  8165. this._pendingPtDist = 0;
  8166. }
  8167. };
  8168. PathProxy.prototype._expandData = function () {
  8169. if (!(this.data instanceof Array)) {
  8170. var newData = [];
  8171. for (var i = 0; i < this._len; i++) {
  8172. newData[i] = this.data[i];
  8173. }
  8174. this.data = newData;
  8175. }
  8176. };
  8177. PathProxy.prototype.toStatic = function () {
  8178. if (!this._saveData) {
  8179. return;
  8180. }
  8181. this._drawPendingPt();
  8182. var data = this.data;
  8183. if (data instanceof Array) {
  8184. data.length = this._len;
  8185. if (hasTypedArray && this._len > 11) {
  8186. this.data = new Float32Array(data);
  8187. }
  8188. }
  8189. };
  8190. PathProxy.prototype.getBoundingRect = function () {
  8191. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  8192. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  8193. var data = this.data;
  8194. var xi = 0;
  8195. var yi = 0;
  8196. var x0 = 0;
  8197. var y0 = 0;
  8198. var i;
  8199. for (i = 0; i < this._len;) {
  8200. var cmd = data[i++];
  8201. var isFirst = i === 1;
  8202. if (isFirst) {
  8203. xi = data[i];
  8204. yi = data[i + 1];
  8205. x0 = xi;
  8206. y0 = yi;
  8207. }
  8208. switch (cmd) {
  8209. case CMD.M:
  8210. xi = x0 = data[i++];
  8211. yi = y0 = data[i++];
  8212. min2[0] = x0;
  8213. min2[1] = y0;
  8214. max2[0] = x0;
  8215. max2[1] = y0;
  8216. break;
  8217. case CMD.L:
  8218. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  8219. xi = data[i++];
  8220. yi = data[i++];
  8221. break;
  8222. case CMD.C:
  8223. fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  8224. xi = data[i++];
  8225. yi = data[i++];
  8226. break;
  8227. case CMD.Q:
  8228. fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  8229. xi = data[i++];
  8230. yi = data[i++];
  8231. break;
  8232. case CMD.A:
  8233. var cx = data[i++];
  8234. var cy = data[i++];
  8235. var rx = data[i++];
  8236. var ry = data[i++];
  8237. var startAngle = data[i++];
  8238. var endAngle = data[i++] + startAngle;
  8239. i += 1;
  8240. var anticlockwise = !data[i++];
  8241. if (isFirst) {
  8242. x0 = mathCos$1(startAngle) * rx + cx;
  8243. y0 = mathSin$1(startAngle) * ry + cy;
  8244. }
  8245. fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  8246. xi = mathCos$1(endAngle) * rx + cx;
  8247. yi = mathSin$1(endAngle) * ry + cy;
  8248. break;
  8249. case CMD.R:
  8250. x0 = xi = data[i++];
  8251. y0 = yi = data[i++];
  8252. var width = data[i++];
  8253. var height = data[i++];
  8254. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  8255. break;
  8256. case CMD.Z:
  8257. xi = x0;
  8258. yi = y0;
  8259. break;
  8260. }
  8261. min(min$1, min$1, min2);
  8262. max(max$1, max$1, max2);
  8263. }
  8264. if (i === 0) {
  8265. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  8266. }
  8267. return new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  8268. };
  8269. PathProxy.prototype._calculateLength = function () {
  8270. var data = this.data;
  8271. var len = this._len;
  8272. var ux = this._ux;
  8273. var uy = this._uy;
  8274. var xi = 0;
  8275. var yi = 0;
  8276. var x0 = 0;
  8277. var y0 = 0;
  8278. if (!this._pathSegLen) {
  8279. this._pathSegLen = [];
  8280. }
  8281. var pathSegLen = this._pathSegLen;
  8282. var pathTotalLen = 0;
  8283. var segCount = 0;
  8284. for (var i = 0; i < len;) {
  8285. var cmd = data[i++];
  8286. var isFirst = i === 1;
  8287. if (isFirst) {
  8288. xi = data[i];
  8289. yi = data[i + 1];
  8290. x0 = xi;
  8291. y0 = yi;
  8292. }
  8293. var l = -1;
  8294. switch (cmd) {
  8295. case CMD.M:
  8296. xi = x0 = data[i++];
  8297. yi = y0 = data[i++];
  8298. break;
  8299. case CMD.L: {
  8300. var x2 = data[i++];
  8301. var y2 = data[i++];
  8302. var dx = x2 - xi;
  8303. var dy = y2 - yi;
  8304. if (mathAbs$1(dx) > ux || mathAbs$1(dy) > uy || i === len - 1) {
  8305. l = Math.sqrt(dx * dx + dy * dy);
  8306. xi = x2;
  8307. yi = y2;
  8308. }
  8309. break;
  8310. }
  8311. case CMD.C: {
  8312. var x1 = data[i++];
  8313. var y1 = data[i++];
  8314. var x2 = data[i++];
  8315. var y2 = data[i++];
  8316. var x3 = data[i++];
  8317. var y3 = data[i++];
  8318. l = cubicLength(xi, yi, x1, y1, x2, y2, x3, y3, 10);
  8319. xi = x3;
  8320. yi = y3;
  8321. break;
  8322. }
  8323. case CMD.Q: {
  8324. var x1 = data[i++];
  8325. var y1 = data[i++];
  8326. var x2 = data[i++];
  8327. var y2 = data[i++];
  8328. l = quadraticLength(xi, yi, x1, y1, x2, y2, 10);
  8329. xi = x2;
  8330. yi = y2;
  8331. break;
  8332. }
  8333. case CMD.A:
  8334. var cx = data[i++];
  8335. var cy = data[i++];
  8336. var rx = data[i++];
  8337. var ry = data[i++];
  8338. var startAngle = data[i++];
  8339. var delta = data[i++];
  8340. var endAngle = delta + startAngle;
  8341. i += 1;
  8342. if (isFirst) {
  8343. x0 = mathCos$1(startAngle) * rx + cx;
  8344. y0 = mathSin$1(startAngle) * ry + cy;
  8345. }
  8346. l = mathMax$2(rx, ry) * mathMin$2(PI2$1, Math.abs(delta));
  8347. xi = mathCos$1(endAngle) * rx + cx;
  8348. yi = mathSin$1(endAngle) * ry + cy;
  8349. break;
  8350. case CMD.R: {
  8351. x0 = xi = data[i++];
  8352. y0 = yi = data[i++];
  8353. var width = data[i++];
  8354. var height = data[i++];
  8355. l = width * 2 + height * 2;
  8356. break;
  8357. }
  8358. case CMD.Z: {
  8359. var dx = x0 - xi;
  8360. var dy = y0 - yi;
  8361. l = Math.sqrt(dx * dx + dy * dy);
  8362. xi = x0;
  8363. yi = y0;
  8364. break;
  8365. }
  8366. }
  8367. if (l >= 0) {
  8368. pathSegLen[segCount++] = l;
  8369. pathTotalLen += l;
  8370. }
  8371. }
  8372. this._pathLen = pathTotalLen;
  8373. return pathTotalLen;
  8374. };
  8375. PathProxy.prototype.rebuildPath = function (ctx, percent) {
  8376. var d = this.data;
  8377. var ux = this._ux;
  8378. var uy = this._uy;
  8379. var len = this._len;
  8380. var x0;
  8381. var y0;
  8382. var xi;
  8383. var yi;
  8384. var x;
  8385. var y;
  8386. var drawPart = percent < 1;
  8387. var pathSegLen;
  8388. var pathTotalLen;
  8389. var accumLength = 0;
  8390. var segCount = 0;
  8391. var displayedLength;
  8392. var pendingPtDist = 0;
  8393. var pendingPtX;
  8394. var pendingPtY;
  8395. if (drawPart) {
  8396. if (!this._pathSegLen) {
  8397. this._calculateLength();
  8398. }
  8399. pathSegLen = this._pathSegLen;
  8400. pathTotalLen = this._pathLen;
  8401. displayedLength = percent * pathTotalLen;
  8402. if (!displayedLength) {
  8403. return;
  8404. }
  8405. }
  8406. lo: for (var i = 0; i < len;) {
  8407. var cmd = d[i++];
  8408. var isFirst = i === 1;
  8409. if (isFirst) {
  8410. xi = d[i];
  8411. yi = d[i + 1];
  8412. x0 = xi;
  8413. y0 = yi;
  8414. }
  8415. if (cmd !== CMD.L && pendingPtDist > 0) {
  8416. ctx.lineTo(pendingPtX, pendingPtY);
  8417. pendingPtDist = 0;
  8418. }
  8419. switch (cmd) {
  8420. case CMD.M:
  8421. x0 = xi = d[i++];
  8422. y0 = yi = d[i++];
  8423. ctx.moveTo(xi, yi);
  8424. break;
  8425. case CMD.L: {
  8426. x = d[i++];
  8427. y = d[i++];
  8428. var dx = mathAbs$1(x - xi);
  8429. var dy = mathAbs$1(y - yi);
  8430. if (dx > ux || dy > uy) {
  8431. if (drawPart) {
  8432. var l = pathSegLen[segCount++];
  8433. if (accumLength + l > displayedLength) {
  8434. var t = (displayedLength - accumLength) / l;
  8435. ctx.lineTo(xi * (1 - t) + x * t, yi * (1 - t) + y * t);
  8436. break lo;
  8437. }
  8438. accumLength += l;
  8439. }
  8440. ctx.lineTo(x, y);
  8441. xi = x;
  8442. yi = y;
  8443. pendingPtDist = 0;
  8444. }
  8445. else {
  8446. var d2 = dx * dx + dy * dy;
  8447. if (d2 > pendingPtDist) {
  8448. pendingPtX = x;
  8449. pendingPtY = y;
  8450. pendingPtDist = d2;
  8451. }
  8452. }
  8453. break;
  8454. }
  8455. case CMD.C: {
  8456. var x1 = d[i++];
  8457. var y1 = d[i++];
  8458. var x2 = d[i++];
  8459. var y2 = d[i++];
  8460. var x3 = d[i++];
  8461. var y3 = d[i++];
  8462. if (drawPart) {
  8463. var l = pathSegLen[segCount++];
  8464. if (accumLength + l > displayedLength) {
  8465. var t = (displayedLength - accumLength) / l;
  8466. cubicSubdivide(xi, x1, x2, x3, t, tmpOutX);
  8467. cubicSubdivide(yi, y1, y2, y3, t, tmpOutY);
  8468. ctx.bezierCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2], tmpOutX[3], tmpOutY[3]);
  8469. break lo;
  8470. }
  8471. accumLength += l;
  8472. }
  8473. ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  8474. xi = x3;
  8475. yi = y3;
  8476. break;
  8477. }
  8478. case CMD.Q: {
  8479. var x1 = d[i++];
  8480. var y1 = d[i++];
  8481. var x2 = d[i++];
  8482. var y2 = d[i++];
  8483. if (drawPart) {
  8484. var l = pathSegLen[segCount++];
  8485. if (accumLength + l > displayedLength) {
  8486. var t = (displayedLength - accumLength) / l;
  8487. quadraticSubdivide(xi, x1, x2, t, tmpOutX);
  8488. quadraticSubdivide(yi, y1, y2, t, tmpOutY);
  8489. ctx.quadraticCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2]);
  8490. break lo;
  8491. }
  8492. accumLength += l;
  8493. }
  8494. ctx.quadraticCurveTo(x1, y1, x2, y2);
  8495. xi = x2;
  8496. yi = y2;
  8497. break;
  8498. }
  8499. case CMD.A:
  8500. var cx = d[i++];
  8501. var cy = d[i++];
  8502. var rx = d[i++];
  8503. var ry = d[i++];
  8504. var startAngle = d[i++];
  8505. var delta = d[i++];
  8506. var psi = d[i++];
  8507. var anticlockwise = !d[i++];
  8508. var r = (rx > ry) ? rx : ry;
  8509. var isEllipse = mathAbs$1(rx - ry) > 1e-3;
  8510. var endAngle = startAngle + delta;
  8511. var breakBuild = false;
  8512. if (drawPart) {
  8513. var l = pathSegLen[segCount++];
  8514. if (accumLength + l > displayedLength) {
  8515. endAngle = startAngle + delta * (displayedLength - accumLength) / l;
  8516. breakBuild = true;
  8517. }
  8518. accumLength += l;
  8519. }
  8520. if (isEllipse && ctx.ellipse) {
  8521. ctx.ellipse(cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise);
  8522. }
  8523. else {
  8524. ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  8525. }
  8526. if (breakBuild) {
  8527. break lo;
  8528. }
  8529. if (isFirst) {
  8530. x0 = mathCos$1(startAngle) * rx + cx;
  8531. y0 = mathSin$1(startAngle) * ry + cy;
  8532. }
  8533. xi = mathCos$1(endAngle) * rx + cx;
  8534. yi = mathSin$1(endAngle) * ry + cy;
  8535. break;
  8536. case CMD.R:
  8537. x0 = xi = d[i];
  8538. y0 = yi = d[i + 1];
  8539. x = d[i++];
  8540. y = d[i++];
  8541. var width = d[i++];
  8542. var height = d[i++];
  8543. if (drawPart) {
  8544. var l = pathSegLen[segCount++];
  8545. if (accumLength + l > displayedLength) {
  8546. var d_1 = displayedLength - accumLength;
  8547. ctx.moveTo(x, y);
  8548. ctx.lineTo(x + mathMin$2(d_1, width), y);
  8549. d_1 -= width;
  8550. if (d_1 > 0) {
  8551. ctx.lineTo(x + width, y + mathMin$2(d_1, height));
  8552. }
  8553. d_1 -= height;
  8554. if (d_1 > 0) {
  8555. ctx.lineTo(x + mathMax$2(width - d_1, 0), y + height);
  8556. }
  8557. d_1 -= width;
  8558. if (d_1 > 0) {
  8559. ctx.lineTo(x, y + mathMax$2(height - d_1, 0));
  8560. }
  8561. break lo;
  8562. }
  8563. accumLength += l;
  8564. }
  8565. ctx.rect(x, y, width, height);
  8566. break;
  8567. case CMD.Z:
  8568. if (drawPart) {
  8569. var l = pathSegLen[segCount++];
  8570. if (accumLength + l > displayedLength) {
  8571. var t = (displayedLength - accumLength) / l;
  8572. ctx.lineTo(xi * (1 - t) + x0 * t, yi * (1 - t) + y0 * t);
  8573. break lo;
  8574. }
  8575. accumLength += l;
  8576. }
  8577. ctx.closePath();
  8578. xi = x0;
  8579. yi = y0;
  8580. }
  8581. }
  8582. };
  8583. PathProxy.prototype.clone = function () {
  8584. var newProxy = new PathProxy();
  8585. var data = this.data;
  8586. newProxy.data = data.slice ? data.slice()
  8587. : Array.prototype.slice.call(data);
  8588. newProxy._len = this._len;
  8589. return newProxy;
  8590. };
  8591. PathProxy.prototype.canSave = function () {
  8592. return !!this._saveData;
  8593. };
  8594. PathProxy.CMD = CMD;
  8595. PathProxy.initDefaultProps = (function () {
  8596. var proto = PathProxy.prototype;
  8597. proto._saveData = true;
  8598. proto._ux = 0;
  8599. proto._uy = 0;
  8600. proto._pendingPtDist = 0;
  8601. proto._version = 0;
  8602. })();
  8603. return PathProxy;
  8604. }());
  8605. function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
  8606. if (lineWidth === 0) {
  8607. return false;
  8608. }
  8609. var _l = lineWidth;
  8610. var _a = 0;
  8611. var _b = x0;
  8612. if ((y > y0 + _l && y > y1 + _l)
  8613. || (y < y0 - _l && y < y1 - _l)
  8614. || (x > x0 + _l && x > x1 + _l)
  8615. || (x < x0 - _l && x < x1 - _l)) {
  8616. return false;
  8617. }
  8618. if (x0 !== x1) {
  8619. _a = (y0 - y1) / (x0 - x1);
  8620. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  8621. }
  8622. else {
  8623. return Math.abs(x - x0) <= _l / 2;
  8624. }
  8625. var tmp = _a * x - y + _b;
  8626. var _s = tmp * tmp / (_a * _a + 1);
  8627. return _s <= _l / 2 * _l / 2;
  8628. }
  8629. function containStroke$1(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  8630. if (lineWidth === 0) {
  8631. return false;
  8632. }
  8633. var _l = lineWidth;
  8634. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  8635. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  8636. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  8637. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)) {
  8638. return false;
  8639. }
  8640. var d = cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  8641. return d <= _l / 2;
  8642. }
  8643. function containStroke$2(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  8644. if (lineWidth === 0) {
  8645. return false;
  8646. }
  8647. var _l = lineWidth;
  8648. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l)
  8649. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  8650. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  8651. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)) {
  8652. return false;
  8653. }
  8654. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  8655. return d <= _l / 2;
  8656. }
  8657. var PI2$2 = Math.PI * 2;
  8658. function normalizeRadian(angle) {
  8659. angle %= PI2$2;
  8660. if (angle < 0) {
  8661. angle += PI2$2;
  8662. }
  8663. return angle;
  8664. }
  8665. var PI2$3 = Math.PI * 2;
  8666. function containStroke$3(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  8667. if (lineWidth === 0) {
  8668. return false;
  8669. }
  8670. var _l = lineWidth;
  8671. x -= cx;
  8672. y -= cy;
  8673. var d = Math.sqrt(x * x + y * y);
  8674. if ((d - _l > r) || (d + _l < r)) {
  8675. return false;
  8676. }
  8677. if (Math.abs(startAngle - endAngle) % PI2$3 < 1e-4) {
  8678. return true;
  8679. }
  8680. if (anticlockwise) {
  8681. var tmp = startAngle;
  8682. startAngle = normalizeRadian(endAngle);
  8683. endAngle = normalizeRadian(tmp);
  8684. }
  8685. else {
  8686. startAngle = normalizeRadian(startAngle);
  8687. endAngle = normalizeRadian(endAngle);
  8688. }
  8689. if (startAngle > endAngle) {
  8690. endAngle += PI2$3;
  8691. }
  8692. var angle = Math.atan2(y, x);
  8693. if (angle < 0) {
  8694. angle += PI2$3;
  8695. }
  8696. return (angle >= startAngle && angle <= endAngle)
  8697. || (angle + PI2$3 >= startAngle && angle + PI2$3 <= endAngle);
  8698. }
  8699. function windingLine(x0, y0, x1, y1, x, y) {
  8700. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  8701. return 0;
  8702. }
  8703. if (y1 === y0) {
  8704. return 0;
  8705. }
  8706. var t = (y - y0) / (y1 - y0);
  8707. var dir = y1 < y0 ? 1 : -1;
  8708. if (t === 1 || t === 0) {
  8709. dir = y1 < y0 ? 0.5 : -0.5;
  8710. }
  8711. var x_ = t * (x1 - x0) + x0;
  8712. return x_ === x ? Infinity : x_ > x ? dir : 0;
  8713. }
  8714. var CMD$1 = PathProxy.CMD;
  8715. var PI2$4 = Math.PI * 2;
  8716. var EPSILON$4 = 1e-4;
  8717. function isAroundEqual(a, b) {
  8718. return Math.abs(a - b) < EPSILON$4;
  8719. }
  8720. var roots = [-1, -1, -1];
  8721. var extrema = [-1, -1];
  8722. function swapExtrema() {
  8723. var tmp = extrema[0];
  8724. extrema[0] = extrema[1];
  8725. extrema[1] = tmp;
  8726. }
  8727. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  8728. if ((y > y0 && y > y1 && y > y2 && y > y3)
  8729. || (y < y0 && y < y1 && y < y2 && y < y3)) {
  8730. return 0;
  8731. }
  8732. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  8733. if (nRoots === 0) {
  8734. return 0;
  8735. }
  8736. else {
  8737. var w = 0;
  8738. var nExtrema = -1;
  8739. var y0_ = void 0;
  8740. var y1_ = void 0;
  8741. for (var i = 0; i < nRoots; i++) {
  8742. var t = roots[i];
  8743. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  8744. var x_ = cubicAt(x0, x1, x2, x3, t);
  8745. if (x_ < x) {
  8746. continue;
  8747. }
  8748. if (nExtrema < 0) {
  8749. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  8750. if (extrema[1] < extrema[0] && nExtrema > 1) {
  8751. swapExtrema();
  8752. }
  8753. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  8754. if (nExtrema > 1) {
  8755. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  8756. }
  8757. }
  8758. if (nExtrema === 2) {
  8759. if (t < extrema[0]) {
  8760. w += y0_ < y0 ? unit : -unit;
  8761. }
  8762. else if (t < extrema[1]) {
  8763. w += y1_ < y0_ ? unit : -unit;
  8764. }
  8765. else {
  8766. w += y3 < y1_ ? unit : -unit;
  8767. }
  8768. }
  8769. else {
  8770. if (t < extrema[0]) {
  8771. w += y0_ < y0 ? unit : -unit;
  8772. }
  8773. else {
  8774. w += y3 < y0_ ? unit : -unit;
  8775. }
  8776. }
  8777. }
  8778. return w;
  8779. }
  8780. }
  8781. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  8782. if ((y > y0 && y > y1 && y > y2)
  8783. || (y < y0 && y < y1 && y < y2)) {
  8784. return 0;
  8785. }
  8786. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  8787. if (nRoots === 0) {
  8788. return 0;
  8789. }
  8790. else {
  8791. var t = quadraticExtremum(y0, y1, y2);
  8792. if (t >= 0 && t <= 1) {
  8793. var w = 0;
  8794. var y_ = quadraticAt(y0, y1, y2, t);
  8795. for (var i = 0; i < nRoots; i++) {
  8796. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  8797. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  8798. if (x_ < x) {
  8799. continue;
  8800. }
  8801. if (roots[i] < t) {
  8802. w += y_ < y0 ? unit : -unit;
  8803. }
  8804. else {
  8805. w += y2 < y_ ? unit : -unit;
  8806. }
  8807. }
  8808. return w;
  8809. }
  8810. else {
  8811. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  8812. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  8813. if (x_ < x) {
  8814. return 0;
  8815. }
  8816. return y2 < y0 ? unit : -unit;
  8817. }
  8818. }
  8819. }
  8820. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  8821. y -= cy;
  8822. if (y > r || y < -r) {
  8823. return 0;
  8824. }
  8825. var tmp = Math.sqrt(r * r - y * y);
  8826. roots[0] = -tmp;
  8827. roots[1] = tmp;
  8828. var dTheta = Math.abs(startAngle - endAngle);
  8829. if (dTheta < 1e-4) {
  8830. return 0;
  8831. }
  8832. if (dTheta >= PI2$4 - 1e-4) {
  8833. startAngle = 0;
  8834. endAngle = PI2$4;
  8835. var dir = anticlockwise ? 1 : -1;
  8836. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  8837. return dir;
  8838. }
  8839. else {
  8840. return 0;
  8841. }
  8842. }
  8843. if (startAngle > endAngle) {
  8844. var tmp_1 = startAngle;
  8845. startAngle = endAngle;
  8846. endAngle = tmp_1;
  8847. }
  8848. if (startAngle < 0) {
  8849. startAngle += PI2$4;
  8850. endAngle += PI2$4;
  8851. }
  8852. var w = 0;
  8853. for (var i = 0; i < 2; i++) {
  8854. var x_ = roots[i];
  8855. if (x_ + cx > x) {
  8856. var angle = Math.atan2(y, x_);
  8857. var dir = anticlockwise ? 1 : -1;
  8858. if (angle < 0) {
  8859. angle = PI2$4 + angle;
  8860. }
  8861. if ((angle >= startAngle && angle <= endAngle)
  8862. || (angle + PI2$4 >= startAngle && angle + PI2$4 <= endAngle)) {
  8863. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  8864. dir = -dir;
  8865. }
  8866. w += dir;
  8867. }
  8868. }
  8869. }
  8870. return w;
  8871. }
  8872. function containPath(path, lineWidth, isStroke, x, y) {
  8873. var data = path.data;
  8874. var len = path.len();
  8875. var w = 0;
  8876. var xi = 0;
  8877. var yi = 0;
  8878. var x0 = 0;
  8879. var y0 = 0;
  8880. var x1;
  8881. var y1;
  8882. for (var i = 0; i < len;) {
  8883. var cmd = data[i++];
  8884. var isFirst = i === 1;
  8885. if (cmd === CMD$1.M && i > 1) {
  8886. if (!isStroke) {
  8887. w += windingLine(xi, yi, x0, y0, x, y);
  8888. }
  8889. }
  8890. if (isFirst) {
  8891. xi = data[i];
  8892. yi = data[i + 1];
  8893. x0 = xi;
  8894. y0 = yi;
  8895. }
  8896. switch (cmd) {
  8897. case CMD$1.M:
  8898. x0 = data[i++];
  8899. y0 = data[i++];
  8900. xi = x0;
  8901. yi = y0;
  8902. break;
  8903. case CMD$1.L:
  8904. if (isStroke) {
  8905. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  8906. return true;
  8907. }
  8908. }
  8909. else {
  8910. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  8911. }
  8912. xi = data[i++];
  8913. yi = data[i++];
  8914. break;
  8915. case CMD$1.C:
  8916. if (isStroke) {
  8917. if (containStroke$1(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8918. return true;
  8919. }
  8920. }
  8921. else {
  8922. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8923. }
  8924. xi = data[i++];
  8925. yi = data[i++];
  8926. break;
  8927. case CMD$1.Q:
  8928. if (isStroke) {
  8929. if (containStroke$2(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  8930. return true;
  8931. }
  8932. }
  8933. else {
  8934. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  8935. }
  8936. xi = data[i++];
  8937. yi = data[i++];
  8938. break;
  8939. case CMD$1.A:
  8940. var cx = data[i++];
  8941. var cy = data[i++];
  8942. var rx = data[i++];
  8943. var ry = data[i++];
  8944. var theta = data[i++];
  8945. var dTheta = data[i++];
  8946. i += 1;
  8947. var anticlockwise = !!(1 - data[i++]);
  8948. x1 = Math.cos(theta) * rx + cx;
  8949. y1 = Math.sin(theta) * ry + cy;
  8950. if (!isFirst) {
  8951. w += windingLine(xi, yi, x1, y1, x, y);
  8952. }
  8953. else {
  8954. x0 = x1;
  8955. y0 = y1;
  8956. }
  8957. var _x = (x - cx) * ry / rx + cx;
  8958. if (isStroke) {
  8959. if (containStroke$3(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  8960. return true;
  8961. }
  8962. }
  8963. else {
  8964. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  8965. }
  8966. xi = Math.cos(theta + dTheta) * rx + cx;
  8967. yi = Math.sin(theta + dTheta) * ry + cy;
  8968. break;
  8969. case CMD$1.R:
  8970. x0 = xi = data[i++];
  8971. y0 = yi = data[i++];
  8972. var width = data[i++];
  8973. var height = data[i++];
  8974. x1 = x0 + width;
  8975. y1 = y0 + height;
  8976. if (isStroke) {
  8977. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  8978. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  8979. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  8980. || containStroke(x0, y1, x0, y0, lineWidth, x, y)) {
  8981. return true;
  8982. }
  8983. }
  8984. else {
  8985. w += windingLine(x1, y0, x1, y1, x, y);
  8986. w += windingLine(x0, y1, x0, y0, x, y);
  8987. }
  8988. break;
  8989. case CMD$1.Z:
  8990. if (isStroke) {
  8991. if (containStroke(xi, yi, x0, y0, lineWidth, x, y)) {
  8992. return true;
  8993. }
  8994. }
  8995. else {
  8996. w += windingLine(xi, yi, x0, y0, x, y);
  8997. }
  8998. xi = x0;
  8999. yi = y0;
  9000. break;
  9001. }
  9002. }
  9003. if (!isStroke && !isAroundEqual(yi, y0)) {
  9004. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  9005. }
  9006. return w !== 0;
  9007. }
  9008. function contain(pathProxy, x, y) {
  9009. return containPath(pathProxy, 0, false, x, y);
  9010. }
  9011. function containStroke$4(pathProxy, lineWidth, x, y) {
  9012. return containPath(pathProxy, lineWidth, true, x, y);
  9013. }
  9014. var DEFAULT_PATH_STYLE = defaults({
  9015. fill: '#000',
  9016. stroke: null,
  9017. strokePercent: 1,
  9018. fillOpacity: 1,
  9019. strokeOpacity: 1,
  9020. lineDashOffset: 0,
  9021. lineWidth: 1,
  9022. lineCap: 'butt',
  9023. miterLimit: 10,
  9024. strokeNoScale: false,
  9025. strokeFirst: false
  9026. }, DEFAULT_COMMON_STYLE);
  9027. var DEFAULT_PATH_ANIMATION_PROPS = {
  9028. style: defaults({
  9029. fill: true,
  9030. stroke: true,
  9031. strokePercent: true,
  9032. fillOpacity: true,
  9033. strokeOpacity: true,
  9034. lineDashOffset: true,
  9035. lineWidth: true,
  9036. miterLimit: true
  9037. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  9038. };
  9039. var pathCopyParams = TRANSFORMABLE_PROPS.concat(['invisible',
  9040. 'culling', 'z', 'z2', 'zlevel', 'parent'
  9041. ]);
  9042. var Path = (function (_super) {
  9043. __extends(Path, _super);
  9044. function Path(opts) {
  9045. return _super.call(this, opts) || this;
  9046. }
  9047. Path.prototype.update = function () {
  9048. var _this = this;
  9049. _super.prototype.update.call(this);
  9050. var style = this.style;
  9051. if (style.decal) {
  9052. var decalEl = this._decalEl = this._decalEl || new Path();
  9053. if (decalEl.buildPath === Path.prototype.buildPath) {
  9054. decalEl.buildPath = function (ctx) {
  9055. _this.buildPath(ctx, _this.shape);
  9056. };
  9057. }
  9058. decalEl.silent = true;
  9059. var decalElStyle = decalEl.style;
  9060. for (var key in style) {
  9061. if (decalElStyle[key] !== style[key]) {
  9062. decalElStyle[key] = style[key];
  9063. }
  9064. }
  9065. decalElStyle.fill = style.fill ? style.decal : null;
  9066. decalElStyle.decal = null;
  9067. decalElStyle.shadowColor = null;
  9068. style.strokeFirst && (decalElStyle.stroke = null);
  9069. for (var i = 0; i < pathCopyParams.length; ++i) {
  9070. decalEl[pathCopyParams[i]] = this[pathCopyParams[i]];
  9071. }
  9072. decalEl.__dirty |= REDRAW_BIT;
  9073. }
  9074. else if (this._decalEl) {
  9075. this._decalEl = null;
  9076. }
  9077. };
  9078. Path.prototype.getDecalElement = function () {
  9079. return this._decalEl;
  9080. };
  9081. Path.prototype._init = function (props) {
  9082. var keysArr = keys(props);
  9083. this.shape = this.getDefaultShape();
  9084. var defaultStyle = this.getDefaultStyle();
  9085. if (defaultStyle) {
  9086. this.useStyle(defaultStyle);
  9087. }
  9088. for (var i = 0; i < keysArr.length; i++) {
  9089. var key = keysArr[i];
  9090. var value = props[key];
  9091. if (key === 'style') {
  9092. if (!this.style) {
  9093. this.useStyle(value);
  9094. }
  9095. else {
  9096. extend(this.style, value);
  9097. }
  9098. }
  9099. else if (key === 'shape') {
  9100. extend(this.shape, value);
  9101. }
  9102. else {
  9103. _super.prototype.attrKV.call(this, key, value);
  9104. }
  9105. }
  9106. if (!this.style) {
  9107. this.useStyle({});
  9108. }
  9109. };
  9110. Path.prototype.getDefaultStyle = function () {
  9111. return null;
  9112. };
  9113. Path.prototype.getDefaultShape = function () {
  9114. return {};
  9115. };
  9116. Path.prototype.canBeInsideText = function () {
  9117. return this.hasFill();
  9118. };
  9119. Path.prototype.getInsideTextFill = function () {
  9120. var pathFill = this.style.fill;
  9121. if (pathFill !== 'none') {
  9122. if (isString(pathFill)) {
  9123. var fillLum = lum(pathFill, 0);
  9124. if (fillLum > 0.5) {
  9125. return DARK_LABEL_COLOR;
  9126. }
  9127. else if (fillLum > 0.2) {
  9128. return LIGHTER_LABEL_COLOR;
  9129. }
  9130. return LIGHT_LABEL_COLOR;
  9131. }
  9132. else if (pathFill) {
  9133. return LIGHT_LABEL_COLOR;
  9134. }
  9135. }
  9136. return DARK_LABEL_COLOR;
  9137. };
  9138. Path.prototype.getInsideTextStroke = function (textFill) {
  9139. var pathFill = this.style.fill;
  9140. if (isString(pathFill)) {
  9141. var zr = this.__zr;
  9142. var isDarkMode = !!(zr && zr.isDarkMode());
  9143. var isDarkLabel = lum(textFill, 0) < DARK_MODE_THRESHOLD;
  9144. if (isDarkMode === isDarkLabel) {
  9145. return pathFill;
  9146. }
  9147. }
  9148. };
  9149. Path.prototype.buildPath = function (ctx, shapeCfg, inBatch) { };
  9150. Path.prototype.pathUpdated = function () {
  9151. this.__dirty &= ~SHAPE_CHANGED_BIT;
  9152. };
  9153. Path.prototype.getUpdatedPathProxy = function (inBatch) {
  9154. !this.path && this.createPathProxy();
  9155. this.path.beginPath();
  9156. this.buildPath(this.path, this.shape, inBatch);
  9157. return this.path;
  9158. };
  9159. Path.prototype.createPathProxy = function () {
  9160. this.path = new PathProxy(false);
  9161. };
  9162. Path.prototype.hasStroke = function () {
  9163. var style = this.style;
  9164. var stroke = style.stroke;
  9165. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  9166. };
  9167. Path.prototype.hasFill = function () {
  9168. var style = this.style;
  9169. var fill = style.fill;
  9170. return fill != null && fill !== 'none';
  9171. };
  9172. Path.prototype.getBoundingRect = function () {
  9173. var rect = this._rect;
  9174. var style = this.style;
  9175. var needsUpdateRect = !rect;
  9176. if (needsUpdateRect) {
  9177. var firstInvoke = false;
  9178. if (!this.path) {
  9179. firstInvoke = true;
  9180. this.createPathProxy();
  9181. }
  9182. var path = this.path;
  9183. if (firstInvoke || (this.__dirty & SHAPE_CHANGED_BIT)) {
  9184. path.beginPath();
  9185. this.buildPath(path, this.shape, false);
  9186. this.pathUpdated();
  9187. }
  9188. rect = path.getBoundingRect();
  9189. }
  9190. this._rect = rect;
  9191. if (this.hasStroke() && this.path && this.path.len() > 0) {
  9192. var rectStroke = this._rectStroke || (this._rectStroke = rect.clone());
  9193. if (this.__dirty || needsUpdateRect) {
  9194. rectStroke.copy(rect);
  9195. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  9196. var w = style.lineWidth;
  9197. if (!this.hasFill()) {
  9198. var strokeContainThreshold = this.strokeContainThreshold;
  9199. w = Math.max(w, strokeContainThreshold == null ? 4 : strokeContainThreshold);
  9200. }
  9201. if (lineScale > 1e-10) {
  9202. rectStroke.width += w / lineScale;
  9203. rectStroke.height += w / lineScale;
  9204. rectStroke.x -= w / lineScale / 2;
  9205. rectStroke.y -= w / lineScale / 2;
  9206. }
  9207. }
  9208. return rectStroke;
  9209. }
  9210. return rect;
  9211. };
  9212. Path.prototype.contain = function (x, y) {
  9213. var localPos = this.transformCoordToLocal(x, y);
  9214. var rect = this.getBoundingRect();
  9215. var style = this.style;
  9216. x = localPos[0];
  9217. y = localPos[1];
  9218. if (rect.contain(x, y)) {
  9219. var pathProxy = this.path;
  9220. if (this.hasStroke()) {
  9221. var lineWidth = style.lineWidth;
  9222. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  9223. if (lineScale > 1e-10) {
  9224. if (!this.hasFill()) {
  9225. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  9226. }
  9227. if (containStroke$4(pathProxy, lineWidth / lineScale, x, y)) {
  9228. return true;
  9229. }
  9230. }
  9231. }
  9232. if (this.hasFill()) {
  9233. return contain(pathProxy, x, y);
  9234. }
  9235. }
  9236. return false;
  9237. };
  9238. Path.prototype.dirtyShape = function () {
  9239. this.__dirty |= SHAPE_CHANGED_BIT;
  9240. if (this._rect) {
  9241. this._rect = null;
  9242. }
  9243. if (this._decalEl) {
  9244. this._decalEl.dirtyShape();
  9245. }
  9246. this.markRedraw();
  9247. };
  9248. Path.prototype.dirty = function () {
  9249. this.dirtyStyle();
  9250. this.dirtyShape();
  9251. };
  9252. Path.prototype.animateShape = function (loop) {
  9253. return this.animate('shape', loop);
  9254. };
  9255. Path.prototype.updateDuringAnimation = function (targetKey) {
  9256. if (targetKey === 'style') {
  9257. this.dirtyStyle();
  9258. }
  9259. else if (targetKey === 'shape') {
  9260. this.dirtyShape();
  9261. }
  9262. else {
  9263. this.markRedraw();
  9264. }
  9265. };
  9266. Path.prototype.attrKV = function (key, value) {
  9267. if (key === 'shape') {
  9268. this.setShape(value);
  9269. }
  9270. else {
  9271. _super.prototype.attrKV.call(this, key, value);
  9272. }
  9273. };
  9274. Path.prototype.setShape = function (keyOrObj, value) {
  9275. var shape = this.shape;
  9276. if (!shape) {
  9277. shape = this.shape = {};
  9278. }
  9279. if (typeof keyOrObj === 'string') {
  9280. shape[keyOrObj] = value;
  9281. }
  9282. else {
  9283. extend(shape, keyOrObj);
  9284. }
  9285. this.dirtyShape();
  9286. return this;
  9287. };
  9288. Path.prototype.shapeChanged = function () {
  9289. return !!(this.__dirty & SHAPE_CHANGED_BIT);
  9290. };
  9291. Path.prototype.createStyle = function (obj) {
  9292. return createObject(DEFAULT_PATH_STYLE, obj);
  9293. };
  9294. Path.prototype._innerSaveToNormal = function (toState) {
  9295. _super.prototype._innerSaveToNormal.call(this, toState);
  9296. var normalState = this._normalState;
  9297. if (toState.shape && !normalState.shape) {
  9298. normalState.shape = extend({}, this.shape);
  9299. }
  9300. };
  9301. Path.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  9302. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  9303. var needsRestoreToNormal = !(state && keepCurrentStates);
  9304. var targetShape;
  9305. if (state && state.shape) {
  9306. if (transition) {
  9307. if (keepCurrentStates) {
  9308. targetShape = state.shape;
  9309. }
  9310. else {
  9311. targetShape = extend({}, normalState.shape);
  9312. extend(targetShape, state.shape);
  9313. }
  9314. }
  9315. else {
  9316. targetShape = extend({}, keepCurrentStates ? this.shape : normalState.shape);
  9317. extend(targetShape, state.shape);
  9318. }
  9319. }
  9320. else if (needsRestoreToNormal) {
  9321. targetShape = normalState.shape;
  9322. }
  9323. if (targetShape) {
  9324. if (transition) {
  9325. this.shape = extend({}, this.shape);
  9326. var targetShapePrimaryProps = {};
  9327. var shapeKeys = keys(targetShape);
  9328. for (var i = 0; i < shapeKeys.length; i++) {
  9329. var key = shapeKeys[i];
  9330. if (typeof targetShape[key] === 'object') {
  9331. this.shape[key] = targetShape[key];
  9332. }
  9333. else {
  9334. targetShapePrimaryProps[key] = targetShape[key];
  9335. }
  9336. }
  9337. this._transitionState(stateName, {
  9338. shape: targetShapePrimaryProps
  9339. }, animationCfg);
  9340. }
  9341. else {
  9342. this.shape = targetShape;
  9343. this.dirtyShape();
  9344. }
  9345. }
  9346. };
  9347. Path.prototype._mergeStates = function (states) {
  9348. var mergedState = _super.prototype._mergeStates.call(this, states);
  9349. var mergedShape;
  9350. for (var i = 0; i < states.length; i++) {
  9351. var state = states[i];
  9352. if (state.shape) {
  9353. mergedShape = mergedShape || {};
  9354. this._mergeStyle(mergedShape, state.shape);
  9355. }
  9356. }
  9357. if (mergedShape) {
  9358. mergedState.shape = mergedShape;
  9359. }
  9360. return mergedState;
  9361. };
  9362. Path.prototype.getAnimationStyleProps = function () {
  9363. return DEFAULT_PATH_ANIMATION_PROPS;
  9364. };
  9365. Path.prototype.isZeroArea = function () {
  9366. return false;
  9367. };
  9368. Path.extend = function (defaultProps) {
  9369. var Sub = (function (_super) {
  9370. __extends(Sub, _super);
  9371. function Sub(opts) {
  9372. var _this = _super.call(this, opts) || this;
  9373. defaultProps.init && defaultProps.init.call(_this, opts);
  9374. return _this;
  9375. }
  9376. Sub.prototype.getDefaultStyle = function () {
  9377. return clone(defaultProps.style);
  9378. };
  9379. Sub.prototype.getDefaultShape = function () {
  9380. return clone(defaultProps.shape);
  9381. };
  9382. return Sub;
  9383. }(Path));
  9384. for (var key in defaultProps) {
  9385. if (typeof defaultProps[key] === 'function') {
  9386. Sub.prototype[key] = defaultProps[key];
  9387. }
  9388. }
  9389. return Sub;
  9390. };
  9391. Path.initDefaultProps = (function () {
  9392. var pathProto = Path.prototype;
  9393. pathProto.type = 'path';
  9394. pathProto.strokeContainThreshold = 5;
  9395. pathProto.segmentIgnoreThreshold = 0;
  9396. pathProto.subPixelOptimize = false;
  9397. pathProto.autoBatch = false;
  9398. pathProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT | SHAPE_CHANGED_BIT;
  9399. })();
  9400. return Path;
  9401. }(Displayable));
  9402. var CMD$2 = PathProxy.CMD;
  9403. var points = [[], [], []];
  9404. var mathSqrt$1 = Math.sqrt;
  9405. var mathAtan2 = Math.atan2;
  9406. function transformPath(path, m) {
  9407. if (!m) {
  9408. return;
  9409. }
  9410. var data = path.data;
  9411. var len = path.len();
  9412. var cmd;
  9413. var nPoint;
  9414. var i;
  9415. var j;
  9416. var k;
  9417. var p;
  9418. var M = CMD$2.M;
  9419. var C = CMD$2.C;
  9420. var L = CMD$2.L;
  9421. var R = CMD$2.R;
  9422. var A = CMD$2.A;
  9423. var Q = CMD$2.Q;
  9424. for (i = 0, j = 0; i < len;) {
  9425. cmd = data[i++];
  9426. j = i;
  9427. nPoint = 0;
  9428. switch (cmd) {
  9429. case M:
  9430. nPoint = 1;
  9431. break;
  9432. case L:
  9433. nPoint = 1;
  9434. break;
  9435. case C:
  9436. nPoint = 3;
  9437. break;
  9438. case Q:
  9439. nPoint = 2;
  9440. break;
  9441. case A:
  9442. var x = m[4];
  9443. var y = m[5];
  9444. var sx = mathSqrt$1(m[0] * m[0] + m[1] * m[1]);
  9445. var sy = mathSqrt$1(m[2] * m[2] + m[3] * m[3]);
  9446. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  9447. data[i] *= sx;
  9448. data[i++] += x;
  9449. data[i] *= sy;
  9450. data[i++] += y;
  9451. data[i++] *= sx;
  9452. data[i++] *= sy;
  9453. data[i++] += angle;
  9454. data[i++] += angle;
  9455. i += 2;
  9456. j = i;
  9457. break;
  9458. case R:
  9459. p[0] = data[i++];
  9460. p[1] = data[i++];
  9461. applyTransform(p, p, m);
  9462. data[j++] = p[0];
  9463. data[j++] = p[1];
  9464. p[0] += data[i++];
  9465. p[1] += data[i++];
  9466. applyTransform(p, p, m);
  9467. data[j++] = p[0];
  9468. data[j++] = p[1];
  9469. }
  9470. for (k = 0; k < nPoint; k++) {
  9471. var p_1 = points[k];
  9472. p_1[0] = data[i++];
  9473. p_1[1] = data[i++];
  9474. applyTransform(p_1, p_1, m);
  9475. data[j++] = p_1[0];
  9476. data[j++] = p_1[1];
  9477. }
  9478. }
  9479. path.increaseVersion();
  9480. }
  9481. var mathSqrt$2 = Math.sqrt;
  9482. var mathSin$2 = Math.sin;
  9483. var mathCos$2 = Math.cos;
  9484. var PI$1 = Math.PI;
  9485. function vMag(v) {
  9486. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  9487. }
  9488. function vRatio(u, v) {
  9489. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  9490. }
  9491. function vAngle(u, v) {
  9492. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  9493. * Math.acos(vRatio(u, v));
  9494. }
  9495. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  9496. var psi = psiDeg * (PI$1 / 180.0);
  9497. var xp = mathCos$2(psi) * (x1 - x2) / 2.0
  9498. + mathSin$2(psi) * (y1 - y2) / 2.0;
  9499. var yp = -1 * mathSin$2(psi) * (x1 - x2) / 2.0
  9500. + mathCos$2(psi) * (y1 - y2) / 2.0;
  9501. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  9502. if (lambda > 1) {
  9503. rx *= mathSqrt$2(lambda);
  9504. ry *= mathSqrt$2(lambda);
  9505. }
  9506. var f = (fa === fs ? -1 : 1)
  9507. * mathSqrt$2((((rx * rx) * (ry * ry))
  9508. - ((rx * rx) * (yp * yp))
  9509. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  9510. + (ry * ry) * (xp * xp))) || 0;
  9511. var cxp = f * rx * yp / ry;
  9512. var cyp = f * -ry * xp / rx;
  9513. var cx = (x1 + x2) / 2.0
  9514. + mathCos$2(psi) * cxp
  9515. - mathSin$2(psi) * cyp;
  9516. var cy = (y1 + y2) / 2.0
  9517. + mathSin$2(psi) * cxp
  9518. + mathCos$2(psi) * cyp;
  9519. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  9520. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  9521. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  9522. var dTheta = vAngle(u, v);
  9523. if (vRatio(u, v) <= -1) {
  9524. dTheta = PI$1;
  9525. }
  9526. if (vRatio(u, v) >= 1) {
  9527. dTheta = 0;
  9528. }
  9529. if (dTheta < 0) {
  9530. var n = Math.round(dTheta / PI$1 * 1e6) / 1e6;
  9531. dTheta = PI$1 * 2 + (n % 2) * PI$1;
  9532. }
  9533. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  9534. }
  9535. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  9536. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  9537. function createPathProxyFromString(data) {
  9538. var path = new PathProxy();
  9539. if (!data) {
  9540. return path;
  9541. }
  9542. var cpx = 0;
  9543. var cpy = 0;
  9544. var subpathX = cpx;
  9545. var subpathY = cpy;
  9546. var prevCmd;
  9547. var CMD = PathProxy.CMD;
  9548. var cmdList = data.match(commandReg);
  9549. if (!cmdList) {
  9550. return path;
  9551. }
  9552. for (var l = 0; l < cmdList.length; l++) {
  9553. var cmdText = cmdList[l];
  9554. var cmdStr = cmdText.charAt(0);
  9555. var cmd = void 0;
  9556. var p = cmdText.match(numberReg) || [];
  9557. var pLen = p.length;
  9558. for (var i = 0; i < pLen; i++) {
  9559. p[i] = parseFloat(p[i]);
  9560. }
  9561. var off = 0;
  9562. while (off < pLen) {
  9563. var ctlPtx = void 0;
  9564. var ctlPty = void 0;
  9565. var rx = void 0;
  9566. var ry = void 0;
  9567. var psi = void 0;
  9568. var fa = void 0;
  9569. var fs = void 0;
  9570. var x1 = cpx;
  9571. var y1 = cpy;
  9572. var len = void 0;
  9573. var pathData = void 0;
  9574. switch (cmdStr) {
  9575. case 'l':
  9576. cpx += p[off++];
  9577. cpy += p[off++];
  9578. cmd = CMD.L;
  9579. path.addData(cmd, cpx, cpy);
  9580. break;
  9581. case 'L':
  9582. cpx = p[off++];
  9583. cpy = p[off++];
  9584. cmd = CMD.L;
  9585. path.addData(cmd, cpx, cpy);
  9586. break;
  9587. case 'm':
  9588. cpx += p[off++];
  9589. cpy += p[off++];
  9590. cmd = CMD.M;
  9591. path.addData(cmd, cpx, cpy);
  9592. subpathX = cpx;
  9593. subpathY = cpy;
  9594. cmdStr = 'l';
  9595. break;
  9596. case 'M':
  9597. cpx = p[off++];
  9598. cpy = p[off++];
  9599. cmd = CMD.M;
  9600. path.addData(cmd, cpx, cpy);
  9601. subpathX = cpx;
  9602. subpathY = cpy;
  9603. cmdStr = 'L';
  9604. break;
  9605. case 'h':
  9606. cpx += p[off++];
  9607. cmd = CMD.L;
  9608. path.addData(cmd, cpx, cpy);
  9609. break;
  9610. case 'H':
  9611. cpx = p[off++];
  9612. cmd = CMD.L;
  9613. path.addData(cmd, cpx, cpy);
  9614. break;
  9615. case 'v':
  9616. cpy += p[off++];
  9617. cmd = CMD.L;
  9618. path.addData(cmd, cpx, cpy);
  9619. break;
  9620. case 'V':
  9621. cpy = p[off++];
  9622. cmd = CMD.L;
  9623. path.addData(cmd, cpx, cpy);
  9624. break;
  9625. case 'C':
  9626. cmd = CMD.C;
  9627. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  9628. cpx = p[off - 2];
  9629. cpy = p[off - 1];
  9630. break;
  9631. case 'c':
  9632. cmd = CMD.C;
  9633. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  9634. cpx += p[off - 2];
  9635. cpy += p[off - 1];
  9636. break;
  9637. case 'S':
  9638. ctlPtx = cpx;
  9639. ctlPty = cpy;
  9640. len = path.len();
  9641. pathData = path.data;
  9642. if (prevCmd === CMD.C) {
  9643. ctlPtx += cpx - pathData[len - 4];
  9644. ctlPty += cpy - pathData[len - 3];
  9645. }
  9646. cmd = CMD.C;
  9647. x1 = p[off++];
  9648. y1 = p[off++];
  9649. cpx = p[off++];
  9650. cpy = p[off++];
  9651. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9652. break;
  9653. case 's':
  9654. ctlPtx = cpx;
  9655. ctlPty = cpy;
  9656. len = path.len();
  9657. pathData = path.data;
  9658. if (prevCmd === CMD.C) {
  9659. ctlPtx += cpx - pathData[len - 4];
  9660. ctlPty += cpy - pathData[len - 3];
  9661. }
  9662. cmd = CMD.C;
  9663. x1 = cpx + p[off++];
  9664. y1 = cpy + p[off++];
  9665. cpx += p[off++];
  9666. cpy += p[off++];
  9667. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9668. break;
  9669. case 'Q':
  9670. x1 = p[off++];
  9671. y1 = p[off++];
  9672. cpx = p[off++];
  9673. cpy = p[off++];
  9674. cmd = CMD.Q;
  9675. path.addData(cmd, x1, y1, cpx, cpy);
  9676. break;
  9677. case 'q':
  9678. x1 = p[off++] + cpx;
  9679. y1 = p[off++] + cpy;
  9680. cpx += p[off++];
  9681. cpy += p[off++];
  9682. cmd = CMD.Q;
  9683. path.addData(cmd, x1, y1, cpx, cpy);
  9684. break;
  9685. case 'T':
  9686. ctlPtx = cpx;
  9687. ctlPty = cpy;
  9688. len = path.len();
  9689. pathData = path.data;
  9690. if (prevCmd === CMD.Q) {
  9691. ctlPtx += cpx - pathData[len - 4];
  9692. ctlPty += cpy - pathData[len - 3];
  9693. }
  9694. cpx = p[off++];
  9695. cpy = p[off++];
  9696. cmd = CMD.Q;
  9697. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9698. break;
  9699. case 't':
  9700. ctlPtx = cpx;
  9701. ctlPty = cpy;
  9702. len = path.len();
  9703. pathData = path.data;
  9704. if (prevCmd === CMD.Q) {
  9705. ctlPtx += cpx - pathData[len - 4];
  9706. ctlPty += cpy - pathData[len - 3];
  9707. }
  9708. cpx += p[off++];
  9709. cpy += p[off++];
  9710. cmd = CMD.Q;
  9711. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9712. break;
  9713. case 'A':
  9714. rx = p[off++];
  9715. ry = p[off++];
  9716. psi = p[off++];
  9717. fa = p[off++];
  9718. fs = p[off++];
  9719. x1 = cpx, y1 = cpy;
  9720. cpx = p[off++];
  9721. cpy = p[off++];
  9722. cmd = CMD.A;
  9723. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9724. break;
  9725. case 'a':
  9726. rx = p[off++];
  9727. ry = p[off++];
  9728. psi = p[off++];
  9729. fa = p[off++];
  9730. fs = p[off++];
  9731. x1 = cpx, y1 = cpy;
  9732. cpx += p[off++];
  9733. cpy += p[off++];
  9734. cmd = CMD.A;
  9735. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  9736. break;
  9737. }
  9738. }
  9739. if (cmdStr === 'z' || cmdStr === 'Z') {
  9740. cmd = CMD.Z;
  9741. path.addData(cmd);
  9742. cpx = subpathX;
  9743. cpy = subpathY;
  9744. }
  9745. prevCmd = cmd;
  9746. }
  9747. path.toStatic();
  9748. return path;
  9749. }
  9750. var SVGPath = (function (_super) {
  9751. __extends(SVGPath, _super);
  9752. function SVGPath() {
  9753. return _super !== null && _super.apply(this, arguments) || this;
  9754. }
  9755. SVGPath.prototype.applyTransform = function (m) { };
  9756. return SVGPath;
  9757. }(Path));
  9758. function isPathProxy(path) {
  9759. return path.setData != null;
  9760. }
  9761. function createPathOptions(str, opts) {
  9762. var pathProxy = createPathProxyFromString(str);
  9763. var innerOpts = extend({}, opts);
  9764. innerOpts.buildPath = function (path) {
  9765. var beProxy = isPathProxy(path);
  9766. if (beProxy && path.canSave()) {
  9767. path.appendPath(pathProxy);
  9768. var ctx = path.getContext();
  9769. if (ctx) {
  9770. path.rebuildPath(ctx, 1);
  9771. }
  9772. }
  9773. else {
  9774. var ctx = beProxy ? path.getContext() : path;
  9775. if (ctx) {
  9776. pathProxy.rebuildPath(ctx, 1);
  9777. }
  9778. }
  9779. };
  9780. innerOpts.applyTransform = function (m) {
  9781. transformPath(pathProxy, m);
  9782. this.dirtyShape();
  9783. };
  9784. return innerOpts;
  9785. }
  9786. function createFromString(str, opts) {
  9787. return new SVGPath(createPathOptions(str, opts));
  9788. }
  9789. function extendFromString(str, defaultOpts) {
  9790. var innerOpts = createPathOptions(str, defaultOpts);
  9791. var Sub = (function (_super) {
  9792. __extends(Sub, _super);
  9793. function Sub(opts) {
  9794. var _this = _super.call(this, opts) || this;
  9795. _this.applyTransform = innerOpts.applyTransform;
  9796. _this.buildPath = innerOpts.buildPath;
  9797. return _this;
  9798. }
  9799. return Sub;
  9800. }(SVGPath));
  9801. return Sub;
  9802. }
  9803. function mergePath(pathEls, opts) {
  9804. var pathList = [];
  9805. var len = pathEls.length;
  9806. for (var i = 0; i < len; i++) {
  9807. var pathEl = pathEls[i];
  9808. pathList.push(pathEl.getUpdatedPathProxy(true));
  9809. }
  9810. var pathBundle = new Path(opts);
  9811. pathBundle.createPathProxy();
  9812. pathBundle.buildPath = function (path) {
  9813. if (isPathProxy(path)) {
  9814. path.appendPath(pathList);
  9815. var ctx = path.getContext();
  9816. if (ctx) {
  9817. path.rebuildPath(ctx, 1);
  9818. }
  9819. }
  9820. };
  9821. return pathBundle;
  9822. }
  9823. function clonePath(sourcePath, opts) {
  9824. opts = opts || {};
  9825. var path = new Path();
  9826. if (sourcePath.shape) {
  9827. path.setShape(sourcePath.shape);
  9828. }
  9829. path.setStyle(sourcePath.style);
  9830. if (opts.bakeTransform) {
  9831. transformPath(path.path, sourcePath.getComputedTransform());
  9832. }
  9833. else {
  9834. if (opts.toLocal) {
  9835. path.setLocalTransform(sourcePath.getComputedTransform());
  9836. }
  9837. else {
  9838. path.copyTransform(sourcePath);
  9839. }
  9840. }
  9841. path.buildPath = sourcePath.buildPath;
  9842. path.applyTransform = path.applyTransform;
  9843. path.z = sourcePath.z;
  9844. path.z2 = sourcePath.z2;
  9845. path.zlevel = sourcePath.zlevel;
  9846. return path;
  9847. }
  9848. var path = /*#__PURE__*/Object.freeze({
  9849. __proto__: null,
  9850. createFromString: createFromString,
  9851. extendFromString: extendFromString,
  9852. mergePath: mergePath,
  9853. clonePath: clonePath
  9854. });
  9855. var DEFAULT_IMAGE_STYLE = defaults({
  9856. x: 0,
  9857. y: 0
  9858. }, DEFAULT_COMMON_STYLE);
  9859. var DEFAULT_IMAGE_ANIMATION_PROPS = {
  9860. style: defaults({
  9861. x: true,
  9862. y: true,
  9863. width: true,
  9864. height: true,
  9865. sx: true,
  9866. sy: true,
  9867. sWidth: true,
  9868. sHeight: true
  9869. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  9870. };
  9871. function isImageLike(source) {
  9872. return !!(source
  9873. && typeof source !== 'string'
  9874. && source.width && source.height);
  9875. }
  9876. var ZRImage = (function (_super) {
  9877. __extends(ZRImage, _super);
  9878. function ZRImage() {
  9879. return _super !== null && _super.apply(this, arguments) || this;
  9880. }
  9881. ZRImage.prototype.createStyle = function (obj) {
  9882. return createObject(DEFAULT_IMAGE_STYLE, obj);
  9883. };
  9884. ZRImage.prototype._getSize = function (dim) {
  9885. var style = this.style;
  9886. var size = style[dim];
  9887. if (size != null) {
  9888. return size;
  9889. }
  9890. var imageSource = isImageLike(style.image)
  9891. ? style.image : this.__image;
  9892. if (!imageSource) {
  9893. return 0;
  9894. }
  9895. var otherDim = dim === 'width' ? 'height' : 'width';
  9896. var otherDimSize = style[otherDim];
  9897. if (otherDimSize == null) {
  9898. return imageSource[dim];
  9899. }
  9900. else {
  9901. return imageSource[dim] / imageSource[otherDim] * otherDimSize;
  9902. }
  9903. };
  9904. ZRImage.prototype.getWidth = function () {
  9905. return this._getSize('width');
  9906. };
  9907. ZRImage.prototype.getHeight = function () {
  9908. return this._getSize('height');
  9909. };
  9910. ZRImage.prototype.getAnimationStyleProps = function () {
  9911. return DEFAULT_IMAGE_ANIMATION_PROPS;
  9912. };
  9913. ZRImage.prototype.getBoundingRect = function () {
  9914. var style = this.style;
  9915. if (!this._rect) {
  9916. this._rect = new BoundingRect(style.x || 0, style.y || 0, this.getWidth(), this.getHeight());
  9917. }
  9918. return this._rect;
  9919. };
  9920. return ZRImage;
  9921. }(Displayable));
  9922. ZRImage.prototype.type = 'image';
  9923. var CircleShape = (function () {
  9924. function CircleShape() {
  9925. this.cx = 0;
  9926. this.cy = 0;
  9927. this.r = 0;
  9928. }
  9929. return CircleShape;
  9930. }());
  9931. var Circle = (function (_super) {
  9932. __extends(Circle, _super);
  9933. function Circle(opts) {
  9934. return _super.call(this, opts) || this;
  9935. }
  9936. Circle.prototype.getDefaultShape = function () {
  9937. return new CircleShape();
  9938. };
  9939. Circle.prototype.buildPath = function (ctx, shape) {
  9940. ctx.moveTo(shape.cx + shape.r, shape.cy);
  9941. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2);
  9942. };
  9943. return Circle;
  9944. }(Path));
  9945. Circle.prototype.type = 'circle';
  9946. function buildPath(ctx, shape) {
  9947. var x = shape.x;
  9948. var y = shape.y;
  9949. var width = shape.width;
  9950. var height = shape.height;
  9951. var r = shape.r;
  9952. var r1;
  9953. var r2;
  9954. var r3;
  9955. var r4;
  9956. if (width < 0) {
  9957. x = x + width;
  9958. width = -width;
  9959. }
  9960. if (height < 0) {
  9961. y = y + height;
  9962. height = -height;
  9963. }
  9964. if (typeof r === 'number') {
  9965. r1 = r2 = r3 = r4 = r;
  9966. }
  9967. else if (r instanceof Array) {
  9968. if (r.length === 1) {
  9969. r1 = r2 = r3 = r4 = r[0];
  9970. }
  9971. else if (r.length === 2) {
  9972. r1 = r3 = r[0];
  9973. r2 = r4 = r[1];
  9974. }
  9975. else if (r.length === 3) {
  9976. r1 = r[0];
  9977. r2 = r4 = r[1];
  9978. r3 = r[2];
  9979. }
  9980. else {
  9981. r1 = r[0];
  9982. r2 = r[1];
  9983. r3 = r[2];
  9984. r4 = r[3];
  9985. }
  9986. }
  9987. else {
  9988. r1 = r2 = r3 = r4 = 0;
  9989. }
  9990. var total;
  9991. if (r1 + r2 > width) {
  9992. total = r1 + r2;
  9993. r1 *= width / total;
  9994. r2 *= width / total;
  9995. }
  9996. if (r3 + r4 > width) {
  9997. total = r3 + r4;
  9998. r3 *= width / total;
  9999. r4 *= width / total;
  10000. }
  10001. if (r2 + r3 > height) {
  10002. total = r2 + r3;
  10003. r2 *= height / total;
  10004. r3 *= height / total;
  10005. }
  10006. if (r1 + r4 > height) {
  10007. total = r1 + r4;
  10008. r1 *= height / total;
  10009. r4 *= height / total;
  10010. }
  10011. ctx.moveTo(x + r1, y);
  10012. ctx.lineTo(x + width - r2, y);
  10013. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  10014. ctx.lineTo(x + width, y + height - r3);
  10015. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  10016. ctx.lineTo(x + r4, y + height);
  10017. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  10018. ctx.lineTo(x, y + r1);
  10019. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  10020. }
  10021. var round = Math.round;
  10022. function subPixelOptimizeLine(outputShape, inputShape, style) {
  10023. if (!inputShape) {
  10024. return;
  10025. }
  10026. var x1 = inputShape.x1;
  10027. var x2 = inputShape.x2;
  10028. var y1 = inputShape.y1;
  10029. var y2 = inputShape.y2;
  10030. outputShape.x1 = x1;
  10031. outputShape.x2 = x2;
  10032. outputShape.y1 = y1;
  10033. outputShape.y2 = y2;
  10034. var lineWidth = style && style.lineWidth;
  10035. if (!lineWidth) {
  10036. return outputShape;
  10037. }
  10038. if (round(x1 * 2) === round(x2 * 2)) {
  10039. outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true);
  10040. }
  10041. if (round(y1 * 2) === round(y2 * 2)) {
  10042. outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true);
  10043. }
  10044. return outputShape;
  10045. }
  10046. function subPixelOptimizeRect(outputShape, inputShape, style) {
  10047. if (!inputShape) {
  10048. return;
  10049. }
  10050. var originX = inputShape.x;
  10051. var originY = inputShape.y;
  10052. var originWidth = inputShape.width;
  10053. var originHeight = inputShape.height;
  10054. outputShape.x = originX;
  10055. outputShape.y = originY;
  10056. outputShape.width = originWidth;
  10057. outputShape.height = originHeight;
  10058. var lineWidth = style && style.lineWidth;
  10059. if (!lineWidth) {
  10060. return outputShape;
  10061. }
  10062. outputShape.x = subPixelOptimize(originX, lineWidth, true);
  10063. outputShape.y = subPixelOptimize(originY, lineWidth, true);
  10064. outputShape.width = Math.max(subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
  10065. outputShape.height = Math.max(subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
  10066. return outputShape;
  10067. }
  10068. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  10069. if (!lineWidth) {
  10070. return position;
  10071. }
  10072. var doubledPosition = round(position * 2);
  10073. return (doubledPosition + round(lineWidth)) % 2 === 0
  10074. ? doubledPosition / 2
  10075. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  10076. }
  10077. var RectShape = (function () {
  10078. function RectShape() {
  10079. this.x = 0;
  10080. this.y = 0;
  10081. this.width = 0;
  10082. this.height = 0;
  10083. }
  10084. return RectShape;
  10085. }());
  10086. var subPixelOptimizeOutputShape = {};
  10087. var Rect = (function (_super) {
  10088. __extends(Rect, _super);
  10089. function Rect(opts) {
  10090. return _super.call(this, opts) || this;
  10091. }
  10092. Rect.prototype.getDefaultShape = function () {
  10093. return new RectShape();
  10094. };
  10095. Rect.prototype.buildPath = function (ctx, shape) {
  10096. var x;
  10097. var y;
  10098. var width;
  10099. var height;
  10100. if (this.subPixelOptimize) {
  10101. var optimizedShape = subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style);
  10102. x = optimizedShape.x;
  10103. y = optimizedShape.y;
  10104. width = optimizedShape.width;
  10105. height = optimizedShape.height;
  10106. optimizedShape.r = shape.r;
  10107. shape = optimizedShape;
  10108. }
  10109. else {
  10110. x = shape.x;
  10111. y = shape.y;
  10112. width = shape.width;
  10113. height = shape.height;
  10114. }
  10115. if (!shape.r) {
  10116. ctx.rect(x, y, width, height);
  10117. }
  10118. else {
  10119. buildPath(ctx, shape);
  10120. }
  10121. };
  10122. Rect.prototype.isZeroArea = function () {
  10123. return !this.shape.width || !this.shape.height;
  10124. };
  10125. return Rect;
  10126. }(Path));
  10127. Rect.prototype.type = 'rect';
  10128. var EllipseShape = (function () {
  10129. function EllipseShape() {
  10130. this.cx = 0;
  10131. this.cy = 0;
  10132. this.rx = 0;
  10133. this.ry = 0;
  10134. }
  10135. return EllipseShape;
  10136. }());
  10137. var Ellipse = (function (_super) {
  10138. __extends(Ellipse, _super);
  10139. function Ellipse(opts) {
  10140. return _super.call(this, opts) || this;
  10141. }
  10142. Ellipse.prototype.getDefaultShape = function () {
  10143. return new EllipseShape();
  10144. };
  10145. Ellipse.prototype.buildPath = function (ctx, shape) {
  10146. var k = 0.5522848;
  10147. var x = shape.cx;
  10148. var y = shape.cy;
  10149. var a = shape.rx;
  10150. var b = shape.ry;
  10151. var ox = a * k;
  10152. var oy = b * k;
  10153. ctx.moveTo(x - a, y);
  10154. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  10155. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  10156. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  10157. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  10158. ctx.closePath();
  10159. };
  10160. return Ellipse;
  10161. }(Path));
  10162. Ellipse.prototype.type = 'ellipse';
  10163. var subPixelOptimizeOutputShape$1 = {};
  10164. var LineShape = (function () {
  10165. function LineShape() {
  10166. this.x1 = 0;
  10167. this.y1 = 0;
  10168. this.x2 = 0;
  10169. this.y2 = 0;
  10170. this.percent = 1;
  10171. }
  10172. return LineShape;
  10173. }());
  10174. var Line = (function (_super) {
  10175. __extends(Line, _super);
  10176. function Line(opts) {
  10177. return _super.call(this, opts) || this;
  10178. }
  10179. Line.prototype.getDefaultStyle = function () {
  10180. return {
  10181. stroke: '#000',
  10182. fill: null
  10183. };
  10184. };
  10185. Line.prototype.getDefaultShape = function () {
  10186. return new LineShape();
  10187. };
  10188. Line.prototype.buildPath = function (ctx, shape) {
  10189. var x1;
  10190. var y1;
  10191. var x2;
  10192. var y2;
  10193. if (this.subPixelOptimize) {
  10194. var optimizedShape = subPixelOptimizeLine(subPixelOptimizeOutputShape$1, shape, this.style);
  10195. x1 = optimizedShape.x1;
  10196. y1 = optimizedShape.y1;
  10197. x2 = optimizedShape.x2;
  10198. y2 = optimizedShape.y2;
  10199. }
  10200. else {
  10201. x1 = shape.x1;
  10202. y1 = shape.y1;
  10203. x2 = shape.x2;
  10204. y2 = shape.y2;
  10205. }
  10206. var percent = shape.percent;
  10207. if (percent === 0) {
  10208. return;
  10209. }
  10210. ctx.moveTo(x1, y1);
  10211. if (percent < 1) {
  10212. x2 = x1 * (1 - percent) + x2 * percent;
  10213. y2 = y1 * (1 - percent) + y2 * percent;
  10214. }
  10215. ctx.lineTo(x2, y2);
  10216. };
  10217. Line.prototype.pointAt = function (p) {
  10218. var shape = this.shape;
  10219. return [
  10220. shape.x1 * (1 - p) + shape.x2 * p,
  10221. shape.y1 * (1 - p) + shape.y2 * p
  10222. ];
  10223. };
  10224. return Line;
  10225. }(Path));
  10226. Line.prototype.type = 'line';
  10227. function smoothBezier(points, smooth, isLoop, constraint) {
  10228. var cps = [];
  10229. var v = [];
  10230. var v1 = [];
  10231. var v2 = [];
  10232. var prevPoint;
  10233. var nextPoint;
  10234. var min$1;
  10235. var max$1;
  10236. if (constraint) {
  10237. min$1 = [Infinity, Infinity];
  10238. max$1 = [-Infinity, -Infinity];
  10239. for (var i = 0, len = points.length; i < len; i++) {
  10240. min(min$1, min$1, points[i]);
  10241. max(max$1, max$1, points[i]);
  10242. }
  10243. min(min$1, min$1, constraint[0]);
  10244. max(max$1, max$1, constraint[1]);
  10245. }
  10246. for (var i = 0, len = points.length; i < len; i++) {
  10247. var point = points[i];
  10248. if (isLoop) {
  10249. prevPoint = points[i ? i - 1 : len - 1];
  10250. nextPoint = points[(i + 1) % len];
  10251. }
  10252. else {
  10253. if (i === 0 || i === len - 1) {
  10254. cps.push(clone$1(points[i]));
  10255. continue;
  10256. }
  10257. else {
  10258. prevPoint = points[i - 1];
  10259. nextPoint = points[i + 1];
  10260. }
  10261. }
  10262. sub(v, nextPoint, prevPoint);
  10263. scale(v, v, smooth);
  10264. var d0 = distance(point, prevPoint);
  10265. var d1 = distance(point, nextPoint);
  10266. var sum = d0 + d1;
  10267. if (sum !== 0) {
  10268. d0 /= sum;
  10269. d1 /= sum;
  10270. }
  10271. scale(v1, v, -d0);
  10272. scale(v2, v, d1);
  10273. var cp0 = add([], point, v1);
  10274. var cp1 = add([], point, v2);
  10275. if (constraint) {
  10276. max(cp0, cp0, min$1);
  10277. min(cp0, cp0, max$1);
  10278. max(cp1, cp1, min$1);
  10279. min(cp1, cp1, max$1);
  10280. }
  10281. cps.push(cp0);
  10282. cps.push(cp1);
  10283. }
  10284. if (isLoop) {
  10285. cps.push(cps.shift());
  10286. }
  10287. return cps;
  10288. }
  10289. function buildPath$1(ctx, shape, closePath) {
  10290. var smooth = shape.smooth;
  10291. var points = shape.points;
  10292. if (points && points.length >= 2) {
  10293. if (smooth) {
  10294. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  10295. ctx.moveTo(points[0][0], points[0][1]);
  10296. var len = points.length;
  10297. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  10298. var cp1 = controlPoints[i * 2];
  10299. var cp2 = controlPoints[i * 2 + 1];
  10300. var p = points[(i + 1) % len];
  10301. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  10302. }
  10303. }
  10304. else {
  10305. ctx.moveTo(points[0][0], points[0][1]);
  10306. for (var i = 1, l = points.length; i < l; i++) {
  10307. ctx.lineTo(points[i][0], points[i][1]);
  10308. }
  10309. }
  10310. closePath && ctx.closePath();
  10311. }
  10312. }
  10313. var PolygonShape = (function () {
  10314. function PolygonShape() {
  10315. this.points = null;
  10316. this.smooth = 0;
  10317. this.smoothConstraint = null;
  10318. }
  10319. return PolygonShape;
  10320. }());
  10321. var Polygon = (function (_super) {
  10322. __extends(Polygon, _super);
  10323. function Polygon(opts) {
  10324. return _super.call(this, opts) || this;
  10325. }
  10326. Polygon.prototype.getDefaultShape = function () {
  10327. return new PolygonShape();
  10328. };
  10329. Polygon.prototype.buildPath = function (ctx, shape) {
  10330. buildPath$1(ctx, shape, true);
  10331. };
  10332. return Polygon;
  10333. }(Path));
  10334. Polygon.prototype.type = 'polygon';
  10335. var PolylineShape = (function () {
  10336. function PolylineShape() {
  10337. this.points = null;
  10338. this.percent = 1;
  10339. this.smooth = 0;
  10340. this.smoothConstraint = null;
  10341. }
  10342. return PolylineShape;
  10343. }());
  10344. var Polyline = (function (_super) {
  10345. __extends(Polyline, _super);
  10346. function Polyline(opts) {
  10347. return _super.call(this, opts) || this;
  10348. }
  10349. Polyline.prototype.getDefaultStyle = function () {
  10350. return {
  10351. stroke: '#000',
  10352. fill: null
  10353. };
  10354. };
  10355. Polyline.prototype.getDefaultShape = function () {
  10356. return new PolylineShape();
  10357. };
  10358. Polyline.prototype.buildPath = function (ctx, shape) {
  10359. buildPath$1(ctx, shape, false);
  10360. };
  10361. return Polyline;
  10362. }(Path));
  10363. Polyline.prototype.type = 'polyline';
  10364. var Gradient = (function () {
  10365. function Gradient(colorStops) {
  10366. this.colorStops = colorStops || [];
  10367. }
  10368. Gradient.prototype.addColorStop = function (offset, color) {
  10369. this.colorStops.push({
  10370. offset: offset,
  10371. color: color
  10372. });
  10373. };
  10374. return Gradient;
  10375. }());
  10376. var LinearGradient = (function (_super) {
  10377. __extends(LinearGradient, _super);
  10378. function LinearGradient(x, y, x2, y2, colorStops, globalCoord) {
  10379. var _this = _super.call(this, colorStops) || this;
  10380. _this.x = x == null ? 0 : x;
  10381. _this.y = y == null ? 0 : y;
  10382. _this.x2 = x2 == null ? 1 : x2;
  10383. _this.y2 = y2 == null ? 0 : y2;
  10384. _this.type = 'linear';
  10385. _this.global = globalCoord || false;
  10386. return _this;
  10387. }
  10388. return LinearGradient;
  10389. }(Gradient));
  10390. var RadialGradient = (function (_super) {
  10391. __extends(RadialGradient, _super);
  10392. function RadialGradient(x, y, r, colorStops, globalCoord) {
  10393. var _this = _super.call(this, colorStops) || this;
  10394. _this.x = x == null ? 0.5 : x;
  10395. _this.y = y == null ? 0.5 : y;
  10396. _this.r = r == null ? 0.5 : r;
  10397. _this.type = 'radial';
  10398. _this.global = globalCoord || false;
  10399. return _this;
  10400. }
  10401. return RadialGradient;
  10402. }(Gradient));
  10403. var globalImageCache = new LRU(50);
  10404. function findExistImage(newImageOrSrc) {
  10405. if (typeof newImageOrSrc === 'string') {
  10406. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  10407. return cachedImgObj && cachedImgObj.image;
  10408. }
  10409. else {
  10410. return newImageOrSrc;
  10411. }
  10412. }
  10413. function createOrUpdateImage(newImageOrSrc, image, hostEl, onload, cbPayload) {
  10414. if (!newImageOrSrc) {
  10415. return image;
  10416. }
  10417. else if (typeof newImageOrSrc === 'string') {
  10418. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  10419. return image;
  10420. }
  10421. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  10422. var pendingWrap = { hostEl: hostEl, cb: onload, cbPayload: cbPayload };
  10423. if (cachedImgObj) {
  10424. image = cachedImgObj.image;
  10425. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  10426. }
  10427. else {
  10428. image = platformApi.loadImage(newImageOrSrc, imageOnLoad, imageOnLoad);
  10429. image.__zrImageSrc = newImageOrSrc;
  10430. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  10431. image: image,
  10432. pending: [pendingWrap]
  10433. });
  10434. }
  10435. return image;
  10436. }
  10437. else {
  10438. return newImageOrSrc;
  10439. }
  10440. }
  10441. function imageOnLoad() {
  10442. var cachedImgObj = this.__cachedImgObj;
  10443. this.onload = this.onerror = this.__cachedImgObj = null;
  10444. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  10445. var pendingWrap = cachedImgObj.pending[i];
  10446. var cb = pendingWrap.cb;
  10447. cb && cb(this, pendingWrap.cbPayload);
  10448. pendingWrap.hostEl.dirty();
  10449. }
  10450. cachedImgObj.pending.length = 0;
  10451. }
  10452. function isImageReady(image) {
  10453. return image && image.width && image.height;
  10454. }
  10455. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  10456. function truncateText2(out, text, containerWidth, font, ellipsis, options) {
  10457. if (!containerWidth) {
  10458. out.text = '';
  10459. out.isTruncated = false;
  10460. return;
  10461. }
  10462. var textLines = (text + '').split('\n');
  10463. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  10464. var isTruncated = false;
  10465. var truncateOut = {};
  10466. for (var i = 0, len = textLines.length; i < len; i++) {
  10467. truncateSingleLine(truncateOut, textLines[i], options);
  10468. textLines[i] = truncateOut.textLine;
  10469. isTruncated = isTruncated || truncateOut.isTruncated;
  10470. }
  10471. out.text = textLines.join('\n');
  10472. out.isTruncated = isTruncated;
  10473. }
  10474. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  10475. options = options || {};
  10476. var preparedOpts = extend({}, options);
  10477. ellipsis = retrieve2(ellipsis, '...');
  10478. preparedOpts.maxIterations = retrieve2(options.maxIterations, 2);
  10479. var minChar = preparedOpts.minChar = retrieve2(options.minChar, 0);
  10480. var fontMeasureInfo = preparedOpts.fontMeasureInfo = ensureFontMeasureInfo(font);
  10481. var ascCharWidth = fontMeasureInfo.asciiCharWidth;
  10482. preparedOpts.placeholder = retrieve2(options.placeholder, '');
  10483. var contentWidth = containerWidth = Math.max(0, containerWidth - 1);
  10484. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  10485. contentWidth -= ascCharWidth;
  10486. }
  10487. var ellipsisWidth = measureWidth(fontMeasureInfo, ellipsis);
  10488. if (ellipsisWidth > contentWidth) {
  10489. ellipsis = '';
  10490. ellipsisWidth = 0;
  10491. }
  10492. contentWidth = containerWidth - ellipsisWidth;
  10493. preparedOpts.ellipsis = ellipsis;
  10494. preparedOpts.ellipsisWidth = ellipsisWidth;
  10495. preparedOpts.contentWidth = contentWidth;
  10496. preparedOpts.containerWidth = containerWidth;
  10497. return preparedOpts;
  10498. }
  10499. function truncateSingleLine(out, textLine, options) {
  10500. var containerWidth = options.containerWidth;
  10501. var contentWidth = options.contentWidth;
  10502. var fontMeasureInfo = options.fontMeasureInfo;
  10503. if (!containerWidth) {
  10504. out.textLine = '';
  10505. out.isTruncated = false;
  10506. return;
  10507. }
  10508. var lineWidth = measureWidth(fontMeasureInfo, textLine);
  10509. if (lineWidth <= containerWidth) {
  10510. out.textLine = textLine;
  10511. out.isTruncated = false;
  10512. return;
  10513. }
  10514. for (var j = 0;; j++) {
  10515. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  10516. textLine += options.ellipsis;
  10517. break;
  10518. }
  10519. var subLength = j === 0
  10520. ? estimateLength(textLine, contentWidth, fontMeasureInfo)
  10521. : lineWidth > 0
  10522. ? Math.floor(textLine.length * contentWidth / lineWidth)
  10523. : 0;
  10524. textLine = textLine.substr(0, subLength);
  10525. lineWidth = measureWidth(fontMeasureInfo, textLine);
  10526. }
  10527. if (textLine === '') {
  10528. textLine = options.placeholder;
  10529. }
  10530. out.textLine = textLine;
  10531. out.isTruncated = true;
  10532. }
  10533. function estimateLength(text, contentWidth, fontMeasureInfo) {
  10534. var width = 0;
  10535. var i = 0;
  10536. for (var len = text.length; i < len && width < contentWidth; i++) {
  10537. width += measureCharWidth(fontMeasureInfo, text.charCodeAt(i));
  10538. }
  10539. return i;
  10540. }
  10541. function parsePlainText(rawText, style, defaultOuterWidth, defaultOuterHeight) {
  10542. var text = formatText(rawText);
  10543. var overflow = style.overflow;
  10544. var padding = style.padding;
  10545. var paddingH = padding ? padding[1] + padding[3] : 0;
  10546. var paddingV = padding ? padding[0] + padding[2] : 0;
  10547. var font = style.font;
  10548. var truncate = overflow === 'truncate';
  10549. var calculatedLineHeight = getLineHeight(font);
  10550. var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
  10551. var truncateLineOverflow = style.lineOverflow === 'truncate';
  10552. var isTruncated = false;
  10553. var width = style.width;
  10554. if (width == null && defaultOuterWidth != null) {
  10555. width = defaultOuterWidth - paddingH;
  10556. }
  10557. var height = style.height;
  10558. if (height == null && defaultOuterHeight != null) {
  10559. height = defaultOuterHeight - paddingV;
  10560. }
  10561. var lines;
  10562. if (width != null && (overflow === 'break' || overflow === 'breakAll')) {
  10563. lines = text ? wrapText(text, style.font, width, overflow === 'breakAll', 0).lines : [];
  10564. }
  10565. else {
  10566. lines = text ? text.split('\n') : [];
  10567. }
  10568. var contentHeight = lines.length * lineHeight;
  10569. if (height == null) {
  10570. height = contentHeight;
  10571. }
  10572. if (contentHeight > height && truncateLineOverflow) {
  10573. var lineCount = Math.floor(height / lineHeight);
  10574. isTruncated = isTruncated || (lines.length > lineCount);
  10575. lines = lines.slice(0, lineCount);
  10576. contentHeight = lines.length * lineHeight;
  10577. }
  10578. if (text && truncate && width != null) {
  10579. var options = prepareTruncateOptions(width, font, style.ellipsis, {
  10580. minChar: style.truncateMinChar,
  10581. placeholder: style.placeholder
  10582. });
  10583. var singleOut = {};
  10584. for (var i = 0; i < lines.length; i++) {
  10585. truncateSingleLine(singleOut, lines[i], options);
  10586. lines[i] = singleOut.textLine;
  10587. isTruncated = isTruncated || singleOut.isTruncated;
  10588. }
  10589. }
  10590. var outerHeight = height;
  10591. var contentWidth = 0;
  10592. var fontMeasureInfo = ensureFontMeasureInfo(font);
  10593. for (var i = 0; i < lines.length; i++) {
  10594. contentWidth = Math.max(measureWidth(fontMeasureInfo, lines[i]), contentWidth);
  10595. }
  10596. if (width == null) {
  10597. width = contentWidth;
  10598. }
  10599. var outerWidth = width;
  10600. outerHeight += paddingV;
  10601. outerWidth += paddingH;
  10602. return {
  10603. lines: lines,
  10604. height: height,
  10605. outerWidth: outerWidth,
  10606. outerHeight: outerHeight,
  10607. lineHeight: lineHeight,
  10608. calculatedLineHeight: calculatedLineHeight,
  10609. contentWidth: contentWidth,
  10610. contentHeight: contentHeight,
  10611. width: width,
  10612. isTruncated: isTruncated
  10613. };
  10614. }
  10615. var RichTextToken = (function () {
  10616. function RichTextToken() {
  10617. }
  10618. return RichTextToken;
  10619. }());
  10620. var RichTextLine = (function () {
  10621. function RichTextLine(tokens) {
  10622. this.tokens = [];
  10623. if (tokens) {
  10624. this.tokens = tokens;
  10625. }
  10626. }
  10627. return RichTextLine;
  10628. }());
  10629. var RichTextContentBlock = (function () {
  10630. function RichTextContentBlock() {
  10631. this.width = 0;
  10632. this.height = 0;
  10633. this.contentWidth = 0;
  10634. this.contentHeight = 0;
  10635. this.outerWidth = 0;
  10636. this.outerHeight = 0;
  10637. this.lines = [];
  10638. this.isTruncated = false;
  10639. }
  10640. return RichTextContentBlock;
  10641. }());
  10642. function parseRichText(rawText, style, defaultOuterWidth, defaultOuterHeight, topTextAlign) {
  10643. var contentBlock = new RichTextContentBlock();
  10644. var text = formatText(rawText);
  10645. if (!text) {
  10646. return contentBlock;
  10647. }
  10648. var stlPadding = style.padding;
  10649. var stlPaddingH = stlPadding ? stlPadding[1] + stlPadding[3] : 0;
  10650. var stlPaddingV = stlPadding ? stlPadding[0] + stlPadding[2] : 0;
  10651. var topWidth = style.width;
  10652. if (topWidth == null && defaultOuterWidth != null) {
  10653. topWidth = defaultOuterWidth - stlPaddingH;
  10654. }
  10655. var topHeight = style.height;
  10656. if (topHeight == null && defaultOuterHeight != null) {
  10657. topHeight = defaultOuterHeight - stlPaddingV;
  10658. }
  10659. var overflow = style.overflow;
  10660. var wrapInfo = (overflow === 'break' || overflow === 'breakAll') && topWidth != null
  10661. ? { width: topWidth, accumWidth: 0, breakAll: overflow === 'breakAll' }
  10662. : null;
  10663. var lastIndex = STYLE_REG.lastIndex = 0;
  10664. var result;
  10665. while ((result = STYLE_REG.exec(text)) != null) {
  10666. var matchedIndex = result.index;
  10667. if (matchedIndex > lastIndex) {
  10668. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex), style, wrapInfo);
  10669. }
  10670. pushTokens(contentBlock, result[2], style, wrapInfo, result[1]);
  10671. lastIndex = STYLE_REG.lastIndex;
  10672. }
  10673. if (lastIndex < text.length) {
  10674. pushTokens(contentBlock, text.substring(lastIndex, text.length), style, wrapInfo);
  10675. }
  10676. var pendingList = [];
  10677. var calculatedHeight = 0;
  10678. var calculatedWidth = 0;
  10679. var truncate = overflow === 'truncate';
  10680. var truncateLine = style.lineOverflow === 'truncate';
  10681. var tmpTruncateOut = {};
  10682. function finishLine(line, lineWidth, lineHeight) {
  10683. line.width = lineWidth;
  10684. line.lineHeight = lineHeight;
  10685. calculatedHeight += lineHeight;
  10686. calculatedWidth = Math.max(calculatedWidth, lineWidth);
  10687. }
  10688. outer: for (var i = 0; i < contentBlock.lines.length; i++) {
  10689. var line = contentBlock.lines[i];
  10690. var lineHeight = 0;
  10691. var lineWidth = 0;
  10692. for (var j = 0; j < line.tokens.length; j++) {
  10693. var token = line.tokens[j];
  10694. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  10695. var textPadding = token.textPadding = tokenStyle.padding;
  10696. var paddingH = textPadding ? textPadding[1] + textPadding[3] : 0;
  10697. var font = token.font = tokenStyle.font || style.font;
  10698. token.contentHeight = getLineHeight(font);
  10699. var tokenHeight = retrieve2(tokenStyle.height, token.contentHeight);
  10700. token.innerHeight = tokenHeight;
  10701. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  10702. token.height = tokenHeight;
  10703. token.lineHeight = retrieve3(tokenStyle.lineHeight, style.lineHeight, tokenHeight);
  10704. token.align = tokenStyle && tokenStyle.align || topTextAlign;
  10705. token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
  10706. if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
  10707. var originalLength = contentBlock.lines.length;
  10708. if (j > 0) {
  10709. line.tokens = line.tokens.slice(0, j);
  10710. finishLine(line, lineWidth, lineHeight);
  10711. contentBlock.lines = contentBlock.lines.slice(0, i + 1);
  10712. }
  10713. else {
  10714. contentBlock.lines = contentBlock.lines.slice(0, i);
  10715. }
  10716. contentBlock.isTruncated = contentBlock.isTruncated || (contentBlock.lines.length < originalLength);
  10717. break outer;
  10718. }
  10719. var styleTokenWidth = tokenStyle.width;
  10720. var tokenWidthNotSpecified = styleTokenWidth == null || styleTokenWidth === 'auto';
  10721. if (typeof styleTokenWidth === 'string' && styleTokenWidth.charAt(styleTokenWidth.length - 1) === '%') {
  10722. token.percentWidth = styleTokenWidth;
  10723. pendingList.push(token);
  10724. token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
  10725. }
  10726. else {
  10727. if (tokenWidthNotSpecified) {
  10728. var textBackgroundColor = tokenStyle.backgroundColor;
  10729. var bgImg = textBackgroundColor && textBackgroundColor.image;
  10730. if (bgImg) {
  10731. bgImg = findExistImage(bgImg);
  10732. if (isImageReady(bgImg)) {
  10733. token.width = Math.max(token.width, bgImg.width * tokenHeight / bgImg.height);
  10734. }
  10735. }
  10736. }
  10737. var remainTruncWidth = truncate && topWidth != null
  10738. ? topWidth - lineWidth : null;
  10739. if (remainTruncWidth != null && remainTruncWidth < token.width) {
  10740. if (!tokenWidthNotSpecified || remainTruncWidth < paddingH) {
  10741. token.text = '';
  10742. token.width = token.contentWidth = 0;
  10743. }
  10744. else {
  10745. truncateText2(tmpTruncateOut, token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
  10746. token.text = tmpTruncateOut.text;
  10747. contentBlock.isTruncated = contentBlock.isTruncated || tmpTruncateOut.isTruncated;
  10748. token.width = token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
  10749. }
  10750. }
  10751. else {
  10752. token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
  10753. }
  10754. }
  10755. token.width += paddingH;
  10756. lineWidth += token.width;
  10757. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  10758. }
  10759. finishLine(line, lineWidth, lineHeight);
  10760. }
  10761. contentBlock.outerWidth = contentBlock.width = retrieve2(topWidth, calculatedWidth);
  10762. contentBlock.outerHeight = contentBlock.height = retrieve2(topHeight, calculatedHeight);
  10763. contentBlock.contentHeight = calculatedHeight;
  10764. contentBlock.contentWidth = calculatedWidth;
  10765. contentBlock.outerWidth += stlPaddingH;
  10766. contentBlock.outerHeight += stlPaddingV;
  10767. for (var i = 0; i < pendingList.length; i++) {
  10768. var token = pendingList[i];
  10769. var percentWidth = token.percentWidth;
  10770. token.width = parseInt(percentWidth, 10) / 100 * contentBlock.width;
  10771. }
  10772. return contentBlock;
  10773. }
  10774. function pushTokens(block, str, style, wrapInfo, styleName) {
  10775. var isEmptyStr = str === '';
  10776. var tokenStyle = styleName && style.rich[styleName] || {};
  10777. var lines = block.lines;
  10778. var font = tokenStyle.font || style.font;
  10779. var newLine = false;
  10780. var strLines;
  10781. var linesWidths;
  10782. if (wrapInfo) {
  10783. var tokenPadding = tokenStyle.padding;
  10784. var tokenPaddingH = tokenPadding ? tokenPadding[1] + tokenPadding[3] : 0;
  10785. if (tokenStyle.width != null && tokenStyle.width !== 'auto') {
  10786. var outerWidth_1 = parsePercent(tokenStyle.width, wrapInfo.width) + tokenPaddingH;
  10787. if (lines.length > 0) {
  10788. if (outerWidth_1 + wrapInfo.accumWidth > wrapInfo.width) {
  10789. strLines = str.split('\n');
  10790. newLine = true;
  10791. }
  10792. }
  10793. wrapInfo.accumWidth = outerWidth_1;
  10794. }
  10795. else {
  10796. var res = wrapText(str, font, wrapInfo.width, wrapInfo.breakAll, wrapInfo.accumWidth);
  10797. wrapInfo.accumWidth = res.accumWidth + tokenPaddingH;
  10798. linesWidths = res.linesWidths;
  10799. strLines = res.lines;
  10800. }
  10801. }
  10802. if (!strLines) {
  10803. strLines = str.split('\n');
  10804. }
  10805. var fontMeasureInfo = ensureFontMeasureInfo(font);
  10806. for (var i = 0; i < strLines.length; i++) {
  10807. var text = strLines[i];
  10808. var token = new RichTextToken();
  10809. token.styleName = styleName;
  10810. token.text = text;
  10811. token.isLineHolder = !text && !isEmptyStr;
  10812. if (typeof tokenStyle.width === 'number') {
  10813. token.width = tokenStyle.width;
  10814. }
  10815. else {
  10816. token.width = linesWidths
  10817. ? linesWidths[i]
  10818. : measureWidth(fontMeasureInfo, text);
  10819. }
  10820. if (!i && !newLine) {
  10821. var tokens = (lines[lines.length - 1] || (lines[0] = new RichTextLine())).tokens;
  10822. var tokensLen = tokens.length;
  10823. (tokensLen === 1 && tokens[0].isLineHolder)
  10824. ? (tokens[0] = token)
  10825. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  10826. }
  10827. else {
  10828. lines.push(new RichTextLine([token]));
  10829. }
  10830. }
  10831. }
  10832. function isAlphabeticLetter(ch) {
  10833. var code = ch.charCodeAt(0);
  10834. return code >= 0x20 && code <= 0x24F
  10835. || code >= 0x370 && code <= 0x10FF
  10836. || code >= 0x1200 && code <= 0x13FF
  10837. || code >= 0x1E00 && code <= 0x206F;
  10838. }
  10839. var breakCharMap = reduce(',&?/;] '.split(''), function (obj, ch) {
  10840. obj[ch] = true;
  10841. return obj;
  10842. }, {});
  10843. function isWordBreakChar(ch) {
  10844. if (isAlphabeticLetter(ch)) {
  10845. if (breakCharMap[ch]) {
  10846. return true;
  10847. }
  10848. return false;
  10849. }
  10850. return true;
  10851. }
  10852. function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
  10853. var lines = [];
  10854. var linesWidths = [];
  10855. var line = '';
  10856. var currentWord = '';
  10857. var currentWordWidth = 0;
  10858. var accumWidth = 0;
  10859. var fontMeasureInfo = ensureFontMeasureInfo(font);
  10860. for (var i = 0; i < text.length; i++) {
  10861. var ch = text.charAt(i);
  10862. if (ch === '\n') {
  10863. if (currentWord) {
  10864. line += currentWord;
  10865. accumWidth += currentWordWidth;
  10866. }
  10867. lines.push(line);
  10868. linesWidths.push(accumWidth);
  10869. line = '';
  10870. currentWord = '';
  10871. currentWordWidth = 0;
  10872. accumWidth = 0;
  10873. continue;
  10874. }
  10875. var chWidth = measureCharWidth(fontMeasureInfo, ch.charCodeAt(0));
  10876. var inWord = isBreakAll ? false : !isWordBreakChar(ch);
  10877. if (!lines.length
  10878. ? lastAccumWidth + accumWidth + chWidth > lineWidth
  10879. : accumWidth + chWidth > lineWidth) {
  10880. if (!accumWidth) {
  10881. if (inWord) {
  10882. lines.push(currentWord);
  10883. linesWidths.push(currentWordWidth);
  10884. currentWord = ch;
  10885. currentWordWidth = chWidth;
  10886. }
  10887. else {
  10888. lines.push(ch);
  10889. linesWidths.push(chWidth);
  10890. }
  10891. }
  10892. else if (line || currentWord) {
  10893. if (inWord) {
  10894. if (!line) {
  10895. line = currentWord;
  10896. currentWord = '';
  10897. currentWordWidth = 0;
  10898. accumWidth = currentWordWidth;
  10899. }
  10900. lines.push(line);
  10901. linesWidths.push(accumWidth - currentWordWidth);
  10902. currentWord += ch;
  10903. currentWordWidth += chWidth;
  10904. line = '';
  10905. accumWidth = currentWordWidth;
  10906. }
  10907. else {
  10908. if (currentWord) {
  10909. line += currentWord;
  10910. currentWord = '';
  10911. currentWordWidth = 0;
  10912. }
  10913. lines.push(line);
  10914. linesWidths.push(accumWidth);
  10915. line = ch;
  10916. accumWidth = chWidth;
  10917. }
  10918. }
  10919. continue;
  10920. }
  10921. accumWidth += chWidth;
  10922. if (inWord) {
  10923. currentWord += ch;
  10924. currentWordWidth += chWidth;
  10925. }
  10926. else {
  10927. if (currentWord) {
  10928. line += currentWord;
  10929. currentWord = '';
  10930. currentWordWidth = 0;
  10931. }
  10932. line += ch;
  10933. }
  10934. }
  10935. if (currentWord) {
  10936. line += currentWord;
  10937. }
  10938. if (line) {
  10939. lines.push(line);
  10940. linesWidths.push(accumWidth);
  10941. }
  10942. if (lines.length === 1) {
  10943. accumWidth += lastAccumWidth;
  10944. }
  10945. return {
  10946. accumWidth: accumWidth,
  10947. lines: lines,
  10948. linesWidths: linesWidths
  10949. };
  10950. }
  10951. function calcInnerTextOverflowArea(out, overflowRect, baseX, baseY, textAlign, textVerticalAlign) {
  10952. out.baseX = baseX;
  10953. out.baseY = baseY;
  10954. out.outerWidth = out.outerHeight = null;
  10955. if (!overflowRect) {
  10956. return;
  10957. }
  10958. var textWidth = overflowRect.width * 2;
  10959. var textHeight = overflowRect.height * 2;
  10960. BoundingRect.set(tmpCITCTextRect, adjustTextX(baseX, textWidth, textAlign), adjustTextY$1(baseY, textHeight, textVerticalAlign), textWidth, textHeight);
  10961. BoundingRect.intersect(overflowRect, tmpCITCTextRect, null, tmpCITCIntersectRectOpt);
  10962. var outIntersectRect = tmpCITCIntersectRectOpt.outIntersectRect;
  10963. out.outerWidth = outIntersectRect.width;
  10964. out.outerHeight = outIntersectRect.height;
  10965. out.baseX = adjustTextX(outIntersectRect.x, outIntersectRect.width, textAlign, true);
  10966. out.baseY = adjustTextY$1(outIntersectRect.y, outIntersectRect.height, textVerticalAlign, true);
  10967. }
  10968. var tmpCITCTextRect = new BoundingRect(0, 0, 0, 0);
  10969. var tmpCITCIntersectRectOpt = { outIntersectRect: {}, clamp: true };
  10970. function formatText(text) {
  10971. return text != null ? (text += '') : (text = '');
  10972. }
  10973. function tSpanCreateBoundingRect(style) {
  10974. var text = formatText(style.text);
  10975. var font = style.font;
  10976. var contentWidth = measureWidth(ensureFontMeasureInfo(font), text);
  10977. var contentHeight = getLineHeight(font);
  10978. return tSpanCreateBoundingRect2(style, contentWidth, contentHeight, null);
  10979. }
  10980. function tSpanCreateBoundingRect2(style, contentWidth, contentHeight, forceLineWidth) {
  10981. var rect = new BoundingRect(adjustTextX(style.x || 0, contentWidth, style.textAlign), adjustTextY$1(style.y || 0, contentHeight, style.textBaseline), contentWidth, contentHeight);
  10982. var lineWidth = forceLineWidth != null
  10983. ? forceLineWidth
  10984. : (tSpanHasStroke(style) ? style.lineWidth : 0);
  10985. if (lineWidth > 0) {
  10986. rect.x -= lineWidth / 2;
  10987. rect.y -= lineWidth / 2;
  10988. rect.width += lineWidth;
  10989. rect.height += lineWidth;
  10990. }
  10991. return rect;
  10992. }
  10993. function tSpanHasStroke(style) {
  10994. var stroke = style.stroke;
  10995. return stroke != null && stroke !== 'none' && style.lineWidth > 0;
  10996. }
  10997. var DEFAULT_TSPAN_STYLE = defaults({
  10998. strokeFirst: true,
  10999. font: DEFAULT_FONT,
  11000. x: 0,
  11001. y: 0,
  11002. textAlign: 'left',
  11003. textBaseline: 'top',
  11004. miterLimit: 2
  11005. }, DEFAULT_PATH_STYLE);
  11006. var TSpan = (function (_super) {
  11007. __extends(TSpan, _super);
  11008. function TSpan() {
  11009. return _super !== null && _super.apply(this, arguments) || this;
  11010. }
  11011. TSpan.prototype.hasStroke = function () {
  11012. return tSpanHasStroke(this.style);
  11013. };
  11014. TSpan.prototype.hasFill = function () {
  11015. var style = this.style;
  11016. var fill = style.fill;
  11017. return fill != null && fill !== 'none';
  11018. };
  11019. TSpan.prototype.createStyle = function (obj) {
  11020. return createObject(DEFAULT_TSPAN_STYLE, obj);
  11021. };
  11022. TSpan.prototype.setBoundingRect = function (rect) {
  11023. this._rect = rect;
  11024. };
  11025. TSpan.prototype.getBoundingRect = function () {
  11026. if (!this._rect) {
  11027. this._rect = tSpanCreateBoundingRect(this.style);
  11028. }
  11029. return this._rect;
  11030. };
  11031. TSpan.initDefaultProps = (function () {
  11032. var tspanProto = TSpan.prototype;
  11033. tspanProto.dirtyRectTolerance = 10;
  11034. })();
  11035. return TSpan;
  11036. }(Displayable));
  11037. TSpan.prototype.type = 'tspan';
  11038. function parseXML(svg) {
  11039. if (isString(svg)) {
  11040. var parser = new DOMParser();
  11041. svg = parser.parseFromString(svg, 'text/xml');
  11042. }
  11043. var svgNode = svg;
  11044. if (svgNode.nodeType === 9) {
  11045. svgNode = svgNode.firstChild;
  11046. }
  11047. while (svgNode.nodeName.toLowerCase() !== 'svg' || svgNode.nodeType !== 1) {
  11048. svgNode = svgNode.nextSibling;
  11049. }
  11050. return svgNode;
  11051. }
  11052. var nodeParsers;
  11053. var INHERITABLE_STYLE_ATTRIBUTES_MAP = {
  11054. 'fill': 'fill',
  11055. 'stroke': 'stroke',
  11056. 'stroke-width': 'lineWidth',
  11057. 'opacity': 'opacity',
  11058. 'fill-opacity': 'fillOpacity',
  11059. 'stroke-opacity': 'strokeOpacity',
  11060. 'stroke-dasharray': 'lineDash',
  11061. 'stroke-dashoffset': 'lineDashOffset',
  11062. 'stroke-linecap': 'lineCap',
  11063. 'stroke-linejoin': 'lineJoin',
  11064. 'stroke-miterlimit': 'miterLimit',
  11065. 'font-family': 'fontFamily',
  11066. 'font-size': 'fontSize',
  11067. 'font-style': 'fontStyle',
  11068. 'font-weight': 'fontWeight',
  11069. 'text-anchor': 'textAlign',
  11070. 'visibility': 'visibility',
  11071. 'display': 'display'
  11072. };
  11073. var INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS = keys(INHERITABLE_STYLE_ATTRIBUTES_MAP);
  11074. var SELF_STYLE_ATTRIBUTES_MAP = {
  11075. 'alignment-baseline': 'textBaseline',
  11076. 'stop-color': 'stopColor'
  11077. };
  11078. var SELF_STYLE_ATTRIBUTES_MAP_KEYS = keys(SELF_STYLE_ATTRIBUTES_MAP);
  11079. var SVGParser = (function () {
  11080. function SVGParser() {
  11081. this._defs = {};
  11082. this._root = null;
  11083. }
  11084. SVGParser.prototype.parse = function (xml, opt) {
  11085. opt = opt || {};
  11086. var svg = parseXML(xml);
  11087. {
  11088. if (!svg) {
  11089. throw new Error('Illegal svg');
  11090. }
  11091. }
  11092. this._defsUsePending = [];
  11093. var root = new Group();
  11094. this._root = root;
  11095. var named = [];
  11096. var viewBox = svg.getAttribute('viewBox') || '';
  11097. var width = parseFloat((svg.getAttribute('width') || opt.width));
  11098. var height = parseFloat((svg.getAttribute('height') || opt.height));
  11099. isNaN(width) && (width = null);
  11100. isNaN(height) && (height = null);
  11101. parseAttributes(svg, root, null, true, false);
  11102. var child = svg.firstChild;
  11103. while (child) {
  11104. this._parseNode(child, root, named, null, false, false);
  11105. child = child.nextSibling;
  11106. }
  11107. applyDefs(this._defs, this._defsUsePending);
  11108. this._defsUsePending = [];
  11109. var viewBoxRect;
  11110. var viewBoxTransform;
  11111. if (viewBox) {
  11112. var viewBoxArr = splitNumberSequence(viewBox);
  11113. if (viewBoxArr.length >= 4) {
  11114. viewBoxRect = {
  11115. x: parseFloat((viewBoxArr[0] || 0)),
  11116. y: parseFloat((viewBoxArr[1] || 0)),
  11117. width: parseFloat(viewBoxArr[2]),
  11118. height: parseFloat(viewBoxArr[3])
  11119. };
  11120. }
  11121. }
  11122. if (viewBoxRect && width != null && height != null) {
  11123. viewBoxTransform = makeViewBoxTransform(viewBoxRect, { x: 0, y: 0, width: width, height: height });
  11124. if (!opt.ignoreViewBox) {
  11125. var elRoot = root;
  11126. root = new Group();
  11127. root.add(elRoot);
  11128. elRoot.scaleX = elRoot.scaleY = viewBoxTransform.scale;
  11129. elRoot.x = viewBoxTransform.x;
  11130. elRoot.y = viewBoxTransform.y;
  11131. }
  11132. }
  11133. if (!opt.ignoreRootClip && width != null && height != null) {
  11134. root.setClipPath(new Rect({
  11135. shape: { x: 0, y: 0, width: width, height: height }
  11136. }));
  11137. }
  11138. return {
  11139. root: root,
  11140. width: width,
  11141. height: height,
  11142. viewBoxRect: viewBoxRect,
  11143. viewBoxTransform: viewBoxTransform,
  11144. named: named
  11145. };
  11146. };
  11147. SVGParser.prototype._parseNode = function (xmlNode, parentGroup, named, namedFrom, isInDefs, isInText) {
  11148. var nodeName = xmlNode.nodeName.toLowerCase();
  11149. var el;
  11150. var namedFromForSub = namedFrom;
  11151. if (nodeName === 'defs') {
  11152. isInDefs = true;
  11153. }
  11154. if (nodeName === 'text') {
  11155. isInText = true;
  11156. }
  11157. if (nodeName === 'defs' || nodeName === 'switch') {
  11158. el = parentGroup;
  11159. }
  11160. else {
  11161. if (!isInDefs) {
  11162. var parser_1 = nodeParsers[nodeName];
  11163. if (parser_1 && hasOwn(nodeParsers, nodeName)) {
  11164. el = parser_1.call(this, xmlNode, parentGroup);
  11165. var nameAttr = xmlNode.getAttribute('name');
  11166. if (nameAttr) {
  11167. var newNamed = {
  11168. name: nameAttr,
  11169. namedFrom: null,
  11170. svgNodeTagLower: nodeName,
  11171. el: el
  11172. };
  11173. named.push(newNamed);
  11174. if (nodeName === 'g') {
  11175. namedFromForSub = newNamed;
  11176. }
  11177. }
  11178. else if (namedFrom) {
  11179. named.push({
  11180. name: namedFrom.name,
  11181. namedFrom: namedFrom,
  11182. svgNodeTagLower: nodeName,
  11183. el: el
  11184. });
  11185. }
  11186. parentGroup.add(el);
  11187. }
  11188. }
  11189. var parser = paintServerParsers[nodeName];
  11190. if (parser && hasOwn(paintServerParsers, nodeName)) {
  11191. var def = parser.call(this, xmlNode);
  11192. var id = xmlNode.getAttribute('id');
  11193. if (id) {
  11194. this._defs[id] = def;
  11195. }
  11196. }
  11197. }
  11198. if (el && el.isGroup) {
  11199. var child = xmlNode.firstChild;
  11200. while (child) {
  11201. if (child.nodeType === 1) {
  11202. this._parseNode(child, el, named, namedFromForSub, isInDefs, isInText);
  11203. }
  11204. else if (child.nodeType === 3 && isInText) {
  11205. this._parseText(child, el);
  11206. }
  11207. child = child.nextSibling;
  11208. }
  11209. }
  11210. };
  11211. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  11212. var text = new TSpan({
  11213. style: {
  11214. text: xmlNode.textContent
  11215. },
  11216. silent: true,
  11217. x: this._textX || 0,
  11218. y: this._textY || 0
  11219. });
  11220. inheritStyle(parentGroup, text);
  11221. parseAttributes(xmlNode, text, this._defsUsePending, false, false);
  11222. applyTextAlignment(text, parentGroup);
  11223. var textStyle = text.style;
  11224. var fontSize = textStyle.fontSize;
  11225. if (fontSize && fontSize < 9) {
  11226. textStyle.fontSize = 9;
  11227. text.scaleX *= fontSize / 9;
  11228. text.scaleY *= fontSize / 9;
  11229. }
  11230. var font = (textStyle.fontSize || textStyle.fontFamily) && [
  11231. textStyle.fontStyle,
  11232. textStyle.fontWeight,
  11233. (textStyle.fontSize || 12) + 'px',
  11234. textStyle.fontFamily || 'sans-serif'
  11235. ].join(' ');
  11236. textStyle.font = font;
  11237. var rect = text.getBoundingRect();
  11238. this._textX += rect.width;
  11239. parentGroup.add(text);
  11240. return text;
  11241. };
  11242. SVGParser.internalField = (function () {
  11243. nodeParsers = {
  11244. 'g': function (xmlNode, parentGroup) {
  11245. var g = new Group();
  11246. inheritStyle(parentGroup, g);
  11247. parseAttributes(xmlNode, g, this._defsUsePending, false, false);
  11248. return g;
  11249. },
  11250. 'rect': function (xmlNode, parentGroup) {
  11251. var rect = new Rect();
  11252. inheritStyle(parentGroup, rect);
  11253. parseAttributes(xmlNode, rect, this._defsUsePending, false, false);
  11254. rect.setShape({
  11255. x: parseFloat(xmlNode.getAttribute('x') || '0'),
  11256. y: parseFloat(xmlNode.getAttribute('y') || '0'),
  11257. width: parseFloat(xmlNode.getAttribute('width') || '0'),
  11258. height: parseFloat(xmlNode.getAttribute('height') || '0')
  11259. });
  11260. rect.silent = true;
  11261. return rect;
  11262. },
  11263. 'circle': function (xmlNode, parentGroup) {
  11264. var circle = new Circle();
  11265. inheritStyle(parentGroup, circle);
  11266. parseAttributes(xmlNode, circle, this._defsUsePending, false, false);
  11267. circle.setShape({
  11268. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  11269. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  11270. r: parseFloat(xmlNode.getAttribute('r') || '0')
  11271. });
  11272. circle.silent = true;
  11273. return circle;
  11274. },
  11275. 'line': function (xmlNode, parentGroup) {
  11276. var line = new Line();
  11277. inheritStyle(parentGroup, line);
  11278. parseAttributes(xmlNode, line, this._defsUsePending, false, false);
  11279. line.setShape({
  11280. x1: parseFloat(xmlNode.getAttribute('x1') || '0'),
  11281. y1: parseFloat(xmlNode.getAttribute('y1') || '0'),
  11282. x2: parseFloat(xmlNode.getAttribute('x2') || '0'),
  11283. y2: parseFloat(xmlNode.getAttribute('y2') || '0')
  11284. });
  11285. line.silent = true;
  11286. return line;
  11287. },
  11288. 'ellipse': function (xmlNode, parentGroup) {
  11289. var ellipse = new Ellipse();
  11290. inheritStyle(parentGroup, ellipse);
  11291. parseAttributes(xmlNode, ellipse, this._defsUsePending, false, false);
  11292. ellipse.setShape({
  11293. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  11294. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  11295. rx: parseFloat(xmlNode.getAttribute('rx') || '0'),
  11296. ry: parseFloat(xmlNode.getAttribute('ry') || '0')
  11297. });
  11298. ellipse.silent = true;
  11299. return ellipse;
  11300. },
  11301. 'polygon': function (xmlNode, parentGroup) {
  11302. var pointsStr = xmlNode.getAttribute('points');
  11303. var pointsArr;
  11304. if (pointsStr) {
  11305. pointsArr = parsePoints(pointsStr);
  11306. }
  11307. var polygon = new Polygon({
  11308. shape: {
  11309. points: pointsArr || []
  11310. },
  11311. silent: true
  11312. });
  11313. inheritStyle(parentGroup, polygon);
  11314. parseAttributes(xmlNode, polygon, this._defsUsePending, false, false);
  11315. return polygon;
  11316. },
  11317. 'polyline': function (xmlNode, parentGroup) {
  11318. var pointsStr = xmlNode.getAttribute('points');
  11319. var pointsArr;
  11320. if (pointsStr) {
  11321. pointsArr = parsePoints(pointsStr);
  11322. }
  11323. var polyline = new Polyline({
  11324. shape: {
  11325. points: pointsArr || []
  11326. },
  11327. silent: true
  11328. });
  11329. inheritStyle(parentGroup, polyline);
  11330. parseAttributes(xmlNode, polyline, this._defsUsePending, false, false);
  11331. return polyline;
  11332. },
  11333. 'image': function (xmlNode, parentGroup) {
  11334. var img = new ZRImage();
  11335. inheritStyle(parentGroup, img);
  11336. parseAttributes(xmlNode, img, this._defsUsePending, false, false);
  11337. img.setStyle({
  11338. image: xmlNode.getAttribute('xlink:href') || xmlNode.getAttribute('href'),
  11339. x: +xmlNode.getAttribute('x'),
  11340. y: +xmlNode.getAttribute('y'),
  11341. width: +xmlNode.getAttribute('width'),
  11342. height: +xmlNode.getAttribute('height')
  11343. });
  11344. img.silent = true;
  11345. return img;
  11346. },
  11347. 'text': function (xmlNode, parentGroup) {
  11348. var x = xmlNode.getAttribute('x') || '0';
  11349. var y = xmlNode.getAttribute('y') || '0';
  11350. var dx = xmlNode.getAttribute('dx') || '0';
  11351. var dy = xmlNode.getAttribute('dy') || '0';
  11352. this._textX = parseFloat(x) + parseFloat(dx);
  11353. this._textY = parseFloat(y) + parseFloat(dy);
  11354. var g = new Group();
  11355. inheritStyle(parentGroup, g);
  11356. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  11357. return g;
  11358. },
  11359. 'tspan': function (xmlNode, parentGroup) {
  11360. var x = xmlNode.getAttribute('x');
  11361. var y = xmlNode.getAttribute('y');
  11362. if (x != null) {
  11363. this._textX = parseFloat(x);
  11364. }
  11365. if (y != null) {
  11366. this._textY = parseFloat(y);
  11367. }
  11368. var dx = xmlNode.getAttribute('dx') || '0';
  11369. var dy = xmlNode.getAttribute('dy') || '0';
  11370. var g = new Group();
  11371. inheritStyle(parentGroup, g);
  11372. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  11373. this._textX += parseFloat(dx);
  11374. this._textY += parseFloat(dy);
  11375. return g;
  11376. },
  11377. 'path': function (xmlNode, parentGroup) {
  11378. var d = xmlNode.getAttribute('d') || '';
  11379. var path = createFromString(d);
  11380. inheritStyle(parentGroup, path);
  11381. parseAttributes(xmlNode, path, this._defsUsePending, false, false);
  11382. path.silent = true;
  11383. return path;
  11384. }
  11385. };
  11386. })();
  11387. return SVGParser;
  11388. }());
  11389. var paintServerParsers = {
  11390. 'lineargradient': function (xmlNode) {
  11391. var x1 = parseInt(xmlNode.getAttribute('x1') || '0', 10);
  11392. var y1 = parseInt(xmlNode.getAttribute('y1') || '0', 10);
  11393. var x2 = parseInt(xmlNode.getAttribute('x2') || '10', 10);
  11394. var y2 = parseInt(xmlNode.getAttribute('y2') || '0', 10);
  11395. var gradient = new LinearGradient(x1, y1, x2, y2);
  11396. parsePaintServerUnit(xmlNode, gradient);
  11397. parseGradientColorStops(xmlNode, gradient);
  11398. return gradient;
  11399. },
  11400. 'radialgradient': function (xmlNode) {
  11401. var cx = parseInt(xmlNode.getAttribute('cx') || '0', 10);
  11402. var cy = parseInt(xmlNode.getAttribute('cy') || '0', 10);
  11403. var r = parseInt(xmlNode.getAttribute('r') || '0', 10);
  11404. var gradient = new RadialGradient(cx, cy, r);
  11405. parsePaintServerUnit(xmlNode, gradient);
  11406. parseGradientColorStops(xmlNode, gradient);
  11407. return gradient;
  11408. }
  11409. };
  11410. function parsePaintServerUnit(xmlNode, gradient) {
  11411. var gradientUnits = xmlNode.getAttribute('gradientUnits');
  11412. if (gradientUnits === 'userSpaceOnUse') {
  11413. gradient.global = true;
  11414. }
  11415. }
  11416. function parseGradientColorStops(xmlNode, gradient) {
  11417. var stop = xmlNode.firstChild;
  11418. while (stop) {
  11419. if (stop.nodeType === 1
  11420. && stop.nodeName.toLocaleLowerCase() === 'stop') {
  11421. var offsetStr = stop.getAttribute('offset');
  11422. var offset = void 0;
  11423. if (offsetStr && offsetStr.indexOf('%') > 0) {
  11424. offset = parseInt(offsetStr, 10) / 100;
  11425. }
  11426. else if (offsetStr) {
  11427. offset = parseFloat(offsetStr);
  11428. }
  11429. else {
  11430. offset = 0;
  11431. }
  11432. var styleVals = {};
  11433. parseInlineStyle(stop, styleVals, styleVals);
  11434. var stopColor = styleVals.stopColor
  11435. || stop.getAttribute('stop-color')
  11436. || '#000000';
  11437. var stopOpacity = styleVals.stopOpacity
  11438. || stop.getAttribute('stop-opacity');
  11439. if (stopOpacity) {
  11440. var rgba = parse(stopColor);
  11441. var stopColorOpacity = rgba && rgba[3];
  11442. if (stopColorOpacity) {
  11443. rgba[3] *= parseCssFloat(stopOpacity);
  11444. stopColor = stringify(rgba, 'rgba');
  11445. }
  11446. }
  11447. gradient.colorStops.push({
  11448. offset: offset,
  11449. color: stopColor
  11450. });
  11451. }
  11452. stop = stop.nextSibling;
  11453. }
  11454. }
  11455. function inheritStyle(parent, child) {
  11456. if (parent && parent.__inheritedStyle) {
  11457. if (!child.__inheritedStyle) {
  11458. child.__inheritedStyle = {};
  11459. }
  11460. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  11461. }
  11462. }
  11463. function parsePoints(pointsString) {
  11464. var list = splitNumberSequence(pointsString);
  11465. var points = [];
  11466. for (var i = 0; i < list.length; i += 2) {
  11467. var x = parseFloat(list[i]);
  11468. var y = parseFloat(list[i + 1]);
  11469. points.push([x, y]);
  11470. }
  11471. return points;
  11472. }
  11473. function parseAttributes(xmlNode, el, defsUsePending, onlyInlineStyle, isTextGroup) {
  11474. var disp = el;
  11475. var inheritedStyle = disp.__inheritedStyle = disp.__inheritedStyle || {};
  11476. var selfStyle = {};
  11477. if (xmlNode.nodeType === 1) {
  11478. parseTransformAttribute(xmlNode, el);
  11479. parseInlineStyle(xmlNode, inheritedStyle, selfStyle);
  11480. if (!onlyInlineStyle) {
  11481. parseAttributeStyle(xmlNode, inheritedStyle, selfStyle);
  11482. }
  11483. }
  11484. disp.style = disp.style || {};
  11485. if (inheritedStyle.fill != null) {
  11486. disp.style.fill = getFillStrokeStyle(disp, 'fill', inheritedStyle.fill, defsUsePending);
  11487. }
  11488. if (inheritedStyle.stroke != null) {
  11489. disp.style.stroke = getFillStrokeStyle(disp, 'stroke', inheritedStyle.stroke, defsUsePending);
  11490. }
  11491. each([
  11492. 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'
  11493. ], function (propName) {
  11494. if (inheritedStyle[propName] != null) {
  11495. disp.style[propName] = parseFloat(inheritedStyle[propName]);
  11496. }
  11497. });
  11498. each([
  11499. 'lineDashOffset', 'lineCap', 'lineJoin', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign'
  11500. ], function (propName) {
  11501. if (inheritedStyle[propName] != null) {
  11502. disp.style[propName] = inheritedStyle[propName];
  11503. }
  11504. });
  11505. if (isTextGroup) {
  11506. disp.__selfStyle = selfStyle;
  11507. }
  11508. if (inheritedStyle.lineDash) {
  11509. disp.style.lineDash = map(splitNumberSequence(inheritedStyle.lineDash), function (str) {
  11510. return parseFloat(str);
  11511. });
  11512. }
  11513. if (inheritedStyle.visibility === 'hidden' || inheritedStyle.visibility === 'collapse') {
  11514. disp.invisible = true;
  11515. }
  11516. if (inheritedStyle.display === 'none') {
  11517. disp.ignore = true;
  11518. }
  11519. }
  11520. function applyTextAlignment(text, parentGroup) {
  11521. var parentSelfStyle = parentGroup.__selfStyle;
  11522. if (parentSelfStyle) {
  11523. var textBaseline = parentSelfStyle.textBaseline;
  11524. var zrTextBaseline = textBaseline;
  11525. if (!textBaseline || textBaseline === 'auto') {
  11526. zrTextBaseline = 'alphabetic';
  11527. }
  11528. else if (textBaseline === 'baseline') {
  11529. zrTextBaseline = 'alphabetic';
  11530. }
  11531. else if (textBaseline === 'before-edge' || textBaseline === 'text-before-edge') {
  11532. zrTextBaseline = 'top';
  11533. }
  11534. else if (textBaseline === 'after-edge' || textBaseline === 'text-after-edge') {
  11535. zrTextBaseline = 'bottom';
  11536. }
  11537. else if (textBaseline === 'central' || textBaseline === 'mathematical') {
  11538. zrTextBaseline = 'middle';
  11539. }
  11540. text.style.textBaseline = zrTextBaseline;
  11541. }
  11542. var parentInheritedStyle = parentGroup.__inheritedStyle;
  11543. if (parentInheritedStyle) {
  11544. var textAlign = parentInheritedStyle.textAlign;
  11545. var zrTextAlign = textAlign;
  11546. if (textAlign) {
  11547. if (textAlign === 'middle') {
  11548. zrTextAlign = 'center';
  11549. }
  11550. text.style.textAlign = zrTextAlign;
  11551. }
  11552. }
  11553. }
  11554. var urlRegex = /^url\(\s*#(.*?)\)/;
  11555. function getFillStrokeStyle(el, method, str, defsUsePending) {
  11556. var urlMatch = str && str.match(urlRegex);
  11557. if (urlMatch) {
  11558. var url = trim(urlMatch[1]);
  11559. defsUsePending.push([el, method, url]);
  11560. return;
  11561. }
  11562. if (str === 'none') {
  11563. str = null;
  11564. }
  11565. return str;
  11566. }
  11567. function applyDefs(defs, defsUsePending) {
  11568. for (var i = 0; i < defsUsePending.length; i++) {
  11569. var item = defsUsePending[i];
  11570. item[0].style[item[1]] = defs[item[2]];
  11571. }
  11572. }
  11573. var numberReg$1 = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  11574. function splitNumberSequence(rawStr) {
  11575. return rawStr.match(numberReg$1) || [];
  11576. }
  11577. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.eE,]*)\)/g;
  11578. var DEGREE_TO_ANGLE = Math.PI / 180;
  11579. function parseTransformAttribute(xmlNode, node) {
  11580. var transform = xmlNode.getAttribute('transform');
  11581. if (transform) {
  11582. transform = transform.replace(/,/g, ' ');
  11583. var transformOps_1 = [];
  11584. var mt = null;
  11585. transform.replace(transformRegex, function (str, type, value) {
  11586. transformOps_1.push(type, value);
  11587. return '';
  11588. });
  11589. for (var i = transformOps_1.length - 1; i > 0; i -= 2) {
  11590. var value = transformOps_1[i];
  11591. var type = transformOps_1[i - 1];
  11592. var valueArr = splitNumberSequence(value);
  11593. mt = mt || create$1();
  11594. switch (type) {
  11595. case 'translate':
  11596. translate(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || '0')]);
  11597. break;
  11598. case 'scale':
  11599. scale$1(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || valueArr[0])]);
  11600. break;
  11601. case 'rotate':
  11602. rotate(mt, mt, -parseFloat(valueArr[0]) * DEGREE_TO_ANGLE, [
  11603. parseFloat(valueArr[1] || '0'),
  11604. parseFloat(valueArr[2] || '0')
  11605. ]);
  11606. break;
  11607. case 'skewX':
  11608. var sx = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  11609. mul$1(mt, [1, 0, sx, 1, 0, 0], mt);
  11610. break;
  11611. case 'skewY':
  11612. var sy = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  11613. mul$1(mt, [1, sy, 0, 1, 0, 0], mt);
  11614. break;
  11615. case 'matrix':
  11616. mt[0] = parseFloat(valueArr[0]);
  11617. mt[1] = parseFloat(valueArr[1]);
  11618. mt[2] = parseFloat(valueArr[2]);
  11619. mt[3] = parseFloat(valueArr[3]);
  11620. mt[4] = parseFloat(valueArr[4]);
  11621. mt[5] = parseFloat(valueArr[5]);
  11622. break;
  11623. }
  11624. }
  11625. node.setLocalTransform(mt);
  11626. }
  11627. }
  11628. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  11629. function parseInlineStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  11630. var style = xmlNode.getAttribute('style');
  11631. if (!style) {
  11632. return;
  11633. }
  11634. styleRegex.lastIndex = 0;
  11635. var styleRegResult;
  11636. while ((styleRegResult = styleRegex.exec(style)) != null) {
  11637. var svgStlAttr = styleRegResult[1];
  11638. var zrInheritableStlAttr = hasOwn(INHERITABLE_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  11639. ? INHERITABLE_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  11640. : null;
  11641. if (zrInheritableStlAttr) {
  11642. inheritableStyleResult[zrInheritableStlAttr] = styleRegResult[2];
  11643. }
  11644. var zrSelfStlAttr = hasOwn(SELF_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  11645. ? SELF_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  11646. : null;
  11647. if (zrSelfStlAttr) {
  11648. selfStyleResult[zrSelfStlAttr] = styleRegResult[2];
  11649. }
  11650. }
  11651. }
  11652. function parseAttributeStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  11653. for (var i = 0; i < INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  11654. var svgAttrName = INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS[i];
  11655. var attrValue = xmlNode.getAttribute(svgAttrName);
  11656. if (attrValue != null) {
  11657. inheritableStyleResult[INHERITABLE_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  11658. }
  11659. }
  11660. for (var i = 0; i < SELF_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  11661. var svgAttrName = SELF_STYLE_ATTRIBUTES_MAP_KEYS[i];
  11662. var attrValue = xmlNode.getAttribute(svgAttrName);
  11663. if (attrValue != null) {
  11664. selfStyleResult[SELF_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  11665. }
  11666. }
  11667. }
  11668. function makeViewBoxTransform(viewBoxRect, boundingRect) {
  11669. var scaleX = boundingRect.width / viewBoxRect.width;
  11670. var scaleY = boundingRect.height / viewBoxRect.height;
  11671. var scale = Math.min(scaleX, scaleY);
  11672. return {
  11673. scale: scale,
  11674. x: -(viewBoxRect.x + viewBoxRect.width / 2) * scale + (boundingRect.x + boundingRect.width / 2),
  11675. y: -(viewBoxRect.y + viewBoxRect.height / 2) * scale + (boundingRect.y + boundingRect.height / 2)
  11676. };
  11677. }
  11678. function parseSVG(xml, opt) {
  11679. var parser = new SVGParser();
  11680. return parser.parse(xml, opt);
  11681. }
  11682. var PI$2 = Math.PI;
  11683. var PI2$5 = PI$2 * 2;
  11684. var mathSin$3 = Math.sin;
  11685. var mathCos$3 = Math.cos;
  11686. var mathACos = Math.acos;
  11687. var mathATan2 = Math.atan2;
  11688. var mathAbs$2 = Math.abs;
  11689. var mathSqrt$3 = Math.sqrt;
  11690. var mathMax$3 = Math.max;
  11691. var mathMin$3 = Math.min;
  11692. var e = 1e-4;
  11693. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  11694. var dx10 = x1 - x0;
  11695. var dy10 = y1 - y0;
  11696. var dx32 = x3 - x2;
  11697. var dy32 = y3 - y2;
  11698. var t = dy32 * dx10 - dx32 * dy10;
  11699. if (t * t < e) {
  11700. return;
  11701. }
  11702. t = (dx32 * (y0 - y2) - dy32 * (x0 - x2)) / t;
  11703. return [x0 + t * dx10, y0 + t * dy10];
  11704. }
  11705. function computeCornerTangents(x0, y0, x1, y1, radius, cr, clockwise) {
  11706. var x01 = x0 - x1;
  11707. var y01 = y0 - y1;
  11708. var lo = (clockwise ? cr : -cr) / mathSqrt$3(x01 * x01 + y01 * y01);
  11709. var ox = lo * y01;
  11710. var oy = -lo * x01;
  11711. var x11 = x0 + ox;
  11712. var y11 = y0 + oy;
  11713. var x10 = x1 + ox;
  11714. var y10 = y1 + oy;
  11715. var x00 = (x11 + x10) / 2;
  11716. var y00 = (y11 + y10) / 2;
  11717. var dx = x10 - x11;
  11718. var dy = y10 - y11;
  11719. var d2 = dx * dx + dy * dy;
  11720. var r = radius - cr;
  11721. var s = x11 * y10 - x10 * y11;
  11722. var d = (dy < 0 ? -1 : 1) * mathSqrt$3(mathMax$3(0, r * r * d2 - s * s));
  11723. var cx0 = (s * dy - dx * d) / d2;
  11724. var cy0 = (-s * dx - dy * d) / d2;
  11725. var cx1 = (s * dy + dx * d) / d2;
  11726. var cy1 = (-s * dx + dy * d) / d2;
  11727. var dx0 = cx0 - x00;
  11728. var dy0 = cy0 - y00;
  11729. var dx1 = cx1 - x00;
  11730. var dy1 = cy1 - y00;
  11731. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
  11732. cx0 = cx1;
  11733. cy0 = cy1;
  11734. }
  11735. return {
  11736. cx: cx0,
  11737. cy: cy0,
  11738. x0: -ox,
  11739. y0: -oy,
  11740. x1: cx0 * (radius / r - 1),
  11741. y1: cy0 * (radius / r - 1)
  11742. };
  11743. }
  11744. function normalizeCornerRadius(cr) {
  11745. var arr;
  11746. if (isArray(cr)) {
  11747. var len = cr.length;
  11748. if (!len) {
  11749. return cr;
  11750. }
  11751. if (len === 1) {
  11752. arr = [cr[0], cr[0], 0, 0];
  11753. }
  11754. else if (len === 2) {
  11755. arr = [cr[0], cr[0], cr[1], cr[1]];
  11756. }
  11757. else if (len === 3) {
  11758. arr = cr.concat(cr[2]);
  11759. }
  11760. else {
  11761. arr = cr;
  11762. }
  11763. }
  11764. else {
  11765. arr = [cr, cr, cr, cr];
  11766. }
  11767. return arr;
  11768. }
  11769. function buildPath$2(ctx, shape) {
  11770. var _a;
  11771. var radius = mathMax$3(shape.r, 0);
  11772. var innerRadius = mathMax$3(shape.r0 || 0, 0);
  11773. var hasRadius = radius > 0;
  11774. var hasInnerRadius = innerRadius > 0;
  11775. if (!hasRadius && !hasInnerRadius) {
  11776. return;
  11777. }
  11778. if (!hasRadius) {
  11779. radius = innerRadius;
  11780. innerRadius = 0;
  11781. }
  11782. if (innerRadius > radius) {
  11783. var tmp = radius;
  11784. radius = innerRadius;
  11785. innerRadius = tmp;
  11786. }
  11787. var startAngle = shape.startAngle, endAngle = shape.endAngle;
  11788. if (isNaN(startAngle) || isNaN(endAngle)) {
  11789. return;
  11790. }
  11791. var cx = shape.cx, cy = shape.cy;
  11792. var clockwise = !!shape.clockwise;
  11793. var arc = mathAbs$2(endAngle - startAngle);
  11794. var mod = arc > PI2$5 && arc % PI2$5;
  11795. mod > e && (arc = mod);
  11796. if (!(radius > e)) {
  11797. ctx.moveTo(cx, cy);
  11798. }
  11799. else if (arc > PI2$5 - e) {
  11800. ctx.moveTo(cx + radius * mathCos$3(startAngle), cy + radius * mathSin$3(startAngle));
  11801. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  11802. if (innerRadius > e) {
  11803. ctx.moveTo(cx + innerRadius * mathCos$3(endAngle), cy + innerRadius * mathSin$3(endAngle));
  11804. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  11805. }
  11806. }
  11807. else {
  11808. var icrStart = void 0;
  11809. var icrEnd = void 0;
  11810. var ocrStart = void 0;
  11811. var ocrEnd = void 0;
  11812. var ocrs = void 0;
  11813. var ocre = void 0;
  11814. var icrs = void 0;
  11815. var icre = void 0;
  11816. var ocrMax = void 0;
  11817. var icrMax = void 0;
  11818. var limitedOcrMax = void 0;
  11819. var limitedIcrMax = void 0;
  11820. var xre = void 0;
  11821. var yre = void 0;
  11822. var xirs = void 0;
  11823. var yirs = void 0;
  11824. var xrs = radius * mathCos$3(startAngle);
  11825. var yrs = radius * mathSin$3(startAngle);
  11826. var xire = innerRadius * mathCos$3(endAngle);
  11827. var yire = innerRadius * mathSin$3(endAngle);
  11828. var hasArc = arc > e;
  11829. if (hasArc) {
  11830. var cornerRadius = shape.cornerRadius;
  11831. if (cornerRadius) {
  11832. _a = normalizeCornerRadius(cornerRadius), icrStart = _a[0], icrEnd = _a[1], ocrStart = _a[2], ocrEnd = _a[3];
  11833. }
  11834. var halfRd = mathAbs$2(radius - innerRadius) / 2;
  11835. ocrs = mathMin$3(halfRd, ocrStart);
  11836. ocre = mathMin$3(halfRd, ocrEnd);
  11837. icrs = mathMin$3(halfRd, icrStart);
  11838. icre = mathMin$3(halfRd, icrEnd);
  11839. limitedOcrMax = ocrMax = mathMax$3(ocrs, ocre);
  11840. limitedIcrMax = icrMax = mathMax$3(icrs, icre);
  11841. if (ocrMax > e || icrMax > e) {
  11842. xre = radius * mathCos$3(endAngle);
  11843. yre = radius * mathSin$3(endAngle);
  11844. xirs = innerRadius * mathCos$3(startAngle);
  11845. yirs = innerRadius * mathSin$3(startAngle);
  11846. if (arc < PI$2) {
  11847. var it_1 = intersect(xrs, yrs, xirs, yirs, xre, yre, xire, yire);
  11848. if (it_1) {
  11849. var x0 = xrs - it_1[0];
  11850. var y0 = yrs - it_1[1];
  11851. var x1 = xre - it_1[0];
  11852. var y1 = yre - it_1[1];
  11853. var a = 1 / mathSin$3(mathACos((x0 * x1 + y0 * y1) / (mathSqrt$3(x0 * x0 + y0 * y0) * mathSqrt$3(x1 * x1 + y1 * y1))) / 2);
  11854. var b = mathSqrt$3(it_1[0] * it_1[0] + it_1[1] * it_1[1]);
  11855. limitedOcrMax = mathMin$3(ocrMax, (radius - b) / (a + 1));
  11856. limitedIcrMax = mathMin$3(icrMax, (innerRadius - b) / (a - 1));
  11857. }
  11858. }
  11859. }
  11860. }
  11861. if (!hasArc) {
  11862. ctx.moveTo(cx + xrs, cy + yrs);
  11863. }
  11864. else if (limitedOcrMax > e) {
  11865. var crStart = mathMin$3(ocrStart, limitedOcrMax);
  11866. var crEnd = mathMin$3(ocrEnd, limitedOcrMax);
  11867. var ct0 = computeCornerTangents(xirs, yirs, xrs, yrs, radius, crStart, clockwise);
  11868. var ct1 = computeCornerTangents(xre, yre, xire, yire, radius, crEnd, clockwise);
  11869. ctx.moveTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  11870. if (limitedOcrMax < ocrMax && crStart === crEnd) {
  11871. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedOcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11872. }
  11873. else {
  11874. crStart > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crStart, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  11875. ctx.arc(cx, cy, radius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), !clockwise);
  11876. crEnd > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crEnd, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11877. }
  11878. }
  11879. else {
  11880. ctx.moveTo(cx + xrs, cy + yrs);
  11881. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  11882. }
  11883. if (!(innerRadius > e) || !hasArc) {
  11884. ctx.lineTo(cx + xire, cy + yire);
  11885. }
  11886. else if (limitedIcrMax > e) {
  11887. var crStart = mathMin$3(icrStart, limitedIcrMax);
  11888. var crEnd = mathMin$3(icrEnd, limitedIcrMax);
  11889. var ct0 = computeCornerTangents(xire, yire, xre, yre, innerRadius, -crEnd, clockwise);
  11890. var ct1 = computeCornerTangents(xrs, yrs, xirs, yirs, innerRadius, -crStart, clockwise);
  11891. ctx.lineTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  11892. if (limitedIcrMax < icrMax && crStart === crEnd) {
  11893. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedIcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11894. }
  11895. else {
  11896. crEnd > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crEnd, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  11897. ctx.arc(cx, cy, innerRadius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), clockwise);
  11898. crStart > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crStart, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  11899. }
  11900. }
  11901. else {
  11902. ctx.lineTo(cx + xire, cy + yire);
  11903. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  11904. }
  11905. }
  11906. ctx.closePath();
  11907. }
  11908. var SectorShape = (function () {
  11909. function SectorShape() {
  11910. this.cx = 0;
  11911. this.cy = 0;
  11912. this.r0 = 0;
  11913. this.r = 0;
  11914. this.startAngle = 0;
  11915. this.endAngle = Math.PI * 2;
  11916. this.clockwise = true;
  11917. this.cornerRadius = 0;
  11918. }
  11919. return SectorShape;
  11920. }());
  11921. var Sector = (function (_super) {
  11922. __extends(Sector, _super);
  11923. function Sector(opts) {
  11924. return _super.call(this, opts) || this;
  11925. }
  11926. Sector.prototype.getDefaultShape = function () {
  11927. return new SectorShape();
  11928. };
  11929. Sector.prototype.buildPath = function (ctx, shape) {
  11930. buildPath$2(ctx, shape);
  11931. };
  11932. Sector.prototype.isZeroArea = function () {
  11933. return this.shape.startAngle === this.shape.endAngle
  11934. || this.shape.r === this.shape.r0;
  11935. };
  11936. return Sector;
  11937. }(Path));
  11938. Sector.prototype.type = 'sector';
  11939. var CMD$3 = PathProxy.CMD;
  11940. function aroundEqual(a, b) {
  11941. return Math.abs(a - b) < 1e-5;
  11942. }
  11943. function pathToBezierCurves(path) {
  11944. var data = path.data;
  11945. var len = path.len();
  11946. var bezierArrayGroups = [];
  11947. var currentSubpath;
  11948. var xi = 0;
  11949. var yi = 0;
  11950. var x0 = 0;
  11951. var y0 = 0;
  11952. function createNewSubpath(x, y) {
  11953. if (currentSubpath && currentSubpath.length > 2) {
  11954. bezierArrayGroups.push(currentSubpath);
  11955. }
  11956. currentSubpath = [x, y];
  11957. }
  11958. function addLine(x0, y0, x1, y1) {
  11959. if (!(aroundEqual(x0, x1) && aroundEqual(y0, y1))) {
  11960. currentSubpath.push(x0, y0, x1, y1, x1, y1);
  11961. }
  11962. }
  11963. function addArc(startAngle, endAngle, cx, cy, rx, ry) {
  11964. var delta = Math.abs(endAngle - startAngle);
  11965. var len = Math.tan(delta / 4) * 4 / 3;
  11966. var dir = endAngle < startAngle ? -1 : 1;
  11967. var c1 = Math.cos(startAngle);
  11968. var s1 = Math.sin(startAngle);
  11969. var c2 = Math.cos(endAngle);
  11970. var s2 = Math.sin(endAngle);
  11971. var x1 = c1 * rx + cx;
  11972. var y1 = s1 * ry + cy;
  11973. var x4 = c2 * rx + cx;
  11974. var y4 = s2 * ry + cy;
  11975. var hx = rx * len * dir;
  11976. var hy = ry * len * dir;
  11977. currentSubpath.push(x1 - hx * s1, y1 + hy * c1, x4 + hx * s2, y4 - hy * c2, x4, y4);
  11978. }
  11979. var x1;
  11980. var y1;
  11981. var x2;
  11982. var y2;
  11983. for (var i = 0; i < len;) {
  11984. var cmd = data[i++];
  11985. var isFirst = i === 1;
  11986. if (isFirst) {
  11987. xi = data[i];
  11988. yi = data[i + 1];
  11989. x0 = xi;
  11990. y0 = yi;
  11991. if (cmd === CMD$3.L || cmd === CMD$3.C || cmd === CMD$3.Q) {
  11992. currentSubpath = [x0, y0];
  11993. }
  11994. }
  11995. switch (cmd) {
  11996. case CMD$3.M:
  11997. xi = x0 = data[i++];
  11998. yi = y0 = data[i++];
  11999. createNewSubpath(x0, y0);
  12000. break;
  12001. case CMD$3.L:
  12002. x1 = data[i++];
  12003. y1 = data[i++];
  12004. addLine(xi, yi, x1, y1);
  12005. xi = x1;
  12006. yi = y1;
  12007. break;
  12008. case CMD$3.C:
  12009. currentSubpath.push(data[i++], data[i++], data[i++], data[i++], xi = data[i++], yi = data[i++]);
  12010. break;
  12011. case CMD$3.Q:
  12012. x1 = data[i++];
  12013. y1 = data[i++];
  12014. x2 = data[i++];
  12015. y2 = data[i++];
  12016. currentSubpath.push(xi + 2 / 3 * (x1 - xi), yi + 2 / 3 * (y1 - yi), x2 + 2 / 3 * (x1 - x2), y2 + 2 / 3 * (y1 - y2), x2, y2);
  12017. xi = x2;
  12018. yi = y2;
  12019. break;
  12020. case CMD$3.A:
  12021. var cx = data[i++];
  12022. var cy = data[i++];
  12023. var rx = data[i++];
  12024. var ry = data[i++];
  12025. var startAngle = data[i++];
  12026. var endAngle = data[i++] + startAngle;
  12027. i += 1;
  12028. var anticlockwise = !data[i++];
  12029. x1 = Math.cos(startAngle) * rx + cx;
  12030. y1 = Math.sin(startAngle) * ry + cy;
  12031. if (isFirst) {
  12032. x0 = x1;
  12033. y0 = y1;
  12034. createNewSubpath(x0, y0);
  12035. }
  12036. else {
  12037. addLine(xi, yi, x1, y1);
  12038. }
  12039. xi = Math.cos(endAngle) * rx + cx;
  12040. yi = Math.sin(endAngle) * ry + cy;
  12041. var step = (anticlockwise ? -1 : 1) * Math.PI / 2;
  12042. for (var angle = startAngle; anticlockwise ? angle > endAngle : angle < endAngle; angle += step) {
  12043. var nextAngle = anticlockwise ? Math.max(angle + step, endAngle)
  12044. : Math.min(angle + step, endAngle);
  12045. addArc(angle, nextAngle, cx, cy, rx, ry);
  12046. }
  12047. break;
  12048. case CMD$3.R:
  12049. x0 = xi = data[i++];
  12050. y0 = yi = data[i++];
  12051. x1 = x0 + data[i++];
  12052. y1 = y0 + data[i++];
  12053. createNewSubpath(x1, y0);
  12054. addLine(x1, y0, x1, y1);
  12055. addLine(x1, y1, x0, y1);
  12056. addLine(x0, y1, x0, y0);
  12057. addLine(x0, y0, x1, y0);
  12058. break;
  12059. case CMD$3.Z:
  12060. currentSubpath && addLine(xi, yi, x0, y0);
  12061. xi = x0;
  12062. yi = y0;
  12063. break;
  12064. }
  12065. }
  12066. if (currentSubpath && currentSubpath.length > 2) {
  12067. bezierArrayGroups.push(currentSubpath);
  12068. }
  12069. return bezierArrayGroups;
  12070. }
  12071. function adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, out, scale) {
  12072. if (aroundEqual(x0, x1) && aroundEqual(y0, y1) && aroundEqual(x2, x3) && aroundEqual(y2, y3)) {
  12073. out.push(x3, y3);
  12074. return;
  12075. }
  12076. var PIXEL_DISTANCE = 2 / scale;
  12077. var PIXEL_DISTANCE_SQR = PIXEL_DISTANCE * PIXEL_DISTANCE;
  12078. var dx = x3 - x0;
  12079. var dy = y3 - y0;
  12080. var d = Math.sqrt(dx * dx + dy * dy);
  12081. dx /= d;
  12082. dy /= d;
  12083. var dx1 = x1 - x0;
  12084. var dy1 = y1 - y0;
  12085. var dx2 = x2 - x3;
  12086. var dy2 = y2 - y3;
  12087. var cp1LenSqr = dx1 * dx1 + dy1 * dy1;
  12088. var cp2LenSqr = dx2 * dx2 + dy2 * dy2;
  12089. if (cp1LenSqr < PIXEL_DISTANCE_SQR && cp2LenSqr < PIXEL_DISTANCE_SQR) {
  12090. out.push(x3, y3);
  12091. return;
  12092. }
  12093. var projLen1 = dx * dx1 + dy * dy1;
  12094. var projLen2 = -dx * dx2 - dy * dy2;
  12095. var d1Sqr = cp1LenSqr - projLen1 * projLen1;
  12096. var d2Sqr = cp2LenSqr - projLen2 * projLen2;
  12097. if (d1Sqr < PIXEL_DISTANCE_SQR && projLen1 >= 0
  12098. && d2Sqr < PIXEL_DISTANCE_SQR && projLen2 >= 0) {
  12099. out.push(x3, y3);
  12100. return;
  12101. }
  12102. var tmpSegX = [];
  12103. var tmpSegY = [];
  12104. cubicSubdivide(x0, x1, x2, x3, 0.5, tmpSegX);
  12105. cubicSubdivide(y0, y1, y2, y3, 0.5, tmpSegY);
  12106. adpativeBezier(tmpSegX[0], tmpSegY[0], tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], tmpSegX[3], tmpSegY[3], out, scale);
  12107. adpativeBezier(tmpSegX[4], tmpSegY[4], tmpSegX[5], tmpSegY[5], tmpSegX[6], tmpSegY[6], tmpSegX[7], tmpSegY[7], out, scale);
  12108. }
  12109. function pathToPolygons(path, scale) {
  12110. var bezierArrayGroups = pathToBezierCurves(path);
  12111. var polygons = [];
  12112. scale = scale || 1;
  12113. for (var i = 0; i < bezierArrayGroups.length; i++) {
  12114. var beziers = bezierArrayGroups[i];
  12115. var polygon = [];
  12116. var x0 = beziers[0];
  12117. var y0 = beziers[1];
  12118. polygon.push(x0, y0);
  12119. for (var k = 2; k < beziers.length;) {
  12120. var x1 = beziers[k++];
  12121. var y1 = beziers[k++];
  12122. var x2 = beziers[k++];
  12123. var y2 = beziers[k++];
  12124. var x3 = beziers[k++];
  12125. var y3 = beziers[k++];
  12126. adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, polygon, scale);
  12127. x0 = x3;
  12128. y0 = y3;
  12129. }
  12130. polygons.push(polygon);
  12131. }
  12132. return polygons;
  12133. }
  12134. function getDividingGrids(dimSize, rowDim, count) {
  12135. var rowSize = dimSize[rowDim];
  12136. var columnSize = dimSize[1 - rowDim];
  12137. var ratio = Math.abs(rowSize / columnSize);
  12138. var rowCount = Math.ceil(Math.sqrt(ratio * count));
  12139. var columnCount = Math.floor(count / rowCount);
  12140. if (columnCount === 0) {
  12141. columnCount = 1;
  12142. rowCount = count;
  12143. }
  12144. var grids = [];
  12145. for (var i = 0; i < rowCount; i++) {
  12146. grids.push(columnCount);
  12147. }
  12148. var currentCount = rowCount * columnCount;
  12149. var remained = count - currentCount;
  12150. if (remained > 0) {
  12151. for (var i = 0; i < remained; i++) {
  12152. grids[i % rowCount] += 1;
  12153. }
  12154. }
  12155. return grids;
  12156. }
  12157. function divideSector(sectorShape, count, outShapes) {
  12158. var r0 = sectorShape.r0;
  12159. var r = sectorShape.r;
  12160. var startAngle = sectorShape.startAngle;
  12161. var endAngle = sectorShape.endAngle;
  12162. var angle = Math.abs(endAngle - startAngle);
  12163. var arcLen = angle * r;
  12164. var deltaR = r - r0;
  12165. var isAngleRow = arcLen > Math.abs(deltaR);
  12166. var grids = getDividingGrids([arcLen, deltaR], isAngleRow ? 0 : 1, count);
  12167. var rowSize = (isAngleRow ? angle : deltaR) / grids.length;
  12168. for (var row = 0; row < grids.length; row++) {
  12169. var columnSize = (isAngleRow ? deltaR : angle) / grids[row];
  12170. for (var column = 0; column < grids[row]; column++) {
  12171. var newShape = {};
  12172. if (isAngleRow) {
  12173. newShape.startAngle = startAngle + rowSize * row;
  12174. newShape.endAngle = startAngle + rowSize * (row + 1);
  12175. newShape.r0 = r0 + columnSize * column;
  12176. newShape.r = r0 + columnSize * (column + 1);
  12177. }
  12178. else {
  12179. newShape.startAngle = startAngle + columnSize * column;
  12180. newShape.endAngle = startAngle + columnSize * (column + 1);
  12181. newShape.r0 = r0 + rowSize * row;
  12182. newShape.r = r0 + rowSize * (row + 1);
  12183. }
  12184. newShape.clockwise = sectorShape.clockwise;
  12185. newShape.cx = sectorShape.cx;
  12186. newShape.cy = sectorShape.cy;
  12187. outShapes.push(newShape);
  12188. }
  12189. }
  12190. }
  12191. function divideRect(rectShape, count, outShapes) {
  12192. var width = rectShape.width;
  12193. var height = rectShape.height;
  12194. var isHorizontalRow = width > height;
  12195. var grids = getDividingGrids([width, height], isHorizontalRow ? 0 : 1, count);
  12196. var rowSizeDim = isHorizontalRow ? 'width' : 'height';
  12197. var columnSizeDim = isHorizontalRow ? 'height' : 'width';
  12198. var rowDim = isHorizontalRow ? 'x' : 'y';
  12199. var columnDim = isHorizontalRow ? 'y' : 'x';
  12200. var rowSize = rectShape[rowSizeDim] / grids.length;
  12201. for (var row = 0; row < grids.length; row++) {
  12202. var columnSize = rectShape[columnSizeDim] / grids[row];
  12203. for (var column = 0; column < grids[row]; column++) {
  12204. var newShape = {};
  12205. newShape[rowDim] = row * rowSize;
  12206. newShape[columnDim] = column * columnSize;
  12207. newShape[rowSizeDim] = rowSize;
  12208. newShape[columnSizeDim] = columnSize;
  12209. newShape.x += rectShape.x;
  12210. newShape.y += rectShape.y;
  12211. outShapes.push(newShape);
  12212. }
  12213. }
  12214. }
  12215. function crossProduct2d(x1, y1, x2, y2) {
  12216. return x1 * y2 - x2 * y1;
  12217. }
  12218. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  12219. var mx = a2x - a1x;
  12220. var my = a2y - a1y;
  12221. var nx = b2x - b1x;
  12222. var ny = b2y - b1y;
  12223. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  12224. if (Math.abs(nmCrossProduct) < 1e-6) {
  12225. return null;
  12226. }
  12227. var b1a1x = a1x - b1x;
  12228. var b1a1y = a1y - b1y;
  12229. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  12230. if (p < 0 || p > 1) {
  12231. return null;
  12232. }
  12233. return new Point(p * mx + a1x, p * my + a1y);
  12234. }
  12235. function projPtOnLine(pt, lineA, lineB) {
  12236. var dir = new Point();
  12237. Point.sub(dir, lineB, lineA);
  12238. dir.normalize();
  12239. var dir2 = new Point();
  12240. Point.sub(dir2, pt, lineA);
  12241. var len = dir2.dot(dir);
  12242. return len;
  12243. }
  12244. function addToPoly(poly, pt) {
  12245. var last = poly[poly.length - 1];
  12246. if (last && last[0] === pt[0] && last[1] === pt[1]) {
  12247. return;
  12248. }
  12249. poly.push(pt);
  12250. }
  12251. function splitPolygonByLine(points, lineA, lineB) {
  12252. var len = points.length;
  12253. var intersections = [];
  12254. for (var i = 0; i < len; i++) {
  12255. var p0 = points[i];
  12256. var p1 = points[(i + 1) % len];
  12257. var intersectionPt = lineLineIntersect(p0[0], p0[1], p1[0], p1[1], lineA.x, lineA.y, lineB.x, lineB.y);
  12258. if (intersectionPt) {
  12259. intersections.push({
  12260. projPt: projPtOnLine(intersectionPt, lineA, lineB),
  12261. pt: intersectionPt,
  12262. idx: i
  12263. });
  12264. }
  12265. }
  12266. if (intersections.length < 2) {
  12267. return [{ points: points }, { points: points }];
  12268. }
  12269. intersections.sort(function (a, b) {
  12270. return a.projPt - b.projPt;
  12271. });
  12272. var splitPt0 = intersections[0];
  12273. var splitPt1 = intersections[intersections.length - 1];
  12274. if (splitPt1.idx < splitPt0.idx) {
  12275. var tmp = splitPt0;
  12276. splitPt0 = splitPt1;
  12277. splitPt1 = tmp;
  12278. }
  12279. var splitPt0Arr = [splitPt0.pt.x, splitPt0.pt.y];
  12280. var splitPt1Arr = [splitPt1.pt.x, splitPt1.pt.y];
  12281. var newPolyA = [splitPt0Arr];
  12282. var newPolyB = [splitPt1Arr];
  12283. for (var i = splitPt0.idx + 1; i <= splitPt1.idx; i++) {
  12284. addToPoly(newPolyA, points[i].slice());
  12285. }
  12286. addToPoly(newPolyA, splitPt1Arr);
  12287. addToPoly(newPolyA, splitPt0Arr);
  12288. for (var i = splitPt1.idx + 1; i <= splitPt0.idx + len; i++) {
  12289. addToPoly(newPolyB, points[i % len].slice());
  12290. }
  12291. addToPoly(newPolyB, splitPt0Arr);
  12292. addToPoly(newPolyB, splitPt1Arr);
  12293. return [{
  12294. points: newPolyA
  12295. }, {
  12296. points: newPolyB
  12297. }];
  12298. }
  12299. function binaryDividePolygon(polygonShape) {
  12300. var points = polygonShape.points;
  12301. var min = [];
  12302. var max = [];
  12303. fromPoints(points, min, max);
  12304. var boundingRect = new BoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  12305. var width = boundingRect.width;
  12306. var height = boundingRect.height;
  12307. var x = boundingRect.x;
  12308. var y = boundingRect.y;
  12309. var pt0 = new Point();
  12310. var pt1 = new Point();
  12311. if (width > height) {
  12312. pt0.x = pt1.x = x + width / 2;
  12313. pt0.y = y;
  12314. pt1.y = y + height;
  12315. }
  12316. else {
  12317. pt0.y = pt1.y = y + height / 2;
  12318. pt0.x = x;
  12319. pt1.x = x + width;
  12320. }
  12321. return splitPolygonByLine(points, pt0, pt1);
  12322. }
  12323. function binaryDivideRecursive(divider, shape, count, out) {
  12324. if (count === 1) {
  12325. out.push(shape);
  12326. }
  12327. else {
  12328. var mid = Math.floor(count / 2);
  12329. var sub = divider(shape);
  12330. binaryDivideRecursive(divider, sub[0], mid, out);
  12331. binaryDivideRecursive(divider, sub[1], count - mid, out);
  12332. }
  12333. return out;
  12334. }
  12335. function clone$3(path, count) {
  12336. var paths = [];
  12337. for (var i = 0; i < count; i++) {
  12338. paths.push(clonePath(path));
  12339. }
  12340. return paths;
  12341. }
  12342. function copyPathProps(source, target) {
  12343. target.setStyle(source.style);
  12344. target.z = source.z;
  12345. target.z2 = source.z2;
  12346. target.zlevel = source.zlevel;
  12347. }
  12348. function polygonConvert(points) {
  12349. var out = [];
  12350. for (var i = 0; i < points.length;) {
  12351. out.push([points[i++], points[i++]]);
  12352. }
  12353. return out;
  12354. }
  12355. function split(path, count) {
  12356. var outShapes = [];
  12357. var shape = path.shape;
  12358. var OutShapeCtor;
  12359. switch (path.type) {
  12360. case 'rect':
  12361. divideRect(shape, count, outShapes);
  12362. OutShapeCtor = Rect;
  12363. break;
  12364. case 'sector':
  12365. divideSector(shape, count, outShapes);
  12366. OutShapeCtor = Sector;
  12367. break;
  12368. case 'circle':
  12369. divideSector({
  12370. r0: 0, r: shape.r, startAngle: 0, endAngle: Math.PI * 2,
  12371. cx: shape.cx, cy: shape.cy
  12372. }, count, outShapes);
  12373. OutShapeCtor = Sector;
  12374. break;
  12375. default:
  12376. var m = path.getComputedTransform();
  12377. var scale = m ? Math.sqrt(Math.max(m[0] * m[0] + m[1] * m[1], m[2] * m[2] + m[3] * m[3])) : 1;
  12378. var polygons = map(pathToPolygons(path.getUpdatedPathProxy(), scale), function (poly) { return polygonConvert(poly); });
  12379. var polygonCount = polygons.length;
  12380. if (polygonCount === 0) {
  12381. binaryDivideRecursive(binaryDividePolygon, {
  12382. points: polygons[0]
  12383. }, count, outShapes);
  12384. }
  12385. else if (polygonCount === count) {
  12386. for (var i = 0; i < polygonCount; i++) {
  12387. outShapes.push({
  12388. points: polygons[i]
  12389. });
  12390. }
  12391. }
  12392. else {
  12393. var totalArea_1 = 0;
  12394. var items = map(polygons, function (poly) {
  12395. var min = [];
  12396. var max = [];
  12397. fromPoints(poly, min, max);
  12398. var area = (max[1] - min[1]) * (max[0] - min[0]);
  12399. totalArea_1 += area;
  12400. return { poly: poly, area: area };
  12401. });
  12402. items.sort(function (a, b) { return b.area - a.area; });
  12403. var left = count;
  12404. for (var i = 0; i < polygonCount; i++) {
  12405. var item = items[i];
  12406. if (left <= 0) {
  12407. break;
  12408. }
  12409. var selfCount = i === polygonCount - 1
  12410. ? left
  12411. : Math.ceil(item.area / totalArea_1 * count);
  12412. if (selfCount < 0) {
  12413. continue;
  12414. }
  12415. binaryDivideRecursive(binaryDividePolygon, {
  12416. points: item.poly
  12417. }, selfCount, outShapes);
  12418. left -= selfCount;
  12419. }
  12420. }
  12421. OutShapeCtor = Polygon;
  12422. break;
  12423. }
  12424. if (!OutShapeCtor) {
  12425. return clone$3(path, count);
  12426. }
  12427. var out = [];
  12428. for (var i = 0; i < outShapes.length; i++) {
  12429. var subPath = new OutShapeCtor();
  12430. subPath.setShape(outShapes[i]);
  12431. copyPathProps(path, subPath);
  12432. out.push(subPath);
  12433. }
  12434. return out;
  12435. }
  12436. function alignSubpath(subpath1, subpath2) {
  12437. var len1 = subpath1.length;
  12438. var len2 = subpath2.length;
  12439. if (len1 === len2) {
  12440. return [subpath1, subpath2];
  12441. }
  12442. var tmpSegX = [];
  12443. var tmpSegY = [];
  12444. var shorterPath = len1 < len2 ? subpath1 : subpath2;
  12445. var shorterLen = Math.min(len1, len2);
  12446. var diff = Math.abs(len2 - len1) / 6;
  12447. var shorterBezierCount = (shorterLen - 2) / 6;
  12448. var eachCurveSubDivCount = Math.ceil(diff / shorterBezierCount) + 1;
  12449. var newSubpath = [shorterPath[0], shorterPath[1]];
  12450. var remained = diff;
  12451. for (var i = 2; i < shorterLen;) {
  12452. var x0 = shorterPath[i - 2];
  12453. var y0 = shorterPath[i - 1];
  12454. var x1 = shorterPath[i++];
  12455. var y1 = shorterPath[i++];
  12456. var x2 = shorterPath[i++];
  12457. var y2 = shorterPath[i++];
  12458. var x3 = shorterPath[i++];
  12459. var y3 = shorterPath[i++];
  12460. if (remained <= 0) {
  12461. newSubpath.push(x1, y1, x2, y2, x3, y3);
  12462. continue;
  12463. }
  12464. var actualSubDivCount = Math.min(remained, eachCurveSubDivCount - 1) + 1;
  12465. for (var k = 1; k <= actualSubDivCount; k++) {
  12466. var p = k / actualSubDivCount;
  12467. cubicSubdivide(x0, x1, x2, x3, p, tmpSegX);
  12468. cubicSubdivide(y0, y1, y2, y3, p, tmpSegY);
  12469. x0 = tmpSegX[3];
  12470. y0 = tmpSegY[3];
  12471. newSubpath.push(tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], x0, y0);
  12472. x1 = tmpSegX[5];
  12473. y1 = tmpSegY[5];
  12474. x2 = tmpSegX[6];
  12475. y2 = tmpSegY[6];
  12476. }
  12477. remained -= actualSubDivCount - 1;
  12478. }
  12479. return shorterPath === subpath1 ? [newSubpath, subpath2] : [subpath1, newSubpath];
  12480. }
  12481. function createSubpath(lastSubpathSubpath, otherSubpath) {
  12482. var len = lastSubpathSubpath.length;
  12483. var lastX = lastSubpathSubpath[len - 2];
  12484. var lastY = lastSubpathSubpath[len - 1];
  12485. var newSubpath = [];
  12486. for (var i = 0; i < otherSubpath.length;) {
  12487. newSubpath[i++] = lastX;
  12488. newSubpath[i++] = lastY;
  12489. }
  12490. return newSubpath;
  12491. }
  12492. function alignBezierCurves(array1, array2) {
  12493. var _a;
  12494. var lastSubpath1;
  12495. var lastSubpath2;
  12496. var newArray1 = [];
  12497. var newArray2 = [];
  12498. for (var i = 0; i < Math.max(array1.length, array2.length); i++) {
  12499. var subpath1 = array1[i];
  12500. var subpath2 = array2[i];
  12501. var newSubpath1 = void 0;
  12502. var newSubpath2 = void 0;
  12503. if (!subpath1) {
  12504. newSubpath1 = createSubpath(lastSubpath1 || subpath2, subpath2);
  12505. newSubpath2 = subpath2;
  12506. }
  12507. else if (!subpath2) {
  12508. newSubpath2 = createSubpath(lastSubpath2 || subpath1, subpath1);
  12509. newSubpath1 = subpath1;
  12510. }
  12511. else {
  12512. _a = alignSubpath(subpath1, subpath2), newSubpath1 = _a[0], newSubpath2 = _a[1];
  12513. lastSubpath1 = newSubpath1;
  12514. lastSubpath2 = newSubpath2;
  12515. }
  12516. newArray1.push(newSubpath1);
  12517. newArray2.push(newSubpath2);
  12518. }
  12519. return [newArray1, newArray2];
  12520. }
  12521. function centroid(array) {
  12522. var signedArea = 0;
  12523. var cx = 0;
  12524. var cy = 0;
  12525. var len = array.length;
  12526. for (var i = 0, j = len - 2; i < len; j = i, i += 2) {
  12527. var x0 = array[j];
  12528. var y0 = array[j + 1];
  12529. var x1 = array[i];
  12530. var y1 = array[i + 1];
  12531. var a = x0 * y1 - x1 * y0;
  12532. signedArea += a;
  12533. cx += (x0 + x1) * a;
  12534. cy += (y0 + y1) * a;
  12535. }
  12536. if (signedArea === 0) {
  12537. return [array[0] || 0, array[1] || 0];
  12538. }
  12539. return [cx / signedArea / 3, cy / signedArea / 3, signedArea];
  12540. }
  12541. function findBestRingOffset(fromSubBeziers, toSubBeziers, fromCp, toCp) {
  12542. var bezierCount = (fromSubBeziers.length - 2) / 6;
  12543. var bestScore = Infinity;
  12544. var bestOffset = 0;
  12545. var len = fromSubBeziers.length;
  12546. var len2 = len - 2;
  12547. for (var offset = 0; offset < bezierCount; offset++) {
  12548. var cursorOffset = offset * 6;
  12549. var score = 0;
  12550. for (var k = 0; k < len; k += 2) {
  12551. var idx = k === 0 ? cursorOffset : ((cursorOffset + k - 2) % len2 + 2);
  12552. var x0 = fromSubBeziers[idx] - fromCp[0];
  12553. var y0 = fromSubBeziers[idx + 1] - fromCp[1];
  12554. var x1 = toSubBeziers[k] - toCp[0];
  12555. var y1 = toSubBeziers[k + 1] - toCp[1];
  12556. var dx = x1 - x0;
  12557. var dy = y1 - y0;
  12558. score += dx * dx + dy * dy;
  12559. }
  12560. if (score < bestScore) {
  12561. bestScore = score;
  12562. bestOffset = offset;
  12563. }
  12564. }
  12565. return bestOffset;
  12566. }
  12567. function reverse(array) {
  12568. var newArr = [];
  12569. var len = array.length;
  12570. for (var i = 0; i < len; i += 2) {
  12571. newArr[i] = array[len - i - 2];
  12572. newArr[i + 1] = array[len - i - 1];
  12573. }
  12574. return newArr;
  12575. }
  12576. function findBestMorphingRotation(fromArr, toArr, searchAngleIteration, searchAngleRange) {
  12577. var result = [];
  12578. var fromNeedsReverse;
  12579. for (var i = 0; i < fromArr.length; i++) {
  12580. var fromSubpathBezier = fromArr[i];
  12581. var toSubpathBezier = toArr[i];
  12582. var fromCp = centroid(fromSubpathBezier);
  12583. var toCp = centroid(toSubpathBezier);
  12584. if (fromNeedsReverse == null) {
  12585. fromNeedsReverse = fromCp[2] < 0 !== toCp[2] < 0;
  12586. }
  12587. var newFromSubpathBezier = [];
  12588. var newToSubpathBezier = [];
  12589. var bestAngle = 0;
  12590. var bestScore = Infinity;
  12591. var tmpArr = [];
  12592. var len = fromSubpathBezier.length;
  12593. if (fromNeedsReverse) {
  12594. fromSubpathBezier = reverse(fromSubpathBezier);
  12595. }
  12596. var offset = findBestRingOffset(fromSubpathBezier, toSubpathBezier, fromCp, toCp) * 6;
  12597. var len2 = len - 2;
  12598. for (var k = 0; k < len2; k += 2) {
  12599. var idx = (offset + k) % len2 + 2;
  12600. newFromSubpathBezier[k + 2] = fromSubpathBezier[idx] - fromCp[0];
  12601. newFromSubpathBezier[k + 3] = fromSubpathBezier[idx + 1] - fromCp[1];
  12602. }
  12603. newFromSubpathBezier[0] = fromSubpathBezier[offset] - fromCp[0];
  12604. newFromSubpathBezier[1] = fromSubpathBezier[offset + 1] - fromCp[1];
  12605. if (searchAngleIteration > 0) {
  12606. var step = searchAngleRange / searchAngleIteration;
  12607. for (var angle = -searchAngleRange / 2; angle <= searchAngleRange / 2; angle += step) {
  12608. var sa = Math.sin(angle);
  12609. var ca = Math.cos(angle);
  12610. var score = 0;
  12611. for (var k = 0; k < fromSubpathBezier.length; k += 2) {
  12612. var x0 = newFromSubpathBezier[k];
  12613. var y0 = newFromSubpathBezier[k + 1];
  12614. var x1 = toSubpathBezier[k] - toCp[0];
  12615. var y1 = toSubpathBezier[k + 1] - toCp[1];
  12616. var newX1 = x1 * ca - y1 * sa;
  12617. var newY1 = x1 * sa + y1 * ca;
  12618. tmpArr[k] = newX1;
  12619. tmpArr[k + 1] = newY1;
  12620. var dx = newX1 - x0;
  12621. var dy = newY1 - y0;
  12622. score += dx * dx + dy * dy;
  12623. }
  12624. if (score < bestScore) {
  12625. bestScore = score;
  12626. bestAngle = angle;
  12627. for (var m = 0; m < tmpArr.length; m++) {
  12628. newToSubpathBezier[m] = tmpArr[m];
  12629. }
  12630. }
  12631. }
  12632. }
  12633. else {
  12634. for (var i_1 = 0; i_1 < len; i_1 += 2) {
  12635. newToSubpathBezier[i_1] = toSubpathBezier[i_1] - toCp[0];
  12636. newToSubpathBezier[i_1 + 1] = toSubpathBezier[i_1 + 1] - toCp[1];
  12637. }
  12638. }
  12639. result.push({
  12640. from: newFromSubpathBezier,
  12641. to: newToSubpathBezier,
  12642. fromCp: fromCp,
  12643. toCp: toCp,
  12644. rotation: -bestAngle
  12645. });
  12646. }
  12647. return result;
  12648. }
  12649. function isCombineMorphing(path) {
  12650. return path.__isCombineMorphing;
  12651. }
  12652. function isMorphing(el) {
  12653. return el.__morphT >= 0;
  12654. }
  12655. var SAVED_METHOD_PREFIX = '__mOriginal_';
  12656. function saveAndModifyMethod(obj, methodName, modifiers) {
  12657. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  12658. var originalMethod = obj[savedMethodName] || obj[methodName];
  12659. if (!obj[savedMethodName]) {
  12660. obj[savedMethodName] = obj[methodName];
  12661. }
  12662. var replace = modifiers.replace;
  12663. var after = modifiers.after;
  12664. var before = modifiers.before;
  12665. obj[methodName] = function () {
  12666. var args = arguments;
  12667. var res;
  12668. before && before.apply(this, args);
  12669. if (replace) {
  12670. res = replace.apply(this, args);
  12671. }
  12672. else {
  12673. res = originalMethod.apply(this, args);
  12674. }
  12675. after && after.apply(this, args);
  12676. return res;
  12677. };
  12678. }
  12679. function restoreMethod(obj, methodName) {
  12680. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  12681. if (obj[savedMethodName]) {
  12682. obj[methodName] = obj[savedMethodName];
  12683. obj[savedMethodName] = null;
  12684. }
  12685. }
  12686. function applyTransformOnBeziers(bezierCurves, mm) {
  12687. for (var i = 0; i < bezierCurves.length; i++) {
  12688. var subBeziers = bezierCurves[i];
  12689. for (var k = 0; k < subBeziers.length;) {
  12690. var x = subBeziers[k];
  12691. var y = subBeziers[k + 1];
  12692. subBeziers[k++] = mm[0] * x + mm[2] * y + mm[4];
  12693. subBeziers[k++] = mm[1] * x + mm[3] * y + mm[5];
  12694. }
  12695. }
  12696. }
  12697. function prepareMorphPath(fromPath, toPath) {
  12698. var fromPathProxy = fromPath.getUpdatedPathProxy();
  12699. var toPathProxy = toPath.getUpdatedPathProxy();
  12700. var _a = alignBezierCurves(pathToBezierCurves(fromPathProxy), pathToBezierCurves(toPathProxy)), fromBezierCurves = _a[0], toBezierCurves = _a[1];
  12701. var fromPathTransform = fromPath.getComputedTransform();
  12702. var toPathTransform = toPath.getComputedTransform();
  12703. function updateIdentityTransform() {
  12704. this.transform = null;
  12705. }
  12706. fromPathTransform && applyTransformOnBeziers(fromBezierCurves, fromPathTransform);
  12707. toPathTransform && applyTransformOnBeziers(toBezierCurves, toPathTransform);
  12708. saveAndModifyMethod(toPath, 'updateTransform', { replace: updateIdentityTransform });
  12709. toPath.transform = null;
  12710. var morphingData = findBestMorphingRotation(fromBezierCurves, toBezierCurves, 10, Math.PI);
  12711. var tmpArr = [];
  12712. saveAndModifyMethod(toPath, 'buildPath', { replace: function (path) {
  12713. var t = toPath.__morphT;
  12714. var onet = 1 - t;
  12715. var newCp = [];
  12716. for (var i = 0; i < morphingData.length; i++) {
  12717. var item = morphingData[i];
  12718. var from = item.from;
  12719. var to = item.to;
  12720. var angle = item.rotation * t;
  12721. var fromCp = item.fromCp;
  12722. var toCp = item.toCp;
  12723. var sa = Math.sin(angle);
  12724. var ca = Math.cos(angle);
  12725. lerp(newCp, fromCp, toCp, t);
  12726. for (var m = 0; m < from.length; m += 2) {
  12727. var x0_1 = from[m];
  12728. var y0_1 = from[m + 1];
  12729. var x1 = to[m];
  12730. var y1 = to[m + 1];
  12731. var x = x0_1 * onet + x1 * t;
  12732. var y = y0_1 * onet + y1 * t;
  12733. tmpArr[m] = (x * ca - y * sa) + newCp[0];
  12734. tmpArr[m + 1] = (x * sa + y * ca) + newCp[1];
  12735. }
  12736. var x0 = tmpArr[0];
  12737. var y0 = tmpArr[1];
  12738. path.moveTo(x0, y0);
  12739. for (var m = 2; m < from.length;) {
  12740. var x1 = tmpArr[m++];
  12741. var y1 = tmpArr[m++];
  12742. var x2 = tmpArr[m++];
  12743. var y2 = tmpArr[m++];
  12744. var x3 = tmpArr[m++];
  12745. var y3 = tmpArr[m++];
  12746. if (x0 === x1 && y0 === y1 && x2 === x3 && y2 === y3) {
  12747. path.lineTo(x3, y3);
  12748. }
  12749. else {
  12750. path.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  12751. }
  12752. x0 = x3;
  12753. y0 = y3;
  12754. }
  12755. }
  12756. } });
  12757. }
  12758. function morphPath(fromPath, toPath, animationOpts) {
  12759. if (!fromPath || !toPath) {
  12760. return toPath;
  12761. }
  12762. var oldDone = animationOpts.done;
  12763. var oldDuring = animationOpts.during;
  12764. prepareMorphPath(fromPath, toPath);
  12765. toPath.__morphT = 0;
  12766. function restoreToPath() {
  12767. restoreMethod(toPath, 'buildPath');
  12768. restoreMethod(toPath, 'updateTransform');
  12769. toPath.__morphT = -1;
  12770. toPath.createPathProxy();
  12771. toPath.dirtyShape();
  12772. }
  12773. toPath.animateTo({
  12774. __morphT: 1
  12775. }, defaults({
  12776. during: function (p) {
  12777. toPath.dirtyShape();
  12778. oldDuring && oldDuring(p);
  12779. },
  12780. done: function () {
  12781. restoreToPath();
  12782. oldDone && oldDone();
  12783. }
  12784. }, animationOpts));
  12785. return toPath;
  12786. }
  12787. function hilbert(x, y, minX, minY, maxX, maxY) {
  12788. var bits = 16;
  12789. x = (maxX === minX) ? 0 : Math.round(32767 * (x - minX) / (maxX - minX));
  12790. y = (maxY === minY) ? 0 : Math.round(32767 * (y - minY) / (maxY - minY));
  12791. var d = 0;
  12792. var tmp;
  12793. for (var s = (1 << bits) / 2; s > 0; s /= 2) {
  12794. var rx = 0;
  12795. var ry = 0;
  12796. if ((x & s) > 0) {
  12797. rx = 1;
  12798. }
  12799. if ((y & s) > 0) {
  12800. ry = 1;
  12801. }
  12802. d += s * s * ((3 * rx) ^ ry);
  12803. if (ry === 0) {
  12804. if (rx === 1) {
  12805. x = s - 1 - x;
  12806. y = s - 1 - y;
  12807. }
  12808. tmp = x;
  12809. x = y;
  12810. y = tmp;
  12811. }
  12812. }
  12813. return d;
  12814. }
  12815. function sortPaths(pathList) {
  12816. var xMin = Infinity;
  12817. var yMin = Infinity;
  12818. var xMax = -Infinity;
  12819. var yMax = -Infinity;
  12820. var cps = map(pathList, function (path) {
  12821. var rect = path.getBoundingRect();
  12822. var m = path.getComputedTransform();
  12823. var x = rect.x + rect.width / 2 + (m ? m[4] : 0);
  12824. var y = rect.y + rect.height / 2 + (m ? m[5] : 0);
  12825. xMin = Math.min(x, xMin);
  12826. yMin = Math.min(y, yMin);
  12827. xMax = Math.max(x, xMax);
  12828. yMax = Math.max(y, yMax);
  12829. return [x, y];
  12830. });
  12831. var items = map(cps, function (cp, idx) {
  12832. return {
  12833. cp: cp,
  12834. z: hilbert(cp[0], cp[1], xMin, yMin, xMax, yMax),
  12835. path: pathList[idx]
  12836. };
  12837. });
  12838. return items.sort(function (a, b) { return a.z - b.z; }).map(function (item) { return item.path; });
  12839. }
  12840. function defaultDividePath(param) {
  12841. return split(param.path, param.count);
  12842. }
  12843. function createEmptyReturn() {
  12844. return {
  12845. fromIndividuals: [],
  12846. toIndividuals: [],
  12847. count: 0
  12848. };
  12849. }
  12850. function combineMorph(fromList, toPath, animationOpts) {
  12851. var fromPathList = [];
  12852. function addFromPath(fromList) {
  12853. for (var i = 0; i < fromList.length; i++) {
  12854. var from = fromList[i];
  12855. if (isCombineMorphing(from)) {
  12856. addFromPath(from.childrenRef());
  12857. }
  12858. else if (from instanceof Path) {
  12859. fromPathList.push(from);
  12860. }
  12861. }
  12862. }
  12863. addFromPath(fromList);
  12864. var separateCount = fromPathList.length;
  12865. if (!separateCount) {
  12866. return createEmptyReturn();
  12867. }
  12868. var dividePath = animationOpts.dividePath || defaultDividePath;
  12869. var toSubPathList = dividePath({
  12870. path: toPath, count: separateCount
  12871. });
  12872. if (toSubPathList.length !== separateCount) {
  12873. console.error('Invalid morphing: unmatched splitted path');
  12874. return createEmptyReturn();
  12875. }
  12876. fromPathList = sortPaths(fromPathList);
  12877. toSubPathList = sortPaths(toSubPathList);
  12878. var oldDone = animationOpts.done;
  12879. var oldDuring = animationOpts.during;
  12880. var individualDelay = animationOpts.individualDelay;
  12881. var identityTransform = new Transformable();
  12882. for (var i = 0; i < separateCount; i++) {
  12883. var from = fromPathList[i];
  12884. var to = toSubPathList[i];
  12885. to.parent = toPath;
  12886. to.copyTransform(identityTransform);
  12887. if (!individualDelay) {
  12888. prepareMorphPath(from, to);
  12889. }
  12890. }
  12891. toPath.__isCombineMorphing = true;
  12892. toPath.childrenRef = function () {
  12893. return toSubPathList;
  12894. };
  12895. function addToSubPathListToZr(zr) {
  12896. for (var i = 0; i < toSubPathList.length; i++) {
  12897. toSubPathList[i].addSelfToZr(zr);
  12898. }
  12899. }
  12900. saveAndModifyMethod(toPath, 'addSelfToZr', {
  12901. after: function (zr) {
  12902. addToSubPathListToZr(zr);
  12903. }
  12904. });
  12905. saveAndModifyMethod(toPath, 'removeSelfFromZr', {
  12906. after: function (zr) {
  12907. for (var i = 0; i < toSubPathList.length; i++) {
  12908. toSubPathList[i].removeSelfFromZr(zr);
  12909. }
  12910. }
  12911. });
  12912. function restoreToPath() {
  12913. toPath.__isCombineMorphing = false;
  12914. toPath.__morphT = -1;
  12915. toPath.childrenRef = null;
  12916. restoreMethod(toPath, 'addSelfToZr');
  12917. restoreMethod(toPath, 'removeSelfFromZr');
  12918. }
  12919. var toLen = toSubPathList.length;
  12920. if (individualDelay) {
  12921. var animating_1 = toLen;
  12922. var eachDone = function () {
  12923. animating_1--;
  12924. if (animating_1 === 0) {
  12925. restoreToPath();
  12926. oldDone && oldDone();
  12927. }
  12928. };
  12929. for (var i = 0; i < toLen; i++) {
  12930. var indivdualAnimationOpts = individualDelay ? defaults({
  12931. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toSubPathList[i]),
  12932. done: eachDone
  12933. }, animationOpts) : animationOpts;
  12934. morphPath(fromPathList[i], toSubPathList[i], indivdualAnimationOpts);
  12935. }
  12936. }
  12937. else {
  12938. toPath.__morphT = 0;
  12939. toPath.animateTo({
  12940. __morphT: 1
  12941. }, defaults({
  12942. during: function (p) {
  12943. for (var i = 0; i < toLen; i++) {
  12944. var child = toSubPathList[i];
  12945. child.__morphT = toPath.__morphT;
  12946. child.dirtyShape();
  12947. }
  12948. oldDuring && oldDuring(p);
  12949. },
  12950. done: function () {
  12951. restoreToPath();
  12952. for (var i = 0; i < fromList.length; i++) {
  12953. restoreMethod(fromList[i], 'updateTransform');
  12954. }
  12955. oldDone && oldDone();
  12956. }
  12957. }, animationOpts));
  12958. }
  12959. if (toPath.__zr) {
  12960. addToSubPathListToZr(toPath.__zr);
  12961. }
  12962. return {
  12963. fromIndividuals: fromPathList,
  12964. toIndividuals: toSubPathList,
  12965. count: toLen
  12966. };
  12967. }
  12968. function separateMorph(fromPath, toPathList, animationOpts) {
  12969. var toLen = toPathList.length;
  12970. var fromPathList = [];
  12971. var dividePath = animationOpts.dividePath || defaultDividePath;
  12972. function addFromPath(fromList) {
  12973. for (var i = 0; i < fromList.length; i++) {
  12974. var from = fromList[i];
  12975. if (isCombineMorphing(from)) {
  12976. addFromPath(from.childrenRef());
  12977. }
  12978. else if (from instanceof Path) {
  12979. fromPathList.push(from);
  12980. }
  12981. }
  12982. }
  12983. if (isCombineMorphing(fromPath)) {
  12984. addFromPath(fromPath.childrenRef());
  12985. var fromLen = fromPathList.length;
  12986. if (fromLen < toLen) {
  12987. var k = 0;
  12988. for (var i = fromLen; i < toLen; i++) {
  12989. fromPathList.push(clonePath(fromPathList[k++ % fromLen]));
  12990. }
  12991. }
  12992. fromPathList.length = toLen;
  12993. }
  12994. else {
  12995. fromPathList = dividePath({ path: fromPath, count: toLen });
  12996. var fromPathTransform = fromPath.getComputedTransform();
  12997. for (var i = 0; i < fromPathList.length; i++) {
  12998. fromPathList[i].setLocalTransform(fromPathTransform);
  12999. }
  13000. if (fromPathList.length !== toLen) {
  13001. console.error('Invalid morphing: unmatched splitted path');
  13002. return createEmptyReturn();
  13003. }
  13004. }
  13005. fromPathList = sortPaths(fromPathList);
  13006. toPathList = sortPaths(toPathList);
  13007. var individualDelay = animationOpts.individualDelay;
  13008. for (var i = 0; i < toLen; i++) {
  13009. var indivdualAnimationOpts = individualDelay ? defaults({
  13010. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toPathList[i])
  13011. }, animationOpts) : animationOpts;
  13012. morphPath(fromPathList[i], toPathList[i], indivdualAnimationOpts);
  13013. }
  13014. return {
  13015. fromIndividuals: fromPathList,
  13016. toIndividuals: toPathList,
  13017. count: toPathList.length
  13018. };
  13019. }
  13020. var morphPath$1 = /*#__PURE__*/Object.freeze({
  13021. __proto__: null,
  13022. alignBezierCurves: alignBezierCurves,
  13023. centroid: centroid,
  13024. isCombineMorphing: isCombineMorphing,
  13025. isMorphing: isMorphing,
  13026. morphPath: morphPath,
  13027. combineMorph: combineMorph,
  13028. separateMorph: separateMorph,
  13029. defaultDividePath: split
  13030. });
  13031. var CompoundPath = (function (_super) {
  13032. __extends(CompoundPath, _super);
  13033. function CompoundPath() {
  13034. var _this = _super !== null && _super.apply(this, arguments) || this;
  13035. _this.type = 'compound';
  13036. return _this;
  13037. }
  13038. CompoundPath.prototype._updatePathDirty = function () {
  13039. var paths = this.shape.paths;
  13040. var dirtyPath = this.shapeChanged();
  13041. for (var i = 0; i < paths.length; i++) {
  13042. dirtyPath = dirtyPath || paths[i].shapeChanged();
  13043. }
  13044. if (dirtyPath) {
  13045. this.dirtyShape();
  13046. }
  13047. };
  13048. CompoundPath.prototype.beforeBrush = function () {
  13049. this._updatePathDirty();
  13050. var paths = this.shape.paths || [];
  13051. var scale = this.getGlobalScale();
  13052. for (var i = 0; i < paths.length; i++) {
  13053. if (!paths[i].path) {
  13054. paths[i].createPathProxy();
  13055. }
  13056. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  13057. }
  13058. };
  13059. CompoundPath.prototype.buildPath = function (ctx, shape) {
  13060. var paths = shape.paths || [];
  13061. for (var i = 0; i < paths.length; i++) {
  13062. paths[i].buildPath(ctx, paths[i].shape, true);
  13063. }
  13064. };
  13065. CompoundPath.prototype.afterBrush = function () {
  13066. var paths = this.shape.paths || [];
  13067. for (var i = 0; i < paths.length; i++) {
  13068. paths[i].pathUpdated();
  13069. }
  13070. };
  13071. CompoundPath.prototype.getBoundingRect = function () {
  13072. this._updatePathDirty.call(this);
  13073. return Path.prototype.getBoundingRect.call(this);
  13074. };
  13075. return CompoundPath;
  13076. }(Path));
  13077. var m = [];
  13078. var IncrementalDisplayable = (function (_super) {
  13079. __extends(IncrementalDisplayable, _super);
  13080. function IncrementalDisplayable() {
  13081. var _this = _super !== null && _super.apply(this, arguments) || this;
  13082. _this.notClear = true;
  13083. _this.incremental = true;
  13084. _this._displayables = [];
  13085. _this._temporaryDisplayables = [];
  13086. _this._cursor = 0;
  13087. return _this;
  13088. }
  13089. IncrementalDisplayable.prototype.traverse = function (cb, context) {
  13090. cb.call(context, this);
  13091. };
  13092. IncrementalDisplayable.prototype.useStyle = function () {
  13093. this.style = {};
  13094. };
  13095. IncrementalDisplayable.prototype.getCursor = function () {
  13096. return this._cursor;
  13097. };
  13098. IncrementalDisplayable.prototype.innerAfterBrush = function () {
  13099. this._cursor = this._displayables.length;
  13100. };
  13101. IncrementalDisplayable.prototype.clearDisplaybles = function () {
  13102. this._displayables = [];
  13103. this._temporaryDisplayables = [];
  13104. this._cursor = 0;
  13105. this.markRedraw();
  13106. this.notClear = false;
  13107. };
  13108. IncrementalDisplayable.prototype.clearTemporalDisplayables = function () {
  13109. this._temporaryDisplayables = [];
  13110. };
  13111. IncrementalDisplayable.prototype.addDisplayable = function (displayable, notPersistent) {
  13112. if (notPersistent) {
  13113. this._temporaryDisplayables.push(displayable);
  13114. }
  13115. else {
  13116. this._displayables.push(displayable);
  13117. }
  13118. this.markRedraw();
  13119. };
  13120. IncrementalDisplayable.prototype.addDisplayables = function (displayables, notPersistent) {
  13121. notPersistent = notPersistent || false;
  13122. for (var i = 0; i < displayables.length; i++) {
  13123. this.addDisplayable(displayables[i], notPersistent);
  13124. }
  13125. };
  13126. IncrementalDisplayable.prototype.getDisplayables = function () {
  13127. return this._displayables;
  13128. };
  13129. IncrementalDisplayable.prototype.getTemporalDisplayables = function () {
  13130. return this._temporaryDisplayables;
  13131. };
  13132. IncrementalDisplayable.prototype.eachPendingDisplayable = function (cb) {
  13133. for (var i = this._cursor; i < this._displayables.length; i++) {
  13134. cb && cb(this._displayables[i]);
  13135. }
  13136. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  13137. cb && cb(this._temporaryDisplayables[i]);
  13138. }
  13139. };
  13140. IncrementalDisplayable.prototype.update = function () {
  13141. this.updateTransform();
  13142. for (var i = this._cursor; i < this._displayables.length; i++) {
  13143. var displayable = this._displayables[i];
  13144. displayable.parent = this;
  13145. displayable.update();
  13146. displayable.parent = null;
  13147. }
  13148. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  13149. var displayable = this._temporaryDisplayables[i];
  13150. displayable.parent = this;
  13151. displayable.update();
  13152. displayable.parent = null;
  13153. }
  13154. };
  13155. IncrementalDisplayable.prototype.getBoundingRect = function () {
  13156. if (!this._rect) {
  13157. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  13158. for (var i = 0; i < this._displayables.length; i++) {
  13159. var displayable = this._displayables[i];
  13160. var childRect = displayable.getBoundingRect().clone();
  13161. if (displayable.needLocalTransform()) {
  13162. childRect.applyTransform(displayable.getLocalTransform(m));
  13163. }
  13164. rect.union(childRect);
  13165. }
  13166. this._rect = rect;
  13167. }
  13168. return this._rect;
  13169. };
  13170. IncrementalDisplayable.prototype.contain = function (x, y) {
  13171. var localPos = this.transformCoordToLocal(x, y);
  13172. var rect = this.getBoundingRect();
  13173. if (rect.contain(localPos[0], localPos[1])) {
  13174. for (var i = 0; i < this._displayables.length; i++) {
  13175. var displayable = this._displayables[i];
  13176. if (displayable.contain(x, y)) {
  13177. return true;
  13178. }
  13179. }
  13180. }
  13181. return false;
  13182. };
  13183. return IncrementalDisplayable;
  13184. }(Displayable));
  13185. var DEFAULT_RICH_TEXT_COLOR = {
  13186. fill: '#000'
  13187. };
  13188. var DEFAULT_STROKE_LINE_WIDTH = 2;
  13189. var tmpCITOverflowAreaOut = {};
  13190. var DEFAULT_TEXT_ANIMATION_PROPS = {
  13191. style: defaults({
  13192. fill: true,
  13193. stroke: true,
  13194. fillOpacity: true,
  13195. strokeOpacity: true,
  13196. lineWidth: true,
  13197. fontSize: true,
  13198. lineHeight: true,
  13199. width: true,
  13200. height: true,
  13201. textShadowColor: true,
  13202. textShadowBlur: true,
  13203. textShadowOffsetX: true,
  13204. textShadowOffsetY: true,
  13205. backgroundColor: true,
  13206. padding: true,
  13207. borderColor: true,
  13208. borderWidth: true,
  13209. borderRadius: true
  13210. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  13211. };
  13212. var ZRText = (function (_super) {
  13213. __extends(ZRText, _super);
  13214. function ZRText(opts) {
  13215. var _this = _super.call(this) || this;
  13216. _this.type = 'text';
  13217. _this._children = [];
  13218. _this._defaultStyle = DEFAULT_RICH_TEXT_COLOR;
  13219. _this.attr(opts);
  13220. return _this;
  13221. }
  13222. ZRText.prototype.childrenRef = function () {
  13223. return this._children;
  13224. };
  13225. ZRText.prototype.update = function () {
  13226. _super.prototype.update.call(this);
  13227. if (this.styleChanged()) {
  13228. this._updateSubTexts();
  13229. }
  13230. for (var i = 0; i < this._children.length; i++) {
  13231. var child = this._children[i];
  13232. child.zlevel = this.zlevel;
  13233. child.z = this.z;
  13234. child.z2 = this.z2;
  13235. child.culling = this.culling;
  13236. child.cursor = this.cursor;
  13237. child.invisible = this.invisible;
  13238. }
  13239. };
  13240. ZRText.prototype.updateTransform = function () {
  13241. var innerTransformable = this.innerTransformable;
  13242. if (innerTransformable) {
  13243. innerTransformable.updateTransform();
  13244. if (innerTransformable.transform) {
  13245. this.transform = innerTransformable.transform;
  13246. }
  13247. }
  13248. else {
  13249. _super.prototype.updateTransform.call(this);
  13250. }
  13251. };
  13252. ZRText.prototype.getLocalTransform = function (m) {
  13253. var innerTransformable = this.innerTransformable;
  13254. return innerTransformable
  13255. ? innerTransformable.getLocalTransform(m)
  13256. : _super.prototype.getLocalTransform.call(this, m);
  13257. };
  13258. ZRText.prototype.getComputedTransform = function () {
  13259. if (this.__hostTarget) {
  13260. this.__hostTarget.getComputedTransform();
  13261. this.__hostTarget.updateInnerText(true);
  13262. }
  13263. return _super.prototype.getComputedTransform.call(this);
  13264. };
  13265. ZRText.prototype._updateSubTexts = function () {
  13266. this._childCursor = 0;
  13267. normalizeTextStyle(this.style);
  13268. this.style.rich
  13269. ? this._updateRichTexts()
  13270. : this._updatePlainTexts();
  13271. this._children.length = this._childCursor;
  13272. this.styleUpdated();
  13273. };
  13274. ZRText.prototype.addSelfToZr = function (zr) {
  13275. _super.prototype.addSelfToZr.call(this, zr);
  13276. for (var i = 0; i < this._children.length; i++) {
  13277. this._children[i].__zr = zr;
  13278. }
  13279. };
  13280. ZRText.prototype.removeSelfFromZr = function (zr) {
  13281. _super.prototype.removeSelfFromZr.call(this, zr);
  13282. for (var i = 0; i < this._children.length; i++) {
  13283. this._children[i].__zr = null;
  13284. }
  13285. };
  13286. ZRText.prototype.getBoundingRect = function () {
  13287. if (this.styleChanged()) {
  13288. this._updateSubTexts();
  13289. }
  13290. if (!this._rect) {
  13291. var tmpRect = new BoundingRect(0, 0, 0, 0);
  13292. var children = this._children;
  13293. var tmpMat = [];
  13294. var rect = null;
  13295. for (var i = 0; i < children.length; i++) {
  13296. var child = children[i];
  13297. var childRect = child.getBoundingRect();
  13298. var transform = child.getLocalTransform(tmpMat);
  13299. if (transform) {
  13300. tmpRect.copy(childRect);
  13301. tmpRect.applyTransform(transform);
  13302. rect = rect || tmpRect.clone();
  13303. rect.union(tmpRect);
  13304. }
  13305. else {
  13306. rect = rect || childRect.clone();
  13307. rect.union(childRect);
  13308. }
  13309. }
  13310. this._rect = rect || tmpRect;
  13311. }
  13312. return this._rect;
  13313. };
  13314. ZRText.prototype.setDefaultTextStyle = function (defaultTextStyle) {
  13315. this._defaultStyle = defaultTextStyle || DEFAULT_RICH_TEXT_COLOR;
  13316. };
  13317. ZRText.prototype.setTextContent = function (textContent) {
  13318. {
  13319. throw new Error('Can\'t attach text on another text');
  13320. }
  13321. };
  13322. ZRText.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  13323. if (!sourceStyle) {
  13324. return targetStyle;
  13325. }
  13326. var sourceRich = sourceStyle.rich;
  13327. var targetRich = targetStyle.rich || (sourceRich && {});
  13328. extend(targetStyle, sourceStyle);
  13329. if (sourceRich && targetRich) {
  13330. this._mergeRich(targetRich, sourceRich);
  13331. targetStyle.rich = targetRich;
  13332. }
  13333. else if (targetRich) {
  13334. targetStyle.rich = targetRich;
  13335. }
  13336. return targetStyle;
  13337. };
  13338. ZRText.prototype._mergeRich = function (targetRich, sourceRich) {
  13339. var richNames = keys(sourceRich);
  13340. for (var i = 0; i < richNames.length; i++) {
  13341. var richName = richNames[i];
  13342. targetRich[richName] = targetRich[richName] || {};
  13343. extend(targetRich[richName], sourceRich[richName]);
  13344. }
  13345. };
  13346. ZRText.prototype.getAnimationStyleProps = function () {
  13347. return DEFAULT_TEXT_ANIMATION_PROPS;
  13348. };
  13349. ZRText.prototype._getOrCreateChild = function (Ctor) {
  13350. var child = this._children[this._childCursor];
  13351. if (!child || !(child instanceof Ctor)) {
  13352. child = new Ctor();
  13353. }
  13354. this._children[this._childCursor++] = child;
  13355. child.__zr = this.__zr;
  13356. child.parent = this;
  13357. return child;
  13358. };
  13359. ZRText.prototype._updatePlainTexts = function () {
  13360. var style = this.style;
  13361. var textFont = style.font || DEFAULT_FONT;
  13362. var textPadding = style.padding;
  13363. var defaultStyle = this._defaultStyle;
  13364. var baseX = style.x || 0;
  13365. var baseY = style.y || 0;
  13366. var textAlign = style.align || defaultStyle.align || 'left';
  13367. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
  13368. calcInnerTextOverflowArea(tmpCITOverflowAreaOut, defaultStyle.overflowRect, baseX, baseY, textAlign, verticalAlign);
  13369. baseX = tmpCITOverflowAreaOut.baseX;
  13370. baseY = tmpCITOverflowAreaOut.baseY;
  13371. var text = getStyleText(style);
  13372. var contentBlock = parsePlainText(text, style, tmpCITOverflowAreaOut.outerWidth, tmpCITOverflowAreaOut.outerHeight);
  13373. var needDrawBg = needDrawBackground(style);
  13374. var bgColorDrawn = !!(style.backgroundColor);
  13375. var outerHeight = contentBlock.outerHeight;
  13376. var outerWidth = contentBlock.outerWidth;
  13377. var textLines = contentBlock.lines;
  13378. var lineHeight = contentBlock.lineHeight;
  13379. this.isTruncated = !!contentBlock.isTruncated;
  13380. var textX = baseX;
  13381. var textY = adjustTextY$1(baseY, contentBlock.contentHeight, verticalAlign);
  13382. if (needDrawBg || textPadding) {
  13383. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  13384. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  13385. needDrawBg && this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  13386. }
  13387. textY += lineHeight / 2;
  13388. if (textPadding) {
  13389. textX = getTextXForPadding(baseX, textAlign, textPadding);
  13390. if (verticalAlign === 'top') {
  13391. textY += textPadding[0];
  13392. }
  13393. else if (verticalAlign === 'bottom') {
  13394. textY -= textPadding[2];
  13395. }
  13396. }
  13397. var defaultLineWidth = 0;
  13398. var usingDefaultStroke = false;
  13399. var useDefaultFill = false;
  13400. var textFill = getFill('fill' in style
  13401. ? style.fill
  13402. : (useDefaultFill = true, defaultStyle.fill));
  13403. var textStroke = getStroke('stroke' in style
  13404. ? style.stroke
  13405. : (!bgColorDrawn
  13406. && (!defaultStyle.autoStroke || useDefaultFill))
  13407. ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, usingDefaultStroke = true, defaultStyle.stroke)
  13408. : null);
  13409. var hasShadow = style.textShadowBlur > 0;
  13410. for (var i = 0; i < textLines.length; i++) {
  13411. var el = this._getOrCreateChild(TSpan);
  13412. var subElStyle = el.createStyle();
  13413. el.useStyle(subElStyle);
  13414. subElStyle.text = textLines[i];
  13415. subElStyle.x = textX;
  13416. subElStyle.y = textY;
  13417. if (textAlign) {
  13418. subElStyle.textAlign = textAlign;
  13419. }
  13420. subElStyle.textBaseline = 'middle';
  13421. subElStyle.opacity = style.opacity;
  13422. subElStyle.strokeFirst = true;
  13423. if (hasShadow) {
  13424. subElStyle.shadowBlur = style.textShadowBlur || 0;
  13425. subElStyle.shadowColor = style.textShadowColor || 'transparent';
  13426. subElStyle.shadowOffsetX = style.textShadowOffsetX || 0;
  13427. subElStyle.shadowOffsetY = style.textShadowOffsetY || 0;
  13428. }
  13429. subElStyle.stroke = textStroke;
  13430. subElStyle.fill = textFill;
  13431. if (textStroke) {
  13432. subElStyle.lineWidth = style.lineWidth || defaultLineWidth;
  13433. subElStyle.lineDash = style.lineDash;
  13434. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13435. }
  13436. subElStyle.font = textFont;
  13437. setSeparateFont(subElStyle, style);
  13438. textY += lineHeight;
  13439. el.setBoundingRect(tSpanCreateBoundingRect2(subElStyle, contentBlock.contentWidth, contentBlock.calculatedLineHeight, usingDefaultStroke ? 0 : null));
  13440. }
  13441. };
  13442. ZRText.prototype._updateRichTexts = function () {
  13443. var style = this.style;
  13444. var defaultStyle = this._defaultStyle;
  13445. var textAlign = style.align || defaultStyle.align;
  13446. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
  13447. var baseX = style.x || 0;
  13448. var baseY = style.y || 0;
  13449. calcInnerTextOverflowArea(tmpCITOverflowAreaOut, defaultStyle.overflowRect, baseX, baseY, textAlign, verticalAlign);
  13450. baseX = tmpCITOverflowAreaOut.baseX;
  13451. baseY = tmpCITOverflowAreaOut.baseY;
  13452. var text = getStyleText(style);
  13453. var contentBlock = parseRichText(text, style, tmpCITOverflowAreaOut.outerWidth, tmpCITOverflowAreaOut.outerHeight, textAlign);
  13454. var contentWidth = contentBlock.width;
  13455. var outerWidth = contentBlock.outerWidth;
  13456. var outerHeight = contentBlock.outerHeight;
  13457. var textPadding = style.padding;
  13458. this.isTruncated = !!contentBlock.isTruncated;
  13459. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  13460. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  13461. var xLeft = boxX;
  13462. var lineTop = boxY;
  13463. if (textPadding) {
  13464. xLeft += textPadding[3];
  13465. lineTop += textPadding[0];
  13466. }
  13467. var xRight = xLeft + contentWidth;
  13468. if (needDrawBackground(style)) {
  13469. this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  13470. }
  13471. var bgColorDrawn = !!(style.backgroundColor);
  13472. for (var i = 0; i < contentBlock.lines.length; i++) {
  13473. var line = contentBlock.lines[i];
  13474. var tokens = line.tokens;
  13475. var tokenCount = tokens.length;
  13476. var lineHeight = line.lineHeight;
  13477. var remainedWidth = line.width;
  13478. var leftIndex = 0;
  13479. var lineXLeft = xLeft;
  13480. var lineXRight = xRight;
  13481. var rightIndex = tokenCount - 1;
  13482. var token = void 0;
  13483. while (leftIndex < tokenCount
  13484. && (token = tokens[leftIndex], !token.align || token.align === 'left')) {
  13485. this._placeToken(token, style, lineHeight, lineTop, lineXLeft, 'left', bgColorDrawn);
  13486. remainedWidth -= token.width;
  13487. lineXLeft += token.width;
  13488. leftIndex++;
  13489. }
  13490. while (rightIndex >= 0
  13491. && (token = tokens[rightIndex], token.align === 'right')) {
  13492. this._placeToken(token, style, lineHeight, lineTop, lineXRight, 'right', bgColorDrawn);
  13493. remainedWidth -= token.width;
  13494. lineXRight -= token.width;
  13495. rightIndex--;
  13496. }
  13497. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - remainedWidth) / 2;
  13498. while (leftIndex <= rightIndex) {
  13499. token = tokens[leftIndex];
  13500. this._placeToken(token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center', bgColorDrawn);
  13501. lineXLeft += token.width;
  13502. leftIndex++;
  13503. }
  13504. lineTop += lineHeight;
  13505. }
  13506. };
  13507. ZRText.prototype._placeToken = function (token, style, lineHeight, lineTop, x, textAlign, parentBgColorDrawn) {
  13508. var tokenStyle = style.rich[token.styleName] || {};
  13509. tokenStyle.text = token.text;
  13510. var verticalAlign = token.verticalAlign;
  13511. var y = lineTop + lineHeight / 2;
  13512. if (verticalAlign === 'top') {
  13513. y = lineTop + token.height / 2;
  13514. }
  13515. else if (verticalAlign === 'bottom') {
  13516. y = lineTop + lineHeight - token.height / 2;
  13517. }
  13518. var needDrawBg = !token.isLineHolder && needDrawBackground(tokenStyle);
  13519. needDrawBg && this._renderBackground(tokenStyle, style, textAlign === 'right'
  13520. ? x - token.width
  13521. : textAlign === 'center'
  13522. ? x - token.width / 2
  13523. : x, y - token.height / 2, token.width, token.height);
  13524. var bgColorDrawn = !!tokenStyle.backgroundColor;
  13525. var textPadding = token.textPadding;
  13526. if (textPadding) {
  13527. x = getTextXForPadding(x, textAlign, textPadding);
  13528. y -= token.height / 2 - textPadding[0] - token.innerHeight / 2;
  13529. }
  13530. var el = this._getOrCreateChild(TSpan);
  13531. var subElStyle = el.createStyle();
  13532. el.useStyle(subElStyle);
  13533. var defaultStyle = this._defaultStyle;
  13534. var useDefaultFill = false;
  13535. var defaultLineWidth = 0;
  13536. var usingDefaultStroke = false;
  13537. var textFill = getFill('fill' in tokenStyle ? tokenStyle.fill
  13538. : 'fill' in style ? style.fill
  13539. : (useDefaultFill = true, defaultStyle.fill));
  13540. var textStroke = getStroke('stroke' in tokenStyle ? tokenStyle.stroke
  13541. : 'stroke' in style ? style.stroke
  13542. : (!bgColorDrawn
  13543. && !parentBgColorDrawn
  13544. && (!defaultStyle.autoStroke || useDefaultFill)) ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, usingDefaultStroke = true, defaultStyle.stroke)
  13545. : null);
  13546. var hasShadow = tokenStyle.textShadowBlur > 0
  13547. || style.textShadowBlur > 0;
  13548. subElStyle.text = token.text;
  13549. subElStyle.x = x;
  13550. subElStyle.y = y;
  13551. if (hasShadow) {
  13552. subElStyle.shadowBlur = tokenStyle.textShadowBlur || style.textShadowBlur || 0;
  13553. subElStyle.shadowColor = tokenStyle.textShadowColor || style.textShadowColor || 'transparent';
  13554. subElStyle.shadowOffsetX = tokenStyle.textShadowOffsetX || style.textShadowOffsetX || 0;
  13555. subElStyle.shadowOffsetY = tokenStyle.textShadowOffsetY || style.textShadowOffsetY || 0;
  13556. }
  13557. subElStyle.textAlign = textAlign;
  13558. subElStyle.textBaseline = 'middle';
  13559. subElStyle.font = token.font || DEFAULT_FONT;
  13560. subElStyle.opacity = retrieve3(tokenStyle.opacity, style.opacity, 1);
  13561. setSeparateFont(subElStyle, tokenStyle);
  13562. if (textStroke) {
  13563. subElStyle.lineWidth = retrieve3(tokenStyle.lineWidth, style.lineWidth, defaultLineWidth);
  13564. subElStyle.lineDash = retrieve2(tokenStyle.lineDash, style.lineDash);
  13565. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  13566. subElStyle.stroke = textStroke;
  13567. }
  13568. if (textFill) {
  13569. subElStyle.fill = textFill;
  13570. }
  13571. el.setBoundingRect(tSpanCreateBoundingRect2(subElStyle, token.contentWidth, token.contentHeight, usingDefaultStroke ? 0 : null));
  13572. };
  13573. ZRText.prototype._renderBackground = function (style, topStyle, x, y, width, height) {
  13574. var textBackgroundColor = style.backgroundColor;
  13575. var textBorderWidth = style.borderWidth;
  13576. var textBorderColor = style.borderColor;
  13577. var isImageBg = textBackgroundColor && textBackgroundColor.image;
  13578. var isPlainOrGradientBg = textBackgroundColor && !isImageBg;
  13579. var textBorderRadius = style.borderRadius;
  13580. var self = this;
  13581. var rectEl;
  13582. var imgEl;
  13583. if (isPlainOrGradientBg || style.lineHeight || (textBorderWidth && textBorderColor)) {
  13584. rectEl = this._getOrCreateChild(Rect);
  13585. rectEl.useStyle(rectEl.createStyle());
  13586. rectEl.style.fill = null;
  13587. var rectShape = rectEl.shape;
  13588. rectShape.x = x;
  13589. rectShape.y = y;
  13590. rectShape.width = width;
  13591. rectShape.height = height;
  13592. rectShape.r = textBorderRadius;
  13593. rectEl.dirtyShape();
  13594. }
  13595. if (isPlainOrGradientBg) {
  13596. var rectStyle = rectEl.style;
  13597. rectStyle.fill = textBackgroundColor || null;
  13598. rectStyle.fillOpacity = retrieve2(style.fillOpacity, 1);
  13599. }
  13600. else if (isImageBg) {
  13601. imgEl = this._getOrCreateChild(ZRImage);
  13602. imgEl.onload = function () {
  13603. self.dirtyStyle();
  13604. };
  13605. var imgStyle = imgEl.style;
  13606. imgStyle.image = textBackgroundColor.image;
  13607. imgStyle.x = x;
  13608. imgStyle.y = y;
  13609. imgStyle.width = width;
  13610. imgStyle.height = height;
  13611. }
  13612. if (textBorderWidth && textBorderColor) {
  13613. var rectStyle = rectEl.style;
  13614. rectStyle.lineWidth = textBorderWidth;
  13615. rectStyle.stroke = textBorderColor;
  13616. rectStyle.strokeOpacity = retrieve2(style.strokeOpacity, 1);
  13617. rectStyle.lineDash = style.borderDash;
  13618. rectStyle.lineDashOffset = style.borderDashOffset || 0;
  13619. rectEl.strokeContainThreshold = 0;
  13620. if (rectEl.hasFill() && rectEl.hasStroke()) {
  13621. rectStyle.strokeFirst = true;
  13622. rectStyle.lineWidth *= 2;
  13623. }
  13624. }
  13625. var commonStyle = (rectEl || imgEl).style;
  13626. commonStyle.shadowBlur = style.shadowBlur || 0;
  13627. commonStyle.shadowColor = style.shadowColor || 'transparent';
  13628. commonStyle.shadowOffsetX = style.shadowOffsetX || 0;
  13629. commonStyle.shadowOffsetY = style.shadowOffsetY || 0;
  13630. commonStyle.opacity = retrieve3(style.opacity, topStyle.opacity, 1);
  13631. };
  13632. ZRText.makeFont = function (style) {
  13633. var font = '';
  13634. if (hasSeparateFont(style)) {
  13635. font = [
  13636. style.fontStyle,
  13637. style.fontWeight,
  13638. parseFontSize(style.fontSize),
  13639. style.fontFamily || 'sans-serif'
  13640. ].join(' ');
  13641. }
  13642. return font && trim(font) || style.textFont || style.font;
  13643. };
  13644. return ZRText;
  13645. }(Displayable));
  13646. var VALID_TEXT_ALIGN = { left: true, right: 1, center: 1 };
  13647. var VALID_TEXT_VERTICAL_ALIGN = { top: 1, bottom: 1, middle: 1 };
  13648. var FONT_PARTS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily'];
  13649. function parseFontSize(fontSize) {
  13650. if (typeof fontSize === 'string'
  13651. && (fontSize.indexOf('px') !== -1
  13652. || fontSize.indexOf('rem') !== -1
  13653. || fontSize.indexOf('em') !== -1)) {
  13654. return fontSize;
  13655. }
  13656. else if (!isNaN(+fontSize)) {
  13657. return fontSize + 'px';
  13658. }
  13659. else {
  13660. return DEFAULT_FONT_SIZE + 'px';
  13661. }
  13662. }
  13663. function setSeparateFont(targetStyle, sourceStyle) {
  13664. for (var i = 0; i < FONT_PARTS.length; i++) {
  13665. var fontProp = FONT_PARTS[i];
  13666. var val = sourceStyle[fontProp];
  13667. if (val != null) {
  13668. targetStyle[fontProp] = val;
  13669. }
  13670. }
  13671. }
  13672. function hasSeparateFont(style) {
  13673. return style.fontSize != null || style.fontFamily || style.fontWeight;
  13674. }
  13675. function normalizeTextStyle(style) {
  13676. normalizeStyle(style);
  13677. each(style.rich, normalizeStyle);
  13678. return style;
  13679. }
  13680. function normalizeStyle(style) {
  13681. if (style) {
  13682. style.font = ZRText.makeFont(style);
  13683. var textAlign = style.align;
  13684. textAlign === 'middle' && (textAlign = 'center');
  13685. style.align = (textAlign == null || VALID_TEXT_ALIGN[textAlign]) ? textAlign : 'left';
  13686. var verticalAlign = style.verticalAlign;
  13687. verticalAlign === 'center' && (verticalAlign = 'middle');
  13688. style.verticalAlign = (verticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[verticalAlign]) ? verticalAlign : 'top';
  13689. var textPadding = style.padding;
  13690. if (textPadding) {
  13691. style.padding = normalizeCssArray(style.padding);
  13692. }
  13693. }
  13694. }
  13695. function getStroke(stroke, lineWidth) {
  13696. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  13697. ? null
  13698. : (stroke.image || stroke.colorStops)
  13699. ? '#000'
  13700. : stroke;
  13701. }
  13702. function getFill(fill) {
  13703. return (fill == null || fill === 'none')
  13704. ? null
  13705. : (fill.image || fill.colorStops)
  13706. ? '#000'
  13707. : fill;
  13708. }
  13709. function getTextXForPadding(x, textAlign, textPadding) {
  13710. return textAlign === 'right'
  13711. ? (x - textPadding[1])
  13712. : textAlign === 'center'
  13713. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  13714. : (x + textPadding[3]);
  13715. }
  13716. function getStyleText(style) {
  13717. var text = style.text;
  13718. text != null && (text += '');
  13719. return text;
  13720. }
  13721. function needDrawBackground(style) {
  13722. return !!(style.backgroundColor
  13723. || style.lineHeight
  13724. || (style.borderWidth && style.borderColor));
  13725. }
  13726. var ArcShape = (function () {
  13727. function ArcShape() {
  13728. this.cx = 0;
  13729. this.cy = 0;
  13730. this.r = 0;
  13731. this.startAngle = 0;
  13732. this.endAngle = Math.PI * 2;
  13733. this.clockwise = true;
  13734. }
  13735. return ArcShape;
  13736. }());
  13737. var Arc = (function (_super) {
  13738. __extends(Arc, _super);
  13739. function Arc(opts) {
  13740. return _super.call(this, opts) || this;
  13741. }
  13742. Arc.prototype.getDefaultStyle = function () {
  13743. return {
  13744. stroke: '#000',
  13745. fill: null
  13746. };
  13747. };
  13748. Arc.prototype.getDefaultShape = function () {
  13749. return new ArcShape();
  13750. };
  13751. Arc.prototype.buildPath = function (ctx, shape) {
  13752. var x = shape.cx;
  13753. var y = shape.cy;
  13754. var r = Math.max(shape.r, 0);
  13755. var startAngle = shape.startAngle;
  13756. var endAngle = shape.endAngle;
  13757. var clockwise = shape.clockwise;
  13758. var unitX = Math.cos(startAngle);
  13759. var unitY = Math.sin(startAngle);
  13760. ctx.moveTo(unitX * r + x, unitY * r + y);
  13761. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13762. };
  13763. return Arc;
  13764. }(Path));
  13765. Arc.prototype.type = 'arc';
  13766. var out = [];
  13767. var BezierCurveShape = (function () {
  13768. function BezierCurveShape() {
  13769. this.x1 = 0;
  13770. this.y1 = 0;
  13771. this.x2 = 0;
  13772. this.y2 = 0;
  13773. this.cpx1 = 0;
  13774. this.cpy1 = 0;
  13775. this.percent = 1;
  13776. }
  13777. return BezierCurveShape;
  13778. }());
  13779. function someVectorAt(shape, t, isTangent) {
  13780. var cpx2 = shape.cpx2;
  13781. var cpy2 = shape.cpy2;
  13782. if (cpx2 != null || cpy2 != null) {
  13783. return [
  13784. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  13785. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  13786. ];
  13787. }
  13788. else {
  13789. return [
  13790. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  13791. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  13792. ];
  13793. }
  13794. }
  13795. var BezierCurve = (function (_super) {
  13796. __extends(BezierCurve, _super);
  13797. function BezierCurve(opts) {
  13798. return _super.call(this, opts) || this;
  13799. }
  13800. BezierCurve.prototype.getDefaultStyle = function () {
  13801. return {
  13802. stroke: '#000',
  13803. fill: null
  13804. };
  13805. };
  13806. BezierCurve.prototype.getDefaultShape = function () {
  13807. return new BezierCurveShape();
  13808. };
  13809. BezierCurve.prototype.buildPath = function (ctx, shape) {
  13810. var x1 = shape.x1;
  13811. var y1 = shape.y1;
  13812. var x2 = shape.x2;
  13813. var y2 = shape.y2;
  13814. var cpx1 = shape.cpx1;
  13815. var cpy1 = shape.cpy1;
  13816. var cpx2 = shape.cpx2;
  13817. var cpy2 = shape.cpy2;
  13818. var percent = shape.percent;
  13819. if (percent === 0) {
  13820. return;
  13821. }
  13822. ctx.moveTo(x1, y1);
  13823. if (cpx2 == null || cpy2 == null) {
  13824. if (percent < 1) {
  13825. quadraticSubdivide(x1, cpx1, x2, percent, out);
  13826. cpx1 = out[1];
  13827. x2 = out[2];
  13828. quadraticSubdivide(y1, cpy1, y2, percent, out);
  13829. cpy1 = out[1];
  13830. y2 = out[2];
  13831. }
  13832. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  13833. }
  13834. else {
  13835. if (percent < 1) {
  13836. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  13837. cpx1 = out[1];
  13838. cpx2 = out[2];
  13839. x2 = out[3];
  13840. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  13841. cpy1 = out[1];
  13842. cpy2 = out[2];
  13843. y2 = out[3];
  13844. }
  13845. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  13846. }
  13847. };
  13848. BezierCurve.prototype.pointAt = function (t) {
  13849. return someVectorAt(this.shape, t, false);
  13850. };
  13851. BezierCurve.prototype.tangentAt = function (t) {
  13852. var p = someVectorAt(this.shape, t, true);
  13853. return normalize(p, p);
  13854. };
  13855. return BezierCurve;
  13856. }(Path));
  13857. BezierCurve.prototype.type = 'bezier-curve';
  13858. var DropletShape = (function () {
  13859. function DropletShape() {
  13860. this.cx = 0;
  13861. this.cy = 0;
  13862. this.width = 0;
  13863. this.height = 0;
  13864. }
  13865. return DropletShape;
  13866. }());
  13867. var Droplet = (function (_super) {
  13868. __extends(Droplet, _super);
  13869. function Droplet(opts) {
  13870. return _super.call(this, opts) || this;
  13871. }
  13872. Droplet.prototype.getDefaultShape = function () {
  13873. return new DropletShape();
  13874. };
  13875. Droplet.prototype.buildPath = function (ctx, shape) {
  13876. var x = shape.cx;
  13877. var y = shape.cy;
  13878. var a = shape.width;
  13879. var b = shape.height;
  13880. ctx.moveTo(x, y + a);
  13881. ctx.bezierCurveTo(x + a, y + a, x + a * 3 / 2, y - a / 3, x, y - b);
  13882. ctx.bezierCurveTo(x - a * 3 / 2, y - a / 3, x - a, y + a, x, y + a);
  13883. ctx.closePath();
  13884. };
  13885. return Droplet;
  13886. }(Path));
  13887. Droplet.prototype.type = 'droplet';
  13888. var HeartShape = (function () {
  13889. function HeartShape() {
  13890. this.cx = 0;
  13891. this.cy = 0;
  13892. this.width = 0;
  13893. this.height = 0;
  13894. }
  13895. return HeartShape;
  13896. }());
  13897. var Heart = (function (_super) {
  13898. __extends(Heart, _super);
  13899. function Heart(opts) {
  13900. return _super.call(this, opts) || this;
  13901. }
  13902. Heart.prototype.getDefaultShape = function () {
  13903. return new HeartShape();
  13904. };
  13905. Heart.prototype.buildPath = function (ctx, shape) {
  13906. var x = shape.cx;
  13907. var y = shape.cy;
  13908. var a = shape.width;
  13909. var b = shape.height;
  13910. ctx.moveTo(x, y);
  13911. ctx.bezierCurveTo(x + a / 2, y - b * 2 / 3, x + a * 2, y + b / 3, x, y + b);
  13912. ctx.bezierCurveTo(x - a * 2, y + b / 3, x - a / 2, y - b * 2 / 3, x, y);
  13913. };
  13914. return Heart;
  13915. }(Path));
  13916. Heart.prototype.type = 'heart';
  13917. var PI$3 = Math.PI;
  13918. var sin = Math.sin;
  13919. var cos = Math.cos;
  13920. var IsogonShape = (function () {
  13921. function IsogonShape() {
  13922. this.x = 0;
  13923. this.y = 0;
  13924. this.r = 0;
  13925. this.n = 0;
  13926. }
  13927. return IsogonShape;
  13928. }());
  13929. var Isogon = (function (_super) {
  13930. __extends(Isogon, _super);
  13931. function Isogon(opts) {
  13932. return _super.call(this, opts) || this;
  13933. }
  13934. Isogon.prototype.getDefaultShape = function () {
  13935. return new IsogonShape();
  13936. };
  13937. Isogon.prototype.buildPath = function (ctx, shape) {
  13938. var n = shape.n;
  13939. if (!n || n < 2) {
  13940. return;
  13941. }
  13942. var x = shape.x;
  13943. var y = shape.y;
  13944. var r = shape.r;
  13945. var dStep = 2 * PI$3 / n;
  13946. var deg = -PI$3 / 2;
  13947. ctx.moveTo(x + r * cos(deg), y + r * sin(deg));
  13948. for (var i = 0, end = n - 1; i < end; i++) {
  13949. deg += dStep;
  13950. ctx.lineTo(x + r * cos(deg), y + r * sin(deg));
  13951. }
  13952. ctx.closePath();
  13953. return;
  13954. };
  13955. return Isogon;
  13956. }(Path));
  13957. Isogon.prototype.type = 'isogon';
  13958. var RingShape = (function () {
  13959. function RingShape() {
  13960. this.cx = 0;
  13961. this.cy = 0;
  13962. this.r = 0;
  13963. this.r0 = 0;
  13964. }
  13965. return RingShape;
  13966. }());
  13967. var Ring = (function (_super) {
  13968. __extends(Ring, _super);
  13969. function Ring(opts) {
  13970. return _super.call(this, opts) || this;
  13971. }
  13972. Ring.prototype.getDefaultShape = function () {
  13973. return new RingShape();
  13974. };
  13975. Ring.prototype.buildPath = function (ctx, shape) {
  13976. var x = shape.cx;
  13977. var y = shape.cy;
  13978. var PI2 = Math.PI * 2;
  13979. ctx.moveTo(x + shape.r, y);
  13980. ctx.arc(x, y, shape.r, 0, PI2, false);
  13981. ctx.moveTo(x + shape.r0, y);
  13982. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13983. };
  13984. return Ring;
  13985. }(Path));
  13986. Ring.prototype.type = 'ring';
  13987. var sin$1 = Math.sin;
  13988. var cos$1 = Math.cos;
  13989. var radian = Math.PI / 180;
  13990. var RoseShape = (function () {
  13991. function RoseShape() {
  13992. this.cx = 0;
  13993. this.cy = 0;
  13994. this.r = [];
  13995. this.k = 0;
  13996. this.n = 1;
  13997. }
  13998. return RoseShape;
  13999. }());
  14000. var Rose = (function (_super) {
  14001. __extends(Rose, _super);
  14002. function Rose(opts) {
  14003. return _super.call(this, opts) || this;
  14004. }
  14005. Rose.prototype.getDefaultStyle = function () {
  14006. return {
  14007. stroke: '#000',
  14008. fill: null
  14009. };
  14010. };
  14011. Rose.prototype.getDefaultShape = function () {
  14012. return new RoseShape();
  14013. };
  14014. Rose.prototype.buildPath = function (ctx, shape) {
  14015. var R = shape.r;
  14016. var k = shape.k;
  14017. var n = shape.n;
  14018. var x0 = shape.cx;
  14019. var y0 = shape.cy;
  14020. var x;
  14021. var y;
  14022. var r;
  14023. ctx.moveTo(x0, y0);
  14024. for (var i = 0, len = R.length; i < len; i++) {
  14025. r = R[i];
  14026. for (var j = 0; j <= 360 * n; j++) {
  14027. x = r
  14028. * sin$1(k / n * j % 360 * radian)
  14029. * cos$1(j * radian)
  14030. + x0;
  14031. y = r
  14032. * sin$1(k / n * j % 360 * radian)
  14033. * sin$1(j * radian)
  14034. + y0;
  14035. ctx.lineTo(x, y);
  14036. }
  14037. }
  14038. };
  14039. return Rose;
  14040. }(Path));
  14041. Rose.prototype.type = 'rose';
  14042. var PI$4 = Math.PI;
  14043. var cos$2 = Math.cos;
  14044. var sin$2 = Math.sin;
  14045. var StarShape = (function () {
  14046. function StarShape() {
  14047. this.cx = 0;
  14048. this.cy = 0;
  14049. this.n = 3;
  14050. this.r = 0;
  14051. }
  14052. return StarShape;
  14053. }());
  14054. var Star = (function (_super) {
  14055. __extends(Star, _super);
  14056. function Star(opts) {
  14057. return _super.call(this, opts) || this;
  14058. }
  14059. Star.prototype.getDefaultShape = function () {
  14060. return new StarShape();
  14061. };
  14062. Star.prototype.buildPath = function (ctx, shape) {
  14063. var n = shape.n;
  14064. if (!n || n < 2) {
  14065. return;
  14066. }
  14067. var x = shape.cx;
  14068. var y = shape.cy;
  14069. var r = shape.r;
  14070. var r0 = shape.r0;
  14071. if (r0 == null) {
  14072. r0 = n > 4
  14073. ? r * cos$2(2 * PI$4 / n) / cos$2(PI$4 / n)
  14074. : r / 3;
  14075. }
  14076. var dStep = PI$4 / n;
  14077. var deg = -PI$4 / 2;
  14078. var xStart = x + r * cos$2(deg);
  14079. var yStart = y + r * sin$2(deg);
  14080. deg += dStep;
  14081. ctx.moveTo(xStart, yStart);
  14082. for (var i = 0, end = n * 2 - 1, ri = void 0; i < end; i++) {
  14083. ri = i % 2 === 0 ? r0 : r;
  14084. ctx.lineTo(x + ri * cos$2(deg), y + ri * sin$2(deg));
  14085. deg += dStep;
  14086. }
  14087. ctx.closePath();
  14088. };
  14089. return Star;
  14090. }(Path));
  14091. Star.prototype.type = 'star';
  14092. var cos$3 = Math.cos;
  14093. var sin$3 = Math.sin;
  14094. var TrochoidShape = (function () {
  14095. function TrochoidShape() {
  14096. this.cx = 0;
  14097. this.cy = 0;
  14098. this.r = 0;
  14099. this.r0 = 0;
  14100. this.d = 0;
  14101. this.location = 'out';
  14102. }
  14103. return TrochoidShape;
  14104. }());
  14105. var Trochoid = (function (_super) {
  14106. __extends(Trochoid, _super);
  14107. function Trochoid(opts) {
  14108. return _super.call(this, opts) || this;
  14109. }
  14110. Trochoid.prototype.getDefaultStyle = function () {
  14111. return {
  14112. stroke: '#000',
  14113. fill: null
  14114. };
  14115. };
  14116. Trochoid.prototype.getDefaultShape = function () {
  14117. return new TrochoidShape();
  14118. };
  14119. Trochoid.prototype.buildPath = function (ctx, shape) {
  14120. var R = shape.r;
  14121. var r = shape.r0;
  14122. var d = shape.d;
  14123. var offsetX = shape.cx;
  14124. var offsetY = shape.cy;
  14125. var delta = shape.location === 'out' ? 1 : -1;
  14126. var x1;
  14127. var y1;
  14128. var x2;
  14129. var y2;
  14130. if (shape.location && R <= r) {
  14131. return;
  14132. }
  14133. var num = 0;
  14134. var i = 1;
  14135. var theta;
  14136. x1 = (R + delta * r) * cos$3(0)
  14137. - delta * d * cos$3(0) + offsetX;
  14138. y1 = (R + delta * r) * sin$3(0)
  14139. - d * sin$3(0) + offsetY;
  14140. ctx.moveTo(x1, y1);
  14141. do {
  14142. num++;
  14143. } while ((r * num) % (R + delta * r) !== 0);
  14144. do {
  14145. theta = Math.PI / 180 * i;
  14146. x2 = (R + delta * r) * cos$3(theta)
  14147. - delta * d * cos$3((R / r + delta) * theta)
  14148. + offsetX;
  14149. y2 = (R + delta * r) * sin$3(theta)
  14150. - d * sin$3((R / r + delta) * theta)
  14151. + offsetY;
  14152. ctx.lineTo(x2, y2);
  14153. i++;
  14154. } while (i <= (r * num) / (R + delta * r) * 360);
  14155. };
  14156. return Trochoid;
  14157. }(Path));
  14158. Trochoid.prototype.type = 'trochoid';
  14159. var Pattern = (function () {
  14160. function Pattern(image, repeat) {
  14161. this.image = image;
  14162. this.repeat = repeat;
  14163. this.x = 0;
  14164. this.y = 0;
  14165. this.rotation = 0;
  14166. this.scaleX = 1;
  14167. this.scaleY = 1;
  14168. }
  14169. return Pattern;
  14170. }());
  14171. var mathMin$4 = Math.min;
  14172. var mathMax$4 = Math.max;
  14173. var mathAbs$3 = Math.abs;
  14174. var _extent = [0, 0];
  14175. var _extent2 = [0, 0];
  14176. var _intersectCtx$1 = createIntersectContext();
  14177. var _minTv$1 = _intersectCtx$1.minTv;
  14178. var _maxTv$1 = _intersectCtx$1.maxTv;
  14179. var OrientedBoundingRect = (function () {
  14180. function OrientedBoundingRect(rect, transform) {
  14181. this._corners = [];
  14182. this._axes = [];
  14183. this._origin = [0, 0];
  14184. for (var i = 0; i < 4; i++) {
  14185. this._corners[i] = new Point();
  14186. }
  14187. for (var i = 0; i < 2; i++) {
  14188. this._axes[i] = new Point();
  14189. }
  14190. if (rect) {
  14191. this.fromBoundingRect(rect, transform);
  14192. }
  14193. }
  14194. OrientedBoundingRect.prototype.fromBoundingRect = function (rect, transform) {
  14195. var corners = this._corners;
  14196. var axes = this._axes;
  14197. var x = rect.x;
  14198. var y = rect.y;
  14199. var x2 = x + rect.width;
  14200. var y2 = y + rect.height;
  14201. corners[0].set(x, y);
  14202. corners[1].set(x2, y);
  14203. corners[2].set(x2, y2);
  14204. corners[3].set(x, y2);
  14205. if (transform) {
  14206. for (var i = 0; i < 4; i++) {
  14207. corners[i].transform(transform);
  14208. }
  14209. }
  14210. Point.sub(axes[0], corners[1], corners[0]);
  14211. Point.sub(axes[1], corners[3], corners[0]);
  14212. axes[0].normalize();
  14213. axes[1].normalize();
  14214. for (var i = 0; i < 2; i++) {
  14215. this._origin[i] = axes[i].dot(corners[0]);
  14216. }
  14217. };
  14218. OrientedBoundingRect.prototype.intersect = function (other, mtv, opt) {
  14219. var overlapped = true;
  14220. var noMtv = !mtv;
  14221. if (mtv) {
  14222. Point.set(mtv, 0, 0);
  14223. }
  14224. _intersectCtx$1.reset(opt, !noMtv);
  14225. if (!this._intersectCheckOneSide(this, other, noMtv, 1)) {
  14226. overlapped = false;
  14227. if (noMtv) {
  14228. return overlapped;
  14229. }
  14230. }
  14231. if (!this._intersectCheckOneSide(other, this, noMtv, -1)) {
  14232. overlapped = false;
  14233. if (noMtv) {
  14234. return overlapped;
  14235. }
  14236. }
  14237. if (!noMtv && !_intersectCtx$1.negativeSize) {
  14238. Point.copy(mtv, overlapped
  14239. ? (_intersectCtx$1.useDir ? _intersectCtx$1.dirMinTv : _minTv$1)
  14240. : _maxTv$1);
  14241. }
  14242. return overlapped;
  14243. };
  14244. OrientedBoundingRect.prototype._intersectCheckOneSide = function (self, other, noMtv, inverse) {
  14245. var overlapped = true;
  14246. for (var i = 0; i < 2; i++) {
  14247. var axis = self._axes[i];
  14248. self._getProjMinMaxOnAxis(i, self._corners, _extent);
  14249. self._getProjMinMaxOnAxis(i, other._corners, _extent2);
  14250. if (_intersectCtx$1.negativeSize || _extent[1] < _extent2[0] || _extent[0] > _extent2[1]) {
  14251. overlapped = false;
  14252. if (_intersectCtx$1.negativeSize || noMtv) {
  14253. return overlapped;
  14254. }
  14255. var dist0 = mathAbs$3(_extent2[0] - _extent[1]);
  14256. var dist1 = mathAbs$3(_extent[0] - _extent2[1]);
  14257. if (mathMin$4(dist0, dist1) > _maxTv$1.len()) {
  14258. if (dist0 < dist1) {
  14259. Point.scale(_maxTv$1, axis, -dist0 * inverse);
  14260. }
  14261. else {
  14262. Point.scale(_maxTv$1, axis, dist1 * inverse);
  14263. }
  14264. }
  14265. }
  14266. else if (!noMtv) {
  14267. var dist0 = mathAbs$3(_extent2[0] - _extent[1]);
  14268. var dist1 = mathAbs$3(_extent[0] - _extent2[1]);
  14269. if (_intersectCtx$1.useDir || mathMin$4(dist0, dist1) < _minTv$1.len()) {
  14270. if (dist0 < dist1 || !_intersectCtx$1.bidirectional) {
  14271. Point.scale(_minTv$1, axis, dist0 * inverse);
  14272. if (_intersectCtx$1.useDir) {
  14273. _intersectCtx$1.calcDirMTV();
  14274. }
  14275. }
  14276. if (dist0 >= dist1 || !_intersectCtx$1.bidirectional) {
  14277. Point.scale(_minTv$1, axis, -dist1 * inverse);
  14278. if (_intersectCtx$1.useDir) {
  14279. _intersectCtx$1.calcDirMTV();
  14280. }
  14281. }
  14282. }
  14283. }
  14284. }
  14285. return overlapped;
  14286. };
  14287. OrientedBoundingRect.prototype._getProjMinMaxOnAxis = function (dim, corners, out) {
  14288. var axis = this._axes[dim];
  14289. var origin = this._origin;
  14290. var proj = corners[0].dot(axis) + origin[dim];
  14291. var min = proj;
  14292. var max = proj;
  14293. for (var i = 1; i < corners.length; i++) {
  14294. var proj_1 = corners[i].dot(axis) + origin[dim];
  14295. min = mathMin$4(proj_1, min);
  14296. max = mathMax$4(proj_1, max);
  14297. }
  14298. out[0] = min + _intersectCtx$1.touchThreshold;
  14299. out[1] = max - _intersectCtx$1.touchThreshold;
  14300. _intersectCtx$1.negativeSize = out[1] < out[0];
  14301. };
  14302. return OrientedBoundingRect;
  14303. }());
  14304. var DebugRect = (function () {
  14305. function DebugRect(style) {
  14306. var dom = this.dom = document.createElement('div');
  14307. dom.className = 'ec-debug-dirty-rect';
  14308. style = extend({}, style);
  14309. extend(style, {
  14310. backgroundColor: 'rgba(0, 0, 255, 0.2)',
  14311. border: '1px solid #00f'
  14312. });
  14313. dom.style.cssText = "\nposition: absolute;\nopacity: 0;\ntransition: opacity 0.5s linear;\npointer-events: none;\n";
  14314. for (var key in style) {
  14315. if (style.hasOwnProperty(key)) {
  14316. dom.style[key] = style[key];
  14317. }
  14318. }
  14319. }
  14320. DebugRect.prototype.update = function (rect) {
  14321. var domStyle = this.dom.style;
  14322. domStyle.width = rect.width + 'px';
  14323. domStyle.height = rect.height + 'px';
  14324. domStyle.left = rect.x + 'px';
  14325. domStyle.top = rect.y + 'px';
  14326. };
  14327. DebugRect.prototype.hide = function () {
  14328. this.dom.style.opacity = '0';
  14329. };
  14330. DebugRect.prototype.show = function (autoHideDelay) {
  14331. var _this = this;
  14332. clearTimeout(this._hideTimeout);
  14333. this.dom.style.opacity = '1';
  14334. this._hideTimeout = setTimeout(function () {
  14335. _this.hide();
  14336. }, autoHideDelay || 1000);
  14337. };
  14338. return DebugRect;
  14339. }());
  14340. function showDebugDirtyRect(zr, opts) {
  14341. opts = opts || {};
  14342. var painter = zr.painter;
  14343. if (!painter.getLayers) {
  14344. throw new Error('Debug dirty rect can only been used on canvas renderer.');
  14345. }
  14346. if (painter.isSingleCanvas()) {
  14347. throw new Error('Debug dirty rect can only been used on zrender inited with container.');
  14348. }
  14349. var debugViewRoot = document.createElement('div');
  14350. debugViewRoot.style.cssText = "\nposition:absolute;\nleft:0;\ntop:0;\nright:0;\nbottom:0;\npointer-events:none;\n";
  14351. debugViewRoot.className = 'ec-debug-dirty-rect-container';
  14352. var debugRects = [];
  14353. var dom = zr.dom;
  14354. dom.appendChild(debugViewRoot);
  14355. var computedStyle = getComputedStyle(dom);
  14356. if (computedStyle.position === 'static') {
  14357. dom.style.position = 'relative';
  14358. }
  14359. zr.on('rendered', function () {
  14360. if (painter.getLayers) {
  14361. var idx_1 = 0;
  14362. painter.eachBuiltinLayer(function (layer) {
  14363. if (!layer.debugGetPaintRects) {
  14364. return;
  14365. }
  14366. var paintRects = layer.debugGetPaintRects();
  14367. for (var i = 0; i < paintRects.length; i++) {
  14368. if (!paintRects[i].width || !paintRects[i].height) {
  14369. continue;
  14370. }
  14371. if (!debugRects[idx_1]) {
  14372. debugRects[idx_1] = new DebugRect(opts.style);
  14373. debugViewRoot.appendChild(debugRects[idx_1].dom);
  14374. }
  14375. debugRects[idx_1].show(opts.autoHideDelay);
  14376. debugRects[idx_1].update(paintRects[i]);
  14377. idx_1++;
  14378. }
  14379. });
  14380. for (var i = idx_1; i < debugRects.length; i++) {
  14381. debugRects[i].hide();
  14382. }
  14383. }
  14384. });
  14385. }
  14386. function isSafeNum(num) {
  14387. return isFinite(num);
  14388. }
  14389. function createLinearGradient(ctx, obj, rect) {
  14390. var x = obj.x == null ? 0 : obj.x;
  14391. var x2 = obj.x2 == null ? 1 : obj.x2;
  14392. var y = obj.y == null ? 0 : obj.y;
  14393. var y2 = obj.y2 == null ? 0 : obj.y2;
  14394. if (!obj.global) {
  14395. x = x * rect.width + rect.x;
  14396. x2 = x2 * rect.width + rect.x;
  14397. y = y * rect.height + rect.y;
  14398. y2 = y2 * rect.height + rect.y;
  14399. }
  14400. x = isSafeNum(x) ? x : 0;
  14401. x2 = isSafeNum(x2) ? x2 : 1;
  14402. y = isSafeNum(y) ? y : 0;
  14403. y2 = isSafeNum(y2) ? y2 : 0;
  14404. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  14405. return canvasGradient;
  14406. }
  14407. function createRadialGradient(ctx, obj, rect) {
  14408. var width = rect.width;
  14409. var height = rect.height;
  14410. var min = Math.min(width, height);
  14411. var x = obj.x == null ? 0.5 : obj.x;
  14412. var y = obj.y == null ? 0.5 : obj.y;
  14413. var r = obj.r == null ? 0.5 : obj.r;
  14414. if (!obj.global) {
  14415. x = x * width + rect.x;
  14416. y = y * height + rect.y;
  14417. r = r * min;
  14418. }
  14419. x = isSafeNum(x) ? x : 0.5;
  14420. y = isSafeNum(y) ? y : 0.5;
  14421. r = r >= 0 && isSafeNum(r) ? r : 0.5;
  14422. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  14423. return canvasGradient;
  14424. }
  14425. function getCanvasGradient(ctx, obj, rect) {
  14426. var canvasGradient = obj.type === 'radial'
  14427. ? createRadialGradient(ctx, obj, rect)
  14428. : createLinearGradient(ctx, obj, rect);
  14429. var colorStops = obj.colorStops;
  14430. for (var i = 0; i < colorStops.length; i++) {
  14431. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  14432. }
  14433. return canvasGradient;
  14434. }
  14435. function isClipPathChanged(clipPaths, prevClipPaths) {
  14436. if (clipPaths === prevClipPaths || (!clipPaths && !prevClipPaths)) {
  14437. return false;
  14438. }
  14439. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  14440. return true;
  14441. }
  14442. for (var i = 0; i < clipPaths.length; i++) {
  14443. if (clipPaths[i] !== prevClipPaths[i]) {
  14444. return true;
  14445. }
  14446. }
  14447. return false;
  14448. }
  14449. function parseInt10(val) {
  14450. return parseInt(val, 10);
  14451. }
  14452. function getSize(root, whIdx, opts) {
  14453. var wh = ['width', 'height'][whIdx];
  14454. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  14455. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  14456. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  14457. if (opts[wh] != null && opts[wh] !== 'auto') {
  14458. return parseFloat(opts[wh]);
  14459. }
  14460. var stl = document.defaultView.getComputedStyle(root);
  14461. return ((root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  14462. - (parseInt10(stl[plt]) || 0)
  14463. - (parseInt10(stl[prb]) || 0)) | 0;
  14464. }
  14465. function normalizeLineDash(lineType, lineWidth) {
  14466. if (!lineType || lineType === 'solid' || !(lineWidth > 0)) {
  14467. return null;
  14468. }
  14469. return lineType === 'dashed'
  14470. ? [4 * lineWidth, 2 * lineWidth]
  14471. : lineType === 'dotted'
  14472. ? [lineWidth]
  14473. : isNumber(lineType)
  14474. ? [lineType] : isArray(lineType) ? lineType : null;
  14475. }
  14476. function getLineDash(el) {
  14477. var style = el.style;
  14478. var lineDash = style.lineDash && style.lineWidth > 0 && normalizeLineDash(style.lineDash, style.lineWidth);
  14479. var lineDashOffset = style.lineDashOffset;
  14480. if (lineDash) {
  14481. var lineScale_1 = (style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1;
  14482. if (lineScale_1 && lineScale_1 !== 1) {
  14483. lineDash = map(lineDash, function (rawVal) {
  14484. return rawVal / lineScale_1;
  14485. });
  14486. lineDashOffset /= lineScale_1;
  14487. }
  14488. }
  14489. return [lineDash, lineDashOffset];
  14490. }
  14491. var pathProxyForDraw = new PathProxy(true);
  14492. function styleHasStroke(style) {
  14493. var stroke = style.stroke;
  14494. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  14495. }
  14496. function isValidStrokeFillStyle(strokeOrFill) {
  14497. return typeof strokeOrFill === 'string' && strokeOrFill !== 'none';
  14498. }
  14499. function styleHasFill(style) {
  14500. var fill = style.fill;
  14501. return fill != null && fill !== 'none';
  14502. }
  14503. function doFillPath(ctx, style) {
  14504. if (style.fillOpacity != null && style.fillOpacity !== 1) {
  14505. var originalGlobalAlpha = ctx.globalAlpha;
  14506. ctx.globalAlpha = style.fillOpacity * style.opacity;
  14507. ctx.fill();
  14508. ctx.globalAlpha = originalGlobalAlpha;
  14509. }
  14510. else {
  14511. ctx.fill();
  14512. }
  14513. }
  14514. function doStrokePath(ctx, style) {
  14515. if (style.strokeOpacity != null && style.strokeOpacity !== 1) {
  14516. var originalGlobalAlpha = ctx.globalAlpha;
  14517. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  14518. ctx.stroke();
  14519. ctx.globalAlpha = originalGlobalAlpha;
  14520. }
  14521. else {
  14522. ctx.stroke();
  14523. }
  14524. }
  14525. function createCanvasPattern(ctx, pattern, el) {
  14526. var image = createOrUpdateImage(pattern.image, pattern.__image, el);
  14527. if (isImageReady(image)) {
  14528. var canvasPattern = ctx.createPattern(image, pattern.repeat || 'repeat');
  14529. if (typeof DOMMatrix === 'function'
  14530. && canvasPattern
  14531. && canvasPattern.setTransform) {
  14532. var matrix = new DOMMatrix();
  14533. matrix.translateSelf((pattern.x || 0), (pattern.y || 0));
  14534. matrix.rotateSelf(0, 0, (pattern.rotation || 0) * RADIAN_TO_DEGREE);
  14535. matrix.scaleSelf((pattern.scaleX || 1), (pattern.scaleY || 1));
  14536. canvasPattern.setTransform(matrix);
  14537. }
  14538. return canvasPattern;
  14539. }
  14540. }
  14541. function brushPath(ctx, el, style, inBatch) {
  14542. var _a;
  14543. var hasStroke = styleHasStroke(style);
  14544. var hasFill = styleHasFill(style);
  14545. var strokePercent = style.strokePercent;
  14546. var strokePart = strokePercent < 1;
  14547. var firstDraw = !el.path;
  14548. if ((!el.silent || strokePart) && firstDraw) {
  14549. el.createPathProxy();
  14550. }
  14551. var path = el.path || pathProxyForDraw;
  14552. var dirtyFlag = el.__dirty;
  14553. if (!inBatch) {
  14554. var fill = style.fill;
  14555. var stroke = style.stroke;
  14556. var hasFillGradient = hasFill && !!fill.colorStops;
  14557. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  14558. var hasFillPattern = hasFill && !!fill.image;
  14559. var hasStrokePattern = hasStroke && !!stroke.image;
  14560. var fillGradient = void 0;
  14561. var strokeGradient = void 0;
  14562. var fillPattern = void 0;
  14563. var strokePattern = void 0;
  14564. var rect = void 0;
  14565. if (hasFillGradient || hasStrokeGradient) {
  14566. rect = el.getBoundingRect();
  14567. }
  14568. if (hasFillGradient) {
  14569. fillGradient = dirtyFlag
  14570. ? getCanvasGradient(ctx, fill, rect)
  14571. : el.__canvasFillGradient;
  14572. el.__canvasFillGradient = fillGradient;
  14573. }
  14574. if (hasStrokeGradient) {
  14575. strokeGradient = dirtyFlag
  14576. ? getCanvasGradient(ctx, stroke, rect)
  14577. : el.__canvasStrokeGradient;
  14578. el.__canvasStrokeGradient = strokeGradient;
  14579. }
  14580. if (hasFillPattern) {
  14581. fillPattern = (dirtyFlag || !el.__canvasFillPattern)
  14582. ? createCanvasPattern(ctx, fill, el)
  14583. : el.__canvasFillPattern;
  14584. el.__canvasFillPattern = fillPattern;
  14585. }
  14586. if (hasStrokePattern) {
  14587. strokePattern = (dirtyFlag || !el.__canvasStrokePattern)
  14588. ? createCanvasPattern(ctx, stroke, el)
  14589. : el.__canvasStrokePattern;
  14590. el.__canvasStrokePattern = strokePattern;
  14591. }
  14592. if (hasFillGradient) {
  14593. ctx.fillStyle = fillGradient;
  14594. }
  14595. else if (hasFillPattern) {
  14596. if (fillPattern) {
  14597. ctx.fillStyle = fillPattern;
  14598. }
  14599. else {
  14600. hasFill = false;
  14601. }
  14602. }
  14603. if (hasStrokeGradient) {
  14604. ctx.strokeStyle = strokeGradient;
  14605. }
  14606. else if (hasStrokePattern) {
  14607. if (strokePattern) {
  14608. ctx.strokeStyle = strokePattern;
  14609. }
  14610. else {
  14611. hasStroke = false;
  14612. }
  14613. }
  14614. }
  14615. var scale = el.getGlobalScale();
  14616. path.setScale(scale[0], scale[1], el.segmentIgnoreThreshold);
  14617. var lineDash;
  14618. var lineDashOffset;
  14619. if (ctx.setLineDash && style.lineDash) {
  14620. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14621. }
  14622. var needsRebuild = true;
  14623. if (firstDraw || (dirtyFlag & SHAPE_CHANGED_BIT)) {
  14624. path.setDPR(ctx.dpr);
  14625. if (strokePart) {
  14626. path.setContext(null);
  14627. }
  14628. else {
  14629. path.setContext(ctx);
  14630. needsRebuild = false;
  14631. }
  14632. path.reset();
  14633. el.buildPath(path, el.shape, inBatch);
  14634. path.toStatic();
  14635. el.pathUpdated();
  14636. }
  14637. if (needsRebuild) {
  14638. path.rebuildPath(ctx, strokePart ? strokePercent : 1);
  14639. }
  14640. if (lineDash) {
  14641. ctx.setLineDash(lineDash);
  14642. ctx.lineDashOffset = lineDashOffset;
  14643. }
  14644. if (!inBatch) {
  14645. if (style.strokeFirst) {
  14646. if (hasStroke) {
  14647. doStrokePath(ctx, style);
  14648. }
  14649. if (hasFill) {
  14650. doFillPath(ctx, style);
  14651. }
  14652. }
  14653. else {
  14654. if (hasFill) {
  14655. doFillPath(ctx, style);
  14656. }
  14657. if (hasStroke) {
  14658. doStrokePath(ctx, style);
  14659. }
  14660. }
  14661. }
  14662. if (lineDash) {
  14663. ctx.setLineDash([]);
  14664. }
  14665. }
  14666. function brushImage(ctx, el, style) {
  14667. var image = el.__image = createOrUpdateImage(style.image, el.__image, el, el.onload);
  14668. if (!image || !isImageReady(image)) {
  14669. return;
  14670. }
  14671. var x = style.x || 0;
  14672. var y = style.y || 0;
  14673. var width = el.getWidth();
  14674. var height = el.getHeight();
  14675. var aspect = image.width / image.height;
  14676. if (width == null && height != null) {
  14677. width = height * aspect;
  14678. }
  14679. else if (height == null && width != null) {
  14680. height = width / aspect;
  14681. }
  14682. else if (width == null && height == null) {
  14683. width = image.width;
  14684. height = image.height;
  14685. }
  14686. if (style.sWidth && style.sHeight) {
  14687. var sx = style.sx || 0;
  14688. var sy = style.sy || 0;
  14689. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  14690. }
  14691. else if (style.sx && style.sy) {
  14692. var sx = style.sx;
  14693. var sy = style.sy;
  14694. var sWidth = width - sx;
  14695. var sHeight = height - sy;
  14696. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  14697. }
  14698. else {
  14699. ctx.drawImage(image, x, y, width, height);
  14700. }
  14701. }
  14702. function brushText(ctx, el, style) {
  14703. var _a;
  14704. var text = style.text;
  14705. text != null && (text += '');
  14706. if (text) {
  14707. ctx.font = style.font || DEFAULT_FONT;
  14708. ctx.textAlign = style.textAlign;
  14709. ctx.textBaseline = style.textBaseline;
  14710. var lineDash = void 0;
  14711. var lineDashOffset = void 0;
  14712. if (ctx.setLineDash && style.lineDash) {
  14713. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  14714. }
  14715. if (lineDash) {
  14716. ctx.setLineDash(lineDash);
  14717. ctx.lineDashOffset = lineDashOffset;
  14718. }
  14719. if (style.strokeFirst) {
  14720. if (styleHasStroke(style)) {
  14721. ctx.strokeText(text, style.x, style.y);
  14722. }
  14723. if (styleHasFill(style)) {
  14724. ctx.fillText(text, style.x, style.y);
  14725. }
  14726. }
  14727. else {
  14728. if (styleHasFill(style)) {
  14729. ctx.fillText(text, style.x, style.y);
  14730. }
  14731. if (styleHasStroke(style)) {
  14732. ctx.strokeText(text, style.x, style.y);
  14733. }
  14734. }
  14735. if (lineDash) {
  14736. ctx.setLineDash([]);
  14737. }
  14738. }
  14739. }
  14740. var SHADOW_NUMBER_PROPS = ['shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  14741. var STROKE_PROPS = [
  14742. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  14743. ];
  14744. function bindCommonProps(ctx, style, prevStyle, forceSetAll, scope) {
  14745. var styleChanged = false;
  14746. if (!forceSetAll) {
  14747. prevStyle = prevStyle || {};
  14748. if (style === prevStyle) {
  14749. return false;
  14750. }
  14751. }
  14752. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14753. flushPathDrawn(ctx, scope);
  14754. styleChanged = true;
  14755. var opacity = Math.max(Math.min(style.opacity, 1), 0);
  14756. ctx.globalAlpha = isNaN(opacity) ? DEFAULT_COMMON_STYLE.opacity : opacity;
  14757. }
  14758. if (forceSetAll || style.blend !== prevStyle.blend) {
  14759. if (!styleChanged) {
  14760. flushPathDrawn(ctx, scope);
  14761. styleChanged = true;
  14762. }
  14763. ctx.globalCompositeOperation = style.blend || DEFAULT_COMMON_STYLE.blend;
  14764. }
  14765. for (var i = 0; i < SHADOW_NUMBER_PROPS.length; i++) {
  14766. var propName = SHADOW_NUMBER_PROPS[i];
  14767. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14768. if (!styleChanged) {
  14769. flushPathDrawn(ctx, scope);
  14770. styleChanged = true;
  14771. }
  14772. ctx[propName] = ctx.dpr * (style[propName] || 0);
  14773. }
  14774. }
  14775. if (forceSetAll || style.shadowColor !== prevStyle.shadowColor) {
  14776. if (!styleChanged) {
  14777. flushPathDrawn(ctx, scope);
  14778. styleChanged = true;
  14779. }
  14780. ctx.shadowColor = style.shadowColor || DEFAULT_COMMON_STYLE.shadowColor;
  14781. }
  14782. return styleChanged;
  14783. }
  14784. function bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetAll, scope) {
  14785. var style = getStyle(el, scope.inHover);
  14786. var prevStyle = forceSetAll
  14787. ? null
  14788. : (prevEl && getStyle(prevEl, scope.inHover) || {});
  14789. if (style === prevStyle) {
  14790. return false;
  14791. }
  14792. var styleChanged = bindCommonProps(ctx, style, prevStyle, forceSetAll, scope);
  14793. if (forceSetAll || style.fill !== prevStyle.fill) {
  14794. if (!styleChanged) {
  14795. flushPathDrawn(ctx, scope);
  14796. styleChanged = true;
  14797. }
  14798. isValidStrokeFillStyle(style.fill) && (ctx.fillStyle = style.fill);
  14799. }
  14800. if (forceSetAll || style.stroke !== prevStyle.stroke) {
  14801. if (!styleChanged) {
  14802. flushPathDrawn(ctx, scope);
  14803. styleChanged = true;
  14804. }
  14805. isValidStrokeFillStyle(style.stroke) && (ctx.strokeStyle = style.stroke);
  14806. }
  14807. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  14808. if (!styleChanged) {
  14809. flushPathDrawn(ctx, scope);
  14810. styleChanged = true;
  14811. }
  14812. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  14813. }
  14814. if (el.hasStroke()) {
  14815. var lineWidth = style.lineWidth;
  14816. var newLineWidth = lineWidth / ((style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1);
  14817. if (ctx.lineWidth !== newLineWidth) {
  14818. if (!styleChanged) {
  14819. flushPathDrawn(ctx, scope);
  14820. styleChanged = true;
  14821. }
  14822. ctx.lineWidth = newLineWidth;
  14823. }
  14824. }
  14825. for (var i = 0; i < STROKE_PROPS.length; i++) {
  14826. var prop = STROKE_PROPS[i];
  14827. var propName = prop[0];
  14828. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  14829. if (!styleChanged) {
  14830. flushPathDrawn(ctx, scope);
  14831. styleChanged = true;
  14832. }
  14833. ctx[propName] = style[propName] || prop[1];
  14834. }
  14835. }
  14836. return styleChanged;
  14837. }
  14838. function bindImageStyle(ctx, el, prevEl, forceSetAll, scope) {
  14839. return bindCommonProps(ctx, getStyle(el, scope.inHover), prevEl && getStyle(prevEl, scope.inHover), forceSetAll, scope);
  14840. }
  14841. function setContextTransform(ctx, el) {
  14842. var m = el.transform;
  14843. var dpr = ctx.dpr || 1;
  14844. if (m) {
  14845. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  14846. }
  14847. else {
  14848. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  14849. }
  14850. }
  14851. function updateClipStatus(clipPaths, ctx, scope) {
  14852. var allClipped = false;
  14853. for (var i = 0; i < clipPaths.length; i++) {
  14854. var clipPath = clipPaths[i];
  14855. allClipped = allClipped || clipPath.isZeroArea();
  14856. setContextTransform(ctx, clipPath);
  14857. ctx.beginPath();
  14858. clipPath.buildPath(ctx, clipPath.shape);
  14859. ctx.clip();
  14860. }
  14861. scope.allClipped = allClipped;
  14862. }
  14863. function isTransformChanged(m0, m1) {
  14864. if (m0 && m1) {
  14865. return m0[0] !== m1[0]
  14866. || m0[1] !== m1[1]
  14867. || m0[2] !== m1[2]
  14868. || m0[3] !== m1[3]
  14869. || m0[4] !== m1[4]
  14870. || m0[5] !== m1[5];
  14871. }
  14872. else if (!m0 && !m1) {
  14873. return false;
  14874. }
  14875. return true;
  14876. }
  14877. var DRAW_TYPE_PATH = 1;
  14878. var DRAW_TYPE_IMAGE = 2;
  14879. var DRAW_TYPE_TEXT = 3;
  14880. var DRAW_TYPE_INCREMENTAL = 4;
  14881. function canPathBatch(style) {
  14882. var hasFill = styleHasFill(style);
  14883. var hasStroke = styleHasStroke(style);
  14884. return !(style.lineDash
  14885. || !(+hasFill ^ +hasStroke)
  14886. || (hasFill && typeof style.fill !== 'string')
  14887. || (hasStroke && typeof style.stroke !== 'string')
  14888. || style.strokePercent < 1
  14889. || style.strokeOpacity < 1
  14890. || style.fillOpacity < 1);
  14891. }
  14892. function flushPathDrawn(ctx, scope) {
  14893. scope.batchFill && ctx.fill();
  14894. scope.batchStroke && ctx.stroke();
  14895. scope.batchFill = '';
  14896. scope.batchStroke = '';
  14897. }
  14898. function getStyle(el, inHover) {
  14899. return inHover ? (el.__hoverStyle || el.style) : el.style;
  14900. }
  14901. function brushSingle(ctx, el) {
  14902. brush(ctx, el, { inHover: false, viewWidth: 0, viewHeight: 0 }, true);
  14903. }
  14904. function brush(ctx, el, scope, isLast) {
  14905. var m = el.transform;
  14906. if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false)) {
  14907. el.__dirty &= ~REDRAW_BIT;
  14908. el.__isRendered = false;
  14909. return;
  14910. }
  14911. var clipPaths = el.__clipPaths;
  14912. var prevElClipPaths = scope.prevElClipPaths;
  14913. var forceSetTransform = false;
  14914. var forceSetStyle = false;
  14915. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  14916. if (prevElClipPaths && prevElClipPaths.length) {
  14917. flushPathDrawn(ctx, scope);
  14918. ctx.restore();
  14919. forceSetStyle = forceSetTransform = true;
  14920. scope.prevElClipPaths = null;
  14921. scope.allClipped = false;
  14922. scope.prevEl = null;
  14923. }
  14924. if (clipPaths && clipPaths.length) {
  14925. flushPathDrawn(ctx, scope);
  14926. ctx.save();
  14927. updateClipStatus(clipPaths, ctx, scope);
  14928. forceSetTransform = true;
  14929. }
  14930. scope.prevElClipPaths = clipPaths;
  14931. }
  14932. if (scope.allClipped) {
  14933. el.__isRendered = false;
  14934. return;
  14935. }
  14936. el.beforeBrush && el.beforeBrush();
  14937. el.innerBeforeBrush();
  14938. var prevEl = scope.prevEl;
  14939. if (!prevEl) {
  14940. forceSetStyle = forceSetTransform = true;
  14941. }
  14942. var canBatchPath = el instanceof Path
  14943. && el.autoBatch
  14944. && canPathBatch(el.style);
  14945. if (forceSetTransform || isTransformChanged(m, prevEl.transform)) {
  14946. flushPathDrawn(ctx, scope);
  14947. setContextTransform(ctx, el);
  14948. }
  14949. else if (!canBatchPath) {
  14950. flushPathDrawn(ctx, scope);
  14951. }
  14952. var style = getStyle(el, scope.inHover);
  14953. if (el instanceof Path) {
  14954. if (scope.lastDrawType !== DRAW_TYPE_PATH) {
  14955. forceSetStyle = true;
  14956. scope.lastDrawType = DRAW_TYPE_PATH;
  14957. }
  14958. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14959. if (!canBatchPath || (!scope.batchFill && !scope.batchStroke)) {
  14960. ctx.beginPath();
  14961. }
  14962. brushPath(ctx, el, style, canBatchPath);
  14963. if (canBatchPath) {
  14964. scope.batchFill = style.fill || '';
  14965. scope.batchStroke = style.stroke || '';
  14966. }
  14967. }
  14968. else {
  14969. if (el instanceof TSpan) {
  14970. if (scope.lastDrawType !== DRAW_TYPE_TEXT) {
  14971. forceSetStyle = true;
  14972. scope.lastDrawType = DRAW_TYPE_TEXT;
  14973. }
  14974. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  14975. brushText(ctx, el, style);
  14976. }
  14977. else if (el instanceof ZRImage) {
  14978. if (scope.lastDrawType !== DRAW_TYPE_IMAGE) {
  14979. forceSetStyle = true;
  14980. scope.lastDrawType = DRAW_TYPE_IMAGE;
  14981. }
  14982. bindImageStyle(ctx, el, prevEl, forceSetStyle, scope);
  14983. brushImage(ctx, el, style);
  14984. }
  14985. else if (el.getTemporalDisplayables) {
  14986. if (scope.lastDrawType !== DRAW_TYPE_INCREMENTAL) {
  14987. forceSetStyle = true;
  14988. scope.lastDrawType = DRAW_TYPE_INCREMENTAL;
  14989. }
  14990. brushIncremental(ctx, el, scope);
  14991. }
  14992. }
  14993. if (canBatchPath && isLast) {
  14994. flushPathDrawn(ctx, scope);
  14995. }
  14996. el.innerAfterBrush();
  14997. el.afterBrush && el.afterBrush();
  14998. scope.prevEl = el;
  14999. el.__dirty = 0;
  15000. el.__isRendered = true;
  15001. }
  15002. function brushIncremental(ctx, el, scope) {
  15003. var displayables = el.getDisplayables();
  15004. var temporalDisplayables = el.getTemporalDisplayables();
  15005. ctx.save();
  15006. var innerScope = {
  15007. prevElClipPaths: null,
  15008. prevEl: null,
  15009. allClipped: false,
  15010. viewWidth: scope.viewWidth,
  15011. viewHeight: scope.viewHeight,
  15012. inHover: scope.inHover
  15013. };
  15014. var i;
  15015. var len;
  15016. for (i = el.getCursor(), len = displayables.length; i < len; i++) {
  15017. var displayable = displayables[i];
  15018. displayable.beforeBrush && displayable.beforeBrush();
  15019. displayable.innerBeforeBrush();
  15020. brush(ctx, displayable, innerScope, i === len - 1);
  15021. displayable.innerAfterBrush();
  15022. displayable.afterBrush && displayable.afterBrush();
  15023. innerScope.prevEl = displayable;
  15024. }
  15025. for (var i_1 = 0, len_1 = temporalDisplayables.length; i_1 < len_1; i_1++) {
  15026. var displayable = temporalDisplayables[i_1];
  15027. displayable.beforeBrush && displayable.beforeBrush();
  15028. displayable.innerBeforeBrush();
  15029. brush(ctx, displayable, innerScope, i_1 === len_1 - 1);
  15030. displayable.innerAfterBrush();
  15031. displayable.afterBrush && displayable.afterBrush();
  15032. innerScope.prevEl = displayable;
  15033. }
  15034. el.clearTemporalDisplayables();
  15035. el.notClear = true;
  15036. ctx.restore();
  15037. }
  15038. function createDom(id, painter, dpr) {
  15039. var newDom = platformApi.createCanvas();
  15040. var width = painter.getWidth();
  15041. var height = painter.getHeight();
  15042. var newDomStyle = newDom.style;
  15043. if (newDomStyle) {
  15044. newDomStyle.position = 'absolute';
  15045. newDomStyle.left = '0';
  15046. newDomStyle.top = '0';
  15047. newDomStyle.width = width + 'px';
  15048. newDomStyle.height = height + 'px';
  15049. newDom.setAttribute('data-zr-dom-id', id);
  15050. }
  15051. newDom.width = width * dpr;
  15052. newDom.height = height * dpr;
  15053. return newDom;
  15054. }
  15055. var Layer = (function (_super) {
  15056. __extends(Layer, _super);
  15057. function Layer(id, painter, dpr) {
  15058. var _this = _super.call(this) || this;
  15059. _this.motionBlur = false;
  15060. _this.lastFrameAlpha = 0.7;
  15061. _this.dpr = 1;
  15062. _this.virtual = false;
  15063. _this.config = {};
  15064. _this.incremental = false;
  15065. _this.zlevel = 0;
  15066. _this.maxRepaintRectCount = 5;
  15067. _this.__dirty = true;
  15068. _this.__firstTimePaint = true;
  15069. _this.__used = false;
  15070. _this.__drawIndex = 0;
  15071. _this.__startIndex = 0;
  15072. _this.__endIndex = 0;
  15073. _this.__prevStartIndex = null;
  15074. _this.__prevEndIndex = null;
  15075. var dom;
  15076. dpr = dpr || devicePixelRatio;
  15077. if (typeof id === 'string') {
  15078. dom = createDom(id, painter, dpr);
  15079. }
  15080. else if (isObject(id)) {
  15081. dom = id;
  15082. id = dom.id;
  15083. }
  15084. _this.id = id;
  15085. _this.dom = dom;
  15086. var domStyle = dom.style;
  15087. if (domStyle) {
  15088. disableUserSelect(dom);
  15089. dom.onselectstart = function () { return false; };
  15090. domStyle.padding = '0';
  15091. domStyle.margin = '0';
  15092. domStyle.borderWidth = '0';
  15093. }
  15094. _this.painter = painter;
  15095. _this.dpr = dpr;
  15096. return _this;
  15097. }
  15098. Layer.prototype.getElementCount = function () {
  15099. return this.__endIndex - this.__startIndex;
  15100. };
  15101. Layer.prototype.afterBrush = function () {
  15102. this.__prevStartIndex = this.__startIndex;
  15103. this.__prevEndIndex = this.__endIndex;
  15104. };
  15105. Layer.prototype.initContext = function () {
  15106. this.ctx = this.dom.getContext('2d');
  15107. this.ctx.dpr = this.dpr;
  15108. };
  15109. Layer.prototype.setUnpainted = function () {
  15110. this.__firstTimePaint = true;
  15111. };
  15112. Layer.prototype.createBackBuffer = function () {
  15113. var dpr = this.dpr;
  15114. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  15115. this.ctxBack = this.domBack.getContext('2d');
  15116. if (dpr !== 1) {
  15117. this.ctxBack.scale(dpr, dpr);
  15118. }
  15119. };
  15120. Layer.prototype.createRepaintRects = function (displayList, prevList, viewWidth, viewHeight) {
  15121. if (this.__firstTimePaint) {
  15122. this.__firstTimePaint = false;
  15123. return null;
  15124. }
  15125. var mergedRepaintRects = [];
  15126. var maxRepaintRectCount = this.maxRepaintRectCount;
  15127. var full = false;
  15128. var pendingRect = new BoundingRect(0, 0, 0, 0);
  15129. function addRectToMergePool(rect) {
  15130. if (!rect.isFinite() || rect.isZero()) {
  15131. return;
  15132. }
  15133. if (mergedRepaintRects.length === 0) {
  15134. var boundingRect = new BoundingRect(0, 0, 0, 0);
  15135. boundingRect.copy(rect);
  15136. mergedRepaintRects.push(boundingRect);
  15137. }
  15138. else {
  15139. var isMerged = false;
  15140. var minDeltaArea = Infinity;
  15141. var bestRectToMergeIdx = 0;
  15142. for (var i = 0; i < mergedRepaintRects.length; ++i) {
  15143. var mergedRect = mergedRepaintRects[i];
  15144. if (mergedRect.intersect(rect)) {
  15145. var pendingRect_1 = new BoundingRect(0, 0, 0, 0);
  15146. pendingRect_1.copy(mergedRect);
  15147. pendingRect_1.union(rect);
  15148. mergedRepaintRects[i] = pendingRect_1;
  15149. isMerged = true;
  15150. break;
  15151. }
  15152. else if (full) {
  15153. pendingRect.copy(rect);
  15154. pendingRect.union(mergedRect);
  15155. var aArea = rect.width * rect.height;
  15156. var bArea = mergedRect.width * mergedRect.height;
  15157. var pendingArea = pendingRect.width * pendingRect.height;
  15158. var deltaArea = pendingArea - aArea - bArea;
  15159. if (deltaArea < minDeltaArea) {
  15160. minDeltaArea = deltaArea;
  15161. bestRectToMergeIdx = i;
  15162. }
  15163. }
  15164. }
  15165. if (full) {
  15166. mergedRepaintRects[bestRectToMergeIdx].union(rect);
  15167. isMerged = true;
  15168. }
  15169. if (!isMerged) {
  15170. var boundingRect = new BoundingRect(0, 0, 0, 0);
  15171. boundingRect.copy(rect);
  15172. mergedRepaintRects.push(boundingRect);
  15173. }
  15174. if (!full) {
  15175. full = mergedRepaintRects.length >= maxRepaintRectCount;
  15176. }
  15177. }
  15178. }
  15179. for (var i = this.__startIndex; i < this.__endIndex; ++i) {
  15180. var el = displayList[i];
  15181. if (el) {
  15182. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  15183. var prevRect = el.__isRendered && ((el.__dirty & REDRAW_BIT) || !shouldPaint)
  15184. ? el.getPrevPaintRect()
  15185. : null;
  15186. if (prevRect) {
  15187. addRectToMergePool(prevRect);
  15188. }
  15189. var curRect = shouldPaint && ((el.__dirty & REDRAW_BIT) || !el.__isRendered)
  15190. ? el.getPaintRect()
  15191. : null;
  15192. if (curRect) {
  15193. addRectToMergePool(curRect);
  15194. }
  15195. }
  15196. }
  15197. for (var i = this.__prevStartIndex; i < this.__prevEndIndex; ++i) {
  15198. var el = prevList[i];
  15199. var shouldPaint = el && el.shouldBePainted(viewWidth, viewHeight, true, true);
  15200. if (el && (!shouldPaint || !el.__zr) && el.__isRendered) {
  15201. var prevRect = el.getPrevPaintRect();
  15202. if (prevRect) {
  15203. addRectToMergePool(prevRect);
  15204. }
  15205. }
  15206. }
  15207. var hasIntersections;
  15208. do {
  15209. hasIntersections = false;
  15210. for (var i = 0; i < mergedRepaintRects.length;) {
  15211. if (mergedRepaintRects[i].isZero()) {
  15212. mergedRepaintRects.splice(i, 1);
  15213. continue;
  15214. }
  15215. for (var j = i + 1; j < mergedRepaintRects.length;) {
  15216. if (mergedRepaintRects[i].intersect(mergedRepaintRects[j])) {
  15217. hasIntersections = true;
  15218. mergedRepaintRects[i].union(mergedRepaintRects[j]);
  15219. mergedRepaintRects.splice(j, 1);
  15220. }
  15221. else {
  15222. j++;
  15223. }
  15224. }
  15225. i++;
  15226. }
  15227. } while (hasIntersections);
  15228. this._paintRects = mergedRepaintRects;
  15229. return mergedRepaintRects;
  15230. };
  15231. Layer.prototype.debugGetPaintRects = function () {
  15232. return (this._paintRects || []).slice();
  15233. };
  15234. Layer.prototype.resize = function (width, height) {
  15235. var dpr = this.dpr;
  15236. var dom = this.dom;
  15237. var domStyle = dom.style;
  15238. var domBack = this.domBack;
  15239. if (domStyle) {
  15240. domStyle.width = width + 'px';
  15241. domStyle.height = height + 'px';
  15242. }
  15243. dom.width = width * dpr;
  15244. dom.height = height * dpr;
  15245. if (domBack) {
  15246. domBack.width = width * dpr;
  15247. domBack.height = height * dpr;
  15248. if (dpr !== 1) {
  15249. this.ctxBack.scale(dpr, dpr);
  15250. }
  15251. }
  15252. };
  15253. Layer.prototype.clear = function (clearAll, clearColor, repaintRects) {
  15254. var dom = this.dom;
  15255. var ctx = this.ctx;
  15256. var width = dom.width;
  15257. var height = dom.height;
  15258. clearColor = clearColor || this.clearColor;
  15259. var haveMotionBLur = this.motionBlur && !clearAll;
  15260. var lastFrameAlpha = this.lastFrameAlpha;
  15261. var dpr = this.dpr;
  15262. var self = this;
  15263. if (haveMotionBLur) {
  15264. if (!this.domBack) {
  15265. this.createBackBuffer();
  15266. }
  15267. this.ctxBack.globalCompositeOperation = 'copy';
  15268. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  15269. }
  15270. var domBack = this.domBack;
  15271. function doClear(x, y, width, height) {
  15272. ctx.clearRect(x, y, width, height);
  15273. if (clearColor && clearColor !== 'transparent') {
  15274. var clearColorGradientOrPattern = void 0;
  15275. if (isGradientObject(clearColor)) {
  15276. var shouldCache = clearColor.global || (clearColor.__width === width
  15277. && clearColor.__height === height);
  15278. clearColorGradientOrPattern = shouldCache
  15279. && clearColor.__canvasGradient
  15280. || getCanvasGradient(ctx, clearColor, {
  15281. x: 0,
  15282. y: 0,
  15283. width: width,
  15284. height: height
  15285. });
  15286. clearColor.__canvasGradient = clearColorGradientOrPattern;
  15287. clearColor.__width = width;
  15288. clearColor.__height = height;
  15289. }
  15290. else if (isImagePatternObject(clearColor)) {
  15291. clearColor.scaleX = clearColor.scaleX || dpr;
  15292. clearColor.scaleY = clearColor.scaleY || dpr;
  15293. clearColorGradientOrPattern = createCanvasPattern(ctx, clearColor, {
  15294. dirty: function () {
  15295. self.setUnpainted();
  15296. self.painter.refresh();
  15297. }
  15298. });
  15299. }
  15300. ctx.save();
  15301. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  15302. ctx.fillRect(x, y, width, height);
  15303. ctx.restore();
  15304. }
  15305. if (haveMotionBLur) {
  15306. ctx.save();
  15307. ctx.globalAlpha = lastFrameAlpha;
  15308. ctx.drawImage(domBack, x, y, width, height);
  15309. ctx.restore();
  15310. }
  15311. }
  15312. if (!repaintRects || haveMotionBLur) {
  15313. doClear(0, 0, width, height);
  15314. }
  15315. else if (repaintRects.length) {
  15316. each(repaintRects, function (rect) {
  15317. doClear(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  15318. });
  15319. }
  15320. };
  15321. return Layer;
  15322. }(Eventful));
  15323. var HOVER_LAYER_ZLEVEL = 1e5;
  15324. var CANVAS_ZLEVEL = 314159;
  15325. var EL_AFTER_INCREMENTAL_INC = 0.01;
  15326. var INCREMENTAL_INC = 0.001;
  15327. function isLayerValid(layer) {
  15328. if (!layer) {
  15329. return false;
  15330. }
  15331. if (layer.__builtin__) {
  15332. return true;
  15333. }
  15334. if (typeof (layer.resize) !== 'function'
  15335. || typeof (layer.refresh) !== 'function') {
  15336. return false;
  15337. }
  15338. return true;
  15339. }
  15340. function createRoot(width, height) {
  15341. var domRoot = document.createElement('div');
  15342. domRoot.style.cssText = [
  15343. 'position:relative',
  15344. 'width:' + width + 'px',
  15345. 'height:' + height + 'px',
  15346. 'padding:0',
  15347. 'margin:0',
  15348. 'border-width:0'
  15349. ].join(';') + ';';
  15350. return domRoot;
  15351. }
  15352. var CanvasPainter = (function () {
  15353. function CanvasPainter(root, storage, opts, id) {
  15354. this.type = 'canvas';
  15355. this._zlevelList = [];
  15356. this._prevDisplayList = [];
  15357. this._layers = {};
  15358. this._layerConfig = {};
  15359. this._needsManuallyCompositing = false;
  15360. this.type = 'canvas';
  15361. var singleCanvas = !root.nodeName
  15362. || root.nodeName.toUpperCase() === 'CANVAS';
  15363. this._opts = opts = extend({}, opts || {});
  15364. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  15365. this._singleCanvas = singleCanvas;
  15366. this.root = root;
  15367. var rootStyle = root.style;
  15368. if (rootStyle) {
  15369. disableUserSelect(root);
  15370. root.innerHTML = '';
  15371. }
  15372. this.storage = storage;
  15373. var zlevelList = this._zlevelList;
  15374. this._prevDisplayList = [];
  15375. var layers = this._layers;
  15376. if (!singleCanvas) {
  15377. this._width = getSize(root, 0, opts);
  15378. this._height = getSize(root, 1, opts);
  15379. var domRoot = this._domRoot = createRoot(this._width, this._height);
  15380. root.appendChild(domRoot);
  15381. }
  15382. else {
  15383. var rootCanvas = root;
  15384. var width = rootCanvas.width;
  15385. var height = rootCanvas.height;
  15386. if (opts.width != null) {
  15387. width = opts.width;
  15388. }
  15389. if (opts.height != null) {
  15390. height = opts.height;
  15391. }
  15392. this.dpr = opts.devicePixelRatio || 1;
  15393. rootCanvas.width = width * this.dpr;
  15394. rootCanvas.height = height * this.dpr;
  15395. this._width = width;
  15396. this._height = height;
  15397. var mainLayer = new Layer(rootCanvas, this, this.dpr);
  15398. mainLayer.__builtin__ = true;
  15399. mainLayer.initContext();
  15400. layers[CANVAS_ZLEVEL] = mainLayer;
  15401. mainLayer.zlevel = CANVAS_ZLEVEL;
  15402. zlevelList.push(CANVAS_ZLEVEL);
  15403. this._domRoot = root;
  15404. }
  15405. }
  15406. CanvasPainter.prototype.getType = function () {
  15407. return 'canvas';
  15408. };
  15409. CanvasPainter.prototype.isSingleCanvas = function () {
  15410. return this._singleCanvas;
  15411. };
  15412. CanvasPainter.prototype.getViewportRoot = function () {
  15413. return this._domRoot;
  15414. };
  15415. CanvasPainter.prototype.getViewportRootOffset = function () {
  15416. var viewportRoot = this.getViewportRoot();
  15417. if (viewportRoot) {
  15418. return {
  15419. offsetLeft: viewportRoot.offsetLeft || 0,
  15420. offsetTop: viewportRoot.offsetTop || 0
  15421. };
  15422. }
  15423. };
  15424. CanvasPainter.prototype.refresh = function (paintAll) {
  15425. var list = this.storage.getDisplayList(true);
  15426. var prevList = this._prevDisplayList;
  15427. var zlevelList = this._zlevelList;
  15428. this._redrawId = Math.random();
  15429. this._paintList(list, prevList, paintAll, this._redrawId);
  15430. for (var i = 0; i < zlevelList.length; i++) {
  15431. var z = zlevelList[i];
  15432. var layer = this._layers[z];
  15433. if (!layer.__builtin__ && layer.refresh) {
  15434. var clearColor = i === 0 ? this._backgroundColor : null;
  15435. layer.refresh(clearColor);
  15436. }
  15437. }
  15438. if (this._opts.useDirtyRect) {
  15439. this._prevDisplayList = list.slice();
  15440. }
  15441. return this;
  15442. };
  15443. CanvasPainter.prototype.refreshHover = function () {
  15444. this._paintHoverList(this.storage.getDisplayList(false));
  15445. };
  15446. CanvasPainter.prototype._paintHoverList = function (list) {
  15447. var len = list.length;
  15448. var hoverLayer = this._hoverlayer;
  15449. hoverLayer && hoverLayer.clear();
  15450. if (!len) {
  15451. return;
  15452. }
  15453. var scope = {
  15454. inHover: true,
  15455. viewWidth: this._width,
  15456. viewHeight: this._height
  15457. };
  15458. var ctx;
  15459. for (var i = 0; i < len; i++) {
  15460. var el = list[i];
  15461. if (el.__inHover) {
  15462. if (!hoverLayer) {
  15463. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  15464. }
  15465. if (!ctx) {
  15466. ctx = hoverLayer.ctx;
  15467. ctx.save();
  15468. }
  15469. brush(ctx, el, scope, i === len - 1);
  15470. }
  15471. }
  15472. if (ctx) {
  15473. ctx.restore();
  15474. }
  15475. };
  15476. CanvasPainter.prototype.getHoverLayer = function () {
  15477. return this.getLayer(HOVER_LAYER_ZLEVEL);
  15478. };
  15479. CanvasPainter.prototype.paintOne = function (ctx, el) {
  15480. brushSingle(ctx, el);
  15481. };
  15482. CanvasPainter.prototype._paintList = function (list, prevList, paintAll, redrawId) {
  15483. if (this._redrawId !== redrawId) {
  15484. return;
  15485. }
  15486. paintAll = paintAll || false;
  15487. this._updateLayerStatus(list);
  15488. var _a = this._doPaintList(list, prevList, paintAll), finished = _a.finished, needsRefreshHover = _a.needsRefreshHover;
  15489. if (this._needsManuallyCompositing) {
  15490. this._compositeManually();
  15491. }
  15492. if (needsRefreshHover) {
  15493. this._paintHoverList(list);
  15494. }
  15495. if (!finished) {
  15496. var self_1 = this;
  15497. requestAnimationFrame$1(function () {
  15498. self_1._paintList(list, prevList, paintAll, redrawId);
  15499. });
  15500. }
  15501. else {
  15502. this.eachLayer(function (layer) {
  15503. layer.afterBrush && layer.afterBrush();
  15504. });
  15505. }
  15506. };
  15507. CanvasPainter.prototype._compositeManually = function () {
  15508. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  15509. var width = this._domRoot.width;
  15510. var height = this._domRoot.height;
  15511. ctx.clearRect(0, 0, width, height);
  15512. this.eachBuiltinLayer(function (layer) {
  15513. if (layer.virtual) {
  15514. ctx.drawImage(layer.dom, 0, 0, width, height);
  15515. }
  15516. });
  15517. };
  15518. CanvasPainter.prototype._doPaintList = function (list, prevList, paintAll) {
  15519. var _this = this;
  15520. var layerList = [];
  15521. var useDirtyRect = this._opts.useDirtyRect;
  15522. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  15523. var zlevel = this._zlevelList[zi];
  15524. var layer = this._layers[zlevel];
  15525. if (layer.__builtin__
  15526. && layer !== this._hoverlayer
  15527. && (layer.__dirty || paintAll)) {
  15528. layerList.push(layer);
  15529. }
  15530. }
  15531. var finished = true;
  15532. var needsRefreshHover = false;
  15533. var _loop_1 = function (k) {
  15534. var layer = layerList[k];
  15535. var ctx = layer.ctx;
  15536. var repaintRects = useDirtyRect
  15537. && layer.createRepaintRects(list, prevList, this_1._width, this_1._height);
  15538. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  15539. var useTimer = !paintAll && layer.incremental && Date.now;
  15540. var startTime = useTimer && Date.now();
  15541. var clearColor = layer.zlevel === this_1._zlevelList[0]
  15542. ? this_1._backgroundColor : null;
  15543. if (layer.__startIndex === layer.__endIndex) {
  15544. layer.clear(false, clearColor, repaintRects);
  15545. }
  15546. else if (start === layer.__startIndex) {
  15547. var firstEl = list[start];
  15548. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  15549. layer.clear(false, clearColor, repaintRects);
  15550. }
  15551. }
  15552. if (start === -1) {
  15553. console.error('For some unknown reason. drawIndex is -1');
  15554. start = layer.__startIndex;
  15555. }
  15556. var i;
  15557. var repaint = function (repaintRect) {
  15558. var scope = {
  15559. inHover: false,
  15560. allClipped: false,
  15561. prevEl: null,
  15562. viewWidth: _this._width,
  15563. viewHeight: _this._height
  15564. };
  15565. for (i = start; i < layer.__endIndex; i++) {
  15566. var el = list[i];
  15567. if (el.__inHover) {
  15568. needsRefreshHover = true;
  15569. }
  15570. _this._doPaintEl(el, layer, useDirtyRect, repaintRect, scope, i === layer.__endIndex - 1);
  15571. if (useTimer) {
  15572. var dTime = Date.now() - startTime;
  15573. if (dTime > 15) {
  15574. break;
  15575. }
  15576. }
  15577. }
  15578. if (scope.prevElClipPaths) {
  15579. ctx.restore();
  15580. }
  15581. };
  15582. if (repaintRects) {
  15583. if (repaintRects.length === 0) {
  15584. i = layer.__endIndex;
  15585. }
  15586. else {
  15587. var dpr = this_1.dpr;
  15588. for (var r = 0; r < repaintRects.length; ++r) {
  15589. var rect = repaintRects[r];
  15590. ctx.save();
  15591. ctx.beginPath();
  15592. ctx.rect(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  15593. ctx.clip();
  15594. repaint(rect);
  15595. ctx.restore();
  15596. }
  15597. }
  15598. }
  15599. else {
  15600. ctx.save();
  15601. repaint();
  15602. ctx.restore();
  15603. }
  15604. layer.__drawIndex = i;
  15605. if (layer.__drawIndex < layer.__endIndex) {
  15606. finished = false;
  15607. }
  15608. };
  15609. var this_1 = this;
  15610. for (var k = 0; k < layerList.length; k++) {
  15611. _loop_1(k);
  15612. }
  15613. if (env.wxa) {
  15614. each(this._layers, function (layer) {
  15615. if (layer && layer.ctx && layer.ctx.draw) {
  15616. layer.ctx.draw();
  15617. }
  15618. });
  15619. }
  15620. return {
  15621. finished: finished,
  15622. needsRefreshHover: needsRefreshHover
  15623. };
  15624. };
  15625. CanvasPainter.prototype._doPaintEl = function (el, currentLayer, useDirtyRect, repaintRect, scope, isLast) {
  15626. var ctx = currentLayer.ctx;
  15627. if (useDirtyRect) {
  15628. var paintRect = el.getPaintRect();
  15629. if (!repaintRect || paintRect && paintRect.intersect(repaintRect)) {
  15630. brush(ctx, el, scope, isLast);
  15631. el.setPrevPaintRect(paintRect);
  15632. }
  15633. }
  15634. else {
  15635. brush(ctx, el, scope, isLast);
  15636. }
  15637. };
  15638. CanvasPainter.prototype.getLayer = function (zlevel, virtual) {
  15639. if (this._singleCanvas && !this._needsManuallyCompositing) {
  15640. zlevel = CANVAS_ZLEVEL;
  15641. }
  15642. var layer = this._layers[zlevel];
  15643. if (!layer) {
  15644. layer = new Layer('zr_' + zlevel, this, this.dpr);
  15645. layer.zlevel = zlevel;
  15646. layer.__builtin__ = true;
  15647. if (this._layerConfig[zlevel]) {
  15648. merge(layer, this._layerConfig[zlevel], true);
  15649. }
  15650. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  15651. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  15652. }
  15653. if (virtual) {
  15654. layer.virtual = virtual;
  15655. }
  15656. this.insertLayer(zlevel, layer);
  15657. layer.initContext();
  15658. }
  15659. return layer;
  15660. };
  15661. CanvasPainter.prototype.insertLayer = function (zlevel, layer) {
  15662. var layersMap = this._layers;
  15663. var zlevelList = this._zlevelList;
  15664. var len = zlevelList.length;
  15665. var domRoot = this._domRoot;
  15666. var prevLayer = null;
  15667. var i = -1;
  15668. if (layersMap[zlevel]) {
  15669. {
  15670. logError('ZLevel ' + zlevel + ' has been used already');
  15671. }
  15672. return;
  15673. }
  15674. if (!isLayerValid(layer)) {
  15675. {
  15676. logError('Layer of zlevel ' + zlevel + ' is not valid');
  15677. }
  15678. return;
  15679. }
  15680. if (len > 0 && zlevel > zlevelList[0]) {
  15681. for (i = 0; i < len - 1; i++) {
  15682. if (zlevelList[i] < zlevel
  15683. && zlevelList[i + 1] > zlevel) {
  15684. break;
  15685. }
  15686. }
  15687. prevLayer = layersMap[zlevelList[i]];
  15688. }
  15689. zlevelList.splice(i + 1, 0, zlevel);
  15690. layersMap[zlevel] = layer;
  15691. if (!layer.virtual) {
  15692. if (prevLayer) {
  15693. var prevDom = prevLayer.dom;
  15694. if (prevDom.nextSibling) {
  15695. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  15696. }
  15697. else {
  15698. domRoot.appendChild(layer.dom);
  15699. }
  15700. }
  15701. else {
  15702. if (domRoot.firstChild) {
  15703. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  15704. }
  15705. else {
  15706. domRoot.appendChild(layer.dom);
  15707. }
  15708. }
  15709. }
  15710. layer.painter || (layer.painter = this);
  15711. };
  15712. CanvasPainter.prototype.eachLayer = function (cb, context) {
  15713. var zlevelList = this._zlevelList;
  15714. for (var i = 0; i < zlevelList.length; i++) {
  15715. var z = zlevelList[i];
  15716. cb.call(context, this._layers[z], z);
  15717. }
  15718. };
  15719. CanvasPainter.prototype.eachBuiltinLayer = function (cb, context) {
  15720. var zlevelList = this._zlevelList;
  15721. for (var i = 0; i < zlevelList.length; i++) {
  15722. var z = zlevelList[i];
  15723. var layer = this._layers[z];
  15724. if (layer.__builtin__) {
  15725. cb.call(context, layer, z);
  15726. }
  15727. }
  15728. };
  15729. CanvasPainter.prototype.eachOtherLayer = function (cb, context) {
  15730. var zlevelList = this._zlevelList;
  15731. for (var i = 0; i < zlevelList.length; i++) {
  15732. var z = zlevelList[i];
  15733. var layer = this._layers[z];
  15734. if (!layer.__builtin__) {
  15735. cb.call(context, layer, z);
  15736. }
  15737. }
  15738. };
  15739. CanvasPainter.prototype.getLayers = function () {
  15740. return this._layers;
  15741. };
  15742. CanvasPainter.prototype._updateLayerStatus = function (list) {
  15743. this.eachBuiltinLayer(function (layer, z) {
  15744. layer.__dirty = layer.__used = false;
  15745. });
  15746. function updatePrevLayer(idx) {
  15747. if (prevLayer) {
  15748. if (prevLayer.__endIndex !== idx) {
  15749. prevLayer.__dirty = true;
  15750. }
  15751. prevLayer.__endIndex = idx;
  15752. }
  15753. }
  15754. if (this._singleCanvas) {
  15755. for (var i_1 = 1; i_1 < list.length; i_1++) {
  15756. var el = list[i_1];
  15757. if (el.zlevel !== list[i_1 - 1].zlevel || el.incremental) {
  15758. this._needsManuallyCompositing = true;
  15759. break;
  15760. }
  15761. }
  15762. }
  15763. var prevLayer = null;
  15764. var incrementalLayerCount = 0;
  15765. var prevZlevel;
  15766. var i;
  15767. for (i = 0; i < list.length; i++) {
  15768. var el = list[i];
  15769. var zlevel = el.zlevel;
  15770. var layer = void 0;
  15771. if (prevZlevel !== zlevel) {
  15772. prevZlevel = zlevel;
  15773. incrementalLayerCount = 0;
  15774. }
  15775. if (el.incremental) {
  15776. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  15777. layer.incremental = true;
  15778. incrementalLayerCount = 1;
  15779. }
  15780. else {
  15781. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  15782. }
  15783. if (!layer.__builtin__) {
  15784. logError('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  15785. }
  15786. if (layer !== prevLayer) {
  15787. layer.__used = true;
  15788. if (layer.__startIndex !== i) {
  15789. layer.__dirty = true;
  15790. }
  15791. layer.__startIndex = i;
  15792. if (!layer.incremental) {
  15793. layer.__drawIndex = i;
  15794. }
  15795. else {
  15796. layer.__drawIndex = -1;
  15797. }
  15798. updatePrevLayer(i);
  15799. prevLayer = layer;
  15800. }
  15801. if ((el.__dirty & REDRAW_BIT) && !el.__inHover) {
  15802. layer.__dirty = true;
  15803. if (layer.incremental && layer.__drawIndex < 0) {
  15804. layer.__drawIndex = i;
  15805. }
  15806. }
  15807. }
  15808. updatePrevLayer(i);
  15809. this.eachBuiltinLayer(function (layer, z) {
  15810. if (!layer.__used && layer.getElementCount() > 0) {
  15811. layer.__dirty = true;
  15812. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  15813. }
  15814. if (layer.__dirty && layer.__drawIndex < 0) {
  15815. layer.__drawIndex = layer.__startIndex;
  15816. }
  15817. });
  15818. };
  15819. CanvasPainter.prototype.clear = function () {
  15820. this.eachBuiltinLayer(this._clearLayer);
  15821. return this;
  15822. };
  15823. CanvasPainter.prototype._clearLayer = function (layer) {
  15824. layer.clear();
  15825. };
  15826. CanvasPainter.prototype.setBackgroundColor = function (backgroundColor) {
  15827. this._backgroundColor = backgroundColor;
  15828. each(this._layers, function (layer) {
  15829. layer.setUnpainted();
  15830. });
  15831. };
  15832. CanvasPainter.prototype.configLayer = function (zlevel, config) {
  15833. if (config) {
  15834. var layerConfig = this._layerConfig;
  15835. if (!layerConfig[zlevel]) {
  15836. layerConfig[zlevel] = config;
  15837. }
  15838. else {
  15839. merge(layerConfig[zlevel], config, true);
  15840. }
  15841. for (var i = 0; i < this._zlevelList.length; i++) {
  15842. var _zlevel = this._zlevelList[i];
  15843. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  15844. var layer = this._layers[_zlevel];
  15845. merge(layer, layerConfig[zlevel], true);
  15846. }
  15847. }
  15848. }
  15849. };
  15850. CanvasPainter.prototype.delLayer = function (zlevel) {
  15851. var layers = this._layers;
  15852. var zlevelList = this._zlevelList;
  15853. var layer = layers[zlevel];
  15854. if (!layer) {
  15855. return;
  15856. }
  15857. layer.dom.parentNode.removeChild(layer.dom);
  15858. delete layers[zlevel];
  15859. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  15860. };
  15861. CanvasPainter.prototype.resize = function (width, height) {
  15862. if (!this._domRoot.style) {
  15863. if (width == null || height == null) {
  15864. return;
  15865. }
  15866. this._width = width;
  15867. this._height = height;
  15868. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  15869. }
  15870. else {
  15871. var domRoot = this._domRoot;
  15872. domRoot.style.display = 'none';
  15873. var opts = this._opts;
  15874. var root = this.root;
  15875. width != null && (opts.width = width);
  15876. height != null && (opts.height = height);
  15877. width = getSize(root, 0, opts);
  15878. height = getSize(root, 1, opts);
  15879. domRoot.style.display = '';
  15880. if (this._width !== width || height !== this._height) {
  15881. domRoot.style.width = width + 'px';
  15882. domRoot.style.height = height + 'px';
  15883. for (var id in this._layers) {
  15884. if (this._layers.hasOwnProperty(id)) {
  15885. this._layers[id].resize(width, height);
  15886. }
  15887. }
  15888. this.refresh(true);
  15889. }
  15890. this._width = width;
  15891. this._height = height;
  15892. }
  15893. return this;
  15894. };
  15895. CanvasPainter.prototype.clearLayer = function (zlevel) {
  15896. var layer = this._layers[zlevel];
  15897. if (layer) {
  15898. layer.clear();
  15899. }
  15900. };
  15901. CanvasPainter.prototype.dispose = function () {
  15902. this.root.innerHTML = '';
  15903. this.root =
  15904. this.storage =
  15905. this._domRoot =
  15906. this._layers = null;
  15907. };
  15908. CanvasPainter.prototype.getRenderedCanvas = function (opts) {
  15909. opts = opts || {};
  15910. if (this._singleCanvas && !this._compositeManually) {
  15911. return this._layers[CANVAS_ZLEVEL].dom;
  15912. }
  15913. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  15914. imageLayer.initContext();
  15915. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  15916. var ctx = imageLayer.ctx;
  15917. if (opts.pixelRatio <= this.dpr) {
  15918. this.refresh();
  15919. var width_1 = imageLayer.dom.width;
  15920. var height_1 = imageLayer.dom.height;
  15921. this.eachLayer(function (layer) {
  15922. if (layer.__builtin__) {
  15923. ctx.drawImage(layer.dom, 0, 0, width_1, height_1);
  15924. }
  15925. else if (layer.renderToCanvas) {
  15926. ctx.save();
  15927. layer.renderToCanvas(ctx);
  15928. ctx.restore();
  15929. }
  15930. });
  15931. }
  15932. else {
  15933. var scope = {
  15934. inHover: false,
  15935. viewWidth: this._width,
  15936. viewHeight: this._height
  15937. };
  15938. var displayList = this.storage.getDisplayList(true);
  15939. for (var i = 0, len = displayList.length; i < len; i++) {
  15940. var el = displayList[i];
  15941. brush(ctx, el, scope, i === len - 1);
  15942. }
  15943. }
  15944. return imageLayer.dom;
  15945. };
  15946. CanvasPainter.prototype.getWidth = function () {
  15947. return this._width;
  15948. };
  15949. CanvasPainter.prototype.getHeight = function () {
  15950. return this._height;
  15951. };
  15952. return CanvasPainter;
  15953. }());
  15954. var mathSin$4 = Math.sin;
  15955. var mathCos$4 = Math.cos;
  15956. var PI$5 = Math.PI;
  15957. var PI2$6 = Math.PI * 2;
  15958. var degree = 180 / PI$5;
  15959. var SVGPathRebuilder = (function () {
  15960. function SVGPathRebuilder() {
  15961. }
  15962. SVGPathRebuilder.prototype.reset = function (precision) {
  15963. this._start = true;
  15964. this._d = [];
  15965. this._str = '';
  15966. this._p = Math.pow(10, precision || 4);
  15967. };
  15968. SVGPathRebuilder.prototype.moveTo = function (x, y) {
  15969. this._add('M', x, y);
  15970. };
  15971. SVGPathRebuilder.prototype.lineTo = function (x, y) {
  15972. this._add('L', x, y);
  15973. };
  15974. SVGPathRebuilder.prototype.bezierCurveTo = function (x, y, x2, y2, x3, y3) {
  15975. this._add('C', x, y, x2, y2, x3, y3);
  15976. };
  15977. SVGPathRebuilder.prototype.quadraticCurveTo = function (x, y, x2, y2) {
  15978. this._add('Q', x, y, x2, y2);
  15979. };
  15980. SVGPathRebuilder.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  15981. this.ellipse(cx, cy, r, r, 0, startAngle, endAngle, anticlockwise);
  15982. };
  15983. SVGPathRebuilder.prototype.ellipse = function (cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise) {
  15984. var dTheta = endAngle - startAngle;
  15985. var clockwise = !anticlockwise;
  15986. var dThetaPositive = Math.abs(dTheta);
  15987. var isCircle = isAroundZero$1(dThetaPositive - PI2$6)
  15988. || (clockwise ? dTheta >= PI2$6 : -dTheta >= PI2$6);
  15989. var unifiedTheta = dTheta > 0 ? dTheta % PI2$6 : (dTheta % PI2$6 + PI2$6);
  15990. var large = false;
  15991. if (isCircle) {
  15992. large = true;
  15993. }
  15994. else if (isAroundZero$1(dThetaPositive)) {
  15995. large = false;
  15996. }
  15997. else {
  15998. large = (unifiedTheta >= PI$5) === !!clockwise;
  15999. }
  16000. var x0 = cx + rx * mathCos$4(startAngle);
  16001. var y0 = cy + ry * mathSin$4(startAngle);
  16002. if (this._start) {
  16003. this._add('M', x0, y0);
  16004. }
  16005. var xRot = Math.round(psi * degree);
  16006. if (isCircle) {
  16007. var p = 1 / this._p;
  16008. var dTheta_1 = (clockwise ? 1 : -1) * (PI2$6 - p);
  16009. this._add('A', rx, ry, xRot, 1, +clockwise, cx + rx * mathCos$4(startAngle + dTheta_1), cy + ry * mathSin$4(startAngle + dTheta_1));
  16010. if (p > 1e-2) {
  16011. this._add('A', rx, ry, xRot, 0, +clockwise, x0, y0);
  16012. }
  16013. }
  16014. else {
  16015. var x = cx + rx * mathCos$4(endAngle);
  16016. var y = cy + ry * mathSin$4(endAngle);
  16017. this._add('A', rx, ry, xRot, +large, +clockwise, x, y);
  16018. }
  16019. };
  16020. SVGPathRebuilder.prototype.rect = function (x, y, w, h) {
  16021. this._add('M', x, y);
  16022. this._add('l', w, 0);
  16023. this._add('l', 0, h);
  16024. this._add('l', -w, 0);
  16025. this._add('Z');
  16026. };
  16027. SVGPathRebuilder.prototype.closePath = function () {
  16028. if (this._d.length > 0) {
  16029. this._add('Z');
  16030. }
  16031. };
  16032. SVGPathRebuilder.prototype._add = function (cmd, a, b, c, d, e, f, g, h) {
  16033. var vals = [];
  16034. var p = this._p;
  16035. for (var i = 1; i < arguments.length; i++) {
  16036. var val = arguments[i];
  16037. if (isNaN(val)) {
  16038. this._invalid = true;
  16039. return;
  16040. }
  16041. vals.push(Math.round(val * p) / p);
  16042. }
  16043. this._d.push(cmd + vals.join(' '));
  16044. this._start = cmd === 'Z';
  16045. };
  16046. SVGPathRebuilder.prototype.generateStr = function () {
  16047. this._str = this._invalid ? '' : this._d.join('');
  16048. this._d = [];
  16049. };
  16050. SVGPathRebuilder.prototype.getStr = function () {
  16051. return this._str;
  16052. };
  16053. return SVGPathRebuilder;
  16054. }());
  16055. var NONE = 'none';
  16056. var mathRound$1 = Math.round;
  16057. function pathHasFill(style) {
  16058. var fill = style.fill;
  16059. return fill != null && fill !== NONE;
  16060. }
  16061. function pathHasStroke(style) {
  16062. var stroke = style.stroke;
  16063. return stroke != null && stroke !== NONE;
  16064. }
  16065. var strokeProps = ['lineCap', 'miterLimit', 'lineJoin'];
  16066. var svgStrokeProps = map(strokeProps, function (prop) { return "stroke-" + prop.toLowerCase(); });
  16067. function mapStyleToAttrs(updateAttr, style, el, forceUpdate) {
  16068. var opacity = style.opacity == null ? 1 : style.opacity;
  16069. if (el instanceof ZRImage) {
  16070. updateAttr('opacity', opacity);
  16071. return;
  16072. }
  16073. if (pathHasFill(style)) {
  16074. var fill = normalizeColor(style.fill);
  16075. updateAttr('fill', fill.color);
  16076. var fillOpacity = style.fillOpacity != null
  16077. ? style.fillOpacity * fill.opacity * opacity
  16078. : fill.opacity * opacity;
  16079. if (forceUpdate || fillOpacity < 1) {
  16080. updateAttr('fill-opacity', fillOpacity);
  16081. }
  16082. }
  16083. else {
  16084. updateAttr('fill', NONE);
  16085. }
  16086. if (pathHasStroke(style)) {
  16087. var stroke = normalizeColor(style.stroke);
  16088. updateAttr('stroke', stroke.color);
  16089. var strokeScale = style.strokeNoScale
  16090. ? el.getLineScale()
  16091. : 1;
  16092. var strokeWidth = (strokeScale ? (style.lineWidth || 0) / strokeScale : 0);
  16093. var strokeOpacity = style.strokeOpacity != null
  16094. ? style.strokeOpacity * stroke.opacity * opacity
  16095. : stroke.opacity * opacity;
  16096. var strokeFirst = style.strokeFirst;
  16097. if (forceUpdate || strokeWidth !== 1) {
  16098. updateAttr('stroke-width', strokeWidth);
  16099. }
  16100. if (forceUpdate || strokeFirst) {
  16101. updateAttr('paint-order', strokeFirst ? 'stroke' : 'fill');
  16102. }
  16103. if (forceUpdate || strokeOpacity < 1) {
  16104. updateAttr('stroke-opacity', strokeOpacity);
  16105. }
  16106. if (style.lineDash) {
  16107. var _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  16108. if (lineDash) {
  16109. lineDashOffset = mathRound$1(lineDashOffset || 0);
  16110. updateAttr('stroke-dasharray', lineDash.join(','));
  16111. if (lineDashOffset || forceUpdate) {
  16112. updateAttr('stroke-dashoffset', lineDashOffset);
  16113. }
  16114. }
  16115. }
  16116. else if (forceUpdate) {
  16117. updateAttr('stroke-dasharray', NONE);
  16118. }
  16119. for (var i = 0; i < strokeProps.length; i++) {
  16120. var propName = strokeProps[i];
  16121. if (forceUpdate || style[propName] !== DEFAULT_PATH_STYLE[propName]) {
  16122. var val = style[propName] || DEFAULT_PATH_STYLE[propName];
  16123. val && updateAttr(svgStrokeProps[i], val);
  16124. }
  16125. }
  16126. }
  16127. else if (forceUpdate) {
  16128. updateAttr('stroke', NONE);
  16129. }
  16130. }
  16131. var SVGNS = 'http://www.w3.org/2000/svg';
  16132. var XLINKNS = 'http://www.w3.org/1999/xlink';
  16133. var XMLNS = 'http://www.w3.org/2000/xmlns/';
  16134. var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
  16135. var META_DATA_PREFIX = 'ecmeta_';
  16136. function createElement(name) {
  16137. return document.createElementNS(SVGNS, name);
  16138. }
  16139. function createVNode(tag, key, attrs, children, text) {
  16140. return {
  16141. tag: tag,
  16142. attrs: attrs || {},
  16143. children: children,
  16144. text: text,
  16145. key: key
  16146. };
  16147. }
  16148. function createElementOpen(name, attrs) {
  16149. var attrsStr = [];
  16150. if (attrs) {
  16151. for (var key in attrs) {
  16152. var val = attrs[key];
  16153. var part = key;
  16154. if (val === false) {
  16155. continue;
  16156. }
  16157. else if (val !== true && val != null) {
  16158. part += "=\"" + val + "\"";
  16159. }
  16160. attrsStr.push(part);
  16161. }
  16162. }
  16163. return "<" + name + " " + attrsStr.join(' ') + ">";
  16164. }
  16165. function createElementClose(name) {
  16166. return "</" + name + ">";
  16167. }
  16168. function vNodeToString(el, opts) {
  16169. opts = opts || {};
  16170. var S = opts.newline ? '\n' : '';
  16171. function convertElToString(el) {
  16172. var children = el.children, tag = el.tag, attrs = el.attrs, text = el.text;
  16173. return createElementOpen(tag, attrs)
  16174. + (tag !== 'style' ? encodeHTML(text) : text || '')
  16175. + (children ? "" + S + map(children, function (child) { return convertElToString(child); }).join(S) + S : '')
  16176. + createElementClose(tag);
  16177. }
  16178. return convertElToString(el);
  16179. }
  16180. function getCssString(selectorNodes, animationNodes, opts) {
  16181. opts = opts || {};
  16182. var S = opts.newline ? '\n' : '';
  16183. var bracketBegin = " {" + S;
  16184. var bracketEnd = S + "}";
  16185. var selectors = map(keys(selectorNodes), function (className) {
  16186. return className + bracketBegin + map(keys(selectorNodes[className]), function (attrName) {
  16187. return attrName + ":" + selectorNodes[className][attrName] + ";";
  16188. }).join(S) + bracketEnd;
  16189. }).join(S);
  16190. var animations = map(keys(animationNodes), function (animationName) {
  16191. return "@keyframes " + animationName + bracketBegin + map(keys(animationNodes[animationName]), function (percent) {
  16192. return percent + bracketBegin + map(keys(animationNodes[animationName][percent]), function (attrName) {
  16193. var val = animationNodes[animationName][percent][attrName];
  16194. if (attrName === 'd') {
  16195. val = "path(\"" + val + "\")";
  16196. }
  16197. return attrName + ":" + val + ";";
  16198. }).join(S) + bracketEnd;
  16199. }).join(S) + bracketEnd;
  16200. }).join(S);
  16201. if (!selectors && !animations) {
  16202. return '';
  16203. }
  16204. return ['<![CDATA[', selectors, animations, ']]>'].join(S);
  16205. }
  16206. function createBrushScope(zrId) {
  16207. return {
  16208. zrId: zrId,
  16209. shadowCache: {},
  16210. patternCache: {},
  16211. gradientCache: {},
  16212. clipPathCache: {},
  16213. defs: {},
  16214. cssNodes: {},
  16215. cssAnims: {},
  16216. cssStyleCache: {},
  16217. cssAnimIdx: 0,
  16218. shadowIdx: 0,
  16219. gradientIdx: 0,
  16220. patternIdx: 0,
  16221. clipPathIdx: 0
  16222. };
  16223. }
  16224. function createSVGVNode(width, height, children, useViewBox) {
  16225. return createVNode('svg', 'root', {
  16226. 'width': width,
  16227. 'height': height,
  16228. 'xmlns': SVGNS,
  16229. 'xmlns:xlink': XLINKNS,
  16230. 'version': '1.1',
  16231. 'baseProfile': 'full',
  16232. 'viewBox': useViewBox ? "0 0 " + width + " " + height : false
  16233. }, children);
  16234. }
  16235. var cssClassIdx = 0;
  16236. function getClassId() {
  16237. return cssClassIdx++;
  16238. }
  16239. var EASING_MAP = {
  16240. cubicIn: '0.32,0,0.67,0',
  16241. cubicOut: '0.33,1,0.68,1',
  16242. cubicInOut: '0.65,0,0.35,1',
  16243. quadraticIn: '0.11,0,0.5,0',
  16244. quadraticOut: '0.5,1,0.89,1',
  16245. quadraticInOut: '0.45,0,0.55,1',
  16246. quarticIn: '0.5,0,0.75,0',
  16247. quarticOut: '0.25,1,0.5,1',
  16248. quarticInOut: '0.76,0,0.24,1',
  16249. quinticIn: '0.64,0,0.78,0',
  16250. quinticOut: '0.22,1,0.36,1',
  16251. quinticInOut: '0.83,0,0.17,1',
  16252. sinusoidalIn: '0.12,0,0.39,0',
  16253. sinusoidalOut: '0.61,1,0.88,1',
  16254. sinusoidalInOut: '0.37,0,0.63,1',
  16255. exponentialIn: '0.7,0,0.84,0',
  16256. exponentialOut: '0.16,1,0.3,1',
  16257. exponentialInOut: '0.87,0,0.13,1',
  16258. circularIn: '0.55,0,1,0.45',
  16259. circularOut: '0,0.55,0.45,1',
  16260. circularInOut: '0.85,0,0.15,1'
  16261. };
  16262. var transformOriginKey = 'transform-origin';
  16263. function buildPathString(el, kfShape, path) {
  16264. var shape = extend({}, el.shape);
  16265. extend(shape, kfShape);
  16266. el.buildPath(path, shape);
  16267. var svgPathBuilder = new SVGPathRebuilder();
  16268. svgPathBuilder.reset(getPathPrecision(el));
  16269. path.rebuildPath(svgPathBuilder, 1);
  16270. svgPathBuilder.generateStr();
  16271. return svgPathBuilder.getStr();
  16272. }
  16273. function setTransformOrigin(target, transform) {
  16274. var originX = transform.originX, originY = transform.originY;
  16275. if (originX || originY) {
  16276. target[transformOriginKey] = originX + "px " + originY + "px";
  16277. }
  16278. }
  16279. var ANIMATE_STYLE_MAP = {
  16280. fill: 'fill',
  16281. opacity: 'opacity',
  16282. lineWidth: 'stroke-width',
  16283. lineDashOffset: 'stroke-dashoffset'
  16284. };
  16285. function addAnimation(cssAnim, scope) {
  16286. var animationName = scope.zrId + '-ani-' + scope.cssAnimIdx++;
  16287. scope.cssAnims[animationName] = cssAnim;
  16288. return animationName;
  16289. }
  16290. function createCompoundPathCSSAnimation(el, attrs, scope) {
  16291. var paths = el.shape.paths;
  16292. var composedAnim = {};
  16293. var cssAnimationCfg;
  16294. var cssAnimationName;
  16295. each(paths, function (path) {
  16296. var subScope = createBrushScope(scope.zrId);
  16297. subScope.animation = true;
  16298. createCSSAnimation(path, {}, subScope, true);
  16299. var cssAnims = subScope.cssAnims;
  16300. var cssNodes = subScope.cssNodes;
  16301. var animNames = keys(cssAnims);
  16302. var len = animNames.length;
  16303. if (!len) {
  16304. return;
  16305. }
  16306. cssAnimationName = animNames[len - 1];
  16307. var lastAnim = cssAnims[cssAnimationName];
  16308. for (var percent in lastAnim) {
  16309. var kf = lastAnim[percent];
  16310. composedAnim[percent] = composedAnim[percent] || { d: '' };
  16311. composedAnim[percent].d += kf.d || '';
  16312. }
  16313. for (var className in cssNodes) {
  16314. var val = cssNodes[className].animation;
  16315. if (val.indexOf(cssAnimationName) >= 0) {
  16316. cssAnimationCfg = val;
  16317. }
  16318. }
  16319. });
  16320. if (!cssAnimationCfg) {
  16321. return;
  16322. }
  16323. attrs.d = false;
  16324. var animationName = addAnimation(composedAnim, scope);
  16325. return cssAnimationCfg.replace(cssAnimationName, animationName);
  16326. }
  16327. function getEasingFunc(easing) {
  16328. return isString(easing)
  16329. ? EASING_MAP[easing]
  16330. ? "cubic-bezier(" + EASING_MAP[easing] + ")"
  16331. : createCubicEasingFunc(easing) ? easing : ''
  16332. : '';
  16333. }
  16334. function createCSSAnimation(el, attrs, scope, onlyShape) {
  16335. var animators = el.animators;
  16336. var len = animators.length;
  16337. var cssAnimations = [];
  16338. if (el instanceof CompoundPath) {
  16339. var animationCfg = createCompoundPathCSSAnimation(el, attrs, scope);
  16340. if (animationCfg) {
  16341. cssAnimations.push(animationCfg);
  16342. }
  16343. else if (!len) {
  16344. return;
  16345. }
  16346. }
  16347. else if (!len) {
  16348. return;
  16349. }
  16350. var groupAnimators = {};
  16351. for (var i = 0; i < len; i++) {
  16352. var animator = animators[i];
  16353. var cfgArr = [animator.getMaxTime() / 1000 + 's'];
  16354. var easing = getEasingFunc(animator.getClip().easing);
  16355. var delay = animator.getDelay();
  16356. if (easing) {
  16357. cfgArr.push(easing);
  16358. }
  16359. else {
  16360. cfgArr.push('linear');
  16361. }
  16362. if (delay) {
  16363. cfgArr.push(delay / 1000 + 's');
  16364. }
  16365. if (animator.getLoop()) {
  16366. cfgArr.push('infinite');
  16367. }
  16368. var cfg = cfgArr.join(' ');
  16369. groupAnimators[cfg] = groupAnimators[cfg] || [cfg, []];
  16370. groupAnimators[cfg][1].push(animator);
  16371. }
  16372. function createSingleCSSAnimation(groupAnimator) {
  16373. var animators = groupAnimator[1];
  16374. var len = animators.length;
  16375. var transformKfs = {};
  16376. var shapeKfs = {};
  16377. var finalKfs = {};
  16378. var animationTimingFunctionAttrName = 'animation-timing-function';
  16379. function saveAnimatorTrackToCssKfs(animator, cssKfs, toCssAttrName) {
  16380. var tracks = animator.getTracks();
  16381. var maxTime = animator.getMaxTime();
  16382. for (var k = 0; k < tracks.length; k++) {
  16383. var track = tracks[k];
  16384. if (track.needsAnimate()) {
  16385. var kfs = track.keyframes;
  16386. var attrName = track.propName;
  16387. toCssAttrName && (attrName = toCssAttrName(attrName));
  16388. if (attrName) {
  16389. for (var i = 0; i < kfs.length; i++) {
  16390. var kf = kfs[i];
  16391. var percent = Math.round(kf.time / maxTime * 100) + '%';
  16392. var kfEasing = getEasingFunc(kf.easing);
  16393. var rawValue = kf.rawValue;
  16394. if (isString(rawValue) || isNumber(rawValue)) {
  16395. cssKfs[percent] = cssKfs[percent] || {};
  16396. cssKfs[percent][attrName] = kf.rawValue;
  16397. if (kfEasing) {
  16398. cssKfs[percent][animationTimingFunctionAttrName] = kfEasing;
  16399. }
  16400. }
  16401. }
  16402. }
  16403. }
  16404. }
  16405. }
  16406. for (var i = 0; i < len; i++) {
  16407. var animator = animators[i];
  16408. var targetProp = animator.targetName;
  16409. if (!targetProp) {
  16410. !onlyShape && saveAnimatorTrackToCssKfs(animator, transformKfs);
  16411. }
  16412. else if (targetProp === 'shape') {
  16413. saveAnimatorTrackToCssKfs(animator, shapeKfs);
  16414. }
  16415. }
  16416. for (var percent in transformKfs) {
  16417. var transform = {};
  16418. copyTransform(transform, el);
  16419. extend(transform, transformKfs[percent]);
  16420. var str = getSRTTransformString(transform);
  16421. var timingFunction = transformKfs[percent][animationTimingFunctionAttrName];
  16422. finalKfs[percent] = str ? {
  16423. transform: str
  16424. } : {};
  16425. setTransformOrigin(finalKfs[percent], transform);
  16426. if (timingFunction) {
  16427. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16428. }
  16429. }
  16430. var path;
  16431. var canAnimateShape = true;
  16432. for (var percent in shapeKfs) {
  16433. finalKfs[percent] = finalKfs[percent] || {};
  16434. var isFirst = !path;
  16435. var timingFunction = shapeKfs[percent][animationTimingFunctionAttrName];
  16436. if (isFirst) {
  16437. path = new PathProxy();
  16438. }
  16439. var len_1 = path.len();
  16440. path.reset();
  16441. finalKfs[percent].d = buildPathString(el, shapeKfs[percent], path);
  16442. var newLen = path.len();
  16443. if (!isFirst && len_1 !== newLen) {
  16444. canAnimateShape = false;
  16445. break;
  16446. }
  16447. if (timingFunction) {
  16448. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  16449. }
  16450. }
  16451. if (!canAnimateShape) {
  16452. for (var percent in finalKfs) {
  16453. delete finalKfs[percent].d;
  16454. }
  16455. }
  16456. if (!onlyShape) {
  16457. for (var i = 0; i < len; i++) {
  16458. var animator = animators[i];
  16459. var targetProp = animator.targetName;
  16460. if (targetProp === 'style') {
  16461. saveAnimatorTrackToCssKfs(animator, finalKfs, function (propName) { return ANIMATE_STYLE_MAP[propName]; });
  16462. }
  16463. }
  16464. }
  16465. var percents = keys(finalKfs);
  16466. var allTransformOriginSame = true;
  16467. var transformOrigin;
  16468. for (var i = 1; i < percents.length; i++) {
  16469. var p0 = percents[i - 1];
  16470. var p1 = percents[i];
  16471. if (finalKfs[p0][transformOriginKey] !== finalKfs[p1][transformOriginKey]) {
  16472. allTransformOriginSame = false;
  16473. break;
  16474. }
  16475. transformOrigin = finalKfs[p0][transformOriginKey];
  16476. }
  16477. if (allTransformOriginSame && transformOrigin) {
  16478. for (var percent in finalKfs) {
  16479. if (finalKfs[percent][transformOriginKey]) {
  16480. delete finalKfs[percent][transformOriginKey];
  16481. }
  16482. }
  16483. attrs[transformOriginKey] = transformOrigin;
  16484. }
  16485. if (filter(percents, function (percent) { return keys(finalKfs[percent]).length > 0; }).length) {
  16486. var animationName = addAnimation(finalKfs, scope);
  16487. return animationName + " " + groupAnimator[0] + " both";
  16488. }
  16489. }
  16490. for (var key in groupAnimators) {
  16491. var animationCfg = createSingleCSSAnimation(groupAnimators[key]);
  16492. if (animationCfg) {
  16493. cssAnimations.push(animationCfg);
  16494. }
  16495. }
  16496. if (cssAnimations.length) {
  16497. var className = scope.zrId + '-cls-' + getClassId();
  16498. scope.cssNodes['.' + className] = {
  16499. animation: cssAnimations.join(',')
  16500. };
  16501. attrs["class"] = className;
  16502. }
  16503. }
  16504. function createCSSEmphasis(el, attrs, scope) {
  16505. if (!el.ignore) {
  16506. if (el.isSilent()) {
  16507. var style = {
  16508. 'pointer-events': 'none'
  16509. };
  16510. setClassAttribute(style, attrs, scope, true);
  16511. }
  16512. else {
  16513. var emphasisStyle = el.states.emphasis && el.states.emphasis.style
  16514. ? el.states.emphasis.style
  16515. : {};
  16516. var fill = emphasisStyle.fill;
  16517. if (!fill) {
  16518. var normalFill = el.style && el.style.fill;
  16519. var selectFill = el.states.select
  16520. && el.states.select.style
  16521. && el.states.select.style.fill;
  16522. var fromFill = el.currentStates.indexOf('select') >= 0
  16523. ? (selectFill || normalFill)
  16524. : normalFill;
  16525. if (fromFill) {
  16526. fill = liftColor(fromFill);
  16527. }
  16528. }
  16529. var lineWidth = emphasisStyle.lineWidth;
  16530. if (lineWidth) {
  16531. var scaleX = (!emphasisStyle.strokeNoScale && el.transform)
  16532. ? el.transform[0]
  16533. : 1;
  16534. lineWidth = lineWidth / scaleX;
  16535. }
  16536. var style = {
  16537. cursor: 'pointer',
  16538. };
  16539. if (fill) {
  16540. style.fill = fill;
  16541. }
  16542. if (emphasisStyle.stroke) {
  16543. style.stroke = emphasisStyle.stroke;
  16544. }
  16545. if (lineWidth) {
  16546. style['stroke-width'] = lineWidth;
  16547. }
  16548. setClassAttribute(style, attrs, scope, true);
  16549. }
  16550. }
  16551. }
  16552. function setClassAttribute(style, attrs, scope, withHover) {
  16553. var styleKey = JSON.stringify(style);
  16554. var className = scope.cssStyleCache[styleKey];
  16555. if (!className) {
  16556. className = scope.zrId + '-cls-' + getClassId();
  16557. scope.cssStyleCache[styleKey] = className;
  16558. scope.cssNodes['.' + className + (withHover ? ':hover' : '')] = style;
  16559. }
  16560. attrs["class"] = attrs["class"] ? (attrs["class"] + ' ' + className) : className;
  16561. }
  16562. var round$1 = Math.round;
  16563. function isImageLike$1(val) {
  16564. return val && isString(val.src);
  16565. }
  16566. function isCanvasLike(val) {
  16567. return val && isFunction(val.toDataURL);
  16568. }
  16569. function setStyleAttrs(attrs, style, el, scope) {
  16570. mapStyleToAttrs(function (key, val) {
  16571. var isFillStroke = key === 'fill' || key === 'stroke';
  16572. if (isFillStroke && isGradient(val)) {
  16573. setGradient(style, attrs, key, scope);
  16574. }
  16575. else if (isFillStroke && isPattern(val)) {
  16576. setPattern(el, attrs, key, scope);
  16577. }
  16578. else {
  16579. attrs[key] = val;
  16580. }
  16581. if (isFillStroke && scope.ssr && val === 'none') {
  16582. attrs['pointer-events'] = 'visible';
  16583. }
  16584. }, style, el, false);
  16585. setShadow(el, attrs, scope);
  16586. }
  16587. function setMetaData(attrs, el) {
  16588. var metaData = getElementSSRData(el);
  16589. if (metaData) {
  16590. metaData.each(function (val, key) {
  16591. val != null && (attrs[(META_DATA_PREFIX + key).toLowerCase()] = val + '');
  16592. });
  16593. if (el.isSilent()) {
  16594. attrs[META_DATA_PREFIX + 'silent'] = 'true';
  16595. }
  16596. }
  16597. }
  16598. function noRotateScale(m) {
  16599. return isAroundZero$1(m[0] - 1)
  16600. && isAroundZero$1(m[1])
  16601. && isAroundZero$1(m[2])
  16602. && isAroundZero$1(m[3] - 1);
  16603. }
  16604. function noTranslate(m) {
  16605. return isAroundZero$1(m[4]) && isAroundZero$1(m[5]);
  16606. }
  16607. function setTransform(attrs, m, compress) {
  16608. if (m && !(noTranslate(m) && noRotateScale(m))) {
  16609. var mul = compress ? 10 : 1e4;
  16610. attrs.transform = noRotateScale(m)
  16611. ? "translate(" + round$1(m[4] * mul) / mul + " " + round$1(m[5] * mul) / mul + ")" : getMatrixStr(m);
  16612. }
  16613. }
  16614. function convertPolyShape(shape, attrs, mul) {
  16615. var points = shape.points;
  16616. var strArr = [];
  16617. for (var i = 0; i < points.length; i++) {
  16618. strArr.push(round$1(points[i][0] * mul) / mul);
  16619. strArr.push(round$1(points[i][1] * mul) / mul);
  16620. }
  16621. attrs.points = strArr.join(' ');
  16622. }
  16623. function validatePolyShape(shape) {
  16624. return !shape.smooth;
  16625. }
  16626. function createAttrsConvert(desc) {
  16627. var normalizedDesc = map(desc, function (item) {
  16628. return (typeof item === 'string' ? [item, item] : item);
  16629. });
  16630. return function (shape, attrs, mul) {
  16631. for (var i = 0; i < normalizedDesc.length; i++) {
  16632. var item = normalizedDesc[i];
  16633. var val = shape[item[0]];
  16634. if (val != null) {
  16635. attrs[item[1]] = round$1(val * mul) / mul;
  16636. }
  16637. }
  16638. };
  16639. }
  16640. var builtinShapesDef = {
  16641. circle: [createAttrsConvert(['cx', 'cy', 'r'])],
  16642. polyline: [convertPolyShape, validatePolyShape],
  16643. polygon: [convertPolyShape, validatePolyShape]
  16644. };
  16645. function hasShapeAnimation(el) {
  16646. var animators = el.animators;
  16647. for (var i = 0; i < animators.length; i++) {
  16648. if (animators[i].targetName === 'shape') {
  16649. return true;
  16650. }
  16651. }
  16652. return false;
  16653. }
  16654. function brushSVGPath(el, scope) {
  16655. var style = el.style;
  16656. var shape = el.shape;
  16657. var builtinShpDef = builtinShapesDef[el.type];
  16658. var attrs = {};
  16659. var needsAnimate = scope.animation;
  16660. var svgElType = 'path';
  16661. var strokePercent = el.style.strokePercent;
  16662. var precision = (scope.compress && getPathPrecision(el)) || 4;
  16663. if (builtinShpDef
  16664. && !scope.willUpdate
  16665. && !(builtinShpDef[1] && !builtinShpDef[1](shape))
  16666. && !(needsAnimate && hasShapeAnimation(el))
  16667. && !(strokePercent < 1)) {
  16668. svgElType = el.type;
  16669. var mul = Math.pow(10, precision);
  16670. builtinShpDef[0](shape, attrs, mul);
  16671. }
  16672. else {
  16673. var needBuildPath = !el.path || el.shapeChanged();
  16674. if (!el.path) {
  16675. el.createPathProxy();
  16676. }
  16677. var path = el.path;
  16678. if (needBuildPath) {
  16679. path.beginPath();
  16680. el.buildPath(path, el.shape);
  16681. el.pathUpdated();
  16682. }
  16683. var pathVersion = path.getVersion();
  16684. var elExt = el;
  16685. var svgPathBuilder = elExt.__svgPathBuilder;
  16686. if (elExt.__svgPathVersion !== pathVersion
  16687. || !svgPathBuilder
  16688. || strokePercent !== elExt.__svgPathStrokePercent) {
  16689. if (!svgPathBuilder) {
  16690. svgPathBuilder = elExt.__svgPathBuilder = new SVGPathRebuilder();
  16691. }
  16692. svgPathBuilder.reset(precision);
  16693. path.rebuildPath(svgPathBuilder, strokePercent);
  16694. svgPathBuilder.generateStr();
  16695. elExt.__svgPathVersion = pathVersion;
  16696. elExt.__svgPathStrokePercent = strokePercent;
  16697. }
  16698. attrs.d = svgPathBuilder.getStr();
  16699. }
  16700. setTransform(attrs, el.transform);
  16701. setStyleAttrs(attrs, style, el, scope);
  16702. setMetaData(attrs, el);
  16703. scope.animation && createCSSAnimation(el, attrs, scope);
  16704. scope.emphasis && createCSSEmphasis(el, attrs, scope);
  16705. return createVNode(svgElType, el.id + '', attrs);
  16706. }
  16707. function brushSVGImage(el, scope) {
  16708. var style = el.style;
  16709. var image = style.image;
  16710. if (image && !isString(image)) {
  16711. if (isImageLike$1(image)) {
  16712. image = image.src;
  16713. }
  16714. else if (isCanvasLike(image)) {
  16715. image = image.toDataURL();
  16716. }
  16717. }
  16718. if (!image) {
  16719. return;
  16720. }
  16721. var x = style.x || 0;
  16722. var y = style.y || 0;
  16723. var dw = style.width;
  16724. var dh = style.height;
  16725. var attrs = {
  16726. href: image,
  16727. width: dw,
  16728. height: dh
  16729. };
  16730. if (x) {
  16731. attrs.x = x;
  16732. }
  16733. if (y) {
  16734. attrs.y = y;
  16735. }
  16736. setTransform(attrs, el.transform);
  16737. setStyleAttrs(attrs, style, el, scope);
  16738. setMetaData(attrs, el);
  16739. scope.animation && createCSSAnimation(el, attrs, scope);
  16740. return createVNode('image', el.id + '', attrs);
  16741. }
  16742. function brushSVGTSpan(el, scope) {
  16743. var style = el.style;
  16744. var text = style.text;
  16745. text != null && (text += '');
  16746. if (!text || isNaN(style.x) || isNaN(style.y)) {
  16747. return;
  16748. }
  16749. var font = style.font || DEFAULT_FONT;
  16750. var x = style.x || 0;
  16751. var y = adjustTextY(style.y || 0, getLineHeight(font), style.textBaseline);
  16752. var textAlign = TEXT_ALIGN_TO_ANCHOR[style.textAlign]
  16753. || style.textAlign;
  16754. var attrs = {
  16755. 'dominant-baseline': 'central',
  16756. 'text-anchor': textAlign
  16757. };
  16758. if (hasSeparateFont(style)) {
  16759. var separatedFontStr = '';
  16760. var fontStyle = style.fontStyle;
  16761. var fontSize = parseFontSize(style.fontSize);
  16762. if (!parseFloat(fontSize)) {
  16763. return;
  16764. }
  16765. var fontFamily = style.fontFamily || DEFAULT_FONT_FAMILY;
  16766. var fontWeight = style.fontWeight;
  16767. separatedFontStr += "font-size:" + fontSize + ";font-family:" + fontFamily + ";";
  16768. if (fontStyle && fontStyle !== 'normal') {
  16769. separatedFontStr += "font-style:" + fontStyle + ";";
  16770. }
  16771. if (fontWeight && fontWeight !== 'normal') {
  16772. separatedFontStr += "font-weight:" + fontWeight + ";";
  16773. }
  16774. attrs.style = separatedFontStr;
  16775. }
  16776. else {
  16777. attrs.style = "font: " + font;
  16778. }
  16779. if (text.match(/\s/)) {
  16780. attrs['xml:space'] = 'preserve';
  16781. }
  16782. if (x) {
  16783. attrs.x = x;
  16784. }
  16785. if (y) {
  16786. attrs.y = y;
  16787. }
  16788. setTransform(attrs, el.transform);
  16789. setStyleAttrs(attrs, style, el, scope);
  16790. setMetaData(attrs, el);
  16791. scope.animation && createCSSAnimation(el, attrs, scope);
  16792. return createVNode('text', el.id + '', attrs, undefined, text);
  16793. }
  16794. function brush$1(el, scope) {
  16795. if (el instanceof Path) {
  16796. return brushSVGPath(el, scope);
  16797. }
  16798. else if (el instanceof ZRImage) {
  16799. return brushSVGImage(el, scope);
  16800. }
  16801. else if (el instanceof TSpan) {
  16802. return brushSVGTSpan(el, scope);
  16803. }
  16804. }
  16805. function setShadow(el, attrs, scope) {
  16806. var style = el.style;
  16807. if (hasShadow(style)) {
  16808. var shadowKey = getShadowKey(el);
  16809. var shadowCache = scope.shadowCache;
  16810. var shadowId = shadowCache[shadowKey];
  16811. if (!shadowId) {
  16812. var globalScale = el.getGlobalScale();
  16813. var scaleX = globalScale[0];
  16814. var scaleY = globalScale[1];
  16815. if (!scaleX || !scaleY) {
  16816. return;
  16817. }
  16818. var offsetX = style.shadowOffsetX || 0;
  16819. var offsetY = style.shadowOffsetY || 0;
  16820. var blur_1 = style.shadowBlur;
  16821. var _a = normalizeColor(style.shadowColor), opacity = _a.opacity, color = _a.color;
  16822. var stdDx = blur_1 / 2 / scaleX;
  16823. var stdDy = blur_1 / 2 / scaleY;
  16824. var stdDeviation = stdDx + ' ' + stdDy;
  16825. shadowId = scope.zrId + '-s' + scope.shadowIdx++;
  16826. scope.defs[shadowId] = createVNode('filter', shadowId, {
  16827. 'id': shadowId,
  16828. 'x': '-100%',
  16829. 'y': '-100%',
  16830. 'width': '300%',
  16831. 'height': '300%'
  16832. }, [
  16833. createVNode('feDropShadow', '', {
  16834. 'dx': offsetX / scaleX,
  16835. 'dy': offsetY / scaleY,
  16836. 'stdDeviation': stdDeviation,
  16837. 'flood-color': color,
  16838. 'flood-opacity': opacity
  16839. })
  16840. ]);
  16841. shadowCache[shadowKey] = shadowId;
  16842. }
  16843. attrs.filter = getIdURL(shadowId);
  16844. }
  16845. }
  16846. function setGradient(style, attrs, target, scope) {
  16847. var val = style[target];
  16848. var gradientTag;
  16849. var gradientAttrs = {
  16850. 'gradientUnits': val.global
  16851. ? 'userSpaceOnUse'
  16852. : 'objectBoundingBox'
  16853. };
  16854. if (isLinearGradient(val)) {
  16855. gradientTag = 'linearGradient';
  16856. gradientAttrs.x1 = val.x;
  16857. gradientAttrs.y1 = val.y;
  16858. gradientAttrs.x2 = val.x2;
  16859. gradientAttrs.y2 = val.y2;
  16860. }
  16861. else if (isRadialGradient(val)) {
  16862. gradientTag = 'radialGradient';
  16863. gradientAttrs.cx = retrieve2(val.x, 0.5);
  16864. gradientAttrs.cy = retrieve2(val.y, 0.5);
  16865. gradientAttrs.r = retrieve2(val.r, 0.5);
  16866. }
  16867. else {
  16868. {
  16869. logError('Illegal gradient type.');
  16870. }
  16871. return;
  16872. }
  16873. var colors = val.colorStops;
  16874. var colorStops = [];
  16875. for (var i = 0, len = colors.length; i < len; ++i) {
  16876. var offset = round4(colors[i].offset) * 100 + '%';
  16877. var stopColor = colors[i].color;
  16878. var _a = normalizeColor(stopColor), color = _a.color, opacity = _a.opacity;
  16879. var stopsAttrs = {
  16880. 'offset': offset
  16881. };
  16882. stopsAttrs['stop-color'] = color;
  16883. if (opacity < 1) {
  16884. stopsAttrs['stop-opacity'] = opacity;
  16885. }
  16886. colorStops.push(createVNode('stop', i + '', stopsAttrs));
  16887. }
  16888. var gradientVNode = createVNode(gradientTag, '', gradientAttrs, colorStops);
  16889. var gradientKey = vNodeToString(gradientVNode);
  16890. var gradientCache = scope.gradientCache;
  16891. var gradientId = gradientCache[gradientKey];
  16892. if (!gradientId) {
  16893. gradientId = scope.zrId + '-g' + scope.gradientIdx++;
  16894. gradientCache[gradientKey] = gradientId;
  16895. gradientAttrs.id = gradientId;
  16896. scope.defs[gradientId] = createVNode(gradientTag, gradientId, gradientAttrs, colorStops);
  16897. }
  16898. attrs[target] = getIdURL(gradientId);
  16899. }
  16900. function setPattern(el, attrs, target, scope) {
  16901. var val = el.style[target];
  16902. var boundingRect = el.getBoundingRect();
  16903. var patternAttrs = {};
  16904. var repeat = val.repeat;
  16905. var noRepeat = repeat === 'no-repeat';
  16906. var repeatX = repeat === 'repeat-x';
  16907. var repeatY = repeat === 'repeat-y';
  16908. var child;
  16909. if (isImagePattern(val)) {
  16910. var imageWidth_1 = val.imageWidth;
  16911. var imageHeight_1 = val.imageHeight;
  16912. var imageSrc = void 0;
  16913. var patternImage = val.image;
  16914. if (isString(patternImage)) {
  16915. imageSrc = patternImage;
  16916. }
  16917. else if (isImageLike$1(patternImage)) {
  16918. imageSrc = patternImage.src;
  16919. }
  16920. else if (isCanvasLike(patternImage)) {
  16921. imageSrc = patternImage.toDataURL();
  16922. }
  16923. if (typeof Image === 'undefined') {
  16924. var errMsg = 'Image width/height must been given explictly in svg-ssr renderer.';
  16925. assert(imageWidth_1, errMsg);
  16926. assert(imageHeight_1, errMsg);
  16927. }
  16928. else if (imageWidth_1 == null || imageHeight_1 == null) {
  16929. var setSizeToVNode_1 = function (vNode, img) {
  16930. if (vNode) {
  16931. var svgEl = vNode.elm;
  16932. var width = imageWidth_1 || img.width;
  16933. var height = imageHeight_1 || img.height;
  16934. if (vNode.tag === 'pattern') {
  16935. if (repeatX) {
  16936. height = 1;
  16937. width /= boundingRect.width;
  16938. }
  16939. else if (repeatY) {
  16940. width = 1;
  16941. height /= boundingRect.height;
  16942. }
  16943. }
  16944. vNode.attrs.width = width;
  16945. vNode.attrs.height = height;
  16946. if (svgEl) {
  16947. svgEl.setAttribute('width', width);
  16948. svgEl.setAttribute('height', height);
  16949. }
  16950. }
  16951. };
  16952. var createdImage = createOrUpdateImage(imageSrc, null, el, function (img) {
  16953. noRepeat || setSizeToVNode_1(patternVNode, img);
  16954. setSizeToVNode_1(child, img);
  16955. });
  16956. if (createdImage && createdImage.width && createdImage.height) {
  16957. imageWidth_1 = imageWidth_1 || createdImage.width;
  16958. imageHeight_1 = imageHeight_1 || createdImage.height;
  16959. }
  16960. }
  16961. child = createVNode('image', 'img', {
  16962. href: imageSrc,
  16963. width: imageWidth_1,
  16964. height: imageHeight_1
  16965. });
  16966. patternAttrs.width = imageWidth_1;
  16967. patternAttrs.height = imageHeight_1;
  16968. }
  16969. else if (val.svgElement) {
  16970. child = clone(val.svgElement);
  16971. patternAttrs.width = val.svgWidth;
  16972. patternAttrs.height = val.svgHeight;
  16973. }
  16974. if (!child) {
  16975. return;
  16976. }
  16977. var patternWidth;
  16978. var patternHeight;
  16979. if (noRepeat) {
  16980. patternWidth = patternHeight = 1;
  16981. }
  16982. else if (repeatX) {
  16983. patternHeight = 1;
  16984. patternWidth = patternAttrs.width / boundingRect.width;
  16985. }
  16986. else if (repeatY) {
  16987. patternWidth = 1;
  16988. patternHeight = patternAttrs.height / boundingRect.height;
  16989. }
  16990. else {
  16991. patternAttrs.patternUnits = 'userSpaceOnUse';
  16992. }
  16993. if (patternWidth != null && !isNaN(patternWidth)) {
  16994. patternAttrs.width = patternWidth;
  16995. }
  16996. if (patternHeight != null && !isNaN(patternHeight)) {
  16997. patternAttrs.height = patternHeight;
  16998. }
  16999. var patternTransform = getSRTTransformString(val);
  17000. patternTransform && (patternAttrs.patternTransform = patternTransform);
  17001. var patternVNode = createVNode('pattern', '', patternAttrs, [child]);
  17002. var patternKey = vNodeToString(patternVNode);
  17003. var patternCache = scope.patternCache;
  17004. var patternId = patternCache[patternKey];
  17005. if (!patternId) {
  17006. patternId = scope.zrId + '-p' + scope.patternIdx++;
  17007. patternCache[patternKey] = patternId;
  17008. patternAttrs.id = patternId;
  17009. patternVNode = scope.defs[patternId] = createVNode('pattern', patternId, patternAttrs, [child]);
  17010. }
  17011. attrs[target] = getIdURL(patternId);
  17012. }
  17013. function setClipPath(clipPath, attrs, scope) {
  17014. var clipPathCache = scope.clipPathCache, defs = scope.defs;
  17015. var clipPathId = clipPathCache[clipPath.id];
  17016. if (!clipPathId) {
  17017. clipPathId = scope.zrId + '-c' + scope.clipPathIdx++;
  17018. var clipPathAttrs = {
  17019. id: clipPathId
  17020. };
  17021. clipPathCache[clipPath.id] = clipPathId;
  17022. defs[clipPathId] = createVNode('clipPath', clipPathId, clipPathAttrs, [brushSVGPath(clipPath, scope)]);
  17023. }
  17024. attrs['clip-path'] = getIdURL(clipPathId);
  17025. }
  17026. function createTextNode(text) {
  17027. return document.createTextNode(text);
  17028. }
  17029. function insertBefore(parentNode, newNode, referenceNode) {
  17030. parentNode.insertBefore(newNode, referenceNode);
  17031. }
  17032. function removeChild(node, child) {
  17033. node.removeChild(child);
  17034. }
  17035. function appendChild(node, child) {
  17036. node.appendChild(child);
  17037. }
  17038. function parentNode(node) {
  17039. return node.parentNode;
  17040. }
  17041. function nextSibling(node) {
  17042. return node.nextSibling;
  17043. }
  17044. function setTextContent(node, text) {
  17045. node.textContent = text;
  17046. }
  17047. var colonChar = 58;
  17048. var xChar = 120;
  17049. var emptyNode = createVNode('', '');
  17050. function isUndef(s) {
  17051. return s === undefined;
  17052. }
  17053. function isDef(s) {
  17054. return s !== undefined;
  17055. }
  17056. function createKeyToOldIdx(children, beginIdx, endIdx) {
  17057. var map = {};
  17058. for (var i = beginIdx; i <= endIdx; ++i) {
  17059. var key = children[i].key;
  17060. if (key !== undefined) {
  17061. {
  17062. if (map[key] != null) {
  17063. console.error("Duplicate key " + key);
  17064. }
  17065. }
  17066. map[key] = i;
  17067. }
  17068. }
  17069. return map;
  17070. }
  17071. function sameVnode(vnode1, vnode2) {
  17072. var isSameKey = vnode1.key === vnode2.key;
  17073. var isSameTag = vnode1.tag === vnode2.tag;
  17074. return isSameTag && isSameKey;
  17075. }
  17076. function createElm(vnode) {
  17077. var i;
  17078. var children = vnode.children;
  17079. var tag = vnode.tag;
  17080. if (isDef(tag)) {
  17081. var elm = (vnode.elm = createElement(tag));
  17082. updateAttrs(emptyNode, vnode);
  17083. if (isArray(children)) {
  17084. for (i = 0; i < children.length; ++i) {
  17085. var ch = children[i];
  17086. if (ch != null) {
  17087. appendChild(elm, createElm(ch));
  17088. }
  17089. }
  17090. }
  17091. else if (isDef(vnode.text) && !isObject(vnode.text)) {
  17092. appendChild(elm, createTextNode(vnode.text));
  17093. }
  17094. }
  17095. else {
  17096. vnode.elm = createTextNode(vnode.text);
  17097. }
  17098. return vnode.elm;
  17099. }
  17100. function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
  17101. for (; startIdx <= endIdx; ++startIdx) {
  17102. var ch = vnodes[startIdx];
  17103. if (ch != null) {
  17104. insertBefore(parentElm, createElm(ch), before);
  17105. }
  17106. }
  17107. }
  17108. function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
  17109. for (; startIdx <= endIdx; ++startIdx) {
  17110. var ch = vnodes[startIdx];
  17111. if (ch != null) {
  17112. if (isDef(ch.tag)) {
  17113. var parent_1 = parentNode(ch.elm);
  17114. removeChild(parent_1, ch.elm);
  17115. }
  17116. else {
  17117. removeChild(parentElm, ch.elm);
  17118. }
  17119. }
  17120. }
  17121. }
  17122. function updateAttrs(oldVnode, vnode) {
  17123. var key;
  17124. var elm = vnode.elm;
  17125. var oldAttrs = oldVnode && oldVnode.attrs || {};
  17126. var attrs = vnode.attrs || {};
  17127. if (oldAttrs === attrs) {
  17128. return;
  17129. }
  17130. for (key in attrs) {
  17131. var cur = attrs[key];
  17132. var old = oldAttrs[key];
  17133. if (old !== cur) {
  17134. if (cur === true) {
  17135. elm.setAttribute(key, '');
  17136. }
  17137. else if (cur === false) {
  17138. elm.removeAttribute(key);
  17139. }
  17140. else {
  17141. if (key === 'style') {
  17142. elm.style.cssText = cur;
  17143. }
  17144. else if (key.charCodeAt(0) !== xChar) {
  17145. elm.setAttribute(key, cur);
  17146. }
  17147. else if (key === 'xmlns:xlink' || key === 'xmlns') {
  17148. elm.setAttributeNS(XMLNS, key, cur);
  17149. }
  17150. else if (key.charCodeAt(3) === colonChar) {
  17151. elm.setAttributeNS(XML_NAMESPACE, key, cur);
  17152. }
  17153. else if (key.charCodeAt(5) === colonChar) {
  17154. elm.setAttributeNS(XLINKNS, key, cur);
  17155. }
  17156. else {
  17157. elm.setAttribute(key, cur);
  17158. }
  17159. }
  17160. }
  17161. }
  17162. for (key in oldAttrs) {
  17163. if (!(key in attrs)) {
  17164. elm.removeAttribute(key);
  17165. }
  17166. }
  17167. }
  17168. function updateChildren(parentElm, oldCh, newCh) {
  17169. var oldStartIdx = 0;
  17170. var newStartIdx = 0;
  17171. var oldEndIdx = oldCh.length - 1;
  17172. var oldStartVnode = oldCh[0];
  17173. var oldEndVnode = oldCh[oldEndIdx];
  17174. var newEndIdx = newCh.length - 1;
  17175. var newStartVnode = newCh[0];
  17176. var newEndVnode = newCh[newEndIdx];
  17177. var oldKeyToIdx;
  17178. var idxInOld;
  17179. var elmToMove;
  17180. var before;
  17181. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  17182. if (oldStartVnode == null) {
  17183. oldStartVnode = oldCh[++oldStartIdx];
  17184. }
  17185. else if (oldEndVnode == null) {
  17186. oldEndVnode = oldCh[--oldEndIdx];
  17187. }
  17188. else if (newStartVnode == null) {
  17189. newStartVnode = newCh[++newStartIdx];
  17190. }
  17191. else if (newEndVnode == null) {
  17192. newEndVnode = newCh[--newEndIdx];
  17193. }
  17194. else if (sameVnode(oldStartVnode, newStartVnode)) {
  17195. patchVnode(oldStartVnode, newStartVnode);
  17196. oldStartVnode = oldCh[++oldStartIdx];
  17197. newStartVnode = newCh[++newStartIdx];
  17198. }
  17199. else if (sameVnode(oldEndVnode, newEndVnode)) {
  17200. patchVnode(oldEndVnode, newEndVnode);
  17201. oldEndVnode = oldCh[--oldEndIdx];
  17202. newEndVnode = newCh[--newEndIdx];
  17203. }
  17204. else if (sameVnode(oldStartVnode, newEndVnode)) {
  17205. patchVnode(oldStartVnode, newEndVnode);
  17206. insertBefore(parentElm, oldStartVnode.elm, nextSibling(oldEndVnode.elm));
  17207. oldStartVnode = oldCh[++oldStartIdx];
  17208. newEndVnode = newCh[--newEndIdx];
  17209. }
  17210. else if (sameVnode(oldEndVnode, newStartVnode)) {
  17211. patchVnode(oldEndVnode, newStartVnode);
  17212. insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
  17213. oldEndVnode = oldCh[--oldEndIdx];
  17214. newStartVnode = newCh[++newStartIdx];
  17215. }
  17216. else {
  17217. if (isUndef(oldKeyToIdx)) {
  17218. oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
  17219. }
  17220. idxInOld = oldKeyToIdx[newStartVnode.key];
  17221. if (isUndef(idxInOld)) {
  17222. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  17223. }
  17224. else {
  17225. elmToMove = oldCh[idxInOld];
  17226. if (elmToMove.tag !== newStartVnode.tag) {
  17227. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  17228. }
  17229. else {
  17230. patchVnode(elmToMove, newStartVnode);
  17231. oldCh[idxInOld] = undefined;
  17232. insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
  17233. }
  17234. }
  17235. newStartVnode = newCh[++newStartIdx];
  17236. }
  17237. }
  17238. if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
  17239. if (oldStartIdx > oldEndIdx) {
  17240. before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm;
  17241. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
  17242. }
  17243. else {
  17244. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
  17245. }
  17246. }
  17247. }
  17248. function patchVnode(oldVnode, vnode) {
  17249. var elm = (vnode.elm = oldVnode.elm);
  17250. var oldCh = oldVnode.children;
  17251. var ch = vnode.children;
  17252. if (oldVnode === vnode) {
  17253. return;
  17254. }
  17255. updateAttrs(oldVnode, vnode);
  17256. if (isUndef(vnode.text)) {
  17257. if (isDef(oldCh) && isDef(ch)) {
  17258. if (oldCh !== ch) {
  17259. updateChildren(elm, oldCh, ch);
  17260. }
  17261. }
  17262. else if (isDef(ch)) {
  17263. if (isDef(oldVnode.text)) {
  17264. setTextContent(elm, '');
  17265. }
  17266. addVnodes(elm, null, ch, 0, ch.length - 1);
  17267. }
  17268. else if (isDef(oldCh)) {
  17269. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  17270. }
  17271. else if (isDef(oldVnode.text)) {
  17272. setTextContent(elm, '');
  17273. }
  17274. }
  17275. else if (oldVnode.text !== vnode.text) {
  17276. if (isDef(oldCh)) {
  17277. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  17278. }
  17279. setTextContent(elm, vnode.text);
  17280. }
  17281. }
  17282. function patch(oldVnode, vnode) {
  17283. if (sameVnode(oldVnode, vnode)) {
  17284. patchVnode(oldVnode, vnode);
  17285. }
  17286. else {
  17287. var elm = oldVnode.elm;
  17288. var parent_2 = parentNode(elm);
  17289. createElm(vnode);
  17290. if (parent_2 !== null) {
  17291. insertBefore(parent_2, vnode.elm, nextSibling(elm));
  17292. removeVnodes(parent_2, [oldVnode], 0, 0);
  17293. }
  17294. }
  17295. return vnode;
  17296. }
  17297. var svgId = 0;
  17298. var SVGPainter = (function () {
  17299. function SVGPainter(root, storage, opts) {
  17300. this.type = 'svg';
  17301. this.refreshHover = createMethodNotSupport('refreshHover');
  17302. this.configLayer = createMethodNotSupport('configLayer');
  17303. this.storage = storage;
  17304. this._opts = opts = extend({}, opts);
  17305. this.root = root;
  17306. this._id = 'zr' + svgId++;
  17307. this._oldVNode = createSVGVNode(opts.width, opts.height);
  17308. if (root && !opts.ssr) {
  17309. var viewport = this._viewport = document.createElement('div');
  17310. viewport.style.cssText = 'position:relative;overflow:hidden';
  17311. var svgDom = this._svgDom = this._oldVNode.elm = createElement('svg');
  17312. updateAttrs(null, this._oldVNode);
  17313. viewport.appendChild(svgDom);
  17314. root.appendChild(viewport);
  17315. }
  17316. this.resize(opts.width, opts.height);
  17317. }
  17318. SVGPainter.prototype.getType = function () {
  17319. return this.type;
  17320. };
  17321. SVGPainter.prototype.getViewportRoot = function () {
  17322. return this._viewport;
  17323. };
  17324. SVGPainter.prototype.getViewportRootOffset = function () {
  17325. var viewportRoot = this.getViewportRoot();
  17326. if (viewportRoot) {
  17327. return {
  17328. offsetLeft: viewportRoot.offsetLeft || 0,
  17329. offsetTop: viewportRoot.offsetTop || 0
  17330. };
  17331. }
  17332. };
  17333. SVGPainter.prototype.getSvgDom = function () {
  17334. return this._svgDom;
  17335. };
  17336. SVGPainter.prototype.refresh = function () {
  17337. if (this.root) {
  17338. var vnode = this.renderToVNode({
  17339. willUpdate: true
  17340. });
  17341. vnode.attrs.style = 'position:absolute;left:0;top:0;user-select:none';
  17342. patch(this._oldVNode, vnode);
  17343. this._oldVNode = vnode;
  17344. }
  17345. };
  17346. SVGPainter.prototype.renderOneToVNode = function (el) {
  17347. return brush$1(el, createBrushScope(this._id));
  17348. };
  17349. SVGPainter.prototype.renderToVNode = function (opts) {
  17350. opts = opts || {};
  17351. var list = this.storage.getDisplayList(true);
  17352. var width = this._width;
  17353. var height = this._height;
  17354. var scope = createBrushScope(this._id);
  17355. scope.animation = opts.animation;
  17356. scope.willUpdate = opts.willUpdate;
  17357. scope.compress = opts.compress;
  17358. scope.emphasis = opts.emphasis;
  17359. scope.ssr = this._opts.ssr;
  17360. var children = [];
  17361. var bgVNode = this._bgVNode = createBackgroundVNode(width, height, this._backgroundColor, scope);
  17362. bgVNode && children.push(bgVNode);
  17363. var mainVNode = !opts.compress
  17364. ? (this._mainVNode = createVNode('g', 'main', {}, [])) : null;
  17365. this._paintList(list, scope, mainVNode ? mainVNode.children : children);
  17366. mainVNode && children.push(mainVNode);
  17367. var defs = map(keys(scope.defs), function (id) { return scope.defs[id]; });
  17368. if (defs.length) {
  17369. children.push(createVNode('defs', 'defs', {}, defs));
  17370. }
  17371. if (opts.animation) {
  17372. var animationCssStr = getCssString(scope.cssNodes, scope.cssAnims, { newline: true });
  17373. if (animationCssStr) {
  17374. var styleNode = createVNode('style', 'stl', {}, [], animationCssStr);
  17375. children.push(styleNode);
  17376. }
  17377. }
  17378. return createSVGVNode(width, height, children, opts.useViewBox);
  17379. };
  17380. SVGPainter.prototype.renderToString = function (opts) {
  17381. opts = opts || {};
  17382. return vNodeToString(this.renderToVNode({
  17383. animation: retrieve2(opts.cssAnimation, true),
  17384. emphasis: retrieve2(opts.cssEmphasis, true),
  17385. willUpdate: false,
  17386. compress: true,
  17387. useViewBox: retrieve2(opts.useViewBox, true)
  17388. }), { newline: true });
  17389. };
  17390. SVGPainter.prototype.setBackgroundColor = function (backgroundColor) {
  17391. this._backgroundColor = backgroundColor;
  17392. };
  17393. SVGPainter.prototype.getSvgRoot = function () {
  17394. return this._mainVNode && this._mainVNode.elm;
  17395. };
  17396. SVGPainter.prototype._paintList = function (list, scope, out) {
  17397. var listLen = list.length;
  17398. var clipPathsGroupsStack = [];
  17399. var clipPathsGroupsStackDepth = 0;
  17400. var currentClipPathGroup;
  17401. var prevClipPaths;
  17402. var clipGroupNodeIdx = 0;
  17403. for (var i = 0; i < listLen; i++) {
  17404. var displayable = list[i];
  17405. if (!displayable.invisible) {
  17406. var clipPaths = displayable.__clipPaths;
  17407. var len = clipPaths && clipPaths.length || 0;
  17408. var prevLen = prevClipPaths && prevClipPaths.length || 0;
  17409. var lca = void 0;
  17410. for (lca = Math.max(len - 1, prevLen - 1); lca >= 0; lca--) {
  17411. if (clipPaths && prevClipPaths
  17412. && clipPaths[lca] === prevClipPaths[lca]) {
  17413. break;
  17414. }
  17415. }
  17416. for (var i_1 = prevLen - 1; i_1 > lca; i_1--) {
  17417. clipPathsGroupsStackDepth--;
  17418. currentClipPathGroup = clipPathsGroupsStack[clipPathsGroupsStackDepth - 1];
  17419. }
  17420. for (var i_2 = lca + 1; i_2 < len; i_2++) {
  17421. var groupAttrs = {};
  17422. setClipPath(clipPaths[i_2], groupAttrs, scope);
  17423. var g = createVNode('g', 'clip-g-' + clipGroupNodeIdx++, groupAttrs, []);
  17424. (currentClipPathGroup ? currentClipPathGroup.children : out).push(g);
  17425. clipPathsGroupsStack[clipPathsGroupsStackDepth++] = g;
  17426. currentClipPathGroup = g;
  17427. }
  17428. prevClipPaths = clipPaths;
  17429. var ret = brush$1(displayable, scope);
  17430. if (ret) {
  17431. (currentClipPathGroup ? currentClipPathGroup.children : out).push(ret);
  17432. }
  17433. }
  17434. }
  17435. };
  17436. SVGPainter.prototype.resize = function (width, height) {
  17437. var opts = this._opts;
  17438. var root = this.root;
  17439. var viewport = this._viewport;
  17440. width != null && (opts.width = width);
  17441. height != null && (opts.height = height);
  17442. if (root && viewport) {
  17443. viewport.style.display = 'none';
  17444. width = getSize(root, 0, opts);
  17445. height = getSize(root, 1, opts);
  17446. viewport.style.display = '';
  17447. }
  17448. if (this._width !== width || this._height !== height) {
  17449. this._width = width;
  17450. this._height = height;
  17451. if (viewport) {
  17452. var viewportStyle = viewport.style;
  17453. viewportStyle.width = width + 'px';
  17454. viewportStyle.height = height + 'px';
  17455. }
  17456. if (!isPattern(this._backgroundColor)) {
  17457. var svgDom = this._svgDom;
  17458. if (svgDom) {
  17459. svgDom.setAttribute('width', width);
  17460. svgDom.setAttribute('height', height);
  17461. }
  17462. var bgEl = this._bgVNode && this._bgVNode.elm;
  17463. if (bgEl) {
  17464. bgEl.setAttribute('width', width);
  17465. bgEl.setAttribute('height', height);
  17466. }
  17467. }
  17468. else {
  17469. this.refresh();
  17470. }
  17471. }
  17472. };
  17473. SVGPainter.prototype.getWidth = function () {
  17474. return this._width;
  17475. };
  17476. SVGPainter.prototype.getHeight = function () {
  17477. return this._height;
  17478. };
  17479. SVGPainter.prototype.dispose = function () {
  17480. if (this.root) {
  17481. this.root.innerHTML = '';
  17482. }
  17483. this._svgDom =
  17484. this._viewport =
  17485. this.storage =
  17486. this._oldVNode =
  17487. this._bgVNode =
  17488. this._mainVNode = null;
  17489. };
  17490. SVGPainter.prototype.clear = function () {
  17491. if (this._svgDom) {
  17492. this._svgDom.innerHTML = null;
  17493. }
  17494. this._oldVNode = null;
  17495. };
  17496. SVGPainter.prototype.toDataURL = function (base64) {
  17497. var str = this.renderToString();
  17498. var prefix = 'data:image/svg+xml;';
  17499. if (base64) {
  17500. str = encodeBase64(str);
  17501. return str && prefix + 'base64,' + str;
  17502. }
  17503. return prefix + 'charset=UTF-8,' + encodeURIComponent(str);
  17504. };
  17505. return SVGPainter;
  17506. }());
  17507. function createMethodNotSupport(method) {
  17508. return function () {
  17509. {
  17510. logError('In SVG mode painter not support method "' + method + '"');
  17511. }
  17512. };
  17513. }
  17514. function createBackgroundVNode(width, height, backgroundColor, scope) {
  17515. var bgVNode;
  17516. if (backgroundColor && backgroundColor !== 'none') {
  17517. bgVNode = createVNode('rect', 'bg', {
  17518. width: width,
  17519. height: height,
  17520. x: '0',
  17521. y: '0'
  17522. });
  17523. if (isGradient(backgroundColor)) {
  17524. setGradient({ fill: backgroundColor }, bgVNode.attrs, 'fill', scope);
  17525. }
  17526. else if (isPattern(backgroundColor)) {
  17527. setPattern({
  17528. style: {
  17529. fill: backgroundColor
  17530. },
  17531. dirty: noop,
  17532. getBoundingRect: function () { return ({ width: width, height: height }); }
  17533. }, bgVNode.attrs, 'fill', scope);
  17534. }
  17535. else {
  17536. var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
  17537. bgVNode.attrs.fill = color;
  17538. opacity < 1 && (bgVNode.attrs['fill-opacity'] = opacity);
  17539. }
  17540. }
  17541. return bgVNode;
  17542. }
  17543. registerPainter('canvas', CanvasPainter);
  17544. registerPainter('svg', SVGPainter);
  17545. exports.Arc = Arc;
  17546. exports.ArcShape = ArcShape;
  17547. exports.BezierCurve = BezierCurve;
  17548. exports.BezierCurveShape = BezierCurveShape;
  17549. exports.BoundingRect = BoundingRect;
  17550. exports.Circle = Circle;
  17551. exports.CircleShape = CircleShape;
  17552. exports.CompoundPath = CompoundPath;
  17553. exports.Displayable = Displayable;
  17554. exports.Droplet = Droplet;
  17555. exports.DropletShape = DropletShape;
  17556. exports.Element = Element;
  17557. exports.Ellipse = Ellipse;
  17558. exports.EllipseShape = EllipseShape;
  17559. exports.Group = Group;
  17560. exports.Heart = Heart;
  17561. exports.HeartShape = HeartShape;
  17562. exports.Image = ZRImage;
  17563. exports.IncrementalDisplayable = IncrementalDisplayable;
  17564. exports.Isogon = Isogon;
  17565. exports.IsogonShape = IsogonShape;
  17566. exports.Line = Line;
  17567. exports.LineShape = LineShape;
  17568. exports.LinearGradient = LinearGradient;
  17569. exports.OrientedBoundingRect = OrientedBoundingRect;
  17570. exports.Path = Path;
  17571. exports.Pattern = Pattern;
  17572. exports.Point = Point;
  17573. exports.Polygon = Polygon;
  17574. exports.PolygonShape = PolygonShape;
  17575. exports.Polyline = Polyline;
  17576. exports.PolylineShape = PolylineShape;
  17577. exports.RadialGradient = RadialGradient;
  17578. exports.Rect = Rect;
  17579. exports.RectShape = RectShape;
  17580. exports.Ring = Ring;
  17581. exports.RingShape = RingShape;
  17582. exports.Rose = Rose;
  17583. exports.RoseShape = RoseShape;
  17584. exports.Sector = Sector;
  17585. exports.SectorShape = SectorShape;
  17586. exports.Star = Star;
  17587. exports.StarShape = StarShape;
  17588. exports.TSpan = TSpan;
  17589. exports.Text = ZRText;
  17590. exports.Trochoid = Trochoid;
  17591. exports.TrochoidShape = TrochoidShape;
  17592. exports.color = color;
  17593. exports.dispose = dispose;
  17594. exports.disposeAll = disposeAll;
  17595. exports.getElementSSRData = getElementSSRData;
  17596. exports.getInstance = getInstance;
  17597. exports.init = init;
  17598. exports.matrix = matrix;
  17599. exports.morph = morphPath$1;
  17600. exports.parseSVG = parseSVG;
  17601. exports.path = path;
  17602. exports.registerPainter = registerPainter;
  17603. exports.registerSSRDataGetter = registerSSRDataGetter;
  17604. exports.setPlatformAPI = setPlatformAPI;
  17605. exports.showDebugDirtyRect = showDebugDirtyRect;
  17606. exports.util = util;
  17607. exports.vector = vector;
  17608. exports.version = version;
  17609. Object.defineProperty(exports, '__esModule', { value: true });
  17610. })));
  17611. //# sourceMappingURL=zrender.js.map