kity.js 302 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574
  1. /*!
  2. * ====================================================
  3. * kity - v2.0.4 - 2016-08-22
  4. * https://github.com/fex-team/kity
  5. * GitHub: https://github.com/fex-team/kity.git
  6. * Copyright (c) 2016 Baidu FEX; Licensed BSD
  7. * ====================================================
  8. */
  9. (function () {
  10. var _p = {
  11. r: function(index) {
  12. if (_p[index].inited) {
  13. return _p[index].value;
  14. }
  15. if (typeof _p[index].value === "function") {
  16. var module = {
  17. exports: {}
  18. }, returnValue = _p[index].value(null, module.exports, module);
  19. _p[index].inited = true;
  20. _p[index].value = returnValue;
  21. if (returnValue !== undefined) {
  22. return returnValue;
  23. } else {
  24. for (var key in module.exports) {
  25. if (module.exports.hasOwnProperty(key)) {
  26. _p[index].inited = true;
  27. _p[index].value = module.exports;
  28. return module.exports;
  29. }
  30. }
  31. }
  32. } else {
  33. _p[index].inited = true;
  34. return _p[index].value;
  35. }
  36. }
  37. };
  38. //src/animate/animator.js
  39. /**
  40. * @fileOverview
  41. *
  42. * 提供基本的动画支持
  43. */
  44. _p[0] = {
  45. value: function(require) {
  46. function parseTime(str) {
  47. var value = parseFloat(str, 10);
  48. if (/ms/.test(str)) {
  49. return value;
  50. }
  51. if (/s/.test(str)) {
  52. return value * 1e3;
  53. }
  54. if (/min/.test(str)) {
  55. return value * 60 * 1e3;
  56. }
  57. return value;
  58. }
  59. var Timeline = _p.r(8);
  60. var easingTable = _p.r(1);
  61. /**
  62. * @class kity.Animator
  63. * @catalog animate
  64. * @description 表示一个动画启动器,可以作用于不同的对象进行动画
  65. */
  66. var Animator = _p.r(11).createClass("Animator", {
  67. /**
  68. * @constructor
  69. * @for kity.Animator
  70. * @catalog animate
  71. *
  72. * @grammar new kity.Animator(beginValue, finishValue, setter)
  73. * @grammar new kity.Animator(option)
  74. *
  75. * @param {any} beginValue|opt.beginValue
  76. * 动画的起始值,允许的类型有数字、数组、字面量、kity.Point、kity.Vector、kity.Box、kity.Matrix
  77. *
  78. * @param {any} finishValue|opt.beginValue
  79. * 动画的结束值,类型应于起始值相同
  80. *
  81. * @param {Function} setter|opt.setter
  82. * 值的使用函数,接受三个参数: function(target, value, timeline)
  83. * target {object} 动画的目标
  84. * value {any} 动画的当前值
  85. * timeline {kity.Timeline} 动画当前的时间线对象
  86. */
  87. constructor: function(beginValue, finishValue, setter) {
  88. if (arguments.length == 1) {
  89. var opt = arguments[0];
  90. this.beginValue = opt.beginValue;
  91. this.finishValue = opt.finishValue;
  92. this.setter = opt.setter;
  93. } else {
  94. this.beginValue = beginValue;
  95. this.finishValue = finishValue;
  96. this.setter = setter;
  97. }
  98. },
  99. /**
  100. * @method start()
  101. * @for kity.Animator
  102. * @description 使用当前的动画器启动在指定目标上启动动画
  103. *
  104. * @grammar start(target, duration, easing, delay, callback) => {kity.Timeline}
  105. * @grammar start(target, option) => {kity.Timeline}
  106. *
  107. * @param {object} target
  108. * 启动动画的目标
  109. *
  110. * @param {Number|String} duration|option.duration
  111. * [Optional] 动画的持续时间,如 300、"300ms"、"1.5min"
  112. *
  113. * @param {String|Function} easing|option.easing
  114. * [Optional] 动画使用的缓动函数,如 "ease"、"linear"、"swing"
  115. *
  116. * @param {Number|String} delay|option.delay
  117. * [Optional] 动画的播放延迟时间
  118. *
  119. * @param {Function} callback|option.callback
  120. * [Optional] 动画结束后的回调函数
  121. *
  122. * @example
  123. *
  124. * ```js
  125. * var turnRed = new kity.Animator(
  126. * new kity.Color('yellow'),
  127. * new kity.Color('red'),
  128. * function(target, value) {
  129. * target.fill(value);
  130. * });
  131. *
  132. * turnRed.start(rect, 300, 'ease', function() {
  133. * console.log('I am red!');
  134. * });
  135. * ```
  136. */
  137. start: function(target, duration, easing, delay, callback) {
  138. if (arguments.length === 2 && typeof duration == "object") {
  139. easing = duration.easing;
  140. delay = duration.delay;
  141. callback = duration.callback;
  142. duration = duration.duration;
  143. }
  144. if (arguments.length === 4 && typeof delay == "function") {
  145. callback = delay;
  146. delay = 0;
  147. }
  148. var timeline = this.create(target, duration, easing, callback);
  149. delay = parseTime(delay);
  150. if (delay > 0) {
  151. setTimeout(function() {
  152. timeline.play();
  153. }, delay);
  154. } else {
  155. timeline.play();
  156. }
  157. return timeline;
  158. },
  159. /**
  160. * @method create()
  161. * @for kity.Animator
  162. * @description 使用当前的动画器为指定目标创建时间线
  163. *
  164. * @grammar create(target, duration, easing, callback) => {kity.Timeline}
  165. *
  166. * @param {object} target 要创建的时间线的目标
  167. * @param {Number|String} duration 要创建的时间线的长度,如 300、"5s"、"0.5min"
  168. * @param {String|Function} easing 要创建的时间线的缓动函数,如 'ease'、'linear'、'swing'
  169. * @param {Function} callback 时间线播放结束之后的回调函数
  170. *
  171. * @example
  172. *
  173. * ```js
  174. * var expand = new kity.Animator({
  175. * beginValue: function(target) {
  176. * return target.getBox();
  177. * },
  178. * finishValue: function(target) {
  179. * return target.getBox().expand(100, 100, 100, 100);
  180. * },
  181. * setter: function(target, value) {
  182. * target.setBox(value)
  183. * }
  184. * });
  185. *
  186. * var timeline = expand.create(rect, 300);
  187. * timeline.repeat(3).play();
  188. * ```
  189. */
  190. create: function(target, duration, easing, callback) {
  191. var timeline;
  192. duration = duration && parseTime(duration) || Animator.DEFAULT_DURATION;
  193. easing = easing || Animator.DEFAULT_EASING;
  194. if (typeof easing == "string") {
  195. easing = easingTable[easing];
  196. }
  197. timeline = new Timeline(this, target, duration, easing);
  198. if (typeof callback == "function") {
  199. timeline.on("finish", callback);
  200. }
  201. return timeline;
  202. },
  203. /**
  204. * @method reverse()
  205. * @for kity.Animator
  206. * @grammar reverse() => {kity.Animator}
  207. * @description 创建一个与当前动画器相反的动画器
  208. *
  209. * @example
  210. *
  211. * ```js
  212. * var turnYellow = turnRed.reverse();
  213. * ```
  214. */
  215. reverse: function() {
  216. return new Animator(this.finishValue, this.beginValue, this.setter);
  217. }
  218. });
  219. Animator.DEFAULT_DURATION = 300;
  220. Animator.DEFAULT_EASING = "linear";
  221. var Shape = _p.r(61);
  222. _p.r(11).extendClass(Shape, {
  223. /**
  224. * @method animate()
  225. * @for kity.Shape
  226. * @description 在图形上播放使用指定的动画器播放动画,如果图形当前有动画正在播放,则会加入播放队列
  227. *
  228. * @grammar animate(animator, duration, easing, delay, callback)
  229. *
  230. * @param {object} animator 播放动画使用的动画器
  231. * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
  232. * @param {Number|String} delay 动画播放前的延时
  233. * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
  234. * @param {Function} callback 播放结束之后的回调函数
  235. *
  236. * @example
  237. *
  238. * ```js
  239. * rect.animate(turnRed, 300); // turnRect 是一个动画器
  240. * rect.animate(expand, 500); // turnRect 播放结束后播放 expand
  241. * ```
  242. */
  243. animate: function(animator, duration, easing, delay, callback) {
  244. var queue = this._KityAnimateQueue = this._KityAnimateQueue || [];
  245. var timeline = animator.create(this, duration, easing, callback);
  246. function dequeue() {
  247. queue.shift();
  248. if (queue.length) {
  249. setTimeout(queue[0].t.play.bind(queue[0].t), queue[0].d);
  250. }
  251. }
  252. timeline.on("finish", dequeue);
  253. queue.push({
  254. t: timeline,
  255. d: delay
  256. });
  257. if (queue.length == 1) {
  258. setTimeout(timeline.play.bind(timeline), delay);
  259. }
  260. return this;
  261. },
  262. /**
  263. * @method timeline()
  264. * @for kity.Shape
  265. * @description 获得当前正在播放的动画的时间线
  266. *
  267. * @grammar timeline() => {kity.Timeline}
  268. *
  269. * @example
  270. *
  271. * ```js
  272. * rect.timeline().repeat(2);
  273. * ```
  274. */
  275. timeline: function() {
  276. return this._KityAnimateQueue[0].t;
  277. },
  278. /**
  279. * @method stop()
  280. * @for kity.Shape
  281. * @description 停止当前正在播放的动画
  282. *
  283. * @grammar stop() => {this}
  284. *
  285. * @example
  286. *
  287. * ```js
  288. * rect.stop(); // 停止 rect 上的动画
  289. * ```
  290. */
  291. stop: function() {
  292. var queue = this._KityAnimateQueue;
  293. if (queue) {
  294. while (queue.length) {
  295. queue.shift().t.stop();
  296. }
  297. }
  298. return this;
  299. }
  300. });
  301. return Animator;
  302. }
  303. };
  304. //src/animate/easing.js
  305. /**
  306. * Kity Animate Easing modified from jQuery Easing
  307. * Author: techird
  308. * Changes:
  309. * 1. make easing functions standalone
  310. * 2. remove the 'x' parameter
  311. */
  312. /* ============================================================
  313. * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
  314. *
  315. * Open source under the BSD License.
  316. *
  317. * Copyright © 2008 George McGinley Smith
  318. * All rights reserved.
  319. * https://raw.github.com/danro/jquery-easing/master/LICENSE
  320. * ======================================================== */
  321. _p[1] = {
  322. value: function(require, exports, module) {
  323. var easings = {
  324. // t: current_time, b: begin_value, c: change_value, d: duration
  325. linear: function(t, b, c, d) {
  326. return c * (t / d) + b;
  327. },
  328. swing: function(t, b, c, d) {
  329. return easings.easeOutQuad(t, b, c, d);
  330. },
  331. ease: function(t, b, c, d) {
  332. return easings.easeInOutCubic(t, b, c, d);
  333. },
  334. easeInQuad: function(t, b, c, d) {
  335. return c * (t /= d) * t + b;
  336. },
  337. easeOutQuad: function(t, b, c, d) {
  338. return -c * (t /= d) * (t - 2) + b;
  339. },
  340. easeInOutQuad: function(t, b, c, d) {
  341. if ((t /= d / 2) < 1) return c / 2 * t * t + b;
  342. return -c / 2 * (--t * (t - 2) - 1) + b;
  343. },
  344. easeInCubic: function(t, b, c, d) {
  345. return c * (t /= d) * t * t + b;
  346. },
  347. easeOutCubic: function(t, b, c, d) {
  348. return c * ((t = t / d - 1) * t * t + 1) + b;
  349. },
  350. easeInOutCubic: function(t, b, c, d) {
  351. if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
  352. return c / 2 * ((t -= 2) * t * t + 2) + b;
  353. },
  354. easeInQuart: function(t, b, c, d) {
  355. return c * (t /= d) * t * t * t + b;
  356. },
  357. easeOutQuart: function(t, b, c, d) {
  358. return -c * ((t = t / d - 1) * t * t * t - 1) + b;
  359. },
  360. easeInOutQuart: function(t, b, c, d) {
  361. if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
  362. return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
  363. },
  364. easeInQuint: function(t, b, c, d) {
  365. return c * (t /= d) * t * t * t * t + b;
  366. },
  367. easeOutQuint: function(t, b, c, d) {
  368. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  369. },
  370. easeInOutQuint: function(t, b, c, d) {
  371. if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
  372. return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
  373. },
  374. easeInSine: function(t, b, c, d) {
  375. return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
  376. },
  377. easeOutSine: function(t, b, c, d) {
  378. return c * Math.sin(t / d * (Math.PI / 2)) + b;
  379. },
  380. easeInOutSine: function(t, b, c, d) {
  381. return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
  382. },
  383. easeInExpo: function(t, b, c, d) {
  384. return t === 0 ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
  385. },
  386. easeOutExpo: function(t, b, c, d) {
  387. return t == d ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
  388. },
  389. easeInOutExpo: function(t, b, c, d) {
  390. if (t === 0) return b;
  391. if (t == d) return b + c;
  392. if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
  393. return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
  394. },
  395. easeInCirc: function(t, b, c, d) {
  396. return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
  397. },
  398. easeOutCirc: function(t, b, c, d) {
  399. return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
  400. },
  401. easeInOutCirc: function(t, b, c, d) {
  402. if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
  403. return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
  404. },
  405. easeInElastic: function(t, b, c, d) {
  406. var s = 1.70158;
  407. var p = 0;
  408. var a = c;
  409. if (t === 0) return b;
  410. if ((t /= d) == 1) return b + c;
  411. if (!p) p = d * .3;
  412. if (a < Math.abs(c)) {
  413. a = c;
  414. s = p / 4;
  415. } else s = p / (2 * Math.PI) * Math.asin(c / a);
  416. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
  417. },
  418. easeOutElastic: function(t, b, c, d) {
  419. var s = 1.70158;
  420. var p = 0;
  421. var a = c;
  422. if (t === 0) return b;
  423. if ((t /= d) == 1) return b + c;
  424. if (!p) p = d * .3;
  425. if (a < Math.abs(c)) {
  426. a = c;
  427. s = p / 4;
  428. } else s = p / (2 * Math.PI) * Math.asin(c / a);
  429. return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
  430. },
  431. easeInOutElastic: function(t, b, c, d) {
  432. var s = 1.70158;
  433. var p = 0;
  434. var a = c;
  435. if (t === 0) return b;
  436. if ((t /= d / 2) == 2) return b + c;
  437. if (!p) p = d * (.3 * 1.5);
  438. if (a < Math.abs(c)) {
  439. a = c;
  440. var s = p / 4;
  441. } else var s = p / (2 * Math.PI) * Math.asin(c / a);
  442. if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
  443. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
  444. },
  445. easeInBack: function(t, b, c, d, s) {
  446. if (s == undefined) s = 1.70158;
  447. return c * (t /= d) * t * ((s + 1) * t - s) + b;
  448. },
  449. easeOutBack: function(t, b, c, d, s) {
  450. if (s == undefined) s = 1.70158;
  451. return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
  452. },
  453. easeInOutBack: function(t, b, c, d, s) {
  454. if (s == undefined) s = 1.70158;
  455. if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
  456. return c / 2 * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
  457. },
  458. easeInBounce: function(t, b, c, d) {
  459. return c - easings.easeOutBounce(d - t, 0, c, d) + b;
  460. },
  461. easeOutBounce: function(t, b, c, d) {
  462. if ((t /= d) < 1 / 2.75) {
  463. return c * (7.5625 * t * t) + b;
  464. } else if (t < 2 / 2.75) {
  465. return c * (7.5625 * (t -= 1.5 / 2.75) * t + .75) + b;
  466. } else if (t < 2.5 / 2.75) {
  467. return c * (7.5625 * (t -= 2.25 / 2.75) * t + .9375) + b;
  468. } else {
  469. return c * (7.5625 * (t -= 2.625 / 2.75) * t + .984375) + b;
  470. }
  471. },
  472. easeInOutBounce: function(t, b, c, d) {
  473. if (t < d / 2) return easings.easeInBounce(t * 2, 0, c, d) * .5 + b;
  474. return easings.easeOutBounce(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
  475. }
  476. };
  477. return easings;
  478. }
  479. };
  480. /*
  481. *
  482. * TERMS OF USE - EASING EQUATIONS
  483. *
  484. * Open source under the BSD License.
  485. *
  486. * Copyright © 2001 Robert Penner
  487. * All rights reserved.
  488. *
  489. * Redistribution and use in source and binary forms, with or without modification,
  490. * are permitted provided that the following conditions are met:
  491. *
  492. * Redistributions of source code must retain the above copyright notice, this list of
  493. * conditions and the following disclaimer.
  494. * Redistributions in binary form must reproduce the above copyright notice, this list
  495. * of conditions and the following disclaimer in the documentation and/or other materials
  496. * provided with the distribution.
  497. *
  498. * Neither the name of the author nor the names of contributors may be used to endorse
  499. * or promote products derived from this software without specific prior written permission.
  500. *
  501. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  502. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  503. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  504. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  505. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  506. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  507. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  508. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  509. * OF THE POSSIBILITY OF SUCH DAMAGE.
  510. *
  511. */
  512. //src/animate/frame.js
  513. /**
  514. * @fileOverview
  515. *
  516. * 提供动画帧的基本支持
  517. */
  518. _p[2] = {
  519. value: function(require, exports) {
  520. // 原生动画帧方法 polyfill
  521. var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function(fn) {
  522. return setTimeout(fn, 1e3 / 60);
  523. };
  524. var cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame || window.clearTimeout;
  525. // 上一个请求的原生动画帧 id
  526. var frameRequestId;
  527. // 等待执行的帧动作的集合,这些帧的方法将在下个原生动画帧同步执行
  528. var pendingFrames = [];
  529. /**
  530. * 添加一个帧到等待集合中
  531. *
  532. * 如果添加的帧是序列的第一个,至少有一个帧需要被执行,则会请求一个原生动画帧来执行
  533. */
  534. function pushFrame(frame) {
  535. if (pendingFrames.push(frame) === 1) {
  536. frameRequestId = requestAnimationFrame(executePendingFrames);
  537. }
  538. }
  539. /**
  540. * 执行所有等待帧
  541. */
  542. function executePendingFrames() {
  543. var frames = pendingFrames;
  544. pendingFrames = [];
  545. while (frames.length) {
  546. executeFrame(frames.pop());
  547. }
  548. frameRequestId = 0;
  549. }
  550. /**
  551. * @method kity.requestFrame
  552. * @catalog animate
  553. * @grammar kity.requestFrame(action) => {frame}
  554. * @description 请求一个帧,执行指定的动作。动作回调提供一些有用的信息
  555. *
  556. * @param {Function} action
  557. *
  558. * 要执行的动作,该动作回调有一个参数 frame,其中:
  559. *
  560. * frame.time {Number}
  561. * 动作执行时的时间戳(ms)
  562. *
  563. * frame.index {Number}
  564. * 当前执行的帧的编号(首帧为 0)
  565. *
  566. * frame.dur {Number}
  567. * 上一帧至当前帧经过的时间,单位 ms
  568. *
  569. * frame.elapsed {Number}
  570. * 从首帧开始到当前帧经过的时间,单位 ms
  571. *
  572. * frame.action {Number}
  573. * 指向当前的帧处理函数
  574. *
  575. * frame.next()
  576. * 表示下一帧继续执行。如果不调用该方法,将不会执行下一帧。
  577. *
  578. * @example
  579. *
  580. * ```js
  581. * kity.requestFrame(function(frame) {
  582. * console.log('平均帧率:' + frame.elapsed / (frame.index + 1));
  583. *
  584. * // 更新或渲染动作
  585. *
  586. * frame.next(); //继续执行下一帧
  587. * });
  588. * ```
  589. */
  590. function requestFrame(action) {
  591. var frame = initFrame(action);
  592. pushFrame(frame);
  593. return frame;
  594. }
  595. /**
  596. * @method kity.releaseFrame
  597. * @catalog animate
  598. * @grammar kity.releaseFrame(frame)
  599. * @description 释放一个已经请求过的帧,如果该帧在等待集合里,将移除,下个动画帧不会执行释放的帧
  600. *
  601. * @param {frame} frame 使用 kity.requestFrame() 返回的帧
  602. *
  603. * @example
  604. *
  605. * ```js
  606. * var frame = kity.requestFrame(function() {....});
  607. * kity.releaseFrame(frame);
  608. * ```
  609. */
  610. function releaseFrame(frame) {
  611. var index = pendingFrames.indexOf(frame);
  612. if (~index) {
  613. pendingFrames.splice(index, 1);
  614. }
  615. if (pendingFrames.length === 0) {
  616. cancelAnimationFrame(frameRequestId);
  617. }
  618. }
  619. /**
  620. * 初始化一个帧,主要用于后续计算
  621. */
  622. function initFrame(action) {
  623. var frame = {
  624. index: 0,
  625. time: +new Date(),
  626. elapsed: 0,
  627. action: action,
  628. next: function() {
  629. pushFrame(frame);
  630. }
  631. };
  632. return frame;
  633. }
  634. /**
  635. * 执行一个帧动作
  636. */
  637. function executeFrame(frame) {
  638. // 当前帧时间错
  639. var time = +new Date();
  640. // 当上一帧到当前帧经过的时间
  641. var dur = time - frame.time;
  642. //
  643. // http://stackoverflow.com/questions/13133434/requestanimationframe-detect-stop
  644. // 浏览器最小化或切换标签,requestAnimationFrame 不会执行。
  645. // 检测时间超过 200 ms(频率小于 5Hz ) 判定为计时器暂停,重置为一帧长度
  646. //
  647. if (dur > 200) {
  648. dur = 1e3 / 60;
  649. }
  650. frame.dur = dur;
  651. frame.elapsed += dur;
  652. frame.time = time;
  653. frame.action.call(null, frame);
  654. frame.index++;
  655. }
  656. // 暴露
  657. exports.requestFrame = requestFrame;
  658. exports.releaseFrame = releaseFrame;
  659. }
  660. };
  661. //src/animate/motionanimator.js
  662. /**
  663. * @fileOverview
  664. *
  665. * 路径动画器,可以让一个物体沿着某个轨迹运动
  666. */
  667. _p[3] = {
  668. value: function(require) {
  669. var Animator = _p.r(0);
  670. var g = _p.r(35);
  671. var Path = _p.r(47);
  672. var Shape = _p.r(61);
  673. /**
  674. * @class kity.MotionAnimator
  675. * @catalog animate
  676. * @base kity.Animator
  677. * @description 路径动画器,可以让一个物体沿着某个轨迹运动
  678. *
  679. * @example
  680. *
  681. * ```js
  682. * var motionAnimator = new MotionAnimator('M0,0C100,0,100,0,100,100L200,200');
  683. * motionAnimator.start(rect, 3000);
  684. * ```
  685. */
  686. var MotionAnimator = _p.r(11).createClass("MotionAnimator", {
  687. base: Animator,
  688. /**
  689. * @constructor
  690. * @for kity.MotionAnimator
  691. * @grammar new kity.MotionAnimator(path, doRotate)
  692. * @param {kity.Path|String|PathSegment} path 运动的轨迹,或者是 kity.Path 对象
  693. * @param {boolean} doRotate 是否让运动的目标沿着路径的切线方向旋转
  694. */
  695. constructor: function(path, doRotate) {
  696. var me = this;
  697. this.callBase({
  698. beginValue: 0,
  699. finishValue: 1,
  700. setter: function(target, value) {
  701. var path = me.motionPath instanceof Path ? me.motionPath.getPathData() : me.motionPath;
  702. var point = g.pointAtPath(path, value);
  703. target.setTranslate(point.x, point.y);
  704. if (this.doRotate) target.setRotate(point.tan.getAngle());
  705. }
  706. });
  707. /**
  708. * @property doRotate
  709. * @for kity.MotionAnimator
  710. * @type {boolean}
  711. * @description 是否让运动的目标沿着路径的切线方向旋转
  712. *
  713. * @example
  714. *
  715. * ```js
  716. * motionAnimator.doRotate = true; // 目标沿着切线方向旋转
  717. * ```
  718. */
  719. this.doRotate = doRotate;
  720. /**
  721. * @property motionPath
  722. * @for kity.MotionAnimator
  723. * @type {kity.Path|String|PathSegment}
  724. * @description 运动沿着的路径,可以在动画过程中更新
  725. */
  726. this.motionPath = path;
  727. }
  728. });
  729. _p.r(11).extendClass(Shape, {
  730. /**
  731. * @method motion()
  732. * @catalog animate
  733. * @for kity.Shape
  734. * @description 让图形沿着指定的路径运动
  735. *
  736. * @grammar motion(path, duration, easing, delay, callback) => this
  737. *
  738. * @param {kity.Path|String|PathSegment} path 运动的轨迹,或者是 kity.Path 对象
  739. * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
  740. * @param {Number|String} delay 动画播放前的延时
  741. * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
  742. * @param {Function} callback 播放结束之后的回调函数
  743. */
  744. motion: function(path, duration, easing, delay, callback) {
  745. return this.animate(new MotionAnimator(path), duration, easing, delay, callback);
  746. }
  747. });
  748. return MotionAnimator;
  749. }
  750. };
  751. //src/animate/opacityanimator.js
  752. /**
  753. * @fileOverview
  754. *
  755. * 透明度动画器,让图形动画过度到指定的透明度。
  756. */
  757. _p[4] = {
  758. value: function(require) {
  759. var Animator = _p.r(0);
  760. /**
  761. * @class kity.OpacityAnimator
  762. * @catalog animate
  763. * @base kity.Animator
  764. * @description 透明度动画器,让图形动画过度到指定的透明度
  765. */
  766. var OpacityAnimator = _p.r(11).createClass("OpacityAnimator", {
  767. base: Animator,
  768. /**
  769. * @constructor
  770. * @for kity.OpacityAnimator
  771. * @grammar new kity.OpacityAnimator(opacity)
  772. *
  773. * @param {Number} opacity 目标透明度,取值范围 0 - 1
  774. */
  775. constructor: function(opacity) {
  776. this.callBase({
  777. beginValue: function(target) {
  778. return target.getOpacity();
  779. },
  780. finishValue: opacity,
  781. setter: function(target, value) {
  782. target.setOpacity(value);
  783. }
  784. });
  785. }
  786. });
  787. var Shape = _p.r(61);
  788. _p.r(11).extendClass(Shape, {
  789. /**
  790. * @method fxOpacity()
  791. * @catalog animate
  792. * @for kity.Shape
  793. * @description 让图形的透明度以动画的形式过渡到指定的值
  794. *
  795. * @grammar fxOpacity(opacity, duration, easing, delay, callback) => {this}
  796. *
  797. * @param {Number} opacity 动画的目标透明度
  798. * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
  799. * @param {Number|String} delay 动画播放前的延时
  800. * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
  801. * @param {Function} callback 播放结束之后的回调函数
  802. */
  803. fxOpacity: function(opacity, duration, easing, delay, callback) {
  804. return this.animate(new OpacityAnimator(opacity), duration, easing, delay, callback);
  805. },
  806. /**
  807. * @method fadeTo()
  808. * @catalog animate
  809. * @for kity.Shape
  810. * @description 让图形的透明度以动画的形式过渡到指定的值
  811. *
  812. * @grammar fadeTo(opacity, duration, easing, delay, callback) => {this}
  813. *
  814. * @param {Number} opacity 动画的目标透明度
  815. * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
  816. * @param {Number|String} delay 动画播放前的延时
  817. * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
  818. * @param {Function} callback 播放结束之后的回调函数
  819. */
  820. fadeTo: function() {
  821. return this.fxOpacity.apply(this, arguments);
  822. },
  823. /**
  824. * @method fadeIn()
  825. * @catalog animate
  826. * @for kity.Shape
  827. * @description 让图形淡入
  828. *
  829. * @grammar fadeIn(duration, easing, delay, callback) => {this}
  830. *
  831. * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
  832. * @param {Number|String} delay 动画播放前的延时
  833. * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
  834. * @param {Function} callback 播放结束之后的回调函数
  835. */
  836. fadeIn: function() {
  837. return this.fxOpacity.apply(this, [ 1 ].concat([].slice.call(arguments)));
  838. },
  839. /**
  840. * @method fadeOut()
  841. * @catalog animate
  842. * @for kity.Shape
  843. * @description 让图形淡出
  844. *
  845. * @grammar fadeIn(duration, easing, delay, callback) => {this}
  846. *
  847. * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
  848. * @param {Number|String} delay 动画播放前的延时
  849. * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
  850. * @param {Function} callback 播放结束之后的回调函数
  851. */
  852. fadeOut: function() {
  853. return this.fxOpacity.apply(this, [ 0 ].concat([].slice.call(arguments)));
  854. }
  855. });
  856. return OpacityAnimator;
  857. }
  858. };
  859. //src/animate/pathanimator.js
  860. /**
  861. * @fileOverview
  862. *
  863. * 路径补间动画器,让图形从一个形状变为另一个形状
  864. */
  865. _p[5] = {
  866. value: function(require) {
  867. var Animator = _p.r(0);
  868. var g = _p.r(35);
  869. /**
  870. * @catalog animate
  871. *
  872. * @class kity.PathAnimator
  873. * @base kity.Animator
  874. * @description 路径补间动画器,让图形从一个形状变为另一个形状
  875. *
  876. * @example
  877. *
  878. * ```js
  879. * var path = new kity.Path('M0,0L0,100');
  880. * var pa = new kity.PathAnimator('M0,0C100,0,100,0,100,100');
  881. * pa.start(path, 300);
  882. * ```
  883. */
  884. var PathAnimator = _p.r(11).createClass("OpacityAnimator", {
  885. base: Animator,
  886. /**
  887. * @constructor
  888. * @for kity.PathAnimator
  889. *
  890. * @grammar new kity.Path.Animator(path)
  891. *
  892. * @param {String|PathSegment} path 目标形状的路径数据
  893. *
  894. */
  895. constructor: function(path) {
  896. this.callBase({
  897. beginValue: function(target) {
  898. this.beginPath = target.getPathData();
  899. return 0;
  900. },
  901. finishValue: 1,
  902. setter: function(target, value) {
  903. target.setPathData(g.pathTween(this.beginPath, path, value));
  904. }
  905. });
  906. }
  907. });
  908. var Path = _p.r(47);
  909. _p.r(11).extendClass(Path, {
  910. /**
  911. * @catalog animate
  912. *
  913. * @method fxPath()
  914. * @for kity.Shape
  915. * @description 以动画的形式把路径变换为新路径
  916. *
  917. * @grammar fxPath(path, duration, easing, delay, callback) => {this}
  918. *
  919. * @param {String|PathSegment} path 要变换新路径
  920. * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
  921. * @param {Number|String} delay 动画播放前的延时
  922. * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
  923. * @param {Function} callback 播放结束之后的回调函数
  924. */
  925. fxPath: function(path, duration, easing, delay, callback) {
  926. return this.animate(new PathAnimator(path), duration, easing, delay, callback);
  927. }
  928. });
  929. return PathAnimator;
  930. }
  931. };
  932. //src/animate/rotateanimator.js
  933. /**
  934. * @fileOverview
  935. *
  936. * 提供支持目标旋转的动画器
  937. */
  938. _p[6] = {
  939. value: function(require) {
  940. var Animator = _p.r(0);
  941. /**
  942. * @class kity.RotateAnimator
  943. * @base Animator
  944. * @description 提供支持目标旋转的动画器
  945. */
  946. var RotateAnimator = _p.r(11).createClass("RotateAnimator", {
  947. base: Animator,
  948. /**
  949. * @constructor
  950. * @for kity.RotateAnimator
  951. *
  952. * @grammar new kity.RotateAnimator(deg, ax, ay)
  953. *
  954. * @param {Number} deg 要旋转的角度
  955. */
  956. constructor: function(deg) {
  957. this.callBase({
  958. beginValue: 0,
  959. finishValue: deg,
  960. setter: function(target, value, timeline) {
  961. var delta = timeline.getDelta();
  962. target.rotate(delta);
  963. }
  964. });
  965. }
  966. });
  967. var Shape = _p.r(61);
  968. _p.r(11).extendClass(Shape, {
  969. /**
  970. * @method fxRotate()
  971. * @for kity.Shape
  972. * @description 让目标以动画旋转指定的角度
  973. *
  974. * @grammar fxRotate(deg, duration, easing, delay) => {this}
  975. *
  976. * @param {Number} deg 要旋转的角度
  977. * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
  978. * @param {Number|String} delay 动画播放前的延时
  979. * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
  980. * @param {Function} callback 播放结束之后的回调函数
  981. */
  982. fxRotate: function(deg, duration, easing, delay, callback) {
  983. return this.animate(new RotateAnimator(deg), duration, easing, delay, callback);
  984. }
  985. });
  986. return RotateAnimator;
  987. }
  988. };
  989. //src/animate/scaleanimator.js
  990. /**
  991. * @fileOverview
  992. *
  993. * 提供支持目标缩放的动画器
  994. */
  995. _p[7] = {
  996. value: function(require) {
  997. var Animator = _p.r(0);
  998. /**
  999. * @class kity.ScaleAnimator
  1000. * @base kity.Animator
  1001. * @description 提供支持目标缩放的动画器
  1002. */
  1003. var ScaleAnimator = _p.r(11).createClass("ScaleAnimator", {
  1004. base: Animator,
  1005. /**
  1006. * @constructor
  1007. * @for kity.ScaleAnimator
  1008. *
  1009. * @grammar new kity.ScaleAnimator(sx, sy)
  1010. * @param {Number} sx x 轴的缩放比例
  1011. * @param {Number} sy y 轴的缩放比例
  1012. */
  1013. constructor: function(sx, sy) {
  1014. this.callBase({
  1015. beginValue: 0,
  1016. finishValue: 1,
  1017. setter: function(target, value, timeline) {
  1018. var delta = timeline.getDelta();
  1019. var kx = Math.pow(sx, delta);
  1020. var ky = Math.pow(sy, delta);
  1021. target.scale(ky, kx);
  1022. }
  1023. });
  1024. }
  1025. });
  1026. var Shape = _p.r(61);
  1027. _p.r(11).extendClass(Shape, {
  1028. /**
  1029. * @method fxScale
  1030. * @for kity.Shape
  1031. * @description 动画缩放当前的图形
  1032. *
  1033. * @grammar fxScale(sx, sy, duration, easing, delay, callback) => {this}
  1034. *
  1035. * @param {Number} sx x 轴的缩放比例
  1036. * @param {Number} sy y 轴的缩放比例
  1037. * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
  1038. * @param {Number|String} delay 动画播放前的延时
  1039. * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
  1040. * @param {Function} callback 播放结束之后的回调函数
  1041. */
  1042. fxScale: function(sx, sy, duration, easing, delay, callback) {
  1043. return this.animate(new ScaleAnimator(sx, sy), duration, easing, delay, callback);
  1044. }
  1045. });
  1046. return ScaleAnimator;
  1047. }
  1048. };
  1049. //src/animate/timeline.js
  1050. /**
  1051. * @fileOverview
  1052. *
  1053. * 动画时间线的实现
  1054. */
  1055. _p[8] = {
  1056. value: function(require) {
  1057. var EventHandler = _p.r(34);
  1058. var utils = _p.r(12);
  1059. var frame = _p.r(2);
  1060. function getPercentValue(b, f, p) {
  1061. return utils.paralle(b, f, function(b, f) {
  1062. return b + (f - b) * p;
  1063. });
  1064. }
  1065. function getDelta(v1, v2) {
  1066. return utils.paralle(v1, v2, function(v1, v2) {
  1067. return v2 - v1;
  1068. });
  1069. }
  1070. function TimelineEvent(timeline, type, param) {
  1071. this.timeline = timeline;
  1072. this.target = timeline.target;
  1073. this.type = type;
  1074. for (var name in param) {
  1075. if (param.hasOwnProperty(name)) {
  1076. this[name] = param[name];
  1077. }
  1078. }
  1079. }
  1080. /**
  1081. * @class kity.Timeline
  1082. * @catalog animate
  1083. * @mixins EventHandler
  1084. * @description 动画时间线
  1085. */
  1086. var Timeline = _p.r(11).createClass("Timeline", {
  1087. mixins: [ EventHandler ],
  1088. /**
  1089. * @constructor
  1090. * @for kity.Timeline
  1091. * @private
  1092. * @description 时间线应该由动画器进行构造,不应手动创建
  1093. *
  1094. */
  1095. constructor: function(animator, target, duration, easing) {
  1096. this.callMixin();
  1097. this.target = target;
  1098. this.time = 0;
  1099. this.duration = duration;
  1100. this.easing = easing;
  1101. this.animator = animator;
  1102. this.beginValue = animator.beginValue;
  1103. this.finishValue = animator.finishValue;
  1104. this.setter = animator.setter;
  1105. this.status = "ready";
  1106. },
  1107. /**
  1108. * @private
  1109. *
  1110. * 让时间线进入下一帧
  1111. */
  1112. nextFrame: function(frame) {
  1113. if (this.status != "playing") {
  1114. return;
  1115. }
  1116. this.time += frame.dur;
  1117. this.setValue(this.getValue());
  1118. if (this.time >= this.duration) {
  1119. this.timeUp();
  1120. }
  1121. frame.next();
  1122. },
  1123. /**
  1124. * @method getPlayTime()
  1125. * @for kity.Timeline
  1126. * @grammar getPlayTime() => {Number}
  1127. * @description 获得当前播放的时间,取值区间为 [0, duration]
  1128. */
  1129. getPlayTime: function() {
  1130. return this.rollbacking ? this.duration - this.time : this.time;
  1131. },
  1132. /**
  1133. * @method getTimeProportion()
  1134. * @for kity.Timeline
  1135. * @grammar getTimeProportion() => {Number}
  1136. * @description 获得当前播放时间的比例,取值区间为 [0, 1]
  1137. */
  1138. getTimeProportion: function() {
  1139. return this.getPlayTime() / this.duration;
  1140. },
  1141. /**
  1142. * @method getValueProportion()
  1143. * @for kity.Timeline
  1144. * @grammar getValueProportion() => {Number}
  1145. * @description 获得当前播放时间对应值的比例,取值区间为 [0, 1];该值实际上是时间比例值经过缓动函数计算之后的值。
  1146. */
  1147. getValueProportion: function() {
  1148. return this.easing(this.getPlayTime(), 0, 1, this.duration);
  1149. },
  1150. /**
  1151. * @method getValue()
  1152. * @for kity.Timeline
  1153. * @grammar getValue() => {any}
  1154. * @description 返回当前播放时间对应的值。
  1155. */
  1156. getValue: function() {
  1157. var b = this.beginValue;
  1158. var f = this.finishValue;
  1159. var p = this.getValueProportion();
  1160. return getPercentValue(b, f, p);
  1161. },
  1162. /**
  1163. * @private
  1164. *
  1165. * 把值通过动画器的 setter 设置到目标上
  1166. */
  1167. setValue: function(value) {
  1168. this.lastValue = this.currentValue;
  1169. this.currentValue = value;
  1170. this.setter.call(this.target, this.target, value, this);
  1171. },
  1172. /**
  1173. * @method getDelta()
  1174. * @for kity.Timeline
  1175. * @grammar getDelta() => {any}
  1176. * @description 返回当前值和上一帧的值的差值
  1177. */
  1178. getDelta: function() {
  1179. this.lastValue = this.lastValue === undefined ? this.beginValue : this.lastValue;
  1180. return getDelta(this.lastValue, this.currentValue);
  1181. },
  1182. /**
  1183. * @method play()
  1184. * @for kity.Timeline
  1185. * @grammar play() => {this}
  1186. * @description 让时间线播放,如果时间线还没开始,或者已停止、已结束,则重头播放;如果是已暂停,从暂停的位置继续播放
  1187. */
  1188. play: function() {
  1189. var lastStatus = this.status;
  1190. this.status = "playing";
  1191. switch (lastStatus) {
  1192. case "ready":
  1193. if (utils.isFunction(this.beginValue)) {
  1194. this.beginValue = this.beginValue.call(this.target, this.target);
  1195. }
  1196. if (utils.isFunction(this.finishValue)) {
  1197. this.finishValue = this.finishValue.call(this.target, this.target);
  1198. }
  1199. this.time = 0;
  1200. this.setValue(this.beginValue);
  1201. this.frame = frame.requestFrame(this.nextFrame.bind(this));
  1202. break;
  1203. case "finished":
  1204. case "stoped":
  1205. this.time = 0;
  1206. this.frame = frame.requestFrame(this.nextFrame.bind(this));
  1207. break;
  1208. case "paused":
  1209. this.frame.next();
  1210. }
  1211. /**
  1212. * @event play
  1213. * @for kity.Timeline
  1214. * @description 在时间线播放后触发
  1215. *
  1216. * @param {String} event.lastStatus
  1217. * 表示播放前的上一个状态,可能取值为 'ready'、'finished'、'stoped'、'paused'
  1218. */
  1219. this.fire("play", new TimelineEvent(this, "play", {
  1220. lastStatus: lastStatus
  1221. }));
  1222. return this;
  1223. },
  1224. /**
  1225. * @method pause()
  1226. * @for kity.Timeline
  1227. * @description 暂停当前的时间线
  1228. *
  1229. * @grammar pause() => {this}
  1230. */
  1231. pause: function() {
  1232. this.status = "paused";
  1233. /**
  1234. * @event pause
  1235. * @for kity.Timeline
  1236. * @description 暂停事件,在时间线暂停时触发
  1237. */
  1238. this.fire("pause", new TimelineEvent(this, "pause"));
  1239. frame.releaseFrame(this.frame);
  1240. return this;
  1241. },
  1242. /**
  1243. * @method stop()
  1244. * @for kity.Timeline
  1245. * @description 停止当前时间线
  1246. *
  1247. * @grammar stop() => {this}
  1248. */
  1249. stop: function() {
  1250. this.status = "stoped";
  1251. this.setValue(this.finishValue);
  1252. this.rollbacking = false;
  1253. /**
  1254. * @event stop
  1255. * @for kity.Timeline
  1256. * @description 停止时间,在时间线停止时触发
  1257. */
  1258. this.fire("stop", new TimelineEvent(this, "stop"));
  1259. frame.releaseFrame(this.frame);
  1260. return this;
  1261. },
  1262. /**
  1263. * @private
  1264. *
  1265. * 播放结束之后的处理
  1266. */
  1267. timeUp: function() {
  1268. if (this.repeatOption) {
  1269. this.time = 0;
  1270. if (this.rollback) {
  1271. if (this.rollbacking) {
  1272. this.decreaseRepeat();
  1273. this.rollbacking = false;
  1274. } else {
  1275. this.rollbacking = true;
  1276. /**
  1277. * @event rollback
  1278. * @for kity.Timeline
  1279. * @description 回滚事件,在时间线回滚播放开始的时候触发
  1280. */
  1281. this.fire("rollback", new TimelineEvent(this, "rollback"));
  1282. }
  1283. } else {
  1284. this.decreaseRepeat();
  1285. }
  1286. if (!this.repeatOption) {
  1287. this.finish();
  1288. } else {
  1289. /**
  1290. * @event repeat
  1291. * @for kity.Timeline
  1292. * @description 循环事件,在时间线循环播放开始的时候触发
  1293. */
  1294. this.fire("repeat", new TimelineEvent(this, "repeat"));
  1295. }
  1296. } else {
  1297. this.finish();
  1298. }
  1299. },
  1300. /**
  1301. * @private
  1302. *
  1303. * 决定播放结束的处理
  1304. */
  1305. finish: function() {
  1306. this.setValue(this.finishValue);
  1307. this.status = "finished";
  1308. /**
  1309. * @event finish
  1310. * @for kity.Timeline
  1311. * @description 结束事件,在时间线播放结束后触发(包括重复和回滚都结束)
  1312. */
  1313. this.fire("finish", new TimelineEvent(this, "finish"));
  1314. frame.releaseFrame(this.frame);
  1315. },
  1316. /**
  1317. * @private
  1318. *
  1319. * 循环次数递减
  1320. */
  1321. decreaseRepeat: function() {
  1322. if (this.repeatOption !== true) {
  1323. this.repeatOption--;
  1324. }
  1325. },
  1326. /**
  1327. * @method repeat()
  1328. * @for kity.Timeline
  1329. * @description 设置时间线的重复选项
  1330. *
  1331. * @grammar repeat(repeat, rollback) => {this}
  1332. *
  1333. * @param {Number|Boolean} repeat
  1334. * 是否重复播放,设置为 true 无限循环播放,设置数值则循环指定的次数
  1335. * @param {Boolean} rollback
  1336. * 指示是否要回滚播放。
  1337. * 如果设置为真,一次事件到 duration 则一个来回算一次循环次数,否则播放完成一次算一次循环次数
  1338. *
  1339. */
  1340. repeat: function(repeat, rollback) {
  1341. this.repeatOption = repeat;
  1342. this.rollback = rollback;
  1343. return this;
  1344. }
  1345. });
  1346. Timeline.requestFrame = frame.requestFrame;
  1347. Timeline.releaseFrame = frame.releaseFrame;
  1348. return Timeline;
  1349. }
  1350. };
  1351. //src/animate/translateanimator.js
  1352. /**
  1353. * @fileOverview
  1354. *
  1355. * 提供让图形移动的动画器
  1356. */
  1357. _p[9] = {
  1358. value: function(require) {
  1359. var Animator = _p.r(0);
  1360. /**
  1361. * @class kity.TranslateAnimator
  1362. * @base kity.Animator
  1363. * @description 提供让图形移动的动画器
  1364. */
  1365. var TranslateAnimator = _p.r(11).createClass("TranslateAnimator", {
  1366. base: Animator,
  1367. /**
  1368. * @constructor
  1369. * @for kity.TranslateAnimator
  1370. * @grammar new kity.TranslateAnimator(x, y)
  1371. * @param {Number} x x 方向上需要移动的距离
  1372. * @param {Number} y y 方向上需要移动的距离
  1373. */
  1374. constructor: function(x, y) {
  1375. this.callBase({
  1376. x: 0,
  1377. y: 0
  1378. }, {
  1379. x: x,
  1380. y: y
  1381. }, function(target, value, timeline) {
  1382. var delta = timeline.getDelta();
  1383. target.translate(delta.x, delta.y);
  1384. });
  1385. }
  1386. });
  1387. var Shape = _p.r(61);
  1388. _p.r(11).extendClass(Shape, {
  1389. /**
  1390. * @method fxTranslate()
  1391. * @for kity.Shape
  1392. * @description 让目标以动画平移指定的距离
  1393. *
  1394. * @grammar fxTranslate(x, y, duration, easing, delay, callback) => {this}
  1395. *
  1396. * @param {Number} x x 方向上需要移动的距离
  1397. * @param {Number} y y 方向上需要移动的距离
  1398. * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
  1399. * @param {Number|String} delay 动画播放前的延时
  1400. * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
  1401. * @param {Function} callback 播放结束之后的回调函数
  1402. */
  1403. fxTranslate: function(x, y, duration, easing, delay, callback) {
  1404. return this.animate(new TranslateAnimator(x, y), duration, easing, delay, callback);
  1405. }
  1406. });
  1407. return TranslateAnimator;
  1408. }
  1409. };
  1410. //src/core/browser.js
  1411. /**
  1412. * @fileOverview
  1413. *
  1414. * 提供浏览器判断的一些字段
  1415. */
  1416. _p[10] = {
  1417. value: function() {
  1418. /**
  1419. * @class kity.Browser
  1420. * @catalog core
  1421. * @static
  1422. * @description 提供浏览器信息
  1423. */
  1424. var browser = function() {
  1425. var agent = navigator.userAgent.toLowerCase(), opera = window.opera, browser;
  1426. // 浏览器对象
  1427. browser = {
  1428. /**
  1429. * @property platform
  1430. * @description 获取浏览器所在系统,"Win"->Windows;"Mac"->Mac;"Lux"->Linux
  1431. * @type {String}
  1432. */
  1433. platform: function(navigator) {
  1434. var _p = {
  1435. win32: "Win",
  1436. macintel: "Mac"
  1437. };
  1438. return _p[navigator.platform.toLowerCase()] || "Lux";
  1439. }(navigator),
  1440. /**
  1441. * 猎豹,区分两种不同内核
  1442. */
  1443. lb: function(agent) {
  1444. if (~agent.indexOf("lbbrowser")) {
  1445. return ~agent.indexOf("msie") ? "ie" : "chrome";
  1446. }
  1447. return false;
  1448. }(agent),
  1449. /**
  1450. * 搜狗
  1451. */
  1452. sg: /se[\s\S]+metasr/.test(agent),
  1453. /**
  1454. * 百度
  1455. */
  1456. bd: !!~agent.indexOf("bidubrowser"),
  1457. /**
  1458. * edge浏览器
  1459. */
  1460. edge: !!~agent.indexOf("edge"),
  1461. /**
  1462. * chrome初始化为false
  1463. * @type {Boolean}
  1464. */
  1465. chrome: false,
  1466. /**
  1467. * @property opera
  1468. * @for kity.Browser
  1469. * @description 判断是否为 Opera 浏览器
  1470. * @type {boolean}
  1471. */
  1472. opera: !!opera && opera.version,
  1473. /**
  1474. * @property webkit
  1475. * @for kity.Browser
  1476. * @description 判断是否为 Webkit 内核的浏览器
  1477. * @type {boolean}
  1478. */
  1479. webkit: agent.indexOf(" applewebkit/") > -1,
  1480. /**
  1481. * @property mac
  1482. * @for kity.Browser
  1483. * @description 判断是否为 Mac 下的浏览器
  1484. * @type {boolean}
  1485. */
  1486. mac: agent.indexOf("macintosh") > -1
  1487. };
  1488. /**
  1489. * @property ie
  1490. * @for kity.Browser
  1491. * @description 判断是否为 IE 浏览器
  1492. * @type {boolean}
  1493. */
  1494. browser.ie = !browser.lb && /(msie\s|trident.*rv:)([\w.]+)/.test(agent);
  1495. browser.gecko = navigator.product == "Gecko" && !browser.webkit && !browser.opera && !browser.ie;
  1496. var version = 0;
  1497. // Internet Explorer 6.0+
  1498. if (browser.ie) {
  1499. version = (agent.match(/(msie\s|trident.*rv:)([\w.]+)/)[2] || 0) * 1;
  1500. browser.ie11Compat = document.documentMode == 11;
  1501. browser.ie9Compat = document.documentMode == 9;
  1502. }
  1503. // Gecko.
  1504. if (browser.gecko) {
  1505. var geckoRelease = agent.match(/rv:([\d\.]+)/);
  1506. if (geckoRelease) {
  1507. geckoRelease = geckoRelease[1].split(".");
  1508. version = geckoRelease[0] * 1e4 + (geckoRelease[1] || 0) * 100 + (geckoRelease[2] || 0) * 1;
  1509. }
  1510. }
  1511. // 排除其他chrome内核的浏览器的干扰
  1512. if (/chrome\/(\d+\.\d)/i.test(agent) && !browser.bd && !browser.opera && !browser.lb && !browser.sg && !browser.edge) {
  1513. /**
  1514. * @property chrome
  1515. * @for kity.Browser
  1516. * @description 判断是否为 Chrome 浏览器
  1517. * @type {boolean}
  1518. */
  1519. browser.chrome = +RegExp["$1"];
  1520. }
  1521. if (/(\d+\.\d)?(?:\.\d)?\s+safari\/?(\d+\.\d+)?/i.test(agent) && !/chrome/i.test(agent)) {
  1522. browser.safari = +(RegExp["$1"] || RegExp["$2"]);
  1523. }
  1524. // Opera 9.50+
  1525. if (browser.opera) version = parseFloat(opera.version());
  1526. // WebKit 522+ (Safari 3+)
  1527. if (browser.webkit) version = parseFloat(agent.match(/ applewebkit\/(\d+)/)[1]);
  1528. // 搜狗版本号无从得知
  1529. // 猎豹版本号无从得知
  1530. // 百度
  1531. if (browser.bd) version = parseFloat(agent.match(/bidubrowser\/(\d+)/)[1]);
  1532. // Opera 9.50+
  1533. if (browser.opera) version = parseFloat(agent.match(/opr\/(\d+)/)[1]);
  1534. // edge
  1535. if (browser.edge) version = parseFloat(agent.match(/edge\/(\d+)/)[1]);
  1536. /**
  1537. * @property version
  1538. * @for kity.Browser
  1539. * @description 获取当前浏览器的版本
  1540. * @type {Number}
  1541. */
  1542. browser.version = version;
  1543. browser.isCompatible = !browser.mobile && (browser.ie && version >= 6 || browser.gecko && version >= 10801 || browser.opera && version >= 9.5 || browser.air && version >= 1 || browser.webkit && version >= 522 || false);
  1544. return browser;
  1545. }();
  1546. return browser;
  1547. }
  1548. };
  1549. //src/core/class.js
  1550. /**
  1551. * @fileOverview
  1552. *
  1553. * 提供 Kity 的 OOP 支持
  1554. */
  1555. _p[11] = {
  1556. value: function(require, exports) {
  1557. /**
  1558. * @class kity.Class
  1559. * @catalog core
  1560. * @description 所有 kity 类的基类
  1561. * @abstract
  1562. */
  1563. function Class() {}
  1564. exports.Class = Class;
  1565. Class.__KityClassName = "Class";
  1566. /**
  1567. * @method base()
  1568. * @for kity.Class
  1569. * @protected
  1570. * @grammar base(name, args...) => {any}
  1571. * @description 调用父类指定名称的函数
  1572. * @param {string} name 函数的名称
  1573. * @param {parameter} args... 传递给父类函数的参数
  1574. *
  1575. * @example
  1576. *
  1577. * ```js
  1578. * var Person = kity.createClass('Person', {
  1579. * toString: function() {
  1580. * return 'I am a person';
  1581. * }
  1582. * });
  1583. *
  1584. * var Male = kity.createClass('Male', {
  1585. * base: Person,
  1586. *
  1587. * toString: function() {
  1588. * return 'I am a man';
  1589. * },
  1590. *
  1591. * speak: function() {
  1592. * return this.base('toString') + ',' + this.toString();
  1593. * }
  1594. * })
  1595. * ```
  1596. */
  1597. Class.prototype.base = function(name) {
  1598. var caller = arguments.callee.caller;
  1599. var method = caller.__KityMethodClass.__KityBaseClass.prototype[name];
  1600. return method.apply(this, Array.prototype.slice.call(arguments, 1));
  1601. };
  1602. /**
  1603. * @method callBase()
  1604. * @for kity.Class
  1605. * @protected
  1606. * @grammar callBase(args...) => {any}
  1607. * @description 调用父类同名函数
  1608. * @param {parameter} args... 传递到父类同名函数的参数
  1609. *
  1610. * @example
  1611. *
  1612. * ```js
  1613. * var Animal = kity.createClass('Animal', {
  1614. * constructor: function(name) {
  1615. * this.name = name;
  1616. * },
  1617. * toString: function() {
  1618. * return 'I am an animal name ' + this.name;
  1619. * }
  1620. * });
  1621. *
  1622. * var Dog = kity.createClass('Dog', {
  1623. * constructor: function(name) {
  1624. * this.callBase(name);
  1625. * },
  1626. * toString: function() {
  1627. * return this.callBase() + ', a dog';
  1628. * }
  1629. * });
  1630. *
  1631. * var dog = new Dog('Dummy');
  1632. * console.log(dog.toString()); // "I am an animal name Dummy, a dog";
  1633. * ```
  1634. */
  1635. Class.prototype.callBase = function() {
  1636. var caller = arguments.callee.caller;
  1637. var method = caller.__KityMethodClass.__KityBaseClass.prototype[caller.__KityMethodName];
  1638. return method.apply(this, arguments);
  1639. };
  1640. Class.prototype.mixin = function(name) {
  1641. var caller = arguments.callee.caller;
  1642. var mixins = caller.__KityMethodClass.__KityMixins;
  1643. if (!mixins) {
  1644. return this;
  1645. }
  1646. var method = mixins[name];
  1647. return method.apply(this, Array.prototype.slice.call(arguments, 1));
  1648. };
  1649. Class.prototype.callMixin = function() {
  1650. var caller = arguments.callee.caller;
  1651. var methodName = caller.__KityMethodName;
  1652. var mixins = caller.__KityMethodClass.__KityMixins;
  1653. if (!mixins) {
  1654. return this;
  1655. }
  1656. var method = mixins[methodName];
  1657. if (methodName == "constructor") {
  1658. for (var i = 0, l = method.length; i < l; i++) {
  1659. method[i].call(this);
  1660. }
  1661. return this;
  1662. } else {
  1663. return method.apply(this, arguments);
  1664. }
  1665. };
  1666. /**
  1667. * @method pipe()
  1668. * @for kity.Class
  1669. * @grammar pipe() => {this}
  1670. * @description 以当前对象为上线文以及管道函数的第一个参数,执行一个管道函数
  1671. * @param {Function} fn 进行管道操作的函数
  1672. *
  1673. * @example
  1674. *
  1675. * ```js
  1676. * var rect = new kity.Rect().pipe(function() {
  1677. * this.setWidth(500);
  1678. * this.setHeight(300);
  1679. * });
  1680. * ```
  1681. */
  1682. Class.prototype.pipe = function(fn) {
  1683. if (typeof fn == "function") {
  1684. fn.call(this, this);
  1685. }
  1686. return this;
  1687. };
  1688. /**
  1689. * @method getType()
  1690. * @for kity.Class
  1691. * @grammar getType() => {string}
  1692. * @description 获得对象的类型
  1693. *
  1694. * @example
  1695. *
  1696. * ```js
  1697. * var rect = new kity.Rect();
  1698. * var circle = new kity.Circle();
  1699. *
  1700. * console.log(rect.getType()); // "Rect"
  1701. * console.log(rect.getType()); // "Circle"
  1702. * ```
  1703. */
  1704. Class.prototype.getType = function() {
  1705. return this.__KityClassName;
  1706. };
  1707. /**
  1708. * @method getClass()
  1709. * @for kity.Class
  1710. * @grammar getClass() => {Class}
  1711. * @description 获得对象的类
  1712. *
  1713. * @example
  1714. *
  1715. * ```js
  1716. * var rect = new kity.Rect();
  1717. *
  1718. * console.log(rect.getClass() === kity.Rect); // true
  1719. * console.log(rect instanceof kity.Rect); // true
  1720. * ```
  1721. */
  1722. Class.prototype.getClass = function() {
  1723. return this.constructor;
  1724. };
  1725. // 检查基类是否调用了父类的构造函数
  1726. // 该检查是弱检查,假如调用的代码被注释了,同样能检查成功(这个特性可用于知道建议调用,但是出于某些原因不想调用的情况)
  1727. function checkBaseConstructorCall(targetClass, classname) {
  1728. var code = targetClass.toString();
  1729. if (!/this\.callBase/.test(code)) {
  1730. throw new Error(classname + " : 类构造函数没有调用父类的构造函数!为了安全,请调用父类的构造函数");
  1731. }
  1732. }
  1733. var KITY_INHERIT_FLAG = "__KITY_INHERIT_FLAG_" + +new Date();
  1734. function inherit(constructor, BaseClass, classname) {
  1735. var KityClass = eval("(function " + classname + "( __inherit__flag ) {" + "if( __inherit__flag != KITY_INHERIT_FLAG ) {" + "KityClass.__KityConstructor.apply(this, arguments);" + "}" + "this.__KityClassName = KityClass.__KityClassName;" + "})");
  1736. KityClass.__KityConstructor = constructor;
  1737. KityClass.prototype = new BaseClass(KITY_INHERIT_FLAG);
  1738. for (var methodName in BaseClass.prototype) {
  1739. if (BaseClass.prototype.hasOwnProperty(methodName) && methodName.indexOf("__Kity") !== 0) {
  1740. KityClass.prototype[methodName] = BaseClass.prototype[methodName];
  1741. }
  1742. }
  1743. KityClass.prototype.constructor = KityClass;
  1744. return KityClass;
  1745. }
  1746. function mixin(NewClass, mixins) {
  1747. if (false === mixins instanceof Array) {
  1748. return NewClass;
  1749. }
  1750. var i, length = mixins.length, proto, method;
  1751. NewClass.__KityMixins = {
  1752. constructor: []
  1753. };
  1754. for (i = 0; i < length; i++) {
  1755. proto = mixins[i].prototype;
  1756. for (method in proto) {
  1757. if (false === proto.hasOwnProperty(method) || method.indexOf("__Kity") === 0) {
  1758. continue;
  1759. }
  1760. if (method === "constructor") {
  1761. // constructor 特殊处理
  1762. NewClass.__KityMixins.constructor.push(proto[method]);
  1763. } else {
  1764. NewClass.prototype[method] = NewClass.__KityMixins[method] = proto[method];
  1765. }
  1766. }
  1767. }
  1768. return NewClass;
  1769. }
  1770. function extend(BaseClass, extension) {
  1771. if (extension.__KityClassName) {
  1772. extension = extension.prototype;
  1773. }
  1774. for (var methodName in extension) {
  1775. if (extension.hasOwnProperty(methodName) && methodName.indexOf("__Kity") && methodName != "constructor") {
  1776. var method = BaseClass.prototype[methodName] = extension[methodName];
  1777. method.__KityMethodClass = BaseClass;
  1778. method.__KityMethodName = methodName;
  1779. }
  1780. }
  1781. return BaseClass;
  1782. }
  1783. /**
  1784. * @method kity.createClass()
  1785. * @grammar kity.createClass(classname, defines) => {Class}
  1786. * @description 创建一个类
  1787. * @param {string} classname 类名,用于调试的时候查看,可选
  1788. * @param {object} defines 类定义
  1789. * defines.base {Class}
  1790. * 定义的类的基类,如果不配置,则表示基类为 kity.Class
  1791. * defines.mixins {Class[]}
  1792. * 定义的类要融合的类列表
  1793. * defines.constructor {Function}
  1794. * 定义类的构造函数,如果父类显式定义了构造函数,需要在构造函数中使用 callBase() 方法调用父类的构造函数
  1795. * defines.* {Function}
  1796. * 定义类的其它函数
  1797. *
  1798. * @example 创建一个类
  1799. *
  1800. * ```js
  1801. * var Animal = kity.createClass('Animal', {
  1802. * constructor: function(name) {
  1803. * this.name = name;
  1804. * },
  1805. * toString: function() {
  1806. * return this.name;
  1807. * }
  1808. * });
  1809. *
  1810. * var a = new Animal('kity');
  1811. * console.log(a.toString()); // "kity"
  1812. * ```
  1813. *
  1814. * @example 继承一个类
  1815. *
  1816. * ```js
  1817. * var Cat = kity.createClass('Cat', {
  1818. * base: Animal,
  1819. * constructor: function(name, color) {
  1820. * // 调用父类构造函数
  1821. * this.callBase(name);
  1822. * },
  1823. * toString: function() {
  1824. * return 'A ' + this.color + ' cat, ' + this.callBase();
  1825. * }
  1826. * });
  1827. *
  1828. * var cat = new Cat('kity', 'black');
  1829. * console.log(cat.toString()); // "A black cat, kity"
  1830. * ```
  1831. *
  1832. * @example 混合类的能力
  1833. * ```js
  1834. * var Walkable = kity.createClass('Walkable', {
  1835. * constructor: function() {
  1836. * this.speed = 'fast';
  1837. * },
  1838. * walk: function() {
  1839. * console.log('I am walking ' + this.speed);
  1840. * }
  1841. * });
  1842. *
  1843. * var Dog = kity.createClass('Dog', {
  1844. * base: Animal,
  1845. * mixins: [Walkable],
  1846. * constructor: function(name) {
  1847. * this.callBase(name);
  1848. * this.callMixins();
  1849. * }
  1850. * });
  1851. *
  1852. * var dog = new Dog('doggy');
  1853. * console.log(dog.toString() + ' say:');
  1854. * dog.walk();
  1855. * ```
  1856. */
  1857. exports.createClass = function(classname, defines) {
  1858. var constructor, NewClass, BaseClass;
  1859. if (arguments.length === 1) {
  1860. defines = arguments[0];
  1861. classname = "AnonymousClass";
  1862. }
  1863. BaseClass = defines.base || Class;
  1864. if (defines.hasOwnProperty("constructor")) {
  1865. constructor = defines.constructor;
  1866. if (BaseClass != Class) {
  1867. checkBaseConstructorCall(constructor, classname);
  1868. }
  1869. } else {
  1870. constructor = function() {
  1871. this.callBase.apply(this, arguments);
  1872. this.callMixin.apply(this, arguments);
  1873. };
  1874. }
  1875. NewClass = inherit(constructor, BaseClass, classname);
  1876. NewClass = mixin(NewClass, defines.mixins);
  1877. NewClass.__KityClassName = constructor.__KityClassName = classname;
  1878. NewClass.__KityBaseClass = constructor.__KityBaseClass = BaseClass;
  1879. NewClass.__KityMethodName = constructor.__KityMethodName = "constructor";
  1880. NewClass.__KityMethodClass = constructor.__KityMethodClass = NewClass;
  1881. // 下面这些不需要拷贝到原型链上
  1882. delete defines.mixins;
  1883. delete defines.constructor;
  1884. delete defines.base;
  1885. NewClass = extend(NewClass, defines);
  1886. return NewClass;
  1887. };
  1888. /**
  1889. * @method kity.extendClass()
  1890. * @grammar kity.extendClass(clazz, extension) => {Class}
  1891. * @description 拓展一个已有的类
  1892. *
  1893. * @example
  1894. *
  1895. * ```js
  1896. * kity.extendClass(Dog, {
  1897. * spark: function() {
  1898. * console.log('wao wao wao!');
  1899. * }
  1900. * });
  1901. *
  1902. * new Dog().spark(); // "wao wao wao!";
  1903. * ```
  1904. */
  1905. exports.extendClass = extend;
  1906. }
  1907. };
  1908. //src/core/utils.js
  1909. /**
  1910. * @fileOverview
  1911. *
  1912. * 一些常用的工具方法
  1913. */
  1914. _p[12] = {
  1915. value: function() {
  1916. /**
  1917. * @class kity.Utils
  1918. * @catalog core
  1919. * @static
  1920. * @description 提供常用的工具方法
  1921. */
  1922. var utils = {
  1923. /**
  1924. * @method each()
  1925. * @for kity.Utils
  1926. * @grammar each(obj, interator, context)
  1927. * @param {Object|Array} obj 要迭代的对象或数组
  1928. * @param {Function} iterator 迭代函数
  1929. * @param {Any} context 迭代函数的上下文
  1930. *
  1931. * @example 迭代数组
  1932. *
  1933. * ```js
  1934. * kity.Utils.each([1, 2, 3, 4, 5], function(value, index, array) {
  1935. * console.log(value, index);
  1936. * });
  1937. * // 1, 0
  1938. * // 2, 1
  1939. * // 3, 2
  1940. * // 4, 3
  1941. * // 5, 4
  1942. * ```
  1943. *
  1944. * @example 迭代对象
  1945. *
  1946. * ```js
  1947. * var obj = {
  1948. * name: 'kity',
  1949. * version: '1.2.1'
  1950. * };
  1951. * var param = [];
  1952. * kity.Utils.each(obj, function(value, key, obj) {
  1953. * param.push(key + '=' + value);
  1954. * });
  1955. * console.log(param.join('&')); // "name=kity&version=1.2.1"
  1956. * ```
  1957. */
  1958. each: function each(obj, iterator, context) {
  1959. if (obj === null) {
  1960. return;
  1961. }
  1962. if (obj.length === +obj.length) {
  1963. for (var i = 0, l = obj.length; i < l; i++) {
  1964. if (iterator.call(context, obj[i], i, obj) === false) {
  1965. return false;
  1966. }
  1967. }
  1968. } else {
  1969. for (var key in obj) {
  1970. if (obj.hasOwnProperty(key)) {
  1971. if (iterator.call(context, obj[key], key, obj) === false) {
  1972. return false;
  1973. }
  1974. }
  1975. }
  1976. }
  1977. },
  1978. /**
  1979. * @method extend()
  1980. * @for kity.Utils
  1981. * @grammar extend(target, sources..., notCover) => {object}
  1982. * @description 把源对象的属性合并到目标对象上
  1983. * @param {object} target 目标对象
  1984. * @param {parameter} sources 源对象
  1985. * @param {boolean} notCover 是否不要覆盖源对象已有的属性
  1986. *
  1987. * @example
  1988. *
  1989. * ```js
  1990. * var a = {
  1991. * key1: 'a1',
  1992. * key2: 'a2'
  1993. * };
  1994. *
  1995. * var b = {
  1996. * key2: 'b2',
  1997. * key3: 'b3'
  1998. * };
  1999. *
  2000. * var c = {
  2001. * key4: 'c4'
  2002. * };
  2003. *
  2004. * var d = kity.extend(a, b, c);
  2005. *
  2006. * console.log(d === a); // true
  2007. * console.log(a); // {key1: 'a1', key2: 'b2', key3: 'b3', key4: 'c4'}
  2008. * ```
  2009. */
  2010. extend: function extend(t) {
  2011. var a = arguments, notCover = this.isBoolean(a[a.length - 1]) ? a[a.length - 1] : false, len = this.isBoolean(a[a.length - 1]) ? a.length - 1 : a.length;
  2012. for (var i = 1; i < len; i++) {
  2013. var x = a[i];
  2014. for (var k in x) {
  2015. if (!notCover || !t.hasOwnProperty(k)) {
  2016. t[k] = x[k];
  2017. }
  2018. }
  2019. }
  2020. return t;
  2021. },
  2022. /**
  2023. * @method deepExtend()
  2024. * @for kity.Utils
  2025. * @grammar deepExtend(target, sources..., notCover)
  2026. * @description 把源对象的属性合并到目标对象上,如果属性是对象,会递归合并
  2027. * @param {object} target 目标对象
  2028. * @param {parameter} sources 源对象
  2029. * @param {boolean} notCover 是否不要覆盖源对象已有的属性
  2030. */
  2031. deepExtend: function(t, s) {
  2032. var a = arguments, notCover = this.isBoolean(a[a.length - 1]) ? a[a.length - 1] : false, len = this.isBoolean(a[a.length - 1]) ? a.length - 1 : a.length;
  2033. for (var i = 1; i < len; i++) {
  2034. var x = a[i];
  2035. for (var k in x) {
  2036. if (!notCover || !t.hasOwnProperty(k)) {
  2037. if (this.isObject(t[k]) && this.isObject(x[k])) {
  2038. this.deepExtend(t[k], x[k], notCover);
  2039. } else {
  2040. t[k] = x[k];
  2041. }
  2042. }
  2043. }
  2044. }
  2045. return t;
  2046. },
  2047. /**
  2048. * @method clone()
  2049. * @for kity.Utils
  2050. * @grammar clone(obj) => {object}
  2051. * @description 返回一个对象的克隆副本(非深度复制)
  2052. * @param {object} obj 要克隆的对象
  2053. *
  2054. * @example
  2055. *
  2056. * ```js
  2057. * var source = {
  2058. * key1: {
  2059. * key2: 'value2'
  2060. * },
  2061. * key3: 'value3'
  2062. * };
  2063. *
  2064. * var target = kity.Utils.clone(source);
  2065. *
  2066. * console.log(target === source); // false
  2067. * console.log(target.key1 === source.key1); // true
  2068. * console.log(target.key3 === source.key3); // true
  2069. * ```
  2070. */
  2071. clone: function clone(obj) {
  2072. var cloned = {};
  2073. for (var m in obj) {
  2074. if (obj.hasOwnProperty(m)) {
  2075. cloned[m] = obj[m];
  2076. }
  2077. }
  2078. return cloned;
  2079. },
  2080. /**
  2081. * @method copy()
  2082. * @for kity.Utils
  2083. * @grammar copy(obj) => {object}
  2084. * @description 返回一个对象的拷贝副本(深度复制)
  2085. * @param {object} obj 要拷贝的对象
  2086. *
  2087. * @example
  2088. *
  2089. * ```js
  2090. * var source = {
  2091. * key1: {
  2092. * key2: 'value2'
  2093. * },
  2094. * key3: 'value3'
  2095. * };
  2096. *
  2097. * var target = kity.Utils.copy(source);
  2098. *
  2099. * console.log(target === source); // false
  2100. * console.log(target.key1 === source.key1); // false
  2101. * console.log(target.key3 === source.key3); // true,因为是值类型
  2102. * ```
  2103. */
  2104. copy: function copy(obj) {
  2105. if (typeof obj !== "object") return obj;
  2106. if (typeof obj === "function") return null;
  2107. return JSON.parse(JSON.stringify(obj));
  2108. },
  2109. queryPath: function(path, obj) {
  2110. var arr = path.split(".");
  2111. var i = 0, tmp = obj, l = arr.length;
  2112. while (i < l) {
  2113. if (arr[i] in tmp) {
  2114. tmp = tmp[arr[i]];
  2115. i++;
  2116. if (i >= l || tmp === undefined) {
  2117. return tmp;
  2118. }
  2119. } else {
  2120. return undefined;
  2121. }
  2122. }
  2123. },
  2124. getValue: function(value, defaultValue) {
  2125. return value !== undefined ? value : defaultValue;
  2126. },
  2127. /**
  2128. * @method flatten()
  2129. * @for kity.Utils
  2130. * @grammar flatten(arr) => {Array}
  2131. * @description 返回给定数组的扁平化版本
  2132. * @param {Array} arr 要扁平化的数组
  2133. *
  2134. * @example
  2135. *
  2136. * ```js
  2137. * var flattened = kity.Utils.flatten([[1, 2], [2, 3], [[4, 5], [6, 7]]]);
  2138. * console.log(flattened); // [1, 2, 3, 4, 5, 6, 7];
  2139. * ```
  2140. */
  2141. flatten: function flatten(arr) {
  2142. var result = [], length = arr.length, i;
  2143. for (i = 0; i < length; i++) {
  2144. if (arr[i] instanceof Array) {
  2145. result = result.concat(utils.flatten(arr[i]));
  2146. } else {
  2147. result.push(arr[i]);
  2148. }
  2149. }
  2150. return result;
  2151. },
  2152. /**
  2153. * @method paralle()
  2154. * @for kity.Utils
  2155. * @grammar paralle() => {Any}
  2156. *
  2157. * @description 平行地对 v1 和 v2 进行指定的操作
  2158. *
  2159. * 如果 v1 是数字,那么直接进行 op 操作
  2160. * 如果 v1 是对象,那么返回一个对象,其元素是 v1 和 v2 同键值的每个元素平行地进行 op 操作的结果
  2161. * 如果 v1 是数组,那么返回一个数组,其元素是 v1 和 v2 同索引的每个元素平行地进行 op 操作的结果
  2162. *
  2163. * @param {Number|Object|Array} v1 第一个操作数
  2164. * @param {Number|Object|Array} v2 第二个操作数
  2165. * @param {Function} op 操作函数
  2166. *
  2167. *
  2168. *
  2169. * @example
  2170. *
  2171. * ```js
  2172. * var a = {
  2173. * value1: 1,
  2174. * value2: 2,
  2175. * value3: [3, 4, 5]
  2176. * };
  2177. *
  2178. * var b = {
  2179. * value1: 2,
  2180. * value2: 3,
  2181. * value3: [4, 5, 6]
  2182. * };
  2183. *
  2184. * var c = kity.Utils.paralle(a, b, function(v1, v2) {
  2185. * return v1 + v2;
  2186. * });
  2187. *
  2188. * console.log(c.value1); // 3
  2189. * console.log(c.value2); // 5
  2190. * console.log(c.value3); // [7, 9, 11]
  2191. *
  2192. * ```
  2193. */
  2194. paralle: function paralle(v1, v2, op) {
  2195. var Class, field, index, name, value;
  2196. // 数组
  2197. if (v1 instanceof Array) {
  2198. value = [];
  2199. for (index = 0; index < v1.length; index++) {
  2200. value.push(utils.paralle(v1[index], v2[index], op));
  2201. }
  2202. return value;
  2203. }
  2204. // 对象
  2205. if (v1 instanceof Object) {
  2206. // 如果值是一个支持原始表示的实例,获取其原始表示
  2207. Class = v1.getClass && v1.getClass();
  2208. if (Class && Class.parse) {
  2209. v1 = v1.valueOf();
  2210. v2 = v2.valueOf();
  2211. value = utils.paralle(v1, v2, op);
  2212. value = Class.parse(value);
  2213. } else {
  2214. value = {};
  2215. for (name in v1) {
  2216. if (v1.hasOwnProperty(name) && v2.hasOwnProperty(name)) {
  2217. value[name] = utils.paralle(v1[name], v2[name], op);
  2218. }
  2219. }
  2220. }
  2221. return value;
  2222. }
  2223. // 是否数字
  2224. if (false === isNaN(parseFloat(v1))) {
  2225. return op(v1, v2);
  2226. }
  2227. return value;
  2228. },
  2229. /**
  2230. * 创建 op 操作的一个平行化版本
  2231. */
  2232. parallelize: function parallelize(op) {
  2233. return function(v1, v2) {
  2234. return utils.paralle(v1, v2, op);
  2235. };
  2236. }
  2237. };
  2238. /**
  2239. * @method isString()
  2240. * @for kity.Utils
  2241. * @grammar isString(unknown) => {boolean}
  2242. * @description 判断一个值是否为字符串类型
  2243. * @param {any} unknown 要判断的值
  2244. */
  2245. /**
  2246. * @method isFunction()
  2247. * @for kity.Utils
  2248. * @grammar isFunction(unknown) => {boolean}
  2249. * @description 判断一个值是否为函数类型
  2250. * @param {any} unknown 要判断的值
  2251. */
  2252. /**
  2253. * @method isArray()
  2254. * @for kity.Utils
  2255. * @grammar isArray(unknown) => {boolean}
  2256. * @description 判断一个值是否为数组类型
  2257. * @param {any} unknown 要判断的值
  2258. */
  2259. /**
  2260. * @method isNumber()
  2261. * @for kity.Utils
  2262. * @grammar isNumber(unknown) => {boolean}
  2263. * @description 判断一个值是否为数字类型
  2264. * @param {any} unknown 要判断的值
  2265. */
  2266. /**
  2267. * @method isRegExp()
  2268. * @for kity.Utils
  2269. * @grammar isRegExp(unknown) => {boolean}
  2270. * @description 判断一个值是否为正则表达式类型
  2271. * @param {any} unknown 要判断的值
  2272. */
  2273. /**
  2274. * @method isObject()
  2275. * @for kity.Utils
  2276. * @grammar isObject(unknown) => {boolean}
  2277. * @description 判断一个值是否为对象类型
  2278. * @param {any} unknown 要判断的值
  2279. */
  2280. /**
  2281. * @method isBoolean()
  2282. * @for kity.Utils
  2283. * @grammar isBoolean(unknown) => {boolean}
  2284. * @description 判断一个值是否为布尔类型
  2285. * @param {any} unknown 要判断的值
  2286. */
  2287. utils.each([ "String", "Function", "Array", "Number", "RegExp", "Object", "Boolean" ], function(v) {
  2288. utils["is" + v] = function typeCheck(obj) {
  2289. return Object.prototype.toString.apply(obj) == "[object " + v + "]";
  2290. };
  2291. });
  2292. return utils;
  2293. }
  2294. };
  2295. //src/expose-kity.js
  2296. _p[13] = {
  2297. value: function(require, exports, module) {
  2298. module.exports = window.kity = _p.r(77);
  2299. }
  2300. };
  2301. //src/filter/effect/colormatrixeffect.js
  2302. /**
  2303. * 颜色矩阵运算效果封装
  2304. */
  2305. _p[14] = {
  2306. value: function(require, exports, module) {
  2307. var Effect = _p.r(17), Utils = _p.r(12);
  2308. var ColorMatrixEffect = _p.r(11).createClass("ColorMatrixEffect", {
  2309. base: Effect,
  2310. constructor: function(type, input) {
  2311. this.callBase(Effect.NAME_COLOR_MATRIX);
  2312. this.set("type", Utils.getValue(type, ColorMatrixEffect.TYPE_MATRIX));
  2313. this.set("in", Utils.getValue(input, Effect.INPUT_SOURCE_GRAPHIC));
  2314. }
  2315. });
  2316. Utils.extend(ColorMatrixEffect, {
  2317. // 类型常量
  2318. TYPE_MATRIX: "matrix",
  2319. TYPE_SATURATE: "saturate",
  2320. TYPE_HUE_ROTATE: "hueRotate",
  2321. TYPE_LUMINANCE_TO_ALPHA: "luminanceToAlpha",
  2322. // 矩阵常量
  2323. MATRIX_ORIGINAL: "10000010000010000010".split("").join(" "),
  2324. MATRIX_EMPTY: "00000000000000000000".split("").join(" ")
  2325. });
  2326. return ColorMatrixEffect;
  2327. }
  2328. };
  2329. //src/filter/effect/compositeeffect.js
  2330. /**
  2331. * 高斯模糊效果封装
  2332. */
  2333. _p[15] = {
  2334. value: function(require, exports, module) {
  2335. var Effect = _p.r(17), Utils = _p.r(12);
  2336. var CompositeEffect = _p.r(11).createClass("CompositeEffect", {
  2337. base: Effect,
  2338. constructor: function(operator, input, input2) {
  2339. this.callBase(Effect.NAME_COMPOSITE);
  2340. this.set("operator", Utils.getValue(operator, CompositeEffect.OPERATOR_OVER));
  2341. if (input) {
  2342. this.set("in", input);
  2343. }
  2344. if (input2) {
  2345. this.set("in2", input2);
  2346. }
  2347. }
  2348. });
  2349. Utils.extend(CompositeEffect, {
  2350. // operator 常量
  2351. OPERATOR_OVER: "over",
  2352. OPERATOR_IN: "in",
  2353. OPERATOR_OUT: "out",
  2354. OPERATOR_ATOP: "atop",
  2355. OPERATOR_XOR: "xor",
  2356. OPERATOR_ARITHMETIC: "arithmetic"
  2357. });
  2358. return CompositeEffect;
  2359. }
  2360. };
  2361. //src/filter/effect/convolvematrixeffect.js
  2362. /**
  2363. * 像素级别的矩阵卷积运算效果封装
  2364. */
  2365. _p[16] = {
  2366. value: function(require, exports, module) {
  2367. var Effect = _p.r(17), Utils = _p.r(12);
  2368. var ConvolveMatrixEffect = _p.r(11).createClass("ConvolveMatrixEffect", {
  2369. base: Effect,
  2370. constructor: function(edgeMode, input) {
  2371. this.callBase(Effect.NAME_CONVOLVE_MATRIX);
  2372. this.set("edgeMode", Utils.getValue(edgeMode, ConvolveMatrixEffect.MODE_DUPLICATE));
  2373. this.set("in", Utils.getValue(input, Effect.INPUT_SOURCE_GRAPHIC));
  2374. }
  2375. });
  2376. Utils.extend(ConvolveMatrixEffect, {
  2377. MODE_DUPLICATE: "duplicate",
  2378. MODE_WRAP: "wrap",
  2379. MODE_NONE: "none"
  2380. });
  2381. return ConvolveMatrixEffect;
  2382. }
  2383. };
  2384. //src/filter/effect/effect.js
  2385. /*
  2386. * 效果类
  2387. * 该类型的对象不存储任何内部属性, 所有操作都是针对该类对象所维护的节点进行的
  2388. */
  2389. _p[17] = {
  2390. value: function(require, exports, module) {
  2391. var svg = _p.r(68), Effect = _p.r(11).createClass("Effect", {
  2392. constructor: function(type) {
  2393. this.node = svg.createNode(type);
  2394. },
  2395. getId: function() {
  2396. return this.node.id;
  2397. },
  2398. setId: function(id) {
  2399. this.node.id = id;
  2400. return this;
  2401. },
  2402. set: function(key, value) {
  2403. this.node.setAttribute(key, value);
  2404. return this;
  2405. },
  2406. get: function(key) {
  2407. return this.node.getAttribute(key);
  2408. },
  2409. getNode: function() {
  2410. return this.node;
  2411. },
  2412. // 返回该效果的result
  2413. toString: function() {
  2414. return this.node.getAttribute("result") || "";
  2415. }
  2416. });
  2417. _p.r(12).extend(Effect, {
  2418. // 特效名称常量
  2419. NAME_GAUSSIAN_BLUR: "feGaussianBlur",
  2420. NAME_OFFSET: "feOffset",
  2421. NAME_COMPOSITE: "feComposite",
  2422. NAME_COLOR_MATRIX: "feColorMatrix",
  2423. NAME_CONVOLVE_MATRIX: "feConvolveMatrix",
  2424. // 输入常量
  2425. INPUT_SOURCE_GRAPHIC: "SourceGraphic",
  2426. INPUT_SOURCE_ALPHA: "SourceAlpha",
  2427. INPUT_BACKGROUND_IMAGE: "BackgroundImage",
  2428. INPUT_BACKGROUND_ALPHA: "BackgroundAlpha",
  2429. INPUT_FILL_PAINT: "FillPaint",
  2430. INPUT_STROKE_PAINT: "StrokePaint"
  2431. });
  2432. return Effect;
  2433. }
  2434. };
  2435. //src/filter/effect/gaussianblureffect.js
  2436. /**
  2437. * 高斯模糊效果封装
  2438. */
  2439. _p[18] = {
  2440. value: function(require, exports, module) {
  2441. var Effect = _p.r(17), Utils = _p.r(12);
  2442. return _p.r(11).createClass("GaussianblurEffect", {
  2443. base: Effect,
  2444. constructor: function(stdDeviation, input) {
  2445. this.callBase(Effect.NAME_GAUSSIAN_BLUR);
  2446. this.set("stdDeviation", Utils.getValue(stdDeviation, 1));
  2447. this.set("in", Utils.getValue(input, Effect.INPUT_SOURCE_GRAPHIC));
  2448. }
  2449. });
  2450. }
  2451. };
  2452. //src/filter/effect/offseteffect.js
  2453. /**
  2454. * 偏移效果封装
  2455. */
  2456. _p[19] = {
  2457. value: function(require, exports, module) {
  2458. var Effect = _p.r(17), Utils = _p.r(12);
  2459. return _p.r(11).createClass("OffsetEffect", {
  2460. base: Effect,
  2461. constructor: function(dx, dy, input) {
  2462. this.callBase(Effect.NAME_OFFSET);
  2463. this.set("dx", Utils.getValue(dx, 0));
  2464. this.set("dy", Utils.getValue(dy, 0));
  2465. this.set("in", Utils.getValue(input, Effect.INPUT_SOURCE_GRAPHIC));
  2466. }
  2467. });
  2468. }
  2469. };
  2470. //src/filter/effectcontainer.js
  2471. /*
  2472. * Effect所用的container
  2473. */
  2474. _p[20] = {
  2475. value: function(require) {
  2476. return _p.r(11).createClass("EffectContainer", {
  2477. base: _p.r(30),
  2478. addEffect: function(point, pos) {
  2479. return this.addItem.apply(this, arguments);
  2480. },
  2481. prependEffect: function() {
  2482. return this.prependItem.apply(this, arguments);
  2483. },
  2484. appendEffect: function() {
  2485. return this.appendItem.apply(this, arguments);
  2486. },
  2487. removeEffect: function(pos) {
  2488. return this.removeItem.apply(this, arguments);
  2489. },
  2490. addEffects: function() {
  2491. return this.addItems.apply(this, arguments);
  2492. },
  2493. setEffects: function() {
  2494. return this.setItems.apply(this, arguments);
  2495. },
  2496. getEffect: function() {
  2497. return this.getItem.apply(this, arguments);
  2498. },
  2499. getEffects: function() {
  2500. return this.getItems.apply(this, arguments);
  2501. },
  2502. getFirstEffect: function() {
  2503. return this.getFirstItem.apply(this, arguments);
  2504. },
  2505. getLastEffect: function() {
  2506. return this.getLastItem.apply(this, arguments);
  2507. },
  2508. handleAdd: function(effectItem, pos) {
  2509. var count = this.getEffects().length, nextEffectItem = this.getItem(pos + 1);
  2510. // 最后一个节点, 直接追加
  2511. if (count === pos + 1) {
  2512. this.node.appendChild(effectItem.getNode());
  2513. return;
  2514. }
  2515. this.node.insertBefore(effectItem.getNode(), nextEffectItem.getNode());
  2516. }
  2517. });
  2518. }
  2519. };
  2520. //src/filter/filter.js
  2521. /**
  2522. * Filter 基类
  2523. */
  2524. _p[21] = {
  2525. value: function(require, exports, module) {
  2526. var svg = _p.r(68);
  2527. var Class = _p.r(11);
  2528. var Filter = Class.createClass("Filter", {
  2529. mixins: [ _p.r(20) ],
  2530. constructor: function(x, y, width, height) {
  2531. this.node = svg.createNode("filter");
  2532. if (x !== undefined) {
  2533. this.set("x", x);
  2534. }
  2535. if (y !== undefined) {
  2536. this.set("y", y);
  2537. }
  2538. if (width !== undefined) {
  2539. this.set("width", width);
  2540. }
  2541. if (height !== undefined) {
  2542. this.set("height", height);
  2543. }
  2544. },
  2545. getId: function() {
  2546. return this.id;
  2547. },
  2548. setId: function(id) {
  2549. this.node.id = id;
  2550. return this;
  2551. },
  2552. set: function(key, value) {
  2553. this.node.setAttribute(key, value);
  2554. return this;
  2555. },
  2556. get: function(key) {
  2557. return this.node.getAttribute(key);
  2558. },
  2559. getNode: function() {
  2560. return this.node;
  2561. }
  2562. });
  2563. var Shape = _p.r(61);
  2564. Class.extendClass(Shape, {
  2565. applyFilter: function(filter) {
  2566. var filterId = filter.get("id");
  2567. if (filterId) {
  2568. this.node.setAttribute("filter", "url(#" + filterId + ")");
  2569. }
  2570. return this;
  2571. }
  2572. });
  2573. return Filter;
  2574. }
  2575. };
  2576. //src/filter/gaussianblurfilter.js
  2577. /*
  2578. * 高斯模糊滤镜
  2579. */
  2580. _p[22] = {
  2581. value: function(require, exports, module) {
  2582. var GaussianblurEffect = _p.r(18);
  2583. return _p.r(11).createClass("GaussianblurFilter", {
  2584. base: _p.r(21),
  2585. constructor: function(stdDeviation) {
  2586. this.callBase();
  2587. this.addEffect(new GaussianblurEffect(stdDeviation));
  2588. }
  2589. });
  2590. }
  2591. };
  2592. //src/filter/projectionfilter.js
  2593. /*
  2594. * 投影滤镜
  2595. */
  2596. _p[23] = {
  2597. value: function(require, exports, module) {
  2598. var GaussianblurEffect = _p.r(18), Effect = _p.r(17), ColorMatrixEffect = _p.r(14), Color = _p.r(29), Utils = _p.r(12), CompositeEffect = _p.r(15), OffsetEffect = _p.r(19);
  2599. return _p.r(11).createClass("ProjectionFilter", {
  2600. base: _p.r(21),
  2601. constructor: function(stdDeviation, dx, dy) {
  2602. this.callBase();
  2603. this.gaussianblurEffect = new GaussianblurEffect(stdDeviation, Effect.INPUT_SOURCE_ALPHA);
  2604. this.gaussianblurEffect.set("result", "gaussianblur");
  2605. this.addEffect(this.gaussianblurEffect);
  2606. this.offsetEffect = new OffsetEffect(dx, dy, this.gaussianblurEffect);
  2607. this.offsetEffect.set("result", "offsetBlur");
  2608. this.addEffect(this.offsetEffect);
  2609. this.colorMatrixEffect = new ColorMatrixEffect(ColorMatrixEffect.TYPE_MATRIX, this.offsetEffect);
  2610. this.colorMatrixEffect.set("values", ColorMatrixEffect.MATRIX_ORIGINAL);
  2611. this.colorMatrixEffect.set("result", "colorOffsetBlur");
  2612. this.addEffect(this.colorMatrixEffect);
  2613. this.compositeEffect = new CompositeEffect(CompositeEffect.OPERATOR_OVER, Effect.INPUT_SOURCE_GRAPHIC, this.colorMatrixEffect);
  2614. this.addEffect(this.compositeEffect);
  2615. },
  2616. // 设置投影颜色
  2617. setColor: function(color) {
  2618. var matrix = null, originMatrix = null, colorValue = [];
  2619. if (Utils.isString(color)) {
  2620. color = Color.parse(color);
  2621. }
  2622. if (!color) {
  2623. return this;
  2624. }
  2625. matrix = ColorMatrixEffect.MATRIX_EMPTY.split(" ");
  2626. colorValue.push(color.get("r"));
  2627. colorValue.push(color.get("g"));
  2628. colorValue.push(color.get("b"));
  2629. // rgb 分量更改
  2630. for (var i = 0, len = colorValue.length; i < len; i++) {
  2631. matrix[i * 5 + 3] = colorValue[i] / 255;
  2632. }
  2633. // alpha 分量更改
  2634. matrix[18] = color.get("a");
  2635. this.colorMatrixEffect.set("values", matrix.join(" "));
  2636. return this;
  2637. },
  2638. // 设置投影透明度
  2639. setOpacity: function(opacity) {
  2640. var matrix = this.colorMatrixEffect.get("values").split(" ");
  2641. matrix[18] = opacity;
  2642. this.colorMatrixEffect.set("values", matrix.join(" "));
  2643. return this;
  2644. },
  2645. // 设置阴影偏移量
  2646. setOffset: function(dx, dy) {
  2647. this.setOffsetX(dx);
  2648. this.setOffsetY(dy);
  2649. },
  2650. setOffsetX: function(dx) {
  2651. this.offsetEffect.set("dx", dx);
  2652. },
  2653. setOffsetY: function(dy) {
  2654. this.offsetEffect.set("dy", dy);
  2655. },
  2656. setDeviation: function(deviation) {
  2657. this.gaussianblurEffect.set("stdDeviation", deviation);
  2658. }
  2659. });
  2660. }
  2661. };
  2662. //src/graphic/bezier.js
  2663. /**
  2664. * @fileOverview
  2665. *
  2666. * 贝塞尔曲线
  2667. */
  2668. _p[24] = {
  2669. value: function(require, exports, module) {
  2670. /**
  2671. * @class kity.Bezier
  2672. * @mixins kity.PointContainer
  2673. * @base kity.Path
  2674. * @description 绘制和使用贝塞尔曲线。贝塞尔曲线作为一个贝塞尔点的容器,任何贝塞尔点的改变都会更改贝塞尔曲线的外观
  2675. */
  2676. return _p.r(11).createClass("Bezier", {
  2677. mixins: [ _p.r(52) ],
  2678. base: _p.r(47),
  2679. /**
  2680. * @constructor
  2681. * @for kity.Bezier
  2682. *
  2683. * @grammar new kity.Bezier(bezierPoints)
  2684. *
  2685. * @param {kity.BezierPoints[]} bezierPoints 贝塞尔点集合,每个元素应该是 {kity.BezierPoint} 类型
  2686. *
  2687. * @example
  2688. *
  2689. * ```js
  2690. * var bezier = new kity.Bezier([
  2691. * new kity.BezierPoint(0, 0).setForward(100, 0),
  2692. * new kity.BezierPoint(100, 100).setBackward(100, 0)
  2693. * ]);
  2694. * ```
  2695. */
  2696. constructor: function(bezierPoints) {
  2697. this.callBase();
  2698. bezierPoints = bezierPoints || [];
  2699. this.changeable = true;
  2700. this.setBezierPoints(bezierPoints);
  2701. },
  2702. /**
  2703. * @method getBezierPoints()
  2704. * @for kity.Bezier
  2705. * @description 返回当前贝塞尔曲线的贝塞尔点集合
  2706. *
  2707. * @grammar getBezierPoints() => {kity.BezierPoints[]}
  2708. *
  2709. */
  2710. getBezierPoints: function() {
  2711. return this.getPoints();
  2712. },
  2713. /**
  2714. * @method setBezierPoints()
  2715. * @for kity.Bezier
  2716. * @description 设置当前贝塞尔曲线的贝塞尔点集合
  2717. *
  2718. * @grammar setBeizerPoints(bezierPoints) => {this}
  2719. *
  2720. * @param {kity.BezierPoint[]} bezierPoints 贝塞尔点集合
  2721. */
  2722. setBezierPoints: function(bezierPoints) {
  2723. return this.setPoints(bezierPoints);
  2724. },
  2725. //当点集合发生变化时采取的动作
  2726. onContainerChanged: function() {
  2727. if (this.changeable) {
  2728. this.update();
  2729. }
  2730. },
  2731. update: function() {
  2732. var drawer = null, bezierPoints = this.getBezierPoints();
  2733. //单独的一个点不画任何图形
  2734. if (bezierPoints.length < 2) {
  2735. return;
  2736. }
  2737. drawer = this.getDrawer();
  2738. drawer.clear();
  2739. var vertex = bezierPoints[0].getVertex(), forward = null, backward = null;
  2740. drawer.moveTo(vertex.x, vertex.y);
  2741. for (var i = 1, len = bezierPoints.length; i < len; i++) {
  2742. vertex = bezierPoints[i].getVertex();
  2743. backward = bezierPoints[i].getBackward();
  2744. forward = bezierPoints[i - 1].getForward();
  2745. drawer.bezierTo(forward.x, forward.y, backward.x, backward.y, vertex.x, vertex.y);
  2746. }
  2747. return this;
  2748. }
  2749. });
  2750. }
  2751. };
  2752. //src/graphic/bezierpoint.js
  2753. /**
  2754. * @fileOverview
  2755. *
  2756. * 表示一个贝塞尔点
  2757. */
  2758. _p[25] = {
  2759. value: function(require, exports, module) {
  2760. var ShapePoint = _p.r(64);
  2761. var Vector = _p.r(74);
  2762. /**
  2763. * @class kity.BezierPoint
  2764. *
  2765. * @description 表示一个贝塞尔点
  2766. * 一个贝塞尔点由顶点坐标(曲线经过的点)、前方控制点、后方控制点表示
  2767. */
  2768. var BezierPoint = _p.r(11).createClass("BezierPoint", {
  2769. /**
  2770. * @constructor
  2771. * @for kity.BezierPoint
  2772. *
  2773. * @description 创建一个具有默认顶点坐标的贝塞尔点,两个控制点的坐标和顶点一致
  2774. *
  2775. * @param {Number} x 顶点的 x 坐标
  2776. * @param {Number} y 顶点的 y 坐标
  2777. * @param {Boolean} isSmooth 指示当前贝塞尔点是否光滑,光滑会约束顶点和两个控制点共线
  2778. */
  2779. constructor: function(x, y, isSmooth) {
  2780. //顶点
  2781. this.vertex = new ShapePoint(x, y);
  2782. //控制点
  2783. this.forward = new ShapePoint(x, y);
  2784. this.backward = new ShapePoint(x, y);
  2785. //是否平滑
  2786. this.setSmooth(isSmooth === undefined || isSmooth);
  2787. this.setSymReflaction(true);
  2788. },
  2789. /**
  2790. * @method clone()
  2791. * @for kity.BezierPoint
  2792. * @description 返回贝塞尔点的一份拷贝
  2793. *
  2794. * @grammar clone() => {kity.BezierPoint}
  2795. */
  2796. clone: function() {
  2797. var newPoint = new BezierPoint(), tmp = null;
  2798. tmp = this.getVertex();
  2799. newPoint.setVertex(tmp.x, tmp.y);
  2800. tmp = this.getForward();
  2801. newPoint.setForward(tmp.x, tmp.y);
  2802. tmp = this.getBackward();
  2803. newPoint.setBackward(tmp.x, tmp.y);
  2804. newPoint.setSymReflaction(this.isSymReflaction);
  2805. newPoint.setSmooth(this.isSmooth());
  2806. return newPoint;
  2807. },
  2808. /**
  2809. * @method setVertex()
  2810. * @for kity.BezierPoint
  2811. * @description 设置贝塞尔点的顶点坐标,注意,控制点的坐标不会跟着变化。希望控制点的坐标跟着变化,请用 moveTo() 方法
  2812. *
  2813. * @grammar setVertex(x, y) => {this}
  2814. *
  2815. * @param {Number} x 顶点的 x 坐标
  2816. * @param {Number} y 顶点的 y 坐标
  2817. */
  2818. setVertex: function(x, y) {
  2819. this.vertex.setPoint(x, y);
  2820. this.update();
  2821. return this;
  2822. },
  2823. /**
  2824. * @method moveTo()
  2825. * @for kity.BezierPoint
  2826. * @description 同步移动整个贝塞尔点,使顶点的移动到指定的坐标中。控制点的位置相对顶点坐标固定。
  2827. *
  2828. * @grammar moveTo() => {this}
  2829. *
  2830. * @param {Number} x 顶点的目标 x 坐标
  2831. * @param {Number} y 顶点的目标 y 坐标
  2832. *
  2833. */
  2834. moveTo: function(x, y) {
  2835. var oldForward = this.forward.getPoint(), oldBackward = this.backward.getPoint(), oldVertex = this.vertex.getPoint(), //移动距离
  2836. distance = {
  2837. left: x - oldVertex.x,
  2838. top: y - oldVertex.y
  2839. };
  2840. // 更新
  2841. this.forward.setPoint(oldForward.x + distance.left, oldForward.y + distance.top);
  2842. this.backward.setPoint(oldBackward.x + distance.left, oldBackward.y + distance.top);
  2843. this.vertex.setPoint(x, y);
  2844. this.update();
  2845. },
  2846. /**
  2847. * @method setForward()
  2848. * @for kity.BezierPoint
  2849. * @description 设置前方控制点的位置,如果贝塞尔点光滑,后方控制点会跟着联动
  2850. *
  2851. * @grammar setForward(x, y) => {this}
  2852. *
  2853. * @param {Number} x 前方控制点的 x 坐标
  2854. * @param {Number} y 前方控制点的 y 坐标
  2855. */
  2856. setForward: function(x, y) {
  2857. this.forward.setPoint(x, y);
  2858. //更新后置点
  2859. if (this.smooth) {
  2860. this.updateAnother(this.forward, this.backward);
  2861. }
  2862. this.update();
  2863. this.lastControlPointSet = this.forward;
  2864. return this;
  2865. },
  2866. /**
  2867. * @method setBackward()
  2868. * @for kity.BezierPoint
  2869. * @description 设置后方控制点的位置,如果贝塞尔点光滑,前方控制点会跟着联动
  2870. *
  2871. * @grammar setBackward(x, y) => {this}
  2872. *
  2873. * @param {Number} x 后方控制点的 x 坐标
  2874. * @param {Number} y 后方控制点的 y 坐标
  2875. */
  2876. setBackward: function(x, y) {
  2877. this.backward.setPoint(x, y);
  2878. //更新前置点
  2879. if (this.smooth) {
  2880. this.updateAnother(this.backward, this.forward);
  2881. }
  2882. this.update();
  2883. this.lastControlPointSet = this.backward;
  2884. return this;
  2885. },
  2886. /**
  2887. * @method setSymReflaction()
  2888. * @for kity.BezierPoint
  2889. * @description 设定是否镜像两个控制点的位置
  2890. *
  2891. * @grammar setSymReflaction(value) => {this}
  2892. *
  2893. * @param {boolean} value 如果设置为 true,且贝塞尔点光滑,两个控制点离顶点的距离相等
  2894. */
  2895. setSymReflaction: function(value) {
  2896. this.symReflaction = value;
  2897. if (this.smooth) this.setSmooth(true);
  2898. return this;
  2899. },
  2900. /**
  2901. * @method isSymReflaction()
  2902. * @for kity.BezierPoint
  2903. * @description 当前贝塞尔点的两个控制点是否被镜像约束
  2904. *
  2905. * @grammar isSymReflaction() => {boolean}
  2906. */
  2907. isSymReflaction: function() {
  2908. return this.symReflaction;
  2909. },
  2910. /**
  2911. * @private
  2912. *
  2913. * 根据前方控制点或后方控制点更新另一方
  2914. */
  2915. updateAnother: function(p, q) {
  2916. var v = this.getVertex(), pv = Vector.fromPoints(p.getPoint(), v), vq = Vector.fromPoints(v, q.getPoint());
  2917. vq = pv.normalize(this.isSymReflaction() ? pv.length() : vq.length());
  2918. q.setPoint(v.x + vq.x, v.y + vq.y);
  2919. return this;
  2920. },
  2921. /**
  2922. * @method setSmooth()
  2923. * @for kity.BezierPoint
  2924. * @description 设置贝塞尔点是否光滑,光滑会约束顶点和两个控制点共线
  2925. *
  2926. * @param {Boolean} isSmooth 设置为 true 让贝塞尔点光滑
  2927. */
  2928. setSmooth: function(isSmooth) {
  2929. var lc;
  2930. this.smooth = !!isSmooth;
  2931. if (this.smooth && (lc = this.lastControlPointSet)) {
  2932. this.updateAnother(lc, lc == this.forward ? this.backward : this.forward);
  2933. }
  2934. return this;
  2935. },
  2936. /**
  2937. * @method isSmooth()
  2938. * @for kity.BezierPoint
  2939. * @description 判断贝塞尔点是否光滑
  2940. *
  2941. * @grammar isSmooth() => {boolean}
  2942. */
  2943. isSmooth: function() {
  2944. return this.smooth;
  2945. },
  2946. /**
  2947. * @method getVertex()
  2948. * @for kity.BezierPoint
  2949. * @description 获得当前贝塞尔点的顶点
  2950. *
  2951. * @grammar getVertex() => {kity.ShapePoint}
  2952. */
  2953. getVertex: function() {
  2954. return this.vertex.getPoint();
  2955. },
  2956. /**
  2957. * @method getForward()
  2958. * @for kity.BezierPoint
  2959. * @description 获得当前贝塞尔点的前方控制点
  2960. *
  2961. * @grammar getForward() => {kity.ShapePoint}
  2962. */
  2963. getForward: function() {
  2964. return this.forward.getPoint();
  2965. },
  2966. /**
  2967. * @method getBackward()
  2968. * @for kity.BezierPoint
  2969. * @description 获得当前贝塞尔点的后方控制点
  2970. *
  2971. * @grammar getBackward() => {kity.ShapePoint}
  2972. */
  2973. getBackward: function() {
  2974. return this.backward.getPoint();
  2975. },
  2976. /**
  2977. * @private
  2978. *
  2979. * 联动更新相关的贝塞尔曲线
  2980. */
  2981. update: function() {
  2982. if (!this.container) {
  2983. return this;
  2984. }
  2985. //新增参数 this, 把当前引起变化的点传递过去, 以便有需要的地方可以获取到引起变化的源
  2986. if (this.container.update) this.container.update(this);
  2987. }
  2988. });
  2989. return BezierPoint;
  2990. }
  2991. };
  2992. //src/graphic/box.js
  2993. /**
  2994. * @fileOverview
  2995. *
  2996. * 表示一个矩形区域
  2997. */
  2998. _p[26] = {
  2999. value: function(require, exports, module) {
  3000. /**
  3001. * @class kity.Box
  3002. * @description 表示一个矩形区域
  3003. */
  3004. var Box = _p.r(11).createClass("Box", {
  3005. /**
  3006. * @constructor
  3007. * @for kity.Box
  3008. *
  3009. * @grammar new kity.Box(x, y, width, height)
  3010. * @grammar new kity.Box(box)
  3011. *
  3012. * @param {Number} x|box.x 矩形区域的 x 坐标
  3013. * @param {Number} y|box.y 矩形区域的 y 坐标
  3014. * @param {Number} width|box.width 矩形区域的宽度
  3015. * @param {Number} height|box.height 矩形区域的高度
  3016. *
  3017. * @example
  3018. *
  3019. * ```js
  3020. * var box = new kity.Box(10, 20, 50, 50);
  3021. * var box2 = new kity.Box({x: 10, y: 20, width: 50, height: 50});
  3022. * ```
  3023. */
  3024. constructor: function(x, y, width, height) {
  3025. var box = arguments[0];
  3026. if (box && typeof box === "object") {
  3027. x = box.x;
  3028. y = box.y;
  3029. width = box.width;
  3030. height = box.height;
  3031. }
  3032. if (width < 0) {
  3033. x -= width = -width;
  3034. }
  3035. if (height < 0) {
  3036. y -= height = -height;
  3037. }
  3038. /**
  3039. * @property x
  3040. * @for kity.Box
  3041. * @type {Number}
  3042. * @readOnly
  3043. * @description 矩形区域的 x 坐标
  3044. */
  3045. this.x = x || 0;
  3046. /**
  3047. * @property y
  3048. * @for kity.Box
  3049. * @type {Number}
  3050. * @readOnly
  3051. * @description 矩形区域的 y 坐标
  3052. */
  3053. this.y = y || 0;
  3054. /**
  3055. * @property width
  3056. * @for kity.Box
  3057. * @type {Number}
  3058. * @readOnly
  3059. * @description 矩形区域的宽度
  3060. */
  3061. this.width = width || 0;
  3062. /**
  3063. * @property height
  3064. * @for kity.Box
  3065. * @type {Number}
  3066. * @readOnly
  3067. * @description 矩形区域的高度
  3068. */
  3069. this.height = height || 0;
  3070. /**
  3071. * @property left
  3072. * @for kity.Box
  3073. * @type {Number}
  3074. * @readOnly
  3075. * @description 矩形区域的最左侧坐标,等价于 x 的值
  3076. */
  3077. this.left = this.x;
  3078. /**
  3079. * @property right
  3080. * @for kity.Box
  3081. * @type {Number}
  3082. * @readOnly
  3083. * @description 矩形区域的最右侧坐标,等价于 x + width 的值
  3084. */
  3085. this.right = this.x + this.width;
  3086. /**
  3087. * @property top
  3088. * @for kity.Box
  3089. * @type {Number}
  3090. * @readOnly
  3091. * @description 矩形区域的最上侧坐标,等价于 y 的值
  3092. */
  3093. this.top = this.y;
  3094. /**
  3095. * @property bottom
  3096. * @for kity.Box
  3097. * @type {Number}
  3098. * @readOnly
  3099. * @description 矩形区域的最下侧坐标,等价于 y + height 的值
  3100. */
  3101. this.bottom = this.y + this.height;
  3102. /**
  3103. * @property cx
  3104. * @for kity.Box
  3105. * @type {Number}
  3106. * @readOnly
  3107. * @description 矩形区域的中心 x 坐标
  3108. */
  3109. this.cx = this.x + this.width / 2;
  3110. /**
  3111. * @property cy
  3112. * @for kity.Box
  3113. * @type {Number}
  3114. * @readOnly
  3115. * @description 矩形区域的中心 y 坐标
  3116. */
  3117. this.cy = this.y + this.height / 2;
  3118. },
  3119. /**
  3120. * @method getRangeX()
  3121. * @for kity.Box
  3122. * @description 获得矩形区域的 x 值域
  3123. *
  3124. * @grammar getRangeX() => {Number[]}
  3125. *
  3126. * @example
  3127. *
  3128. * var box = new kity.Box(10, 10, 30, 50);
  3129. * console.log(box.getRangeX()); // [10, 40]
  3130. */
  3131. getRangeX: function() {
  3132. return [ this.left, this.right ];
  3133. },
  3134. /**
  3135. * @method getRangeY()
  3136. * @for kity.Box
  3137. * @description 获得矩形区域的 y 值域
  3138. *
  3139. * @grammar getRangeY() => {Number[]}
  3140. *
  3141. * @example
  3142. *
  3143. * var box = new kity.Box(10, 10, 30, 50);
  3144. * console.log(box.getRangeY()); // [10, 60]
  3145. */
  3146. getRangeY: function() {
  3147. return [ this.top, this.bottom ];
  3148. },
  3149. /**
  3150. * @method merge()
  3151. * @for kity.Box
  3152. * @description 把当前矩形区域和指定的矩形区域合并,返回一个新的矩形区域(即包含两个源矩形区域的最小矩形区域)
  3153. *
  3154. * @grammar merge(another) => {kity.Box}
  3155. * @param {kity.Box} another 要合并的矩形区域
  3156. *
  3157. * @example
  3158. *
  3159. * ```js
  3160. * var box1 = new kity.Box(10, 10, 50, 50);
  3161. * var box2 = new kity.Box(30, 30, 50, 50);
  3162. * var box3 = box1.merge(box2);
  3163. * console.log(box3.valueOf()); // [10, 10, 70, 70]
  3164. * ```
  3165. */
  3166. merge: function(another) {
  3167. if (this.isEmpty()) {
  3168. return new Box(another.x, another.y, another.width, another.height);
  3169. }
  3170. var left = Math.min(this.left, another.left), right = Math.max(this.right, another.right), top = Math.min(this.top, another.top), bottom = Math.max(this.bottom, another.bottom);
  3171. return new Box(left, top, right - left, bottom - top);
  3172. },
  3173. /**
  3174. * @method intersect()
  3175. * @for kity.Box
  3176. * @description 求当前矩形区域和指定的矩形区域重叠的矩形区域
  3177. *
  3178. * @grammar intersect(another) => {kity.Box}
  3179. * @param {kity.Box} another 要求重叠的矩形区域
  3180. *
  3181. * @example
  3182. *
  3183. * ```js
  3184. * var box1 = new kity.Box(10, 10, 50, 50);
  3185. * var box2 = new kity.Box(30, 30, 50, 50);
  3186. * var box3 = box1.intersect(box2);
  3187. * console.log(box3.valueOf()); // [30, 30, 20, 20]
  3188. * ```
  3189. */
  3190. intersect: function(another) {
  3191. if (!another instanceof Box) {
  3192. another = new Box(another);
  3193. }
  3194. var left = Math.max(this.left, another.left), right = Math.min(this.right, another.right), top = Math.max(this.top, another.top), bottom = Math.min(this.bottom, another.bottom);
  3195. if (left > right || top > bottom) return new Box();
  3196. return new Box(left, top, right - left, bottom - top);
  3197. },
  3198. /**
  3199. * @method expand()
  3200. * @for kity.Box
  3201. * @description 扩展(或收缩)当前的盒子,返回新的盒子
  3202. *
  3203. * @param {Number} top
  3204. * 矩形区域的上边界往上扩展的值;如果是负数,则上边界往下收缩
  3205. *
  3206. * @param {Number} right
  3207. * [Optional] 矩形区域的右边界往右拓展的值;
  3208. * 如果是负数,则右边界往左收缩;
  3209. * 如果不设置该值,使用和 top 同样的值。
  3210. *
  3211. * @param {Number} bottom
  3212. * [Optional] 矩形区域的下边界往下拓展的值;
  3213. * 如果是负数,则下边界往上收缩;
  3214. * 如果不设置该值,使用和 top 同样的值。
  3215. *
  3216. * @param {Number} left
  3217. * [Optional] 矩形区域的左边界往左拓展的值;
  3218. * 如果是负数,则左边界往右收缩;
  3219. * 如果不设置该值,使用和 right 同样的值。
  3220. *
  3221. * @example
  3222. *
  3223. * ```js
  3224. * var box = new kity.Box(10, 10, 20, 20);
  3225. * var box1 = box.expand(10); // [0, 0, 40, 40]
  3226. * var box2 = box.expand(10, 20); // [0, -10, 40, 60]
  3227. * var box3 = box.expand(1, 2, 3, 4); // [9, 8, 24, 26]
  3228. * ```
  3229. */
  3230. expand: function(top, right, bottom, left) {
  3231. if (arguments.length < 1) {
  3232. return new Box(this);
  3233. }
  3234. if (arguments.length < 2) {
  3235. right = top;
  3236. }
  3237. if (arguments.length < 3) {
  3238. bottom = top;
  3239. }
  3240. if (arguments.length < 4) {
  3241. left = right;
  3242. }
  3243. var x = this.left - left, y = this.top - top, width = this.width + right + left, height = this.height + top + bottom;
  3244. return new Box(x, y, width, height);
  3245. },
  3246. /**
  3247. * @method valueOf()
  3248. * @for kity.Box
  3249. * @description 返回当前盒子的数组表示
  3250. *
  3251. * @grammar valueOf() => {Number[]}
  3252. *
  3253. * @example
  3254. *
  3255. * ```js
  3256. * var box = new kity.Box(0, 0, 200, 50);
  3257. * console.log(box.valueOf()); // [0, 0, 200, 50]
  3258. * ```
  3259. */
  3260. valueOf: function() {
  3261. return [ this.x, this.y, this.width, this.height ];
  3262. },
  3263. /**
  3264. * @method toString()
  3265. * @for kity.Box
  3266. * @description 返回当前盒子的字符串表示
  3267. *
  3268. * @grammar toString() => {String}
  3269. *
  3270. * @example
  3271. *
  3272. * ```js
  3273. * var box = new kity.Box(0, 0, 200, 50);
  3274. * console.log(box.toString()); // "0 0 200 50"
  3275. */
  3276. toString: function() {
  3277. return this.valueOf().join(" ");
  3278. },
  3279. /**
  3280. * @method isEmpty()
  3281. * @for kity.Box
  3282. * @description 判断当前盒子是否具有尺寸(面积大
  3283. *
  3284. * @grammar isEmpty() => {boolean}
  3285. *
  3286. * @example
  3287. * ```js
  3288. * var box = new kity.Box(0, 0, 0, 100000);
  3289. * console.log(box.isEmpty()); // true
  3290. * ```
  3291. */
  3292. isEmpty: function() {
  3293. return !this.width || !this.height;
  3294. }
  3295. });
  3296. /**
  3297. * @method parse()
  3298. * @static
  3299. * @for kity.Box
  3300. * @description 解析一个字符串或数组为 kity.Box 对象
  3301. *
  3302. * @grammar kity.Box.parse(any) => {kity.Box}
  3303. *
  3304. * @param {Number[]|String} any 要解析的字符串或数组
  3305. *
  3306. * @example
  3307. *
  3308. * ```js
  3309. * console.log(kity.Box.parse('0 0 100 200'));
  3310. * console.log(kity.Box.parse([0, 0, 100, 200]));
  3311. * ```
  3312. */
  3313. Box.parse = function(any) {
  3314. if (typeof any == "string") {
  3315. return Box.parse(any.split(/[\s,]+/).map(parseFloat));
  3316. }
  3317. if (any instanceof Array) {
  3318. return new Box(any[0], any[1], any[2], any[3]);
  3319. }
  3320. if ("x" in any) return new Box(any);
  3321. return null;
  3322. };
  3323. return Box;
  3324. }
  3325. };
  3326. //src/graphic/circle.js
  3327. /**
  3328. * @fileOverview
  3329. *
  3330. * 绘制和使用圆形
  3331. */
  3332. _p[27] = {
  3333. value: function(require, exports, module) {
  3334. /**
  3335. * @class kity.Circle
  3336. * @base kity.Ellipse
  3337. * @description 表示一个圆形
  3338. */
  3339. return _p.r(11).createClass("Circle", {
  3340. base: _p.r(33),
  3341. /**
  3342. * @constructor
  3343. * @for kity.Circle
  3344. *
  3345. * @grammar new kity.Circle(radius, cx, cy)
  3346. *
  3347. * @param {Number} radius 半径
  3348. * @param {Number} cx 圆心 x 坐标
  3349. * @param {Number} cy 圆心 y 坐标
  3350. */
  3351. constructor: function(radius, cx, cy) {
  3352. this.callBase(radius, radius, cx, cy);
  3353. },
  3354. /**
  3355. * @method
  3356. * @for kity.Circle
  3357. * @description 获取圆形的半径
  3358. *
  3359. * @grammar getRadius() => {Number}
  3360. */
  3361. getRadius: function() {
  3362. return this.getRadiusX();
  3363. },
  3364. /**
  3365. * @method
  3366. * @for kity.Circle
  3367. * @description 设置圆形的半径
  3368. *
  3369. * @grammar setRadius() => {this}
  3370. *
  3371. * @param {Number} radius 半径大小
  3372. */
  3373. setRadius: function(radius) {
  3374. return this.callBase(radius, radius);
  3375. }
  3376. });
  3377. }
  3378. };
  3379. //src/graphic/clip.js
  3380. /**
  3381. * @fileOverview
  3382. *
  3383. * 支持图形裁切
  3384. */
  3385. _p[28] = {
  3386. value: function(require, exports, module) {
  3387. var Class = _p.r(11);
  3388. var Shape = _p.r(61);
  3389. /**
  3390. * @class kity.Clip
  3391. * @base kity.Resource
  3392. * @mixins kity.ShapeContainer
  3393. *
  3394. * @description 创建图形裁切,用于裁切目标图形
  3395. */
  3396. var Clip = Class.createClass("Clip", {
  3397. base: Shape,
  3398. mixins: [ _p.r(62) ],
  3399. /**
  3400. * @constructor
  3401. * @for kity.Clip
  3402. *
  3403. * @grammar new kity.Clip(paper)
  3404. *
  3405. * @param {kity.Paper} paper 资源所属的文档
  3406. *
  3407. * @example
  3408. *
  3409. * ```js
  3410. * var circle = paper.put(new kity.Circle(100).fill('yellow'));
  3411. * var clip = new kity.Clip(paper);
  3412. * clip.addShape(new kity.Circle(100, 50, 0));
  3413. * clip.clip(circle);
  3414. * ```
  3415. */
  3416. constructor: function(paper) {
  3417. this.callBase("clipPath", paper);
  3418. },
  3419. /**
  3420. * @method clip()
  3421. * @for kity.Clip
  3422. * @description 将裁切应用到指定的图形上,应用之后,目标图形将显示与裁切形状重合的部分
  3423. *
  3424. * @grammar clip(shape) => {this}
  3425. *
  3426. * @param {kity.Shape} shape 要应用裁切的图形
  3427. */
  3428. clip: function(shape) {
  3429. shape.getNode().setAttribute("clip-path", this);
  3430. return this;
  3431. }
  3432. });
  3433. Class.extendClass(Shape, {
  3434. /**
  3435. * @method clipWidth()
  3436. * @for kity.Shape
  3437. *
  3438. * @grammar clipWidth(clip) => {this}
  3439. *
  3440. * @param {kity.Clip|kity.Shape} clip 要用于裁切当前图形的图形;
  3441. * 如果 clip 本身是一个裁切对象(kity.Clip 类型),则直接裁切;
  3442. * 否则将创建新的裁切包含给定的图形,然后对当前图形进行裁切
  3443. *
  3444. * @example
  3445. *
  3446. * ```js
  3447. * var circle = paper.put(new kity.Circle(100));
  3448. * var rect = paper.put(new kity.Rect(100, 100, -100, 0));
  3449. *
  3450. * circle.clipWidth(rect);
  3451. * ```
  3452. */
  3453. clipWith: function(clip) {
  3454. if (clip instanceof Shape) {
  3455. clip = new Clip(clip.getPaper()).addShape(clip);
  3456. }
  3457. clip.clip(this);
  3458. return this;
  3459. }
  3460. });
  3461. return Clip;
  3462. }
  3463. };
  3464. //src/graphic/color.js
  3465. /**
  3466. * @fileOverview
  3467. *
  3468. * 提供颜色支持
  3469. */
  3470. _p[29] = {
  3471. value: function(require, exports, module) {
  3472. var Utils = _p.r(12), StandardColor = _p.r(65), ColorUtils = {}, /**
  3473. * @class kity.Color
  3474. * @description 表示一个颜色
  3475. */
  3476. Color = _p.r(11).createClass("Color", {
  3477. /**
  3478. * @constructor
  3479. * @for kity.Color
  3480. *
  3481. * @grammar new kity.Color(r, g, b)
  3482. * @grammar new kity.Color(r, g, b, a)
  3483. * @grammar new kity.Color(colorString)
  3484. *
  3485. * @param {Number} r 红色分量,取值 0 - 255
  3486. * @param {Number} g 绿色分量,取值 0 - 255
  3487. * @param {Number} b 蓝色分量,取值 0 - 255
  3488. * @param {Number} a 透明度(可选),取值 0 - 100
  3489. * @param {String} colorString 一个代表颜色的字符串,可以是:
  3490. * 熟知颜色表:如 'red', 'yellow'
  3491. * HEX 表示:如 '#368', '#123456'
  3492. * RGB 表示:如 'RGB(200, 200, 0)', 'RGBA(200, 200, 200, .5)'
  3493. * HSL 表示:如 'HSL(100, 60%, 80%)', 'HSLA(100, 60%, 80%, .5)'
  3494. */
  3495. constructor: function() {
  3496. var colorValue = null;
  3497. //parse构造
  3498. if (typeof arguments[0] === "string") {
  3499. colorValue = ColorUtils.parseToValue(arguments[0]);
  3500. //解析失败
  3501. if (colorValue === null) {
  3502. colorValue = {
  3503. r: 0,
  3504. g: 0,
  3505. b: 0,
  3506. h: 0,
  3507. s: 0,
  3508. l: 0,
  3509. a: 1
  3510. };
  3511. }
  3512. } else {
  3513. colorValue = {
  3514. r: arguments[0] | 0,
  3515. g: arguments[1] | 0,
  3516. b: arguments[2] | 0,
  3517. //alpha 默认为1
  3518. a: arguments[3] === undefined ? 1 : parseFloat(arguments[3])
  3519. };
  3520. colorValue = ColorUtils.overflowFormat(colorValue);
  3521. //获取hsl分量
  3522. colorValue = Utils.extend(colorValue, ColorUtils.rgbValueToHslValue(colorValue));
  3523. }
  3524. this._color = colorValue;
  3525. },
  3526. /**
  3527. * @method set()
  3528. * @for kity.Color
  3529. *
  3530. * @description 设置当前颜色某个分量的值
  3531. *
  3532. * @grammar set(name, value) => {this}
  3533. *
  3534. * @param {string} name 要设置的颜色通道的名称
  3535. * r: 红色(Red),取值范围 [0, 255]
  3536. * g: 绿色(Green),取值范围 [0, 255]
  3537. * b: 蓝色(Blue),取值范围 [0, 255]
  3538. * a: 透明度(Alpha),取值范围 [0, 1]
  3539. * h: 色环角度(Hue),取值范围 [0, 359]
  3540. * s: 饱和度(Saturation),取值范围 [0, 100]
  3541. * l: 亮度(Lightness),取值范围 [0, 100]
  3542. * r、g、b 值和 h、s、l 值会联动修改
  3543. * @param {number} value 要设置的值
  3544. */
  3545. set: function(name, value) {
  3546. var values = null;
  3547. //设置的值非法
  3548. if (!Color._MAX_VALUE[name]) {
  3549. throw new Error("Color set(): Illegal parameter");
  3550. }
  3551. if (name !== "a") {
  3552. value = Math.floor(value);
  3553. }
  3554. if (name == "h") {
  3555. value = (value + 360) % 360;
  3556. }
  3557. this._color[name] = Math.max(Color._MIN_VALUE[name], Math.min(Color._MAX_VALUE[name], value));
  3558. if ("rgb".indexOf(name) !== -1) {
  3559. this._color = Utils.extend(this._color, ColorUtils.rgbValueToHslValue(this._color));
  3560. } else if ("hsl".indexOf(name) !== -1) {
  3561. this._color = Utils.extend(this._color, ColorUtils.hslValueToRGBValue(this._color));
  3562. }
  3563. return this;
  3564. },
  3565. /**
  3566. * @method inc()
  3567. *
  3568. * @description 返回新的颜色,表示当前颜色增加指定通道的值之后的颜色
  3569. *
  3570. * @grammar inc(name, value) => {this}
  3571. *
  3572. * @param {string} name 要增加的通道的名称,具体含义请查看 set 方法
  3573. * @param {number} value 增量值
  3574. */
  3575. inc: function(name, value) {
  3576. value = this.get(name) + value;
  3577. if (name == "h") {
  3578. value = (value + 360) % 360;
  3579. } else {
  3580. value = Math.min(Color._MAX_VALUE[name], value);
  3581. value = Math.max(Color._MIN_VALUE[name], value);
  3582. }
  3583. return this.clone().set(name, value);
  3584. },
  3585. /**
  3586. * @method dec()
  3587. * @for kity.Color
  3588. *
  3589. * @description 返回新的颜色,表示当前颜色减少指定通道的值之后的颜色
  3590. *
  3591. * @grammar dec(name, value) => {this}
  3592. *
  3593. * @param {string} name 要减少值的通道的名称,具体含义请查看 set 方法
  3594. * @param {number} value 减量值
  3595. */
  3596. dec: function(name, value) {
  3597. return this.inc(name, -value);
  3598. },
  3599. /**
  3600. * @method clone()
  3601. * @for kity.Color
  3602. *
  3603. * @description 返回当前颜色的一个拷贝
  3604. *
  3605. * @grammar clone() => {kity.Color}
  3606. */
  3607. clone: function() {
  3608. return new Color(this.toRGBA());
  3609. },
  3610. /**
  3611. * @method get()
  3612. * @for kity.Color
  3613. *
  3614. * @description 返回当前颜色指定的分量
  3615. *
  3616. * @grammar get() => {number}
  3617. */
  3618. get: function(name) {
  3619. if (!Color._MAX_VALUE[name]) {
  3620. return null;
  3621. }
  3622. return this._color[name];
  3623. },
  3624. getValues: function() {
  3625. return Utils.clone(this._color);
  3626. },
  3627. /**
  3628. * @method valueOf()
  3629. * @for kity.Color
  3630. *
  3631. * @description 返回当前颜色的一个字面量表示
  3632. *
  3633. * @return {plain} 颜色字面量,其结构为:
  3634. * {
  3635. * r: 0,
  3636. * g: 0,
  3637. * b: 0,
  3638. * a: 0,
  3639. * h: 0,
  3640. * s: 0,
  3641. * l: 0
  3642. * }
  3643. */
  3644. valueOf: function() {
  3645. return this.getValues();
  3646. },
  3647. /**
  3648. * @method toRGB()
  3649. * @for kity.Color
  3650. *
  3651. * @description 返回当前颜色的 RGB 表示,如果颜色有透明度,将抛弃透明度属性(想要保留请使用 toRGBA())方法。
  3652. *
  3653. * @grammar toRGB() => {string}
  3654. */
  3655. toRGB: function() {
  3656. return ColorUtils.toString(this._color, "rgb");
  3657. },
  3658. /**
  3659. * @method toRGBA()
  3660. * @for kity.Color
  3661. *
  3662. * @description 返回当前颜色的 RGBA 表示
  3663. *
  3664. * @grammar toRGBA() => {string}
  3665. */
  3666. toRGBA: function() {
  3667. return ColorUtils.toString(this._color, "rgba");
  3668. },
  3669. /**
  3670. * @method toHEX()
  3671. * @for kity.Color
  3672. *
  3673. * @description 返回当前颜色的 HEX 表示,如果颜色有透明度,将抛弃透明度属性(想要保留请使用 toRGBA())方法。
  3674. *
  3675. * @grammar toHEX() => {string}
  3676. */
  3677. toHEX: function() {
  3678. return ColorUtils.toString(this._color, "hex");
  3679. },
  3680. /**
  3681. * @method toHSL()
  3682. * @for kity.Color
  3683. *
  3684. * @description 返回当前颜色的 HSL 表示,如果颜色有透明度,将抛弃透明度属性(想要保留请使用 toHSLA())方法。
  3685. *
  3686. * @grammar toHSL() => {string}
  3687. */
  3688. toHSL: function() {
  3689. return ColorUtils.toString(this._color, "hsl");
  3690. },
  3691. /**
  3692. * @method toHSLA()
  3693. * @for kity.Color
  3694. *
  3695. * @description 返回当前颜色的 HSLA 表示
  3696. *
  3697. * @grammar toHSLA() => {string}
  3698. */
  3699. toHSLA: function() {
  3700. return ColorUtils.toString(this._color, "hsla");
  3701. },
  3702. /**
  3703. * @method toString()
  3704. * @for kity.Color
  3705. *
  3706. * @description 返回当前颜色的 RGB 或 RGBA 表示,如果颜色有透明度,将使用 RGBA 形式,否则是 RGB 形式
  3707. * @grammar toString() => {string}
  3708. */
  3709. toString: function() {
  3710. if (this._color.a === 1) {
  3711. return this.toRGB();
  3712. }
  3713. return this.toRGBA();
  3714. }
  3715. });
  3716. //Color 静态方法
  3717. Utils.extend(Color, {
  3718. //各分量可表示的最大值
  3719. _MAX_VALUE: {
  3720. r: 255,
  3721. g: 255,
  3722. b: 255,
  3723. h: 360,
  3724. s: 100,
  3725. l: 100,
  3726. a: 1
  3727. },
  3728. //各分量最小值
  3729. _MIN_VALUE: {
  3730. r: 0,
  3731. g: 0,
  3732. b: 0,
  3733. h: 0,
  3734. s: 0,
  3735. l: 0,
  3736. a: 0
  3737. },
  3738. //分量常量
  3739. R: "r",
  3740. G: "g",
  3741. B: "b",
  3742. H: "h",
  3743. S: "s",
  3744. L: "l",
  3745. A: "a",
  3746. /**
  3747. * @method parse()
  3748. * @static
  3749. * @for kity.Color
  3750. *
  3751. * @description 解析一个颜色字符串为 kity.Color 对象
  3752. *
  3753. * @grammar kity.Color.parse(valStr)
  3754. *
  3755. * @param {string} valStr 一个代表颜色的字符串,可以是:
  3756. * 熟知颜色表:如 'red', 'yellow'
  3757. * HEX 表示:如 '#368', '#123456'
  3758. * RGB 表示:如 'RGB(200, 200, 0)', 'RGBA(200, 200, 200, .5)'
  3759. * HSL 表示:如 'HSL(100, 60%, 80%)', 'HSLA(100, 60%, 80%, .5)'
  3760. */
  3761. parse: function(valStr) {
  3762. var rgbValue;
  3763. if (Utils.isString(valStr)) {
  3764. rgbValue = ColorUtils.parseToValue(valStr);
  3765. }
  3766. if (Utils.isObject(valStr) && "r" in valStr) {
  3767. rgbValue = valStr;
  3768. }
  3769. //解析失败, 返回一个默认color实例
  3770. if (rgbValue === null) {
  3771. return new Color();
  3772. }
  3773. return new Color(rgbValue.r, rgbValue.g, rgbValue.b, rgbValue.a);
  3774. },
  3775. /**
  3776. * @method createHSL()
  3777. * @for kity.Color
  3778. * @static
  3779. *
  3780. * @description 创建一个 HSL 颜色
  3781. *
  3782. * @grammar kity.Color.createHSL(h, s, l) => {kity.Color}
  3783. *
  3784. * @param {number} h 色环(Hue)分量值,取值范围 [0, 359]
  3785. * @param {number} s 饱和度(Saturation)分量值,取值范围 [0, 100]
  3786. * @param {number} l 亮度(Lighteness)分量值,取值范围 [0, 100]
  3787. */
  3788. createHSL: function(h, s, l) {
  3789. return Color.createHSLA(h, s, l, 1);
  3790. },
  3791. /**
  3792. * @method createHSLA()
  3793. * @for kity.Color
  3794. * @static
  3795. *
  3796. * @description 创建一个 HSLA 颜色
  3797. *
  3798. * @grammar kity.Color.createHSLA(h, s, l, a) => {kity.Color}
  3799. *
  3800. * @param {number} h 色环(Hue)分量值,取值范围 [0, 359]
  3801. * @param {number} s 饱和度(Saturation)分量值,取值范围 [0, 100]
  3802. * @param {number} l 亮度(Lighteness)分量值,取值范围 [0, 100]
  3803. * @param {number} a 透明度(Alpha)分量值,取值范围 [0, 1]
  3804. */
  3805. createHSLA: function(h, s, l, a) {
  3806. var colorValue = null;
  3807. s += "%";
  3808. l += "%";
  3809. colorValue = [ "hsla(" + h, s, l, a + ")" ];
  3810. return Color.parse(colorValue.join(", "));
  3811. },
  3812. /**
  3813. * @method createRGB()
  3814. * @for kity.Color
  3815. * @static
  3816. *
  3817. * @description 创建一个 RGB 颜色
  3818. *
  3819. * @grammar kity.Color.createRGB(r, g, b) => {kity.Color}
  3820. *
  3821. * @param {number} r 红色(Red)分量值,取值范围 [0, 255]
  3822. * @param {number} g 绿色(Green)分量值,取值范围 [0, 255]
  3823. * @param {number} b 蓝色(Blue)分量值,取值范围 [0, 255]
  3824. */
  3825. createRGB: function(r, g, b) {
  3826. return Color.createRGBA(r, g, b, 1);
  3827. },
  3828. /**
  3829. * @method createRGBA()
  3830. * @for kity.Color
  3831. * @static
  3832. *
  3833. * @description 创建一个 RGBA 颜色
  3834. *
  3835. * @grammar kity.Color.createRGBA(r, g, b, a) => {kity.Color}
  3836. *
  3837. * @param {number} r 红色(Red)分量值,取值范围 [0, 255]
  3838. * @param {number} g 绿色(Green)分量值,取值范围 [0, 255]
  3839. * @param {number} b 蓝色(Blue)分量值,取值范围 [0, 255]
  3840. * @param {number} a 透明度(Alpha)分量值,取值范围 [0, 1]
  3841. */
  3842. createRGBA: function(r, g, b, a) {
  3843. return new Color(r, g, b, a);
  3844. }
  3845. });
  3846. //内部工具对象
  3847. Utils.extend(ColorUtils, {
  3848. parseToValue: function(valStr) {
  3849. var rgbaValue = {};
  3850. /* 优先检测在调色板中是否有对应的颜色 */
  3851. valStr = StandardColor.EXTEND_STANDARD[valStr] || StandardColor.COLOR_STANDARD[valStr] || valStr;
  3852. /* 颜色转换 */
  3853. //hex格式
  3854. if (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(valStr)) {
  3855. rgbaValue = ColorUtils.hexToValue(valStr);
  3856. } else if (/^(rgba?)/i.test(valStr)) {
  3857. rgbaValue = ColorUtils.rgbaToValue(valStr);
  3858. } else if (/^(hsla?)/i.test(valStr)) {
  3859. rgbaValue = ColorUtils.hslaToValue(valStr);
  3860. } else {
  3861. return null;
  3862. }
  3863. return ColorUtils.overflowFormat(rgbaValue);
  3864. },
  3865. hexToValue: function(hexStr) {
  3866. var result = {}, keys = [ "r", "g", "b" ];
  3867. if (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(hexStr)) {
  3868. hexStr = RegExp.$1.split("");
  3869. Utils.each(keys, function(key, index) {
  3870. if (hexStr.length === 3) {
  3871. result[key] = ColorUtils.toNumber(hexStr[index] + hexStr[index]);
  3872. } else {
  3873. result[key] = ColorUtils.toNumber(hexStr[index * 2] + hexStr[index * 2 + 1]);
  3874. }
  3875. });
  3876. //转换出hsl值
  3877. result = Utils.extend(result, ColorUtils.rgbValueToHslValue(result));
  3878. result.a = 1;
  3879. return result;
  3880. }
  3881. return null;
  3882. },
  3883. rgbaToValue: function(rgbaStr) {
  3884. var result = {}, hasAlpha = false, keys = [ "r", "g", "b" ];
  3885. if (/^(rgba?)/i.test(rgbaStr)) {
  3886. hasAlpha = RegExp.$1.length === 4;
  3887. rgbaStr = rgbaStr.replace(/^rgba?/i, "").replace(/\s+/g, "").replace(/[^0-9,.]/g, "").split(",");
  3888. Utils.each(keys, function(key, index) {
  3889. result[key] = rgbaStr[index] | 0;
  3890. });
  3891. //转换出hsl值
  3892. result = Utils.extend(result, ColorUtils.rgbValueToHslValue(result));
  3893. result.a = hasAlpha ? parseFloat(rgbaStr[3]) : 1;
  3894. return result;
  3895. }
  3896. return null;
  3897. },
  3898. hslaToValue: function(hslaStr) {
  3899. var result = {}, hasAlpha = false;
  3900. if (/^(hsla?)/i.test(hslaStr)) {
  3901. hasAlpha = RegExp.$1.length === 4;
  3902. hslaStr = hslaStr.replace(/^hsla?/i, "").replace(/\s+/g, "").replace(/[^0-9,.]/g, "").split(",");
  3903. //记录hsl值
  3904. result.h = hslaStr[0] | 0;
  3905. result.s = hslaStr[1] | 0;
  3906. result.l = hslaStr[2] | 0;
  3907. //转换出rgb值
  3908. result = Utils.extend(result, ColorUtils.hslValueToRGBValue(result));
  3909. //hsl值转换为rgb值
  3910. result = ColorUtils.hslValueToRGBValue(result);
  3911. result.a = hasAlpha ? parseFloat(hslaStr[3]) : 1;
  3912. return result;
  3913. }
  3914. return null;
  3915. },
  3916. //hsl值对象转换为rgb值对象
  3917. hslValueToRGBValue: function(hslValue) {
  3918. function trans(v1, v2, vH) {
  3919. if (vH < 0) {
  3920. vH += 1;
  3921. } else if (vH > 1) {
  3922. vH -= 1;
  3923. }
  3924. if (6 * vH < 1) {
  3925. return v1 + (v2 - v1) * 6 * vH;
  3926. } else if (2 * vH < 1) {
  3927. return v2;
  3928. } else if (3 * vH < 2) {
  3929. return v1 + (v2 - v1) * ((2 / 3 - vH) * 6);
  3930. }
  3931. return v1;
  3932. }
  3933. var q = null, p = null, result = {};
  3934. hslValue = Utils.extend({}, hslValue);
  3935. hslValue.h = hslValue.h / 360;
  3936. hslValue.s = hslValue.s / 100;
  3937. hslValue.l = hslValue.l / 100;
  3938. //分量计算
  3939. if (hslValue.s === 0) {
  3940. result.r = result.g = result.b = hslValue.l;
  3941. } else {
  3942. if (hslValue.l < .5) {
  3943. q = hslValue.l * (1 + hslValue.s);
  3944. } else {
  3945. q = hslValue.l + hslValue.s - hslValue.l * hslValue.s;
  3946. }
  3947. p = 2 * hslValue.l - q;
  3948. result.r = trans(p, q, hslValue.h + 1 / 3);
  3949. result.g = trans(p, q, hslValue.h);
  3950. result.b = trans(p, q, hslValue.h - 1 / 3);
  3951. }
  3952. result.r = Math.min(Math.round(result.r * 255), 255);
  3953. result.g = Math.min(Math.round(result.g * 255), 255);
  3954. result.b = Math.min(Math.round(result.b * 255), 255);
  3955. return result;
  3956. },
  3957. //rgb值对象转换为hsl值对象
  3958. rgbValueToHslValue: function(rgbValue) {
  3959. var max = null, min = null, result = {};
  3960. rgbValue = Utils.extend({}, rgbValue);
  3961. rgbValue.r = rgbValue.r / 255;
  3962. rgbValue.g = rgbValue.g / 255;
  3963. rgbValue.b = rgbValue.b / 255;
  3964. max = Math.max(rgbValue.r, rgbValue.g, rgbValue.b);
  3965. min = Math.min(rgbValue.r, rgbValue.g, rgbValue.b);
  3966. //h分量计算
  3967. if (max === min) {
  3968. result.h = 0;
  3969. } else if (max === rgbValue.r) {
  3970. if (rgbValue.g >= rgbValue.b) {
  3971. result.h = 60 * (rgbValue.g - rgbValue.b) / (max - min);
  3972. } else {
  3973. result.h = 60 * (rgbValue.g - rgbValue.b) / (max - min) + 360;
  3974. }
  3975. } else if (max === rgbValue.g) {
  3976. result.h = 60 * (rgbValue.b - rgbValue.r) / (max - min) + 120;
  3977. } else if (max === rgbValue.b) {
  3978. result.h = 60 * (rgbValue.r - rgbValue.g) / (max - min) + 240;
  3979. }
  3980. //l分量计算
  3981. result.l = (max + min) / 2;
  3982. //s分量计算
  3983. if (result.l === 0 || max === min) {
  3984. result.s = 0;
  3985. } else if (result.l > 0 && result.l <= .5) {
  3986. result.s = (max - min) / (max + min);
  3987. } else {
  3988. result.s = (max - min) / (2 - max - min);
  3989. }
  3990. //格式化hsl结果
  3991. result.h = Math.round(result.h);
  3992. result.s = Math.round(result.s * 100);
  3993. result.l = Math.round(result.l * 100);
  3994. return result;
  3995. },
  3996. toString: function(colorValue, type) {
  3997. var vals = [];
  3998. colorValue = Utils.extend({}, colorValue);
  3999. if (type.indexOf("hsl") !== -1) {
  4000. colorValue.s += "%";
  4001. colorValue.l += "%";
  4002. }
  4003. if (type !== "hex") {
  4004. Utils.each(type.split(""), function(key) {
  4005. vals.push(colorValue[key]);
  4006. });
  4007. return (type + "(" + vals.join(", ") + ")").toLowerCase();
  4008. } else {
  4009. vals.push(ColorUtils.toHexValue(+colorValue.r));
  4010. vals.push(ColorUtils.toHexValue(+colorValue.g));
  4011. vals.push(ColorUtils.toHexValue(+colorValue.b));
  4012. return ("#" + vals.join("")).toLowerCase();
  4013. }
  4014. },
  4015. //16进制的2个数字转化为10进制, 如果转化失败, 返回0
  4016. toNumber: function(value) {
  4017. return Number("0x" + value) | 0;
  4018. },
  4019. toHexValue: function(value) {
  4020. var result = value.toString(16);
  4021. return result.length === 1 ? "0" + result : result;
  4022. },
  4023. //溢出控制
  4024. overflowFormat: function(value) {
  4025. var tmpValue = Utils.extend({}, value), keys = "rgba";
  4026. Utils.each(keys.split(""), function(key) {
  4027. if (!tmpValue.hasOwnProperty(key)) {
  4028. return;
  4029. }
  4030. //上溢出
  4031. tmpValue[key] = Math.min(Color._MAX_VALUE[key], tmpValue[key]);
  4032. //下溢出
  4033. tmpValue[key] = Math.max(Color._MIN_VALUE[key], tmpValue[key]);
  4034. });
  4035. return tmpValue;
  4036. }
  4037. });
  4038. return Color;
  4039. }
  4040. };
  4041. //src/graphic/container.js
  4042. _p[30] = {
  4043. value: function(require, exports, module) {
  4044. function itemRemove() {
  4045. this.container.removeItem(this);
  4046. return this;
  4047. }
  4048. return _p.r(11).createClass("Container", {
  4049. getItems: function() {
  4050. return this.items || (this.items = []);
  4051. },
  4052. getItem: function(index) {
  4053. return this.getItems()[index];
  4054. },
  4055. getFirstItem: function() {
  4056. return this.getItem(0);
  4057. },
  4058. getLastItem: function() {
  4059. return this.getItem(this.getItems().length - 1);
  4060. },
  4061. indexOf: function(item) {
  4062. return this.getItems().indexOf(item);
  4063. },
  4064. eachItem: function(fn) {
  4065. var items = this.getItems(), length = items.length, i;
  4066. for (i = 0; i < length; i++) {
  4067. fn.call(this, i, items[i]);
  4068. }
  4069. return this;
  4070. },
  4071. addItem: function(item, pos, noEvent) {
  4072. var items = this.getItems(), length = items.length;
  4073. if (~items.indexOf(item)) {
  4074. return this;
  4075. }
  4076. if (!(pos >= 0 && pos < length)) {
  4077. pos = length;
  4078. }
  4079. items.splice(pos, 0, item);
  4080. if (typeof item === "object") {
  4081. item.container = this;
  4082. item.remove = itemRemove;
  4083. }
  4084. this.handleAdd(item, pos);
  4085. if (!noEvent) {
  4086. this.onContainerChanged("add", [ item ]);
  4087. }
  4088. return this;
  4089. },
  4090. addItems: function(items) {
  4091. for (var i = 0, l = items.length; i < l; i++) {
  4092. this.addItem(items[i], -1, true);
  4093. }
  4094. this.onContainerChanged("add", items);
  4095. return this;
  4096. },
  4097. setItems: function(items) {
  4098. return this.clear().addItems(items);
  4099. },
  4100. appendItem: function(item) {
  4101. return this.addItem(item);
  4102. },
  4103. prependItem: function(item) {
  4104. return this.addItem(item, 0);
  4105. },
  4106. removeItem: function(pos, noEvent) {
  4107. if (typeof pos !== "number") {
  4108. return this.removeItem(this.indexOf(pos));
  4109. }
  4110. var items = this.getItems(), length = items.length, item = items[pos];
  4111. if (item === undefined) {
  4112. return this;
  4113. }
  4114. items.splice(pos, 1);
  4115. if (item.container) {
  4116. delete item.container;
  4117. }
  4118. if (item.remove) {
  4119. delete item.remove;
  4120. }
  4121. this.handleRemove(item, pos);
  4122. if (!noEvent) {
  4123. this.onContainerChanged("remove", [ item ]);
  4124. }
  4125. return this;
  4126. },
  4127. clear: function() {
  4128. var removed = [];
  4129. var item;
  4130. while (item = this.getFirstItem()) {
  4131. removed.push(item);
  4132. this.removeItem(0, true);
  4133. }
  4134. this.onContainerChanged("remove", removed);
  4135. return this;
  4136. },
  4137. onContainerChanged: function(type, items) {},
  4138. handleAdd: function(item, index) {},
  4139. handleRemove: function(item, index) {}
  4140. });
  4141. }
  4142. };
  4143. //src/graphic/curve.js
  4144. /*
  4145. * 曲线
  4146. * */
  4147. _p[31] = {
  4148. value: function(require, exports, module) {
  4149. var Utils = _p.r(12), CurveUtil = {
  4150. /*
  4151. * 获取由两个以上的点组成的曲线的平移线
  4152. * @param points 曲线上的点的集合, 集合中的点的数量必须大于2
  4153. * @return 平移线数组
  4154. */
  4155. getCurvePanLines: function(points, smoothFactor) {
  4156. //计算原始点的中点坐标
  4157. var centerPoints = CurveUtil.getCenterPoints(points), //注意:计算中点连线的中点坐标, 得出平移线
  4158. panLines = CurveUtil.getPanLine(points.length, centerPoints);
  4159. //平移线移动到顶点
  4160. return CurveUtil.getMovedPanLines(points, panLines, smoothFactor);
  4161. },
  4162. /*
  4163. * 计算给定点集合的连线的中点
  4164. * @param points
  4165. */
  4166. getCenterPoints: function(points) {
  4167. var centerPoints = {}, key = null;
  4168. for (var i = 0, j = 0, len = points.length; i < len; i++) {
  4169. //j是下一个点的索引
  4170. j = i === len - 1 ? 0 : i + 1;
  4171. key = i + "," + j;
  4172. //计算中点坐标
  4173. centerPoints[key] = {
  4174. x: (points[i].x + points[j].y) / 2,
  4175. y: (points[i].x + points[j].y) / 2
  4176. };
  4177. }
  4178. return centerPoints;
  4179. },
  4180. /*
  4181. * 对getCenterPoints()接口获取到的数据做处理, 计算出各个顶点对应的平移线数据
  4182. * @param length 集合中点的个数
  4183. * @param points 点集合, 该集合应该是getCenterPoints()接口返回的数据
  4184. */
  4185. getPanLine: function(length, points) {
  4186. var result = {}, //顶点索引
  4187. pointIndex = null;
  4188. for (var i = 0, j; i < length; i++) {
  4189. var point1 = null, point2 = null;
  4190. //计算当前点
  4191. j = (i + 1) % length;
  4192. //保存当前处理的顶点索引
  4193. pointIndex = j;
  4194. point1 = points[i + "," + j];
  4195. //计算下一个点
  4196. i = j;
  4197. j = (i + 1) % length;
  4198. point2 = points[i + "," + j];
  4199. result[pointIndex] = {
  4200. points: [ {
  4201. x: point1.x,
  4202. y: point1.y
  4203. }, {
  4204. x: point2.x,
  4205. y: point2.y
  4206. } ],
  4207. center: {
  4208. x: (point1.x + point2.x) / 2,
  4209. y: (point1.y + point2.y) / 2
  4210. }
  4211. };
  4212. //还原i值
  4213. i = (pointIndex + length - 1) % length;
  4214. }
  4215. return result;
  4216. },
  4217. /*
  4218. * 计算平移线移动到顶点后的位置
  4219. * @param points 顶点集合
  4220. * @param panLines 平移线集合
  4221. */
  4222. getMovedPanLines: function(points, panLines, smoothFactor) {
  4223. var result = {};
  4224. Utils.each(points, function(point, index) {
  4225. //当前平移线
  4226. var currentPanLine = panLines[index], //平移线中点
  4227. center = currentPanLine.center, //移动距离
  4228. distance = {
  4229. x: center.x - point.x,
  4230. y: center.y - point.y
  4231. };
  4232. var currentResult = result[index] = {
  4233. points: [],
  4234. center: {
  4235. x: point.x,
  4236. y: point.y
  4237. }
  4238. };
  4239. //计算控制点到顶点的距离, 并且应用平滑系数到距离上
  4240. Utils.each(currentPanLine.points, function(controlPoint, index) {
  4241. var moved = {
  4242. x: controlPoint.x - distance.x,
  4243. y: controlPoint.y - distance.y
  4244. };
  4245. var vertex = currentResult.center;
  4246. var dx = moved.x - vertex.x;
  4247. var dy = moved.y - vertex.y;
  4248. moved.x = vertex.x + smoothFactor * dx;
  4249. moved.y = vertex.y + smoothFactor * dy;
  4250. currentResult.points.push(moved);
  4251. });
  4252. });
  4253. return result;
  4254. }
  4255. };
  4256. return _p.r(11).createClass("Curve", {
  4257. base: _p.r(47),
  4258. mixins: [ _p.r(52) ],
  4259. constructor: function(points, isColse) {
  4260. this.callBase();
  4261. this.setPoints(points || []);
  4262. this.closeState = !!isColse;
  4263. this.changeable = true;
  4264. this.smoothFactor = 1;
  4265. this.update();
  4266. },
  4267. //当点集合发生变化时采取的动作
  4268. onContainerChanged: function() {
  4269. if (this.changeable) {
  4270. this.update();
  4271. }
  4272. },
  4273. setSmoothFactor: function(factor) {
  4274. this.smoothFactor = factor < 0 ? 0 : factor;
  4275. this.update();
  4276. return this;
  4277. },
  4278. getSmoothFactor: function() {
  4279. return this.smoothFactor;
  4280. },
  4281. update: function() {
  4282. var points = this.getPoints(), withControlPoints = null, drawer = this.getDrawer(), curPoint = null, curControlPoint = null, prevControlPoint = null;
  4283. drawer.clear();
  4284. if (points.length === 0) {
  4285. return this;
  4286. } else {
  4287. drawer.moveTo(points[0]);
  4288. }
  4289. if (points.length === 1) {
  4290. return this;
  4291. }
  4292. if (points.length === 2) {
  4293. drawer.lineTo(points[1]);
  4294. return this;
  4295. }
  4296. //获取已转换过后的带控制点的所有点
  4297. withControlPoints = CurveUtil.getCurvePanLines(points, this.getSmoothFactor());
  4298. for (var i = 1, len = points.length; i < len; i++) {
  4299. //当前顶点
  4300. curPoint = withControlPoints[i].center;
  4301. //当前控制点
  4302. if (this.closeState || i != len - 1) {
  4303. curControlPoint = withControlPoints[i].points[0];
  4304. } else {
  4305. //非闭合状态下最后一个点的处理
  4306. curControlPoint = withControlPoints[i].center;
  4307. }
  4308. if (this.closeState || i != 1) {
  4309. prevControlPoint = withControlPoints[i - 1].points[1];
  4310. } else {
  4311. //非闭合状态下第一个点的处理
  4312. prevControlPoint = withControlPoints[i - 1].center;
  4313. }
  4314. drawer.bezierTo(prevControlPoint.x, prevControlPoint.y, curControlPoint.x, curControlPoint.y, curPoint.x, curPoint.y);
  4315. }
  4316. //处理闭合
  4317. if (this.closeState) {
  4318. curPoint = withControlPoints[0].center;
  4319. curControlPoint = withControlPoints[0].points[0];
  4320. prevControlPoint = withControlPoints[points.length - 1].points[1];
  4321. drawer.bezierTo(prevControlPoint.x, prevControlPoint.y, curControlPoint.x, curControlPoint.y, curPoint.x, curPoint.y);
  4322. }
  4323. return this;
  4324. },
  4325. close: function() {
  4326. this.closeState = true;
  4327. return this.update();
  4328. },
  4329. open: function() {
  4330. this.closeState = false;
  4331. return this.update();
  4332. },
  4333. isClose: function() {
  4334. return !!this.closeState;
  4335. }
  4336. });
  4337. }
  4338. };
  4339. //src/graphic/data.js
  4340. _p[32] = {
  4341. value: function(require, exports, module) {
  4342. return _p.r(11).createClass("Data", {
  4343. constructor: function() {
  4344. this._data = {};
  4345. },
  4346. setData: function(name, value) {
  4347. this._data[name] = value;
  4348. return this;
  4349. },
  4350. getData: function(name) {
  4351. return this._data[name];
  4352. },
  4353. removeData: function(name) {
  4354. delete this._data[name];
  4355. return this;
  4356. }
  4357. });
  4358. }
  4359. };
  4360. //src/graphic/ellipse.js
  4361. _p[33] = {
  4362. value: function(require, exports, module) {
  4363. var Utils = _p.r(12), Point = _p.r(51);
  4364. return _p.r(11).createClass("Ellipse", {
  4365. base: _p.r(47),
  4366. constructor: function(rx, ry, cx, cy) {
  4367. this.callBase();
  4368. this.rx = rx || 0;
  4369. this.ry = ry || 0;
  4370. this.cx = cx || 0;
  4371. this.cy = cy || 0;
  4372. this.update();
  4373. },
  4374. update: function() {
  4375. var rx = this.rx, ry = this.ry, x1 = this.cx + rx, x2 = this.cx - rx, y = this.cy;
  4376. var drawer = this.getDrawer();
  4377. drawer.clear();
  4378. drawer.moveTo(x1, y);
  4379. drawer.arcTo(rx, ry, 0, 1, 1, x2, y);
  4380. drawer.arcTo(rx, ry, 0, 1, 1, x1, y);
  4381. return this;
  4382. },
  4383. getRadius: function() {
  4384. return {
  4385. x: this.rx,
  4386. y: this.ry
  4387. };
  4388. },
  4389. getRadiusX: function() {
  4390. return this.rx;
  4391. },
  4392. getRadiusY: function() {
  4393. return this.ry;
  4394. },
  4395. getCenter: function() {
  4396. return new Point(this.cx, this.cy);
  4397. },
  4398. getCenterX: function() {
  4399. return this.cx;
  4400. },
  4401. getCenterY: function() {
  4402. return this.cy;
  4403. },
  4404. setRadius: function(rx, ry) {
  4405. this.rx = rx;
  4406. this.ry = ry;
  4407. return this.update();
  4408. },
  4409. setRadiusX: function(rx) {
  4410. this.rx = rx;
  4411. return this.update();
  4412. },
  4413. setRadiusY: function(ry) {
  4414. this.ry = ry;
  4415. return this.update();
  4416. },
  4417. setCenter: function(cx, cy) {
  4418. if (arguments.length == 1) {
  4419. var p = Point.parse(arguments[0]);
  4420. cx = p.x;
  4421. cy = p.y;
  4422. }
  4423. this.cx = cx;
  4424. this.cy = cy;
  4425. return this.update();
  4426. },
  4427. setCenterX: function(cx) {
  4428. this.cx = cx;
  4429. return this.update();
  4430. },
  4431. setCenterY: function(cy) {
  4432. this.cy = cy;
  4433. return this.update();
  4434. }
  4435. });
  4436. }
  4437. };
  4438. //src/graphic/eventhandler.js
  4439. /*
  4440. * kity event 实现
  4441. */
  4442. _p[34] = {
  4443. value: function(require, exports, module) {
  4444. // polyfill
  4445. (function() {
  4446. function CustomEvent(event, params) {
  4447. params = params || {
  4448. bubbles: false,
  4449. cancelable: false,
  4450. detail: undefined
  4451. };
  4452. var evt = document.createEvent("CustomEvent");
  4453. evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
  4454. return evt;
  4455. }
  4456. CustomEvent.prototype = window.Event.prototype;
  4457. window.CustomEvent = CustomEvent;
  4458. })();
  4459. var Utils = _p.r(12), ShapeEvent = _p.r(63);
  4460. // 内部处理器缓存
  4461. var INNER_HANDLER_CACHE = {}, // 用户处理器缓存
  4462. USER_HANDLER_CACHE = {}, guid = 0;
  4463. // 添加事件统一入口
  4464. function _addEvent(type, handler, isOnce) {
  4465. isOnce = !!isOnce;
  4466. if (Utils.isString(type)) {
  4467. type = type.match(/\S+/g);
  4468. }
  4469. Utils.each(type, function(currentType) {
  4470. listen.call(this, this.node, currentType, handler, isOnce);
  4471. }, this);
  4472. return this;
  4473. }
  4474. // 移除事件统一入口
  4475. function _removeEvent(type, handler) {
  4476. var userHandlerList = null, eventId = this._EVNET_UID, isRemoveAll = handler === undefined;
  4477. userHandlerList = USER_HANDLER_CACHE[eventId][type];
  4478. //移除指定的监听器
  4479. if (!isRemoveAll) {
  4480. isRemoveAll = true;
  4481. Utils.each(userHandlerList, function removeKityEvent(fn, index) {
  4482. if (fn === handler) {
  4483. // 不能结束, 需要查找完整个list, 避免丢失移除多次绑定同一个处理器的情况
  4484. delete userHandlerList[index];
  4485. } else {
  4486. isRemoveAll = false;
  4487. }
  4488. });
  4489. }
  4490. //删除所有监听器
  4491. if (isRemoveAll) {
  4492. deleteDomEvent(this.node, type, INNER_HANDLER_CACHE[eventId][type]);
  4493. delete USER_HANDLER_CACHE[eventId][type];
  4494. delete INNER_HANDLER_CACHE[eventId][type];
  4495. }
  4496. return this;
  4497. }
  4498. // 执行绑定, 该方法context为shape或者mixin了eventhandler的对象
  4499. function listen(node, type, handler, isOnce) {
  4500. var eid = this._EVNET_UID, targetObject = this;
  4501. // 初始化内部监听器
  4502. if (!INNER_HANDLER_CACHE[eid]) {
  4503. INNER_HANDLER_CACHE[eid] = {};
  4504. }
  4505. if (!INNER_HANDLER_CACHE[eid][type]) {
  4506. // 内部监听器
  4507. INNER_HANDLER_CACHE[eid][type] = function kityEventHandler(e) {
  4508. e = new ShapeEvent(e || window.event);
  4509. Utils.each(USER_HANDLER_CACHE[eid][type], function executeKityEvent(fn) {
  4510. var result;
  4511. if (fn) {
  4512. result = fn.call(targetObject, e);
  4513. //once 绑定, 执行完后删除
  4514. if (isOnce) {
  4515. targetObject.off(type, fn);
  4516. }
  4517. }
  4518. // 如果用户handler里return了false, 则该节点上的此后的同类型事件将不再执行
  4519. return result;
  4520. }, targetObject);
  4521. };
  4522. }
  4523. // 初始化用户监听器列表
  4524. if (!USER_HANDLER_CACHE[eid]) {
  4525. USER_HANDLER_CACHE[eid] = {};
  4526. }
  4527. if (!USER_HANDLER_CACHE[eid][type]) {
  4528. USER_HANDLER_CACHE[eid][type] = [ handler ];
  4529. // 绑定对应类型的事件
  4530. // dom对象利用dom event进行处理, 非dom对象, 由消息分发机制处理
  4531. if (!!node && "on" + type in node) {
  4532. bindDomEvent(node, type, INNER_HANDLER_CACHE[eid][type]);
  4533. }
  4534. } else {
  4535. USER_HANDLER_CACHE[eid][type].push(handler);
  4536. }
  4537. }
  4538. // 绑定dom事件
  4539. function bindDomEvent(node, type, handler) {
  4540. if (node.addEventListener) {
  4541. node.addEventListener(type, handler, false);
  4542. } else {
  4543. node.attachEvent("on" + type, handler);
  4544. }
  4545. }
  4546. // 删除dom事件
  4547. function deleteDomEvent(node, type, handler) {
  4548. if (node.removeEventListener) {
  4549. node.removeEventListener(type, handler, false);
  4550. } else {
  4551. node.detachEvent(type, handler);
  4552. }
  4553. }
  4554. // 触发dom事件
  4555. function triggerDomEvent(node, type, params) {
  4556. var event = new CustomEvent(type, {
  4557. bubbles: true,
  4558. cancelable: true
  4559. });
  4560. event._kityParam = params;
  4561. node.dispatchEvent(event);
  4562. }
  4563. // 发送消息
  4564. function sendMessage(messageObj, type, msg) {
  4565. var event = null, handler = null;
  4566. var handlers = INNER_HANDLER_CACHE[messageObj._EVNET_UID];
  4567. if (!handlers) return;
  4568. handler = handlers[type];
  4569. if (!handler) {
  4570. return;
  4571. }
  4572. event = Utils.extend({
  4573. type: type,
  4574. target: messageObj
  4575. }, msg || {});
  4576. handler.call(messageObj, event);
  4577. }
  4578. // 对外接口
  4579. return _p.r(11).createClass("EventHandler", {
  4580. constructor: function() {
  4581. this._EVNET_UID = ++guid;
  4582. },
  4583. addEventListener: function(type, handler) {
  4584. return _addEvent.call(this, type, handler, false);
  4585. },
  4586. addOnceEventListener: function(type, handler) {
  4587. return _addEvent.call(this, type, handler, true);
  4588. },
  4589. removeEventListener: function(type, handler) {
  4590. return _removeEvent.call(this, type, handler);
  4591. },
  4592. on: function(type, handler) {
  4593. return this.addEventListener.apply(this, arguments);
  4594. },
  4595. once: function(type, handler) {
  4596. return this.addOnceEventListener.apply(this, arguments);
  4597. },
  4598. off: function() {
  4599. return this.removeEventListener.apply(this, arguments);
  4600. },
  4601. fire: function(type, params) {
  4602. return this.trigger.apply(this, arguments);
  4603. },
  4604. trigger: function(type, params) {
  4605. sendMessage(this, type, params);
  4606. return this;
  4607. }
  4608. });
  4609. }
  4610. };
  4611. //src/graphic/geometry.js
  4612. _p[35] = {
  4613. value: function(require) {
  4614. var utils = _p.r(12);
  4615. var Point = _p.r(51);
  4616. var Vector = _p.r(74);
  4617. var Matrix = _p.r(44);
  4618. var g = {};
  4619. var pathCommand = /([achlmrqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\s]*,?\s*)+)/gi, pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)\s*,?\s*/gi, paramCounts = {
  4620. a: 7,
  4621. c: 6,
  4622. h: 1,
  4623. l: 2,
  4624. m: 2,
  4625. q: 4,
  4626. s: 4,
  4627. t: 2,
  4628. v: 1,
  4629. z: 0
  4630. };
  4631. function pathClone(path) {
  4632. var result, i, j, segment, segmentCopy;
  4633. result = [];
  4634. for (i = 0; i < path.length; i++) {
  4635. segment = path[i];
  4636. result.push(segmentCopy = []);
  4637. for (j = 0; j < segment.length; j++) {
  4638. segmentCopy.push(segment[j]);
  4639. }
  4640. }
  4641. if (path.isUniform) result.isUniform = true;
  4642. if (path.isAbsolute) result.isAbsolute = true;
  4643. if (path.isCurve) result.isCurve = true;
  4644. return result;
  4645. }
  4646. // 缓存函数
  4647. // from raphael.js
  4648. function cacher(f, scope, postprocessor) {
  4649. function repush(array, item) {
  4650. for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
  4651. return array.push(array.splice(i, 1)[0]);
  4652. }
  4653. }
  4654. function newf() {
  4655. var arg = Array.prototype.slice.call(arguments, 0), args = arg.join("␀"), cache = newf.cache = newf.cache || {}, count = newf.count = newf.count || [];
  4656. if (cache.hasOwnProperty(args)) {
  4657. repush(count, args);
  4658. return postprocessor ? postprocessor(cache[args]) : cache[args];
  4659. }
  4660. if (count.length >= 1e3) {
  4661. delete cache[count.shift()];
  4662. }
  4663. count.push(args);
  4664. cache[args] = f.apply(scope, arg);
  4665. return postprocessor ? postprocessor(cache[args]) : cache[args];
  4666. }
  4667. return newf;
  4668. }
  4669. /**
  4670. *
  4671. * kity.g.pathToString(pathSegment)
  4672. *
  4673. * 返回表示 PathSegment 的字符串
  4674. *
  4675. * @param {Array} pathSegment
  4676. * 要表示的 Path Segment
  4677. *
  4678. * @return {String} 表示该 Path 的字符串
  4679. *
  4680. * @example
  4681. *
  4682. * var pathSegment = [['M', 0, 0], ['L', 10, 10]]
  4683. * var pathString = kity.g.pathToString(pathSegment);
  4684. * // 返回 'M0,0L10,10'
  4685. */
  4686. g.pathToString = function(pathSegment) {
  4687. pathSegment = pathSegment || this;
  4688. if (typeof pathSegment == "string") return pathSegment;
  4689. if (pathSegment instanceof Array) {
  4690. pathSegment = utils.flatten(pathSegment);
  4691. return pathSegment.join(",").replace(/,?([achlmqrstvxz]),?/gi, "$1");
  4692. }
  4693. };
  4694. /**
  4695. * kity.g.parsePathString(pathString)
  4696. *
  4697. * 解析 Path 字符串成 PathSegment
  4698. *
  4699. * @copyright rapheal.js
  4700. *
  4701. * @example
  4702. *
  4703. * var seg = kity.g.parsePathString('M10,12l21-23-21.5,11z');
  4704. * // 返回: [['M', 10, 12], ['l', 21, -23], ['l', -21.5, 11], ['z']]
  4705. *
  4706. * @param {String} pathString Path 字符串
  4707. * @return {Array}
  4708. */
  4709. g.parsePathString = cacher(function(pathString) {
  4710. var data = [];
  4711. pathString.replace(pathCommand, function(a, b, c) {
  4712. var params = [], name = b.toLowerCase();
  4713. c.replace(pathValues, function(a, b) {
  4714. if (b) params.push(+b);
  4715. });
  4716. if (name == "m" && params.length > 2) {
  4717. data.push([ b ].concat(params.splice(0, 2)));
  4718. name = "l";
  4719. b = b == "m" ? "l" : "L";
  4720. }
  4721. if (name == "r") {
  4722. data.push([ b ].concat(params));
  4723. } else {
  4724. while (params.length >= paramCounts[name]) {
  4725. data.push([ b ].concat(params.splice(0, paramCounts[name])));
  4726. if (!paramCounts[name]) {
  4727. break;
  4728. }
  4729. }
  4730. }
  4731. });
  4732. data.isUniform = true;
  4733. data.toString = g.pathToString;
  4734. return data;
  4735. });
  4736. /**
  4737. * kity.g.pathToAbsolute(path)
  4738. *
  4739. * 把路径转换为绝对路径的形式
  4740. *
  4741. * @param {Array|String} path
  4742. * 要转换的 path 路径或者数组
  4743. *
  4744. * @return {Array}
  4745. * 转换后的 Path Segment
  4746. *
  4747. * @example
  4748. *
  4749. * var path = 'M10,10l50,50';
  4750. * var absPath = kity.g.pathToAbsolute(path);
  4751. * // 返回 [['M', 10, 10], ['L', 60, 60]]
  4752. */
  4753. g.pathToAbsolute = cacher(function(path) {
  4754. var pathArray = path.isUniform ? path : g.parsePathString(g.pathToString(path));
  4755. var res = [], x = 0, y = 0, mx = 0, my = 0, start = 0;
  4756. var r, pa, i, j, k, ii, jj, kk;
  4757. if (pathArray[0][0] == "M") {
  4758. x = +pathArray[0][1];
  4759. y = +pathArray[0][2];
  4760. mx = x;
  4761. my = y;
  4762. start++;
  4763. res[0] = [ "M", x, y ];
  4764. }
  4765. for (r, pa, i = start, ii = pathArray.length; i < ii; i++) {
  4766. res.push(r = []);
  4767. pa = pathArray[i];
  4768. if (pa[0] != pa[0].toUpperCase()) {
  4769. r[0] = pa[0].toUpperCase();
  4770. switch (r[0]) {
  4771. case "A":
  4772. r[1] = pa[1];
  4773. r[2] = pa[2];
  4774. r[3] = pa[3];
  4775. r[4] = pa[4];
  4776. r[5] = pa[5];
  4777. r[6] = +(pa[6] + x);
  4778. r[7] = +(pa[7] + y);
  4779. break;
  4780. case "V":
  4781. r[1] = +pa[1] + y;
  4782. break;
  4783. case "H":
  4784. r[1] = +pa[1] + x;
  4785. break;
  4786. case "M":
  4787. mx = +pa[1] + x;
  4788. my = +pa[2] + y;
  4789. break;
  4790. default:
  4791. for (j = 1, jj = pa.length; j < jj; j++) {
  4792. r[j] = +pa[j] + (j % 2 ? x : y);
  4793. }
  4794. }
  4795. } else {
  4796. for (k = 0, kk = pa.length; k < kk; k++) {
  4797. r[k] = pa[k];
  4798. }
  4799. }
  4800. switch (r[0]) {
  4801. case "Z":
  4802. x = mx;
  4803. y = my;
  4804. break;
  4805. case "H":
  4806. x = r[1];
  4807. break;
  4808. case "V":
  4809. y = r[1];
  4810. break;
  4811. case "M":
  4812. mx = r[r.length - 2];
  4813. my = r[r.length - 1];
  4814. break;
  4815. default:
  4816. x = r[r.length - 2];
  4817. y = r[r.length - 1];
  4818. }
  4819. }
  4820. res.isUniform = true;
  4821. res.isAbsolute = true;
  4822. res.toString = g.pathToString;
  4823. return res;
  4824. });
  4825. // 把圆弧绘制的曲线转化为对应的三次贝塞尔形式
  4826. function a2c(x1, y1, rx, ry, angle, laf, sf, x2, y2, recursive) {
  4827. // copy from raphael.js
  4828. // for more information of where this math came from visit:
  4829. // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  4830. var math = Math, PI = math.PI, abs = Math.abs, _120 = PI * 120 / 180, rad = PI / 180 * (+angle || 0), res = [], xy, rotate = function(x, y, rad) {
  4831. var X = x * math.cos(rad) - y * math.sin(rad), Y = x * math.sin(rad) + y * math.cos(rad);
  4832. return {
  4833. x: X,
  4834. y: Y
  4835. };
  4836. };
  4837. var cos, sin, h, x, y, rx2, ry2, k, cx, cy, f1, f2, df, f2old, x2old, y2old, c1, s1, c2, s2, t, hx, hy, m1, m2, m3, m4, newres, i, ii;
  4838. if (!recursive) {
  4839. xy = rotate(x1, y1, -rad);
  4840. x1 = xy.x;
  4841. y1 = xy.y;
  4842. xy = rotate(x2, y2, -rad);
  4843. x2 = xy.x;
  4844. y2 = xy.y;
  4845. cos = math.cos(PI / 180 * angle);
  4846. sin = math.sin(PI / 180 * angle);
  4847. x = (x1 - x2) / 2;
  4848. y = (y1 - y2) / 2;
  4849. h = x * x / (rx * rx) + y * y / (ry * ry);
  4850. if (h > 1) {
  4851. h = math.sqrt(h);
  4852. rx = h * rx;
  4853. ry = h * ry;
  4854. }
  4855. rx2 = rx * rx;
  4856. ry2 = ry * ry;
  4857. k = (laf == sf ? -1 : 1) * math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)));
  4858. cx = k * rx * y / ry + (x1 + x2) / 2;
  4859. cy = k * -ry * x / rx + (y1 + y2) / 2;
  4860. f1 = math.asin(((y1 - cy) / ry).toFixed(9));
  4861. f2 = math.asin(((y2 - cy) / ry).toFixed(9));
  4862. f1 = x1 < cx ? PI - f1 : f1;
  4863. f2 = x2 < cx ? PI - f2 : f2;
  4864. if (f1 < 0) f1 = PI * 2 + f1;
  4865. if (f2 < 0) f2 = PI * 2 + f2;
  4866. if (sf && f1 > f2) {
  4867. f1 = f1 - PI * 2;
  4868. }
  4869. if (!sf && f2 > f1) {
  4870. f2 = f2 - PI * 2;
  4871. }
  4872. } else {
  4873. f1 = recursive[0];
  4874. f2 = recursive[1];
  4875. cx = recursive[2];
  4876. cy = recursive[3];
  4877. }
  4878. df = f2 - f1;
  4879. if (abs(df) > _120) {
  4880. f2old = f2;
  4881. x2old = x2;
  4882. y2old = y2;
  4883. f2 = f1 + _120 * (sf && f2 > f1 ? 1 : -1);
  4884. x2 = cx + rx * math.cos(f2);
  4885. y2 = cy + ry * math.sin(f2);
  4886. res = a2c(x2, y2, rx, ry, angle, 0, sf, x2old, y2old, [ f2, f2old, cx, cy ]);
  4887. }
  4888. df = f2 - f1;
  4889. c1 = math.cos(f1);
  4890. s1 = math.sin(f1);
  4891. c2 = math.cos(f2);
  4892. s2 = math.sin(f2);
  4893. t = math.tan(df / 4);
  4894. hx = 4 / 3 * rx * t;
  4895. hy = 4 / 3 * ry * t;
  4896. m1 = [ x1, y1 ];
  4897. m2 = [ x1 + hx * s1, y1 - hy * c1 ];
  4898. m3 = [ x2 + hx * s2, y2 - hy * c2 ];
  4899. m4 = [ x2, y2 ];
  4900. m2[0] = 2 * m1[0] - m2[0];
  4901. m2[1] = 2 * m1[1] - m2[1];
  4902. if (recursive) {
  4903. return [ m2, m3, m4 ].concat(res);
  4904. } else {
  4905. res = [ m2, m3, m4 ].concat(res).join().split(",");
  4906. newres = [];
  4907. for (i = 0, ii = res.length; i < ii; i++) {
  4908. newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
  4909. }
  4910. return newres;
  4911. }
  4912. }
  4913. // 把二次贝塞尔曲线参数转化为三次贝塞尔曲线参数
  4914. function q2c(x1, y1, ax, ay, x2, y2) {
  4915. // copy from raphael.js
  4916. var _13 = 1 / 3, _23 = 2 / 3;
  4917. return [ _13 * x1 + _23 * ax, _13 * y1 + _23 * ay, _13 * x2 + _23 * ax, _13 * y2 + _23 * ay, x2, y2 ];
  4918. }
  4919. /**
  4920. * kity.g.pathToCurve(path)
  4921. *
  4922. * 把路径转换为贝塞尔路径
  4923. *
  4924. * @param {Array|String} path
  4925. * 要转换的 path 路径或数组
  4926. *
  4927. * @return {Array}
  4928. * 转换后的 PathSegment,每一段都是 'C'
  4929. */
  4930. g.pathToCurve = cacher(function(path) {
  4931. var i, j, command, param;
  4932. var initPoint, currentPoint, endPoint, shouldClose, lastControlPoint, aussumedControlPoint;
  4933. var controlPoint1, controlPoint2;
  4934. var res = [];
  4935. // 处理的路径要求是一个绝对路径
  4936. if (!path.isAbsolute) path = g.pathToAbsolute(path);
  4937. for (i = 0; i < path.length; i++) {
  4938. command = path[i][0];
  4939. param = path[i].slice(1);
  4940. // 画笔移动
  4941. if (command == "M") {
  4942. initPoint = lastControlPoint = currentPoint = param;
  4943. res.push(path[i]);
  4944. continue;
  4945. }
  4946. // 路径闭合
  4947. if (command == "Z") {
  4948. shouldClose = true;
  4949. command = "L";
  4950. param = initPoint;
  4951. }
  4952. // 绘制命令的目的位置
  4953. endPoint = param.slice(param.length - 2);
  4954. // 对 'H' 命令的修正
  4955. if (command == "H") {
  4956. endPoint = [ param[0], currentPoint[1] ];
  4957. command = "L";
  4958. }
  4959. // 对 'V' 命令的修正
  4960. if (command == "V") {
  4961. endPoint = [ currentPoint[0], param[0] ];
  4962. command = "L";
  4963. }
  4964. // 对 'S' 命令求出隐含的控制点位置
  4965. if (command == "S" || command == "T") {
  4966. // 隐含控制点是上一个控制点关于当前位置的镜像
  4967. aussumedControlPoint = [ currentPoint[0] + (currentPoint[0] - lastControlPoint[0]), currentPoint[1] + (currentPoint[1] - lastControlPoint[1]) ];
  4968. }
  4969. // 针对不同的命令求控制点
  4970. switch (command) {
  4971. case "L":
  4972. controlPoint1 = currentPoint;
  4973. controlPoint2 = endPoint;
  4974. break;
  4975. case "C":
  4976. controlPoint1 = param.slice(0, 2);
  4977. controlPoint2 = param.slice(2, 4);
  4978. break;
  4979. case "S":
  4980. controlPoint1 = aussumedControlPoint.slice();
  4981. controlPoint2 = param.slice(0, 2);
  4982. break;
  4983. case "Q":
  4984. lastControlPoint = param.slice(0, 2);
  4985. param = q2c.apply(null, currentPoint.concat(param));
  4986. controlPoint1 = param.slice(0, 2);
  4987. controlPoint2 = param.slice(2, 4);
  4988. break;
  4989. case "T":
  4990. param = q2c.apply(null, currentPoint.concat(aussumedControlPoint).concat(param));
  4991. controlPoint1 = param.slice(0, 2);
  4992. controlPoint2 = param.slice(2, 4);
  4993. break;
  4994. case "A":
  4995. param = a2c.apply(null, currentPoint.concat(param));
  4996. j = 0;
  4997. while (j in param) {
  4998. controlPoint1 = param.slice(j, j + 2);
  4999. controlPoint2 = param.slice(j + 2, j + 4);
  5000. endPoint = param.slice(j + 4, j + 6);
  5001. // 写入当前一段曲线
  5002. res.push([ "C" ].concat(controlPoint1).concat(controlPoint2).concat(endPoint));
  5003. j += 6;
  5004. }
  5005. break;
  5006. }
  5007. if (command != "A") {
  5008. // 写入当前一段曲线
  5009. res.push([ "C" ].concat(controlPoint1).concat(controlPoint2).concat(endPoint));
  5010. }
  5011. // 为下次循环准备当前位置
  5012. currentPoint = endPoint;
  5013. // 二次贝塞尔曲线自己已经记录了上个控制点的位置,其它的记录控制点 2 的位置
  5014. if (command != "Q") {
  5015. lastControlPoint = controlPoint2;
  5016. }
  5017. if (shouldClose) {
  5018. res.push([ "Z" ]);
  5019. shouldClose = false;
  5020. }
  5021. }
  5022. res.isUniform = true;
  5023. res.isAbsolute = true;
  5024. res.isCurve = true;
  5025. res.toString = g.pathToString;
  5026. return res;
  5027. });
  5028. /**
  5029. * 将贝塞尔曲线切成两部分
  5030. *
  5031. * @see http://stackoverflow.com/questions/18655135/divide-bezier-curve-into-two-equal-halves
  5032. */
  5033. function cutBezier(bezierArray, t) {
  5034. function __(t) {
  5035. return function(p, q) {
  5036. return p + t * (q - p);
  5037. };
  5038. }
  5039. var _ = __(t || .5), ba = bezierArray, ax = ba[0], ay = ba[1], bx = ba[2], by = ba[3], cx = ba[4], cy = ba[5], dx = ba[6], dy = ba[7], ex = _(ax, bx), ey = _(ay, by), fx = _(bx, cx), fy = _(by, cy), gx = _(cx, dx), gy = _(cy, dy), hx = _(ex, fx), hy = _(ey, fy), jx = _(fx, gx), jy = _(fy, gy), kx = _(hx, jx), ky = _(hy, jy);
  5040. return [ [ ax, ay, ex, ey, hx, hy, kx, ky ], [ kx, ky, jx, jy, gx, gy, dx, dy ] ];
  5041. }
  5042. /**
  5043. * kity.g.cutBezier(bezierArray, t)
  5044. *
  5045. * 在指定位置把贝塞尔曲线切割为两部分
  5046. *
  5047. * @param {Array} bezierArray
  5048. * 表示贝塞尔曲线的一个数组 [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y]
  5049. * p1 和 p2 是贝塞尔曲线的起点和终点,c1 和 c2 是两个控制点
  5050. *
  5051. * @param {Number} t
  5052. * 切割的位置(0 到 1)
  5053. *
  5054. * @return {Array}
  5055. * 切割的两个贝塞尔曲线:[
  5056. * [p1x1, p1y1, c1x1, c1y1, c2x1, c2y1, p2x1, p2y1],
  5057. * [p1x2, p1y2, c1x2, c1y2, c2x2, c2y2, p2x2, p2y2]
  5058. * ]
  5059. *
  5060. */
  5061. g.cutBezier = cacher(cutBezier);
  5062. /**
  5063. * 求一段贝塞尔曲线的子段
  5064. *
  5065. * @param {Array} bezierArray
  5066. * 长度为 8 的数组,表示 [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y]
  5067. *
  5068. * @param {Number} t
  5069. * 子段的结束位置(0 到 1)
  5070. *
  5071. * @param {Number} t0
  5072. * 字段的开始位置(0 到 t),可不传,默认为 0
  5073. *
  5074. * @return {Array}
  5075. * 长度为 8 的数组,表示给定贝塞尔曲线的子段
  5076. */
  5077. g.subBezier = function(bezierArray, t, t0) {
  5078. var b2t = cutBezier(bezierArray, t)[0];
  5079. return t0 ? cutBezier(b2t, t0 / t)[1] : b2t;
  5080. };
  5081. /**
  5082. * 求贝塞尔曲线上的一个点
  5083. *
  5084. * @param {Array} bezierArray
  5085. * 长度为 8 的数组,表示 [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y]
  5086. *
  5087. * @param {Number} t
  5088. * 所求点的开始位置(0 到 1)
  5089. *
  5090. * @return {Point} p
  5091. * p.x: x 坐标
  5092. * p.y: y 坐标
  5093. * p.tan: 在 t 处的切线方向(类型为 kity.Vector,模为 1)
  5094. */
  5095. g.pointAtBezier = function(bezierArray, t) {
  5096. var b2t = cutBezier(bezierArray, t)[0];
  5097. var p = Point.parse(b2t.slice(6)), c = Point.parse(b2t.slice(4, 2)), v = Vector.fromPoints(c, p);
  5098. if (t === 0) {
  5099. p.tan = g.pointAtBezier(bezierArray, .01).tan;
  5100. } else {
  5101. p.tan = v.normalize();
  5102. }
  5103. return p;
  5104. };
  5105. /**
  5106. * 求贝塞尔曲线的长度
  5107. *
  5108. * @param {Array} bezierArray
  5109. * 长度为 8 的数组,表示 [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y]
  5110. *
  5111. * @param {Number} tolerate
  5112. * 允许的误差,默认是 0.1
  5113. *
  5114. * @return {Number} 贝塞尔曲线的长度
  5115. */
  5116. g.bezierLength = cacher(function bezierLength(bezierArray) {
  5117. // 表示(c[0]*t^4 + c[1]*t^3 + c[2]*t^2 + c[3]*t^1 + c[4])^(1/2)的函数
  5118. function f(x) {
  5119. var m = c0 * Math.pow(x, 4) + c1 * Math.pow(x, 3) + c2 * Math.pow(x, 2) + c3 * x + c4;
  5120. if (m < 0) {
  5121. m = 0;
  5122. }
  5123. return Math.pow(m, .5);
  5124. }
  5125. // 用Newton-Cotes型求积公式
  5126. var arr = bezierArray;
  5127. // 三次贝塞尔曲线函数求导后,求出对应的方程系数,用cx[],cy[]表示x`(t)和y`(t)的系数
  5128. var cx0, cx1, cx2;
  5129. var cy0, cy1, cy2;
  5130. // 用c[]表示x`(t)^2 + y`(t)^2的结果的系数
  5131. var c0, c1, c2, c3, c4;
  5132. // 求x`(t) 和 y`(t)的系数
  5133. cx0 = -3 * arr[0] + 9 * arr[2] - 9 * arr[4] + 3 * arr[6];
  5134. cx1 = 6 * arr[0] - 12 * arr[2] + 6 * arr[4];
  5135. cx2 = -3 * arr[0] + 3 * arr[2];
  5136. cy0 = -3 * arr[1] + 9 * arr[3] - 9 * arr[5] + 3 * arr[7];
  5137. cy1 = 6 * arr[1] - 12 * arr[3] + 6 * arr[5];
  5138. cy2 = -3 * arr[1] + 3 * arr[3];
  5139. // 求x`(t)^2 + y`(t)^2的结果的系数 c[]
  5140. c0 = Math.pow(cx0, 2) + Math.pow(cy0, 2);
  5141. c1 = 2 * (cx0 * cx1 + cy0 * cy1);
  5142. c2 = 2 * (cx0 * cx2 + cy0 * cy2) + Math.pow(cx1, 2) + Math.pow(cy1, 2);
  5143. c3 = 2 * (cx1 * cx2 + cy1 * cy2);
  5144. c4 = Math.pow(cx2, 2) + Math.pow(cy2, 2);
  5145. // 用cotes积分公式求值
  5146. return (f(0) + f(1) + 4 * (f(.125) + f(.375) + f(.625) + f(.875)) + 2 * (f(.25) + f(.5) + f(.75))) / 24;
  5147. });
  5148. // 计算一个 pathSegment 中每一段的在整体中所占的长度范围,以及总长度
  5149. // 方法要求每一段都是贝塞尔曲线
  5150. var getBezierPathSegmentRanges = cacher(function(pathSegment) {
  5151. var i, ii, segment, position, bezierLength, segmentRanges, totalLength;
  5152. segmentRanges = [];
  5153. // 总长度
  5154. totalLength = 0;
  5155. for (i = 0, ii = pathSegment.length; i < ii; i++) {
  5156. segment = pathSegment[i];
  5157. if (segment[0] == "M") {
  5158. position = segment.slice(1);
  5159. segmentRanges.push(null);
  5160. continue;
  5161. }
  5162. if (segment[0] == "Z") {
  5163. segmentRanges.push(null);
  5164. continue;
  5165. }
  5166. bezierLength = g.bezierLength(position.concat(segment.slice(1)));
  5167. segmentRanges.push([ totalLength, totalLength + bezierLength ]);
  5168. totalLength += bezierLength;
  5169. // 迭代当前位置
  5170. position = segment.slice(4);
  5171. }
  5172. segmentRanges.totalLength = totalLength;
  5173. return segmentRanges;
  5174. });
  5175. /**
  5176. * 求一段路径的子路径
  5177. *
  5178. * @param {Array|String} path
  5179. * 原路径
  5180. *
  5181. * @param {Number} t1
  5182. * 要求的子路径的结束位置(0 到 1)
  5183. *
  5184. * @param {Number} t0
  5185. * 要求的子路径的开始位置(0 到 t1),可不传,默认为 0
  5186. *
  5187. * @return {Array}
  5188. * 子路径的 PathSegment
  5189. */
  5190. g.subPath = function(path, t1, t0) {
  5191. var dt;
  5192. t0 = t0 || 0;
  5193. dt = t1 - t0;
  5194. dt = dt - (dt | 0);
  5195. t0 = t0 - (t0 | 0);
  5196. t1 = t0 + dt;
  5197. if (t1 > 1) {
  5198. return g.subPath(path, 1, t0).concat(g.subPath(path, t1 - 1));
  5199. }
  5200. if (!path.isCurve) {
  5201. path = g.pathToCurve(path);
  5202. }
  5203. // path 每一段在整体中的长度区间
  5204. var segmentRanges = getBezierPathSegmentRanges(path);
  5205. // path 总长度
  5206. var totalLength = segmentRanges.totalLength;
  5207. // t1 和 t0 位置命中的长度位置
  5208. var t1Length = totalLength * t1, t0Length = totalLength * (t0 || 0);
  5209. // 产生的子路径
  5210. var subPath = [];
  5211. // 迭代变量,a 是一段的长度区间左值,b 是右值,d 是区间长度
  5212. var i, ii, a, b, d;
  5213. var position;
  5214. var bezier, subBezier, stared;
  5215. for (i = 0, ii = path.length; i < ii; i++) {
  5216. if (path[i][0] == "M") {
  5217. position = path[i].slice(1);
  5218. if (stared) {
  5219. subPath.push(path[i].slice());
  5220. }
  5221. continue;
  5222. }
  5223. if (path[i][0] == "Z") {
  5224. // subpath 路径不闭合
  5225. continue;
  5226. }
  5227. a = segmentRanges[i][0];
  5228. b = segmentRanges[i][1];
  5229. d = b - a;
  5230. bezier = position.concat(path[i].slice(1));
  5231. if (t0Length > b) {
  5232. // t0 和 t1 都右溢出
  5233. // -----------------------------------
  5234. // t0 t1
  5235. // |________|
  5236. //
  5237. // 需要跳过当前块
  5238. position = bezier.slice(bezier.length - 2);
  5239. continue;
  5240. } else if (t0Length >= a) {
  5241. // 命中 t0;t1 可能命中或右溢出
  5242. // -----------------------------------
  5243. // t0 t1
  5244. // |______|__|
  5245. //
  5246. // or: |_|____|__|
  5247. //
  5248. // 取当前块 t0 到 t1 的部分
  5249. subBezier = g.subBezier(bezier, Math.min((t1Length - a) / d, 1), (t0Length - a) / d);
  5250. stared = true;
  5251. position = subBezier.slice(0, 2);
  5252. subPath.push([ "M" ].concat(subBezier.slice(0, 2)));
  5253. subPath.push([ "C" ].concat(subBezier.slice(2)));
  5254. } else if (t1Length >= b) {
  5255. // t0 左溢出;t1 右溢出,整个块是需要的
  5256. // -----------------------------------
  5257. // t0 t1
  5258. // |_________|
  5259. //
  5260. // 此时取整个块
  5261. subPath.push(path[i].slice());
  5262. } else if (t1Length >= a) {
  5263. // t0 左溢出;t1 命中,取当前块 t1 之前的部分
  5264. // -----------------------------------
  5265. // t0 t1
  5266. // |__|______|
  5267. // 取当前块 t1 之前的部分
  5268. subBezier = g.subBezier(bezier, (t1Length - a) / d);
  5269. subPath.push([ "C" ].concat(subBezier.slice(2)));
  5270. stared = false;
  5271. } else {
  5272. // 没有可以再要的了
  5273. break;
  5274. }
  5275. position = bezier.slice(bezier.length - 2);
  5276. }
  5277. subPath.isAbsolute = true;
  5278. subPath.isCurve = true;
  5279. subPath.isUniform = true;
  5280. subPath.toString = g.pathToString;
  5281. return subPath;
  5282. };
  5283. /**
  5284. * 求路径上的一个点
  5285. *
  5286. * @param {Array|String} path
  5287. * 要求点的路径
  5288. *
  5289. * @param {Number} t
  5290. * 要求的点的位置(0 到 1)
  5291. *
  5292. * @return {Point} p
  5293. * p.x: x 坐标
  5294. * p.y: y 坐标
  5295. * p.tan: 在 t 处的切线方向(类型为 kity.Vector,模为 1)
  5296. */
  5297. g.pointAtPath = function(path, t) {
  5298. if (!path.isCurve) {
  5299. path = g.pathToCurve(path);
  5300. }
  5301. var subPath = g.subPath(path, t);
  5302. var lastCurve = subPath[subPath.length - 1][0] == "Z" ? subPath[subPath.length - 2] : subPath[subPath.length - 1];
  5303. // 跳过 'C' 命令,只留参数
  5304. lastCurve = lastCurve.slice(1);
  5305. var p = Point.parse(lastCurve.slice(4)), c = Point.parse(lastCurve.slice(2, 4));
  5306. p.tan = Vector.fromPoints(c, p).normalize();
  5307. return p;
  5308. };
  5309. /**
  5310. * 求一段路径的长度
  5311. *
  5312. * @param {string|Array} path
  5313. * 要求的路径
  5314. *
  5315. * @return {Number}
  5316. * 路径的长度
  5317. */
  5318. g.pathLength = cacher(function(path) {
  5319. if (!path.isCurve) {
  5320. path = g.pathToCurve(path);
  5321. }
  5322. // path 每一段在整体中的长度区间
  5323. var segmentRanges = getBezierPathSegmentRanges(path);
  5324. return segmentRanges.totalLength;
  5325. });
  5326. /**
  5327. * 求一段路径的关键点
  5328. *
  5329. * @param {string|Array} path
  5330. * 要求的路径
  5331. *
  5332. * @return {Array}
  5333. * 关键点的集合
  5334. */
  5335. g.pathKeyPoints = cacher(function(path) {
  5336. var i, ii, command, keyPoints;
  5337. if (!path.isCurve) {
  5338. path = g.pathToCurve(path);
  5339. }
  5340. keyPoints = [];
  5341. for (i = 0, ii = path.length; i < ii; i++) {
  5342. if (path[i][0] == "z") continue;
  5343. keyPoints.push(path[i].slice(path[i].length - 2));
  5344. }
  5345. return keyPoints;
  5346. });
  5347. // 对比两个路径的关键位置,在合适的位置切割合适的路径,使得两个路径的段数一致
  5348. // TODO: 使用插值算法,使对应点更合理
  5349. var alignCurve = cacher(function(path1, path2) {
  5350. if (!path1.isCurve) path1 = g.pathToCurve(path1);
  5351. if (!path2.isCurve) path2 = g.pathToCurve(path2);
  5352. var p1 = pathClone(path1);
  5353. var p2 = pathClone(path2);
  5354. p1.i = 0;
  5355. p2.i = 0;
  5356. p1.o = p2;
  5357. p2.o = p1;
  5358. function command(p, i) {
  5359. return p[i || p.i] && p[i || p.i][0];
  5360. }
  5361. function param(p, i) {
  5362. return p[i || p.i] && p[i || p.i].slice(1);
  5363. }
  5364. function point(p, i) {
  5365. var _param = param(p, i);
  5366. return _param && _param.slice(-2);
  5367. }
  5368. function fixZ(p) {
  5369. if (command(p) == "Z") {
  5370. p.splice(p.i, 1);
  5371. return true;
  5372. }
  5373. return false;
  5374. }
  5375. function fixM(p) {
  5376. if (command(p) == "M") {
  5377. p.o.splice(p.o.i, 0, [ "M" ].concat(point(p.o, p.o.i - 1)));
  5378. p.i++;
  5379. p.o.i++;
  5380. return true;
  5381. }
  5382. return false;
  5383. }
  5384. function fill(p) {
  5385. var lastPoint;
  5386. var i = 1;
  5387. while (!lastPoint) {
  5388. lastPoint = point(p, p.length - i++);
  5389. }
  5390. p.o.i = p.i;
  5391. while (p.length < p.o.length) {
  5392. if (fixZ(p.o)) continue;
  5393. if (fixM(p.o)) continue;
  5394. p.push([ "C" ].concat(lastPoint).concat(lastPoint).concat(lastPoint));
  5395. p.i++;
  5396. p.o.i++;
  5397. }
  5398. }
  5399. while (p1.i < p1.length && p2.i < p2.length) {
  5400. if (fixZ(p1) || fixZ(p2)) continue;
  5401. if (command(p1) == command(p2)) {
  5402. p1.i++;
  5403. p2.i++;
  5404. continue;
  5405. }
  5406. if (fixM(p1) || fixM(p2)) continue;
  5407. p1.i++;
  5408. p2.i++;
  5409. }
  5410. if (p1.i == p1.length) fill(p1);
  5411. if (p2.i == p2.length) fill(p2);
  5412. delete p1.i;
  5413. delete p1.o;
  5414. delete p2.i;
  5415. delete p2.o;
  5416. return [ p1, p2 ];
  5417. });
  5418. g.alignCurve = alignCurve;
  5419. /**
  5420. * 获得两个路径的补间结果
  5421. *
  5422. * @param {string|Array} path1
  5423. * 补间起始路径
  5424. *
  5425. * @param {string|Array} path2
  5426. * 补间结束路径
  5427. *
  5428. * @param {Number} t
  5429. * 补间比例,0 返回跟 path1 等效的结果;1 返回跟 path2 等效的结果
  5430. *
  5431. * @return {PathSegment}
  5432. * 补间的结果
  5433. */
  5434. g.pathTween = function(path1, path2, t) {
  5435. if (t === 0) return path1;
  5436. if (t === 1) return path2;
  5437. var aligned = alignCurve(path1, path2);
  5438. var result = [], seg, i, j;
  5439. path1 = aligned[0];
  5440. path2 = aligned[1];
  5441. for (i = 0; i < path1.length; i++) {
  5442. result.push(seg = []);
  5443. seg.push(path1[i][0]);
  5444. for (j = 1; j < path1[i].length; j++) {
  5445. seg.push(path1[i][j] + t * (path2[i][j] - path1[i][j]));
  5446. }
  5447. }
  5448. result.isUniform = result.isCurve = result.isAbsolute = true;
  5449. return result;
  5450. };
  5451. /**
  5452. * 变换指定的路径
  5453. *
  5454. * @param {String|Array} path
  5455. * 需要变换的路径
  5456. *
  5457. * @param {kity.Matrix} matrix
  5458. * 使用的变换矩阵
  5459. *
  5460. * @return {Array}
  5461. * 变换后的路径
  5462. */
  5463. g.transformPath = cacher(function(path, matrix) {
  5464. var i, ii, j, result, seg, pair;
  5465. if (!path.isCurve) {
  5466. path = g.pathToCurve(path);
  5467. }
  5468. result = [];
  5469. for (i = 0, ii = path.length; i < ii; i++) {
  5470. result.push(seg = [ path[i][0] ]);
  5471. for (j = 1; j < path[i].length; j += 2) {
  5472. pair = path[i].slice(j, j + 2);
  5473. pair = matrix.transformPoint(Point.parse(pair));
  5474. result.push(pair);
  5475. }
  5476. }
  5477. return result;
  5478. });
  5479. // entend
  5480. _p.r(11).extendClass(Matrix, {
  5481. transformPath: function(path) {
  5482. return g.transformPath(path, this);
  5483. }
  5484. });
  5485. return g;
  5486. }
  5487. };
  5488. //src/graphic/gradient.js
  5489. _p[36] = {
  5490. value: function(require, exports, module) {
  5491. var svg = _p.r(68);
  5492. var Resource = _p.r(59);
  5493. var Color = _p.r(29);
  5494. return _p.r(11).createClass("GradientBrush", {
  5495. base: Resource,
  5496. constructor: function(gradientNodeType, paper) {
  5497. this.callBase(gradientNodeType, paper);
  5498. this.stops = [];
  5499. },
  5500. addStop: function(offset, color, opacity) {
  5501. var gstop = svg.createNode("stop");
  5502. if (!(color instanceof Color)) {
  5503. color = Color.parse(color);
  5504. }
  5505. if (opacity === undefined) {
  5506. opacity = color.get("a");
  5507. }
  5508. gstop.setAttribute("offset", offset);
  5509. gstop.setAttribute("stop-color", color.toRGB());
  5510. if (opacity < 1) {
  5511. gstop.setAttribute("stop-opacity", opacity);
  5512. }
  5513. this.node.appendChild(gstop);
  5514. return this;
  5515. }
  5516. });
  5517. }
  5518. };
  5519. //src/graphic/group.js
  5520. _p[37] = {
  5521. value: function(require, exports, module) {
  5522. var ShapeContainer = _p.r(62);
  5523. return _p.r(11).createClass("Group", {
  5524. mixins: [ ShapeContainer ],
  5525. base: _p.r(61),
  5526. constructor: function Group() {
  5527. this.callBase("g");
  5528. }
  5529. });
  5530. }
  5531. };
  5532. //src/graphic/hyperlink.js
  5533. _p[38] = {
  5534. value: function(require, exports, module) {
  5535. var ShapeContainer = _p.r(62);
  5536. return _p.r(11).createClass("HyperLink", {
  5537. mixins: [ ShapeContainer ],
  5538. base: _p.r(61),
  5539. constructor: function(url) {
  5540. this.callBase("a");
  5541. this.setHref(url);
  5542. },
  5543. setHref: function(href) {
  5544. this.node.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", href);
  5545. return this;
  5546. },
  5547. getHref: function() {
  5548. return this.node.getAttributeNS("xlink:href");
  5549. },
  5550. setTarget: function(target) {
  5551. this.node.setAttribute("target", target);
  5552. return this;
  5553. },
  5554. getTarget: function() {
  5555. return this.node.getAttribute("target");
  5556. }
  5557. });
  5558. }
  5559. };
  5560. //src/graphic/image.js
  5561. _p[39] = {
  5562. value: function(require, exports, module) {
  5563. return _p.r(11).createClass("Image", {
  5564. base: _p.r(61),
  5565. constructor: function(url, width, height, x, y) {
  5566. this.callBase("image");
  5567. this.url = url;
  5568. this.width = width || 0;
  5569. this.height = height || 0;
  5570. this.x = x || 0;
  5571. this.y = y || 0;
  5572. this.update();
  5573. },
  5574. update: function() {
  5575. this.node.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", this.url);
  5576. this.node.setAttribute("x", this.x);
  5577. this.node.setAttribute("y", this.y);
  5578. this.node.setAttribute("width", this.width);
  5579. this.node.setAttribute("height", this.height);
  5580. return this;
  5581. },
  5582. setUrl: function(url) {
  5583. this.url = url === "" ? null : url;
  5584. return this.update();
  5585. },
  5586. getUrl: function() {
  5587. return this.url;
  5588. },
  5589. setWidth: function(width) {
  5590. this.width = width;
  5591. return this.update();
  5592. },
  5593. getWidth: function() {
  5594. return this.width;
  5595. },
  5596. setHeight: function(height) {
  5597. this.height = height;
  5598. return this.update();
  5599. },
  5600. getHeight: function() {
  5601. return this.height;
  5602. },
  5603. setX: function(x) {
  5604. this.x = x;
  5605. return this.update();
  5606. },
  5607. getX: function() {
  5608. return this.x;
  5609. },
  5610. setY: function(y) {
  5611. this.y = y;
  5612. return this.update();
  5613. },
  5614. getY: function() {
  5615. return this.y;
  5616. }
  5617. });
  5618. }
  5619. };
  5620. //src/graphic/line.js
  5621. _p[40] = {
  5622. value: function(require, exports, module) {
  5623. return _p.r(11).createClass("Line", {
  5624. base: _p.r(47),
  5625. constructor: function(x1, y1, x2, y2) {
  5626. this.callBase();
  5627. this.point1 = {
  5628. x: x1 || 0,
  5629. y: y1 || 0
  5630. };
  5631. this.point2 = {
  5632. x: x2 || 0,
  5633. y: y2 || 0
  5634. };
  5635. this.update();
  5636. },
  5637. setPoint1: function(x, y) {
  5638. this.point1.x = x;
  5639. this.point1.y = y;
  5640. return this.update();
  5641. },
  5642. setPoint2: function(x, y) {
  5643. this.point2.x = x;
  5644. this.point2.y = y;
  5645. return this.update();
  5646. },
  5647. getPoint1: function() {
  5648. return {
  5649. x: this.point1.x,
  5650. y: this.point1.y
  5651. };
  5652. },
  5653. getPoint2: function() {
  5654. return {
  5655. x: this.point2.x,
  5656. y: this.point2.y
  5657. };
  5658. },
  5659. update: function() {
  5660. var drawer = this.getDrawer();
  5661. drawer.clear();
  5662. drawer.moveTo(this.point1.x, this.point1.y);
  5663. drawer.lineTo(this.point2.x, this.point2.y);
  5664. return this;
  5665. }
  5666. });
  5667. }
  5668. };
  5669. //src/graphic/lineargradient.js
  5670. _p[41] = {
  5671. value: function(require, exports, module) {
  5672. var svg = _p.r(68);
  5673. var Gradient = _p.r(36);
  5674. return _p.r(11).createClass("LinearGradientBrush", {
  5675. base: Gradient,
  5676. constructor: function(paper) {
  5677. this.callBase("linearGradient", paper);
  5678. this.setStartPosition(0, 0);
  5679. this.setEndPosition(1, 0);
  5680. },
  5681. setStartPosition: function(px, py) {
  5682. this.node.setAttribute("x1", px);
  5683. this.node.setAttribute("y1", py);
  5684. return this;
  5685. },
  5686. setEndPosition: function(px, py) {
  5687. this.node.setAttribute("x2", px);
  5688. this.node.setAttribute("y2", py);
  5689. return this;
  5690. },
  5691. getStartPosition: function() {
  5692. return {
  5693. x: +this.node.getAttribute("x1"),
  5694. y: +this.node.getAttribute("y1")
  5695. };
  5696. },
  5697. getEndPosition: function() {
  5698. return {
  5699. x: +this.node.getAttribute("x2"),
  5700. y: +this.node.getAttribute("y2")
  5701. };
  5702. }
  5703. });
  5704. }
  5705. };
  5706. //src/graphic/marker.js
  5707. _p[42] = {
  5708. value: function(require, exports, module) {
  5709. var Point = _p.r(51);
  5710. var Marker = _p.r(11).createClass("Marker", {
  5711. base: _p.r(59),
  5712. mixins: [ _p.r(62), _p.r(76) ],
  5713. constructor: function() {
  5714. this.callBase("marker");
  5715. this.setOrient("auto");
  5716. },
  5717. setRef: function(x, y) {
  5718. if (arguments.length === 1) {
  5719. y = x.y;
  5720. x = x.x;
  5721. }
  5722. this.node.setAttribute("refX", x);
  5723. this.node.setAttribute("refY", y);
  5724. return this;
  5725. },
  5726. getRef: function() {
  5727. return new Point(+this.node.getAttribute("refX"), +this.node.getAttribute("refY"));
  5728. },
  5729. setWidth: function(width) {
  5730. this.node.setAttribute("markerWidth", this.width = width);
  5731. return this;
  5732. },
  5733. setOrient: function(orient) {
  5734. this.node.setAttribute("orient", this.orient = orient);
  5735. return this;
  5736. },
  5737. getOrient: function() {
  5738. return this.orient;
  5739. },
  5740. getWidth: function() {
  5741. return +this.width;
  5742. },
  5743. setHeight: function(height) {
  5744. this.node.setAttribute("markerHeight", this.height = height);
  5745. return this;
  5746. },
  5747. getHeight: function() {
  5748. return +this.height;
  5749. }
  5750. });
  5751. var Path = _p.r(47);
  5752. _p.r(11).extendClass(Path, {
  5753. setMarker: function(marker, pos) {
  5754. pos = pos || "end";
  5755. if (!marker) {
  5756. this.node.removeAttribute("marker-" + pos);
  5757. } else {
  5758. this.node.setAttribute("marker-" + pos, marker.toString());
  5759. }
  5760. return this;
  5761. }
  5762. });
  5763. return Marker;
  5764. }
  5765. };
  5766. //src/graphic/mask.js
  5767. /**
  5768. * 蒙板
  5769. */
  5770. _p[43] = {
  5771. value: function(require, exports, module) {
  5772. var Class = _p.r(11);
  5773. var Shape = _p.r(61);
  5774. var Mask = Class.createClass("Mask", {
  5775. base: Shape,
  5776. mixins: [ _p.r(62) ],
  5777. constructor: function() {
  5778. this.callBase("mask");
  5779. },
  5780. mask: function(shape) {
  5781. shape.getNode().setAttribute("mask", "url(#" + this.getId() + ")");
  5782. return this;
  5783. }
  5784. });
  5785. Class.extendClass(Shape, {
  5786. maskWith: function(mask) {
  5787. mask.mask(this);
  5788. return this;
  5789. }
  5790. });
  5791. return Mask;
  5792. }
  5793. };
  5794. //src/graphic/matrix.js
  5795. _p[44] = {
  5796. value: function(require, exports, module) {
  5797. var utils = _p.r(12);
  5798. var Box = _p.r(26);
  5799. var mPattern = /matrix\s*\((.+)\)/i;
  5800. var Point = _p.r(51);
  5801. // 注意,合并的结果是先执行m2,再执行m1的结果
  5802. function mergeMatrixData(m2, m1) {
  5803. return {
  5804. a: m1.a * m2.a + m1.c * m2.b,
  5805. b: m1.b * m2.a + m1.d * m2.b,
  5806. c: m1.a * m2.c + m1.c * m2.d,
  5807. d: m1.b * m2.c + m1.d * m2.d,
  5808. e: m1.a * m2.e + m1.c * m2.f + m1.e,
  5809. f: m1.b * m2.e + m1.d * m2.f + m1.f
  5810. };
  5811. }
  5812. function d2r(deg) {
  5813. return deg * Math.PI / 180;
  5814. }
  5815. var Matrix = _p.r(11).createClass("Matrix", {
  5816. constructor: function() {
  5817. if (arguments.length) {
  5818. this.setMatrix.apply(this, arguments);
  5819. } else {
  5820. this.setMatrix(1, 0, 0, 1, 0, 0);
  5821. }
  5822. },
  5823. translate: function(x, y) {
  5824. this.m = mergeMatrixData(this.m, {
  5825. a: 1,
  5826. c: 0,
  5827. e: x,
  5828. b: 0,
  5829. d: 1,
  5830. f: y
  5831. });
  5832. return this;
  5833. },
  5834. rotate: function(deg) {
  5835. var rad = d2r(deg);
  5836. var sin = Math.sin(rad), cos = Math.cos(rad);
  5837. this.m = mergeMatrixData(this.m, {
  5838. a: cos,
  5839. c: -sin,
  5840. e: 0,
  5841. b: sin,
  5842. d: cos,
  5843. f: 0
  5844. });
  5845. return this;
  5846. },
  5847. scale: function(sx, sy) {
  5848. if (sy === undefined) {
  5849. sy = sx;
  5850. }
  5851. this.m = mergeMatrixData(this.m, {
  5852. a: sx,
  5853. c: 0,
  5854. e: 0,
  5855. b: 0,
  5856. d: sy,
  5857. f: 0
  5858. });
  5859. return this;
  5860. },
  5861. skew: function(degX, degY) {
  5862. if (degY === undefined) {
  5863. degY = degX;
  5864. }
  5865. var tx = Math.tan(d2r(degX)), ty = Math.tan(d2r(degY));
  5866. this.m = mergeMatrixData(this.m, {
  5867. a: 1,
  5868. c: tx,
  5869. e: 0,
  5870. b: ty,
  5871. d: 1,
  5872. f: 0
  5873. });
  5874. return this;
  5875. },
  5876. /**
  5877. * 获得反转矩阵
  5878. *
  5879. * 这是我解方程算出来的
  5880. */
  5881. inverse: function() {
  5882. var m = this.m, a = m.a, b = m.b, c = m.c, d = m.d, e = m.e, f = m.f, k, aa, bb, cc, dd, ee, ff;
  5883. k = a * d - b * c;
  5884. aa = d / k;
  5885. bb = -b / k;
  5886. cc = -c / k;
  5887. dd = a / k;
  5888. ee = (c * f - e * d) / k;
  5889. ff = (b * e - a * f) / k;
  5890. return new Matrix(aa, bb, cc, dd, ee, ff);
  5891. },
  5892. setMatrix: function(a, b, c, d, e, f) {
  5893. if (arguments.length === 1) {
  5894. this.m = utils.clone(arguments[0]);
  5895. } else {
  5896. this.m = {
  5897. a: a,
  5898. b: b,
  5899. c: c,
  5900. d: d,
  5901. e: e,
  5902. f: f
  5903. };
  5904. }
  5905. return this;
  5906. },
  5907. getMatrix: function() {
  5908. return utils.clone(this.m);
  5909. },
  5910. getTranslate: function() {
  5911. var m = this.m;
  5912. return {
  5913. x: m.e / m.a,
  5914. y: m.f / m.d
  5915. };
  5916. },
  5917. mergeMatrix: function(matrix) {
  5918. return new Matrix(mergeMatrixData(this.m, matrix.m));
  5919. },
  5920. merge: function(matrix) {
  5921. return this.mergeMatrix(matrix);
  5922. },
  5923. toString: function() {
  5924. return this.valueOf().join(" ");
  5925. },
  5926. valueOf: function() {
  5927. var m = this.m;
  5928. return [ m.a, m.b, m.c, m.d, m.e, m.f ];
  5929. },
  5930. equals: function(matrix) {
  5931. var m1 = this.m, m2 = matrix.m;
  5932. return m1.a == m2.a && m1.b == m2.b && m1.c == m2.c && m1.d == m2.d && m1.e == m2.e && m1.f == m2.f;
  5933. },
  5934. transformPoint: function() {
  5935. return Matrix.transformPoint.apply(null, [].slice.call(arguments).concat([ this.m ]));
  5936. },
  5937. transformBox: function(box) {
  5938. return Matrix.transformBox(box, this.m);
  5939. },
  5940. clone: function() {
  5941. return new Matrix(this.m);
  5942. }
  5943. });
  5944. Matrix.parse = function(str) {
  5945. var match;
  5946. var f = parseFloat;
  5947. if (str instanceof Array) {
  5948. return new Matrix({
  5949. a: str[0],
  5950. b: str[1],
  5951. c: str[2],
  5952. d: str[3],
  5953. e: str[4],
  5954. f: str[5]
  5955. });
  5956. }
  5957. if (match = mPattern.exec(str)) {
  5958. var values = match[1].split(",");
  5959. if (values.length != 6) {
  5960. values = match[1].split(" ");
  5961. }
  5962. return new Matrix({
  5963. a: f(values[0]),
  5964. b: f(values[1]),
  5965. c: f(values[2]),
  5966. d: f(values[3]),
  5967. e: f(values[4]),
  5968. f: f(values[5])
  5969. });
  5970. }
  5971. return new Matrix();
  5972. };
  5973. Matrix.transformPoint = function(x, y, m) {
  5974. if (arguments.length === 2) {
  5975. m = y;
  5976. y = x.y;
  5977. x = x.x;
  5978. }
  5979. return new Point(m.a * x + m.c * y + m.e, m.b * x + m.d * y + m.f);
  5980. };
  5981. Matrix.transformBox = function(box, matrix) {
  5982. var xMin = Number.MAX_VALUE, xMax = -Number.MAX_VALUE, yMin = Number.MAX_VALUE, yMax = -Number.MAX_VALUE;
  5983. var bps = [ [ box.x, box.y ], [ box.x + box.width, box.y ], [ box.x, box.y + box.height ], [ box.x + box.width, box.y + box.height ] ];
  5984. var bp, rp, rps = [];
  5985. while (bp = bps.pop()) {
  5986. rp = Matrix.transformPoint(bp[0], bp[1], matrix);
  5987. rps.push(rp);
  5988. xMin = Math.min(xMin, rp.x);
  5989. xMax = Math.max(xMax, rp.x);
  5990. yMin = Math.min(yMin, rp.y);
  5991. yMax = Math.max(yMax, rp.y);
  5992. }
  5993. box = new Box({
  5994. x: xMin,
  5995. y: yMin,
  5996. width: xMax - xMin,
  5997. height: yMax - yMin
  5998. });
  5999. utils.extend(box, {
  6000. closurePoints: rps
  6001. });
  6002. return box;
  6003. };
  6004. // 获得从 node 到 refer 的变换矩阵
  6005. Matrix.getCTM = function(target, refer) {
  6006. var ctm = {
  6007. a: 1,
  6008. b: 0,
  6009. c: 0,
  6010. d: 1,
  6011. e: 0,
  6012. f: 0
  6013. };
  6014. var node = target.shapeNode || target.node;
  6015. refer = refer || "parent";
  6016. /**
  6017. * 由于新版chrome(dev 48.0)移除了getTransformToElement这个方法可能导致报错,这里做兼容处理
  6018. * @Date 2015-11-12
  6019. * @Editor Naixor
  6020. */
  6021. function getTransformToElement(target, source) {
  6022. var matrix;
  6023. try {
  6024. matrix = source.getScreenCTM().inverse();
  6025. } catch (e) {
  6026. throw new Error("Can not inverse source element' ctm.");
  6027. }
  6028. return matrix.multiply(target.getScreenCTM());
  6029. }
  6030. // 根据参照坐标系选区的不一样,返回不同的结果
  6031. switch (refer) {
  6032. case "screen":
  6033. // 以浏览器屏幕为参照坐标系
  6034. ctm = node.getScreenCTM();
  6035. break;
  6036. case "doc":
  6037. case "paper":
  6038. // 以文档(Paper)为参照坐标系
  6039. ctm = node.getCTM();
  6040. break;
  6041. case "view":
  6042. case "top":
  6043. // 以顶层绘图容器(视野)为参照坐标系
  6044. if (target.getPaper()) {
  6045. ctm = node.getTransformToElement !== undefined ? node.getTransformToElement(target.getPaper().shapeNode) : getTransformToElement(node, target.getPaper().shapeNode);
  6046. }
  6047. break;
  6048. case "parent":
  6049. // 以父容器为参照坐标系
  6050. if (target.node.parentNode) {
  6051. ctm = node.getTransformToElement !== undefined ? node.getTransformToElement(target.node.parentNode) : getTransformToElement(node, target.node.parentNode);
  6052. }
  6053. break;
  6054. default:
  6055. // 其他情况,指定参照物
  6056. if (refer.node) {
  6057. ctm = node.getTransformToElement !== undefined ? node.getTransformToElement(refer.shapeNode || refer.node) : getTransformToElement(node, refer.shapeNode || refer.node);
  6058. }
  6059. }
  6060. return ctm ? new Matrix(ctm.a, ctm.b, ctm.c, ctm.d, ctm.e, ctm.f) : new Matrix();
  6061. };
  6062. return Matrix;
  6063. }
  6064. };
  6065. //src/graphic/palette.js
  6066. /**
  6067. * 调色板
  6068. */
  6069. _p[45] = {
  6070. value: function(require, exports, module) {
  6071. //标准color
  6072. var StandardColor = _p.r(65), Color = _p.r(29), Utils = _p.r(12);
  6073. var Palette = _p.r(11).createClass("Palette", {
  6074. constructor: function() {
  6075. this.color = {};
  6076. },
  6077. /*
  6078. * 获取颜色名称所对应的颜色值的Color对象
  6079. * @param name 需要获取的颜色名称
  6080. * @return 对应颜色名称的color对象, 如果未找到对应的名称, 则返回null
  6081. */
  6082. get: function(name) {
  6083. var colorValue = this.color[name] || StandardColor.EXTEND_STANDARD[name] || StandardColor.COLOR_STANDARD[name] || "";
  6084. if (colorValue) {
  6085. return new Color(colorValue);
  6086. }
  6087. return null;
  6088. },
  6089. /*
  6090. * 获取给定名称的颜色的hex值表示
  6091. * @param name 需要获取的颜色名称
  6092. * @return 如果找到对应的名称, 则返回该名称所对应的hex格式的值, 否则, 返回一个空字符串
  6093. */
  6094. getColorValue: function(name) {
  6095. return this.color[name] || StandardColor.EXTEND_STANDARD[name] || StandardColor.COLOR_STANDARD[name] || "";
  6096. },
  6097. /*
  6098. * 向调色板实例添加自己独有的颜色名称,对已存在的颜色名称, 将会覆盖掉
  6099. * @param name 新添加的颜色名称
  6100. * @param value 新添加的颜色名称所对应的值, 可以是一个合法的颜色字符串或者是一个color对象
  6101. * @return 新添加的颜色的值
  6102. */
  6103. add: function(name, value) {
  6104. if (typeof value === "string") {
  6105. this.color[name] = new Color(value).toRGBA();
  6106. } else {
  6107. this.color[name] = value.toRGBA();
  6108. }
  6109. return value;
  6110. },
  6111. /*
  6112. * 删除调色板实例上用户自己添加的颜色, 该方法不能删除内置的颜色
  6113. * @param name 需要删除的颜色名称
  6114. * @return 删除是否成功的bool值
  6115. */
  6116. remove: function(name) {
  6117. if (this.color.hasOwnProperty(name)) {
  6118. delete this.color[name];
  6119. return true;
  6120. }
  6121. return false;
  6122. }
  6123. });
  6124. Utils.extend(Palette, {
  6125. getColor: function(name) {
  6126. var colorValue = StandardColor.EXTEND_STANDARD[name] || StandardColor.COLOR_STANDARD[name];
  6127. if (colorValue) {
  6128. return new Color(colorValue);
  6129. }
  6130. return null;
  6131. },
  6132. /*
  6133. * 通过给定的名字获取标准的颜色值表示, 返回的值以hex的方式提供
  6134. * @param name 需要获取的标准颜色名称
  6135. * @return 名字所对应的颜色值的hex表示, 如果未找到对应名称的值, 则返回一个空字符串
  6136. */
  6137. getColorValue: function(name) {
  6138. return StandardColor.EXTEND_STANDARD[name] || StandardColor.COLOR_STANDARD[name] || "";
  6139. },
  6140. /*
  6141. * 向调色板添加颜色名称,新添加的颜色对所有的调色板对象都可见
  6142. * 对已存在的颜色名称, 将会覆盖掉
  6143. * @param name 新添加的颜色名称
  6144. * @param value 新添加的颜色名称所对于的值, 应该是一个hex格式的颜色字符串, 如: ”#ff0000“
  6145. * @return 新添加的颜色的值
  6146. */
  6147. addColor: function(name, value) {
  6148. if (typeof value === "string") {
  6149. StandardColor.EXTEND_STANDARD[name] = new Color(value).toRGBA();
  6150. } else {
  6151. StandardColor.EXTEND_STANDARD[name] = value.toRGBA();
  6152. }
  6153. return value;
  6154. },
  6155. /*
  6156. * 删除用户自己添加的颜色, 该方法不能删除内置的颜色, 该方法不会影响调色板实例自由的颜色
  6157. * @param name 需要删除的颜色名称
  6158. * @return 删除是否成功的bool值
  6159. */
  6160. removeColor: function(name) {
  6161. if (StandardColor.EXTEND_STANDARD.hasOwnProperty(name)) {
  6162. delete StandardColor.EXTEND_STANDARD[name];
  6163. return true;
  6164. }
  6165. return false;
  6166. }
  6167. });
  6168. return Palette;
  6169. }
  6170. };
  6171. //src/graphic/paper.js
  6172. _p[46] = {
  6173. value: function(require, exports, module) {
  6174. var Class = _p.r(11);
  6175. var utils = _p.r(12);
  6176. var svg = _p.r(68);
  6177. var Container = _p.r(30);
  6178. var ShapeContainer = _p.r(62);
  6179. var ViewBox = _p.r(76);
  6180. var EventHandler = _p.r(34);
  6181. var Styled = _p.r(67);
  6182. var Matrix = _p.r(44);
  6183. var Paper = Class.createClass("Paper", {
  6184. mixins: [ ShapeContainer, EventHandler, Styled, ViewBox ],
  6185. constructor: function(container) {
  6186. this.callBase();
  6187. this.node = this.createSVGNode();
  6188. this.node.paper = this;
  6189. this.node.appendChild(this.resourceNode = svg.createNode("defs"));
  6190. this.node.appendChild(this.shapeNode = svg.createNode("g"));
  6191. this.resources = new Container();
  6192. this.setWidth("100%").setHeight("100%");
  6193. if (container) {
  6194. this.renderTo(container);
  6195. }
  6196. this.callMixin();
  6197. },
  6198. renderTo: function(container) {
  6199. if (utils.isString(container)) {
  6200. container = document.getElementById(container);
  6201. }
  6202. this.container = container;
  6203. container.appendChild(this.node);
  6204. },
  6205. createSVGNode: function() {
  6206. var node = svg.createNode("svg");
  6207. node.setAttribute("xmlns", "http://www.w3.org/2000/svg");
  6208. node.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
  6209. node.setAttribute("version", "1.1");
  6210. return node;
  6211. },
  6212. getNode: function() {
  6213. return this.node;
  6214. },
  6215. getContainer: function() {
  6216. return this.container;
  6217. },
  6218. getWidth: function() {
  6219. return this.node.clientWidth;
  6220. },
  6221. setWidth: function(width) {
  6222. this.node.setAttribute("width", width);
  6223. return this;
  6224. },
  6225. getHeight: function() {
  6226. return this.node.clientHeight;
  6227. },
  6228. setHeight: function(height) {
  6229. this.node.setAttribute("height", height);
  6230. return this;
  6231. },
  6232. setViewPort: function(cx, cy, zoom) {
  6233. var viewport, box;
  6234. if (arguments.length == 1) {
  6235. viewport = arguments[0];
  6236. cx = viewport.center.x;
  6237. cy = viewport.center.y;
  6238. zoom = viewport.zoom;
  6239. }
  6240. zoom = zoom || 1;
  6241. box = this.getViewBox();
  6242. var matrix = new Matrix();
  6243. var dx = box.x + box.width / 2 - cx, dy = box.y + box.height / 2 - cy;
  6244. matrix.translate(-cx, -cy);
  6245. matrix.scale(zoom);
  6246. matrix.translate(cx, cy);
  6247. matrix.translate(dx, dy);
  6248. this.shapeNode.setAttribute("transform", "matrix(" + matrix + ")");
  6249. this.viewport = {
  6250. center: {
  6251. x: cx,
  6252. y: cy
  6253. },
  6254. offset: {
  6255. x: dx,
  6256. y: dy
  6257. },
  6258. zoom: zoom
  6259. };
  6260. return this;
  6261. },
  6262. getViewPort: function() {
  6263. if (!this.viewport) {
  6264. var box = this.getViewBox();
  6265. return {
  6266. zoom: 1,
  6267. center: {
  6268. x: box.x + box.width / 2,
  6269. y: box.y + box.height / 2
  6270. },
  6271. offset: {
  6272. x: 0,
  6273. y: 0
  6274. }
  6275. };
  6276. }
  6277. return this.viewport;
  6278. },
  6279. getViewPortMatrix: function() {
  6280. return Matrix.parse(this.shapeNode.getAttribute("transform"));
  6281. },
  6282. getViewPortTransform: function() {
  6283. var m = this.shapeNode.getCTM();
  6284. return new Matrix(m.a, m.b, m.c, m.d, m.e, m.f);
  6285. },
  6286. getTransform: function() {
  6287. return this.getViewPortTransform().reverse();
  6288. },
  6289. addResource: function(resource) {
  6290. this.resources.appendItem(resource);
  6291. if (resource.node) {
  6292. this.resourceNode.appendChild(resource.node);
  6293. }
  6294. return this;
  6295. },
  6296. removeResource: function(resource) {
  6297. if (resource.remove) {
  6298. resource.remove();
  6299. }
  6300. if (resource.node) {
  6301. this.resourceNode.removeChild(resource.node);
  6302. }
  6303. return this;
  6304. },
  6305. getPaper: function() {
  6306. return this;
  6307. }
  6308. });
  6309. var Shape = _p.r(61);
  6310. Class.extendClass(Shape, {
  6311. getPaper: function() {
  6312. var parent = this.container;
  6313. while (parent && parent instanceof Paper === false) {
  6314. parent = parent.container;
  6315. }
  6316. return parent;
  6317. },
  6318. isAttached: function() {
  6319. return !!this.getPaper();
  6320. },
  6321. whenPaperReady: function(fn) {
  6322. var me = this;
  6323. function check() {
  6324. var paper = me.getPaper();
  6325. if (paper && fn) {
  6326. fn.call(me, paper);
  6327. }
  6328. return paper;
  6329. }
  6330. if (!check()) {
  6331. this.on("add treeadd", function listen() {
  6332. if (check()) {
  6333. me.off("add", listen);
  6334. me.off("treeadd", listen);
  6335. }
  6336. });
  6337. }
  6338. return this;
  6339. }
  6340. });
  6341. return Paper;
  6342. }
  6343. };
  6344. //src/graphic/path.js
  6345. _p[47] = {
  6346. value: function(require, exports, module) {
  6347. var Utils = _p.r(12);
  6348. var createClass = _p.r(11).createClass;
  6349. var Shape = _p.r(61);
  6350. var svg = _p.r(68);
  6351. var g = _p.r(35);
  6352. var slice = Array.prototype.slice, flatten = Utils.flatten;
  6353. var PathDrawer = createClass("PathDrawer", {
  6354. constructor: function(path) {
  6355. this.segment = [];
  6356. this.path = path;
  6357. this.__clear = false;
  6358. },
  6359. getPath: function() {
  6360. return this.path;
  6361. },
  6362. redraw: function() {
  6363. this._transation = this._transation || [];
  6364. return this.clear();
  6365. },
  6366. done: function() {
  6367. var transation = this._transation;
  6368. this._transation = null;
  6369. this.push(transation);
  6370. return this;
  6371. },
  6372. clear: function() {
  6373. if (this._transation) {
  6374. this._transation = [];
  6375. } else {
  6376. this.path.setPathData("M 0 0");
  6377. }
  6378. this._clear = true;
  6379. return this;
  6380. },
  6381. push: function() {
  6382. var segment = slice.call(arguments);
  6383. var originData;
  6384. if (this._transation) {
  6385. this._transation.push(segment);
  6386. return this;
  6387. }
  6388. if (this._clear) {
  6389. originData = "";
  6390. this._clear = false;
  6391. } else {
  6392. originData = this.path.getPathData();
  6393. }
  6394. originData = originData || "";
  6395. this.path.setPathData(originData + g.pathToString(segment));
  6396. return this;
  6397. },
  6398. moveTo: function(x, y) {
  6399. return this.push("M", slice.call(arguments));
  6400. },
  6401. moveBy: function(dx, dy) {
  6402. return this.push("m", slice.call(arguments));
  6403. },
  6404. lineTo: function(x, y) {
  6405. return this.push("L", slice.call(arguments));
  6406. },
  6407. lineBy: function(dx, dy) {
  6408. return this.push("l", slice.call(arguments));
  6409. },
  6410. arcTo: function(rx, ry, xr, laf, sf, x, y) {
  6411. return this.push("A", slice.call(arguments));
  6412. },
  6413. arcBy: function(rx, ry, xr, laf, sf, dx, dy) {
  6414. return this.push("a", arguments);
  6415. },
  6416. carcTo: function(r, laf, sf, x, y) {
  6417. return this.push("A", [ r, r, 0 ].concat(slice.call(arguments, 1)));
  6418. },
  6419. carcBy: function(r, laf, sf, dx, dy) {
  6420. return this.push("a", [ r, r, 0 ].concat(slice.call(arguments, 1)));
  6421. },
  6422. bezierTo: function(x1, y1, x2, y2, x, y) {
  6423. return this.push("C", slice.call(arguments));
  6424. },
  6425. bezierBy: function(dx1, dy1, dx2, dy2, dx, dy) {
  6426. return this.push("c", slice.call(arguments));
  6427. },
  6428. close: function() {
  6429. return this.push("z");
  6430. }
  6431. });
  6432. return createClass("Path", {
  6433. base: Shape,
  6434. constructor: function(data) {
  6435. this.callBase("path");
  6436. if (data) {
  6437. this.setPathData(data);
  6438. }
  6439. this.node.setAttribute("fill", svg.defaults.fill);
  6440. this.node.setAttribute("stroke", svg.defaults.stroke);
  6441. },
  6442. setPathData: function(data) {
  6443. data = data || "M0,0";
  6444. this.pathdata = g.pathToString(data);
  6445. this.node.setAttribute("d", this.pathdata);
  6446. this.trigger("shapeupdate", {
  6447. type: "pathdata"
  6448. });
  6449. return this;
  6450. },
  6451. getPathData: function() {
  6452. return this.pathdata || "";
  6453. },
  6454. getDrawer: function() {
  6455. return new PathDrawer(this);
  6456. },
  6457. isClosed: function() {
  6458. var data = this.getPathData();
  6459. return !!~data.indexOf("z") || !!~data.indexOf("Z");
  6460. }
  6461. });
  6462. }
  6463. };
  6464. //src/graphic/pattern.js
  6465. _p[48] = {
  6466. value: function(require, exports, module) {
  6467. var Resource = _p.r(59);
  6468. var ShapeContainer = _p.r(62);
  6469. var svg = _p.r(68);
  6470. return _p.r(11).createClass("PatternBrush", {
  6471. base: Resource,
  6472. mixins: [ ShapeContainer ],
  6473. constructor: function(paper) {
  6474. this.callBase("pattern", paper);
  6475. this.node.setAttribute("patternUnits", "userSpaceOnUse");
  6476. },
  6477. setX: function(x) {
  6478. this.x = x;
  6479. this.node.setAttribute("x", x);
  6480. return this;
  6481. },
  6482. setY: function(y) {
  6483. this.y = y;
  6484. this.node.setAttribute("y", y);
  6485. return this;
  6486. },
  6487. setWidth: function(width) {
  6488. this.width = width;
  6489. this.node.setAttribute("width", width);
  6490. return this;
  6491. },
  6492. setHeight: function(height) {
  6493. this.height = height;
  6494. this.node.setAttribute("height", height);
  6495. return this;
  6496. },
  6497. getWidth: function() {
  6498. return this.width;
  6499. },
  6500. getHeight: function() {
  6501. return this.height;
  6502. }
  6503. });
  6504. }
  6505. };
  6506. //src/graphic/pen.js
  6507. _p[49] = {
  6508. value: function(require, exports, module) {
  6509. var Color = _p.r(29);
  6510. return _p.r(11).createClass("Pen", {
  6511. constructor: function(brush, width) {
  6512. this.brush = brush;
  6513. this.width = width || 1;
  6514. this.linecap = null;
  6515. this.linejoin = null;
  6516. this.dashArray = null;
  6517. this.opacity = 1;
  6518. },
  6519. getBrush: function() {
  6520. return this.brush;
  6521. },
  6522. setBrush: function(brush) {
  6523. this.brush = brush;
  6524. return this;
  6525. },
  6526. setColor: function(color) {
  6527. return this.setBrush(color);
  6528. },
  6529. getColor: function() {
  6530. return this.brush instanceof Color ? this.brush : null;
  6531. },
  6532. getWidth: function() {
  6533. return this.width;
  6534. },
  6535. setWidth: function(width) {
  6536. this.width = width;
  6537. return this;
  6538. },
  6539. getOpacity: function() {
  6540. return this.opacity;
  6541. },
  6542. setOpacity: function(opacity) {
  6543. this.opacity = opacity;
  6544. },
  6545. getLineCap: function() {
  6546. return this.linecap;
  6547. },
  6548. setLineCap: function(linecap) {
  6549. this.linecap = linecap;
  6550. return this;
  6551. },
  6552. getLineJoin: function() {
  6553. return this.linejoin;
  6554. },
  6555. setLineJoin: function(linejoin) {
  6556. this.linejoin = linejoin;
  6557. return this;
  6558. },
  6559. getDashArray: function() {
  6560. return this.dashArray;
  6561. },
  6562. setDashArray: function(dashArray) {
  6563. this.dashArray = dashArray;
  6564. return this;
  6565. },
  6566. stroke: function(shape) {
  6567. var node = shape.node;
  6568. node.setAttribute("stroke", this.brush.toString());
  6569. node.setAttribute("stroke-width", this.getWidth());
  6570. if (this.getOpacity() < 1) {
  6571. node.setAttribute("stroke-opacity", this.getOpacity());
  6572. }
  6573. if (this.getLineCap()) {
  6574. node.setAttribute("stroke-linecap", this.getLineCap());
  6575. }
  6576. if (this.getLineJoin()) {
  6577. node.setAttribute("stroke-linejoin", this.getLineJoin());
  6578. }
  6579. if (this.getDashArray()) {
  6580. node.setAttribute("stroke-dasharray", this.getDashArray());
  6581. }
  6582. }
  6583. });
  6584. }
  6585. };
  6586. //src/graphic/pie.js
  6587. _p[50] = {
  6588. value: function(require, exports, module) {
  6589. return _p.r(11).createClass({
  6590. base: _p.r(69),
  6591. constructor: function(radius, angle, angleOffset) {
  6592. this.callBase([ 0, radius ], angle, angleOffset);
  6593. },
  6594. getRadius: function() {
  6595. return this.getSectionArray()[1];
  6596. },
  6597. setRadius: function(radius) {
  6598. this.setSectionArray([ 0, radius ]);
  6599. }
  6600. });
  6601. }
  6602. };
  6603. //src/graphic/point.js
  6604. /*
  6605. * 点对象抽象
  6606. */
  6607. _p[51] = {
  6608. value: function(require, exports, module) {
  6609. /**
  6610. * @class kity.Point
  6611. * @description 表示一个点
  6612. */
  6613. var Point = _p.r(11).createClass("Point", {
  6614. /**
  6615. * @constructor
  6616. * @for kity.Point
  6617. * @description 指定默认的 x 和 y 创建一个点
  6618. *
  6619. * @param {Number} x 点的 x 坐标
  6620. * @param {Number} y 点的 y 坐标
  6621. */
  6622. constructor: function(x, y) {
  6623. /**
  6624. * @property
  6625. * @for kity.Point
  6626. * @description 表示点的 x 坐标
  6627. * @type {Number}
  6628. */
  6629. this.x = x || 0;
  6630. /**
  6631. * @property
  6632. * @for kity.Point
  6633. * @description 表示点的 y 坐标
  6634. * @type {Number}
  6635. */
  6636. this.y = y || 0;
  6637. },
  6638. offset: function(dx, dy) {
  6639. if (arguments.length == 1) {
  6640. dy = dx.y;
  6641. dx = dx.x;
  6642. }
  6643. return new Point(this.x + dx, this.y + dy);
  6644. },
  6645. valueOf: function() {
  6646. return [ this.x, this.y ];
  6647. },
  6648. toString: function() {
  6649. return this.valueOf().join(" ");
  6650. },
  6651. spof: function() {
  6652. return new Point((this.x | 0) + .5, (this.y | 0) + .5);
  6653. },
  6654. round: function() {
  6655. return new Point(this.x | 0, this.y | 0);
  6656. },
  6657. isOrigin: function() {
  6658. return this.x === 0 && this.y === 0;
  6659. }
  6660. });
  6661. /**
  6662. * @static
  6663. * @method fromPolar()
  6664. * @for kity.Point
  6665. * @grammar kity.Point.fromPolar(radius, angle, unit) => kity.Point
  6666. * @param {Number} radius 极坐标中的半径
  6667. * @param {Number} angle 极坐标中的角度
  6668. * @param {String} unit 角度使用的单位,默认为 'deg' (角度),可以取值为 'rad',表示传入的是弧度值
  6669. */
  6670. Point.fromPolar = function(radius, angle, unit) {
  6671. if (unit != "rad") {
  6672. // deg to rad
  6673. angle = angle / 180 * Math.PI;
  6674. }
  6675. return new Point(radius * Math.cos(angle), radius * Math.sin(angle));
  6676. };
  6677. Point.parse = function(unknown) {
  6678. if (!unknown) return new Point();
  6679. if (unknown instanceof Point) {
  6680. return unknown;
  6681. }
  6682. if (typeof unknown == "string") {
  6683. return Point.parse(unknown.split(/\s*[\s,]\s*/));
  6684. }
  6685. if ("0" in unknown && "1" in unknown) {
  6686. return new Point(unknown[0], unknown[1]);
  6687. }
  6688. };
  6689. return Point;
  6690. }
  6691. };
  6692. //src/graphic/pointcontainer.js
  6693. /**
  6694. * 点集合容器
  6695. */
  6696. _p[52] = {
  6697. value: function(require, exports, module) {
  6698. return _p.r(11).createClass("PointContainer", {
  6699. base: _p.r(30),
  6700. constructor: function() {
  6701. this.callBase();
  6702. },
  6703. addPoint: function(point, pos) {
  6704. return this.addItem.apply(this, arguments);
  6705. },
  6706. prependPoint: function() {
  6707. return this.prependItem.apply(this, arguments);
  6708. },
  6709. appendPoint: function() {
  6710. return this.appendItem.apply(this, arguments);
  6711. },
  6712. removePoint: function(pos) {
  6713. return this.removeItem.apply(this, arguments);
  6714. },
  6715. addPoints: function() {
  6716. return this.addItems.apply(this, arguments);
  6717. },
  6718. setPoints: function() {
  6719. return this.setItems.apply(this, arguments);
  6720. },
  6721. getPoint: function() {
  6722. return this.getItem.apply(this, arguments);
  6723. },
  6724. getPoints: function() {
  6725. return this.getItems.apply(this, arguments);
  6726. },
  6727. getFirstPoint: function() {
  6728. return this.getFirstItem.apply(this, arguments);
  6729. },
  6730. getLastPoint: function() {
  6731. return this.getLastItem.apply(this, arguments);
  6732. }
  6733. });
  6734. }
  6735. };
  6736. //src/graphic/poly.js
  6737. /*
  6738. * 通过点来决定图形的公共父类
  6739. */
  6740. _p[53] = {
  6741. value: function(require, exports, module) {
  6742. var Utils = _p.r(12);
  6743. return _p.r(11).createClass("Poly", {
  6744. base: _p.r(47),
  6745. mixins: [ _p.r(52) ],
  6746. constructor: function(points, closeable) {
  6747. this.callBase();
  6748. //是否可闭合
  6749. this.closeable = !!closeable;
  6750. this.setPoints(points || []);
  6751. this.changeable = true;
  6752. this.update();
  6753. },
  6754. //当点集合发生变化时采取的动作
  6755. onContainerChanged: function() {
  6756. if (this.changeable) {
  6757. this.update();
  6758. }
  6759. },
  6760. update: function() {
  6761. var drawer = this.getDrawer(), points = this.getPoints();
  6762. drawer.clear();
  6763. if (!points.length) {
  6764. return this;
  6765. }
  6766. drawer.moveTo(points[0]);
  6767. for (var i = 1, point, len = points.length; i < len; i++) {
  6768. point = points[i];
  6769. drawer.lineTo(point);
  6770. }
  6771. if (this.closeable && points.length > 2) {
  6772. drawer.close();
  6773. }
  6774. return this;
  6775. }
  6776. });
  6777. }
  6778. };
  6779. //src/graphic/polygon.js
  6780. _p[54] = {
  6781. value: function(require, exports, module) {
  6782. return _p.r(11).createClass("Polygon", {
  6783. base: _p.r(53),
  6784. constructor: function(points) {
  6785. this.callBase(points, true);
  6786. }
  6787. });
  6788. }
  6789. };
  6790. //src/graphic/polyline.js
  6791. _p[55] = {
  6792. value: function(require, exports, module) {
  6793. return _p.r(11).createClass("Polyline", {
  6794. base: _p.r(53),
  6795. constructor: function(points) {
  6796. this.callBase(points);
  6797. }
  6798. });
  6799. }
  6800. };
  6801. //src/graphic/radialgradient.js
  6802. _p[56] = {
  6803. value: function(require, exports, module) {
  6804. var Gradient = _p.r(36);
  6805. return _p.r(11).createClass("RadialGradientBrush", {
  6806. base: Gradient,
  6807. constructor: function(paper) {
  6808. this.callBase("radialGradient", paper);
  6809. this.setCenter(.5, .5);
  6810. this.setFocal(.5, .5);
  6811. this.setRadius(.5);
  6812. },
  6813. setCenter: function(cx, cy) {
  6814. this.node.setAttribute("cx", cx);
  6815. this.node.setAttribute("cy", cy);
  6816. return this;
  6817. },
  6818. getCenter: function() {
  6819. return {
  6820. x: +this.node.getAttribute("cx"),
  6821. y: +this.node.getAttribute("cy")
  6822. };
  6823. },
  6824. setFocal: function(fx, fy) {
  6825. this.node.setAttribute("fx", fx);
  6826. this.node.setAttribute("fy", fy);
  6827. return this;
  6828. },
  6829. getFocal: function() {
  6830. return {
  6831. x: +this.node.getAttribute("fx"),
  6832. y: +this.node.getAttribute("fy")
  6833. };
  6834. },
  6835. setRadius: function(r) {
  6836. this.node.setAttribute("r", r);
  6837. return this;
  6838. },
  6839. getRadius: function() {
  6840. return +this.node.getAttribute("r");
  6841. }
  6842. });
  6843. }
  6844. };
  6845. //src/graphic/rect.js
  6846. _p[57] = {
  6847. value: function(require, exports, module) {
  6848. var RectUtils = {}, Utils = _p.r(12), Point = _p.r(51), Box = _p.r(26);
  6849. Utils.extend(RectUtils, {
  6850. //根据传递进来的width、height和radius属性,
  6851. //获取最适合的radius值
  6852. formatRadius: function(width, height, radius) {
  6853. var minValue = Math.floor(Math.min(width / 2, height / 2));
  6854. return Math.min(minValue, radius);
  6855. }
  6856. });
  6857. /**
  6858. * @class kity.Rect
  6859. * @description 表示一个矩形
  6860. * @base kity.Path
  6861. */
  6862. var Rect = _p.r(11).createClass("Rect", {
  6863. base: _p.r(47),
  6864. /**
  6865. * @constructor
  6866. * @for kity.Rect
  6867. * @grammar new kity.Rect(width, height, x, y, radius)
  6868. * @param {Number} width 矩形的初始化宽度
  6869. * @param {Number} height 矩形的初始化高度
  6870. * @param {Number} x 矩形的初始化 x 坐标
  6871. * @param {Number} y 矩形的初始化 y 坐标
  6872. * @param {Number} radius 矩形的初始化圆角大小
  6873. */
  6874. constructor: function(width, height, x, y, radius) {
  6875. this.callBase();
  6876. this.x = x || 0;
  6877. this.y = y || 0;
  6878. this.width = width || 0;
  6879. this.height = height || 0;
  6880. this.radius = RectUtils.formatRadius(this.width, this.height, radius || 0);
  6881. this.update();
  6882. },
  6883. update: function() {
  6884. var x = this.x, y = this.y, w = this.width, h = this.height, r = this.radius;
  6885. var drawer = this.getDrawer().redraw();
  6886. if (!r) {
  6887. // 直角
  6888. drawer.push("M", x, y);
  6889. drawer.push("h", w);
  6890. drawer.push("v", h);
  6891. drawer.push("h", -w);
  6892. drawer.push("z");
  6893. } else {
  6894. //圆角
  6895. w -= 2 * r;
  6896. h -= 2 * r;
  6897. drawer.push("M", x + r, y);
  6898. drawer.push("h", w);
  6899. drawer.push("a", r, r, 0, 0, 1, r, r);
  6900. drawer.push("v", h);
  6901. drawer.push("a", r, r, 0, 0, 1, -r, r);
  6902. drawer.push("h", -w);
  6903. drawer.push("a", r, r, 0, 0, 1, -r, -r);
  6904. drawer.push("v", -h);
  6905. drawer.push("a", r, r, 0, 0, 1, r, -r);
  6906. drawer.push("z");
  6907. }
  6908. drawer.done();
  6909. return this;
  6910. },
  6911. /**
  6912. * @method setWidth
  6913. * @for kity.Rect
  6914. * @grammar setWidth(width) => kity.Rect
  6915. * @description 设置矩形的宽度,设置后返回矩形实例本身
  6916. * @param {Number} width 宽度值
  6917. *
  6918. * @example
  6919. * ```js
  6920. * rect.setWidth(300);
  6921. * ```
  6922. */
  6923. setWidth: function(width) {
  6924. this.width = width;
  6925. return this.update();
  6926. },
  6927. /**
  6928. * @method setHeight
  6929. * @for kity.Rect
  6930. * @grammar setHeight(height) => kity.Rect
  6931. * @description 设置矩形的高度,设置后返回矩形实例本身
  6932. * @param {Number} height 高度值
  6933. *
  6934. * @example
  6935. * ```js
  6936. * rect.setHeight(200);
  6937. * ```
  6938. */
  6939. setHeight: function(height) {
  6940. this.height = height;
  6941. return this.update();
  6942. },
  6943. /**
  6944. * @method setSize
  6945. * @for kity.Rect
  6946. * @grammar setSize(width, height) => kity.Rect
  6947. * @description 设置矩形的尺寸,设置后返回矩形本身
  6948. * @param {Number} width 矩形的宽度值
  6949. * @param {Number} height 矩形的高度值
  6950. *
  6951. * @example
  6952. * ```js
  6953. * rect.setSize(300, 200);
  6954. * ```
  6955. */
  6956. setSize: function(width, height) {
  6957. this.width = width;
  6958. this.height = height;
  6959. return this.update();
  6960. },
  6961. /**
  6962. * @method setBox
  6963. * @for kity.Rect
  6964. * @grammar setBox(box) => kity.Rect
  6965. * @description 使用一个 kity 的盒子数据,
  6966. * @param {kity.Box} box 盒子数据
  6967. */
  6968. setBox: function(box) {
  6969. this.x = box.x;
  6970. this.y = box.y;
  6971. this.width = box.width;
  6972. this.height = box.height;
  6973. return this.update();
  6974. },
  6975. getBox: function() {
  6976. return new Box(this.x, this.y, this.width, this.height);
  6977. },
  6978. getRadius: function() {
  6979. return this.radius;
  6980. },
  6981. setRadius: function(radius) {
  6982. this.radius = RectUtils.formatRadius(this.width, this.height, radius || 0);
  6983. return this.update();
  6984. },
  6985. getPosition: function() {
  6986. return new Point(this.x, this.y);
  6987. },
  6988. setPosition: function(x, y) {
  6989. if (arguments.length == 1) {
  6990. var p = Point.parse(arguments[0]);
  6991. y = p.y;
  6992. x = p.x;
  6993. }
  6994. this.x = x;
  6995. this.y = y;
  6996. return this.update();
  6997. },
  6998. getWidth: function() {
  6999. return this.width;
  7000. },
  7001. getHeight: function() {
  7002. return this.height;
  7003. },
  7004. getPositionX: function() {
  7005. return this.x;
  7006. },
  7007. getPositionY: function() {
  7008. return this.y;
  7009. },
  7010. setPositionX: function(x) {
  7011. this.x = x;
  7012. return this.update();
  7013. },
  7014. setPositionY: function(y) {
  7015. this.y = y;
  7016. return this.update();
  7017. }
  7018. });
  7019. return Rect;
  7020. }
  7021. };
  7022. //src/graphic/regularpolygon.js
  7023. _p[58] = {
  7024. value: function(require, exports, module) {
  7025. var Point = _p.r(51);
  7026. return _p.r(11).createClass("RegularPolygon", {
  7027. base: _p.r(47),
  7028. constructor: function(side, radius, x, y) {
  7029. this.callBase();
  7030. this.radius = radius || 0;
  7031. this.side = Math.max(side || 3, 3);
  7032. if (arguments.length > 2) {
  7033. if (arguments.length == 3) {
  7034. y = x.y;
  7035. x = x.x;
  7036. }
  7037. }
  7038. this.center = new Point(x, y);
  7039. this.draw();
  7040. },
  7041. getSide: function() {
  7042. return this.side;
  7043. },
  7044. setSide: function(side) {
  7045. this.side = side;
  7046. return this.draw();
  7047. },
  7048. getRadius: function() {
  7049. return this.radius;
  7050. },
  7051. setRadius: function(radius) {
  7052. this.radius = radius;
  7053. return this.draw();
  7054. },
  7055. draw: function() {
  7056. var radius = this.radius, side = this.side, step = Math.PI * 2 / side, drawer = this.getDrawer(), i;
  7057. drawer.clear();
  7058. drawer.moveTo(Point.fromPolar(radius, Math.PI / 2, "rad").offset(this.center));
  7059. for (i = 0; i <= side; i++) {
  7060. drawer.lineTo(Point.fromPolar(radius, step * i + Math.PI / 2, "rad").offset(this.center));
  7061. }
  7062. drawer.close();
  7063. return this;
  7064. }
  7065. });
  7066. }
  7067. };
  7068. //src/graphic/resource.js
  7069. /**
  7070. * @fileOverview
  7071. *
  7072. * 资源节点基类
  7073. *
  7074. * @author: techird
  7075. * @copyright: Baidu FEX, 2014
  7076. */
  7077. _p[59] = {
  7078. value: function(require, exports, module) {
  7079. var svg = _p.r(68);
  7080. return _p.r(11).createClass("Resource", {
  7081. constructor: function(nodeType, paper) {
  7082. this.callBase();
  7083. this.node = svg.createNode(nodeType);
  7084. if (paper) {
  7085. paper.addResource(this);
  7086. }
  7087. },
  7088. toString: function() {
  7089. return "url(#" + this.node.id + ")";
  7090. }
  7091. });
  7092. }
  7093. };
  7094. //src/graphic/ring.js
  7095. _p[60] = {
  7096. value: function(require, exports, module) {
  7097. return _p.r(11).createClass({
  7098. base: _p.r(69),
  7099. constructor: function(innerRadius, outerRadius) {
  7100. this.callBase([ innerRadius, outerRadius ], 360, 0);
  7101. },
  7102. getInnerRadius: function() {
  7103. return this.getSectionArray()[0];
  7104. },
  7105. getOuterRadius: function() {
  7106. return this.getSectionArray()[1];
  7107. },
  7108. setInnerRadius: function(value) {
  7109. this.setSectionArray([ value, this.getOuterRadius() ]);
  7110. },
  7111. setOuterRadius: function(value) {
  7112. this.setSectionArray([ this.getInnerRadius(), value ]);
  7113. }
  7114. });
  7115. }
  7116. };
  7117. //src/graphic/shape.js
  7118. _p[61] = {
  7119. value: function(require, exports, module) {
  7120. var svg = _p.r(68);
  7121. var utils = _p.r(12);
  7122. var EventHandler = _p.r(34);
  7123. var Styled = _p.r(67);
  7124. var Data = _p.r(32);
  7125. var Matrix = _p.r(44);
  7126. var Pen = _p.r(49);
  7127. var slice = Array.prototype.slice;
  7128. var Box = _p.r(26);
  7129. var Shape = _p.r(11).createClass("Shape", {
  7130. mixins: [ EventHandler, Styled, Data ],
  7131. constructor: function Shape(tagName) {
  7132. this.node = svg.createNode(tagName);
  7133. this.node.shape = this;
  7134. this.transform = {
  7135. translate: null,
  7136. rotate: null,
  7137. scale: null,
  7138. matrix: null
  7139. };
  7140. this.callMixin();
  7141. },
  7142. getId: function() {
  7143. return this.node.id;
  7144. },
  7145. setId: function(id) {
  7146. this.node.id = id;
  7147. return this;
  7148. },
  7149. getNode: function() {
  7150. return this.node;
  7151. },
  7152. getBoundaryBox: function() {
  7153. var box;
  7154. try {
  7155. box = this.node.getBBox();
  7156. } catch (e) {
  7157. box = {
  7158. x: this.node.clientLeft,
  7159. y: this.node.clientTop,
  7160. width: this.node.clientWidth,
  7161. height: this.node.clientHeight
  7162. };
  7163. }
  7164. return new Box(box);
  7165. },
  7166. getRenderBox: function(refer) {
  7167. var box = this.getBoundaryBox();
  7168. var matrix = this.getTransform(refer);
  7169. return matrix.transformBox(box);
  7170. },
  7171. getWidth: function() {
  7172. return this.getRenderBox().width;
  7173. },
  7174. getHeight: function() {
  7175. return this.getRenderBox().height;
  7176. },
  7177. getSize: function() {
  7178. var box = this.getRenderBox();
  7179. delete box.x;
  7180. delete box.y;
  7181. return box;
  7182. },
  7183. setOpacity: function(value) {
  7184. this.node.setAttribute("opacity", value);
  7185. return this;
  7186. },
  7187. getOpacity: function() {
  7188. var opacity = this.node.getAttribute("opacity");
  7189. return opacity ? +opacity : 1;
  7190. },
  7191. setVisible: function(value) {
  7192. if (value) {
  7193. this.node.removeAttribute("display");
  7194. } else {
  7195. this.node.setAttribute("display", "none");
  7196. }
  7197. return this;
  7198. },
  7199. getVisible: function() {
  7200. this.node.getAttribute("display");
  7201. },
  7202. hasAncestor: function(node) {
  7203. var parent = this.container;
  7204. while (parent) {
  7205. if (parent === node) {
  7206. return true;
  7207. }
  7208. parent = parent.container;
  7209. }
  7210. return false;
  7211. },
  7212. getTransform: function(refer) {
  7213. return Matrix.getCTM(this, refer);
  7214. },
  7215. clearTransform: function() {
  7216. this.node.removeAttribute("transform");
  7217. this.transform = {
  7218. translate: null,
  7219. rotate: null,
  7220. scale: null,
  7221. matrix: null
  7222. };
  7223. this.trigger("shapeupdate", {
  7224. type: "transform"
  7225. });
  7226. return this;
  7227. },
  7228. _applyTransform: function() {
  7229. var t = this.transform, result = [];
  7230. if (t.translate) {
  7231. result.push([ "translate(", t.translate, ")" ]);
  7232. }
  7233. if (t.rotate) {
  7234. result.push([ "rotate(", t.rotate, ")" ]);
  7235. }
  7236. if (t.scale) {
  7237. result.push([ "scale(", t.scale, ")" ]);
  7238. }
  7239. if (t.matrix) {
  7240. result.push([ "matrix(", t.matrix, ")" ]);
  7241. }
  7242. this.node.setAttribute("transform", utils.flatten(result).join(" "));
  7243. return this;
  7244. },
  7245. setMatrix: function(m) {
  7246. this.transform.matrix = m;
  7247. return this._applyTransform();
  7248. },
  7249. setTranslate: function(t) {
  7250. this.transform.translate = t !== null && slice.call(arguments) || null;
  7251. return this._applyTransform();
  7252. },
  7253. setRotate: function(r) {
  7254. this.transform.rotate = r !== null && slice.call(arguments) || null;
  7255. return this._applyTransform();
  7256. },
  7257. setScale: function(s) {
  7258. this.transform.scale = s !== null && slice.call(arguments) || null;
  7259. return this._applyTransform();
  7260. },
  7261. translate: function(dx, dy) {
  7262. var m = this.transform.matrix || new Matrix();
  7263. if (dy === undefined) {
  7264. dy = 0;
  7265. }
  7266. this.transform.matrix = m.translate(dx, dy);
  7267. return this._applyTransform();
  7268. },
  7269. rotate: function(deg) {
  7270. var m = this.transform.matrix || new Matrix();
  7271. this.transform.matrix = m.rotate(deg);
  7272. return this._applyTransform();
  7273. },
  7274. scale: function(sx, sy) {
  7275. var m = this.transform.matrix || new Matrix();
  7276. if (sy === undefined) {
  7277. sy = sx;
  7278. }
  7279. this.transform.matrix = m.scale(sx, sy);
  7280. return this._applyTransform();
  7281. },
  7282. skew: function(sx, sy) {
  7283. var m = this.transform.matrix || new Matrix();
  7284. if (sy === undefined) {
  7285. sy = sx;
  7286. }
  7287. this.transform.matrix = m.skew(sx, sy);
  7288. return this._applyTransform();
  7289. },
  7290. stroke: function(pen, width) {
  7291. if (pen && pen.stroke) {
  7292. pen.stroke(this);
  7293. } else if (pen) {
  7294. // 字符串或重写了 toString 的对象
  7295. this.node.setAttribute("stroke", pen.toString());
  7296. if (width) {
  7297. this.node.setAttribute("stroke-width", width);
  7298. }
  7299. } else if (pen === null) {
  7300. this.node.removeAttribute("stroe");
  7301. }
  7302. return this;
  7303. },
  7304. fill: function(brush) {
  7305. // 字符串或重写了 toString 的对象
  7306. if (brush) {
  7307. this.node.setAttribute("fill", brush.toString());
  7308. }
  7309. if (brush === null) {
  7310. this.node.removeAttribute("fill");
  7311. }
  7312. return this;
  7313. },
  7314. setAttr: function(a, v) {
  7315. var me = this;
  7316. if (utils.isObject(a)) {
  7317. utils.each(a, function(val, key) {
  7318. me.setAttr(key, val);
  7319. });
  7320. }
  7321. if (v === undefined || v === null || v === "") {
  7322. this.node.removeAttribute(a);
  7323. } else {
  7324. this.node.setAttribute(a, v);
  7325. }
  7326. return this;
  7327. },
  7328. getAttr: function(a) {
  7329. return this.node.getAttribute(a);
  7330. }
  7331. });
  7332. return Shape;
  7333. }
  7334. };
  7335. //src/graphic/shapecontainer.js
  7336. _p[62] = {
  7337. value: function(require, exports, module) {
  7338. var Container = _p.r(30);
  7339. var utils = _p.r(12);
  7340. var ShapeContainer = _p.r(11).createClass("ShapeContainer", {
  7341. base: Container,
  7342. isShapeContainer: true,
  7343. /* private */
  7344. handleAdd: function(shape, index) {
  7345. var parent = this.getShapeNode();
  7346. parent.insertBefore(shape.node, parent.childNodes[index] || null);
  7347. shape.trigger("add", {
  7348. container: this
  7349. });
  7350. if (shape.notifyTreeModification) {
  7351. shape.notifyTreeModification("treeadd", this);
  7352. }
  7353. },
  7354. /* private */
  7355. handleRemove: function(shape, index) {
  7356. var parent = this.getShapeNode();
  7357. parent.removeChild(shape.node);
  7358. shape.trigger("remove", {
  7359. container: this
  7360. });
  7361. if (shape.notifyTreeModification) {
  7362. shape.notifyTreeModification("treeremove", this);
  7363. }
  7364. },
  7365. /* private */
  7366. notifyTreeModification: function(type, container) {
  7367. this.eachItem(function(index, shape) {
  7368. if (shape.notifyTreeModification) {
  7369. shape.notifyTreeModification(type, container);
  7370. }
  7371. shape.trigger(type, {
  7372. container: container
  7373. });
  7374. });
  7375. },
  7376. /* public */
  7377. getShape: function(index) {
  7378. return this.getItem(index);
  7379. },
  7380. /* public */
  7381. addShape: function(shape, index) {
  7382. return this.addItem(shape, index);
  7383. },
  7384. put: function(shape) {
  7385. this.addShape(shape);
  7386. return shape;
  7387. },
  7388. appendShape: function(shape) {
  7389. return this.addShape(shape);
  7390. },
  7391. prependShape: function(shape) {
  7392. return this.addShape(shape, 0);
  7393. },
  7394. replaceShape: function(replacer, origin) {
  7395. var index = this.indexOf(origin);
  7396. if (index === -1) {
  7397. return;
  7398. }
  7399. this.removeShape(index);
  7400. this.addShape(replacer, index);
  7401. return this;
  7402. },
  7403. addShapeBefore: function(shape, refer) {
  7404. var index = this.indexOf(refer);
  7405. return this.addShape(shape, index);
  7406. },
  7407. addShapeAfter: function(shape, refer) {
  7408. var index = this.indexOf(refer);
  7409. return this.addShape(shape, index === -1 ? undefined : index + 1);
  7410. },
  7411. /* public */
  7412. addShapes: function(shapes) {
  7413. return this.addItems(shapes);
  7414. },
  7415. /* public */
  7416. removeShape: function(index) {
  7417. return this.removeItem(index);
  7418. },
  7419. getShapes: function() {
  7420. return this.getItems();
  7421. },
  7422. getShapesByType: function(name) {
  7423. var shapes = [];
  7424. function getShapes(shape) {
  7425. if (name.toLowerCase() == shape.getType().toLowerCase()) {
  7426. shapes.push(shape);
  7427. }
  7428. if (shape.isShapeContainer) {
  7429. utils.each(shape.getShapes(), function(n) {
  7430. getShapes(n);
  7431. });
  7432. }
  7433. }
  7434. getShapes(this);
  7435. return shapes;
  7436. },
  7437. /* public */
  7438. getShapeById: function(id) {
  7439. return this.getShapeNode().getElementById(id).shape;
  7440. },
  7441. arrangeShape: function(shape, index) {
  7442. return this.removeShape(shape).addShape(shape, index);
  7443. },
  7444. /* protected */
  7445. getShapeNode: function() {
  7446. return this.shapeNode || this.node;
  7447. }
  7448. });
  7449. var Shape = _p.r(61);
  7450. _p.r(11).extendClass(Shape, {
  7451. bringTo: function(index) {
  7452. this.container.arrangeShape(this, index);
  7453. return this;
  7454. },
  7455. bringFront: function() {
  7456. return this.bringTo(this.container.indexOf(this) + 1);
  7457. },
  7458. bringBack: function() {
  7459. return this.bringTo(this.container.indexOf(this) - 1);
  7460. },
  7461. bringTop: function() {
  7462. this.container.removeShape(this).addShape(this);
  7463. return this;
  7464. },
  7465. bringRear: function() {
  7466. return this.bringTo(0);
  7467. },
  7468. bringRefer: function(referShape, offset) {
  7469. if (referShape.container) {
  7470. if (this.remove) {
  7471. this.remove();
  7472. }
  7473. referShape.container.addShape(this, referShape.container.indexOf(referShape) + (offset || 0));
  7474. }
  7475. return this;
  7476. },
  7477. bringAbove: function(referShape) {
  7478. return this.bringRefer(referShape);
  7479. },
  7480. bringBelow: function(referShape) {
  7481. return this.bringRefer(referShape, 1);
  7482. },
  7483. replaceBy: function(newShape) {
  7484. if (this.container) {
  7485. newShape.bringAbove(this);
  7486. this.remove();
  7487. }
  7488. return this;
  7489. }
  7490. });
  7491. return ShapeContainer;
  7492. }
  7493. };
  7494. //src/graphic/shapeevent.js
  7495. /*
  7496. * 图形事件包装类
  7497. * */
  7498. _p[63] = {
  7499. value: function(require, exprots, module) {
  7500. var Matrix = _p.r(44), Utils = _p.r(12), Point = _p.r(51);
  7501. return _p.r(11).createClass("ShapeEvent", {
  7502. constructor: function(event) {
  7503. var target = null;
  7504. // dom 事件封装对象
  7505. if (!Utils.isObject(event.target)) {
  7506. this.type = event.type;
  7507. target = event.target;
  7508. // use标签有特殊属性, 需要区别对待
  7509. if (target.correspondingUseElement) {
  7510. target = target.correspondingUseElement;
  7511. }
  7512. this.originEvent = event;
  7513. this.targetShape = target.shape || target.paper || event.currentTarget && (event.currentTarget.shape || event.currentTarget.paper);
  7514. if (event._kityParam) {
  7515. Utils.extend(this, event._kityParam);
  7516. }
  7517. } else {
  7518. Utils.extend(this, event);
  7519. }
  7520. },
  7521. preventDefault: function() {
  7522. var evt = this.originEvent;
  7523. if (!evt) {
  7524. return true;
  7525. }
  7526. if (evt.preventDefault) {
  7527. evt.preventDefault();
  7528. return evt.cancelable;
  7529. } else {
  7530. evt.returnValue = false;
  7531. return true;
  7532. }
  7533. },
  7534. //当前鼠标事件在用户坐标系中点击的点的坐标位置
  7535. getPosition: function(refer, touchIndex) {
  7536. if (!this.originEvent) {
  7537. return null;
  7538. }
  7539. var eventClient = this.originEvent.touches ? this.originEvent.touches[touchIndex || 0] : this.originEvent;
  7540. var target = this.targetShape;
  7541. var targetNode = target.shapeNode || target.node;
  7542. var pScreen = new Point(eventClient && eventClient.clientX || 0, eventClient && eventClient.clientY || 0);
  7543. var pTarget = Matrix.transformPoint(pScreen, targetNode.getScreenCTM().inverse());
  7544. var pRefer = Matrix.getCTM(target, refer || "view").transformPoint(pTarget);
  7545. return pRefer;
  7546. },
  7547. stopPropagation: function() {
  7548. var evt = this.originEvent;
  7549. if (!evt) {
  7550. return true;
  7551. }
  7552. if (evt.stopPropagation) {
  7553. evt.stopPropagation();
  7554. } else {
  7555. evt.cancelBubble = false;
  7556. }
  7557. }
  7558. });
  7559. }
  7560. };
  7561. //src/graphic/shapepoint.js
  7562. /*
  7563. * 图形上的点抽象
  7564. */
  7565. _p[64] = {
  7566. value: function(require, exports, module) {
  7567. return _p.r(11).createClass("ShapePoint", {
  7568. base: _p.r(51),
  7569. constructor: function(px, py) {
  7570. this.callBase(px, py);
  7571. },
  7572. setX: function(x) {
  7573. return this.setPoint(x, this.y);
  7574. },
  7575. setY: function(y) {
  7576. return this.setPoint(this.x, y);
  7577. },
  7578. setPoint: function(x, y) {
  7579. this.x = x;
  7580. this.y = y;
  7581. this.update();
  7582. return this;
  7583. },
  7584. getPoint: function() {
  7585. return this;
  7586. },
  7587. update: function() {
  7588. if (this.container && this.container.update) {
  7589. this.container.update();
  7590. }
  7591. return this;
  7592. }
  7593. });
  7594. }
  7595. };
  7596. //src/graphic/standardcolor.js
  7597. /**
  7598. * 标准颜色映射
  7599. */
  7600. _p[65] = {
  7601. value: {
  7602. COLOR_STANDARD: {
  7603. aliceblue: "#f0f8ff",
  7604. antiquewhite: "#faebd7",
  7605. aqua: "#00ffff",
  7606. aquamarine: "#7fffd4",
  7607. azure: "#f0ffff",
  7608. beige: "#f5f5dc",
  7609. bisque: "#ffe4c4",
  7610. black: "#000000",
  7611. blanchedalmond: "#ffebcd",
  7612. blue: "#0000ff",
  7613. blueviolet: "#8a2be2",
  7614. brown: "#a52a2a",
  7615. burlywood: "#deb887",
  7616. cadetblue: "#5f9ea0",
  7617. chartreuse: "#7fff00",
  7618. chocolate: "#d2691e",
  7619. coral: "#ff7f50",
  7620. cornflowerblue: "#6495ed",
  7621. cornsilk: "#fff8dc",
  7622. crimson: "#dc143c",
  7623. cyan: "#00ffff",
  7624. darkblue: "#00008b",
  7625. darkcyan: "#008b8b",
  7626. darkgoldenrod: "#b8860b",
  7627. darkgray: "#a9a9a9",
  7628. darkgreen: "#006400",
  7629. darkgrey: "#a9a9a9",
  7630. darkkhaki: "#bdb76b",
  7631. darkmagenta: "#8b008b",
  7632. darkolivegreen: "#556b2f",
  7633. darkorange: "#ff8c00",
  7634. darkorchid: "#9932cc",
  7635. darkred: "#8b0000",
  7636. darksalmon: "#e9967a",
  7637. darkseagreen: "#8fbc8f",
  7638. darkslateblue: "#483d8b",
  7639. darkslategray: "#2f4f4f",
  7640. darkslategrey: "#2f4f4f",
  7641. darkturquoise: "#00ced1",
  7642. darkviolet: "#9400d3",
  7643. deeppink: "#ff1493",
  7644. deepskyblue: "#00bfff",
  7645. dimgray: "#696969",
  7646. dimgrey: "#696969",
  7647. dodgerblue: "#1e90ff",
  7648. firebrick: "#b22222",
  7649. floralwhite: "#fffaf0",
  7650. forestgreen: "#228b22",
  7651. fuchsia: "#ff00ff",
  7652. gainsboro: "#dcdcdc",
  7653. ghostwhite: "#f8f8ff",
  7654. gold: "#ffd700",
  7655. goldenrod: "#daa520",
  7656. gray: "#808080",
  7657. green: "#008000",
  7658. greenyellow: "#adff2f",
  7659. grey: "#808080",
  7660. honeydew: "#f0fff0",
  7661. hotpink: "#ff69b4",
  7662. indianred: "#cd5c5c",
  7663. indigo: "#4b0082",
  7664. ivory: "#fffff0",
  7665. khaki: "#f0e68c",
  7666. lavender: "#e6e6fa",
  7667. lavenderblush: "#fff0f5",
  7668. lawngreen: "#7cfc00",
  7669. lemonchiffon: "#fffacd",
  7670. lightblue: "#add8e6",
  7671. lightcoral: "#f08080",
  7672. lightcyan: "#e0ffff",
  7673. lightgoldenrodyellow: "#fafad2",
  7674. lightgray: "#d3d3d3",
  7675. lightgreen: "#90ee90",
  7676. lightgrey: "#d3d3d3",
  7677. lightpink: "#ffb6c1",
  7678. lightsalmon: "#ffa07a",
  7679. lightseagreen: "#20b2aa",
  7680. lightskyblue: "#87cefa",
  7681. lightslategray: "#778899",
  7682. lightslategrey: "#778899",
  7683. lightsteelblue: "#b0c4de",
  7684. lightyellow: "#ffffe0",
  7685. lime: "#00ff00",
  7686. limegreen: "#32cd32",
  7687. linen: "#faf0e6",
  7688. magenta: "#ff00ff",
  7689. maroon: "#800000",
  7690. mediumaquamarine: "#66cdaa",
  7691. mediumblue: "#0000cd",
  7692. mediumorchid: "#ba55d3",
  7693. mediumpurple: "#9370db",
  7694. mediumseagreen: "#3cb371",
  7695. mediumslateblue: "#7b68ee",
  7696. mediumspringgreen: "#00fa9a",
  7697. mediumturquoise: "#48d1cc",
  7698. mediumvioletred: "#c71585",
  7699. midnightblue: "#191970",
  7700. mintcream: "#f5fffa",
  7701. mistyrose: "#ffe4e1",
  7702. moccasin: "#ffe4b5",
  7703. navajowhite: "#ffdead",
  7704. navy: "#000080",
  7705. oldlace: "#fdf5e6",
  7706. olive: "#808000",
  7707. olivedrab: "#6b8e23",
  7708. orange: "#ffa500",
  7709. orangered: "#ff4500",
  7710. orchid: "#da70d6",
  7711. palegoldenrod: "#eee8aa",
  7712. palegreen: "#98fb98",
  7713. paleturquoise: "#afeeee",
  7714. palevioletred: "#db7093",
  7715. papayawhip: "#ffefd5",
  7716. peachpuff: "#ffdab9",
  7717. peru: "#cd853f",
  7718. pink: "#ffc0cb",
  7719. plum: "#dda0dd",
  7720. powderblue: "#b0e0e6",
  7721. purple: "#800080",
  7722. red: "#ff0000",
  7723. rosybrown: "#bc8f8f",
  7724. royalblue: "#4169e1",
  7725. saddlebrown: "#8b4513",
  7726. salmon: "#fa8072",
  7727. sandybrown: "#f4a460",
  7728. seagreen: "#2e8b57",
  7729. seashell: "#fff5ee",
  7730. sienna: "#a0522d",
  7731. silver: "#c0c0c0",
  7732. skyblue: "#87ceeb",
  7733. slateblue: "#6a5acd",
  7734. slategray: "#708090",
  7735. slategrey: "#708090",
  7736. snow: "#fffafa",
  7737. springgreen: "#00ff7f",
  7738. steelblue: "#4682b4",
  7739. tan: "#d2b48c",
  7740. teal: "#008080",
  7741. thistle: "#d8bfd8",
  7742. tomato: "#ff6347",
  7743. turquoise: "#40e0d0",
  7744. violet: "#ee82ee",
  7745. wheat: "#f5deb3",
  7746. white: "#ffffff",
  7747. whitesmoke: "#f5f5f5",
  7748. yellow: "#ffff00"
  7749. },
  7750. //标准扩展
  7751. EXTEND_STANDARD: {}
  7752. }
  7753. };
  7754. //src/graphic/star.js
  7755. _p[66] = {
  7756. value: function(require, exports, module) {
  7757. /**
  7758. * @see http://www.jdawiseman.com/papers/easymath/surds_star_inner_radius.html
  7759. */
  7760. var defaultRatioForStar = {
  7761. "3": .2,
  7762. // yy
  7763. "5": .38196601125,
  7764. "6": .57735026919,
  7765. "8": .541196100146,
  7766. "10": .726542528005,
  7767. "12": .707106781187
  7768. };
  7769. var Point = _p.r(51);
  7770. return _p.r(11).createClass("Star", {
  7771. base: _p.r(47),
  7772. constructor: function(vertex, radius, shrink, offset, angleOffset) {
  7773. this.callBase();
  7774. this.vertex = vertex || 3;
  7775. this.radius = radius || 0;
  7776. this.shrink = shrink;
  7777. this.offset = offset || new Point(0, 0);
  7778. this.angleOffset = angleOffset || 0;
  7779. this.draw();
  7780. },
  7781. getVertex: function() {
  7782. return this.vertex;
  7783. },
  7784. setVertex: function(value) {
  7785. this.vertex = value;
  7786. return this.draw();
  7787. },
  7788. getRadius: function() {
  7789. return this.radius;
  7790. },
  7791. setRadius: function(value) {
  7792. this.radius = value;
  7793. return this.draw();
  7794. },
  7795. getShrink: function() {
  7796. return this.shrink;
  7797. },
  7798. setShrink: function(value) {
  7799. this.shrink = value;
  7800. return this.draw();
  7801. },
  7802. getOffset: function() {
  7803. return this.offset;
  7804. },
  7805. setOffset: function(value) {
  7806. this.offset = value;
  7807. return this.draw();
  7808. },
  7809. getAngleOffset: function() {
  7810. return this.angleOffset;
  7811. },
  7812. setAngleOffset: function(value) {
  7813. this.angleOffset = value;
  7814. return this.draw();
  7815. },
  7816. draw: function() {
  7817. var innerRadius = this.radius, outerRadius = this.radius * (this.shrink || defaultRatioForStar[this.vertex] || .5), vertex = this.vertex, offset = this.offset, angleStart = 90, angleStep = 180 / vertex, angleOffset = this.angleOffset, drawer = this.getDrawer(), i, angle;
  7818. drawer.clear();
  7819. drawer.moveTo(Point.fromPolar(outerRadius, angleStart));
  7820. for (i = 1; i <= vertex * 2; i++) {
  7821. angle = angleStart + angleStep * i;
  7822. // 绘制内点
  7823. if (i % 2) {
  7824. drawer.lineTo(Point.fromPolar(innerRadius, angle + angleOffset).offset(offset));
  7825. } else {
  7826. drawer.lineTo(Point.fromPolar(outerRadius, angle));
  7827. }
  7828. }
  7829. drawer.close();
  7830. }
  7831. });
  7832. }
  7833. };
  7834. //src/graphic/styled.js
  7835. _p[67] = {
  7836. value: function(require, exports, module) {
  7837. // polyfill for ie
  7838. var ClassList = _p.r(11).createClass("ClassList", {
  7839. constructor: function(node) {
  7840. this._node = node;
  7841. this._list = node.className.toString().split(" ");
  7842. },
  7843. _update: function() {
  7844. this._node.className = this._list.join(" ");
  7845. },
  7846. add: function(name) {
  7847. this._list.push(name);
  7848. this._update();
  7849. },
  7850. remove: function(name) {
  7851. var index = this._list.indexOf(name);
  7852. if (~index) {
  7853. this._list.splice(index, 1);
  7854. }
  7855. this._update();
  7856. },
  7857. contains: function(name) {
  7858. return !!~this._list.indexOf(name);
  7859. }
  7860. });
  7861. function getClassList(node) {
  7862. if (!node.classList) {
  7863. node.classList = new ClassList(node);
  7864. }
  7865. return node.classList;
  7866. }
  7867. return _p.r(11).createClass("Styled", {
  7868. addClass: function(name) {
  7869. getClassList(this.node).add(name);
  7870. return this;
  7871. },
  7872. removeClass: function(name) {
  7873. getClassList(this.node).remove(name);
  7874. return this;
  7875. },
  7876. hasClass: function(name) {
  7877. return getClassList(this.node).contains(name);
  7878. },
  7879. setStyle: function(styles) {
  7880. if (arguments.length == 2) {
  7881. this.node.style[arguments[0]] = arguments[1];
  7882. return this;
  7883. }
  7884. for (var name in styles) {
  7885. if (styles.hasOwnProperty(name)) {
  7886. this.node.style[name] = styles[name];
  7887. }
  7888. }
  7889. return this;
  7890. }
  7891. });
  7892. }
  7893. };
  7894. //src/graphic/svg.js
  7895. _p[68] = {
  7896. value: function(require, exports, module) {
  7897. var doc = document;
  7898. var id = 0;
  7899. var svg = {
  7900. createNode: function(name) {
  7901. var node = doc.createElementNS(svg.ns, name);
  7902. node.id = "kity_" + name + "_" + id++;
  7903. return node;
  7904. },
  7905. defaults: {
  7906. stroke: "none",
  7907. fill: "none"
  7908. },
  7909. xlink: "http://www.w3.org/1999/xlink",
  7910. ns: "http://www.w3.org/2000/svg"
  7911. };
  7912. return svg;
  7913. }
  7914. };
  7915. //src/graphic/sweep.js
  7916. _p[69] = {
  7917. value: function(require, exports, module) {
  7918. var Point = _p.r(51);
  7919. return _p.r(11).createClass("Sweep", {
  7920. base: _p.r(47),
  7921. constructor: function(sectionArray, angle, angleOffset) {
  7922. this.callBase();
  7923. this.sectionArray = sectionArray || [];
  7924. this.angle = angle || 0;
  7925. this.angleOffset = angleOffset || 0;
  7926. this.draw();
  7927. },
  7928. getSectionArray: function() {
  7929. return this.sectionArray;
  7930. },
  7931. setSectionArray: function(value) {
  7932. this.sectionArray = value;
  7933. return this.draw();
  7934. },
  7935. getAngle: function() {
  7936. return this.angle;
  7937. },
  7938. setAngle: function(value) {
  7939. this.angle = value;
  7940. return this.draw();
  7941. },
  7942. getAngleOffset: function() {
  7943. return this.angleOffset;
  7944. },
  7945. setAngleOffset: function(value) {
  7946. this.angleOffset = value;
  7947. return this.draw();
  7948. },
  7949. draw: function() {
  7950. var sectionArray = this.sectionArray, i;
  7951. for (i = 0; i < sectionArray.length; i += 2) {
  7952. this.drawSection(sectionArray[i], sectionArray[i + 1]);
  7953. }
  7954. return this;
  7955. },
  7956. drawSection: function(from, to) {
  7957. var angleLength = this.angle && (this.angle % 360 ? this.angle % 360 : 360), angleStart = this.angleOffset, angleHalf = angleStart + angleLength / 2, angleEnd = angleStart + angleLength, sweepFlag = angleLength < 0 ? 0 : 1, drawer = this.getDrawer();
  7958. drawer.redraw();
  7959. if (angleLength === 0) {
  7960. drawer.done();
  7961. return;
  7962. }
  7963. drawer.moveTo(Point.fromPolar(from, angleStart));
  7964. drawer.lineTo(Point.fromPolar(to, angleStart));
  7965. if (to) {
  7966. drawer.carcTo(to, 0, sweepFlag, Point.fromPolar(to, angleHalf));
  7967. drawer.carcTo(to, 0, sweepFlag, Point.fromPolar(to, angleEnd));
  7968. }
  7969. drawer.lineTo(Point.fromPolar(from, angleEnd));
  7970. if (from) {
  7971. drawer.carcTo(from, 0, sweepFlag, Point.fromPolar(from, angleHalf));
  7972. drawer.carcTo(from, 0, sweepFlag, Point.fromPolar(from, angleStart));
  7973. }
  7974. drawer.close();
  7975. drawer.done();
  7976. }
  7977. });
  7978. }
  7979. };
  7980. //src/graphic/text.js
  7981. _p[70] = {
  7982. value: function(require, exports, module) {
  7983. var TextContent = _p.r(71);
  7984. var ShapeContainer = _p.r(62);
  7985. var svg = _p.r(68);
  7986. var utils = _p.r(12);
  7987. var offsetHash = {};
  7988. function getTextBoundOffset(text) {
  7989. var font = text._cachedFontHash;
  7990. if (offsetHash[font]) {
  7991. return offsetHash[font];
  7992. }
  7993. var textContent = text.getContent();
  7994. text.setContent("百度Fex");
  7995. var bbox = text.getBoundaryBox(), y = text.getY();
  7996. if (!bbox.height) return {
  7997. top: 0,
  7998. bottom: 0,
  7999. middle: 0
  8000. };
  8001. var topOffset = y - bbox.y + +text.node.getAttribute("dy"), bottomOffset = topOffset - bbox.height;
  8002. text.setContent(textContent);
  8003. return offsetHash[font] = {
  8004. top: topOffset,
  8005. bottom: bottomOffset,
  8006. middle: (topOffset + bottomOffset) / 2
  8007. };
  8008. }
  8009. return _p.r(11).createClass("Text", {
  8010. base: TextContent,
  8011. mixins: [ ShapeContainer ],
  8012. constructor: function(content) {
  8013. this.callBase("text");
  8014. if (content !== undefined) {
  8015. this.setContent(content);
  8016. }
  8017. this._buildFontHash();
  8018. },
  8019. fixPosition: function() {
  8020. if (!this.__fixedPosition) {
  8021. this.setVerticalAlign(this.getVerticalAlign());
  8022. }
  8023. },
  8024. _buildFontHash: function() {
  8025. var style = window.getComputedStyle(this.node);
  8026. this._cachedFontHash = [ style.fontFamily, style.fontSize, style.fontStretch, style.fontStyle, style.fontVariant, style.fontWeight ].join("-");
  8027. },
  8028. _fontChanged: function(font) {
  8029. var last = this._lastFont;
  8030. var current = utils.extend({}, last, font);
  8031. if (!last) {
  8032. this._lastFont = font;
  8033. return true;
  8034. }
  8035. var changed = last.family != current.family || last.size != current.size || last.style != current.style || last.weight != current.weight;
  8036. this._lastFont = current;
  8037. return changed;
  8038. },
  8039. setX: function(x) {
  8040. this.node.setAttribute("x", x);
  8041. return this;
  8042. },
  8043. setPosition: function(x, y) {
  8044. return this.setX(x).setY(y);
  8045. },
  8046. setY: function(y) {
  8047. this.node.setAttribute("y", y);
  8048. return this;
  8049. },
  8050. getX: function() {
  8051. return +this.node.getAttribute("x") || 0;
  8052. },
  8053. getY: function() {
  8054. return +this.node.getAttribute("y") || 0;
  8055. },
  8056. setFont: function(font) {
  8057. this.callBase(font);
  8058. if (this._fontChanged(font)) {
  8059. this._buildFontHash();
  8060. this.setVerticalAlign(this.getVerticalAlign());
  8061. }
  8062. return this;
  8063. },
  8064. setTextAnchor: function(anchor) {
  8065. this.node.setAttribute("text-anchor", anchor);
  8066. return this;
  8067. },
  8068. getTextAnchor: function() {
  8069. return this.node.getAttribute("text-anchor") || "start";
  8070. },
  8071. // top/bottom/middle/baseline
  8072. setVerticalAlign: function(align) {
  8073. this.whenPaperReady(function() {
  8074. var dy;
  8075. switch (align) {
  8076. case "top":
  8077. dy = getTextBoundOffset(this).top;
  8078. break;
  8079. case "bottom":
  8080. dy = getTextBoundOffset(this).bottom;
  8081. break;
  8082. case "middle":
  8083. dy = getTextBoundOffset(this).middle;
  8084. break;
  8085. default:
  8086. dy = 0;
  8087. }
  8088. if (dy) this.__fixedPosition = true;
  8089. this.node.setAttribute("dy", dy);
  8090. });
  8091. this.verticalAlign = align;
  8092. return this;
  8093. },
  8094. getVerticalAlign: function() {
  8095. return this.verticalAlign || "baseline";
  8096. },
  8097. setStartOffset: function(offset) {
  8098. // only for text path
  8099. if (this.shapeNode != this.node) {
  8100. this.shapeNode.setAttribute("startOffset", offset * 100 + "%");
  8101. }
  8102. },
  8103. addSpan: function(span) {
  8104. this.addShape(span);
  8105. return this;
  8106. },
  8107. setPath: function(path) {
  8108. var textpath = this.shapeNode;
  8109. if (this.shapeNode == this.node) {
  8110. // 当前还不是 textpath
  8111. textpath = this.shapeNode = svg.createNode("textPath");
  8112. while (this.node.firstChild) {
  8113. this.shapeNode.appendChild(this.node.firstChild);
  8114. }
  8115. this.node.appendChild(textpath);
  8116. }
  8117. textpath.setAttributeNS(svg.xlink, "xlink:href", "#" + path.node.id);
  8118. this.setTextAnchor(this.getTextAnchor());
  8119. return this;
  8120. }
  8121. });
  8122. }
  8123. };
  8124. //src/graphic/textcontent.js
  8125. _p[71] = {
  8126. value: function(require, exports, module) {
  8127. var Shape = _p.r(61);
  8128. return _p.r(11).createClass("TextContent", {
  8129. base: Shape,
  8130. constructor: function(nodeType) {
  8131. // call shape constructor
  8132. this.callBase(nodeType);
  8133. this.shapeNode = this.shapeNode || this.node;
  8134. this.shapeNode.setAttribute("text-rendering", "geometricPrecision");
  8135. },
  8136. clearContent: function() {
  8137. while (this.shapeNode.firstChild) {
  8138. this.shapeNode.removeChild(this.shapeNode.firstChild);
  8139. }
  8140. return this;
  8141. },
  8142. setContent: function(content) {
  8143. this.shapeNode.textContent = content;
  8144. return this;
  8145. },
  8146. getContent: function() {
  8147. return this.shapeNode.textContent;
  8148. },
  8149. appendContent: function(content) {
  8150. this.shapeNode.textContent += content;
  8151. return this;
  8152. },
  8153. setSize: function(value) {
  8154. return this.setFontSize(value);
  8155. },
  8156. setFontSize: function(value) {
  8157. return this.setFont({
  8158. size: value
  8159. });
  8160. },
  8161. setFontFamily: function(value) {
  8162. return this.setFont({
  8163. family: value
  8164. });
  8165. },
  8166. setFontBold: function(bold) {
  8167. return this.setFont({
  8168. weight: bold ? "bold" : "normal"
  8169. });
  8170. },
  8171. setFontItalic: function(italic) {
  8172. return this.setFont({
  8173. style: italic ? "italic" : "normal"
  8174. });
  8175. },
  8176. setFont: function(font) {
  8177. var node = this.node;
  8178. [ "family", "size", "weight", "style" ].forEach(function(section) {
  8179. if (font[section] === null) {
  8180. node.removeAttribute("font-" + section);
  8181. } else if (font[section]) {
  8182. node.setAttribute("font-" + section, font[section]);
  8183. }
  8184. });
  8185. return this;
  8186. },
  8187. getExtentOfChar: function(index) {
  8188. return this.node.getExtentOfChar(index);
  8189. },
  8190. getRotationOfChar: function(index) {
  8191. return this.node.getRotationOfChar(index);
  8192. },
  8193. getCharNumAtPosition: function(x, y) {
  8194. return this.node.getCharNumAtPosition(this.node.viewportElement.createSVGPoint(x, y));
  8195. }
  8196. });
  8197. }
  8198. };
  8199. //src/graphic/textspan.js
  8200. _p[72] = {
  8201. value: function(require, exports, module) {
  8202. var TextContent = _p.r(71);
  8203. var Styled = _p.r(67);
  8204. return _p.r(11).createClass("TextSpan", {
  8205. base: TextContent,
  8206. mixins: [ Styled ],
  8207. constructor: function(content) {
  8208. this.callBase("tspan");
  8209. this.setContent(content);
  8210. }
  8211. });
  8212. }
  8213. };
  8214. //src/graphic/use.js
  8215. /*
  8216. * USE 功能
  8217. */
  8218. _p[73] = {
  8219. value: function(require, exports, module) {
  8220. var Svg = _p.r(68);
  8221. var Class = _p.r(11);
  8222. var Use = Class.createClass("Use", {
  8223. base: _p.r(61),
  8224. constructor: function(shape) {
  8225. this.callBase("use");
  8226. this.ref(shape);
  8227. },
  8228. ref: function(shape) {
  8229. if (!shape) {
  8230. this.node.removeAttributeNS(Svg.xlink, "xlink:href");
  8231. return this;
  8232. }
  8233. var shapeId = shape.getId();
  8234. if (shapeId) {
  8235. this.node.setAttributeNS(Svg.xlink, "xlink:href", "#" + shapeId);
  8236. }
  8237. // by techird
  8238. // 作为 Use 的图形,如果没有 fill 和 stroke,移除默认的 'none' 值,用于 Use 覆盖
  8239. if (shape.node.getAttribute("fill") === "none") {
  8240. shape.node.removeAttribute("fill");
  8241. }
  8242. if (shape.node.getAttribute("stroke") === "none") {
  8243. shape.node.removeAttribute("stroke");
  8244. }
  8245. return this;
  8246. }
  8247. });
  8248. var Shape = _p.r(61);
  8249. Class.extendClass(Shape, {
  8250. // fast-use
  8251. use: function() {
  8252. return new Use(this);
  8253. }
  8254. });
  8255. return Use;
  8256. }
  8257. };
  8258. //src/graphic/vector.js
  8259. _p[74] = {
  8260. value: function(require, exports, module) {
  8261. var Point = _p.r(51);
  8262. var Matrix = _p.r(44);
  8263. var Vector = _p.r(11).createClass("Vector", {
  8264. base: Point,
  8265. constructor: function(x, y) {
  8266. this.callBase(x, y);
  8267. },
  8268. square: function() {
  8269. return this.x * this.x + this.y * this.y;
  8270. },
  8271. length: function() {
  8272. return Math.sqrt(this.square());
  8273. },
  8274. add: function(q) {
  8275. return new Vector(this.x + q.x, this.y + q.y);
  8276. },
  8277. minus: function(q) {
  8278. return new Vector(this.x - q.x, this.y - q.y);
  8279. },
  8280. dot: function(q) {
  8281. return this.x * q.x + this.y * q.y;
  8282. },
  8283. project: function(q) {
  8284. return q.multipy(this.dot(q) / q.square());
  8285. },
  8286. normalize: function(length) {
  8287. if (length === undefined) {
  8288. length = 1;
  8289. }
  8290. return this.multipy(length / this.length());
  8291. },
  8292. multipy: function(scale) {
  8293. return new Vector(this.x * scale, this.y * scale);
  8294. },
  8295. rotate: function(angle, unit) {
  8296. if (unit == "rad") {
  8297. angle = angle / Math.PI * 180;
  8298. }
  8299. var p = new Matrix().rotate(angle).transformPoint(this);
  8300. return new Vector(p.x, p.y);
  8301. },
  8302. vertical: function() {
  8303. return new Vector(this.y, -this.x);
  8304. },
  8305. reverse: function() {
  8306. return this.multipy(-1);
  8307. },
  8308. getAngle: function() {
  8309. var length = this.length();
  8310. if (length === 0) return 0;
  8311. var rad = Math.acos(this.x / length);
  8312. var sign = this.y > 0 ? 1 : -1;
  8313. return sign * 180 * rad / Math.PI;
  8314. }
  8315. });
  8316. Vector.fromPoints = function(p1, p2) {
  8317. return new Vector(p2.x - p1.x, p2.y - p1.y);
  8318. };
  8319. Vector.fromPolar = function() {
  8320. var p = Point.fromPolar.apply(Point, arguments);
  8321. return new Vector(p.x, p.y);
  8322. };
  8323. _p.r(11).extendClass(Point, {
  8324. asVector: function() {
  8325. return new Vector(this.x, this.y);
  8326. }
  8327. });
  8328. return Vector;
  8329. }
  8330. };
  8331. //src/graphic/view.js
  8332. _p[75] = {
  8333. value: function(require, exports, module) {
  8334. var ShapeContainer = _p.r(62);
  8335. var ViewBox = _p.r(76);
  8336. return _p.r(11).createClass("View", {
  8337. mixins: [ ShapeContainer, ViewBox ],
  8338. base: _p.r(75),
  8339. constructor: function() {
  8340. this.callBase("view");
  8341. }
  8342. });
  8343. }
  8344. };
  8345. //src/graphic/viewbox.js
  8346. _p[76] = {
  8347. value: function(require, exports, module) {
  8348. return _p.r(11).createClass("ViewBox", {
  8349. getViewBox: function() {
  8350. var attr = this.node.getAttribute("viewBox");
  8351. if (attr === null) {
  8352. // firefox:
  8353. // 1. viewBox 没有设置过的时候获得的是 null
  8354. // 2. svg 标签没有指定绝对大小的时候 clientWidth 和 clientHeigt 为 0,需要在父容器上查找
  8355. // TODO: 第 2 条取得的不准确(假如有 padding 之类的)
  8356. return {
  8357. x: 0,
  8358. y: 0,
  8359. width: this.node.clientWidth || this.node.parentNode.clientWidth,
  8360. height: this.node.clientHeight || this.node.parentNode.clientHeight
  8361. };
  8362. } else {
  8363. attr = attr.split(" ");
  8364. return {
  8365. x: +attr[0],
  8366. y: +attr[1],
  8367. width: +attr[2],
  8368. height: +attr[3]
  8369. };
  8370. }
  8371. },
  8372. setViewBox: function(x, y, width, height) {
  8373. this.node.setAttribute("viewBox", [ x, y, width, height ].join(" "));
  8374. return this;
  8375. }
  8376. });
  8377. }
  8378. };
  8379. //src/kity.js
  8380. /**
  8381. * @fileOverview kity 暴露的方法或对象
  8382. */
  8383. _p[77] = {
  8384. value: function(require, exports, module) {
  8385. var kity = {}, utils = _p.r(12);
  8386. kity.version = "2.0.0";
  8387. utils.extend(kity, {
  8388. // core
  8389. createClass: _p.r(11).createClass,
  8390. extendClass: _p.r(11).extendClass,
  8391. Utils: utils,
  8392. Browser: _p.r(10),
  8393. // shape
  8394. Box: _p.r(26),
  8395. Bezier: _p.r(24),
  8396. BezierPoint: _p.r(25),
  8397. Circle: _p.r(27),
  8398. Clip: _p.r(28),
  8399. Color: _p.r(29),
  8400. Container: _p.r(30),
  8401. Curve: _p.r(31),
  8402. Ellipse: _p.r(33),
  8403. Group: _p.r(37),
  8404. Gradient: _p.r(36),
  8405. HyperLink: _p.r(38),
  8406. Image: _p.r(39),
  8407. Line: _p.r(40),
  8408. LinearGradient: _p.r(41),
  8409. Mask: _p.r(43),
  8410. Matrix: _p.r(44),
  8411. Marker: _p.r(42),
  8412. Palette: _p.r(45),
  8413. Paper: _p.r(46),
  8414. Path: _p.r(47),
  8415. Pattern: _p.r(48),
  8416. Pen: _p.r(49),
  8417. Point: _p.r(51),
  8418. PointContainer: _p.r(52),
  8419. Polygon: _p.r(54),
  8420. Polyline: _p.r(55),
  8421. Pie: _p.r(50),
  8422. RadialGradient: _p.r(56),
  8423. Resource: _p.r(59),
  8424. Rect: _p.r(57),
  8425. RegularPolygon: _p.r(58),
  8426. Ring: _p.r(60),
  8427. Shape: _p.r(61),
  8428. ShapePoint: _p.r(64),
  8429. ShapeContainer: _p.r(62),
  8430. Sweep: _p.r(69),
  8431. Star: _p.r(66),
  8432. Text: _p.r(70),
  8433. TextSpan: _p.r(72),
  8434. Use: _p.r(73),
  8435. Vector: _p.r(74),
  8436. g: _p.r(35),
  8437. // animate
  8438. Animator: _p.r(0),
  8439. Easing: _p.r(1),
  8440. OpacityAnimator: _p.r(4),
  8441. RotateAnimator: _p.r(6),
  8442. ScaleAnimator: _p.r(7),
  8443. Timeline: _p.r(8),
  8444. TranslateAnimator: _p.r(9),
  8445. PathAnimator: _p.r(5),
  8446. MotionAnimator: _p.r(3),
  8447. requestFrame: _p.r(2).requestFrame,
  8448. releaseFrame: _p.r(2).releaseFrame,
  8449. // filter
  8450. Filter: _p.r(21),
  8451. GaussianblurFilter: _p.r(22),
  8452. ProjectionFilter: _p.r(23),
  8453. // effect
  8454. ColorMatrixEffect: _p.r(14),
  8455. CompositeEffect: _p.r(15),
  8456. ConvolveMatrixEffect: _p.r(16),
  8457. Effect: _p.r(17),
  8458. GaussianblurEffect: _p.r(18),
  8459. OffsetEffect: _p.r(19)
  8460. });
  8461. module.exports = kity;
  8462. }
  8463. };
  8464. var moduleMapping = {
  8465. "expose-kity": 13
  8466. };
  8467. function use(name) {
  8468. _p.r([ moduleMapping[name] ]);
  8469. }
  8470. use('expose-kity');
  8471. })();