lottie_light.js 380 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854
  1. (typeof document !== "undefined") && (typeof navigator !== "undefined") && (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.lottie = factory());
  5. })(this, (function () { 'use strict';
  6. var svgNS = 'http://www.w3.org/2000/svg';
  7. var locationHref = '';
  8. var _useWebWorker = false;
  9. var initialDefaultFrame = -999999;
  10. var setWebWorker = function setWebWorker(flag) {
  11. _useWebWorker = !!flag;
  12. };
  13. var getWebWorker = function getWebWorker() {
  14. return _useWebWorker;
  15. };
  16. var setLocationHref = function setLocationHref(value) {
  17. locationHref = value;
  18. };
  19. var getLocationHref = function getLocationHref() {
  20. return locationHref;
  21. };
  22. function createTag(type) {
  23. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  24. return document.createElement(type);
  25. }
  26. function extendPrototype(sources, destination) {
  27. var i;
  28. var len = sources.length;
  29. var sourcePrototype;
  30. for (i = 0; i < len; i += 1) {
  31. sourcePrototype = sources[i].prototype;
  32. for (var attr in sourcePrototype) {
  33. if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
  34. }
  35. }
  36. }
  37. function getDescriptor(object, prop) {
  38. return Object.getOwnPropertyDescriptor(object, prop);
  39. }
  40. function createProxyFunction(prototype) {
  41. function ProxyFunction() {}
  42. ProxyFunction.prototype = prototype;
  43. return ProxyFunction;
  44. }
  45. // import Howl from '../../3rd_party/howler';
  46. var audioControllerFactory = function () {
  47. function AudioController(audioFactory) {
  48. this.audios = [];
  49. this.audioFactory = audioFactory;
  50. this._volume = 1;
  51. this._isMuted = false;
  52. }
  53. AudioController.prototype = {
  54. addAudio: function addAudio(audio) {
  55. this.audios.push(audio);
  56. },
  57. pause: function pause() {
  58. var i;
  59. var len = this.audios.length;
  60. for (i = 0; i < len; i += 1) {
  61. this.audios[i].pause();
  62. }
  63. },
  64. resume: function resume() {
  65. var i;
  66. var len = this.audios.length;
  67. for (i = 0; i < len; i += 1) {
  68. this.audios[i].resume();
  69. }
  70. },
  71. setRate: function setRate(rateValue) {
  72. var i;
  73. var len = this.audios.length;
  74. for (i = 0; i < len; i += 1) {
  75. this.audios[i].setRate(rateValue);
  76. }
  77. },
  78. createAudio: function createAudio(assetPath) {
  79. if (this.audioFactory) {
  80. return this.audioFactory(assetPath);
  81. }
  82. if (window.Howl) {
  83. return new window.Howl({
  84. src: [assetPath]
  85. });
  86. }
  87. return {
  88. isPlaying: false,
  89. play: function play() {
  90. this.isPlaying = true;
  91. },
  92. seek: function seek() {
  93. this.isPlaying = false;
  94. },
  95. playing: function playing() {},
  96. rate: function rate() {},
  97. setVolume: function setVolume() {}
  98. };
  99. },
  100. setAudioFactory: function setAudioFactory(audioFactory) {
  101. this.audioFactory = audioFactory;
  102. },
  103. setVolume: function setVolume(value) {
  104. this._volume = value;
  105. this._updateVolume();
  106. },
  107. mute: function mute() {
  108. this._isMuted = true;
  109. this._updateVolume();
  110. },
  111. unmute: function unmute() {
  112. this._isMuted = false;
  113. this._updateVolume();
  114. },
  115. getVolume: function getVolume() {
  116. return this._volume;
  117. },
  118. _updateVolume: function _updateVolume() {
  119. var i;
  120. var len = this.audios.length;
  121. for (i = 0; i < len; i += 1) {
  122. this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1));
  123. }
  124. }
  125. };
  126. return function () {
  127. return new AudioController();
  128. };
  129. }();
  130. var createTypedArray = function () {
  131. function createRegularArray(type, len) {
  132. var i = 0;
  133. var arr = [];
  134. var value;
  135. switch (type) {
  136. case 'int16':
  137. case 'uint8c':
  138. value = 1;
  139. break;
  140. default:
  141. value = 1.1;
  142. break;
  143. }
  144. for (i = 0; i < len; i += 1) {
  145. arr.push(value);
  146. }
  147. return arr;
  148. }
  149. function createTypedArrayFactory(type, len) {
  150. if (type === 'float32') {
  151. return new Float32Array(len);
  152. }
  153. if (type === 'int16') {
  154. return new Int16Array(len);
  155. }
  156. if (type === 'uint8c') {
  157. return new Uint8ClampedArray(len);
  158. }
  159. return createRegularArray(type, len);
  160. }
  161. if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  162. return createTypedArrayFactory;
  163. }
  164. return createRegularArray;
  165. }();
  166. function createSizedArray(len) {
  167. return Array.apply(null, {
  168. length: len
  169. });
  170. }
  171. function _typeof$3(o) { "@babel/helpers - typeof"; return _typeof$3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$3(o); }
  172. var subframeEnabled = true;
  173. var expressionsPlugin = null;
  174. var expressionsInterfaces = null;
  175. var idPrefix$1 = '';
  176. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  177. var _shouldRoundValues = false;
  178. var bmPow = Math.pow;
  179. var bmSqrt = Math.sqrt;
  180. var bmFloor = Math.floor;
  181. var bmMax = Math.max;
  182. var bmMin = Math.min;
  183. var BMMath = {};
  184. (function () {
  185. var propertyNames = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'atan2', 'ceil', 'cbrt', 'expm1', 'clz32', 'cos', 'cosh', 'exp', 'floor', 'fround', 'hypot', 'imul', 'log', 'log1p', 'log2', 'log10', 'max', 'min', 'pow', 'random', 'round', 'sign', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc', 'E', 'LN10', 'LN2', 'LOG10E', 'LOG2E', 'PI', 'SQRT1_2', 'SQRT2'];
  186. var i;
  187. var len = propertyNames.length;
  188. for (i = 0; i < len; i += 1) {
  189. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  190. }
  191. })();
  192. function ProjectInterface$1() {
  193. return {};
  194. }
  195. BMMath.random = Math.random;
  196. BMMath.abs = function (val) {
  197. var tOfVal = _typeof$3(val);
  198. if (tOfVal === 'object' && val.length) {
  199. var absArr = createSizedArray(val.length);
  200. var i;
  201. var len = val.length;
  202. for (i = 0; i < len; i += 1) {
  203. absArr[i] = Math.abs(val[i]);
  204. }
  205. return absArr;
  206. }
  207. return Math.abs(val);
  208. };
  209. var defaultCurveSegments = 150;
  210. var degToRads = Math.PI / 180;
  211. var roundCorner = 0.5519;
  212. function roundValues(flag) {
  213. _shouldRoundValues = !!flag;
  214. }
  215. function bmRnd(value) {
  216. if (_shouldRoundValues) {
  217. return Math.round(value);
  218. }
  219. return value;
  220. }
  221. function styleDiv(element) {
  222. element.style.position = 'absolute';
  223. element.style.top = 0;
  224. element.style.left = 0;
  225. element.style.display = 'block';
  226. element.style.transformOrigin = '0 0';
  227. element.style.webkitTransformOrigin = '0 0';
  228. element.style.backfaceVisibility = 'visible';
  229. element.style.webkitBackfaceVisibility = 'visible';
  230. element.style.transformStyle = 'preserve-3d';
  231. element.style.webkitTransformStyle = 'preserve-3d';
  232. element.style.mozTransformStyle = 'preserve-3d';
  233. }
  234. function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) {
  235. this.type = type;
  236. this.currentTime = currentTime;
  237. this.totalTime = totalTime;
  238. this.direction = frameMultiplier < 0 ? -1 : 1;
  239. }
  240. function BMCompleteEvent(type, frameMultiplier) {
  241. this.type = type;
  242. this.direction = frameMultiplier < 0 ? -1 : 1;
  243. }
  244. function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) {
  245. this.type = type;
  246. this.currentLoop = currentLoop;
  247. this.totalLoops = totalLoops;
  248. this.direction = frameMultiplier < 0 ? -1 : 1;
  249. }
  250. function BMSegmentStartEvent(type, firstFrame, totalFrames) {
  251. this.type = type;
  252. this.firstFrame = firstFrame;
  253. this.totalFrames = totalFrames;
  254. }
  255. function BMDestroyEvent(type, target) {
  256. this.type = type;
  257. this.target = target;
  258. }
  259. function BMRenderFrameErrorEvent(nativeError, currentTime) {
  260. this.type = 'renderFrameError';
  261. this.nativeError = nativeError;
  262. this.currentTime = currentTime;
  263. }
  264. function BMConfigErrorEvent(nativeError) {
  265. this.type = 'configError';
  266. this.nativeError = nativeError;
  267. }
  268. function BMAnimationConfigErrorEvent(type, nativeError) {
  269. this.type = type;
  270. this.nativeError = nativeError;
  271. }
  272. var createElementID = function () {
  273. var _count = 0;
  274. return function createID() {
  275. _count += 1;
  276. return idPrefix$1 + '__lottie_element_' + _count;
  277. };
  278. }();
  279. function HSVtoRGB(h, s, v) {
  280. var r;
  281. var g;
  282. var b;
  283. var i;
  284. var f;
  285. var p;
  286. var q;
  287. var t;
  288. i = Math.floor(h * 6);
  289. f = h * 6 - i;
  290. p = v * (1 - s);
  291. q = v * (1 - f * s);
  292. t = v * (1 - (1 - f) * s);
  293. switch (i % 6) {
  294. case 0:
  295. r = v;
  296. g = t;
  297. b = p;
  298. break;
  299. case 1:
  300. r = q;
  301. g = v;
  302. b = p;
  303. break;
  304. case 2:
  305. r = p;
  306. g = v;
  307. b = t;
  308. break;
  309. case 3:
  310. r = p;
  311. g = q;
  312. b = v;
  313. break;
  314. case 4:
  315. r = t;
  316. g = p;
  317. b = v;
  318. break;
  319. case 5:
  320. r = v;
  321. g = p;
  322. b = q;
  323. break;
  324. default:
  325. break;
  326. }
  327. return [r, g, b];
  328. }
  329. function RGBtoHSV(r, g, b) {
  330. var max = Math.max(r, g, b);
  331. var min = Math.min(r, g, b);
  332. var d = max - min;
  333. var h;
  334. var s = max === 0 ? 0 : d / max;
  335. var v = max / 255;
  336. switch (max) {
  337. case min:
  338. h = 0;
  339. break;
  340. case r:
  341. h = g - b + d * (g < b ? 6 : 0);
  342. h /= 6 * d;
  343. break;
  344. case g:
  345. h = b - r + d * 2;
  346. h /= 6 * d;
  347. break;
  348. case b:
  349. h = r - g + d * 4;
  350. h /= 6 * d;
  351. break;
  352. default:
  353. break;
  354. }
  355. return [h, s, v];
  356. }
  357. function addSaturationToRGB(color, offset) {
  358. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  359. hsv[1] += offset;
  360. if (hsv[1] > 1) {
  361. hsv[1] = 1;
  362. } else if (hsv[1] <= 0) {
  363. hsv[1] = 0;
  364. }
  365. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  366. }
  367. function addBrightnessToRGB(color, offset) {
  368. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  369. hsv[2] += offset;
  370. if (hsv[2] > 1) {
  371. hsv[2] = 1;
  372. } else if (hsv[2] < 0) {
  373. hsv[2] = 0;
  374. }
  375. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  376. }
  377. function addHueToRGB(color, offset) {
  378. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  379. hsv[0] += offset / 360;
  380. if (hsv[0] > 1) {
  381. hsv[0] -= 1;
  382. } else if (hsv[0] < 0) {
  383. hsv[0] += 1;
  384. }
  385. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  386. }
  387. var rgbToHex = function () {
  388. var colorMap = [];
  389. var i;
  390. var hex;
  391. for (i = 0; i < 256; i += 1) {
  392. hex = i.toString(16);
  393. colorMap[i] = hex.length === 1 ? '0' + hex : hex;
  394. }
  395. return function (r, g, b) {
  396. if (r < 0) {
  397. r = 0;
  398. }
  399. if (g < 0) {
  400. g = 0;
  401. }
  402. if (b < 0) {
  403. b = 0;
  404. }
  405. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  406. };
  407. }();
  408. var setSubframeEnabled = function setSubframeEnabled(flag) {
  409. subframeEnabled = !!flag;
  410. };
  411. var getSubframeEnabled = function getSubframeEnabled() {
  412. return subframeEnabled;
  413. };
  414. var setExpressionsPlugin = function setExpressionsPlugin(value) {
  415. expressionsPlugin = value;
  416. };
  417. var getExpressionsPlugin = function getExpressionsPlugin() {
  418. return expressionsPlugin;
  419. };
  420. var setExpressionInterfaces = function setExpressionInterfaces(value) {
  421. expressionsInterfaces = value;
  422. };
  423. var getExpressionInterfaces = function getExpressionInterfaces() {
  424. return expressionsInterfaces;
  425. };
  426. var setDefaultCurveSegments = function setDefaultCurveSegments(value) {
  427. defaultCurveSegments = value;
  428. };
  429. var getDefaultCurveSegments = function getDefaultCurveSegments() {
  430. return defaultCurveSegments;
  431. };
  432. var setIdPrefix = function setIdPrefix(value) {
  433. idPrefix$1 = value;
  434. };
  435. var getIdPrefix = function getIdPrefix() {
  436. return idPrefix$1;
  437. };
  438. function createNS(type) {
  439. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  440. return document.createElementNS(svgNS, type);
  441. }
  442. function _typeof$2(o) { "@babel/helpers - typeof"; return _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$2(o); }
  443. var dataManager = function () {
  444. var _counterId = 1;
  445. var processes = [];
  446. var workerFn;
  447. var workerInstance;
  448. var workerProxy = {
  449. onmessage: function onmessage() {},
  450. postMessage: function postMessage(path) {
  451. workerFn({
  452. data: path
  453. });
  454. }
  455. };
  456. var _workerSelf = {
  457. postMessage: function postMessage(data) {
  458. workerProxy.onmessage({
  459. data: data
  460. });
  461. }
  462. };
  463. function createWorker(fn) {
  464. if (window.Worker && window.Blob && getWebWorker()) {
  465. var blob = new Blob(['var _workerSelf = self; self.onmessage = ', fn.toString()], {
  466. type: 'text/javascript'
  467. });
  468. // var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  469. var url = URL.createObjectURL(blob);
  470. return new Worker(url);
  471. }
  472. workerFn = fn;
  473. return workerProxy;
  474. }
  475. function setupWorker() {
  476. if (!workerInstance) {
  477. workerInstance = createWorker(function workerStart(e) {
  478. function dataFunctionManager() {
  479. function completeLayers(layers, comps) {
  480. var layerData;
  481. var i;
  482. var len = layers.length;
  483. var j;
  484. var jLen;
  485. var k;
  486. var kLen;
  487. for (i = 0; i < len; i += 1) {
  488. layerData = layers[i];
  489. if ('ks' in layerData && !layerData.completed) {
  490. layerData.completed = true;
  491. if (layerData.hasMask) {
  492. var maskProps = layerData.masksProperties;
  493. jLen = maskProps.length;
  494. for (j = 0; j < jLen; j += 1) {
  495. if (maskProps[j].pt.k.i) {
  496. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  497. } else {
  498. kLen = maskProps[j].pt.k.length;
  499. for (k = 0; k < kLen; k += 1) {
  500. if (maskProps[j].pt.k[k].s) {
  501. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  502. }
  503. if (maskProps[j].pt.k[k].e) {
  504. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  505. }
  506. }
  507. }
  508. }
  509. }
  510. if (layerData.ty === 0) {
  511. layerData.layers = findCompLayers(layerData.refId, comps);
  512. completeLayers(layerData.layers, comps);
  513. } else if (layerData.ty === 4) {
  514. completeShapes(layerData.shapes);
  515. } else if (layerData.ty === 5) {
  516. completeText(layerData);
  517. }
  518. }
  519. }
  520. }
  521. function completeChars(chars, assets) {
  522. if (chars) {
  523. var i = 0;
  524. var len = chars.length;
  525. for (i = 0; i < len; i += 1) {
  526. if (chars[i].t === 1) {
  527. // var compData = findComp(chars[i].data.refId, assets);
  528. chars[i].data.layers = findCompLayers(chars[i].data.refId, assets);
  529. // chars[i].data.ip = 0;
  530. // chars[i].data.op = 99999;
  531. // chars[i].data.st = 0;
  532. // chars[i].data.sr = 1;
  533. // chars[i].w = compData.w;
  534. // chars[i].data.ks = {
  535. // a: { k: [0, 0, 0], a: 0 },
  536. // p: { k: [0, -compData.h, 0], a: 0 },
  537. // r: { k: 0, a: 0 },
  538. // s: { k: [100, 100], a: 0 },
  539. // o: { k: 100, a: 0 },
  540. // };
  541. completeLayers(chars[i].data.layers, assets);
  542. }
  543. }
  544. }
  545. }
  546. function findComp(id, comps) {
  547. var i = 0;
  548. var len = comps.length;
  549. while (i < len) {
  550. if (comps[i].id === id) {
  551. return comps[i];
  552. }
  553. i += 1;
  554. }
  555. return null;
  556. }
  557. function findCompLayers(id, comps) {
  558. var comp = findComp(id, comps);
  559. if (comp) {
  560. if (!comp.layers.__used) {
  561. comp.layers.__used = true;
  562. return comp.layers;
  563. }
  564. return JSON.parse(JSON.stringify(comp.layers));
  565. }
  566. return null;
  567. }
  568. function completeShapes(arr) {
  569. var i;
  570. var len = arr.length;
  571. var j;
  572. var jLen;
  573. for (i = len - 1; i >= 0; i -= 1) {
  574. if (arr[i].ty === 'sh') {
  575. if (arr[i].ks.k.i) {
  576. convertPathsToAbsoluteValues(arr[i].ks.k);
  577. } else {
  578. jLen = arr[i].ks.k.length;
  579. for (j = 0; j < jLen; j += 1) {
  580. if (arr[i].ks.k[j].s) {
  581. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  582. }
  583. if (arr[i].ks.k[j].e) {
  584. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  585. }
  586. }
  587. }
  588. } else if (arr[i].ty === 'gr') {
  589. completeShapes(arr[i].it);
  590. }
  591. }
  592. }
  593. function convertPathsToAbsoluteValues(path) {
  594. var i;
  595. var len = path.i.length;
  596. for (i = 0; i < len; i += 1) {
  597. path.i[i][0] += path.v[i][0];
  598. path.i[i][1] += path.v[i][1];
  599. path.o[i][0] += path.v[i][0];
  600. path.o[i][1] += path.v[i][1];
  601. }
  602. }
  603. function checkVersion(minimum, animVersionString) {
  604. var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100];
  605. if (minimum[0] > animVersion[0]) {
  606. return true;
  607. }
  608. if (animVersion[0] > minimum[0]) {
  609. return false;
  610. }
  611. if (minimum[1] > animVersion[1]) {
  612. return true;
  613. }
  614. if (animVersion[1] > minimum[1]) {
  615. return false;
  616. }
  617. if (minimum[2] > animVersion[2]) {
  618. return true;
  619. }
  620. if (animVersion[2] > minimum[2]) {
  621. return false;
  622. }
  623. return null;
  624. }
  625. var checkText = function () {
  626. var minimumVersion = [4, 4, 14];
  627. function updateTextLayer(textLayer) {
  628. var documentData = textLayer.t.d;
  629. textLayer.t.d = {
  630. k: [{
  631. s: documentData,
  632. t: 0
  633. }]
  634. };
  635. }
  636. function iterateLayers(layers) {
  637. var i;
  638. var len = layers.length;
  639. for (i = 0; i < len; i += 1) {
  640. if (layers[i].ty === 5) {
  641. updateTextLayer(layers[i]);
  642. }
  643. }
  644. }
  645. return function (animationData) {
  646. if (checkVersion(minimumVersion, animationData.v)) {
  647. iterateLayers(animationData.layers);
  648. if (animationData.assets) {
  649. var i;
  650. var len = animationData.assets.length;
  651. for (i = 0; i < len; i += 1) {
  652. if (animationData.assets[i].layers) {
  653. iterateLayers(animationData.assets[i].layers);
  654. }
  655. }
  656. }
  657. }
  658. };
  659. }();
  660. var checkChars = function () {
  661. var minimumVersion = [4, 7, 99];
  662. return function (animationData) {
  663. if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) {
  664. var i;
  665. var len = animationData.chars.length;
  666. for (i = 0; i < len; i += 1) {
  667. var charData = animationData.chars[i];
  668. if (charData.data && charData.data.shapes) {
  669. completeShapes(charData.data.shapes);
  670. charData.data.ip = 0;
  671. charData.data.op = 99999;
  672. charData.data.st = 0;
  673. charData.data.sr = 1;
  674. charData.data.ks = {
  675. p: {
  676. k: [0, 0],
  677. a: 0
  678. },
  679. s: {
  680. k: [100, 100],
  681. a: 0
  682. },
  683. a: {
  684. k: [0, 0],
  685. a: 0
  686. },
  687. r: {
  688. k: 0,
  689. a: 0
  690. },
  691. o: {
  692. k: 100,
  693. a: 0
  694. }
  695. };
  696. if (!animationData.chars[i].t) {
  697. charData.data.shapes.push({
  698. ty: 'no'
  699. });
  700. charData.data.shapes[0].it.push({
  701. p: {
  702. k: [0, 0],
  703. a: 0
  704. },
  705. s: {
  706. k: [100, 100],
  707. a: 0
  708. },
  709. a: {
  710. k: [0, 0],
  711. a: 0
  712. },
  713. r: {
  714. k: 0,
  715. a: 0
  716. },
  717. o: {
  718. k: 100,
  719. a: 0
  720. },
  721. sk: {
  722. k: 0,
  723. a: 0
  724. },
  725. sa: {
  726. k: 0,
  727. a: 0
  728. },
  729. ty: 'tr'
  730. });
  731. }
  732. }
  733. }
  734. }
  735. };
  736. }();
  737. var checkPathProperties = function () {
  738. var minimumVersion = [5, 7, 15];
  739. function updateTextLayer(textLayer) {
  740. var pathData = textLayer.t.p;
  741. if (typeof pathData.a === 'number') {
  742. pathData.a = {
  743. a: 0,
  744. k: pathData.a
  745. };
  746. }
  747. if (typeof pathData.p === 'number') {
  748. pathData.p = {
  749. a: 0,
  750. k: pathData.p
  751. };
  752. }
  753. if (typeof pathData.r === 'number') {
  754. pathData.r = {
  755. a: 0,
  756. k: pathData.r
  757. };
  758. }
  759. }
  760. function iterateLayers(layers) {
  761. var i;
  762. var len = layers.length;
  763. for (i = 0; i < len; i += 1) {
  764. if (layers[i].ty === 5) {
  765. updateTextLayer(layers[i]);
  766. }
  767. }
  768. }
  769. return function (animationData) {
  770. if (checkVersion(minimumVersion, animationData.v)) {
  771. iterateLayers(animationData.layers);
  772. if (animationData.assets) {
  773. var i;
  774. var len = animationData.assets.length;
  775. for (i = 0; i < len; i += 1) {
  776. if (animationData.assets[i].layers) {
  777. iterateLayers(animationData.assets[i].layers);
  778. }
  779. }
  780. }
  781. }
  782. };
  783. }();
  784. var checkColors = function () {
  785. var minimumVersion = [4, 1, 9];
  786. function iterateShapes(shapes) {
  787. var i;
  788. var len = shapes.length;
  789. var j;
  790. var jLen;
  791. for (i = 0; i < len; i += 1) {
  792. if (shapes[i].ty === 'gr') {
  793. iterateShapes(shapes[i].it);
  794. } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') {
  795. if (shapes[i].c.k && shapes[i].c.k[0].i) {
  796. jLen = shapes[i].c.k.length;
  797. for (j = 0; j < jLen; j += 1) {
  798. if (shapes[i].c.k[j].s) {
  799. shapes[i].c.k[j].s[0] /= 255;
  800. shapes[i].c.k[j].s[1] /= 255;
  801. shapes[i].c.k[j].s[2] /= 255;
  802. shapes[i].c.k[j].s[3] /= 255;
  803. }
  804. if (shapes[i].c.k[j].e) {
  805. shapes[i].c.k[j].e[0] /= 255;
  806. shapes[i].c.k[j].e[1] /= 255;
  807. shapes[i].c.k[j].e[2] /= 255;
  808. shapes[i].c.k[j].e[3] /= 255;
  809. }
  810. }
  811. } else {
  812. shapes[i].c.k[0] /= 255;
  813. shapes[i].c.k[1] /= 255;
  814. shapes[i].c.k[2] /= 255;
  815. shapes[i].c.k[3] /= 255;
  816. }
  817. }
  818. }
  819. }
  820. function iterateLayers(layers) {
  821. var i;
  822. var len = layers.length;
  823. for (i = 0; i < len; i += 1) {
  824. if (layers[i].ty === 4) {
  825. iterateShapes(layers[i].shapes);
  826. }
  827. }
  828. }
  829. return function (animationData) {
  830. if (checkVersion(minimumVersion, animationData.v)) {
  831. iterateLayers(animationData.layers);
  832. if (animationData.assets) {
  833. var i;
  834. var len = animationData.assets.length;
  835. for (i = 0; i < len; i += 1) {
  836. if (animationData.assets[i].layers) {
  837. iterateLayers(animationData.assets[i].layers);
  838. }
  839. }
  840. }
  841. }
  842. };
  843. }();
  844. var checkShapes = function () {
  845. var minimumVersion = [4, 4, 18];
  846. function completeClosingShapes(arr) {
  847. var i;
  848. var len = arr.length;
  849. var j;
  850. var jLen;
  851. for (i = len - 1; i >= 0; i -= 1) {
  852. if (arr[i].ty === 'sh') {
  853. if (arr[i].ks.k.i) {
  854. arr[i].ks.k.c = arr[i].closed;
  855. } else {
  856. jLen = arr[i].ks.k.length;
  857. for (j = 0; j < jLen; j += 1) {
  858. if (arr[i].ks.k[j].s) {
  859. arr[i].ks.k[j].s[0].c = arr[i].closed;
  860. }
  861. if (arr[i].ks.k[j].e) {
  862. arr[i].ks.k[j].e[0].c = arr[i].closed;
  863. }
  864. }
  865. }
  866. } else if (arr[i].ty === 'gr') {
  867. completeClosingShapes(arr[i].it);
  868. }
  869. }
  870. }
  871. function iterateLayers(layers) {
  872. var layerData;
  873. var i;
  874. var len = layers.length;
  875. var j;
  876. var jLen;
  877. var k;
  878. var kLen;
  879. for (i = 0; i < len; i += 1) {
  880. layerData = layers[i];
  881. if (layerData.hasMask) {
  882. var maskProps = layerData.masksProperties;
  883. jLen = maskProps.length;
  884. for (j = 0; j < jLen; j += 1) {
  885. if (maskProps[j].pt.k.i) {
  886. maskProps[j].pt.k.c = maskProps[j].cl;
  887. } else {
  888. kLen = maskProps[j].pt.k.length;
  889. for (k = 0; k < kLen; k += 1) {
  890. if (maskProps[j].pt.k[k].s) {
  891. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  892. }
  893. if (maskProps[j].pt.k[k].e) {
  894. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  895. }
  896. }
  897. }
  898. }
  899. }
  900. if (layerData.ty === 4) {
  901. completeClosingShapes(layerData.shapes);
  902. }
  903. }
  904. }
  905. return function (animationData) {
  906. if (checkVersion(minimumVersion, animationData.v)) {
  907. iterateLayers(animationData.layers);
  908. if (animationData.assets) {
  909. var i;
  910. var len = animationData.assets.length;
  911. for (i = 0; i < len; i += 1) {
  912. if (animationData.assets[i].layers) {
  913. iterateLayers(animationData.assets[i].layers);
  914. }
  915. }
  916. }
  917. }
  918. };
  919. }();
  920. function completeData(animationData) {
  921. if (animationData.__complete) {
  922. return;
  923. }
  924. checkColors(animationData);
  925. checkText(animationData);
  926. checkChars(animationData);
  927. checkPathProperties(animationData);
  928. checkShapes(animationData);
  929. completeLayers(animationData.layers, animationData.assets);
  930. completeChars(animationData.chars, animationData.assets);
  931. animationData.__complete = true;
  932. }
  933. function completeText(data) {
  934. if (data.t.a.length === 0 && !('m' in data.t.p)) {
  935. // data.singleShape = true;
  936. }
  937. }
  938. var moduleOb = {};
  939. moduleOb.completeData = completeData;
  940. moduleOb.checkColors = checkColors;
  941. moduleOb.checkChars = checkChars;
  942. moduleOb.checkPathProperties = checkPathProperties;
  943. moduleOb.checkShapes = checkShapes;
  944. moduleOb.completeLayers = completeLayers;
  945. return moduleOb;
  946. }
  947. if (!_workerSelf.dataManager) {
  948. _workerSelf.dataManager = dataFunctionManager();
  949. }
  950. if (!_workerSelf.assetLoader) {
  951. _workerSelf.assetLoader = function () {
  952. function formatResponse(xhr) {
  953. // using typeof doubles the time of execution of this method,
  954. // so if available, it's better to use the header to validate the type
  955. var contentTypeHeader = xhr.getResponseHeader('content-type');
  956. if (contentTypeHeader && xhr.responseType === 'json' && contentTypeHeader.indexOf('json') !== -1) {
  957. return xhr.response;
  958. }
  959. if (xhr.response && _typeof$2(xhr.response) === 'object') {
  960. return xhr.response;
  961. }
  962. if (xhr.response && typeof xhr.response === 'string') {
  963. return JSON.parse(xhr.response);
  964. }
  965. if (xhr.responseText) {
  966. return JSON.parse(xhr.responseText);
  967. }
  968. return null;
  969. }
  970. function loadAsset(path, fullPath, callback, errorCallback) {
  971. var response;
  972. var xhr = new XMLHttpRequest();
  973. // set responseType after calling open or IE will break.
  974. try {
  975. // This crashes on Android WebView prior to KitKat
  976. xhr.responseType = 'json';
  977. } catch (err) {} // eslint-disable-line no-empty
  978. xhr.onreadystatechange = function () {
  979. if (xhr.readyState === 4) {
  980. if (xhr.status === 200) {
  981. response = formatResponse(xhr);
  982. callback(response);
  983. } else {
  984. try {
  985. response = formatResponse(xhr);
  986. callback(response);
  987. } catch (err) {
  988. if (errorCallback) {
  989. errorCallback(err);
  990. }
  991. }
  992. }
  993. }
  994. };
  995. try {
  996. // Hack to workaround banner validation
  997. xhr.open(['G', 'E', 'T'].join(''), path, true);
  998. } catch (error) {
  999. // Hack to workaround banner validation
  1000. xhr.open(['G', 'E', 'T'].join(''), fullPath + '/' + path, true);
  1001. }
  1002. xhr.send();
  1003. }
  1004. return {
  1005. load: loadAsset
  1006. };
  1007. }();
  1008. }
  1009. if (e.data.type === 'loadAnimation') {
  1010. _workerSelf.assetLoader.load(e.data.path, e.data.fullPath, function (data) {
  1011. _workerSelf.dataManager.completeData(data);
  1012. _workerSelf.postMessage({
  1013. id: e.data.id,
  1014. payload: data,
  1015. status: 'success'
  1016. });
  1017. }, function () {
  1018. _workerSelf.postMessage({
  1019. id: e.data.id,
  1020. status: 'error'
  1021. });
  1022. });
  1023. } else if (e.data.type === 'complete') {
  1024. var animation = e.data.animation;
  1025. _workerSelf.dataManager.completeData(animation);
  1026. _workerSelf.postMessage({
  1027. id: e.data.id,
  1028. payload: animation,
  1029. status: 'success'
  1030. });
  1031. } else if (e.data.type === 'loadData') {
  1032. _workerSelf.assetLoader.load(e.data.path, e.data.fullPath, function (data) {
  1033. _workerSelf.postMessage({
  1034. id: e.data.id,
  1035. payload: data,
  1036. status: 'success'
  1037. });
  1038. }, function () {
  1039. _workerSelf.postMessage({
  1040. id: e.data.id,
  1041. status: 'error'
  1042. });
  1043. });
  1044. }
  1045. });
  1046. workerInstance.onmessage = function (event) {
  1047. var data = event.data;
  1048. var id = data.id;
  1049. var process = processes[id];
  1050. processes[id] = null;
  1051. if (data.status === 'success') {
  1052. process.onComplete(data.payload);
  1053. } else if (process.onError) {
  1054. process.onError();
  1055. }
  1056. };
  1057. }
  1058. }
  1059. function createProcess(onComplete, onError) {
  1060. _counterId += 1;
  1061. var id = 'processId_' + _counterId;
  1062. processes[id] = {
  1063. onComplete: onComplete,
  1064. onError: onError
  1065. };
  1066. return id;
  1067. }
  1068. function loadAnimation(path, onComplete, onError) {
  1069. setupWorker();
  1070. var processId = createProcess(onComplete, onError);
  1071. workerInstance.postMessage({
  1072. type: 'loadAnimation',
  1073. path: path,
  1074. fullPath: window.location.origin + window.location.pathname,
  1075. id: processId
  1076. });
  1077. }
  1078. function loadData(path, onComplete, onError) {
  1079. setupWorker();
  1080. var processId = createProcess(onComplete, onError);
  1081. workerInstance.postMessage({
  1082. type: 'loadData',
  1083. path: path,
  1084. fullPath: window.location.origin + window.location.pathname,
  1085. id: processId
  1086. });
  1087. }
  1088. function completeAnimation(anim, onComplete, onError) {
  1089. setupWorker();
  1090. var processId = createProcess(onComplete, onError);
  1091. workerInstance.postMessage({
  1092. type: 'complete',
  1093. animation: anim,
  1094. id: processId
  1095. });
  1096. }
  1097. return {
  1098. loadAnimation: loadAnimation,
  1099. loadData: loadData,
  1100. completeAnimation: completeAnimation
  1101. };
  1102. }();
  1103. var ImagePreloader = function () {
  1104. var proxyImage = function () {
  1105. var canvas = createTag('canvas');
  1106. canvas.width = 1;
  1107. canvas.height = 1;
  1108. var ctx = canvas.getContext('2d');
  1109. ctx.fillStyle = 'rgba(0,0,0,0)';
  1110. ctx.fillRect(0, 0, 1, 1);
  1111. return canvas;
  1112. }();
  1113. function imageLoaded() {
  1114. this.loadedAssets += 1;
  1115. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1116. if (this.imagesLoadedCb) {
  1117. this.imagesLoadedCb(null);
  1118. }
  1119. }
  1120. }
  1121. function footageLoaded() {
  1122. this.loadedFootagesCount += 1;
  1123. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1124. if (this.imagesLoadedCb) {
  1125. this.imagesLoadedCb(null);
  1126. }
  1127. }
  1128. }
  1129. function getAssetsPath(assetData, assetsPath, originalPath) {
  1130. var path = '';
  1131. if (assetData.e) {
  1132. path = assetData.p;
  1133. } else if (assetsPath) {
  1134. var imagePath = assetData.p;
  1135. if (imagePath.indexOf('images/') !== -1) {
  1136. imagePath = imagePath.split('/')[1];
  1137. }
  1138. path = assetsPath + imagePath;
  1139. } else {
  1140. path = originalPath;
  1141. path += assetData.u ? assetData.u : '';
  1142. path += assetData.p;
  1143. }
  1144. return path;
  1145. }
  1146. function testImageLoaded(img) {
  1147. var _count = 0;
  1148. var intervalId = setInterval(function () {
  1149. var box = img.getBBox();
  1150. if (box.width || _count > 500) {
  1151. this._imageLoaded();
  1152. clearInterval(intervalId);
  1153. }
  1154. _count += 1;
  1155. }.bind(this), 50);
  1156. }
  1157. function createImageData(assetData) {
  1158. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1159. var img = createNS('image');
  1160. if (isSafari) {
  1161. this.testImageLoaded(img);
  1162. } else {
  1163. img.addEventListener('load', this._imageLoaded, false);
  1164. }
  1165. img.addEventListener('error', function () {
  1166. ob.img = proxyImage;
  1167. this._imageLoaded();
  1168. }.bind(this), false);
  1169. img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
  1170. if (this._elementHelper.append) {
  1171. this._elementHelper.append(img);
  1172. } else {
  1173. this._elementHelper.appendChild(img);
  1174. }
  1175. var ob = {
  1176. img: img,
  1177. assetData: assetData
  1178. };
  1179. return ob;
  1180. }
  1181. function createImgData(assetData) {
  1182. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1183. var img = createTag('img');
  1184. img.crossOrigin = 'anonymous';
  1185. img.addEventListener('load', this._imageLoaded, false);
  1186. img.addEventListener('error', function () {
  1187. ob.img = proxyImage;
  1188. this._imageLoaded();
  1189. }.bind(this), false);
  1190. img.src = path;
  1191. var ob = {
  1192. img: img,
  1193. assetData: assetData
  1194. };
  1195. return ob;
  1196. }
  1197. function createFootageData(data) {
  1198. var ob = {
  1199. assetData: data
  1200. };
  1201. var path = getAssetsPath(data, this.assetsPath, this.path);
  1202. dataManager.loadData(path, function (footageData) {
  1203. ob.img = footageData;
  1204. this._footageLoaded();
  1205. }.bind(this), function () {
  1206. ob.img = {};
  1207. this._footageLoaded();
  1208. }.bind(this));
  1209. return ob;
  1210. }
  1211. function loadAssets(assets, cb) {
  1212. this.imagesLoadedCb = cb;
  1213. var i;
  1214. var len = assets.length;
  1215. for (i = 0; i < len; i += 1) {
  1216. if (!assets[i].layers) {
  1217. if (!assets[i].t || assets[i].t === 'seq') {
  1218. this.totalImages += 1;
  1219. this.images.push(this._createImageData(assets[i]));
  1220. } else if (assets[i].t === 3) {
  1221. this.totalFootages += 1;
  1222. this.images.push(this.createFootageData(assets[i]));
  1223. }
  1224. }
  1225. }
  1226. }
  1227. function setPath(path) {
  1228. this.path = path || '';
  1229. }
  1230. function setAssetsPath(path) {
  1231. this.assetsPath = path || '';
  1232. }
  1233. function getAsset(assetData) {
  1234. var i = 0;
  1235. var len = this.images.length;
  1236. while (i < len) {
  1237. if (this.images[i].assetData === assetData) {
  1238. return this.images[i].img;
  1239. }
  1240. i += 1;
  1241. }
  1242. return null;
  1243. }
  1244. function destroy() {
  1245. this.imagesLoadedCb = null;
  1246. this.images.length = 0;
  1247. }
  1248. function loadedImages() {
  1249. return this.totalImages === this.loadedAssets;
  1250. }
  1251. function loadedFootages() {
  1252. return this.totalFootages === this.loadedFootagesCount;
  1253. }
  1254. function setCacheType(type, elementHelper) {
  1255. if (type === 'svg') {
  1256. this._elementHelper = elementHelper;
  1257. this._createImageData = this.createImageData.bind(this);
  1258. } else {
  1259. this._createImageData = this.createImgData.bind(this);
  1260. }
  1261. }
  1262. function ImagePreloaderFactory() {
  1263. this._imageLoaded = imageLoaded.bind(this);
  1264. this._footageLoaded = footageLoaded.bind(this);
  1265. this.testImageLoaded = testImageLoaded.bind(this);
  1266. this.createFootageData = createFootageData.bind(this);
  1267. this.assetsPath = '';
  1268. this.path = '';
  1269. this.totalImages = 0;
  1270. this.totalFootages = 0;
  1271. this.loadedAssets = 0;
  1272. this.loadedFootagesCount = 0;
  1273. this.imagesLoadedCb = null;
  1274. this.images = [];
  1275. }
  1276. ImagePreloaderFactory.prototype = {
  1277. loadAssets: loadAssets,
  1278. setAssetsPath: setAssetsPath,
  1279. setPath: setPath,
  1280. loadedImages: loadedImages,
  1281. loadedFootages: loadedFootages,
  1282. destroy: destroy,
  1283. getAsset: getAsset,
  1284. createImgData: createImgData,
  1285. createImageData: createImageData,
  1286. imageLoaded: imageLoaded,
  1287. footageLoaded: footageLoaded,
  1288. setCacheType: setCacheType
  1289. };
  1290. return ImagePreloaderFactory;
  1291. }();
  1292. function BaseEvent() {}
  1293. BaseEvent.prototype = {
  1294. triggerEvent: function triggerEvent(eventName, args) {
  1295. if (this._cbs[eventName]) {
  1296. var callbacks = this._cbs[eventName];
  1297. for (var i = 0; i < callbacks.length; i += 1) {
  1298. callbacks[i](args);
  1299. }
  1300. }
  1301. },
  1302. addEventListener: function addEventListener(eventName, callback) {
  1303. if (!this._cbs[eventName]) {
  1304. this._cbs[eventName] = [];
  1305. }
  1306. this._cbs[eventName].push(callback);
  1307. return function () {
  1308. this.removeEventListener(eventName, callback);
  1309. }.bind(this);
  1310. },
  1311. removeEventListener: function removeEventListener(eventName, callback) {
  1312. if (!callback) {
  1313. this._cbs[eventName] = null;
  1314. } else if (this._cbs[eventName]) {
  1315. var i = 0;
  1316. var len = this._cbs[eventName].length;
  1317. while (i < len) {
  1318. if (this._cbs[eventName][i] === callback) {
  1319. this._cbs[eventName].splice(i, 1);
  1320. i -= 1;
  1321. len -= 1;
  1322. }
  1323. i += 1;
  1324. }
  1325. if (!this._cbs[eventName].length) {
  1326. this._cbs[eventName] = null;
  1327. }
  1328. }
  1329. }
  1330. };
  1331. var markerParser = function () {
  1332. function parsePayloadLines(payload) {
  1333. var lines = payload.split('\r\n');
  1334. var keys = {};
  1335. var line;
  1336. var keysCount = 0;
  1337. for (var i = 0; i < lines.length; i += 1) {
  1338. line = lines[i].split(':');
  1339. if (line.length === 2) {
  1340. keys[line[0]] = line[1].trim();
  1341. keysCount += 1;
  1342. }
  1343. }
  1344. if (keysCount === 0) {
  1345. throw new Error();
  1346. }
  1347. return keys;
  1348. }
  1349. return function (_markers) {
  1350. var markers = [];
  1351. for (var i = 0; i < _markers.length; i += 1) {
  1352. var _marker = _markers[i];
  1353. var markerData = {
  1354. time: _marker.tm,
  1355. duration: _marker.dr
  1356. };
  1357. try {
  1358. markerData.payload = JSON.parse(_markers[i].cm);
  1359. } catch (_) {
  1360. try {
  1361. markerData.payload = parsePayloadLines(_markers[i].cm);
  1362. } catch (__) {
  1363. markerData.payload = {
  1364. name: _markers[i].cm
  1365. };
  1366. }
  1367. }
  1368. markers.push(markerData);
  1369. }
  1370. return markers;
  1371. };
  1372. }();
  1373. var ProjectInterface = function () {
  1374. function registerComposition(comp) {
  1375. this.compositions.push(comp);
  1376. }
  1377. return function () {
  1378. function _thisProjectFunction(name) {
  1379. var i = 0;
  1380. var len = this.compositions.length;
  1381. while (i < len) {
  1382. if (this.compositions[i].data && this.compositions[i].data.nm === name) {
  1383. if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  1384. this.compositions[i].prepareFrame(this.currentFrame);
  1385. }
  1386. return this.compositions[i].compInterface;
  1387. }
  1388. i += 1;
  1389. }
  1390. return null;
  1391. }
  1392. _thisProjectFunction.compositions = [];
  1393. _thisProjectFunction.currentFrame = 0;
  1394. _thisProjectFunction.registerComposition = registerComposition;
  1395. return _thisProjectFunction;
  1396. };
  1397. }();
  1398. var renderers = {};
  1399. var registerRenderer = function registerRenderer(key, value) {
  1400. renderers[key] = value;
  1401. };
  1402. function getRenderer(key) {
  1403. return renderers[key];
  1404. }
  1405. function getRegisteredRenderer() {
  1406. // Returns canvas by default for compatibility
  1407. if (renderers.canvas) {
  1408. return 'canvas';
  1409. }
  1410. // Returns any renderer that is registered
  1411. for (var key in renderers) {
  1412. if (renderers[key]) {
  1413. return key;
  1414. }
  1415. }
  1416. return '';
  1417. }
  1418. function _typeof$1(o) { "@babel/helpers - typeof"; return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$1(o); }
  1419. var AnimationItem = function AnimationItem() {
  1420. this._cbs = [];
  1421. this.name = '';
  1422. this.path = '';
  1423. this.isLoaded = false;
  1424. this.currentFrame = 0;
  1425. this.currentRawFrame = 0;
  1426. this.firstFrame = 0;
  1427. this.totalFrames = 0;
  1428. this.frameRate = 0;
  1429. this.frameMult = 0;
  1430. this.playSpeed = 1;
  1431. this.playDirection = 1;
  1432. this.playCount = 0;
  1433. this.animationData = {};
  1434. this.assets = [];
  1435. this.isPaused = true;
  1436. this.autoplay = false;
  1437. this.loop = true;
  1438. this.renderer = null;
  1439. this.animationID = createElementID();
  1440. this.assetsPath = '';
  1441. this.timeCompleted = 0;
  1442. this.segmentPos = 0;
  1443. this.isSubframeEnabled = getSubframeEnabled();
  1444. this.segments = [];
  1445. this._idle = true;
  1446. this._completedLoop = false;
  1447. this.projectInterface = ProjectInterface();
  1448. this.imagePreloader = new ImagePreloader();
  1449. this.audioController = audioControllerFactory();
  1450. this.markers = [];
  1451. this.configAnimation = this.configAnimation.bind(this);
  1452. this.onSetupError = this.onSetupError.bind(this);
  1453. this.onSegmentComplete = this.onSegmentComplete.bind(this);
  1454. this.drawnFrameEvent = new BMEnterFrameEvent('drawnFrame', 0, 0, 0);
  1455. this.expressionsPlugin = getExpressionsPlugin();
  1456. };
  1457. extendPrototype([BaseEvent], AnimationItem);
  1458. AnimationItem.prototype.setParams = function (params) {
  1459. if (params.wrapper || params.container) {
  1460. this.wrapper = params.wrapper || params.container;
  1461. }
  1462. var animType = 'svg';
  1463. if (params.animType) {
  1464. animType = params.animType;
  1465. } else if (params.renderer) {
  1466. animType = params.renderer;
  1467. }
  1468. var RendererClass = getRenderer(animType);
  1469. this.renderer = new RendererClass(this, params.rendererSettings);
  1470. this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs);
  1471. this.renderer.setProjectInterface(this.projectInterface);
  1472. this.animType = animType;
  1473. if (params.loop === '' || params.loop === null || params.loop === undefined || params.loop === true) {
  1474. this.loop = true;
  1475. } else if (params.loop === false) {
  1476. this.loop = false;
  1477. } else {
  1478. this.loop = parseInt(params.loop, 10);
  1479. }
  1480. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  1481. this.name = params.name ? params.name : '';
  1482. this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true;
  1483. this.assetsPath = params.assetsPath;
  1484. this.initialSegment = params.initialSegment;
  1485. if (params.audioFactory) {
  1486. this.audioController.setAudioFactory(params.audioFactory);
  1487. }
  1488. if (params.animationData) {
  1489. this.setupAnimation(params.animationData);
  1490. } else if (params.path) {
  1491. if (params.path.lastIndexOf('\\') !== -1) {
  1492. this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1);
  1493. } else {
  1494. this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1);
  1495. }
  1496. this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1);
  1497. this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json'));
  1498. dataManager.loadAnimation(params.path, this.configAnimation, this.onSetupError);
  1499. }
  1500. };
  1501. AnimationItem.prototype.onSetupError = function () {
  1502. this.trigger('data_failed');
  1503. };
  1504. AnimationItem.prototype.setupAnimation = function (data) {
  1505. dataManager.completeAnimation(data, this.configAnimation);
  1506. };
  1507. AnimationItem.prototype.setData = function (wrapper, animationData) {
  1508. if (animationData) {
  1509. if (_typeof$1(animationData) !== 'object') {
  1510. animationData = JSON.parse(animationData);
  1511. }
  1512. }
  1513. var params = {
  1514. wrapper: wrapper,
  1515. animationData: animationData
  1516. };
  1517. var wrapperAttributes = wrapper.attributes;
  1518. params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary
  1519. ? wrapperAttributes.getNamedItem('data-animation-path').value : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary
  1520. ? wrapperAttributes.getNamedItem('data-bm-path').value : wrapperAttributes.getNamedItem('bm-path') ? wrapperAttributes.getNamedItem('bm-path').value : '';
  1521. params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary
  1522. ? wrapperAttributes.getNamedItem('data-anim-type').value : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary
  1523. ? wrapperAttributes.getNamedItem('data-bm-type').value : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary
  1524. ? wrapperAttributes.getNamedItem('bm-type').value : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary
  1525. ? wrapperAttributes.getNamedItem('data-bm-renderer').value : wrapperAttributes.getNamedItem('bm-renderer') ? wrapperAttributes.getNamedItem('bm-renderer').value : getRegisteredRenderer() || 'canvas';
  1526. var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary
  1527. ? wrapperAttributes.getNamedItem('data-anim-loop').value : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary
  1528. ? wrapperAttributes.getNamedItem('data-bm-loop').value : wrapperAttributes.getNamedItem('bm-loop') ? wrapperAttributes.getNamedItem('bm-loop').value : '';
  1529. if (loop === 'false') {
  1530. params.loop = false;
  1531. } else if (loop === 'true') {
  1532. params.loop = true;
  1533. } else if (loop !== '') {
  1534. params.loop = parseInt(loop, 10);
  1535. }
  1536. var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary
  1537. ? wrapperAttributes.getNamedItem('data-anim-autoplay').value : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary
  1538. ? wrapperAttributes.getNamedItem('data-bm-autoplay').value : wrapperAttributes.getNamedItem('bm-autoplay') ? wrapperAttributes.getNamedItem('bm-autoplay').value : true;
  1539. params.autoplay = autoplay !== 'false';
  1540. params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary
  1541. ? wrapperAttributes.getNamedItem('data-name').value : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary
  1542. ? wrapperAttributes.getNamedItem('data-bm-name').value : wrapperAttributes.getNamedItem('bm-name') ? wrapperAttributes.getNamedItem('bm-name').value : '';
  1543. var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary
  1544. ? wrapperAttributes.getNamedItem('data-anim-prerender').value : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary
  1545. ? wrapperAttributes.getNamedItem('data-bm-prerender').value : wrapperAttributes.getNamedItem('bm-prerender') ? wrapperAttributes.getNamedItem('bm-prerender').value : '';
  1546. if (prerender === 'false') {
  1547. params.prerender = false;
  1548. }
  1549. if (!params.path) {
  1550. this.trigger('destroy');
  1551. } else {
  1552. this.setParams(params);
  1553. }
  1554. };
  1555. AnimationItem.prototype.includeLayers = function (data) {
  1556. if (data.op > this.animationData.op) {
  1557. this.animationData.op = data.op;
  1558. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  1559. }
  1560. var layers = this.animationData.layers;
  1561. var i;
  1562. var len = layers.length;
  1563. var newLayers = data.layers;
  1564. var j;
  1565. var jLen = newLayers.length;
  1566. for (j = 0; j < jLen; j += 1) {
  1567. i = 0;
  1568. while (i < len) {
  1569. if (layers[i].id === newLayers[j].id) {
  1570. layers[i] = newLayers[j];
  1571. break;
  1572. }
  1573. i += 1;
  1574. }
  1575. }
  1576. if (data.chars || data.fonts) {
  1577. this.renderer.globalData.fontManager.addChars(data.chars);
  1578. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  1579. }
  1580. if (data.assets) {
  1581. len = data.assets.length;
  1582. for (i = 0; i < len; i += 1) {
  1583. this.animationData.assets.push(data.assets[i]);
  1584. }
  1585. }
  1586. this.animationData.__complete = false;
  1587. dataManager.completeAnimation(this.animationData, this.onSegmentComplete);
  1588. };
  1589. AnimationItem.prototype.onSegmentComplete = function (data) {
  1590. this.animationData = data;
  1591. var expressionsPlugin = getExpressionsPlugin();
  1592. if (expressionsPlugin) {
  1593. expressionsPlugin.initExpressions(this);
  1594. }
  1595. this.loadNextSegment();
  1596. };
  1597. AnimationItem.prototype.loadNextSegment = function () {
  1598. var segments = this.animationData.segments;
  1599. if (!segments || segments.length === 0 || !this.autoloadSegments) {
  1600. this.trigger('data_ready');
  1601. this.timeCompleted = this.totalFrames;
  1602. return;
  1603. }
  1604. var segment = segments.shift();
  1605. this.timeCompleted = segment.time * this.frameRate;
  1606. var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json';
  1607. this.segmentPos += 1;
  1608. dataManager.loadData(segmentPath, this.includeLayers.bind(this), function () {
  1609. this.trigger('data_failed');
  1610. }.bind(this));
  1611. };
  1612. AnimationItem.prototype.loadSegments = function () {
  1613. var segments = this.animationData.segments;
  1614. if (!segments) {
  1615. this.timeCompleted = this.totalFrames;
  1616. }
  1617. this.loadNextSegment();
  1618. };
  1619. AnimationItem.prototype.imagesLoaded = function () {
  1620. this.trigger('loaded_images');
  1621. this.checkLoaded();
  1622. };
  1623. AnimationItem.prototype.preloadImages = function () {
  1624. this.imagePreloader.setAssetsPath(this.assetsPath);
  1625. this.imagePreloader.setPath(this.path);
  1626. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  1627. };
  1628. AnimationItem.prototype.configAnimation = function (animData) {
  1629. if (!this.renderer) {
  1630. return;
  1631. }
  1632. try {
  1633. this.animationData = animData;
  1634. if (this.initialSegment) {
  1635. this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
  1636. this.firstFrame = Math.round(this.initialSegment[0]);
  1637. } else {
  1638. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  1639. this.firstFrame = Math.round(this.animationData.ip);
  1640. }
  1641. this.renderer.configAnimation(animData);
  1642. if (!animData.assets) {
  1643. animData.assets = [];
  1644. }
  1645. this.assets = this.animationData.assets;
  1646. this.frameRate = this.animationData.fr;
  1647. this.frameMult = this.animationData.fr / 1000;
  1648. this.renderer.searchExtraCompositions(animData.assets);
  1649. this.markers = markerParser(animData.markers || []);
  1650. this.trigger('config_ready');
  1651. this.preloadImages();
  1652. this.loadSegments();
  1653. this.updaFrameModifier();
  1654. this.waitForFontsLoaded();
  1655. if (this.isPaused) {
  1656. this.audioController.pause();
  1657. }
  1658. } catch (error) {
  1659. this.triggerConfigError(error);
  1660. }
  1661. };
  1662. AnimationItem.prototype.waitForFontsLoaded = function () {
  1663. if (!this.renderer) {
  1664. return;
  1665. }
  1666. if (this.renderer.globalData.fontManager.isLoaded) {
  1667. this.checkLoaded();
  1668. } else {
  1669. setTimeout(this.waitForFontsLoaded.bind(this), 20);
  1670. }
  1671. };
  1672. AnimationItem.prototype.checkLoaded = function () {
  1673. if (!this.isLoaded && this.renderer.globalData.fontManager.isLoaded && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== 'canvas') && this.imagePreloader.loadedFootages()) {
  1674. this.isLoaded = true;
  1675. var expressionsPlugin = getExpressionsPlugin();
  1676. if (expressionsPlugin) {
  1677. expressionsPlugin.initExpressions(this);
  1678. }
  1679. this.renderer.initItems();
  1680. setTimeout(function () {
  1681. this.trigger('DOMLoaded');
  1682. }.bind(this), 0);
  1683. this.gotoFrame();
  1684. if (this.autoplay) {
  1685. this.play();
  1686. }
  1687. }
  1688. };
  1689. AnimationItem.prototype.resize = function (width, height) {
  1690. // Adding this validation for backwards compatibility in case an event object was being passed down
  1691. var _width = typeof width === 'number' ? width : undefined;
  1692. var _height = typeof height === 'number' ? height : undefined;
  1693. this.renderer.updateContainerSize(_width, _height);
  1694. };
  1695. AnimationItem.prototype.setSubframe = function (flag) {
  1696. this.isSubframeEnabled = !!flag;
  1697. };
  1698. AnimationItem.prototype.gotoFrame = function () {
  1699. this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise
  1700. if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) {
  1701. this.currentFrame = this.timeCompleted;
  1702. }
  1703. this.trigger('enterFrame');
  1704. this.renderFrame();
  1705. this.trigger('drawnFrame');
  1706. };
  1707. AnimationItem.prototype.renderFrame = function () {
  1708. if (this.isLoaded === false || !this.renderer) {
  1709. return;
  1710. }
  1711. try {
  1712. if (this.expressionsPlugin) {
  1713. this.expressionsPlugin.resetFrame();
  1714. }
  1715. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  1716. } catch (error) {
  1717. this.triggerRenderFrameError(error);
  1718. }
  1719. };
  1720. AnimationItem.prototype.play = function (name) {
  1721. if (name && this.name !== name) {
  1722. return;
  1723. }
  1724. if (this.isPaused === true) {
  1725. this.isPaused = false;
  1726. this.trigger('_play');
  1727. this.audioController.resume();
  1728. if (this._idle) {
  1729. this._idle = false;
  1730. this.trigger('_active');
  1731. }
  1732. }
  1733. };
  1734. AnimationItem.prototype.pause = function (name) {
  1735. if (name && this.name !== name) {
  1736. return;
  1737. }
  1738. if (this.isPaused === false) {
  1739. this.isPaused = true;
  1740. this.trigger('_pause');
  1741. this._idle = true;
  1742. this.trigger('_idle');
  1743. this.audioController.pause();
  1744. }
  1745. };
  1746. AnimationItem.prototype.togglePause = function (name) {
  1747. if (name && this.name !== name) {
  1748. return;
  1749. }
  1750. if (this.isPaused === true) {
  1751. this.play();
  1752. } else {
  1753. this.pause();
  1754. }
  1755. };
  1756. AnimationItem.prototype.stop = function (name) {
  1757. if (name && this.name !== name) {
  1758. return;
  1759. }
  1760. this.pause();
  1761. this.playCount = 0;
  1762. this._completedLoop = false;
  1763. this.setCurrentRawFrameValue(0);
  1764. };
  1765. AnimationItem.prototype.getMarkerData = function (markerName) {
  1766. var marker;
  1767. for (var i = 0; i < this.markers.length; i += 1) {
  1768. marker = this.markers[i];
  1769. if (marker.payload && marker.payload.name === markerName) {
  1770. return marker;
  1771. }
  1772. }
  1773. return null;
  1774. };
  1775. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  1776. if (name && this.name !== name) {
  1777. return;
  1778. }
  1779. var numValue = Number(value);
  1780. if (isNaN(numValue)) {
  1781. var marker = this.getMarkerData(value);
  1782. if (marker) {
  1783. this.goToAndStop(marker.time, true);
  1784. }
  1785. } else if (isFrame) {
  1786. this.setCurrentRawFrameValue(value);
  1787. } else {
  1788. this.setCurrentRawFrameValue(value * this.frameModifier);
  1789. }
  1790. this.pause();
  1791. };
  1792. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  1793. if (name && this.name !== name) {
  1794. return;
  1795. }
  1796. var numValue = Number(value);
  1797. if (isNaN(numValue)) {
  1798. var marker = this.getMarkerData(value);
  1799. if (marker) {
  1800. if (!marker.duration) {
  1801. this.goToAndStop(marker.time, true);
  1802. } else {
  1803. this.playSegments([marker.time, marker.time + marker.duration], true);
  1804. }
  1805. }
  1806. } else {
  1807. this.goToAndStop(numValue, isFrame, name);
  1808. }
  1809. this.play();
  1810. };
  1811. AnimationItem.prototype.advanceTime = function (value) {
  1812. if (this.isPaused === true || this.isLoaded === false) {
  1813. return;
  1814. }
  1815. var nextValue = this.currentRawFrame + value * this.frameModifier;
  1816. var _isComplete = false;
  1817. // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  1818. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  1819. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  1820. if (!this.loop || this.playCount === this.loop) {
  1821. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  1822. _isComplete = true;
  1823. nextValue = this.totalFrames - 1;
  1824. }
  1825. } else if (nextValue >= this.totalFrames) {
  1826. this.playCount += 1;
  1827. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1828. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  1829. this._completedLoop = true;
  1830. this.trigger('loopComplete');
  1831. }
  1832. } else {
  1833. this.setCurrentRawFrameValue(nextValue);
  1834. }
  1835. } else if (nextValue < 0) {
  1836. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1837. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) {
  1838. // eslint-disable-line no-plusplus
  1839. this.setCurrentRawFrameValue(this.totalFrames + nextValue % this.totalFrames);
  1840. if (!this._completedLoop) {
  1841. this._completedLoop = true;
  1842. } else {
  1843. this.trigger('loopComplete');
  1844. }
  1845. } else {
  1846. _isComplete = true;
  1847. nextValue = 0;
  1848. }
  1849. }
  1850. } else {
  1851. this.setCurrentRawFrameValue(nextValue);
  1852. }
  1853. if (_isComplete) {
  1854. this.setCurrentRawFrameValue(nextValue);
  1855. this.pause();
  1856. this.trigger('complete');
  1857. }
  1858. };
  1859. AnimationItem.prototype.adjustSegment = function (arr, offset) {
  1860. this.playCount = 0;
  1861. if (arr[1] < arr[0]) {
  1862. if (this.frameModifier > 0) {
  1863. if (this.playSpeed < 0) {
  1864. this.setSpeed(-this.playSpeed);
  1865. } else {
  1866. this.setDirection(-1);
  1867. }
  1868. }
  1869. this.totalFrames = arr[0] - arr[1];
  1870. this.timeCompleted = this.totalFrames;
  1871. this.firstFrame = arr[1];
  1872. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  1873. } else if (arr[1] > arr[0]) {
  1874. if (this.frameModifier < 0) {
  1875. if (this.playSpeed < 0) {
  1876. this.setSpeed(-this.playSpeed);
  1877. } else {
  1878. this.setDirection(1);
  1879. }
  1880. }
  1881. this.totalFrames = arr[1] - arr[0];
  1882. this.timeCompleted = this.totalFrames;
  1883. this.firstFrame = arr[0];
  1884. this.setCurrentRawFrameValue(0.001 + offset);
  1885. }
  1886. this.trigger('segmentStart');
  1887. };
  1888. AnimationItem.prototype.setSegment = function (init, end) {
  1889. var pendingFrame = -1;
  1890. if (this.isPaused) {
  1891. if (this.currentRawFrame + this.firstFrame < init) {
  1892. pendingFrame = init;
  1893. } else if (this.currentRawFrame + this.firstFrame > end) {
  1894. pendingFrame = end - init;
  1895. }
  1896. }
  1897. this.firstFrame = init;
  1898. this.totalFrames = end - init;
  1899. this.timeCompleted = this.totalFrames;
  1900. if (pendingFrame !== -1) {
  1901. this.goToAndStop(pendingFrame, true);
  1902. }
  1903. };
  1904. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  1905. if (forceFlag) {
  1906. this.segments.length = 0;
  1907. }
  1908. if (_typeof$1(arr[0]) === 'object') {
  1909. var i;
  1910. var len = arr.length;
  1911. for (i = 0; i < len; i += 1) {
  1912. this.segments.push(arr[i]);
  1913. }
  1914. } else {
  1915. this.segments.push(arr);
  1916. }
  1917. if (this.segments.length && forceFlag) {
  1918. this.adjustSegment(this.segments.shift(), 0);
  1919. }
  1920. if (this.isPaused) {
  1921. this.play();
  1922. }
  1923. };
  1924. AnimationItem.prototype.resetSegments = function (forceFlag) {
  1925. this.segments.length = 0;
  1926. this.segments.push([this.animationData.ip, this.animationData.op]);
  1927. if (forceFlag) {
  1928. this.checkSegments(0);
  1929. }
  1930. };
  1931. AnimationItem.prototype.checkSegments = function (offset) {
  1932. if (this.segments.length) {
  1933. this.adjustSegment(this.segments.shift(), offset);
  1934. return true;
  1935. }
  1936. return false;
  1937. };
  1938. AnimationItem.prototype.destroy = function (name) {
  1939. if (name && this.name !== name || !this.renderer) {
  1940. return;
  1941. }
  1942. this.renderer.destroy();
  1943. this.imagePreloader.destroy();
  1944. this.trigger('destroy');
  1945. this._cbs = null;
  1946. this.onEnterFrame = null;
  1947. this.onLoopComplete = null;
  1948. this.onComplete = null;
  1949. this.onSegmentStart = null;
  1950. this.onDestroy = null;
  1951. this.renderer = null;
  1952. this.expressionsPlugin = null;
  1953. this.imagePreloader = null;
  1954. this.projectInterface = null;
  1955. };
  1956. AnimationItem.prototype.setCurrentRawFrameValue = function (value) {
  1957. this.currentRawFrame = value;
  1958. this.gotoFrame();
  1959. };
  1960. AnimationItem.prototype.setSpeed = function (val) {
  1961. this.playSpeed = val;
  1962. this.updaFrameModifier();
  1963. };
  1964. AnimationItem.prototype.setDirection = function (val) {
  1965. this.playDirection = val < 0 ? -1 : 1;
  1966. this.updaFrameModifier();
  1967. };
  1968. AnimationItem.prototype.setLoop = function (isLooping) {
  1969. this.loop = isLooping;
  1970. };
  1971. AnimationItem.prototype.setVolume = function (val, name) {
  1972. if (name && this.name !== name) {
  1973. return;
  1974. }
  1975. this.audioController.setVolume(val);
  1976. };
  1977. AnimationItem.prototype.getVolume = function () {
  1978. return this.audioController.getVolume();
  1979. };
  1980. AnimationItem.prototype.mute = function (name) {
  1981. if (name && this.name !== name) {
  1982. return;
  1983. }
  1984. this.audioController.mute();
  1985. };
  1986. AnimationItem.prototype.unmute = function (name) {
  1987. if (name && this.name !== name) {
  1988. return;
  1989. }
  1990. this.audioController.unmute();
  1991. };
  1992. AnimationItem.prototype.updaFrameModifier = function () {
  1993. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  1994. this.audioController.setRate(this.playSpeed * this.playDirection);
  1995. };
  1996. AnimationItem.prototype.getPath = function () {
  1997. return this.path;
  1998. };
  1999. AnimationItem.prototype.getAssetsPath = function (assetData) {
  2000. var path = '';
  2001. if (assetData.e) {
  2002. path = assetData.p;
  2003. } else if (this.assetsPath) {
  2004. var imagePath = assetData.p;
  2005. if (imagePath.indexOf('images/') !== -1) {
  2006. imagePath = imagePath.split('/')[1];
  2007. }
  2008. path = this.assetsPath + imagePath;
  2009. } else {
  2010. path = this.path;
  2011. path += assetData.u ? assetData.u : '';
  2012. path += assetData.p;
  2013. }
  2014. return path;
  2015. };
  2016. AnimationItem.prototype.getAssetData = function (id) {
  2017. var i = 0;
  2018. var len = this.assets.length;
  2019. while (i < len) {
  2020. if (id === this.assets[i].id) {
  2021. return this.assets[i];
  2022. }
  2023. i += 1;
  2024. }
  2025. return null;
  2026. };
  2027. AnimationItem.prototype.hide = function () {
  2028. this.renderer.hide();
  2029. };
  2030. AnimationItem.prototype.show = function () {
  2031. this.renderer.show();
  2032. };
  2033. AnimationItem.prototype.getDuration = function (isFrame) {
  2034. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  2035. };
  2036. AnimationItem.prototype.updateDocumentData = function (path, documentData, index) {
  2037. try {
  2038. var element = this.renderer.getElementByPath(path);
  2039. element.updateDocumentData(documentData, index);
  2040. } catch (error) {
  2041. // TODO: decide how to handle catch case
  2042. }
  2043. };
  2044. AnimationItem.prototype.trigger = function (name) {
  2045. if (this._cbs && this._cbs[name]) {
  2046. switch (name) {
  2047. case 'enterFrame':
  2048. this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
  2049. break;
  2050. case 'drawnFrame':
  2051. this.drawnFrameEvent.currentTime = this.currentFrame;
  2052. this.drawnFrameEvent.totalTime = this.totalFrames;
  2053. this.drawnFrameEvent.direction = this.frameModifier;
  2054. this.triggerEvent(name, this.drawnFrameEvent);
  2055. break;
  2056. case 'loopComplete':
  2057. this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2058. break;
  2059. case 'complete':
  2060. this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult));
  2061. break;
  2062. case 'segmentStart':
  2063. this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2064. break;
  2065. case 'destroy':
  2066. this.triggerEvent(name, new BMDestroyEvent(name, this));
  2067. break;
  2068. default:
  2069. this.triggerEvent(name);
  2070. }
  2071. }
  2072. if (name === 'enterFrame' && this.onEnterFrame) {
  2073. this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult));
  2074. }
  2075. if (name === 'loopComplete' && this.onLoopComplete) {
  2076. this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2077. }
  2078. if (name === 'complete' && this.onComplete) {
  2079. this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult));
  2080. }
  2081. if (name === 'segmentStart' && this.onSegmentStart) {
  2082. this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2083. }
  2084. if (name === 'destroy' && this.onDestroy) {
  2085. this.onDestroy.call(this, new BMDestroyEvent(name, this));
  2086. }
  2087. };
  2088. AnimationItem.prototype.triggerRenderFrameError = function (nativeError) {
  2089. var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
  2090. this.triggerEvent('error', error);
  2091. if (this.onError) {
  2092. this.onError.call(this, error);
  2093. }
  2094. };
  2095. AnimationItem.prototype.triggerConfigError = function (nativeError) {
  2096. var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
  2097. this.triggerEvent('error', error);
  2098. if (this.onError) {
  2099. this.onError.call(this, error);
  2100. }
  2101. };
  2102. var animationManager = function () {
  2103. var moduleOb = {};
  2104. var registeredAnimations = [];
  2105. var initTime = 0;
  2106. var len = 0;
  2107. var playingAnimationsNum = 0;
  2108. var _stopped = true;
  2109. var _isFrozen = false;
  2110. function removeElement(ev) {
  2111. var i = 0;
  2112. var animItem = ev.target;
  2113. while (i < len) {
  2114. if (registeredAnimations[i].animation === animItem) {
  2115. registeredAnimations.splice(i, 1);
  2116. i -= 1;
  2117. len -= 1;
  2118. if (!animItem.isPaused) {
  2119. subtractPlayingCount();
  2120. }
  2121. }
  2122. i += 1;
  2123. }
  2124. }
  2125. function registerAnimation(element, animationData) {
  2126. if (!element) {
  2127. return null;
  2128. }
  2129. var i = 0;
  2130. while (i < len) {
  2131. if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) {
  2132. return registeredAnimations[i].animation;
  2133. }
  2134. i += 1;
  2135. }
  2136. var animItem = new AnimationItem();
  2137. setupAnimation(animItem, element);
  2138. animItem.setData(element, animationData);
  2139. return animItem;
  2140. }
  2141. function getRegisteredAnimations() {
  2142. var i;
  2143. var lenAnims = registeredAnimations.length;
  2144. var animations = [];
  2145. for (i = 0; i < lenAnims; i += 1) {
  2146. animations.push(registeredAnimations[i].animation);
  2147. }
  2148. return animations;
  2149. }
  2150. function addPlayingCount() {
  2151. playingAnimationsNum += 1;
  2152. activate();
  2153. }
  2154. function subtractPlayingCount() {
  2155. playingAnimationsNum -= 1;
  2156. }
  2157. function setupAnimation(animItem, element) {
  2158. animItem.addEventListener('destroy', removeElement);
  2159. animItem.addEventListener('_active', addPlayingCount);
  2160. animItem.addEventListener('_idle', subtractPlayingCount);
  2161. registeredAnimations.push({
  2162. elem: element,
  2163. animation: animItem
  2164. });
  2165. len += 1;
  2166. }
  2167. function loadAnimation(params) {
  2168. var animItem = new AnimationItem();
  2169. setupAnimation(animItem, null);
  2170. animItem.setParams(params);
  2171. return animItem;
  2172. }
  2173. function setSpeed(val, animation) {
  2174. var i;
  2175. for (i = 0; i < len; i += 1) {
  2176. registeredAnimations[i].animation.setSpeed(val, animation);
  2177. }
  2178. }
  2179. function setDirection(val, animation) {
  2180. var i;
  2181. for (i = 0; i < len; i += 1) {
  2182. registeredAnimations[i].animation.setDirection(val, animation);
  2183. }
  2184. }
  2185. function play(animation) {
  2186. var i;
  2187. for (i = 0; i < len; i += 1) {
  2188. registeredAnimations[i].animation.play(animation);
  2189. }
  2190. }
  2191. function resume(nowTime) {
  2192. var elapsedTime = nowTime - initTime;
  2193. var i;
  2194. for (i = 0; i < len; i += 1) {
  2195. registeredAnimations[i].animation.advanceTime(elapsedTime);
  2196. }
  2197. initTime = nowTime;
  2198. if (playingAnimationsNum && !_isFrozen) {
  2199. window.requestAnimationFrame(resume);
  2200. } else {
  2201. _stopped = true;
  2202. }
  2203. }
  2204. function first(nowTime) {
  2205. initTime = nowTime;
  2206. window.requestAnimationFrame(resume);
  2207. }
  2208. function pause(animation) {
  2209. var i;
  2210. for (i = 0; i < len; i += 1) {
  2211. registeredAnimations[i].animation.pause(animation);
  2212. }
  2213. }
  2214. function goToAndStop(value, isFrame, animation) {
  2215. var i;
  2216. for (i = 0; i < len; i += 1) {
  2217. registeredAnimations[i].animation.goToAndStop(value, isFrame, animation);
  2218. }
  2219. }
  2220. function stop(animation) {
  2221. var i;
  2222. for (i = 0; i < len; i += 1) {
  2223. registeredAnimations[i].animation.stop(animation);
  2224. }
  2225. }
  2226. function togglePause(animation) {
  2227. var i;
  2228. for (i = 0; i < len; i += 1) {
  2229. registeredAnimations[i].animation.togglePause(animation);
  2230. }
  2231. }
  2232. function destroy(animation) {
  2233. var i;
  2234. for (i = len - 1; i >= 0; i -= 1) {
  2235. registeredAnimations[i].animation.destroy(animation);
  2236. }
  2237. }
  2238. function searchAnimations(animationData, standalone, renderer) {
  2239. var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')), [].slice.call(document.getElementsByClassName('bodymovin')));
  2240. var i;
  2241. var lenAnims = animElements.length;
  2242. for (i = 0; i < lenAnims; i += 1) {
  2243. if (renderer) {
  2244. animElements[i].setAttribute('data-bm-type', renderer);
  2245. }
  2246. registerAnimation(animElements[i], animationData);
  2247. }
  2248. if (standalone && lenAnims === 0) {
  2249. if (!renderer) {
  2250. renderer = 'svg';
  2251. }
  2252. var body = document.getElementsByTagName('body')[0];
  2253. body.innerText = '';
  2254. var div = createTag('div');
  2255. div.style.width = '100%';
  2256. div.style.height = '100%';
  2257. div.setAttribute('data-bm-type', renderer);
  2258. body.appendChild(div);
  2259. registerAnimation(div, animationData);
  2260. }
  2261. }
  2262. function resize() {
  2263. var i;
  2264. for (i = 0; i < len; i += 1) {
  2265. registeredAnimations[i].animation.resize();
  2266. }
  2267. }
  2268. function activate() {
  2269. if (!_isFrozen && playingAnimationsNum) {
  2270. if (_stopped) {
  2271. window.requestAnimationFrame(first);
  2272. _stopped = false;
  2273. }
  2274. }
  2275. }
  2276. function freeze() {
  2277. _isFrozen = true;
  2278. }
  2279. function unfreeze() {
  2280. _isFrozen = false;
  2281. activate();
  2282. }
  2283. function setVolume(val, animation) {
  2284. var i;
  2285. for (i = 0; i < len; i += 1) {
  2286. registeredAnimations[i].animation.setVolume(val, animation);
  2287. }
  2288. }
  2289. function mute(animation) {
  2290. var i;
  2291. for (i = 0; i < len; i += 1) {
  2292. registeredAnimations[i].animation.mute(animation);
  2293. }
  2294. }
  2295. function unmute(animation) {
  2296. var i;
  2297. for (i = 0; i < len; i += 1) {
  2298. registeredAnimations[i].animation.unmute(animation);
  2299. }
  2300. }
  2301. moduleOb.registerAnimation = registerAnimation;
  2302. moduleOb.loadAnimation = loadAnimation;
  2303. moduleOb.setSpeed = setSpeed;
  2304. moduleOb.setDirection = setDirection;
  2305. moduleOb.play = play;
  2306. moduleOb.pause = pause;
  2307. moduleOb.stop = stop;
  2308. moduleOb.togglePause = togglePause;
  2309. moduleOb.searchAnimations = searchAnimations;
  2310. moduleOb.resize = resize;
  2311. // moduleOb.start = start;
  2312. moduleOb.goToAndStop = goToAndStop;
  2313. moduleOb.destroy = destroy;
  2314. moduleOb.freeze = freeze;
  2315. moduleOb.unfreeze = unfreeze;
  2316. moduleOb.setVolume = setVolume;
  2317. moduleOb.mute = mute;
  2318. moduleOb.unmute = unmute;
  2319. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  2320. return moduleOb;
  2321. }();
  2322. /* eslint-disable */
  2323. var BezierFactory = function () {
  2324. /**
  2325. * BezierEasing - use bezier curve for transition easing function
  2326. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  2327. *
  2328. * Credits: is based on Firefox's nsSMILKeySpline.cpp
  2329. * Usage:
  2330. * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
  2331. * spline.get(x) => returns the easing value | x must be in [0, 1] range
  2332. *
  2333. */
  2334. var ob = {};
  2335. ob.getBezierEasing = getBezierEasing;
  2336. var beziers = {};
  2337. function getBezierEasing(a, b, c, d, nm) {
  2338. var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p');
  2339. if (beziers[str]) {
  2340. return beziers[str];
  2341. }
  2342. var bezEasing = new BezierEasing([a, b, c, d]);
  2343. beziers[str] = bezEasing;
  2344. return bezEasing;
  2345. }
  2346. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  2347. var NEWTON_ITERATIONS = 4;
  2348. var NEWTON_MIN_SLOPE = 0.001;
  2349. var SUBDIVISION_PRECISION = 0.0000001;
  2350. var SUBDIVISION_MAX_ITERATIONS = 10;
  2351. var kSplineTableSize = 11;
  2352. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  2353. var float32ArraySupported = typeof Float32Array === 'function';
  2354. function A(aA1, aA2) {
  2355. return 1.0 - 3.0 * aA2 + 3.0 * aA1;
  2356. }
  2357. function B(aA1, aA2) {
  2358. return 3.0 * aA2 - 6.0 * aA1;
  2359. }
  2360. function C(aA1) {
  2361. return 3.0 * aA1;
  2362. }
  2363. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  2364. function calcBezier(aT, aA1, aA2) {
  2365. return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
  2366. }
  2367. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  2368. function getSlope(aT, aA1, aA2) {
  2369. return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  2370. }
  2371. function binarySubdivide(aX, aA, aB, mX1, mX2) {
  2372. var currentX,
  2373. currentT,
  2374. i = 0;
  2375. do {
  2376. currentT = aA + (aB - aA) / 2.0;
  2377. currentX = calcBezier(currentT, mX1, mX2) - aX;
  2378. if (currentX > 0.0) {
  2379. aB = currentT;
  2380. } else {
  2381. aA = currentT;
  2382. }
  2383. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  2384. return currentT;
  2385. }
  2386. function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
  2387. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  2388. var currentSlope = getSlope(aGuessT, mX1, mX2);
  2389. if (currentSlope === 0.0) return aGuessT;
  2390. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  2391. aGuessT -= currentX / currentSlope;
  2392. }
  2393. return aGuessT;
  2394. }
  2395. /**
  2396. * points is an array of [ mX1, mY1, mX2, mY2 ]
  2397. */
  2398. function BezierEasing(points) {
  2399. this._p = points;
  2400. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  2401. this._precomputed = false;
  2402. this.get = this.get.bind(this);
  2403. }
  2404. BezierEasing.prototype = {
  2405. get: function get(x) {
  2406. var mX1 = this._p[0],
  2407. mY1 = this._p[1],
  2408. mX2 = this._p[2],
  2409. mY2 = this._p[3];
  2410. if (!this._precomputed) this._precompute();
  2411. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  2412. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  2413. if (x === 0) return 0;
  2414. if (x === 1) return 1;
  2415. return calcBezier(this._getTForX(x), mY1, mY2);
  2416. },
  2417. // Private part
  2418. _precompute: function _precompute() {
  2419. var mX1 = this._p[0],
  2420. mY1 = this._p[1],
  2421. mX2 = this._p[2],
  2422. mY2 = this._p[3];
  2423. this._precomputed = true;
  2424. if (mX1 !== mY1 || mX2 !== mY2) {
  2425. this._calcSampleValues();
  2426. }
  2427. },
  2428. _calcSampleValues: function _calcSampleValues() {
  2429. var mX1 = this._p[0],
  2430. mX2 = this._p[2];
  2431. for (var i = 0; i < kSplineTableSize; ++i) {
  2432. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  2433. }
  2434. },
  2435. /**
  2436. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  2437. */
  2438. _getTForX: function _getTForX(aX) {
  2439. var mX1 = this._p[0],
  2440. mX2 = this._p[2],
  2441. mSampleValues = this._mSampleValues;
  2442. var intervalStart = 0.0;
  2443. var currentSample = 1;
  2444. var lastSample = kSplineTableSize - 1;
  2445. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  2446. intervalStart += kSampleStepSize;
  2447. }
  2448. --currentSample;
  2449. // Interpolate to provide an initial guess for t
  2450. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
  2451. var guessForT = intervalStart + dist * kSampleStepSize;
  2452. var initialSlope = getSlope(guessForT, mX1, mX2);
  2453. if (initialSlope >= NEWTON_MIN_SLOPE) {
  2454. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  2455. }
  2456. if (initialSlope === 0.0) {
  2457. return guessForT;
  2458. }
  2459. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  2460. }
  2461. };
  2462. return ob;
  2463. }();
  2464. var pooling = function () {
  2465. function _double(arr) {
  2466. return arr.concat(createSizedArray(arr.length));
  2467. }
  2468. return {
  2469. "double": _double
  2470. };
  2471. }();
  2472. var poolFactory = function () {
  2473. return function (initialLength, _create, _release) {
  2474. var _length = 0;
  2475. var _maxLength = initialLength;
  2476. var pool = createSizedArray(_maxLength);
  2477. var ob = {
  2478. newElement: newElement,
  2479. release: release
  2480. };
  2481. function newElement() {
  2482. var element;
  2483. if (_length) {
  2484. _length -= 1;
  2485. element = pool[_length];
  2486. } else {
  2487. element = _create();
  2488. }
  2489. return element;
  2490. }
  2491. function release(element) {
  2492. if (_length === _maxLength) {
  2493. pool = pooling["double"](pool);
  2494. _maxLength *= 2;
  2495. }
  2496. if (_release) {
  2497. _release(element);
  2498. }
  2499. pool[_length] = element;
  2500. _length += 1;
  2501. }
  2502. return ob;
  2503. };
  2504. }();
  2505. var bezierLengthPool = function () {
  2506. function create() {
  2507. return {
  2508. addedLength: 0,
  2509. percents: createTypedArray('float32', getDefaultCurveSegments()),
  2510. lengths: createTypedArray('float32', getDefaultCurveSegments())
  2511. };
  2512. }
  2513. return poolFactory(8, create);
  2514. }();
  2515. var segmentsLengthPool = function () {
  2516. function create() {
  2517. return {
  2518. lengths: [],
  2519. totalLength: 0
  2520. };
  2521. }
  2522. function release(element) {
  2523. var i;
  2524. var len = element.lengths.length;
  2525. for (i = 0; i < len; i += 1) {
  2526. bezierLengthPool.release(element.lengths[i]);
  2527. }
  2528. element.lengths.length = 0;
  2529. }
  2530. return poolFactory(8, create, release);
  2531. }();
  2532. function bezFunction() {
  2533. var math = Math;
  2534. function pointOnLine2D(x1, y1, x2, y2, x3, y3) {
  2535. var det1 = x1 * y2 + y1 * x3 + x2 * y3 - x3 * y2 - y3 * x1 - x2 * y1;
  2536. return det1 > -0.001 && det1 < 0.001;
  2537. }
  2538. function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
  2539. if (z1 === 0 && z2 === 0 && z3 === 0) {
  2540. return pointOnLine2D(x1, y1, x2, y2, x3, y3);
  2541. }
  2542. var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2));
  2543. var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2));
  2544. var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2));
  2545. var diffDist;
  2546. if (dist1 > dist2) {
  2547. if (dist1 > dist3) {
  2548. diffDist = dist1 - dist2 - dist3;
  2549. } else {
  2550. diffDist = dist3 - dist2 - dist1;
  2551. }
  2552. } else if (dist3 > dist2) {
  2553. diffDist = dist3 - dist2 - dist1;
  2554. } else {
  2555. diffDist = dist2 - dist1 - dist3;
  2556. }
  2557. return diffDist > -0.0001 && diffDist < 0.0001;
  2558. }
  2559. var getBezierLength = function () {
  2560. return function (pt1, pt2, pt3, pt4) {
  2561. var curveSegments = getDefaultCurveSegments();
  2562. var k;
  2563. var i;
  2564. var len;
  2565. var ptCoord;
  2566. var perc;
  2567. var addedLength = 0;
  2568. var ptDistance;
  2569. var point = [];
  2570. var lastPoint = [];
  2571. var lengthData = bezierLengthPool.newElement();
  2572. len = pt3.length;
  2573. for (k = 0; k < curveSegments; k += 1) {
  2574. perc = k / (curveSegments - 1);
  2575. ptDistance = 0;
  2576. for (i = 0; i < len; i += 1) {
  2577. ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * pt3[i] + 3 * (1 - perc) * bmPow(perc, 2) * pt4[i] + bmPow(perc, 3) * pt2[i];
  2578. point[i] = ptCoord;
  2579. if (lastPoint[i] !== null) {
  2580. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2581. }
  2582. lastPoint[i] = point[i];
  2583. }
  2584. if (ptDistance) {
  2585. ptDistance = bmSqrt(ptDistance);
  2586. addedLength += ptDistance;
  2587. }
  2588. lengthData.percents[k] = perc;
  2589. lengthData.lengths[k] = addedLength;
  2590. }
  2591. lengthData.addedLength = addedLength;
  2592. return lengthData;
  2593. };
  2594. }();
  2595. function getSegmentsLength(shapeData) {
  2596. var segmentsLength = segmentsLengthPool.newElement();
  2597. var closed = shapeData.c;
  2598. var pathV = shapeData.v;
  2599. var pathO = shapeData.o;
  2600. var pathI = shapeData.i;
  2601. var i;
  2602. var len = shapeData._length;
  2603. var lengths = segmentsLength.lengths;
  2604. var totalLength = 0;
  2605. for (i = 0; i < len - 1; i += 1) {
  2606. lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]);
  2607. totalLength += lengths[i].addedLength;
  2608. }
  2609. if (closed && len) {
  2610. lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]);
  2611. totalLength += lengths[i].addedLength;
  2612. }
  2613. segmentsLength.totalLength = totalLength;
  2614. return segmentsLength;
  2615. }
  2616. function BezierData(length) {
  2617. this.segmentLength = 0;
  2618. this.points = new Array(length);
  2619. }
  2620. function PointData(partial, point) {
  2621. this.partialLength = partial;
  2622. this.point = point;
  2623. }
  2624. var buildBezierData = function () {
  2625. var storedData = {};
  2626. return function (pt1, pt2, pt3, pt4) {
  2627. var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p');
  2628. if (!storedData[bezierName]) {
  2629. var curveSegments = getDefaultCurveSegments();
  2630. var k;
  2631. var i;
  2632. var len;
  2633. var ptCoord;
  2634. var perc;
  2635. var addedLength = 0;
  2636. var ptDistance;
  2637. var point;
  2638. var lastPoint = null;
  2639. if (pt1.length === 2 && (pt1[0] !== pt2[0] || pt1[1] !== pt2[1]) && pointOnLine2D(pt1[0], pt1[1], pt2[0], pt2[1], pt1[0] + pt3[0], pt1[1] + pt3[1]) && pointOnLine2D(pt1[0], pt1[1], pt2[0], pt2[1], pt2[0] + pt4[0], pt2[1] + pt4[1])) {
  2640. curveSegments = 2;
  2641. }
  2642. var bezierData = new BezierData(curveSegments);
  2643. len = pt3.length;
  2644. for (k = 0; k < curveSegments; k += 1) {
  2645. point = createSizedArray(len);
  2646. perc = k / (curveSegments - 1);
  2647. ptDistance = 0;
  2648. for (i = 0; i < len; i += 1) {
  2649. ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * (pt1[i] + pt3[i]) + 3 * (1 - perc) * bmPow(perc, 2) * (pt2[i] + pt4[i]) + bmPow(perc, 3) * pt2[i];
  2650. point[i] = ptCoord;
  2651. if (lastPoint !== null) {
  2652. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2653. }
  2654. }
  2655. ptDistance = bmSqrt(ptDistance);
  2656. addedLength += ptDistance;
  2657. bezierData.points[k] = new PointData(ptDistance, point);
  2658. lastPoint = point;
  2659. }
  2660. bezierData.segmentLength = addedLength;
  2661. storedData[bezierName] = bezierData;
  2662. }
  2663. return storedData[bezierName];
  2664. };
  2665. }();
  2666. function getDistancePerc(perc, bezierData) {
  2667. var percents = bezierData.percents;
  2668. var lengths = bezierData.lengths;
  2669. var len = percents.length;
  2670. var initPos = bmFloor((len - 1) * perc);
  2671. var lengthPos = perc * bezierData.addedLength;
  2672. var lPerc = 0;
  2673. if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) {
  2674. return percents[initPos];
  2675. }
  2676. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  2677. var flag = true;
  2678. while (flag) {
  2679. if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) {
  2680. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]);
  2681. flag = false;
  2682. } else {
  2683. initPos += dir;
  2684. }
  2685. if (initPos < 0 || initPos >= len - 1) {
  2686. // FIX for TypedArrays that don't store floating point values with enough accuracy
  2687. if (initPos === len - 1) {
  2688. return percents[initPos];
  2689. }
  2690. flag = false;
  2691. }
  2692. }
  2693. return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc;
  2694. }
  2695. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  2696. var t1 = getDistancePerc(percent, bezierData);
  2697. var u1 = 1 - t1;
  2698. var ptX = math.round((u1 * u1 * u1 * pt1[0] + (t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1) * pt3[0] + (t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1) * pt4[0] + t1 * t1 * t1 * pt2[0]) * 1000) / 1000;
  2699. var ptY = math.round((u1 * u1 * u1 * pt1[1] + (t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1) * pt3[1] + (t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1) * pt4[1] + t1 * t1 * t1 * pt2[1]) * 1000) / 1000;
  2700. return [ptX, ptY];
  2701. }
  2702. var bezierSegmentPoints = createTypedArray('float32', 8);
  2703. function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) {
  2704. if (startPerc < 0) {
  2705. startPerc = 0;
  2706. } else if (startPerc > 1) {
  2707. startPerc = 1;
  2708. }
  2709. var t0 = getDistancePerc(startPerc, bezierData);
  2710. endPerc = endPerc > 1 ? 1 : endPerc;
  2711. var t1 = getDistancePerc(endPerc, bezierData);
  2712. var i;
  2713. var len = pt1.length;
  2714. var u0 = 1 - t0;
  2715. var u1 = 1 - t1;
  2716. var u0u0u0 = u0 * u0 * u0;
  2717. var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase
  2718. var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase
  2719. var t0t0t0 = t0 * t0 * t0;
  2720. //
  2721. var u0u0u1 = u0 * u0 * u1;
  2722. var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase
  2723. var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase
  2724. var t0t0t1 = t0 * t0 * t1;
  2725. //
  2726. var u0u1u1 = u0 * u1 * u1;
  2727. var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase
  2728. var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase
  2729. var t0t1t1 = t0 * t1 * t1;
  2730. //
  2731. var u1u1u1 = u1 * u1 * u1;
  2732. var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase
  2733. var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase
  2734. var t1t1t1 = t1 * t1 * t1;
  2735. for (i = 0; i < len; i += 1) {
  2736. bezierSegmentPoints[i * 4] = math.round((u0u0u0 * pt1[i] + t0u0u0_3 * pt3[i] + t0t0u0_3 * pt4[i] + t0t0t0 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2737. bezierSegmentPoints[i * 4 + 1] = math.round((u0u0u1 * pt1[i] + t0u0u1_3 * pt3[i] + t0t0u1_3 * pt4[i] + t0t0t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2738. bezierSegmentPoints[i * 4 + 2] = math.round((u0u1u1 * pt1[i] + t0u1u1_3 * pt3[i] + t0t1u1_3 * pt4[i] + t0t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2739. bezierSegmentPoints[i * 4 + 3] = math.round((u1u1u1 * pt1[i] + t1u1u1_3 * pt3[i] + t1t1u1_3 * pt4[i] + t1t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2740. }
  2741. return bezierSegmentPoints;
  2742. }
  2743. return {
  2744. getSegmentsLength: getSegmentsLength,
  2745. getNewSegment: getNewSegment,
  2746. getPointInSegment: getPointInSegment,
  2747. buildBezierData: buildBezierData,
  2748. pointOnLine2D: pointOnLine2D,
  2749. pointOnLine3D: pointOnLine3D
  2750. };
  2751. }
  2752. var bez = bezFunction();
  2753. var initFrame = initialDefaultFrame;
  2754. var mathAbs = Math.abs;
  2755. function interpolateValue(frameNum, caching) {
  2756. var offsetTime = this.offsetTime;
  2757. var newValue;
  2758. if (this.propType === 'multidimensional') {
  2759. newValue = createTypedArray('float32', this.pv.length);
  2760. }
  2761. var iterationIndex = caching.lastIndex;
  2762. var i = iterationIndex;
  2763. var len = this.keyframes.length - 1;
  2764. var flag = true;
  2765. var keyData;
  2766. var nextKeyData;
  2767. var keyframeMetadata;
  2768. while (flag) {
  2769. keyData = this.keyframes[i];
  2770. nextKeyData = this.keyframes[i + 1];
  2771. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) {
  2772. if (keyData.h) {
  2773. keyData = nextKeyData;
  2774. }
  2775. iterationIndex = 0;
  2776. break;
  2777. }
  2778. if (nextKeyData.t - offsetTime > frameNum) {
  2779. iterationIndex = i;
  2780. break;
  2781. }
  2782. if (i < len - 1) {
  2783. i += 1;
  2784. } else {
  2785. iterationIndex = 0;
  2786. flag = false;
  2787. }
  2788. }
  2789. keyframeMetadata = this.keyframesMetadata[i] || {};
  2790. var k;
  2791. var kLen;
  2792. var perc;
  2793. var jLen;
  2794. var j;
  2795. var fnc;
  2796. var nextKeyTime = nextKeyData.t - offsetTime;
  2797. var keyTime = keyData.t - offsetTime;
  2798. var endValue;
  2799. if (keyData.to) {
  2800. if (!keyframeMetadata.bezierData) {
  2801. keyframeMetadata.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  2802. }
  2803. var bezierData = keyframeMetadata.bezierData;
  2804. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  2805. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  2806. kLen = bezierData.points[ind].point.length;
  2807. for (k = 0; k < kLen; k += 1) {
  2808. newValue[k] = bezierData.points[ind].point[k];
  2809. }
  2810. // caching._lastKeyframeIndex = -1;
  2811. } else {
  2812. if (keyframeMetadata.__fnct) {
  2813. fnc = keyframeMetadata.__fnct;
  2814. } else {
  2815. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  2816. keyframeMetadata.__fnct = fnc;
  2817. }
  2818. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2819. var distanceInLine = bezierData.segmentLength * perc;
  2820. var segmentPerc;
  2821. var addedLength = caching.lastFrame < frameNum && caching._lastKeyframeIndex === i ? caching._lastAddedLength : 0;
  2822. j = caching.lastFrame < frameNum && caching._lastKeyframeIndex === i ? caching._lastPoint : 0;
  2823. flag = true;
  2824. jLen = bezierData.points.length;
  2825. while (flag) {
  2826. addedLength += bezierData.points[j].partialLength;
  2827. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  2828. kLen = bezierData.points[j].point.length;
  2829. for (k = 0; k < kLen; k += 1) {
  2830. newValue[k] = bezierData.points[j].point[k];
  2831. }
  2832. break;
  2833. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  2834. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  2835. kLen = bezierData.points[j].point.length;
  2836. for (k = 0; k < kLen; k += 1) {
  2837. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  2838. }
  2839. break;
  2840. }
  2841. if (j < jLen - 1) {
  2842. j += 1;
  2843. } else {
  2844. flag = false;
  2845. }
  2846. }
  2847. caching._lastPoint = j;
  2848. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  2849. caching._lastKeyframeIndex = i;
  2850. }
  2851. } else {
  2852. var outX;
  2853. var outY;
  2854. var inX;
  2855. var inY;
  2856. var keyValue;
  2857. len = keyData.s.length;
  2858. endValue = nextKeyData.s || keyData.e;
  2859. if (this.sh && keyData.h !== 1) {
  2860. if (frameNum >= nextKeyTime) {
  2861. newValue[0] = endValue[0];
  2862. newValue[1] = endValue[1];
  2863. newValue[2] = endValue[2];
  2864. } else if (frameNum <= keyTime) {
  2865. newValue[0] = keyData.s[0];
  2866. newValue[1] = keyData.s[1];
  2867. newValue[2] = keyData.s[2];
  2868. } else {
  2869. var quatStart = createQuaternion(keyData.s);
  2870. var quatEnd = createQuaternion(endValue);
  2871. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  2872. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  2873. }
  2874. } else {
  2875. for (i = 0; i < len; i += 1) {
  2876. if (keyData.h !== 1) {
  2877. if (frameNum >= nextKeyTime) {
  2878. perc = 1;
  2879. } else if (frameNum < keyTime) {
  2880. perc = 0;
  2881. } else {
  2882. if (keyData.o.x.constructor === Array) {
  2883. if (!keyframeMetadata.__fnct) {
  2884. keyframeMetadata.__fnct = [];
  2885. }
  2886. if (!keyframeMetadata.__fnct[i]) {
  2887. outX = keyData.o.x[i] === undefined ? keyData.o.x[0] : keyData.o.x[i];
  2888. outY = keyData.o.y[i] === undefined ? keyData.o.y[0] : keyData.o.y[i];
  2889. inX = keyData.i.x[i] === undefined ? keyData.i.x[0] : keyData.i.x[i];
  2890. inY = keyData.i.y[i] === undefined ? keyData.i.y[0] : keyData.i.y[i];
  2891. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2892. keyframeMetadata.__fnct[i] = fnc;
  2893. } else {
  2894. fnc = keyframeMetadata.__fnct[i];
  2895. }
  2896. } else if (!keyframeMetadata.__fnct) {
  2897. outX = keyData.o.x;
  2898. outY = keyData.o.y;
  2899. inX = keyData.i.x;
  2900. inY = keyData.i.y;
  2901. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2902. keyData.keyframeMetadata = fnc;
  2903. } else {
  2904. fnc = keyframeMetadata.__fnct;
  2905. }
  2906. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2907. }
  2908. }
  2909. endValue = nextKeyData.s || keyData.e;
  2910. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  2911. if (this.propType === 'multidimensional') {
  2912. newValue[i] = keyValue;
  2913. } else {
  2914. newValue = keyValue;
  2915. }
  2916. }
  2917. }
  2918. }
  2919. caching.lastIndex = iterationIndex;
  2920. return newValue;
  2921. }
  2922. // based on @Toji's https://github.com/toji/gl-matrix/
  2923. function slerp(a, b, t) {
  2924. var out = [];
  2925. var ax = a[0];
  2926. var ay = a[1];
  2927. var az = a[2];
  2928. var aw = a[3];
  2929. var bx = b[0];
  2930. var by = b[1];
  2931. var bz = b[2];
  2932. var bw = b[3];
  2933. var omega;
  2934. var cosom;
  2935. var sinom;
  2936. var scale0;
  2937. var scale1;
  2938. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2939. if (cosom < 0.0) {
  2940. cosom = -cosom;
  2941. bx = -bx;
  2942. by = -by;
  2943. bz = -bz;
  2944. bw = -bw;
  2945. }
  2946. if (1.0 - cosom > 0.000001) {
  2947. omega = Math.acos(cosom);
  2948. sinom = Math.sin(omega);
  2949. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2950. scale1 = Math.sin(t * omega) / sinom;
  2951. } else {
  2952. scale0 = 1.0 - t;
  2953. scale1 = t;
  2954. }
  2955. out[0] = scale0 * ax + scale1 * bx;
  2956. out[1] = scale0 * ay + scale1 * by;
  2957. out[2] = scale0 * az + scale1 * bz;
  2958. out[3] = scale0 * aw + scale1 * bw;
  2959. return out;
  2960. }
  2961. function quaternionToEuler(out, quat) {
  2962. var qx = quat[0];
  2963. var qy = quat[1];
  2964. var qz = quat[2];
  2965. var qw = quat[3];
  2966. var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz);
  2967. var attitude = Math.asin(2 * qx * qy + 2 * qz * qw);
  2968. var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz);
  2969. out[0] = heading / degToRads;
  2970. out[1] = attitude / degToRads;
  2971. out[2] = bank / degToRads;
  2972. }
  2973. function createQuaternion(values) {
  2974. var heading = values[0] * degToRads;
  2975. var attitude = values[1] * degToRads;
  2976. var bank = values[2] * degToRads;
  2977. var c1 = Math.cos(heading / 2);
  2978. var c2 = Math.cos(attitude / 2);
  2979. var c3 = Math.cos(bank / 2);
  2980. var s1 = Math.sin(heading / 2);
  2981. var s2 = Math.sin(attitude / 2);
  2982. var s3 = Math.sin(bank / 2);
  2983. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2984. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2985. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2986. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2987. return [x, y, z, w];
  2988. }
  2989. function getValueAtCurrentTime() {
  2990. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2991. var initTime = this.keyframes[0].t - this.offsetTime;
  2992. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2993. if (!(frameNum === this._caching.lastFrame || this._caching.lastFrame !== initFrame && (this._caching.lastFrame >= endTime && frameNum >= endTime || this._caching.lastFrame < initTime && frameNum < initTime))) {
  2994. if (this._caching.lastFrame >= frameNum) {
  2995. this._caching._lastKeyframeIndex = -1;
  2996. this._caching.lastIndex = 0;
  2997. }
  2998. var renderResult = this.interpolateValue(frameNum, this._caching);
  2999. this.pv = renderResult;
  3000. }
  3001. this._caching.lastFrame = frameNum;
  3002. return this.pv;
  3003. }
  3004. function setVValue(val) {
  3005. var multipliedValue;
  3006. if (this.propType === 'unidimensional') {
  3007. multipliedValue = val * this.mult;
  3008. if (mathAbs(this.v - multipliedValue) > 0.00001) {
  3009. this.v = multipliedValue;
  3010. this._mdf = true;
  3011. }
  3012. } else {
  3013. var i = 0;
  3014. var len = this.v.length;
  3015. while (i < len) {
  3016. multipliedValue = val[i] * this.mult;
  3017. if (mathAbs(this.v[i] - multipliedValue) > 0.00001) {
  3018. this.v[i] = multipliedValue;
  3019. this._mdf = true;
  3020. }
  3021. i += 1;
  3022. }
  3023. }
  3024. }
  3025. function processEffectsSequence() {
  3026. if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  3027. return;
  3028. }
  3029. if (this.lock) {
  3030. this.setVValue(this.pv);
  3031. return;
  3032. }
  3033. this.lock = true;
  3034. this._mdf = this._isFirstFrame;
  3035. var i;
  3036. var len = this.effectsSequence.length;
  3037. var finalValue = this.kf ? this.pv : this.data.k;
  3038. for (i = 0; i < len; i += 1) {
  3039. finalValue = this.effectsSequence[i](finalValue);
  3040. }
  3041. this.setVValue(finalValue);
  3042. this._isFirstFrame = false;
  3043. this.lock = false;
  3044. this.frameId = this.elem.globalData.frameId;
  3045. }
  3046. function addEffect(effectFunction) {
  3047. this.effectsSequence.push(effectFunction);
  3048. this.container.addDynamicProperty(this);
  3049. }
  3050. function ValueProperty(elem, data, mult, container) {
  3051. this.propType = 'unidimensional';
  3052. this.mult = mult || 1;
  3053. this.data = data;
  3054. this.v = mult ? data.k * mult : data.k;
  3055. this.pv = data.k;
  3056. this._mdf = false;
  3057. this.elem = elem;
  3058. this.container = container;
  3059. this.comp = elem.comp;
  3060. this.k = false;
  3061. this.kf = false;
  3062. this.vel = 0;
  3063. this.effectsSequence = [];
  3064. this._isFirstFrame = true;
  3065. this.getValue = processEffectsSequence;
  3066. this.setVValue = setVValue;
  3067. this.addEffect = addEffect;
  3068. }
  3069. function MultiDimensionalProperty(elem, data, mult, container) {
  3070. this.propType = 'multidimensional';
  3071. this.mult = mult || 1;
  3072. this.data = data;
  3073. this._mdf = false;
  3074. this.elem = elem;
  3075. this.container = container;
  3076. this.comp = elem.comp;
  3077. this.k = false;
  3078. this.kf = false;
  3079. this.frameId = -1;
  3080. var i;
  3081. var len = data.k.length;
  3082. this.v = createTypedArray('float32', len);
  3083. this.pv = createTypedArray('float32', len);
  3084. this.vel = createTypedArray('float32', len);
  3085. for (i = 0; i < len; i += 1) {
  3086. this.v[i] = data.k[i] * this.mult;
  3087. this.pv[i] = data.k[i];
  3088. }
  3089. this._isFirstFrame = true;
  3090. this.effectsSequence = [];
  3091. this.getValue = processEffectsSequence;
  3092. this.setVValue = setVValue;
  3093. this.addEffect = addEffect;
  3094. }
  3095. function KeyframedValueProperty(elem, data, mult, container) {
  3096. this.propType = 'unidimensional';
  3097. this.keyframes = data.k;
  3098. this.keyframesMetadata = [];
  3099. this.offsetTime = elem.data.st;
  3100. this.frameId = -1;
  3101. this._caching = {
  3102. lastFrame: initFrame,
  3103. lastIndex: 0,
  3104. value: 0,
  3105. _lastKeyframeIndex: -1
  3106. };
  3107. this.k = true;
  3108. this.kf = true;
  3109. this.data = data;
  3110. this.mult = mult || 1;
  3111. this.elem = elem;
  3112. this.container = container;
  3113. this.comp = elem.comp;
  3114. this.v = initFrame;
  3115. this.pv = initFrame;
  3116. this._isFirstFrame = true;
  3117. this.getValue = processEffectsSequence;
  3118. this.setVValue = setVValue;
  3119. this.interpolateValue = interpolateValue;
  3120. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3121. this.addEffect = addEffect;
  3122. }
  3123. function KeyframedMultidimensionalProperty(elem, data, mult, container) {
  3124. this.propType = 'multidimensional';
  3125. var i;
  3126. var len = data.k.length;
  3127. var s;
  3128. var e;
  3129. var to;
  3130. var ti;
  3131. for (i = 0; i < len - 1; i += 1) {
  3132. if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
  3133. s = data.k[i].s;
  3134. e = data.k[i + 1].s;
  3135. to = data.k[i].to;
  3136. ti = data.k[i].ti;
  3137. if (s.length === 2 && !(s[0] === e[0] && s[1] === e[1]) && bez.pointOnLine2D(s[0], s[1], e[0], e[1], s[0] + to[0], s[1] + to[1]) && bez.pointOnLine2D(s[0], s[1], e[0], e[1], e[0] + ti[0], e[1] + ti[1]) || s.length === 3 && !(s[0] === e[0] && s[1] === e[1] && s[2] === e[2]) && bez.pointOnLine3D(s[0], s[1], s[2], e[0], e[1], e[2], s[0] + to[0], s[1] + to[1], s[2] + to[2]) && bez.pointOnLine3D(s[0], s[1], s[2], e[0], e[1], e[2], e[0] + ti[0], e[1] + ti[1], e[2] + ti[2])) {
  3138. data.k[i].to = null;
  3139. data.k[i].ti = null;
  3140. }
  3141. if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  3142. if (s.length === 2 || s[2] === e[2] && to[2] === 0 && ti[2] === 0) {
  3143. data.k[i].to = null;
  3144. data.k[i].ti = null;
  3145. }
  3146. }
  3147. }
  3148. }
  3149. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3150. this.data = data;
  3151. this.keyframes = data.k;
  3152. this.keyframesMetadata = [];
  3153. this.offsetTime = elem.data.st;
  3154. this.k = true;
  3155. this.kf = true;
  3156. this._isFirstFrame = true;
  3157. this.mult = mult || 1;
  3158. this.elem = elem;
  3159. this.container = container;
  3160. this.comp = elem.comp;
  3161. this.getValue = processEffectsSequence;
  3162. this.setVValue = setVValue;
  3163. this.interpolateValue = interpolateValue;
  3164. this.frameId = -1;
  3165. var arrLen = data.k[0].s.length;
  3166. this.v = createTypedArray('float32', arrLen);
  3167. this.pv = createTypedArray('float32', arrLen);
  3168. for (i = 0; i < arrLen; i += 1) {
  3169. this.v[i] = initFrame;
  3170. this.pv[i] = initFrame;
  3171. }
  3172. this._caching = {
  3173. lastFrame: initFrame,
  3174. lastIndex: 0,
  3175. value: createTypedArray('float32', arrLen)
  3176. };
  3177. this.addEffect = addEffect;
  3178. }
  3179. var PropertyFactory = function () {
  3180. function getProp(elem, data, type, mult, container) {
  3181. if (data.sid) {
  3182. data = elem.globalData.slotManager.getProp(data);
  3183. }
  3184. var p;
  3185. if (!data.k.length) {
  3186. p = new ValueProperty(elem, data, mult, container);
  3187. } else if (typeof data.k[0] === 'number') {
  3188. p = new MultiDimensionalProperty(elem, data, mult, container);
  3189. } else {
  3190. switch (type) {
  3191. case 0:
  3192. p = new KeyframedValueProperty(elem, data, mult, container);
  3193. break;
  3194. case 1:
  3195. p = new KeyframedMultidimensionalProperty(elem, data, mult, container);
  3196. break;
  3197. default:
  3198. break;
  3199. }
  3200. }
  3201. if (p.effectsSequence.length) {
  3202. container.addDynamicProperty(p);
  3203. }
  3204. return p;
  3205. }
  3206. var ob = {
  3207. getProp: getProp
  3208. };
  3209. return ob;
  3210. }();
  3211. function DynamicPropertyContainer() {}
  3212. DynamicPropertyContainer.prototype = {
  3213. addDynamicProperty: function addDynamicProperty(prop) {
  3214. if (this.dynamicProperties.indexOf(prop) === -1) {
  3215. this.dynamicProperties.push(prop);
  3216. this.container.addDynamicProperty(this);
  3217. this._isAnimated = true;
  3218. }
  3219. },
  3220. iterateDynamicProperties: function iterateDynamicProperties() {
  3221. this._mdf = false;
  3222. var i;
  3223. var len = this.dynamicProperties.length;
  3224. for (i = 0; i < len; i += 1) {
  3225. this.dynamicProperties[i].getValue();
  3226. if (this.dynamicProperties[i]._mdf) {
  3227. this._mdf = true;
  3228. }
  3229. }
  3230. },
  3231. initDynamicPropertyContainer: function initDynamicPropertyContainer(container) {
  3232. this.container = container;
  3233. this.dynamicProperties = [];
  3234. this._mdf = false;
  3235. this._isAnimated = false;
  3236. }
  3237. };
  3238. var pointPool = function () {
  3239. function create() {
  3240. return createTypedArray('float32', 2);
  3241. }
  3242. return poolFactory(8, create);
  3243. }();
  3244. function ShapePath() {
  3245. this.c = false;
  3246. this._length = 0;
  3247. this._maxLength = 8;
  3248. this.v = createSizedArray(this._maxLength);
  3249. this.o = createSizedArray(this._maxLength);
  3250. this.i = createSizedArray(this._maxLength);
  3251. }
  3252. ShapePath.prototype.setPathData = function (closed, len) {
  3253. this.c = closed;
  3254. this.setLength(len);
  3255. var i = 0;
  3256. while (i < len) {
  3257. this.v[i] = pointPool.newElement();
  3258. this.o[i] = pointPool.newElement();
  3259. this.i[i] = pointPool.newElement();
  3260. i += 1;
  3261. }
  3262. };
  3263. ShapePath.prototype.setLength = function (len) {
  3264. while (this._maxLength < len) {
  3265. this.doubleArrayLength();
  3266. }
  3267. this._length = len;
  3268. };
  3269. ShapePath.prototype.doubleArrayLength = function () {
  3270. this.v = this.v.concat(createSizedArray(this._maxLength));
  3271. this.i = this.i.concat(createSizedArray(this._maxLength));
  3272. this.o = this.o.concat(createSizedArray(this._maxLength));
  3273. this._maxLength *= 2;
  3274. };
  3275. ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) {
  3276. var arr;
  3277. this._length = Math.max(this._length, pos + 1);
  3278. if (this._length >= this._maxLength) {
  3279. this.doubleArrayLength();
  3280. }
  3281. switch (type) {
  3282. case 'v':
  3283. arr = this.v;
  3284. break;
  3285. case 'i':
  3286. arr = this.i;
  3287. break;
  3288. case 'o':
  3289. arr = this.o;
  3290. break;
  3291. default:
  3292. arr = [];
  3293. break;
  3294. }
  3295. if (!arr[pos] || arr[pos] && !replace) {
  3296. arr[pos] = pointPool.newElement();
  3297. }
  3298. arr[pos][0] = x;
  3299. arr[pos][1] = y;
  3300. };
  3301. ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) {
  3302. this.setXYAt(vX, vY, 'v', pos, replace);
  3303. this.setXYAt(oX, oY, 'o', pos, replace);
  3304. this.setXYAt(iX, iY, 'i', pos, replace);
  3305. };
  3306. ShapePath.prototype.reverse = function () {
  3307. var newPath = new ShapePath();
  3308. newPath.setPathData(this.c, this._length);
  3309. var vertices = this.v;
  3310. var outPoints = this.o;
  3311. var inPoints = this.i;
  3312. var init = 0;
  3313. if (this.c) {
  3314. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  3315. init = 1;
  3316. }
  3317. var cnt = this._length - 1;
  3318. var len = this._length;
  3319. var i;
  3320. for (i = init; i < len; i += 1) {
  3321. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  3322. cnt -= 1;
  3323. }
  3324. return newPath;
  3325. };
  3326. ShapePath.prototype.length = function () {
  3327. return this._length;
  3328. };
  3329. var shapePool = function () {
  3330. function create() {
  3331. return new ShapePath();
  3332. }
  3333. function release(shapePath) {
  3334. var len = shapePath._length;
  3335. var i;
  3336. for (i = 0; i < len; i += 1) {
  3337. pointPool.release(shapePath.v[i]);
  3338. pointPool.release(shapePath.i[i]);
  3339. pointPool.release(shapePath.o[i]);
  3340. shapePath.v[i] = null;
  3341. shapePath.i[i] = null;
  3342. shapePath.o[i] = null;
  3343. }
  3344. shapePath._length = 0;
  3345. shapePath.c = false;
  3346. }
  3347. function clone(shape) {
  3348. var cloned = factory.newElement();
  3349. var i;
  3350. var len = shape._length === undefined ? shape.v.length : shape._length;
  3351. cloned.setLength(len);
  3352. cloned.c = shape.c;
  3353. for (i = 0; i < len; i += 1) {
  3354. cloned.setTripleAt(shape.v[i][0], shape.v[i][1], shape.o[i][0], shape.o[i][1], shape.i[i][0], shape.i[i][1], i);
  3355. }
  3356. return cloned;
  3357. }
  3358. var factory = poolFactory(4, create, release);
  3359. factory.clone = clone;
  3360. return factory;
  3361. }();
  3362. function ShapeCollection() {
  3363. this._length = 0;
  3364. this._maxLength = 4;
  3365. this.shapes = createSizedArray(this._maxLength);
  3366. }
  3367. ShapeCollection.prototype.addShape = function (shapeData) {
  3368. if (this._length === this._maxLength) {
  3369. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3370. this._maxLength *= 2;
  3371. }
  3372. this.shapes[this._length] = shapeData;
  3373. this._length += 1;
  3374. };
  3375. ShapeCollection.prototype.releaseShapes = function () {
  3376. var i;
  3377. for (i = 0; i < this._length; i += 1) {
  3378. shapePool.release(this.shapes[i]);
  3379. }
  3380. this._length = 0;
  3381. };
  3382. var shapeCollectionPool = function () {
  3383. var ob = {
  3384. newShapeCollection: newShapeCollection,
  3385. release: release
  3386. };
  3387. var _length = 0;
  3388. var _maxLength = 4;
  3389. var pool = createSizedArray(_maxLength);
  3390. function newShapeCollection() {
  3391. var shapeCollection;
  3392. if (_length) {
  3393. _length -= 1;
  3394. shapeCollection = pool[_length];
  3395. } else {
  3396. shapeCollection = new ShapeCollection();
  3397. }
  3398. return shapeCollection;
  3399. }
  3400. function release(shapeCollection) {
  3401. var i;
  3402. var len = shapeCollection._length;
  3403. for (i = 0; i < len; i += 1) {
  3404. shapePool.release(shapeCollection.shapes[i]);
  3405. }
  3406. shapeCollection._length = 0;
  3407. if (_length === _maxLength) {
  3408. pool = pooling["double"](pool);
  3409. _maxLength *= 2;
  3410. }
  3411. pool[_length] = shapeCollection;
  3412. _length += 1;
  3413. }
  3414. return ob;
  3415. }();
  3416. var ShapePropertyFactory = function () {
  3417. var initFrame = -999999;
  3418. function interpolateShape(frameNum, previousValue, caching) {
  3419. var iterationIndex = caching.lastIndex;
  3420. var keyPropS;
  3421. var keyPropE;
  3422. var isHold;
  3423. var j;
  3424. var k;
  3425. var jLen;
  3426. var kLen;
  3427. var perc;
  3428. var vertexValue;
  3429. var kf = this.keyframes;
  3430. if (frameNum < kf[0].t - this.offsetTime) {
  3431. keyPropS = kf[0].s[0];
  3432. isHold = true;
  3433. iterationIndex = 0;
  3434. } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) {
  3435. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  3436. /* if(kf[kf.length - 1].s){
  3437. keyPropS = kf[kf.length - 1].s[0];
  3438. }else{
  3439. keyPropS = kf[kf.length - 2].e[0];
  3440. } */
  3441. isHold = true;
  3442. } else {
  3443. var i = iterationIndex;
  3444. var len = kf.length - 1;
  3445. var flag = true;
  3446. var keyData;
  3447. var nextKeyData;
  3448. var keyframeMetadata;
  3449. while (flag) {
  3450. keyData = kf[i];
  3451. nextKeyData = kf[i + 1];
  3452. if (nextKeyData.t - this.offsetTime > frameNum) {
  3453. break;
  3454. }
  3455. if (i < len - 1) {
  3456. i += 1;
  3457. } else {
  3458. flag = false;
  3459. }
  3460. }
  3461. keyframeMetadata = this.keyframesMetadata[i] || {};
  3462. isHold = keyData.h === 1;
  3463. iterationIndex = i;
  3464. if (!isHold) {
  3465. if (frameNum >= nextKeyData.t - this.offsetTime) {
  3466. perc = 1;
  3467. } else if (frameNum < keyData.t - this.offsetTime) {
  3468. perc = 0;
  3469. } else {
  3470. var fnc;
  3471. if (keyframeMetadata.__fnct) {
  3472. fnc = keyframeMetadata.__fnct;
  3473. } else {
  3474. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get;
  3475. keyframeMetadata.__fnct = fnc;
  3476. }
  3477. perc = fnc((frameNum - (keyData.t - this.offsetTime)) / (nextKeyData.t - this.offsetTime - (keyData.t - this.offsetTime)));
  3478. }
  3479. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  3480. }
  3481. keyPropS = keyData.s[0];
  3482. }
  3483. jLen = previousValue._length;
  3484. kLen = keyPropS.i[0].length;
  3485. caching.lastIndex = iterationIndex;
  3486. for (j = 0; j < jLen; j += 1) {
  3487. for (k = 0; k < kLen; k += 1) {
  3488. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc;
  3489. previousValue.i[j][k] = vertexValue;
  3490. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc;
  3491. previousValue.o[j][k] = vertexValue;
  3492. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc;
  3493. previousValue.v[j][k] = vertexValue;
  3494. }
  3495. }
  3496. }
  3497. function interpolateShapeCurrentTime() {
  3498. var frameNum = this.comp.renderedFrame - this.offsetTime;
  3499. var initTime = this.keyframes[0].t - this.offsetTime;
  3500. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  3501. var lastFrame = this._caching.lastFrame;
  3502. if (!(lastFrame !== initFrame && (lastFrame < initTime && frameNum < initTime || lastFrame > endTime && frameNum > endTime))) {
  3503. /// /
  3504. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  3505. this.interpolateShape(frameNum, this.pv, this._caching);
  3506. /// /
  3507. }
  3508. this._caching.lastFrame = frameNum;
  3509. return this.pv;
  3510. }
  3511. function resetShape() {
  3512. this.paths = this.localShapeCollection;
  3513. }
  3514. function shapesEqual(shape1, shape2) {
  3515. if (shape1._length !== shape2._length || shape1.c !== shape2.c) {
  3516. return false;
  3517. }
  3518. var i;
  3519. var len = shape1._length;
  3520. for (i = 0; i < len; i += 1) {
  3521. if (shape1.v[i][0] !== shape2.v[i][0] || shape1.v[i][1] !== shape2.v[i][1] || shape1.o[i][0] !== shape2.o[i][0] || shape1.o[i][1] !== shape2.o[i][1] || shape1.i[i][0] !== shape2.i[i][0] || shape1.i[i][1] !== shape2.i[i][1]) {
  3522. return false;
  3523. }
  3524. }
  3525. return true;
  3526. }
  3527. function setVValue(newPath) {
  3528. if (!shapesEqual(this.v, newPath)) {
  3529. this.v = shapePool.clone(newPath);
  3530. this.localShapeCollection.releaseShapes();
  3531. this.localShapeCollection.addShape(this.v);
  3532. this._mdf = true;
  3533. this.paths = this.localShapeCollection;
  3534. }
  3535. }
  3536. function processEffectsSequence() {
  3537. if (this.elem.globalData.frameId === this.frameId) {
  3538. return;
  3539. }
  3540. if (!this.effectsSequence.length) {
  3541. this._mdf = false;
  3542. return;
  3543. }
  3544. if (this.lock) {
  3545. this.setVValue(this.pv);
  3546. return;
  3547. }
  3548. this.lock = true;
  3549. this._mdf = false;
  3550. var finalValue;
  3551. if (this.kf) {
  3552. finalValue = this.pv;
  3553. } else if (this.data.ks) {
  3554. finalValue = this.data.ks.k;
  3555. } else {
  3556. finalValue = this.data.pt.k;
  3557. }
  3558. var i;
  3559. var len = this.effectsSequence.length;
  3560. for (i = 0; i < len; i += 1) {
  3561. finalValue = this.effectsSequence[i](finalValue);
  3562. }
  3563. this.setVValue(finalValue);
  3564. this.lock = false;
  3565. this.frameId = this.elem.globalData.frameId;
  3566. }
  3567. function ShapeProperty(elem, data, type) {
  3568. this.propType = 'shape';
  3569. this.comp = elem.comp;
  3570. this.container = elem;
  3571. this.elem = elem;
  3572. this.data = data;
  3573. this.k = false;
  3574. this.kf = false;
  3575. this._mdf = false;
  3576. var pathData = type === 3 ? data.pt.k : data.ks.k;
  3577. this.v = shapePool.clone(pathData);
  3578. this.pv = shapePool.clone(this.v);
  3579. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3580. this.paths = this.localShapeCollection;
  3581. this.paths.addShape(this.v);
  3582. this.reset = resetShape;
  3583. this.effectsSequence = [];
  3584. }
  3585. function addEffect(effectFunction) {
  3586. this.effectsSequence.push(effectFunction);
  3587. this.container.addDynamicProperty(this);
  3588. }
  3589. ShapeProperty.prototype.interpolateShape = interpolateShape;
  3590. ShapeProperty.prototype.getValue = processEffectsSequence;
  3591. ShapeProperty.prototype.setVValue = setVValue;
  3592. ShapeProperty.prototype.addEffect = addEffect;
  3593. function KeyframedShapeProperty(elem, data, type) {
  3594. this.propType = 'shape';
  3595. this.comp = elem.comp;
  3596. this.elem = elem;
  3597. this.container = elem;
  3598. this.offsetTime = elem.data.st;
  3599. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  3600. this.keyframesMetadata = [];
  3601. this.k = true;
  3602. this.kf = true;
  3603. var len = this.keyframes[0].s[0].i.length;
  3604. this.v = shapePool.newElement();
  3605. this.v.setPathData(this.keyframes[0].s[0].c, len);
  3606. this.pv = shapePool.clone(this.v);
  3607. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3608. this.paths = this.localShapeCollection;
  3609. this.paths.addShape(this.v);
  3610. this.lastFrame = initFrame;
  3611. this.reset = resetShape;
  3612. this._caching = {
  3613. lastFrame: initFrame,
  3614. lastIndex: 0
  3615. };
  3616. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  3617. }
  3618. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  3619. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  3620. KeyframedShapeProperty.prototype.setVValue = setVValue;
  3621. KeyframedShapeProperty.prototype.addEffect = addEffect;
  3622. var EllShapeProperty = function () {
  3623. var cPoint = roundCorner;
  3624. function EllShapePropertyFactory(elem, data) {
  3625. this.v = shapePool.newElement();
  3626. this.v.setPathData(true, 4);
  3627. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3628. this.paths = this.localShapeCollection;
  3629. this.localShapeCollection.addShape(this.v);
  3630. this.d = data.d;
  3631. this.elem = elem;
  3632. this.comp = elem.comp;
  3633. this.frameId = -1;
  3634. this.initDynamicPropertyContainer(elem);
  3635. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3636. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3637. if (this.dynamicProperties.length) {
  3638. this.k = true;
  3639. } else {
  3640. this.k = false;
  3641. this.convertEllToPath();
  3642. }
  3643. }
  3644. EllShapePropertyFactory.prototype = {
  3645. reset: resetShape,
  3646. getValue: function getValue() {
  3647. if (this.elem.globalData.frameId === this.frameId) {
  3648. return;
  3649. }
  3650. this.frameId = this.elem.globalData.frameId;
  3651. this.iterateDynamicProperties();
  3652. if (this._mdf) {
  3653. this.convertEllToPath();
  3654. }
  3655. },
  3656. convertEllToPath: function convertEllToPath() {
  3657. var p0 = this.p.v[0];
  3658. var p1 = this.p.v[1];
  3659. var s0 = this.s.v[0] / 2;
  3660. var s1 = this.s.v[1] / 2;
  3661. var _cw = this.d !== 3;
  3662. var _v = this.v;
  3663. _v.v[0][0] = p0;
  3664. _v.v[0][1] = p1 - s1;
  3665. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  3666. _v.v[1][1] = p1;
  3667. _v.v[2][0] = p0;
  3668. _v.v[2][1] = p1 + s1;
  3669. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  3670. _v.v[3][1] = p1;
  3671. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3672. _v.i[0][1] = p1 - s1;
  3673. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  3674. _v.i[1][1] = p1 - s1 * cPoint;
  3675. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3676. _v.i[2][1] = p1 + s1;
  3677. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  3678. _v.i[3][1] = p1 + s1 * cPoint;
  3679. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3680. _v.o[0][1] = p1 - s1;
  3681. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  3682. _v.o[1][1] = p1 + s1 * cPoint;
  3683. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3684. _v.o[2][1] = p1 + s1;
  3685. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  3686. _v.o[3][1] = p1 - s1 * cPoint;
  3687. }
  3688. };
  3689. extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory);
  3690. return EllShapePropertyFactory;
  3691. }();
  3692. var StarShapeProperty = function () {
  3693. function StarShapePropertyFactory(elem, data) {
  3694. this.v = shapePool.newElement();
  3695. this.v.setPathData(true, 0);
  3696. this.elem = elem;
  3697. this.comp = elem.comp;
  3698. this.data = data;
  3699. this.frameId = -1;
  3700. this.d = data.d;
  3701. this.initDynamicPropertyContainer(elem);
  3702. if (data.sy === 1) {
  3703. this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this);
  3704. this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this);
  3705. this.convertToPath = this.convertStarToPath;
  3706. } else {
  3707. this.convertToPath = this.convertPolygonToPath;
  3708. }
  3709. this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this);
  3710. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3711. this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this);
  3712. this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this);
  3713. this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this);
  3714. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3715. this.localShapeCollection.addShape(this.v);
  3716. this.paths = this.localShapeCollection;
  3717. if (this.dynamicProperties.length) {
  3718. this.k = true;
  3719. } else {
  3720. this.k = false;
  3721. this.convertToPath();
  3722. }
  3723. }
  3724. StarShapePropertyFactory.prototype = {
  3725. reset: resetShape,
  3726. getValue: function getValue() {
  3727. if (this.elem.globalData.frameId === this.frameId) {
  3728. return;
  3729. }
  3730. this.frameId = this.elem.globalData.frameId;
  3731. this.iterateDynamicProperties();
  3732. if (this._mdf) {
  3733. this.convertToPath();
  3734. }
  3735. },
  3736. convertStarToPath: function convertStarToPath() {
  3737. var numPts = Math.floor(this.pt.v) * 2;
  3738. var angle = Math.PI * 2 / numPts;
  3739. /* this.v.v.length = numPts;
  3740. this.v.i.length = numPts;
  3741. this.v.o.length = numPts; */
  3742. var longFlag = true;
  3743. var longRad = this.or.v;
  3744. var shortRad = this.ir.v;
  3745. var longRound = this.os.v;
  3746. var shortRound = this.is.v;
  3747. var longPerimSegment = 2 * Math.PI * longRad / (numPts * 2);
  3748. var shortPerimSegment = 2 * Math.PI * shortRad / (numPts * 2);
  3749. var i;
  3750. var rad;
  3751. var roundness;
  3752. var perimSegment;
  3753. var currentAng = -Math.PI / 2;
  3754. currentAng += this.r.v;
  3755. var dir = this.data.d === 3 ? -1 : 1;
  3756. this.v._length = 0;
  3757. for (i = 0; i < numPts; i += 1) {
  3758. rad = longFlag ? longRad : shortRad;
  3759. roundness = longFlag ? longRound : shortRound;
  3760. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  3761. var x = rad * Math.cos(currentAng);
  3762. var y = rad * Math.sin(currentAng);
  3763. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3764. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3765. x += +this.p.v[0];
  3766. y += +this.p.v[1];
  3767. this.v.setTripleAt(x, y, x - ox * perimSegment * roundness * dir, y - oy * perimSegment * roundness * dir, x + ox * perimSegment * roundness * dir, y + oy * perimSegment * roundness * dir, i, true);
  3768. /* this.v.v[i] = [x,y];
  3769. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  3770. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  3771. this.v._length = numPts; */
  3772. longFlag = !longFlag;
  3773. currentAng += angle * dir;
  3774. }
  3775. },
  3776. convertPolygonToPath: function convertPolygonToPath() {
  3777. var numPts = Math.floor(this.pt.v);
  3778. var angle = Math.PI * 2 / numPts;
  3779. var rad = this.or.v;
  3780. var roundness = this.os.v;
  3781. var perimSegment = 2 * Math.PI * rad / (numPts * 4);
  3782. var i;
  3783. var currentAng = -Math.PI * 0.5;
  3784. var dir = this.data.d === 3 ? -1 : 1;
  3785. currentAng += this.r.v;
  3786. this.v._length = 0;
  3787. for (i = 0; i < numPts; i += 1) {
  3788. var x = rad * Math.cos(currentAng);
  3789. var y = rad * Math.sin(currentAng);
  3790. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3791. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3792. x += +this.p.v[0];
  3793. y += +this.p.v[1];
  3794. this.v.setTripleAt(x, y, x - ox * perimSegment * roundness * dir, y - oy * perimSegment * roundness * dir, x + ox * perimSegment * roundness * dir, y + oy * perimSegment * roundness * dir, i, true);
  3795. currentAng += angle * dir;
  3796. }
  3797. this.paths.length = 0;
  3798. this.paths[0] = this.v;
  3799. }
  3800. };
  3801. extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory);
  3802. return StarShapePropertyFactory;
  3803. }();
  3804. var RectShapeProperty = function () {
  3805. function RectShapePropertyFactory(elem, data) {
  3806. this.v = shapePool.newElement();
  3807. this.v.c = true;
  3808. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3809. this.localShapeCollection.addShape(this.v);
  3810. this.paths = this.localShapeCollection;
  3811. this.elem = elem;
  3812. this.comp = elem.comp;
  3813. this.frameId = -1;
  3814. this.d = data.d;
  3815. this.initDynamicPropertyContainer(elem);
  3816. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3817. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3818. this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this);
  3819. if (this.dynamicProperties.length) {
  3820. this.k = true;
  3821. } else {
  3822. this.k = false;
  3823. this.convertRectToPath();
  3824. }
  3825. }
  3826. RectShapePropertyFactory.prototype = {
  3827. convertRectToPath: function convertRectToPath() {
  3828. var p0 = this.p.v[0];
  3829. var p1 = this.p.v[1];
  3830. var v0 = this.s.v[0] / 2;
  3831. var v1 = this.s.v[1] / 2;
  3832. var round = bmMin(v0, v1, this.r.v);
  3833. var cPoint = round * (1 - roundCorner);
  3834. this.v._length = 0;
  3835. if (this.d === 2 || this.d === 1) {
  3836. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true);
  3837. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true);
  3838. if (round !== 0) {
  3839. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true);
  3840. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true);
  3841. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true);
  3842. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true);
  3843. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true);
  3844. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true);
  3845. } else {
  3846. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2);
  3847. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3);
  3848. }
  3849. } else {
  3850. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true);
  3851. if (round !== 0) {
  3852. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true);
  3853. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true);
  3854. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true);
  3855. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true);
  3856. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true);
  3857. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true);
  3858. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true);
  3859. } else {
  3860. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true);
  3861. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true);
  3862. this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true);
  3863. }
  3864. }
  3865. },
  3866. getValue: function getValue() {
  3867. if (this.elem.globalData.frameId === this.frameId) {
  3868. return;
  3869. }
  3870. this.frameId = this.elem.globalData.frameId;
  3871. this.iterateDynamicProperties();
  3872. if (this._mdf) {
  3873. this.convertRectToPath();
  3874. }
  3875. },
  3876. reset: resetShape
  3877. };
  3878. extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory);
  3879. return RectShapePropertyFactory;
  3880. }();
  3881. function getShapeProp(elem, data, type) {
  3882. var prop;
  3883. if (type === 3 || type === 4) {
  3884. var dataProp = type === 3 ? data.pt : data.ks;
  3885. var keys = dataProp.k;
  3886. if (keys.length) {
  3887. prop = new KeyframedShapeProperty(elem, data, type);
  3888. } else {
  3889. prop = new ShapeProperty(elem, data, type);
  3890. }
  3891. } else if (type === 5) {
  3892. prop = new RectShapeProperty(elem, data);
  3893. } else if (type === 6) {
  3894. prop = new EllShapeProperty(elem, data);
  3895. } else if (type === 7) {
  3896. prop = new StarShapeProperty(elem, data);
  3897. }
  3898. if (prop.k) {
  3899. elem.addDynamicProperty(prop);
  3900. }
  3901. return prop;
  3902. }
  3903. function getConstructorFunction() {
  3904. return ShapeProperty;
  3905. }
  3906. function getKeyframedConstructorFunction() {
  3907. return KeyframedShapeProperty;
  3908. }
  3909. var ob = {};
  3910. ob.getShapeProp = getShapeProp;
  3911. ob.getConstructorFunction = getConstructorFunction;
  3912. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3913. return ob;
  3914. }();
  3915. /*!
  3916. Transformation Matrix v2.0
  3917. (c) Epistemex 2014-2015
  3918. www.epistemex.com
  3919. By Ken Fyrstenberg
  3920. Contributions by leeoniya.
  3921. License: MIT, header required.
  3922. */
  3923. /**
  3924. * 2D transformation matrix object initialized with identity matrix.
  3925. *
  3926. * The matrix can synchronize a canvas context by supplying the context
  3927. * as an argument, or later apply current absolute transform to an
  3928. * existing context.
  3929. *
  3930. * All values are handled as floating point values.
  3931. *
  3932. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  3933. * @prop {number} a - scale x
  3934. * @prop {number} b - shear y
  3935. * @prop {number} c - shear x
  3936. * @prop {number} d - scale y
  3937. * @prop {number} e - translate x
  3938. * @prop {number} f - translate y
  3939. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  3940. * @constructor
  3941. */
  3942. var Matrix = function () {
  3943. var _cos = Math.cos;
  3944. var _sin = Math.sin;
  3945. var _tan = Math.tan;
  3946. var _rnd = Math.round;
  3947. function reset() {
  3948. this.props[0] = 1;
  3949. this.props[1] = 0;
  3950. this.props[2] = 0;
  3951. this.props[3] = 0;
  3952. this.props[4] = 0;
  3953. this.props[5] = 1;
  3954. this.props[6] = 0;
  3955. this.props[7] = 0;
  3956. this.props[8] = 0;
  3957. this.props[9] = 0;
  3958. this.props[10] = 1;
  3959. this.props[11] = 0;
  3960. this.props[12] = 0;
  3961. this.props[13] = 0;
  3962. this.props[14] = 0;
  3963. this.props[15] = 1;
  3964. return this;
  3965. }
  3966. function rotate(angle) {
  3967. if (angle === 0) {
  3968. return this;
  3969. }
  3970. var mCos = _cos(angle);
  3971. var mSin = _sin(angle);
  3972. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3973. }
  3974. function rotateX(angle) {
  3975. if (angle === 0) {
  3976. return this;
  3977. }
  3978. var mCos = _cos(angle);
  3979. var mSin = _sin(angle);
  3980. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  3981. }
  3982. function rotateY(angle) {
  3983. if (angle === 0) {
  3984. return this;
  3985. }
  3986. var mCos = _cos(angle);
  3987. var mSin = _sin(angle);
  3988. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  3989. }
  3990. function rotateZ(angle) {
  3991. if (angle === 0) {
  3992. return this;
  3993. }
  3994. var mCos = _cos(angle);
  3995. var mSin = _sin(angle);
  3996. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3997. }
  3998. function shear(sx, sy) {
  3999. return this._t(1, sy, sx, 1, 0, 0);
  4000. }
  4001. function skew(ax, ay) {
  4002. return this.shear(_tan(ax), _tan(ay));
  4003. }
  4004. function skewFromAxis(ax, angle) {
  4005. var mCos = _cos(angle);
  4006. var mSin = _sin(angle);
  4007. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4008. // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  4009. }
  4010. function scale(sx, sy, sz) {
  4011. if (!sz && sz !== 0) {
  4012. sz = 1;
  4013. }
  4014. if (sx === 1 && sy === 1 && sz === 1) {
  4015. return this;
  4016. }
  4017. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  4018. }
  4019. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  4020. this.props[0] = a;
  4021. this.props[1] = b;
  4022. this.props[2] = c;
  4023. this.props[3] = d;
  4024. this.props[4] = e;
  4025. this.props[5] = f;
  4026. this.props[6] = g;
  4027. this.props[7] = h;
  4028. this.props[8] = i;
  4029. this.props[9] = j;
  4030. this.props[10] = k;
  4031. this.props[11] = l;
  4032. this.props[12] = m;
  4033. this.props[13] = n;
  4034. this.props[14] = o;
  4035. this.props[15] = p;
  4036. return this;
  4037. }
  4038. function translate(tx, ty, tz) {
  4039. tz = tz || 0;
  4040. if (tx !== 0 || ty !== 0 || tz !== 0) {
  4041. return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1);
  4042. }
  4043. return this;
  4044. }
  4045. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  4046. var _p = this.props;
  4047. if (a2 === 1 && b2 === 0 && c2 === 0 && d2 === 0 && e2 === 0 && f2 === 1 && g2 === 0 && h2 === 0 && i2 === 0 && j2 === 0 && k2 === 1 && l2 === 0) {
  4048. // NOTE: commenting this condition because TurboFan deoptimizes code when present
  4049. // if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  4050. _p[12] = _p[12] * a2 + _p[15] * m2;
  4051. _p[13] = _p[13] * f2 + _p[15] * n2;
  4052. _p[14] = _p[14] * k2 + _p[15] * o2;
  4053. _p[15] *= p2;
  4054. // }
  4055. this._identityCalculated = false;
  4056. return this;
  4057. }
  4058. var a1 = _p[0];
  4059. var b1 = _p[1];
  4060. var c1 = _p[2];
  4061. var d1 = _p[3];
  4062. var e1 = _p[4];
  4063. var f1 = _p[5];
  4064. var g1 = _p[6];
  4065. var h1 = _p[7];
  4066. var i1 = _p[8];
  4067. var j1 = _p[9];
  4068. var k1 = _p[10];
  4069. var l1 = _p[11];
  4070. var m1 = _p[12];
  4071. var n1 = _p[13];
  4072. var o1 = _p[14];
  4073. var p1 = _p[15];
  4074. /* matrix order (canvas compatible):
  4075. * ace
  4076. * bdf
  4077. * 001
  4078. */
  4079. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  4080. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2;
  4081. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2;
  4082. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2;
  4083. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2;
  4084. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2;
  4085. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2;
  4086. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2;
  4087. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2;
  4088. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2;
  4089. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2;
  4090. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2;
  4091. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2;
  4092. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2;
  4093. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2;
  4094. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2;
  4095. this._identityCalculated = false;
  4096. return this;
  4097. }
  4098. function multiply(matrix) {
  4099. var matrixProps = matrix.props;
  4100. return this.transform(matrixProps[0], matrixProps[1], matrixProps[2], matrixProps[3], matrixProps[4], matrixProps[5], matrixProps[6], matrixProps[7], matrixProps[8], matrixProps[9], matrixProps[10], matrixProps[11], matrixProps[12], matrixProps[13], matrixProps[14], matrixProps[15]);
  4101. }
  4102. function isIdentity() {
  4103. if (!this._identityCalculated) {
  4104. this._identity = !(this.props[0] !== 1 || this.props[1] !== 0 || this.props[2] !== 0 || this.props[3] !== 0 || this.props[4] !== 0 || this.props[5] !== 1 || this.props[6] !== 0 || this.props[7] !== 0 || this.props[8] !== 0 || this.props[9] !== 0 || this.props[10] !== 1 || this.props[11] !== 0 || this.props[12] !== 0 || this.props[13] !== 0 || this.props[14] !== 0 || this.props[15] !== 1);
  4105. this._identityCalculated = true;
  4106. }
  4107. return this._identity;
  4108. }
  4109. function equals(matr) {
  4110. var i = 0;
  4111. while (i < 16) {
  4112. if (matr.props[i] !== this.props[i]) {
  4113. return false;
  4114. }
  4115. i += 1;
  4116. }
  4117. return true;
  4118. }
  4119. function clone(matr) {
  4120. var i;
  4121. for (i = 0; i < 16; i += 1) {
  4122. matr.props[i] = this.props[i];
  4123. }
  4124. return matr;
  4125. }
  4126. function cloneFromProps(props) {
  4127. var i;
  4128. for (i = 0; i < 16; i += 1) {
  4129. this.props[i] = props[i];
  4130. }
  4131. }
  4132. function applyToPoint(x, y, z) {
  4133. return {
  4134. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4135. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4136. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]
  4137. };
  4138. /* return {
  4139. x: x * me.a + y * me.c + me.e,
  4140. y: x * me.b + y * me.d + me.f
  4141. }; */
  4142. }
  4143. function applyToX(x, y, z) {
  4144. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  4145. }
  4146. function applyToY(x, y, z) {
  4147. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  4148. }
  4149. function applyToZ(x, y, z) {
  4150. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  4151. }
  4152. function getInverseMatrix() {
  4153. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  4154. var a = this.props[5] / determinant;
  4155. var b = -this.props[1] / determinant;
  4156. var c = -this.props[4] / determinant;
  4157. var d = this.props[0] / determinant;
  4158. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant;
  4159. var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant;
  4160. var inverseMatrix = new Matrix();
  4161. inverseMatrix.props[0] = a;
  4162. inverseMatrix.props[1] = b;
  4163. inverseMatrix.props[4] = c;
  4164. inverseMatrix.props[5] = d;
  4165. inverseMatrix.props[12] = e;
  4166. inverseMatrix.props[13] = f;
  4167. return inverseMatrix;
  4168. }
  4169. function inversePoint(pt) {
  4170. var inverseMatrix = this.getInverseMatrix();
  4171. return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0);
  4172. }
  4173. function inversePoints(pts) {
  4174. var i;
  4175. var len = pts.length;
  4176. var retPts = [];
  4177. for (i = 0; i < len; i += 1) {
  4178. retPts[i] = inversePoint(pts[i]);
  4179. }
  4180. return retPts;
  4181. }
  4182. function applyToTriplePoints(pt1, pt2, pt3) {
  4183. var arr = createTypedArray('float32', 6);
  4184. if (this.isIdentity()) {
  4185. arr[0] = pt1[0];
  4186. arr[1] = pt1[1];
  4187. arr[2] = pt2[0];
  4188. arr[3] = pt2[1];
  4189. arr[4] = pt3[0];
  4190. arr[5] = pt3[1];
  4191. } else {
  4192. var p0 = this.props[0];
  4193. var p1 = this.props[1];
  4194. var p4 = this.props[4];
  4195. var p5 = this.props[5];
  4196. var p12 = this.props[12];
  4197. var p13 = this.props[13];
  4198. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  4199. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  4200. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  4201. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  4202. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  4203. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  4204. }
  4205. return arr;
  4206. }
  4207. function applyToPointArray(x, y, z) {
  4208. var arr;
  4209. if (this.isIdentity()) {
  4210. arr = [x, y, z];
  4211. } else {
  4212. arr = [x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12], x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13], x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]];
  4213. }
  4214. return arr;
  4215. }
  4216. function applyToPointStringified(x, y) {
  4217. if (this.isIdentity()) {
  4218. return x + ',' + y;
  4219. }
  4220. var _p = this.props;
  4221. return Math.round((x * _p[0] + y * _p[4] + _p[12]) * 100) / 100 + ',' + Math.round((x * _p[1] + y * _p[5] + _p[13]) * 100) / 100;
  4222. }
  4223. function toCSS() {
  4224. // Doesn't make much sense to add this optimization. If it is an identity matrix, it's very likely this will get called only once since it won't be keyframed.
  4225. /* if(this.isIdentity()) {
  4226. return '';
  4227. } */
  4228. var i = 0;
  4229. var props = this.props;
  4230. var cssValue = 'matrix3d(';
  4231. var v = 10000;
  4232. while (i < 16) {
  4233. cssValue += _rnd(props[i] * v) / v;
  4234. cssValue += i === 15 ? ')' : ',';
  4235. i += 1;
  4236. }
  4237. return cssValue;
  4238. }
  4239. function roundMatrixProperty(val) {
  4240. var v = 10000;
  4241. if (val < 0.000001 && val > 0 || val > -0.000001 && val < 0) {
  4242. return _rnd(val * v) / v;
  4243. }
  4244. return val;
  4245. }
  4246. function to2dCSS() {
  4247. // Doesn't make much sense to add this optimization. If it is an identity matrix, it's very likely this will get called only once since it won't be keyframed.
  4248. /* if(this.isIdentity()) {
  4249. return '';
  4250. } */
  4251. var props = this.props;
  4252. var _a = roundMatrixProperty(props[0]);
  4253. var _b = roundMatrixProperty(props[1]);
  4254. var _c = roundMatrixProperty(props[4]);
  4255. var _d = roundMatrixProperty(props[5]);
  4256. var _e = roundMatrixProperty(props[12]);
  4257. var _f = roundMatrixProperty(props[13]);
  4258. return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')';
  4259. }
  4260. return function () {
  4261. this.reset = reset;
  4262. this.rotate = rotate;
  4263. this.rotateX = rotateX;
  4264. this.rotateY = rotateY;
  4265. this.rotateZ = rotateZ;
  4266. this.skew = skew;
  4267. this.skewFromAxis = skewFromAxis;
  4268. this.shear = shear;
  4269. this.scale = scale;
  4270. this.setTransform = setTransform;
  4271. this.translate = translate;
  4272. this.transform = transform;
  4273. this.multiply = multiply;
  4274. this.applyToPoint = applyToPoint;
  4275. this.applyToX = applyToX;
  4276. this.applyToY = applyToY;
  4277. this.applyToZ = applyToZ;
  4278. this.applyToPointArray = applyToPointArray;
  4279. this.applyToTriplePoints = applyToTriplePoints;
  4280. this.applyToPointStringified = applyToPointStringified;
  4281. this.toCSS = toCSS;
  4282. this.to2dCSS = to2dCSS;
  4283. this.clone = clone;
  4284. this.cloneFromProps = cloneFromProps;
  4285. this.equals = equals;
  4286. this.inversePoints = inversePoints;
  4287. this.inversePoint = inversePoint;
  4288. this.getInverseMatrix = getInverseMatrix;
  4289. this._t = this.transform;
  4290. this.isIdentity = isIdentity;
  4291. this._identity = true;
  4292. this._identityCalculated = false;
  4293. this.props = createTypedArray('float32', 16);
  4294. this.reset();
  4295. };
  4296. }();
  4297. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  4298. var lottie = {};
  4299. var standalone = '__[STANDALONE]__';
  4300. var animationData = '__[ANIMATIONDATA]__';
  4301. var renderer = '';
  4302. function setLocation(href) {
  4303. setLocationHref(href);
  4304. }
  4305. function searchAnimations() {
  4306. if (standalone === true) {
  4307. animationManager.searchAnimations(animationData, standalone, renderer);
  4308. } else {
  4309. animationManager.searchAnimations();
  4310. }
  4311. }
  4312. function setSubframeRendering(flag) {
  4313. setSubframeEnabled(flag);
  4314. }
  4315. function setPrefix(prefix) {
  4316. setIdPrefix(prefix);
  4317. }
  4318. function loadAnimation(params) {
  4319. if (standalone === true) {
  4320. params.animationData = JSON.parse(animationData);
  4321. }
  4322. return animationManager.loadAnimation(params);
  4323. }
  4324. function setQuality(value) {
  4325. if (typeof value === 'string') {
  4326. switch (value) {
  4327. case 'high':
  4328. setDefaultCurveSegments(200);
  4329. break;
  4330. default:
  4331. case 'medium':
  4332. setDefaultCurveSegments(50);
  4333. break;
  4334. case 'low':
  4335. setDefaultCurveSegments(10);
  4336. break;
  4337. }
  4338. } else if (!isNaN(value) && value > 1) {
  4339. setDefaultCurveSegments(value);
  4340. }
  4341. if (getDefaultCurveSegments() >= 50) {
  4342. roundValues(false);
  4343. } else {
  4344. roundValues(true);
  4345. }
  4346. }
  4347. function inBrowser() {
  4348. return typeof navigator !== 'undefined';
  4349. }
  4350. function installPlugin(type, plugin) {
  4351. if (type === 'expressions') {
  4352. setExpressionsPlugin(plugin);
  4353. }
  4354. }
  4355. function getFactory(name) {
  4356. switch (name) {
  4357. case 'propertyFactory':
  4358. return PropertyFactory;
  4359. case 'shapePropertyFactory':
  4360. return ShapePropertyFactory;
  4361. case 'matrix':
  4362. return Matrix;
  4363. default:
  4364. return null;
  4365. }
  4366. }
  4367. lottie.play = animationManager.play;
  4368. lottie.pause = animationManager.pause;
  4369. lottie.setLocationHref = setLocation;
  4370. lottie.togglePause = animationManager.togglePause;
  4371. lottie.setSpeed = animationManager.setSpeed;
  4372. lottie.setDirection = animationManager.setDirection;
  4373. lottie.stop = animationManager.stop;
  4374. lottie.searchAnimations = searchAnimations;
  4375. lottie.registerAnimation = animationManager.registerAnimation;
  4376. lottie.loadAnimation = loadAnimation;
  4377. lottie.setSubframeRendering = setSubframeRendering;
  4378. lottie.resize = animationManager.resize;
  4379. // lottie.start = start;
  4380. lottie.goToAndStop = animationManager.goToAndStop;
  4381. lottie.destroy = animationManager.destroy;
  4382. lottie.setQuality = setQuality;
  4383. lottie.inBrowser = inBrowser;
  4384. lottie.installPlugin = installPlugin;
  4385. lottie.freeze = animationManager.freeze;
  4386. lottie.unfreeze = animationManager.unfreeze;
  4387. lottie.setVolume = animationManager.setVolume;
  4388. lottie.mute = animationManager.mute;
  4389. lottie.unmute = animationManager.unmute;
  4390. lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  4391. lottie.useWebWorker = setWebWorker;
  4392. lottie.setIDPrefix = setPrefix;
  4393. lottie.__getFactory = getFactory;
  4394. lottie.version = '5.13.0';
  4395. function checkReady() {
  4396. if (document.readyState === 'complete') {
  4397. clearInterval(readyStateCheckInterval);
  4398. searchAnimations();
  4399. }
  4400. }
  4401. function getQueryVariable(variable) {
  4402. var vars = queryString.split('&');
  4403. for (var i = 0; i < vars.length; i += 1) {
  4404. var pair = vars[i].split('=');
  4405. if (decodeURIComponent(pair[0]) == variable) {
  4406. // eslint-disable-line eqeqeq
  4407. return decodeURIComponent(pair[1]);
  4408. }
  4409. }
  4410. return null;
  4411. }
  4412. var queryString = '';
  4413. if (standalone) {
  4414. var scripts = document.getElementsByTagName('script');
  4415. var index = scripts.length - 1;
  4416. var myScript = scripts[index] || {
  4417. src: ''
  4418. };
  4419. queryString = myScript.src ? myScript.src.replace(/^[^\?]+\??/, '') : ''; // eslint-disable-line no-useless-escape
  4420. renderer = getQueryVariable('renderer');
  4421. }
  4422. var readyStateCheckInterval = setInterval(checkReady, 100);
  4423. // this adds bodymovin to the window object for backwards compatibility
  4424. try {
  4425. if (!((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined') && !(typeof define === 'function' && define.amd) // eslint-disable-line no-undef
  4426. ) {
  4427. window.bodymovin = lottie;
  4428. }
  4429. } catch (err) {
  4430. //
  4431. }
  4432. var ShapeModifiers = function () {
  4433. var ob = {};
  4434. var modifiers = {};
  4435. ob.registerModifier = registerModifier;
  4436. ob.getModifier = getModifier;
  4437. function registerModifier(nm, factory) {
  4438. if (!modifiers[nm]) {
  4439. modifiers[nm] = factory;
  4440. }
  4441. }
  4442. function getModifier(nm, elem, data) {
  4443. return new modifiers[nm](elem, data);
  4444. }
  4445. return ob;
  4446. }();
  4447. function ShapeModifier() {}
  4448. ShapeModifier.prototype.initModifierProperties = function () {};
  4449. ShapeModifier.prototype.addShapeToModifier = function () {};
  4450. ShapeModifier.prototype.addShape = function (data) {
  4451. if (!this.closed) {
  4452. // Adding shape to dynamic properties. It covers the case where a shape has no effects applied, to reset it's _mdf state on every tick.
  4453. data.sh.container.addDynamicProperty(data.sh);
  4454. var shapeData = {
  4455. shape: data.sh,
  4456. data: data,
  4457. localShapeCollection: shapeCollectionPool.newShapeCollection()
  4458. };
  4459. this.shapes.push(shapeData);
  4460. this.addShapeToModifier(shapeData);
  4461. if (this._isAnimated) {
  4462. data.setAsAnimated();
  4463. }
  4464. }
  4465. };
  4466. ShapeModifier.prototype.init = function (elem, data) {
  4467. this.shapes = [];
  4468. this.elem = elem;
  4469. this.initDynamicPropertyContainer(elem);
  4470. this.initModifierProperties(elem, data);
  4471. this.frameId = initialDefaultFrame;
  4472. this.closed = false;
  4473. this.k = false;
  4474. if (this.dynamicProperties.length) {
  4475. this.k = true;
  4476. } else {
  4477. this.getValue(true);
  4478. }
  4479. };
  4480. ShapeModifier.prototype.processKeys = function () {
  4481. if (this.elem.globalData.frameId === this.frameId) {
  4482. return;
  4483. }
  4484. this.frameId = this.elem.globalData.frameId;
  4485. this.iterateDynamicProperties();
  4486. };
  4487. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  4488. function TrimModifier() {}
  4489. extendPrototype([ShapeModifier], TrimModifier);
  4490. TrimModifier.prototype.initModifierProperties = function (elem, data) {
  4491. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  4492. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  4493. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  4494. this.sValue = 0;
  4495. this.eValue = 0;
  4496. this.getValue = this.processKeys;
  4497. this.m = data.m;
  4498. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  4499. };
  4500. TrimModifier.prototype.addShapeToModifier = function (shapeData) {
  4501. shapeData.pathsData = [];
  4502. };
  4503. TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) {
  4504. var segments = [];
  4505. if (e <= 1) {
  4506. segments.push({
  4507. s: s,
  4508. e: e
  4509. });
  4510. } else if (s >= 1) {
  4511. segments.push({
  4512. s: s - 1,
  4513. e: e - 1
  4514. });
  4515. } else {
  4516. segments.push({
  4517. s: s,
  4518. e: 1
  4519. });
  4520. segments.push({
  4521. s: 0,
  4522. e: e - 1
  4523. });
  4524. }
  4525. var shapeSegments = [];
  4526. var i;
  4527. var len = segments.length;
  4528. var segmentOb;
  4529. for (i = 0; i < len; i += 1) {
  4530. segmentOb = segments[i];
  4531. if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) {
  4532. var shapeS;
  4533. var shapeE;
  4534. if (segmentOb.s * totalModifierLength <= addedLength) {
  4535. shapeS = 0;
  4536. } else {
  4537. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  4538. }
  4539. if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  4540. shapeE = 1;
  4541. } else {
  4542. shapeE = (segmentOb.e * totalModifierLength - addedLength) / shapeLength;
  4543. }
  4544. shapeSegments.push([shapeS, shapeE]);
  4545. }
  4546. }
  4547. if (!shapeSegments.length) {
  4548. shapeSegments.push([0, 0]);
  4549. }
  4550. return shapeSegments;
  4551. };
  4552. TrimModifier.prototype.releasePathsData = function (pathsData) {
  4553. var i;
  4554. var len = pathsData.length;
  4555. for (i = 0; i < len; i += 1) {
  4556. segmentsLengthPool.release(pathsData[i]);
  4557. }
  4558. pathsData.length = 0;
  4559. return pathsData;
  4560. };
  4561. TrimModifier.prototype.processShapes = function (_isFirstFrame) {
  4562. var s;
  4563. var e;
  4564. if (this._mdf || _isFirstFrame) {
  4565. var o = this.o.v % 360 / 360;
  4566. if (o < 0) {
  4567. o += 1;
  4568. }
  4569. if (this.s.v > 1) {
  4570. s = 1 + o;
  4571. } else if (this.s.v < 0) {
  4572. s = 0 + o;
  4573. } else {
  4574. s = this.s.v + o;
  4575. }
  4576. if (this.e.v > 1) {
  4577. e = 1 + o;
  4578. } else if (this.e.v < 0) {
  4579. e = 0 + o;
  4580. } else {
  4581. e = this.e.v + o;
  4582. }
  4583. if (s > e) {
  4584. var _s = s;
  4585. s = e;
  4586. e = _s;
  4587. }
  4588. s = Math.round(s * 10000) * 0.0001;
  4589. e = Math.round(e * 10000) * 0.0001;
  4590. this.sValue = s;
  4591. this.eValue = e;
  4592. } else {
  4593. s = this.sValue;
  4594. e = this.eValue;
  4595. }
  4596. var shapePaths;
  4597. var i;
  4598. var len = this.shapes.length;
  4599. var j;
  4600. var jLen;
  4601. var pathsData;
  4602. var pathData;
  4603. var totalShapeLength;
  4604. var totalModifierLength = 0;
  4605. if (e === s) {
  4606. for (i = 0; i < len; i += 1) {
  4607. this.shapes[i].localShapeCollection.releaseShapes();
  4608. this.shapes[i].shape._mdf = true;
  4609. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  4610. if (this._mdf) {
  4611. this.shapes[i].pathsData.length = 0;
  4612. }
  4613. }
  4614. } else if (!(e === 1 && s === 0 || e === 0 && s === 1)) {
  4615. var segments = [];
  4616. var shapeData;
  4617. var localShapeCollection;
  4618. for (i = 0; i < len; i += 1) {
  4619. shapeData = this.shapes[i];
  4620. // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  4621. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  4622. shapeData.shape.paths = shapeData.localShapeCollection;
  4623. } else {
  4624. shapePaths = shapeData.shape.paths;
  4625. jLen = shapePaths._length;
  4626. totalShapeLength = 0;
  4627. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  4628. totalShapeLength = shapeData.totalShapeLength;
  4629. } else {
  4630. pathsData = this.releasePathsData(shapeData.pathsData);
  4631. for (j = 0; j < jLen; j += 1) {
  4632. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  4633. pathsData.push(pathData);
  4634. totalShapeLength += pathData.totalLength;
  4635. }
  4636. shapeData.totalShapeLength = totalShapeLength;
  4637. shapeData.pathsData = pathsData;
  4638. }
  4639. totalModifierLength += totalShapeLength;
  4640. shapeData.shape._mdf = true;
  4641. }
  4642. }
  4643. var shapeS = s;
  4644. var shapeE = e;
  4645. var addedLength = 0;
  4646. var edges;
  4647. for (i = len - 1; i >= 0; i -= 1) {
  4648. shapeData = this.shapes[i];
  4649. if (shapeData.shape._mdf) {
  4650. localShapeCollection = shapeData.localShapeCollection;
  4651. localShapeCollection.releaseShapes();
  4652. // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  4653. if (this.m === 2 && len > 1) {
  4654. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  4655. addedLength += shapeData.totalShapeLength;
  4656. } else {
  4657. edges = [[shapeS, shapeE]];
  4658. }
  4659. jLen = edges.length;
  4660. for (j = 0; j < jLen; j += 1) {
  4661. shapeS = edges[j][0];
  4662. shapeE = edges[j][1];
  4663. segments.length = 0;
  4664. if (shapeE <= 1) {
  4665. segments.push({
  4666. s: shapeData.totalShapeLength * shapeS,
  4667. e: shapeData.totalShapeLength * shapeE
  4668. });
  4669. } else if (shapeS >= 1) {
  4670. segments.push({
  4671. s: shapeData.totalShapeLength * (shapeS - 1),
  4672. e: shapeData.totalShapeLength * (shapeE - 1)
  4673. });
  4674. } else {
  4675. segments.push({
  4676. s: shapeData.totalShapeLength * shapeS,
  4677. e: shapeData.totalShapeLength
  4678. });
  4679. segments.push({
  4680. s: 0,
  4681. e: shapeData.totalShapeLength * (shapeE - 1)
  4682. });
  4683. }
  4684. var newShapesData = this.addShapes(shapeData, segments[0]);
  4685. if (segments[0].s !== segments[0].e) {
  4686. if (segments.length > 1) {
  4687. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  4688. if (lastShapeInCollection.c) {
  4689. var lastShape = newShapesData.pop();
  4690. this.addPaths(newShapesData, localShapeCollection);
  4691. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  4692. } else {
  4693. this.addPaths(newShapesData, localShapeCollection);
  4694. newShapesData = this.addShapes(shapeData, segments[1]);
  4695. }
  4696. }
  4697. this.addPaths(newShapesData, localShapeCollection);
  4698. }
  4699. }
  4700. shapeData.shape.paths = localShapeCollection;
  4701. }
  4702. }
  4703. } else if (this._mdf) {
  4704. for (i = 0; i < len; i += 1) {
  4705. // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  4706. // Don't remove this even if it's losing cached info.
  4707. this.shapes[i].pathsData.length = 0;
  4708. this.shapes[i].shape._mdf = true;
  4709. }
  4710. }
  4711. };
  4712. TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) {
  4713. var i;
  4714. var len = newPaths.length;
  4715. for (i = 0; i < len; i += 1) {
  4716. localShapeCollection.addShape(newPaths[i]);
  4717. }
  4718. };
  4719. TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  4720. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  4721. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  4722. if (newShape) {
  4723. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  4724. }
  4725. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  4726. };
  4727. TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) {
  4728. shapePath.setXYAt(points[1], points[5], 'o', pos);
  4729. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  4730. if (newShape) {
  4731. shapePath.setXYAt(points[0], points[4], 'v', pos);
  4732. }
  4733. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  4734. };
  4735. TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) {
  4736. var pathsData = shapeData.pathsData;
  4737. var shapePaths = shapeData.shape.paths.shapes;
  4738. var i;
  4739. var len = shapeData.shape.paths._length;
  4740. var j;
  4741. var jLen;
  4742. var addedLength = 0;
  4743. var currentLengthData;
  4744. var segmentCount;
  4745. var lengths;
  4746. var segment;
  4747. var shapes = [];
  4748. var initPos;
  4749. var newShape = true;
  4750. if (!shapePath) {
  4751. shapePath = shapePool.newElement();
  4752. segmentCount = 0;
  4753. initPos = 0;
  4754. } else {
  4755. segmentCount = shapePath._length;
  4756. initPos = shapePath._length;
  4757. }
  4758. shapes.push(shapePath);
  4759. for (i = 0; i < len; i += 1) {
  4760. lengths = pathsData[i].lengths;
  4761. shapePath.c = shapePaths[i].c;
  4762. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  4763. for (j = 1; j < jLen; j += 1) {
  4764. currentLengthData = lengths[j - 1];
  4765. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  4766. addedLength += currentLengthData.addedLength;
  4767. shapePath.c = false;
  4768. } else if (addedLength > shapeSegment.e) {
  4769. shapePath.c = false;
  4770. break;
  4771. } else {
  4772. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  4773. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  4774. newShape = false;
  4775. } else {
  4776. segment = bez.getNewSegment(shapePaths[i].v[j - 1], shapePaths[i].v[j], shapePaths[i].o[j - 1], shapePaths[i].i[j], (shapeSegment.s - addedLength) / currentLengthData.addedLength, (shapeSegment.e - addedLength) / currentLengthData.addedLength, lengths[j - 1]);
  4777. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4778. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4779. newShape = false;
  4780. shapePath.c = false;
  4781. }
  4782. addedLength += currentLengthData.addedLength;
  4783. segmentCount += 1;
  4784. }
  4785. }
  4786. if (shapePaths[i].c && lengths.length) {
  4787. currentLengthData = lengths[j - 1];
  4788. if (addedLength <= shapeSegment.e) {
  4789. var segmentLength = lengths[j - 1].addedLength;
  4790. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  4791. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  4792. newShape = false;
  4793. } else {
  4794. segment = bez.getNewSegment(shapePaths[i].v[j - 1], shapePaths[i].v[0], shapePaths[i].o[j - 1], shapePaths[i].i[0], (shapeSegment.s - addedLength) / segmentLength, (shapeSegment.e - addedLength) / segmentLength, lengths[j - 1]);
  4795. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4796. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4797. newShape = false;
  4798. shapePath.c = false;
  4799. }
  4800. } else {
  4801. shapePath.c = false;
  4802. }
  4803. addedLength += currentLengthData.addedLength;
  4804. segmentCount += 1;
  4805. }
  4806. if (shapePath._length) {
  4807. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  4808. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1);
  4809. }
  4810. if (addedLength > shapeSegment.e) {
  4811. break;
  4812. }
  4813. if (i < len - 1) {
  4814. shapePath = shapePool.newElement();
  4815. newShape = true;
  4816. shapes.push(shapePath);
  4817. segmentCount = 0;
  4818. }
  4819. }
  4820. return shapes;
  4821. };
  4822. function PuckerAndBloatModifier() {}
  4823. extendPrototype([ShapeModifier], PuckerAndBloatModifier);
  4824. PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) {
  4825. this.getValue = this.processKeys;
  4826. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  4827. this._isAnimated = !!this.amount.effectsSequence.length;
  4828. };
  4829. PuckerAndBloatModifier.prototype.processPath = function (path, amount) {
  4830. var percent = amount / 100;
  4831. var centerPoint = [0, 0];
  4832. var pathLength = path._length;
  4833. var i = 0;
  4834. for (i = 0; i < pathLength; i += 1) {
  4835. centerPoint[0] += path.v[i][0];
  4836. centerPoint[1] += path.v[i][1];
  4837. }
  4838. centerPoint[0] /= pathLength;
  4839. centerPoint[1] /= pathLength;
  4840. var clonedPath = shapePool.newElement();
  4841. clonedPath.c = path.c;
  4842. var vX;
  4843. var vY;
  4844. var oX;
  4845. var oY;
  4846. var iX;
  4847. var iY;
  4848. for (i = 0; i < pathLength; i += 1) {
  4849. vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
  4850. vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
  4851. oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
  4852. oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
  4853. iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
  4854. iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
  4855. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i);
  4856. }
  4857. return clonedPath;
  4858. };
  4859. PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) {
  4860. var shapePaths;
  4861. var i;
  4862. var len = this.shapes.length;
  4863. var j;
  4864. var jLen;
  4865. var amount = this.amount.v;
  4866. if (amount !== 0) {
  4867. var shapeData;
  4868. var localShapeCollection;
  4869. for (i = 0; i < len; i += 1) {
  4870. shapeData = this.shapes[i];
  4871. localShapeCollection = shapeData.localShapeCollection;
  4872. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  4873. localShapeCollection.releaseShapes();
  4874. shapeData.shape._mdf = true;
  4875. shapePaths = shapeData.shape.paths.shapes;
  4876. jLen = shapeData.shape.paths._length;
  4877. for (j = 0; j < jLen; j += 1) {
  4878. localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
  4879. }
  4880. }
  4881. shapeData.shape.paths = shapeData.localShapeCollection;
  4882. }
  4883. }
  4884. if (!this.dynamicProperties.length) {
  4885. this._mdf = false;
  4886. }
  4887. };
  4888. var TransformPropertyFactory = function () {
  4889. var defaultVector = [0, 0];
  4890. function applyToMatrix(mat) {
  4891. var _mdf = this._mdf;
  4892. this.iterateDynamicProperties();
  4893. this._mdf = this._mdf || _mdf;
  4894. if (this.a) {
  4895. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4896. }
  4897. if (this.s) {
  4898. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4899. }
  4900. if (this.sk) {
  4901. mat.skewFromAxis(-this.sk.v, this.sa.v);
  4902. }
  4903. if (this.r) {
  4904. mat.rotate(-this.r.v);
  4905. } else {
  4906. mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  4907. }
  4908. if (this.data.p.s) {
  4909. if (this.data.p.z) {
  4910. mat.translate(this.px.v, this.py.v, -this.pz.v);
  4911. } else {
  4912. mat.translate(this.px.v, this.py.v, 0);
  4913. }
  4914. } else {
  4915. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4916. }
  4917. }
  4918. function processKeys(forceRender) {
  4919. if (this.elem.globalData.frameId === this.frameId) {
  4920. return;
  4921. }
  4922. if (this._isDirty) {
  4923. this.precalculateMatrix();
  4924. this._isDirty = false;
  4925. }
  4926. this.iterateDynamicProperties();
  4927. if (this._mdf || forceRender) {
  4928. var frameRate;
  4929. this.v.cloneFromProps(this.pre.props);
  4930. if (this.appliedTransformations < 1) {
  4931. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4932. }
  4933. if (this.appliedTransformations < 2) {
  4934. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4935. }
  4936. if (this.sk && this.appliedTransformations < 3) {
  4937. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  4938. }
  4939. if (this.r && this.appliedTransformations < 4) {
  4940. this.v.rotate(-this.r.v);
  4941. } else if (!this.r && this.appliedTransformations < 4) {
  4942. this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  4943. }
  4944. if (this.autoOriented) {
  4945. var v1;
  4946. var v2;
  4947. frameRate = this.elem.globalData.frameRate;
  4948. if (this.p && this.p.keyframes && this.p.getValueAtTime) {
  4949. if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) {
  4950. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0);
  4951. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  4952. } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  4953. v1 = this.p.getValueAtTime(this.p.keyframes[this.p.keyframes.length - 1].t / frameRate, 0);
  4954. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0);
  4955. } else {
  4956. v1 = this.p.pv;
  4957. v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  4958. }
  4959. } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  4960. v1 = [];
  4961. v2 = [];
  4962. var px = this.px;
  4963. var py = this.py;
  4964. if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) {
  4965. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0);
  4966. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0);
  4967. v2[0] = px.getValueAtTime(px.keyframes[0].t / frameRate, 0);
  4968. v2[1] = py.getValueAtTime(py.keyframes[0].t / frameRate, 0);
  4969. } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  4970. v1[0] = px.getValueAtTime(px.keyframes[px.keyframes.length - 1].t / frameRate, 0);
  4971. v1[1] = py.getValueAtTime(py.keyframes[py.keyframes.length - 1].t / frameRate, 0);
  4972. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4973. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4974. } else {
  4975. v1 = [px.pv, py.pv];
  4976. v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime);
  4977. v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime);
  4978. }
  4979. } else {
  4980. v2 = defaultVector;
  4981. v1 = v2;
  4982. }
  4983. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  4984. }
  4985. if (this.data.p && this.data.p.s) {
  4986. if (this.data.p.z) {
  4987. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  4988. } else {
  4989. this.v.translate(this.px.v, this.py.v, 0);
  4990. }
  4991. } else {
  4992. this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4993. }
  4994. }
  4995. this.frameId = this.elem.globalData.frameId;
  4996. }
  4997. function precalculateMatrix() {
  4998. this.appliedTransformations = 0;
  4999. this.pre.reset();
  5000. if (!this.a.effectsSequence.length) {
  5001. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  5002. this.appliedTransformations = 1;
  5003. } else {
  5004. return;
  5005. }
  5006. if (!this.s.effectsSequence.length) {
  5007. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  5008. this.appliedTransformations = 2;
  5009. } else {
  5010. return;
  5011. }
  5012. if (this.sk) {
  5013. if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  5014. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  5015. this.appliedTransformations = 3;
  5016. } else {
  5017. return;
  5018. }
  5019. }
  5020. if (this.r) {
  5021. if (!this.r.effectsSequence.length) {
  5022. this.pre.rotate(-this.r.v);
  5023. this.appliedTransformations = 4;
  5024. }
  5025. } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  5026. this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  5027. this.appliedTransformations = 4;
  5028. }
  5029. }
  5030. function autoOrient() {
  5031. //
  5032. // var prevP = this.getValueAtTime();
  5033. }
  5034. function addDynamicProperty(prop) {
  5035. this._addDynamicProperty(prop);
  5036. this.elem.addDynamicProperty(prop);
  5037. this._isDirty = true;
  5038. }
  5039. function TransformProperty(elem, data, container) {
  5040. this.elem = elem;
  5041. this.frameId = -1;
  5042. this.propType = 'transform';
  5043. this.data = data;
  5044. this.v = new Matrix();
  5045. // Precalculated matrix with non animated properties
  5046. this.pre = new Matrix();
  5047. this.appliedTransformations = 0;
  5048. this.initDynamicPropertyContainer(container || elem);
  5049. if (data.p && data.p.s) {
  5050. this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this);
  5051. this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this);
  5052. if (data.p.z) {
  5053. this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this);
  5054. }
  5055. } else {
  5056. this.p = PropertyFactory.getProp(elem, data.p || {
  5057. k: [0, 0, 0]
  5058. }, 1, 0, this);
  5059. }
  5060. if (data.rx) {
  5061. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  5062. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  5063. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  5064. if (data.or.k[0].ti) {
  5065. var i;
  5066. var len = data.or.k.length;
  5067. for (i = 0; i < len; i += 1) {
  5068. data.or.k[i].to = null;
  5069. data.or.k[i].ti = null;
  5070. }
  5071. }
  5072. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
  5073. // sh Indicates it needs to be capped between -180 and 180
  5074. this.or.sh = true;
  5075. } else {
  5076. this.r = PropertyFactory.getProp(elem, data.r || {
  5077. k: 0
  5078. }, 0, degToRads, this);
  5079. }
  5080. if (data.sk) {
  5081. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  5082. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  5083. }
  5084. this.a = PropertyFactory.getProp(elem, data.a || {
  5085. k: [0, 0, 0]
  5086. }, 1, 0, this);
  5087. this.s = PropertyFactory.getProp(elem, data.s || {
  5088. k: [100, 100, 100]
  5089. }, 1, 0.01, this);
  5090. // Opacity is not part of the transform properties, that's why it won't use this.dynamicProperties. That way transforms won't get updated if opacity changes.
  5091. if (data.o) {
  5092. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem);
  5093. } else {
  5094. this.o = {
  5095. _mdf: false,
  5096. v: 1
  5097. };
  5098. }
  5099. this._isDirty = true;
  5100. if (!this.dynamicProperties.length) {
  5101. this.getValue(true);
  5102. }
  5103. }
  5104. TransformProperty.prototype = {
  5105. applyToMatrix: applyToMatrix,
  5106. getValue: processKeys,
  5107. precalculateMatrix: precalculateMatrix,
  5108. autoOrient: autoOrient
  5109. };
  5110. extendPrototype([DynamicPropertyContainer], TransformProperty);
  5111. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  5112. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  5113. function getTransformProperty(elem, data, container) {
  5114. return new TransformProperty(elem, data, container);
  5115. }
  5116. return {
  5117. getTransformProperty: getTransformProperty
  5118. };
  5119. }();
  5120. function RepeaterModifier() {}
  5121. extendPrototype([ShapeModifier], RepeaterModifier);
  5122. RepeaterModifier.prototype.initModifierProperties = function (elem, data) {
  5123. this.getValue = this.processKeys;
  5124. this.c = PropertyFactory.getProp(elem, data.c, 0, null, this);
  5125. this.o = PropertyFactory.getProp(elem, data.o, 0, null, this);
  5126. this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this);
  5127. this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this);
  5128. this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this);
  5129. this.data = data;
  5130. if (!this.dynamicProperties.length) {
  5131. this.getValue(true);
  5132. }
  5133. this._isAnimated = !!this.dynamicProperties.length;
  5134. this.pMatrix = new Matrix();
  5135. this.rMatrix = new Matrix();
  5136. this.sMatrix = new Matrix();
  5137. this.tMatrix = new Matrix();
  5138. this.matrix = new Matrix();
  5139. };
  5140. RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) {
  5141. var dir = inv ? -1 : 1;
  5142. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  5143. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  5144. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  5145. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5146. rMatrix.rotate(-transform.r.v * dir * perc);
  5147. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5148. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5149. sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY);
  5150. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5151. };
  5152. RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) {
  5153. this.elem = elem;
  5154. this.arr = arr;
  5155. this.pos = pos;
  5156. this.elemsData = elemsData;
  5157. this._currentCopies = 0;
  5158. this._elements = [];
  5159. this._groups = [];
  5160. this.frameId = -1;
  5161. this.initDynamicPropertyContainer(elem);
  5162. this.initModifierProperties(elem, arr[pos]);
  5163. while (pos > 0) {
  5164. pos -= 1;
  5165. // this._elements.unshift(arr.splice(pos,1)[0]);
  5166. this._elements.unshift(arr[pos]);
  5167. }
  5168. if (this.dynamicProperties.length) {
  5169. this.k = true;
  5170. } else {
  5171. this.getValue(true);
  5172. }
  5173. };
  5174. RepeaterModifier.prototype.resetElements = function (elements) {
  5175. var i;
  5176. var len = elements.length;
  5177. for (i = 0; i < len; i += 1) {
  5178. elements[i]._processed = false;
  5179. if (elements[i].ty === 'gr') {
  5180. this.resetElements(elements[i].it);
  5181. }
  5182. }
  5183. };
  5184. RepeaterModifier.prototype.cloneElements = function (elements) {
  5185. var newElements = JSON.parse(JSON.stringify(elements));
  5186. this.resetElements(newElements);
  5187. return newElements;
  5188. };
  5189. RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) {
  5190. var i;
  5191. var len = elements.length;
  5192. for (i = 0; i < len; i += 1) {
  5193. elements[i]._render = renderFlag;
  5194. if (elements[i].ty === 'gr') {
  5195. this.changeGroupRender(elements[i].it, renderFlag);
  5196. }
  5197. }
  5198. };
  5199. RepeaterModifier.prototype.processShapes = function (_isFirstFrame) {
  5200. var items;
  5201. var itemsTransform;
  5202. var i;
  5203. var dir;
  5204. var cont;
  5205. var hasReloaded = false;
  5206. if (this._mdf || _isFirstFrame) {
  5207. var copies = Math.ceil(this.c.v);
  5208. if (this._groups.length < copies) {
  5209. while (this._groups.length < copies) {
  5210. var group = {
  5211. it: this.cloneElements(this._elements),
  5212. ty: 'gr'
  5213. };
  5214. group.it.push({
  5215. a: {
  5216. a: 0,
  5217. ix: 1,
  5218. k: [0, 0]
  5219. },
  5220. nm: 'Transform',
  5221. o: {
  5222. a: 0,
  5223. ix: 7,
  5224. k: 100
  5225. },
  5226. p: {
  5227. a: 0,
  5228. ix: 2,
  5229. k: [0, 0]
  5230. },
  5231. r: {
  5232. a: 1,
  5233. ix: 6,
  5234. k: [{
  5235. s: 0,
  5236. e: 0,
  5237. t: 0
  5238. }, {
  5239. s: 0,
  5240. e: 0,
  5241. t: 1
  5242. }]
  5243. },
  5244. s: {
  5245. a: 0,
  5246. ix: 3,
  5247. k: [100, 100]
  5248. },
  5249. sa: {
  5250. a: 0,
  5251. ix: 5,
  5252. k: 0
  5253. },
  5254. sk: {
  5255. a: 0,
  5256. ix: 4,
  5257. k: 0
  5258. },
  5259. ty: 'tr'
  5260. });
  5261. this.arr.splice(0, 0, group);
  5262. this._groups.splice(0, 0, group);
  5263. this._currentCopies += 1;
  5264. }
  5265. this.elem.reloadShapes();
  5266. hasReloaded = true;
  5267. }
  5268. cont = 0;
  5269. var renderFlag;
  5270. for (i = 0; i <= this._groups.length - 1; i += 1) {
  5271. renderFlag = cont < copies;
  5272. this._groups[i]._render = renderFlag;
  5273. this.changeGroupRender(this._groups[i].it, renderFlag);
  5274. if (!renderFlag) {
  5275. var elems = this.elemsData[i].it;
  5276. var transformData = elems[elems.length - 1];
  5277. if (transformData.transform.op.v !== 0) {
  5278. transformData.transform.op._mdf = true;
  5279. transformData.transform.op.v = 0;
  5280. } else {
  5281. transformData.transform.op._mdf = false;
  5282. }
  5283. }
  5284. cont += 1;
  5285. }
  5286. this._currentCopies = copies;
  5287. /// /
  5288. var offset = this.o.v;
  5289. var offsetModulo = offset % 1;
  5290. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  5291. var pProps = this.pMatrix.props;
  5292. var rProps = this.rMatrix.props;
  5293. var sProps = this.sMatrix.props;
  5294. this.pMatrix.reset();
  5295. this.rMatrix.reset();
  5296. this.sMatrix.reset();
  5297. this.tMatrix.reset();
  5298. this.matrix.reset();
  5299. var iteration = 0;
  5300. if (offset > 0) {
  5301. while (iteration < roundOffset) {
  5302. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5303. iteration += 1;
  5304. }
  5305. if (offsetModulo) {
  5306. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  5307. iteration += offsetModulo;
  5308. }
  5309. } else if (offset < 0) {
  5310. while (iteration > roundOffset) {
  5311. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  5312. iteration -= 1;
  5313. }
  5314. if (offsetModulo) {
  5315. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true);
  5316. iteration -= offsetModulo;
  5317. }
  5318. }
  5319. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  5320. dir = this.data.m === 1 ? 1 : -1;
  5321. cont = this._currentCopies;
  5322. var j;
  5323. var jLen;
  5324. while (cont) {
  5325. items = this.elemsData[i].it;
  5326. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5327. jLen = itemsTransform.length;
  5328. items[items.length - 1].transform.mProps._mdf = true;
  5329. items[items.length - 1].transform.op._mdf = true;
  5330. items[items.length - 1].transform.op.v = this._currentCopies === 1 ? this.so.v : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  5331. if (iteration !== 0) {
  5332. if (i !== 0 && dir === 1 || i !== this._currentCopies - 1 && dir === -1) {
  5333. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5334. }
  5335. this.matrix.transform(rProps[0], rProps[1], rProps[2], rProps[3], rProps[4], rProps[5], rProps[6], rProps[7], rProps[8], rProps[9], rProps[10], rProps[11], rProps[12], rProps[13], rProps[14], rProps[15]);
  5336. this.matrix.transform(sProps[0], sProps[1], sProps[2], sProps[3], sProps[4], sProps[5], sProps[6], sProps[7], sProps[8], sProps[9], sProps[10], sProps[11], sProps[12], sProps[13], sProps[14], sProps[15]);
  5337. this.matrix.transform(pProps[0], pProps[1], pProps[2], pProps[3], pProps[4], pProps[5], pProps[6], pProps[7], pProps[8], pProps[9], pProps[10], pProps[11], pProps[12], pProps[13], pProps[14], pProps[15]);
  5338. for (j = 0; j < jLen; j += 1) {
  5339. itemsTransform[j] = this.matrix.props[j];
  5340. }
  5341. this.matrix.reset();
  5342. } else {
  5343. this.matrix.reset();
  5344. for (j = 0; j < jLen; j += 1) {
  5345. itemsTransform[j] = this.matrix.props[j];
  5346. }
  5347. }
  5348. iteration += 1;
  5349. cont -= 1;
  5350. i += dir;
  5351. }
  5352. } else {
  5353. cont = this._currentCopies;
  5354. i = 0;
  5355. dir = 1;
  5356. while (cont) {
  5357. items = this.elemsData[i].it;
  5358. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5359. items[items.length - 1].transform.mProps._mdf = false;
  5360. items[items.length - 1].transform.op._mdf = false;
  5361. cont -= 1;
  5362. i += dir;
  5363. }
  5364. }
  5365. return hasReloaded;
  5366. };
  5367. RepeaterModifier.prototype.addShape = function () {};
  5368. function RoundCornersModifier() {}
  5369. extendPrototype([ShapeModifier], RoundCornersModifier);
  5370. RoundCornersModifier.prototype.initModifierProperties = function (elem, data) {
  5371. this.getValue = this.processKeys;
  5372. this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5373. this._isAnimated = !!this.rd.effectsSequence.length;
  5374. };
  5375. RoundCornersModifier.prototype.processPath = function (path, round) {
  5376. var clonedPath = shapePool.newElement();
  5377. clonedPath.c = path.c;
  5378. var i;
  5379. var len = path._length;
  5380. var currentV;
  5381. var currentI;
  5382. var currentO;
  5383. var closerV;
  5384. var distance;
  5385. var newPosPerc;
  5386. var index = 0;
  5387. var vX;
  5388. var vY;
  5389. var oX;
  5390. var oY;
  5391. var iX;
  5392. var iY;
  5393. for (i = 0; i < len; i += 1) {
  5394. currentV = path.v[i];
  5395. currentO = path.o[i];
  5396. currentI = path.i[i];
  5397. if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) {
  5398. if ((i === 0 || i === len - 1) && !path.c) {
  5399. clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index);
  5400. /* clonedPath.v[index] = currentV;
  5401. clonedPath.o[index] = currentO;
  5402. clonedPath.i[index] = currentI; */
  5403. index += 1;
  5404. } else {
  5405. if (i === 0) {
  5406. closerV = path.v[len - 1];
  5407. } else {
  5408. closerV = path.v[i - 1];
  5409. }
  5410. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5411. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5412. iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5413. vX = iX;
  5414. iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc;
  5415. vY = iY;
  5416. oX = vX - (vX - currentV[0]) * roundCorner;
  5417. oY = vY - (vY - currentV[1]) * roundCorner;
  5418. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5419. index += 1;
  5420. if (i === len - 1) {
  5421. closerV = path.v[0];
  5422. } else {
  5423. closerV = path.v[i + 1];
  5424. }
  5425. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5426. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5427. oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5428. vX = oX;
  5429. oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc;
  5430. vY = oY;
  5431. iX = vX - (vX - currentV[0]) * roundCorner;
  5432. iY = vY - (vY - currentV[1]) * roundCorner;
  5433. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5434. index += 1;
  5435. }
  5436. } else {
  5437. clonedPath.setTripleAt(path.v[i][0], path.v[i][1], path.o[i][0], path.o[i][1], path.i[i][0], path.i[i][1], index);
  5438. index += 1;
  5439. }
  5440. }
  5441. return clonedPath;
  5442. };
  5443. RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) {
  5444. var shapePaths;
  5445. var i;
  5446. var len = this.shapes.length;
  5447. var j;
  5448. var jLen;
  5449. var rd = this.rd.v;
  5450. if (rd !== 0) {
  5451. var shapeData;
  5452. var localShapeCollection;
  5453. for (i = 0; i < len; i += 1) {
  5454. shapeData = this.shapes[i];
  5455. localShapeCollection = shapeData.localShapeCollection;
  5456. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5457. localShapeCollection.releaseShapes();
  5458. shapeData.shape._mdf = true;
  5459. shapePaths = shapeData.shape.paths.shapes;
  5460. jLen = shapeData.shape.paths._length;
  5461. for (j = 0; j < jLen; j += 1) {
  5462. localShapeCollection.addShape(this.processPath(shapePaths[j], rd));
  5463. }
  5464. }
  5465. shapeData.shape.paths = shapeData.localShapeCollection;
  5466. }
  5467. }
  5468. if (!this.dynamicProperties.length) {
  5469. this._mdf = false;
  5470. }
  5471. };
  5472. function floatEqual(a, b) {
  5473. return Math.abs(a - b) * 100000 <= Math.min(Math.abs(a), Math.abs(b));
  5474. }
  5475. function floatZero(f) {
  5476. return Math.abs(f) <= 0.00001;
  5477. }
  5478. function lerp(p0, p1, amount) {
  5479. return p0 * (1 - amount) + p1 * amount;
  5480. }
  5481. function lerpPoint(p0, p1, amount) {
  5482. return [lerp(p0[0], p1[0], amount), lerp(p0[1], p1[1], amount)];
  5483. }
  5484. function quadRoots(a, b, c) {
  5485. // no root
  5486. if (a === 0) return [];
  5487. var s = b * b - 4 * a * c;
  5488. // Complex roots
  5489. if (s < 0) return [];
  5490. var singleRoot = -b / (2 * a);
  5491. // 1 root
  5492. if (s === 0) return [singleRoot];
  5493. var delta = Math.sqrt(s) / (2 * a);
  5494. // 2 roots
  5495. return [singleRoot - delta, singleRoot + delta];
  5496. }
  5497. function polynomialCoefficients(p0, p1, p2, p3) {
  5498. return [-p0 + 3 * p1 - 3 * p2 + p3, 3 * p0 - 6 * p1 + 3 * p2, -3 * p0 + 3 * p1, p0];
  5499. }
  5500. function singlePoint(p) {
  5501. return new PolynomialBezier(p, p, p, p, false);
  5502. }
  5503. function PolynomialBezier(p0, p1, p2, p3, linearize) {
  5504. if (linearize && pointEqual(p0, p1)) {
  5505. p1 = lerpPoint(p0, p3, 1 / 3);
  5506. }
  5507. if (linearize && pointEqual(p2, p3)) {
  5508. p2 = lerpPoint(p0, p3, 2 / 3);
  5509. }
  5510. var coeffx = polynomialCoefficients(p0[0], p1[0], p2[0], p3[0]);
  5511. var coeffy = polynomialCoefficients(p0[1], p1[1], p2[1], p3[1]);
  5512. this.a = [coeffx[0], coeffy[0]];
  5513. this.b = [coeffx[1], coeffy[1]];
  5514. this.c = [coeffx[2], coeffy[2]];
  5515. this.d = [coeffx[3], coeffy[3]];
  5516. this.points = [p0, p1, p2, p3];
  5517. }
  5518. PolynomialBezier.prototype.point = function (t) {
  5519. return [((this.a[0] * t + this.b[0]) * t + this.c[0]) * t + this.d[0], ((this.a[1] * t + this.b[1]) * t + this.c[1]) * t + this.d[1]];
  5520. };
  5521. PolynomialBezier.prototype.derivative = function (t) {
  5522. return [(3 * t * this.a[0] + 2 * this.b[0]) * t + this.c[0], (3 * t * this.a[1] + 2 * this.b[1]) * t + this.c[1]];
  5523. };
  5524. PolynomialBezier.prototype.tangentAngle = function (t) {
  5525. var p = this.derivative(t);
  5526. return Math.atan2(p[1], p[0]);
  5527. };
  5528. PolynomialBezier.prototype.normalAngle = function (t) {
  5529. var p = this.derivative(t);
  5530. return Math.atan2(p[0], p[1]);
  5531. };
  5532. PolynomialBezier.prototype.inflectionPoints = function () {
  5533. var denom = this.a[1] * this.b[0] - this.a[0] * this.b[1];
  5534. if (floatZero(denom)) return [];
  5535. var tcusp = -0.5 * (this.a[1] * this.c[0] - this.a[0] * this.c[1]) / denom;
  5536. var square = tcusp * tcusp - 1 / 3 * (this.b[1] * this.c[0] - this.b[0] * this.c[1]) / denom;
  5537. if (square < 0) return [];
  5538. var root = Math.sqrt(square);
  5539. if (floatZero(root)) {
  5540. if (root > 0 && root < 1) return [tcusp];
  5541. return [];
  5542. }
  5543. return [tcusp - root, tcusp + root].filter(function (r) {
  5544. return r > 0 && r < 1;
  5545. });
  5546. };
  5547. PolynomialBezier.prototype.split = function (t) {
  5548. if (t <= 0) return [singlePoint(this.points[0]), this];
  5549. if (t >= 1) return [this, singlePoint(this.points[this.points.length - 1])];
  5550. var p10 = lerpPoint(this.points[0], this.points[1], t);
  5551. var p11 = lerpPoint(this.points[1], this.points[2], t);
  5552. var p12 = lerpPoint(this.points[2], this.points[3], t);
  5553. var p20 = lerpPoint(p10, p11, t);
  5554. var p21 = lerpPoint(p11, p12, t);
  5555. var p3 = lerpPoint(p20, p21, t);
  5556. return [new PolynomialBezier(this.points[0], p10, p20, p3, true), new PolynomialBezier(p3, p21, p12, this.points[3], true)];
  5557. };
  5558. function extrema(bez, comp) {
  5559. var min = bez.points[0][comp];
  5560. var max = bez.points[bez.points.length - 1][comp];
  5561. if (min > max) {
  5562. var e = max;
  5563. max = min;
  5564. min = e;
  5565. }
  5566. // Derivative roots to find min/max
  5567. var f = quadRoots(3 * bez.a[comp], 2 * bez.b[comp], bez.c[comp]);
  5568. for (var i = 0; i < f.length; i += 1) {
  5569. if (f[i] > 0 && f[i] < 1) {
  5570. var val = bez.point(f[i])[comp];
  5571. if (val < min) min = val;else if (val > max) max = val;
  5572. }
  5573. }
  5574. return {
  5575. min: min,
  5576. max: max
  5577. };
  5578. }
  5579. PolynomialBezier.prototype.bounds = function () {
  5580. return {
  5581. x: extrema(this, 0),
  5582. y: extrema(this, 1)
  5583. };
  5584. };
  5585. PolynomialBezier.prototype.boundingBox = function () {
  5586. var bounds = this.bounds();
  5587. return {
  5588. left: bounds.x.min,
  5589. right: bounds.x.max,
  5590. top: bounds.y.min,
  5591. bottom: bounds.y.max,
  5592. width: bounds.x.max - bounds.x.min,
  5593. height: bounds.y.max - bounds.y.min,
  5594. cx: (bounds.x.max + bounds.x.min) / 2,
  5595. cy: (bounds.y.max + bounds.y.min) / 2
  5596. };
  5597. };
  5598. function intersectData(bez, t1, t2) {
  5599. var box = bez.boundingBox();
  5600. return {
  5601. cx: box.cx,
  5602. cy: box.cy,
  5603. width: box.width,
  5604. height: box.height,
  5605. bez: bez,
  5606. t: (t1 + t2) / 2,
  5607. t1: t1,
  5608. t2: t2
  5609. };
  5610. }
  5611. function splitData(data) {
  5612. var split = data.bez.split(0.5);
  5613. return [intersectData(split[0], data.t1, data.t), intersectData(split[1], data.t, data.t2)];
  5614. }
  5615. function boxIntersect(b1, b2) {
  5616. return Math.abs(b1.cx - b2.cx) * 2 < b1.width + b2.width && Math.abs(b1.cy - b2.cy) * 2 < b1.height + b2.height;
  5617. }
  5618. function intersectsImpl(d1, d2, depth, tolerance, intersections, maxRecursion) {
  5619. if (!boxIntersect(d1, d2)) return;
  5620. if (depth >= maxRecursion || d1.width <= tolerance && d1.height <= tolerance && d2.width <= tolerance && d2.height <= tolerance) {
  5621. intersections.push([d1.t, d2.t]);
  5622. return;
  5623. }
  5624. var d1s = splitData(d1);
  5625. var d2s = splitData(d2);
  5626. intersectsImpl(d1s[0], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5627. intersectsImpl(d1s[0], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5628. intersectsImpl(d1s[1], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5629. intersectsImpl(d1s[1], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5630. }
  5631. PolynomialBezier.prototype.intersections = function (other, tolerance, maxRecursion) {
  5632. if (tolerance === undefined) tolerance = 2;
  5633. if (maxRecursion === undefined) maxRecursion = 7;
  5634. var intersections = [];
  5635. intersectsImpl(intersectData(this, 0, 1), intersectData(other, 0, 1), 0, tolerance, intersections, maxRecursion);
  5636. return intersections;
  5637. };
  5638. PolynomialBezier.shapeSegment = function (shapePath, index) {
  5639. var nextIndex = (index + 1) % shapePath.length();
  5640. return new PolynomialBezier(shapePath.v[index], shapePath.o[index], shapePath.i[nextIndex], shapePath.v[nextIndex], true);
  5641. };
  5642. PolynomialBezier.shapeSegmentInverted = function (shapePath, index) {
  5643. var nextIndex = (index + 1) % shapePath.length();
  5644. return new PolynomialBezier(shapePath.v[nextIndex], shapePath.i[nextIndex], shapePath.o[index], shapePath.v[index], true);
  5645. };
  5646. function crossProduct(a, b) {
  5647. return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
  5648. }
  5649. function lineIntersection(start1, end1, start2, end2) {
  5650. var v1 = [start1[0], start1[1], 1];
  5651. var v2 = [end1[0], end1[1], 1];
  5652. var v3 = [start2[0], start2[1], 1];
  5653. var v4 = [end2[0], end2[1], 1];
  5654. var r = crossProduct(crossProduct(v1, v2), crossProduct(v3, v4));
  5655. if (floatZero(r[2])) return null;
  5656. return [r[0] / r[2], r[1] / r[2]];
  5657. }
  5658. function polarOffset(p, angle, length) {
  5659. return [p[0] + Math.cos(angle) * length, p[1] - Math.sin(angle) * length];
  5660. }
  5661. function pointDistance(p1, p2) {
  5662. return Math.hypot(p1[0] - p2[0], p1[1] - p2[1]);
  5663. }
  5664. function pointEqual(p1, p2) {
  5665. return floatEqual(p1[0], p2[0]) && floatEqual(p1[1], p2[1]);
  5666. }
  5667. function ZigZagModifier() {}
  5668. extendPrototype([ShapeModifier], ZigZagModifier);
  5669. ZigZagModifier.prototype.initModifierProperties = function (elem, data) {
  5670. this.getValue = this.processKeys;
  5671. this.amplitude = PropertyFactory.getProp(elem, data.s, 0, null, this);
  5672. this.frequency = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5673. this.pointsType = PropertyFactory.getProp(elem, data.pt, 0, null, this);
  5674. this._isAnimated = this.amplitude.effectsSequence.length !== 0 || this.frequency.effectsSequence.length !== 0 || this.pointsType.effectsSequence.length !== 0;
  5675. };
  5676. function setPoint(outputBezier, point, angle, direction, amplitude, outAmplitude, inAmplitude) {
  5677. var angO = angle - Math.PI / 2;
  5678. var angI = angle + Math.PI / 2;
  5679. var px = point[0] + Math.cos(angle) * direction * amplitude;
  5680. var py = point[1] - Math.sin(angle) * direction * amplitude;
  5681. outputBezier.setTripleAt(px, py, px + Math.cos(angO) * outAmplitude, py - Math.sin(angO) * outAmplitude, px + Math.cos(angI) * inAmplitude, py - Math.sin(angI) * inAmplitude, outputBezier.length());
  5682. }
  5683. function getPerpendicularVector(pt1, pt2) {
  5684. var vector = [pt2[0] - pt1[0], pt2[1] - pt1[1]];
  5685. var rot = -Math.PI * 0.5;
  5686. var rotatedVector = [Math.cos(rot) * vector[0] - Math.sin(rot) * vector[1], Math.sin(rot) * vector[0] + Math.cos(rot) * vector[1]];
  5687. return rotatedVector;
  5688. }
  5689. function getProjectingAngle(path, cur) {
  5690. var prevIndex = cur === 0 ? path.length() - 1 : cur - 1;
  5691. var nextIndex = (cur + 1) % path.length();
  5692. var prevPoint = path.v[prevIndex];
  5693. var nextPoint = path.v[nextIndex];
  5694. var pVector = getPerpendicularVector(prevPoint, nextPoint);
  5695. return Math.atan2(0, 1) - Math.atan2(pVector[1], pVector[0]);
  5696. }
  5697. function zigZagCorner(outputBezier, path, cur, amplitude, frequency, pointType, direction) {
  5698. var angle = getProjectingAngle(path, cur);
  5699. var point = path.v[cur % path._length];
  5700. var prevPoint = path.v[cur === 0 ? path._length - 1 : cur - 1];
  5701. var nextPoint = path.v[(cur + 1) % path._length];
  5702. var prevDist = pointType === 2 ? Math.sqrt(Math.pow(point[0] - prevPoint[0], 2) + Math.pow(point[1] - prevPoint[1], 2)) : 0;
  5703. var nextDist = pointType === 2 ? Math.sqrt(Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2)) : 0;
  5704. setPoint(outputBezier, path.v[cur % path._length], angle, direction, amplitude, nextDist / ((frequency + 1) * 2), prevDist / ((frequency + 1) * 2), pointType);
  5705. }
  5706. function zigZagSegment(outputBezier, segment, amplitude, frequency, pointType, direction) {
  5707. for (var i = 0; i < frequency; i += 1) {
  5708. var t = (i + 1) / (frequency + 1);
  5709. var dist = pointType === 2 ? Math.sqrt(Math.pow(segment.points[3][0] - segment.points[0][0], 2) + Math.pow(segment.points[3][1] - segment.points[0][1], 2)) : 0;
  5710. var angle = segment.normalAngle(t);
  5711. var point = segment.point(t);
  5712. setPoint(outputBezier, point, angle, direction, amplitude, dist / ((frequency + 1) * 2), dist / ((frequency + 1) * 2), pointType);
  5713. direction = -direction;
  5714. }
  5715. return direction;
  5716. }
  5717. ZigZagModifier.prototype.processPath = function (path, amplitude, frequency, pointType) {
  5718. var count = path._length;
  5719. var clonedPath = shapePool.newElement();
  5720. clonedPath.c = path.c;
  5721. if (!path.c) {
  5722. count -= 1;
  5723. }
  5724. if (count === 0) return clonedPath;
  5725. var direction = -1;
  5726. var segment = PolynomialBezier.shapeSegment(path, 0);
  5727. zigZagCorner(clonedPath, path, 0, amplitude, frequency, pointType, direction);
  5728. for (var i = 0; i < count; i += 1) {
  5729. direction = zigZagSegment(clonedPath, segment, amplitude, frequency, pointType, -direction);
  5730. if (i === count - 1 && !path.c) {
  5731. segment = null;
  5732. } else {
  5733. segment = PolynomialBezier.shapeSegment(path, (i + 1) % count);
  5734. }
  5735. zigZagCorner(clonedPath, path, i + 1, amplitude, frequency, pointType, direction);
  5736. }
  5737. return clonedPath;
  5738. };
  5739. ZigZagModifier.prototype.processShapes = function (_isFirstFrame) {
  5740. var shapePaths;
  5741. var i;
  5742. var len = this.shapes.length;
  5743. var j;
  5744. var jLen;
  5745. var amplitude = this.amplitude.v;
  5746. var frequency = Math.max(0, Math.round(this.frequency.v));
  5747. var pointType = this.pointsType.v;
  5748. if (amplitude !== 0) {
  5749. var shapeData;
  5750. var localShapeCollection;
  5751. for (i = 0; i < len; i += 1) {
  5752. shapeData = this.shapes[i];
  5753. localShapeCollection = shapeData.localShapeCollection;
  5754. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5755. localShapeCollection.releaseShapes();
  5756. shapeData.shape._mdf = true;
  5757. shapePaths = shapeData.shape.paths.shapes;
  5758. jLen = shapeData.shape.paths._length;
  5759. for (j = 0; j < jLen; j += 1) {
  5760. localShapeCollection.addShape(this.processPath(shapePaths[j], amplitude, frequency, pointType));
  5761. }
  5762. }
  5763. shapeData.shape.paths = shapeData.localShapeCollection;
  5764. }
  5765. }
  5766. if (!this.dynamicProperties.length) {
  5767. this._mdf = false;
  5768. }
  5769. };
  5770. function linearOffset(p1, p2, amount) {
  5771. var angle = Math.atan2(p2[0] - p1[0], p2[1] - p1[1]);
  5772. return [polarOffset(p1, angle, amount), polarOffset(p2, angle, amount)];
  5773. }
  5774. function offsetSegment(segment, amount) {
  5775. var p0;
  5776. var p1a;
  5777. var p1b;
  5778. var p2b;
  5779. var p2a;
  5780. var p3;
  5781. var e;
  5782. e = linearOffset(segment.points[0], segment.points[1], amount);
  5783. p0 = e[0];
  5784. p1a = e[1];
  5785. e = linearOffset(segment.points[1], segment.points[2], amount);
  5786. p1b = e[0];
  5787. p2b = e[1];
  5788. e = linearOffset(segment.points[2], segment.points[3], amount);
  5789. p2a = e[0];
  5790. p3 = e[1];
  5791. var p1 = lineIntersection(p0, p1a, p1b, p2b);
  5792. if (p1 === null) p1 = p1a;
  5793. var p2 = lineIntersection(p2a, p3, p1b, p2b);
  5794. if (p2 === null) p2 = p2a;
  5795. return new PolynomialBezier(p0, p1, p2, p3);
  5796. }
  5797. function joinLines(outputBezier, seg1, seg2, lineJoin, miterLimit) {
  5798. var p0 = seg1.points[3];
  5799. var p1 = seg2.points[0];
  5800. // Bevel
  5801. if (lineJoin === 3) return p0;
  5802. // Connected, they don't need a joint
  5803. if (pointEqual(p0, p1)) return p0;
  5804. // Round
  5805. if (lineJoin === 2) {
  5806. var angleOut = -seg1.tangentAngle(1);
  5807. var angleIn = -seg2.tangentAngle(0) + Math.PI;
  5808. var center = lineIntersection(p0, polarOffset(p0, angleOut + Math.PI / 2, 100), p1, polarOffset(p1, angleOut + Math.PI / 2, 100));
  5809. var radius = center ? pointDistance(center, p0) : pointDistance(p0, p1) / 2;
  5810. var tan = polarOffset(p0, angleOut, 2 * radius * roundCorner);
  5811. outputBezier.setXYAt(tan[0], tan[1], 'o', outputBezier.length() - 1);
  5812. tan = polarOffset(p1, angleIn, 2 * radius * roundCorner);
  5813. outputBezier.setTripleAt(p1[0], p1[1], p1[0], p1[1], tan[0], tan[1], outputBezier.length());
  5814. return p1;
  5815. }
  5816. // Miter
  5817. var t0 = pointEqual(p0, seg1.points[2]) ? seg1.points[0] : seg1.points[2];
  5818. var t1 = pointEqual(p1, seg2.points[1]) ? seg2.points[3] : seg2.points[1];
  5819. var intersection = lineIntersection(t0, p0, p1, t1);
  5820. if (intersection && pointDistance(intersection, p0) < miterLimit) {
  5821. outputBezier.setTripleAt(intersection[0], intersection[1], intersection[0], intersection[1], intersection[0], intersection[1], outputBezier.length());
  5822. return intersection;
  5823. }
  5824. return p0;
  5825. }
  5826. function getIntersection(a, b) {
  5827. var intersect = a.intersections(b);
  5828. if (intersect.length && floatEqual(intersect[0][0], 1)) intersect.shift();
  5829. if (intersect.length) return intersect[0];
  5830. return null;
  5831. }
  5832. function pruneSegmentIntersection(a, b) {
  5833. var outa = a.slice();
  5834. var outb = b.slice();
  5835. var intersect = getIntersection(a[a.length - 1], b[0]);
  5836. if (intersect) {
  5837. outa[a.length - 1] = a[a.length - 1].split(intersect[0])[0];
  5838. outb[0] = b[0].split(intersect[1])[1];
  5839. }
  5840. if (a.length > 1 && b.length > 1) {
  5841. intersect = getIntersection(a[0], b[b.length - 1]);
  5842. if (intersect) {
  5843. return [[a[0].split(intersect[0])[0]], [b[b.length - 1].split(intersect[1])[1]]];
  5844. }
  5845. }
  5846. return [outa, outb];
  5847. }
  5848. function pruneIntersections(segments) {
  5849. var e;
  5850. for (var i = 1; i < segments.length; i += 1) {
  5851. e = pruneSegmentIntersection(segments[i - 1], segments[i]);
  5852. segments[i - 1] = e[0];
  5853. segments[i] = e[1];
  5854. }
  5855. if (segments.length > 1) {
  5856. e = pruneSegmentIntersection(segments[segments.length - 1], segments[0]);
  5857. segments[segments.length - 1] = e[0];
  5858. segments[0] = e[1];
  5859. }
  5860. return segments;
  5861. }
  5862. function offsetSegmentSplit(segment, amount) {
  5863. /*
  5864. We split each bezier segment into smaller pieces based
  5865. on inflection points, this ensures the control point
  5866. polygon is convex.
  5867. (A cubic bezier can have none, one, or two inflection points)
  5868. */
  5869. var flex = segment.inflectionPoints();
  5870. var left;
  5871. var right;
  5872. var split;
  5873. var mid;
  5874. if (flex.length === 0) {
  5875. return [offsetSegment(segment, amount)];
  5876. }
  5877. if (flex.length === 1 || floatEqual(flex[1], 1)) {
  5878. split = segment.split(flex[0]);
  5879. left = split[0];
  5880. right = split[1];
  5881. return [offsetSegment(left, amount), offsetSegment(right, amount)];
  5882. }
  5883. split = segment.split(flex[0]);
  5884. left = split[0];
  5885. var t = (flex[1] - flex[0]) / (1 - flex[0]);
  5886. split = split[1].split(t);
  5887. mid = split[0];
  5888. right = split[1];
  5889. return [offsetSegment(left, amount), offsetSegment(mid, amount), offsetSegment(right, amount)];
  5890. }
  5891. function OffsetPathModifier() {}
  5892. extendPrototype([ShapeModifier], OffsetPathModifier);
  5893. OffsetPathModifier.prototype.initModifierProperties = function (elem, data) {
  5894. this.getValue = this.processKeys;
  5895. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  5896. this.miterLimit = PropertyFactory.getProp(elem, data.ml, 0, null, this);
  5897. this.lineJoin = data.lj;
  5898. this._isAnimated = this.amount.effectsSequence.length !== 0;
  5899. };
  5900. OffsetPathModifier.prototype.processPath = function (inputBezier, amount, lineJoin, miterLimit) {
  5901. var outputBezier = shapePool.newElement();
  5902. outputBezier.c = inputBezier.c;
  5903. var count = inputBezier.length();
  5904. if (!inputBezier.c) {
  5905. count -= 1;
  5906. }
  5907. var i;
  5908. var j;
  5909. var segment;
  5910. var multiSegments = [];
  5911. for (i = 0; i < count; i += 1) {
  5912. segment = PolynomialBezier.shapeSegment(inputBezier, i);
  5913. multiSegments.push(offsetSegmentSplit(segment, amount));
  5914. }
  5915. if (!inputBezier.c) {
  5916. for (i = count - 1; i >= 0; i -= 1) {
  5917. segment = PolynomialBezier.shapeSegmentInverted(inputBezier, i);
  5918. multiSegments.push(offsetSegmentSplit(segment, amount));
  5919. }
  5920. }
  5921. multiSegments = pruneIntersections(multiSegments);
  5922. // Add bezier segments to the output and apply line joints
  5923. var lastPoint = null;
  5924. var lastSeg = null;
  5925. for (i = 0; i < multiSegments.length; i += 1) {
  5926. var multiSegment = multiSegments[i];
  5927. if (lastSeg) lastPoint = joinLines(outputBezier, lastSeg, multiSegment[0], lineJoin, miterLimit);
  5928. lastSeg = multiSegment[multiSegment.length - 1];
  5929. for (j = 0; j < multiSegment.length; j += 1) {
  5930. segment = multiSegment[j];
  5931. if (lastPoint && pointEqual(segment.points[0], lastPoint)) {
  5932. outputBezier.setXYAt(segment.points[1][0], segment.points[1][1], 'o', outputBezier.length() - 1);
  5933. } else {
  5934. outputBezier.setTripleAt(segment.points[0][0], segment.points[0][1], segment.points[1][0], segment.points[1][1], segment.points[0][0], segment.points[0][1], outputBezier.length());
  5935. }
  5936. outputBezier.setTripleAt(segment.points[3][0], segment.points[3][1], segment.points[3][0], segment.points[3][1], segment.points[2][0], segment.points[2][1], outputBezier.length());
  5937. lastPoint = segment.points[3];
  5938. }
  5939. }
  5940. if (multiSegments.length) joinLines(outputBezier, lastSeg, multiSegments[0][0], lineJoin, miterLimit);
  5941. return outputBezier;
  5942. };
  5943. OffsetPathModifier.prototype.processShapes = function (_isFirstFrame) {
  5944. var shapePaths;
  5945. var i;
  5946. var len = this.shapes.length;
  5947. var j;
  5948. var jLen;
  5949. var amount = this.amount.v;
  5950. var miterLimit = this.miterLimit.v;
  5951. var lineJoin = this.lineJoin;
  5952. if (amount !== 0) {
  5953. var shapeData;
  5954. var localShapeCollection;
  5955. for (i = 0; i < len; i += 1) {
  5956. shapeData = this.shapes[i];
  5957. localShapeCollection = shapeData.localShapeCollection;
  5958. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5959. localShapeCollection.releaseShapes();
  5960. shapeData.shape._mdf = true;
  5961. shapePaths = shapeData.shape.paths.shapes;
  5962. jLen = shapeData.shape.paths._length;
  5963. for (j = 0; j < jLen; j += 1) {
  5964. localShapeCollection.addShape(this.processPath(shapePaths[j], amount, lineJoin, miterLimit));
  5965. }
  5966. }
  5967. shapeData.shape.paths = shapeData.localShapeCollection;
  5968. }
  5969. }
  5970. if (!this.dynamicProperties.length) {
  5971. this._mdf = false;
  5972. }
  5973. };
  5974. function getFontProperties(fontData) {
  5975. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  5976. var fWeight = 'normal';
  5977. var fStyle = 'normal';
  5978. var len = styles.length;
  5979. var styleName;
  5980. for (var i = 0; i < len; i += 1) {
  5981. styleName = styles[i].toLowerCase();
  5982. switch (styleName) {
  5983. case 'italic':
  5984. fStyle = 'italic';
  5985. break;
  5986. case 'bold':
  5987. fWeight = '700';
  5988. break;
  5989. case 'black':
  5990. fWeight = '900';
  5991. break;
  5992. case 'medium':
  5993. fWeight = '500';
  5994. break;
  5995. case 'regular':
  5996. case 'normal':
  5997. fWeight = '400';
  5998. break;
  5999. case 'light':
  6000. case 'thin':
  6001. fWeight = '200';
  6002. break;
  6003. default:
  6004. break;
  6005. }
  6006. }
  6007. return {
  6008. style: fStyle,
  6009. weight: fontData.fWeight || fWeight
  6010. };
  6011. }
  6012. var FontManager = function () {
  6013. var maxWaitingTime = 5000;
  6014. var emptyChar = {
  6015. w: 0,
  6016. size: 0,
  6017. shapes: [],
  6018. data: {
  6019. shapes: []
  6020. }
  6021. };
  6022. var combinedCharacters = [];
  6023. // Hindi characters
  6024. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366, 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379, 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  6025. var BLACK_FLAG_CODE_POINT = 127988;
  6026. var CANCEL_TAG_CODE_POINT = 917631;
  6027. var A_TAG_CODE_POINT = 917601;
  6028. var Z_TAG_CODE_POINT = 917626;
  6029. var VARIATION_SELECTOR_16_CODE_POINT = 65039;
  6030. var ZERO_WIDTH_JOINER_CODE_POINT = 8205;
  6031. var REGIONAL_CHARACTER_A_CODE_POINT = 127462;
  6032. var REGIONAL_CHARACTER_Z_CODE_POINT = 127487;
  6033. var surrogateModifiers = ['d83cdffb', 'd83cdffc', 'd83cdffd', 'd83cdffe', 'd83cdfff'];
  6034. function trimFontOptions(font) {
  6035. var familyArray = font.split(',');
  6036. var i;
  6037. var len = familyArray.length;
  6038. var enabledFamilies = [];
  6039. for (i = 0; i < len; i += 1) {
  6040. if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
  6041. enabledFamilies.push(familyArray[i]);
  6042. }
  6043. }
  6044. return enabledFamilies.join(',');
  6045. }
  6046. function setUpNode(font, family) {
  6047. var parentNode = createTag('span');
  6048. // Node is invisible to screen readers.
  6049. parentNode.setAttribute('aria-hidden', true);
  6050. parentNode.style.fontFamily = family;
  6051. var node = createTag('span');
  6052. // Characters that vary significantly among different fonts
  6053. node.innerText = 'giItT1WQy@!-/#';
  6054. // Visible - so we can measure it - but not on the screen
  6055. parentNode.style.position = 'absolute';
  6056. parentNode.style.left = '-10000px';
  6057. parentNode.style.top = '-10000px';
  6058. // Large font size makes even subtle changes obvious
  6059. parentNode.style.fontSize = '300px';
  6060. // Reset any font properties
  6061. parentNode.style.fontVariant = 'normal';
  6062. parentNode.style.fontStyle = 'normal';
  6063. parentNode.style.fontWeight = 'normal';
  6064. parentNode.style.letterSpacing = '0';
  6065. parentNode.appendChild(node);
  6066. document.body.appendChild(parentNode);
  6067. // Remember width with no applied web font
  6068. var width = node.offsetWidth;
  6069. node.style.fontFamily = trimFontOptions(font) + ', ' + family;
  6070. return {
  6071. node: node,
  6072. w: width,
  6073. parent: parentNode
  6074. };
  6075. }
  6076. function checkLoadedFonts() {
  6077. var i;
  6078. var len = this.fonts.length;
  6079. var node;
  6080. var w;
  6081. var loadedCount = len;
  6082. for (i = 0; i < len; i += 1) {
  6083. if (this.fonts[i].loaded) {
  6084. loadedCount -= 1;
  6085. } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) {
  6086. this.fonts[i].loaded = true;
  6087. } else {
  6088. node = this.fonts[i].monoCase.node;
  6089. w = this.fonts[i].monoCase.w;
  6090. if (node.offsetWidth !== w) {
  6091. loadedCount -= 1;
  6092. this.fonts[i].loaded = true;
  6093. } else {
  6094. node = this.fonts[i].sansCase.node;
  6095. w = this.fonts[i].sansCase.w;
  6096. if (node.offsetWidth !== w) {
  6097. loadedCount -= 1;
  6098. this.fonts[i].loaded = true;
  6099. }
  6100. }
  6101. if (this.fonts[i].loaded) {
  6102. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  6103. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  6104. }
  6105. }
  6106. }
  6107. if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) {
  6108. setTimeout(this.checkLoadedFontsBinded, 20);
  6109. } else {
  6110. setTimeout(this.setIsLoadedBinded, 10);
  6111. }
  6112. }
  6113. function createHelper(fontData, def) {
  6114. var engine = document.body && def ? 'svg' : 'canvas';
  6115. var helper;
  6116. var fontProps = getFontProperties(fontData);
  6117. if (engine === 'svg') {
  6118. var tHelper = createNS('text');
  6119. tHelper.style.fontSize = '100px';
  6120. // tHelper.style.fontFamily = fontData.fFamily;
  6121. tHelper.setAttribute('font-family', fontData.fFamily);
  6122. tHelper.setAttribute('font-style', fontProps.style);
  6123. tHelper.setAttribute('font-weight', fontProps.weight);
  6124. tHelper.textContent = '1';
  6125. if (fontData.fClass) {
  6126. tHelper.style.fontFamily = 'inherit';
  6127. tHelper.setAttribute('class', fontData.fClass);
  6128. } else {
  6129. tHelper.style.fontFamily = fontData.fFamily;
  6130. }
  6131. def.appendChild(tHelper);
  6132. helper = tHelper;
  6133. } else {
  6134. var tCanvasHelper = new OffscreenCanvas(500, 500).getContext('2d');
  6135. tCanvasHelper.font = fontProps.style + ' ' + fontProps.weight + ' 100px ' + fontData.fFamily;
  6136. helper = tCanvasHelper;
  6137. }
  6138. function measure(text) {
  6139. if (engine === 'svg') {
  6140. helper.textContent = text;
  6141. return helper.getComputedTextLength();
  6142. }
  6143. return helper.measureText(text).width;
  6144. }
  6145. return {
  6146. measureText: measure
  6147. };
  6148. }
  6149. function addFonts(fontData, defs) {
  6150. if (!fontData) {
  6151. this.isLoaded = true;
  6152. return;
  6153. }
  6154. if (this.chars) {
  6155. this.isLoaded = true;
  6156. this.fonts = fontData.list;
  6157. return;
  6158. }
  6159. if (!document.body) {
  6160. this.isLoaded = true;
  6161. fontData.list.forEach(function (data) {
  6162. data.helper = createHelper(data);
  6163. data.cache = {};
  6164. });
  6165. this.fonts = fontData.list;
  6166. return;
  6167. }
  6168. var fontArr = fontData.list;
  6169. var i;
  6170. var len = fontArr.length;
  6171. var _pendingFonts = len;
  6172. for (i = 0; i < len; i += 1) {
  6173. var shouldLoadFont = true;
  6174. var loadedSelector;
  6175. var j;
  6176. fontArr[i].loaded = false;
  6177. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace');
  6178. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif');
  6179. if (!fontArr[i].fPath) {
  6180. fontArr[i].loaded = true;
  6181. _pendingFonts -= 1;
  6182. } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) {
  6183. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]');
  6184. if (loadedSelector.length > 0) {
  6185. shouldLoadFont = false;
  6186. }
  6187. if (shouldLoadFont) {
  6188. var s = createTag('style');
  6189. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  6190. s.setAttribute('f-origin', fontArr[i].origin);
  6191. s.setAttribute('f-family', fontArr[i].fFamily);
  6192. s.type = 'text/css';
  6193. s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}";
  6194. defs.appendChild(s);
  6195. }
  6196. } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) {
  6197. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  6198. for (j = 0; j < loadedSelector.length; j += 1) {
  6199. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  6200. // Font is already loaded
  6201. shouldLoadFont = false;
  6202. }
  6203. }
  6204. if (shouldLoadFont) {
  6205. var l = createTag('link');
  6206. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  6207. l.setAttribute('f-origin', fontArr[i].origin);
  6208. l.type = 'text/css';
  6209. l.rel = 'stylesheet';
  6210. l.href = fontArr[i].fPath;
  6211. document.body.appendChild(l);
  6212. }
  6213. } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) {
  6214. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  6215. for (j = 0; j < loadedSelector.length; j += 1) {
  6216. if (fontArr[i].fPath === loadedSelector[j].src) {
  6217. // Font is already loaded
  6218. shouldLoadFont = false;
  6219. }
  6220. }
  6221. if (shouldLoadFont) {
  6222. var sc = createTag('link');
  6223. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  6224. sc.setAttribute('f-origin', fontArr[i].origin);
  6225. sc.setAttribute('rel', 'stylesheet');
  6226. sc.setAttribute('href', fontArr[i].fPath);
  6227. defs.appendChild(sc);
  6228. }
  6229. }
  6230. fontArr[i].helper = createHelper(fontArr[i], defs);
  6231. fontArr[i].cache = {};
  6232. this.fonts.push(fontArr[i]);
  6233. }
  6234. if (_pendingFonts === 0) {
  6235. this.isLoaded = true;
  6236. } else {
  6237. // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  6238. // Adding this timeout seems to fix it
  6239. setTimeout(this.checkLoadedFonts.bind(this), 100);
  6240. }
  6241. }
  6242. function addChars(chars) {
  6243. if (!chars) {
  6244. return;
  6245. }
  6246. if (!this.chars) {
  6247. this.chars = [];
  6248. }
  6249. var i;
  6250. var len = chars.length;
  6251. var j;
  6252. var jLen = this.chars.length;
  6253. var found;
  6254. for (i = 0; i < len; i += 1) {
  6255. j = 0;
  6256. found = false;
  6257. while (j < jLen) {
  6258. if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) {
  6259. found = true;
  6260. }
  6261. j += 1;
  6262. }
  6263. if (!found) {
  6264. this.chars.push(chars[i]);
  6265. jLen += 1;
  6266. }
  6267. }
  6268. }
  6269. function getCharData(_char, style, font) {
  6270. var i = 0;
  6271. var len = this.chars.length;
  6272. while (i < len) {
  6273. if (this.chars[i].ch === _char && this.chars[i].style === style && this.chars[i].fFamily === font) {
  6274. return this.chars[i];
  6275. }
  6276. i += 1;
  6277. }
  6278. if ((typeof _char === 'string' && _char.charCodeAt(0) !== 13 || !_char) && console && console.warn // eslint-disable-line no-console
  6279. && !this._warned) {
  6280. this._warned = true;
  6281. console.warn('Missing character from exported characters list: ', _char, style, font); // eslint-disable-line no-console
  6282. }
  6283. return emptyChar;
  6284. }
  6285. function measureText(_char2, fontName, size) {
  6286. var fontData = this.getFontByName(fontName);
  6287. // Using the char instead of char.charCodeAt(0)
  6288. // to avoid collisions between equal chars
  6289. var index = _char2;
  6290. if (!fontData.cache[index]) {
  6291. var tHelper = fontData.helper;
  6292. if (_char2 === ' ') {
  6293. var doubleSize = tHelper.measureText('|' + _char2 + '|');
  6294. var singleSize = tHelper.measureText('||');
  6295. fontData.cache[index] = (doubleSize - singleSize) / 100;
  6296. } else {
  6297. fontData.cache[index] = tHelper.measureText(_char2) / 100;
  6298. }
  6299. }
  6300. return fontData.cache[index] * size;
  6301. }
  6302. function getFontByName(name) {
  6303. var i = 0;
  6304. var len = this.fonts.length;
  6305. while (i < len) {
  6306. if (this.fonts[i].fName === name) {
  6307. return this.fonts[i];
  6308. }
  6309. i += 1;
  6310. }
  6311. return this.fonts[0];
  6312. }
  6313. function getCodePoint(string) {
  6314. var codePoint = 0;
  6315. var first = string.charCodeAt(0);
  6316. if (first >= 0xD800 && first <= 0xDBFF) {
  6317. var second = string.charCodeAt(1);
  6318. if (second >= 0xDC00 && second <= 0xDFFF) {
  6319. codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  6320. }
  6321. }
  6322. return codePoint;
  6323. }
  6324. // Skin tone modifiers
  6325. function isModifier(firstCharCode, secondCharCode) {
  6326. var sum = firstCharCode.toString(16) + secondCharCode.toString(16);
  6327. return surrogateModifiers.indexOf(sum) !== -1;
  6328. }
  6329. function isZeroWidthJoiner(charCode) {
  6330. return charCode === ZERO_WIDTH_JOINER_CODE_POINT;
  6331. }
  6332. // This codepoint may change the appearance of the preceding character.
  6333. // If that is a symbol, dingbat or emoji, U+FE0F forces it to be rendered
  6334. // as a colorful image as compared to a monochrome text variant.
  6335. function isVariationSelector(charCode) {
  6336. return charCode === VARIATION_SELECTOR_16_CODE_POINT;
  6337. }
  6338. // The regional indicator symbols are a set of 26 alphabetic Unicode
  6339. /// characters (A–Z) intended to be used to encode ISO 3166-1 alpha-2
  6340. // two-letter country codes in a way that allows optional special treatment.
  6341. function isRegionalCode(string) {
  6342. var codePoint = getCodePoint(string);
  6343. if (codePoint >= REGIONAL_CHARACTER_A_CODE_POINT && codePoint <= REGIONAL_CHARACTER_Z_CODE_POINT) {
  6344. return true;
  6345. }
  6346. return false;
  6347. }
  6348. // Some Emoji implementations represent combinations of
  6349. // two “regional indicator” letters as a single flag symbol.
  6350. function isFlagEmoji(string) {
  6351. return isRegionalCode(string.substr(0, 2)) && isRegionalCode(string.substr(2, 2));
  6352. }
  6353. function isCombinedCharacter(_char3) {
  6354. return combinedCharacters.indexOf(_char3) !== -1;
  6355. }
  6356. // Regional flags start with a BLACK_FLAG_CODE_POINT
  6357. // folowed by 5 chars in the TAG range
  6358. // and end with a CANCEL_TAG_CODE_POINT
  6359. function isRegionalFlag(text, index) {
  6360. var codePoint = getCodePoint(text.substr(index, 2));
  6361. if (codePoint !== BLACK_FLAG_CODE_POINT) {
  6362. return false;
  6363. }
  6364. var count = 0;
  6365. index += 2;
  6366. while (count < 5) {
  6367. codePoint = getCodePoint(text.substr(index, 2));
  6368. if (codePoint < A_TAG_CODE_POINT || codePoint > Z_TAG_CODE_POINT) {
  6369. return false;
  6370. }
  6371. count += 1;
  6372. index += 2;
  6373. }
  6374. return getCodePoint(text.substr(index, 2)) === CANCEL_TAG_CODE_POINT;
  6375. }
  6376. function setIsLoaded() {
  6377. this.isLoaded = true;
  6378. }
  6379. var Font = function Font() {
  6380. this.fonts = [];
  6381. this.chars = null;
  6382. this.typekitLoaded = 0;
  6383. this.isLoaded = false;
  6384. this._warned = false;
  6385. this.initTime = Date.now();
  6386. this.setIsLoadedBinded = this.setIsLoaded.bind(this);
  6387. this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this);
  6388. };
  6389. Font.isModifier = isModifier;
  6390. Font.isZeroWidthJoiner = isZeroWidthJoiner;
  6391. Font.isFlagEmoji = isFlagEmoji;
  6392. Font.isRegionalCode = isRegionalCode;
  6393. Font.isCombinedCharacter = isCombinedCharacter;
  6394. Font.isRegionalFlag = isRegionalFlag;
  6395. Font.isVariationSelector = isVariationSelector;
  6396. Font.BLACK_FLAG_CODE_POINT = BLACK_FLAG_CODE_POINT;
  6397. var fontPrototype = {
  6398. addChars: addChars,
  6399. addFonts: addFonts,
  6400. getCharData: getCharData,
  6401. getFontByName: getFontByName,
  6402. measureText: measureText,
  6403. checkLoadedFonts: checkLoadedFonts,
  6404. setIsLoaded: setIsLoaded
  6405. };
  6406. Font.prototype = fontPrototype;
  6407. return Font;
  6408. }();
  6409. function SlotManager(animationData) {
  6410. this.animationData = animationData;
  6411. }
  6412. SlotManager.prototype.getProp = function (data) {
  6413. if (this.animationData.slots && this.animationData.slots[data.sid]) {
  6414. return Object.assign(data, this.animationData.slots[data.sid].p);
  6415. }
  6416. return data;
  6417. };
  6418. function slotFactory(animationData) {
  6419. return new SlotManager(animationData);
  6420. }
  6421. function RenderableElement() {}
  6422. RenderableElement.prototype = {
  6423. initRenderable: function initRenderable() {
  6424. // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6425. this.isInRange = false;
  6426. // layer's display state
  6427. this.hidden = false;
  6428. // If layer's transparency equals 0, it can be hidden
  6429. this.isTransparent = false;
  6430. // list of animated components
  6431. this.renderableComponents = [];
  6432. },
  6433. addRenderableComponent: function addRenderableComponent(component) {
  6434. if (this.renderableComponents.indexOf(component) === -1) {
  6435. this.renderableComponents.push(component);
  6436. }
  6437. },
  6438. removeRenderableComponent: function removeRenderableComponent(component) {
  6439. if (this.renderableComponents.indexOf(component) !== -1) {
  6440. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  6441. }
  6442. },
  6443. prepareRenderableFrame: function prepareRenderableFrame(num) {
  6444. this.checkLayerLimits(num);
  6445. },
  6446. checkTransparency: function checkTransparency() {
  6447. if (this.finalTransform.mProp.o.v <= 0) {
  6448. if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
  6449. this.isTransparent = true;
  6450. this.hide();
  6451. }
  6452. } else if (this.isTransparent) {
  6453. this.isTransparent = false;
  6454. this.show();
  6455. }
  6456. },
  6457. /**
  6458. * @function
  6459. * Initializes frame related properties.
  6460. *
  6461. * @param {number} num
  6462. * current frame number in Layer's time
  6463. *
  6464. */
  6465. checkLayerLimits: function checkLayerLimits(num) {
  6466. if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
  6467. if (this.isInRange !== true) {
  6468. this.globalData._mdf = true;
  6469. this._mdf = true;
  6470. this.isInRange = true;
  6471. this.show();
  6472. }
  6473. } else if (this.isInRange !== false) {
  6474. this.globalData._mdf = true;
  6475. this.isInRange = false;
  6476. this.hide();
  6477. }
  6478. },
  6479. renderRenderable: function renderRenderable() {
  6480. var i;
  6481. var len = this.renderableComponents.length;
  6482. for (i = 0; i < len; i += 1) {
  6483. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  6484. }
  6485. /* this.maskManager.renderFrame(this.finalTransform.mat);
  6486. this.renderableEffectsManager.renderFrame(this._isFirstFrame); */
  6487. },
  6488. sourceRectAtTime: function sourceRectAtTime() {
  6489. return {
  6490. top: 0,
  6491. left: 0,
  6492. width: 100,
  6493. height: 100
  6494. };
  6495. },
  6496. getLayerSize: function getLayerSize() {
  6497. if (this.data.ty === 5) {
  6498. return {
  6499. w: this.data.textData.width,
  6500. h: this.data.textData.height
  6501. };
  6502. }
  6503. return {
  6504. w: this.data.width,
  6505. h: this.data.height
  6506. };
  6507. }
  6508. };
  6509. var getBlendMode = function () {
  6510. var blendModeEnums = {
  6511. 0: 'source-over',
  6512. 1: 'multiply',
  6513. 2: 'screen',
  6514. 3: 'overlay',
  6515. 4: 'darken',
  6516. 5: 'lighten',
  6517. 6: 'color-dodge',
  6518. 7: 'color-burn',
  6519. 8: 'hard-light',
  6520. 9: 'soft-light',
  6521. 10: 'difference',
  6522. 11: 'exclusion',
  6523. 12: 'hue',
  6524. 13: 'saturation',
  6525. 14: 'color',
  6526. 15: 'luminosity'
  6527. };
  6528. return function (mode) {
  6529. return blendModeEnums[mode] || '';
  6530. };
  6531. }();
  6532. function SliderEffect(data, elem, container) {
  6533. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6534. }
  6535. function AngleEffect(data, elem, container) {
  6536. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6537. }
  6538. function ColorEffect(data, elem, container) {
  6539. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6540. }
  6541. function PointEffect(data, elem, container) {
  6542. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6543. }
  6544. function LayerIndexEffect(data, elem, container) {
  6545. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6546. }
  6547. function MaskIndexEffect(data, elem, container) {
  6548. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6549. }
  6550. function CheckboxEffect(data, elem, container) {
  6551. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6552. }
  6553. function NoValueEffect() {
  6554. this.p = {};
  6555. }
  6556. function EffectsManager(data, element) {
  6557. var effects = data.ef || [];
  6558. this.effectElements = [];
  6559. var i;
  6560. var len = effects.length;
  6561. var effectItem;
  6562. for (i = 0; i < len; i += 1) {
  6563. effectItem = new GroupEffect(effects[i], element);
  6564. this.effectElements.push(effectItem);
  6565. }
  6566. }
  6567. function GroupEffect(data, element) {
  6568. this.init(data, element);
  6569. }
  6570. extendPrototype([DynamicPropertyContainer], GroupEffect);
  6571. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  6572. GroupEffect.prototype.init = function (data, element) {
  6573. this.data = data;
  6574. this.effectElements = [];
  6575. this.initDynamicPropertyContainer(element);
  6576. var i;
  6577. var len = this.data.ef.length;
  6578. var eff;
  6579. var effects = this.data.ef;
  6580. for (i = 0; i < len; i += 1) {
  6581. eff = null;
  6582. switch (effects[i].ty) {
  6583. case 0:
  6584. eff = new SliderEffect(effects[i], element, this);
  6585. break;
  6586. case 1:
  6587. eff = new AngleEffect(effects[i], element, this);
  6588. break;
  6589. case 2:
  6590. eff = new ColorEffect(effects[i], element, this);
  6591. break;
  6592. case 3:
  6593. eff = new PointEffect(effects[i], element, this);
  6594. break;
  6595. case 4:
  6596. case 7:
  6597. eff = new CheckboxEffect(effects[i], element, this);
  6598. break;
  6599. case 10:
  6600. eff = new LayerIndexEffect(effects[i], element, this);
  6601. break;
  6602. case 11:
  6603. eff = new MaskIndexEffect(effects[i], element, this);
  6604. break;
  6605. case 5:
  6606. eff = new EffectsManager(effects[i], element, this);
  6607. break;
  6608. // case 6:
  6609. default:
  6610. eff = new NoValueEffect(effects[i], element, this);
  6611. break;
  6612. }
  6613. if (eff) {
  6614. this.effectElements.push(eff);
  6615. }
  6616. }
  6617. };
  6618. function BaseElement() {}
  6619. BaseElement.prototype = {
  6620. checkMasks: function checkMasks() {
  6621. if (!this.data.hasMask) {
  6622. return false;
  6623. }
  6624. var i = 0;
  6625. var len = this.data.masksProperties.length;
  6626. while (i < len) {
  6627. if (this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false) {
  6628. return true;
  6629. }
  6630. i += 1;
  6631. }
  6632. return false;
  6633. },
  6634. initExpressions: function initExpressions() {
  6635. var expressionsInterfaces = getExpressionInterfaces();
  6636. if (!expressionsInterfaces) {
  6637. return;
  6638. }
  6639. var LayerExpressionInterface = expressionsInterfaces('layer');
  6640. var EffectsExpressionInterface = expressionsInterfaces('effects');
  6641. var ShapeExpressionInterface = expressionsInterfaces('shape');
  6642. var TextExpressionInterface = expressionsInterfaces('text');
  6643. var CompExpressionInterface = expressionsInterfaces('comp');
  6644. this.layerInterface = LayerExpressionInterface(this);
  6645. if (this.data.hasMask && this.maskManager) {
  6646. this.layerInterface.registerMaskInterface(this.maskManager);
  6647. }
  6648. var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this, this.layerInterface);
  6649. this.layerInterface.registerEffectsInterface(effectsInterface);
  6650. if (this.data.ty === 0 || this.data.xt) {
  6651. this.compInterface = CompExpressionInterface(this);
  6652. } else if (this.data.ty === 4) {
  6653. this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface);
  6654. this.layerInterface.content = this.layerInterface.shapeInterface;
  6655. } else if (this.data.ty === 5) {
  6656. this.layerInterface.textInterface = TextExpressionInterface(this);
  6657. this.layerInterface.text = this.layerInterface.textInterface;
  6658. }
  6659. },
  6660. setBlendMode: function setBlendMode() {
  6661. var blendModeValue = getBlendMode(this.data.bm);
  6662. var elem = this.baseElement || this.layerElement;
  6663. elem.style['mix-blend-mode'] = blendModeValue;
  6664. },
  6665. initBaseData: function initBaseData(data, globalData, comp) {
  6666. this.globalData = globalData;
  6667. this.comp = comp;
  6668. this.data = data;
  6669. this.layerId = createElementID();
  6670. // Stretch factor for old animations missing this property.
  6671. if (!this.data.sr) {
  6672. this.data.sr = 1;
  6673. }
  6674. // effects manager
  6675. this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties);
  6676. },
  6677. getType: function getType() {
  6678. return this.type;
  6679. },
  6680. sourceRectAtTime: function sourceRectAtTime() {}
  6681. };
  6682. /**
  6683. * @file
  6684. * Handles element's layer frame update.
  6685. * Checks layer in point and out point
  6686. *
  6687. */
  6688. function FrameElement() {}
  6689. FrameElement.prototype = {
  6690. /**
  6691. * @function
  6692. * Initializes frame related properties.
  6693. *
  6694. */
  6695. initFrame: function initFrame() {
  6696. // set to true when inpoint is rendered
  6697. this._isFirstFrame = false;
  6698. // list of animated properties
  6699. this.dynamicProperties = [];
  6700. // If layer has been modified in current tick this will be true
  6701. this._mdf = false;
  6702. },
  6703. /**
  6704. * @function
  6705. * Calculates all dynamic values
  6706. *
  6707. * @param {number} num
  6708. * current frame number in Layer's time
  6709. * @param {boolean} isVisible
  6710. * if layers is currently in range
  6711. *
  6712. */
  6713. prepareProperties: function prepareProperties(num, isVisible) {
  6714. var i;
  6715. var len = this.dynamicProperties.length;
  6716. for (i = 0; i < len; i += 1) {
  6717. if (isVisible || this._isParent && this.dynamicProperties[i].propType === 'transform') {
  6718. this.dynamicProperties[i].getValue();
  6719. if (this.dynamicProperties[i]._mdf) {
  6720. this.globalData._mdf = true;
  6721. this._mdf = true;
  6722. }
  6723. }
  6724. }
  6725. },
  6726. addDynamicProperty: function addDynamicProperty(prop) {
  6727. if (this.dynamicProperties.indexOf(prop) === -1) {
  6728. this.dynamicProperties.push(prop);
  6729. }
  6730. }
  6731. };
  6732. function FootageElement(data, globalData, comp) {
  6733. this.initFrame();
  6734. this.initRenderable();
  6735. this.assetData = globalData.getAssetData(data.refId);
  6736. this.footageData = globalData.imageLoader.getAsset(this.assetData);
  6737. this.initBaseData(data, globalData, comp);
  6738. }
  6739. FootageElement.prototype.prepareFrame = function () {};
  6740. extendPrototype([RenderableElement, BaseElement, FrameElement], FootageElement);
  6741. FootageElement.prototype.getBaseElement = function () {
  6742. return null;
  6743. };
  6744. FootageElement.prototype.renderFrame = function () {};
  6745. FootageElement.prototype.destroy = function () {};
  6746. FootageElement.prototype.initExpressions = function () {
  6747. var expressionsInterfaces = getExpressionInterfaces();
  6748. if (!expressionsInterfaces) {
  6749. return;
  6750. }
  6751. var FootageInterface = expressionsInterfaces('footage');
  6752. this.layerInterface = FootageInterface(this);
  6753. };
  6754. FootageElement.prototype.getFootageData = function () {
  6755. return this.footageData;
  6756. };
  6757. function AudioElement(data, globalData, comp) {
  6758. this.initFrame();
  6759. this.initRenderable();
  6760. this.assetData = globalData.getAssetData(data.refId);
  6761. this.initBaseData(data, globalData, comp);
  6762. this._isPlaying = false;
  6763. this._canPlay = false;
  6764. var assetPath = this.globalData.getAssetsPath(this.assetData);
  6765. this.audio = this.globalData.audioController.createAudio(assetPath);
  6766. this._currentTime = 0;
  6767. this.globalData.audioController.addAudio(this);
  6768. this._volumeMultiplier = 1;
  6769. this._volume = 1;
  6770. this._previousVolume = null;
  6771. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : {
  6772. _placeholder: true
  6773. };
  6774. this.lv = PropertyFactory.getProp(this, data.au && data.au.lv ? data.au.lv : {
  6775. k: [100]
  6776. }, 1, 0.01, this);
  6777. }
  6778. AudioElement.prototype.prepareFrame = function (num) {
  6779. this.prepareRenderableFrame(num, true);
  6780. this.prepareProperties(num, true);
  6781. if (!this.tm._placeholder) {
  6782. var timeRemapped = this.tm.v;
  6783. this._currentTime = timeRemapped;
  6784. } else {
  6785. this._currentTime = num / this.data.sr;
  6786. }
  6787. this._volume = this.lv.v[0];
  6788. var totalVolume = this._volume * this._volumeMultiplier;
  6789. if (this._previousVolume !== totalVolume) {
  6790. this._previousVolume = totalVolume;
  6791. this.audio.volume(totalVolume);
  6792. }
  6793. };
  6794. extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement);
  6795. AudioElement.prototype.renderFrame = function () {
  6796. if (this.isInRange && this._canPlay) {
  6797. if (!this._isPlaying) {
  6798. this.audio.play();
  6799. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6800. this._isPlaying = true;
  6801. } else if (!this.audio.playing() || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1) {
  6802. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6803. }
  6804. }
  6805. };
  6806. AudioElement.prototype.show = function () {
  6807. // this.audio.play()
  6808. };
  6809. AudioElement.prototype.hide = function () {
  6810. this.audio.pause();
  6811. this._isPlaying = false;
  6812. };
  6813. AudioElement.prototype.pause = function () {
  6814. this.audio.pause();
  6815. this._isPlaying = false;
  6816. this._canPlay = false;
  6817. };
  6818. AudioElement.prototype.resume = function () {
  6819. this._canPlay = true;
  6820. };
  6821. AudioElement.prototype.setRate = function (rateValue) {
  6822. this.audio.rate(rateValue);
  6823. };
  6824. AudioElement.prototype.volume = function (volumeValue) {
  6825. this._volumeMultiplier = volumeValue;
  6826. this._previousVolume = volumeValue * this._volume;
  6827. this.audio.volume(this._previousVolume);
  6828. };
  6829. AudioElement.prototype.getBaseElement = function () {
  6830. return null;
  6831. };
  6832. AudioElement.prototype.destroy = function () {};
  6833. AudioElement.prototype.sourceRectAtTime = function () {};
  6834. AudioElement.prototype.initExpressions = function () {};
  6835. function BaseRenderer() {}
  6836. BaseRenderer.prototype.checkLayers = function (num) {
  6837. var i;
  6838. var len = this.layers.length;
  6839. var data;
  6840. this.completeLayers = true;
  6841. for (i = len - 1; i >= 0; i -= 1) {
  6842. if (!this.elements[i]) {
  6843. data = this.layers[i];
  6844. if (data.ip - data.st <= num - this.layers[i].st && data.op - data.st > num - this.layers[i].st) {
  6845. this.buildItem(i);
  6846. }
  6847. }
  6848. this.completeLayers = this.elements[i] ? this.completeLayers : false;
  6849. }
  6850. this.checkPendingElements();
  6851. };
  6852. BaseRenderer.prototype.createItem = function (layer) {
  6853. switch (layer.ty) {
  6854. case 2:
  6855. return this.createImage(layer);
  6856. case 0:
  6857. return this.createComp(layer);
  6858. case 1:
  6859. return this.createSolid(layer);
  6860. case 3:
  6861. return this.createNull(layer);
  6862. case 4:
  6863. return this.createShape(layer);
  6864. case 5:
  6865. return this.createText(layer);
  6866. case 6:
  6867. return this.createAudio(layer);
  6868. case 13:
  6869. return this.createCamera(layer);
  6870. case 15:
  6871. return this.createFootage(layer);
  6872. default:
  6873. return this.createNull(layer);
  6874. }
  6875. };
  6876. BaseRenderer.prototype.createCamera = function () {
  6877. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  6878. };
  6879. BaseRenderer.prototype.createAudio = function (data) {
  6880. return new AudioElement(data, this.globalData, this);
  6881. };
  6882. BaseRenderer.prototype.createFootage = function (data) {
  6883. return new FootageElement(data, this.globalData, this);
  6884. };
  6885. BaseRenderer.prototype.buildAllItems = function () {
  6886. var i;
  6887. var len = this.layers.length;
  6888. for (i = 0; i < len; i += 1) {
  6889. this.buildItem(i);
  6890. }
  6891. this.checkPendingElements();
  6892. };
  6893. BaseRenderer.prototype.includeLayers = function (newLayers) {
  6894. this.completeLayers = false;
  6895. var i;
  6896. var len = newLayers.length;
  6897. var j;
  6898. var jLen = this.layers.length;
  6899. for (i = 0; i < len; i += 1) {
  6900. j = 0;
  6901. while (j < jLen) {
  6902. if (this.layers[j].id === newLayers[i].id) {
  6903. this.layers[j] = newLayers[i];
  6904. break;
  6905. }
  6906. j += 1;
  6907. }
  6908. }
  6909. };
  6910. BaseRenderer.prototype.setProjectInterface = function (pInterface) {
  6911. this.globalData.projectInterface = pInterface;
  6912. };
  6913. BaseRenderer.prototype.initItems = function () {
  6914. if (!this.globalData.progressiveLoad) {
  6915. this.buildAllItems();
  6916. }
  6917. };
  6918. BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) {
  6919. var elements = this.elements;
  6920. var layers = this.layers;
  6921. var i = 0;
  6922. var len = layers.length;
  6923. while (i < len) {
  6924. if (layers[i].ind == parentName) {
  6925. // eslint-disable-line eqeqeq
  6926. if (!elements[i] || elements[i] === true) {
  6927. this.buildItem(i);
  6928. this.addPendingElement(element);
  6929. } else {
  6930. hierarchy.push(elements[i]);
  6931. elements[i].setAsParent();
  6932. if (layers[i].parent !== undefined) {
  6933. this.buildElementParenting(element, layers[i].parent, hierarchy);
  6934. } else {
  6935. element.setHierarchy(hierarchy);
  6936. }
  6937. }
  6938. }
  6939. i += 1;
  6940. }
  6941. };
  6942. BaseRenderer.prototype.addPendingElement = function (element) {
  6943. this.pendingElements.push(element);
  6944. };
  6945. BaseRenderer.prototype.searchExtraCompositions = function (assets) {
  6946. var i;
  6947. var len = assets.length;
  6948. for (i = 0; i < len; i += 1) {
  6949. if (assets[i].xt) {
  6950. var comp = this.createComp(assets[i]);
  6951. comp.initExpressions();
  6952. this.globalData.projectInterface.registerComposition(comp);
  6953. }
  6954. }
  6955. };
  6956. BaseRenderer.prototype.getElementById = function (ind) {
  6957. var i;
  6958. var len = this.elements.length;
  6959. for (i = 0; i < len; i += 1) {
  6960. if (this.elements[i].data.ind === ind) {
  6961. return this.elements[i];
  6962. }
  6963. }
  6964. return null;
  6965. };
  6966. BaseRenderer.prototype.getElementByPath = function (path) {
  6967. var pathValue = path.shift();
  6968. var element;
  6969. if (typeof pathValue === 'number') {
  6970. element = this.elements[pathValue];
  6971. } else {
  6972. var i;
  6973. var len = this.elements.length;
  6974. for (i = 0; i < len; i += 1) {
  6975. if (this.elements[i].data.nm === pathValue) {
  6976. element = this.elements[i];
  6977. break;
  6978. }
  6979. }
  6980. }
  6981. if (path.length === 0) {
  6982. return element;
  6983. }
  6984. return element.getElementByPath(path);
  6985. };
  6986. BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) {
  6987. this.globalData.fontManager = new FontManager();
  6988. this.globalData.slotManager = slotFactory(animData);
  6989. this.globalData.fontManager.addChars(animData.chars);
  6990. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  6991. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  6992. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  6993. this.globalData.imageLoader = this.animationItem.imagePreloader;
  6994. this.globalData.audioController = this.animationItem.audioController;
  6995. this.globalData.frameId = 0;
  6996. this.globalData.frameRate = animData.fr;
  6997. this.globalData.nm = animData.nm;
  6998. this.globalData.compSize = {
  6999. w: animData.w,
  7000. h: animData.h
  7001. };
  7002. };
  7003. var effectTypes = {
  7004. TRANSFORM_EFFECT: 'transformEFfect'
  7005. };
  7006. function TransformElement() {}
  7007. TransformElement.prototype = {
  7008. initTransform: function initTransform() {
  7009. var mat = new Matrix();
  7010. this.finalTransform = {
  7011. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : {
  7012. o: 0
  7013. },
  7014. _matMdf: false,
  7015. _localMatMdf: false,
  7016. _opMdf: false,
  7017. mat: mat,
  7018. localMat: mat,
  7019. localOpacity: 1
  7020. };
  7021. if (this.data.ao) {
  7022. this.finalTransform.mProp.autoOriented = true;
  7023. }
  7024. // TODO: check TYPE 11: Guided elements
  7025. if (this.data.ty !== 11) {
  7026. // this.createElements();
  7027. }
  7028. },
  7029. renderTransform: function renderTransform() {
  7030. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  7031. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  7032. if (this.hierarchy) {
  7033. var mat;
  7034. var finalMat = this.finalTransform.mat;
  7035. var i = 0;
  7036. var len = this.hierarchy.length;
  7037. // Checking if any of the transformation matrices in the hierarchy chain has changed.
  7038. if (!this.finalTransform._matMdf) {
  7039. while (i < len) {
  7040. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  7041. this.finalTransform._matMdf = true;
  7042. break;
  7043. }
  7044. i += 1;
  7045. }
  7046. }
  7047. if (this.finalTransform._matMdf) {
  7048. mat = this.finalTransform.mProp.v.props;
  7049. finalMat.cloneFromProps(mat);
  7050. for (i = 0; i < len; i += 1) {
  7051. finalMat.multiply(this.hierarchy[i].finalTransform.mProp.v);
  7052. }
  7053. }
  7054. }
  7055. if (!this.localTransforms || this.finalTransform._matMdf) {
  7056. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7057. }
  7058. if (this.finalTransform._opMdf) {
  7059. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7060. }
  7061. },
  7062. renderLocalTransform: function renderLocalTransform() {
  7063. if (this.localTransforms) {
  7064. var i = 0;
  7065. var len = this.localTransforms.length;
  7066. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7067. if (!this.finalTransform._localMatMdf || !this.finalTransform._opMdf) {
  7068. while (i < len) {
  7069. if (this.localTransforms[i]._mdf) {
  7070. this.finalTransform._localMatMdf = true;
  7071. }
  7072. if (this.localTransforms[i]._opMdf && !this.finalTransform._opMdf) {
  7073. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7074. this.finalTransform._opMdf = true;
  7075. }
  7076. i += 1;
  7077. }
  7078. }
  7079. if (this.finalTransform._localMatMdf) {
  7080. var localMat = this.finalTransform.localMat;
  7081. this.localTransforms[0].matrix.clone(localMat);
  7082. for (i = 1; i < len; i += 1) {
  7083. var lmat = this.localTransforms[i].matrix;
  7084. localMat.multiply(lmat);
  7085. }
  7086. localMat.multiply(this.finalTransform.mat);
  7087. }
  7088. if (this.finalTransform._opMdf) {
  7089. var localOp = this.finalTransform.localOpacity;
  7090. for (i = 0; i < len; i += 1) {
  7091. localOp *= this.localTransforms[i].opacity * 0.01;
  7092. }
  7093. this.finalTransform.localOpacity = localOp;
  7094. }
  7095. }
  7096. },
  7097. searchEffectTransforms: function searchEffectTransforms() {
  7098. if (this.renderableEffectsManager) {
  7099. var transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  7100. if (transformEffects.length) {
  7101. this.localTransforms = [];
  7102. this.finalTransform.localMat = new Matrix();
  7103. var i = 0;
  7104. var len = transformEffects.length;
  7105. for (i = 0; i < len; i += 1) {
  7106. this.localTransforms.push(transformEffects[i]);
  7107. }
  7108. }
  7109. }
  7110. },
  7111. globalToLocal: function globalToLocal(pt) {
  7112. var transforms = [];
  7113. transforms.push(this.finalTransform);
  7114. var flag = true;
  7115. var comp = this.comp;
  7116. while (flag) {
  7117. if (comp.finalTransform) {
  7118. if (comp.data.hasMask) {
  7119. transforms.splice(0, 0, comp.finalTransform);
  7120. }
  7121. comp = comp.comp;
  7122. } else {
  7123. flag = false;
  7124. }
  7125. }
  7126. var i;
  7127. var len = transforms.length;
  7128. var ptNew;
  7129. for (i = 0; i < len; i += 1) {
  7130. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
  7131. // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  7132. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  7133. }
  7134. return pt;
  7135. },
  7136. mHelper: new Matrix()
  7137. };
  7138. function MaskElement(data, element, globalData) {
  7139. this.data = data;
  7140. this.element = element;
  7141. this.globalData = globalData;
  7142. this.storedData = [];
  7143. this.masksProperties = this.data.masksProperties || [];
  7144. this.maskElement = null;
  7145. var defs = this.globalData.defs;
  7146. var i;
  7147. var len = this.masksProperties ? this.masksProperties.length : 0;
  7148. this.viewData = createSizedArray(len);
  7149. this.solidPath = '';
  7150. var path;
  7151. var properties = this.masksProperties;
  7152. var count = 0;
  7153. var currentMasks = [];
  7154. var j;
  7155. var jLen;
  7156. var layerId = createElementID();
  7157. var rect;
  7158. var expansor;
  7159. var feMorph;
  7160. var x;
  7161. var maskType = 'clipPath';
  7162. var maskRef = 'clip-path';
  7163. for (i = 0; i < len; i += 1) {
  7164. if (properties[i].mode !== 'a' && properties[i].mode !== 'n' || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) {
  7165. maskType = 'mask';
  7166. maskRef = 'mask';
  7167. }
  7168. if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) {
  7169. rect = createNS('rect');
  7170. rect.setAttribute('fill', '#ffffff');
  7171. rect.setAttribute('width', this.element.comp.data.w || 0);
  7172. rect.setAttribute('height', this.element.comp.data.h || 0);
  7173. currentMasks.push(rect);
  7174. } else {
  7175. rect = null;
  7176. }
  7177. path = createNS('path');
  7178. if (properties[i].mode === 'n') {
  7179. // TODO move this to a factory or to a constructor
  7180. this.viewData[i] = {
  7181. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7182. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7183. elem: path,
  7184. lastPath: ''
  7185. };
  7186. defs.appendChild(path);
  7187. } else {
  7188. count += 1;
  7189. path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7190. path.setAttribute('clip-rule', 'nonzero');
  7191. var filterID;
  7192. if (properties[i].x.k !== 0) {
  7193. maskType = 'mask';
  7194. maskRef = 'mask';
  7195. x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element);
  7196. filterID = createElementID();
  7197. expansor = createNS('filter');
  7198. expansor.setAttribute('id', filterID);
  7199. feMorph = createNS('feMorphology');
  7200. feMorph.setAttribute('operator', 'erode');
  7201. feMorph.setAttribute('in', 'SourceGraphic');
  7202. feMorph.setAttribute('radius', '0');
  7203. expansor.appendChild(feMorph);
  7204. defs.appendChild(expansor);
  7205. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7206. } else {
  7207. feMorph = null;
  7208. x = null;
  7209. }
  7210. // TODO move this to a factory or to a constructor
  7211. this.storedData[i] = {
  7212. elem: path,
  7213. x: x,
  7214. expan: feMorph,
  7215. lastPath: '',
  7216. lastOperator: '',
  7217. filterId: filterID,
  7218. lastRadius: 0
  7219. };
  7220. if (properties[i].mode === 'i') {
  7221. jLen = currentMasks.length;
  7222. var g = createNS('g');
  7223. for (j = 0; j < jLen; j += 1) {
  7224. g.appendChild(currentMasks[j]);
  7225. }
  7226. var mask = createNS('mask');
  7227. mask.setAttribute('mask-type', 'alpha');
  7228. mask.setAttribute('id', layerId + '_' + count);
  7229. mask.appendChild(path);
  7230. defs.appendChild(mask);
  7231. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + layerId + '_' + count + ')');
  7232. currentMasks.length = 0;
  7233. currentMasks.push(g);
  7234. } else {
  7235. currentMasks.push(path);
  7236. }
  7237. if (properties[i].inv && !this.solidPath) {
  7238. this.solidPath = this.createLayerSolidPath();
  7239. }
  7240. // TODO move this to a factory or to a constructor
  7241. this.viewData[i] = {
  7242. elem: path,
  7243. lastPath: '',
  7244. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7245. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7246. invRect: rect
  7247. };
  7248. if (!this.viewData[i].prop.k) {
  7249. this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]);
  7250. }
  7251. }
  7252. }
  7253. this.maskElement = createNS(maskType);
  7254. len = currentMasks.length;
  7255. for (i = 0; i < len; i += 1) {
  7256. this.maskElement.appendChild(currentMasks[i]);
  7257. }
  7258. if (count > 0) {
  7259. this.maskElement.setAttribute('id', layerId);
  7260. this.element.maskedElement.setAttribute(maskRef, 'url(' + getLocationHref() + '#' + layerId + ')');
  7261. defs.appendChild(this.maskElement);
  7262. }
  7263. if (this.viewData.length) {
  7264. this.element.addRenderableComponent(this);
  7265. }
  7266. }
  7267. MaskElement.prototype.getMaskProperty = function (pos) {
  7268. return this.viewData[pos].prop;
  7269. };
  7270. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  7271. var finalMat = this.element.finalTransform.mat;
  7272. var i;
  7273. var len = this.masksProperties.length;
  7274. for (i = 0; i < len; i += 1) {
  7275. if (this.viewData[i].prop._mdf || isFirstFrame) {
  7276. this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]);
  7277. }
  7278. if (this.viewData[i].op._mdf || isFirstFrame) {
  7279. this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v);
  7280. }
  7281. if (this.masksProperties[i].mode !== 'n') {
  7282. if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) {
  7283. this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS());
  7284. }
  7285. if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) {
  7286. var feMorph = this.storedData[i].expan;
  7287. if (this.storedData[i].x.v < 0) {
  7288. if (this.storedData[i].lastOperator !== 'erode') {
  7289. this.storedData[i].lastOperator = 'erode';
  7290. this.storedData[i].elem.setAttribute('filter', 'url(' + getLocationHref() + '#' + this.storedData[i].filterId + ')');
  7291. }
  7292. feMorph.setAttribute('radius', -this.storedData[i].x.v);
  7293. } else {
  7294. if (this.storedData[i].lastOperator !== 'dilate') {
  7295. this.storedData[i].lastOperator = 'dilate';
  7296. this.storedData[i].elem.setAttribute('filter', null);
  7297. }
  7298. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2);
  7299. }
  7300. }
  7301. }
  7302. }
  7303. };
  7304. MaskElement.prototype.getMaskelement = function () {
  7305. return this.maskElement;
  7306. };
  7307. MaskElement.prototype.createLayerSolidPath = function () {
  7308. var path = 'M0,0 ';
  7309. path += ' h' + this.globalData.compSize.w;
  7310. path += ' v' + this.globalData.compSize.h;
  7311. path += ' h-' + this.globalData.compSize.w;
  7312. path += ' v-' + this.globalData.compSize.h + ' ';
  7313. return path;
  7314. };
  7315. MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) {
  7316. var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7317. var i;
  7318. var len;
  7319. len = pathNodes._length;
  7320. for (i = 1; i < len; i += 1) {
  7321. // pathString += " C"+pathNodes.o[i-1][0]+','+pathNodes.o[i-1][1] + " "+pathNodes.i[i][0]+','+pathNodes.i[i][1] + " "+pathNodes.v[i][0]+','+pathNodes.v[i][1];
  7322. pathString += ' C' + pathNodes.o[i - 1][0] + ',' + pathNodes.o[i - 1][1] + ' ' + pathNodes.i[i][0] + ',' + pathNodes.i[i][1] + ' ' + pathNodes.v[i][0] + ',' + pathNodes.v[i][1];
  7323. }
  7324. // pathString += " C"+pathNodes.o[i-1][0]+','+pathNodes.o[i-1][1] + " "+pathNodes.i[0][0]+','+pathNodes.i[0][1] + " "+pathNodes.v[0][0]+','+pathNodes.v[0][1];
  7325. if (pathNodes.c && len > 1) {
  7326. pathString += ' C' + pathNodes.o[i - 1][0] + ',' + pathNodes.o[i - 1][1] + ' ' + pathNodes.i[0][0] + ',' + pathNodes.i[0][1] + ' ' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7327. }
  7328. // pathNodes.__renderedString = pathString;
  7329. if (viewData.lastPath !== pathString) {
  7330. var pathShapeValue = '';
  7331. if (viewData.elem) {
  7332. if (pathNodes.c) {
  7333. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  7334. }
  7335. viewData.elem.setAttribute('d', pathShapeValue);
  7336. }
  7337. viewData.lastPath = pathString;
  7338. }
  7339. };
  7340. MaskElement.prototype.destroy = function () {
  7341. this.element = null;
  7342. this.globalData = null;
  7343. this.maskElement = null;
  7344. this.data = null;
  7345. this.masksProperties = null;
  7346. };
  7347. var filtersFactory = function () {
  7348. var ob = {};
  7349. ob.createFilter = createFilter;
  7350. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  7351. function createFilter(filId, skipCoordinates) {
  7352. var fil = createNS('filter');
  7353. fil.setAttribute('id', filId);
  7354. if (skipCoordinates !== true) {
  7355. fil.setAttribute('filterUnits', 'objectBoundingBox');
  7356. fil.setAttribute('x', '0%');
  7357. fil.setAttribute('y', '0%');
  7358. fil.setAttribute('width', '100%');
  7359. fil.setAttribute('height', '100%');
  7360. }
  7361. return fil;
  7362. }
  7363. function createAlphaToLuminanceFilter() {
  7364. var feColorMatrix = createNS('feColorMatrix');
  7365. feColorMatrix.setAttribute('type', 'matrix');
  7366. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  7367. feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  7368. return feColorMatrix;
  7369. }
  7370. return ob;
  7371. }();
  7372. var featureSupport = function () {
  7373. var ob = {
  7374. maskType: true,
  7375. svgLumaHidden: true,
  7376. offscreenCanvas: typeof OffscreenCanvas !== 'undefined'
  7377. };
  7378. if (/MSIE 10/i.test(navigator.userAgent) || /MSIE 9/i.test(navigator.userAgent) || /rv:11.0/i.test(navigator.userAgent) || /Edge\/\d./i.test(navigator.userAgent)) {
  7379. ob.maskType = false;
  7380. }
  7381. if (/firefox/i.test(navigator.userAgent)) {
  7382. ob.svgLumaHidden = false;
  7383. }
  7384. return ob;
  7385. }();
  7386. var registeredEffects = {};
  7387. var idPrefix = 'filter_result_';
  7388. function SVGEffects(elem) {
  7389. var i;
  7390. var source = 'SourceGraphic';
  7391. var len = elem.data.ef ? elem.data.ef.length : 0;
  7392. var filId = createElementID();
  7393. var fil = filtersFactory.createFilter(filId, true);
  7394. var count = 0;
  7395. this.filters = [];
  7396. var filterManager;
  7397. for (i = 0; i < len; i += 1) {
  7398. filterManager = null;
  7399. var type = elem.data.ef[i].ty;
  7400. if (registeredEffects[type]) {
  7401. var Effect = registeredEffects[type].effect;
  7402. filterManager = new Effect(fil, elem.effectsManager.effectElements[i], elem, idPrefix + count, source);
  7403. source = idPrefix + count;
  7404. if (registeredEffects[type].countsAsEffect) {
  7405. count += 1;
  7406. }
  7407. }
  7408. if (filterManager) {
  7409. this.filters.push(filterManager);
  7410. }
  7411. }
  7412. if (count) {
  7413. elem.globalData.defs.appendChild(fil);
  7414. elem.layerElement.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7415. }
  7416. if (this.filters.length) {
  7417. elem.addRenderableComponent(this);
  7418. }
  7419. }
  7420. SVGEffects.prototype.renderFrame = function (_isFirstFrame) {
  7421. var i;
  7422. var len = this.filters.length;
  7423. for (i = 0; i < len; i += 1) {
  7424. this.filters[i].renderFrame(_isFirstFrame);
  7425. }
  7426. };
  7427. SVGEffects.prototype.getEffects = function (type) {
  7428. var i;
  7429. var len = this.filters.length;
  7430. var effects = [];
  7431. for (i = 0; i < len; i += 1) {
  7432. if (this.filters[i].type === type) {
  7433. effects.push(this.filters[i]);
  7434. }
  7435. }
  7436. return effects;
  7437. };
  7438. function registerEffect(id, effect, countsAsEffect) {
  7439. registeredEffects[id] = {
  7440. effect: effect,
  7441. countsAsEffect: countsAsEffect
  7442. };
  7443. }
  7444. function SVGBaseElement() {}
  7445. SVGBaseElement.prototype = {
  7446. initRendererElement: function initRendererElement() {
  7447. this.layerElement = createNS('g');
  7448. },
  7449. createContainerElements: function createContainerElements() {
  7450. this.matteElement = createNS('g');
  7451. this.transformedElement = this.layerElement;
  7452. this.maskedElement = this.layerElement;
  7453. this._sizeChanged = false;
  7454. var layerElementParent = null;
  7455. // If this layer acts as a mask for the following layer
  7456. if (this.data.td) {
  7457. this.matteMasks = {};
  7458. var gg = createNS('g');
  7459. gg.setAttribute('id', this.layerId);
  7460. gg.appendChild(this.layerElement);
  7461. layerElementParent = gg;
  7462. this.globalData.defs.appendChild(gg);
  7463. } else if (this.data.tt) {
  7464. this.matteElement.appendChild(this.layerElement);
  7465. layerElementParent = this.matteElement;
  7466. this.baseElement = this.matteElement;
  7467. } else {
  7468. this.baseElement = this.layerElement;
  7469. }
  7470. if (this.data.ln) {
  7471. this.layerElement.setAttribute('id', this.data.ln);
  7472. }
  7473. if (this.data.cl) {
  7474. this.layerElement.setAttribute('class', this.data.cl);
  7475. }
  7476. // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  7477. if (this.data.ty === 0 && !this.data.hd) {
  7478. var cp = createNS('clipPath');
  7479. var pt = createNS('path');
  7480. pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  7481. var clipId = createElementID();
  7482. cp.setAttribute('id', clipId);
  7483. cp.appendChild(pt);
  7484. this.globalData.defs.appendChild(cp);
  7485. if (this.checkMasks()) {
  7486. var cpGroup = createNS('g');
  7487. cpGroup.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7488. cpGroup.appendChild(this.layerElement);
  7489. this.transformedElement = cpGroup;
  7490. if (layerElementParent) {
  7491. layerElementParent.appendChild(this.transformedElement);
  7492. } else {
  7493. this.baseElement = this.transformedElement;
  7494. }
  7495. } else {
  7496. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7497. }
  7498. }
  7499. if (this.data.bm !== 0) {
  7500. this.setBlendMode();
  7501. }
  7502. },
  7503. renderElement: function renderElement() {
  7504. if (this.finalTransform._localMatMdf) {
  7505. this.transformedElement.setAttribute('transform', this.finalTransform.localMat.to2dCSS());
  7506. }
  7507. if (this.finalTransform._opMdf) {
  7508. this.transformedElement.setAttribute('opacity', this.finalTransform.localOpacity);
  7509. }
  7510. },
  7511. destroyBaseElement: function destroyBaseElement() {
  7512. this.layerElement = null;
  7513. this.matteElement = null;
  7514. this.maskManager.destroy();
  7515. },
  7516. getBaseElement: function getBaseElement() {
  7517. if (this.data.hd) {
  7518. return null;
  7519. }
  7520. return this.baseElement;
  7521. },
  7522. createRenderableComponents: function createRenderableComponents() {
  7523. this.maskManager = new MaskElement(this.data, this, this.globalData);
  7524. this.renderableEffectsManager = new SVGEffects(this);
  7525. this.searchEffectTransforms();
  7526. },
  7527. getMatte: function getMatte(matteType) {
  7528. // This should not be a common case. But for backward compatibility, we'll create the matte object.
  7529. // It solves animations that have two consecutive layers marked as matte masks.
  7530. // Which is an undefined behavior in AE.
  7531. if (!this.matteMasks) {
  7532. this.matteMasks = {};
  7533. }
  7534. if (!this.matteMasks[matteType]) {
  7535. var id = this.layerId + '_' + matteType;
  7536. var filId;
  7537. var fil;
  7538. var useElement;
  7539. var gg;
  7540. if (matteType === 1 || matteType === 3) {
  7541. var masker = createNS('mask');
  7542. masker.setAttribute('id', id);
  7543. masker.setAttribute('mask-type', matteType === 3 ? 'luminance' : 'alpha');
  7544. useElement = createNS('use');
  7545. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7546. masker.appendChild(useElement);
  7547. this.globalData.defs.appendChild(masker);
  7548. if (!featureSupport.maskType && matteType === 1) {
  7549. masker.setAttribute('mask-type', 'luminance');
  7550. filId = createElementID();
  7551. fil = filtersFactory.createFilter(filId);
  7552. this.globalData.defs.appendChild(fil);
  7553. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7554. gg = createNS('g');
  7555. gg.appendChild(useElement);
  7556. masker.appendChild(gg);
  7557. gg.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7558. }
  7559. } else if (matteType === 2) {
  7560. var maskGroup = createNS('mask');
  7561. maskGroup.setAttribute('id', id);
  7562. maskGroup.setAttribute('mask-type', 'alpha');
  7563. var maskGrouper = createNS('g');
  7564. maskGroup.appendChild(maskGrouper);
  7565. filId = createElementID();
  7566. fil = filtersFactory.createFilter(filId);
  7567. /// /
  7568. var feCTr = createNS('feComponentTransfer');
  7569. feCTr.setAttribute('in', 'SourceGraphic');
  7570. fil.appendChild(feCTr);
  7571. var feFunc = createNS('feFuncA');
  7572. feFunc.setAttribute('type', 'table');
  7573. feFunc.setAttribute('tableValues', '1.0 0.0');
  7574. feCTr.appendChild(feFunc);
  7575. /// /
  7576. this.globalData.defs.appendChild(fil);
  7577. var alphaRect = createNS('rect');
  7578. alphaRect.setAttribute('width', this.comp.data.w);
  7579. alphaRect.setAttribute('height', this.comp.data.h);
  7580. alphaRect.setAttribute('x', '0');
  7581. alphaRect.setAttribute('y', '0');
  7582. alphaRect.setAttribute('fill', '#ffffff');
  7583. alphaRect.setAttribute('opacity', '0');
  7584. maskGrouper.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7585. maskGrouper.appendChild(alphaRect);
  7586. useElement = createNS('use');
  7587. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7588. maskGrouper.appendChild(useElement);
  7589. if (!featureSupport.maskType) {
  7590. maskGroup.setAttribute('mask-type', 'luminance');
  7591. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7592. gg = createNS('g');
  7593. maskGrouper.appendChild(alphaRect);
  7594. gg.appendChild(this.layerElement);
  7595. maskGrouper.appendChild(gg);
  7596. }
  7597. this.globalData.defs.appendChild(maskGroup);
  7598. }
  7599. this.matteMasks[matteType] = id;
  7600. }
  7601. return this.matteMasks[matteType];
  7602. },
  7603. setMatte: function setMatte(id) {
  7604. if (!this.matteElement) {
  7605. return;
  7606. }
  7607. this.matteElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  7608. }
  7609. };
  7610. /**
  7611. * @file
  7612. * Handles AE's layer parenting property.
  7613. *
  7614. */
  7615. function HierarchyElement() {}
  7616. HierarchyElement.prototype = {
  7617. /**
  7618. * @function
  7619. * Initializes hierarchy properties
  7620. *
  7621. */
  7622. initHierarchy: function initHierarchy() {
  7623. // element's parent list
  7624. this.hierarchy = [];
  7625. // if element is parent of another layer _isParent will be true
  7626. this._isParent = false;
  7627. this.checkParenting();
  7628. },
  7629. /**
  7630. * @function
  7631. * Sets layer's hierarchy.
  7632. * @param {array} hierarch
  7633. * layer's parent list
  7634. *
  7635. */
  7636. setHierarchy: function setHierarchy(hierarchy) {
  7637. this.hierarchy = hierarchy;
  7638. },
  7639. /**
  7640. * @function
  7641. * Sets layer as parent.
  7642. *
  7643. */
  7644. setAsParent: function setAsParent() {
  7645. this._isParent = true;
  7646. },
  7647. /**
  7648. * @function
  7649. * Searches layer's parenting chain
  7650. *
  7651. */
  7652. checkParenting: function checkParenting() {
  7653. if (this.data.parent !== undefined) {
  7654. this.comp.buildElementParenting(this, this.data.parent, []);
  7655. }
  7656. }
  7657. };
  7658. function RenderableDOMElement() {}
  7659. (function () {
  7660. var _prototype = {
  7661. initElement: function initElement(data, globalData, comp) {
  7662. this.initFrame();
  7663. this.initBaseData(data, globalData, comp);
  7664. this.initTransform(data, globalData, comp);
  7665. this.initHierarchy();
  7666. this.initRenderable();
  7667. this.initRendererElement();
  7668. this.createContainerElements();
  7669. this.createRenderableComponents();
  7670. this.createContent();
  7671. this.hide();
  7672. },
  7673. hide: function hide() {
  7674. // console.log('HIDE', this);
  7675. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7676. var elem = this.baseElement || this.layerElement;
  7677. elem.style.display = 'none';
  7678. this.hidden = true;
  7679. }
  7680. },
  7681. show: function show() {
  7682. // console.log('SHOW', this);
  7683. if (this.isInRange && !this.isTransparent) {
  7684. if (!this.data.hd) {
  7685. var elem = this.baseElement || this.layerElement;
  7686. elem.style.display = 'block';
  7687. }
  7688. this.hidden = false;
  7689. this._isFirstFrame = true;
  7690. }
  7691. },
  7692. renderFrame: function renderFrame() {
  7693. // If it is exported as hidden (data.hd === true) no need to render
  7694. // If it is not visible no need to render
  7695. if (this.data.hd || this.hidden) {
  7696. return;
  7697. }
  7698. this.renderTransform();
  7699. this.renderRenderable();
  7700. this.renderLocalTransform();
  7701. this.renderElement();
  7702. this.renderInnerContent();
  7703. if (this._isFirstFrame) {
  7704. this._isFirstFrame = false;
  7705. }
  7706. },
  7707. renderInnerContent: function renderInnerContent() {},
  7708. prepareFrame: function prepareFrame(num) {
  7709. this._mdf = false;
  7710. this.prepareRenderableFrame(num);
  7711. this.prepareProperties(num, this.isInRange);
  7712. this.checkTransparency();
  7713. },
  7714. destroy: function destroy() {
  7715. this.innerElem = null;
  7716. this.destroyBaseElement();
  7717. }
  7718. };
  7719. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  7720. })();
  7721. function IImageElement(data, globalData, comp) {
  7722. this.assetData = globalData.getAssetData(data.refId);
  7723. if (this.assetData && this.assetData.sid) {
  7724. this.assetData = globalData.slotManager.getProp(this.assetData);
  7725. }
  7726. this.initElement(data, globalData, comp);
  7727. this.sourceRect = {
  7728. top: 0,
  7729. left: 0,
  7730. width: this.assetData.w,
  7731. height: this.assetData.h
  7732. };
  7733. }
  7734. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement);
  7735. IImageElement.prototype.createContent = function () {
  7736. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7737. this.innerElem = createNS('image');
  7738. this.innerElem.setAttribute('width', this.assetData.w + 'px');
  7739. this.innerElem.setAttribute('height', this.assetData.h + 'px');
  7740. this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  7741. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  7742. this.layerElement.appendChild(this.innerElem);
  7743. };
  7744. IImageElement.prototype.sourceRectAtTime = function () {
  7745. return this.sourceRect;
  7746. };
  7747. function ProcessedElement(element, position) {
  7748. this.elem = element;
  7749. this.pos = position;
  7750. }
  7751. function IShapeElement() {}
  7752. IShapeElement.prototype = {
  7753. addShapeToModifiers: function addShapeToModifiers(data) {
  7754. var i;
  7755. var len = this.shapeModifiers.length;
  7756. for (i = 0; i < len; i += 1) {
  7757. this.shapeModifiers[i].addShape(data);
  7758. }
  7759. },
  7760. isShapeInAnimatedModifiers: function isShapeInAnimatedModifiers(data) {
  7761. var i = 0;
  7762. var len = this.shapeModifiers.length;
  7763. while (i < len) {
  7764. if (this.shapeModifiers[i].isAnimatedWithShape(data)) {
  7765. return true;
  7766. }
  7767. }
  7768. return false;
  7769. },
  7770. renderModifiers: function renderModifiers() {
  7771. if (!this.shapeModifiers.length) {
  7772. return;
  7773. }
  7774. var i;
  7775. var len = this.shapes.length;
  7776. for (i = 0; i < len; i += 1) {
  7777. this.shapes[i].sh.reset();
  7778. }
  7779. len = this.shapeModifiers.length;
  7780. var shouldBreakProcess;
  7781. for (i = len - 1; i >= 0; i -= 1) {
  7782. shouldBreakProcess = this.shapeModifiers[i].processShapes(this._isFirstFrame);
  7783. // workaround to fix cases where a repeater resets the shape so the following processes get called twice
  7784. // TODO: find a better solution for this
  7785. if (shouldBreakProcess) {
  7786. break;
  7787. }
  7788. }
  7789. },
  7790. searchProcessedElement: function searchProcessedElement(elem) {
  7791. var elements = this.processedElements;
  7792. var i = 0;
  7793. var len = elements.length;
  7794. while (i < len) {
  7795. if (elements[i].elem === elem) {
  7796. return elements[i].pos;
  7797. }
  7798. i += 1;
  7799. }
  7800. return 0;
  7801. },
  7802. addProcessedElement: function addProcessedElement(elem, pos) {
  7803. var elements = this.processedElements;
  7804. var i = elements.length;
  7805. while (i) {
  7806. i -= 1;
  7807. if (elements[i].elem === elem) {
  7808. elements[i].pos = pos;
  7809. return;
  7810. }
  7811. }
  7812. elements.push(new ProcessedElement(elem, pos));
  7813. },
  7814. prepareFrame: function prepareFrame(num) {
  7815. this.prepareRenderableFrame(num);
  7816. this.prepareProperties(num, this.isInRange);
  7817. }
  7818. };
  7819. var lineCapEnum = {
  7820. 1: 'butt',
  7821. 2: 'round',
  7822. 3: 'square'
  7823. };
  7824. var lineJoinEnum = {
  7825. 1: 'miter',
  7826. 2: 'round',
  7827. 3: 'bevel'
  7828. };
  7829. function SVGShapeData(transformers, level, shape) {
  7830. this.caches = [];
  7831. this.styles = [];
  7832. this.transformers = transformers;
  7833. this.lStr = '';
  7834. this.sh = shape;
  7835. this.lvl = level;
  7836. // TODO find if there are some cases where _isAnimated can be false.
  7837. // For now, since shapes add up with other shapes. They have to be calculated every time.
  7838. // One way of finding out is checking if all styles associated to this shape depend only of this shape
  7839. this._isAnimated = !!shape.k;
  7840. // TODO: commenting this for now since all shapes are animated
  7841. var i = 0;
  7842. var len = transformers.length;
  7843. while (i < len) {
  7844. if (transformers[i].mProps.dynamicProperties.length) {
  7845. this._isAnimated = true;
  7846. break;
  7847. }
  7848. i += 1;
  7849. }
  7850. }
  7851. SVGShapeData.prototype.setAsAnimated = function () {
  7852. this._isAnimated = true;
  7853. };
  7854. function SVGStyleData(data, level) {
  7855. this.data = data;
  7856. this.type = data.ty;
  7857. this.d = '';
  7858. this.lvl = level;
  7859. this._mdf = false;
  7860. this.closed = data.hd === true;
  7861. this.pElem = createNS('path');
  7862. this.msElem = null;
  7863. }
  7864. SVGStyleData.prototype.reset = function () {
  7865. this.d = '';
  7866. this._mdf = false;
  7867. };
  7868. function DashProperty(elem, data, renderer, container) {
  7869. this.elem = elem;
  7870. this.frameId = -1;
  7871. this.dataProps = createSizedArray(data.length);
  7872. this.renderer = renderer;
  7873. this.k = false;
  7874. this.dashStr = '';
  7875. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  7876. this.dashoffset = createTypedArray('float32', 1);
  7877. this.initDynamicPropertyContainer(container);
  7878. var i;
  7879. var len = data.length || 0;
  7880. var prop;
  7881. for (i = 0; i < len; i += 1) {
  7882. prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this);
  7883. this.k = prop.k || this.k;
  7884. this.dataProps[i] = {
  7885. n: data[i].n,
  7886. p: prop
  7887. };
  7888. }
  7889. if (!this.k) {
  7890. this.getValue(true);
  7891. }
  7892. this._isAnimated = this.k;
  7893. }
  7894. DashProperty.prototype.getValue = function (forceRender) {
  7895. if (this.elem.globalData.frameId === this.frameId && !forceRender) {
  7896. return;
  7897. }
  7898. this.frameId = this.elem.globalData.frameId;
  7899. this.iterateDynamicProperties();
  7900. this._mdf = this._mdf || forceRender;
  7901. if (this._mdf) {
  7902. var i = 0;
  7903. var len = this.dataProps.length;
  7904. if (this.renderer === 'svg') {
  7905. this.dashStr = '';
  7906. }
  7907. for (i = 0; i < len; i += 1) {
  7908. if (this.dataProps[i].n !== 'o') {
  7909. if (this.renderer === 'svg') {
  7910. this.dashStr += ' ' + this.dataProps[i].p.v;
  7911. } else {
  7912. this.dashArray[i] = this.dataProps[i].p.v;
  7913. }
  7914. } else {
  7915. this.dashoffset[0] = this.dataProps[i].p.v;
  7916. }
  7917. }
  7918. }
  7919. };
  7920. extendPrototype([DynamicPropertyContainer], DashProperty);
  7921. function SVGStrokeStyleData(elem, data, styleOb) {
  7922. this.initDynamicPropertyContainer(elem);
  7923. this.getValue = this.iterateDynamicProperties;
  7924. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7925. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  7926. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  7927. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7928. this.style = styleOb;
  7929. this._isAnimated = !!this._isAnimated;
  7930. }
  7931. extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData);
  7932. function SVGFillStyleData(elem, data, styleOb) {
  7933. this.initDynamicPropertyContainer(elem);
  7934. this.getValue = this.iterateDynamicProperties;
  7935. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7936. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7937. this.style = styleOb;
  7938. }
  7939. extendPrototype([DynamicPropertyContainer], SVGFillStyleData);
  7940. function SVGNoStyleData(elem, data, styleOb) {
  7941. this.initDynamicPropertyContainer(elem);
  7942. this.getValue = this.iterateDynamicProperties;
  7943. this.style = styleOb;
  7944. }
  7945. extendPrototype([DynamicPropertyContainer], SVGNoStyleData);
  7946. function GradientProperty(elem, data, container) {
  7947. this.data = data;
  7948. this.c = createTypedArray('uint8c', data.p * 4);
  7949. var cLength = data.k.k[0].s ? data.k.k[0].s.length - data.p * 4 : data.k.k.length - data.p * 4;
  7950. this.o = createTypedArray('float32', cLength);
  7951. this._cmdf = false;
  7952. this._omdf = false;
  7953. this._collapsable = this.checkCollapsable();
  7954. this._hasOpacity = cLength;
  7955. this.initDynamicPropertyContainer(container);
  7956. this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this);
  7957. this.k = this.prop.k;
  7958. this.getValue(true);
  7959. }
  7960. GradientProperty.prototype.comparePoints = function (values, points) {
  7961. var i = 0;
  7962. var len = this.o.length / 2;
  7963. var diff;
  7964. while (i < len) {
  7965. diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]);
  7966. if (diff > 0.01) {
  7967. return false;
  7968. }
  7969. i += 1;
  7970. }
  7971. return true;
  7972. };
  7973. GradientProperty.prototype.checkCollapsable = function () {
  7974. if (this.o.length / 2 !== this.c.length / 4) {
  7975. return false;
  7976. }
  7977. if (this.data.k.k[0].s) {
  7978. var i = 0;
  7979. var len = this.data.k.k.length;
  7980. while (i < len) {
  7981. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  7982. return false;
  7983. }
  7984. i += 1;
  7985. }
  7986. } else if (!this.comparePoints(this.data.k.k, this.data.p)) {
  7987. return false;
  7988. }
  7989. return true;
  7990. };
  7991. GradientProperty.prototype.getValue = function (forceRender) {
  7992. this.prop.getValue();
  7993. this._mdf = false;
  7994. this._cmdf = false;
  7995. this._omdf = false;
  7996. if (this.prop._mdf || forceRender) {
  7997. var i;
  7998. var len = this.data.p * 4;
  7999. var mult;
  8000. var val;
  8001. for (i = 0; i < len; i += 1) {
  8002. mult = i % 4 === 0 ? 100 : 255;
  8003. val = Math.round(this.prop.v[i] * mult);
  8004. if (this.c[i] !== val) {
  8005. this.c[i] = val;
  8006. this._cmdf = !forceRender;
  8007. }
  8008. }
  8009. if (this.o.length) {
  8010. len = this.prop.v.length;
  8011. for (i = this.data.p * 4; i < len; i += 1) {
  8012. mult = i % 2 === 0 ? 100 : 1;
  8013. val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i];
  8014. if (this.o[i - this.data.p * 4] !== val) {
  8015. this.o[i - this.data.p * 4] = val;
  8016. this._omdf = !forceRender;
  8017. }
  8018. }
  8019. }
  8020. this._mdf = !forceRender;
  8021. }
  8022. };
  8023. extendPrototype([DynamicPropertyContainer], GradientProperty);
  8024. function SVGGradientFillStyleData(elem, data, styleOb) {
  8025. this.initDynamicPropertyContainer(elem);
  8026. this.getValue = this.iterateDynamicProperties;
  8027. this.initGradientData(elem, data, styleOb);
  8028. }
  8029. SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) {
  8030. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  8031. this.s = PropertyFactory.getProp(elem, data.s, 1, null, this);
  8032. this.e = PropertyFactory.getProp(elem, data.e, 1, null, this);
  8033. this.h = PropertyFactory.getProp(elem, data.h || {
  8034. k: 0
  8035. }, 0, 0.01, this);
  8036. this.a = PropertyFactory.getProp(elem, data.a || {
  8037. k: 0
  8038. }, 0, degToRads, this);
  8039. this.g = new GradientProperty(elem, data.g, this);
  8040. this.style = styleOb;
  8041. this.stops = [];
  8042. this.setGradientData(styleOb.pElem, data);
  8043. this.setGradientOpacity(data, styleOb);
  8044. this._isAnimated = !!this._isAnimated;
  8045. };
  8046. SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) {
  8047. var gradientId = createElementID();
  8048. var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8049. gfill.setAttribute('id', gradientId);
  8050. gfill.setAttribute('spreadMethod', 'pad');
  8051. gfill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8052. var stops = [];
  8053. var stop;
  8054. var j;
  8055. var jLen;
  8056. jLen = data.g.p * 4;
  8057. for (j = 0; j < jLen; j += 4) {
  8058. stop = createNS('stop');
  8059. gfill.appendChild(stop);
  8060. stops.push(stop);
  8061. }
  8062. pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + gradientId + ')');
  8063. this.gf = gfill;
  8064. this.cst = stops;
  8065. };
  8066. SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) {
  8067. if (this.g._hasOpacity && !this.g._collapsable) {
  8068. var stop;
  8069. var j;
  8070. var jLen;
  8071. var mask = createNS('mask');
  8072. var maskElement = createNS('path');
  8073. mask.appendChild(maskElement);
  8074. var opacityId = createElementID();
  8075. var maskId = createElementID();
  8076. mask.setAttribute('id', maskId);
  8077. var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8078. opFill.setAttribute('id', opacityId);
  8079. opFill.setAttribute('spreadMethod', 'pad');
  8080. opFill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8081. jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length;
  8082. var stops = this.stops;
  8083. for (j = data.g.p * 4; j < jLen; j += 2) {
  8084. stop = createNS('stop');
  8085. stop.setAttribute('stop-color', 'rgb(255,255,255)');
  8086. opFill.appendChild(stop);
  8087. stops.push(stop);
  8088. }
  8089. maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + opacityId + ')');
  8090. if (data.ty === 'gs') {
  8091. maskElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8092. maskElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8093. if (data.lj === 1) {
  8094. maskElement.setAttribute('stroke-miterlimit', data.ml);
  8095. }
  8096. }
  8097. this.of = opFill;
  8098. this.ms = mask;
  8099. this.ost = stops;
  8100. this.maskId = maskId;
  8101. styleOb.msElem = maskElement;
  8102. }
  8103. };
  8104. extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData);
  8105. function SVGGradientStrokeStyleData(elem, data, styleOb) {
  8106. this.initDynamicPropertyContainer(elem);
  8107. this.getValue = this.iterateDynamicProperties;
  8108. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  8109. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  8110. this.initGradientData(elem, data, styleOb);
  8111. this._isAnimated = !!this._isAnimated;
  8112. }
  8113. extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData);
  8114. function ShapeGroupData() {
  8115. this.it = [];
  8116. this.prevViewData = [];
  8117. this.gr = createNS('g');
  8118. }
  8119. function SVGTransformData(mProps, op, container) {
  8120. this.transform = {
  8121. mProps: mProps,
  8122. op: op,
  8123. container: container
  8124. };
  8125. this.elements = [];
  8126. this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length;
  8127. }
  8128. var buildShapeString = function buildShapeString(pathNodes, length, closed, mat) {
  8129. if (length === 0) {
  8130. return '';
  8131. }
  8132. var _o = pathNodes.o;
  8133. var _i = pathNodes.i;
  8134. var _v = pathNodes.v;
  8135. var i;
  8136. var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8137. for (i = 1; i < length; i += 1) {
  8138. shapeString += ' C' + mat.applyToPointStringified(_o[i - 1][0], _o[i - 1][1]) + ' ' + mat.applyToPointStringified(_i[i][0], _i[i][1]) + ' ' + mat.applyToPointStringified(_v[i][0], _v[i][1]);
  8139. }
  8140. if (closed && length) {
  8141. shapeString += ' C' + mat.applyToPointStringified(_o[i - 1][0], _o[i - 1][1]) + ' ' + mat.applyToPointStringified(_i[0][0], _i[0][1]) + ' ' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8142. shapeString += 'z';
  8143. }
  8144. return shapeString;
  8145. };
  8146. var SVGElementsRenderer = function () {
  8147. var _identityMatrix = new Matrix();
  8148. var _matrixHelper = new Matrix();
  8149. var ob = {
  8150. createRenderFunction: createRenderFunction
  8151. };
  8152. function createRenderFunction(data) {
  8153. switch (data.ty) {
  8154. case 'fl':
  8155. return renderFill;
  8156. case 'gf':
  8157. return renderGradient;
  8158. case 'gs':
  8159. return renderGradientStroke;
  8160. case 'st':
  8161. return renderStroke;
  8162. case 'sh':
  8163. case 'el':
  8164. case 'rc':
  8165. case 'sr':
  8166. return renderPath;
  8167. case 'tr':
  8168. return renderContentTransform;
  8169. case 'no':
  8170. return renderNoop;
  8171. default:
  8172. return null;
  8173. }
  8174. }
  8175. function renderContentTransform(styleData, itemData, isFirstFrame) {
  8176. if (isFirstFrame || itemData.transform.op._mdf) {
  8177. itemData.transform.container.setAttribute('opacity', itemData.transform.op.v);
  8178. }
  8179. if (isFirstFrame || itemData.transform.mProps._mdf) {
  8180. itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS());
  8181. }
  8182. }
  8183. function renderNoop() {}
  8184. function renderPath(styleData, itemData, isFirstFrame) {
  8185. var j;
  8186. var jLen;
  8187. var pathStringTransformed;
  8188. var redraw;
  8189. var pathNodes;
  8190. var l;
  8191. var lLen = itemData.styles.length;
  8192. var lvl = itemData.lvl;
  8193. var paths;
  8194. var mat;
  8195. var iterations;
  8196. var k;
  8197. for (l = 0; l < lLen; l += 1) {
  8198. redraw = itemData.sh._mdf || isFirstFrame;
  8199. if (itemData.styles[l].lvl < lvl) {
  8200. mat = _matrixHelper.reset();
  8201. iterations = lvl - itemData.styles[l].lvl;
  8202. k = itemData.transformers.length - 1;
  8203. while (!redraw && iterations > 0) {
  8204. redraw = itemData.transformers[k].mProps._mdf || redraw;
  8205. iterations -= 1;
  8206. k -= 1;
  8207. }
  8208. if (redraw) {
  8209. iterations = lvl - itemData.styles[l].lvl;
  8210. k = itemData.transformers.length - 1;
  8211. while (iterations > 0) {
  8212. mat.multiply(itemData.transformers[k].mProps.v);
  8213. iterations -= 1;
  8214. k -= 1;
  8215. }
  8216. }
  8217. } else {
  8218. mat = _identityMatrix;
  8219. }
  8220. paths = itemData.sh.paths;
  8221. jLen = paths._length;
  8222. if (redraw) {
  8223. pathStringTransformed = '';
  8224. for (j = 0; j < jLen; j += 1) {
  8225. pathNodes = paths.shapes[j];
  8226. if (pathNodes && pathNodes._length) {
  8227. pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat);
  8228. }
  8229. }
  8230. itemData.caches[l] = pathStringTransformed;
  8231. } else {
  8232. pathStringTransformed = itemData.caches[l];
  8233. }
  8234. itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed;
  8235. itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf;
  8236. }
  8237. }
  8238. function renderFill(styleData, itemData, isFirstFrame) {
  8239. var styleElem = itemData.style;
  8240. if (itemData.c._mdf || isFirstFrame) {
  8241. styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8242. }
  8243. if (itemData.o._mdf || isFirstFrame) {
  8244. styleElem.pElem.setAttribute('fill-opacity', itemData.o.v);
  8245. }
  8246. }
  8247. function renderGradientStroke(styleData, itemData, isFirstFrame) {
  8248. renderGradient(styleData, itemData, isFirstFrame);
  8249. renderStroke(styleData, itemData, isFirstFrame);
  8250. }
  8251. function renderGradient(styleData, itemData, isFirstFrame) {
  8252. var gfill = itemData.gf;
  8253. var hasOpacity = itemData.g._hasOpacity;
  8254. var pt1 = itemData.s.v;
  8255. var pt2 = itemData.e.v;
  8256. if (itemData.o._mdf || isFirstFrame) {
  8257. var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity';
  8258. itemData.style.pElem.setAttribute(attr, itemData.o.v);
  8259. }
  8260. if (itemData.s._mdf || isFirstFrame) {
  8261. var attr1 = styleData.t === 1 ? 'x1' : 'cx';
  8262. var attr2 = attr1 === 'x1' ? 'y1' : 'cy';
  8263. gfill.setAttribute(attr1, pt1[0]);
  8264. gfill.setAttribute(attr2, pt1[1]);
  8265. if (hasOpacity && !itemData.g._collapsable) {
  8266. itemData.of.setAttribute(attr1, pt1[0]);
  8267. itemData.of.setAttribute(attr2, pt1[1]);
  8268. }
  8269. }
  8270. var stops;
  8271. var i;
  8272. var len;
  8273. var stop;
  8274. if (itemData.g._cmdf || isFirstFrame) {
  8275. stops = itemData.cst;
  8276. var cValues = itemData.g.c;
  8277. len = stops.length;
  8278. for (i = 0; i < len; i += 1) {
  8279. stop = stops[i];
  8280. stop.setAttribute('offset', cValues[i * 4] + '%');
  8281. stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')');
  8282. }
  8283. }
  8284. if (hasOpacity && (itemData.g._omdf || isFirstFrame)) {
  8285. var oValues = itemData.g.o;
  8286. if (itemData.g._collapsable) {
  8287. stops = itemData.cst;
  8288. } else {
  8289. stops = itemData.ost;
  8290. }
  8291. len = stops.length;
  8292. for (i = 0; i < len; i += 1) {
  8293. stop = stops[i];
  8294. if (!itemData.g._collapsable) {
  8295. stop.setAttribute('offset', oValues[i * 2] + '%');
  8296. }
  8297. stop.setAttribute('stop-opacity', oValues[i * 2 + 1]);
  8298. }
  8299. }
  8300. if (styleData.t === 1) {
  8301. if (itemData.e._mdf || isFirstFrame) {
  8302. gfill.setAttribute('x2', pt2[0]);
  8303. gfill.setAttribute('y2', pt2[1]);
  8304. if (hasOpacity && !itemData.g._collapsable) {
  8305. itemData.of.setAttribute('x2', pt2[0]);
  8306. itemData.of.setAttribute('y2', pt2[1]);
  8307. }
  8308. }
  8309. } else {
  8310. var rad;
  8311. if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) {
  8312. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8313. gfill.setAttribute('r', rad);
  8314. if (hasOpacity && !itemData.g._collapsable) {
  8315. itemData.of.setAttribute('r', rad);
  8316. }
  8317. }
  8318. if (itemData.s._mdf || itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) {
  8319. if (!rad) {
  8320. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8321. }
  8322. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  8323. var percent = itemData.h.v;
  8324. if (percent >= 1) {
  8325. percent = 0.99;
  8326. } else if (percent <= -1) {
  8327. percent = -0.99;
  8328. }
  8329. var dist = rad * percent;
  8330. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  8331. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  8332. gfill.setAttribute('fx', x);
  8333. gfill.setAttribute('fy', y);
  8334. if (hasOpacity && !itemData.g._collapsable) {
  8335. itemData.of.setAttribute('fx', x);
  8336. itemData.of.setAttribute('fy', y);
  8337. }
  8338. }
  8339. // gfill.setAttribute('fy','200');
  8340. }
  8341. }
  8342. function renderStroke(styleData, itemData, isFirstFrame) {
  8343. var styleElem = itemData.style;
  8344. var d = itemData.d;
  8345. if (d && (d._mdf || isFirstFrame) && d.dashStr) {
  8346. styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr);
  8347. styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]);
  8348. }
  8349. if (itemData.c && (itemData.c._mdf || isFirstFrame)) {
  8350. styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8351. }
  8352. if (itemData.o._mdf || isFirstFrame) {
  8353. styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v);
  8354. }
  8355. if (itemData.w._mdf || isFirstFrame) {
  8356. styleElem.pElem.setAttribute('stroke-width', itemData.w.v);
  8357. if (styleElem.msElem) {
  8358. styleElem.msElem.setAttribute('stroke-width', itemData.w.v);
  8359. }
  8360. }
  8361. }
  8362. return ob;
  8363. }();
  8364. function SVGShapeElement(data, globalData, comp) {
  8365. // List of drawable elements
  8366. this.shapes = [];
  8367. // Full shape data
  8368. this.shapesData = data.shapes;
  8369. // List of styles that will be applied to shapes
  8370. this.stylesList = [];
  8371. // List of modifiers that will be applied to shapes
  8372. this.shapeModifiers = [];
  8373. // List of items in shape tree
  8374. this.itemsData = [];
  8375. // List of items in previous shape tree
  8376. this.processedElements = [];
  8377. // List of animated components
  8378. this.animatedContents = [];
  8379. this.initElement(data, globalData, comp);
  8380. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8381. // List of elements that have been created
  8382. this.prevViewData = [];
  8383. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8384. }
  8385. extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement);
  8386. SVGShapeElement.prototype.initSecondaryElement = function () {};
  8387. SVGShapeElement.prototype.identityMatrix = new Matrix();
  8388. SVGShapeElement.prototype.buildExpressionInterface = function () {};
  8389. SVGShapeElement.prototype.createContent = function () {
  8390. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8391. this.filterUniqueShapes();
  8392. };
  8393. /*
  8394. This method searches for multiple shapes that affect a single element and one of them is animated
  8395. */
  8396. SVGShapeElement.prototype.filterUniqueShapes = function () {
  8397. var i;
  8398. var len = this.shapes.length;
  8399. var shape;
  8400. var j;
  8401. var jLen = this.stylesList.length;
  8402. var style;
  8403. var tempShapes = [];
  8404. var areAnimated = false;
  8405. for (j = 0; j < jLen; j += 1) {
  8406. style = this.stylesList[j];
  8407. areAnimated = false;
  8408. tempShapes.length = 0;
  8409. for (i = 0; i < len; i += 1) {
  8410. shape = this.shapes[i];
  8411. if (shape.styles.indexOf(style) !== -1) {
  8412. tempShapes.push(shape);
  8413. areAnimated = shape._isAnimated || areAnimated;
  8414. }
  8415. }
  8416. if (tempShapes.length > 1 && areAnimated) {
  8417. this.setShapesAsAnimated(tempShapes);
  8418. }
  8419. }
  8420. };
  8421. SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) {
  8422. var i;
  8423. var len = shapes.length;
  8424. for (i = 0; i < len; i += 1) {
  8425. shapes[i].setAsAnimated();
  8426. }
  8427. };
  8428. SVGShapeElement.prototype.createStyleElement = function (data, level) {
  8429. // TODO: prevent drawing of hidden styles
  8430. var elementData;
  8431. var styleOb = new SVGStyleData(data, level);
  8432. var pathElement = styleOb.pElem;
  8433. if (data.ty === 'st') {
  8434. elementData = new SVGStrokeStyleData(this, data, styleOb);
  8435. } else if (data.ty === 'fl') {
  8436. elementData = new SVGFillStyleData(this, data, styleOb);
  8437. } else if (data.ty === 'gf' || data.ty === 'gs') {
  8438. var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  8439. elementData = new GradientConstructor(this, data, styleOb);
  8440. this.globalData.defs.appendChild(elementData.gf);
  8441. if (elementData.maskId) {
  8442. this.globalData.defs.appendChild(elementData.ms);
  8443. this.globalData.defs.appendChild(elementData.of);
  8444. pathElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + elementData.maskId + ')');
  8445. }
  8446. } else if (data.ty === 'no') {
  8447. elementData = new SVGNoStyleData(this, data, styleOb);
  8448. }
  8449. if (data.ty === 'st' || data.ty === 'gs') {
  8450. pathElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8451. pathElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8452. pathElement.setAttribute('fill-opacity', '0');
  8453. if (data.lj === 1) {
  8454. pathElement.setAttribute('stroke-miterlimit', data.ml);
  8455. }
  8456. }
  8457. if (data.r === 2) {
  8458. pathElement.setAttribute('fill-rule', 'evenodd');
  8459. }
  8460. if (data.ln) {
  8461. pathElement.setAttribute('id', data.ln);
  8462. }
  8463. if (data.cl) {
  8464. pathElement.setAttribute('class', data.cl);
  8465. }
  8466. if (data.bm) {
  8467. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  8468. }
  8469. this.stylesList.push(styleOb);
  8470. this.addToAnimatedContents(data, elementData);
  8471. return elementData;
  8472. };
  8473. SVGShapeElement.prototype.createGroupElement = function (data) {
  8474. var elementData = new ShapeGroupData();
  8475. if (data.ln) {
  8476. elementData.gr.setAttribute('id', data.ln);
  8477. }
  8478. if (data.cl) {
  8479. elementData.gr.setAttribute('class', data.cl);
  8480. }
  8481. if (data.bm) {
  8482. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  8483. }
  8484. return elementData;
  8485. };
  8486. SVGShapeElement.prototype.createTransformElement = function (data, container) {
  8487. var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this);
  8488. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  8489. this.addToAnimatedContents(data, elementData);
  8490. return elementData;
  8491. };
  8492. SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) {
  8493. var ty = 4;
  8494. if (data.ty === 'rc') {
  8495. ty = 5;
  8496. } else if (data.ty === 'el') {
  8497. ty = 6;
  8498. } else if (data.ty === 'sr') {
  8499. ty = 7;
  8500. }
  8501. var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this);
  8502. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  8503. this.shapes.push(elementData);
  8504. this.addShapeToModifiers(elementData);
  8505. this.addToAnimatedContents(data, elementData);
  8506. return elementData;
  8507. };
  8508. SVGShapeElement.prototype.addToAnimatedContents = function (data, element) {
  8509. var i = 0;
  8510. var len = this.animatedContents.length;
  8511. while (i < len) {
  8512. if (this.animatedContents[i].element === element) {
  8513. return;
  8514. }
  8515. i += 1;
  8516. }
  8517. this.animatedContents.push({
  8518. fn: SVGElementsRenderer.createRenderFunction(data),
  8519. element: element,
  8520. data: data
  8521. });
  8522. };
  8523. SVGShapeElement.prototype.setElementStyles = function (elementData) {
  8524. var arr = elementData.styles;
  8525. var j;
  8526. var jLen = this.stylesList.length;
  8527. for (j = 0; j < jLen; j += 1) {
  8528. if (arr.indexOf(this.stylesList[j]) === -1 && !this.stylesList[j].closed) {
  8529. arr.push(this.stylesList[j]);
  8530. }
  8531. }
  8532. };
  8533. SVGShapeElement.prototype.reloadShapes = function () {
  8534. this._isFirstFrame = true;
  8535. var i;
  8536. var len = this.itemsData.length;
  8537. for (i = 0; i < len; i += 1) {
  8538. this.prevViewData[i] = this.itemsData[i];
  8539. }
  8540. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8541. this.filterUniqueShapes();
  8542. len = this.dynamicProperties.length;
  8543. for (i = 0; i < len; i += 1) {
  8544. this.dynamicProperties[i].getValue();
  8545. }
  8546. this.renderModifiers();
  8547. };
  8548. SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) {
  8549. var ownTransformers = [].concat(transformers);
  8550. var i;
  8551. var len = arr.length - 1;
  8552. var j;
  8553. var jLen;
  8554. var ownStyles = [];
  8555. var ownModifiers = [];
  8556. var currentTransform;
  8557. var modifier;
  8558. var processedPos;
  8559. for (i = len; i >= 0; i -= 1) {
  8560. processedPos = this.searchProcessedElement(arr[i]);
  8561. if (!processedPos) {
  8562. arr[i]._render = render;
  8563. } else {
  8564. itemsData[i] = prevViewData[processedPos - 1];
  8565. }
  8566. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs' || arr[i].ty === 'no') {
  8567. if (!processedPos) {
  8568. itemsData[i] = this.createStyleElement(arr[i], level);
  8569. } else {
  8570. itemsData[i].style.closed = arr[i].hd;
  8571. }
  8572. if (arr[i]._render) {
  8573. if (itemsData[i].style.pElem.parentNode !== container) {
  8574. container.appendChild(itemsData[i].style.pElem);
  8575. }
  8576. }
  8577. ownStyles.push(itemsData[i].style);
  8578. } else if (arr[i].ty === 'gr') {
  8579. if (!processedPos) {
  8580. itemsData[i] = this.createGroupElement(arr[i]);
  8581. } else {
  8582. jLen = itemsData[i].it.length;
  8583. for (j = 0; j < jLen; j += 1) {
  8584. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  8585. }
  8586. }
  8587. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render);
  8588. if (arr[i]._render) {
  8589. if (itemsData[i].gr.parentNode !== container) {
  8590. container.appendChild(itemsData[i].gr);
  8591. }
  8592. }
  8593. } else if (arr[i].ty === 'tr') {
  8594. if (!processedPos) {
  8595. itemsData[i] = this.createTransformElement(arr[i], container);
  8596. }
  8597. currentTransform = itemsData[i].transform;
  8598. ownTransformers.push(currentTransform);
  8599. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  8600. if (!processedPos) {
  8601. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  8602. }
  8603. this.setElementStyles(itemsData[i]);
  8604. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'ms' || arr[i].ty === 'pb' || arr[i].ty === 'zz' || arr[i].ty === 'op') {
  8605. if (!processedPos) {
  8606. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8607. modifier.init(this, arr[i]);
  8608. itemsData[i] = modifier;
  8609. this.shapeModifiers.push(modifier);
  8610. } else {
  8611. modifier = itemsData[i];
  8612. modifier.closed = false;
  8613. }
  8614. ownModifiers.push(modifier);
  8615. } else if (arr[i].ty === 'rp') {
  8616. if (!processedPos) {
  8617. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8618. itemsData[i] = modifier;
  8619. modifier.init(this, arr, i, itemsData);
  8620. this.shapeModifiers.push(modifier);
  8621. render = false;
  8622. } else {
  8623. modifier = itemsData[i];
  8624. modifier.closed = true;
  8625. }
  8626. ownModifiers.push(modifier);
  8627. }
  8628. this.addProcessedElement(arr[i], i + 1);
  8629. }
  8630. len = ownStyles.length;
  8631. for (i = 0; i < len; i += 1) {
  8632. ownStyles[i].closed = true;
  8633. }
  8634. len = ownModifiers.length;
  8635. for (i = 0; i < len; i += 1) {
  8636. ownModifiers[i].closed = true;
  8637. }
  8638. };
  8639. SVGShapeElement.prototype.renderInnerContent = function () {
  8640. this.renderModifiers();
  8641. var i;
  8642. var len = this.stylesList.length;
  8643. for (i = 0; i < len; i += 1) {
  8644. this.stylesList[i].reset();
  8645. }
  8646. this.renderShape();
  8647. for (i = 0; i < len; i += 1) {
  8648. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  8649. if (this.stylesList[i].msElem) {
  8650. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d);
  8651. // Adding M0 0 fixes same mask bug on all browsers
  8652. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  8653. }
  8654. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  8655. }
  8656. }
  8657. };
  8658. SVGShapeElement.prototype.renderShape = function () {
  8659. var i;
  8660. var len = this.animatedContents.length;
  8661. var animatedContent;
  8662. for (i = 0; i < len; i += 1) {
  8663. animatedContent = this.animatedContents[i];
  8664. if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  8665. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  8666. }
  8667. }
  8668. };
  8669. SVGShapeElement.prototype.destroy = function () {
  8670. this.destroyBaseElement();
  8671. this.shapesData = null;
  8672. this.itemsData = null;
  8673. };
  8674. function LetterProps(o, sw, sc, fc, m, p) {
  8675. this.o = o;
  8676. this.sw = sw;
  8677. this.sc = sc;
  8678. this.fc = fc;
  8679. this.m = m;
  8680. this.p = p;
  8681. this._mdf = {
  8682. o: true,
  8683. sw: !!sw,
  8684. sc: !!sc,
  8685. fc: !!fc,
  8686. m: true,
  8687. p: true
  8688. };
  8689. }
  8690. LetterProps.prototype.update = function (o, sw, sc, fc, m, p) {
  8691. this._mdf.o = false;
  8692. this._mdf.sw = false;
  8693. this._mdf.sc = false;
  8694. this._mdf.fc = false;
  8695. this._mdf.m = false;
  8696. this._mdf.p = false;
  8697. var updated = false;
  8698. if (this.o !== o) {
  8699. this.o = o;
  8700. this._mdf.o = true;
  8701. updated = true;
  8702. }
  8703. if (this.sw !== sw) {
  8704. this.sw = sw;
  8705. this._mdf.sw = true;
  8706. updated = true;
  8707. }
  8708. if (this.sc !== sc) {
  8709. this.sc = sc;
  8710. this._mdf.sc = true;
  8711. updated = true;
  8712. }
  8713. if (this.fc !== fc) {
  8714. this.fc = fc;
  8715. this._mdf.fc = true;
  8716. updated = true;
  8717. }
  8718. if (this.m !== m) {
  8719. this.m = m;
  8720. this._mdf.m = true;
  8721. updated = true;
  8722. }
  8723. if (p.length && (this.p[0] !== p[0] || this.p[1] !== p[1] || this.p[4] !== p[4] || this.p[5] !== p[5] || this.p[12] !== p[12] || this.p[13] !== p[13])) {
  8724. this.p = p;
  8725. this._mdf.p = true;
  8726. updated = true;
  8727. }
  8728. return updated;
  8729. };
  8730. function TextProperty(elem, data) {
  8731. this._frameId = initialDefaultFrame;
  8732. this.pv = '';
  8733. this.v = '';
  8734. this.kf = false;
  8735. this._isFirstFrame = true;
  8736. this._mdf = false;
  8737. if (data.d && data.d.sid) {
  8738. data.d = elem.globalData.slotManager.getProp(data.d);
  8739. }
  8740. this.data = data;
  8741. this.elem = elem;
  8742. this.comp = this.elem.comp;
  8743. this.keysIndex = 0;
  8744. this.canResize = false;
  8745. this.minimumFontSize = 1;
  8746. this.effectsSequence = [];
  8747. this.currentData = {
  8748. ascent: 0,
  8749. boxWidth: this.defaultBoxWidth,
  8750. f: '',
  8751. fStyle: '',
  8752. fWeight: '',
  8753. fc: '',
  8754. j: '',
  8755. justifyOffset: '',
  8756. l: [],
  8757. lh: 0,
  8758. lineWidths: [],
  8759. ls: '',
  8760. of: '',
  8761. s: '',
  8762. sc: '',
  8763. sw: 0,
  8764. t: 0,
  8765. tr: 0,
  8766. sz: 0,
  8767. ps: null,
  8768. fillColorAnim: false,
  8769. strokeColorAnim: false,
  8770. strokeWidthAnim: false,
  8771. yOffset: 0,
  8772. finalSize: 0,
  8773. finalText: [],
  8774. finalLineHeight: 0,
  8775. __complete: false
  8776. };
  8777. this.copyData(this.currentData, this.data.d.k[0].s);
  8778. if (!this.searchProperty()) {
  8779. this.completeTextData(this.currentData);
  8780. }
  8781. }
  8782. TextProperty.prototype.defaultBoxWidth = [0, 0];
  8783. TextProperty.prototype.copyData = function (obj, data) {
  8784. for (var s in data) {
  8785. if (Object.prototype.hasOwnProperty.call(data, s)) {
  8786. obj[s] = data[s];
  8787. }
  8788. }
  8789. return obj;
  8790. };
  8791. TextProperty.prototype.setCurrentData = function (data) {
  8792. if (!data.__complete) {
  8793. this.completeTextData(data);
  8794. }
  8795. this.currentData = data;
  8796. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  8797. this._mdf = true;
  8798. };
  8799. TextProperty.prototype.searchProperty = function () {
  8800. return this.searchKeyframes();
  8801. };
  8802. TextProperty.prototype.searchKeyframes = function () {
  8803. this.kf = this.data.d.k.length > 1;
  8804. if (this.kf) {
  8805. this.addEffect(this.getKeyframeValue.bind(this));
  8806. }
  8807. return this.kf;
  8808. };
  8809. TextProperty.prototype.addEffect = function (effectFunction) {
  8810. this.effectsSequence.push(effectFunction);
  8811. this.elem.addDynamicProperty(this);
  8812. };
  8813. TextProperty.prototype.getValue = function (_finalValue) {
  8814. if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  8815. return;
  8816. }
  8817. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  8818. var currentValue = this.currentData;
  8819. var currentIndex = this.keysIndex;
  8820. if (this.lock) {
  8821. this.setCurrentData(this.currentData);
  8822. return;
  8823. }
  8824. this.lock = true;
  8825. this._mdf = false;
  8826. var i;
  8827. var len = this.effectsSequence.length;
  8828. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  8829. for (i = 0; i < len; i += 1) {
  8830. // Checking if index changed to prevent creating a new object every time the expression updates.
  8831. if (currentIndex !== this.keysIndex) {
  8832. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  8833. } else {
  8834. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  8835. }
  8836. }
  8837. if (currentValue !== finalValue) {
  8838. this.setCurrentData(finalValue);
  8839. }
  8840. this.v = this.currentData;
  8841. this.pv = this.v;
  8842. this.lock = false;
  8843. this.frameId = this.elem.globalData.frameId;
  8844. };
  8845. TextProperty.prototype.getKeyframeValue = function () {
  8846. var textKeys = this.data.d.k;
  8847. var frameNum = this.elem.comp.renderedFrame;
  8848. var i = 0;
  8849. var len = textKeys.length;
  8850. while (i <= len - 1) {
  8851. if (i === len - 1 || textKeys[i + 1].t > frameNum) {
  8852. break;
  8853. }
  8854. i += 1;
  8855. }
  8856. if (this.keysIndex !== i) {
  8857. this.keysIndex = i;
  8858. }
  8859. return this.data.d.k[this.keysIndex].s;
  8860. };
  8861. TextProperty.prototype.buildFinalText = function (text) {
  8862. var charactersArray = [];
  8863. var i = 0;
  8864. var len = text.length;
  8865. var charCode;
  8866. var secondCharCode;
  8867. var shouldCombine = false;
  8868. var shouldCombineNext = false;
  8869. var currentChars = '';
  8870. while (i < len) {
  8871. shouldCombine = shouldCombineNext;
  8872. shouldCombineNext = false;
  8873. charCode = text.charCodeAt(i);
  8874. currentChars = text.charAt(i);
  8875. if (FontManager.isCombinedCharacter(charCode)) {
  8876. shouldCombine = true;
  8877. // It's a potential surrogate pair (this is the High surrogate)
  8878. } else if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  8879. if (FontManager.isRegionalFlag(text, i)) {
  8880. currentChars = text.substr(i, 14);
  8881. } else {
  8882. secondCharCode = text.charCodeAt(i + 1);
  8883. // It's a surrogate pair (this is the Low surrogate)
  8884. if (secondCharCode >= 0xDC00 && secondCharCode <= 0xDFFF) {
  8885. if (FontManager.isModifier(charCode, secondCharCode)) {
  8886. currentChars = text.substr(i, 2);
  8887. shouldCombine = true;
  8888. } else if (FontManager.isFlagEmoji(text.substr(i, 4))) {
  8889. currentChars = text.substr(i, 4);
  8890. } else {
  8891. currentChars = text.substr(i, 2);
  8892. }
  8893. }
  8894. }
  8895. } else if (charCode > 0xDBFF) {
  8896. secondCharCode = text.charCodeAt(i + 1);
  8897. if (FontManager.isVariationSelector(charCode)) {
  8898. shouldCombine = true;
  8899. }
  8900. } else if (FontManager.isZeroWidthJoiner(charCode)) {
  8901. shouldCombine = true;
  8902. shouldCombineNext = true;
  8903. }
  8904. if (shouldCombine) {
  8905. charactersArray[charactersArray.length - 1] += currentChars;
  8906. shouldCombine = false;
  8907. } else {
  8908. charactersArray.push(currentChars);
  8909. }
  8910. i += currentChars.length;
  8911. }
  8912. return charactersArray;
  8913. };
  8914. TextProperty.prototype.completeTextData = function (documentData) {
  8915. documentData.__complete = true;
  8916. var fontManager = this.elem.globalData.fontManager;
  8917. var data = this.data;
  8918. var letters = [];
  8919. var i;
  8920. var len;
  8921. var newLineFlag;
  8922. var index = 0;
  8923. var val;
  8924. var anchorGrouping = data.m.g;
  8925. var currentSize = 0;
  8926. var currentPos = 0;
  8927. var currentLine = 0;
  8928. var lineWidths = [];
  8929. var lineWidth = 0;
  8930. var maxLineWidth = 0;
  8931. var j;
  8932. var jLen;
  8933. var fontData = fontManager.getFontByName(documentData.f);
  8934. var charData;
  8935. var cLength = 0;
  8936. var fontProps = getFontProperties(fontData);
  8937. documentData.fWeight = fontProps.weight;
  8938. documentData.fStyle = fontProps.style;
  8939. documentData.finalSize = documentData.s;
  8940. documentData.finalText = this.buildFinalText(documentData.t);
  8941. len = documentData.finalText.length;
  8942. documentData.finalLineHeight = documentData.lh;
  8943. var trackingOffset = documentData.tr / 1000 * documentData.finalSize;
  8944. var charCode;
  8945. if (documentData.sz) {
  8946. var flag = true;
  8947. var boxWidth = documentData.sz[0];
  8948. var boxHeight = documentData.sz[1];
  8949. var currentHeight;
  8950. var finalText;
  8951. while (flag) {
  8952. finalText = this.buildFinalText(documentData.t);
  8953. currentHeight = 0;
  8954. lineWidth = 0;
  8955. len = finalText.length;
  8956. trackingOffset = documentData.tr / 1000 * documentData.finalSize;
  8957. var lastSpaceIndex = -1;
  8958. for (i = 0; i < len; i += 1) {
  8959. charCode = finalText[i].charCodeAt(0);
  8960. newLineFlag = false;
  8961. if (finalText[i] === ' ') {
  8962. lastSpaceIndex = i;
  8963. } else if (charCode === 13 || charCode === 3) {
  8964. lineWidth = 0;
  8965. newLineFlag = true;
  8966. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8967. }
  8968. if (fontManager.chars) {
  8969. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  8970. cLength = newLineFlag ? 0 : charData.w * documentData.finalSize / 100;
  8971. } else {
  8972. // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  8973. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  8974. }
  8975. if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') {
  8976. if (lastSpaceIndex === -1) {
  8977. len += 1;
  8978. } else {
  8979. i = lastSpaceIndex;
  8980. }
  8981. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8982. finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r');
  8983. // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  8984. lastSpaceIndex = -1;
  8985. lineWidth = 0;
  8986. } else {
  8987. lineWidth += cLength;
  8988. lineWidth += trackingOffset;
  8989. }
  8990. }
  8991. currentHeight += fontData.ascent * documentData.finalSize / 100;
  8992. if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  8993. documentData.finalSize -= 1;
  8994. documentData.finalLineHeight = documentData.finalSize * documentData.lh / documentData.s;
  8995. } else {
  8996. documentData.finalText = finalText;
  8997. len = documentData.finalText.length;
  8998. flag = false;
  8999. }
  9000. }
  9001. }
  9002. lineWidth = -trackingOffset;
  9003. cLength = 0;
  9004. var uncollapsedSpaces = 0;
  9005. var currentChar;
  9006. for (i = 0; i < len; i += 1) {
  9007. newLineFlag = false;
  9008. currentChar = documentData.finalText[i];
  9009. charCode = currentChar.charCodeAt(0);
  9010. if (charCode === 13 || charCode === 3) {
  9011. uncollapsedSpaces = 0;
  9012. lineWidths.push(lineWidth);
  9013. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9014. lineWidth = -2 * trackingOffset;
  9015. val = '';
  9016. newLineFlag = true;
  9017. currentLine += 1;
  9018. } else {
  9019. val = currentChar;
  9020. }
  9021. if (fontManager.chars) {
  9022. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  9023. cLength = newLineFlag ? 0 : charData.w * documentData.finalSize / 100;
  9024. } else {
  9025. // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9026. // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  9027. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9028. }
  9029. //
  9030. if (currentChar === ' ') {
  9031. uncollapsedSpaces += cLength + trackingOffset;
  9032. } else {
  9033. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  9034. uncollapsedSpaces = 0;
  9035. }
  9036. letters.push({
  9037. l: cLength,
  9038. an: cLength,
  9039. add: currentSize,
  9040. n: newLineFlag,
  9041. anIndexes: [],
  9042. val: val,
  9043. line: currentLine,
  9044. animatorJustifyOffset: 0
  9045. });
  9046. if (anchorGrouping == 2) {
  9047. // eslint-disable-line eqeqeq
  9048. currentSize += cLength;
  9049. if (val === '' || val === ' ' || i === len - 1) {
  9050. if (val === '' || val === ' ') {
  9051. currentSize -= cLength;
  9052. }
  9053. while (currentPos <= i) {
  9054. letters[currentPos].an = currentSize;
  9055. letters[currentPos].ind = index;
  9056. letters[currentPos].extra = cLength;
  9057. currentPos += 1;
  9058. }
  9059. index += 1;
  9060. currentSize = 0;
  9061. }
  9062. } else if (anchorGrouping == 3) {
  9063. // eslint-disable-line eqeqeq
  9064. currentSize += cLength;
  9065. if (val === '' || i === len - 1) {
  9066. if (val === '') {
  9067. currentSize -= cLength;
  9068. }
  9069. while (currentPos <= i) {
  9070. letters[currentPos].an = currentSize;
  9071. letters[currentPos].ind = index;
  9072. letters[currentPos].extra = cLength;
  9073. currentPos += 1;
  9074. }
  9075. currentSize = 0;
  9076. index += 1;
  9077. }
  9078. } else {
  9079. letters[index].ind = index;
  9080. letters[index].extra = 0;
  9081. index += 1;
  9082. }
  9083. }
  9084. documentData.l = letters;
  9085. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9086. lineWidths.push(lineWidth);
  9087. if (documentData.sz) {
  9088. documentData.boxWidth = documentData.sz[0];
  9089. documentData.justifyOffset = 0;
  9090. } else {
  9091. documentData.boxWidth = maxLineWidth;
  9092. switch (documentData.j) {
  9093. case 1:
  9094. documentData.justifyOffset = -documentData.boxWidth;
  9095. break;
  9096. case 2:
  9097. documentData.justifyOffset = -documentData.boxWidth / 2;
  9098. break;
  9099. default:
  9100. documentData.justifyOffset = 0;
  9101. }
  9102. }
  9103. documentData.lineWidths = lineWidths;
  9104. var animators = data.a;
  9105. var animatorData;
  9106. var letterData;
  9107. jLen = animators.length;
  9108. var based;
  9109. var ind;
  9110. var indexes = [];
  9111. for (j = 0; j < jLen; j += 1) {
  9112. animatorData = animators[j];
  9113. if (animatorData.a.sc) {
  9114. documentData.strokeColorAnim = true;
  9115. }
  9116. if (animatorData.a.sw) {
  9117. documentData.strokeWidthAnim = true;
  9118. }
  9119. if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) {
  9120. documentData.fillColorAnim = true;
  9121. }
  9122. ind = 0;
  9123. based = animatorData.s.b;
  9124. for (i = 0; i < len; i += 1) {
  9125. letterData = letters[i];
  9126. letterData.anIndexes[j] = ind;
  9127. if (based == 1 && letterData.val !== '' || based == 2 && letterData.val !== '' && letterData.val !== ' ' || based == 3 && (letterData.n || letterData.val == ' ' || i == len - 1) || based == 4 && (letterData.n || i == len - 1)) {
  9128. // eslint-disable-line eqeqeq
  9129. if (animatorData.s.rn === 1) {
  9130. indexes.push(ind);
  9131. }
  9132. ind += 1;
  9133. }
  9134. }
  9135. data.a[j].s.totalChars = ind;
  9136. var currentInd = -1;
  9137. var newInd;
  9138. if (animatorData.s.rn === 1) {
  9139. for (i = 0; i < len; i += 1) {
  9140. letterData = letters[i];
  9141. if (currentInd != letterData.anIndexes[j]) {
  9142. // eslint-disable-line eqeqeq
  9143. currentInd = letterData.anIndexes[j];
  9144. newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0];
  9145. }
  9146. letterData.anIndexes[j] = newInd;
  9147. }
  9148. }
  9149. }
  9150. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2;
  9151. documentData.ls = documentData.ls || 0;
  9152. documentData.ascent = fontData.ascent * documentData.finalSize / 100;
  9153. };
  9154. TextProperty.prototype.updateDocumentData = function (newData, index) {
  9155. index = index === undefined ? this.keysIndex : index;
  9156. var dData = this.copyData({}, this.data.d.k[index].s);
  9157. dData = this.copyData(dData, newData);
  9158. this.data.d.k[index].s = dData;
  9159. this.recalculate(index);
  9160. this.setCurrentData(dData);
  9161. this.elem.addDynamicProperty(this);
  9162. };
  9163. TextProperty.prototype.recalculate = function (index) {
  9164. var dData = this.data.d.k[index].s;
  9165. dData.__complete = false;
  9166. this.keysIndex = 0;
  9167. this._isFirstFrame = true;
  9168. this.getValue(dData);
  9169. };
  9170. TextProperty.prototype.canResizeFont = function (_canResize) {
  9171. this.canResize = _canResize;
  9172. this.recalculate(this.keysIndex);
  9173. this.elem.addDynamicProperty(this);
  9174. };
  9175. TextProperty.prototype.setMinimumFontSize = function (_fontValue) {
  9176. this.minimumFontSize = Math.floor(_fontValue) || 1;
  9177. this.recalculate(this.keysIndex);
  9178. this.elem.addDynamicProperty(this);
  9179. };
  9180. var TextSelectorProp = function () {
  9181. var max = Math.max;
  9182. var min = Math.min;
  9183. var floor = Math.floor;
  9184. function TextSelectorPropFactory(elem, data) {
  9185. this._currentTextLength = -1;
  9186. this.k = false;
  9187. this.data = data;
  9188. this.elem = elem;
  9189. this.comp = elem.comp;
  9190. this.finalS = 0;
  9191. this.finalE = 0;
  9192. this.initDynamicPropertyContainer(elem);
  9193. this.s = PropertyFactory.getProp(elem, data.s || {
  9194. k: 0
  9195. }, 0, 0, this);
  9196. if ('e' in data) {
  9197. this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this);
  9198. } else {
  9199. this.e = {
  9200. v: 100
  9201. };
  9202. }
  9203. this.o = PropertyFactory.getProp(elem, data.o || {
  9204. k: 0
  9205. }, 0, 0, this);
  9206. this.xe = PropertyFactory.getProp(elem, data.xe || {
  9207. k: 0
  9208. }, 0, 0, this);
  9209. this.ne = PropertyFactory.getProp(elem, data.ne || {
  9210. k: 0
  9211. }, 0, 0, this);
  9212. this.sm = PropertyFactory.getProp(elem, data.sm || {
  9213. k: 100
  9214. }, 0, 0, this);
  9215. this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this);
  9216. if (!this.dynamicProperties.length) {
  9217. this.getValue();
  9218. }
  9219. }
  9220. TextSelectorPropFactory.prototype = {
  9221. getMult: function getMult(ind) {
  9222. if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  9223. this.getValue();
  9224. }
  9225. var x1 = 0;
  9226. var y1 = 0;
  9227. var x2 = 1;
  9228. var y2 = 1;
  9229. if (this.ne.v > 0) {
  9230. x1 = this.ne.v / 100.0;
  9231. } else {
  9232. y1 = -this.ne.v / 100.0;
  9233. }
  9234. if (this.xe.v > 0) {
  9235. x2 = 1.0 - this.xe.v / 100.0;
  9236. } else {
  9237. y2 = 1.0 + this.xe.v / 100.0;
  9238. }
  9239. var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
  9240. var mult = 0;
  9241. var s = this.finalS;
  9242. var e = this.finalE;
  9243. var type = this.data.sh;
  9244. if (type === 2) {
  9245. if (e === s) {
  9246. mult = ind >= e ? 1 : 0;
  9247. } else {
  9248. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9249. }
  9250. mult = easer(mult);
  9251. } else if (type === 3) {
  9252. if (e === s) {
  9253. mult = ind >= e ? 0 : 1;
  9254. } else {
  9255. mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9256. }
  9257. mult = easer(mult);
  9258. } else if (type === 4) {
  9259. if (e === s) {
  9260. mult = 0;
  9261. } else {
  9262. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9263. if (mult < 0.5) {
  9264. mult *= 2;
  9265. } else {
  9266. mult = 1 - 2 * (mult - 0.5);
  9267. }
  9268. }
  9269. mult = easer(mult);
  9270. } else if (type === 5) {
  9271. if (e === s) {
  9272. mult = 0;
  9273. } else {
  9274. var tot = e - s;
  9275. /* ind += 0.5;
  9276. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */
  9277. ind = min(max(0, ind + 0.5 - s), e - s);
  9278. var x = -tot / 2 + ind;
  9279. var a = tot / 2;
  9280. mult = Math.sqrt(1 - x * x / (a * a));
  9281. }
  9282. mult = easer(mult);
  9283. } else if (type === 6) {
  9284. if (e === s) {
  9285. mult = 0;
  9286. } else {
  9287. ind = min(max(0, ind + 0.5 - s), e - s);
  9288. mult = (1 + Math.cos(Math.PI + Math.PI * 2 * ind / (e - s))) / 2; // eslint-disable-line
  9289. }
  9290. mult = easer(mult);
  9291. } else {
  9292. if (ind >= floor(s)) {
  9293. if (ind - s < 0) {
  9294. mult = max(0, min(min(e, 1) - (s - ind), 1));
  9295. } else {
  9296. mult = max(0, min(e - ind, 1));
  9297. }
  9298. }
  9299. mult = easer(mult);
  9300. }
  9301. // Smoothness implementation.
  9302. // The smoothness represents a reduced range of the original [0; 1] range.
  9303. // if smoothness is 25%, the new range will be [0.375; 0.625]
  9304. // Steps are:
  9305. // - find the lower value of the new range (threshold)
  9306. // - if multiplier is smaller than that value, floor it to 0
  9307. // - if it is larger,
  9308. // - subtract the threshold
  9309. // - divide it by the smoothness (this will return the range to [0; 1])
  9310. // Note: If it doesn't work on some scenarios, consider applying it before the easer.
  9311. if (this.sm.v !== 100) {
  9312. var smoothness = this.sm.v * 0.01;
  9313. if (smoothness === 0) {
  9314. smoothness = 0.00000001;
  9315. }
  9316. var threshold = 0.5 - smoothness * 0.5;
  9317. if (mult < threshold) {
  9318. mult = 0;
  9319. } else {
  9320. mult = (mult - threshold) / smoothness;
  9321. if (mult > 1) {
  9322. mult = 1;
  9323. }
  9324. }
  9325. }
  9326. return mult * this.a.v;
  9327. },
  9328. getValue: function getValue(newCharsFlag) {
  9329. this.iterateDynamicProperties();
  9330. this._mdf = newCharsFlag || this._mdf;
  9331. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  9332. if (newCharsFlag && this.data.r === 2) {
  9333. this.e.v = this._currentTextLength;
  9334. }
  9335. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  9336. var o = this.o.v / divisor;
  9337. var s = this.s.v / divisor + o;
  9338. var e = this.e.v / divisor + o;
  9339. if (s > e) {
  9340. var _s = s;
  9341. s = e;
  9342. e = _s;
  9343. }
  9344. this.finalS = s;
  9345. this.finalE = e;
  9346. }
  9347. };
  9348. extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory);
  9349. function getTextSelectorProp(elem, data, arr) {
  9350. return new TextSelectorPropFactory(elem, data, arr);
  9351. }
  9352. return {
  9353. getTextSelectorProp: getTextSelectorProp
  9354. };
  9355. }();
  9356. function TextAnimatorDataProperty(elem, animatorProps, container) {
  9357. var defaultData = {
  9358. propType: false
  9359. };
  9360. var getProp = PropertyFactory.getProp;
  9361. var textAnimatorAnimatables = animatorProps.a;
  9362. this.a = {
  9363. r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData,
  9364. rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData,
  9365. ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData,
  9366. sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData,
  9367. sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData,
  9368. s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData,
  9369. a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData,
  9370. o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData,
  9371. p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData,
  9372. sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData,
  9373. sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData,
  9374. fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData,
  9375. fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData,
  9376. fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData,
  9377. fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData,
  9378. t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData
  9379. };
  9380. this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container);
  9381. this.s.t = animatorProps.s.t;
  9382. }
  9383. function TextAnimatorProperty(textData, renderType, elem) {
  9384. this._isFirstFrame = true;
  9385. this._hasMaskedPath = false;
  9386. this._frameId = -1;
  9387. this._textData = textData;
  9388. this._renderType = renderType;
  9389. this._elem = elem;
  9390. this._animatorsData = createSizedArray(this._textData.a.length);
  9391. this._pathData = {};
  9392. this._moreOptions = {
  9393. alignment: {}
  9394. };
  9395. this.renderedLetters = [];
  9396. this.lettersChangedFlag = false;
  9397. this.initDynamicPropertyContainer(elem);
  9398. }
  9399. TextAnimatorProperty.prototype.searchProperties = function () {
  9400. var i;
  9401. var len = this._textData.a.length;
  9402. var animatorProps;
  9403. var getProp = PropertyFactory.getProp;
  9404. for (i = 0; i < len; i += 1) {
  9405. animatorProps = this._textData.a[i];
  9406. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  9407. }
  9408. if (this._textData.p && 'm' in this._textData.p) {
  9409. this._pathData = {
  9410. a: getProp(this._elem, this._textData.p.a, 0, 0, this),
  9411. f: getProp(this._elem, this._textData.p.f, 0, 0, this),
  9412. l: getProp(this._elem, this._textData.p.l, 0, 0, this),
  9413. r: getProp(this._elem, this._textData.p.r, 0, 0, this),
  9414. p: getProp(this._elem, this._textData.p.p, 0, 0, this),
  9415. m: this._elem.maskManager.getMaskProperty(this._textData.p.m)
  9416. };
  9417. this._hasMaskedPath = true;
  9418. } else {
  9419. this._hasMaskedPath = false;
  9420. }
  9421. this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this);
  9422. };
  9423. TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) {
  9424. this.lettersChangedFlag = lettersChangedFlag;
  9425. if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  9426. return;
  9427. }
  9428. this._isFirstFrame = false;
  9429. var alignment = this._moreOptions.alignment.v;
  9430. var animators = this._animatorsData;
  9431. var textData = this._textData;
  9432. var matrixHelper = this.mHelper;
  9433. var renderType = this._renderType;
  9434. var renderedLettersCount = this.renderedLetters.length;
  9435. var xPos;
  9436. var yPos;
  9437. var i;
  9438. var len;
  9439. var letters = documentData.l;
  9440. var pathInfo;
  9441. var currentLength;
  9442. var currentPoint;
  9443. var segmentLength;
  9444. var flag;
  9445. var pointInd;
  9446. var segmentInd;
  9447. var prevPoint;
  9448. var points;
  9449. var segments;
  9450. var partialLength;
  9451. var totalLength;
  9452. var perc;
  9453. var tanAngle;
  9454. var mask;
  9455. if (this._hasMaskedPath) {
  9456. mask = this._pathData.m;
  9457. if (!this._pathData.n || this._pathData._mdf) {
  9458. var paths = mask.v;
  9459. if (this._pathData.r.v) {
  9460. paths = paths.reverse();
  9461. }
  9462. // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  9463. pathInfo = {
  9464. tLength: 0,
  9465. segments: []
  9466. };
  9467. len = paths._length - 1;
  9468. var bezierData;
  9469. totalLength = 0;
  9470. for (i = 0; i < len; i += 1) {
  9471. bezierData = bez.buildBezierData(paths.v[i], paths.v[i + 1], [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  9472. pathInfo.tLength += bezierData.segmentLength;
  9473. pathInfo.segments.push(bezierData);
  9474. totalLength += bezierData.segmentLength;
  9475. }
  9476. i = len;
  9477. if (mask.v.c) {
  9478. bezierData = bez.buildBezierData(paths.v[i], paths.v[0], [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  9479. pathInfo.tLength += bezierData.segmentLength;
  9480. pathInfo.segments.push(bezierData);
  9481. totalLength += bezierData.segmentLength;
  9482. }
  9483. this._pathData.pi = pathInfo;
  9484. }
  9485. pathInfo = this._pathData.pi;
  9486. currentLength = this._pathData.f.v;
  9487. segmentInd = 0;
  9488. pointInd = 1;
  9489. segmentLength = 0;
  9490. flag = true;
  9491. segments = pathInfo.segments;
  9492. if (currentLength < 0 && mask.v.c) {
  9493. if (pathInfo.tLength < Math.abs(currentLength)) {
  9494. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  9495. }
  9496. segmentInd = segments.length - 1;
  9497. points = segments[segmentInd].points;
  9498. pointInd = points.length - 1;
  9499. while (currentLength < 0) {
  9500. currentLength += points[pointInd].partialLength;
  9501. pointInd -= 1;
  9502. if (pointInd < 0) {
  9503. segmentInd -= 1;
  9504. points = segments[segmentInd].points;
  9505. pointInd = points.length - 1;
  9506. }
  9507. }
  9508. }
  9509. points = segments[segmentInd].points;
  9510. prevPoint = points[pointInd - 1];
  9511. currentPoint = points[pointInd];
  9512. partialLength = currentPoint.partialLength;
  9513. }
  9514. len = letters.length;
  9515. xPos = 0;
  9516. yPos = 0;
  9517. var yOff = documentData.finalSize * 1.2 * 0.714;
  9518. var firstLine = true;
  9519. var animatorProps;
  9520. var animatorSelector;
  9521. var j;
  9522. var jLen;
  9523. var letterValue;
  9524. jLen = animators.length;
  9525. var mult;
  9526. var ind = -1;
  9527. var offf;
  9528. var xPathPos;
  9529. var yPathPos;
  9530. var initPathPos = currentLength;
  9531. var initSegmentInd = segmentInd;
  9532. var initPointInd = pointInd;
  9533. var currentLine = -1;
  9534. var elemOpacity;
  9535. var sc;
  9536. var sw;
  9537. var fc;
  9538. var k;
  9539. var letterSw;
  9540. var letterSc;
  9541. var letterFc;
  9542. var letterM = '';
  9543. var letterP = this.defaultPropsArray;
  9544. var letterO;
  9545. //
  9546. if (documentData.j === 2 || documentData.j === 1) {
  9547. var animatorJustifyOffset = 0;
  9548. var animatorFirstCharOffset = 0;
  9549. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  9550. var lastIndex = 0;
  9551. var isNewLine = true;
  9552. for (i = 0; i < len; i += 1) {
  9553. if (letters[i].n) {
  9554. if (animatorJustifyOffset) {
  9555. animatorJustifyOffset += animatorFirstCharOffset;
  9556. }
  9557. while (lastIndex < i) {
  9558. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9559. lastIndex += 1;
  9560. }
  9561. animatorJustifyOffset = 0;
  9562. isNewLine = true;
  9563. } else {
  9564. for (j = 0; j < jLen; j += 1) {
  9565. animatorProps = animators[j].a;
  9566. if (animatorProps.t.propType) {
  9567. if (isNewLine && documentData.j === 2) {
  9568. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  9569. }
  9570. animatorSelector = animators[j].s;
  9571. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9572. if (mult.length) {
  9573. animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult;
  9574. } else {
  9575. animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult;
  9576. }
  9577. }
  9578. }
  9579. isNewLine = false;
  9580. }
  9581. }
  9582. if (animatorJustifyOffset) {
  9583. animatorJustifyOffset += animatorFirstCharOffset;
  9584. }
  9585. while (lastIndex < i) {
  9586. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9587. lastIndex += 1;
  9588. }
  9589. }
  9590. //
  9591. for (i = 0; i < len; i += 1) {
  9592. matrixHelper.reset();
  9593. elemOpacity = 1;
  9594. if (letters[i].n) {
  9595. xPos = 0;
  9596. yPos += documentData.yOffset;
  9597. yPos += firstLine ? 1 : 0;
  9598. currentLength = initPathPos;
  9599. firstLine = false;
  9600. if (this._hasMaskedPath) {
  9601. segmentInd = initSegmentInd;
  9602. pointInd = initPointInd;
  9603. points = segments[segmentInd].points;
  9604. prevPoint = points[pointInd - 1];
  9605. currentPoint = points[pointInd];
  9606. partialLength = currentPoint.partialLength;
  9607. segmentLength = 0;
  9608. }
  9609. letterM = '';
  9610. letterFc = '';
  9611. letterSw = '';
  9612. letterO = '';
  9613. letterP = this.defaultPropsArray;
  9614. } else {
  9615. if (this._hasMaskedPath) {
  9616. if (currentLine !== letters[i].line) {
  9617. switch (documentData.j) {
  9618. case 1:
  9619. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  9620. break;
  9621. case 2:
  9622. currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2;
  9623. break;
  9624. default:
  9625. break;
  9626. }
  9627. currentLine = letters[i].line;
  9628. }
  9629. if (ind !== letters[i].ind) {
  9630. if (letters[ind]) {
  9631. currentLength += letters[ind].extra;
  9632. }
  9633. currentLength += letters[i].an / 2;
  9634. ind = letters[i].ind;
  9635. }
  9636. currentLength += alignment[0] * letters[i].an * 0.005;
  9637. var animatorOffset = 0;
  9638. for (j = 0; j < jLen; j += 1) {
  9639. animatorProps = animators[j].a;
  9640. if (animatorProps.p.propType) {
  9641. animatorSelector = animators[j].s;
  9642. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9643. if (mult.length) {
  9644. animatorOffset += animatorProps.p.v[0] * mult[0];
  9645. } else {
  9646. animatorOffset += animatorProps.p.v[0] * mult;
  9647. }
  9648. }
  9649. if (animatorProps.a.propType) {
  9650. animatorSelector = animators[j].s;
  9651. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9652. if (mult.length) {
  9653. animatorOffset += animatorProps.a.v[0] * mult[0];
  9654. } else {
  9655. animatorOffset += animatorProps.a.v[0] * mult;
  9656. }
  9657. }
  9658. }
  9659. flag = true;
  9660. // Force alignment only works with a single line for now
  9661. if (this._pathData.a.v) {
  9662. currentLength = letters[0].an * 0.5 + (totalLength - this._pathData.f.v - letters[0].an * 0.5 - letters[letters.length - 1].an * 0.5) * ind / (len - 1);
  9663. currentLength += this._pathData.f.v;
  9664. }
  9665. while (flag) {
  9666. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  9667. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  9668. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  9669. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  9670. matrixHelper.translate(-alignment[0] * letters[i].an * 0.005, -(alignment[1] * yOff) * 0.01);
  9671. flag = false;
  9672. } else if (points) {
  9673. segmentLength += currentPoint.partialLength;
  9674. pointInd += 1;
  9675. if (pointInd >= points.length) {
  9676. pointInd = 0;
  9677. segmentInd += 1;
  9678. if (!segments[segmentInd]) {
  9679. if (mask.v.c) {
  9680. pointInd = 0;
  9681. segmentInd = 0;
  9682. points = segments[segmentInd].points;
  9683. } else {
  9684. segmentLength -= currentPoint.partialLength;
  9685. points = null;
  9686. }
  9687. } else {
  9688. points = segments[segmentInd].points;
  9689. }
  9690. }
  9691. if (points) {
  9692. prevPoint = currentPoint;
  9693. currentPoint = points[pointInd];
  9694. partialLength = currentPoint.partialLength;
  9695. }
  9696. }
  9697. }
  9698. offf = letters[i].an / 2 - letters[i].add;
  9699. matrixHelper.translate(-offf, 0, 0);
  9700. } else {
  9701. offf = letters[i].an / 2 - letters[i].add;
  9702. matrixHelper.translate(-offf, 0, 0);
  9703. // Grouping alignment
  9704. matrixHelper.translate(-alignment[0] * letters[i].an * 0.005, -alignment[1] * yOff * 0.01, 0);
  9705. }
  9706. for (j = 0; j < jLen; j += 1) {
  9707. animatorProps = animators[j].a;
  9708. if (animatorProps.t.propType) {
  9709. animatorSelector = animators[j].s;
  9710. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9711. // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  9712. if (xPos !== 0 || documentData.j !== 0) {
  9713. if (this._hasMaskedPath) {
  9714. if (mult.length) {
  9715. currentLength += animatorProps.t.v * mult[0];
  9716. } else {
  9717. currentLength += animatorProps.t.v * mult;
  9718. }
  9719. } else if (mult.length) {
  9720. xPos += animatorProps.t.v * mult[0];
  9721. } else {
  9722. xPos += animatorProps.t.v * mult;
  9723. }
  9724. }
  9725. }
  9726. }
  9727. if (documentData.strokeWidthAnim) {
  9728. sw = documentData.sw || 0;
  9729. }
  9730. if (documentData.strokeColorAnim) {
  9731. if (documentData.sc) {
  9732. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  9733. } else {
  9734. sc = [0, 0, 0];
  9735. }
  9736. }
  9737. if (documentData.fillColorAnim && documentData.fc) {
  9738. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  9739. }
  9740. for (j = 0; j < jLen; j += 1) {
  9741. animatorProps = animators[j].a;
  9742. if (animatorProps.a.propType) {
  9743. animatorSelector = animators[j].s;
  9744. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9745. if (mult.length) {
  9746. matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]);
  9747. } else {
  9748. matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult);
  9749. }
  9750. }
  9751. }
  9752. for (j = 0; j < jLen; j += 1) {
  9753. animatorProps = animators[j].a;
  9754. if (animatorProps.s.propType) {
  9755. animatorSelector = animators[j].s;
  9756. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9757. if (mult.length) {
  9758. matrixHelper.scale(1 + (animatorProps.s.v[0] - 1) * mult[0], 1 + (animatorProps.s.v[1] - 1) * mult[1], 1);
  9759. } else {
  9760. matrixHelper.scale(1 + (animatorProps.s.v[0] - 1) * mult, 1 + (animatorProps.s.v[1] - 1) * mult, 1);
  9761. }
  9762. }
  9763. }
  9764. for (j = 0; j < jLen; j += 1) {
  9765. animatorProps = animators[j].a;
  9766. animatorSelector = animators[j].s;
  9767. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9768. if (animatorProps.sk.propType) {
  9769. if (mult.length) {
  9770. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  9771. } else {
  9772. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  9773. }
  9774. }
  9775. if (animatorProps.r.propType) {
  9776. if (mult.length) {
  9777. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  9778. } else {
  9779. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  9780. }
  9781. }
  9782. if (animatorProps.ry.propType) {
  9783. if (mult.length) {
  9784. matrixHelper.rotateY(animatorProps.ry.v * mult[1]);
  9785. } else {
  9786. matrixHelper.rotateY(animatorProps.ry.v * mult);
  9787. }
  9788. }
  9789. if (animatorProps.rx.propType) {
  9790. if (mult.length) {
  9791. matrixHelper.rotateX(animatorProps.rx.v * mult[0]);
  9792. } else {
  9793. matrixHelper.rotateX(animatorProps.rx.v * mult);
  9794. }
  9795. }
  9796. if (animatorProps.o.propType) {
  9797. if (mult.length) {
  9798. elemOpacity += (animatorProps.o.v * mult[0] - elemOpacity) * mult[0];
  9799. } else {
  9800. elemOpacity += (animatorProps.o.v * mult - elemOpacity) * mult;
  9801. }
  9802. }
  9803. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  9804. if (mult.length) {
  9805. sw += animatorProps.sw.v * mult[0];
  9806. } else {
  9807. sw += animatorProps.sw.v * mult;
  9808. }
  9809. }
  9810. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  9811. for (k = 0; k < 3; k += 1) {
  9812. if (mult.length) {
  9813. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0];
  9814. } else {
  9815. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult;
  9816. }
  9817. }
  9818. }
  9819. if (documentData.fillColorAnim && documentData.fc) {
  9820. if (animatorProps.fc.propType) {
  9821. for (k = 0; k < 3; k += 1) {
  9822. if (mult.length) {
  9823. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0];
  9824. } else {
  9825. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult;
  9826. }
  9827. }
  9828. }
  9829. if (animatorProps.fh.propType) {
  9830. if (mult.length) {
  9831. fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]);
  9832. } else {
  9833. fc = addHueToRGB(fc, animatorProps.fh.v * mult);
  9834. }
  9835. }
  9836. if (animatorProps.fs.propType) {
  9837. if (mult.length) {
  9838. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]);
  9839. } else {
  9840. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult);
  9841. }
  9842. }
  9843. if (animatorProps.fb.propType) {
  9844. if (mult.length) {
  9845. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]);
  9846. } else {
  9847. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult);
  9848. }
  9849. }
  9850. }
  9851. }
  9852. for (j = 0; j < jLen; j += 1) {
  9853. animatorProps = animators[j].a;
  9854. if (animatorProps.p.propType) {
  9855. animatorSelector = animators[j].s;
  9856. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9857. if (this._hasMaskedPath) {
  9858. if (mult.length) {
  9859. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  9860. } else {
  9861. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9862. }
  9863. } else if (mult.length) {
  9864. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  9865. } else {
  9866. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9867. }
  9868. }
  9869. }
  9870. if (documentData.strokeWidthAnim) {
  9871. letterSw = sw < 0 ? 0 : sw;
  9872. }
  9873. if (documentData.strokeColorAnim) {
  9874. letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')';
  9875. }
  9876. if (documentData.fillColorAnim && documentData.fc) {
  9877. letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')';
  9878. }
  9879. if (this._hasMaskedPath) {
  9880. matrixHelper.translate(0, -documentData.ls);
  9881. matrixHelper.translate(0, alignment[1] * yOff * 0.01 + yPos, 0);
  9882. if (this._pathData.p.v) {
  9883. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  9884. var rot = Math.atan(tanAngle) * 180 / Math.PI;
  9885. if (currentPoint.point[0] < prevPoint.point[0]) {
  9886. rot += 180;
  9887. }
  9888. matrixHelper.rotate(-rot * Math.PI / 180);
  9889. }
  9890. matrixHelper.translate(xPathPos, yPathPos, 0);
  9891. currentLength -= alignment[0] * letters[i].an * 0.005;
  9892. if (letters[i + 1] && ind !== letters[i + 1].ind) {
  9893. currentLength += letters[i].an / 2;
  9894. currentLength += documentData.tr * 0.001 * documentData.finalSize;
  9895. }
  9896. } else {
  9897. matrixHelper.translate(xPos, yPos, 0);
  9898. if (documentData.ps) {
  9899. // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  9900. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9901. }
  9902. switch (documentData.j) {
  9903. case 1:
  9904. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0);
  9905. break;
  9906. case 2:
  9907. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0);
  9908. break;
  9909. default:
  9910. break;
  9911. }
  9912. matrixHelper.translate(0, -documentData.ls);
  9913. matrixHelper.translate(offf, 0, 0);
  9914. matrixHelper.translate(alignment[0] * letters[i].an * 0.005, alignment[1] * yOff * 0.01, 0);
  9915. xPos += letters[i].l + documentData.tr * 0.001 * documentData.finalSize;
  9916. }
  9917. if (renderType === 'html') {
  9918. letterM = matrixHelper.toCSS();
  9919. } else if (renderType === 'svg') {
  9920. letterM = matrixHelper.to2dCSS();
  9921. } else {
  9922. letterP = [matrixHelper.props[0], matrixHelper.props[1], matrixHelper.props[2], matrixHelper.props[3], matrixHelper.props[4], matrixHelper.props[5], matrixHelper.props[6], matrixHelper.props[7], matrixHelper.props[8], matrixHelper.props[9], matrixHelper.props[10], matrixHelper.props[11], matrixHelper.props[12], matrixHelper.props[13], matrixHelper.props[14], matrixHelper.props[15]];
  9923. }
  9924. letterO = elemOpacity;
  9925. }
  9926. if (renderedLettersCount <= i) {
  9927. letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP);
  9928. this.renderedLetters.push(letterValue);
  9929. renderedLettersCount += 1;
  9930. this.lettersChangedFlag = true;
  9931. } else {
  9932. letterValue = this.renderedLetters[i];
  9933. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  9934. }
  9935. }
  9936. };
  9937. TextAnimatorProperty.prototype.getValue = function () {
  9938. if (this._elem.globalData.frameId === this._frameId) {
  9939. return;
  9940. }
  9941. this._frameId = this._elem.globalData.frameId;
  9942. this.iterateDynamicProperties();
  9943. };
  9944. TextAnimatorProperty.prototype.mHelper = new Matrix();
  9945. TextAnimatorProperty.prototype.defaultPropsArray = [];
  9946. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  9947. function ITextElement() {}
  9948. ITextElement.prototype.initElement = function (data, globalData, comp) {
  9949. this.lettersChangedFlag = true;
  9950. this.initFrame();
  9951. this.initBaseData(data, globalData, comp);
  9952. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  9953. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  9954. this.initTransform(data, globalData, comp);
  9955. this.initHierarchy();
  9956. this.initRenderable();
  9957. this.initRendererElement();
  9958. this.createContainerElements();
  9959. this.createRenderableComponents();
  9960. this.createContent();
  9961. this.hide();
  9962. this.textAnimator.searchProperties(this.dynamicProperties);
  9963. };
  9964. ITextElement.prototype.prepareFrame = function (num) {
  9965. this._mdf = false;
  9966. this.prepareRenderableFrame(num);
  9967. this.prepareProperties(num, this.isInRange);
  9968. };
  9969. ITextElement.prototype.createPathShape = function (matrixHelper, shapes) {
  9970. var j;
  9971. var jLen = shapes.length;
  9972. var pathNodes;
  9973. var shapeStr = '';
  9974. for (j = 0; j < jLen; j += 1) {
  9975. if (shapes[j].ty === 'sh') {
  9976. pathNodes = shapes[j].ks.k;
  9977. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  9978. }
  9979. }
  9980. return shapeStr;
  9981. };
  9982. ITextElement.prototype.updateDocumentData = function (newData, index) {
  9983. this.textProperty.updateDocumentData(newData, index);
  9984. };
  9985. ITextElement.prototype.canResizeFont = function (_canResize) {
  9986. this.textProperty.canResizeFont(_canResize);
  9987. };
  9988. ITextElement.prototype.setMinimumFontSize = function (_fontSize) {
  9989. this.textProperty.setMinimumFontSize(_fontSize);
  9990. };
  9991. ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) {
  9992. if (documentData.ps) {
  9993. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9994. }
  9995. matrixHelper.translate(0, -documentData.ls, 0);
  9996. switch (documentData.j) {
  9997. case 1:
  9998. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
  9999. break;
  10000. case 2:
  10001. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
  10002. break;
  10003. default:
  10004. break;
  10005. }
  10006. matrixHelper.translate(xPos, yPos, 0);
  10007. };
  10008. ITextElement.prototype.buildColor = function (colorData) {
  10009. return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')';
  10010. };
  10011. ITextElement.prototype.emptyProp = new LetterProps();
  10012. ITextElement.prototype.destroy = function () {};
  10013. ITextElement.prototype.validateText = function () {
  10014. if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
  10015. this.buildNewText();
  10016. this.textProperty._isFirstFrame = false;
  10017. this.textProperty._mdf = false;
  10018. }
  10019. };
  10020. var emptyShapeData = {
  10021. shapes: []
  10022. };
  10023. function SVGTextLottieElement(data, globalData, comp) {
  10024. this.textSpans = [];
  10025. this.renderType = 'svg';
  10026. this.initElement(data, globalData, comp);
  10027. }
  10028. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement);
  10029. SVGTextLottieElement.prototype.createContent = function () {
  10030. if (this.data.singleShape && !this.globalData.fontManager.chars) {
  10031. this.textContainer = createNS('text');
  10032. }
  10033. };
  10034. SVGTextLottieElement.prototype.buildTextContents = function (textArray) {
  10035. var i = 0;
  10036. var len = textArray.length;
  10037. var textContents = [];
  10038. var currentTextContent = '';
  10039. while (i < len) {
  10040. if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) {
  10041. textContents.push(currentTextContent);
  10042. currentTextContent = '';
  10043. } else {
  10044. currentTextContent += textArray[i];
  10045. }
  10046. i += 1;
  10047. }
  10048. textContents.push(currentTextContent);
  10049. return textContents;
  10050. };
  10051. SVGTextLottieElement.prototype.buildShapeData = function (data, scale) {
  10052. // data should probably be cloned to apply scale separately to each instance of a text on different layers
  10053. // but since text internal content gets only rendered once and then it's never rerendered,
  10054. // it's probably safe not to clone data and reuse always the same instance even if the object is mutated.
  10055. // Avoiding cloning is preferred since cloning each character shape data is expensive
  10056. if (data.shapes && data.shapes.length) {
  10057. var shape = data.shapes[0];
  10058. if (shape.it) {
  10059. var shapeItem = shape.it[shape.it.length - 1];
  10060. if (shapeItem.s) {
  10061. shapeItem.s.k[0] = scale;
  10062. shapeItem.s.k[1] = scale;
  10063. }
  10064. }
  10065. }
  10066. return data;
  10067. };
  10068. SVGTextLottieElement.prototype.buildNewText = function () {
  10069. this.addDynamicProperty(this);
  10070. var i;
  10071. var len;
  10072. var documentData = this.textProperty.currentData;
  10073. this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0);
  10074. if (documentData.fc) {
  10075. this.layerElement.setAttribute('fill', this.buildColor(documentData.fc));
  10076. } else {
  10077. this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)');
  10078. }
  10079. if (documentData.sc) {
  10080. this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc));
  10081. this.layerElement.setAttribute('stroke-width', documentData.sw);
  10082. }
  10083. this.layerElement.setAttribute('font-size', documentData.finalSize);
  10084. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  10085. if (fontData.fClass) {
  10086. this.layerElement.setAttribute('class', fontData.fClass);
  10087. } else {
  10088. this.layerElement.setAttribute('font-family', fontData.fFamily);
  10089. var fWeight = documentData.fWeight;
  10090. var fStyle = documentData.fStyle;
  10091. this.layerElement.setAttribute('font-style', fStyle);
  10092. this.layerElement.setAttribute('font-weight', fWeight);
  10093. }
  10094. this.layerElement.setAttribute('aria-label', documentData.t);
  10095. var letters = documentData.l || [];
  10096. var usesGlyphs = !!this.globalData.fontManager.chars;
  10097. len = letters.length;
  10098. var tSpan;
  10099. var matrixHelper = this.mHelper;
  10100. var shapeStr = '';
  10101. var singleShape = this.data.singleShape;
  10102. var xPos = 0;
  10103. var yPos = 0;
  10104. var firstLine = true;
  10105. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  10106. if (singleShape && !usesGlyphs && !documentData.sz) {
  10107. var tElement = this.textContainer;
  10108. var justify = 'start';
  10109. switch (documentData.j) {
  10110. case 1:
  10111. justify = 'end';
  10112. break;
  10113. case 2:
  10114. justify = 'middle';
  10115. break;
  10116. default:
  10117. justify = 'start';
  10118. break;
  10119. }
  10120. tElement.setAttribute('text-anchor', justify);
  10121. tElement.setAttribute('letter-spacing', trackingOffset);
  10122. var textContent = this.buildTextContents(documentData.finalText);
  10123. len = textContent.length;
  10124. yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0;
  10125. for (i = 0; i < len; i += 1) {
  10126. tSpan = this.textSpans[i].span || createNS('tspan');
  10127. tSpan.textContent = textContent[i];
  10128. tSpan.setAttribute('x', 0);
  10129. tSpan.setAttribute('y', yPos);
  10130. tSpan.style.display = 'inherit';
  10131. tElement.appendChild(tSpan);
  10132. if (!this.textSpans[i]) {
  10133. this.textSpans[i] = {
  10134. span: null,
  10135. glyph: null
  10136. };
  10137. }
  10138. this.textSpans[i].span = tSpan;
  10139. yPos += documentData.finalLineHeight;
  10140. }
  10141. this.layerElement.appendChild(tElement);
  10142. } else {
  10143. var cachedSpansLength = this.textSpans.length;
  10144. var charData;
  10145. for (i = 0; i < len; i += 1) {
  10146. if (!this.textSpans[i]) {
  10147. this.textSpans[i] = {
  10148. span: null,
  10149. childSpan: null,
  10150. glyph: null
  10151. };
  10152. }
  10153. if (!usesGlyphs || !singleShape || i === 0) {
  10154. tSpan = cachedSpansLength > i ? this.textSpans[i].span : createNS(usesGlyphs ? 'g' : 'text');
  10155. if (cachedSpansLength <= i) {
  10156. tSpan.setAttribute('stroke-linecap', 'butt');
  10157. tSpan.setAttribute('stroke-linejoin', 'round');
  10158. tSpan.setAttribute('stroke-miterlimit', '4');
  10159. this.textSpans[i].span = tSpan;
  10160. if (usesGlyphs) {
  10161. var childSpan = createNS('g');
  10162. tSpan.appendChild(childSpan);
  10163. this.textSpans[i].childSpan = childSpan;
  10164. }
  10165. this.textSpans[i].span = tSpan;
  10166. this.layerElement.appendChild(tSpan);
  10167. }
  10168. tSpan.style.display = 'inherit';
  10169. }
  10170. matrixHelper.reset();
  10171. if (singleShape) {
  10172. if (letters[i].n) {
  10173. xPos = -trackingOffset;
  10174. yPos += documentData.yOffset;
  10175. yPos += firstLine ? 1 : 0;
  10176. firstLine = false;
  10177. }
  10178. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  10179. xPos += letters[i].l || 0;
  10180. // xPos += letters[i].val === ' ' ? 0 : trackingOffset;
  10181. xPos += trackingOffset;
  10182. }
  10183. if (usesGlyphs) {
  10184. charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  10185. var glyphElement;
  10186. // t === 1 means the character has been replaced with an animated shaped
  10187. if (charData.t === 1) {
  10188. glyphElement = new SVGCompElement(charData.data, this.globalData, this);
  10189. } else {
  10190. var data = emptyShapeData;
  10191. if (charData.data && charData.data.shapes) {
  10192. data = this.buildShapeData(charData.data, documentData.finalSize);
  10193. }
  10194. glyphElement = new SVGShapeElement(data, this.globalData, this);
  10195. }
  10196. if (this.textSpans[i].glyph) {
  10197. var glyph = this.textSpans[i].glyph;
  10198. this.textSpans[i].childSpan.removeChild(glyph.layerElement);
  10199. glyph.destroy();
  10200. }
  10201. this.textSpans[i].glyph = glyphElement;
  10202. glyphElement._debug = true;
  10203. glyphElement.prepareFrame(0);
  10204. glyphElement.renderFrame();
  10205. this.textSpans[i].childSpan.appendChild(glyphElement.layerElement);
  10206. // when using animated shapes, the layer will be scaled instead of replacing the internal scale
  10207. // this might have issues with strokes and might need a different solution
  10208. if (charData.t === 1) {
  10209. this.textSpans[i].childSpan.setAttribute('transform', 'scale(' + documentData.finalSize / 100 + ',' + documentData.finalSize / 100 + ')');
  10210. }
  10211. } else {
  10212. if (singleShape) {
  10213. tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')');
  10214. }
  10215. tSpan.textContent = letters[i].val;
  10216. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  10217. }
  10218. //
  10219. }
  10220. if (singleShape && tSpan) {
  10221. tSpan.setAttribute('d', shapeStr);
  10222. }
  10223. }
  10224. while (i < this.textSpans.length) {
  10225. this.textSpans[i].span.style.display = 'none';
  10226. i += 1;
  10227. }
  10228. this._sizeChanged = true;
  10229. };
  10230. SVGTextLottieElement.prototype.sourceRectAtTime = function () {
  10231. this.prepareFrame(this.comp.renderedFrame - this.data.st);
  10232. this.renderInnerContent();
  10233. if (this._sizeChanged) {
  10234. this._sizeChanged = false;
  10235. var textBox = this.layerElement.getBBox();
  10236. this.bbox = {
  10237. top: textBox.y,
  10238. left: textBox.x,
  10239. width: textBox.width,
  10240. height: textBox.height
  10241. };
  10242. }
  10243. return this.bbox;
  10244. };
  10245. SVGTextLottieElement.prototype.getValue = function () {
  10246. var i;
  10247. var len = this.textSpans.length;
  10248. var glyphElement;
  10249. this.renderedFrame = this.comp.renderedFrame;
  10250. for (i = 0; i < len; i += 1) {
  10251. glyphElement = this.textSpans[i].glyph;
  10252. if (glyphElement) {
  10253. glyphElement.prepareFrame(this.comp.renderedFrame - this.data.st);
  10254. if (glyphElement._mdf) {
  10255. this._mdf = true;
  10256. }
  10257. }
  10258. }
  10259. };
  10260. SVGTextLottieElement.prototype.renderInnerContent = function () {
  10261. this.validateText();
  10262. if (!this.data.singleShape || this._mdf) {
  10263. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  10264. if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) {
  10265. this._sizeChanged = true;
  10266. var i;
  10267. var len;
  10268. var renderedLetters = this.textAnimator.renderedLetters;
  10269. var letters = this.textProperty.currentData.l;
  10270. len = letters.length;
  10271. var renderedLetter;
  10272. var textSpan;
  10273. var glyphElement;
  10274. for (i = 0; i < len; i += 1) {
  10275. if (!letters[i].n) {
  10276. renderedLetter = renderedLetters[i];
  10277. textSpan = this.textSpans[i].span;
  10278. glyphElement = this.textSpans[i].glyph;
  10279. if (glyphElement) {
  10280. glyphElement.renderFrame();
  10281. }
  10282. if (renderedLetter._mdf.m) {
  10283. textSpan.setAttribute('transform', renderedLetter.m);
  10284. }
  10285. if (renderedLetter._mdf.o) {
  10286. textSpan.setAttribute('opacity', renderedLetter.o);
  10287. }
  10288. if (renderedLetter._mdf.sw) {
  10289. textSpan.setAttribute('stroke-width', renderedLetter.sw);
  10290. }
  10291. if (renderedLetter._mdf.sc) {
  10292. textSpan.setAttribute('stroke', renderedLetter.sc);
  10293. }
  10294. if (renderedLetter._mdf.fc) {
  10295. textSpan.setAttribute('fill', renderedLetter.fc);
  10296. }
  10297. }
  10298. }
  10299. }
  10300. }
  10301. };
  10302. function ISolidElement(data, globalData, comp) {
  10303. this.initElement(data, globalData, comp);
  10304. }
  10305. extendPrototype([IImageElement], ISolidElement);
  10306. ISolidElement.prototype.createContent = function () {
  10307. var rect = createNS('rect');
  10308. /// /rect.style.width = this.data.sw;
  10309. /// /rect.style.height = this.data.sh;
  10310. /// /rect.style.fill = this.data.sc;
  10311. rect.setAttribute('width', this.data.sw);
  10312. rect.setAttribute('height', this.data.sh);
  10313. rect.setAttribute('fill', this.data.sc);
  10314. this.layerElement.appendChild(rect);
  10315. };
  10316. function NullElement(data, globalData, comp) {
  10317. this.initFrame();
  10318. this.initBaseData(data, globalData, comp);
  10319. this.initFrame();
  10320. this.initTransform(data, globalData, comp);
  10321. this.initHierarchy();
  10322. }
  10323. NullElement.prototype.prepareFrame = function (num) {
  10324. this.prepareProperties(num, true);
  10325. };
  10326. NullElement.prototype.renderFrame = function () {};
  10327. NullElement.prototype.getBaseElement = function () {
  10328. return null;
  10329. };
  10330. NullElement.prototype.destroy = function () {};
  10331. NullElement.prototype.sourceRectAtTime = function () {};
  10332. NullElement.prototype.hide = function () {};
  10333. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement);
  10334. function SVGRendererBase() {}
  10335. extendPrototype([BaseRenderer], SVGRendererBase);
  10336. SVGRendererBase.prototype.createNull = function (data) {
  10337. return new NullElement(data, this.globalData, this);
  10338. };
  10339. SVGRendererBase.prototype.createShape = function (data) {
  10340. return new SVGShapeElement(data, this.globalData, this);
  10341. };
  10342. SVGRendererBase.prototype.createText = function (data) {
  10343. return new SVGTextLottieElement(data, this.globalData, this);
  10344. };
  10345. SVGRendererBase.prototype.createImage = function (data) {
  10346. return new IImageElement(data, this.globalData, this);
  10347. };
  10348. SVGRendererBase.prototype.createSolid = function (data) {
  10349. return new ISolidElement(data, this.globalData, this);
  10350. };
  10351. SVGRendererBase.prototype.configAnimation = function (animData) {
  10352. this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  10353. this.svgElement.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  10354. if (this.renderConfig.viewBoxSize) {
  10355. this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize);
  10356. } else {
  10357. this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h);
  10358. }
  10359. if (!this.renderConfig.viewBoxOnly) {
  10360. this.svgElement.setAttribute('width', animData.w);
  10361. this.svgElement.setAttribute('height', animData.h);
  10362. this.svgElement.style.width = '100%';
  10363. this.svgElement.style.height = '100%';
  10364. this.svgElement.style.transform = 'translate3d(0,0,0)';
  10365. this.svgElement.style.contentVisibility = this.renderConfig.contentVisibility;
  10366. }
  10367. if (this.renderConfig.width) {
  10368. this.svgElement.setAttribute('width', this.renderConfig.width);
  10369. }
  10370. if (this.renderConfig.height) {
  10371. this.svgElement.setAttribute('height', this.renderConfig.height);
  10372. }
  10373. if (this.renderConfig.className) {
  10374. this.svgElement.setAttribute('class', this.renderConfig.className);
  10375. }
  10376. if (this.renderConfig.id) {
  10377. this.svgElement.setAttribute('id', this.renderConfig.id);
  10378. }
  10379. if (this.renderConfig.focusable !== undefined) {
  10380. this.svgElement.setAttribute('focusable', this.renderConfig.focusable);
  10381. }
  10382. this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio);
  10383. // this.layerElement.style.transform = 'translate3d(0,0,0)';
  10384. // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  10385. this.animationItem.wrapper.appendChild(this.svgElement);
  10386. // Mask animation
  10387. var defs = this.globalData.defs;
  10388. this.setupGlobalData(animData, defs);
  10389. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  10390. this.data = animData;
  10391. var maskElement = createNS('clipPath');
  10392. var rect = createNS('rect');
  10393. rect.setAttribute('width', animData.w);
  10394. rect.setAttribute('height', animData.h);
  10395. rect.setAttribute('x', 0);
  10396. rect.setAttribute('y', 0);
  10397. var maskId = createElementID();
  10398. maskElement.setAttribute('id', maskId);
  10399. maskElement.appendChild(rect);
  10400. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + maskId + ')');
  10401. defs.appendChild(maskElement);
  10402. this.layers = animData.layers;
  10403. this.elements = createSizedArray(animData.layers.length);
  10404. };
  10405. SVGRendererBase.prototype.destroy = function () {
  10406. if (this.animationItem.wrapper) {
  10407. this.animationItem.wrapper.innerText = '';
  10408. }
  10409. this.layerElement = null;
  10410. this.globalData.defs = null;
  10411. var i;
  10412. var len = this.layers ? this.layers.length : 0;
  10413. for (i = 0; i < len; i += 1) {
  10414. if (this.elements[i] && this.elements[i].destroy) {
  10415. this.elements[i].destroy();
  10416. }
  10417. }
  10418. this.elements.length = 0;
  10419. this.destroyed = true;
  10420. this.animationItem = null;
  10421. };
  10422. SVGRendererBase.prototype.updateContainerSize = function () {};
  10423. SVGRendererBase.prototype.findIndexByInd = function (ind) {
  10424. var i = 0;
  10425. var len = this.layers.length;
  10426. for (i = 0; i < len; i += 1) {
  10427. if (this.layers[i].ind === ind) {
  10428. return i;
  10429. }
  10430. }
  10431. return -1;
  10432. };
  10433. SVGRendererBase.prototype.buildItem = function (pos) {
  10434. var elements = this.elements;
  10435. if (elements[pos] || this.layers[pos].ty === 99) {
  10436. return;
  10437. }
  10438. elements[pos] = true;
  10439. var element = this.createItem(this.layers[pos]);
  10440. elements[pos] = element;
  10441. if (getExpressionsPlugin()) {
  10442. if (this.layers[pos].ty === 0) {
  10443. this.globalData.projectInterface.registerComposition(element);
  10444. }
  10445. element.initExpressions();
  10446. }
  10447. this.appendElementInPos(element, pos);
  10448. if (this.layers[pos].tt) {
  10449. var elementIndex = 'tp' in this.layers[pos] ? this.findIndexByInd(this.layers[pos].tp) : pos - 1;
  10450. if (elementIndex === -1) {
  10451. return;
  10452. }
  10453. if (!this.elements[elementIndex] || this.elements[elementIndex] === true) {
  10454. this.buildItem(elementIndex);
  10455. this.addPendingElement(element);
  10456. } else {
  10457. var matteElement = elements[elementIndex];
  10458. var matteMask = matteElement.getMatte(this.layers[pos].tt);
  10459. element.setMatte(matteMask);
  10460. }
  10461. }
  10462. };
  10463. SVGRendererBase.prototype.checkPendingElements = function () {
  10464. while (this.pendingElements.length) {
  10465. var element = this.pendingElements.pop();
  10466. element.checkParenting();
  10467. if (element.data.tt) {
  10468. var i = 0;
  10469. var len = this.elements.length;
  10470. while (i < len) {
  10471. if (this.elements[i] === element) {
  10472. var elementIndex = 'tp' in element.data ? this.findIndexByInd(element.data.tp) : i - 1;
  10473. var matteElement = this.elements[elementIndex];
  10474. var matteMask = matteElement.getMatte(this.layers[i].tt);
  10475. element.setMatte(matteMask);
  10476. break;
  10477. }
  10478. i += 1;
  10479. }
  10480. }
  10481. }
  10482. };
  10483. SVGRendererBase.prototype.renderFrame = function (num) {
  10484. if (this.renderedFrame === num || this.destroyed) {
  10485. return;
  10486. }
  10487. if (num === null) {
  10488. num = this.renderedFrame;
  10489. } else {
  10490. this.renderedFrame = num;
  10491. }
  10492. // console.log('-------');
  10493. // console.log('FRAME ',num);
  10494. this.globalData.frameNum = num;
  10495. this.globalData.frameId += 1;
  10496. this.globalData.projectInterface.currentFrame = num;
  10497. this.globalData._mdf = false;
  10498. var i;
  10499. var len = this.layers.length;
  10500. if (!this.completeLayers) {
  10501. this.checkLayers(num);
  10502. }
  10503. for (i = len - 1; i >= 0; i -= 1) {
  10504. if (this.completeLayers || this.elements[i]) {
  10505. this.elements[i].prepareFrame(num - this.layers[i].st);
  10506. }
  10507. }
  10508. if (this.globalData._mdf) {
  10509. for (i = 0; i < len; i += 1) {
  10510. if (this.completeLayers || this.elements[i]) {
  10511. this.elements[i].renderFrame();
  10512. }
  10513. }
  10514. }
  10515. };
  10516. SVGRendererBase.prototype.appendElementInPos = function (element, pos) {
  10517. var newElement = element.getBaseElement();
  10518. if (!newElement) {
  10519. return;
  10520. }
  10521. var i = 0;
  10522. var nextElement;
  10523. while (i < pos) {
  10524. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) {
  10525. nextElement = this.elements[i].getBaseElement();
  10526. }
  10527. i += 1;
  10528. }
  10529. if (nextElement) {
  10530. this.layerElement.insertBefore(newElement, nextElement);
  10531. } else {
  10532. this.layerElement.appendChild(newElement);
  10533. }
  10534. };
  10535. SVGRendererBase.prototype.hide = function () {
  10536. this.layerElement.style.display = 'none';
  10537. };
  10538. SVGRendererBase.prototype.show = function () {
  10539. this.layerElement.style.display = 'block';
  10540. };
  10541. function ICompElement() {}
  10542. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  10543. ICompElement.prototype.initElement = function (data, globalData, comp) {
  10544. this.initFrame();
  10545. this.initBaseData(data, globalData, comp);
  10546. this.initTransform(data, globalData, comp);
  10547. this.initRenderable();
  10548. this.initHierarchy();
  10549. this.initRendererElement();
  10550. this.createContainerElements();
  10551. this.createRenderableComponents();
  10552. if (this.data.xt || !globalData.progressiveLoad) {
  10553. this.buildAllItems();
  10554. }
  10555. this.hide();
  10556. };
  10557. /* ICompElement.prototype.hide = function(){
  10558. if(!this.hidden){
  10559. this.hideElement();
  10560. var i,len = this.elements.length;
  10561. for( i = 0; i < len; i+=1 ){
  10562. if(this.elements[i]){
  10563. this.elements[i].hide();
  10564. }
  10565. }
  10566. }
  10567. }; */
  10568. ICompElement.prototype.prepareFrame = function (num) {
  10569. this._mdf = false;
  10570. this.prepareRenderableFrame(num);
  10571. this.prepareProperties(num, this.isInRange);
  10572. if (!this.isInRange && !this.data.xt) {
  10573. return;
  10574. }
  10575. if (!this.tm._placeholder) {
  10576. var timeRemapped = this.tm.v;
  10577. if (timeRemapped === this.data.op) {
  10578. timeRemapped = this.data.op - 1;
  10579. }
  10580. this.renderedFrame = timeRemapped;
  10581. } else {
  10582. this.renderedFrame = num / this.data.sr;
  10583. }
  10584. var i;
  10585. var len = this.elements.length;
  10586. if (!this.completeLayers) {
  10587. this.checkLayers(this.renderedFrame);
  10588. }
  10589. // This iteration needs to be backwards because of how expressions connect between each other
  10590. for (i = len - 1; i >= 0; i -= 1) {
  10591. if (this.completeLayers || this.elements[i]) {
  10592. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  10593. if (this.elements[i]._mdf) {
  10594. this._mdf = true;
  10595. }
  10596. }
  10597. }
  10598. };
  10599. ICompElement.prototype.renderInnerContent = function () {
  10600. var i;
  10601. var len = this.layers.length;
  10602. for (i = 0; i < len; i += 1) {
  10603. if (this.completeLayers || this.elements[i]) {
  10604. this.elements[i].renderFrame();
  10605. }
  10606. }
  10607. };
  10608. ICompElement.prototype.setElements = function (elems) {
  10609. this.elements = elems;
  10610. };
  10611. ICompElement.prototype.getElements = function () {
  10612. return this.elements;
  10613. };
  10614. ICompElement.prototype.destroyElements = function () {
  10615. var i;
  10616. var len = this.layers.length;
  10617. for (i = 0; i < len; i += 1) {
  10618. if (this.elements[i]) {
  10619. this.elements[i].destroy();
  10620. }
  10621. }
  10622. };
  10623. ICompElement.prototype.destroy = function () {
  10624. this.destroyElements();
  10625. this.destroyBaseElement();
  10626. };
  10627. function SVGCompElement(data, globalData, comp) {
  10628. this.layers = data.layers;
  10629. this.supports3d = true;
  10630. this.completeLayers = false;
  10631. this.pendingElements = [];
  10632. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  10633. this.initElement(data, globalData, comp);
  10634. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : {
  10635. _placeholder: true
  10636. };
  10637. }
  10638. extendPrototype([SVGRendererBase, ICompElement, SVGBaseElement], SVGCompElement);
  10639. SVGCompElement.prototype.createComp = function (data) {
  10640. return new SVGCompElement(data, this.globalData, this);
  10641. };
  10642. function SVGRenderer(animationItem, config) {
  10643. this.animationItem = animationItem;
  10644. this.layers = null;
  10645. this.renderedFrame = -1;
  10646. this.svgElement = createNS('svg');
  10647. var ariaLabel = '';
  10648. if (config && config.title) {
  10649. var titleElement = createNS('title');
  10650. var titleId = createElementID();
  10651. titleElement.setAttribute('id', titleId);
  10652. titleElement.textContent = config.title;
  10653. this.svgElement.appendChild(titleElement);
  10654. ariaLabel += titleId;
  10655. }
  10656. if (config && config.description) {
  10657. var descElement = createNS('desc');
  10658. var descId = createElementID();
  10659. descElement.setAttribute('id', descId);
  10660. descElement.textContent = config.description;
  10661. this.svgElement.appendChild(descElement);
  10662. ariaLabel += ' ' + descId;
  10663. }
  10664. if (ariaLabel) {
  10665. this.svgElement.setAttribute('aria-labelledby', ariaLabel);
  10666. }
  10667. var defs = createNS('defs');
  10668. this.svgElement.appendChild(defs);
  10669. var maskElement = createNS('g');
  10670. this.svgElement.appendChild(maskElement);
  10671. this.layerElement = maskElement;
  10672. this.renderConfig = {
  10673. preserveAspectRatio: config && config.preserveAspectRatio || 'xMidYMid meet',
  10674. imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || 'xMidYMid slice',
  10675. contentVisibility: config && config.contentVisibility || 'visible',
  10676. progressiveLoad: config && config.progressiveLoad || false,
  10677. hideOnTransparent: !(config && config.hideOnTransparent === false),
  10678. viewBoxOnly: config && config.viewBoxOnly || false,
  10679. viewBoxSize: config && config.viewBoxSize || false,
  10680. className: config && config.className || '',
  10681. id: config && config.id || '',
  10682. focusable: config && config.focusable,
  10683. filterSize: {
  10684. width: config && config.filterSize && config.filterSize.width || '100%',
  10685. height: config && config.filterSize && config.filterSize.height || '100%',
  10686. x: config && config.filterSize && config.filterSize.x || '0%',
  10687. y: config && config.filterSize && config.filterSize.y || '0%'
  10688. },
  10689. width: config && config.width,
  10690. height: config && config.height,
  10691. runExpressions: !config || config.runExpressions === undefined || config.runExpressions
  10692. };
  10693. this.globalData = {
  10694. _mdf: false,
  10695. frameNum: -1,
  10696. defs: defs,
  10697. renderConfig: this.renderConfig
  10698. };
  10699. this.elements = [];
  10700. this.pendingElements = [];
  10701. this.destroyed = false;
  10702. this.rendererType = 'svg';
  10703. }
  10704. extendPrototype([SVGRendererBase], SVGRenderer);
  10705. SVGRenderer.prototype.createComp = function (data) {
  10706. return new SVGCompElement(data, this.globalData, this);
  10707. };
  10708. // Registering renderers
  10709. registerRenderer('svg', SVGRenderer);
  10710. // Registering shape modifiers
  10711. ShapeModifiers.registerModifier('tm', TrimModifier);
  10712. ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier);
  10713. ShapeModifiers.registerModifier('rp', RepeaterModifier);
  10714. ShapeModifiers.registerModifier('rd', RoundCornersModifier);
  10715. ShapeModifiers.registerModifier('zz', ZigZagModifier);
  10716. ShapeModifiers.registerModifier('op', OffsetPathModifier);
  10717. return lottie;
  10718. }));