lottie_canvas.module.js 466 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844
  1. const svgNS = 'http://www.w3.org/2000/svg';
  2. let locationHref = '';
  3. let _useWebWorker = false;
  4. const initialDefaultFrame = -999999;
  5. const setWebWorker = (flag) => { _useWebWorker = !!flag; };
  6. const getWebWorker = () => _useWebWorker;
  7. const setLocationHref = (value) => { locationHref = value; };
  8. const getLocationHref = () => locationHref;
  9. function createTag(type) {
  10. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  11. return document.createElement(type);
  12. }
  13. function extendPrototype(sources, destination) {
  14. var i;
  15. var len = sources.length;
  16. var sourcePrototype;
  17. for (i = 0; i < len; i += 1) {
  18. sourcePrototype = sources[i].prototype;
  19. for (var attr in sourcePrototype) {
  20. if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
  21. }
  22. }
  23. }
  24. function getDescriptor(object, prop) {
  25. return Object.getOwnPropertyDescriptor(object, prop);
  26. }
  27. function createProxyFunction(prototype) {
  28. function ProxyFunction() {}
  29. ProxyFunction.prototype = prototype;
  30. return ProxyFunction;
  31. }
  32. // import Howl from '../../3rd_party/howler';
  33. const audioControllerFactory = (function () {
  34. function AudioController(audioFactory) {
  35. this.audios = [];
  36. this.audioFactory = audioFactory;
  37. this._volume = 1;
  38. this._isMuted = false;
  39. }
  40. AudioController.prototype = {
  41. addAudio: function (audio) {
  42. this.audios.push(audio);
  43. },
  44. pause: function () {
  45. var i;
  46. var len = this.audios.length;
  47. for (i = 0; i < len; i += 1) {
  48. this.audios[i].pause();
  49. }
  50. },
  51. resume: function () {
  52. var i;
  53. var len = this.audios.length;
  54. for (i = 0; i < len; i += 1) {
  55. this.audios[i].resume();
  56. }
  57. },
  58. setRate: function (rateValue) {
  59. var i;
  60. var len = this.audios.length;
  61. for (i = 0; i < len; i += 1) {
  62. this.audios[i].setRate(rateValue);
  63. }
  64. },
  65. createAudio: function (assetPath) {
  66. if (this.audioFactory) {
  67. return this.audioFactory(assetPath);
  68. } if (window.Howl) {
  69. return new window.Howl({
  70. src: [assetPath],
  71. });
  72. }
  73. return {
  74. isPlaying: false,
  75. play: function () { this.isPlaying = true; },
  76. seek: function () { this.isPlaying = false; },
  77. playing: function () {},
  78. rate: function () {},
  79. setVolume: function () {},
  80. };
  81. },
  82. setAudioFactory: function (audioFactory) {
  83. this.audioFactory = audioFactory;
  84. },
  85. setVolume: function (value) {
  86. this._volume = value;
  87. this._updateVolume();
  88. },
  89. mute: function () {
  90. this._isMuted = true;
  91. this._updateVolume();
  92. },
  93. unmute: function () {
  94. this._isMuted = false;
  95. this._updateVolume();
  96. },
  97. getVolume: function () {
  98. return this._volume;
  99. },
  100. _updateVolume: function () {
  101. var i;
  102. var len = this.audios.length;
  103. for (i = 0; i < len; i += 1) {
  104. this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1));
  105. }
  106. },
  107. };
  108. return function () {
  109. return new AudioController();
  110. };
  111. }());
  112. const createTypedArray = (function () {
  113. function createRegularArray(type, len) {
  114. var i = 0;
  115. var arr = [];
  116. var value;
  117. switch (type) {
  118. case 'int16':
  119. case 'uint8c':
  120. value = 1;
  121. break;
  122. default:
  123. value = 1.1;
  124. break;
  125. }
  126. for (i = 0; i < len; i += 1) {
  127. arr.push(value);
  128. }
  129. return arr;
  130. }
  131. function createTypedArrayFactory(type, len) {
  132. if (type === 'float32') {
  133. return new Float32Array(len);
  134. } if (type === 'int16') {
  135. return new Int16Array(len);
  136. } if (type === 'uint8c') {
  137. return new Uint8ClampedArray(len);
  138. }
  139. return createRegularArray(type, len);
  140. }
  141. if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  142. return createTypedArrayFactory;
  143. }
  144. return createRegularArray;
  145. }());
  146. function createSizedArray(len) {
  147. return Array.apply(null, { length: len });
  148. }
  149. let subframeEnabled = true;
  150. let expressionsPlugin = null;
  151. let idPrefix$1 = '';
  152. const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  153. let _shouldRoundValues = false;
  154. const bmPow = Math.pow;
  155. const bmSqrt = Math.sqrt;
  156. const bmFloor = Math.floor;
  157. const bmMax = Math.max;
  158. const bmMin = Math.min;
  159. const BMMath = {};
  160. (function () {
  161. 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'];
  162. var i;
  163. var len = propertyNames.length;
  164. for (i = 0; i < len; i += 1) {
  165. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  166. }
  167. }());
  168. function ProjectInterface$1() { return {}; }
  169. BMMath.random = Math.random;
  170. BMMath.abs = function (val) {
  171. var tOfVal = typeof val;
  172. if (tOfVal === 'object' && val.length) {
  173. var absArr = createSizedArray(val.length);
  174. var i;
  175. var len = val.length;
  176. for (i = 0; i < len; i += 1) {
  177. absArr[i] = Math.abs(val[i]);
  178. }
  179. return absArr;
  180. }
  181. return Math.abs(val);
  182. };
  183. let defaultCurveSegments = 150;
  184. const degToRads = Math.PI / 180;
  185. const roundCorner = 0.5519;
  186. function roundValues(flag) {
  187. _shouldRoundValues = !!flag;
  188. }
  189. function bmRnd(value) {
  190. if (_shouldRoundValues) {
  191. return Math.round(value);
  192. }
  193. return value;
  194. }
  195. function styleDiv(element) {
  196. element.style.position = 'absolute';
  197. element.style.top = 0;
  198. element.style.left = 0;
  199. element.style.display = 'block';
  200. element.style.transformOrigin = '0 0';
  201. element.style.webkitTransformOrigin = '0 0';
  202. element.style.backfaceVisibility = 'visible';
  203. element.style.webkitBackfaceVisibility = 'visible';
  204. element.style.transformStyle = 'preserve-3d';
  205. element.style.webkitTransformStyle = 'preserve-3d';
  206. element.style.mozTransformStyle = 'preserve-3d';
  207. }
  208. function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) {
  209. this.type = type;
  210. this.currentTime = currentTime;
  211. this.totalTime = totalTime;
  212. this.direction = frameMultiplier < 0 ? -1 : 1;
  213. }
  214. function BMCompleteEvent(type, frameMultiplier) {
  215. this.type = type;
  216. this.direction = frameMultiplier < 0 ? -1 : 1;
  217. }
  218. function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) {
  219. this.type = type;
  220. this.currentLoop = currentLoop;
  221. this.totalLoops = totalLoops;
  222. this.direction = frameMultiplier < 0 ? -1 : 1;
  223. }
  224. function BMSegmentStartEvent(type, firstFrame, totalFrames) {
  225. this.type = type;
  226. this.firstFrame = firstFrame;
  227. this.totalFrames = totalFrames;
  228. }
  229. function BMDestroyEvent(type, target) {
  230. this.type = type;
  231. this.target = target;
  232. }
  233. function BMRenderFrameErrorEvent(nativeError, currentTime) {
  234. this.type = 'renderFrameError';
  235. this.nativeError = nativeError;
  236. this.currentTime = currentTime;
  237. }
  238. function BMConfigErrorEvent(nativeError) {
  239. this.type = 'configError';
  240. this.nativeError = nativeError;
  241. }
  242. function BMAnimationConfigErrorEvent(type, nativeError) {
  243. this.type = type;
  244. this.nativeError = nativeError;
  245. }
  246. const createElementID = (function () {
  247. var _count = 0;
  248. return function createID() {
  249. _count += 1;
  250. return idPrefix$1 + '__lottie_element_' + _count;
  251. };
  252. }());
  253. function HSVtoRGB(h, s, v) {
  254. var r;
  255. var g;
  256. var b;
  257. var i;
  258. var f;
  259. var p;
  260. var q;
  261. var t;
  262. i = Math.floor(h * 6);
  263. f = h * 6 - i;
  264. p = v * (1 - s);
  265. q = v * (1 - f * s);
  266. t = v * (1 - (1 - f) * s);
  267. switch (i % 6) {
  268. case 0: r = v; g = t; b = p; break;
  269. case 1: r = q; g = v; b = p; break;
  270. case 2: r = p; g = v; b = t; break;
  271. case 3: r = p; g = q; b = v; break;
  272. case 4: r = t; g = p; b = v; break;
  273. case 5: r = v; g = p; b = q; break;
  274. default: break;
  275. }
  276. return [r,
  277. g,
  278. b];
  279. }
  280. function RGBtoHSV(r, g, b) {
  281. var max = Math.max(r, g, b);
  282. var min = Math.min(r, g, b);
  283. var d = max - min;
  284. var h;
  285. var s = (max === 0 ? 0 : d / max);
  286. var v = max / 255;
  287. switch (max) {
  288. case min: h = 0; break;
  289. case r: h = (g - b) + d * (g < b ? 6 : 0); h /= 6 * d; break;
  290. case g: h = (b - r) + d * 2; h /= 6 * d; break;
  291. case b: h = (r - g) + d * 4; h /= 6 * d; break;
  292. default: break;
  293. }
  294. return [
  295. h,
  296. s,
  297. v,
  298. ];
  299. }
  300. function addSaturationToRGB(color, offset) {
  301. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  302. hsv[1] += offset;
  303. if (hsv[1] > 1) {
  304. hsv[1] = 1;
  305. } else if (hsv[1] <= 0) {
  306. hsv[1] = 0;
  307. }
  308. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  309. }
  310. function addBrightnessToRGB(color, offset) {
  311. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  312. hsv[2] += offset;
  313. if (hsv[2] > 1) {
  314. hsv[2] = 1;
  315. } else if (hsv[2] < 0) {
  316. hsv[2] = 0;
  317. }
  318. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  319. }
  320. function addHueToRGB(color, offset) {
  321. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  322. hsv[0] += offset / 360;
  323. if (hsv[0] > 1) {
  324. hsv[0] -= 1;
  325. } else if (hsv[0] < 0) {
  326. hsv[0] += 1;
  327. }
  328. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  329. }
  330. const rgbToHex = (function () {
  331. var colorMap = [];
  332. var i;
  333. var hex;
  334. for (i = 0; i < 256; i += 1) {
  335. hex = i.toString(16);
  336. colorMap[i] = hex.length === 1 ? '0' + hex : hex;
  337. }
  338. return function (r, g, b) {
  339. if (r < 0) {
  340. r = 0;
  341. }
  342. if (g < 0) {
  343. g = 0;
  344. }
  345. if (b < 0) {
  346. b = 0;
  347. }
  348. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  349. };
  350. }());
  351. const setSubframeEnabled = (flag) => { subframeEnabled = !!flag; };
  352. const getSubframeEnabled = () => subframeEnabled;
  353. const setExpressionsPlugin = (value) => { expressionsPlugin = value; };
  354. const getExpressionsPlugin = () => expressionsPlugin;
  355. const setDefaultCurveSegments = (value) => { defaultCurveSegments = value; };
  356. const getDefaultCurveSegments = () => defaultCurveSegments;
  357. const setIdPrefix = (value) => { idPrefix$1 = value; };
  358. const getIdPrefix = () => idPrefix$1;
  359. function createNS(type) {
  360. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  361. return document.createElementNS(svgNS, type);
  362. }
  363. const dataManager = (function () {
  364. var _counterId = 1;
  365. var processes = [];
  366. var workerFn;
  367. var workerInstance;
  368. var workerProxy = {
  369. onmessage: function () {
  370. },
  371. postMessage: function (path) {
  372. workerFn({
  373. data: path,
  374. });
  375. },
  376. };
  377. var _workerSelf = {
  378. postMessage: function (data) {
  379. workerProxy.onmessage({
  380. data: data,
  381. });
  382. },
  383. };
  384. function createWorker(fn) {
  385. if (window.Worker && window.Blob && getWebWorker()) {
  386. var blob = new Blob(['var _workerSelf = self; self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  387. // var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  388. var url = URL.createObjectURL(blob);
  389. return new Worker(url);
  390. }
  391. workerFn = fn;
  392. return workerProxy;
  393. }
  394. function setupWorker() {
  395. if (!workerInstance) {
  396. workerInstance = createWorker(function workerStart(e) {
  397. function dataFunctionManager() {
  398. function completeLayers(layers, comps) {
  399. var layerData;
  400. var i;
  401. var len = layers.length;
  402. var j;
  403. var jLen;
  404. var k;
  405. var kLen;
  406. for (i = 0; i < len; i += 1) {
  407. layerData = layers[i];
  408. if (('ks' in layerData) && !layerData.completed) {
  409. layerData.completed = true;
  410. if (layerData.tt) {
  411. layers[i - 1].td = layerData.tt;
  412. }
  413. if (layerData.hasMask) {
  414. var maskProps = layerData.masksProperties;
  415. jLen = maskProps.length;
  416. for (j = 0; j < jLen; j += 1) {
  417. if (maskProps[j].pt.k.i) {
  418. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  419. } else {
  420. kLen = maskProps[j].pt.k.length;
  421. for (k = 0; k < kLen; k += 1) {
  422. if (maskProps[j].pt.k[k].s) {
  423. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  424. }
  425. if (maskProps[j].pt.k[k].e) {
  426. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  427. }
  428. }
  429. }
  430. }
  431. }
  432. if (layerData.ty === 0) {
  433. layerData.layers = findCompLayers(layerData.refId, comps);
  434. completeLayers(layerData.layers, comps);
  435. } else if (layerData.ty === 4) {
  436. completeShapes(layerData.shapes);
  437. } else if (layerData.ty === 5) {
  438. completeText(layerData);
  439. }
  440. }
  441. }
  442. }
  443. function completeChars(chars, assets) {
  444. if (chars) {
  445. var i = 0;
  446. var len = chars.length;
  447. for (i = 0; i < len; i += 1) {
  448. if (chars[i].t === 1) {
  449. // var compData = findComp(chars[i].data.refId, assets);
  450. chars[i].data.layers = findCompLayers(chars[i].data.refId, assets);
  451. // chars[i].data.ip = 0;
  452. // chars[i].data.op = 99999;
  453. // chars[i].data.st = 0;
  454. // chars[i].data.sr = 1;
  455. // chars[i].w = compData.w;
  456. // chars[i].data.ks = {
  457. // a: { k: [0, 0, 0], a: 0 },
  458. // p: { k: [0, -compData.h, 0], a: 0 },
  459. // r: { k: 0, a: 0 },
  460. // s: { k: [100, 100], a: 0 },
  461. // o: { k: 100, a: 0 },
  462. // };
  463. completeLayers(chars[i].data.layers, assets);
  464. }
  465. }
  466. }
  467. }
  468. function findComp(id, comps) {
  469. var i = 0;
  470. var len = comps.length;
  471. while (i < len) {
  472. if (comps[i].id === id) {
  473. return comps[i];
  474. }
  475. i += 1;
  476. }
  477. return null;
  478. }
  479. function findCompLayers(id, comps) {
  480. var comp = findComp(id, comps);
  481. if (comp) {
  482. if (!comp.layers.__used) {
  483. comp.layers.__used = true;
  484. return comp.layers;
  485. }
  486. return JSON.parse(JSON.stringify(comp.layers));
  487. }
  488. return null;
  489. }
  490. function completeShapes(arr) {
  491. var i;
  492. var len = arr.length;
  493. var j;
  494. var jLen;
  495. for (i = len - 1; i >= 0; i -= 1) {
  496. if (arr[i].ty === 'sh') {
  497. if (arr[i].ks.k.i) {
  498. convertPathsToAbsoluteValues(arr[i].ks.k);
  499. } else {
  500. jLen = arr[i].ks.k.length;
  501. for (j = 0; j < jLen; j += 1) {
  502. if (arr[i].ks.k[j].s) {
  503. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  504. }
  505. if (arr[i].ks.k[j].e) {
  506. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  507. }
  508. }
  509. }
  510. } else if (arr[i].ty === 'gr') {
  511. completeShapes(arr[i].it);
  512. }
  513. }
  514. }
  515. function convertPathsToAbsoluteValues(path) {
  516. var i;
  517. var len = path.i.length;
  518. for (i = 0; i < len; i += 1) {
  519. path.i[i][0] += path.v[i][0];
  520. path.i[i][1] += path.v[i][1];
  521. path.o[i][0] += path.v[i][0];
  522. path.o[i][1] += path.v[i][1];
  523. }
  524. }
  525. function checkVersion(minimum, animVersionString) {
  526. var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100];
  527. if (minimum[0] > animVersion[0]) {
  528. return true;
  529. } if (animVersion[0] > minimum[0]) {
  530. return false;
  531. }
  532. if (minimum[1] > animVersion[1]) {
  533. return true;
  534. } if (animVersion[1] > minimum[1]) {
  535. return false;
  536. }
  537. if (minimum[2] > animVersion[2]) {
  538. return true;
  539. } if (animVersion[2] > minimum[2]) {
  540. return false;
  541. }
  542. return null;
  543. }
  544. var checkText = (function () {
  545. var minimumVersion = [4, 4, 14];
  546. function updateTextLayer(textLayer) {
  547. var documentData = textLayer.t.d;
  548. textLayer.t.d = {
  549. k: [
  550. {
  551. s: documentData,
  552. t: 0,
  553. },
  554. ],
  555. };
  556. }
  557. function iterateLayers(layers) {
  558. var i;
  559. var len = layers.length;
  560. for (i = 0; i < len; i += 1) {
  561. if (layers[i].ty === 5) {
  562. updateTextLayer(layers[i]);
  563. }
  564. }
  565. }
  566. return function (animationData) {
  567. if (checkVersion(minimumVersion, animationData.v)) {
  568. iterateLayers(animationData.layers);
  569. if (animationData.assets) {
  570. var i;
  571. var len = animationData.assets.length;
  572. for (i = 0; i < len; i += 1) {
  573. if (animationData.assets[i].layers) {
  574. iterateLayers(animationData.assets[i].layers);
  575. }
  576. }
  577. }
  578. }
  579. };
  580. }());
  581. var checkChars = (function () {
  582. var minimumVersion = [4, 7, 99];
  583. return function (animationData) {
  584. if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) {
  585. var i;
  586. var len = animationData.chars.length;
  587. for (i = 0; i < len; i += 1) {
  588. var charData = animationData.chars[i];
  589. if (charData.data && charData.data.shapes) {
  590. completeShapes(charData.data.shapes);
  591. charData.data.ip = 0;
  592. charData.data.op = 99999;
  593. charData.data.st = 0;
  594. charData.data.sr = 1;
  595. charData.data.ks = {
  596. p: { k: [0, 0], a: 0 },
  597. s: { k: [100, 100], a: 0 },
  598. a: { k: [0, 0], a: 0 },
  599. r: { k: 0, a: 0 },
  600. o: { k: 100, a: 0 },
  601. };
  602. if (!animationData.chars[i].t) {
  603. charData.data.shapes.push(
  604. {
  605. ty: 'no',
  606. }
  607. );
  608. charData.data.shapes[0].it.push(
  609. {
  610. p: { k: [0, 0], a: 0 },
  611. s: { k: [100, 100], a: 0 },
  612. a: { k: [0, 0], a: 0 },
  613. r: { k: 0, a: 0 },
  614. o: { k: 100, a: 0 },
  615. sk: { k: 0, a: 0 },
  616. sa: { k: 0, a: 0 },
  617. ty: 'tr',
  618. }
  619. );
  620. }
  621. }
  622. }
  623. }
  624. };
  625. }());
  626. var checkPathProperties = (function () {
  627. var minimumVersion = [5, 7, 15];
  628. function updateTextLayer(textLayer) {
  629. var pathData = textLayer.t.p;
  630. if (typeof pathData.a === 'number') {
  631. pathData.a = {
  632. a: 0,
  633. k: pathData.a,
  634. };
  635. }
  636. if (typeof pathData.p === 'number') {
  637. pathData.p = {
  638. a: 0,
  639. k: pathData.p,
  640. };
  641. }
  642. if (typeof pathData.r === 'number') {
  643. pathData.r = {
  644. a: 0,
  645. k: pathData.r,
  646. };
  647. }
  648. }
  649. function iterateLayers(layers) {
  650. var i;
  651. var len = layers.length;
  652. for (i = 0; i < len; i += 1) {
  653. if (layers[i].ty === 5) {
  654. updateTextLayer(layers[i]);
  655. }
  656. }
  657. }
  658. return function (animationData) {
  659. if (checkVersion(minimumVersion, animationData.v)) {
  660. iterateLayers(animationData.layers);
  661. if (animationData.assets) {
  662. var i;
  663. var len = animationData.assets.length;
  664. for (i = 0; i < len; i += 1) {
  665. if (animationData.assets[i].layers) {
  666. iterateLayers(animationData.assets[i].layers);
  667. }
  668. }
  669. }
  670. }
  671. };
  672. }());
  673. var checkColors = (function () {
  674. var minimumVersion = [4, 1, 9];
  675. function iterateShapes(shapes) {
  676. var i;
  677. var len = shapes.length;
  678. var j;
  679. var jLen;
  680. for (i = 0; i < len; i += 1) {
  681. if (shapes[i].ty === 'gr') {
  682. iterateShapes(shapes[i].it);
  683. } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') {
  684. if (shapes[i].c.k && shapes[i].c.k[0].i) {
  685. jLen = shapes[i].c.k.length;
  686. for (j = 0; j < jLen; j += 1) {
  687. if (shapes[i].c.k[j].s) {
  688. shapes[i].c.k[j].s[0] /= 255;
  689. shapes[i].c.k[j].s[1] /= 255;
  690. shapes[i].c.k[j].s[2] /= 255;
  691. shapes[i].c.k[j].s[3] /= 255;
  692. }
  693. if (shapes[i].c.k[j].e) {
  694. shapes[i].c.k[j].e[0] /= 255;
  695. shapes[i].c.k[j].e[1] /= 255;
  696. shapes[i].c.k[j].e[2] /= 255;
  697. shapes[i].c.k[j].e[3] /= 255;
  698. }
  699. }
  700. } else {
  701. shapes[i].c.k[0] /= 255;
  702. shapes[i].c.k[1] /= 255;
  703. shapes[i].c.k[2] /= 255;
  704. shapes[i].c.k[3] /= 255;
  705. }
  706. }
  707. }
  708. }
  709. function iterateLayers(layers) {
  710. var i;
  711. var len = layers.length;
  712. for (i = 0; i < len; i += 1) {
  713. if (layers[i].ty === 4) {
  714. iterateShapes(layers[i].shapes);
  715. }
  716. }
  717. }
  718. return function (animationData) {
  719. if (checkVersion(minimumVersion, animationData.v)) {
  720. iterateLayers(animationData.layers);
  721. if (animationData.assets) {
  722. var i;
  723. var len = animationData.assets.length;
  724. for (i = 0; i < len; i += 1) {
  725. if (animationData.assets[i].layers) {
  726. iterateLayers(animationData.assets[i].layers);
  727. }
  728. }
  729. }
  730. }
  731. };
  732. }());
  733. var checkShapes = (function () {
  734. var minimumVersion = [4, 4, 18];
  735. function completeClosingShapes(arr) {
  736. var i;
  737. var len = arr.length;
  738. var j;
  739. var jLen;
  740. for (i = len - 1; i >= 0; i -= 1) {
  741. if (arr[i].ty === 'sh') {
  742. if (arr[i].ks.k.i) {
  743. arr[i].ks.k.c = arr[i].closed;
  744. } else {
  745. jLen = arr[i].ks.k.length;
  746. for (j = 0; j < jLen; j += 1) {
  747. if (arr[i].ks.k[j].s) {
  748. arr[i].ks.k[j].s[0].c = arr[i].closed;
  749. }
  750. if (arr[i].ks.k[j].e) {
  751. arr[i].ks.k[j].e[0].c = arr[i].closed;
  752. }
  753. }
  754. }
  755. } else if (arr[i].ty === 'gr') {
  756. completeClosingShapes(arr[i].it);
  757. }
  758. }
  759. }
  760. function iterateLayers(layers) {
  761. var layerData;
  762. var i;
  763. var len = layers.length;
  764. var j;
  765. var jLen;
  766. var k;
  767. var kLen;
  768. for (i = 0; i < len; i += 1) {
  769. layerData = layers[i];
  770. if (layerData.hasMask) {
  771. var maskProps = layerData.masksProperties;
  772. jLen = maskProps.length;
  773. for (j = 0; j < jLen; j += 1) {
  774. if (maskProps[j].pt.k.i) {
  775. maskProps[j].pt.k.c = maskProps[j].cl;
  776. } else {
  777. kLen = maskProps[j].pt.k.length;
  778. for (k = 0; k < kLen; k += 1) {
  779. if (maskProps[j].pt.k[k].s) {
  780. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  781. }
  782. if (maskProps[j].pt.k[k].e) {
  783. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  784. }
  785. }
  786. }
  787. }
  788. }
  789. if (layerData.ty === 4) {
  790. completeClosingShapes(layerData.shapes);
  791. }
  792. }
  793. }
  794. return function (animationData) {
  795. if (checkVersion(minimumVersion, animationData.v)) {
  796. iterateLayers(animationData.layers);
  797. if (animationData.assets) {
  798. var i;
  799. var len = animationData.assets.length;
  800. for (i = 0; i < len; i += 1) {
  801. if (animationData.assets[i].layers) {
  802. iterateLayers(animationData.assets[i].layers);
  803. }
  804. }
  805. }
  806. }
  807. };
  808. }());
  809. function completeData(animationData) {
  810. if (animationData.__complete) {
  811. return;
  812. }
  813. checkColors(animationData);
  814. checkText(animationData);
  815. checkChars(animationData);
  816. checkPathProperties(animationData);
  817. checkShapes(animationData);
  818. completeLayers(animationData.layers, animationData.assets);
  819. completeChars(animationData.chars, animationData.assets);
  820. animationData.__complete = true;
  821. }
  822. function completeText(data) {
  823. if (data.t.a.length === 0 && !('m' in data.t.p)) {
  824. // data.singleShape = true;
  825. }
  826. }
  827. var moduleOb = {};
  828. moduleOb.completeData = completeData;
  829. moduleOb.checkColors = checkColors;
  830. moduleOb.checkChars = checkChars;
  831. moduleOb.checkPathProperties = checkPathProperties;
  832. moduleOb.checkShapes = checkShapes;
  833. moduleOb.completeLayers = completeLayers;
  834. return moduleOb;
  835. }
  836. if (!_workerSelf.dataManager) {
  837. _workerSelf.dataManager = dataFunctionManager();
  838. }
  839. if (!_workerSelf.assetLoader) {
  840. _workerSelf.assetLoader = (function () {
  841. function formatResponse(xhr) {
  842. // using typeof doubles the time of execution of this method,
  843. // so if available, it's better to use the header to validate the type
  844. var contentTypeHeader = xhr.getResponseHeader('content-type');
  845. if (contentTypeHeader && xhr.responseType === 'json' && contentTypeHeader.indexOf('json') !== -1) {
  846. return xhr.response;
  847. }
  848. if (xhr.response && typeof xhr.response === 'object') {
  849. return xhr.response;
  850. } if (xhr.response && typeof xhr.response === 'string') {
  851. return JSON.parse(xhr.response);
  852. } if (xhr.responseText) {
  853. return JSON.parse(xhr.responseText);
  854. }
  855. return null;
  856. }
  857. function loadAsset(path, fullPath, callback, errorCallback) {
  858. var response;
  859. var xhr = new XMLHttpRequest();
  860. // set responseType after calling open or IE will break.
  861. try {
  862. // This crashes on Android WebView prior to KitKat
  863. xhr.responseType = 'json';
  864. } catch (err) {} // eslint-disable-line no-empty
  865. xhr.onreadystatechange = function () {
  866. if (xhr.readyState === 4) {
  867. if (xhr.status === 200) {
  868. response = formatResponse(xhr);
  869. callback(response);
  870. } else {
  871. try {
  872. response = formatResponse(xhr);
  873. callback(response);
  874. } catch (err) {
  875. if (errorCallback) {
  876. errorCallback(err);
  877. }
  878. }
  879. }
  880. }
  881. };
  882. try {
  883. xhr.open('GET', path, true);
  884. } catch (error) {
  885. xhr.open('GET', fullPath + '/' + path, true);
  886. }
  887. xhr.send();
  888. }
  889. return {
  890. load: loadAsset,
  891. };
  892. }());
  893. }
  894. if (e.data.type === 'loadAnimation') {
  895. _workerSelf.assetLoader.load(
  896. e.data.path,
  897. e.data.fullPath,
  898. function (data) {
  899. _workerSelf.dataManager.completeData(data);
  900. _workerSelf.postMessage({
  901. id: e.data.id,
  902. payload: data,
  903. status: 'success',
  904. });
  905. },
  906. function () {
  907. _workerSelf.postMessage({
  908. id: e.data.id,
  909. status: 'error',
  910. });
  911. }
  912. );
  913. } else if (e.data.type === 'complete') {
  914. var animation = e.data.animation;
  915. _workerSelf.dataManager.completeData(animation);
  916. _workerSelf.postMessage({
  917. id: e.data.id,
  918. payload: animation,
  919. status: 'success',
  920. });
  921. } else if (e.data.type === 'loadData') {
  922. _workerSelf.assetLoader.load(
  923. e.data.path,
  924. e.data.fullPath,
  925. function (data) {
  926. _workerSelf.postMessage({
  927. id: e.data.id,
  928. payload: data,
  929. status: 'success',
  930. });
  931. },
  932. function () {
  933. _workerSelf.postMessage({
  934. id: e.data.id,
  935. status: 'error',
  936. });
  937. }
  938. );
  939. }
  940. });
  941. workerInstance.onmessage = function (event) {
  942. var data = event.data;
  943. var id = data.id;
  944. var process = processes[id];
  945. processes[id] = null;
  946. if (data.status === 'success') {
  947. process.onComplete(data.payload);
  948. } else if (process.onError) {
  949. process.onError();
  950. }
  951. };
  952. }
  953. }
  954. function createProcess(onComplete, onError) {
  955. _counterId += 1;
  956. var id = 'processId_' + _counterId;
  957. processes[id] = {
  958. onComplete: onComplete,
  959. onError: onError,
  960. };
  961. return id;
  962. }
  963. function loadAnimation(path, onComplete, onError) {
  964. setupWorker();
  965. var processId = createProcess(onComplete, onError);
  966. workerInstance.postMessage({
  967. type: 'loadAnimation',
  968. path: path,
  969. fullPath: window.location.origin + window.location.pathname,
  970. id: processId,
  971. });
  972. }
  973. function loadData(path, onComplete, onError) {
  974. setupWorker();
  975. var processId = createProcess(onComplete, onError);
  976. workerInstance.postMessage({
  977. type: 'loadData',
  978. path: path,
  979. fullPath: window.location.origin + window.location.pathname,
  980. id: processId,
  981. });
  982. }
  983. function completeAnimation(anim, onComplete, onError) {
  984. setupWorker();
  985. var processId = createProcess(onComplete, onError);
  986. workerInstance.postMessage({
  987. type: 'complete',
  988. animation: anim,
  989. id: processId,
  990. });
  991. }
  992. return {
  993. loadAnimation: loadAnimation,
  994. loadData: loadData,
  995. completeAnimation: completeAnimation,
  996. };
  997. }());
  998. const ImagePreloader = (function () {
  999. var proxyImage = (function () {
  1000. var canvas = createTag('canvas');
  1001. canvas.width = 1;
  1002. canvas.height = 1;
  1003. var ctx = canvas.getContext('2d');
  1004. ctx.fillStyle = 'rgba(0,0,0,0)';
  1005. ctx.fillRect(0, 0, 1, 1);
  1006. return canvas;
  1007. }());
  1008. function imageLoaded() {
  1009. this.loadedAssets += 1;
  1010. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1011. if (this.imagesLoadedCb) {
  1012. this.imagesLoadedCb(null);
  1013. }
  1014. }
  1015. }
  1016. function footageLoaded() {
  1017. this.loadedFootagesCount += 1;
  1018. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1019. if (this.imagesLoadedCb) {
  1020. this.imagesLoadedCb(null);
  1021. }
  1022. }
  1023. }
  1024. function getAssetsPath(assetData, assetsPath, originalPath) {
  1025. var path = '';
  1026. if (assetData.e) {
  1027. path = assetData.p;
  1028. } else if (assetsPath) {
  1029. var imagePath = assetData.p;
  1030. if (imagePath.indexOf('images/') !== -1) {
  1031. imagePath = imagePath.split('/')[1];
  1032. }
  1033. path = assetsPath + imagePath;
  1034. } else {
  1035. path = originalPath;
  1036. path += assetData.u ? assetData.u : '';
  1037. path += assetData.p;
  1038. }
  1039. return path;
  1040. }
  1041. function testImageLoaded(img) {
  1042. var _count = 0;
  1043. var intervalId = setInterval(function () {
  1044. var box = img.getBBox();
  1045. if (box.width || _count > 500) {
  1046. this._imageLoaded();
  1047. clearInterval(intervalId);
  1048. }
  1049. _count += 1;
  1050. }.bind(this), 50);
  1051. }
  1052. function createImageData(assetData) {
  1053. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1054. var img = createNS('image');
  1055. if (isSafari) {
  1056. this.testImageLoaded(img);
  1057. } else {
  1058. img.addEventListener('load', this._imageLoaded, false);
  1059. }
  1060. img.addEventListener('error', function () {
  1061. ob.img = proxyImage;
  1062. this._imageLoaded();
  1063. }.bind(this), false);
  1064. img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
  1065. if (this._elementHelper.append) {
  1066. this._elementHelper.append(img);
  1067. } else {
  1068. this._elementHelper.appendChild(img);
  1069. }
  1070. var ob = {
  1071. img: img,
  1072. assetData: assetData,
  1073. };
  1074. return ob;
  1075. }
  1076. function createImgData(assetData) {
  1077. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1078. var img = createTag('img');
  1079. img.crossOrigin = 'anonymous';
  1080. img.addEventListener('load', this._imageLoaded, false);
  1081. img.addEventListener('error', function () {
  1082. ob.img = proxyImage;
  1083. this._imageLoaded();
  1084. }.bind(this), false);
  1085. img.src = path;
  1086. var ob = {
  1087. img: img,
  1088. assetData: assetData,
  1089. };
  1090. return ob;
  1091. }
  1092. function createFootageData(data) {
  1093. var ob = {
  1094. assetData: data,
  1095. };
  1096. var path = getAssetsPath(data, this.assetsPath, this.path);
  1097. dataManager.loadData(path, function (footageData) {
  1098. ob.img = footageData;
  1099. this._footageLoaded();
  1100. }.bind(this), function () {
  1101. ob.img = {};
  1102. this._footageLoaded();
  1103. }.bind(this));
  1104. return ob;
  1105. }
  1106. function loadAssets(assets, cb) {
  1107. this.imagesLoadedCb = cb;
  1108. var i;
  1109. var len = assets.length;
  1110. for (i = 0; i < len; i += 1) {
  1111. if (!assets[i].layers) {
  1112. if (!assets[i].t || assets[i].t === 'seq') {
  1113. this.totalImages += 1;
  1114. this.images.push(this._createImageData(assets[i]));
  1115. } else if (assets[i].t === 3) {
  1116. this.totalFootages += 1;
  1117. this.images.push(this.createFootageData(assets[i]));
  1118. }
  1119. }
  1120. }
  1121. }
  1122. function setPath(path) {
  1123. this.path = path || '';
  1124. }
  1125. function setAssetsPath(path) {
  1126. this.assetsPath = path || '';
  1127. }
  1128. function getAsset(assetData) {
  1129. var i = 0;
  1130. var len = this.images.length;
  1131. while (i < len) {
  1132. if (this.images[i].assetData === assetData) {
  1133. return this.images[i].img;
  1134. }
  1135. i += 1;
  1136. }
  1137. return null;
  1138. }
  1139. function destroy() {
  1140. this.imagesLoadedCb = null;
  1141. this.images.length = 0;
  1142. }
  1143. function loadedImages() {
  1144. return this.totalImages === this.loadedAssets;
  1145. }
  1146. function loadedFootages() {
  1147. return this.totalFootages === this.loadedFootagesCount;
  1148. }
  1149. function setCacheType(type, elementHelper) {
  1150. if (type === 'svg') {
  1151. this._elementHelper = elementHelper;
  1152. this._createImageData = this.createImageData.bind(this);
  1153. } else {
  1154. this._createImageData = this.createImgData.bind(this);
  1155. }
  1156. }
  1157. function ImagePreloaderFactory() {
  1158. this._imageLoaded = imageLoaded.bind(this);
  1159. this._footageLoaded = footageLoaded.bind(this);
  1160. this.testImageLoaded = testImageLoaded.bind(this);
  1161. this.createFootageData = createFootageData.bind(this);
  1162. this.assetsPath = '';
  1163. this.path = '';
  1164. this.totalImages = 0;
  1165. this.totalFootages = 0;
  1166. this.loadedAssets = 0;
  1167. this.loadedFootagesCount = 0;
  1168. this.imagesLoadedCb = null;
  1169. this.images = [];
  1170. }
  1171. ImagePreloaderFactory.prototype = {
  1172. loadAssets: loadAssets,
  1173. setAssetsPath: setAssetsPath,
  1174. setPath: setPath,
  1175. loadedImages: loadedImages,
  1176. loadedFootages: loadedFootages,
  1177. destroy: destroy,
  1178. getAsset: getAsset,
  1179. createImgData: createImgData,
  1180. createImageData: createImageData,
  1181. imageLoaded: imageLoaded,
  1182. footageLoaded: footageLoaded,
  1183. setCacheType: setCacheType,
  1184. };
  1185. return ImagePreloaderFactory;
  1186. }());
  1187. function BaseEvent() {}
  1188. BaseEvent.prototype = {
  1189. triggerEvent: function (eventName, args) {
  1190. if (this._cbs[eventName]) {
  1191. var callbacks = this._cbs[eventName];
  1192. for (var i = 0; i < callbacks.length; i += 1) {
  1193. callbacks[i](args);
  1194. }
  1195. }
  1196. },
  1197. addEventListener: function (eventName, callback) {
  1198. if (!this._cbs[eventName]) {
  1199. this._cbs[eventName] = [];
  1200. }
  1201. this._cbs[eventName].push(callback);
  1202. return function () {
  1203. this.removeEventListener(eventName, callback);
  1204. }.bind(this);
  1205. },
  1206. removeEventListener: function (eventName, callback) {
  1207. if (!callback) {
  1208. this._cbs[eventName] = null;
  1209. } else if (this._cbs[eventName]) {
  1210. var i = 0;
  1211. var len = this._cbs[eventName].length;
  1212. while (i < len) {
  1213. if (this._cbs[eventName][i] === callback) {
  1214. this._cbs[eventName].splice(i, 1);
  1215. i -= 1;
  1216. len -= 1;
  1217. }
  1218. i += 1;
  1219. }
  1220. if (!this._cbs[eventName].length) {
  1221. this._cbs[eventName] = null;
  1222. }
  1223. }
  1224. },
  1225. };
  1226. const markerParser = (
  1227. function () {
  1228. function parsePayloadLines(payload) {
  1229. var lines = payload.split('\r\n');
  1230. var keys = {};
  1231. var line;
  1232. var keysCount = 0;
  1233. for (var i = 0; i < lines.length; i += 1) {
  1234. line = lines[i].split(':');
  1235. if (line.length === 2) {
  1236. keys[line[0]] = line[1].trim();
  1237. keysCount += 1;
  1238. }
  1239. }
  1240. if (keysCount === 0) {
  1241. throw new Error();
  1242. }
  1243. return keys;
  1244. }
  1245. return function (_markers) {
  1246. var markers = [];
  1247. for (var i = 0; i < _markers.length; i += 1) {
  1248. var _marker = _markers[i];
  1249. var markerData = {
  1250. time: _marker.tm,
  1251. duration: _marker.dr,
  1252. };
  1253. try {
  1254. markerData.payload = JSON.parse(_markers[i].cm);
  1255. } catch (_) {
  1256. try {
  1257. markerData.payload = parsePayloadLines(_markers[i].cm);
  1258. } catch (__) {
  1259. markerData.payload = {
  1260. name: _markers[i].cm,
  1261. };
  1262. }
  1263. }
  1264. markers.push(markerData);
  1265. }
  1266. return markers;
  1267. };
  1268. }());
  1269. const ProjectInterface = (function () {
  1270. function registerComposition(comp) {
  1271. this.compositions.push(comp);
  1272. }
  1273. return function () {
  1274. function _thisProjectFunction(name) {
  1275. var i = 0;
  1276. var len = this.compositions.length;
  1277. while (i < len) {
  1278. if (this.compositions[i].data && this.compositions[i].data.nm === name) {
  1279. if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  1280. this.compositions[i].prepareFrame(this.currentFrame);
  1281. }
  1282. return this.compositions[i].compInterface;
  1283. }
  1284. i += 1;
  1285. }
  1286. return null;
  1287. }
  1288. _thisProjectFunction.compositions = [];
  1289. _thisProjectFunction.currentFrame = 0;
  1290. _thisProjectFunction.registerComposition = registerComposition;
  1291. return _thisProjectFunction;
  1292. };
  1293. }());
  1294. const renderers = {};
  1295. const registerRenderer = (key, value) => {
  1296. renderers[key] = value;
  1297. };
  1298. function getRenderer(key) {
  1299. return renderers[key];
  1300. }
  1301. const AnimationItem = function () {
  1302. this._cbs = [];
  1303. this.name = '';
  1304. this.path = '';
  1305. this.isLoaded = false;
  1306. this.currentFrame = 0;
  1307. this.currentRawFrame = 0;
  1308. this.firstFrame = 0;
  1309. this.totalFrames = 0;
  1310. this.frameRate = 0;
  1311. this.frameMult = 0;
  1312. this.playSpeed = 1;
  1313. this.playDirection = 1;
  1314. this.playCount = 0;
  1315. this.animationData = {};
  1316. this.assets = [];
  1317. this.isPaused = true;
  1318. this.autoplay = false;
  1319. this.loop = true;
  1320. this.renderer = null;
  1321. this.animationID = createElementID();
  1322. this.assetsPath = '';
  1323. this.timeCompleted = 0;
  1324. this.segmentPos = 0;
  1325. this.isSubframeEnabled = getSubframeEnabled();
  1326. this.segments = [];
  1327. this._idle = true;
  1328. this._completedLoop = false;
  1329. this.projectInterface = ProjectInterface();
  1330. this.imagePreloader = new ImagePreloader();
  1331. this.audioController = audioControllerFactory();
  1332. this.markers = [];
  1333. this.configAnimation = this.configAnimation.bind(this);
  1334. this.onSetupError = this.onSetupError.bind(this);
  1335. this.onSegmentComplete = this.onSegmentComplete.bind(this);
  1336. this.drawnFrameEvent = new BMEnterFrameEvent('drawnFrame', 0, 0, 0);
  1337. };
  1338. extendPrototype([BaseEvent], AnimationItem);
  1339. AnimationItem.prototype.setParams = function (params) {
  1340. if (params.wrapper || params.container) {
  1341. this.wrapper = params.wrapper || params.container;
  1342. }
  1343. var animType = 'svg';
  1344. if (params.animType) {
  1345. animType = params.animType;
  1346. } else if (params.renderer) {
  1347. animType = params.renderer;
  1348. }
  1349. const RendererClass = getRenderer(animType);
  1350. this.renderer = new RendererClass(this, params.rendererSettings);
  1351. this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs);
  1352. this.renderer.setProjectInterface(this.projectInterface);
  1353. this.animType = animType;
  1354. if (params.loop === ''
  1355. || params.loop === null
  1356. || params.loop === undefined
  1357. || params.loop === true) {
  1358. this.loop = true;
  1359. } else if (params.loop === false) {
  1360. this.loop = false;
  1361. } else {
  1362. this.loop = parseInt(params.loop, 10);
  1363. }
  1364. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  1365. this.name = params.name ? params.name : '';
  1366. this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true;
  1367. this.assetsPath = params.assetsPath;
  1368. this.initialSegment = params.initialSegment;
  1369. if (params.audioFactory) {
  1370. this.audioController.setAudioFactory(params.audioFactory);
  1371. }
  1372. if (params.animationData) {
  1373. this.setupAnimation(params.animationData);
  1374. } else if (params.path) {
  1375. if (params.path.lastIndexOf('\\') !== -1) {
  1376. this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1);
  1377. } else {
  1378. this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1);
  1379. }
  1380. this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1);
  1381. this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json'));
  1382. dataManager.loadAnimation(
  1383. params.path,
  1384. this.configAnimation,
  1385. this.onSetupError
  1386. );
  1387. }
  1388. };
  1389. AnimationItem.prototype.onSetupError = function () {
  1390. this.trigger('data_failed');
  1391. };
  1392. AnimationItem.prototype.setupAnimation = function (data) {
  1393. dataManager.completeAnimation(
  1394. data,
  1395. this.configAnimation
  1396. );
  1397. };
  1398. AnimationItem.prototype.setData = function (wrapper, animationData) {
  1399. if (animationData) {
  1400. if (typeof animationData !== 'object') {
  1401. animationData = JSON.parse(animationData);
  1402. }
  1403. }
  1404. var params = {
  1405. wrapper: wrapper,
  1406. animationData: animationData,
  1407. };
  1408. var wrapperAttributes = wrapper.attributes;
  1409. params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary
  1410. ? wrapperAttributes.getNamedItem('data-animation-path').value
  1411. : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary
  1412. ? wrapperAttributes.getNamedItem('data-bm-path').value
  1413. : wrapperAttributes.getNamedItem('bm-path')
  1414. ? wrapperAttributes.getNamedItem('bm-path').value
  1415. : '';
  1416. params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary
  1417. ? wrapperAttributes.getNamedItem('data-anim-type').value
  1418. : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary
  1419. ? wrapperAttributes.getNamedItem('data-bm-type').value
  1420. : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary
  1421. ? wrapperAttributes.getNamedItem('bm-type').value
  1422. : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary
  1423. ? wrapperAttributes.getNamedItem('data-bm-renderer').value
  1424. : wrapperAttributes.getNamedItem('bm-renderer')
  1425. ? wrapperAttributes.getNamedItem('bm-renderer').value
  1426. : 'canvas';
  1427. var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary
  1428. ? wrapperAttributes.getNamedItem('data-anim-loop').value
  1429. : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary
  1430. ? wrapperAttributes.getNamedItem('data-bm-loop').value
  1431. : wrapperAttributes.getNamedItem('bm-loop')
  1432. ? wrapperAttributes.getNamedItem('bm-loop').value
  1433. : '';
  1434. if (loop === 'false') {
  1435. params.loop = false;
  1436. } else if (loop === 'true') {
  1437. params.loop = true;
  1438. } else if (loop !== '') {
  1439. params.loop = parseInt(loop, 10);
  1440. }
  1441. var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary
  1442. ? wrapperAttributes.getNamedItem('data-anim-autoplay').value
  1443. : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary
  1444. ? wrapperAttributes.getNamedItem('data-bm-autoplay').value
  1445. : wrapperAttributes.getNamedItem('bm-autoplay')
  1446. ? wrapperAttributes.getNamedItem('bm-autoplay').value
  1447. : true;
  1448. params.autoplay = autoplay !== 'false';
  1449. params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary
  1450. ? wrapperAttributes.getNamedItem('data-name').value
  1451. : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary
  1452. ? wrapperAttributes.getNamedItem('data-bm-name').value
  1453. : wrapperAttributes.getNamedItem('bm-name')
  1454. ? wrapperAttributes.getNamedItem('bm-name').value
  1455. : '';
  1456. var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary
  1457. ? wrapperAttributes.getNamedItem('data-anim-prerender').value
  1458. : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary
  1459. ? wrapperAttributes.getNamedItem('data-bm-prerender').value
  1460. : wrapperAttributes.getNamedItem('bm-prerender')
  1461. ? wrapperAttributes.getNamedItem('bm-prerender').value
  1462. : '';
  1463. if (prerender === 'false') {
  1464. params.prerender = false;
  1465. }
  1466. this.setParams(params);
  1467. };
  1468. AnimationItem.prototype.includeLayers = function (data) {
  1469. if (data.op > this.animationData.op) {
  1470. this.animationData.op = data.op;
  1471. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  1472. }
  1473. var layers = this.animationData.layers;
  1474. var i;
  1475. var len = layers.length;
  1476. var newLayers = data.layers;
  1477. var j;
  1478. var jLen = newLayers.length;
  1479. for (j = 0; j < jLen; j += 1) {
  1480. i = 0;
  1481. while (i < len) {
  1482. if (layers[i].id === newLayers[j].id) {
  1483. layers[i] = newLayers[j];
  1484. break;
  1485. }
  1486. i += 1;
  1487. }
  1488. }
  1489. if (data.chars || data.fonts) {
  1490. this.renderer.globalData.fontManager.addChars(data.chars);
  1491. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  1492. }
  1493. if (data.assets) {
  1494. len = data.assets.length;
  1495. for (i = 0; i < len; i += 1) {
  1496. this.animationData.assets.push(data.assets[i]);
  1497. }
  1498. }
  1499. this.animationData.__complete = false;
  1500. dataManager.completeAnimation(
  1501. this.animationData,
  1502. this.onSegmentComplete
  1503. );
  1504. };
  1505. AnimationItem.prototype.onSegmentComplete = function (data) {
  1506. this.animationData = data;
  1507. var expressionsPlugin = getExpressionsPlugin();
  1508. if (expressionsPlugin) {
  1509. expressionsPlugin.initExpressions(this);
  1510. }
  1511. this.loadNextSegment();
  1512. };
  1513. AnimationItem.prototype.loadNextSegment = function () {
  1514. var segments = this.animationData.segments;
  1515. if (!segments || segments.length === 0 || !this.autoloadSegments) {
  1516. this.trigger('data_ready');
  1517. this.timeCompleted = this.totalFrames;
  1518. return;
  1519. }
  1520. var segment = segments.shift();
  1521. this.timeCompleted = segment.time * this.frameRate;
  1522. var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json';
  1523. this.segmentPos += 1;
  1524. dataManager.loadData(segmentPath, this.includeLayers.bind(this), function () {
  1525. this.trigger('data_failed');
  1526. }.bind(this));
  1527. };
  1528. AnimationItem.prototype.loadSegments = function () {
  1529. var segments = this.animationData.segments;
  1530. if (!segments) {
  1531. this.timeCompleted = this.totalFrames;
  1532. }
  1533. this.loadNextSegment();
  1534. };
  1535. AnimationItem.prototype.imagesLoaded = function () {
  1536. this.trigger('loaded_images');
  1537. this.checkLoaded();
  1538. };
  1539. AnimationItem.prototype.preloadImages = function () {
  1540. this.imagePreloader.setAssetsPath(this.assetsPath);
  1541. this.imagePreloader.setPath(this.path);
  1542. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  1543. };
  1544. AnimationItem.prototype.configAnimation = function (animData) {
  1545. if (!this.renderer) {
  1546. return;
  1547. }
  1548. try {
  1549. this.animationData = animData;
  1550. if (this.initialSegment) {
  1551. this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
  1552. this.firstFrame = Math.round(this.initialSegment[0]);
  1553. } else {
  1554. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  1555. this.firstFrame = Math.round(this.animationData.ip);
  1556. }
  1557. this.renderer.configAnimation(animData);
  1558. if (!animData.assets) {
  1559. animData.assets = [];
  1560. }
  1561. this.assets = this.animationData.assets;
  1562. this.frameRate = this.animationData.fr;
  1563. this.frameMult = this.animationData.fr / 1000;
  1564. this.renderer.searchExtraCompositions(animData.assets);
  1565. this.markers = markerParser(animData.markers || []);
  1566. this.trigger('config_ready');
  1567. this.preloadImages();
  1568. this.loadSegments();
  1569. this.updaFrameModifier();
  1570. this.waitForFontsLoaded();
  1571. if (this.isPaused) {
  1572. this.audioController.pause();
  1573. }
  1574. } catch (error) {
  1575. this.triggerConfigError(error);
  1576. }
  1577. };
  1578. AnimationItem.prototype.waitForFontsLoaded = function () {
  1579. if (!this.renderer) {
  1580. return;
  1581. }
  1582. if (this.renderer.globalData.fontManager.isLoaded) {
  1583. this.checkLoaded();
  1584. } else {
  1585. setTimeout(this.waitForFontsLoaded.bind(this), 20);
  1586. }
  1587. };
  1588. AnimationItem.prototype.checkLoaded = function () {
  1589. if (!this.isLoaded
  1590. && this.renderer.globalData.fontManager.isLoaded
  1591. && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== 'canvas')
  1592. && (this.imagePreloader.loadedFootages())
  1593. ) {
  1594. this.isLoaded = true;
  1595. var expressionsPlugin = getExpressionsPlugin();
  1596. if (expressionsPlugin) {
  1597. expressionsPlugin.initExpressions(this);
  1598. }
  1599. this.renderer.initItems();
  1600. setTimeout(function () {
  1601. this.trigger('DOMLoaded');
  1602. }.bind(this), 0);
  1603. this.gotoFrame();
  1604. if (this.autoplay) {
  1605. this.play();
  1606. }
  1607. }
  1608. };
  1609. AnimationItem.prototype.resize = function () {
  1610. this.renderer.updateContainerSize();
  1611. };
  1612. AnimationItem.prototype.setSubframe = function (flag) {
  1613. this.isSubframeEnabled = !!flag;
  1614. };
  1615. AnimationItem.prototype.gotoFrame = function () {
  1616. this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise
  1617. if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) {
  1618. this.currentFrame = this.timeCompleted;
  1619. }
  1620. this.trigger('enterFrame');
  1621. this.renderFrame();
  1622. this.trigger('drawnFrame');
  1623. };
  1624. AnimationItem.prototype.renderFrame = function () {
  1625. if (this.isLoaded === false || !this.renderer) {
  1626. return;
  1627. }
  1628. try {
  1629. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  1630. } catch (error) {
  1631. this.triggerRenderFrameError(error);
  1632. }
  1633. };
  1634. AnimationItem.prototype.play = function (name) {
  1635. if (name && this.name !== name) {
  1636. return;
  1637. }
  1638. if (this.isPaused === true) {
  1639. this.isPaused = false;
  1640. this.trigger('_pause');
  1641. this.audioController.resume();
  1642. if (this._idle) {
  1643. this._idle = false;
  1644. this.trigger('_active');
  1645. }
  1646. }
  1647. };
  1648. AnimationItem.prototype.pause = function (name) {
  1649. if (name && this.name !== name) {
  1650. return;
  1651. }
  1652. if (this.isPaused === false) {
  1653. this.isPaused = true;
  1654. this.trigger('_play');
  1655. this._idle = true;
  1656. this.trigger('_idle');
  1657. this.audioController.pause();
  1658. }
  1659. };
  1660. AnimationItem.prototype.togglePause = function (name) {
  1661. if (name && this.name !== name) {
  1662. return;
  1663. }
  1664. if (this.isPaused === true) {
  1665. this.play();
  1666. } else {
  1667. this.pause();
  1668. }
  1669. };
  1670. AnimationItem.prototype.stop = function (name) {
  1671. if (name && this.name !== name) {
  1672. return;
  1673. }
  1674. this.pause();
  1675. this.playCount = 0;
  1676. this._completedLoop = false;
  1677. this.setCurrentRawFrameValue(0);
  1678. };
  1679. AnimationItem.prototype.getMarkerData = function (markerName) {
  1680. var marker;
  1681. for (var i = 0; i < this.markers.length; i += 1) {
  1682. marker = this.markers[i];
  1683. if (marker.payload && marker.payload.name === markerName) {
  1684. return marker;
  1685. }
  1686. }
  1687. return null;
  1688. };
  1689. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  1690. if (name && this.name !== name) {
  1691. return;
  1692. }
  1693. var numValue = Number(value);
  1694. if (isNaN(numValue)) {
  1695. var marker = this.getMarkerData(value);
  1696. if (marker) {
  1697. this.goToAndStop(marker.time, true);
  1698. }
  1699. } else if (isFrame) {
  1700. this.setCurrentRawFrameValue(value);
  1701. } else {
  1702. this.setCurrentRawFrameValue(value * this.frameModifier);
  1703. }
  1704. this.pause();
  1705. };
  1706. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  1707. if (name && this.name !== name) {
  1708. return;
  1709. }
  1710. var numValue = Number(value);
  1711. if (isNaN(numValue)) {
  1712. var marker = this.getMarkerData(value);
  1713. if (marker) {
  1714. if (!marker.duration) {
  1715. this.goToAndStop(marker.time, true);
  1716. } else {
  1717. this.playSegments([marker.time, marker.time + marker.duration], true);
  1718. }
  1719. }
  1720. } else {
  1721. this.goToAndStop(numValue, isFrame, name);
  1722. }
  1723. this.play();
  1724. };
  1725. AnimationItem.prototype.advanceTime = function (value) {
  1726. if (this.isPaused === true || this.isLoaded === false) {
  1727. return;
  1728. }
  1729. var nextValue = this.currentRawFrame + value * this.frameModifier;
  1730. var _isComplete = false;
  1731. // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  1732. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  1733. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  1734. if (!this.loop || this.playCount === this.loop) {
  1735. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  1736. _isComplete = true;
  1737. nextValue = this.totalFrames - 1;
  1738. }
  1739. } else if (nextValue >= this.totalFrames) {
  1740. this.playCount += 1;
  1741. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1742. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  1743. this._completedLoop = true;
  1744. this.trigger('loopComplete');
  1745. }
  1746. } else {
  1747. this.setCurrentRawFrameValue(nextValue);
  1748. }
  1749. } else if (nextValue < 0) {
  1750. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1751. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) { // eslint-disable-line no-plusplus
  1752. this.setCurrentRawFrameValue(this.totalFrames + (nextValue % this.totalFrames));
  1753. if (!this._completedLoop) {
  1754. this._completedLoop = true;
  1755. } else {
  1756. this.trigger('loopComplete');
  1757. }
  1758. } else {
  1759. _isComplete = true;
  1760. nextValue = 0;
  1761. }
  1762. }
  1763. } else {
  1764. this.setCurrentRawFrameValue(nextValue);
  1765. }
  1766. if (_isComplete) {
  1767. this.setCurrentRawFrameValue(nextValue);
  1768. this.pause();
  1769. this.trigger('complete');
  1770. }
  1771. };
  1772. AnimationItem.prototype.adjustSegment = function (arr, offset) {
  1773. this.playCount = 0;
  1774. if (arr[1] < arr[0]) {
  1775. if (this.frameModifier > 0) {
  1776. if (this.playSpeed < 0) {
  1777. this.setSpeed(-this.playSpeed);
  1778. } else {
  1779. this.setDirection(-1);
  1780. }
  1781. }
  1782. this.totalFrames = arr[0] - arr[1];
  1783. this.timeCompleted = this.totalFrames;
  1784. this.firstFrame = arr[1];
  1785. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  1786. } else if (arr[1] > arr[0]) {
  1787. if (this.frameModifier < 0) {
  1788. if (this.playSpeed < 0) {
  1789. this.setSpeed(-this.playSpeed);
  1790. } else {
  1791. this.setDirection(1);
  1792. }
  1793. }
  1794. this.totalFrames = arr[1] - arr[0];
  1795. this.timeCompleted = this.totalFrames;
  1796. this.firstFrame = arr[0];
  1797. this.setCurrentRawFrameValue(0.001 + offset);
  1798. }
  1799. this.trigger('segmentStart');
  1800. };
  1801. AnimationItem.prototype.setSegment = function (init, end) {
  1802. var pendingFrame = -1;
  1803. if (this.isPaused) {
  1804. if (this.currentRawFrame + this.firstFrame < init) {
  1805. pendingFrame = init;
  1806. } else if (this.currentRawFrame + this.firstFrame > end) {
  1807. pendingFrame = end - init;
  1808. }
  1809. }
  1810. this.firstFrame = init;
  1811. this.totalFrames = end - init;
  1812. this.timeCompleted = this.totalFrames;
  1813. if (pendingFrame !== -1) {
  1814. this.goToAndStop(pendingFrame, true);
  1815. }
  1816. };
  1817. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  1818. if (forceFlag) {
  1819. this.segments.length = 0;
  1820. }
  1821. if (typeof arr[0] === 'object') {
  1822. var i;
  1823. var len = arr.length;
  1824. for (i = 0; i < len; i += 1) {
  1825. this.segments.push(arr[i]);
  1826. }
  1827. } else {
  1828. this.segments.push(arr);
  1829. }
  1830. if (this.segments.length && forceFlag) {
  1831. this.adjustSegment(this.segments.shift(), 0);
  1832. }
  1833. if (this.isPaused) {
  1834. this.play();
  1835. }
  1836. };
  1837. AnimationItem.prototype.resetSegments = function (forceFlag) {
  1838. this.segments.length = 0;
  1839. this.segments.push([this.animationData.ip, this.animationData.op]);
  1840. if (forceFlag) {
  1841. this.checkSegments(0);
  1842. }
  1843. };
  1844. AnimationItem.prototype.checkSegments = function (offset) {
  1845. if (this.segments.length) {
  1846. this.adjustSegment(this.segments.shift(), offset);
  1847. return true;
  1848. }
  1849. return false;
  1850. };
  1851. AnimationItem.prototype.destroy = function (name) {
  1852. if ((name && this.name !== name) || !this.renderer) {
  1853. return;
  1854. }
  1855. this.renderer.destroy();
  1856. this.imagePreloader.destroy();
  1857. this.trigger('destroy');
  1858. this._cbs = null;
  1859. this.onEnterFrame = null;
  1860. this.onLoopComplete = null;
  1861. this.onComplete = null;
  1862. this.onSegmentStart = null;
  1863. this.onDestroy = null;
  1864. this.renderer = null;
  1865. this.renderer = null;
  1866. this.imagePreloader = null;
  1867. this.projectInterface = null;
  1868. };
  1869. AnimationItem.prototype.setCurrentRawFrameValue = function (value) {
  1870. this.currentRawFrame = value;
  1871. this.gotoFrame();
  1872. };
  1873. AnimationItem.prototype.setSpeed = function (val) {
  1874. this.playSpeed = val;
  1875. this.updaFrameModifier();
  1876. };
  1877. AnimationItem.prototype.setDirection = function (val) {
  1878. this.playDirection = val < 0 ? -1 : 1;
  1879. this.updaFrameModifier();
  1880. };
  1881. AnimationItem.prototype.setVolume = function (val, name) {
  1882. if (name && this.name !== name) {
  1883. return;
  1884. }
  1885. this.audioController.setVolume(val);
  1886. };
  1887. AnimationItem.prototype.getVolume = function () {
  1888. return this.audioController.getVolume();
  1889. };
  1890. AnimationItem.prototype.mute = function (name) {
  1891. if (name && this.name !== name) {
  1892. return;
  1893. }
  1894. this.audioController.mute();
  1895. };
  1896. AnimationItem.prototype.unmute = function (name) {
  1897. if (name && this.name !== name) {
  1898. return;
  1899. }
  1900. this.audioController.unmute();
  1901. };
  1902. AnimationItem.prototype.updaFrameModifier = function () {
  1903. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  1904. this.audioController.setRate(this.playSpeed * this.playDirection);
  1905. };
  1906. AnimationItem.prototype.getPath = function () {
  1907. return this.path;
  1908. };
  1909. AnimationItem.prototype.getAssetsPath = function (assetData) {
  1910. var path = '';
  1911. if (assetData.e) {
  1912. path = assetData.p;
  1913. } else if (this.assetsPath) {
  1914. var imagePath = assetData.p;
  1915. if (imagePath.indexOf('images/') !== -1) {
  1916. imagePath = imagePath.split('/')[1];
  1917. }
  1918. path = this.assetsPath + imagePath;
  1919. } else {
  1920. path = this.path;
  1921. path += assetData.u ? assetData.u : '';
  1922. path += assetData.p;
  1923. }
  1924. return path;
  1925. };
  1926. AnimationItem.prototype.getAssetData = function (id) {
  1927. var i = 0;
  1928. var len = this.assets.length;
  1929. while (i < len) {
  1930. if (id === this.assets[i].id) {
  1931. return this.assets[i];
  1932. }
  1933. i += 1;
  1934. }
  1935. return null;
  1936. };
  1937. AnimationItem.prototype.hide = function () {
  1938. this.renderer.hide();
  1939. };
  1940. AnimationItem.prototype.show = function () {
  1941. this.renderer.show();
  1942. };
  1943. AnimationItem.prototype.getDuration = function (isFrame) {
  1944. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  1945. };
  1946. AnimationItem.prototype.updateDocumentData = function (path, documentData, index) {
  1947. try {
  1948. var element = this.renderer.getElementByPath(path);
  1949. element.updateDocumentData(documentData, index);
  1950. } catch (error) {
  1951. // TODO: decide how to handle catch case
  1952. }
  1953. };
  1954. AnimationItem.prototype.trigger = function (name) {
  1955. if (this._cbs && this._cbs[name]) {
  1956. switch (name) {
  1957. case 'enterFrame':
  1958. this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
  1959. break;
  1960. case 'drawnFrame':
  1961. this.drawnFrameEvent.currentTime = this.currentFrame;
  1962. this.drawnFrameEvent.totalTime = this.totalFrames;
  1963. this.drawnFrameEvent.direction = this.frameModifier;
  1964. this.triggerEvent(name, this.drawnFrameEvent);
  1965. break;
  1966. case 'loopComplete':
  1967. this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  1968. break;
  1969. case 'complete':
  1970. this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult));
  1971. break;
  1972. case 'segmentStart':
  1973. this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  1974. break;
  1975. case 'destroy':
  1976. this.triggerEvent(name, new BMDestroyEvent(name, this));
  1977. break;
  1978. default:
  1979. this.triggerEvent(name);
  1980. }
  1981. }
  1982. if (name === 'enterFrame' && this.onEnterFrame) {
  1983. this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult));
  1984. }
  1985. if (name === 'loopComplete' && this.onLoopComplete) {
  1986. this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  1987. }
  1988. if (name === 'complete' && this.onComplete) {
  1989. this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult));
  1990. }
  1991. if (name === 'segmentStart' && this.onSegmentStart) {
  1992. this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  1993. }
  1994. if (name === 'destroy' && this.onDestroy) {
  1995. this.onDestroy.call(this, new BMDestroyEvent(name, this));
  1996. }
  1997. };
  1998. AnimationItem.prototype.triggerRenderFrameError = function (nativeError) {
  1999. var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
  2000. this.triggerEvent('error', error);
  2001. if (this.onError) {
  2002. this.onError.call(this, error);
  2003. }
  2004. };
  2005. AnimationItem.prototype.triggerConfigError = function (nativeError) {
  2006. var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
  2007. this.triggerEvent('error', error);
  2008. if (this.onError) {
  2009. this.onError.call(this, error);
  2010. }
  2011. };
  2012. const animationManager = (function () {
  2013. var moduleOb = {};
  2014. var registeredAnimations = [];
  2015. var initTime = 0;
  2016. var len = 0;
  2017. var playingAnimationsNum = 0;
  2018. var _stopped = true;
  2019. var _isFrozen = false;
  2020. function removeElement(ev) {
  2021. var i = 0;
  2022. var animItem = ev.target;
  2023. while (i < len) {
  2024. if (registeredAnimations[i].animation === animItem) {
  2025. registeredAnimations.splice(i, 1);
  2026. i -= 1;
  2027. len -= 1;
  2028. if (!animItem.isPaused) {
  2029. subtractPlayingCount();
  2030. }
  2031. }
  2032. i += 1;
  2033. }
  2034. }
  2035. function registerAnimation(element, animationData) {
  2036. if (!element) {
  2037. return null;
  2038. }
  2039. var i = 0;
  2040. while (i < len) {
  2041. if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) {
  2042. return registeredAnimations[i].animation;
  2043. }
  2044. i += 1;
  2045. }
  2046. var animItem = new AnimationItem();
  2047. setupAnimation(animItem, element);
  2048. animItem.setData(element, animationData);
  2049. return animItem;
  2050. }
  2051. function getRegisteredAnimations() {
  2052. var i;
  2053. var lenAnims = registeredAnimations.length;
  2054. var animations = [];
  2055. for (i = 0; i < lenAnims; i += 1) {
  2056. animations.push(registeredAnimations[i].animation);
  2057. }
  2058. return animations;
  2059. }
  2060. function addPlayingCount() {
  2061. playingAnimationsNum += 1;
  2062. activate();
  2063. }
  2064. function subtractPlayingCount() {
  2065. playingAnimationsNum -= 1;
  2066. }
  2067. function setupAnimation(animItem, element) {
  2068. animItem.addEventListener('destroy', removeElement);
  2069. animItem.addEventListener('_active', addPlayingCount);
  2070. animItem.addEventListener('_idle', subtractPlayingCount);
  2071. registeredAnimations.push({ elem: element, animation: animItem });
  2072. len += 1;
  2073. }
  2074. function loadAnimation(params) {
  2075. var animItem = new AnimationItem();
  2076. setupAnimation(animItem, null);
  2077. animItem.setParams(params);
  2078. return animItem;
  2079. }
  2080. function setSpeed(val, animation) {
  2081. var i;
  2082. for (i = 0; i < len; i += 1) {
  2083. registeredAnimations[i].animation.setSpeed(val, animation);
  2084. }
  2085. }
  2086. function setDirection(val, animation) {
  2087. var i;
  2088. for (i = 0; i < len; i += 1) {
  2089. registeredAnimations[i].animation.setDirection(val, animation);
  2090. }
  2091. }
  2092. function play(animation) {
  2093. var i;
  2094. for (i = 0; i < len; i += 1) {
  2095. registeredAnimations[i].animation.play(animation);
  2096. }
  2097. }
  2098. function resume(nowTime) {
  2099. var elapsedTime = nowTime - initTime;
  2100. var i;
  2101. for (i = 0; i < len; i += 1) {
  2102. registeredAnimations[i].animation.advanceTime(elapsedTime);
  2103. }
  2104. initTime = nowTime;
  2105. if (playingAnimationsNum && !_isFrozen) {
  2106. window.requestAnimationFrame(resume);
  2107. } else {
  2108. _stopped = true;
  2109. }
  2110. }
  2111. function first(nowTime) {
  2112. initTime = nowTime;
  2113. window.requestAnimationFrame(resume);
  2114. }
  2115. function pause(animation) {
  2116. var i;
  2117. for (i = 0; i < len; i += 1) {
  2118. registeredAnimations[i].animation.pause(animation);
  2119. }
  2120. }
  2121. function goToAndStop(value, isFrame, animation) {
  2122. var i;
  2123. for (i = 0; i < len; i += 1) {
  2124. registeredAnimations[i].animation.goToAndStop(value, isFrame, animation);
  2125. }
  2126. }
  2127. function stop(animation) {
  2128. var i;
  2129. for (i = 0; i < len; i += 1) {
  2130. registeredAnimations[i].animation.stop(animation);
  2131. }
  2132. }
  2133. function togglePause(animation) {
  2134. var i;
  2135. for (i = 0; i < len; i += 1) {
  2136. registeredAnimations[i].animation.togglePause(animation);
  2137. }
  2138. }
  2139. function destroy(animation) {
  2140. var i;
  2141. for (i = (len - 1); i >= 0; i -= 1) {
  2142. registeredAnimations[i].animation.destroy(animation);
  2143. }
  2144. }
  2145. function searchAnimations(animationData, standalone, renderer) {
  2146. var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')),
  2147. [].slice.call(document.getElementsByClassName('bodymovin')));
  2148. var i;
  2149. var lenAnims = animElements.length;
  2150. for (i = 0; i < lenAnims; i += 1) {
  2151. if (renderer) {
  2152. animElements[i].setAttribute('data-bm-type', renderer);
  2153. }
  2154. registerAnimation(animElements[i], animationData);
  2155. }
  2156. if (standalone && lenAnims === 0) {
  2157. if (!renderer) {
  2158. renderer = 'svg';
  2159. }
  2160. var body = document.getElementsByTagName('body')[0];
  2161. body.innerText = '';
  2162. var div = createTag('div');
  2163. div.style.width = '100%';
  2164. div.style.height = '100%';
  2165. div.setAttribute('data-bm-type', renderer);
  2166. body.appendChild(div);
  2167. registerAnimation(div, animationData);
  2168. }
  2169. }
  2170. function resize() {
  2171. var i;
  2172. for (i = 0; i < len; i += 1) {
  2173. registeredAnimations[i].animation.resize();
  2174. }
  2175. }
  2176. function activate() {
  2177. if (!_isFrozen && playingAnimationsNum) {
  2178. if (_stopped) {
  2179. window.requestAnimationFrame(first);
  2180. _stopped = false;
  2181. }
  2182. }
  2183. }
  2184. function freeze() {
  2185. _isFrozen = true;
  2186. }
  2187. function unfreeze() {
  2188. _isFrozen = false;
  2189. activate();
  2190. }
  2191. function setVolume(val, animation) {
  2192. var i;
  2193. for (i = 0; i < len; i += 1) {
  2194. registeredAnimations[i].animation.setVolume(val, animation);
  2195. }
  2196. }
  2197. function mute(animation) {
  2198. var i;
  2199. for (i = 0; i < len; i += 1) {
  2200. registeredAnimations[i].animation.mute(animation);
  2201. }
  2202. }
  2203. function unmute(animation) {
  2204. var i;
  2205. for (i = 0; i < len; i += 1) {
  2206. registeredAnimations[i].animation.unmute(animation);
  2207. }
  2208. }
  2209. moduleOb.registerAnimation = registerAnimation;
  2210. moduleOb.loadAnimation = loadAnimation;
  2211. moduleOb.setSpeed = setSpeed;
  2212. moduleOb.setDirection = setDirection;
  2213. moduleOb.play = play;
  2214. moduleOb.pause = pause;
  2215. moduleOb.stop = stop;
  2216. moduleOb.togglePause = togglePause;
  2217. moduleOb.searchAnimations = searchAnimations;
  2218. moduleOb.resize = resize;
  2219. // moduleOb.start = start;
  2220. moduleOb.goToAndStop = goToAndStop;
  2221. moduleOb.destroy = destroy;
  2222. moduleOb.freeze = freeze;
  2223. moduleOb.unfreeze = unfreeze;
  2224. moduleOb.setVolume = setVolume;
  2225. moduleOb.mute = mute;
  2226. moduleOb.unmute = unmute;
  2227. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  2228. return moduleOb;
  2229. }());
  2230. /* eslint-disable */
  2231. const BezierFactory = (function () {
  2232. /**
  2233. * BezierEasing - use bezier curve for transition easing function
  2234. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  2235. *
  2236. * Credits: is based on Firefox's nsSMILKeySpline.cpp
  2237. * Usage:
  2238. * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
  2239. * spline.get(x) => returns the easing value | x must be in [0, 1] range
  2240. *
  2241. */
  2242. var ob = {};
  2243. ob.getBezierEasing = getBezierEasing;
  2244. var beziers = {};
  2245. function getBezierEasing(a, b, c, d, nm) {
  2246. var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p');
  2247. if (beziers[str]) {
  2248. return beziers[str];
  2249. }
  2250. var bezEasing = new BezierEasing([a, b, c, d]);
  2251. beziers[str] = bezEasing;
  2252. return bezEasing;
  2253. }
  2254. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  2255. var NEWTON_ITERATIONS = 4;
  2256. var NEWTON_MIN_SLOPE = 0.001;
  2257. var SUBDIVISION_PRECISION = 0.0000001;
  2258. var SUBDIVISION_MAX_ITERATIONS = 10;
  2259. var kSplineTableSize = 11;
  2260. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  2261. var float32ArraySupported = typeof Float32Array === 'function';
  2262. function A(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
  2263. function B(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
  2264. function C(aA1) { return 3.0 * aA1; }
  2265. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  2266. function calcBezier(aT, aA1, aA2) {
  2267. return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
  2268. }
  2269. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  2270. function getSlope(aT, aA1, aA2) {
  2271. return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  2272. }
  2273. function binarySubdivide(aX, aA, aB, mX1, mX2) {
  2274. var currentX,
  2275. currentT,
  2276. i = 0;
  2277. do {
  2278. currentT = aA + (aB - aA) / 2.0;
  2279. currentX = calcBezier(currentT, mX1, mX2) - aX;
  2280. if (currentX > 0.0) {
  2281. aB = currentT;
  2282. } else {
  2283. aA = currentT;
  2284. }
  2285. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  2286. return currentT;
  2287. }
  2288. function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
  2289. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  2290. var currentSlope = getSlope(aGuessT, mX1, mX2);
  2291. if (currentSlope === 0.0) return aGuessT;
  2292. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  2293. aGuessT -= currentX / currentSlope;
  2294. }
  2295. return aGuessT;
  2296. }
  2297. /**
  2298. * points is an array of [ mX1, mY1, mX2, mY2 ]
  2299. */
  2300. function BezierEasing(points) {
  2301. this._p = points;
  2302. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  2303. this._precomputed = false;
  2304. this.get = this.get.bind(this);
  2305. }
  2306. BezierEasing.prototype = {
  2307. get: function (x) {
  2308. var mX1 = this._p[0],
  2309. mY1 = this._p[1],
  2310. mX2 = this._p[2],
  2311. mY2 = this._p[3];
  2312. if (!this._precomputed) this._precompute();
  2313. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  2314. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  2315. if (x === 0) return 0;
  2316. if (x === 1) return 1;
  2317. return calcBezier(this._getTForX(x), mY1, mY2);
  2318. },
  2319. // Private part
  2320. _precompute: function () {
  2321. var mX1 = this._p[0],
  2322. mY1 = this._p[1],
  2323. mX2 = this._p[2],
  2324. mY2 = this._p[3];
  2325. this._precomputed = true;
  2326. if (mX1 !== mY1 || mX2 !== mY2) { this._calcSampleValues(); }
  2327. },
  2328. _calcSampleValues: function () {
  2329. var mX1 = this._p[0],
  2330. mX2 = this._p[2];
  2331. for (var i = 0; i < kSplineTableSize; ++i) {
  2332. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  2333. }
  2334. },
  2335. /**
  2336. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  2337. */
  2338. _getTForX: function (aX) {
  2339. var mX1 = this._p[0],
  2340. mX2 = this._p[2],
  2341. mSampleValues = this._mSampleValues;
  2342. var intervalStart = 0.0;
  2343. var currentSample = 1;
  2344. var lastSample = kSplineTableSize - 1;
  2345. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  2346. intervalStart += kSampleStepSize;
  2347. }
  2348. --currentSample;
  2349. // Interpolate to provide an initial guess for t
  2350. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
  2351. var guessForT = intervalStart + dist * kSampleStepSize;
  2352. var initialSlope = getSlope(guessForT, mX1, mX2);
  2353. if (initialSlope >= NEWTON_MIN_SLOPE) {
  2354. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  2355. } if (initialSlope === 0.0) {
  2356. return guessForT;
  2357. }
  2358. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  2359. },
  2360. };
  2361. return ob;
  2362. }());
  2363. const pooling = (function () {
  2364. function double(arr) {
  2365. return arr.concat(createSizedArray(arr.length));
  2366. }
  2367. return {
  2368. double: double,
  2369. };
  2370. }());
  2371. const poolFactory = (function () {
  2372. return function (initialLength, _create, _release) {
  2373. var _length = 0;
  2374. var _maxLength = initialLength;
  2375. var pool = createSizedArray(_maxLength);
  2376. var ob = {
  2377. newElement: newElement,
  2378. release: release,
  2379. };
  2380. function newElement() {
  2381. var element;
  2382. if (_length) {
  2383. _length -= 1;
  2384. element = pool[_length];
  2385. } else {
  2386. element = _create();
  2387. }
  2388. return element;
  2389. }
  2390. function release(element) {
  2391. if (_length === _maxLength) {
  2392. pool = pooling.double(pool);
  2393. _maxLength *= 2;
  2394. }
  2395. if (_release) {
  2396. _release(element);
  2397. }
  2398. pool[_length] = element;
  2399. _length += 1;
  2400. }
  2401. return ob;
  2402. };
  2403. }());
  2404. const bezierLengthPool = (function () {
  2405. function create() {
  2406. return {
  2407. addedLength: 0,
  2408. percents: createTypedArray('float32', getDefaultCurveSegments()),
  2409. lengths: createTypedArray('float32', getDefaultCurveSegments()),
  2410. };
  2411. }
  2412. return poolFactory(8, create);
  2413. }());
  2414. const segmentsLengthPool = (function () {
  2415. function create() {
  2416. return {
  2417. lengths: [],
  2418. totalLength: 0,
  2419. };
  2420. }
  2421. function release(element) {
  2422. var i;
  2423. var len = element.lengths.length;
  2424. for (i = 0; i < len; i += 1) {
  2425. bezierLengthPool.release(element.lengths[i]);
  2426. }
  2427. element.lengths.length = 0;
  2428. }
  2429. return poolFactory(8, create, release);
  2430. }());
  2431. function bezFunction() {
  2432. var math = Math;
  2433. function pointOnLine2D(x1, y1, x2, y2, x3, y3) {
  2434. var det1 = (x1 * y2) + (y1 * x3) + (x2 * y3) - (x3 * y2) - (y3 * x1) - (x2 * y1);
  2435. return det1 > -0.001 && det1 < 0.001;
  2436. }
  2437. function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
  2438. if (z1 === 0 && z2 === 0 && z3 === 0) {
  2439. return pointOnLine2D(x1, y1, x2, y2, x3, y3);
  2440. }
  2441. var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2));
  2442. var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2));
  2443. var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2));
  2444. var diffDist;
  2445. if (dist1 > dist2) {
  2446. if (dist1 > dist3) {
  2447. diffDist = dist1 - dist2 - dist3;
  2448. } else {
  2449. diffDist = dist3 - dist2 - dist1;
  2450. }
  2451. } else if (dist3 > dist2) {
  2452. diffDist = dist3 - dist2 - dist1;
  2453. } else {
  2454. diffDist = dist2 - dist1 - dist3;
  2455. }
  2456. return diffDist > -0.0001 && diffDist < 0.0001;
  2457. }
  2458. var getBezierLength = (function () {
  2459. return function (pt1, pt2, pt3, pt4) {
  2460. var curveSegments = getDefaultCurveSegments();
  2461. var k;
  2462. var i;
  2463. var len;
  2464. var ptCoord;
  2465. var perc;
  2466. var addedLength = 0;
  2467. var ptDistance;
  2468. var point = [];
  2469. var lastPoint = [];
  2470. var lengthData = bezierLengthPool.newElement();
  2471. len = pt3.length;
  2472. for (k = 0; k < curveSegments; k += 1) {
  2473. perc = k / (curveSegments - 1);
  2474. ptDistance = 0;
  2475. for (i = 0; i < len; i += 1) {
  2476. 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];
  2477. point[i] = ptCoord;
  2478. if (lastPoint[i] !== null) {
  2479. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2480. }
  2481. lastPoint[i] = point[i];
  2482. }
  2483. if (ptDistance) {
  2484. ptDistance = bmSqrt(ptDistance);
  2485. addedLength += ptDistance;
  2486. }
  2487. lengthData.percents[k] = perc;
  2488. lengthData.lengths[k] = addedLength;
  2489. }
  2490. lengthData.addedLength = addedLength;
  2491. return lengthData;
  2492. };
  2493. }());
  2494. function getSegmentsLength(shapeData) {
  2495. var segmentsLength = segmentsLengthPool.newElement();
  2496. var closed = shapeData.c;
  2497. var pathV = shapeData.v;
  2498. var pathO = shapeData.o;
  2499. var pathI = shapeData.i;
  2500. var i;
  2501. var len = shapeData._length;
  2502. var lengths = segmentsLength.lengths;
  2503. var totalLength = 0;
  2504. for (i = 0; i < len - 1; i += 1) {
  2505. lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]);
  2506. totalLength += lengths[i].addedLength;
  2507. }
  2508. if (closed && len) {
  2509. lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]);
  2510. totalLength += lengths[i].addedLength;
  2511. }
  2512. segmentsLength.totalLength = totalLength;
  2513. return segmentsLength;
  2514. }
  2515. function BezierData(length) {
  2516. this.segmentLength = 0;
  2517. this.points = new Array(length);
  2518. }
  2519. function PointData(partial, point) {
  2520. this.partialLength = partial;
  2521. this.point = point;
  2522. }
  2523. var buildBezierData = (function () {
  2524. var storedData = {};
  2525. return function (pt1, pt2, pt3, pt4) {
  2526. var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p');
  2527. if (!storedData[bezierName]) {
  2528. var curveSegments = getDefaultCurveSegments();
  2529. var k;
  2530. var i;
  2531. var len;
  2532. var ptCoord;
  2533. var perc;
  2534. var addedLength = 0;
  2535. var ptDistance;
  2536. var point;
  2537. var lastPoint = null;
  2538. 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])) {
  2539. curveSegments = 2;
  2540. }
  2541. var bezierData = new BezierData(curveSegments);
  2542. len = pt3.length;
  2543. for (k = 0; k < curveSegments; k += 1) {
  2544. point = createSizedArray(len);
  2545. perc = k / (curveSegments - 1);
  2546. ptDistance = 0;
  2547. for (i = 0; i < len; i += 1) {
  2548. 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];
  2549. point[i] = ptCoord;
  2550. if (lastPoint !== null) {
  2551. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2552. }
  2553. }
  2554. ptDistance = bmSqrt(ptDistance);
  2555. addedLength += ptDistance;
  2556. bezierData.points[k] = new PointData(ptDistance, point);
  2557. lastPoint = point;
  2558. }
  2559. bezierData.segmentLength = addedLength;
  2560. storedData[bezierName] = bezierData;
  2561. }
  2562. return storedData[bezierName];
  2563. };
  2564. }());
  2565. function getDistancePerc(perc, bezierData) {
  2566. var percents = bezierData.percents;
  2567. var lengths = bezierData.lengths;
  2568. var len = percents.length;
  2569. var initPos = bmFloor((len - 1) * perc);
  2570. var lengthPos = perc * bezierData.addedLength;
  2571. var lPerc = 0;
  2572. if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) {
  2573. return percents[initPos];
  2574. }
  2575. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  2576. var flag = true;
  2577. while (flag) {
  2578. if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) {
  2579. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]);
  2580. flag = false;
  2581. } else {
  2582. initPos += dir;
  2583. }
  2584. if (initPos < 0 || initPos >= len - 1) {
  2585. // FIX for TypedArrays that don't store floating point values with enough accuracy
  2586. if (initPos === len - 1) {
  2587. return percents[initPos];
  2588. }
  2589. flag = false;
  2590. }
  2591. }
  2592. return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc;
  2593. }
  2594. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  2595. var t1 = getDistancePerc(percent, bezierData);
  2596. var u1 = 1 - t1;
  2597. 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;
  2598. 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;
  2599. return [ptX, ptY];
  2600. }
  2601. var bezierSegmentPoints = createTypedArray('float32', 8);
  2602. function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) {
  2603. if (startPerc < 0) {
  2604. startPerc = 0;
  2605. } else if (startPerc > 1) {
  2606. startPerc = 1;
  2607. }
  2608. var t0 = getDistancePerc(startPerc, bezierData);
  2609. endPerc = endPerc > 1 ? 1 : endPerc;
  2610. var t1 = getDistancePerc(endPerc, bezierData);
  2611. var i;
  2612. var len = pt1.length;
  2613. var u0 = 1 - t0;
  2614. var u1 = 1 - t1;
  2615. var u0u0u0 = u0 * u0 * u0;
  2616. var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase
  2617. var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase
  2618. var t0t0t0 = t0 * t0 * t0;
  2619. //
  2620. var u0u0u1 = u0 * u0 * u1;
  2621. var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase
  2622. var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase
  2623. var t0t0t1 = t0 * t0 * t1;
  2624. //
  2625. var u0u1u1 = u0 * u1 * u1;
  2626. var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase
  2627. var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase
  2628. var t0t1t1 = t0 * t1 * t1;
  2629. //
  2630. var u1u1u1 = u1 * u1 * u1;
  2631. var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase
  2632. var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase
  2633. var t1t1t1 = t1 * t1 * t1;
  2634. for (i = 0; i < len; i += 1) {
  2635. 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
  2636. 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
  2637. 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
  2638. 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
  2639. }
  2640. return bezierSegmentPoints;
  2641. }
  2642. return {
  2643. getSegmentsLength: getSegmentsLength,
  2644. getNewSegment: getNewSegment,
  2645. getPointInSegment: getPointInSegment,
  2646. buildBezierData: buildBezierData,
  2647. pointOnLine2D: pointOnLine2D,
  2648. pointOnLine3D: pointOnLine3D,
  2649. };
  2650. }
  2651. const bez = bezFunction();
  2652. const PropertyFactory = (function () {
  2653. var initFrame = initialDefaultFrame;
  2654. var mathAbs = Math.abs;
  2655. function interpolateValue(frameNum, caching) {
  2656. var offsetTime = this.offsetTime;
  2657. var newValue;
  2658. if (this.propType === 'multidimensional') {
  2659. newValue = createTypedArray('float32', this.pv.length);
  2660. }
  2661. var iterationIndex = caching.lastIndex;
  2662. var i = iterationIndex;
  2663. var len = this.keyframes.length - 1;
  2664. var flag = true;
  2665. var keyData;
  2666. var nextKeyData;
  2667. var keyframeMetadata;
  2668. while (flag) {
  2669. keyData = this.keyframes[i];
  2670. nextKeyData = this.keyframes[i + 1];
  2671. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) {
  2672. if (keyData.h) {
  2673. keyData = nextKeyData;
  2674. }
  2675. iterationIndex = 0;
  2676. break;
  2677. }
  2678. if ((nextKeyData.t - offsetTime) > frameNum) {
  2679. iterationIndex = i;
  2680. break;
  2681. }
  2682. if (i < len - 1) {
  2683. i += 1;
  2684. } else {
  2685. iterationIndex = 0;
  2686. flag = false;
  2687. }
  2688. }
  2689. keyframeMetadata = this.keyframesMetadata[i] || {};
  2690. var k;
  2691. var kLen;
  2692. var perc;
  2693. var jLen;
  2694. var j;
  2695. var fnc;
  2696. var nextKeyTime = nextKeyData.t - offsetTime;
  2697. var keyTime = keyData.t - offsetTime;
  2698. var endValue;
  2699. if (keyData.to) {
  2700. if (!keyframeMetadata.bezierData) {
  2701. keyframeMetadata.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  2702. }
  2703. var bezierData = keyframeMetadata.bezierData;
  2704. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  2705. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  2706. kLen = bezierData.points[ind].point.length;
  2707. for (k = 0; k < kLen; k += 1) {
  2708. newValue[k] = bezierData.points[ind].point[k];
  2709. }
  2710. // caching._lastKeyframeIndex = -1;
  2711. } else {
  2712. if (keyframeMetadata.__fnct) {
  2713. fnc = keyframeMetadata.__fnct;
  2714. } else {
  2715. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  2716. keyframeMetadata.__fnct = fnc;
  2717. }
  2718. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2719. var distanceInLine = bezierData.segmentLength * perc;
  2720. var segmentPerc;
  2721. var addedLength = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastAddedLength : 0;
  2722. j = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastPoint : 0;
  2723. flag = true;
  2724. jLen = bezierData.points.length;
  2725. while (flag) {
  2726. addedLength += bezierData.points[j].partialLength;
  2727. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  2728. kLen = bezierData.points[j].point.length;
  2729. for (k = 0; k < kLen; k += 1) {
  2730. newValue[k] = bezierData.points[j].point[k];
  2731. }
  2732. break;
  2733. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  2734. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  2735. kLen = bezierData.points[j].point.length;
  2736. for (k = 0; k < kLen; k += 1) {
  2737. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  2738. }
  2739. break;
  2740. }
  2741. if (j < jLen - 1) {
  2742. j += 1;
  2743. } else {
  2744. flag = false;
  2745. }
  2746. }
  2747. caching._lastPoint = j;
  2748. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  2749. caching._lastKeyframeIndex = i;
  2750. }
  2751. } else {
  2752. var outX;
  2753. var outY;
  2754. var inX;
  2755. var inY;
  2756. var keyValue;
  2757. len = keyData.s.length;
  2758. endValue = nextKeyData.s || keyData.e;
  2759. if (this.sh && keyData.h !== 1) {
  2760. if (frameNum >= nextKeyTime) {
  2761. newValue[0] = endValue[0];
  2762. newValue[1] = endValue[1];
  2763. newValue[2] = endValue[2];
  2764. } else if (frameNum <= keyTime) {
  2765. newValue[0] = keyData.s[0];
  2766. newValue[1] = keyData.s[1];
  2767. newValue[2] = keyData.s[2];
  2768. } else {
  2769. var quatStart = createQuaternion(keyData.s);
  2770. var quatEnd = createQuaternion(endValue);
  2771. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  2772. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  2773. }
  2774. } else {
  2775. for (i = 0; i < len; i += 1) {
  2776. if (keyData.h !== 1) {
  2777. if (frameNum >= nextKeyTime) {
  2778. perc = 1;
  2779. } else if (frameNum < keyTime) {
  2780. perc = 0;
  2781. } else {
  2782. if (keyData.o.x.constructor === Array) {
  2783. if (!keyframeMetadata.__fnct) {
  2784. keyframeMetadata.__fnct = [];
  2785. }
  2786. if (!keyframeMetadata.__fnct[i]) {
  2787. outX = keyData.o.x[i] === undefined ? keyData.o.x[0] : keyData.o.x[i];
  2788. outY = keyData.o.y[i] === undefined ? keyData.o.y[0] : keyData.o.y[i];
  2789. inX = keyData.i.x[i] === undefined ? keyData.i.x[0] : keyData.i.x[i];
  2790. inY = keyData.i.y[i] === undefined ? keyData.i.y[0] : keyData.i.y[i];
  2791. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2792. keyframeMetadata.__fnct[i] = fnc;
  2793. } else {
  2794. fnc = keyframeMetadata.__fnct[i];
  2795. }
  2796. } else if (!keyframeMetadata.__fnct) {
  2797. outX = keyData.o.x;
  2798. outY = keyData.o.y;
  2799. inX = keyData.i.x;
  2800. inY = keyData.i.y;
  2801. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2802. keyData.keyframeMetadata = fnc;
  2803. } else {
  2804. fnc = keyframeMetadata.__fnct;
  2805. }
  2806. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2807. }
  2808. }
  2809. endValue = nextKeyData.s || keyData.e;
  2810. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  2811. if (this.propType === 'multidimensional') {
  2812. newValue[i] = keyValue;
  2813. } else {
  2814. newValue = keyValue;
  2815. }
  2816. }
  2817. }
  2818. }
  2819. caching.lastIndex = iterationIndex;
  2820. return newValue;
  2821. }
  2822. // based on @Toji's https://github.com/toji/gl-matrix/
  2823. function slerp(a, b, t) {
  2824. var out = [];
  2825. var ax = a[0];
  2826. var ay = a[1];
  2827. var az = a[2];
  2828. var aw = a[3];
  2829. var bx = b[0];
  2830. var by = b[1];
  2831. var bz = b[2];
  2832. var bw = b[3];
  2833. var omega;
  2834. var cosom;
  2835. var sinom;
  2836. var scale0;
  2837. var scale1;
  2838. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2839. if (cosom < 0.0) {
  2840. cosom = -cosom;
  2841. bx = -bx;
  2842. by = -by;
  2843. bz = -bz;
  2844. bw = -bw;
  2845. }
  2846. if ((1.0 - cosom) > 0.000001) {
  2847. omega = Math.acos(cosom);
  2848. sinom = Math.sin(omega);
  2849. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2850. scale1 = Math.sin(t * omega) / sinom;
  2851. } else {
  2852. scale0 = 1.0 - t;
  2853. scale1 = t;
  2854. }
  2855. out[0] = scale0 * ax + scale1 * bx;
  2856. out[1] = scale0 * ay + scale1 * by;
  2857. out[2] = scale0 * az + scale1 * bz;
  2858. out[3] = scale0 * aw + scale1 * bw;
  2859. return out;
  2860. }
  2861. function quaternionToEuler(out, quat) {
  2862. var qx = quat[0];
  2863. var qy = quat[1];
  2864. var qz = quat[2];
  2865. var qw = quat[3];
  2866. var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz);
  2867. var attitude = Math.asin(2 * qx * qy + 2 * qz * qw);
  2868. var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz);
  2869. out[0] = heading / degToRads;
  2870. out[1] = attitude / degToRads;
  2871. out[2] = bank / degToRads;
  2872. }
  2873. function createQuaternion(values) {
  2874. var heading = values[0] * degToRads;
  2875. var attitude = values[1] * degToRads;
  2876. var bank = values[2] * degToRads;
  2877. var c1 = Math.cos(heading / 2);
  2878. var c2 = Math.cos(attitude / 2);
  2879. var c3 = Math.cos(bank / 2);
  2880. var s1 = Math.sin(heading / 2);
  2881. var s2 = Math.sin(attitude / 2);
  2882. var s3 = Math.sin(bank / 2);
  2883. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2884. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2885. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2886. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2887. return [x, y, z, w];
  2888. }
  2889. function getValueAtCurrentTime() {
  2890. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2891. var initTime = this.keyframes[0].t - this.offsetTime;
  2892. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2893. if (!(frameNum === this._caching.lastFrame || (this._caching.lastFrame !== initFrame && ((this._caching.lastFrame >= endTime && frameNum >= endTime) || (this._caching.lastFrame < initTime && frameNum < initTime))))) {
  2894. if (this._caching.lastFrame >= frameNum) {
  2895. this._caching._lastKeyframeIndex = -1;
  2896. this._caching.lastIndex = 0;
  2897. }
  2898. var renderResult = this.interpolateValue(frameNum, this._caching);
  2899. this.pv = renderResult;
  2900. }
  2901. this._caching.lastFrame = frameNum;
  2902. return this.pv;
  2903. }
  2904. function setVValue(val) {
  2905. var multipliedValue;
  2906. if (this.propType === 'unidimensional') {
  2907. multipliedValue = val * this.mult;
  2908. if (mathAbs(this.v - multipliedValue) > 0.00001) {
  2909. this.v = multipliedValue;
  2910. this._mdf = true;
  2911. }
  2912. } else {
  2913. var i = 0;
  2914. var len = this.v.length;
  2915. while (i < len) {
  2916. multipliedValue = val[i] * this.mult;
  2917. if (mathAbs(this.v[i] - multipliedValue) > 0.00001) {
  2918. this.v[i] = multipliedValue;
  2919. this._mdf = true;
  2920. }
  2921. i += 1;
  2922. }
  2923. }
  2924. }
  2925. function processEffectsSequence() {
  2926. if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  2927. return;
  2928. }
  2929. if (this.lock) {
  2930. this.setVValue(this.pv);
  2931. return;
  2932. }
  2933. this.lock = true;
  2934. this._mdf = this._isFirstFrame;
  2935. var i;
  2936. var len = this.effectsSequence.length;
  2937. var finalValue = this.kf ? this.pv : this.data.k;
  2938. for (i = 0; i < len; i += 1) {
  2939. finalValue = this.effectsSequence[i](finalValue);
  2940. }
  2941. this.setVValue(finalValue);
  2942. this._isFirstFrame = false;
  2943. this.lock = false;
  2944. this.frameId = this.elem.globalData.frameId;
  2945. }
  2946. function addEffect(effectFunction) {
  2947. this.effectsSequence.push(effectFunction);
  2948. this.container.addDynamicProperty(this);
  2949. }
  2950. function ValueProperty(elem, data, mult, container) {
  2951. this.propType = 'unidimensional';
  2952. this.mult = mult || 1;
  2953. this.data = data;
  2954. this.v = mult ? data.k * mult : data.k;
  2955. this.pv = data.k;
  2956. this._mdf = false;
  2957. this.elem = elem;
  2958. this.container = container;
  2959. this.comp = elem.comp;
  2960. this.k = false;
  2961. this.kf = false;
  2962. this.vel = 0;
  2963. this.effectsSequence = [];
  2964. this._isFirstFrame = true;
  2965. this.getValue = processEffectsSequence;
  2966. this.setVValue = setVValue;
  2967. this.addEffect = addEffect;
  2968. }
  2969. function MultiDimensionalProperty(elem, data, mult, container) {
  2970. this.propType = 'multidimensional';
  2971. this.mult = mult || 1;
  2972. this.data = data;
  2973. this._mdf = false;
  2974. this.elem = elem;
  2975. this.container = container;
  2976. this.comp = elem.comp;
  2977. this.k = false;
  2978. this.kf = false;
  2979. this.frameId = -1;
  2980. var i;
  2981. var len = data.k.length;
  2982. this.v = createTypedArray('float32', len);
  2983. this.pv = createTypedArray('float32', len);
  2984. this.vel = createTypedArray('float32', len);
  2985. for (i = 0; i < len; i += 1) {
  2986. this.v[i] = data.k[i] * this.mult;
  2987. this.pv[i] = data.k[i];
  2988. }
  2989. this._isFirstFrame = true;
  2990. this.effectsSequence = [];
  2991. this.getValue = processEffectsSequence;
  2992. this.setVValue = setVValue;
  2993. this.addEffect = addEffect;
  2994. }
  2995. function KeyframedValueProperty(elem, data, mult, container) {
  2996. this.propType = 'unidimensional';
  2997. this.keyframes = data.k;
  2998. this.keyframesMetadata = [];
  2999. this.offsetTime = elem.data.st;
  3000. this.frameId = -1;
  3001. this._caching = {
  3002. lastFrame: initFrame, lastIndex: 0, value: 0, _lastKeyframeIndex: -1,
  3003. };
  3004. this.k = true;
  3005. this.kf = true;
  3006. this.data = data;
  3007. this.mult = mult || 1;
  3008. this.elem = elem;
  3009. this.container = container;
  3010. this.comp = elem.comp;
  3011. this.v = initFrame;
  3012. this.pv = initFrame;
  3013. this._isFirstFrame = true;
  3014. this.getValue = processEffectsSequence;
  3015. this.setVValue = setVValue;
  3016. this.interpolateValue = interpolateValue;
  3017. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3018. this.addEffect = addEffect;
  3019. }
  3020. function KeyframedMultidimensionalProperty(elem, data, mult, container) {
  3021. this.propType = 'multidimensional';
  3022. var i;
  3023. var len = data.k.length;
  3024. var s;
  3025. var e;
  3026. var to;
  3027. var ti;
  3028. for (i = 0; i < len - 1; i += 1) {
  3029. if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
  3030. s = data.k[i].s;
  3031. e = data.k[i + 1].s;
  3032. to = data.k[i].to;
  3033. ti = data.k[i].ti;
  3034. 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]))) {
  3035. data.k[i].to = null;
  3036. data.k[i].ti = null;
  3037. }
  3038. if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  3039. if (s.length === 2 || (s[2] === e[2] && to[2] === 0 && ti[2] === 0)) {
  3040. data.k[i].to = null;
  3041. data.k[i].ti = null;
  3042. }
  3043. }
  3044. }
  3045. }
  3046. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3047. this.data = data;
  3048. this.keyframes = data.k;
  3049. this.keyframesMetadata = [];
  3050. this.offsetTime = elem.data.st;
  3051. this.k = true;
  3052. this.kf = true;
  3053. this._isFirstFrame = true;
  3054. this.mult = mult || 1;
  3055. this.elem = elem;
  3056. this.container = container;
  3057. this.comp = elem.comp;
  3058. this.getValue = processEffectsSequence;
  3059. this.setVValue = setVValue;
  3060. this.interpolateValue = interpolateValue;
  3061. this.frameId = -1;
  3062. var arrLen = data.k[0].s.length;
  3063. this.v = createTypedArray('float32', arrLen);
  3064. this.pv = createTypedArray('float32', arrLen);
  3065. for (i = 0; i < arrLen; i += 1) {
  3066. this.v[i] = initFrame;
  3067. this.pv[i] = initFrame;
  3068. }
  3069. this._caching = { lastFrame: initFrame, lastIndex: 0, value: createTypedArray('float32', arrLen) };
  3070. this.addEffect = addEffect;
  3071. }
  3072. function getProp(elem, data, type, mult, container) {
  3073. var p;
  3074. if (!data.k.length) {
  3075. p = new ValueProperty(elem, data, mult, container);
  3076. } else if (typeof (data.k[0]) === 'number') {
  3077. p = new MultiDimensionalProperty(elem, data, mult, container);
  3078. } else {
  3079. switch (type) {
  3080. case 0:
  3081. p = new KeyframedValueProperty(elem, data, mult, container);
  3082. break;
  3083. case 1:
  3084. p = new KeyframedMultidimensionalProperty(elem, data, mult, container);
  3085. break;
  3086. default:
  3087. break;
  3088. }
  3089. }
  3090. if (p.effectsSequence.length) {
  3091. container.addDynamicProperty(p);
  3092. }
  3093. return p;
  3094. }
  3095. var ob = {
  3096. getProp: getProp,
  3097. };
  3098. return ob;
  3099. }());
  3100. function DynamicPropertyContainer() {}
  3101. DynamicPropertyContainer.prototype = {
  3102. addDynamicProperty: function (prop) {
  3103. if (this.dynamicProperties.indexOf(prop) === -1) {
  3104. this.dynamicProperties.push(prop);
  3105. this.container.addDynamicProperty(this);
  3106. this._isAnimated = true;
  3107. }
  3108. },
  3109. iterateDynamicProperties: function () {
  3110. this._mdf = false;
  3111. var i;
  3112. var len = this.dynamicProperties.length;
  3113. for (i = 0; i < len; i += 1) {
  3114. this.dynamicProperties[i].getValue();
  3115. if (this.dynamicProperties[i]._mdf) {
  3116. this._mdf = true;
  3117. }
  3118. }
  3119. },
  3120. initDynamicPropertyContainer: function (container) {
  3121. this.container = container;
  3122. this.dynamicProperties = [];
  3123. this._mdf = false;
  3124. this._isAnimated = false;
  3125. },
  3126. };
  3127. const pointPool = (function () {
  3128. function create() {
  3129. return createTypedArray('float32', 2);
  3130. }
  3131. return poolFactory(8, create);
  3132. }());
  3133. function ShapePath() {
  3134. this.c = false;
  3135. this._length = 0;
  3136. this._maxLength = 8;
  3137. this.v = createSizedArray(this._maxLength);
  3138. this.o = createSizedArray(this._maxLength);
  3139. this.i = createSizedArray(this._maxLength);
  3140. }
  3141. ShapePath.prototype.setPathData = function (closed, len) {
  3142. this.c = closed;
  3143. this.setLength(len);
  3144. var i = 0;
  3145. while (i < len) {
  3146. this.v[i] = pointPool.newElement();
  3147. this.o[i] = pointPool.newElement();
  3148. this.i[i] = pointPool.newElement();
  3149. i += 1;
  3150. }
  3151. };
  3152. ShapePath.prototype.setLength = function (len) {
  3153. while (this._maxLength < len) {
  3154. this.doubleArrayLength();
  3155. }
  3156. this._length = len;
  3157. };
  3158. ShapePath.prototype.doubleArrayLength = function () {
  3159. this.v = this.v.concat(createSizedArray(this._maxLength));
  3160. this.i = this.i.concat(createSizedArray(this._maxLength));
  3161. this.o = this.o.concat(createSizedArray(this._maxLength));
  3162. this._maxLength *= 2;
  3163. };
  3164. ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) {
  3165. var arr;
  3166. this._length = Math.max(this._length, pos + 1);
  3167. if (this._length >= this._maxLength) {
  3168. this.doubleArrayLength();
  3169. }
  3170. switch (type) {
  3171. case 'v':
  3172. arr = this.v;
  3173. break;
  3174. case 'i':
  3175. arr = this.i;
  3176. break;
  3177. case 'o':
  3178. arr = this.o;
  3179. break;
  3180. default:
  3181. arr = [];
  3182. break;
  3183. }
  3184. if (!arr[pos] || (arr[pos] && !replace)) {
  3185. arr[pos] = pointPool.newElement();
  3186. }
  3187. arr[pos][0] = x;
  3188. arr[pos][1] = y;
  3189. };
  3190. ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) {
  3191. this.setXYAt(vX, vY, 'v', pos, replace);
  3192. this.setXYAt(oX, oY, 'o', pos, replace);
  3193. this.setXYAt(iX, iY, 'i', pos, replace);
  3194. };
  3195. ShapePath.prototype.reverse = function () {
  3196. var newPath = new ShapePath();
  3197. newPath.setPathData(this.c, this._length);
  3198. var vertices = this.v;
  3199. var outPoints = this.o;
  3200. var inPoints = this.i;
  3201. var init = 0;
  3202. if (this.c) {
  3203. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  3204. init = 1;
  3205. }
  3206. var cnt = this._length - 1;
  3207. var len = this._length;
  3208. var i;
  3209. for (i = init; i < len; i += 1) {
  3210. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  3211. cnt -= 1;
  3212. }
  3213. return newPath;
  3214. };
  3215. const shapePool = (function () {
  3216. function create() {
  3217. return new ShapePath();
  3218. }
  3219. function release(shapePath) {
  3220. var len = shapePath._length;
  3221. var i;
  3222. for (i = 0; i < len; i += 1) {
  3223. pointPool.release(shapePath.v[i]);
  3224. pointPool.release(shapePath.i[i]);
  3225. pointPool.release(shapePath.o[i]);
  3226. shapePath.v[i] = null;
  3227. shapePath.i[i] = null;
  3228. shapePath.o[i] = null;
  3229. }
  3230. shapePath._length = 0;
  3231. shapePath.c = false;
  3232. }
  3233. function clone(shape) {
  3234. var cloned = factory.newElement();
  3235. var i;
  3236. var len = shape._length === undefined ? shape.v.length : shape._length;
  3237. cloned.setLength(len);
  3238. cloned.c = shape.c;
  3239. for (i = 0; i < len; i += 1) {
  3240. 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);
  3241. }
  3242. return cloned;
  3243. }
  3244. var factory = poolFactory(4, create, release);
  3245. factory.clone = clone;
  3246. return factory;
  3247. }());
  3248. function ShapeCollection() {
  3249. this._length = 0;
  3250. this._maxLength = 4;
  3251. this.shapes = createSizedArray(this._maxLength);
  3252. }
  3253. ShapeCollection.prototype.addShape = function (shapeData) {
  3254. if (this._length === this._maxLength) {
  3255. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3256. this._maxLength *= 2;
  3257. }
  3258. this.shapes[this._length] = shapeData;
  3259. this._length += 1;
  3260. };
  3261. ShapeCollection.prototype.releaseShapes = function () {
  3262. var i;
  3263. for (i = 0; i < this._length; i += 1) {
  3264. shapePool.release(this.shapes[i]);
  3265. }
  3266. this._length = 0;
  3267. };
  3268. const shapeCollectionPool = (function () {
  3269. var ob = {
  3270. newShapeCollection: newShapeCollection,
  3271. release: release,
  3272. };
  3273. var _length = 0;
  3274. var _maxLength = 4;
  3275. var pool = createSizedArray(_maxLength);
  3276. function newShapeCollection() {
  3277. var shapeCollection;
  3278. if (_length) {
  3279. _length -= 1;
  3280. shapeCollection = pool[_length];
  3281. } else {
  3282. shapeCollection = new ShapeCollection();
  3283. }
  3284. return shapeCollection;
  3285. }
  3286. function release(shapeCollection) {
  3287. var i;
  3288. var len = shapeCollection._length;
  3289. for (i = 0; i < len; i += 1) {
  3290. shapePool.release(shapeCollection.shapes[i]);
  3291. }
  3292. shapeCollection._length = 0;
  3293. if (_length === _maxLength) {
  3294. pool = pooling.double(pool);
  3295. _maxLength *= 2;
  3296. }
  3297. pool[_length] = shapeCollection;
  3298. _length += 1;
  3299. }
  3300. return ob;
  3301. }());
  3302. const ShapePropertyFactory = (function () {
  3303. var initFrame = -999999;
  3304. function interpolateShape(frameNum, previousValue, caching) {
  3305. var iterationIndex = caching.lastIndex;
  3306. var keyPropS;
  3307. var keyPropE;
  3308. var isHold;
  3309. var j;
  3310. var k;
  3311. var jLen;
  3312. var kLen;
  3313. var perc;
  3314. var vertexValue;
  3315. var kf = this.keyframes;
  3316. if (frameNum < kf[0].t - this.offsetTime) {
  3317. keyPropS = kf[0].s[0];
  3318. isHold = true;
  3319. iterationIndex = 0;
  3320. } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) {
  3321. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  3322. /* if(kf[kf.length - 1].s){
  3323. keyPropS = kf[kf.length - 1].s[0];
  3324. }else{
  3325. keyPropS = kf[kf.length - 2].e[0];
  3326. } */
  3327. isHold = true;
  3328. } else {
  3329. var i = iterationIndex;
  3330. var len = kf.length - 1;
  3331. var flag = true;
  3332. var keyData;
  3333. var nextKeyData;
  3334. var keyframeMetadata;
  3335. while (flag) {
  3336. keyData = kf[i];
  3337. nextKeyData = kf[i + 1];
  3338. if ((nextKeyData.t - this.offsetTime) > frameNum) {
  3339. break;
  3340. }
  3341. if (i < len - 1) {
  3342. i += 1;
  3343. } else {
  3344. flag = false;
  3345. }
  3346. }
  3347. keyframeMetadata = this.keyframesMetadata[i] || {};
  3348. isHold = keyData.h === 1;
  3349. iterationIndex = i;
  3350. if (!isHold) {
  3351. if (frameNum >= nextKeyData.t - this.offsetTime) {
  3352. perc = 1;
  3353. } else if (frameNum < keyData.t - this.offsetTime) {
  3354. perc = 0;
  3355. } else {
  3356. var fnc;
  3357. if (keyframeMetadata.__fnct) {
  3358. fnc = keyframeMetadata.__fnct;
  3359. } else {
  3360. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get;
  3361. keyframeMetadata.__fnct = fnc;
  3362. }
  3363. perc = fnc((frameNum - (keyData.t - this.offsetTime)) / ((nextKeyData.t - this.offsetTime) - (keyData.t - this.offsetTime)));
  3364. }
  3365. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  3366. }
  3367. keyPropS = keyData.s[0];
  3368. }
  3369. jLen = previousValue._length;
  3370. kLen = keyPropS.i[0].length;
  3371. caching.lastIndex = iterationIndex;
  3372. for (j = 0; j < jLen; j += 1) {
  3373. for (k = 0; k < kLen; k += 1) {
  3374. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc;
  3375. previousValue.i[j][k] = vertexValue;
  3376. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc;
  3377. previousValue.o[j][k] = vertexValue;
  3378. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc;
  3379. previousValue.v[j][k] = vertexValue;
  3380. }
  3381. }
  3382. }
  3383. function interpolateShapeCurrentTime() {
  3384. var frameNum = this.comp.renderedFrame - this.offsetTime;
  3385. var initTime = this.keyframes[0].t - this.offsetTime;
  3386. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  3387. var lastFrame = this._caching.lastFrame;
  3388. if (!(lastFrame !== initFrame && ((lastFrame < initTime && frameNum < initTime) || (lastFrame > endTime && frameNum > endTime)))) {
  3389. /// /
  3390. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  3391. this.interpolateShape(frameNum, this.pv, this._caching);
  3392. /// /
  3393. }
  3394. this._caching.lastFrame = frameNum;
  3395. return this.pv;
  3396. }
  3397. function resetShape() {
  3398. this.paths = this.localShapeCollection;
  3399. }
  3400. function shapesEqual(shape1, shape2) {
  3401. if (shape1._length !== shape2._length || shape1.c !== shape2.c) {
  3402. return false;
  3403. }
  3404. var i;
  3405. var len = shape1._length;
  3406. for (i = 0; i < len; i += 1) {
  3407. if (shape1.v[i][0] !== shape2.v[i][0]
  3408. || shape1.v[i][1] !== shape2.v[i][1]
  3409. || shape1.o[i][0] !== shape2.o[i][0]
  3410. || shape1.o[i][1] !== shape2.o[i][1]
  3411. || shape1.i[i][0] !== shape2.i[i][0]
  3412. || shape1.i[i][1] !== shape2.i[i][1]) {
  3413. return false;
  3414. }
  3415. }
  3416. return true;
  3417. }
  3418. function setVValue(newPath) {
  3419. if (!shapesEqual(this.v, newPath)) {
  3420. this.v = shapePool.clone(newPath);
  3421. this.localShapeCollection.releaseShapes();
  3422. this.localShapeCollection.addShape(this.v);
  3423. this._mdf = true;
  3424. this.paths = this.localShapeCollection;
  3425. }
  3426. }
  3427. function processEffectsSequence() {
  3428. if (this.elem.globalData.frameId === this.frameId) {
  3429. return;
  3430. } if (!this.effectsSequence.length) {
  3431. this._mdf = false;
  3432. return;
  3433. }
  3434. if (this.lock) {
  3435. this.setVValue(this.pv);
  3436. return;
  3437. }
  3438. this.lock = true;
  3439. this._mdf = false;
  3440. var finalValue;
  3441. if (this.kf) {
  3442. finalValue = this.pv;
  3443. } else if (this.data.ks) {
  3444. finalValue = this.data.ks.k;
  3445. } else {
  3446. finalValue = this.data.pt.k;
  3447. }
  3448. var i;
  3449. var len = this.effectsSequence.length;
  3450. for (i = 0; i < len; i += 1) {
  3451. finalValue = this.effectsSequence[i](finalValue);
  3452. }
  3453. this.setVValue(finalValue);
  3454. this.lock = false;
  3455. this.frameId = this.elem.globalData.frameId;
  3456. }
  3457. function ShapeProperty(elem, data, type) {
  3458. this.propType = 'shape';
  3459. this.comp = elem.comp;
  3460. this.container = elem;
  3461. this.elem = elem;
  3462. this.data = data;
  3463. this.k = false;
  3464. this.kf = false;
  3465. this._mdf = false;
  3466. var pathData = type === 3 ? data.pt.k : data.ks.k;
  3467. this.v = shapePool.clone(pathData);
  3468. this.pv = shapePool.clone(this.v);
  3469. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3470. this.paths = this.localShapeCollection;
  3471. this.paths.addShape(this.v);
  3472. this.reset = resetShape;
  3473. this.effectsSequence = [];
  3474. }
  3475. function addEffect(effectFunction) {
  3476. this.effectsSequence.push(effectFunction);
  3477. this.container.addDynamicProperty(this);
  3478. }
  3479. ShapeProperty.prototype.interpolateShape = interpolateShape;
  3480. ShapeProperty.prototype.getValue = processEffectsSequence;
  3481. ShapeProperty.prototype.setVValue = setVValue;
  3482. ShapeProperty.prototype.addEffect = addEffect;
  3483. function KeyframedShapeProperty(elem, data, type) {
  3484. this.propType = 'shape';
  3485. this.comp = elem.comp;
  3486. this.elem = elem;
  3487. this.container = elem;
  3488. this.offsetTime = elem.data.st;
  3489. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  3490. this.keyframesMetadata = [];
  3491. this.k = true;
  3492. this.kf = true;
  3493. var len = this.keyframes[0].s[0].i.length;
  3494. this.v = shapePool.newElement();
  3495. this.v.setPathData(this.keyframes[0].s[0].c, len);
  3496. this.pv = shapePool.clone(this.v);
  3497. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3498. this.paths = this.localShapeCollection;
  3499. this.paths.addShape(this.v);
  3500. this.lastFrame = initFrame;
  3501. this.reset = resetShape;
  3502. this._caching = { lastFrame: initFrame, lastIndex: 0 };
  3503. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  3504. }
  3505. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  3506. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  3507. KeyframedShapeProperty.prototype.setVValue = setVValue;
  3508. KeyframedShapeProperty.prototype.addEffect = addEffect;
  3509. var EllShapeProperty = (function () {
  3510. var cPoint = roundCorner;
  3511. function EllShapePropertyFactory(elem, data) {
  3512. this.v = shapePool.newElement();
  3513. this.v.setPathData(true, 4);
  3514. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3515. this.paths = this.localShapeCollection;
  3516. this.localShapeCollection.addShape(this.v);
  3517. this.d = data.d;
  3518. this.elem = elem;
  3519. this.comp = elem.comp;
  3520. this.frameId = -1;
  3521. this.initDynamicPropertyContainer(elem);
  3522. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3523. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3524. if (this.dynamicProperties.length) {
  3525. this.k = true;
  3526. } else {
  3527. this.k = false;
  3528. this.convertEllToPath();
  3529. }
  3530. }
  3531. EllShapePropertyFactory.prototype = {
  3532. reset: resetShape,
  3533. getValue: function () {
  3534. if (this.elem.globalData.frameId === this.frameId) {
  3535. return;
  3536. }
  3537. this.frameId = this.elem.globalData.frameId;
  3538. this.iterateDynamicProperties();
  3539. if (this._mdf) {
  3540. this.convertEllToPath();
  3541. }
  3542. },
  3543. convertEllToPath: function () {
  3544. var p0 = this.p.v[0];
  3545. var p1 = this.p.v[1];
  3546. var s0 = this.s.v[0] / 2;
  3547. var s1 = this.s.v[1] / 2;
  3548. var _cw = this.d !== 3;
  3549. var _v = this.v;
  3550. _v.v[0][0] = p0;
  3551. _v.v[0][1] = p1 - s1;
  3552. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  3553. _v.v[1][1] = p1;
  3554. _v.v[2][0] = p0;
  3555. _v.v[2][1] = p1 + s1;
  3556. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  3557. _v.v[3][1] = p1;
  3558. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3559. _v.i[0][1] = p1 - s1;
  3560. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  3561. _v.i[1][1] = p1 - s1 * cPoint;
  3562. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3563. _v.i[2][1] = p1 + s1;
  3564. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  3565. _v.i[3][1] = p1 + s1 * cPoint;
  3566. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3567. _v.o[0][1] = p1 - s1;
  3568. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  3569. _v.o[1][1] = p1 + s1 * cPoint;
  3570. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3571. _v.o[2][1] = p1 + s1;
  3572. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  3573. _v.o[3][1] = p1 - s1 * cPoint;
  3574. },
  3575. };
  3576. extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory);
  3577. return EllShapePropertyFactory;
  3578. }());
  3579. var StarShapeProperty = (function () {
  3580. function StarShapePropertyFactory(elem, data) {
  3581. this.v = shapePool.newElement();
  3582. this.v.setPathData(true, 0);
  3583. this.elem = elem;
  3584. this.comp = elem.comp;
  3585. this.data = data;
  3586. this.frameId = -1;
  3587. this.d = data.d;
  3588. this.initDynamicPropertyContainer(elem);
  3589. if (data.sy === 1) {
  3590. this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this);
  3591. this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this);
  3592. this.convertToPath = this.convertStarToPath;
  3593. } else {
  3594. this.convertToPath = this.convertPolygonToPath;
  3595. }
  3596. this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this);
  3597. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3598. this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this);
  3599. this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this);
  3600. this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this);
  3601. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3602. this.localShapeCollection.addShape(this.v);
  3603. this.paths = this.localShapeCollection;
  3604. if (this.dynamicProperties.length) {
  3605. this.k = true;
  3606. } else {
  3607. this.k = false;
  3608. this.convertToPath();
  3609. }
  3610. }
  3611. StarShapePropertyFactory.prototype = {
  3612. reset: resetShape,
  3613. getValue: function () {
  3614. if (this.elem.globalData.frameId === this.frameId) {
  3615. return;
  3616. }
  3617. this.frameId = this.elem.globalData.frameId;
  3618. this.iterateDynamicProperties();
  3619. if (this._mdf) {
  3620. this.convertToPath();
  3621. }
  3622. },
  3623. convertStarToPath: function () {
  3624. var numPts = Math.floor(this.pt.v) * 2;
  3625. var angle = (Math.PI * 2) / numPts;
  3626. /* this.v.v.length = numPts;
  3627. this.v.i.length = numPts;
  3628. this.v.o.length = numPts; */
  3629. var longFlag = true;
  3630. var longRad = this.or.v;
  3631. var shortRad = this.ir.v;
  3632. var longRound = this.os.v;
  3633. var shortRound = this.is.v;
  3634. var longPerimSegment = (2 * Math.PI * longRad) / (numPts * 2);
  3635. var shortPerimSegment = (2 * Math.PI * shortRad) / (numPts * 2);
  3636. var i;
  3637. var rad;
  3638. var roundness;
  3639. var perimSegment;
  3640. var currentAng = -Math.PI / 2;
  3641. currentAng += this.r.v;
  3642. var dir = this.data.d === 3 ? -1 : 1;
  3643. this.v._length = 0;
  3644. for (i = 0; i < numPts; i += 1) {
  3645. rad = longFlag ? longRad : shortRad;
  3646. roundness = longFlag ? longRound : shortRound;
  3647. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  3648. var x = rad * Math.cos(currentAng);
  3649. var y = rad * Math.sin(currentAng);
  3650. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3651. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3652. x += +this.p.v[0];
  3653. y += +this.p.v[1];
  3654. 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);
  3655. /* this.v.v[i] = [x,y];
  3656. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  3657. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  3658. this.v._length = numPts; */
  3659. longFlag = !longFlag;
  3660. currentAng += angle * dir;
  3661. }
  3662. },
  3663. convertPolygonToPath: function () {
  3664. var numPts = Math.floor(this.pt.v);
  3665. var angle = (Math.PI * 2) / numPts;
  3666. var rad = this.or.v;
  3667. var roundness = this.os.v;
  3668. var perimSegment = (2 * Math.PI * rad) / (numPts * 4);
  3669. var i;
  3670. var currentAng = -Math.PI * 0.5;
  3671. var dir = this.data.d === 3 ? -1 : 1;
  3672. currentAng += this.r.v;
  3673. this.v._length = 0;
  3674. for (i = 0; i < numPts; i += 1) {
  3675. var x = rad * Math.cos(currentAng);
  3676. var y = rad * Math.sin(currentAng);
  3677. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3678. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3679. x += +this.p.v[0];
  3680. y += +this.p.v[1];
  3681. 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);
  3682. currentAng += angle * dir;
  3683. }
  3684. this.paths.length = 0;
  3685. this.paths[0] = this.v;
  3686. },
  3687. };
  3688. extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory);
  3689. return StarShapePropertyFactory;
  3690. }());
  3691. var RectShapeProperty = (function () {
  3692. function RectShapePropertyFactory(elem, data) {
  3693. this.v = shapePool.newElement();
  3694. this.v.c = true;
  3695. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3696. this.localShapeCollection.addShape(this.v);
  3697. this.paths = this.localShapeCollection;
  3698. this.elem = elem;
  3699. this.comp = elem.comp;
  3700. this.frameId = -1;
  3701. this.d = data.d;
  3702. this.initDynamicPropertyContainer(elem);
  3703. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3704. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3705. this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this);
  3706. if (this.dynamicProperties.length) {
  3707. this.k = true;
  3708. } else {
  3709. this.k = false;
  3710. this.convertRectToPath();
  3711. }
  3712. }
  3713. RectShapePropertyFactory.prototype = {
  3714. convertRectToPath: function () {
  3715. var p0 = this.p.v[0];
  3716. var p1 = this.p.v[1];
  3717. var v0 = this.s.v[0] / 2;
  3718. var v1 = this.s.v[1] / 2;
  3719. var round = bmMin(v0, v1, this.r.v);
  3720. var cPoint = round * (1 - roundCorner);
  3721. this.v._length = 0;
  3722. if (this.d === 2 || this.d === 1) {
  3723. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true);
  3724. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true);
  3725. if (round !== 0) {
  3726. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true);
  3727. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true);
  3728. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true);
  3729. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true);
  3730. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true);
  3731. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true);
  3732. } else {
  3733. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2);
  3734. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3);
  3735. }
  3736. } else {
  3737. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true);
  3738. if (round !== 0) {
  3739. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true);
  3740. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true);
  3741. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true);
  3742. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true);
  3743. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true);
  3744. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true);
  3745. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true);
  3746. } else {
  3747. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true);
  3748. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true);
  3749. this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true);
  3750. }
  3751. }
  3752. },
  3753. getValue: function () {
  3754. if (this.elem.globalData.frameId === this.frameId) {
  3755. return;
  3756. }
  3757. this.frameId = this.elem.globalData.frameId;
  3758. this.iterateDynamicProperties();
  3759. if (this._mdf) {
  3760. this.convertRectToPath();
  3761. }
  3762. },
  3763. reset: resetShape,
  3764. };
  3765. extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory);
  3766. return RectShapePropertyFactory;
  3767. }());
  3768. function getShapeProp(elem, data, type) {
  3769. var prop;
  3770. if (type === 3 || type === 4) {
  3771. var dataProp = type === 3 ? data.pt : data.ks;
  3772. var keys = dataProp.k;
  3773. if (keys.length) {
  3774. prop = new KeyframedShapeProperty(elem, data, type);
  3775. } else {
  3776. prop = new ShapeProperty(elem, data, type);
  3777. }
  3778. } else if (type === 5) {
  3779. prop = new RectShapeProperty(elem, data);
  3780. } else if (type === 6) {
  3781. prop = new EllShapeProperty(elem, data);
  3782. } else if (type === 7) {
  3783. prop = new StarShapeProperty(elem, data);
  3784. }
  3785. if (prop.k) {
  3786. elem.addDynamicProperty(prop);
  3787. }
  3788. return prop;
  3789. }
  3790. function getConstructorFunction() {
  3791. return ShapeProperty;
  3792. }
  3793. function getKeyframedConstructorFunction() {
  3794. return KeyframedShapeProperty;
  3795. }
  3796. var ob = {};
  3797. ob.getShapeProp = getShapeProp;
  3798. ob.getConstructorFunction = getConstructorFunction;
  3799. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3800. return ob;
  3801. }());
  3802. /*!
  3803. Transformation Matrix v2.0
  3804. (c) Epistemex 2014-2015
  3805. www.epistemex.com
  3806. By Ken Fyrstenberg
  3807. Contributions by leeoniya.
  3808. License: MIT, header required.
  3809. */
  3810. /**
  3811. * 2D transformation matrix object initialized with identity matrix.
  3812. *
  3813. * The matrix can synchronize a canvas context by supplying the context
  3814. * as an argument, or later apply current absolute transform to an
  3815. * existing context.
  3816. *
  3817. * All values are handled as floating point values.
  3818. *
  3819. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  3820. * @prop {number} a - scale x
  3821. * @prop {number} b - shear y
  3822. * @prop {number} c - shear x
  3823. * @prop {number} d - scale y
  3824. * @prop {number} e - translate x
  3825. * @prop {number} f - translate y
  3826. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  3827. * @constructor
  3828. */
  3829. const Matrix = (function () {
  3830. var _cos = Math.cos;
  3831. var _sin = Math.sin;
  3832. var _tan = Math.tan;
  3833. var _rnd = Math.round;
  3834. function reset() {
  3835. this.props[0] = 1;
  3836. this.props[1] = 0;
  3837. this.props[2] = 0;
  3838. this.props[3] = 0;
  3839. this.props[4] = 0;
  3840. this.props[5] = 1;
  3841. this.props[6] = 0;
  3842. this.props[7] = 0;
  3843. this.props[8] = 0;
  3844. this.props[9] = 0;
  3845. this.props[10] = 1;
  3846. this.props[11] = 0;
  3847. this.props[12] = 0;
  3848. this.props[13] = 0;
  3849. this.props[14] = 0;
  3850. this.props[15] = 1;
  3851. return this;
  3852. }
  3853. function rotate(angle) {
  3854. if (angle === 0) {
  3855. return this;
  3856. }
  3857. var mCos = _cos(angle);
  3858. var mSin = _sin(angle);
  3859. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3860. }
  3861. function rotateX(angle) {
  3862. if (angle === 0) {
  3863. return this;
  3864. }
  3865. var mCos = _cos(angle);
  3866. var mSin = _sin(angle);
  3867. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  3868. }
  3869. function rotateY(angle) {
  3870. if (angle === 0) {
  3871. return this;
  3872. }
  3873. var mCos = _cos(angle);
  3874. var mSin = _sin(angle);
  3875. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  3876. }
  3877. function rotateZ(angle) {
  3878. if (angle === 0) {
  3879. return this;
  3880. }
  3881. var mCos = _cos(angle);
  3882. var mSin = _sin(angle);
  3883. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3884. }
  3885. function shear(sx, sy) {
  3886. return this._t(1, sy, sx, 1, 0, 0);
  3887. }
  3888. function skew(ax, ay) {
  3889. return this.shear(_tan(ax), _tan(ay));
  3890. }
  3891. function skewFromAxis(ax, angle) {
  3892. var mCos = _cos(angle);
  3893. var mSin = _sin(angle);
  3894. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3895. ._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3896. ._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3897. // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  3898. }
  3899. function scale(sx, sy, sz) {
  3900. if (!sz && sz !== 0) {
  3901. sz = 1;
  3902. }
  3903. if (sx === 1 && sy === 1 && sz === 1) {
  3904. return this;
  3905. }
  3906. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  3907. }
  3908. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  3909. this.props[0] = a;
  3910. this.props[1] = b;
  3911. this.props[2] = c;
  3912. this.props[3] = d;
  3913. this.props[4] = e;
  3914. this.props[5] = f;
  3915. this.props[6] = g;
  3916. this.props[7] = h;
  3917. this.props[8] = i;
  3918. this.props[9] = j;
  3919. this.props[10] = k;
  3920. this.props[11] = l;
  3921. this.props[12] = m;
  3922. this.props[13] = n;
  3923. this.props[14] = o;
  3924. this.props[15] = p;
  3925. return this;
  3926. }
  3927. function translate(tx, ty, tz) {
  3928. tz = tz || 0;
  3929. if (tx !== 0 || ty !== 0 || tz !== 0) {
  3930. return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1);
  3931. }
  3932. return this;
  3933. }
  3934. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  3935. var _p = this.props;
  3936. 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) {
  3937. // NOTE: commenting this condition because TurboFan deoptimizes code when present
  3938. // if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  3939. _p[12] = _p[12] * a2 + _p[15] * m2;
  3940. _p[13] = _p[13] * f2 + _p[15] * n2;
  3941. _p[14] = _p[14] * k2 + _p[15] * o2;
  3942. _p[15] *= p2;
  3943. // }
  3944. this._identityCalculated = false;
  3945. return this;
  3946. }
  3947. var a1 = _p[0];
  3948. var b1 = _p[1];
  3949. var c1 = _p[2];
  3950. var d1 = _p[3];
  3951. var e1 = _p[4];
  3952. var f1 = _p[5];
  3953. var g1 = _p[6];
  3954. var h1 = _p[7];
  3955. var i1 = _p[8];
  3956. var j1 = _p[9];
  3957. var k1 = _p[10];
  3958. var l1 = _p[11];
  3959. var m1 = _p[12];
  3960. var n1 = _p[13];
  3961. var o1 = _p[14];
  3962. var p1 = _p[15];
  3963. /* matrix order (canvas compatible):
  3964. * ace
  3965. * bdf
  3966. * 001
  3967. */
  3968. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  3969. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2;
  3970. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2;
  3971. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2;
  3972. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2;
  3973. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2;
  3974. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2;
  3975. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2;
  3976. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2;
  3977. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2;
  3978. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2;
  3979. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2;
  3980. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2;
  3981. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2;
  3982. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2;
  3983. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2;
  3984. this._identityCalculated = false;
  3985. return this;
  3986. }
  3987. function isIdentity() {
  3988. if (!this._identityCalculated) {
  3989. 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);
  3990. this._identityCalculated = true;
  3991. }
  3992. return this._identity;
  3993. }
  3994. function equals(matr) {
  3995. var i = 0;
  3996. while (i < 16) {
  3997. if (matr.props[i] !== this.props[i]) {
  3998. return false;
  3999. }
  4000. i += 1;
  4001. }
  4002. return true;
  4003. }
  4004. function clone(matr) {
  4005. var i;
  4006. for (i = 0; i < 16; i += 1) {
  4007. matr.props[i] = this.props[i];
  4008. }
  4009. return matr;
  4010. }
  4011. function cloneFromProps(props) {
  4012. var i;
  4013. for (i = 0; i < 16; i += 1) {
  4014. this.props[i] = props[i];
  4015. }
  4016. }
  4017. function applyToPoint(x, y, z) {
  4018. return {
  4019. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4020. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4021. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4022. };
  4023. /* return {
  4024. x: x * me.a + y * me.c + me.e,
  4025. y: x * me.b + y * me.d + me.f
  4026. }; */
  4027. }
  4028. function applyToX(x, y, z) {
  4029. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  4030. }
  4031. function applyToY(x, y, z) {
  4032. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  4033. }
  4034. function applyToZ(x, y, z) {
  4035. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  4036. }
  4037. function getInverseMatrix() {
  4038. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  4039. var a = this.props[5] / determinant;
  4040. var b = -this.props[1] / determinant;
  4041. var c = -this.props[4] / determinant;
  4042. var d = this.props[0] / determinant;
  4043. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant;
  4044. var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant;
  4045. var inverseMatrix = new Matrix();
  4046. inverseMatrix.props[0] = a;
  4047. inverseMatrix.props[1] = b;
  4048. inverseMatrix.props[4] = c;
  4049. inverseMatrix.props[5] = d;
  4050. inverseMatrix.props[12] = e;
  4051. inverseMatrix.props[13] = f;
  4052. return inverseMatrix;
  4053. }
  4054. function inversePoint(pt) {
  4055. var inverseMatrix = this.getInverseMatrix();
  4056. return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0);
  4057. }
  4058. function inversePoints(pts) {
  4059. var i;
  4060. var len = pts.length;
  4061. var retPts = [];
  4062. for (i = 0; i < len; i += 1) {
  4063. retPts[i] = inversePoint(pts[i]);
  4064. }
  4065. return retPts;
  4066. }
  4067. function applyToTriplePoints(pt1, pt2, pt3) {
  4068. var arr = createTypedArray('float32', 6);
  4069. if (this.isIdentity()) {
  4070. arr[0] = pt1[0];
  4071. arr[1] = pt1[1];
  4072. arr[2] = pt2[0];
  4073. arr[3] = pt2[1];
  4074. arr[4] = pt3[0];
  4075. arr[5] = pt3[1];
  4076. } else {
  4077. var p0 = this.props[0];
  4078. var p1 = this.props[1];
  4079. var p4 = this.props[4];
  4080. var p5 = this.props[5];
  4081. var p12 = this.props[12];
  4082. var p13 = this.props[13];
  4083. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  4084. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  4085. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  4086. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  4087. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  4088. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  4089. }
  4090. return arr;
  4091. }
  4092. function applyToPointArray(x, y, z) {
  4093. var arr;
  4094. if (this.isIdentity()) {
  4095. arr = [x, y, z];
  4096. } else {
  4097. arr = [
  4098. x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4099. x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4100. x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4101. ];
  4102. }
  4103. return arr;
  4104. }
  4105. function applyToPointStringified(x, y) {
  4106. if (this.isIdentity()) {
  4107. return x + ',' + y;
  4108. }
  4109. var _p = this.props;
  4110. 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;
  4111. }
  4112. function toCSS() {
  4113. // 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.
  4114. /* if(this.isIdentity()) {
  4115. return '';
  4116. } */
  4117. var i = 0;
  4118. var props = this.props;
  4119. var cssValue = 'matrix3d(';
  4120. var v = 10000;
  4121. while (i < 16) {
  4122. cssValue += _rnd(props[i] * v) / v;
  4123. cssValue += i === 15 ? ')' : ',';
  4124. i += 1;
  4125. }
  4126. return cssValue;
  4127. }
  4128. function roundMatrixProperty(val) {
  4129. var v = 10000;
  4130. if ((val < 0.000001 && val > 0) || (val > -0.000001 && val < 0)) {
  4131. return _rnd(val * v) / v;
  4132. }
  4133. return val;
  4134. }
  4135. function to2dCSS() {
  4136. // 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.
  4137. /* if(this.isIdentity()) {
  4138. return '';
  4139. } */
  4140. var props = this.props;
  4141. var _a = roundMatrixProperty(props[0]);
  4142. var _b = roundMatrixProperty(props[1]);
  4143. var _c = roundMatrixProperty(props[4]);
  4144. var _d = roundMatrixProperty(props[5]);
  4145. var _e = roundMatrixProperty(props[12]);
  4146. var _f = roundMatrixProperty(props[13]);
  4147. return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')';
  4148. }
  4149. return function () {
  4150. this.reset = reset;
  4151. this.rotate = rotate;
  4152. this.rotateX = rotateX;
  4153. this.rotateY = rotateY;
  4154. this.rotateZ = rotateZ;
  4155. this.skew = skew;
  4156. this.skewFromAxis = skewFromAxis;
  4157. this.shear = shear;
  4158. this.scale = scale;
  4159. this.setTransform = setTransform;
  4160. this.translate = translate;
  4161. this.transform = transform;
  4162. this.applyToPoint = applyToPoint;
  4163. this.applyToX = applyToX;
  4164. this.applyToY = applyToY;
  4165. this.applyToZ = applyToZ;
  4166. this.applyToPointArray = applyToPointArray;
  4167. this.applyToTriplePoints = applyToTriplePoints;
  4168. this.applyToPointStringified = applyToPointStringified;
  4169. this.toCSS = toCSS;
  4170. this.to2dCSS = to2dCSS;
  4171. this.clone = clone;
  4172. this.cloneFromProps = cloneFromProps;
  4173. this.equals = equals;
  4174. this.inversePoints = inversePoints;
  4175. this.inversePoint = inversePoint;
  4176. this.getInverseMatrix = getInverseMatrix;
  4177. this._t = this.transform;
  4178. this.isIdentity = isIdentity;
  4179. this._identity = true;
  4180. this._identityCalculated = false;
  4181. this.props = createTypedArray('float32', 16);
  4182. this.reset();
  4183. };
  4184. }());
  4185. const lottie = {};
  4186. var standalone = '__[STANDALONE]__';
  4187. var animationData = '__[ANIMATIONDATA]__';
  4188. var renderer = '';
  4189. function setLocation(href) {
  4190. setLocationHref(href);
  4191. }
  4192. function searchAnimations() {
  4193. if (standalone === true) {
  4194. animationManager.searchAnimations(animationData, standalone, renderer);
  4195. } else {
  4196. animationManager.searchAnimations();
  4197. }
  4198. }
  4199. function setSubframeRendering(flag) {
  4200. setSubframeEnabled(flag);
  4201. }
  4202. function setPrefix(prefix) {
  4203. setIdPrefix(prefix);
  4204. }
  4205. function loadAnimation(params) {
  4206. if (standalone === true) {
  4207. params.animationData = JSON.parse(animationData);
  4208. }
  4209. return animationManager.loadAnimation(params);
  4210. }
  4211. function setQuality(value) {
  4212. if (typeof value === 'string') {
  4213. switch (value) {
  4214. case 'high':
  4215. setDefaultCurveSegments(200);
  4216. break;
  4217. default:
  4218. case 'medium':
  4219. setDefaultCurveSegments(50);
  4220. break;
  4221. case 'low':
  4222. setDefaultCurveSegments(10);
  4223. break;
  4224. }
  4225. } else if (!isNaN(value) && value > 1) {
  4226. setDefaultCurveSegments(value);
  4227. }
  4228. if (getDefaultCurveSegments() >= 50) {
  4229. roundValues(false);
  4230. } else {
  4231. roundValues(true);
  4232. }
  4233. }
  4234. function inBrowser() {
  4235. return typeof navigator !== 'undefined';
  4236. }
  4237. function installPlugin(type, plugin) {
  4238. if (type === 'expressions') {
  4239. setExpressionsPlugin(plugin);
  4240. }
  4241. }
  4242. function getFactory(name) {
  4243. switch (name) {
  4244. case 'propertyFactory':
  4245. return PropertyFactory;
  4246. case 'shapePropertyFactory':
  4247. return ShapePropertyFactory;
  4248. case 'matrix':
  4249. return Matrix;
  4250. default:
  4251. return null;
  4252. }
  4253. }
  4254. lottie.play = animationManager.play;
  4255. lottie.pause = animationManager.pause;
  4256. lottie.setLocationHref = setLocation;
  4257. lottie.togglePause = animationManager.togglePause;
  4258. lottie.setSpeed = animationManager.setSpeed;
  4259. lottie.setDirection = animationManager.setDirection;
  4260. lottie.stop = animationManager.stop;
  4261. lottie.searchAnimations = searchAnimations;
  4262. lottie.registerAnimation = animationManager.registerAnimation;
  4263. lottie.loadAnimation = loadAnimation;
  4264. lottie.setSubframeRendering = setSubframeRendering;
  4265. lottie.resize = animationManager.resize;
  4266. // lottie.start = start;
  4267. lottie.goToAndStop = animationManager.goToAndStop;
  4268. lottie.destroy = animationManager.destroy;
  4269. lottie.setQuality = setQuality;
  4270. lottie.inBrowser = inBrowser;
  4271. lottie.installPlugin = installPlugin;
  4272. lottie.freeze = animationManager.freeze;
  4273. lottie.unfreeze = animationManager.unfreeze;
  4274. lottie.setVolume = animationManager.setVolume;
  4275. lottie.mute = animationManager.mute;
  4276. lottie.unmute = animationManager.unmute;
  4277. lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  4278. lottie.useWebWorker = setWebWorker;
  4279. lottie.setIDPrefix = setPrefix;
  4280. lottie.__getFactory = getFactory;
  4281. lottie.version = '[[BM_VERSION]]';
  4282. function checkReady() {
  4283. if (document.readyState === 'complete') {
  4284. clearInterval(readyStateCheckInterval);
  4285. searchAnimations();
  4286. }
  4287. }
  4288. function getQueryVariable(variable) {
  4289. var vars = queryString.split('&');
  4290. for (var i = 0; i < vars.length; i += 1) {
  4291. var pair = vars[i].split('=');
  4292. if (decodeURIComponent(pair[0]) == variable) { // eslint-disable-line eqeqeq
  4293. return decodeURIComponent(pair[1]);
  4294. }
  4295. }
  4296. return null;
  4297. }
  4298. var queryString = '';
  4299. if (standalone) {
  4300. var scripts = document.getElementsByTagName('script');
  4301. var index = scripts.length - 1;
  4302. var myScript = scripts[index] || {
  4303. src: '',
  4304. };
  4305. queryString = myScript.src ? myScript.src.replace(/^[^\?]+\??/, '') : ''; // eslint-disable-line no-useless-escape
  4306. renderer = getQueryVariable('renderer');
  4307. }
  4308. var readyStateCheckInterval = setInterval(checkReady, 100);
  4309. // this adds bodymovin to the window object for backwards compatibility
  4310. try {
  4311. if (!(typeof exports === 'object' && typeof module !== 'undefined')
  4312. && !(typeof define === 'function' && define.amd) // eslint-disable-line no-undef
  4313. ) {
  4314. window.bodymovin = lottie;
  4315. }
  4316. } catch (err) {
  4317. //
  4318. }
  4319. const ShapeModifiers = (function () {
  4320. var ob = {};
  4321. var modifiers = {};
  4322. ob.registerModifier = registerModifier;
  4323. ob.getModifier = getModifier;
  4324. function registerModifier(nm, factory) {
  4325. if (!modifiers[nm]) {
  4326. modifiers[nm] = factory;
  4327. }
  4328. }
  4329. function getModifier(nm, elem, data) {
  4330. return new modifiers[nm](elem, data);
  4331. }
  4332. return ob;
  4333. }());
  4334. function ShapeModifier() {}
  4335. ShapeModifier.prototype.initModifierProperties = function () {};
  4336. ShapeModifier.prototype.addShapeToModifier = function () {};
  4337. ShapeModifier.prototype.addShape = function (data) {
  4338. if (!this.closed) {
  4339. // 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.
  4340. data.sh.container.addDynamicProperty(data.sh);
  4341. var shapeData = { shape: data.sh, data: data, localShapeCollection: shapeCollectionPool.newShapeCollection() };
  4342. this.shapes.push(shapeData);
  4343. this.addShapeToModifier(shapeData);
  4344. if (this._isAnimated) {
  4345. data.setAsAnimated();
  4346. }
  4347. }
  4348. };
  4349. ShapeModifier.prototype.init = function (elem, data) {
  4350. this.shapes = [];
  4351. this.elem = elem;
  4352. this.initDynamicPropertyContainer(elem);
  4353. this.initModifierProperties(elem, data);
  4354. this.frameId = initialDefaultFrame;
  4355. this.closed = false;
  4356. this.k = false;
  4357. if (this.dynamicProperties.length) {
  4358. this.k = true;
  4359. } else {
  4360. this.getValue(true);
  4361. }
  4362. };
  4363. ShapeModifier.prototype.processKeys = function () {
  4364. if (this.elem.globalData.frameId === this.frameId) {
  4365. return;
  4366. }
  4367. this.frameId = this.elem.globalData.frameId;
  4368. this.iterateDynamicProperties();
  4369. };
  4370. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  4371. function TrimModifier() {
  4372. }
  4373. extendPrototype([ShapeModifier], TrimModifier);
  4374. TrimModifier.prototype.initModifierProperties = function (elem, data) {
  4375. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  4376. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  4377. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  4378. this.sValue = 0;
  4379. this.eValue = 0;
  4380. this.getValue = this.processKeys;
  4381. this.m = data.m;
  4382. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  4383. };
  4384. TrimModifier.prototype.addShapeToModifier = function (shapeData) {
  4385. shapeData.pathsData = [];
  4386. };
  4387. TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) {
  4388. var segments = [];
  4389. if (e <= 1) {
  4390. segments.push({
  4391. s: s,
  4392. e: e,
  4393. });
  4394. } else if (s >= 1) {
  4395. segments.push({
  4396. s: s - 1,
  4397. e: e - 1,
  4398. });
  4399. } else {
  4400. segments.push({
  4401. s: s,
  4402. e: 1,
  4403. });
  4404. segments.push({
  4405. s: 0,
  4406. e: e - 1,
  4407. });
  4408. }
  4409. var shapeSegments = [];
  4410. var i;
  4411. var len = segments.length;
  4412. var segmentOb;
  4413. for (i = 0; i < len; i += 1) {
  4414. segmentOb = segments[i];
  4415. if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) {
  4416. var shapeS;
  4417. var shapeE;
  4418. if (segmentOb.s * totalModifierLength <= addedLength) {
  4419. shapeS = 0;
  4420. } else {
  4421. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  4422. }
  4423. if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  4424. shapeE = 1;
  4425. } else {
  4426. shapeE = ((segmentOb.e * totalModifierLength - addedLength) / shapeLength);
  4427. }
  4428. shapeSegments.push([shapeS, shapeE]);
  4429. }
  4430. }
  4431. if (!shapeSegments.length) {
  4432. shapeSegments.push([0, 0]);
  4433. }
  4434. return shapeSegments;
  4435. };
  4436. TrimModifier.prototype.releasePathsData = function (pathsData) {
  4437. var i;
  4438. var len = pathsData.length;
  4439. for (i = 0; i < len; i += 1) {
  4440. segmentsLengthPool.release(pathsData[i]);
  4441. }
  4442. pathsData.length = 0;
  4443. return pathsData;
  4444. };
  4445. TrimModifier.prototype.processShapes = function (_isFirstFrame) {
  4446. var s;
  4447. var e;
  4448. if (this._mdf || _isFirstFrame) {
  4449. var o = (this.o.v % 360) / 360;
  4450. if (o < 0) {
  4451. o += 1;
  4452. }
  4453. if (this.s.v > 1) {
  4454. s = 1 + o;
  4455. } else if (this.s.v < 0) {
  4456. s = 0 + o;
  4457. } else {
  4458. s = this.s.v + o;
  4459. }
  4460. if (this.e.v > 1) {
  4461. e = 1 + o;
  4462. } else if (this.e.v < 0) {
  4463. e = 0 + o;
  4464. } else {
  4465. e = this.e.v + o;
  4466. }
  4467. if (s > e) {
  4468. var _s = s;
  4469. s = e;
  4470. e = _s;
  4471. }
  4472. s = Math.round(s * 10000) * 0.0001;
  4473. e = Math.round(e * 10000) * 0.0001;
  4474. this.sValue = s;
  4475. this.eValue = e;
  4476. } else {
  4477. s = this.sValue;
  4478. e = this.eValue;
  4479. }
  4480. var shapePaths;
  4481. var i;
  4482. var len = this.shapes.length;
  4483. var j;
  4484. var jLen;
  4485. var pathsData;
  4486. var pathData;
  4487. var totalShapeLength;
  4488. var totalModifierLength = 0;
  4489. if (e === s) {
  4490. for (i = 0; i < len; i += 1) {
  4491. this.shapes[i].localShapeCollection.releaseShapes();
  4492. this.shapes[i].shape._mdf = true;
  4493. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  4494. if (this._mdf) {
  4495. this.shapes[i].pathsData.length = 0;
  4496. }
  4497. }
  4498. } else if (!((e === 1 && s === 0) || (e === 0 && s === 1))) {
  4499. var segments = [];
  4500. var shapeData;
  4501. var localShapeCollection;
  4502. for (i = 0; i < len; i += 1) {
  4503. shapeData = this.shapes[i];
  4504. // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  4505. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  4506. shapeData.shape.paths = shapeData.localShapeCollection;
  4507. } else {
  4508. shapePaths = shapeData.shape.paths;
  4509. jLen = shapePaths._length;
  4510. totalShapeLength = 0;
  4511. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  4512. totalShapeLength = shapeData.totalShapeLength;
  4513. } else {
  4514. pathsData = this.releasePathsData(shapeData.pathsData);
  4515. for (j = 0; j < jLen; j += 1) {
  4516. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  4517. pathsData.push(pathData);
  4518. totalShapeLength += pathData.totalLength;
  4519. }
  4520. shapeData.totalShapeLength = totalShapeLength;
  4521. shapeData.pathsData = pathsData;
  4522. }
  4523. totalModifierLength += totalShapeLength;
  4524. shapeData.shape._mdf = true;
  4525. }
  4526. }
  4527. var shapeS = s;
  4528. var shapeE = e;
  4529. var addedLength = 0;
  4530. var edges;
  4531. for (i = len - 1; i >= 0; i -= 1) {
  4532. shapeData = this.shapes[i];
  4533. if (shapeData.shape._mdf) {
  4534. localShapeCollection = shapeData.localShapeCollection;
  4535. localShapeCollection.releaseShapes();
  4536. // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  4537. if (this.m === 2 && len > 1) {
  4538. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  4539. addedLength += shapeData.totalShapeLength;
  4540. } else {
  4541. edges = [[shapeS, shapeE]];
  4542. }
  4543. jLen = edges.length;
  4544. for (j = 0; j < jLen; j += 1) {
  4545. shapeS = edges[j][0];
  4546. shapeE = edges[j][1];
  4547. segments.length = 0;
  4548. if (shapeE <= 1) {
  4549. segments.push({
  4550. s: shapeData.totalShapeLength * shapeS,
  4551. e: shapeData.totalShapeLength * shapeE,
  4552. });
  4553. } else if (shapeS >= 1) {
  4554. segments.push({
  4555. s: shapeData.totalShapeLength * (shapeS - 1),
  4556. e: shapeData.totalShapeLength * (shapeE - 1),
  4557. });
  4558. } else {
  4559. segments.push({
  4560. s: shapeData.totalShapeLength * shapeS,
  4561. e: shapeData.totalShapeLength,
  4562. });
  4563. segments.push({
  4564. s: 0,
  4565. e: shapeData.totalShapeLength * (shapeE - 1),
  4566. });
  4567. }
  4568. var newShapesData = this.addShapes(shapeData, segments[0]);
  4569. if (segments[0].s !== segments[0].e) {
  4570. if (segments.length > 1) {
  4571. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  4572. if (lastShapeInCollection.c) {
  4573. var lastShape = newShapesData.pop();
  4574. this.addPaths(newShapesData, localShapeCollection);
  4575. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  4576. } else {
  4577. this.addPaths(newShapesData, localShapeCollection);
  4578. newShapesData = this.addShapes(shapeData, segments[1]);
  4579. }
  4580. }
  4581. this.addPaths(newShapesData, localShapeCollection);
  4582. }
  4583. }
  4584. shapeData.shape.paths = localShapeCollection;
  4585. }
  4586. }
  4587. } else if (this._mdf) {
  4588. for (i = 0; i < len; i += 1) {
  4589. // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  4590. // Don't remove this even if it's losing cached info.
  4591. this.shapes[i].pathsData.length = 0;
  4592. this.shapes[i].shape._mdf = true;
  4593. }
  4594. }
  4595. };
  4596. TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) {
  4597. var i;
  4598. var len = newPaths.length;
  4599. for (i = 0; i < len; i += 1) {
  4600. localShapeCollection.addShape(newPaths[i]);
  4601. }
  4602. };
  4603. TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  4604. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  4605. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  4606. if (newShape) {
  4607. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  4608. }
  4609. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  4610. };
  4611. TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) {
  4612. shapePath.setXYAt(points[1], points[5], 'o', pos);
  4613. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  4614. if (newShape) {
  4615. shapePath.setXYAt(points[0], points[4], 'v', pos);
  4616. }
  4617. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  4618. };
  4619. TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) {
  4620. var pathsData = shapeData.pathsData;
  4621. var shapePaths = shapeData.shape.paths.shapes;
  4622. var i;
  4623. var len = shapeData.shape.paths._length;
  4624. var j;
  4625. var jLen;
  4626. var addedLength = 0;
  4627. var currentLengthData;
  4628. var segmentCount;
  4629. var lengths;
  4630. var segment;
  4631. var shapes = [];
  4632. var initPos;
  4633. var newShape = true;
  4634. if (!shapePath) {
  4635. shapePath = shapePool.newElement();
  4636. segmentCount = 0;
  4637. initPos = 0;
  4638. } else {
  4639. segmentCount = shapePath._length;
  4640. initPos = shapePath._length;
  4641. }
  4642. shapes.push(shapePath);
  4643. for (i = 0; i < len; i += 1) {
  4644. lengths = pathsData[i].lengths;
  4645. shapePath.c = shapePaths[i].c;
  4646. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  4647. for (j = 1; j < jLen; j += 1) {
  4648. currentLengthData = lengths[j - 1];
  4649. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  4650. addedLength += currentLengthData.addedLength;
  4651. shapePath.c = false;
  4652. } else if (addedLength > shapeSegment.e) {
  4653. shapePath.c = false;
  4654. break;
  4655. } else {
  4656. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  4657. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  4658. newShape = false;
  4659. } else {
  4660. 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]);
  4661. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4662. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4663. newShape = false;
  4664. shapePath.c = false;
  4665. }
  4666. addedLength += currentLengthData.addedLength;
  4667. segmentCount += 1;
  4668. }
  4669. }
  4670. if (shapePaths[i].c && lengths.length) {
  4671. currentLengthData = lengths[j - 1];
  4672. if (addedLength <= shapeSegment.e) {
  4673. var segmentLength = lengths[j - 1].addedLength;
  4674. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  4675. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  4676. newShape = false;
  4677. } else {
  4678. 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]);
  4679. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4680. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4681. newShape = false;
  4682. shapePath.c = false;
  4683. }
  4684. } else {
  4685. shapePath.c = false;
  4686. }
  4687. addedLength += currentLengthData.addedLength;
  4688. segmentCount += 1;
  4689. }
  4690. if (shapePath._length) {
  4691. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  4692. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1);
  4693. }
  4694. if (addedLength > shapeSegment.e) {
  4695. break;
  4696. }
  4697. if (i < len - 1) {
  4698. shapePath = shapePool.newElement();
  4699. newShape = true;
  4700. shapes.push(shapePath);
  4701. segmentCount = 0;
  4702. }
  4703. }
  4704. return shapes;
  4705. };
  4706. function PuckerAndBloatModifier() {}
  4707. extendPrototype([ShapeModifier], PuckerAndBloatModifier);
  4708. PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) {
  4709. this.getValue = this.processKeys;
  4710. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  4711. this._isAnimated = !!this.amount.effectsSequence.length;
  4712. };
  4713. PuckerAndBloatModifier.prototype.processPath = function (path, amount) {
  4714. var percent = amount / 100;
  4715. var centerPoint = [0, 0];
  4716. var pathLength = path._length;
  4717. var i = 0;
  4718. for (i = 0; i < pathLength; i += 1) {
  4719. centerPoint[0] += path.v[i][0];
  4720. centerPoint[1] += path.v[i][1];
  4721. }
  4722. centerPoint[0] /= pathLength;
  4723. centerPoint[1] /= pathLength;
  4724. var clonedPath = shapePool.newElement();
  4725. clonedPath.c = path.c;
  4726. var vX;
  4727. var vY;
  4728. var oX;
  4729. var oY;
  4730. var iX;
  4731. var iY;
  4732. for (i = 0; i < pathLength; i += 1) {
  4733. vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
  4734. vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
  4735. oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
  4736. oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
  4737. iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
  4738. iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
  4739. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i);
  4740. }
  4741. return clonedPath;
  4742. };
  4743. PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) {
  4744. var shapePaths;
  4745. var i;
  4746. var len = this.shapes.length;
  4747. var j;
  4748. var jLen;
  4749. var amount = this.amount.v;
  4750. if (amount !== 0) {
  4751. var shapeData;
  4752. var localShapeCollection;
  4753. for (i = 0; i < len; i += 1) {
  4754. shapeData = this.shapes[i];
  4755. localShapeCollection = shapeData.localShapeCollection;
  4756. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  4757. localShapeCollection.releaseShapes();
  4758. shapeData.shape._mdf = true;
  4759. shapePaths = shapeData.shape.paths.shapes;
  4760. jLen = shapeData.shape.paths._length;
  4761. for (j = 0; j < jLen; j += 1) {
  4762. localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
  4763. }
  4764. }
  4765. shapeData.shape.paths = shapeData.localShapeCollection;
  4766. }
  4767. }
  4768. if (!this.dynamicProperties.length) {
  4769. this._mdf = false;
  4770. }
  4771. };
  4772. const TransformPropertyFactory = (function () {
  4773. var defaultVector = [0, 0];
  4774. function applyToMatrix(mat) {
  4775. var _mdf = this._mdf;
  4776. this.iterateDynamicProperties();
  4777. this._mdf = this._mdf || _mdf;
  4778. if (this.a) {
  4779. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4780. }
  4781. if (this.s) {
  4782. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4783. }
  4784. if (this.sk) {
  4785. mat.skewFromAxis(-this.sk.v, this.sa.v);
  4786. }
  4787. if (this.r) {
  4788. mat.rotate(-this.r.v);
  4789. } else {
  4790. mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4791. .rotateY(this.or.v[1])
  4792. .rotateX(this.or.v[0]);
  4793. }
  4794. if (this.data.p.s) {
  4795. if (this.data.p.z) {
  4796. mat.translate(this.px.v, this.py.v, -this.pz.v);
  4797. } else {
  4798. mat.translate(this.px.v, this.py.v, 0);
  4799. }
  4800. } else {
  4801. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4802. }
  4803. }
  4804. function processKeys(forceRender) {
  4805. if (this.elem.globalData.frameId === this.frameId) {
  4806. return;
  4807. }
  4808. if (this._isDirty) {
  4809. this.precalculateMatrix();
  4810. this._isDirty = false;
  4811. }
  4812. this.iterateDynamicProperties();
  4813. if (this._mdf || forceRender) {
  4814. var frameRate;
  4815. this.v.cloneFromProps(this.pre.props);
  4816. if (this.appliedTransformations < 1) {
  4817. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4818. }
  4819. if (this.appliedTransformations < 2) {
  4820. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4821. }
  4822. if (this.sk && this.appliedTransformations < 3) {
  4823. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  4824. }
  4825. if (this.r && this.appliedTransformations < 4) {
  4826. this.v.rotate(-this.r.v);
  4827. } else if (!this.r && this.appliedTransformations < 4) {
  4828. this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4829. .rotateY(this.or.v[1])
  4830. .rotateX(this.or.v[0]);
  4831. }
  4832. if (this.autoOriented) {
  4833. var v1;
  4834. var v2;
  4835. frameRate = this.elem.globalData.frameRate;
  4836. if (this.p && this.p.keyframes && this.p.getValueAtTime) {
  4837. if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) {
  4838. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0);
  4839. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  4840. } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  4841. v1 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t / frameRate), 0);
  4842. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0);
  4843. } else {
  4844. v1 = this.p.pv;
  4845. v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  4846. }
  4847. } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  4848. v1 = [];
  4849. v2 = [];
  4850. var px = this.px;
  4851. var py = this.py;
  4852. if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) {
  4853. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0);
  4854. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0);
  4855. v2[0] = px.getValueAtTime((px.keyframes[0].t) / frameRate, 0);
  4856. v2[1] = py.getValueAtTime((py.keyframes[0].t) / frameRate, 0);
  4857. } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  4858. v1[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t / frameRate), 0);
  4859. v1[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t / frameRate), 0);
  4860. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4861. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4862. } else {
  4863. v1 = [px.pv, py.pv];
  4864. v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime);
  4865. v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime);
  4866. }
  4867. } else {
  4868. v2 = defaultVector;
  4869. v1 = v2;
  4870. }
  4871. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  4872. }
  4873. if (this.data.p && this.data.p.s) {
  4874. if (this.data.p.z) {
  4875. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  4876. } else {
  4877. this.v.translate(this.px.v, this.py.v, 0);
  4878. }
  4879. } else {
  4880. this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4881. }
  4882. }
  4883. this.frameId = this.elem.globalData.frameId;
  4884. }
  4885. function precalculateMatrix() {
  4886. if (!this.a.k) {
  4887. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4888. this.appliedTransformations = 1;
  4889. } else {
  4890. return;
  4891. }
  4892. if (!this.s.effectsSequence.length) {
  4893. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4894. this.appliedTransformations = 2;
  4895. } else {
  4896. return;
  4897. }
  4898. if (this.sk) {
  4899. if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  4900. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  4901. this.appliedTransformations = 3;
  4902. } else {
  4903. return;
  4904. }
  4905. }
  4906. if (this.r) {
  4907. if (!this.r.effectsSequence.length) {
  4908. this.pre.rotate(-this.r.v);
  4909. this.appliedTransformations = 4;
  4910. }
  4911. } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  4912. this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4913. .rotateY(this.or.v[1])
  4914. .rotateX(this.or.v[0]);
  4915. this.appliedTransformations = 4;
  4916. }
  4917. }
  4918. function autoOrient() {
  4919. //
  4920. // var prevP = this.getValueAtTime();
  4921. }
  4922. function addDynamicProperty(prop) {
  4923. this._addDynamicProperty(prop);
  4924. this.elem.addDynamicProperty(prop);
  4925. this._isDirty = true;
  4926. }
  4927. function TransformProperty(elem, data, container) {
  4928. this.elem = elem;
  4929. this.frameId = -1;
  4930. this.propType = 'transform';
  4931. this.data = data;
  4932. this.v = new Matrix();
  4933. // Precalculated matrix with non animated properties
  4934. this.pre = new Matrix();
  4935. this.appliedTransformations = 0;
  4936. this.initDynamicPropertyContainer(container || elem);
  4937. if (data.p && data.p.s) {
  4938. this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this);
  4939. this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this);
  4940. if (data.p.z) {
  4941. this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this);
  4942. }
  4943. } else {
  4944. this.p = PropertyFactory.getProp(elem, data.p || { k: [0, 0, 0] }, 1, 0, this);
  4945. }
  4946. if (data.rx) {
  4947. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  4948. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  4949. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  4950. if (data.or.k[0].ti) {
  4951. var i;
  4952. var len = data.or.k.length;
  4953. for (i = 0; i < len; i += 1) {
  4954. data.or.k[i].to = null;
  4955. data.or.k[i].ti = null;
  4956. }
  4957. }
  4958. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
  4959. // sh Indicates it needs to be capped between -180 and 180
  4960. this.or.sh = true;
  4961. } else {
  4962. this.r = PropertyFactory.getProp(elem, data.r || { k: 0 }, 0, degToRads, this);
  4963. }
  4964. if (data.sk) {
  4965. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  4966. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  4967. }
  4968. this.a = PropertyFactory.getProp(elem, data.a || { k: [0, 0, 0] }, 1, 0, this);
  4969. this.s = PropertyFactory.getProp(elem, data.s || { k: [100, 100, 100] }, 1, 0.01, this);
  4970. // 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.
  4971. if (data.o) {
  4972. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem);
  4973. } else {
  4974. this.o = { _mdf: false, v: 1 };
  4975. }
  4976. this._isDirty = true;
  4977. if (!this.dynamicProperties.length) {
  4978. this.getValue(true);
  4979. }
  4980. }
  4981. TransformProperty.prototype = {
  4982. applyToMatrix: applyToMatrix,
  4983. getValue: processKeys,
  4984. precalculateMatrix: precalculateMatrix,
  4985. autoOrient: autoOrient,
  4986. };
  4987. extendPrototype([DynamicPropertyContainer], TransformProperty);
  4988. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  4989. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  4990. function getTransformProperty(elem, data, container) {
  4991. return new TransformProperty(elem, data, container);
  4992. }
  4993. return {
  4994. getTransformProperty: getTransformProperty,
  4995. };
  4996. }());
  4997. function RepeaterModifier() {}
  4998. extendPrototype([ShapeModifier], RepeaterModifier);
  4999. RepeaterModifier.prototype.initModifierProperties = function (elem, data) {
  5000. this.getValue = this.processKeys;
  5001. this.c = PropertyFactory.getProp(elem, data.c, 0, null, this);
  5002. this.o = PropertyFactory.getProp(elem, data.o, 0, null, this);
  5003. this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this);
  5004. this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this);
  5005. this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this);
  5006. this.data = data;
  5007. if (!this.dynamicProperties.length) {
  5008. this.getValue(true);
  5009. }
  5010. this._isAnimated = !!this.dynamicProperties.length;
  5011. this.pMatrix = new Matrix();
  5012. this.rMatrix = new Matrix();
  5013. this.sMatrix = new Matrix();
  5014. this.tMatrix = new Matrix();
  5015. this.matrix = new Matrix();
  5016. };
  5017. RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) {
  5018. var dir = inv ? -1 : 1;
  5019. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  5020. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  5021. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  5022. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5023. rMatrix.rotate(-transform.r.v * dir * perc);
  5024. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5025. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5026. sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY);
  5027. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5028. };
  5029. RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) {
  5030. this.elem = elem;
  5031. this.arr = arr;
  5032. this.pos = pos;
  5033. this.elemsData = elemsData;
  5034. this._currentCopies = 0;
  5035. this._elements = [];
  5036. this._groups = [];
  5037. this.frameId = -1;
  5038. this.initDynamicPropertyContainer(elem);
  5039. this.initModifierProperties(elem, arr[pos]);
  5040. while (pos > 0) {
  5041. pos -= 1;
  5042. // this._elements.unshift(arr.splice(pos,1)[0]);
  5043. this._elements.unshift(arr[pos]);
  5044. }
  5045. if (this.dynamicProperties.length) {
  5046. this.k = true;
  5047. } else {
  5048. this.getValue(true);
  5049. }
  5050. };
  5051. RepeaterModifier.prototype.resetElements = function (elements) {
  5052. var i;
  5053. var len = elements.length;
  5054. for (i = 0; i < len; i += 1) {
  5055. elements[i]._processed = false;
  5056. if (elements[i].ty === 'gr') {
  5057. this.resetElements(elements[i].it);
  5058. }
  5059. }
  5060. };
  5061. RepeaterModifier.prototype.cloneElements = function (elements) {
  5062. var newElements = JSON.parse(JSON.stringify(elements));
  5063. this.resetElements(newElements);
  5064. return newElements;
  5065. };
  5066. RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) {
  5067. var i;
  5068. var len = elements.length;
  5069. for (i = 0; i < len; i += 1) {
  5070. elements[i]._render = renderFlag;
  5071. if (elements[i].ty === 'gr') {
  5072. this.changeGroupRender(elements[i].it, renderFlag);
  5073. }
  5074. }
  5075. };
  5076. RepeaterModifier.prototype.processShapes = function (_isFirstFrame) {
  5077. var items;
  5078. var itemsTransform;
  5079. var i;
  5080. var dir;
  5081. var cont;
  5082. var hasReloaded = false;
  5083. if (this._mdf || _isFirstFrame) {
  5084. var copies = Math.ceil(this.c.v);
  5085. if (this._groups.length < copies) {
  5086. while (this._groups.length < copies) {
  5087. var group = {
  5088. it: this.cloneElements(this._elements),
  5089. ty: 'gr',
  5090. };
  5091. group.it.push({
  5092. a: { a: 0, ix: 1, k: [0, 0] }, nm: 'Transform', o: { a: 0, ix: 7, k: 100 }, p: { a: 0, ix: 2, k: [0, 0] }, r: { a: 1, ix: 6, k: [{ s: 0, e: 0, t: 0 }, { s: 0, e: 0, t: 1 }] }, s: { a: 0, ix: 3, k: [100, 100] }, sa: { a: 0, ix: 5, k: 0 }, sk: { a: 0, ix: 4, k: 0 }, ty: 'tr',
  5093. });
  5094. this.arr.splice(0, 0, group);
  5095. this._groups.splice(0, 0, group);
  5096. this._currentCopies += 1;
  5097. }
  5098. this.elem.reloadShapes();
  5099. hasReloaded = true;
  5100. }
  5101. cont = 0;
  5102. var renderFlag;
  5103. for (i = 0; i <= this._groups.length - 1; i += 1) {
  5104. renderFlag = cont < copies;
  5105. this._groups[i]._render = renderFlag;
  5106. this.changeGroupRender(this._groups[i].it, renderFlag);
  5107. if (!renderFlag) {
  5108. var elems = this.elemsData[i].it;
  5109. var transformData = elems[elems.length - 1];
  5110. if (transformData.transform.op.v !== 0) {
  5111. transformData.transform.op._mdf = true;
  5112. transformData.transform.op.v = 0;
  5113. } else {
  5114. transformData.transform.op._mdf = false;
  5115. }
  5116. }
  5117. cont += 1;
  5118. }
  5119. this._currentCopies = copies;
  5120. /// /
  5121. var offset = this.o.v;
  5122. var offsetModulo = offset % 1;
  5123. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  5124. var pProps = this.pMatrix.props;
  5125. var rProps = this.rMatrix.props;
  5126. var sProps = this.sMatrix.props;
  5127. this.pMatrix.reset();
  5128. this.rMatrix.reset();
  5129. this.sMatrix.reset();
  5130. this.tMatrix.reset();
  5131. this.matrix.reset();
  5132. var iteration = 0;
  5133. if (offset > 0) {
  5134. while (iteration < roundOffset) {
  5135. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5136. iteration += 1;
  5137. }
  5138. if (offsetModulo) {
  5139. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  5140. iteration += offsetModulo;
  5141. }
  5142. } else if (offset < 0) {
  5143. while (iteration > roundOffset) {
  5144. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  5145. iteration -= 1;
  5146. }
  5147. if (offsetModulo) {
  5148. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true);
  5149. iteration -= offsetModulo;
  5150. }
  5151. }
  5152. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  5153. dir = this.data.m === 1 ? 1 : -1;
  5154. cont = this._currentCopies;
  5155. var j;
  5156. var jLen;
  5157. while (cont) {
  5158. items = this.elemsData[i].it;
  5159. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5160. jLen = itemsTransform.length;
  5161. items[items.length - 1].transform.mProps._mdf = true;
  5162. items[items.length - 1].transform.op._mdf = true;
  5163. items[items.length - 1].transform.op.v = this._currentCopies === 1
  5164. ? this.so.v
  5165. : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  5166. if (iteration !== 0) {
  5167. if ((i !== 0 && dir === 1) || (i !== this._currentCopies - 1 && dir === -1)) {
  5168. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5169. }
  5170. 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]);
  5171. 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]);
  5172. 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]);
  5173. for (j = 0; j < jLen; j += 1) {
  5174. itemsTransform[j] = this.matrix.props[j];
  5175. }
  5176. this.matrix.reset();
  5177. } else {
  5178. this.matrix.reset();
  5179. for (j = 0; j < jLen; j += 1) {
  5180. itemsTransform[j] = this.matrix.props[j];
  5181. }
  5182. }
  5183. iteration += 1;
  5184. cont -= 1;
  5185. i += dir;
  5186. }
  5187. } else {
  5188. cont = this._currentCopies;
  5189. i = 0;
  5190. dir = 1;
  5191. while (cont) {
  5192. items = this.elemsData[i].it;
  5193. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5194. items[items.length - 1].transform.mProps._mdf = false;
  5195. items[items.length - 1].transform.op._mdf = false;
  5196. cont -= 1;
  5197. i += dir;
  5198. }
  5199. }
  5200. return hasReloaded;
  5201. };
  5202. RepeaterModifier.prototype.addShape = function () {};
  5203. function RoundCornersModifier() {}
  5204. extendPrototype([ShapeModifier], RoundCornersModifier);
  5205. RoundCornersModifier.prototype.initModifierProperties = function (elem, data) {
  5206. this.getValue = this.processKeys;
  5207. this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5208. this._isAnimated = !!this.rd.effectsSequence.length;
  5209. };
  5210. RoundCornersModifier.prototype.processPath = function (path, round) {
  5211. var clonedPath = shapePool.newElement();
  5212. clonedPath.c = path.c;
  5213. var i;
  5214. var len = path._length;
  5215. var currentV;
  5216. var currentI;
  5217. var currentO;
  5218. var closerV;
  5219. var distance;
  5220. var newPosPerc;
  5221. var index = 0;
  5222. var vX;
  5223. var vY;
  5224. var oX;
  5225. var oY;
  5226. var iX;
  5227. var iY;
  5228. for (i = 0; i < len; i += 1) {
  5229. currentV = path.v[i];
  5230. currentO = path.o[i];
  5231. currentI = path.i[i];
  5232. if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) {
  5233. if ((i === 0 || i === len - 1) && !path.c) {
  5234. clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index);
  5235. /* clonedPath.v[index] = currentV;
  5236. clonedPath.o[index] = currentO;
  5237. clonedPath.i[index] = currentI; */
  5238. index += 1;
  5239. } else {
  5240. if (i === 0) {
  5241. closerV = path.v[len - 1];
  5242. } else {
  5243. closerV = path.v[i - 1];
  5244. }
  5245. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5246. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5247. iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5248. vX = iX;
  5249. iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc;
  5250. vY = iY;
  5251. oX = vX - (vX - currentV[0]) * roundCorner;
  5252. oY = vY - (vY - currentV[1]) * roundCorner;
  5253. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5254. index += 1;
  5255. if (i === len - 1) {
  5256. closerV = path.v[0];
  5257. } else {
  5258. closerV = path.v[i + 1];
  5259. }
  5260. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5261. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5262. oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5263. vX = oX;
  5264. oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc;
  5265. vY = oY;
  5266. iX = vX - (vX - currentV[0]) * roundCorner;
  5267. iY = vY - (vY - currentV[1]) * roundCorner;
  5268. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5269. index += 1;
  5270. }
  5271. } else {
  5272. 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);
  5273. index += 1;
  5274. }
  5275. }
  5276. return clonedPath;
  5277. };
  5278. RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) {
  5279. var shapePaths;
  5280. var i;
  5281. var len = this.shapes.length;
  5282. var j;
  5283. var jLen;
  5284. var rd = this.rd.v;
  5285. if (rd !== 0) {
  5286. var shapeData;
  5287. var localShapeCollection;
  5288. for (i = 0; i < len; i += 1) {
  5289. shapeData = this.shapes[i];
  5290. localShapeCollection = shapeData.localShapeCollection;
  5291. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5292. localShapeCollection.releaseShapes();
  5293. shapeData.shape._mdf = true;
  5294. shapePaths = shapeData.shape.paths.shapes;
  5295. jLen = shapeData.shape.paths._length;
  5296. for (j = 0; j < jLen; j += 1) {
  5297. localShapeCollection.addShape(this.processPath(shapePaths[j], rd));
  5298. }
  5299. }
  5300. shapeData.shape.paths = shapeData.localShapeCollection;
  5301. }
  5302. }
  5303. if (!this.dynamicProperties.length) {
  5304. this._mdf = false;
  5305. }
  5306. };
  5307. function getFontProperties(fontData) {
  5308. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  5309. var fWeight = 'normal'; var
  5310. fStyle = 'normal';
  5311. var len = styles.length;
  5312. var styleName;
  5313. for (var i = 0; i < len; i += 1) {
  5314. styleName = styles[i].toLowerCase();
  5315. switch (styleName) {
  5316. case 'italic':
  5317. fStyle = 'italic';
  5318. break;
  5319. case 'bold':
  5320. fWeight = '700';
  5321. break;
  5322. case 'black':
  5323. fWeight = '900';
  5324. break;
  5325. case 'medium':
  5326. fWeight = '500';
  5327. break;
  5328. case 'regular':
  5329. case 'normal':
  5330. fWeight = '400';
  5331. break;
  5332. case 'light':
  5333. case 'thin':
  5334. fWeight = '200';
  5335. break;
  5336. default:
  5337. break;
  5338. }
  5339. }
  5340. return {
  5341. style: fStyle,
  5342. weight: fontData.fWeight || fWeight,
  5343. };
  5344. }
  5345. const FontManager = (function () {
  5346. var maxWaitingTime = 5000;
  5347. var emptyChar = {
  5348. w: 0,
  5349. size: 0,
  5350. shapes: [],
  5351. data: {
  5352. shapes: [],
  5353. },
  5354. };
  5355. var combinedCharacters = [];
  5356. // Hindi characters
  5357. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366,
  5358. 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379,
  5359. 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  5360. var surrogateModifiers = [
  5361. 'd83cdffb',
  5362. 'd83cdffc',
  5363. 'd83cdffd',
  5364. 'd83cdffe',
  5365. 'd83cdfff',
  5366. ];
  5367. var zeroWidthJoiner = [65039, 8205];
  5368. function trimFontOptions(font) {
  5369. var familyArray = font.split(',');
  5370. var i;
  5371. var len = familyArray.length;
  5372. var enabledFamilies = [];
  5373. for (i = 0; i < len; i += 1) {
  5374. if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
  5375. enabledFamilies.push(familyArray[i]);
  5376. }
  5377. }
  5378. return enabledFamilies.join(',');
  5379. }
  5380. function setUpNode(font, family) {
  5381. var parentNode = createTag('span');
  5382. // Node is invisible to screen readers.
  5383. parentNode.setAttribute('aria-hidden', true);
  5384. parentNode.style.fontFamily = family;
  5385. var node = createTag('span');
  5386. // Characters that vary significantly among different fonts
  5387. node.innerText = 'giItT1WQy@!-/#';
  5388. // Visible - so we can measure it - but not on the screen
  5389. parentNode.style.position = 'absolute';
  5390. parentNode.style.left = '-10000px';
  5391. parentNode.style.top = '-10000px';
  5392. // Large font size makes even subtle changes obvious
  5393. parentNode.style.fontSize = '300px';
  5394. // Reset any font properties
  5395. parentNode.style.fontVariant = 'normal';
  5396. parentNode.style.fontStyle = 'normal';
  5397. parentNode.style.fontWeight = 'normal';
  5398. parentNode.style.letterSpacing = '0';
  5399. parentNode.appendChild(node);
  5400. document.body.appendChild(parentNode);
  5401. // Remember width with no applied web font
  5402. var width = node.offsetWidth;
  5403. node.style.fontFamily = trimFontOptions(font) + ', ' + family;
  5404. return { node: node, w: width, parent: parentNode };
  5405. }
  5406. function checkLoadedFonts() {
  5407. var i;
  5408. var len = this.fonts.length;
  5409. var node;
  5410. var w;
  5411. var loadedCount = len;
  5412. for (i = 0; i < len; i += 1) {
  5413. if (this.fonts[i].loaded) {
  5414. loadedCount -= 1;
  5415. } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) {
  5416. this.fonts[i].loaded = true;
  5417. } else {
  5418. node = this.fonts[i].monoCase.node;
  5419. w = this.fonts[i].monoCase.w;
  5420. if (node.offsetWidth !== w) {
  5421. loadedCount -= 1;
  5422. this.fonts[i].loaded = true;
  5423. } else {
  5424. node = this.fonts[i].sansCase.node;
  5425. w = this.fonts[i].sansCase.w;
  5426. if (node.offsetWidth !== w) {
  5427. loadedCount -= 1;
  5428. this.fonts[i].loaded = true;
  5429. }
  5430. }
  5431. if (this.fonts[i].loaded) {
  5432. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  5433. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  5434. }
  5435. }
  5436. }
  5437. if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) {
  5438. setTimeout(this.checkLoadedFontsBinded, 20);
  5439. } else {
  5440. setTimeout(this.setIsLoadedBinded, 10);
  5441. }
  5442. }
  5443. function createHelper(fontData, def) {
  5444. var engine = (document.body && def) ? 'svg' : 'canvas';
  5445. var helper;
  5446. var fontProps = getFontProperties(fontData);
  5447. if (engine === 'svg') {
  5448. var tHelper = createNS('text');
  5449. tHelper.style.fontSize = '100px';
  5450. // tHelper.style.fontFamily = fontData.fFamily;
  5451. tHelper.setAttribute('font-family', fontData.fFamily);
  5452. tHelper.setAttribute('font-style', fontProps.style);
  5453. tHelper.setAttribute('font-weight', fontProps.weight);
  5454. tHelper.textContent = '1';
  5455. if (fontData.fClass) {
  5456. tHelper.style.fontFamily = 'inherit';
  5457. tHelper.setAttribute('class', fontData.fClass);
  5458. } else {
  5459. tHelper.style.fontFamily = fontData.fFamily;
  5460. }
  5461. def.appendChild(tHelper);
  5462. helper = tHelper;
  5463. } else {
  5464. var tCanvasHelper = new OffscreenCanvas(500, 500).getContext('2d');
  5465. tCanvasHelper.font = fontProps.style + ' ' + fontProps.weight + ' 100px ' + fontData.fFamily;
  5466. helper = tCanvasHelper;
  5467. }
  5468. function measure(text) {
  5469. if (engine === 'svg') {
  5470. helper.textContent = text;
  5471. return helper.getComputedTextLength();
  5472. }
  5473. return helper.measureText(text).width;
  5474. }
  5475. return {
  5476. measureText: measure,
  5477. };
  5478. }
  5479. function addFonts(fontData, defs) {
  5480. if (!fontData) {
  5481. this.isLoaded = true;
  5482. return;
  5483. }
  5484. if (this.chars) {
  5485. this.isLoaded = true;
  5486. this.fonts = fontData.list;
  5487. return;
  5488. }
  5489. if (!document.body) {
  5490. this.isLoaded = true;
  5491. fontData.list.forEach((data) => {
  5492. data.helper = createHelper(data);
  5493. data.cache = {};
  5494. });
  5495. this.fonts = fontData.list;
  5496. return;
  5497. }
  5498. var fontArr = fontData.list;
  5499. var i;
  5500. var len = fontArr.length;
  5501. var _pendingFonts = len;
  5502. for (i = 0; i < len; i += 1) {
  5503. var shouldLoadFont = true;
  5504. var loadedSelector;
  5505. var j;
  5506. fontArr[i].loaded = false;
  5507. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace');
  5508. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif');
  5509. if (!fontArr[i].fPath) {
  5510. fontArr[i].loaded = true;
  5511. _pendingFonts -= 1;
  5512. } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) {
  5513. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]');
  5514. if (loadedSelector.length > 0) {
  5515. shouldLoadFont = false;
  5516. }
  5517. if (shouldLoadFont) {
  5518. var s = createTag('style');
  5519. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  5520. s.setAttribute('f-origin', fontArr[i].origin);
  5521. s.setAttribute('f-family', fontArr[i].fFamily);
  5522. s.type = 'text/css';
  5523. s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}";
  5524. defs.appendChild(s);
  5525. }
  5526. } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) {
  5527. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  5528. for (j = 0; j < loadedSelector.length; j += 1) {
  5529. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  5530. // Font is already loaded
  5531. shouldLoadFont = false;
  5532. }
  5533. }
  5534. if (shouldLoadFont) {
  5535. var l = createTag('link');
  5536. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  5537. l.setAttribute('f-origin', fontArr[i].origin);
  5538. l.type = 'text/css';
  5539. l.rel = 'stylesheet';
  5540. l.href = fontArr[i].fPath;
  5541. document.body.appendChild(l);
  5542. }
  5543. } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) {
  5544. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  5545. for (j = 0; j < loadedSelector.length; j += 1) {
  5546. if (fontArr[i].fPath === loadedSelector[j].src) {
  5547. // Font is already loaded
  5548. shouldLoadFont = false;
  5549. }
  5550. }
  5551. if (shouldLoadFont) {
  5552. var sc = createTag('link');
  5553. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  5554. sc.setAttribute('f-origin', fontArr[i].origin);
  5555. sc.setAttribute('rel', 'stylesheet');
  5556. sc.setAttribute('href', fontArr[i].fPath);
  5557. defs.appendChild(sc);
  5558. }
  5559. }
  5560. fontArr[i].helper = createHelper(fontArr[i], defs);
  5561. fontArr[i].cache = {};
  5562. this.fonts.push(fontArr[i]);
  5563. }
  5564. if (_pendingFonts === 0) {
  5565. this.isLoaded = true;
  5566. } else {
  5567. // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  5568. // Adding this timeout seems to fix it
  5569. setTimeout(this.checkLoadedFonts.bind(this), 100);
  5570. }
  5571. }
  5572. function addChars(chars) {
  5573. if (!chars) {
  5574. return;
  5575. }
  5576. if (!this.chars) {
  5577. this.chars = [];
  5578. }
  5579. var i;
  5580. var len = chars.length;
  5581. var j;
  5582. var jLen = this.chars.length;
  5583. var found;
  5584. for (i = 0; i < len; i += 1) {
  5585. j = 0;
  5586. found = false;
  5587. while (j < jLen) {
  5588. if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) {
  5589. found = true;
  5590. }
  5591. j += 1;
  5592. }
  5593. if (!found) {
  5594. this.chars.push(chars[i]);
  5595. jLen += 1;
  5596. }
  5597. }
  5598. }
  5599. function getCharData(char, style, font) {
  5600. var i = 0;
  5601. var len = this.chars.length;
  5602. while (i < len) {
  5603. if (this.chars[i].ch === char && this.chars[i].style === style && this.chars[i].fFamily === font) {
  5604. return this.chars[i];
  5605. }
  5606. i += 1;
  5607. }
  5608. if (((typeof char === 'string' && char.charCodeAt(0) !== 13) || !char)
  5609. && console
  5610. && console.warn // eslint-disable-line no-console
  5611. && !this._warned
  5612. ) {
  5613. this._warned = true;
  5614. console.warn('Missing character from exported characters list: ', char, style, font); // eslint-disable-line no-console
  5615. }
  5616. return emptyChar;
  5617. }
  5618. function measureText(char, fontName, size) {
  5619. var fontData = this.getFontByName(fontName);
  5620. var index = char.charCodeAt(0);
  5621. if (!fontData.cache[index + 1]) {
  5622. var tHelper = fontData.helper;
  5623. if (char === ' ') {
  5624. var doubleSize = tHelper.measureText('|' + char + '|');
  5625. var singleSize = tHelper.measureText('||');
  5626. fontData.cache[index + 1] = (doubleSize - singleSize) / 100;
  5627. } else {
  5628. fontData.cache[index + 1] = tHelper.measureText(char) / 100;
  5629. }
  5630. }
  5631. return fontData.cache[index + 1] * size;
  5632. }
  5633. function getFontByName(name) {
  5634. var i = 0;
  5635. var len = this.fonts.length;
  5636. while (i < len) {
  5637. if (this.fonts[i].fName === name) {
  5638. return this.fonts[i];
  5639. }
  5640. i += 1;
  5641. }
  5642. return this.fonts[0];
  5643. }
  5644. function isModifier(firstCharCode, secondCharCode) {
  5645. var sum = firstCharCode.toString(16) + secondCharCode.toString(16);
  5646. return surrogateModifiers.indexOf(sum) !== -1;
  5647. }
  5648. function isZeroWidthJoiner(firstCharCode, secondCharCode) {
  5649. if (!secondCharCode) {
  5650. return firstCharCode === zeroWidthJoiner[1];
  5651. }
  5652. return firstCharCode === zeroWidthJoiner[0] && secondCharCode === zeroWidthJoiner[1];
  5653. }
  5654. function isCombinedCharacter(char) {
  5655. return combinedCharacters.indexOf(char) !== -1;
  5656. }
  5657. function setIsLoaded() {
  5658. this.isLoaded = true;
  5659. }
  5660. var Font = function () {
  5661. this.fonts = [];
  5662. this.chars = null;
  5663. this.typekitLoaded = 0;
  5664. this.isLoaded = false;
  5665. this._warned = false;
  5666. this.initTime = Date.now();
  5667. this.setIsLoadedBinded = this.setIsLoaded.bind(this);
  5668. this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this);
  5669. };
  5670. Font.isModifier = isModifier;
  5671. Font.isZeroWidthJoiner = isZeroWidthJoiner;
  5672. Font.isCombinedCharacter = isCombinedCharacter;
  5673. var fontPrototype = {
  5674. addChars: addChars,
  5675. addFonts: addFonts,
  5676. getCharData: getCharData,
  5677. getFontByName: getFontByName,
  5678. measureText: measureText,
  5679. checkLoadedFonts: checkLoadedFonts,
  5680. setIsLoaded: setIsLoaded,
  5681. };
  5682. Font.prototype = fontPrototype;
  5683. return Font;
  5684. }());
  5685. function RenderableElement() {
  5686. }
  5687. RenderableElement.prototype = {
  5688. initRenderable: function () {
  5689. // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  5690. this.isInRange = false;
  5691. // layer's display state
  5692. this.hidden = false;
  5693. // If layer's transparency equals 0, it can be hidden
  5694. this.isTransparent = false;
  5695. // list of animated components
  5696. this.renderableComponents = [];
  5697. },
  5698. addRenderableComponent: function (component) {
  5699. if (this.renderableComponents.indexOf(component) === -1) {
  5700. this.renderableComponents.push(component);
  5701. }
  5702. },
  5703. removeRenderableComponent: function (component) {
  5704. if (this.renderableComponents.indexOf(component) !== -1) {
  5705. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  5706. }
  5707. },
  5708. prepareRenderableFrame: function (num) {
  5709. this.checkLayerLimits(num);
  5710. },
  5711. checkTransparency: function () {
  5712. if (this.finalTransform.mProp.o.v <= 0) {
  5713. if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
  5714. this.isTransparent = true;
  5715. this.hide();
  5716. }
  5717. } else if (this.isTransparent) {
  5718. this.isTransparent = false;
  5719. this.show();
  5720. }
  5721. },
  5722. /**
  5723. * @function
  5724. * Initializes frame related properties.
  5725. *
  5726. * @param {number} num
  5727. * current frame number in Layer's time
  5728. *
  5729. */
  5730. checkLayerLimits: function (num) {
  5731. if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
  5732. if (this.isInRange !== true) {
  5733. this.globalData._mdf = true;
  5734. this._mdf = true;
  5735. this.isInRange = true;
  5736. this.show();
  5737. }
  5738. } else if (this.isInRange !== false) {
  5739. this.globalData._mdf = true;
  5740. this.isInRange = false;
  5741. this.hide();
  5742. }
  5743. },
  5744. renderRenderable: function () {
  5745. var i;
  5746. var len = this.renderableComponents.length;
  5747. for (i = 0; i < len; i += 1) {
  5748. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  5749. }
  5750. /* this.maskManager.renderFrame(this.finalTransform.mat);
  5751. this.renderableEffectsManager.renderFrame(this._isFirstFrame); */
  5752. },
  5753. sourceRectAtTime: function () {
  5754. return {
  5755. top: 0,
  5756. left: 0,
  5757. width: 100,
  5758. height: 100,
  5759. };
  5760. },
  5761. getLayerSize: function () {
  5762. if (this.data.ty === 5) {
  5763. return { w: this.data.textData.width, h: this.data.textData.height };
  5764. }
  5765. return { w: this.data.width, h: this.data.height };
  5766. },
  5767. };
  5768. const MaskManagerInterface = (function () {
  5769. function MaskInterface(mask, data) {
  5770. this._mask = mask;
  5771. this._data = data;
  5772. }
  5773. Object.defineProperty(MaskInterface.prototype, 'maskPath', {
  5774. get: function () {
  5775. if (this._mask.prop.k) {
  5776. this._mask.prop.getValue();
  5777. }
  5778. return this._mask.prop;
  5779. },
  5780. });
  5781. Object.defineProperty(MaskInterface.prototype, 'maskOpacity', {
  5782. get: function () {
  5783. if (this._mask.op.k) {
  5784. this._mask.op.getValue();
  5785. }
  5786. return this._mask.op.v * 100;
  5787. },
  5788. });
  5789. var MaskManager = function (maskManager) {
  5790. var _masksInterfaces = createSizedArray(maskManager.viewData.length);
  5791. var i;
  5792. var len = maskManager.viewData.length;
  5793. for (i = 0; i < len; i += 1) {
  5794. _masksInterfaces[i] = new MaskInterface(maskManager.viewData[i], maskManager.masksProperties[i]);
  5795. }
  5796. var maskFunction = function (name) {
  5797. i = 0;
  5798. while (i < len) {
  5799. if (maskManager.masksProperties[i].nm === name) {
  5800. return _masksInterfaces[i];
  5801. }
  5802. i += 1;
  5803. }
  5804. return null;
  5805. };
  5806. return maskFunction;
  5807. };
  5808. return MaskManager;
  5809. }());
  5810. const ExpressionPropertyInterface = (function () {
  5811. var defaultUnidimensionalValue = { pv: 0, v: 0, mult: 1 };
  5812. var defaultMultidimensionalValue = { pv: [0, 0, 0], v: [0, 0, 0], mult: 1 };
  5813. function completeProperty(expressionValue, property, type) {
  5814. Object.defineProperty(expressionValue, 'velocity', {
  5815. get: function () {
  5816. return property.getVelocityAtTime(property.comp.currentFrame);
  5817. },
  5818. });
  5819. expressionValue.numKeys = property.keyframes ? property.keyframes.length : 0;
  5820. expressionValue.key = function (pos) {
  5821. if (!expressionValue.numKeys) {
  5822. return 0;
  5823. }
  5824. var value = '';
  5825. if ('s' in property.keyframes[pos - 1]) {
  5826. value = property.keyframes[pos - 1].s;
  5827. } else if ('e' in property.keyframes[pos - 2]) {
  5828. value = property.keyframes[pos - 2].e;
  5829. } else {
  5830. value = property.keyframes[pos - 2].s;
  5831. }
  5832. var valueProp = type === 'unidimensional' ? new Number(value) : Object.assign({}, value); // eslint-disable-line no-new-wrappers
  5833. valueProp.time = property.keyframes[pos - 1].t / property.elem.comp.globalData.frameRate;
  5834. valueProp.value = type === 'unidimensional' ? value[0] : value;
  5835. return valueProp;
  5836. };
  5837. expressionValue.valueAtTime = property.getValueAtTime;
  5838. expressionValue.speedAtTime = property.getSpeedAtTime;
  5839. expressionValue.velocityAtTime = property.getVelocityAtTime;
  5840. expressionValue.propertyGroup = property.propertyGroup;
  5841. }
  5842. function UnidimensionalPropertyInterface(property) {
  5843. if (!property || !('pv' in property)) {
  5844. property = defaultUnidimensionalValue;
  5845. }
  5846. var mult = 1 / property.mult;
  5847. var val = property.pv * mult;
  5848. var expressionValue = new Number(val); // eslint-disable-line no-new-wrappers
  5849. expressionValue.value = val;
  5850. completeProperty(expressionValue, property, 'unidimensional');
  5851. return function () {
  5852. if (property.k) {
  5853. property.getValue();
  5854. }
  5855. val = property.v * mult;
  5856. if (expressionValue.value !== val) {
  5857. expressionValue = new Number(val); // eslint-disable-line no-new-wrappers
  5858. expressionValue.value = val;
  5859. completeProperty(expressionValue, property, 'unidimensional');
  5860. }
  5861. return expressionValue;
  5862. };
  5863. }
  5864. function MultidimensionalPropertyInterface(property) {
  5865. if (!property || !('pv' in property)) {
  5866. property = defaultMultidimensionalValue;
  5867. }
  5868. var mult = 1 / property.mult;
  5869. var len = (property.data && property.data.l) || property.pv.length;
  5870. var expressionValue = createTypedArray('float32', len);
  5871. var arrValue = createTypedArray('float32', len);
  5872. expressionValue.value = arrValue;
  5873. completeProperty(expressionValue, property, 'multidimensional');
  5874. return function () {
  5875. if (property.k) {
  5876. property.getValue();
  5877. }
  5878. for (var i = 0; i < len; i += 1) {
  5879. arrValue[i] = property.v[i] * mult;
  5880. expressionValue[i] = arrValue[i];
  5881. }
  5882. return expressionValue;
  5883. };
  5884. }
  5885. // TODO: try to avoid using this getter
  5886. function defaultGetter() {
  5887. return defaultUnidimensionalValue;
  5888. }
  5889. return function (property) {
  5890. if (!property) {
  5891. return defaultGetter;
  5892. } if (property.propType === 'unidimensional') {
  5893. return UnidimensionalPropertyInterface(property);
  5894. }
  5895. return MultidimensionalPropertyInterface(property);
  5896. };
  5897. }());
  5898. const TransformExpressionInterface = (function () {
  5899. return function (transform) {
  5900. function _thisFunction(name) {
  5901. switch (name) {
  5902. case 'scale':
  5903. case 'Scale':
  5904. case 'ADBE Scale':
  5905. case 6:
  5906. return _thisFunction.scale;
  5907. case 'rotation':
  5908. case 'Rotation':
  5909. case 'ADBE Rotation':
  5910. case 'ADBE Rotate Z':
  5911. case 10:
  5912. return _thisFunction.rotation;
  5913. case 'ADBE Rotate X':
  5914. return _thisFunction.xRotation;
  5915. case 'ADBE Rotate Y':
  5916. return _thisFunction.yRotation;
  5917. case 'position':
  5918. case 'Position':
  5919. case 'ADBE Position':
  5920. case 2:
  5921. return _thisFunction.position;
  5922. case 'ADBE Position_0':
  5923. return _thisFunction.xPosition;
  5924. case 'ADBE Position_1':
  5925. return _thisFunction.yPosition;
  5926. case 'ADBE Position_2':
  5927. return _thisFunction.zPosition;
  5928. case 'anchorPoint':
  5929. case 'AnchorPoint':
  5930. case 'Anchor Point':
  5931. case 'ADBE AnchorPoint':
  5932. case 1:
  5933. return _thisFunction.anchorPoint;
  5934. case 'opacity':
  5935. case 'Opacity':
  5936. case 11:
  5937. return _thisFunction.opacity;
  5938. default:
  5939. return null;
  5940. }
  5941. }
  5942. Object.defineProperty(_thisFunction, 'rotation', {
  5943. get: ExpressionPropertyInterface(transform.r || transform.rz),
  5944. });
  5945. Object.defineProperty(_thisFunction, 'zRotation', {
  5946. get: ExpressionPropertyInterface(transform.rz || transform.r),
  5947. });
  5948. Object.defineProperty(_thisFunction, 'xRotation', {
  5949. get: ExpressionPropertyInterface(transform.rx),
  5950. });
  5951. Object.defineProperty(_thisFunction, 'yRotation', {
  5952. get: ExpressionPropertyInterface(transform.ry),
  5953. });
  5954. Object.defineProperty(_thisFunction, 'scale', {
  5955. get: ExpressionPropertyInterface(transform.s),
  5956. });
  5957. var _px;
  5958. var _py;
  5959. var _pz;
  5960. var _transformFactory;
  5961. if (transform.p) {
  5962. _transformFactory = ExpressionPropertyInterface(transform.p);
  5963. } else {
  5964. _px = ExpressionPropertyInterface(transform.px);
  5965. _py = ExpressionPropertyInterface(transform.py);
  5966. if (transform.pz) {
  5967. _pz = ExpressionPropertyInterface(transform.pz);
  5968. }
  5969. }
  5970. Object.defineProperty(_thisFunction, 'position', {
  5971. get: function () {
  5972. if (transform.p) {
  5973. return _transformFactory();
  5974. }
  5975. return [
  5976. _px(),
  5977. _py(),
  5978. _pz ? _pz() : 0];
  5979. },
  5980. });
  5981. Object.defineProperty(_thisFunction, 'xPosition', {
  5982. get: ExpressionPropertyInterface(transform.px),
  5983. });
  5984. Object.defineProperty(_thisFunction, 'yPosition', {
  5985. get: ExpressionPropertyInterface(transform.py),
  5986. });
  5987. Object.defineProperty(_thisFunction, 'zPosition', {
  5988. get: ExpressionPropertyInterface(transform.pz),
  5989. });
  5990. Object.defineProperty(_thisFunction, 'anchorPoint', {
  5991. get: ExpressionPropertyInterface(transform.a),
  5992. });
  5993. Object.defineProperty(_thisFunction, 'opacity', {
  5994. get: ExpressionPropertyInterface(transform.o),
  5995. });
  5996. Object.defineProperty(_thisFunction, 'skew', {
  5997. get: ExpressionPropertyInterface(transform.sk),
  5998. });
  5999. Object.defineProperty(_thisFunction, 'skewAxis', {
  6000. get: ExpressionPropertyInterface(transform.sa),
  6001. });
  6002. Object.defineProperty(_thisFunction, 'orientation', {
  6003. get: ExpressionPropertyInterface(transform.or),
  6004. });
  6005. return _thisFunction;
  6006. };
  6007. }());
  6008. const LayerExpressionInterface = (function () {
  6009. function getMatrix(time) {
  6010. var toWorldMat = new Matrix();
  6011. if (time !== undefined) {
  6012. var propMatrix = this._elem.finalTransform.mProp.getValueAtTime(time);
  6013. propMatrix.clone(toWorldMat);
  6014. } else {
  6015. var transformMat = this._elem.finalTransform.mProp;
  6016. transformMat.applyToMatrix(toWorldMat);
  6017. }
  6018. return toWorldMat;
  6019. }
  6020. function toWorldVec(arr, time) {
  6021. var toWorldMat = this.getMatrix(time);
  6022. toWorldMat.props[12] = 0;
  6023. toWorldMat.props[13] = 0;
  6024. toWorldMat.props[14] = 0;
  6025. return this.applyPoint(toWorldMat, arr);
  6026. }
  6027. function toWorld(arr, time) {
  6028. var toWorldMat = this.getMatrix(time);
  6029. return this.applyPoint(toWorldMat, arr);
  6030. }
  6031. function fromWorldVec(arr, time) {
  6032. var toWorldMat = this.getMatrix(time);
  6033. toWorldMat.props[12] = 0;
  6034. toWorldMat.props[13] = 0;
  6035. toWorldMat.props[14] = 0;
  6036. return this.invertPoint(toWorldMat, arr);
  6037. }
  6038. function fromWorld(arr, time) {
  6039. var toWorldMat = this.getMatrix(time);
  6040. return this.invertPoint(toWorldMat, arr);
  6041. }
  6042. function applyPoint(matrix, arr) {
  6043. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  6044. var i;
  6045. var len = this._elem.hierarchy.length;
  6046. for (i = 0; i < len; i += 1) {
  6047. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
  6048. }
  6049. }
  6050. return matrix.applyToPointArray(arr[0], arr[1], arr[2] || 0);
  6051. }
  6052. function invertPoint(matrix, arr) {
  6053. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  6054. var i;
  6055. var len = this._elem.hierarchy.length;
  6056. for (i = 0; i < len; i += 1) {
  6057. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
  6058. }
  6059. }
  6060. return matrix.inversePoint(arr);
  6061. }
  6062. function fromComp(arr) {
  6063. var toWorldMat = new Matrix();
  6064. toWorldMat.reset();
  6065. this._elem.finalTransform.mProp.applyToMatrix(toWorldMat);
  6066. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  6067. var i;
  6068. var len = this._elem.hierarchy.length;
  6069. for (i = 0; i < len; i += 1) {
  6070. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
  6071. }
  6072. return toWorldMat.inversePoint(arr);
  6073. }
  6074. return toWorldMat.inversePoint(arr);
  6075. }
  6076. function sampleImage() {
  6077. return [1, 1, 1, 1];
  6078. }
  6079. return function (elem) {
  6080. var transformInterface;
  6081. function _registerMaskInterface(maskManager) {
  6082. _thisLayerFunction.mask = new MaskManagerInterface(maskManager, elem);
  6083. }
  6084. function _registerEffectsInterface(effects) {
  6085. _thisLayerFunction.effect = effects;
  6086. }
  6087. function _thisLayerFunction(name) {
  6088. switch (name) {
  6089. case 'ADBE Root Vectors Group':
  6090. case 'Contents':
  6091. case 2:
  6092. return _thisLayerFunction.shapeInterface;
  6093. case 1:
  6094. case 6:
  6095. case 'Transform':
  6096. case 'transform':
  6097. case 'ADBE Transform Group':
  6098. return transformInterface;
  6099. case 4:
  6100. case 'ADBE Effect Parade':
  6101. case 'effects':
  6102. case 'Effects':
  6103. return _thisLayerFunction.effect;
  6104. case 'ADBE Text Properties':
  6105. return _thisLayerFunction.textInterface;
  6106. default:
  6107. return null;
  6108. }
  6109. }
  6110. _thisLayerFunction.getMatrix = getMatrix;
  6111. _thisLayerFunction.invertPoint = invertPoint;
  6112. _thisLayerFunction.applyPoint = applyPoint;
  6113. _thisLayerFunction.toWorld = toWorld;
  6114. _thisLayerFunction.toWorldVec = toWorldVec;
  6115. _thisLayerFunction.fromWorld = fromWorld;
  6116. _thisLayerFunction.fromWorldVec = fromWorldVec;
  6117. _thisLayerFunction.toComp = toWorld;
  6118. _thisLayerFunction.fromComp = fromComp;
  6119. _thisLayerFunction.sampleImage = sampleImage;
  6120. _thisLayerFunction.sourceRectAtTime = elem.sourceRectAtTime.bind(elem);
  6121. _thisLayerFunction._elem = elem;
  6122. transformInterface = TransformExpressionInterface(elem.finalTransform.mProp);
  6123. var anchorPointDescriptor = getDescriptor(transformInterface, 'anchorPoint');
  6124. Object.defineProperties(_thisLayerFunction, {
  6125. hasParent: {
  6126. get: function () {
  6127. return elem.hierarchy.length;
  6128. },
  6129. },
  6130. parent: {
  6131. get: function () {
  6132. return elem.hierarchy[0].layerInterface;
  6133. },
  6134. },
  6135. rotation: getDescriptor(transformInterface, 'rotation'),
  6136. scale: getDescriptor(transformInterface, 'scale'),
  6137. position: getDescriptor(transformInterface, 'position'),
  6138. opacity: getDescriptor(transformInterface, 'opacity'),
  6139. anchorPoint: anchorPointDescriptor,
  6140. anchor_point: anchorPointDescriptor,
  6141. transform: {
  6142. get: function () {
  6143. return transformInterface;
  6144. },
  6145. },
  6146. active: {
  6147. get: function () {
  6148. return elem.isInRange;
  6149. },
  6150. },
  6151. });
  6152. _thisLayerFunction.startTime = elem.data.st;
  6153. _thisLayerFunction.index = elem.data.ind;
  6154. _thisLayerFunction.source = elem.data.refId;
  6155. _thisLayerFunction.height = elem.data.ty === 0 ? elem.data.h : 100;
  6156. _thisLayerFunction.width = elem.data.ty === 0 ? elem.data.w : 100;
  6157. _thisLayerFunction.inPoint = elem.data.ip / elem.comp.globalData.frameRate;
  6158. _thisLayerFunction.outPoint = elem.data.op / elem.comp.globalData.frameRate;
  6159. _thisLayerFunction._name = elem.data.nm;
  6160. _thisLayerFunction.registerMaskInterface = _registerMaskInterface;
  6161. _thisLayerFunction.registerEffectsInterface = _registerEffectsInterface;
  6162. return _thisLayerFunction;
  6163. };
  6164. }());
  6165. const propertyGroupFactory = (function () {
  6166. return function (interfaceFunction, parentPropertyGroup) {
  6167. return function (val) {
  6168. val = val === undefined ? 1 : val;
  6169. if (val <= 0) {
  6170. return interfaceFunction;
  6171. }
  6172. return parentPropertyGroup(val - 1);
  6173. };
  6174. };
  6175. }());
  6176. const PropertyInterface = (function () {
  6177. return function (propertyName, propertyGroup) {
  6178. var interfaceFunction = {
  6179. _name: propertyName,
  6180. };
  6181. function _propertyGroup(val) {
  6182. val = val === undefined ? 1 : val;
  6183. if (val <= 0) {
  6184. return interfaceFunction;
  6185. }
  6186. return propertyGroup(val - 1);
  6187. }
  6188. return _propertyGroup;
  6189. };
  6190. }());
  6191. const EffectsExpressionInterface = (function () {
  6192. var ob = {
  6193. createEffectsInterface: createEffectsInterface,
  6194. };
  6195. function createEffectsInterface(elem, propertyGroup) {
  6196. if (elem.effectsManager) {
  6197. var effectElements = [];
  6198. var effectsData = elem.data.ef;
  6199. var i;
  6200. var len = elem.effectsManager.effectElements.length;
  6201. for (i = 0; i < len; i += 1) {
  6202. effectElements.push(createGroupInterface(effectsData[i], elem.effectsManager.effectElements[i], propertyGroup, elem));
  6203. }
  6204. var effects = elem.data.ef || [];
  6205. var groupInterface = function (name) {
  6206. i = 0;
  6207. len = effects.length;
  6208. while (i < len) {
  6209. if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) {
  6210. return effectElements[i];
  6211. }
  6212. i += 1;
  6213. }
  6214. return null;
  6215. };
  6216. Object.defineProperty(groupInterface, 'numProperties', {
  6217. get: function () {
  6218. return effects.length;
  6219. },
  6220. });
  6221. return groupInterface;
  6222. }
  6223. return null;
  6224. }
  6225. function createGroupInterface(data, elements, propertyGroup, elem) {
  6226. function groupInterface(name) {
  6227. var effects = data.ef;
  6228. var i = 0;
  6229. var len = effects.length;
  6230. while (i < len) {
  6231. if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) {
  6232. if (effects[i].ty === 5) {
  6233. return effectElements[i];
  6234. }
  6235. return effectElements[i]();
  6236. }
  6237. i += 1;
  6238. }
  6239. throw new Error();
  6240. }
  6241. var _propertyGroup = propertyGroupFactory(groupInterface, propertyGroup);
  6242. var effectElements = [];
  6243. var i;
  6244. var len = data.ef.length;
  6245. for (i = 0; i < len; i += 1) {
  6246. if (data.ef[i].ty === 5) {
  6247. effectElements.push(createGroupInterface(data.ef[i], elements.effectElements[i], elements.effectElements[i].propertyGroup, elem));
  6248. } else {
  6249. effectElements.push(createValueInterface(elements.effectElements[i], data.ef[i].ty, elem, _propertyGroup));
  6250. }
  6251. }
  6252. if (data.mn === 'ADBE Color Control') {
  6253. Object.defineProperty(groupInterface, 'color', {
  6254. get: function () {
  6255. return effectElements[0]();
  6256. },
  6257. });
  6258. }
  6259. Object.defineProperties(groupInterface, {
  6260. numProperties: {
  6261. get: function () {
  6262. return data.np;
  6263. },
  6264. },
  6265. _name: { value: data.nm },
  6266. propertyGroup: { value: _propertyGroup },
  6267. });
  6268. groupInterface.enabled = data.en !== 0;
  6269. groupInterface.active = groupInterface.enabled;
  6270. return groupInterface;
  6271. }
  6272. function createValueInterface(element, type, elem, propertyGroup) {
  6273. var expressionProperty = ExpressionPropertyInterface(element.p);
  6274. function interfaceFunction() {
  6275. if (type === 10) {
  6276. return elem.comp.compInterface(element.p.v);
  6277. }
  6278. return expressionProperty();
  6279. }
  6280. if (element.p.setGroupProperty) {
  6281. element.p.setGroupProperty(PropertyInterface('', propertyGroup));
  6282. }
  6283. return interfaceFunction;
  6284. }
  6285. return ob;
  6286. }());
  6287. const CompExpressionInterface = (function () {
  6288. return function (comp) {
  6289. function _thisLayerFunction(name) {
  6290. var i = 0;
  6291. var len = comp.layers.length;
  6292. while (i < len) {
  6293. if (comp.layers[i].nm === name || comp.layers[i].ind === name) {
  6294. return comp.elements[i].layerInterface;
  6295. }
  6296. i += 1;
  6297. }
  6298. return null;
  6299. // return {active:false};
  6300. }
  6301. Object.defineProperty(_thisLayerFunction, '_name', { value: comp.data.nm });
  6302. _thisLayerFunction.layer = _thisLayerFunction;
  6303. _thisLayerFunction.pixelAspect = 1;
  6304. _thisLayerFunction.height = comp.data.h || comp.globalData.compSize.h;
  6305. _thisLayerFunction.width = comp.data.w || comp.globalData.compSize.w;
  6306. _thisLayerFunction.pixelAspect = 1;
  6307. _thisLayerFunction.frameDuration = 1 / comp.globalData.frameRate;
  6308. _thisLayerFunction.displayStartTime = 0;
  6309. _thisLayerFunction.numLayers = comp.layers.length;
  6310. return _thisLayerFunction;
  6311. };
  6312. }());
  6313. const ShapePathInterface = (
  6314. function () {
  6315. return function pathInterfaceFactory(shape, view, propertyGroup) {
  6316. var prop = view.sh;
  6317. function interfaceFunction(val) {
  6318. if (val === 'Shape' || val === 'shape' || val === 'Path' || val === 'path' || val === 'ADBE Vector Shape' || val === 2) {
  6319. return interfaceFunction.path;
  6320. }
  6321. return null;
  6322. }
  6323. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  6324. prop.setGroupProperty(PropertyInterface('Path', _propertyGroup));
  6325. Object.defineProperties(interfaceFunction, {
  6326. path: {
  6327. get: function () {
  6328. if (prop.k) {
  6329. prop.getValue();
  6330. }
  6331. return prop;
  6332. },
  6333. },
  6334. shape: {
  6335. get: function () {
  6336. if (prop.k) {
  6337. prop.getValue();
  6338. }
  6339. return prop;
  6340. },
  6341. },
  6342. _name: { value: shape.nm },
  6343. ix: { value: shape.ix },
  6344. propertyIndex: { value: shape.ix },
  6345. mn: { value: shape.mn },
  6346. propertyGroup: { value: propertyGroup },
  6347. });
  6348. return interfaceFunction;
  6349. };
  6350. }()
  6351. );
  6352. const ShapeExpressionInterface = (function () {
  6353. function iterateElements(shapes, view, propertyGroup) {
  6354. var arr = [];
  6355. var i;
  6356. var len = shapes ? shapes.length : 0;
  6357. for (i = 0; i < len; i += 1) {
  6358. if (shapes[i].ty === 'gr') {
  6359. arr.push(groupInterfaceFactory(shapes[i], view[i], propertyGroup));
  6360. } else if (shapes[i].ty === 'fl') {
  6361. arr.push(fillInterfaceFactory(shapes[i], view[i], propertyGroup));
  6362. } else if (shapes[i].ty === 'st') {
  6363. arr.push(strokeInterfaceFactory(shapes[i], view[i], propertyGroup));
  6364. } else if (shapes[i].ty === 'tm') {
  6365. arr.push(trimInterfaceFactory(shapes[i], view[i], propertyGroup));
  6366. } else if (shapes[i].ty === 'tr') {
  6367. // arr.push(transformInterfaceFactory(shapes[i],view[i],propertyGroup));
  6368. } else if (shapes[i].ty === 'el') {
  6369. arr.push(ellipseInterfaceFactory(shapes[i], view[i], propertyGroup));
  6370. } else if (shapes[i].ty === 'sr') {
  6371. arr.push(starInterfaceFactory(shapes[i], view[i], propertyGroup));
  6372. } else if (shapes[i].ty === 'sh') {
  6373. arr.push(ShapePathInterface(shapes[i], view[i], propertyGroup));
  6374. } else if (shapes[i].ty === 'rc') {
  6375. arr.push(rectInterfaceFactory(shapes[i], view[i], propertyGroup));
  6376. } else if (shapes[i].ty === 'rd') {
  6377. arr.push(roundedInterfaceFactory(shapes[i], view[i], propertyGroup));
  6378. } else if (shapes[i].ty === 'rp') {
  6379. arr.push(repeaterInterfaceFactory(shapes[i], view[i], propertyGroup));
  6380. } else if (shapes[i].ty === 'gf') {
  6381. arr.push(gradientFillInterfaceFactory(shapes[i], view[i], propertyGroup));
  6382. } else {
  6383. arr.push(defaultInterfaceFactory(shapes[i], view[i], propertyGroup));
  6384. }
  6385. }
  6386. return arr;
  6387. }
  6388. function contentsInterfaceFactory(shape, view, propertyGroup) {
  6389. var interfaces;
  6390. var interfaceFunction = function _interfaceFunction(value) {
  6391. var i = 0;
  6392. var len = interfaces.length;
  6393. while (i < len) {
  6394. if (interfaces[i]._name === value || interfaces[i].mn === value || interfaces[i].propertyIndex === value || interfaces[i].ix === value || interfaces[i].ind === value) {
  6395. return interfaces[i];
  6396. }
  6397. i += 1;
  6398. }
  6399. if (typeof value === 'number') {
  6400. return interfaces[value - 1];
  6401. }
  6402. return null;
  6403. };
  6404. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  6405. interfaces = iterateElements(shape.it, view.it, interfaceFunction.propertyGroup);
  6406. interfaceFunction.numProperties = interfaces.length;
  6407. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
  6408. interfaceFunction.transform = transformInterface;
  6409. interfaceFunction.propertyIndex = shape.cix;
  6410. interfaceFunction._name = shape.nm;
  6411. return interfaceFunction;
  6412. }
  6413. function groupInterfaceFactory(shape, view, propertyGroup) {
  6414. var interfaceFunction = function _interfaceFunction(value) {
  6415. switch (value) {
  6416. case 'ADBE Vectors Group':
  6417. case 'Contents':
  6418. case 2:
  6419. return interfaceFunction.content;
  6420. // Not necessary for now. Keeping them here in case a new case appears
  6421. // case 'ADBE Vector Transform Group':
  6422. // case 3:
  6423. default:
  6424. return interfaceFunction.transform;
  6425. }
  6426. };
  6427. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  6428. var content = contentsInterfaceFactory(shape, view, interfaceFunction.propertyGroup);
  6429. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
  6430. interfaceFunction.content = content;
  6431. interfaceFunction.transform = transformInterface;
  6432. Object.defineProperty(interfaceFunction, '_name', {
  6433. get: function () {
  6434. return shape.nm;
  6435. },
  6436. });
  6437. // interfaceFunction.content = interfaceFunction;
  6438. interfaceFunction.numProperties = shape.np;
  6439. interfaceFunction.propertyIndex = shape.ix;
  6440. interfaceFunction.nm = shape.nm;
  6441. interfaceFunction.mn = shape.mn;
  6442. return interfaceFunction;
  6443. }
  6444. function fillInterfaceFactory(shape, view, propertyGroup) {
  6445. function interfaceFunction(val) {
  6446. if (val === 'Color' || val === 'color') {
  6447. return interfaceFunction.color;
  6448. } if (val === 'Opacity' || val === 'opacity') {
  6449. return interfaceFunction.opacity;
  6450. }
  6451. return null;
  6452. }
  6453. Object.defineProperties(interfaceFunction, {
  6454. color: {
  6455. get: ExpressionPropertyInterface(view.c),
  6456. },
  6457. opacity: {
  6458. get: ExpressionPropertyInterface(view.o),
  6459. },
  6460. _name: { value: shape.nm },
  6461. mn: { value: shape.mn },
  6462. });
  6463. view.c.setGroupProperty(PropertyInterface('Color', propertyGroup));
  6464. view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup));
  6465. return interfaceFunction;
  6466. }
  6467. function gradientFillInterfaceFactory(shape, view, propertyGroup) {
  6468. function interfaceFunction(val) {
  6469. if (val === 'Start Point' || val === 'start point') {
  6470. return interfaceFunction.startPoint;
  6471. }
  6472. if (val === 'End Point' || val === 'end point') {
  6473. return interfaceFunction.endPoint;
  6474. }
  6475. if (val === 'Opacity' || val === 'opacity') {
  6476. return interfaceFunction.opacity;
  6477. }
  6478. return null;
  6479. }
  6480. Object.defineProperties(interfaceFunction, {
  6481. startPoint: {
  6482. get: ExpressionPropertyInterface(view.s),
  6483. },
  6484. endPoint: {
  6485. get: ExpressionPropertyInterface(view.e),
  6486. },
  6487. opacity: {
  6488. get: ExpressionPropertyInterface(view.o),
  6489. },
  6490. type: {
  6491. get: function () {
  6492. return 'a';
  6493. },
  6494. },
  6495. _name: { value: shape.nm },
  6496. mn: { value: shape.mn },
  6497. });
  6498. view.s.setGroupProperty(PropertyInterface('Start Point', propertyGroup));
  6499. view.e.setGroupProperty(PropertyInterface('End Point', propertyGroup));
  6500. view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup));
  6501. return interfaceFunction;
  6502. }
  6503. function defaultInterfaceFactory() {
  6504. function interfaceFunction() {
  6505. return null;
  6506. }
  6507. return interfaceFunction;
  6508. }
  6509. function strokeInterfaceFactory(shape, view, propertyGroup) {
  6510. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  6511. var _dashPropertyGroup = propertyGroupFactory(dashOb, _propertyGroup);
  6512. function addPropertyToDashOb(i) {
  6513. Object.defineProperty(dashOb, shape.d[i].nm, {
  6514. get: ExpressionPropertyInterface(view.d.dataProps[i].p),
  6515. });
  6516. }
  6517. var i;
  6518. var len = shape.d ? shape.d.length : 0;
  6519. var dashOb = {};
  6520. for (i = 0; i < len; i += 1) {
  6521. addPropertyToDashOb(i);
  6522. view.d.dataProps[i].p.setGroupProperty(_dashPropertyGroup);
  6523. }
  6524. function interfaceFunction(val) {
  6525. if (val === 'Color' || val === 'color') {
  6526. return interfaceFunction.color;
  6527. } if (val === 'Opacity' || val === 'opacity') {
  6528. return interfaceFunction.opacity;
  6529. } if (val === 'Stroke Width' || val === 'stroke width') {
  6530. return interfaceFunction.strokeWidth;
  6531. }
  6532. return null;
  6533. }
  6534. Object.defineProperties(interfaceFunction, {
  6535. color: {
  6536. get: ExpressionPropertyInterface(view.c),
  6537. },
  6538. opacity: {
  6539. get: ExpressionPropertyInterface(view.o),
  6540. },
  6541. strokeWidth: {
  6542. get: ExpressionPropertyInterface(view.w),
  6543. },
  6544. dash: {
  6545. get: function () {
  6546. return dashOb;
  6547. },
  6548. },
  6549. _name: { value: shape.nm },
  6550. mn: { value: shape.mn },
  6551. });
  6552. view.c.setGroupProperty(PropertyInterface('Color', _propertyGroup));
  6553. view.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  6554. view.w.setGroupProperty(PropertyInterface('Stroke Width', _propertyGroup));
  6555. return interfaceFunction;
  6556. }
  6557. function trimInterfaceFactory(shape, view, propertyGroup) {
  6558. function interfaceFunction(val) {
  6559. if (val === shape.e.ix || val === 'End' || val === 'end') {
  6560. return interfaceFunction.end;
  6561. }
  6562. if (val === shape.s.ix) {
  6563. return interfaceFunction.start;
  6564. }
  6565. if (val === shape.o.ix) {
  6566. return interfaceFunction.offset;
  6567. }
  6568. return null;
  6569. }
  6570. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  6571. interfaceFunction.propertyIndex = shape.ix;
  6572. view.s.setGroupProperty(PropertyInterface('Start', _propertyGroup));
  6573. view.e.setGroupProperty(PropertyInterface('End', _propertyGroup));
  6574. view.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  6575. interfaceFunction.propertyIndex = shape.ix;
  6576. interfaceFunction.propertyGroup = propertyGroup;
  6577. Object.defineProperties(interfaceFunction, {
  6578. start: {
  6579. get: ExpressionPropertyInterface(view.s),
  6580. },
  6581. end: {
  6582. get: ExpressionPropertyInterface(view.e),
  6583. },
  6584. offset: {
  6585. get: ExpressionPropertyInterface(view.o),
  6586. },
  6587. _name: { value: shape.nm },
  6588. });
  6589. interfaceFunction.mn = shape.mn;
  6590. return interfaceFunction;
  6591. }
  6592. function transformInterfaceFactory(shape, view, propertyGroup) {
  6593. function interfaceFunction(value) {
  6594. if (shape.a.ix === value || value === 'Anchor Point') {
  6595. return interfaceFunction.anchorPoint;
  6596. }
  6597. if (shape.o.ix === value || value === 'Opacity') {
  6598. return interfaceFunction.opacity;
  6599. }
  6600. if (shape.p.ix === value || value === 'Position') {
  6601. return interfaceFunction.position;
  6602. }
  6603. if (shape.r.ix === value || value === 'Rotation' || value === 'ADBE Vector Rotation') {
  6604. return interfaceFunction.rotation;
  6605. }
  6606. if (shape.s.ix === value || value === 'Scale') {
  6607. return interfaceFunction.scale;
  6608. }
  6609. if ((shape.sk && shape.sk.ix === value) || value === 'Skew') {
  6610. return interfaceFunction.skew;
  6611. }
  6612. if ((shape.sa && shape.sa.ix === value) || value === 'Skew Axis') {
  6613. return interfaceFunction.skewAxis;
  6614. }
  6615. return null;
  6616. }
  6617. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  6618. view.transform.mProps.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  6619. view.transform.mProps.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  6620. view.transform.mProps.a.setGroupProperty(PropertyInterface('Anchor Point', _propertyGroup));
  6621. view.transform.mProps.s.setGroupProperty(PropertyInterface('Scale', _propertyGroup));
  6622. view.transform.mProps.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  6623. if (view.transform.mProps.sk) {
  6624. view.transform.mProps.sk.setGroupProperty(PropertyInterface('Skew', _propertyGroup));
  6625. view.transform.mProps.sa.setGroupProperty(PropertyInterface('Skew Angle', _propertyGroup));
  6626. }
  6627. view.transform.op.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  6628. Object.defineProperties(interfaceFunction, {
  6629. opacity: {
  6630. get: ExpressionPropertyInterface(view.transform.mProps.o),
  6631. },
  6632. position: {
  6633. get: ExpressionPropertyInterface(view.transform.mProps.p),
  6634. },
  6635. anchorPoint: {
  6636. get: ExpressionPropertyInterface(view.transform.mProps.a),
  6637. },
  6638. scale: {
  6639. get: ExpressionPropertyInterface(view.transform.mProps.s),
  6640. },
  6641. rotation: {
  6642. get: ExpressionPropertyInterface(view.transform.mProps.r),
  6643. },
  6644. skew: {
  6645. get: ExpressionPropertyInterface(view.transform.mProps.sk),
  6646. },
  6647. skewAxis: {
  6648. get: ExpressionPropertyInterface(view.transform.mProps.sa),
  6649. },
  6650. _name: { value: shape.nm },
  6651. });
  6652. interfaceFunction.ty = 'tr';
  6653. interfaceFunction.mn = shape.mn;
  6654. interfaceFunction.propertyGroup = propertyGroup;
  6655. return interfaceFunction;
  6656. }
  6657. function ellipseInterfaceFactory(shape, view, propertyGroup) {
  6658. function interfaceFunction(value) {
  6659. if (shape.p.ix === value) {
  6660. return interfaceFunction.position;
  6661. }
  6662. if (shape.s.ix === value) {
  6663. return interfaceFunction.size;
  6664. }
  6665. return null;
  6666. }
  6667. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  6668. interfaceFunction.propertyIndex = shape.ix;
  6669. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  6670. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  6671. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  6672. Object.defineProperties(interfaceFunction, {
  6673. size: {
  6674. get: ExpressionPropertyInterface(prop.s),
  6675. },
  6676. position: {
  6677. get: ExpressionPropertyInterface(prop.p),
  6678. },
  6679. _name: { value: shape.nm },
  6680. });
  6681. interfaceFunction.mn = shape.mn;
  6682. return interfaceFunction;
  6683. }
  6684. function starInterfaceFactory(shape, view, propertyGroup) {
  6685. function interfaceFunction(value) {
  6686. if (shape.p.ix === value) {
  6687. return interfaceFunction.position;
  6688. }
  6689. if (shape.r.ix === value) {
  6690. return interfaceFunction.rotation;
  6691. }
  6692. if (shape.pt.ix === value) {
  6693. return interfaceFunction.points;
  6694. }
  6695. if (shape.or.ix === value || value === 'ADBE Vector Star Outer Radius') {
  6696. return interfaceFunction.outerRadius;
  6697. }
  6698. if (shape.os.ix === value) {
  6699. return interfaceFunction.outerRoundness;
  6700. }
  6701. if (shape.ir && (shape.ir.ix === value || value === 'ADBE Vector Star Inner Radius')) {
  6702. return interfaceFunction.innerRadius;
  6703. }
  6704. if (shape.is && shape.is.ix === value) {
  6705. return interfaceFunction.innerRoundness;
  6706. }
  6707. return null;
  6708. }
  6709. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  6710. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  6711. interfaceFunction.propertyIndex = shape.ix;
  6712. prop.or.setGroupProperty(PropertyInterface('Outer Radius', _propertyGroup));
  6713. prop.os.setGroupProperty(PropertyInterface('Outer Roundness', _propertyGroup));
  6714. prop.pt.setGroupProperty(PropertyInterface('Points', _propertyGroup));
  6715. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  6716. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  6717. if (shape.ir) {
  6718. prop.ir.setGroupProperty(PropertyInterface('Inner Radius', _propertyGroup));
  6719. prop.is.setGroupProperty(PropertyInterface('Inner Roundness', _propertyGroup));
  6720. }
  6721. Object.defineProperties(interfaceFunction, {
  6722. position: {
  6723. get: ExpressionPropertyInterface(prop.p),
  6724. },
  6725. rotation: {
  6726. get: ExpressionPropertyInterface(prop.r),
  6727. },
  6728. points: {
  6729. get: ExpressionPropertyInterface(prop.pt),
  6730. },
  6731. outerRadius: {
  6732. get: ExpressionPropertyInterface(prop.or),
  6733. },
  6734. outerRoundness: {
  6735. get: ExpressionPropertyInterface(prop.os),
  6736. },
  6737. innerRadius: {
  6738. get: ExpressionPropertyInterface(prop.ir),
  6739. },
  6740. innerRoundness: {
  6741. get: ExpressionPropertyInterface(prop.is),
  6742. },
  6743. _name: { value: shape.nm },
  6744. });
  6745. interfaceFunction.mn = shape.mn;
  6746. return interfaceFunction;
  6747. }
  6748. function rectInterfaceFactory(shape, view, propertyGroup) {
  6749. function interfaceFunction(value) {
  6750. if (shape.p.ix === value) {
  6751. return interfaceFunction.position;
  6752. }
  6753. if (shape.r.ix === value) {
  6754. return interfaceFunction.roundness;
  6755. }
  6756. if (shape.s.ix === value || value === 'Size' || value === 'ADBE Vector Rect Size') {
  6757. return interfaceFunction.size;
  6758. }
  6759. return null;
  6760. }
  6761. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  6762. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  6763. interfaceFunction.propertyIndex = shape.ix;
  6764. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  6765. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  6766. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  6767. Object.defineProperties(interfaceFunction, {
  6768. position: {
  6769. get: ExpressionPropertyInterface(prop.p),
  6770. },
  6771. roundness: {
  6772. get: ExpressionPropertyInterface(prop.r),
  6773. },
  6774. size: {
  6775. get: ExpressionPropertyInterface(prop.s),
  6776. },
  6777. _name: { value: shape.nm },
  6778. });
  6779. interfaceFunction.mn = shape.mn;
  6780. return interfaceFunction;
  6781. }
  6782. function roundedInterfaceFactory(shape, view, propertyGroup) {
  6783. function interfaceFunction(value) {
  6784. if (shape.r.ix === value || value === 'Round Corners 1') {
  6785. return interfaceFunction.radius;
  6786. }
  6787. return null;
  6788. }
  6789. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  6790. var prop = view;
  6791. interfaceFunction.propertyIndex = shape.ix;
  6792. prop.rd.setGroupProperty(PropertyInterface('Radius', _propertyGroup));
  6793. Object.defineProperties(interfaceFunction, {
  6794. radius: {
  6795. get: ExpressionPropertyInterface(prop.rd),
  6796. },
  6797. _name: { value: shape.nm },
  6798. });
  6799. interfaceFunction.mn = shape.mn;
  6800. return interfaceFunction;
  6801. }
  6802. function repeaterInterfaceFactory(shape, view, propertyGroup) {
  6803. function interfaceFunction(value) {
  6804. if (shape.c.ix === value || value === 'Copies') {
  6805. return interfaceFunction.copies;
  6806. } if (shape.o.ix === value || value === 'Offset') {
  6807. return interfaceFunction.offset;
  6808. }
  6809. return null;
  6810. }
  6811. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  6812. var prop = view;
  6813. interfaceFunction.propertyIndex = shape.ix;
  6814. prop.c.setGroupProperty(PropertyInterface('Copies', _propertyGroup));
  6815. prop.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  6816. Object.defineProperties(interfaceFunction, {
  6817. copies: {
  6818. get: ExpressionPropertyInterface(prop.c),
  6819. },
  6820. offset: {
  6821. get: ExpressionPropertyInterface(prop.o),
  6822. },
  6823. _name: { value: shape.nm },
  6824. });
  6825. interfaceFunction.mn = shape.mn;
  6826. return interfaceFunction;
  6827. }
  6828. return function (shapes, view, propertyGroup) {
  6829. var interfaces;
  6830. function _interfaceFunction(value) {
  6831. if (typeof value === 'number') {
  6832. value = value === undefined ? 1 : value;
  6833. if (value === 0) {
  6834. return propertyGroup;
  6835. }
  6836. return interfaces[value - 1];
  6837. }
  6838. var i = 0;
  6839. var len = interfaces.length;
  6840. while (i < len) {
  6841. if (interfaces[i]._name === value) {
  6842. return interfaces[i];
  6843. }
  6844. i += 1;
  6845. }
  6846. return null;
  6847. }
  6848. function parentGroupWrapper() {
  6849. return propertyGroup;
  6850. }
  6851. _interfaceFunction.propertyGroup = propertyGroupFactory(_interfaceFunction, parentGroupWrapper);
  6852. interfaces = iterateElements(shapes, view, _interfaceFunction.propertyGroup);
  6853. _interfaceFunction.numProperties = interfaces.length;
  6854. _interfaceFunction._name = 'Contents';
  6855. return _interfaceFunction;
  6856. };
  6857. }());
  6858. const TextExpressionInterface = (function () {
  6859. return function (elem) {
  6860. var _prevValue;
  6861. var _sourceText;
  6862. function _thisLayerFunction(name) {
  6863. switch (name) {
  6864. case 'ADBE Text Document':
  6865. return _thisLayerFunction.sourceText;
  6866. default:
  6867. return null;
  6868. }
  6869. }
  6870. Object.defineProperty(_thisLayerFunction, 'sourceText', {
  6871. get: function () {
  6872. elem.textProperty.getValue();
  6873. var stringValue = elem.textProperty.currentData.t;
  6874. if (stringValue !== _prevValue) {
  6875. elem.textProperty.currentData.t = _prevValue;
  6876. _sourceText = new String(stringValue); // eslint-disable-line no-new-wrappers
  6877. // If stringValue is an empty string, eval returns undefined, so it has to be returned as a String primitive
  6878. _sourceText.value = stringValue || new String(stringValue); // eslint-disable-line no-new-wrappers
  6879. }
  6880. return _sourceText;
  6881. },
  6882. });
  6883. return _thisLayerFunction;
  6884. };
  6885. }());
  6886. const getBlendMode = (function () {
  6887. var blendModeEnums = {
  6888. 0: 'source-over',
  6889. 1: 'multiply',
  6890. 2: 'screen',
  6891. 3: 'overlay',
  6892. 4: 'darken',
  6893. 5: 'lighten',
  6894. 6: 'color-dodge',
  6895. 7: 'color-burn',
  6896. 8: 'hard-light',
  6897. 9: 'soft-light',
  6898. 10: 'difference',
  6899. 11: 'exclusion',
  6900. 12: 'hue',
  6901. 13: 'saturation',
  6902. 14: 'color',
  6903. 15: 'luminosity',
  6904. };
  6905. return function (mode) {
  6906. return blendModeEnums[mode] || '';
  6907. };
  6908. }());
  6909. function SliderEffect(data, elem, container) {
  6910. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6911. }
  6912. function AngleEffect(data, elem, container) {
  6913. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6914. }
  6915. function ColorEffect(data, elem, container) {
  6916. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6917. }
  6918. function PointEffect(data, elem, container) {
  6919. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6920. }
  6921. function LayerIndexEffect(data, elem, container) {
  6922. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6923. }
  6924. function MaskIndexEffect(data, elem, container) {
  6925. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6926. }
  6927. function CheckboxEffect(data, elem, container) {
  6928. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6929. }
  6930. function NoValueEffect() {
  6931. this.p = {};
  6932. }
  6933. function EffectsManager(data, element) {
  6934. var effects = data.ef || [];
  6935. this.effectElements = [];
  6936. var i;
  6937. var len = effects.length;
  6938. var effectItem;
  6939. for (i = 0; i < len; i += 1) {
  6940. effectItem = new GroupEffect(effects[i], element);
  6941. this.effectElements.push(effectItem);
  6942. }
  6943. }
  6944. function GroupEffect(data, element) {
  6945. this.init(data, element);
  6946. }
  6947. extendPrototype([DynamicPropertyContainer], GroupEffect);
  6948. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  6949. GroupEffect.prototype.init = function (data, element) {
  6950. this.data = data;
  6951. this.effectElements = [];
  6952. this.initDynamicPropertyContainer(element);
  6953. var i;
  6954. var len = this.data.ef.length;
  6955. var eff;
  6956. var effects = this.data.ef;
  6957. for (i = 0; i < len; i += 1) {
  6958. eff = null;
  6959. switch (effects[i].ty) {
  6960. case 0:
  6961. eff = new SliderEffect(effects[i], element, this);
  6962. break;
  6963. case 1:
  6964. eff = new AngleEffect(effects[i], element, this);
  6965. break;
  6966. case 2:
  6967. eff = new ColorEffect(effects[i], element, this);
  6968. break;
  6969. case 3:
  6970. eff = new PointEffect(effects[i], element, this);
  6971. break;
  6972. case 4:
  6973. case 7:
  6974. eff = new CheckboxEffect(effects[i], element, this);
  6975. break;
  6976. case 10:
  6977. eff = new LayerIndexEffect(effects[i], element, this);
  6978. break;
  6979. case 11:
  6980. eff = new MaskIndexEffect(effects[i], element, this);
  6981. break;
  6982. case 5:
  6983. eff = new EffectsManager(effects[i], element, this);
  6984. break;
  6985. // case 6:
  6986. default:
  6987. eff = new NoValueEffect(effects[i], element, this);
  6988. break;
  6989. }
  6990. if (eff) {
  6991. this.effectElements.push(eff);
  6992. }
  6993. }
  6994. };
  6995. function BaseElement() {
  6996. }
  6997. BaseElement.prototype = {
  6998. checkMasks: function () {
  6999. if (!this.data.hasMask) {
  7000. return false;
  7001. }
  7002. var i = 0;
  7003. var len = this.data.masksProperties.length;
  7004. while (i < len) {
  7005. if ((this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false)) {
  7006. return true;
  7007. }
  7008. i += 1;
  7009. }
  7010. return false;
  7011. },
  7012. initExpressions: function () {
  7013. this.layerInterface = LayerExpressionInterface(this);
  7014. if (this.data.hasMask && this.maskManager) {
  7015. this.layerInterface.registerMaskInterface(this.maskManager);
  7016. }
  7017. var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this, this.layerInterface);
  7018. this.layerInterface.registerEffectsInterface(effectsInterface);
  7019. if (this.data.ty === 0 || this.data.xt) {
  7020. this.compInterface = CompExpressionInterface(this);
  7021. } else if (this.data.ty === 4) {
  7022. this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface);
  7023. this.layerInterface.content = this.layerInterface.shapeInterface;
  7024. } else if (this.data.ty === 5) {
  7025. this.layerInterface.textInterface = TextExpressionInterface(this);
  7026. this.layerInterface.text = this.layerInterface.textInterface;
  7027. }
  7028. },
  7029. setBlendMode: function () {
  7030. var blendModeValue = getBlendMode(this.data.bm);
  7031. var elem = this.baseElement || this.layerElement;
  7032. elem.style['mix-blend-mode'] = blendModeValue;
  7033. },
  7034. initBaseData: function (data, globalData, comp) {
  7035. this.globalData = globalData;
  7036. this.comp = comp;
  7037. this.data = data;
  7038. this.layerId = createElementID();
  7039. // Stretch factor for old animations missing this property.
  7040. if (!this.data.sr) {
  7041. this.data.sr = 1;
  7042. }
  7043. // effects manager
  7044. this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties);
  7045. },
  7046. getType: function () {
  7047. return this.type;
  7048. },
  7049. sourceRectAtTime: function () {},
  7050. };
  7051. /**
  7052. * @file
  7053. * Handles element's layer frame update.
  7054. * Checks layer in point and out point
  7055. *
  7056. */
  7057. function FrameElement() {}
  7058. FrameElement.prototype = {
  7059. /**
  7060. * @function
  7061. * Initializes frame related properties.
  7062. *
  7063. */
  7064. initFrame: function () {
  7065. // set to true when inpoint is rendered
  7066. this._isFirstFrame = false;
  7067. // list of animated properties
  7068. this.dynamicProperties = [];
  7069. // If layer has been modified in current tick this will be true
  7070. this._mdf = false;
  7071. },
  7072. /**
  7073. * @function
  7074. * Calculates all dynamic values
  7075. *
  7076. * @param {number} num
  7077. * current frame number in Layer's time
  7078. * @param {boolean} isVisible
  7079. * if layers is currently in range
  7080. *
  7081. */
  7082. prepareProperties: function (num, isVisible) {
  7083. var i;
  7084. var len = this.dynamicProperties.length;
  7085. for (i = 0; i < len; i += 1) {
  7086. if (isVisible || (this._isParent && this.dynamicProperties[i].propType === 'transform')) {
  7087. this.dynamicProperties[i].getValue();
  7088. if (this.dynamicProperties[i]._mdf) {
  7089. this.globalData._mdf = true;
  7090. this._mdf = true;
  7091. }
  7092. }
  7093. }
  7094. },
  7095. addDynamicProperty: function (prop) {
  7096. if (this.dynamicProperties.indexOf(prop) === -1) {
  7097. this.dynamicProperties.push(prop);
  7098. }
  7099. },
  7100. };
  7101. const FootageInterface = (function () {
  7102. var outlineInterfaceFactory = (function (elem) {
  7103. var currentPropertyName = '';
  7104. var currentProperty = elem.getFootageData();
  7105. function init() {
  7106. currentPropertyName = '';
  7107. currentProperty = elem.getFootageData();
  7108. return searchProperty;
  7109. }
  7110. function searchProperty(value) {
  7111. if (currentProperty[value]) {
  7112. currentPropertyName = value;
  7113. currentProperty = currentProperty[value];
  7114. if (typeof currentProperty === 'object') {
  7115. return searchProperty;
  7116. }
  7117. return currentProperty;
  7118. }
  7119. var propertyNameIndex = value.indexOf(currentPropertyName);
  7120. if (propertyNameIndex !== -1) {
  7121. var index = parseInt(value.substr(propertyNameIndex + currentPropertyName.length), 10);
  7122. currentProperty = currentProperty[index];
  7123. if (typeof currentProperty === 'object') {
  7124. return searchProperty;
  7125. }
  7126. return currentProperty;
  7127. }
  7128. return '';
  7129. }
  7130. return init;
  7131. });
  7132. var dataInterfaceFactory = function (elem) {
  7133. function interfaceFunction(value) {
  7134. if (value === 'Outline') {
  7135. return interfaceFunction.outlineInterface();
  7136. }
  7137. return null;
  7138. }
  7139. interfaceFunction._name = 'Outline';
  7140. interfaceFunction.outlineInterface = outlineInterfaceFactory(elem);
  7141. return interfaceFunction;
  7142. };
  7143. return function (elem) {
  7144. function _interfaceFunction(value) {
  7145. if (value === 'Data') {
  7146. return _interfaceFunction.dataInterface;
  7147. }
  7148. return null;
  7149. }
  7150. _interfaceFunction._name = 'Data';
  7151. _interfaceFunction.dataInterface = dataInterfaceFactory(elem);
  7152. return _interfaceFunction;
  7153. };
  7154. }());
  7155. function FootageElement(data, globalData, comp) {
  7156. this.initFrame();
  7157. this.initRenderable();
  7158. this.assetData = globalData.getAssetData(data.refId);
  7159. this.footageData = globalData.imageLoader.getAsset(this.assetData);
  7160. this.initBaseData(data, globalData, comp);
  7161. }
  7162. FootageElement.prototype.prepareFrame = function () {
  7163. };
  7164. extendPrototype([RenderableElement, BaseElement, FrameElement], FootageElement);
  7165. FootageElement.prototype.getBaseElement = function () {
  7166. return null;
  7167. };
  7168. FootageElement.prototype.renderFrame = function () {
  7169. };
  7170. FootageElement.prototype.destroy = function () {
  7171. };
  7172. FootageElement.prototype.initExpressions = function () {
  7173. this.layerInterface = FootageInterface(this);
  7174. };
  7175. FootageElement.prototype.getFootageData = function () {
  7176. return this.footageData;
  7177. };
  7178. function AudioElement(data, globalData, comp) {
  7179. this.initFrame();
  7180. this.initRenderable();
  7181. this.assetData = globalData.getAssetData(data.refId);
  7182. this.initBaseData(data, globalData, comp);
  7183. this._isPlaying = false;
  7184. this._canPlay = false;
  7185. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7186. this.audio = this.globalData.audioController.createAudio(assetPath);
  7187. this._currentTime = 0;
  7188. this.globalData.audioController.addAudio(this);
  7189. this._volumeMultiplier = 1;
  7190. this._volume = 1;
  7191. this._previousVolume = null;
  7192. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  7193. this.lv = PropertyFactory.getProp(this, data.au && data.au.lv ? data.au.lv : { k: [100] }, 1, 0.01, this);
  7194. }
  7195. AudioElement.prototype.prepareFrame = function (num) {
  7196. this.prepareRenderableFrame(num, true);
  7197. this.prepareProperties(num, true);
  7198. if (!this.tm._placeholder) {
  7199. var timeRemapped = this.tm.v;
  7200. this._currentTime = timeRemapped;
  7201. } else {
  7202. this._currentTime = num / this.data.sr;
  7203. }
  7204. this._volume = this.lv.v[0];
  7205. var totalVolume = this._volume * this._volumeMultiplier;
  7206. if (this._previousVolume !== totalVolume) {
  7207. this._previousVolume = totalVolume;
  7208. this.audio.volume(totalVolume);
  7209. }
  7210. };
  7211. extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement);
  7212. AudioElement.prototype.renderFrame = function () {
  7213. if (this.isInRange && this._canPlay) {
  7214. if (!this._isPlaying) {
  7215. this.audio.play();
  7216. this.audio.seek(this._currentTime / this.globalData.frameRate);
  7217. this._isPlaying = true;
  7218. } else if (!this.audio.playing()
  7219. || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1
  7220. ) {
  7221. this.audio.seek(this._currentTime / this.globalData.frameRate);
  7222. }
  7223. }
  7224. };
  7225. AudioElement.prototype.show = function () {
  7226. // this.audio.play()
  7227. };
  7228. AudioElement.prototype.hide = function () {
  7229. this.audio.pause();
  7230. this._isPlaying = false;
  7231. };
  7232. AudioElement.prototype.pause = function () {
  7233. this.audio.pause();
  7234. this._isPlaying = false;
  7235. this._canPlay = false;
  7236. };
  7237. AudioElement.prototype.resume = function () {
  7238. this._canPlay = true;
  7239. };
  7240. AudioElement.prototype.setRate = function (rateValue) {
  7241. this.audio.rate(rateValue);
  7242. };
  7243. AudioElement.prototype.volume = function (volumeValue) {
  7244. this._volumeMultiplier = volumeValue;
  7245. this._previousVolume = volumeValue * this._volume;
  7246. this.audio.volume(this._previousVolume);
  7247. };
  7248. AudioElement.prototype.getBaseElement = function () {
  7249. return null;
  7250. };
  7251. AudioElement.prototype.destroy = function () {
  7252. };
  7253. AudioElement.prototype.sourceRectAtTime = function () {
  7254. };
  7255. AudioElement.prototype.initExpressions = function () {
  7256. };
  7257. function BaseRenderer() {}
  7258. BaseRenderer.prototype.checkLayers = function (num) {
  7259. var i;
  7260. var len = this.layers.length;
  7261. var data;
  7262. this.completeLayers = true;
  7263. for (i = len - 1; i >= 0; i -= 1) {
  7264. if (!this.elements[i]) {
  7265. data = this.layers[i];
  7266. if (data.ip - data.st <= (num - this.layers[i].st) && data.op - data.st > (num - this.layers[i].st)) {
  7267. this.buildItem(i);
  7268. }
  7269. }
  7270. this.completeLayers = this.elements[i] ? this.completeLayers : false;
  7271. }
  7272. this.checkPendingElements();
  7273. };
  7274. BaseRenderer.prototype.createItem = function (layer) {
  7275. switch (layer.ty) {
  7276. case 2:
  7277. return this.createImage(layer);
  7278. case 0:
  7279. return this.createComp(layer);
  7280. case 1:
  7281. return this.createSolid(layer);
  7282. case 3:
  7283. return this.createNull(layer);
  7284. case 4:
  7285. return this.createShape(layer);
  7286. case 5:
  7287. return this.createText(layer);
  7288. case 6:
  7289. return this.createAudio(layer);
  7290. case 13:
  7291. return this.createCamera(layer);
  7292. case 15:
  7293. return this.createFootage(layer);
  7294. default:
  7295. return this.createNull(layer);
  7296. }
  7297. };
  7298. BaseRenderer.prototype.createCamera = function () {
  7299. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  7300. };
  7301. BaseRenderer.prototype.createAudio = function (data) {
  7302. return new AudioElement(data, this.globalData, this);
  7303. };
  7304. BaseRenderer.prototype.createFootage = function (data) {
  7305. return new FootageElement(data, this.globalData, this);
  7306. };
  7307. BaseRenderer.prototype.buildAllItems = function () {
  7308. var i;
  7309. var len = this.layers.length;
  7310. for (i = 0; i < len; i += 1) {
  7311. this.buildItem(i);
  7312. }
  7313. this.checkPendingElements();
  7314. };
  7315. BaseRenderer.prototype.includeLayers = function (newLayers) {
  7316. this.completeLayers = false;
  7317. var i;
  7318. var len = newLayers.length;
  7319. var j;
  7320. var jLen = this.layers.length;
  7321. for (i = 0; i < len; i += 1) {
  7322. j = 0;
  7323. while (j < jLen) {
  7324. if (this.layers[j].id === newLayers[i].id) {
  7325. this.layers[j] = newLayers[i];
  7326. break;
  7327. }
  7328. j += 1;
  7329. }
  7330. }
  7331. };
  7332. BaseRenderer.prototype.setProjectInterface = function (pInterface) {
  7333. this.globalData.projectInterface = pInterface;
  7334. };
  7335. BaseRenderer.prototype.initItems = function () {
  7336. if (!this.globalData.progressiveLoad) {
  7337. this.buildAllItems();
  7338. }
  7339. };
  7340. BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) {
  7341. var elements = this.elements;
  7342. var layers = this.layers;
  7343. var i = 0;
  7344. var len = layers.length;
  7345. while (i < len) {
  7346. if (layers[i].ind == parentName) { // eslint-disable-line eqeqeq
  7347. if (!elements[i] || elements[i] === true) {
  7348. this.buildItem(i);
  7349. this.addPendingElement(element);
  7350. } else {
  7351. hierarchy.push(elements[i]);
  7352. elements[i].setAsParent();
  7353. if (layers[i].parent !== undefined) {
  7354. this.buildElementParenting(element, layers[i].parent, hierarchy);
  7355. } else {
  7356. element.setHierarchy(hierarchy);
  7357. }
  7358. }
  7359. }
  7360. i += 1;
  7361. }
  7362. };
  7363. BaseRenderer.prototype.addPendingElement = function (element) {
  7364. this.pendingElements.push(element);
  7365. };
  7366. BaseRenderer.prototype.searchExtraCompositions = function (assets) {
  7367. var i;
  7368. var len = assets.length;
  7369. for (i = 0; i < len; i += 1) {
  7370. if (assets[i].xt) {
  7371. var comp = this.createComp(assets[i]);
  7372. comp.initExpressions();
  7373. this.globalData.projectInterface.registerComposition(comp);
  7374. }
  7375. }
  7376. };
  7377. BaseRenderer.prototype.getElementByPath = function (path) {
  7378. var pathValue = path.shift();
  7379. var element;
  7380. if (typeof pathValue === 'number') {
  7381. element = this.elements[pathValue];
  7382. } else {
  7383. var i;
  7384. var len = this.elements.length;
  7385. for (i = 0; i < len; i += 1) {
  7386. if (this.elements[i].data.nm === pathValue) {
  7387. element = this.elements[i];
  7388. break;
  7389. }
  7390. }
  7391. }
  7392. if (path.length === 0) {
  7393. return element;
  7394. }
  7395. return element.getElementByPath(path);
  7396. };
  7397. BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) {
  7398. this.globalData.fontManager = new FontManager();
  7399. this.globalData.fontManager.addChars(animData.chars);
  7400. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  7401. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  7402. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  7403. this.globalData.imageLoader = this.animationItem.imagePreloader;
  7404. this.globalData.audioController = this.animationItem.audioController;
  7405. this.globalData.frameId = 0;
  7406. this.globalData.frameRate = animData.fr;
  7407. this.globalData.nm = animData.nm;
  7408. this.globalData.compSize = {
  7409. w: animData.w,
  7410. h: animData.h,
  7411. };
  7412. };
  7413. function TransformElement() {}
  7414. TransformElement.prototype = {
  7415. initTransform: function () {
  7416. this.finalTransform = {
  7417. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : { o: 0 },
  7418. _matMdf: false,
  7419. _opMdf: false,
  7420. mat: new Matrix(),
  7421. };
  7422. if (this.data.ao) {
  7423. this.finalTransform.mProp.autoOriented = true;
  7424. }
  7425. // TODO: check TYPE 11: Guided elements
  7426. if (this.data.ty !== 11) {
  7427. // this.createElements();
  7428. }
  7429. },
  7430. renderTransform: function () {
  7431. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  7432. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  7433. if (this.hierarchy) {
  7434. var mat;
  7435. var finalMat = this.finalTransform.mat;
  7436. var i = 0;
  7437. var len = this.hierarchy.length;
  7438. // Checking if any of the transformation matrices in the hierarchy chain has changed.
  7439. if (!this.finalTransform._matMdf) {
  7440. while (i < len) {
  7441. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  7442. this.finalTransform._matMdf = true;
  7443. break;
  7444. }
  7445. i += 1;
  7446. }
  7447. }
  7448. if (this.finalTransform._matMdf) {
  7449. mat = this.finalTransform.mProp.v.props;
  7450. finalMat.cloneFromProps(mat);
  7451. for (i = 0; i < len; i += 1) {
  7452. mat = this.hierarchy[i].finalTransform.mProp.v.props;
  7453. finalMat.transform(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5], mat[6], mat[7], mat[8], mat[9], mat[10], mat[11], mat[12], mat[13], mat[14], mat[15]);
  7454. }
  7455. }
  7456. }
  7457. },
  7458. globalToLocal: function (pt) {
  7459. var transforms = [];
  7460. transforms.push(this.finalTransform);
  7461. var flag = true;
  7462. var comp = this.comp;
  7463. while (flag) {
  7464. if (comp.finalTransform) {
  7465. if (comp.data.hasMask) {
  7466. transforms.splice(0, 0, comp.finalTransform);
  7467. }
  7468. comp = comp.comp;
  7469. } else {
  7470. flag = false;
  7471. }
  7472. }
  7473. var i;
  7474. var len = transforms.length;
  7475. var ptNew;
  7476. for (i = 0; i < len; i += 1) {
  7477. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
  7478. // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  7479. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  7480. }
  7481. return pt;
  7482. },
  7483. mHelper: new Matrix(),
  7484. };
  7485. function MaskElement(data, element, globalData) {
  7486. this.data = data;
  7487. this.element = element;
  7488. this.globalData = globalData;
  7489. this.storedData = [];
  7490. this.masksProperties = this.data.masksProperties || [];
  7491. this.maskElement = null;
  7492. var defs = this.globalData.defs;
  7493. var i;
  7494. var len = this.masksProperties ? this.masksProperties.length : 0;
  7495. this.viewData = createSizedArray(len);
  7496. this.solidPath = '';
  7497. var path;
  7498. var properties = this.masksProperties;
  7499. var count = 0;
  7500. var currentMasks = [];
  7501. var j;
  7502. var jLen;
  7503. var layerId = createElementID();
  7504. var rect;
  7505. var expansor;
  7506. var feMorph;
  7507. var x;
  7508. var maskType = 'clipPath';
  7509. var maskRef = 'clip-path';
  7510. for (i = 0; i < len; i += 1) {
  7511. if ((properties[i].mode !== 'a' && properties[i].mode !== 'n') || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) {
  7512. maskType = 'mask';
  7513. maskRef = 'mask';
  7514. }
  7515. if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) {
  7516. rect = createNS('rect');
  7517. rect.setAttribute('fill', '#ffffff');
  7518. rect.setAttribute('width', this.element.comp.data.w || 0);
  7519. rect.setAttribute('height', this.element.comp.data.h || 0);
  7520. currentMasks.push(rect);
  7521. } else {
  7522. rect = null;
  7523. }
  7524. path = createNS('path');
  7525. if (properties[i].mode === 'n') {
  7526. // TODO move this to a factory or to a constructor
  7527. this.viewData[i] = {
  7528. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7529. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7530. elem: path,
  7531. lastPath: '',
  7532. };
  7533. defs.appendChild(path);
  7534. } else {
  7535. count += 1;
  7536. path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7537. path.setAttribute('clip-rule', 'nonzero');
  7538. var filterID;
  7539. if (properties[i].x.k !== 0) {
  7540. maskType = 'mask';
  7541. maskRef = 'mask';
  7542. x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element);
  7543. filterID = createElementID();
  7544. expansor = createNS('filter');
  7545. expansor.setAttribute('id', filterID);
  7546. feMorph = createNS('feMorphology');
  7547. feMorph.setAttribute('operator', 'erode');
  7548. feMorph.setAttribute('in', 'SourceGraphic');
  7549. feMorph.setAttribute('radius', '0');
  7550. expansor.appendChild(feMorph);
  7551. defs.appendChild(expansor);
  7552. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7553. } else {
  7554. feMorph = null;
  7555. x = null;
  7556. }
  7557. // TODO move this to a factory or to a constructor
  7558. this.storedData[i] = {
  7559. elem: path,
  7560. x: x,
  7561. expan: feMorph,
  7562. lastPath: '',
  7563. lastOperator: '',
  7564. filterId: filterID,
  7565. lastRadius: 0,
  7566. };
  7567. if (properties[i].mode === 'i') {
  7568. jLen = currentMasks.length;
  7569. var g = createNS('g');
  7570. for (j = 0; j < jLen; j += 1) {
  7571. g.appendChild(currentMasks[j]);
  7572. }
  7573. var mask = createNS('mask');
  7574. mask.setAttribute('mask-type', 'alpha');
  7575. mask.setAttribute('id', layerId + '_' + count);
  7576. mask.appendChild(path);
  7577. defs.appendChild(mask);
  7578. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + layerId + '_' + count + ')');
  7579. currentMasks.length = 0;
  7580. currentMasks.push(g);
  7581. } else {
  7582. currentMasks.push(path);
  7583. }
  7584. if (properties[i].inv && !this.solidPath) {
  7585. this.solidPath = this.createLayerSolidPath();
  7586. }
  7587. // TODO move this to a factory or to a constructor
  7588. this.viewData[i] = {
  7589. elem: path,
  7590. lastPath: '',
  7591. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7592. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7593. invRect: rect,
  7594. };
  7595. if (!this.viewData[i].prop.k) {
  7596. this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]);
  7597. }
  7598. }
  7599. }
  7600. this.maskElement = createNS(maskType);
  7601. len = currentMasks.length;
  7602. for (i = 0; i < len; i += 1) {
  7603. this.maskElement.appendChild(currentMasks[i]);
  7604. }
  7605. if (count > 0) {
  7606. this.maskElement.setAttribute('id', layerId);
  7607. this.element.maskedElement.setAttribute(maskRef, 'url(' + getLocationHref() + '#' + layerId + ')');
  7608. defs.appendChild(this.maskElement);
  7609. }
  7610. if (this.viewData.length) {
  7611. this.element.addRenderableComponent(this);
  7612. }
  7613. }
  7614. MaskElement.prototype.getMaskProperty = function (pos) {
  7615. return this.viewData[pos].prop;
  7616. };
  7617. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  7618. var finalMat = this.element.finalTransform.mat;
  7619. var i;
  7620. var len = this.masksProperties.length;
  7621. for (i = 0; i < len; i += 1) {
  7622. if (this.viewData[i].prop._mdf || isFirstFrame) {
  7623. this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]);
  7624. }
  7625. if (this.viewData[i].op._mdf || isFirstFrame) {
  7626. this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v);
  7627. }
  7628. if (this.masksProperties[i].mode !== 'n') {
  7629. if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) {
  7630. this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS());
  7631. }
  7632. if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) {
  7633. var feMorph = this.storedData[i].expan;
  7634. if (this.storedData[i].x.v < 0) {
  7635. if (this.storedData[i].lastOperator !== 'erode') {
  7636. this.storedData[i].lastOperator = 'erode';
  7637. this.storedData[i].elem.setAttribute('filter', 'url(' + getLocationHref() + '#' + this.storedData[i].filterId + ')');
  7638. }
  7639. feMorph.setAttribute('radius', -this.storedData[i].x.v);
  7640. } else {
  7641. if (this.storedData[i].lastOperator !== 'dilate') {
  7642. this.storedData[i].lastOperator = 'dilate';
  7643. this.storedData[i].elem.setAttribute('filter', null);
  7644. }
  7645. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2);
  7646. }
  7647. }
  7648. }
  7649. }
  7650. };
  7651. MaskElement.prototype.getMaskelement = function () {
  7652. return this.maskElement;
  7653. };
  7654. MaskElement.prototype.createLayerSolidPath = function () {
  7655. var path = 'M0,0 ';
  7656. path += ' h' + this.globalData.compSize.w;
  7657. path += ' v' + this.globalData.compSize.h;
  7658. path += ' h-' + this.globalData.compSize.w;
  7659. path += ' v-' + this.globalData.compSize.h + ' ';
  7660. return path;
  7661. };
  7662. MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) {
  7663. var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7664. var i;
  7665. var len;
  7666. len = pathNodes._length;
  7667. for (i = 1; i < len; i += 1) {
  7668. // 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];
  7669. 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];
  7670. }
  7671. // 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];
  7672. if (pathNodes.c && len > 1) {
  7673. 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];
  7674. }
  7675. // pathNodes.__renderedString = pathString;
  7676. if (viewData.lastPath !== pathString) {
  7677. var pathShapeValue = '';
  7678. if (viewData.elem) {
  7679. if (pathNodes.c) {
  7680. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  7681. }
  7682. viewData.elem.setAttribute('d', pathShapeValue);
  7683. }
  7684. viewData.lastPath = pathString;
  7685. }
  7686. };
  7687. MaskElement.prototype.destroy = function () {
  7688. this.element = null;
  7689. this.globalData = null;
  7690. this.maskElement = null;
  7691. this.data = null;
  7692. this.masksProperties = null;
  7693. };
  7694. const filtersFactory = (function () {
  7695. var ob = {};
  7696. ob.createFilter = createFilter;
  7697. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  7698. function createFilter(filId, skipCoordinates) {
  7699. var fil = createNS('filter');
  7700. fil.setAttribute('id', filId);
  7701. if (skipCoordinates !== true) {
  7702. fil.setAttribute('filterUnits', 'objectBoundingBox');
  7703. fil.setAttribute('x', '0%');
  7704. fil.setAttribute('y', '0%');
  7705. fil.setAttribute('width', '100%');
  7706. fil.setAttribute('height', '100%');
  7707. }
  7708. return fil;
  7709. }
  7710. function createAlphaToLuminanceFilter() {
  7711. var feColorMatrix = createNS('feColorMatrix');
  7712. feColorMatrix.setAttribute('type', 'matrix');
  7713. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  7714. feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  7715. return feColorMatrix;
  7716. }
  7717. return ob;
  7718. }());
  7719. const featureSupport = (function () {
  7720. var ob = {
  7721. maskType: true,
  7722. };
  7723. 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)) {
  7724. ob.maskType = false;
  7725. }
  7726. return ob;
  7727. }());
  7728. var registeredEffects = {};
  7729. var idPrefix = 'filter_result_';
  7730. function SVGEffects(elem) {
  7731. var i;
  7732. var source = 'SourceGraphic';
  7733. var len = elem.data.ef ? elem.data.ef.length : 0;
  7734. var filId = createElementID();
  7735. var fil = filtersFactory.createFilter(filId, true);
  7736. var count = 0;
  7737. this.filters = [];
  7738. var filterManager;
  7739. for (i = 0; i < len; i += 1) {
  7740. filterManager = null;
  7741. var type = elem.data.ef[i].ty;
  7742. if (registeredEffects[type]) {
  7743. var Effect = registeredEffects[type].effect;
  7744. filterManager = new Effect(fil, elem.effectsManager.effectElements[i], elem, idPrefix + count, source);
  7745. source = idPrefix + count;
  7746. if (registeredEffects[type].countsAsEffect) {
  7747. count += 1;
  7748. }
  7749. }
  7750. if (filterManager) {
  7751. this.filters.push(filterManager);
  7752. }
  7753. }
  7754. if (count) {
  7755. elem.globalData.defs.appendChild(fil);
  7756. elem.layerElement.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7757. }
  7758. if (this.filters.length) {
  7759. elem.addRenderableComponent(this);
  7760. }
  7761. }
  7762. SVGEffects.prototype.renderFrame = function (_isFirstFrame) {
  7763. var i;
  7764. var len = this.filters.length;
  7765. for (i = 0; i < len; i += 1) {
  7766. this.filters[i].renderFrame(_isFirstFrame);
  7767. }
  7768. };
  7769. function registerEffect(id, effect, countsAsEffect) {
  7770. registeredEffects[id] = {
  7771. effect,
  7772. countsAsEffect,
  7773. };
  7774. }
  7775. function SVGBaseElement() {
  7776. }
  7777. SVGBaseElement.prototype = {
  7778. initRendererElement: function () {
  7779. this.layerElement = createNS('g');
  7780. },
  7781. createContainerElements: function () {
  7782. this.matteElement = createNS('g');
  7783. this.transformedElement = this.layerElement;
  7784. this.maskedElement = this.layerElement;
  7785. this._sizeChanged = false;
  7786. var layerElementParent = null;
  7787. // If this layer acts as a mask for the following layer
  7788. var filId;
  7789. var fil;
  7790. var gg;
  7791. if (this.data.td) {
  7792. if (this.data.td == 3 || this.data.td == 1) { // eslint-disable-line eqeqeq
  7793. var masker = createNS('mask');
  7794. masker.setAttribute('id', this.layerId);
  7795. masker.setAttribute('mask-type', this.data.td == 3 ? 'luminance' : 'alpha'); // eslint-disable-line eqeqeq
  7796. masker.appendChild(this.layerElement);
  7797. layerElementParent = masker;
  7798. this.globalData.defs.appendChild(masker);
  7799. // This is only for IE and Edge when mask if of type alpha
  7800. if (!featureSupport.maskType && this.data.td == 1) { // eslint-disable-line eqeqeq
  7801. masker.setAttribute('mask-type', 'luminance');
  7802. filId = createElementID();
  7803. fil = filtersFactory.createFilter(filId);
  7804. this.globalData.defs.appendChild(fil);
  7805. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7806. gg = createNS('g');
  7807. gg.appendChild(this.layerElement);
  7808. layerElementParent = gg;
  7809. masker.appendChild(gg);
  7810. gg.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7811. }
  7812. } else if (this.data.td == 2) { // eslint-disable-line eqeqeq
  7813. var maskGroup = createNS('mask');
  7814. maskGroup.setAttribute('id', this.layerId);
  7815. maskGroup.setAttribute('mask-type', 'alpha');
  7816. var maskGrouper = createNS('g');
  7817. maskGroup.appendChild(maskGrouper);
  7818. filId = createElementID();
  7819. fil = filtersFactory.createFilter(filId);
  7820. /// /
  7821. // This solution doesn't work on Android when meta tag with viewport attribute is set
  7822. /* var feColorMatrix = createNS('feColorMatrix');
  7823. feColorMatrix.setAttribute('type', 'matrix');
  7824. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  7825. feColorMatrix.setAttribute('values','1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 -1 1');
  7826. fil.appendChild(feColorMatrix); */
  7827. /// /
  7828. var feCTr = createNS('feComponentTransfer');
  7829. feCTr.setAttribute('in', 'SourceGraphic');
  7830. fil.appendChild(feCTr);
  7831. var feFunc = createNS('feFuncA');
  7832. feFunc.setAttribute('type', 'table');
  7833. feFunc.setAttribute('tableValues', '1.0 0.0');
  7834. feCTr.appendChild(feFunc);
  7835. /// /
  7836. this.globalData.defs.appendChild(fil);
  7837. var alphaRect = createNS('rect');
  7838. alphaRect.setAttribute('width', this.comp.data.w);
  7839. alphaRect.setAttribute('height', this.comp.data.h);
  7840. alphaRect.setAttribute('x', '0');
  7841. alphaRect.setAttribute('y', '0');
  7842. alphaRect.setAttribute('fill', '#ffffff');
  7843. alphaRect.setAttribute('opacity', '0');
  7844. maskGrouper.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7845. maskGrouper.appendChild(alphaRect);
  7846. maskGrouper.appendChild(this.layerElement);
  7847. layerElementParent = maskGrouper;
  7848. if (!featureSupport.maskType) {
  7849. maskGroup.setAttribute('mask-type', 'luminance');
  7850. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7851. gg = createNS('g');
  7852. maskGrouper.appendChild(alphaRect);
  7853. gg.appendChild(this.layerElement);
  7854. layerElementParent = gg;
  7855. maskGrouper.appendChild(gg);
  7856. }
  7857. this.globalData.defs.appendChild(maskGroup);
  7858. }
  7859. } else if (this.data.tt) {
  7860. this.matteElement.appendChild(this.layerElement);
  7861. layerElementParent = this.matteElement;
  7862. this.baseElement = this.matteElement;
  7863. } else {
  7864. this.baseElement = this.layerElement;
  7865. }
  7866. if (this.data.ln) {
  7867. this.layerElement.setAttribute('id', this.data.ln);
  7868. }
  7869. if (this.data.cl) {
  7870. this.layerElement.setAttribute('class', this.data.cl);
  7871. }
  7872. // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  7873. if (this.data.ty === 0 && !this.data.hd) {
  7874. var cp = createNS('clipPath');
  7875. var pt = createNS('path');
  7876. pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  7877. var clipId = createElementID();
  7878. cp.setAttribute('id', clipId);
  7879. cp.appendChild(pt);
  7880. this.globalData.defs.appendChild(cp);
  7881. if (this.checkMasks()) {
  7882. var cpGroup = createNS('g');
  7883. cpGroup.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7884. cpGroup.appendChild(this.layerElement);
  7885. this.transformedElement = cpGroup;
  7886. if (layerElementParent) {
  7887. layerElementParent.appendChild(this.transformedElement);
  7888. } else {
  7889. this.baseElement = this.transformedElement;
  7890. }
  7891. } else {
  7892. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7893. }
  7894. }
  7895. if (this.data.bm !== 0) {
  7896. this.setBlendMode();
  7897. }
  7898. },
  7899. renderElement: function () {
  7900. if (this.finalTransform._matMdf) {
  7901. this.transformedElement.setAttribute('transform', this.finalTransform.mat.to2dCSS());
  7902. }
  7903. if (this.finalTransform._opMdf) {
  7904. this.transformedElement.setAttribute('opacity', this.finalTransform.mProp.o.v);
  7905. }
  7906. },
  7907. destroyBaseElement: function () {
  7908. this.layerElement = null;
  7909. this.matteElement = null;
  7910. this.maskManager.destroy();
  7911. },
  7912. getBaseElement: function () {
  7913. if (this.data.hd) {
  7914. return null;
  7915. }
  7916. return this.baseElement;
  7917. },
  7918. createRenderableComponents: function () {
  7919. this.maskManager = new MaskElement(this.data, this, this.globalData);
  7920. this.renderableEffectsManager = new SVGEffects(this);
  7921. },
  7922. setMatte: function (id) {
  7923. if (!this.matteElement) {
  7924. return;
  7925. }
  7926. this.matteElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  7927. },
  7928. };
  7929. /**
  7930. * @file
  7931. * Handles AE's layer parenting property.
  7932. *
  7933. */
  7934. function HierarchyElement() {}
  7935. HierarchyElement.prototype = {
  7936. /**
  7937. * @function
  7938. * Initializes hierarchy properties
  7939. *
  7940. */
  7941. initHierarchy: function () {
  7942. // element's parent list
  7943. this.hierarchy = [];
  7944. // if element is parent of another layer _isParent will be true
  7945. this._isParent = false;
  7946. this.checkParenting();
  7947. },
  7948. /**
  7949. * @function
  7950. * Sets layer's hierarchy.
  7951. * @param {array} hierarch
  7952. * layer's parent list
  7953. *
  7954. */
  7955. setHierarchy: function (hierarchy) {
  7956. this.hierarchy = hierarchy;
  7957. },
  7958. /**
  7959. * @function
  7960. * Sets layer as parent.
  7961. *
  7962. */
  7963. setAsParent: function () {
  7964. this._isParent = true;
  7965. },
  7966. /**
  7967. * @function
  7968. * Searches layer's parenting chain
  7969. *
  7970. */
  7971. checkParenting: function () {
  7972. if (this.data.parent !== undefined) {
  7973. this.comp.buildElementParenting(this, this.data.parent, []);
  7974. }
  7975. },
  7976. };
  7977. function RenderableDOMElement() {}
  7978. (function () {
  7979. var _prototype = {
  7980. initElement: function (data, globalData, comp) {
  7981. this.initFrame();
  7982. this.initBaseData(data, globalData, comp);
  7983. this.initTransform(data, globalData, comp);
  7984. this.initHierarchy();
  7985. this.initRenderable();
  7986. this.initRendererElement();
  7987. this.createContainerElements();
  7988. this.createRenderableComponents();
  7989. this.createContent();
  7990. this.hide();
  7991. },
  7992. hide: function () {
  7993. // console.log('HIDE', this);
  7994. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7995. var elem = this.baseElement || this.layerElement;
  7996. elem.style.display = 'none';
  7997. this.hidden = true;
  7998. }
  7999. },
  8000. show: function () {
  8001. // console.log('SHOW', this);
  8002. if (this.isInRange && !this.isTransparent) {
  8003. if (!this.data.hd) {
  8004. var elem = this.baseElement || this.layerElement;
  8005. elem.style.display = 'block';
  8006. }
  8007. this.hidden = false;
  8008. this._isFirstFrame = true;
  8009. }
  8010. },
  8011. renderFrame: function () {
  8012. // If it is exported as hidden (data.hd === true) no need to render
  8013. // If it is not visible no need to render
  8014. if (this.data.hd || this.hidden) {
  8015. return;
  8016. }
  8017. this.renderTransform();
  8018. this.renderRenderable();
  8019. this.renderElement();
  8020. this.renderInnerContent();
  8021. if (this._isFirstFrame) {
  8022. this._isFirstFrame = false;
  8023. }
  8024. },
  8025. renderInnerContent: function () {},
  8026. prepareFrame: function (num) {
  8027. this._mdf = false;
  8028. this.prepareRenderableFrame(num);
  8029. this.prepareProperties(num, this.isInRange);
  8030. this.checkTransparency();
  8031. },
  8032. destroy: function () {
  8033. this.innerElem = null;
  8034. this.destroyBaseElement();
  8035. },
  8036. };
  8037. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  8038. }());
  8039. function IImageElement(data, globalData, comp) {
  8040. this.assetData = globalData.getAssetData(data.refId);
  8041. this.initElement(data, globalData, comp);
  8042. this.sourceRect = {
  8043. top: 0, left: 0, width: this.assetData.w, height: this.assetData.h,
  8044. };
  8045. }
  8046. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement);
  8047. IImageElement.prototype.createContent = function () {
  8048. var assetPath = this.globalData.getAssetsPath(this.assetData);
  8049. this.innerElem = createNS('image');
  8050. this.innerElem.setAttribute('width', this.assetData.w + 'px');
  8051. this.innerElem.setAttribute('height', this.assetData.h + 'px');
  8052. this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  8053. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  8054. this.layerElement.appendChild(this.innerElem);
  8055. };
  8056. IImageElement.prototype.sourceRectAtTime = function () {
  8057. return this.sourceRect;
  8058. };
  8059. function ProcessedElement(element, position) {
  8060. this.elem = element;
  8061. this.pos = position;
  8062. }
  8063. function IShapeElement() {
  8064. }
  8065. IShapeElement.prototype = {
  8066. addShapeToModifiers: function (data) {
  8067. var i;
  8068. var len = this.shapeModifiers.length;
  8069. for (i = 0; i < len; i += 1) {
  8070. this.shapeModifiers[i].addShape(data);
  8071. }
  8072. },
  8073. isShapeInAnimatedModifiers: function (data) {
  8074. var i = 0;
  8075. var len = this.shapeModifiers.length;
  8076. while (i < len) {
  8077. if (this.shapeModifiers[i].isAnimatedWithShape(data)) {
  8078. return true;
  8079. }
  8080. }
  8081. return false;
  8082. },
  8083. renderModifiers: function () {
  8084. if (!this.shapeModifiers.length) {
  8085. return;
  8086. }
  8087. var i;
  8088. var len = this.shapes.length;
  8089. for (i = 0; i < len; i += 1) {
  8090. this.shapes[i].sh.reset();
  8091. }
  8092. len = this.shapeModifiers.length;
  8093. var shouldBreakProcess;
  8094. for (i = len - 1; i >= 0; i -= 1) {
  8095. shouldBreakProcess = this.shapeModifiers[i].processShapes(this._isFirstFrame);
  8096. // workaround to fix cases where a repeater resets the shape so the following processes get called twice
  8097. // TODO: find a better solution for this
  8098. if (shouldBreakProcess) {
  8099. break;
  8100. }
  8101. }
  8102. },
  8103. searchProcessedElement: function (elem) {
  8104. var elements = this.processedElements;
  8105. var i = 0;
  8106. var len = elements.length;
  8107. while (i < len) {
  8108. if (elements[i].elem === elem) {
  8109. return elements[i].pos;
  8110. }
  8111. i += 1;
  8112. }
  8113. return 0;
  8114. },
  8115. addProcessedElement: function (elem, pos) {
  8116. var elements = this.processedElements;
  8117. var i = elements.length;
  8118. while (i) {
  8119. i -= 1;
  8120. if (elements[i].elem === elem) {
  8121. elements[i].pos = pos;
  8122. return;
  8123. }
  8124. }
  8125. elements.push(new ProcessedElement(elem, pos));
  8126. },
  8127. prepareFrame: function (num) {
  8128. this.prepareRenderableFrame(num);
  8129. this.prepareProperties(num, this.isInRange);
  8130. },
  8131. };
  8132. const lineCapEnum = {
  8133. 1: 'butt',
  8134. 2: 'round',
  8135. 3: 'square',
  8136. };
  8137. const lineJoinEnum = {
  8138. 1: 'miter',
  8139. 2: 'round',
  8140. 3: 'bevel',
  8141. };
  8142. function SVGShapeData(transformers, level, shape) {
  8143. this.caches = [];
  8144. this.styles = [];
  8145. this.transformers = transformers;
  8146. this.lStr = '';
  8147. this.sh = shape;
  8148. this.lvl = level;
  8149. // TODO find if there are some cases where _isAnimated can be false.
  8150. // For now, since shapes add up with other shapes. They have to be calculated every time.
  8151. // One way of finding out is checking if all styles associated to this shape depend only of this shape
  8152. this._isAnimated = !!shape.k;
  8153. // TODO: commenting this for now since all shapes are animated
  8154. var i = 0;
  8155. var len = transformers.length;
  8156. while (i < len) {
  8157. if (transformers[i].mProps.dynamicProperties.length) {
  8158. this._isAnimated = true;
  8159. break;
  8160. }
  8161. i += 1;
  8162. }
  8163. }
  8164. SVGShapeData.prototype.setAsAnimated = function () {
  8165. this._isAnimated = true;
  8166. };
  8167. function SVGStyleData(data, level) {
  8168. this.data = data;
  8169. this.type = data.ty;
  8170. this.d = '';
  8171. this.lvl = level;
  8172. this._mdf = false;
  8173. this.closed = data.hd === true;
  8174. this.pElem = createNS('path');
  8175. this.msElem = null;
  8176. }
  8177. SVGStyleData.prototype.reset = function () {
  8178. this.d = '';
  8179. this._mdf = false;
  8180. };
  8181. function DashProperty(elem, data, renderer, container) {
  8182. this.elem = elem;
  8183. this.frameId = -1;
  8184. this.dataProps = createSizedArray(data.length);
  8185. this.renderer = renderer;
  8186. this.k = false;
  8187. this.dashStr = '';
  8188. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  8189. this.dashoffset = createTypedArray('float32', 1);
  8190. this.initDynamicPropertyContainer(container);
  8191. var i;
  8192. var len = data.length || 0;
  8193. var prop;
  8194. for (i = 0; i < len; i += 1) {
  8195. prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this);
  8196. this.k = prop.k || this.k;
  8197. this.dataProps[i] = { n: data[i].n, p: prop };
  8198. }
  8199. if (!this.k) {
  8200. this.getValue(true);
  8201. }
  8202. this._isAnimated = this.k;
  8203. }
  8204. DashProperty.prototype.getValue = function (forceRender) {
  8205. if (this.elem.globalData.frameId === this.frameId && !forceRender) {
  8206. return;
  8207. }
  8208. this.frameId = this.elem.globalData.frameId;
  8209. this.iterateDynamicProperties();
  8210. this._mdf = this._mdf || forceRender;
  8211. if (this._mdf) {
  8212. var i = 0;
  8213. var len = this.dataProps.length;
  8214. if (this.renderer === 'svg') {
  8215. this.dashStr = '';
  8216. }
  8217. for (i = 0; i < len; i += 1) {
  8218. if (this.dataProps[i].n !== 'o') {
  8219. if (this.renderer === 'svg') {
  8220. this.dashStr += ' ' + this.dataProps[i].p.v;
  8221. } else {
  8222. this.dashArray[i] = this.dataProps[i].p.v;
  8223. }
  8224. } else {
  8225. this.dashoffset[0] = this.dataProps[i].p.v;
  8226. }
  8227. }
  8228. }
  8229. };
  8230. extendPrototype([DynamicPropertyContainer], DashProperty);
  8231. function SVGStrokeStyleData(elem, data, styleOb) {
  8232. this.initDynamicPropertyContainer(elem);
  8233. this.getValue = this.iterateDynamicProperties;
  8234. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  8235. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  8236. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  8237. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  8238. this.style = styleOb;
  8239. this._isAnimated = !!this._isAnimated;
  8240. }
  8241. extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData);
  8242. function SVGFillStyleData(elem, data, styleOb) {
  8243. this.initDynamicPropertyContainer(elem);
  8244. this.getValue = this.iterateDynamicProperties;
  8245. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  8246. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  8247. this.style = styleOb;
  8248. }
  8249. extendPrototype([DynamicPropertyContainer], SVGFillStyleData);
  8250. function SVGNoStyleData(elem, data, styleOb) {
  8251. this.initDynamicPropertyContainer(elem);
  8252. this.getValue = this.iterateDynamicProperties;
  8253. this.style = styleOb;
  8254. }
  8255. extendPrototype([DynamicPropertyContainer], SVGNoStyleData);
  8256. function GradientProperty(elem, data, container) {
  8257. this.data = data;
  8258. this.c = createTypedArray('uint8c', data.p * 4);
  8259. var cLength = data.k.k[0].s ? (data.k.k[0].s.length - data.p * 4) : data.k.k.length - data.p * 4;
  8260. this.o = createTypedArray('float32', cLength);
  8261. this._cmdf = false;
  8262. this._omdf = false;
  8263. this._collapsable = this.checkCollapsable();
  8264. this._hasOpacity = cLength;
  8265. this.initDynamicPropertyContainer(container);
  8266. this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this);
  8267. this.k = this.prop.k;
  8268. this.getValue(true);
  8269. }
  8270. GradientProperty.prototype.comparePoints = function (values, points) {
  8271. var i = 0;
  8272. var len = this.o.length / 2;
  8273. var diff;
  8274. while (i < len) {
  8275. diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]);
  8276. if (diff > 0.01) {
  8277. return false;
  8278. }
  8279. i += 1;
  8280. }
  8281. return true;
  8282. };
  8283. GradientProperty.prototype.checkCollapsable = function () {
  8284. if (this.o.length / 2 !== this.c.length / 4) {
  8285. return false;
  8286. }
  8287. if (this.data.k.k[0].s) {
  8288. var i = 0;
  8289. var len = this.data.k.k.length;
  8290. while (i < len) {
  8291. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  8292. return false;
  8293. }
  8294. i += 1;
  8295. }
  8296. } else if (!this.comparePoints(this.data.k.k, this.data.p)) {
  8297. return false;
  8298. }
  8299. return true;
  8300. };
  8301. GradientProperty.prototype.getValue = function (forceRender) {
  8302. this.prop.getValue();
  8303. this._mdf = false;
  8304. this._cmdf = false;
  8305. this._omdf = false;
  8306. if (this.prop._mdf || forceRender) {
  8307. var i;
  8308. var len = this.data.p * 4;
  8309. var mult;
  8310. var val;
  8311. for (i = 0; i < len; i += 1) {
  8312. mult = i % 4 === 0 ? 100 : 255;
  8313. val = Math.round(this.prop.v[i] * mult);
  8314. if (this.c[i] !== val) {
  8315. this.c[i] = val;
  8316. this._cmdf = !forceRender;
  8317. }
  8318. }
  8319. if (this.o.length) {
  8320. len = this.prop.v.length;
  8321. for (i = this.data.p * 4; i < len; i += 1) {
  8322. mult = i % 2 === 0 ? 100 : 1;
  8323. val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i];
  8324. if (this.o[i - this.data.p * 4] !== val) {
  8325. this.o[i - this.data.p * 4] = val;
  8326. this._omdf = !forceRender;
  8327. }
  8328. }
  8329. }
  8330. this._mdf = !forceRender;
  8331. }
  8332. };
  8333. extendPrototype([DynamicPropertyContainer], GradientProperty);
  8334. function SVGGradientFillStyleData(elem, data, styleOb) {
  8335. this.initDynamicPropertyContainer(elem);
  8336. this.getValue = this.iterateDynamicProperties;
  8337. this.initGradientData(elem, data, styleOb);
  8338. }
  8339. SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) {
  8340. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  8341. this.s = PropertyFactory.getProp(elem, data.s, 1, null, this);
  8342. this.e = PropertyFactory.getProp(elem, data.e, 1, null, this);
  8343. this.h = PropertyFactory.getProp(elem, data.h || { k: 0 }, 0, 0.01, this);
  8344. this.a = PropertyFactory.getProp(elem, data.a || { k: 0 }, 0, degToRads, this);
  8345. this.g = new GradientProperty(elem, data.g, this);
  8346. this.style = styleOb;
  8347. this.stops = [];
  8348. this.setGradientData(styleOb.pElem, data);
  8349. this.setGradientOpacity(data, styleOb);
  8350. this._isAnimated = !!this._isAnimated;
  8351. };
  8352. SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) {
  8353. var gradientId = createElementID();
  8354. var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8355. gfill.setAttribute('id', gradientId);
  8356. gfill.setAttribute('spreadMethod', 'pad');
  8357. gfill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8358. var stops = [];
  8359. var stop;
  8360. var j;
  8361. var jLen;
  8362. jLen = data.g.p * 4;
  8363. for (j = 0; j < jLen; j += 4) {
  8364. stop = createNS('stop');
  8365. gfill.appendChild(stop);
  8366. stops.push(stop);
  8367. }
  8368. pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + gradientId + ')');
  8369. this.gf = gfill;
  8370. this.cst = stops;
  8371. };
  8372. SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) {
  8373. if (this.g._hasOpacity && !this.g._collapsable) {
  8374. var stop;
  8375. var j;
  8376. var jLen;
  8377. var mask = createNS('mask');
  8378. var maskElement = createNS('path');
  8379. mask.appendChild(maskElement);
  8380. var opacityId = createElementID();
  8381. var maskId = createElementID();
  8382. mask.setAttribute('id', maskId);
  8383. var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8384. opFill.setAttribute('id', opacityId);
  8385. opFill.setAttribute('spreadMethod', 'pad');
  8386. opFill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8387. jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length;
  8388. var stops = this.stops;
  8389. for (j = data.g.p * 4; j < jLen; j += 2) {
  8390. stop = createNS('stop');
  8391. stop.setAttribute('stop-color', 'rgb(255,255,255)');
  8392. opFill.appendChild(stop);
  8393. stops.push(stop);
  8394. }
  8395. maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + opacityId + ')');
  8396. if (data.ty === 'gs') {
  8397. maskElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8398. maskElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8399. if (data.lj === 1) {
  8400. maskElement.setAttribute('stroke-miterlimit', data.ml);
  8401. }
  8402. }
  8403. this.of = opFill;
  8404. this.ms = mask;
  8405. this.ost = stops;
  8406. this.maskId = maskId;
  8407. styleOb.msElem = maskElement;
  8408. }
  8409. };
  8410. extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData);
  8411. function SVGGradientStrokeStyleData(elem, data, styleOb) {
  8412. this.initDynamicPropertyContainer(elem);
  8413. this.getValue = this.iterateDynamicProperties;
  8414. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  8415. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  8416. this.initGradientData(elem, data, styleOb);
  8417. this._isAnimated = !!this._isAnimated;
  8418. }
  8419. extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData);
  8420. function ShapeGroupData() {
  8421. this.it = [];
  8422. this.prevViewData = [];
  8423. this.gr = createNS('g');
  8424. }
  8425. function SVGTransformData(mProps, op, container) {
  8426. this.transform = {
  8427. mProps: mProps,
  8428. op: op,
  8429. container: container,
  8430. };
  8431. this.elements = [];
  8432. this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length;
  8433. }
  8434. const buildShapeString = function (pathNodes, length, closed, mat) {
  8435. if (length === 0) {
  8436. return '';
  8437. }
  8438. var _o = pathNodes.o;
  8439. var _i = pathNodes.i;
  8440. var _v = pathNodes.v;
  8441. var i;
  8442. var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8443. for (i = 1; i < length; i += 1) {
  8444. 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]);
  8445. }
  8446. if (closed && length) {
  8447. 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]);
  8448. shapeString += 'z';
  8449. }
  8450. return shapeString;
  8451. };
  8452. const SVGElementsRenderer = (function () {
  8453. var _identityMatrix = new Matrix();
  8454. var _matrixHelper = new Matrix();
  8455. var ob = {
  8456. createRenderFunction: createRenderFunction,
  8457. };
  8458. function createRenderFunction(data) {
  8459. switch (data.ty) {
  8460. case 'fl':
  8461. return renderFill;
  8462. case 'gf':
  8463. return renderGradient;
  8464. case 'gs':
  8465. return renderGradientStroke;
  8466. case 'st':
  8467. return renderStroke;
  8468. case 'sh':
  8469. case 'el':
  8470. case 'rc':
  8471. case 'sr':
  8472. return renderPath;
  8473. case 'tr':
  8474. return renderContentTransform;
  8475. case 'no':
  8476. return renderNoop;
  8477. default:
  8478. return null;
  8479. }
  8480. }
  8481. function renderContentTransform(styleData, itemData, isFirstFrame) {
  8482. if (isFirstFrame || itemData.transform.op._mdf) {
  8483. itemData.transform.container.setAttribute('opacity', itemData.transform.op.v);
  8484. }
  8485. if (isFirstFrame || itemData.transform.mProps._mdf) {
  8486. itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS());
  8487. }
  8488. }
  8489. function renderNoop() {
  8490. }
  8491. function renderPath(styleData, itemData, isFirstFrame) {
  8492. var j;
  8493. var jLen;
  8494. var pathStringTransformed;
  8495. var redraw;
  8496. var pathNodes;
  8497. var l;
  8498. var lLen = itemData.styles.length;
  8499. var lvl = itemData.lvl;
  8500. var paths;
  8501. var mat;
  8502. var props;
  8503. var iterations;
  8504. var k;
  8505. for (l = 0; l < lLen; l += 1) {
  8506. redraw = itemData.sh._mdf || isFirstFrame;
  8507. if (itemData.styles[l].lvl < lvl) {
  8508. mat = _matrixHelper.reset();
  8509. iterations = lvl - itemData.styles[l].lvl;
  8510. k = itemData.transformers.length - 1;
  8511. while (!redraw && iterations > 0) {
  8512. redraw = itemData.transformers[k].mProps._mdf || redraw;
  8513. iterations -= 1;
  8514. k -= 1;
  8515. }
  8516. if (redraw) {
  8517. iterations = lvl - itemData.styles[l].lvl;
  8518. k = itemData.transformers.length - 1;
  8519. while (iterations > 0) {
  8520. props = itemData.transformers[k].mProps.v.props;
  8521. mat.transform(props[0], props[1], props[2], props[3], props[4], props[5], props[6], props[7], props[8], props[9], props[10], props[11], props[12], props[13], props[14], props[15]);
  8522. iterations -= 1;
  8523. k -= 1;
  8524. }
  8525. }
  8526. } else {
  8527. mat = _identityMatrix;
  8528. }
  8529. paths = itemData.sh.paths;
  8530. jLen = paths._length;
  8531. if (redraw) {
  8532. pathStringTransformed = '';
  8533. for (j = 0; j < jLen; j += 1) {
  8534. pathNodes = paths.shapes[j];
  8535. if (pathNodes && pathNodes._length) {
  8536. pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat);
  8537. }
  8538. }
  8539. itemData.caches[l] = pathStringTransformed;
  8540. } else {
  8541. pathStringTransformed = itemData.caches[l];
  8542. }
  8543. itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed;
  8544. itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf;
  8545. }
  8546. }
  8547. function renderFill(styleData, itemData, isFirstFrame) {
  8548. var styleElem = itemData.style;
  8549. if (itemData.c._mdf || isFirstFrame) {
  8550. styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8551. }
  8552. if (itemData.o._mdf || isFirstFrame) {
  8553. styleElem.pElem.setAttribute('fill-opacity', itemData.o.v);
  8554. }
  8555. }
  8556. function renderGradientStroke(styleData, itemData, isFirstFrame) {
  8557. renderGradient(styleData, itemData, isFirstFrame);
  8558. renderStroke(styleData, itemData, isFirstFrame);
  8559. }
  8560. function renderGradient(styleData, itemData, isFirstFrame) {
  8561. var gfill = itemData.gf;
  8562. var hasOpacity = itemData.g._hasOpacity;
  8563. var pt1 = itemData.s.v;
  8564. var pt2 = itemData.e.v;
  8565. if (itemData.o._mdf || isFirstFrame) {
  8566. var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity';
  8567. itemData.style.pElem.setAttribute(attr, itemData.o.v);
  8568. }
  8569. if (itemData.s._mdf || isFirstFrame) {
  8570. var attr1 = styleData.t === 1 ? 'x1' : 'cx';
  8571. var attr2 = attr1 === 'x1' ? 'y1' : 'cy';
  8572. gfill.setAttribute(attr1, pt1[0]);
  8573. gfill.setAttribute(attr2, pt1[1]);
  8574. if (hasOpacity && !itemData.g._collapsable) {
  8575. itemData.of.setAttribute(attr1, pt1[0]);
  8576. itemData.of.setAttribute(attr2, pt1[1]);
  8577. }
  8578. }
  8579. var stops;
  8580. var i;
  8581. var len;
  8582. var stop;
  8583. if (itemData.g._cmdf || isFirstFrame) {
  8584. stops = itemData.cst;
  8585. var cValues = itemData.g.c;
  8586. len = stops.length;
  8587. for (i = 0; i < len; i += 1) {
  8588. stop = stops[i];
  8589. stop.setAttribute('offset', cValues[i * 4] + '%');
  8590. stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')');
  8591. }
  8592. }
  8593. if (hasOpacity && (itemData.g._omdf || isFirstFrame)) {
  8594. var oValues = itemData.g.o;
  8595. if (itemData.g._collapsable) {
  8596. stops = itemData.cst;
  8597. } else {
  8598. stops = itemData.ost;
  8599. }
  8600. len = stops.length;
  8601. for (i = 0; i < len; i += 1) {
  8602. stop = stops[i];
  8603. if (!itemData.g._collapsable) {
  8604. stop.setAttribute('offset', oValues[i * 2] + '%');
  8605. }
  8606. stop.setAttribute('stop-opacity', oValues[i * 2 + 1]);
  8607. }
  8608. }
  8609. if (styleData.t === 1) {
  8610. if (itemData.e._mdf || isFirstFrame) {
  8611. gfill.setAttribute('x2', pt2[0]);
  8612. gfill.setAttribute('y2', pt2[1]);
  8613. if (hasOpacity && !itemData.g._collapsable) {
  8614. itemData.of.setAttribute('x2', pt2[0]);
  8615. itemData.of.setAttribute('y2', pt2[1]);
  8616. }
  8617. }
  8618. } else {
  8619. var rad;
  8620. if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) {
  8621. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8622. gfill.setAttribute('r', rad);
  8623. if (hasOpacity && !itemData.g._collapsable) {
  8624. itemData.of.setAttribute('r', rad);
  8625. }
  8626. }
  8627. if (itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) {
  8628. if (!rad) {
  8629. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8630. }
  8631. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  8632. var percent = itemData.h.v;
  8633. if (percent >= 1) {
  8634. percent = 0.99;
  8635. } else if (percent <= -1) {
  8636. percent = -0.99;
  8637. }
  8638. var dist = rad * percent;
  8639. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  8640. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  8641. gfill.setAttribute('fx', x);
  8642. gfill.setAttribute('fy', y);
  8643. if (hasOpacity && !itemData.g._collapsable) {
  8644. itemData.of.setAttribute('fx', x);
  8645. itemData.of.setAttribute('fy', y);
  8646. }
  8647. }
  8648. // gfill.setAttribute('fy','200');
  8649. }
  8650. }
  8651. function renderStroke(styleData, itemData, isFirstFrame) {
  8652. var styleElem = itemData.style;
  8653. var d = itemData.d;
  8654. if (d && (d._mdf || isFirstFrame) && d.dashStr) {
  8655. styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr);
  8656. styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]);
  8657. }
  8658. if (itemData.c && (itemData.c._mdf || isFirstFrame)) {
  8659. styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8660. }
  8661. if (itemData.o._mdf || isFirstFrame) {
  8662. styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v);
  8663. }
  8664. if (itemData.w._mdf || isFirstFrame) {
  8665. styleElem.pElem.setAttribute('stroke-width', itemData.w.v);
  8666. if (styleElem.msElem) {
  8667. styleElem.msElem.setAttribute('stroke-width', itemData.w.v);
  8668. }
  8669. }
  8670. }
  8671. return ob;
  8672. }());
  8673. function SVGShapeElement(data, globalData, comp) {
  8674. // List of drawable elements
  8675. this.shapes = [];
  8676. // Full shape data
  8677. this.shapesData = data.shapes;
  8678. // List of styles that will be applied to shapes
  8679. this.stylesList = [];
  8680. // List of modifiers that will be applied to shapes
  8681. this.shapeModifiers = [];
  8682. // List of items in shape tree
  8683. this.itemsData = [];
  8684. // List of items in previous shape tree
  8685. this.processedElements = [];
  8686. // List of animated components
  8687. this.animatedContents = [];
  8688. this.initElement(data, globalData, comp);
  8689. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8690. // List of elements that have been created
  8691. this.prevViewData = [];
  8692. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8693. }
  8694. extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement);
  8695. SVGShapeElement.prototype.initSecondaryElement = function () {
  8696. };
  8697. SVGShapeElement.prototype.identityMatrix = new Matrix();
  8698. SVGShapeElement.prototype.buildExpressionInterface = function () {};
  8699. SVGShapeElement.prototype.createContent = function () {
  8700. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8701. this.filterUniqueShapes();
  8702. };
  8703. /*
  8704. This method searches for multiple shapes that affect a single element and one of them is animated
  8705. */
  8706. SVGShapeElement.prototype.filterUniqueShapes = function () {
  8707. var i;
  8708. var len = this.shapes.length;
  8709. var shape;
  8710. var j;
  8711. var jLen = this.stylesList.length;
  8712. var style;
  8713. var tempShapes = [];
  8714. var areAnimated = false;
  8715. for (j = 0; j < jLen; j += 1) {
  8716. style = this.stylesList[j];
  8717. areAnimated = false;
  8718. tempShapes.length = 0;
  8719. for (i = 0; i < len; i += 1) {
  8720. shape = this.shapes[i];
  8721. if (shape.styles.indexOf(style) !== -1) {
  8722. tempShapes.push(shape);
  8723. areAnimated = shape._isAnimated || areAnimated;
  8724. }
  8725. }
  8726. if (tempShapes.length > 1 && areAnimated) {
  8727. this.setShapesAsAnimated(tempShapes);
  8728. }
  8729. }
  8730. };
  8731. SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) {
  8732. var i;
  8733. var len = shapes.length;
  8734. for (i = 0; i < len; i += 1) {
  8735. shapes[i].setAsAnimated();
  8736. }
  8737. };
  8738. SVGShapeElement.prototype.createStyleElement = function (data, level) {
  8739. // TODO: prevent drawing of hidden styles
  8740. var elementData;
  8741. var styleOb = new SVGStyleData(data, level);
  8742. var pathElement = styleOb.pElem;
  8743. if (data.ty === 'st') {
  8744. elementData = new SVGStrokeStyleData(this, data, styleOb);
  8745. } else if (data.ty === 'fl') {
  8746. elementData = new SVGFillStyleData(this, data, styleOb);
  8747. } else if (data.ty === 'gf' || data.ty === 'gs') {
  8748. var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  8749. elementData = new GradientConstructor(this, data, styleOb);
  8750. this.globalData.defs.appendChild(elementData.gf);
  8751. if (elementData.maskId) {
  8752. this.globalData.defs.appendChild(elementData.ms);
  8753. this.globalData.defs.appendChild(elementData.of);
  8754. pathElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + elementData.maskId + ')');
  8755. }
  8756. } else if (data.ty === 'no') {
  8757. elementData = new SVGNoStyleData(this, data, styleOb);
  8758. }
  8759. if (data.ty === 'st' || data.ty === 'gs') {
  8760. pathElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8761. pathElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8762. pathElement.setAttribute('fill-opacity', '0');
  8763. if (data.lj === 1) {
  8764. pathElement.setAttribute('stroke-miterlimit', data.ml);
  8765. }
  8766. }
  8767. if (data.r === 2) {
  8768. pathElement.setAttribute('fill-rule', 'evenodd');
  8769. }
  8770. if (data.ln) {
  8771. pathElement.setAttribute('id', data.ln);
  8772. }
  8773. if (data.cl) {
  8774. pathElement.setAttribute('class', data.cl);
  8775. }
  8776. if (data.bm) {
  8777. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  8778. }
  8779. this.stylesList.push(styleOb);
  8780. this.addToAnimatedContents(data, elementData);
  8781. return elementData;
  8782. };
  8783. SVGShapeElement.prototype.createGroupElement = function (data) {
  8784. var elementData = new ShapeGroupData();
  8785. if (data.ln) {
  8786. elementData.gr.setAttribute('id', data.ln);
  8787. }
  8788. if (data.cl) {
  8789. elementData.gr.setAttribute('class', data.cl);
  8790. }
  8791. if (data.bm) {
  8792. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  8793. }
  8794. return elementData;
  8795. };
  8796. SVGShapeElement.prototype.createTransformElement = function (data, container) {
  8797. var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this);
  8798. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  8799. this.addToAnimatedContents(data, elementData);
  8800. return elementData;
  8801. };
  8802. SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) {
  8803. var ty = 4;
  8804. if (data.ty === 'rc') {
  8805. ty = 5;
  8806. } else if (data.ty === 'el') {
  8807. ty = 6;
  8808. } else if (data.ty === 'sr') {
  8809. ty = 7;
  8810. }
  8811. var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this);
  8812. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  8813. this.shapes.push(elementData);
  8814. this.addShapeToModifiers(elementData);
  8815. this.addToAnimatedContents(data, elementData);
  8816. return elementData;
  8817. };
  8818. SVGShapeElement.prototype.addToAnimatedContents = function (data, element) {
  8819. var i = 0;
  8820. var len = this.animatedContents.length;
  8821. while (i < len) {
  8822. if (this.animatedContents[i].element === element) {
  8823. return;
  8824. }
  8825. i += 1;
  8826. }
  8827. this.animatedContents.push({
  8828. fn: SVGElementsRenderer.createRenderFunction(data),
  8829. element: element,
  8830. data: data,
  8831. });
  8832. };
  8833. SVGShapeElement.prototype.setElementStyles = function (elementData) {
  8834. var arr = elementData.styles;
  8835. var j;
  8836. var jLen = this.stylesList.length;
  8837. for (j = 0; j < jLen; j += 1) {
  8838. if (!this.stylesList[j].closed) {
  8839. arr.push(this.stylesList[j]);
  8840. }
  8841. }
  8842. };
  8843. SVGShapeElement.prototype.reloadShapes = function () {
  8844. this._isFirstFrame = true;
  8845. var i;
  8846. var len = this.itemsData.length;
  8847. for (i = 0; i < len; i += 1) {
  8848. this.prevViewData[i] = this.itemsData[i];
  8849. }
  8850. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8851. this.filterUniqueShapes();
  8852. len = this.dynamicProperties.length;
  8853. for (i = 0; i < len; i += 1) {
  8854. this.dynamicProperties[i].getValue();
  8855. }
  8856. this.renderModifiers();
  8857. };
  8858. SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) {
  8859. var ownTransformers = [].concat(transformers);
  8860. var i;
  8861. var len = arr.length - 1;
  8862. var j;
  8863. var jLen;
  8864. var ownStyles = [];
  8865. var ownModifiers = [];
  8866. var currentTransform;
  8867. var modifier;
  8868. var processedPos;
  8869. for (i = len; i >= 0; i -= 1) {
  8870. processedPos = this.searchProcessedElement(arr[i]);
  8871. if (!processedPos) {
  8872. arr[i]._render = render;
  8873. } else {
  8874. itemsData[i] = prevViewData[processedPos - 1];
  8875. }
  8876. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs' || arr[i].ty === 'no') {
  8877. if (!processedPos) {
  8878. itemsData[i] = this.createStyleElement(arr[i], level);
  8879. } else {
  8880. itemsData[i].style.closed = false;
  8881. }
  8882. if (arr[i]._render) {
  8883. if (itemsData[i].style.pElem.parentNode !== container) {
  8884. container.appendChild(itemsData[i].style.pElem);
  8885. }
  8886. }
  8887. ownStyles.push(itemsData[i].style);
  8888. } else if (arr[i].ty === 'gr') {
  8889. if (!processedPos) {
  8890. itemsData[i] = this.createGroupElement(arr[i]);
  8891. } else {
  8892. jLen = itemsData[i].it.length;
  8893. for (j = 0; j < jLen; j += 1) {
  8894. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  8895. }
  8896. }
  8897. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render);
  8898. if (arr[i]._render) {
  8899. if (itemsData[i].gr.parentNode !== container) {
  8900. container.appendChild(itemsData[i].gr);
  8901. }
  8902. }
  8903. } else if (arr[i].ty === 'tr') {
  8904. if (!processedPos) {
  8905. itemsData[i] = this.createTransformElement(arr[i], container);
  8906. }
  8907. currentTransform = itemsData[i].transform;
  8908. ownTransformers.push(currentTransform);
  8909. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  8910. if (!processedPos) {
  8911. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  8912. }
  8913. this.setElementStyles(itemsData[i]);
  8914. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'ms' || arr[i].ty === 'pb') {
  8915. if (!processedPos) {
  8916. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8917. modifier.init(this, arr[i]);
  8918. itemsData[i] = modifier;
  8919. this.shapeModifiers.push(modifier);
  8920. } else {
  8921. modifier = itemsData[i];
  8922. modifier.closed = false;
  8923. }
  8924. ownModifiers.push(modifier);
  8925. } else if (arr[i].ty === 'rp') {
  8926. if (!processedPos) {
  8927. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8928. itemsData[i] = modifier;
  8929. modifier.init(this, arr, i, itemsData);
  8930. this.shapeModifiers.push(modifier);
  8931. render = false;
  8932. } else {
  8933. modifier = itemsData[i];
  8934. modifier.closed = true;
  8935. }
  8936. ownModifiers.push(modifier);
  8937. }
  8938. this.addProcessedElement(arr[i], i + 1);
  8939. }
  8940. len = ownStyles.length;
  8941. for (i = 0; i < len; i += 1) {
  8942. ownStyles[i].closed = true;
  8943. }
  8944. len = ownModifiers.length;
  8945. for (i = 0; i < len; i += 1) {
  8946. ownModifiers[i].closed = true;
  8947. }
  8948. };
  8949. SVGShapeElement.prototype.renderInnerContent = function () {
  8950. this.renderModifiers();
  8951. var i;
  8952. var len = this.stylesList.length;
  8953. for (i = 0; i < len; i += 1) {
  8954. this.stylesList[i].reset();
  8955. }
  8956. this.renderShape();
  8957. for (i = 0; i < len; i += 1) {
  8958. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  8959. if (this.stylesList[i].msElem) {
  8960. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d);
  8961. // Adding M0 0 fixes same mask bug on all browsers
  8962. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  8963. }
  8964. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  8965. }
  8966. }
  8967. };
  8968. SVGShapeElement.prototype.renderShape = function () {
  8969. var i;
  8970. var len = this.animatedContents.length;
  8971. var animatedContent;
  8972. for (i = 0; i < len; i += 1) {
  8973. animatedContent = this.animatedContents[i];
  8974. if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  8975. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  8976. }
  8977. }
  8978. };
  8979. SVGShapeElement.prototype.destroy = function () {
  8980. this.destroyBaseElement();
  8981. this.shapesData = null;
  8982. this.itemsData = null;
  8983. };
  8984. function LetterProps(o, sw, sc, fc, m, p) {
  8985. this.o = o;
  8986. this.sw = sw;
  8987. this.sc = sc;
  8988. this.fc = fc;
  8989. this.m = m;
  8990. this.p = p;
  8991. this._mdf = {
  8992. o: true,
  8993. sw: !!sw,
  8994. sc: !!sc,
  8995. fc: !!fc,
  8996. m: true,
  8997. p: true,
  8998. };
  8999. }
  9000. LetterProps.prototype.update = function (o, sw, sc, fc, m, p) {
  9001. this._mdf.o = false;
  9002. this._mdf.sw = false;
  9003. this._mdf.sc = false;
  9004. this._mdf.fc = false;
  9005. this._mdf.m = false;
  9006. this._mdf.p = false;
  9007. var updated = false;
  9008. if (this.o !== o) {
  9009. this.o = o;
  9010. this._mdf.o = true;
  9011. updated = true;
  9012. }
  9013. if (this.sw !== sw) {
  9014. this.sw = sw;
  9015. this._mdf.sw = true;
  9016. updated = true;
  9017. }
  9018. if (this.sc !== sc) {
  9019. this.sc = sc;
  9020. this._mdf.sc = true;
  9021. updated = true;
  9022. }
  9023. if (this.fc !== fc) {
  9024. this.fc = fc;
  9025. this._mdf.fc = true;
  9026. updated = true;
  9027. }
  9028. if (this.m !== m) {
  9029. this.m = m;
  9030. this._mdf.m = true;
  9031. updated = true;
  9032. }
  9033. 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])) {
  9034. this.p = p;
  9035. this._mdf.p = true;
  9036. updated = true;
  9037. }
  9038. return updated;
  9039. };
  9040. function TextProperty(elem, data) {
  9041. this._frameId = initialDefaultFrame;
  9042. this.pv = '';
  9043. this.v = '';
  9044. this.kf = false;
  9045. this._isFirstFrame = true;
  9046. this._mdf = false;
  9047. this.data = data;
  9048. this.elem = elem;
  9049. this.comp = this.elem.comp;
  9050. this.keysIndex = 0;
  9051. this.canResize = false;
  9052. this.minimumFontSize = 1;
  9053. this.effectsSequence = [];
  9054. this.currentData = {
  9055. ascent: 0,
  9056. boxWidth: this.defaultBoxWidth,
  9057. f: '',
  9058. fStyle: '',
  9059. fWeight: '',
  9060. fc: '',
  9061. j: '',
  9062. justifyOffset: '',
  9063. l: [],
  9064. lh: 0,
  9065. lineWidths: [],
  9066. ls: '',
  9067. of: '',
  9068. s: '',
  9069. sc: '',
  9070. sw: 0,
  9071. t: 0,
  9072. tr: 0,
  9073. sz: 0,
  9074. ps: null,
  9075. fillColorAnim: false,
  9076. strokeColorAnim: false,
  9077. strokeWidthAnim: false,
  9078. yOffset: 0,
  9079. finalSize: 0,
  9080. finalText: [],
  9081. finalLineHeight: 0,
  9082. __complete: false,
  9083. };
  9084. this.copyData(this.currentData, this.data.d.k[0].s);
  9085. if (!this.searchProperty()) {
  9086. this.completeTextData(this.currentData);
  9087. }
  9088. }
  9089. TextProperty.prototype.defaultBoxWidth = [0, 0];
  9090. TextProperty.prototype.copyData = function (obj, data) {
  9091. for (var s in data) {
  9092. if (Object.prototype.hasOwnProperty.call(data, s)) {
  9093. obj[s] = data[s];
  9094. }
  9095. }
  9096. return obj;
  9097. };
  9098. TextProperty.prototype.setCurrentData = function (data) {
  9099. if (!data.__complete) {
  9100. this.completeTextData(data);
  9101. }
  9102. this.currentData = data;
  9103. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  9104. this._mdf = true;
  9105. };
  9106. TextProperty.prototype.searchProperty = function () {
  9107. return this.searchKeyframes();
  9108. };
  9109. TextProperty.prototype.searchKeyframes = function () {
  9110. this.kf = this.data.d.k.length > 1;
  9111. if (this.kf) {
  9112. this.addEffect(this.getKeyframeValue.bind(this));
  9113. }
  9114. return this.kf;
  9115. };
  9116. TextProperty.prototype.addEffect = function (effectFunction) {
  9117. this.effectsSequence.push(effectFunction);
  9118. this.elem.addDynamicProperty(this);
  9119. };
  9120. TextProperty.prototype.getValue = function (_finalValue) {
  9121. if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  9122. return;
  9123. }
  9124. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  9125. var currentValue = this.currentData;
  9126. var currentIndex = this.keysIndex;
  9127. if (this.lock) {
  9128. this.setCurrentData(this.currentData);
  9129. return;
  9130. }
  9131. this.lock = true;
  9132. this._mdf = false;
  9133. var i; var
  9134. len = this.effectsSequence.length;
  9135. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  9136. for (i = 0; i < len; i += 1) {
  9137. // Checking if index changed to prevent creating a new object every time the expression updates.
  9138. if (currentIndex !== this.keysIndex) {
  9139. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  9140. } else {
  9141. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  9142. }
  9143. }
  9144. if (currentValue !== finalValue) {
  9145. this.setCurrentData(finalValue);
  9146. }
  9147. this.v = this.currentData;
  9148. this.pv = this.v;
  9149. this.lock = false;
  9150. this.frameId = this.elem.globalData.frameId;
  9151. };
  9152. TextProperty.prototype.getKeyframeValue = function () {
  9153. var textKeys = this.data.d.k;
  9154. var frameNum = this.elem.comp.renderedFrame;
  9155. var i = 0; var
  9156. len = textKeys.length;
  9157. while (i <= len - 1) {
  9158. if (i === len - 1 || textKeys[i + 1].t > frameNum) {
  9159. break;
  9160. }
  9161. i += 1;
  9162. }
  9163. if (this.keysIndex !== i) {
  9164. this.keysIndex = i;
  9165. }
  9166. return this.data.d.k[this.keysIndex].s;
  9167. };
  9168. TextProperty.prototype.buildFinalText = function (text) {
  9169. var charactersArray = [];
  9170. var i = 0;
  9171. var len = text.length;
  9172. var charCode;
  9173. var secondCharCode;
  9174. var shouldCombine = false;
  9175. while (i < len) {
  9176. charCode = text.charCodeAt(i);
  9177. if (FontManager.isCombinedCharacter(charCode)) {
  9178. charactersArray[charactersArray.length - 1] += text.charAt(i);
  9179. } else if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  9180. secondCharCode = text.charCodeAt(i + 1);
  9181. if (secondCharCode >= 0xDC00 && secondCharCode <= 0xDFFF) {
  9182. if (shouldCombine || FontManager.isModifier(charCode, secondCharCode)) {
  9183. charactersArray[charactersArray.length - 1] += text.substr(i, 2);
  9184. shouldCombine = false;
  9185. } else {
  9186. charactersArray.push(text.substr(i, 2));
  9187. }
  9188. i += 1;
  9189. } else {
  9190. charactersArray.push(text.charAt(i));
  9191. }
  9192. } else if (charCode > 0xDBFF) {
  9193. secondCharCode = text.charCodeAt(i + 1);
  9194. if (FontManager.isZeroWidthJoiner(charCode, secondCharCode)) {
  9195. shouldCombine = true;
  9196. charactersArray[charactersArray.length - 1] += text.substr(i, 2);
  9197. i += 1;
  9198. } else {
  9199. charactersArray.push(text.charAt(i));
  9200. }
  9201. } else if (FontManager.isZeroWidthJoiner(charCode)) {
  9202. charactersArray[charactersArray.length - 1] += text.charAt(i);
  9203. shouldCombine = true;
  9204. } else {
  9205. charactersArray.push(text.charAt(i));
  9206. }
  9207. i += 1;
  9208. }
  9209. return charactersArray;
  9210. };
  9211. TextProperty.prototype.completeTextData = function (documentData) {
  9212. documentData.__complete = true;
  9213. var fontManager = this.elem.globalData.fontManager;
  9214. var data = this.data;
  9215. var letters = [];
  9216. var i; var
  9217. len;
  9218. var newLineFlag; var index = 0; var
  9219. val;
  9220. var anchorGrouping = data.m.g;
  9221. var currentSize = 0; var currentPos = 0; var currentLine = 0; var
  9222. lineWidths = [];
  9223. var lineWidth = 0;
  9224. var maxLineWidth = 0;
  9225. var j; var
  9226. jLen;
  9227. var fontData = fontManager.getFontByName(documentData.f);
  9228. var charData; var
  9229. cLength = 0;
  9230. var fontProps = getFontProperties(fontData);
  9231. documentData.fWeight = fontProps.weight;
  9232. documentData.fStyle = fontProps.style;
  9233. documentData.finalSize = documentData.s;
  9234. documentData.finalText = this.buildFinalText(documentData.t);
  9235. len = documentData.finalText.length;
  9236. documentData.finalLineHeight = documentData.lh;
  9237. var trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  9238. var charCode;
  9239. if (documentData.sz) {
  9240. var flag = true;
  9241. var boxWidth = documentData.sz[0];
  9242. var boxHeight = documentData.sz[1];
  9243. var currentHeight; var
  9244. finalText;
  9245. while (flag) {
  9246. finalText = this.buildFinalText(documentData.t);
  9247. currentHeight = 0;
  9248. lineWidth = 0;
  9249. len = finalText.length;
  9250. trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  9251. var lastSpaceIndex = -1;
  9252. for (i = 0; i < len; i += 1) {
  9253. charCode = finalText[i].charCodeAt(0);
  9254. newLineFlag = false;
  9255. if (finalText[i] === ' ') {
  9256. lastSpaceIndex = i;
  9257. } else if (charCode === 13 || charCode === 3) {
  9258. lineWidth = 0;
  9259. newLineFlag = true;
  9260. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  9261. }
  9262. if (fontManager.chars) {
  9263. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  9264. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  9265. } else {
  9266. // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  9267. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  9268. }
  9269. if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') {
  9270. if (lastSpaceIndex === -1) {
  9271. len += 1;
  9272. } else {
  9273. i = lastSpaceIndex;
  9274. }
  9275. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  9276. finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r');
  9277. // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  9278. lastSpaceIndex = -1;
  9279. lineWidth = 0;
  9280. } else {
  9281. lineWidth += cLength;
  9282. lineWidth += trackingOffset;
  9283. }
  9284. }
  9285. currentHeight += (fontData.ascent * documentData.finalSize) / 100;
  9286. if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  9287. documentData.finalSize -= 1;
  9288. documentData.finalLineHeight = (documentData.finalSize * documentData.lh) / documentData.s;
  9289. } else {
  9290. documentData.finalText = finalText;
  9291. len = documentData.finalText.length;
  9292. flag = false;
  9293. }
  9294. }
  9295. }
  9296. lineWidth = -trackingOffset;
  9297. cLength = 0;
  9298. var uncollapsedSpaces = 0;
  9299. var currentChar;
  9300. for (i = 0; i < len; i += 1) {
  9301. newLineFlag = false;
  9302. currentChar = documentData.finalText[i];
  9303. charCode = currentChar.charCodeAt(0);
  9304. if (charCode === 13 || charCode === 3) {
  9305. uncollapsedSpaces = 0;
  9306. lineWidths.push(lineWidth);
  9307. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9308. lineWidth = -2 * trackingOffset;
  9309. val = '';
  9310. newLineFlag = true;
  9311. currentLine += 1;
  9312. } else {
  9313. val = currentChar;
  9314. }
  9315. if (fontManager.chars) {
  9316. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  9317. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  9318. } else {
  9319. // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9320. // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  9321. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9322. }
  9323. //
  9324. if (currentChar === ' ') {
  9325. uncollapsedSpaces += cLength + trackingOffset;
  9326. } else {
  9327. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  9328. uncollapsedSpaces = 0;
  9329. }
  9330. letters.push({
  9331. l: cLength, an: cLength, add: currentSize, n: newLineFlag, anIndexes: [], val: val, line: currentLine, animatorJustifyOffset: 0,
  9332. });
  9333. if (anchorGrouping == 2) { // eslint-disable-line eqeqeq
  9334. currentSize += cLength;
  9335. if (val === '' || val === ' ' || i === len - 1) {
  9336. if (val === '' || val === ' ') {
  9337. currentSize -= cLength;
  9338. }
  9339. while (currentPos <= i) {
  9340. letters[currentPos].an = currentSize;
  9341. letters[currentPos].ind = index;
  9342. letters[currentPos].extra = cLength;
  9343. currentPos += 1;
  9344. }
  9345. index += 1;
  9346. currentSize = 0;
  9347. }
  9348. } else if (anchorGrouping == 3) { // eslint-disable-line eqeqeq
  9349. currentSize += cLength;
  9350. if (val === '' || i === len - 1) {
  9351. if (val === '') {
  9352. currentSize -= cLength;
  9353. }
  9354. while (currentPos <= i) {
  9355. letters[currentPos].an = currentSize;
  9356. letters[currentPos].ind = index;
  9357. letters[currentPos].extra = cLength;
  9358. currentPos += 1;
  9359. }
  9360. currentSize = 0;
  9361. index += 1;
  9362. }
  9363. } else {
  9364. letters[index].ind = index;
  9365. letters[index].extra = 0;
  9366. index += 1;
  9367. }
  9368. }
  9369. documentData.l = letters;
  9370. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9371. lineWidths.push(lineWidth);
  9372. if (documentData.sz) {
  9373. documentData.boxWidth = documentData.sz[0];
  9374. documentData.justifyOffset = 0;
  9375. } else {
  9376. documentData.boxWidth = maxLineWidth;
  9377. switch (documentData.j) {
  9378. case 1:
  9379. documentData.justifyOffset = -documentData.boxWidth;
  9380. break;
  9381. case 2:
  9382. documentData.justifyOffset = -documentData.boxWidth / 2;
  9383. break;
  9384. default:
  9385. documentData.justifyOffset = 0;
  9386. }
  9387. }
  9388. documentData.lineWidths = lineWidths;
  9389. var animators = data.a; var animatorData; var
  9390. letterData;
  9391. jLen = animators.length;
  9392. var based; var ind; var
  9393. indexes = [];
  9394. for (j = 0; j < jLen; j += 1) {
  9395. animatorData = animators[j];
  9396. if (animatorData.a.sc) {
  9397. documentData.strokeColorAnim = true;
  9398. }
  9399. if (animatorData.a.sw) {
  9400. documentData.strokeWidthAnim = true;
  9401. }
  9402. if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) {
  9403. documentData.fillColorAnim = true;
  9404. }
  9405. ind = 0;
  9406. based = animatorData.s.b;
  9407. for (i = 0; i < len; i += 1) {
  9408. letterData = letters[i];
  9409. letterData.anIndexes[j] = ind;
  9410. 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))) { // eslint-disable-line eqeqeq
  9411. if (animatorData.s.rn === 1) {
  9412. indexes.push(ind);
  9413. }
  9414. ind += 1;
  9415. }
  9416. }
  9417. data.a[j].s.totalChars = ind;
  9418. var currentInd = -1; var
  9419. newInd;
  9420. if (animatorData.s.rn === 1) {
  9421. for (i = 0; i < len; i += 1) {
  9422. letterData = letters[i];
  9423. if (currentInd != letterData.anIndexes[j]) { // eslint-disable-line eqeqeq
  9424. currentInd = letterData.anIndexes[j];
  9425. newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0];
  9426. }
  9427. letterData.anIndexes[j] = newInd;
  9428. }
  9429. }
  9430. }
  9431. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2;
  9432. documentData.ls = documentData.ls || 0;
  9433. documentData.ascent = (fontData.ascent * documentData.finalSize) / 100;
  9434. };
  9435. TextProperty.prototype.updateDocumentData = function (newData, index) {
  9436. index = index === undefined ? this.keysIndex : index;
  9437. var dData = this.copyData({}, this.data.d.k[index].s);
  9438. dData = this.copyData(dData, newData);
  9439. this.data.d.k[index].s = dData;
  9440. this.recalculate(index);
  9441. this.elem.addDynamicProperty(this);
  9442. };
  9443. TextProperty.prototype.recalculate = function (index) {
  9444. var dData = this.data.d.k[index].s;
  9445. dData.__complete = false;
  9446. this.keysIndex = 0;
  9447. this._isFirstFrame = true;
  9448. this.getValue(dData);
  9449. };
  9450. TextProperty.prototype.canResizeFont = function (_canResize) {
  9451. this.canResize = _canResize;
  9452. this.recalculate(this.keysIndex);
  9453. this.elem.addDynamicProperty(this);
  9454. };
  9455. TextProperty.prototype.setMinimumFontSize = function (_fontValue) {
  9456. this.minimumFontSize = Math.floor(_fontValue) || 1;
  9457. this.recalculate(this.keysIndex);
  9458. this.elem.addDynamicProperty(this);
  9459. };
  9460. const TextSelectorProp = (function () {
  9461. var max = Math.max;
  9462. var min = Math.min;
  9463. var floor = Math.floor;
  9464. function TextSelectorPropFactory(elem, data) {
  9465. this._currentTextLength = -1;
  9466. this.k = false;
  9467. this.data = data;
  9468. this.elem = elem;
  9469. this.comp = elem.comp;
  9470. this.finalS = 0;
  9471. this.finalE = 0;
  9472. this.initDynamicPropertyContainer(elem);
  9473. this.s = PropertyFactory.getProp(elem, data.s || { k: 0 }, 0, 0, this);
  9474. if ('e' in data) {
  9475. this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this);
  9476. } else {
  9477. this.e = { v: 100 };
  9478. }
  9479. this.o = PropertyFactory.getProp(elem, data.o || { k: 0 }, 0, 0, this);
  9480. this.xe = PropertyFactory.getProp(elem, data.xe || { k: 0 }, 0, 0, this);
  9481. this.ne = PropertyFactory.getProp(elem, data.ne || { k: 0 }, 0, 0, this);
  9482. this.sm = PropertyFactory.getProp(elem, data.sm || { k: 100 }, 0, 0, this);
  9483. this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this);
  9484. if (!this.dynamicProperties.length) {
  9485. this.getValue();
  9486. }
  9487. }
  9488. TextSelectorPropFactory.prototype = {
  9489. getMult: function (ind) {
  9490. if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  9491. this.getValue();
  9492. }
  9493. var x1 = 0;
  9494. var y1 = 0;
  9495. var x2 = 1;
  9496. var y2 = 1;
  9497. if (this.ne.v > 0) {
  9498. x1 = this.ne.v / 100.0;
  9499. } else {
  9500. y1 = -this.ne.v / 100.0;
  9501. }
  9502. if (this.xe.v > 0) {
  9503. x2 = 1.0 - this.xe.v / 100.0;
  9504. } else {
  9505. y2 = 1.0 + this.xe.v / 100.0;
  9506. }
  9507. var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
  9508. var mult = 0;
  9509. var s = this.finalS;
  9510. var e = this.finalE;
  9511. var type = this.data.sh;
  9512. if (type === 2) {
  9513. if (e === s) {
  9514. mult = ind >= e ? 1 : 0;
  9515. } else {
  9516. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9517. }
  9518. mult = easer(mult);
  9519. } else if (type === 3) {
  9520. if (e === s) {
  9521. mult = ind >= e ? 0 : 1;
  9522. } else {
  9523. mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9524. }
  9525. mult = easer(mult);
  9526. } else if (type === 4) {
  9527. if (e === s) {
  9528. mult = 0;
  9529. } else {
  9530. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9531. if (mult < 0.5) {
  9532. mult *= 2;
  9533. } else {
  9534. mult = 1 - 2 * (mult - 0.5);
  9535. }
  9536. }
  9537. mult = easer(mult);
  9538. } else if (type === 5) {
  9539. if (e === s) {
  9540. mult = 0;
  9541. } else {
  9542. var tot = e - s;
  9543. /* ind += 0.5;
  9544. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */
  9545. ind = min(max(0, ind + 0.5 - s), e - s);
  9546. var x = -tot / 2 + ind;
  9547. var a = tot / 2;
  9548. mult = Math.sqrt(1 - (x * x) / (a * a));
  9549. }
  9550. mult = easer(mult);
  9551. } else if (type === 6) {
  9552. if (e === s) {
  9553. mult = 0;
  9554. } else {
  9555. ind = min(max(0, ind + 0.5 - s), e - s);
  9556. mult = (1 + (Math.cos((Math.PI + Math.PI * 2 * (ind) / (e - s))))) / 2; // eslint-disable-line
  9557. }
  9558. mult = easer(mult);
  9559. } else {
  9560. if (ind >= floor(s)) {
  9561. if (ind - s < 0) {
  9562. mult = max(0, min(min(e, 1) - (s - ind), 1));
  9563. } else {
  9564. mult = max(0, min(e - ind, 1));
  9565. }
  9566. }
  9567. mult = easer(mult);
  9568. }
  9569. // Smoothness implementation.
  9570. // The smoothness represents a reduced range of the original [0; 1] range.
  9571. // if smoothness is 25%, the new range will be [0.375; 0.625]
  9572. // Steps are:
  9573. // - find the lower value of the new range (threshold)
  9574. // - if multiplier is smaller than that value, floor it to 0
  9575. // - if it is larger,
  9576. // - subtract the threshold
  9577. // - divide it by the smoothness (this will return the range to [0; 1])
  9578. // Note: If it doesn't work on some scenarios, consider applying it before the easer.
  9579. if (this.sm.v !== 100) {
  9580. var smoothness = this.sm.v * 0.01;
  9581. if (smoothness === 0) {
  9582. smoothness = 0.00000001;
  9583. }
  9584. var threshold = 0.5 - smoothness * 0.5;
  9585. if (mult < threshold) {
  9586. mult = 0;
  9587. } else {
  9588. mult = (mult - threshold) / smoothness;
  9589. if (mult > 1) {
  9590. mult = 1;
  9591. }
  9592. }
  9593. }
  9594. return mult * this.a.v;
  9595. },
  9596. getValue: function (newCharsFlag) {
  9597. this.iterateDynamicProperties();
  9598. this._mdf = newCharsFlag || this._mdf;
  9599. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  9600. if (newCharsFlag && this.data.r === 2) {
  9601. this.e.v = this._currentTextLength;
  9602. }
  9603. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  9604. var o = this.o.v / divisor;
  9605. var s = this.s.v / divisor + o;
  9606. var e = (this.e.v / divisor) + o;
  9607. if (s > e) {
  9608. var _s = s;
  9609. s = e;
  9610. e = _s;
  9611. }
  9612. this.finalS = s;
  9613. this.finalE = e;
  9614. },
  9615. };
  9616. extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory);
  9617. function getTextSelectorProp(elem, data, arr) {
  9618. return new TextSelectorPropFactory(elem, data, arr);
  9619. }
  9620. return {
  9621. getTextSelectorProp: getTextSelectorProp,
  9622. };
  9623. }());
  9624. function TextAnimatorDataProperty(elem, animatorProps, container) {
  9625. var defaultData = { propType: false };
  9626. var getProp = PropertyFactory.getProp;
  9627. var textAnimatorAnimatables = animatorProps.a;
  9628. this.a = {
  9629. r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData,
  9630. rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData,
  9631. ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData,
  9632. sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData,
  9633. sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData,
  9634. s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData,
  9635. a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData,
  9636. o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData,
  9637. p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData,
  9638. sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData,
  9639. sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData,
  9640. fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData,
  9641. fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData,
  9642. fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData,
  9643. fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData,
  9644. t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData,
  9645. };
  9646. this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container);
  9647. this.s.t = animatorProps.s.t;
  9648. }
  9649. function TextAnimatorProperty(textData, renderType, elem) {
  9650. this._isFirstFrame = true;
  9651. this._hasMaskedPath = false;
  9652. this._frameId = -1;
  9653. this._textData = textData;
  9654. this._renderType = renderType;
  9655. this._elem = elem;
  9656. this._animatorsData = createSizedArray(this._textData.a.length);
  9657. this._pathData = {};
  9658. this._moreOptions = {
  9659. alignment: {},
  9660. };
  9661. this.renderedLetters = [];
  9662. this.lettersChangedFlag = false;
  9663. this.initDynamicPropertyContainer(elem);
  9664. }
  9665. TextAnimatorProperty.prototype.searchProperties = function () {
  9666. var i;
  9667. var len = this._textData.a.length;
  9668. var animatorProps;
  9669. var getProp = PropertyFactory.getProp;
  9670. for (i = 0; i < len; i += 1) {
  9671. animatorProps = this._textData.a[i];
  9672. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  9673. }
  9674. if (this._textData.p && 'm' in this._textData.p) {
  9675. this._pathData = {
  9676. a: getProp(this._elem, this._textData.p.a, 0, 0, this),
  9677. f: getProp(this._elem, this._textData.p.f, 0, 0, this),
  9678. l: getProp(this._elem, this._textData.p.l, 0, 0, this),
  9679. r: getProp(this._elem, this._textData.p.r, 0, 0, this),
  9680. p: getProp(this._elem, this._textData.p.p, 0, 0, this),
  9681. m: this._elem.maskManager.getMaskProperty(this._textData.p.m),
  9682. };
  9683. this._hasMaskedPath = true;
  9684. } else {
  9685. this._hasMaskedPath = false;
  9686. }
  9687. this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this);
  9688. };
  9689. TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) {
  9690. this.lettersChangedFlag = lettersChangedFlag;
  9691. if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  9692. return;
  9693. }
  9694. this._isFirstFrame = false;
  9695. var alignment = this._moreOptions.alignment.v;
  9696. var animators = this._animatorsData;
  9697. var textData = this._textData;
  9698. var matrixHelper = this.mHelper;
  9699. var renderType = this._renderType;
  9700. var renderedLettersCount = this.renderedLetters.length;
  9701. var xPos;
  9702. var yPos;
  9703. var i;
  9704. var len;
  9705. var letters = documentData.l;
  9706. var pathInfo;
  9707. var currentLength;
  9708. var currentPoint;
  9709. var segmentLength;
  9710. var flag;
  9711. var pointInd;
  9712. var segmentInd;
  9713. var prevPoint;
  9714. var points;
  9715. var segments;
  9716. var partialLength;
  9717. var totalLength;
  9718. var perc;
  9719. var tanAngle;
  9720. var mask;
  9721. if (this._hasMaskedPath) {
  9722. mask = this._pathData.m;
  9723. if (!this._pathData.n || this._pathData._mdf) {
  9724. var paths = mask.v;
  9725. if (this._pathData.r.v) {
  9726. paths = paths.reverse();
  9727. }
  9728. // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  9729. pathInfo = {
  9730. tLength: 0,
  9731. segments: [],
  9732. };
  9733. len = paths._length - 1;
  9734. var bezierData;
  9735. totalLength = 0;
  9736. for (i = 0; i < len; i += 1) {
  9737. bezierData = bez.buildBezierData(paths.v[i],
  9738. paths.v[i + 1],
  9739. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9740. [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  9741. pathInfo.tLength += bezierData.segmentLength;
  9742. pathInfo.segments.push(bezierData);
  9743. totalLength += bezierData.segmentLength;
  9744. }
  9745. i = len;
  9746. if (mask.v.c) {
  9747. bezierData = bez.buildBezierData(paths.v[i],
  9748. paths.v[0],
  9749. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9750. [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  9751. pathInfo.tLength += bezierData.segmentLength;
  9752. pathInfo.segments.push(bezierData);
  9753. totalLength += bezierData.segmentLength;
  9754. }
  9755. this._pathData.pi = pathInfo;
  9756. }
  9757. pathInfo = this._pathData.pi;
  9758. currentLength = this._pathData.f.v;
  9759. segmentInd = 0;
  9760. pointInd = 1;
  9761. segmentLength = 0;
  9762. flag = true;
  9763. segments = pathInfo.segments;
  9764. if (currentLength < 0 && mask.v.c) {
  9765. if (pathInfo.tLength < Math.abs(currentLength)) {
  9766. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  9767. }
  9768. segmentInd = segments.length - 1;
  9769. points = segments[segmentInd].points;
  9770. pointInd = points.length - 1;
  9771. while (currentLength < 0) {
  9772. currentLength += points[pointInd].partialLength;
  9773. pointInd -= 1;
  9774. if (pointInd < 0) {
  9775. segmentInd -= 1;
  9776. points = segments[segmentInd].points;
  9777. pointInd = points.length - 1;
  9778. }
  9779. }
  9780. }
  9781. points = segments[segmentInd].points;
  9782. prevPoint = points[pointInd - 1];
  9783. currentPoint = points[pointInd];
  9784. partialLength = currentPoint.partialLength;
  9785. }
  9786. len = letters.length;
  9787. xPos = 0;
  9788. yPos = 0;
  9789. var yOff = documentData.finalSize * 1.2 * 0.714;
  9790. var firstLine = true;
  9791. var animatorProps;
  9792. var animatorSelector;
  9793. var j;
  9794. var jLen;
  9795. var letterValue;
  9796. jLen = animators.length;
  9797. var mult;
  9798. var ind = -1;
  9799. var offf;
  9800. var xPathPos;
  9801. var yPathPos;
  9802. var initPathPos = currentLength;
  9803. var initSegmentInd = segmentInd;
  9804. var initPointInd = pointInd;
  9805. var currentLine = -1;
  9806. var elemOpacity;
  9807. var sc;
  9808. var sw;
  9809. var fc;
  9810. var k;
  9811. var letterSw;
  9812. var letterSc;
  9813. var letterFc;
  9814. var letterM = '';
  9815. var letterP = this.defaultPropsArray;
  9816. var letterO;
  9817. //
  9818. if (documentData.j === 2 || documentData.j === 1) {
  9819. var animatorJustifyOffset = 0;
  9820. var animatorFirstCharOffset = 0;
  9821. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  9822. var lastIndex = 0;
  9823. var isNewLine = true;
  9824. for (i = 0; i < len; i += 1) {
  9825. if (letters[i].n) {
  9826. if (animatorJustifyOffset) {
  9827. animatorJustifyOffset += animatorFirstCharOffset;
  9828. }
  9829. while (lastIndex < i) {
  9830. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9831. lastIndex += 1;
  9832. }
  9833. animatorJustifyOffset = 0;
  9834. isNewLine = true;
  9835. } else {
  9836. for (j = 0; j < jLen; j += 1) {
  9837. animatorProps = animators[j].a;
  9838. if (animatorProps.t.propType) {
  9839. if (isNewLine && documentData.j === 2) {
  9840. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  9841. }
  9842. animatorSelector = animators[j].s;
  9843. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9844. if (mult.length) {
  9845. animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult;
  9846. } else {
  9847. animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult;
  9848. }
  9849. }
  9850. }
  9851. isNewLine = false;
  9852. }
  9853. }
  9854. if (animatorJustifyOffset) {
  9855. animatorJustifyOffset += animatorFirstCharOffset;
  9856. }
  9857. while (lastIndex < i) {
  9858. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9859. lastIndex += 1;
  9860. }
  9861. }
  9862. //
  9863. for (i = 0; i < len; i += 1) {
  9864. matrixHelper.reset();
  9865. elemOpacity = 1;
  9866. if (letters[i].n) {
  9867. xPos = 0;
  9868. yPos += documentData.yOffset;
  9869. yPos += firstLine ? 1 : 0;
  9870. currentLength = initPathPos;
  9871. firstLine = false;
  9872. if (this._hasMaskedPath) {
  9873. segmentInd = initSegmentInd;
  9874. pointInd = initPointInd;
  9875. points = segments[segmentInd].points;
  9876. prevPoint = points[pointInd - 1];
  9877. currentPoint = points[pointInd];
  9878. partialLength = currentPoint.partialLength;
  9879. segmentLength = 0;
  9880. }
  9881. letterM = '';
  9882. letterFc = '';
  9883. letterSw = '';
  9884. letterO = '';
  9885. letterP = this.defaultPropsArray;
  9886. } else {
  9887. if (this._hasMaskedPath) {
  9888. if (currentLine !== letters[i].line) {
  9889. switch (documentData.j) {
  9890. case 1:
  9891. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  9892. break;
  9893. case 2:
  9894. currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2;
  9895. break;
  9896. default:
  9897. break;
  9898. }
  9899. currentLine = letters[i].line;
  9900. }
  9901. if (ind !== letters[i].ind) {
  9902. if (letters[ind]) {
  9903. currentLength += letters[ind].extra;
  9904. }
  9905. currentLength += letters[i].an / 2;
  9906. ind = letters[i].ind;
  9907. }
  9908. currentLength += (alignment[0] * letters[i].an) * 0.005;
  9909. var animatorOffset = 0;
  9910. for (j = 0; j < jLen; j += 1) {
  9911. animatorProps = animators[j].a;
  9912. if (animatorProps.p.propType) {
  9913. animatorSelector = animators[j].s;
  9914. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9915. if (mult.length) {
  9916. animatorOffset += animatorProps.p.v[0] * mult[0];
  9917. } else {
  9918. animatorOffset += animatorProps.p.v[0] * mult;
  9919. }
  9920. }
  9921. if (animatorProps.a.propType) {
  9922. animatorSelector = animators[j].s;
  9923. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9924. if (mult.length) {
  9925. animatorOffset += animatorProps.a.v[0] * mult[0];
  9926. } else {
  9927. animatorOffset += animatorProps.a.v[0] * mult;
  9928. }
  9929. }
  9930. }
  9931. flag = true;
  9932. // Force alignment only works with a single line for now
  9933. if (this._pathData.a.v) {
  9934. 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);
  9935. currentLength += this._pathData.f.v;
  9936. }
  9937. while (flag) {
  9938. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  9939. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  9940. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  9941. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  9942. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, -(alignment[1] * yOff) * 0.01);
  9943. flag = false;
  9944. } else if (points) {
  9945. segmentLength += currentPoint.partialLength;
  9946. pointInd += 1;
  9947. if (pointInd >= points.length) {
  9948. pointInd = 0;
  9949. segmentInd += 1;
  9950. if (!segments[segmentInd]) {
  9951. if (mask.v.c) {
  9952. pointInd = 0;
  9953. segmentInd = 0;
  9954. points = segments[segmentInd].points;
  9955. } else {
  9956. segmentLength -= currentPoint.partialLength;
  9957. points = null;
  9958. }
  9959. } else {
  9960. points = segments[segmentInd].points;
  9961. }
  9962. }
  9963. if (points) {
  9964. prevPoint = currentPoint;
  9965. currentPoint = points[pointInd];
  9966. partialLength = currentPoint.partialLength;
  9967. }
  9968. }
  9969. }
  9970. offf = letters[i].an / 2 - letters[i].add;
  9971. matrixHelper.translate(-offf, 0, 0);
  9972. } else {
  9973. offf = letters[i].an / 2 - letters[i].add;
  9974. matrixHelper.translate(-offf, 0, 0);
  9975. // Grouping alignment
  9976. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, (-alignment[1] * yOff) * 0.01, 0);
  9977. }
  9978. for (j = 0; j < jLen; j += 1) {
  9979. animatorProps = animators[j].a;
  9980. if (animatorProps.t.propType) {
  9981. animatorSelector = animators[j].s;
  9982. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9983. // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  9984. if (xPos !== 0 || documentData.j !== 0) {
  9985. if (this._hasMaskedPath) {
  9986. if (mult.length) {
  9987. currentLength += animatorProps.t.v * mult[0];
  9988. } else {
  9989. currentLength += animatorProps.t.v * mult;
  9990. }
  9991. } else if (mult.length) {
  9992. xPos += animatorProps.t.v * mult[0];
  9993. } else {
  9994. xPos += animatorProps.t.v * mult;
  9995. }
  9996. }
  9997. }
  9998. }
  9999. if (documentData.strokeWidthAnim) {
  10000. sw = documentData.sw || 0;
  10001. }
  10002. if (documentData.strokeColorAnim) {
  10003. if (documentData.sc) {
  10004. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  10005. } else {
  10006. sc = [0, 0, 0];
  10007. }
  10008. }
  10009. if (documentData.fillColorAnim && documentData.fc) {
  10010. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  10011. }
  10012. for (j = 0; j < jLen; j += 1) {
  10013. animatorProps = animators[j].a;
  10014. if (animatorProps.a.propType) {
  10015. animatorSelector = animators[j].s;
  10016. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  10017. if (mult.length) {
  10018. matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]);
  10019. } else {
  10020. matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult);
  10021. }
  10022. }
  10023. }
  10024. for (j = 0; j < jLen; j += 1) {
  10025. animatorProps = animators[j].a;
  10026. if (animatorProps.s.propType) {
  10027. animatorSelector = animators[j].s;
  10028. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  10029. if (mult.length) {
  10030. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult[0]), 1 + ((animatorProps.s.v[1] - 1) * mult[1]), 1);
  10031. } else {
  10032. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult), 1 + ((animatorProps.s.v[1] - 1) * mult), 1);
  10033. }
  10034. }
  10035. }
  10036. for (j = 0; j < jLen; j += 1) {
  10037. animatorProps = animators[j].a;
  10038. animatorSelector = animators[j].s;
  10039. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  10040. if (animatorProps.sk.propType) {
  10041. if (mult.length) {
  10042. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  10043. } else {
  10044. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  10045. }
  10046. }
  10047. if (animatorProps.r.propType) {
  10048. if (mult.length) {
  10049. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  10050. } else {
  10051. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  10052. }
  10053. }
  10054. if (animatorProps.ry.propType) {
  10055. if (mult.length) {
  10056. matrixHelper.rotateY(animatorProps.ry.v * mult[1]);
  10057. } else {
  10058. matrixHelper.rotateY(animatorProps.ry.v * mult);
  10059. }
  10060. }
  10061. if (animatorProps.rx.propType) {
  10062. if (mult.length) {
  10063. matrixHelper.rotateX(animatorProps.rx.v * mult[0]);
  10064. } else {
  10065. matrixHelper.rotateX(animatorProps.rx.v * mult);
  10066. }
  10067. }
  10068. if (animatorProps.o.propType) {
  10069. if (mult.length) {
  10070. elemOpacity += ((animatorProps.o.v) * mult[0] - elemOpacity) * mult[0];
  10071. } else {
  10072. elemOpacity += ((animatorProps.o.v) * mult - elemOpacity) * mult;
  10073. }
  10074. }
  10075. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  10076. if (mult.length) {
  10077. sw += animatorProps.sw.v * mult[0];
  10078. } else {
  10079. sw += animatorProps.sw.v * mult;
  10080. }
  10081. }
  10082. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  10083. for (k = 0; k < 3; k += 1) {
  10084. if (mult.length) {
  10085. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0];
  10086. } else {
  10087. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult;
  10088. }
  10089. }
  10090. }
  10091. if (documentData.fillColorAnim && documentData.fc) {
  10092. if (animatorProps.fc.propType) {
  10093. for (k = 0; k < 3; k += 1) {
  10094. if (mult.length) {
  10095. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0];
  10096. } else {
  10097. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult;
  10098. }
  10099. }
  10100. }
  10101. if (animatorProps.fh.propType) {
  10102. if (mult.length) {
  10103. fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]);
  10104. } else {
  10105. fc = addHueToRGB(fc, animatorProps.fh.v * mult);
  10106. }
  10107. }
  10108. if (animatorProps.fs.propType) {
  10109. if (mult.length) {
  10110. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]);
  10111. } else {
  10112. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult);
  10113. }
  10114. }
  10115. if (animatorProps.fb.propType) {
  10116. if (mult.length) {
  10117. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]);
  10118. } else {
  10119. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult);
  10120. }
  10121. }
  10122. }
  10123. }
  10124. for (j = 0; j < jLen; j += 1) {
  10125. animatorProps = animators[j].a;
  10126. if (animatorProps.p.propType) {
  10127. animatorSelector = animators[j].s;
  10128. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  10129. if (this._hasMaskedPath) {
  10130. if (mult.length) {
  10131. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  10132. } else {
  10133. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  10134. }
  10135. } else if (mult.length) {
  10136. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  10137. } else {
  10138. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  10139. }
  10140. }
  10141. }
  10142. if (documentData.strokeWidthAnim) {
  10143. letterSw = sw < 0 ? 0 : sw;
  10144. }
  10145. if (documentData.strokeColorAnim) {
  10146. letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')';
  10147. }
  10148. if (documentData.fillColorAnim && documentData.fc) {
  10149. letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')';
  10150. }
  10151. if (this._hasMaskedPath) {
  10152. matrixHelper.translate(0, -documentData.ls);
  10153. matrixHelper.translate(0, (alignment[1] * yOff) * 0.01 + yPos, 0);
  10154. if (this._pathData.p.v) {
  10155. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  10156. var rot = (Math.atan(tanAngle) * 180) / Math.PI;
  10157. if (currentPoint.point[0] < prevPoint.point[0]) {
  10158. rot += 180;
  10159. }
  10160. matrixHelper.rotate((-rot * Math.PI) / 180);
  10161. }
  10162. matrixHelper.translate(xPathPos, yPathPos, 0);
  10163. currentLength -= (alignment[0] * letters[i].an) * 0.005;
  10164. if (letters[i + 1] && ind !== letters[i + 1].ind) {
  10165. currentLength += letters[i].an / 2;
  10166. currentLength += (documentData.tr * 0.001) * documentData.finalSize;
  10167. }
  10168. } else {
  10169. matrixHelper.translate(xPos, yPos, 0);
  10170. if (documentData.ps) {
  10171. // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  10172. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  10173. }
  10174. switch (documentData.j) {
  10175. case 1:
  10176. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0);
  10177. break;
  10178. case 2:
  10179. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0);
  10180. break;
  10181. default:
  10182. break;
  10183. }
  10184. matrixHelper.translate(0, -documentData.ls);
  10185. matrixHelper.translate(offf, 0, 0);
  10186. matrixHelper.translate((alignment[0] * letters[i].an) * 0.005, (alignment[1] * yOff) * 0.01, 0);
  10187. xPos += letters[i].l + (documentData.tr * 0.001) * documentData.finalSize;
  10188. }
  10189. if (renderType === 'html') {
  10190. letterM = matrixHelper.toCSS();
  10191. } else if (renderType === 'svg') {
  10192. letterM = matrixHelper.to2dCSS();
  10193. } else {
  10194. 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]];
  10195. }
  10196. letterO = elemOpacity;
  10197. }
  10198. if (renderedLettersCount <= i) {
  10199. letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP);
  10200. this.renderedLetters.push(letterValue);
  10201. renderedLettersCount += 1;
  10202. this.lettersChangedFlag = true;
  10203. } else {
  10204. letterValue = this.renderedLetters[i];
  10205. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  10206. }
  10207. }
  10208. };
  10209. TextAnimatorProperty.prototype.getValue = function () {
  10210. if (this._elem.globalData.frameId === this._frameId) {
  10211. return;
  10212. }
  10213. this._frameId = this._elem.globalData.frameId;
  10214. this.iterateDynamicProperties();
  10215. };
  10216. TextAnimatorProperty.prototype.mHelper = new Matrix();
  10217. TextAnimatorProperty.prototype.defaultPropsArray = [];
  10218. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  10219. function ITextElement() {
  10220. }
  10221. ITextElement.prototype.initElement = function (data, globalData, comp) {
  10222. this.lettersChangedFlag = true;
  10223. this.initFrame();
  10224. this.initBaseData(data, globalData, comp);
  10225. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  10226. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  10227. this.initTransform(data, globalData, comp);
  10228. this.initHierarchy();
  10229. this.initRenderable();
  10230. this.initRendererElement();
  10231. this.createContainerElements();
  10232. this.createRenderableComponents();
  10233. this.createContent();
  10234. this.hide();
  10235. this.textAnimator.searchProperties(this.dynamicProperties);
  10236. };
  10237. ITextElement.prototype.prepareFrame = function (num) {
  10238. this._mdf = false;
  10239. this.prepareRenderableFrame(num);
  10240. this.prepareProperties(num, this.isInRange);
  10241. if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
  10242. this.buildNewText();
  10243. this.textProperty._isFirstFrame = false;
  10244. this.textProperty._mdf = false;
  10245. }
  10246. };
  10247. ITextElement.prototype.createPathShape = function (matrixHelper, shapes) {
  10248. var j;
  10249. var jLen = shapes.length;
  10250. var pathNodes;
  10251. var shapeStr = '';
  10252. for (j = 0; j < jLen; j += 1) {
  10253. if (shapes[j].ty === 'sh') {
  10254. pathNodes = shapes[j].ks.k;
  10255. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  10256. }
  10257. }
  10258. return shapeStr;
  10259. };
  10260. ITextElement.prototype.updateDocumentData = function (newData, index) {
  10261. this.textProperty.updateDocumentData(newData, index);
  10262. };
  10263. ITextElement.prototype.canResizeFont = function (_canResize) {
  10264. this.textProperty.canResizeFont(_canResize);
  10265. };
  10266. ITextElement.prototype.setMinimumFontSize = function (_fontSize) {
  10267. this.textProperty.setMinimumFontSize(_fontSize);
  10268. };
  10269. ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) {
  10270. if (documentData.ps) {
  10271. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  10272. }
  10273. matrixHelper.translate(0, -documentData.ls, 0);
  10274. switch (documentData.j) {
  10275. case 1:
  10276. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
  10277. break;
  10278. case 2:
  10279. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
  10280. break;
  10281. default:
  10282. break;
  10283. }
  10284. matrixHelper.translate(xPos, yPos, 0);
  10285. };
  10286. ITextElement.prototype.buildColor = function (colorData) {
  10287. return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')';
  10288. };
  10289. ITextElement.prototype.emptyProp = new LetterProps();
  10290. ITextElement.prototype.destroy = function () {
  10291. };
  10292. var emptyShapeData = {
  10293. shapes: [],
  10294. };
  10295. function SVGTextLottieElement(data, globalData, comp) {
  10296. this.textSpans = [];
  10297. this.renderType = 'svg';
  10298. this.initElement(data, globalData, comp);
  10299. }
  10300. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement);
  10301. SVGTextLottieElement.prototype.createContent = function () {
  10302. if (this.data.singleShape && !this.globalData.fontManager.chars) {
  10303. this.textContainer = createNS('text');
  10304. }
  10305. };
  10306. SVGTextLottieElement.prototype.buildTextContents = function (textArray) {
  10307. var i = 0;
  10308. var len = textArray.length;
  10309. var textContents = [];
  10310. var currentTextContent = '';
  10311. while (i < len) {
  10312. if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) {
  10313. textContents.push(currentTextContent);
  10314. currentTextContent = '';
  10315. } else {
  10316. currentTextContent += textArray[i];
  10317. }
  10318. i += 1;
  10319. }
  10320. textContents.push(currentTextContent);
  10321. return textContents;
  10322. };
  10323. SVGTextLottieElement.prototype.buildShapeData = function (data, scale) {
  10324. // data should probably be cloned to apply scale separately to each instance of a text on different layers
  10325. // but since text internal content gets only rendered once and then it's never rerendered,
  10326. // it's probably safe not to clone data and reuse always the same instance even if the object is mutated.
  10327. // Avoiding cloning is preferred since cloning each character shape data is expensive
  10328. if (data.shapes && data.shapes.length) {
  10329. var shape = data.shapes[0];
  10330. if (shape.it) {
  10331. var shapeItem = shape.it[shape.it.length - 1];
  10332. if (shapeItem.s) {
  10333. shapeItem.s.k[0] = scale;
  10334. shapeItem.s.k[1] = scale;
  10335. }
  10336. }
  10337. }
  10338. return data;
  10339. };
  10340. SVGTextLottieElement.prototype.buildNewText = function () {
  10341. this.addDynamicProperty(this);
  10342. var i;
  10343. var len;
  10344. var documentData = this.textProperty.currentData;
  10345. this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0);
  10346. if (documentData.fc) {
  10347. this.layerElement.setAttribute('fill', this.buildColor(documentData.fc));
  10348. } else {
  10349. this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)');
  10350. }
  10351. if (documentData.sc) {
  10352. this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc));
  10353. this.layerElement.setAttribute('stroke-width', documentData.sw);
  10354. }
  10355. this.layerElement.setAttribute('font-size', documentData.finalSize);
  10356. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  10357. if (fontData.fClass) {
  10358. this.layerElement.setAttribute('class', fontData.fClass);
  10359. } else {
  10360. this.layerElement.setAttribute('font-family', fontData.fFamily);
  10361. var fWeight = documentData.fWeight;
  10362. var fStyle = documentData.fStyle;
  10363. this.layerElement.setAttribute('font-style', fStyle);
  10364. this.layerElement.setAttribute('font-weight', fWeight);
  10365. }
  10366. this.layerElement.setAttribute('aria-label', documentData.t);
  10367. var letters = documentData.l || [];
  10368. var usesGlyphs = !!this.globalData.fontManager.chars;
  10369. len = letters.length;
  10370. var tSpan;
  10371. var matrixHelper = this.mHelper;
  10372. var shapeStr = '';
  10373. var singleShape = this.data.singleShape;
  10374. var xPos = 0;
  10375. var yPos = 0;
  10376. var firstLine = true;
  10377. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  10378. if (singleShape && !usesGlyphs && !documentData.sz) {
  10379. var tElement = this.textContainer;
  10380. var justify = 'start';
  10381. switch (documentData.j) {
  10382. case 1:
  10383. justify = 'end';
  10384. break;
  10385. case 2:
  10386. justify = 'middle';
  10387. break;
  10388. default:
  10389. justify = 'start';
  10390. break;
  10391. }
  10392. tElement.setAttribute('text-anchor', justify);
  10393. tElement.setAttribute('letter-spacing', trackingOffset);
  10394. var textContent = this.buildTextContents(documentData.finalText);
  10395. len = textContent.length;
  10396. yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0;
  10397. for (i = 0; i < len; i += 1) {
  10398. tSpan = this.textSpans[i].span || createNS('tspan');
  10399. tSpan.textContent = textContent[i];
  10400. tSpan.setAttribute('x', 0);
  10401. tSpan.setAttribute('y', yPos);
  10402. tSpan.style.display = 'inherit';
  10403. tElement.appendChild(tSpan);
  10404. if (!this.textSpans[i]) {
  10405. this.textSpans[i] = {
  10406. span: null,
  10407. glyph: null,
  10408. };
  10409. }
  10410. this.textSpans[i].span = tSpan;
  10411. yPos += documentData.finalLineHeight;
  10412. }
  10413. this.layerElement.appendChild(tElement);
  10414. } else {
  10415. var cachedSpansLength = this.textSpans.length;
  10416. var charData;
  10417. for (i = 0; i < len; i += 1) {
  10418. if (!this.textSpans[i]) {
  10419. this.textSpans[i] = {
  10420. span: null,
  10421. childSpan: null,
  10422. glyph: null,
  10423. };
  10424. }
  10425. if (!usesGlyphs || !singleShape || i === 0) {
  10426. tSpan = cachedSpansLength > i ? this.textSpans[i].span : createNS(usesGlyphs ? 'g' : 'text');
  10427. if (cachedSpansLength <= i) {
  10428. tSpan.setAttribute('stroke-linecap', 'butt');
  10429. tSpan.setAttribute('stroke-linejoin', 'round');
  10430. tSpan.setAttribute('stroke-miterlimit', '4');
  10431. this.textSpans[i].span = tSpan;
  10432. if (usesGlyphs) {
  10433. var childSpan = createNS('g');
  10434. tSpan.appendChild(childSpan);
  10435. this.textSpans[i].childSpan = childSpan;
  10436. }
  10437. this.textSpans[i].span = tSpan;
  10438. this.layerElement.appendChild(tSpan);
  10439. }
  10440. tSpan.style.display = 'inherit';
  10441. }
  10442. matrixHelper.reset();
  10443. if (singleShape) {
  10444. if (letters[i].n) {
  10445. xPos = -trackingOffset;
  10446. yPos += documentData.yOffset;
  10447. yPos += firstLine ? 1 : 0;
  10448. firstLine = false;
  10449. }
  10450. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  10451. xPos += letters[i].l || 0;
  10452. // xPos += letters[i].val === ' ' ? 0 : trackingOffset;
  10453. xPos += trackingOffset;
  10454. }
  10455. if (usesGlyphs) {
  10456. charData = this.globalData.fontManager.getCharData(
  10457. documentData.finalText[i],
  10458. fontData.fStyle,
  10459. this.globalData.fontManager.getFontByName(documentData.f).fFamily
  10460. );
  10461. var glyphElement;
  10462. // t === 1 means the character has been replaced with an animated shaped
  10463. if (charData.t === 1) {
  10464. glyphElement = new SVGCompElement(charData.data, this.globalData, this);
  10465. } else {
  10466. var data = emptyShapeData;
  10467. if (charData.data && charData.data.shapes) {
  10468. data = this.buildShapeData(charData.data, documentData.finalSize);
  10469. }
  10470. glyphElement = new SVGShapeElement(data, this.globalData, this);
  10471. }
  10472. if (this.textSpans[i].glyph) {
  10473. var glyph = this.textSpans[i].glyph;
  10474. this.textSpans[i].childSpan.removeChild(glyph.layerElement);
  10475. glyph.destroy();
  10476. }
  10477. this.textSpans[i].glyph = glyphElement;
  10478. glyphElement._debug = true;
  10479. glyphElement.prepareFrame(0);
  10480. glyphElement.renderFrame();
  10481. this.textSpans[i].childSpan.appendChild(glyphElement.layerElement);
  10482. // when using animated shapes, the layer will be scaled instead of replacing the internal scale
  10483. // this might have issues with strokes and might need a different solution
  10484. if (charData.t === 1) {
  10485. this.textSpans[i].childSpan.setAttribute('transform', 'scale(' + documentData.finalSize / 100 + ',' + documentData.finalSize / 100 + ')');
  10486. }
  10487. } else {
  10488. if (singleShape) {
  10489. tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')');
  10490. }
  10491. tSpan.textContent = letters[i].val;
  10492. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  10493. }
  10494. //
  10495. }
  10496. if (singleShape && tSpan) {
  10497. tSpan.setAttribute('d', shapeStr);
  10498. }
  10499. }
  10500. while (i < this.textSpans.length) {
  10501. this.textSpans[i].span.style.display = 'none';
  10502. i += 1;
  10503. }
  10504. this._sizeChanged = true;
  10505. };
  10506. SVGTextLottieElement.prototype.sourceRectAtTime = function () {
  10507. this.prepareFrame(this.comp.renderedFrame - this.data.st);
  10508. this.renderInnerContent();
  10509. if (this._sizeChanged) {
  10510. this._sizeChanged = false;
  10511. var textBox = this.layerElement.getBBox();
  10512. this.bbox = {
  10513. top: textBox.y,
  10514. left: textBox.x,
  10515. width: textBox.width,
  10516. height: textBox.height,
  10517. };
  10518. }
  10519. return this.bbox;
  10520. };
  10521. SVGTextLottieElement.prototype.getValue = function () {
  10522. var i;
  10523. var len = this.textSpans.length;
  10524. var glyphElement;
  10525. this.renderedFrame = this.comp.renderedFrame;
  10526. for (i = 0; i < len; i += 1) {
  10527. glyphElement = this.textSpans[i].glyph;
  10528. if (glyphElement) {
  10529. glyphElement.prepareFrame(this.comp.renderedFrame - this.data.st);
  10530. if (glyphElement._mdf) {
  10531. this._mdf = true;
  10532. }
  10533. }
  10534. }
  10535. };
  10536. SVGTextLottieElement.prototype.renderInnerContent = function () {
  10537. if (!this.data.singleShape || this._mdf) {
  10538. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  10539. if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) {
  10540. this._sizeChanged = true;
  10541. var i;
  10542. var len;
  10543. var renderedLetters = this.textAnimator.renderedLetters;
  10544. var letters = this.textProperty.currentData.l;
  10545. len = letters.length;
  10546. var renderedLetter;
  10547. var textSpan;
  10548. var glyphElement;
  10549. for (i = 0; i < len; i += 1) {
  10550. if (!letters[i].n) {
  10551. renderedLetter = renderedLetters[i];
  10552. textSpan = this.textSpans[i].span;
  10553. glyphElement = this.textSpans[i].glyph;
  10554. if (glyphElement) {
  10555. glyphElement.renderFrame();
  10556. }
  10557. if (renderedLetter._mdf.m) {
  10558. textSpan.setAttribute('transform', renderedLetter.m);
  10559. }
  10560. if (renderedLetter._mdf.o) {
  10561. textSpan.setAttribute('opacity', renderedLetter.o);
  10562. }
  10563. if (renderedLetter._mdf.sw) {
  10564. textSpan.setAttribute('stroke-width', renderedLetter.sw);
  10565. }
  10566. if (renderedLetter._mdf.sc) {
  10567. textSpan.setAttribute('stroke', renderedLetter.sc);
  10568. }
  10569. if (renderedLetter._mdf.fc) {
  10570. textSpan.setAttribute('fill', renderedLetter.fc);
  10571. }
  10572. }
  10573. }
  10574. }
  10575. }
  10576. };
  10577. function ISolidElement(data, globalData, comp) {
  10578. this.initElement(data, globalData, comp);
  10579. }
  10580. extendPrototype([IImageElement], ISolidElement);
  10581. ISolidElement.prototype.createContent = function () {
  10582. var rect = createNS('rect');
  10583. /// /rect.style.width = this.data.sw;
  10584. /// /rect.style.height = this.data.sh;
  10585. /// /rect.style.fill = this.data.sc;
  10586. rect.setAttribute('width', this.data.sw);
  10587. rect.setAttribute('height', this.data.sh);
  10588. rect.setAttribute('fill', this.data.sc);
  10589. this.layerElement.appendChild(rect);
  10590. };
  10591. function NullElement(data, globalData, comp) {
  10592. this.initFrame();
  10593. this.initBaseData(data, globalData, comp);
  10594. this.initFrame();
  10595. this.initTransform(data, globalData, comp);
  10596. this.initHierarchy();
  10597. }
  10598. NullElement.prototype.prepareFrame = function (num) {
  10599. this.prepareProperties(num, true);
  10600. };
  10601. NullElement.prototype.renderFrame = function () {
  10602. };
  10603. NullElement.prototype.getBaseElement = function () {
  10604. return null;
  10605. };
  10606. NullElement.prototype.destroy = function () {
  10607. };
  10608. NullElement.prototype.sourceRectAtTime = function () {
  10609. };
  10610. NullElement.prototype.hide = function () {
  10611. };
  10612. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement);
  10613. function SVGRendererBase() {
  10614. }
  10615. extendPrototype([BaseRenderer], SVGRendererBase);
  10616. SVGRendererBase.prototype.createNull = function (data) {
  10617. return new NullElement(data, this.globalData, this);
  10618. };
  10619. SVGRendererBase.prototype.createShape = function (data) {
  10620. return new SVGShapeElement(data, this.globalData, this);
  10621. };
  10622. SVGRendererBase.prototype.createText = function (data) {
  10623. return new SVGTextLottieElement(data, this.globalData, this);
  10624. };
  10625. SVGRendererBase.prototype.createImage = function (data) {
  10626. return new IImageElement(data, this.globalData, this);
  10627. };
  10628. SVGRendererBase.prototype.createSolid = function (data) {
  10629. return new ISolidElement(data, this.globalData, this);
  10630. };
  10631. SVGRendererBase.prototype.configAnimation = function (animData) {
  10632. this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  10633. if (this.renderConfig.viewBoxSize) {
  10634. this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize);
  10635. } else {
  10636. this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h);
  10637. }
  10638. if (!this.renderConfig.viewBoxOnly) {
  10639. this.svgElement.setAttribute('width', animData.w);
  10640. this.svgElement.setAttribute('height', animData.h);
  10641. this.svgElement.style.width = '100%';
  10642. this.svgElement.style.height = '100%';
  10643. this.svgElement.style.transform = 'translate3d(0,0,0)';
  10644. this.svgElement.style.contentVisibility = this.renderConfig.contentVisibility;
  10645. }
  10646. if (this.renderConfig.width) {
  10647. this.svgElement.setAttribute('width', this.renderConfig.width);
  10648. }
  10649. if (this.renderConfig.height) {
  10650. this.svgElement.setAttribute('height', this.renderConfig.height);
  10651. }
  10652. if (this.renderConfig.className) {
  10653. this.svgElement.setAttribute('class', this.renderConfig.className);
  10654. }
  10655. if (this.renderConfig.id) {
  10656. this.svgElement.setAttribute('id', this.renderConfig.id);
  10657. }
  10658. if (this.renderConfig.focusable !== undefined) {
  10659. this.svgElement.setAttribute('focusable', this.renderConfig.focusable);
  10660. }
  10661. this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio);
  10662. // this.layerElement.style.transform = 'translate3d(0,0,0)';
  10663. // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  10664. this.animationItem.wrapper.appendChild(this.svgElement);
  10665. // Mask animation
  10666. var defs = this.globalData.defs;
  10667. this.setupGlobalData(animData, defs);
  10668. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  10669. this.data = animData;
  10670. var maskElement = createNS('clipPath');
  10671. var rect = createNS('rect');
  10672. rect.setAttribute('width', animData.w);
  10673. rect.setAttribute('height', animData.h);
  10674. rect.setAttribute('x', 0);
  10675. rect.setAttribute('y', 0);
  10676. var maskId = createElementID();
  10677. maskElement.setAttribute('id', maskId);
  10678. maskElement.appendChild(rect);
  10679. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + maskId + ')');
  10680. defs.appendChild(maskElement);
  10681. this.layers = animData.layers;
  10682. this.elements = createSizedArray(animData.layers.length);
  10683. };
  10684. SVGRendererBase.prototype.destroy = function () {
  10685. if (this.animationItem.wrapper) {
  10686. this.animationItem.wrapper.innerText = '';
  10687. }
  10688. this.layerElement = null;
  10689. this.globalData.defs = null;
  10690. var i;
  10691. var len = this.layers ? this.layers.length : 0;
  10692. for (i = 0; i < len; i += 1) {
  10693. if (this.elements[i]) {
  10694. this.elements[i].destroy();
  10695. }
  10696. }
  10697. this.elements.length = 0;
  10698. this.destroyed = true;
  10699. this.animationItem = null;
  10700. };
  10701. SVGRendererBase.prototype.updateContainerSize = function () {
  10702. };
  10703. SVGRendererBase.prototype.buildItem = function (pos) {
  10704. var elements = this.elements;
  10705. if (elements[pos] || this.layers[pos].ty === 99) {
  10706. return;
  10707. }
  10708. elements[pos] = true;
  10709. var element = this.createItem(this.layers[pos]);
  10710. elements[pos] = element;
  10711. if (getExpressionsPlugin()) {
  10712. if (this.layers[pos].ty === 0) {
  10713. this.globalData.projectInterface.registerComposition(element);
  10714. }
  10715. element.initExpressions();
  10716. }
  10717. this.appendElementInPos(element, pos);
  10718. if (this.layers[pos].tt) {
  10719. if (!this.elements[pos - 1] || this.elements[pos - 1] === true) {
  10720. this.buildItem(pos - 1);
  10721. this.addPendingElement(element);
  10722. } else {
  10723. element.setMatte(elements[pos - 1].layerId);
  10724. }
  10725. }
  10726. };
  10727. SVGRendererBase.prototype.checkPendingElements = function () {
  10728. while (this.pendingElements.length) {
  10729. var element = this.pendingElements.pop();
  10730. element.checkParenting();
  10731. if (element.data.tt) {
  10732. var i = 0;
  10733. var len = this.elements.length;
  10734. while (i < len) {
  10735. if (this.elements[i] === element) {
  10736. element.setMatte(this.elements[i - 1].layerId);
  10737. break;
  10738. }
  10739. i += 1;
  10740. }
  10741. }
  10742. }
  10743. };
  10744. SVGRendererBase.prototype.renderFrame = function (num) {
  10745. if (this.renderedFrame === num || this.destroyed) {
  10746. return;
  10747. }
  10748. if (num === null) {
  10749. num = this.renderedFrame;
  10750. } else {
  10751. this.renderedFrame = num;
  10752. }
  10753. // console.log('-------');
  10754. // console.log('FRAME ',num);
  10755. this.globalData.frameNum = num;
  10756. this.globalData.frameId += 1;
  10757. this.globalData.projectInterface.currentFrame = num;
  10758. this.globalData._mdf = false;
  10759. var i;
  10760. var len = this.layers.length;
  10761. if (!this.completeLayers) {
  10762. this.checkLayers(num);
  10763. }
  10764. for (i = len - 1; i >= 0; i -= 1) {
  10765. if (this.completeLayers || this.elements[i]) {
  10766. this.elements[i].prepareFrame(num - this.layers[i].st);
  10767. }
  10768. }
  10769. if (this.globalData._mdf) {
  10770. for (i = 0; i < len; i += 1) {
  10771. if (this.completeLayers || this.elements[i]) {
  10772. this.elements[i].renderFrame();
  10773. }
  10774. }
  10775. }
  10776. };
  10777. SVGRendererBase.prototype.appendElementInPos = function (element, pos) {
  10778. var newElement = element.getBaseElement();
  10779. if (!newElement) {
  10780. return;
  10781. }
  10782. var i = 0;
  10783. var nextElement;
  10784. while (i < pos) {
  10785. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) {
  10786. nextElement = this.elements[i].getBaseElement();
  10787. }
  10788. i += 1;
  10789. }
  10790. if (nextElement) {
  10791. this.layerElement.insertBefore(newElement, nextElement);
  10792. } else {
  10793. this.layerElement.appendChild(newElement);
  10794. }
  10795. };
  10796. SVGRendererBase.prototype.hide = function () {
  10797. this.layerElement.style.display = 'none';
  10798. };
  10799. SVGRendererBase.prototype.show = function () {
  10800. this.layerElement.style.display = 'block';
  10801. };
  10802. function ICompElement() {}
  10803. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  10804. ICompElement.prototype.initElement = function (data, globalData, comp) {
  10805. this.initFrame();
  10806. this.initBaseData(data, globalData, comp);
  10807. this.initTransform(data, globalData, comp);
  10808. this.initRenderable();
  10809. this.initHierarchy();
  10810. this.initRendererElement();
  10811. this.createContainerElements();
  10812. this.createRenderableComponents();
  10813. if (this.data.xt || !globalData.progressiveLoad) {
  10814. this.buildAllItems();
  10815. }
  10816. this.hide();
  10817. };
  10818. /* ICompElement.prototype.hide = function(){
  10819. if(!this.hidden){
  10820. this.hideElement();
  10821. var i,len = this.elements.length;
  10822. for( i = 0; i < len; i+=1 ){
  10823. if(this.elements[i]){
  10824. this.elements[i].hide();
  10825. }
  10826. }
  10827. }
  10828. }; */
  10829. ICompElement.prototype.prepareFrame = function (num) {
  10830. this._mdf = false;
  10831. this.prepareRenderableFrame(num);
  10832. this.prepareProperties(num, this.isInRange);
  10833. if (!this.isInRange && !this.data.xt) {
  10834. return;
  10835. }
  10836. if (!this.tm._placeholder) {
  10837. var timeRemapped = this.tm.v;
  10838. if (timeRemapped === this.data.op) {
  10839. timeRemapped = this.data.op - 1;
  10840. }
  10841. this.renderedFrame = timeRemapped;
  10842. } else {
  10843. this.renderedFrame = num / this.data.sr;
  10844. }
  10845. var i;
  10846. var len = this.elements.length;
  10847. if (!this.completeLayers) {
  10848. this.checkLayers(this.renderedFrame);
  10849. }
  10850. // This iteration needs to be backwards because of how expressions connect between each other
  10851. for (i = len - 1; i >= 0; i -= 1) {
  10852. if (this.completeLayers || this.elements[i]) {
  10853. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  10854. if (this.elements[i]._mdf) {
  10855. this._mdf = true;
  10856. }
  10857. }
  10858. }
  10859. };
  10860. ICompElement.prototype.renderInnerContent = function () {
  10861. var i;
  10862. var len = this.layers.length;
  10863. for (i = 0; i < len; i += 1) {
  10864. if (this.completeLayers || this.elements[i]) {
  10865. this.elements[i].renderFrame();
  10866. }
  10867. }
  10868. };
  10869. ICompElement.prototype.setElements = function (elems) {
  10870. this.elements = elems;
  10871. };
  10872. ICompElement.prototype.getElements = function () {
  10873. return this.elements;
  10874. };
  10875. ICompElement.prototype.destroyElements = function () {
  10876. var i;
  10877. var len = this.layers.length;
  10878. for (i = 0; i < len; i += 1) {
  10879. if (this.elements[i]) {
  10880. this.elements[i].destroy();
  10881. }
  10882. }
  10883. };
  10884. ICompElement.prototype.destroy = function () {
  10885. this.destroyElements();
  10886. this.destroyBaseElement();
  10887. };
  10888. function SVGCompElement(data, globalData, comp) {
  10889. this.layers = data.layers;
  10890. this.supports3d = true;
  10891. this.completeLayers = false;
  10892. this.pendingElements = [];
  10893. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  10894. this.initElement(data, globalData, comp);
  10895. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  10896. }
  10897. extendPrototype([SVGRendererBase, ICompElement, SVGBaseElement], SVGCompElement);
  10898. SVGCompElement.prototype.createComp = function (data) {
  10899. return new SVGCompElement(data, this.globalData, this);
  10900. };
  10901. function SVGRenderer(animationItem, config) {
  10902. this.animationItem = animationItem;
  10903. this.layers = null;
  10904. this.renderedFrame = -1;
  10905. this.svgElement = createNS('svg');
  10906. var ariaLabel = '';
  10907. if (config && config.title) {
  10908. var titleElement = createNS('title');
  10909. var titleId = createElementID();
  10910. titleElement.setAttribute('id', titleId);
  10911. titleElement.textContent = config.title;
  10912. this.svgElement.appendChild(titleElement);
  10913. ariaLabel += titleId;
  10914. }
  10915. if (config && config.description) {
  10916. var descElement = createNS('desc');
  10917. var descId = createElementID();
  10918. descElement.setAttribute('id', descId);
  10919. descElement.textContent = config.description;
  10920. this.svgElement.appendChild(descElement);
  10921. ariaLabel += ' ' + descId;
  10922. }
  10923. if (ariaLabel) {
  10924. this.svgElement.setAttribute('aria-labelledby', ariaLabel);
  10925. }
  10926. var defs = createNS('defs');
  10927. this.svgElement.appendChild(defs);
  10928. var maskElement = createNS('g');
  10929. this.svgElement.appendChild(maskElement);
  10930. this.layerElement = maskElement;
  10931. this.renderConfig = {
  10932. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  10933. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  10934. contentVisibility: (config && config.contentVisibility) || 'visible',
  10935. progressiveLoad: (config && config.progressiveLoad) || false,
  10936. hideOnTransparent: !((config && config.hideOnTransparent === false)),
  10937. viewBoxOnly: (config && config.viewBoxOnly) || false,
  10938. viewBoxSize: (config && config.viewBoxSize) || false,
  10939. className: (config && config.className) || '',
  10940. id: (config && config.id) || '',
  10941. focusable: config && config.focusable,
  10942. filterSize: {
  10943. width: (config && config.filterSize && config.filterSize.width) || '100%',
  10944. height: (config && config.filterSize && config.filterSize.height) || '100%',
  10945. x: (config && config.filterSize && config.filterSize.x) || '0%',
  10946. y: (config && config.filterSize && config.filterSize.y) || '0%',
  10947. },
  10948. width: (config && config.width),
  10949. height: (config && config.height),
  10950. };
  10951. this.globalData = {
  10952. _mdf: false,
  10953. frameNum: -1,
  10954. defs: defs,
  10955. renderConfig: this.renderConfig,
  10956. };
  10957. this.elements = [];
  10958. this.pendingElements = [];
  10959. this.destroyed = false;
  10960. this.rendererType = 'svg';
  10961. }
  10962. extendPrototype([SVGRendererBase], SVGRenderer);
  10963. SVGRenderer.prototype.createComp = function (data) {
  10964. return new SVGCompElement(data, this.globalData, this);
  10965. };
  10966. function CVContextData() {
  10967. this.saved = [];
  10968. this.cArrPos = 0;
  10969. this.cTr = new Matrix();
  10970. this.cO = 1;
  10971. var i;
  10972. var len = 15;
  10973. this.savedOp = createTypedArray('float32', len);
  10974. for (i = 0; i < len; i += 1) {
  10975. this.saved[i] = createTypedArray('float32', 16);
  10976. }
  10977. this._length = len;
  10978. }
  10979. CVContextData.prototype.duplicate = function () {
  10980. var newLength = this._length * 2;
  10981. var currentSavedOp = this.savedOp;
  10982. this.savedOp = createTypedArray('float32', newLength);
  10983. this.savedOp.set(currentSavedOp);
  10984. var i = 0;
  10985. for (i = this._length; i < newLength; i += 1) {
  10986. this.saved[i] = createTypedArray('float32', 16);
  10987. }
  10988. this._length = newLength;
  10989. };
  10990. CVContextData.prototype.reset = function () {
  10991. this.cArrPos = 0;
  10992. this.cTr.reset();
  10993. this.cO = 1;
  10994. };
  10995. function ShapeTransformManager() {
  10996. this.sequences = {};
  10997. this.sequenceList = [];
  10998. this.transform_key_count = 0;
  10999. }
  11000. ShapeTransformManager.prototype = {
  11001. addTransformSequence: function (transforms) {
  11002. var i;
  11003. var len = transforms.length;
  11004. var key = '_';
  11005. for (i = 0; i < len; i += 1) {
  11006. key += transforms[i].transform.key + '_';
  11007. }
  11008. var sequence = this.sequences[key];
  11009. if (!sequence) {
  11010. sequence = {
  11011. transforms: [].concat(transforms),
  11012. finalTransform: new Matrix(),
  11013. _mdf: false,
  11014. };
  11015. this.sequences[key] = sequence;
  11016. this.sequenceList.push(sequence);
  11017. }
  11018. return sequence;
  11019. },
  11020. processSequence: function (sequence, isFirstFrame) {
  11021. var i = 0;
  11022. var len = sequence.transforms.length;
  11023. var _mdf = isFirstFrame;
  11024. while (i < len && !isFirstFrame) {
  11025. if (sequence.transforms[i].transform.mProps._mdf) {
  11026. _mdf = true;
  11027. break;
  11028. }
  11029. i += 1;
  11030. }
  11031. if (_mdf) {
  11032. var props;
  11033. sequence.finalTransform.reset();
  11034. for (i = len - 1; i >= 0; i -= 1) {
  11035. props = sequence.transforms[i].transform.mProps.v.props;
  11036. sequence.finalTransform.transform(props[0], props[1], props[2], props[3], props[4], props[5], props[6], props[7], props[8], props[9], props[10], props[11], props[12], props[13], props[14], props[15]);
  11037. }
  11038. }
  11039. sequence._mdf = _mdf;
  11040. },
  11041. processSequences: function (isFirstFrame) {
  11042. var i;
  11043. var len = this.sequenceList.length;
  11044. for (i = 0; i < len; i += 1) {
  11045. this.processSequence(this.sequenceList[i], isFirstFrame);
  11046. }
  11047. },
  11048. getNewKey: function () {
  11049. this.transform_key_count += 1;
  11050. return '_' + this.transform_key_count;
  11051. },
  11052. };
  11053. function CVEffects() {
  11054. }
  11055. CVEffects.prototype.renderFrame = function () {};
  11056. function CVMaskElement(data, element) {
  11057. this.data = data;
  11058. this.element = element;
  11059. this.masksProperties = this.data.masksProperties || [];
  11060. this.viewData = createSizedArray(this.masksProperties.length);
  11061. var i;
  11062. var len = this.masksProperties.length;
  11063. var hasMasks = false;
  11064. for (i = 0; i < len; i += 1) {
  11065. if (this.masksProperties[i].mode !== 'n') {
  11066. hasMasks = true;
  11067. }
  11068. this.viewData[i] = ShapePropertyFactory.getShapeProp(this.element, this.masksProperties[i], 3);
  11069. }
  11070. this.hasMasks = hasMasks;
  11071. if (hasMasks) {
  11072. this.element.addRenderableComponent(this);
  11073. }
  11074. }
  11075. CVMaskElement.prototype.renderFrame = function () {
  11076. if (!this.hasMasks) {
  11077. return;
  11078. }
  11079. var transform = this.element.finalTransform.mat;
  11080. var ctx = this.element.canvasContext;
  11081. var i;
  11082. var len = this.masksProperties.length;
  11083. var pt;
  11084. var pts;
  11085. var data;
  11086. ctx.beginPath();
  11087. for (i = 0; i < len; i += 1) {
  11088. if (this.masksProperties[i].mode !== 'n') {
  11089. if (this.masksProperties[i].inv) {
  11090. ctx.moveTo(0, 0);
  11091. ctx.lineTo(this.element.globalData.compSize.w, 0);
  11092. ctx.lineTo(this.element.globalData.compSize.w, this.element.globalData.compSize.h);
  11093. ctx.lineTo(0, this.element.globalData.compSize.h);
  11094. ctx.lineTo(0, 0);
  11095. }
  11096. data = this.viewData[i].v;
  11097. pt = transform.applyToPointArray(data.v[0][0], data.v[0][1], 0);
  11098. ctx.moveTo(pt[0], pt[1]);
  11099. var j;
  11100. var jLen = data._length;
  11101. for (j = 1; j < jLen; j += 1) {
  11102. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[j], data.v[j]);
  11103. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  11104. }
  11105. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[0], data.v[0]);
  11106. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  11107. }
  11108. }
  11109. this.element.globalData.renderer.save(true);
  11110. ctx.clip();
  11111. };
  11112. CVMaskElement.prototype.getMaskProperty = MaskElement.prototype.getMaskProperty;
  11113. CVMaskElement.prototype.destroy = function () {
  11114. this.element = null;
  11115. };
  11116. function CVBaseElement() {
  11117. }
  11118. CVBaseElement.prototype = {
  11119. createElements: function () {},
  11120. initRendererElement: function () {},
  11121. createContainerElements: function () {
  11122. this.canvasContext = this.globalData.canvasContext;
  11123. this.renderableEffectsManager = new CVEffects(this);
  11124. },
  11125. createContent: function () {},
  11126. setBlendMode: function () {
  11127. var globalData = this.globalData;
  11128. if (globalData.blendMode !== this.data.bm) {
  11129. globalData.blendMode = this.data.bm;
  11130. var blendModeValue = getBlendMode(this.data.bm);
  11131. globalData.canvasContext.globalCompositeOperation = blendModeValue;
  11132. }
  11133. },
  11134. createRenderableComponents: function () {
  11135. this.maskManager = new CVMaskElement(this.data, this);
  11136. },
  11137. hideElement: function () {
  11138. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  11139. this.hidden = true;
  11140. }
  11141. },
  11142. showElement: function () {
  11143. if (this.isInRange && !this.isTransparent) {
  11144. this.hidden = false;
  11145. this._isFirstFrame = true;
  11146. this.maskManager._isFirstFrame = true;
  11147. }
  11148. },
  11149. renderFrame: function () {
  11150. if (this.hidden || this.data.hd) {
  11151. return;
  11152. }
  11153. this.renderTransform();
  11154. this.renderRenderable();
  11155. this.setBlendMode();
  11156. var forceRealStack = this.data.ty === 0;
  11157. this.globalData.renderer.save(forceRealStack);
  11158. this.globalData.renderer.ctxTransform(this.finalTransform.mat.props);
  11159. this.globalData.renderer.ctxOpacity(this.finalTransform.mProp.o.v);
  11160. this.renderInnerContent();
  11161. this.globalData.renderer.restore(forceRealStack);
  11162. if (this.maskManager.hasMasks) {
  11163. this.globalData.renderer.restore(true);
  11164. }
  11165. if (this._isFirstFrame) {
  11166. this._isFirstFrame = false;
  11167. }
  11168. },
  11169. destroy: function () {
  11170. this.canvasContext = null;
  11171. this.data = null;
  11172. this.globalData = null;
  11173. this.maskManager.destroy();
  11174. },
  11175. mHelper: new Matrix(),
  11176. };
  11177. CVBaseElement.prototype.hide = CVBaseElement.prototype.hideElement;
  11178. CVBaseElement.prototype.show = CVBaseElement.prototype.showElement;
  11179. function CVShapeData(element, data, styles, transformsManager) {
  11180. this.styledShapes = [];
  11181. this.tr = [0, 0, 0, 0, 0, 0];
  11182. var ty = 4;
  11183. if (data.ty === 'rc') {
  11184. ty = 5;
  11185. } else if (data.ty === 'el') {
  11186. ty = 6;
  11187. } else if (data.ty === 'sr') {
  11188. ty = 7;
  11189. }
  11190. this.sh = ShapePropertyFactory.getShapeProp(element, data, ty, element);
  11191. var i;
  11192. var len = styles.length;
  11193. var styledShape;
  11194. for (i = 0; i < len; i += 1) {
  11195. if (!styles[i].closed) {
  11196. styledShape = {
  11197. transforms: transformsManager.addTransformSequence(styles[i].transforms),
  11198. trNodes: [],
  11199. };
  11200. this.styledShapes.push(styledShape);
  11201. styles[i].elements.push(styledShape);
  11202. }
  11203. }
  11204. }
  11205. CVShapeData.prototype.setAsAnimated = SVGShapeData.prototype.setAsAnimated;
  11206. function CVShapeElement(data, globalData, comp) {
  11207. this.shapes = [];
  11208. this.shapesData = data.shapes;
  11209. this.stylesList = [];
  11210. this.itemsData = [];
  11211. this.prevViewData = [];
  11212. this.shapeModifiers = [];
  11213. this.processedElements = [];
  11214. this.transformsManager = new ShapeTransformManager();
  11215. this.initElement(data, globalData, comp);
  11216. }
  11217. extendPrototype([BaseElement, TransformElement, CVBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableElement], CVShapeElement);
  11218. CVShapeElement.prototype.initElement = RenderableDOMElement.prototype.initElement;
  11219. CVShapeElement.prototype.transformHelper = { opacity: 1, _opMdf: false };
  11220. CVShapeElement.prototype.dashResetter = [];
  11221. CVShapeElement.prototype.createContent = function () {
  11222. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
  11223. };
  11224. CVShapeElement.prototype.createStyleElement = function (data, transforms) {
  11225. var styleElem = {
  11226. data: data,
  11227. type: data.ty,
  11228. preTransforms: this.transformsManager.addTransformSequence(transforms),
  11229. transforms: [],
  11230. elements: [],
  11231. closed: data.hd === true,
  11232. };
  11233. var elementData = {};
  11234. if (data.ty === 'fl' || data.ty === 'st') {
  11235. elementData.c = PropertyFactory.getProp(this, data.c, 1, 255, this);
  11236. if (!elementData.c.k) {
  11237. styleElem.co = 'rgb(' + bmFloor(elementData.c.v[0]) + ',' + bmFloor(elementData.c.v[1]) + ',' + bmFloor(elementData.c.v[2]) + ')';
  11238. }
  11239. } else if (data.ty === 'gf' || data.ty === 'gs') {
  11240. elementData.s = PropertyFactory.getProp(this, data.s, 1, null, this);
  11241. elementData.e = PropertyFactory.getProp(this, data.e, 1, null, this);
  11242. elementData.h = PropertyFactory.getProp(this, data.h || { k: 0 }, 0, 0.01, this);
  11243. elementData.a = PropertyFactory.getProp(this, data.a || { k: 0 }, 0, degToRads, this);
  11244. elementData.g = new GradientProperty(this, data.g, this);
  11245. }
  11246. elementData.o = PropertyFactory.getProp(this, data.o, 0, 0.01, this);
  11247. if (data.ty === 'st' || data.ty === 'gs') {
  11248. styleElem.lc = lineCapEnum[data.lc || 2];
  11249. styleElem.lj = lineJoinEnum[data.lj || 2];
  11250. if (data.lj == 1) { // eslint-disable-line eqeqeq
  11251. styleElem.ml = data.ml;
  11252. }
  11253. elementData.w = PropertyFactory.getProp(this, data.w, 0, null, this);
  11254. if (!elementData.w.k) {
  11255. styleElem.wi = elementData.w.v;
  11256. }
  11257. if (data.d) {
  11258. var d = new DashProperty(this, data.d, 'canvas', this);
  11259. elementData.d = d;
  11260. if (!elementData.d.k) {
  11261. styleElem.da = elementData.d.dashArray;
  11262. styleElem.do = elementData.d.dashoffset[0];
  11263. }
  11264. }
  11265. } else {
  11266. styleElem.r = data.r === 2 ? 'evenodd' : 'nonzero';
  11267. }
  11268. this.stylesList.push(styleElem);
  11269. elementData.style = styleElem;
  11270. return elementData;
  11271. };
  11272. CVShapeElement.prototype.createGroupElement = function () {
  11273. var elementData = {
  11274. it: [],
  11275. prevViewData: [],
  11276. };
  11277. return elementData;
  11278. };
  11279. CVShapeElement.prototype.createTransformElement = function (data) {
  11280. var elementData = {
  11281. transform: {
  11282. opacity: 1,
  11283. _opMdf: false,
  11284. key: this.transformsManager.getNewKey(),
  11285. op: PropertyFactory.getProp(this, data.o, 0, 0.01, this),
  11286. mProps: TransformPropertyFactory.getTransformProperty(this, data, this),
  11287. },
  11288. };
  11289. return elementData;
  11290. };
  11291. CVShapeElement.prototype.createShapeElement = function (data) {
  11292. var elementData = new CVShapeData(this, data, this.stylesList, this.transformsManager);
  11293. this.shapes.push(elementData);
  11294. this.addShapeToModifiers(elementData);
  11295. return elementData;
  11296. };
  11297. CVShapeElement.prototype.reloadShapes = function () {
  11298. this._isFirstFrame = true;
  11299. var i;
  11300. var len = this.itemsData.length;
  11301. for (i = 0; i < len; i += 1) {
  11302. this.prevViewData[i] = this.itemsData[i];
  11303. }
  11304. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
  11305. len = this.dynamicProperties.length;
  11306. for (i = 0; i < len; i += 1) {
  11307. this.dynamicProperties[i].getValue();
  11308. }
  11309. this.renderModifiers();
  11310. this.transformsManager.processSequences(this._isFirstFrame);
  11311. };
  11312. CVShapeElement.prototype.addTransformToStyleList = function (transform) {
  11313. var i;
  11314. var len = this.stylesList.length;
  11315. for (i = 0; i < len; i += 1) {
  11316. if (!this.stylesList[i].closed) {
  11317. this.stylesList[i].transforms.push(transform);
  11318. }
  11319. }
  11320. };
  11321. CVShapeElement.prototype.removeTransformFromStyleList = function () {
  11322. var i;
  11323. var len = this.stylesList.length;
  11324. for (i = 0; i < len; i += 1) {
  11325. if (!this.stylesList[i].closed) {
  11326. this.stylesList[i].transforms.pop();
  11327. }
  11328. }
  11329. };
  11330. CVShapeElement.prototype.closeStyles = function (styles) {
  11331. var i;
  11332. var len = styles.length;
  11333. for (i = 0; i < len; i += 1) {
  11334. styles[i].closed = true;
  11335. }
  11336. };
  11337. CVShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, shouldRender, transforms) {
  11338. var i;
  11339. var len = arr.length - 1;
  11340. var j;
  11341. var jLen;
  11342. var ownStyles = [];
  11343. var ownModifiers = [];
  11344. var processedPos;
  11345. var modifier;
  11346. var currentTransform;
  11347. var ownTransforms = [].concat(transforms);
  11348. for (i = len; i >= 0; i -= 1) {
  11349. processedPos = this.searchProcessedElement(arr[i]);
  11350. if (!processedPos) {
  11351. arr[i]._shouldRender = shouldRender;
  11352. } else {
  11353. itemsData[i] = prevViewData[processedPos - 1];
  11354. }
  11355. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs') {
  11356. if (!processedPos) {
  11357. itemsData[i] = this.createStyleElement(arr[i], ownTransforms);
  11358. } else {
  11359. itemsData[i].style.closed = false;
  11360. }
  11361. ownStyles.push(itemsData[i].style);
  11362. } else if (arr[i].ty === 'gr') {
  11363. if (!processedPos) {
  11364. itemsData[i] = this.createGroupElement(arr[i]);
  11365. } else {
  11366. jLen = itemsData[i].it.length;
  11367. for (j = 0; j < jLen; j += 1) {
  11368. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  11369. }
  11370. }
  11371. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, shouldRender, ownTransforms);
  11372. } else if (arr[i].ty === 'tr') {
  11373. if (!processedPos) {
  11374. currentTransform = this.createTransformElement(arr[i]);
  11375. itemsData[i] = currentTransform;
  11376. }
  11377. ownTransforms.push(itemsData[i]);
  11378. this.addTransformToStyleList(itemsData[i]);
  11379. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  11380. if (!processedPos) {
  11381. itemsData[i] = this.createShapeElement(arr[i]);
  11382. }
  11383. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'pb') {
  11384. if (!processedPos) {
  11385. modifier = ShapeModifiers.getModifier(arr[i].ty);
  11386. modifier.init(this, arr[i]);
  11387. itemsData[i] = modifier;
  11388. this.shapeModifiers.push(modifier);
  11389. } else {
  11390. modifier = itemsData[i];
  11391. modifier.closed = false;
  11392. }
  11393. ownModifiers.push(modifier);
  11394. } else if (arr[i].ty === 'rp') {
  11395. if (!processedPos) {
  11396. modifier = ShapeModifiers.getModifier(arr[i].ty);
  11397. itemsData[i] = modifier;
  11398. modifier.init(this, arr, i, itemsData);
  11399. this.shapeModifiers.push(modifier);
  11400. shouldRender = false;
  11401. } else {
  11402. modifier = itemsData[i];
  11403. modifier.closed = true;
  11404. }
  11405. ownModifiers.push(modifier);
  11406. }
  11407. this.addProcessedElement(arr[i], i + 1);
  11408. }
  11409. this.removeTransformFromStyleList();
  11410. this.closeStyles(ownStyles);
  11411. len = ownModifiers.length;
  11412. for (i = 0; i < len; i += 1) {
  11413. ownModifiers[i].closed = true;
  11414. }
  11415. };
  11416. CVShapeElement.prototype.renderInnerContent = function () {
  11417. this.transformHelper.opacity = 1;
  11418. this.transformHelper._opMdf = false;
  11419. this.renderModifiers();
  11420. this.transformsManager.processSequences(this._isFirstFrame);
  11421. this.renderShape(this.transformHelper, this.shapesData, this.itemsData, true);
  11422. };
  11423. CVShapeElement.prototype.renderShapeTransform = function (parentTransform, groupTransform) {
  11424. if (parentTransform._opMdf || groupTransform.op._mdf || this._isFirstFrame) {
  11425. groupTransform.opacity = parentTransform.opacity;
  11426. groupTransform.opacity *= groupTransform.op.v;
  11427. groupTransform._opMdf = true;
  11428. }
  11429. };
  11430. CVShapeElement.prototype.drawLayer = function () {
  11431. var i;
  11432. var len = this.stylesList.length;
  11433. var j;
  11434. var jLen;
  11435. var k;
  11436. var kLen;
  11437. var elems;
  11438. var nodes;
  11439. var renderer = this.globalData.renderer;
  11440. var ctx = this.globalData.canvasContext;
  11441. var type;
  11442. var currentStyle;
  11443. for (i = 0; i < len; i += 1) {
  11444. currentStyle = this.stylesList[i];
  11445. type = currentStyle.type;
  11446. // Skipping style when
  11447. // Stroke width equals 0
  11448. // style should not be rendered (extra unused repeaters)
  11449. // current opacity equals 0
  11450. // global opacity equals 0
  11451. if (!(((type === 'st' || type === 'gs') && currentStyle.wi === 0) || !currentStyle.data._shouldRender || currentStyle.coOp === 0 || this.globalData.currentGlobalAlpha === 0)) {
  11452. renderer.save();
  11453. elems = currentStyle.elements;
  11454. if (type === 'st' || type === 'gs') {
  11455. ctx.strokeStyle = type === 'st' ? currentStyle.co : currentStyle.grd;
  11456. ctx.lineWidth = currentStyle.wi;
  11457. ctx.lineCap = currentStyle.lc;
  11458. ctx.lineJoin = currentStyle.lj;
  11459. ctx.miterLimit = currentStyle.ml || 0;
  11460. } else {
  11461. ctx.fillStyle = type === 'fl' ? currentStyle.co : currentStyle.grd;
  11462. }
  11463. renderer.ctxOpacity(currentStyle.coOp);
  11464. if (type !== 'st' && type !== 'gs') {
  11465. ctx.beginPath();
  11466. }
  11467. renderer.ctxTransform(currentStyle.preTransforms.finalTransform.props);
  11468. jLen = elems.length;
  11469. for (j = 0; j < jLen; j += 1) {
  11470. if (type === 'st' || type === 'gs') {
  11471. ctx.beginPath();
  11472. if (currentStyle.da) {
  11473. ctx.setLineDash(currentStyle.da);
  11474. ctx.lineDashOffset = currentStyle.do;
  11475. }
  11476. }
  11477. nodes = elems[j].trNodes;
  11478. kLen = nodes.length;
  11479. for (k = 0; k < kLen; k += 1) {
  11480. if (nodes[k].t === 'm') {
  11481. ctx.moveTo(nodes[k].p[0], nodes[k].p[1]);
  11482. } else if (nodes[k].t === 'c') {
  11483. ctx.bezierCurveTo(nodes[k].pts[0], nodes[k].pts[1], nodes[k].pts[2], nodes[k].pts[3], nodes[k].pts[4], nodes[k].pts[5]);
  11484. } else {
  11485. ctx.closePath();
  11486. }
  11487. }
  11488. if (type === 'st' || type === 'gs') {
  11489. ctx.stroke();
  11490. if (currentStyle.da) {
  11491. ctx.setLineDash(this.dashResetter);
  11492. }
  11493. }
  11494. }
  11495. if (type !== 'st' && type !== 'gs') {
  11496. ctx.fill(currentStyle.r);
  11497. }
  11498. renderer.restore();
  11499. }
  11500. }
  11501. };
  11502. CVShapeElement.prototype.renderShape = function (parentTransform, items, data, isMain) {
  11503. var i;
  11504. var len = items.length - 1;
  11505. var groupTransform;
  11506. groupTransform = parentTransform;
  11507. for (i = len; i >= 0; i -= 1) {
  11508. if (items[i].ty === 'tr') {
  11509. groupTransform = data[i].transform;
  11510. this.renderShapeTransform(parentTransform, groupTransform);
  11511. } else if (items[i].ty === 'sh' || items[i].ty === 'el' || items[i].ty === 'rc' || items[i].ty === 'sr') {
  11512. this.renderPath(items[i], data[i]);
  11513. } else if (items[i].ty === 'fl') {
  11514. this.renderFill(items[i], data[i], groupTransform);
  11515. } else if (items[i].ty === 'st') {
  11516. this.renderStroke(items[i], data[i], groupTransform);
  11517. } else if (items[i].ty === 'gf' || items[i].ty === 'gs') {
  11518. this.renderGradientFill(items[i], data[i], groupTransform);
  11519. } else if (items[i].ty === 'gr') {
  11520. this.renderShape(groupTransform, items[i].it, data[i].it);
  11521. } else if (items[i].ty === 'tm') {
  11522. //
  11523. }
  11524. }
  11525. if (isMain) {
  11526. this.drawLayer();
  11527. }
  11528. };
  11529. CVShapeElement.prototype.renderStyledShape = function (styledShape, shape) {
  11530. if (this._isFirstFrame || shape._mdf || styledShape.transforms._mdf) {
  11531. var shapeNodes = styledShape.trNodes;
  11532. var paths = shape.paths;
  11533. var i;
  11534. var len;
  11535. var j;
  11536. var jLen = paths._length;
  11537. shapeNodes.length = 0;
  11538. var groupTransformMat = styledShape.transforms.finalTransform;
  11539. for (j = 0; j < jLen; j += 1) {
  11540. var pathNodes = paths.shapes[j];
  11541. if (pathNodes && pathNodes.v) {
  11542. len = pathNodes._length;
  11543. for (i = 1; i < len; i += 1) {
  11544. if (i === 1) {
  11545. shapeNodes.push({
  11546. t: 'm',
  11547. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0),
  11548. });
  11549. }
  11550. shapeNodes.push({
  11551. t: 'c',
  11552. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[i], pathNodes.v[i]),
  11553. });
  11554. }
  11555. if (len === 1) {
  11556. shapeNodes.push({
  11557. t: 'm',
  11558. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0),
  11559. });
  11560. }
  11561. if (pathNodes.c && len) {
  11562. shapeNodes.push({
  11563. t: 'c',
  11564. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[0], pathNodes.v[0]),
  11565. });
  11566. shapeNodes.push({
  11567. t: 'z',
  11568. });
  11569. }
  11570. }
  11571. }
  11572. styledShape.trNodes = shapeNodes;
  11573. }
  11574. };
  11575. CVShapeElement.prototype.renderPath = function (pathData, itemData) {
  11576. if (pathData.hd !== true && pathData._shouldRender) {
  11577. var i;
  11578. var len = itemData.styledShapes.length;
  11579. for (i = 0; i < len; i += 1) {
  11580. this.renderStyledShape(itemData.styledShapes[i], itemData.sh);
  11581. }
  11582. }
  11583. };
  11584. CVShapeElement.prototype.renderFill = function (styleData, itemData, groupTransform) {
  11585. var styleElem = itemData.style;
  11586. if (itemData.c._mdf || this._isFirstFrame) {
  11587. styleElem.co = 'rgb('
  11588. + bmFloor(itemData.c.v[0]) + ','
  11589. + bmFloor(itemData.c.v[1]) + ','
  11590. + bmFloor(itemData.c.v[2]) + ')';
  11591. }
  11592. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  11593. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11594. }
  11595. };
  11596. CVShapeElement.prototype.renderGradientFill = function (styleData, itemData, groupTransform) {
  11597. var styleElem = itemData.style;
  11598. var grd;
  11599. if (!styleElem.grd || itemData.g._mdf || itemData.s._mdf || itemData.e._mdf || (styleData.t !== 1 && (itemData.h._mdf || itemData.a._mdf))) {
  11600. var ctx = this.globalData.canvasContext;
  11601. var pt1 = itemData.s.v;
  11602. var pt2 = itemData.e.v;
  11603. if (styleData.t === 1) {
  11604. grd = ctx.createLinearGradient(pt1[0], pt1[1], pt2[0], pt2[1]);
  11605. } else {
  11606. var rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  11607. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  11608. var percent = itemData.h.v;
  11609. if (percent >= 1) {
  11610. percent = 0.99;
  11611. } else if (percent <= -1) {
  11612. percent = -0.99;
  11613. }
  11614. var dist = rad * percent;
  11615. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  11616. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  11617. grd = ctx.createRadialGradient(x, y, 0, pt1[0], pt1[1], rad);
  11618. }
  11619. var i;
  11620. var len = styleData.g.p;
  11621. var cValues = itemData.g.c;
  11622. var opacity = 1;
  11623. for (i = 0; i < len; i += 1) {
  11624. if (itemData.g._hasOpacity && itemData.g._collapsable) {
  11625. opacity = itemData.g.o[i * 2 + 1];
  11626. }
  11627. grd.addColorStop(cValues[i * 4] / 100, 'rgba(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ',' + opacity + ')');
  11628. }
  11629. styleElem.grd = grd;
  11630. }
  11631. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11632. };
  11633. CVShapeElement.prototype.renderStroke = function (styleData, itemData, groupTransform) {
  11634. var styleElem = itemData.style;
  11635. var d = itemData.d;
  11636. if (d && (d._mdf || this._isFirstFrame)) {
  11637. styleElem.da = d.dashArray;
  11638. styleElem.do = d.dashoffset[0];
  11639. }
  11640. if (itemData.c._mdf || this._isFirstFrame) {
  11641. styleElem.co = 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')';
  11642. }
  11643. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  11644. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11645. }
  11646. if (itemData.w._mdf || this._isFirstFrame) {
  11647. styleElem.wi = itemData.w.v;
  11648. }
  11649. };
  11650. CVShapeElement.prototype.destroy = function () {
  11651. this.shapesData = null;
  11652. this.globalData = null;
  11653. this.canvasContext = null;
  11654. this.stylesList.length = 0;
  11655. this.itemsData.length = 0;
  11656. };
  11657. function CVTextElement(data, globalData, comp) {
  11658. this.textSpans = [];
  11659. this.yOffset = 0;
  11660. this.fillColorAnim = false;
  11661. this.strokeColorAnim = false;
  11662. this.strokeWidthAnim = false;
  11663. this.stroke = false;
  11664. this.fill = false;
  11665. this.justifyOffset = 0;
  11666. this.currentRender = null;
  11667. this.renderType = 'canvas';
  11668. this.values = {
  11669. fill: 'rgba(0,0,0,0)',
  11670. stroke: 'rgba(0,0,0,0)',
  11671. sWidth: 0,
  11672. fValue: '',
  11673. };
  11674. this.initElement(data, globalData, comp);
  11675. }
  11676. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement, ITextElement], CVTextElement);
  11677. CVTextElement.prototype.tHelper = createTag('canvas').getContext('2d');
  11678. CVTextElement.prototype.buildNewText = function () {
  11679. var documentData = this.textProperty.currentData;
  11680. this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
  11681. var hasFill = false;
  11682. if (documentData.fc) {
  11683. hasFill = true;
  11684. this.values.fill = this.buildColor(documentData.fc);
  11685. } else {
  11686. this.values.fill = 'rgba(0,0,0,0)';
  11687. }
  11688. this.fill = hasFill;
  11689. var hasStroke = false;
  11690. if (documentData.sc) {
  11691. hasStroke = true;
  11692. this.values.stroke = this.buildColor(documentData.sc);
  11693. this.values.sWidth = documentData.sw;
  11694. }
  11695. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  11696. var i;
  11697. var len;
  11698. var letters = documentData.l;
  11699. var matrixHelper = this.mHelper;
  11700. this.stroke = hasStroke;
  11701. this.values.fValue = documentData.finalSize + 'px ' + this.globalData.fontManager.getFontByName(documentData.f).fFamily;
  11702. len = documentData.finalText.length;
  11703. // this.tHelper.font = this.values.fValue;
  11704. var charData;
  11705. var shapeData;
  11706. var k;
  11707. var kLen;
  11708. var shapes;
  11709. var j;
  11710. var jLen;
  11711. var pathNodes;
  11712. var commands;
  11713. var pathArr;
  11714. var singleShape = this.data.singleShape;
  11715. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  11716. var xPos = 0;
  11717. var yPos = 0;
  11718. var firstLine = true;
  11719. var cnt = 0;
  11720. for (i = 0; i < len; i += 1) {
  11721. charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  11722. shapeData = (charData && charData.data) || {};
  11723. matrixHelper.reset();
  11724. if (singleShape && letters[i].n) {
  11725. xPos = -trackingOffset;
  11726. yPos += documentData.yOffset;
  11727. yPos += firstLine ? 1 : 0;
  11728. firstLine = false;
  11729. }
  11730. shapes = shapeData.shapes ? shapeData.shapes[0].it : [];
  11731. jLen = shapes.length;
  11732. matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
  11733. if (singleShape) {
  11734. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  11735. }
  11736. commands = createSizedArray(jLen - 1);
  11737. var commandsCounter = 0;
  11738. for (j = 0; j < jLen; j += 1) {
  11739. if (shapes[j].ty === 'sh') {
  11740. kLen = shapes[j].ks.k.i.length;
  11741. pathNodes = shapes[j].ks.k;
  11742. pathArr = [];
  11743. for (k = 1; k < kLen; k += 1) {
  11744. if (k === 1) {
  11745. pathArr.push(matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0));
  11746. }
  11747. pathArr.push(matrixHelper.applyToX(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToY(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToX(pathNodes.i[k][0], pathNodes.i[k][1], 0), matrixHelper.applyToY(pathNodes.i[k][0], pathNodes.i[k][1], 0), matrixHelper.applyToX(pathNodes.v[k][0], pathNodes.v[k][1], 0), matrixHelper.applyToY(pathNodes.v[k][0], pathNodes.v[k][1], 0));
  11748. }
  11749. pathArr.push(matrixHelper.applyToX(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToY(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToX(pathNodes.i[0][0], pathNodes.i[0][1], 0), matrixHelper.applyToY(pathNodes.i[0][0], pathNodes.i[0][1], 0), matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0));
  11750. commands[commandsCounter] = pathArr;
  11751. commandsCounter += 1;
  11752. }
  11753. }
  11754. if (singleShape) {
  11755. xPos += letters[i].l;
  11756. xPos += trackingOffset;
  11757. }
  11758. if (this.textSpans[cnt]) {
  11759. this.textSpans[cnt].elem = commands;
  11760. } else {
  11761. this.textSpans[cnt] = { elem: commands };
  11762. }
  11763. cnt += 1;
  11764. }
  11765. };
  11766. CVTextElement.prototype.renderInnerContent = function () {
  11767. var ctx = this.canvasContext;
  11768. ctx.font = this.values.fValue;
  11769. ctx.lineCap = 'butt';
  11770. ctx.lineJoin = 'miter';
  11771. ctx.miterLimit = 4;
  11772. if (!this.data.singleShape) {
  11773. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  11774. }
  11775. var i;
  11776. var len;
  11777. var j;
  11778. var jLen;
  11779. var k;
  11780. var kLen;
  11781. var renderedLetters = this.textAnimator.renderedLetters;
  11782. var letters = this.textProperty.currentData.l;
  11783. len = letters.length;
  11784. var renderedLetter;
  11785. var lastFill = null;
  11786. var lastStroke = null;
  11787. var lastStrokeW = null;
  11788. var commands;
  11789. var pathArr;
  11790. for (i = 0; i < len; i += 1) {
  11791. if (!letters[i].n) {
  11792. renderedLetter = renderedLetters[i];
  11793. if (renderedLetter) {
  11794. this.globalData.renderer.save();
  11795. this.globalData.renderer.ctxTransform(renderedLetter.p);
  11796. this.globalData.renderer.ctxOpacity(renderedLetter.o);
  11797. }
  11798. if (this.fill) {
  11799. if (renderedLetter && renderedLetter.fc) {
  11800. if (lastFill !== renderedLetter.fc) {
  11801. lastFill = renderedLetter.fc;
  11802. ctx.fillStyle = renderedLetter.fc;
  11803. }
  11804. } else if (lastFill !== this.values.fill) {
  11805. lastFill = this.values.fill;
  11806. ctx.fillStyle = this.values.fill;
  11807. }
  11808. commands = this.textSpans[i].elem;
  11809. jLen = commands.length;
  11810. this.globalData.canvasContext.beginPath();
  11811. for (j = 0; j < jLen; j += 1) {
  11812. pathArr = commands[j];
  11813. kLen = pathArr.length;
  11814. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  11815. for (k = 2; k < kLen; k += 6) {
  11816. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  11817. }
  11818. }
  11819. this.globalData.canvasContext.closePath();
  11820. this.globalData.canvasContext.fill();
  11821. /// ctx.fillText(this.textSpans[i].val,0,0);
  11822. }
  11823. if (this.stroke) {
  11824. if (renderedLetter && renderedLetter.sw) {
  11825. if (lastStrokeW !== renderedLetter.sw) {
  11826. lastStrokeW = renderedLetter.sw;
  11827. ctx.lineWidth = renderedLetter.sw;
  11828. }
  11829. } else if (lastStrokeW !== this.values.sWidth) {
  11830. lastStrokeW = this.values.sWidth;
  11831. ctx.lineWidth = this.values.sWidth;
  11832. }
  11833. if (renderedLetter && renderedLetter.sc) {
  11834. if (lastStroke !== renderedLetter.sc) {
  11835. lastStroke = renderedLetter.sc;
  11836. ctx.strokeStyle = renderedLetter.sc;
  11837. }
  11838. } else if (lastStroke !== this.values.stroke) {
  11839. lastStroke = this.values.stroke;
  11840. ctx.strokeStyle = this.values.stroke;
  11841. }
  11842. commands = this.textSpans[i].elem;
  11843. jLen = commands.length;
  11844. this.globalData.canvasContext.beginPath();
  11845. for (j = 0; j < jLen; j += 1) {
  11846. pathArr = commands[j];
  11847. kLen = pathArr.length;
  11848. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  11849. for (k = 2; k < kLen; k += 6) {
  11850. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  11851. }
  11852. }
  11853. this.globalData.canvasContext.closePath();
  11854. this.globalData.canvasContext.stroke();
  11855. /// ctx.strokeText(letters[i].val,0,0);
  11856. }
  11857. if (renderedLetter) {
  11858. this.globalData.renderer.restore();
  11859. }
  11860. }
  11861. }
  11862. };
  11863. function CVImageElement(data, globalData, comp) {
  11864. this.assetData = globalData.getAssetData(data.refId);
  11865. this.img = globalData.imageLoader.getAsset(this.assetData);
  11866. this.initElement(data, globalData, comp);
  11867. }
  11868. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVImageElement);
  11869. CVImageElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  11870. CVImageElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  11871. CVImageElement.prototype.createContent = function () {
  11872. if (this.img.width && (this.assetData.w !== this.img.width || this.assetData.h !== this.img.height)) {
  11873. var canvas = createTag('canvas');
  11874. canvas.width = this.assetData.w;
  11875. canvas.height = this.assetData.h;
  11876. var ctx = canvas.getContext('2d');
  11877. var imgW = this.img.width;
  11878. var imgH = this.img.height;
  11879. var imgRel = imgW / imgH;
  11880. var canvasRel = this.assetData.w / this.assetData.h;
  11881. var widthCrop;
  11882. var heightCrop;
  11883. var par = this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio;
  11884. if ((imgRel > canvasRel && par === 'xMidYMid slice') || (imgRel < canvasRel && par !== 'xMidYMid slice')) {
  11885. heightCrop = imgH;
  11886. widthCrop = heightCrop * canvasRel;
  11887. } else {
  11888. widthCrop = imgW;
  11889. heightCrop = widthCrop / canvasRel;
  11890. }
  11891. ctx.drawImage(this.img, (imgW - widthCrop) / 2, (imgH - heightCrop) / 2, widthCrop, heightCrop, 0, 0, this.assetData.w, this.assetData.h);
  11892. this.img = canvas;
  11893. }
  11894. };
  11895. CVImageElement.prototype.renderInnerContent = function () {
  11896. this.canvasContext.drawImage(this.img, 0, 0);
  11897. };
  11898. CVImageElement.prototype.destroy = function () {
  11899. this.img = null;
  11900. };
  11901. function CVSolidElement(data, globalData, comp) {
  11902. this.initElement(data, globalData, comp);
  11903. }
  11904. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVSolidElement);
  11905. CVSolidElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  11906. CVSolidElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  11907. CVSolidElement.prototype.renderInnerContent = function () {
  11908. var ctx = this.canvasContext;
  11909. ctx.fillStyle = this.data.sc;
  11910. ctx.fillRect(0, 0, this.data.sw, this.data.sh);
  11911. //
  11912. };
  11913. function CanvasRendererBase(animationItem, config) {
  11914. this.animationItem = animationItem;
  11915. this.renderConfig = {
  11916. clearCanvas: (config && config.clearCanvas !== undefined) ? config.clearCanvas : true,
  11917. context: (config && config.context) || null,
  11918. progressiveLoad: (config && config.progressiveLoad) || false,
  11919. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  11920. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  11921. contentVisibility: (config && config.contentVisibility) || 'visible',
  11922. className: (config && config.className) || '',
  11923. id: (config && config.id) || '',
  11924. };
  11925. this.renderConfig.dpr = (config && config.dpr) || 1;
  11926. if (this.animationItem.wrapper) {
  11927. this.renderConfig.dpr = (config && config.dpr) || window.devicePixelRatio || 1;
  11928. }
  11929. this.renderedFrame = -1;
  11930. this.globalData = {
  11931. frameNum: -1,
  11932. _mdf: false,
  11933. renderConfig: this.renderConfig,
  11934. currentGlobalAlpha: -1,
  11935. };
  11936. this.contextData = new CVContextData();
  11937. this.elements = [];
  11938. this.pendingElements = [];
  11939. this.transformMat = new Matrix();
  11940. this.completeLayers = false;
  11941. this.rendererType = 'canvas';
  11942. }
  11943. extendPrototype([BaseRenderer], CanvasRendererBase);
  11944. CanvasRendererBase.prototype.createShape = function (data) {
  11945. return new CVShapeElement(data, this.globalData, this);
  11946. };
  11947. CanvasRendererBase.prototype.createText = function (data) {
  11948. return new CVTextElement(data, this.globalData, this);
  11949. };
  11950. CanvasRendererBase.prototype.createImage = function (data) {
  11951. return new CVImageElement(data, this.globalData, this);
  11952. };
  11953. CanvasRendererBase.prototype.createSolid = function (data) {
  11954. return new CVSolidElement(data, this.globalData, this);
  11955. };
  11956. CanvasRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
  11957. CanvasRendererBase.prototype.ctxTransform = function (props) {
  11958. if (props[0] === 1 && props[1] === 0 && props[4] === 0 && props[5] === 1 && props[12] === 0 && props[13] === 0) {
  11959. return;
  11960. }
  11961. if (!this.renderConfig.clearCanvas) {
  11962. this.canvasContext.transform(props[0], props[1], props[4], props[5], props[12], props[13]);
  11963. return;
  11964. }
  11965. this.transformMat.cloneFromProps(props);
  11966. var cProps = this.contextData.cTr.props;
  11967. this.transformMat.transform(cProps[0], cProps[1], cProps[2], cProps[3], cProps[4], cProps[5], cProps[6], cProps[7], cProps[8], cProps[9], cProps[10], cProps[11], cProps[12], cProps[13], cProps[14], cProps[15]);
  11968. // this.contextData.cTr.transform(props[0],props[1],props[2],props[3],props[4],props[5],props[6],props[7],props[8],props[9],props[10],props[11],props[12],props[13],props[14],props[15]);
  11969. this.contextData.cTr.cloneFromProps(this.transformMat.props);
  11970. var trProps = this.contextData.cTr.props;
  11971. this.canvasContext.setTransform(trProps[0], trProps[1], trProps[4], trProps[5], trProps[12], trProps[13]);
  11972. };
  11973. CanvasRendererBase.prototype.ctxOpacity = function (op) {
  11974. /* if(op === 1){
  11975. return;
  11976. } */
  11977. if (!this.renderConfig.clearCanvas) {
  11978. this.canvasContext.globalAlpha *= op < 0 ? 0 : op;
  11979. this.globalData.currentGlobalAlpha = this.contextData.cO;
  11980. return;
  11981. }
  11982. this.contextData.cO *= op < 0 ? 0 : op;
  11983. if (this.globalData.currentGlobalAlpha !== this.contextData.cO) {
  11984. this.canvasContext.globalAlpha = this.contextData.cO;
  11985. this.globalData.currentGlobalAlpha = this.contextData.cO;
  11986. }
  11987. };
  11988. CanvasRendererBase.prototype.reset = function () {
  11989. if (!this.renderConfig.clearCanvas) {
  11990. this.canvasContext.restore();
  11991. return;
  11992. }
  11993. this.contextData.reset();
  11994. };
  11995. CanvasRendererBase.prototype.save = function (actionFlag) {
  11996. if (!this.renderConfig.clearCanvas) {
  11997. this.canvasContext.save();
  11998. return;
  11999. }
  12000. if (actionFlag) {
  12001. this.canvasContext.save();
  12002. }
  12003. var props = this.contextData.cTr.props;
  12004. if (this.contextData._length <= this.contextData.cArrPos) {
  12005. this.contextData.duplicate();
  12006. }
  12007. var i;
  12008. var arr = this.contextData.saved[this.contextData.cArrPos];
  12009. for (i = 0; i < 16; i += 1) {
  12010. arr[i] = props[i];
  12011. }
  12012. this.contextData.savedOp[this.contextData.cArrPos] = this.contextData.cO;
  12013. this.contextData.cArrPos += 1;
  12014. };
  12015. CanvasRendererBase.prototype.restore = function (actionFlag) {
  12016. if (!this.renderConfig.clearCanvas) {
  12017. this.canvasContext.restore();
  12018. return;
  12019. }
  12020. if (actionFlag) {
  12021. this.canvasContext.restore();
  12022. this.globalData.blendMode = 'source-over';
  12023. }
  12024. this.contextData.cArrPos -= 1;
  12025. var popped = this.contextData.saved[this.contextData.cArrPos];
  12026. var i;
  12027. var arr = this.contextData.cTr.props;
  12028. for (i = 0; i < 16; i += 1) {
  12029. arr[i] = popped[i];
  12030. }
  12031. this.canvasContext.setTransform(popped[0], popped[1], popped[4], popped[5], popped[12], popped[13]);
  12032. popped = this.contextData.savedOp[this.contextData.cArrPos];
  12033. this.contextData.cO = popped;
  12034. if (this.globalData.currentGlobalAlpha !== popped) {
  12035. this.canvasContext.globalAlpha = popped;
  12036. this.globalData.currentGlobalAlpha = popped;
  12037. }
  12038. };
  12039. CanvasRendererBase.prototype.configAnimation = function (animData) {
  12040. if (this.animationItem.wrapper) {
  12041. this.animationItem.container = createTag('canvas');
  12042. var containerStyle = this.animationItem.container.style;
  12043. containerStyle.width = '100%';
  12044. containerStyle.height = '100%';
  12045. var origin = '0px 0px 0px';
  12046. containerStyle.transformOrigin = origin;
  12047. containerStyle.mozTransformOrigin = origin;
  12048. containerStyle.webkitTransformOrigin = origin;
  12049. containerStyle['-webkit-transform'] = origin;
  12050. containerStyle.contentVisibility = this.renderConfig.contentVisibility;
  12051. this.animationItem.wrapper.appendChild(this.animationItem.container);
  12052. this.canvasContext = this.animationItem.container.getContext('2d');
  12053. if (this.renderConfig.className) {
  12054. this.animationItem.container.setAttribute('class', this.renderConfig.className);
  12055. }
  12056. if (this.renderConfig.id) {
  12057. this.animationItem.container.setAttribute('id', this.renderConfig.id);
  12058. }
  12059. } else {
  12060. this.canvasContext = this.renderConfig.context;
  12061. }
  12062. this.data = animData;
  12063. this.layers = animData.layers;
  12064. this.transformCanvas = {
  12065. w: animData.w,
  12066. h: animData.h,
  12067. sx: 0,
  12068. sy: 0,
  12069. tx: 0,
  12070. ty: 0,
  12071. };
  12072. this.setupGlobalData(animData, document.body);
  12073. this.globalData.canvasContext = this.canvasContext;
  12074. this.globalData.renderer = this;
  12075. this.globalData.isDashed = false;
  12076. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  12077. this.globalData.transformCanvas = this.transformCanvas;
  12078. this.elements = createSizedArray(animData.layers.length);
  12079. this.updateContainerSize();
  12080. };
  12081. CanvasRendererBase.prototype.updateContainerSize = function () {
  12082. this.reset();
  12083. var elementWidth;
  12084. var elementHeight;
  12085. if (this.animationItem.wrapper && this.animationItem.container) {
  12086. elementWidth = this.animationItem.wrapper.offsetWidth;
  12087. elementHeight = this.animationItem.wrapper.offsetHeight;
  12088. this.animationItem.container.setAttribute('width', elementWidth * this.renderConfig.dpr);
  12089. this.animationItem.container.setAttribute('height', elementHeight * this.renderConfig.dpr);
  12090. } else {
  12091. elementWidth = this.canvasContext.canvas.width * this.renderConfig.dpr;
  12092. elementHeight = this.canvasContext.canvas.height * this.renderConfig.dpr;
  12093. }
  12094. var elementRel;
  12095. var animationRel;
  12096. if (this.renderConfig.preserveAspectRatio.indexOf('meet') !== -1 || this.renderConfig.preserveAspectRatio.indexOf('slice') !== -1) {
  12097. var par = this.renderConfig.preserveAspectRatio.split(' ');
  12098. var fillType = par[1] || 'meet';
  12099. var pos = par[0] || 'xMidYMid';
  12100. var xPos = pos.substr(0, 4);
  12101. var yPos = pos.substr(4);
  12102. elementRel = elementWidth / elementHeight;
  12103. animationRel = this.transformCanvas.w / this.transformCanvas.h;
  12104. if ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice')) {
  12105. this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12106. this.transformCanvas.sy = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12107. } else {
  12108. this.transformCanvas.sx = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12109. this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12110. }
  12111. if (xPos === 'xMid' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) {
  12112. this.transformCanvas.tx = ((elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) / 2) * this.renderConfig.dpr;
  12113. } else if (xPos === 'xMax' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) {
  12114. this.transformCanvas.tx = (elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) * this.renderConfig.dpr;
  12115. } else {
  12116. this.transformCanvas.tx = 0;
  12117. }
  12118. if (yPos === 'YMid' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
  12119. this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w)) / 2) * this.renderConfig.dpr;
  12120. } else if (yPos === 'YMax' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
  12121. this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w))) * this.renderConfig.dpr;
  12122. } else {
  12123. this.transformCanvas.ty = 0;
  12124. }
  12125. } else if (this.renderConfig.preserveAspectRatio === 'none') {
  12126. this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12127. this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12128. this.transformCanvas.tx = 0;
  12129. this.transformCanvas.ty = 0;
  12130. } else {
  12131. this.transformCanvas.sx = this.renderConfig.dpr;
  12132. this.transformCanvas.sy = this.renderConfig.dpr;
  12133. this.transformCanvas.tx = 0;
  12134. this.transformCanvas.ty = 0;
  12135. }
  12136. this.transformCanvas.props = [this.transformCanvas.sx, 0, 0, 0, 0, this.transformCanvas.sy, 0, 0, 0, 0, 1, 0, this.transformCanvas.tx, this.transformCanvas.ty, 0, 1];
  12137. /* var i, len = this.elements.length;
  12138. for(i=0;i<len;i+=1){
  12139. if(this.elements[i] && this.elements[i].data.ty === 0){
  12140. this.elements[i].resize(this.globalData.transformCanvas);
  12141. }
  12142. } */
  12143. this.ctxTransform(this.transformCanvas.props);
  12144. this.canvasContext.beginPath();
  12145. this.canvasContext.rect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  12146. this.canvasContext.closePath();
  12147. this.canvasContext.clip();
  12148. this.renderFrame(this.renderedFrame, true);
  12149. };
  12150. CanvasRendererBase.prototype.destroy = function () {
  12151. if (this.renderConfig.clearCanvas && this.animationItem.wrapper) {
  12152. this.animationItem.wrapper.innerText = '';
  12153. }
  12154. var i;
  12155. var len = this.layers ? this.layers.length : 0;
  12156. for (i = len - 1; i >= 0; i -= 1) {
  12157. if (this.elements[i]) {
  12158. this.elements[i].destroy();
  12159. }
  12160. }
  12161. this.elements.length = 0;
  12162. this.globalData.canvasContext = null;
  12163. this.animationItem.container = null;
  12164. this.destroyed = true;
  12165. };
  12166. CanvasRendererBase.prototype.renderFrame = function (num, forceRender) {
  12167. if ((this.renderedFrame === num && this.renderConfig.clearCanvas === true && !forceRender) || this.destroyed || num === -1) {
  12168. return;
  12169. }
  12170. this.renderedFrame = num;
  12171. this.globalData.frameNum = num - this.animationItem._isFirstFrame;
  12172. this.globalData.frameId += 1;
  12173. this.globalData._mdf = !this.renderConfig.clearCanvas || forceRender;
  12174. this.globalData.projectInterface.currentFrame = num;
  12175. // console.log('--------');
  12176. // console.log('NEW: ',num);
  12177. var i;
  12178. var len = this.layers.length;
  12179. if (!this.completeLayers) {
  12180. this.checkLayers(num);
  12181. }
  12182. for (i = 0; i < len; i += 1) {
  12183. if (this.completeLayers || this.elements[i]) {
  12184. this.elements[i].prepareFrame(num - this.layers[i].st);
  12185. }
  12186. }
  12187. if (this.globalData._mdf) {
  12188. if (this.renderConfig.clearCanvas === true) {
  12189. this.canvasContext.clearRect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  12190. } else {
  12191. this.save();
  12192. }
  12193. for (i = len - 1; i >= 0; i -= 1) {
  12194. if (this.completeLayers || this.elements[i]) {
  12195. this.elements[i].renderFrame();
  12196. }
  12197. }
  12198. if (this.renderConfig.clearCanvas !== true) {
  12199. this.restore();
  12200. }
  12201. }
  12202. };
  12203. CanvasRendererBase.prototype.buildItem = function (pos) {
  12204. var elements = this.elements;
  12205. if (elements[pos] || this.layers[pos].ty === 99) {
  12206. return;
  12207. }
  12208. var element = this.createItem(this.layers[pos], this, this.globalData);
  12209. elements[pos] = element;
  12210. element.initExpressions();
  12211. /* if(this.layers[pos].ty === 0){
  12212. element.resize(this.globalData.transformCanvas);
  12213. } */
  12214. };
  12215. CanvasRendererBase.prototype.checkPendingElements = function () {
  12216. while (this.pendingElements.length) {
  12217. var element = this.pendingElements.pop();
  12218. element.checkParenting();
  12219. }
  12220. };
  12221. CanvasRendererBase.prototype.hide = function () {
  12222. this.animationItem.container.style.display = 'none';
  12223. };
  12224. CanvasRendererBase.prototype.show = function () {
  12225. this.animationItem.container.style.display = 'block';
  12226. };
  12227. function CVCompElement(data, globalData, comp) {
  12228. this.completeLayers = false;
  12229. this.layers = data.layers;
  12230. this.pendingElements = [];
  12231. this.elements = createSizedArray(this.layers.length);
  12232. this.initElement(data, globalData, comp);
  12233. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  12234. }
  12235. extendPrototype([CanvasRendererBase, ICompElement, CVBaseElement], CVCompElement);
  12236. CVCompElement.prototype.renderInnerContent = function () {
  12237. var ctx = this.canvasContext;
  12238. ctx.beginPath();
  12239. ctx.moveTo(0, 0);
  12240. ctx.lineTo(this.data.w, 0);
  12241. ctx.lineTo(this.data.w, this.data.h);
  12242. ctx.lineTo(0, this.data.h);
  12243. ctx.lineTo(0, 0);
  12244. ctx.clip();
  12245. var i;
  12246. var len = this.layers.length;
  12247. for (i = len - 1; i >= 0; i -= 1) {
  12248. if (this.completeLayers || this.elements[i]) {
  12249. this.elements[i].renderFrame();
  12250. }
  12251. }
  12252. };
  12253. CVCompElement.prototype.destroy = function () {
  12254. var i;
  12255. var len = this.layers.length;
  12256. for (i = len - 1; i >= 0; i -= 1) {
  12257. if (this.elements[i]) {
  12258. this.elements[i].destroy();
  12259. }
  12260. }
  12261. this.layers = null;
  12262. this.elements = null;
  12263. };
  12264. CVCompElement.prototype.createComp = function (data) {
  12265. return new CVCompElement(data, this.globalData, this);
  12266. };
  12267. function CanvasRenderer(animationItem, config) {
  12268. this.animationItem = animationItem;
  12269. this.renderConfig = {
  12270. clearCanvas: (config && config.clearCanvas !== undefined) ? config.clearCanvas : true,
  12271. context: (config && config.context) || null,
  12272. progressiveLoad: (config && config.progressiveLoad) || false,
  12273. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  12274. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  12275. contentVisibility: (config && config.contentVisibility) || 'visible',
  12276. className: (config && config.className) || '',
  12277. id: (config && config.id) || '',
  12278. };
  12279. this.renderConfig.dpr = (config && config.dpr) || 1;
  12280. if (this.animationItem.wrapper) {
  12281. this.renderConfig.dpr = (config && config.dpr) || window.devicePixelRatio || 1;
  12282. }
  12283. this.renderedFrame = -1;
  12284. this.globalData = {
  12285. frameNum: -1,
  12286. _mdf: false,
  12287. renderConfig: this.renderConfig,
  12288. currentGlobalAlpha: -1,
  12289. };
  12290. this.contextData = new CVContextData();
  12291. this.elements = [];
  12292. this.pendingElements = [];
  12293. this.transformMat = new Matrix();
  12294. this.completeLayers = false;
  12295. this.rendererType = 'canvas';
  12296. }
  12297. extendPrototype([CanvasRendererBase], CanvasRenderer);
  12298. CanvasRenderer.prototype.createComp = function (data) {
  12299. return new CVCompElement(data, this.globalData, this);
  12300. };
  12301. // Registering renderers
  12302. registerRenderer('canvas', CanvasRenderer);
  12303. // Registering shape modifiers
  12304. ShapeModifiers.registerModifier('tm', TrimModifier);
  12305. ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier);
  12306. ShapeModifiers.registerModifier('rp', RepeaterModifier);
  12307. ShapeModifiers.registerModifier('rd', RoundCornersModifier);
  12308. const Expressions = (function () {
  12309. var ob = {};
  12310. ob.initExpressions = initExpressions;
  12311. function initExpressions(animation) {
  12312. var stackCount = 0;
  12313. var registers = [];
  12314. function pushExpression() {
  12315. stackCount += 1;
  12316. }
  12317. function popExpression() {
  12318. stackCount -= 1;
  12319. if (stackCount === 0) {
  12320. releaseInstances();
  12321. }
  12322. }
  12323. function registerExpressionProperty(expression) {
  12324. if (registers.indexOf(expression) === -1) {
  12325. registers.push(expression);
  12326. }
  12327. }
  12328. function releaseInstances() {
  12329. var i;
  12330. var len = registers.length;
  12331. for (i = 0; i < len; i += 1) {
  12332. registers[i].release();
  12333. }
  12334. registers.length = 0;
  12335. }
  12336. animation.renderer.compInterface = CompExpressionInterface(animation.renderer);
  12337. animation.renderer.globalData.projectInterface.registerComposition(animation.renderer);
  12338. animation.renderer.globalData.pushExpression = pushExpression;
  12339. animation.renderer.globalData.popExpression = popExpression;
  12340. animation.renderer.globalData.registerExpressionProperty = registerExpressionProperty;
  12341. }
  12342. return ob;
  12343. }());
  12344. /* eslint-disable */
  12345. /*
  12346. Copyright 2014 David Bau.
  12347. Permission is hereby granted, free of charge, to any person obtaining
  12348. a copy of this software and associated documentation files (the
  12349. "Software"), to deal in the Software without restriction, including
  12350. without limitation the rights to use, copy, modify, merge, publish,
  12351. distribute, sublicense, and/or sell copies of the Software, and to
  12352. permit persons to whom the Software is furnished to do so, subject to
  12353. the following conditions:
  12354. The above copyright notice and this permission notice shall be
  12355. included in all copies or substantial portions of the Software.
  12356. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  12357. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12358. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  12359. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  12360. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  12361. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  12362. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  12363. */
  12364. function seedRandom(pool, math) {
  12365. //
  12366. // The following constants are related to IEEE 754 limits.
  12367. //
  12368. var global = this,
  12369. width = 256, // each RC4 output is 0 <= x < 256
  12370. chunks = 6, // at least six RC4 outputs for each double
  12371. digits = 52, // there are 52 significant digits in a double
  12372. rngname = 'random', // rngname: name for Math.random and Math.seedrandom
  12373. startdenom = math.pow(width, chunks),
  12374. significance = math.pow(2, digits),
  12375. overflow = significance * 2,
  12376. mask = width - 1,
  12377. nodecrypto; // node.js crypto module, initialized at the bottom.
  12378. //
  12379. // seedrandom()
  12380. // This is the seedrandom function described above.
  12381. //
  12382. function seedrandom(seed, options, callback) {
  12383. var key = [];
  12384. options = (options === true) ? { entropy: true } : (options || {});
  12385. // Flatten the seed string or build one from local entropy if needed.
  12386. var shortseed = mixkey(flatten(
  12387. options.entropy ? [seed, tostring(pool)] :
  12388. (seed === null) ? autoseed() : seed, 3), key);
  12389. // Use the seed to initialize an ARC4 generator.
  12390. var arc4 = new ARC4(key);
  12391. // This function returns a random double in [0, 1) that contains
  12392. // randomness in every bit of the mantissa of the IEEE 754 value.
  12393. var prng = function() {
  12394. var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48
  12395. d = startdenom, // and denominator d = 2 ^ 48.
  12396. x = 0; // and no 'extra last byte'.
  12397. while (n < significance) { // Fill up all significant digits by
  12398. n = (n + x) * width; // shifting numerator and
  12399. d *= width; // denominator and generating a
  12400. x = arc4.g(1); // new least-significant-byte.
  12401. }
  12402. while (n >= overflow) { // To avoid rounding up, before adding
  12403. n /= 2; // last byte, shift everything
  12404. d /= 2; // right using integer math until
  12405. x >>>= 1; // we have exactly the desired bits.
  12406. }
  12407. return (n + x) / d; // Form the number within [0, 1).
  12408. };
  12409. prng.int32 = function() { return arc4.g(4) | 0; };
  12410. prng.quick = function() { return arc4.g(4) / 0x100000000; };
  12411. prng.double = prng;
  12412. // Mix the randomness into accumulated entropy.
  12413. mixkey(tostring(arc4.S), pool);
  12414. // Calling convention: what to return as a function of prng, seed, is_math.
  12415. return (options.pass || callback ||
  12416. function(prng, seed, is_math_call, state) {
  12417. if (state) {
  12418. // Load the arc4 state from the given state if it has an S array.
  12419. if (state.S) { copy(state, arc4); }
  12420. // Only provide the .state method if requested via options.state.
  12421. prng.state = function() { return copy(arc4, {}); };
  12422. }
  12423. // If called as a method of Math (Math.seedrandom()), mutate
  12424. // Math.random because that is how seedrandom.js has worked since v1.0.
  12425. if (is_math_call) { math[rngname] = prng; return seed; }
  12426. // Otherwise, it is a newer calling convention, so return the
  12427. // prng directly.
  12428. else return prng;
  12429. })(
  12430. prng,
  12431. shortseed,
  12432. 'global' in options ? options.global : (this == math),
  12433. options.state);
  12434. }
  12435. math['seed' + rngname] = seedrandom;
  12436. //
  12437. // ARC4
  12438. //
  12439. // An ARC4 implementation. The constructor takes a key in the form of
  12440. // an array of at most (width) integers that should be 0 <= x < (width).
  12441. //
  12442. // The g(count) method returns a pseudorandom integer that concatenates
  12443. // the next (count) outputs from ARC4. Its return value is a number x
  12444. // that is in the range 0 <= x < (width ^ count).
  12445. //
  12446. function ARC4(key) {
  12447. var t, keylen = key.length,
  12448. me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];
  12449. // The empty key [] is treated as [0].
  12450. if (!keylen) { key = [keylen++]; }
  12451. // Set up S using the standard key scheduling algorithm.
  12452. while (i < width) {
  12453. s[i] = i++;
  12454. }
  12455. for (i = 0; i < width; i++) {
  12456. s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];
  12457. s[j] = t;
  12458. }
  12459. // The "g" method returns the next (count) outputs as one number.
  12460. me.g = function(count) {
  12461. // Using instance members instead of closure state nearly doubles speed.
  12462. var t, r = 0,
  12463. i = me.i, j = me.j, s = me.S;
  12464. while (count--) {
  12465. t = s[i = mask & (i + 1)];
  12466. r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];
  12467. }
  12468. me.i = i; me.j = j;
  12469. return r;
  12470. // For robust unpredictability, the function call below automatically
  12471. // discards an initial batch of values. This is called RC4-drop[256].
  12472. // See http://google.com/search?q=rsa+fluhrer+response&btnI
  12473. };
  12474. }
  12475. //
  12476. // copy()
  12477. // Copies internal state of ARC4 to or from a plain object.
  12478. //
  12479. function copy(f, t) {
  12480. t.i = f.i;
  12481. t.j = f.j;
  12482. t.S = f.S.slice();
  12483. return t;
  12484. }
  12485. //
  12486. // flatten()
  12487. // Converts an object tree to nested arrays of strings.
  12488. //
  12489. function flatten(obj, depth) {
  12490. var result = [], typ = (typeof obj), prop;
  12491. if (depth && typ == 'object') {
  12492. for (prop in obj) {
  12493. try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
  12494. }
  12495. }
  12496. return (result.length ? result : typ == 'string' ? obj : obj + '\0');
  12497. }
  12498. //
  12499. // mixkey()
  12500. // Mixes a string seed into a key that is an array of integers, and
  12501. // returns a shortened string seed that is equivalent to the result key.
  12502. //
  12503. function mixkey(seed, key) {
  12504. var stringseed = seed + '', smear, j = 0;
  12505. while (j < stringseed.length) {
  12506. key[mask & j] =
  12507. mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));
  12508. }
  12509. return tostring(key);
  12510. }
  12511. //
  12512. // autoseed()
  12513. // Returns an object for autoseeding, using window.crypto and Node crypto
  12514. // module if available.
  12515. //
  12516. function autoseed() {
  12517. try {
  12518. if (nodecrypto) { return tostring(nodecrypto.randomBytes(width)); }
  12519. var out = new Uint8Array(width);
  12520. (global.crypto || global.msCrypto).getRandomValues(out);
  12521. return tostring(out);
  12522. } catch (e) {
  12523. var browser = global.navigator,
  12524. plugins = browser && browser.plugins;
  12525. return [+new Date(), global, plugins, global.screen, tostring(pool)];
  12526. }
  12527. }
  12528. //
  12529. // tostring()
  12530. // Converts an array of charcodes to a string
  12531. //
  12532. function tostring(a) {
  12533. return String.fromCharCode.apply(0, a);
  12534. }
  12535. //
  12536. // When seedrandom.js is loaded, we immediately mix a few bits
  12537. // from the built-in RNG into the entropy pool. Because we do
  12538. // not want to interfere with deterministic PRNG state later,
  12539. // seedrandom will not call math.random on its own again after
  12540. // initialization.
  12541. //
  12542. mixkey(math.random(), pool);
  12543. //
  12544. // Nodejs and AMD support: export the implementation as a module using
  12545. // either convention.
  12546. //
  12547. // End anonymous scope, and pass initial values.
  12548. };
  12549. function initialize$2(BMMath) {
  12550. seedRandom([], BMMath);
  12551. }
  12552. var propTypes = {
  12553. SHAPE: 'shape',
  12554. };
  12555. /* eslint-disable camelcase */
  12556. const ExpressionManager = (function () {
  12557. 'use strict';
  12558. var ob = {};
  12559. var Math = BMMath;
  12560. var window = null;
  12561. var document = null;
  12562. var XMLHttpRequest = null;
  12563. var fetch = null;
  12564. var frames = null;
  12565. initialize$2(BMMath);
  12566. function $bm_isInstanceOfArray(arr) {
  12567. return arr.constructor === Array || arr.constructor === Float32Array;
  12568. }
  12569. function isNumerable(tOfV, v) {
  12570. return tOfV === 'number' || tOfV === 'boolean' || tOfV === 'string' || v instanceof Number;
  12571. }
  12572. function $bm_neg(a) {
  12573. var tOfA = typeof a;
  12574. if (tOfA === 'number' || tOfA === 'boolean' || a instanceof Number) {
  12575. return -a;
  12576. }
  12577. if ($bm_isInstanceOfArray(a)) {
  12578. var i;
  12579. var lenA = a.length;
  12580. var retArr = [];
  12581. for (i = 0; i < lenA; i += 1) {
  12582. retArr[i] = -a[i];
  12583. }
  12584. return retArr;
  12585. }
  12586. if (a.propType) {
  12587. return a.v;
  12588. }
  12589. return -a;
  12590. }
  12591. var easeInBez = BezierFactory.getBezierEasing(0.333, 0, 0.833, 0.833, 'easeIn').get;
  12592. var easeOutBez = BezierFactory.getBezierEasing(0.167, 0.167, 0.667, 1, 'easeOut').get;
  12593. var easeInOutBez = BezierFactory.getBezierEasing(0.33, 0, 0.667, 1, 'easeInOut').get;
  12594. function sum(a, b) {
  12595. var tOfA = typeof a;
  12596. var tOfB = typeof b;
  12597. if (tOfA === 'string' || tOfB === 'string') {
  12598. return a + b;
  12599. }
  12600. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12601. return a + b;
  12602. }
  12603. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12604. a = a.slice(0);
  12605. a[0] += b;
  12606. return a;
  12607. }
  12608. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12609. b = b.slice(0);
  12610. b[0] = a + b[0];
  12611. return b;
  12612. }
  12613. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  12614. var i = 0;
  12615. var lenA = a.length;
  12616. var lenB = b.length;
  12617. var retArr = [];
  12618. while (i < lenA || i < lenB) {
  12619. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  12620. retArr[i] = a[i] + b[i];
  12621. } else {
  12622. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  12623. }
  12624. i += 1;
  12625. }
  12626. return retArr;
  12627. }
  12628. return 0;
  12629. }
  12630. var add = sum;
  12631. function sub(a, b) {
  12632. var tOfA = typeof a;
  12633. var tOfB = typeof b;
  12634. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12635. if (tOfA === 'string') {
  12636. a = parseInt(a, 10);
  12637. }
  12638. if (tOfB === 'string') {
  12639. b = parseInt(b, 10);
  12640. }
  12641. return a - b;
  12642. }
  12643. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12644. a = a.slice(0);
  12645. a[0] -= b;
  12646. return a;
  12647. }
  12648. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12649. b = b.slice(0);
  12650. b[0] = a - b[0];
  12651. return b;
  12652. }
  12653. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  12654. var i = 0;
  12655. var lenA = a.length;
  12656. var lenB = b.length;
  12657. var retArr = [];
  12658. while (i < lenA || i < lenB) {
  12659. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  12660. retArr[i] = a[i] - b[i];
  12661. } else {
  12662. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  12663. }
  12664. i += 1;
  12665. }
  12666. return retArr;
  12667. }
  12668. return 0;
  12669. }
  12670. function mul(a, b) {
  12671. var tOfA = typeof a;
  12672. var tOfB = typeof b;
  12673. var arr;
  12674. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12675. return a * b;
  12676. }
  12677. var i;
  12678. var len;
  12679. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12680. len = a.length;
  12681. arr = createTypedArray('float32', len);
  12682. for (i = 0; i < len; i += 1) {
  12683. arr[i] = a[i] * b;
  12684. }
  12685. return arr;
  12686. }
  12687. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12688. len = b.length;
  12689. arr = createTypedArray('float32', len);
  12690. for (i = 0; i < len; i += 1) {
  12691. arr[i] = a * b[i];
  12692. }
  12693. return arr;
  12694. }
  12695. return 0;
  12696. }
  12697. function div(a, b) {
  12698. var tOfA = typeof a;
  12699. var tOfB = typeof b;
  12700. var arr;
  12701. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12702. return a / b;
  12703. }
  12704. var i;
  12705. var len;
  12706. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12707. len = a.length;
  12708. arr = createTypedArray('float32', len);
  12709. for (i = 0; i < len; i += 1) {
  12710. arr[i] = a[i] / b;
  12711. }
  12712. return arr;
  12713. }
  12714. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12715. len = b.length;
  12716. arr = createTypedArray('float32', len);
  12717. for (i = 0; i < len; i += 1) {
  12718. arr[i] = a / b[i];
  12719. }
  12720. return arr;
  12721. }
  12722. return 0;
  12723. }
  12724. function mod(a, b) {
  12725. if (typeof a === 'string') {
  12726. a = parseInt(a, 10);
  12727. }
  12728. if (typeof b === 'string') {
  12729. b = parseInt(b, 10);
  12730. }
  12731. return a % b;
  12732. }
  12733. var $bm_sum = sum;
  12734. var $bm_sub = sub;
  12735. var $bm_mul = mul;
  12736. var $bm_div = div;
  12737. var $bm_mod = mod;
  12738. function clamp(num, min, max) {
  12739. if (min > max) {
  12740. var mm = max;
  12741. max = min;
  12742. min = mm;
  12743. }
  12744. return Math.min(Math.max(num, min), max);
  12745. }
  12746. function radiansToDegrees(val) {
  12747. return val / degToRads;
  12748. }
  12749. var radians_to_degrees = radiansToDegrees;
  12750. function degreesToRadians(val) {
  12751. return val * degToRads;
  12752. }
  12753. var degrees_to_radians = radiansToDegrees;
  12754. var helperLengthArray = [0, 0, 0, 0, 0, 0];
  12755. function length(arr1, arr2) {
  12756. if (typeof arr1 === 'number' || arr1 instanceof Number) {
  12757. arr2 = arr2 || 0;
  12758. return Math.abs(arr1 - arr2);
  12759. }
  12760. if (!arr2) {
  12761. arr2 = helperLengthArray;
  12762. }
  12763. var i;
  12764. var len = Math.min(arr1.length, arr2.length);
  12765. var addedLength = 0;
  12766. for (i = 0; i < len; i += 1) {
  12767. addedLength += Math.pow(arr2[i] - arr1[i], 2);
  12768. }
  12769. return Math.sqrt(addedLength);
  12770. }
  12771. function normalize(vec) {
  12772. return div(vec, length(vec));
  12773. }
  12774. function rgbToHsl(val) {
  12775. var r = val[0]; var g = val[1]; var b = val[2];
  12776. var max = Math.max(r, g, b);
  12777. var min = Math.min(r, g, b);
  12778. var h;
  12779. var s;
  12780. var l = (max + min) / 2;
  12781. if (max === min) {
  12782. h = 0; // achromatic
  12783. s = 0; // achromatic
  12784. } else {
  12785. var d = max - min;
  12786. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  12787. switch (max) {
  12788. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  12789. case g: h = (b - r) / d + 2; break;
  12790. case b: h = (r - g) / d + 4; break;
  12791. default: break;
  12792. }
  12793. h /= 6;
  12794. }
  12795. return [h, s, l, val[3]];
  12796. }
  12797. function hue2rgb(p, q, t) {
  12798. if (t < 0) t += 1;
  12799. if (t > 1) t -= 1;
  12800. if (t < 1 / 6) return p + (q - p) * 6 * t;
  12801. if (t < 1 / 2) return q;
  12802. if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
  12803. return p;
  12804. }
  12805. function hslToRgb(val) {
  12806. var h = val[0];
  12807. var s = val[1];
  12808. var l = val[2];
  12809. var r;
  12810. var g;
  12811. var b;
  12812. if (s === 0) {
  12813. r = l; // achromatic
  12814. b = l; // achromatic
  12815. g = l; // achromatic
  12816. } else {
  12817. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  12818. var p = 2 * l - q;
  12819. r = hue2rgb(p, q, h + 1 / 3);
  12820. g = hue2rgb(p, q, h);
  12821. b = hue2rgb(p, q, h - 1 / 3);
  12822. }
  12823. return [r, g, b, val[3]];
  12824. }
  12825. function linear(t, tMin, tMax, value1, value2) {
  12826. if (value1 === undefined || value2 === undefined) {
  12827. value1 = tMin;
  12828. value2 = tMax;
  12829. tMin = 0;
  12830. tMax = 1;
  12831. }
  12832. if (tMax < tMin) {
  12833. var _tMin = tMax;
  12834. tMax = tMin;
  12835. tMin = _tMin;
  12836. }
  12837. if (t <= tMin) {
  12838. return value1;
  12839. } if (t >= tMax) {
  12840. return value2;
  12841. }
  12842. var perc = tMax === tMin ? 0 : (t - tMin) / (tMax - tMin);
  12843. if (!value1.length) {
  12844. return value1 + (value2 - value1) * perc;
  12845. }
  12846. var i;
  12847. var len = value1.length;
  12848. var arr = createTypedArray('float32', len);
  12849. for (i = 0; i < len; i += 1) {
  12850. arr[i] = value1[i] + (value2[i] - value1[i]) * perc;
  12851. }
  12852. return arr;
  12853. }
  12854. function random(min, max) {
  12855. if (max === undefined) {
  12856. if (min === undefined) {
  12857. min = 0;
  12858. max = 1;
  12859. } else {
  12860. max = min;
  12861. min = undefined;
  12862. }
  12863. }
  12864. if (max.length) {
  12865. var i;
  12866. var len = max.length;
  12867. if (!min) {
  12868. min = createTypedArray('float32', len);
  12869. }
  12870. var arr = createTypedArray('float32', len);
  12871. var rnd = BMMath.random();
  12872. for (i = 0; i < len; i += 1) {
  12873. arr[i] = min[i] + rnd * (max[i] - min[i]);
  12874. }
  12875. return arr;
  12876. }
  12877. if (min === undefined) {
  12878. min = 0;
  12879. }
  12880. var rndm = BMMath.random();
  12881. return min + rndm * (max - min);
  12882. }
  12883. function createPath(points, inTangents, outTangents, closed) {
  12884. var i;
  12885. var len = points.length;
  12886. var path = shapePool.newElement();
  12887. path.setPathData(!!closed, len);
  12888. var arrPlaceholder = [0, 0];
  12889. var inVertexPoint;
  12890. var outVertexPoint;
  12891. for (i = 0; i < len; i += 1) {
  12892. inVertexPoint = (inTangents && inTangents[i]) ? inTangents[i] : arrPlaceholder;
  12893. outVertexPoint = (outTangents && outTangents[i]) ? outTangents[i] : arrPlaceholder;
  12894. path.setTripleAt(points[i][0], points[i][1], outVertexPoint[0] + points[i][0], outVertexPoint[1] + points[i][1], inVertexPoint[0] + points[i][0], inVertexPoint[1] + points[i][1], i, true);
  12895. }
  12896. return path;
  12897. }
  12898. function initiateExpression(elem, data, property) {
  12899. var val = data.x;
  12900. var needsVelocity = /velocity(?![\w\d])/.test(val);
  12901. var _needsRandom = val.indexOf('random') !== -1;
  12902. var elemType = elem.data.ty;
  12903. var transform;
  12904. var $bm_transform;
  12905. var content;
  12906. var effect;
  12907. var thisProperty = property;
  12908. thisProperty.valueAtTime = thisProperty.getValueAtTime;
  12909. Object.defineProperty(thisProperty, 'value', {
  12910. get: function () {
  12911. return thisProperty.v;
  12912. },
  12913. });
  12914. elem.comp.frameDuration = 1 / elem.comp.globalData.frameRate;
  12915. elem.comp.displayStartTime = 0;
  12916. var inPoint = elem.data.ip / elem.comp.globalData.frameRate;
  12917. var outPoint = elem.data.op / elem.comp.globalData.frameRate;
  12918. var width = elem.data.sw ? elem.data.sw : 0;
  12919. var height = elem.data.sh ? elem.data.sh : 0;
  12920. var name = elem.data.nm;
  12921. var loopIn;
  12922. var loop_in;
  12923. var loopOut;
  12924. var loop_out;
  12925. var smooth;
  12926. var toWorld;
  12927. var fromWorld;
  12928. var fromComp;
  12929. var toComp;
  12930. var fromCompToSurface;
  12931. var position;
  12932. var rotation;
  12933. var anchorPoint;
  12934. var scale;
  12935. var thisLayer;
  12936. var thisComp;
  12937. var mask;
  12938. var valueAtTime;
  12939. var velocityAtTime;
  12940. var scoped_bm_rt;
  12941. // val = val.replace(/(\\?"|')((http)(s)?(:\/))?\/.*?(\\?"|')/g, "\"\""); // deter potential network calls
  12942. var expression_function = eval('[function _expression_function(){' + val + ';scoped_bm_rt=$bm_rt}]')[0]; // eslint-disable-line no-eval
  12943. var numKeys = property.kf ? data.k.length : 0;
  12944. var active = !this.data || this.data.hd !== true;
  12945. var wiggle = function wiggle(freq, amp) {
  12946. var iWiggle;
  12947. var j;
  12948. var lenWiggle = this.pv.length ? this.pv.length : 1;
  12949. var addedAmps = createTypedArray('float32', lenWiggle);
  12950. freq = 5;
  12951. var iterations = Math.floor(time * freq);
  12952. iWiggle = 0;
  12953. j = 0;
  12954. while (iWiggle < iterations) {
  12955. // var rnd = BMMath.random();
  12956. for (j = 0; j < lenWiggle; j += 1) {
  12957. addedAmps[j] += -amp + amp * 2 * BMMath.random();
  12958. // addedAmps[j] += -amp + amp*2*rnd;
  12959. }
  12960. iWiggle += 1;
  12961. }
  12962. // var rnd2 = BMMath.random();
  12963. var periods = time * freq;
  12964. var perc = periods - Math.floor(periods);
  12965. var arr = createTypedArray('float32', lenWiggle);
  12966. if (lenWiggle > 1) {
  12967. for (j = 0; j < lenWiggle; j += 1) {
  12968. arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp * 2 * BMMath.random()) * perc;
  12969. // arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*rnd)*perc;
  12970. // arr[i] = this.pv[i] + addedAmp + amp1*perc + amp2*(1-perc);
  12971. }
  12972. return arr;
  12973. }
  12974. return this.pv + addedAmps[0] + (-amp + amp * 2 * BMMath.random()) * perc;
  12975. }.bind(this);
  12976. if (thisProperty.loopIn) {
  12977. loopIn = thisProperty.loopIn.bind(thisProperty);
  12978. loop_in = loopIn;
  12979. }
  12980. if (thisProperty.loopOut) {
  12981. loopOut = thisProperty.loopOut.bind(thisProperty);
  12982. loop_out = loopOut;
  12983. }
  12984. if (thisProperty.smooth) {
  12985. smooth = thisProperty.smooth.bind(thisProperty);
  12986. }
  12987. function loopInDuration(type, duration) {
  12988. return loopIn(type, duration, true);
  12989. }
  12990. function loopOutDuration(type, duration) {
  12991. return loopOut(type, duration, true);
  12992. }
  12993. if (this.getValueAtTime) {
  12994. valueAtTime = this.getValueAtTime.bind(this);
  12995. }
  12996. if (this.getVelocityAtTime) {
  12997. velocityAtTime = this.getVelocityAtTime.bind(this);
  12998. }
  12999. var comp = elem.comp.globalData.projectInterface.bind(elem.comp.globalData.projectInterface);
  13000. function lookAt(elem1, elem2) {
  13001. var fVec = [elem2[0] - elem1[0], elem2[1] - elem1[1], elem2[2] - elem1[2]];
  13002. var pitch = Math.atan2(fVec[0], Math.sqrt(fVec[1] * fVec[1] + fVec[2] * fVec[2])) / degToRads;
  13003. var yaw = -Math.atan2(fVec[1], fVec[2]) / degToRads;
  13004. return [yaw, pitch, 0];
  13005. }
  13006. function easeOut(t, tMin, tMax, val1, val2) {
  13007. return applyEase(easeOutBez, t, tMin, tMax, val1, val2);
  13008. }
  13009. function easeIn(t, tMin, tMax, val1, val2) {
  13010. return applyEase(easeInBez, t, tMin, tMax, val1, val2);
  13011. }
  13012. function ease(t, tMin, tMax, val1, val2) {
  13013. return applyEase(easeInOutBez, t, tMin, tMax, val1, val2);
  13014. }
  13015. function applyEase(fn, t, tMin, tMax, val1, val2) {
  13016. if (val1 === undefined) {
  13017. val1 = tMin;
  13018. val2 = tMax;
  13019. } else {
  13020. t = (t - tMin) / (tMax - tMin);
  13021. }
  13022. if (t > 1) {
  13023. t = 1;
  13024. } else if (t < 0) {
  13025. t = 0;
  13026. }
  13027. var mult = fn(t);
  13028. if ($bm_isInstanceOfArray(val1)) {
  13029. var iKey;
  13030. var lenKey = val1.length;
  13031. var arr = createTypedArray('float32', lenKey);
  13032. for (iKey = 0; iKey < lenKey; iKey += 1) {
  13033. arr[iKey] = (val2[iKey] - val1[iKey]) * mult + val1[iKey];
  13034. }
  13035. return arr;
  13036. }
  13037. return (val2 - val1) * mult + val1;
  13038. }
  13039. function nearestKey(time) {
  13040. var iKey;
  13041. var lenKey = data.k.length;
  13042. var index;
  13043. var keyTime;
  13044. if (!data.k.length || typeof (data.k[0]) === 'number') {
  13045. index = 0;
  13046. keyTime = 0;
  13047. } else {
  13048. index = -1;
  13049. time *= elem.comp.globalData.frameRate;
  13050. if (time < data.k[0].t) {
  13051. index = 1;
  13052. keyTime = data.k[0].t;
  13053. } else {
  13054. for (iKey = 0; iKey < lenKey - 1; iKey += 1) {
  13055. if (time === data.k[iKey].t) {
  13056. index = iKey + 1;
  13057. keyTime = data.k[iKey].t;
  13058. break;
  13059. } else if (time > data.k[iKey].t && time < data.k[iKey + 1].t) {
  13060. if (time - data.k[iKey].t > data.k[iKey + 1].t - time) {
  13061. index = iKey + 2;
  13062. keyTime = data.k[iKey + 1].t;
  13063. } else {
  13064. index = iKey + 1;
  13065. keyTime = data.k[iKey].t;
  13066. }
  13067. break;
  13068. }
  13069. }
  13070. if (index === -1) {
  13071. index = iKey + 1;
  13072. keyTime = data.k[iKey].t;
  13073. }
  13074. }
  13075. }
  13076. var obKey = {};
  13077. obKey.index = index;
  13078. obKey.time = keyTime / elem.comp.globalData.frameRate;
  13079. return obKey;
  13080. }
  13081. function key(ind) {
  13082. var obKey;
  13083. var iKey;
  13084. var lenKey;
  13085. if (!data.k.length || typeof (data.k[0]) === 'number') {
  13086. throw new Error('The property has no keyframe at index ' + ind);
  13087. }
  13088. ind -= 1;
  13089. obKey = {
  13090. time: data.k[ind].t / elem.comp.globalData.frameRate,
  13091. value: [],
  13092. };
  13093. var arr = Object.prototype.hasOwnProperty.call(data.k[ind], 's') ? data.k[ind].s : data.k[ind - 1].e;
  13094. lenKey = arr.length;
  13095. for (iKey = 0; iKey < lenKey; iKey += 1) {
  13096. obKey[iKey] = arr[iKey];
  13097. obKey.value[iKey] = arr[iKey];
  13098. }
  13099. return obKey;
  13100. }
  13101. function framesToTime(fr, fps) {
  13102. if (!fps) {
  13103. fps = elem.comp.globalData.frameRate;
  13104. }
  13105. return fr / fps;
  13106. }
  13107. function timeToFrames(t, fps) {
  13108. if (!t && t !== 0) {
  13109. t = time;
  13110. }
  13111. if (!fps) {
  13112. fps = elem.comp.globalData.frameRate;
  13113. }
  13114. return t * fps;
  13115. }
  13116. function seedRandom(seed) {
  13117. BMMath.seedrandom(randSeed + seed);
  13118. }
  13119. function sourceRectAtTime() {
  13120. return elem.sourceRectAtTime();
  13121. }
  13122. function substring(init, end) {
  13123. if (typeof value === 'string') {
  13124. if (end === undefined) {
  13125. return value.substring(init);
  13126. }
  13127. return value.substring(init, end);
  13128. }
  13129. return '';
  13130. }
  13131. function substr(init, end) {
  13132. if (typeof value === 'string') {
  13133. if (end === undefined) {
  13134. return value.substr(init);
  13135. }
  13136. return value.substr(init, end);
  13137. }
  13138. return '';
  13139. }
  13140. function posterizeTime(framesPerSecond) {
  13141. time = framesPerSecond === 0 ? 0 : Math.floor(time * framesPerSecond) / framesPerSecond;
  13142. value = valueAtTime(time);
  13143. }
  13144. var time;
  13145. var velocity;
  13146. var value;
  13147. var text;
  13148. var textIndex;
  13149. var textTotal;
  13150. var selectorValue;
  13151. var index = elem.data.ind;
  13152. var hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  13153. var parent;
  13154. var randSeed = Math.floor(Math.random() * 1000000);
  13155. var globalData = elem.globalData;
  13156. function executeExpression(_value) {
  13157. // globalData.pushExpression();
  13158. value = _value;
  13159. if (this.frameExpressionId === elem.globalData.frameId && this.propType !== 'textSelector') {
  13160. return value;
  13161. }
  13162. if (this.propType === 'textSelector') {
  13163. textIndex = this.textIndex;
  13164. textTotal = this.textTotal;
  13165. selectorValue = this.selectorValue;
  13166. }
  13167. if (!thisLayer) {
  13168. text = elem.layerInterface.text;
  13169. thisLayer = elem.layerInterface;
  13170. thisComp = elem.comp.compInterface;
  13171. toWorld = thisLayer.toWorld.bind(thisLayer);
  13172. fromWorld = thisLayer.fromWorld.bind(thisLayer);
  13173. fromComp = thisLayer.fromComp.bind(thisLayer);
  13174. toComp = thisLayer.toComp.bind(thisLayer);
  13175. mask = thisLayer.mask ? thisLayer.mask.bind(thisLayer) : null;
  13176. fromCompToSurface = fromComp;
  13177. }
  13178. if (!transform) {
  13179. transform = elem.layerInterface('ADBE Transform Group');
  13180. $bm_transform = transform;
  13181. if (transform) {
  13182. anchorPoint = transform.anchorPoint;
  13183. /* position = transform.position;
  13184. rotation = transform.rotation;
  13185. scale = transform.scale; */
  13186. }
  13187. }
  13188. if (elemType === 4 && !content) {
  13189. content = thisLayer('ADBE Root Vectors Group');
  13190. }
  13191. if (!effect) {
  13192. effect = thisLayer(4);
  13193. }
  13194. hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  13195. if (hasParent && !parent) {
  13196. parent = elem.hierarchy[0].layerInterface;
  13197. }
  13198. time = this.comp.renderedFrame / this.comp.globalData.frameRate;
  13199. if (_needsRandom) {
  13200. seedRandom(randSeed + time);
  13201. }
  13202. if (needsVelocity) {
  13203. velocity = velocityAtTime(time);
  13204. }
  13205. expression_function();
  13206. this.frameExpressionId = elem.globalData.frameId;
  13207. // TODO: Check if it's possible to return on ShapeInterface the .v value
  13208. // Changed this to a ternary operation because Rollup failed compiling it correctly
  13209. scoped_bm_rt = scoped_bm_rt.propType === propTypes.SHAPE
  13210. ? scoped_bm_rt.v
  13211. : scoped_bm_rt;
  13212. return scoped_bm_rt;
  13213. }
  13214. // Bundlers will see these as dead code and unless we reference them
  13215. executeExpression.__preventDeadCodeRemoval = [$bm_transform, anchorPoint, time, velocity, inPoint, outPoint, width, height, name, loop_in, loop_out, smooth, toComp, fromCompToSurface, toWorld, fromWorld, mask, position, rotation, scale, thisComp, numKeys, active, wiggle, loopInDuration, loopOutDuration, comp, lookAt, easeOut, easeIn, ease, nearestKey, key, text, textIndex, textTotal, selectorValue, framesToTime, timeToFrames, sourceRectAtTime, substring, substr, posterizeTime, index, globalData];
  13216. return executeExpression;
  13217. }
  13218. ob.initiateExpression = initiateExpression;
  13219. ob.__preventDeadCodeRemoval = [window, document, XMLHttpRequest, fetch, frames, $bm_neg, add, $bm_sum, $bm_sub, $bm_mul, $bm_div, $bm_mod, clamp, radians_to_degrees, degreesToRadians, degrees_to_radians, normalize, rgbToHsl, hslToRgb, linear, random, createPath];
  13220. return ob;
  13221. }());
  13222. const expressionHelpers = (function () {
  13223. function searchExpressions(elem, data, prop) {
  13224. if (data.x) {
  13225. prop.k = true;
  13226. prop.x = true;
  13227. prop.initiateExpression = ExpressionManager.initiateExpression;
  13228. prop.effectsSequence.push(prop.initiateExpression(elem, data, prop).bind(prop));
  13229. }
  13230. }
  13231. function getValueAtTime(frameNum) {
  13232. frameNum *= this.elem.globalData.frameRate;
  13233. frameNum -= this.offsetTime;
  13234. if (frameNum !== this._cachingAtTime.lastFrame) {
  13235. this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0;
  13236. this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime);
  13237. this._cachingAtTime.lastFrame = frameNum;
  13238. }
  13239. return this._cachingAtTime.value;
  13240. }
  13241. function getSpeedAtTime(frameNum) {
  13242. var delta = -0.01;
  13243. var v1 = this.getValueAtTime(frameNum);
  13244. var v2 = this.getValueAtTime(frameNum + delta);
  13245. var speed = 0;
  13246. if (v1.length) {
  13247. var i;
  13248. for (i = 0; i < v1.length; i += 1) {
  13249. speed += Math.pow(v2[i] - v1[i], 2);
  13250. }
  13251. speed = Math.sqrt(speed) * 100;
  13252. } else {
  13253. speed = 0;
  13254. }
  13255. return speed;
  13256. }
  13257. function getVelocityAtTime(frameNum) {
  13258. if (this.vel !== undefined) {
  13259. return this.vel;
  13260. }
  13261. var delta = -0.001;
  13262. // frameNum += this.elem.data.st;
  13263. var v1 = this.getValueAtTime(frameNum);
  13264. var v2 = this.getValueAtTime(frameNum + delta);
  13265. var velocity;
  13266. if (v1.length) {
  13267. velocity = createTypedArray('float32', v1.length);
  13268. var i;
  13269. for (i = 0; i < v1.length; i += 1) {
  13270. // removing frameRate
  13271. // if needed, don't add it here
  13272. // velocity[i] = this.elem.globalData.frameRate*((v2[i] - v1[i])/delta);
  13273. velocity[i] = (v2[i] - v1[i]) / delta;
  13274. }
  13275. } else {
  13276. velocity = (v2 - v1) / delta;
  13277. }
  13278. return velocity;
  13279. }
  13280. function getStaticValueAtTime() {
  13281. return this.pv;
  13282. }
  13283. function setGroupProperty(propertyGroup) {
  13284. this.propertyGroup = propertyGroup;
  13285. }
  13286. return {
  13287. searchExpressions: searchExpressions,
  13288. getSpeedAtTime: getSpeedAtTime,
  13289. getVelocityAtTime: getVelocityAtTime,
  13290. getValueAtTime: getValueAtTime,
  13291. getStaticValueAtTime: getStaticValueAtTime,
  13292. setGroupProperty: setGroupProperty,
  13293. };
  13294. }());
  13295. function addPropertyDecorator() {
  13296. function loopOut(type, duration, durationFlag) {
  13297. if (!this.k || !this.keyframes) {
  13298. return this.pv;
  13299. }
  13300. type = type ? type.toLowerCase() : '';
  13301. var currentFrame = this.comp.renderedFrame;
  13302. var keyframes = this.keyframes;
  13303. var lastKeyFrame = keyframes[keyframes.length - 1].t;
  13304. if (currentFrame <= lastKeyFrame) {
  13305. return this.pv;
  13306. }
  13307. var cycleDuration;
  13308. var firstKeyFrame;
  13309. if (!durationFlag) {
  13310. if (!duration || duration > keyframes.length - 1) {
  13311. duration = keyframes.length - 1;
  13312. }
  13313. firstKeyFrame = keyframes[keyframes.length - 1 - duration].t;
  13314. cycleDuration = lastKeyFrame - firstKeyFrame;
  13315. } else {
  13316. if (!duration) {
  13317. cycleDuration = Math.max(0, lastKeyFrame - this.elem.data.ip);
  13318. } else {
  13319. cycleDuration = Math.abs(lastKeyFrame - this.elem.comp.globalData.frameRate * duration);
  13320. }
  13321. firstKeyFrame = lastKeyFrame - cycleDuration;
  13322. }
  13323. var i;
  13324. var len;
  13325. var ret;
  13326. if (type === 'pingpong') {
  13327. var iterations = Math.floor((currentFrame - firstKeyFrame) / cycleDuration);
  13328. if (iterations % 2 !== 0) {
  13329. return this.getValueAtTime(((cycleDuration - (currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  13330. }
  13331. } else if (type === 'offset') {
  13332. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  13333. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  13334. var current = this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  13335. var repeats = Math.floor((currentFrame - firstKeyFrame) / cycleDuration);
  13336. if (this.pv.length) {
  13337. ret = new Array(initV.length);
  13338. len = ret.length;
  13339. for (i = 0; i < len; i += 1) {
  13340. ret[i] = (endV[i] - initV[i]) * repeats + current[i];
  13341. }
  13342. return ret;
  13343. }
  13344. return (endV - initV) * repeats + current;
  13345. } else if (type === 'continue') {
  13346. var lastValue = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  13347. var nextLastValue = this.getValueAtTime((lastKeyFrame - 0.001) / this.comp.globalData.frameRate, 0);
  13348. if (this.pv.length) {
  13349. ret = new Array(lastValue.length);
  13350. len = ret.length;
  13351. for (i = 0; i < len; i += 1) {
  13352. ret[i] = lastValue[i] + (lastValue[i] - nextLastValue[i]) * ((currentFrame - lastKeyFrame) / this.comp.globalData.frameRate) / 0.0005; // eslint-disable-line
  13353. }
  13354. return ret;
  13355. }
  13356. return lastValue + (lastValue - nextLastValue) * (((currentFrame - lastKeyFrame)) / 0.001);
  13357. }
  13358. return this.getValueAtTime((((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  13359. }
  13360. function loopIn(type, duration, durationFlag) {
  13361. if (!this.k) {
  13362. return this.pv;
  13363. }
  13364. type = type ? type.toLowerCase() : '';
  13365. var currentFrame = this.comp.renderedFrame;
  13366. var keyframes = this.keyframes;
  13367. var firstKeyFrame = keyframes[0].t;
  13368. if (currentFrame >= firstKeyFrame) {
  13369. return this.pv;
  13370. }
  13371. var cycleDuration;
  13372. var lastKeyFrame;
  13373. if (!durationFlag) {
  13374. if (!duration || duration > keyframes.length - 1) {
  13375. duration = keyframes.length - 1;
  13376. }
  13377. lastKeyFrame = keyframes[duration].t;
  13378. cycleDuration = lastKeyFrame - firstKeyFrame;
  13379. } else {
  13380. if (!duration) {
  13381. cycleDuration = Math.max(0, this.elem.data.op - firstKeyFrame);
  13382. } else {
  13383. cycleDuration = Math.abs(this.elem.comp.globalData.frameRate * duration);
  13384. }
  13385. lastKeyFrame = firstKeyFrame + cycleDuration;
  13386. }
  13387. var i;
  13388. var len;
  13389. var ret;
  13390. if (type === 'pingpong') {
  13391. var iterations = Math.floor((firstKeyFrame - currentFrame) / cycleDuration);
  13392. if (iterations % 2 === 0) {
  13393. return this.getValueAtTime((((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  13394. }
  13395. } else if (type === 'offset') {
  13396. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  13397. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  13398. var current = this.getValueAtTime((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration) + firstKeyFrame) / this.comp.globalData.frameRate, 0);
  13399. var repeats = Math.floor((firstKeyFrame - currentFrame) / cycleDuration) + 1;
  13400. if (this.pv.length) {
  13401. ret = new Array(initV.length);
  13402. len = ret.length;
  13403. for (i = 0; i < len; i += 1) {
  13404. ret[i] = current[i] - (endV[i] - initV[i]) * repeats;
  13405. }
  13406. return ret;
  13407. }
  13408. return current - (endV - initV) * repeats;
  13409. } else if (type === 'continue') {
  13410. var firstValue = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  13411. var nextFirstValue = this.getValueAtTime((firstKeyFrame + 0.001) / this.comp.globalData.frameRate, 0);
  13412. if (this.pv.length) {
  13413. ret = new Array(firstValue.length);
  13414. len = ret.length;
  13415. for (i = 0; i < len; i += 1) {
  13416. ret[i] = firstValue[i] + ((firstValue[i] - nextFirstValue[i]) * (firstKeyFrame - currentFrame)) / 0.001;
  13417. }
  13418. return ret;
  13419. }
  13420. return firstValue + ((firstValue - nextFirstValue) * (firstKeyFrame - currentFrame)) / 0.001;
  13421. }
  13422. return this.getValueAtTime(((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame))) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  13423. }
  13424. function smooth(width, samples) {
  13425. if (!this.k) {
  13426. return this.pv;
  13427. }
  13428. width = (width || 0.4) * 0.5;
  13429. samples = Math.floor(samples || 5);
  13430. if (samples <= 1) {
  13431. return this.pv;
  13432. }
  13433. var currentTime = this.comp.renderedFrame / this.comp.globalData.frameRate;
  13434. var initFrame = currentTime - width;
  13435. var endFrame = currentTime + width;
  13436. var sampleFrequency = samples > 1 ? (endFrame - initFrame) / (samples - 1) : 1;
  13437. var i = 0;
  13438. var j = 0;
  13439. var value;
  13440. if (this.pv.length) {
  13441. value = createTypedArray('float32', this.pv.length);
  13442. } else {
  13443. value = 0;
  13444. }
  13445. var sampleValue;
  13446. while (i < samples) {
  13447. sampleValue = this.getValueAtTime(initFrame + i * sampleFrequency);
  13448. if (this.pv.length) {
  13449. for (j = 0; j < this.pv.length; j += 1) {
  13450. value[j] += sampleValue[j];
  13451. }
  13452. } else {
  13453. value += sampleValue;
  13454. }
  13455. i += 1;
  13456. }
  13457. if (this.pv.length) {
  13458. for (j = 0; j < this.pv.length; j += 1) {
  13459. value[j] /= samples;
  13460. }
  13461. } else {
  13462. value /= samples;
  13463. }
  13464. return value;
  13465. }
  13466. function getTransformValueAtTime(time) {
  13467. if (!this._transformCachingAtTime) {
  13468. this._transformCachingAtTime = {
  13469. v: new Matrix(),
  13470. };
  13471. }
  13472. /// /
  13473. var matrix = this._transformCachingAtTime.v;
  13474. matrix.cloneFromProps(this.pre.props);
  13475. if (this.appliedTransformations < 1) {
  13476. var anchor = this.a.getValueAtTime(time);
  13477. matrix.translate(
  13478. -anchor[0] * this.a.mult,
  13479. -anchor[1] * this.a.mult,
  13480. anchor[2] * this.a.mult
  13481. );
  13482. }
  13483. if (this.appliedTransformations < 2) {
  13484. var scale = this.s.getValueAtTime(time);
  13485. matrix.scale(
  13486. scale[0] * this.s.mult,
  13487. scale[1] * this.s.mult,
  13488. scale[2] * this.s.mult
  13489. );
  13490. }
  13491. if (this.sk && this.appliedTransformations < 3) {
  13492. var skew = this.sk.getValueAtTime(time);
  13493. var skewAxis = this.sa.getValueAtTime(time);
  13494. matrix.skewFromAxis(-skew * this.sk.mult, skewAxis * this.sa.mult);
  13495. }
  13496. if (this.r && this.appliedTransformations < 4) {
  13497. var rotation = this.r.getValueAtTime(time);
  13498. matrix.rotate(-rotation * this.r.mult);
  13499. } else if (!this.r && this.appliedTransformations < 4) {
  13500. var rotationZ = this.rz.getValueAtTime(time);
  13501. var rotationY = this.ry.getValueAtTime(time);
  13502. var rotationX = this.rx.getValueAtTime(time);
  13503. var orientation = this.or.getValueAtTime(time);
  13504. matrix.rotateZ(-rotationZ * this.rz.mult)
  13505. .rotateY(rotationY * this.ry.mult)
  13506. .rotateX(rotationX * this.rx.mult)
  13507. .rotateZ(-orientation[2] * this.or.mult)
  13508. .rotateY(orientation[1] * this.or.mult)
  13509. .rotateX(orientation[0] * this.or.mult);
  13510. }
  13511. if (this.data.p && this.data.p.s) {
  13512. var positionX = this.px.getValueAtTime(time);
  13513. var positionY = this.py.getValueAtTime(time);
  13514. if (this.data.p.z) {
  13515. var positionZ = this.pz.getValueAtTime(time);
  13516. matrix.translate(
  13517. positionX * this.px.mult,
  13518. positionY * this.py.mult,
  13519. -positionZ * this.pz.mult
  13520. );
  13521. } else {
  13522. matrix.translate(positionX * this.px.mult, positionY * this.py.mult, 0);
  13523. }
  13524. } else {
  13525. var position = this.p.getValueAtTime(time);
  13526. matrix.translate(
  13527. position[0] * this.p.mult,
  13528. position[1] * this.p.mult,
  13529. -position[2] * this.p.mult
  13530. );
  13531. }
  13532. return matrix;
  13533. /// /
  13534. }
  13535. function getTransformStaticValueAtTime() {
  13536. return this.v.clone(new Matrix());
  13537. }
  13538. var getTransformProperty = TransformPropertyFactory.getTransformProperty;
  13539. TransformPropertyFactory.getTransformProperty = function (elem, data, container) {
  13540. var prop = getTransformProperty(elem, data, container);
  13541. if (prop.dynamicProperties.length) {
  13542. prop.getValueAtTime = getTransformValueAtTime.bind(prop);
  13543. } else {
  13544. prop.getValueAtTime = getTransformStaticValueAtTime.bind(prop);
  13545. }
  13546. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  13547. return prop;
  13548. };
  13549. var propertyGetProp = PropertyFactory.getProp;
  13550. PropertyFactory.getProp = function (elem, data, type, mult, container) {
  13551. var prop = propertyGetProp(elem, data, type, mult, container);
  13552. // prop.getVelocityAtTime = getVelocityAtTime;
  13553. // prop.loopOut = loopOut;
  13554. // prop.loopIn = loopIn;
  13555. if (prop.kf) {
  13556. prop.getValueAtTime = expressionHelpers.getValueAtTime.bind(prop);
  13557. } else {
  13558. prop.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(prop);
  13559. }
  13560. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  13561. prop.loopOut = loopOut;
  13562. prop.loopIn = loopIn;
  13563. prop.smooth = smooth;
  13564. prop.getVelocityAtTime = expressionHelpers.getVelocityAtTime.bind(prop);
  13565. prop.getSpeedAtTime = expressionHelpers.getSpeedAtTime.bind(prop);
  13566. prop.numKeys = data.a === 1 ? data.k.length : 0;
  13567. prop.propertyIndex = data.ix;
  13568. var value = 0;
  13569. if (type !== 0) {
  13570. value = createTypedArray('float32', data.a === 1 ? data.k[0].s.length : data.k.length);
  13571. }
  13572. prop._cachingAtTime = {
  13573. lastFrame: initialDefaultFrame,
  13574. lastIndex: 0,
  13575. value: value,
  13576. };
  13577. expressionHelpers.searchExpressions(elem, data, prop);
  13578. if (prop.k) {
  13579. container.addDynamicProperty(prop);
  13580. }
  13581. return prop;
  13582. };
  13583. function getShapeValueAtTime(frameNum) {
  13584. // For now this caching object is created only when needed instead of creating it when the shape is initialized.
  13585. if (!this._cachingAtTime) {
  13586. this._cachingAtTime = {
  13587. shapeValue: shapePool.clone(this.pv),
  13588. lastIndex: 0,
  13589. lastTime: initialDefaultFrame,
  13590. };
  13591. }
  13592. frameNum *= this.elem.globalData.frameRate;
  13593. frameNum -= this.offsetTime;
  13594. if (frameNum !== this._cachingAtTime.lastTime) {
  13595. this._cachingAtTime.lastIndex = this._cachingAtTime.lastTime < frameNum ? this._caching.lastIndex : 0;
  13596. this._cachingAtTime.lastTime = frameNum;
  13597. this.interpolateShape(frameNum, this._cachingAtTime.shapeValue, this._cachingAtTime);
  13598. }
  13599. return this._cachingAtTime.shapeValue;
  13600. }
  13601. var ShapePropertyConstructorFunction = ShapePropertyFactory.getConstructorFunction();
  13602. var KeyframedShapePropertyConstructorFunction = ShapePropertyFactory.getKeyframedConstructorFunction();
  13603. function ShapeExpressions() {}
  13604. ShapeExpressions.prototype = {
  13605. vertices: function (prop, time) {
  13606. if (this.k) {
  13607. this.getValue();
  13608. }
  13609. var shapePath = this.v;
  13610. if (time !== undefined) {
  13611. shapePath = this.getValueAtTime(time, 0);
  13612. }
  13613. var i;
  13614. var len = shapePath._length;
  13615. var vertices = shapePath[prop];
  13616. var points = shapePath.v;
  13617. var arr = createSizedArray(len);
  13618. for (i = 0; i < len; i += 1) {
  13619. if (prop === 'i' || prop === 'o') {
  13620. arr[i] = [vertices[i][0] - points[i][0], vertices[i][1] - points[i][1]];
  13621. } else {
  13622. arr[i] = [vertices[i][0], vertices[i][1]];
  13623. }
  13624. }
  13625. return arr;
  13626. },
  13627. points: function (time) {
  13628. return this.vertices('v', time);
  13629. },
  13630. inTangents: function (time) {
  13631. return this.vertices('i', time);
  13632. },
  13633. outTangents: function (time) {
  13634. return this.vertices('o', time);
  13635. },
  13636. isClosed: function () {
  13637. return this.v.c;
  13638. },
  13639. pointOnPath: function (perc, time) {
  13640. var shapePath = this.v;
  13641. if (time !== undefined) {
  13642. shapePath = this.getValueAtTime(time, 0);
  13643. }
  13644. if (!this._segmentsLength) {
  13645. this._segmentsLength = bez.getSegmentsLength(shapePath);
  13646. }
  13647. var segmentsLength = this._segmentsLength;
  13648. var lengths = segmentsLength.lengths;
  13649. var lengthPos = segmentsLength.totalLength * perc;
  13650. var i = 0;
  13651. var len = lengths.length;
  13652. var accumulatedLength = 0;
  13653. var pt;
  13654. while (i < len) {
  13655. if (accumulatedLength + lengths[i].addedLength > lengthPos) {
  13656. var initIndex = i;
  13657. var endIndex = (shapePath.c && i === len - 1) ? 0 : i + 1;
  13658. var segmentPerc = (lengthPos - accumulatedLength) / lengths[i].addedLength;
  13659. pt = bez.getPointInSegment(shapePath.v[initIndex], shapePath.v[endIndex], shapePath.o[initIndex], shapePath.i[endIndex], segmentPerc, lengths[i]);
  13660. break;
  13661. } else {
  13662. accumulatedLength += lengths[i].addedLength;
  13663. }
  13664. i += 1;
  13665. }
  13666. if (!pt) {
  13667. pt = shapePath.c ? [shapePath.v[0][0], shapePath.v[0][1]] : [shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1]];
  13668. }
  13669. return pt;
  13670. },
  13671. vectorOnPath: function (perc, time, vectorType) {
  13672. // perc doesn't use triple equality because it can be a Number object as well as a primitive.
  13673. if (perc == 1) { // eslint-disable-line eqeqeq
  13674. perc = this.v.c;
  13675. } else if (perc == 0) { // eslint-disable-line eqeqeq
  13676. perc = 0.999;
  13677. }
  13678. var pt1 = this.pointOnPath(perc, time);
  13679. var pt2 = this.pointOnPath(perc + 0.001, time);
  13680. var xLength = pt2[0] - pt1[0];
  13681. var yLength = pt2[1] - pt1[1];
  13682. var magnitude = Math.sqrt(Math.pow(xLength, 2) + Math.pow(yLength, 2));
  13683. if (magnitude === 0) {
  13684. return [0, 0];
  13685. }
  13686. var unitVector = vectorType === 'tangent' ? [xLength / magnitude, yLength / magnitude] : [-yLength / magnitude, xLength / magnitude];
  13687. return unitVector;
  13688. },
  13689. tangentOnPath: function (perc, time) {
  13690. return this.vectorOnPath(perc, time, 'tangent');
  13691. },
  13692. normalOnPath: function (perc, time) {
  13693. return this.vectorOnPath(perc, time, 'normal');
  13694. },
  13695. setGroupProperty: expressionHelpers.setGroupProperty,
  13696. getValueAtTime: expressionHelpers.getStaticValueAtTime,
  13697. };
  13698. extendPrototype([ShapeExpressions], ShapePropertyConstructorFunction);
  13699. extendPrototype([ShapeExpressions], KeyframedShapePropertyConstructorFunction);
  13700. KeyframedShapePropertyConstructorFunction.prototype.getValueAtTime = getShapeValueAtTime;
  13701. KeyframedShapePropertyConstructorFunction.prototype.initiateExpression = ExpressionManager.initiateExpression;
  13702. var propertyGetShapeProp = ShapePropertyFactory.getShapeProp;
  13703. ShapePropertyFactory.getShapeProp = function (elem, data, type, arr, trims) {
  13704. var prop = propertyGetShapeProp(elem, data, type, arr, trims);
  13705. prop.propertyIndex = data.ix;
  13706. prop.lock = false;
  13707. if (type === 3) {
  13708. expressionHelpers.searchExpressions(elem, data.pt, prop);
  13709. } else if (type === 4) {
  13710. expressionHelpers.searchExpressions(elem, data.ks, prop);
  13711. }
  13712. if (prop.k) {
  13713. elem.addDynamicProperty(prop);
  13714. }
  13715. return prop;
  13716. };
  13717. }
  13718. function initialize$1() {
  13719. addPropertyDecorator();
  13720. }
  13721. function addDecorator() {
  13722. function searchExpressions() {
  13723. if (this.data.d.x) {
  13724. this.calculateExpression = ExpressionManager.initiateExpression.bind(this)(this.elem, this.data.d, this);
  13725. this.addEffect(this.getExpressionValue.bind(this));
  13726. return true;
  13727. }
  13728. return null;
  13729. }
  13730. TextProperty.prototype.getExpressionValue = function (currentValue, text) {
  13731. var newValue = this.calculateExpression(text);
  13732. if (currentValue.t !== newValue) {
  13733. var newData = {};
  13734. this.copyData(newData, currentValue);
  13735. newData.t = newValue.toString();
  13736. newData.__complete = false;
  13737. return newData;
  13738. }
  13739. return currentValue;
  13740. };
  13741. TextProperty.prototype.searchProperty = function () {
  13742. var isKeyframed = this.searchKeyframes();
  13743. var hasExpressions = this.searchExpressions();
  13744. this.kf = isKeyframed || hasExpressions;
  13745. return this.kf;
  13746. };
  13747. TextProperty.prototype.searchExpressions = searchExpressions;
  13748. }
  13749. function initialize() {
  13750. addDecorator();
  13751. }
  13752. // Registering expression plugin
  13753. setExpressionsPlugin(Expressions);
  13754. initialize$1();
  13755. initialize();
  13756. export { lottie as default };